OpenASIP  2.0
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"
35 #include "ExecutableInstruction.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  }
67  implicitInstructions_.clear();
68 }
69 
70 /**
71  * Adds new ExecutableInstruction to memory.
72  *
73  * @param instruction Instruction to be added.
74  */
75 void
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  */
91 void
93  InstructionAddress addr, ExecutableInstruction* instruction) {
94  if (implicitInstructions_.find(addr) == implicitInstructions_.end()) {
96  }
97  implicitInstructions_[addr]->push_back(instruction);
98 }
99 
100 /**
101  * Resets execution counters of all instructions.
102  *
103  */
104 void
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  */
116 bool
118  return instructionMap_.find(addr) != instructionMap_.end();
119 }
120 
121 
122 bool
124  return implicitInstructions_.find(addr) != implicitInstructions_.end();
125 }
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 }
ExecutableInstruction
Definition: ExecutableInstruction.hh:49
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
InstructionMemory::hasInstructionAt
bool hasInstructionAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:117
InstructionMemory::addImplicitExecutableInstruction
void addImplicitExecutableInstruction(InstructionAddress addr, ExecutableInstruction *instruction)
Definition: InstructionMemory.cc:92
InstructionMemory::emptyInstructions_
InstructionContainer emptyInstructions_
Definition: InstructionMemory.hh:90
InstructionMemory::implicitInstructionsAt
const InstructionContainer & implicitInstructionsAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:128
SequenceTools.hh
InstructionMemory.hh
InstructionMemory::resetExecutionCounts
void resetExecutionCounts()
Definition: InstructionMemory.cc:105
InstructionMemory::InstructionContainer
std::vector< ExecutableInstruction * > InstructionContainer
Container for instructions.
Definition: InstructionMemory.hh:57
Conversion.hh
Application.hh
InstructionMemory::instructionMap_
std::map< InstructionAddress, ExecutableInstruction * > instructionMap_
Stores the explicit instruction addresses.
Definition: InstructionMemory.hh:95
InstructionMemory::hasImplicitInstructionsAt
bool hasImplicitInstructionsAt(InstructionAddress addr) const
Definition: InstructionMemory.cc:123
InstructionMemory::instructions_
InstructionContainer instructions_
All the instructions of the memory.
Definition: InstructionMemory.hh:88
ExecutableInstruction.hh
InstructionMemory::~InstructionMemory
virtual ~InstructionMemory()
Definition: InstructionMemory.cc:55
InstructionMemory::InstructionMemory
InstructionMemory(InstructionAddress startAddress)
Definition: InstructionMemory.cc:47
InstructionMemory::addExecutableInstruction
void addExecutableInstruction(InstructionAddress addr, ExecutableInstruction *instruction)
Definition: InstructionMemory.cc:76
InstructionMemory::implicitInstructions_
std::map< InstructionAddress, InstructionContainer * > implicitInstructions_
Stores implicit instructions that should be executed after the explicit one in the same address.
Definition: InstructionMemory.hh:98