OpenASIP 2.2
Loading...
Searching...
No Matches
InstructionMemory.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2016 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file InstructionMemory.cc
26 *
27 * Definition of InstructionMemory class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Pekka Jääskeläinen 2005,2016 (pjaaskel-no.spam-cs.tut.fi)
31 * @note rating: red
32 */
33
34#include "InstructionMemory.hh"
36#include "SequenceTools.hh"
37#include "Application.hh"
38#include "Conversion.hh"
39
40/**
41 * Constructor.
42 *
43 * This constructor is for constant width instructions only.
44 *
45 * @param startAddress The starting address of the instruction memory.
46 */
48 InstructionAddress startAddress) :
49 startAddress_(startAddress) {
50}
51
52/**
53 * Destructor.
54 */
56
57 for (InstructionContainer::const_iterator i = instructions_.begin();
58 i != instructions_.end(); ++i) {
59 delete (*i);
60 }
61 instructions_.clear();
62
63 for (auto Pair : implicitInstructions_) {
64 InstructionContainer* C = Pair.second;
65 delete C;
66 }
68}
69
70/**
71 * Adds new ExecutableInstruction to memory.
72 *
73 * @param instruction Instruction to be added.
74 */
75void
77 InstructionAddress addr, ExecutableInstruction* instruction) {
78
79 instructions_.push_back(instruction);
80 instructionMap_[addr] = instruction;
81}
82
83/**
84 * Adds an "implicit instruction" used to simulate effects triggered
85 * by operation-triggered instructions as side-effects, but which are
86 * not controlled by the programmer.
87 *
88 * Should be added after the explicit instruction in the order of
89 * how the effects should be done.
90 */
91void
99
100/**
101 * Resets execution counters of all instructions.
102 *
103 */
104void
106 for (InstructionContainer::iterator i = instructions_.begin();
107 i != instructions_.end(); ++i) {
108 (*i)->resetExecutionCounts();
109 }
110}
111
112/**
113 * Returns true in case there is an implicit or explicit instruction
114 * at the given address.
115 */
116bool
120
121
122bool
126
129 if (implicitInstructions_.find(addr) == implicitInstructions_.end()) {
130 return emptyInstructions_;
131 }
132
133 const InstructionContainer* IC = implicitInstructions_.find(addr)->second;
134 return *IC;
135}
UInt32 InstructionAddress
Definition BaseType.hh:175
std::vector< ExecutableInstruction * > InstructionContainer
Container for instructions.
std::map< InstructionAddress, InstructionContainer * > implicitInstructions_
Stores implicit instructions that should be executed after the explicit one in the same address.
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
void addImplicitExecutableInstruction(InstructionAddress addr, ExecutableInstruction *instruction)
std::map< InstructionAddress, ExecutableInstruction * > instructionMap_
Stores the explicit instruction addresses.
InstructionMemory(InstructionAddress startAddress)
InstructionContainer emptyInstructions_
bool hasInstructionAt(InstructionAddress addr) const
InstructionContainer instructions_
All the instructions of the memory.
void addExecutableInstruction(InstructionAddress addr, ExecutableInstruction *instruction)
bool hasImplicitInstructionsAt(InstructionAddress addr) const