OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CompiledSimSymbolGenerator Class Reference

#include <CompiledSimSymbolGenerator.hh>

Collaboration diagram for CompiledSimSymbolGenerator:
Collaboration graph

Public Member Functions

 CompiledSimSymbolGenerator (const TCEString &globalSymbolSuffix)
 
virtual ~CompiledSimSymbolGenerator ()
 
void enablePrefix (const std::string &prefix)
 
void disablePrefix ()
 
std::string timeStamp () const
 
std::string portSymbol (const TTAMachine::Port &port) const
 
std::string registerSymbol (const TTAProgram::Terminal &terminal) const
 
std::string registerSymbol (const TTAMachine::RegisterFile &rf, int index) const
 
std::string immediateRegisterSymbol (const TTAProgram::Terminal &terminal) const
 
std::string immediateRegisterSymbol (const TTAMachine::ImmediateUnit &iu, int index) const
 
std::string busSymbol (const TTAMachine::Bus &bus) const
 
std::string returnAddressSymbol (const TTAMachine::ControlUnit &gcu) const
 
std::string moveOperandSymbol (const TTAProgram::Terminal &terminal, const TTAProgram::Move &move) const
 
std::string operationContextSymbol (const TTAMachine::FunctionUnit &fu) const
 
std::string conflictDetectorSymbol (const TTAMachine::FunctionUnit &fu) const
 
std::string targetMemorySymbol (const TTAMachine::FunctionUnit &fu) const
 
std::string DAMemorySymbol (const TTAMachine::FunctionUnit &fu) const
 
std::string guardBoolSymbol () const
 
std::string basicBlockSymbol (InstructionAddress startAddress) const
 
std::string operationSymbol (const std::string &operationName, const TTAMachine::FunctionUnit &fu) const
 
std::string FUResultSymbol (const TTAMachine::Port &port) const
 
std::string generateTempVariable () const
 
std::string jumpTargetSetterSymbol (InstructionAddress address) const
 

Private Member Functions

 CompiledSimSymbolGenerator (const CompiledSimSymbolGenerator &)
 Copying not allowed.
 
CompiledSimSymbolGeneratoroperator= (const CompiledSimSymbolGenerator &)
 Assignment not allowed.
 

Private Attributes

TCEString prefix_
 Prefix used for generated variable symbols.
 
TCEString globalSymbolSuffix_
 Suffix used for the generated global function symbols.
 

Detailed Description

A class that generates C/C++ symbol names for given objects in the simulation

Used for the compiled simulation

Definition at line 66 of file CompiledSimSymbolGenerator.hh.

Constructor & Destructor Documentation

◆ CompiledSimSymbolGenerator() [1/2]

CompiledSimSymbolGenerator::CompiledSimSymbolGenerator ( const TCEString globalSymbolSuffix)

Default constructor.

Parameters
globalSymbolSuffixCan be used to produce unique symbol names for the global BB simulation functions. This has to be used in case using multiple simulation engines in the same process.

Definition at line 62 of file CompiledSimSymbolGenerator.cc.

63 :
64 globalSymbolSuffix_(globalSymbolSuffix) {
65}
TCEString globalSymbolSuffix_
Suffix used for the generated global function symbols.

◆ ~CompiledSimSymbolGenerator()

CompiledSimSymbolGenerator::~CompiledSimSymbolGenerator ( )
virtual

Default destructor

Definition at line 70 of file CompiledSimSymbolGenerator.cc.

70 {
71}

◆ CompiledSimSymbolGenerator() [2/2]

CompiledSimSymbolGenerator::CompiledSimSymbolGenerator ( const CompiledSimSymbolGenerator )
private

Copying not allowed.

Member Function Documentation

◆ basicBlockSymbol()

std::string CompiledSimSymbolGenerator::basicBlockSymbol ( InstructionAddress  startAddress) const

Generates an unique symbol name for a basic block function

A new C/C++ function is created for each basic block in the program, so the generated symbol will also be used as the generated function name.

Parameters
startAddressThe start address of the basic block
Returns
A string containing the generated symbol name

Definition at line 320 of file CompiledSimSymbolGenerator.cc.

321 {
322 return "simulate_" + globalSymbolSuffix_ + "_" + Conversion::toString(startAddress);
323}
static std::string toString(const T &source)

References globalSymbolSuffix_, and Conversion::toString().

Referenced by CompiledSimulation::compileAndLoadFunction(), CompiledSimCodeGenerator::generateConstructorCode(), CompiledSimCodeGenerator::generateInstruction(), and CompiledSimCodeGenerator::generateJumpTableCode().

Here is the call graph for this function:

◆ busSymbol()

std::string CompiledSimSymbolGenerator::busSymbol ( const TTAMachine::Bus bus) const

Generates an unique symbol name for a TTA machine bus

Parameters
busThe given bus
Returns
A string containing the generated symbol name

Definition at line 205 of file CompiledSimSymbolGenerator.cc.

205 {
206 return prefix_ + "bus_" + bus.name();
207}
TCEString prefix_
Prefix used for generated variable symbols.
virtual TCEString name() const

References TTAMachine::Component::name(), and prefix_.

Referenced by CompiledSimMove::copyFromBusCode(), CompiledSimMove::copyToBusCode(), and CompiledSimCodeGenerator::generateHeaderAndMainCode().

Here is the call graph for this function:

◆ conflictDetectorSymbol()

std::string CompiledSimSymbolGenerator::conflictDetectorSymbol ( const TTAMachine::FunctionUnit fu) const

Generates an unique symbol name for a given FU conflict detector.

Parameters
fuThe given function unit
Returns
std::string containing the generated symbol name

Definition at line 270 of file CompiledSimSymbolGenerator.cc.

271 {
272 return prefix_ + "FU_" + fu.name() + "_conflict_detector";
273}

References TTAMachine::Component::name(), and prefix_.

Referenced by ConflictDetectionCodeGenerator::ConflictDetectionCodeGenerator(), and ConflictDetectionCodeGenerator::symbolDeclaration().

Here is the call graph for this function:

◆ DAMemorySymbol()

std::string CompiledSimSymbolGenerator::DAMemorySymbol ( const TTAMachine::FunctionUnit fu) const

Generates an unique symbol name for the given FU's DirectAccessMemory&

Parameters
fuNameGiven function unit
Returns
A string containing the generated symbol name

Definition at line 294 of file CompiledSimSymbolGenerator.cc.

295 {
296 return prefix_ + fu.name() + "_direct_access_memory";
297}

References TTAMachine::Component::name(), and prefix_.

Referenced by CompiledSimCodeGenerator::generateConstructorCode(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateLoadTrigger(), CompiledSimCodeGenerator::generateStoreTrigger(), and CompiledSimCodeGenerator::updateDeclaredSymbolsList().

Here is the call graph for this function:

◆ disablePrefix()

void CompiledSimSymbolGenerator::disablePrefix ( )

◆ enablePrefix()

void CompiledSimSymbolGenerator::enablePrefix ( const std::string &  prefix)

Sets a new prefix to be used for generated variable symbols

Parameters
prefixnew prefix to be set

Definition at line 79 of file CompiledSimSymbolGenerator.cc.

79 {
80 prefix_ = prefix;
81}

References prefix_.

Referenced by CompiledSimCodeGenerator::generateFUOutputUpdater(), and CompiledSimCodeGenerator::generateInstruction().

◆ FUResultSymbol()

std::string CompiledSimSymbolGenerator::FUResultSymbol ( const TTAMachine::Port port) const

Generates an unique symbol name for FU's results.

Parameters
portThe FU port
Returns
A string containing the generated FU results symbol

Definition at line 346 of file CompiledSimSymbolGenerator.cc.

346 {
347 return portSymbol(port) + "_results";
348}
std::string portSymbol(const TTAMachine::Port &port) const

References portSymbol().

Referenced by CompiledSimCodeGenerator::generateAddFUResult(), CompiledSimCodeGenerator::generateFUOutputUpdater(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateInstruction(), and CompiledSimCodeGenerator::updateDeclaredSymbolsList().

Here is the call graph for this function:

◆ generateTempVariable()

std::string CompiledSimSymbolGenerator::generateTempVariable ( ) const

Generates name for temporary variables using incremental numbers

Returns
The generated temporary variable name

Definition at line 356 of file CompiledSimSymbolGenerator.cc.

356 {
357 static int counter = 0;
358 return "_tmp_variable_" + Conversion::toString(counter++);
359}

References Conversion::toString().

Referenced by CompiledSimCodeGenerator::generateLoadTrigger(), CompiledSimCodeGenerator::generateTriggerCode(), and CompiledSimCodeGenerator::handleOperationWithoutDag().

Here is the call graph for this function:

◆ guardBoolSymbol()

std::string CompiledSimSymbolGenerator::guardBoolSymbol ( ) const

Generates an unique symbol name for a temporary guard variable

Returns
A string containing the generated symbol name

Definition at line 305 of file CompiledSimSymbolGenerator.cc.

305 {
306 static int guardNumber = 0;
307 return "guard_" + Conversion::toString(guardNumber++);
308}

References Conversion::toString().

Referenced by CompiledSimCodeGenerator::generateGuardCondition(), and CompiledSimCodeGenerator::generateGuardRead().

Here is the call graph for this function:

◆ immediateRegisterSymbol() [1/2]

std::string CompiledSimSymbolGenerator::immediateRegisterSymbol ( const TTAMachine::ImmediateUnit iu,
int  index 
) const

Generates an unique symbol name for a IU register

Parameters
iuThe given IU
indexIndex of the immediate register
Returns
A string containing the generated symbol name

Definition at line 191 of file CompiledSimSymbolGenerator.cc.

193 {
194 return prefix_ + "IU_" + DisassemblyRegister::registerName(iu, index, '_');
195 //.name() + "_" + Conversion::toString(index);
196}
static TCEString registerName(const TTAMachine::RegisterFile &rf, int index, char delim='.')

References prefix_, and DisassemblyRegister::registerName().

Here is the call graph for this function:

◆ immediateRegisterSymbol() [2/2]

std::string CompiledSimSymbolGenerator::immediateRegisterSymbol ( const TTAProgram::Terminal terminal) const

Generates an unique symbol name for a IU register of the terminal

Parameters
terminalGiven terminal
Returns
A string containing the generated symbol name

Definition at line 178 of file CompiledSimSymbolGenerator.cc.

179 {
180 return immediateRegisterSymbol(terminal.immediateUnit(), terminal.index());
181}
std::string immediateRegisterSymbol(const TTAProgram::Terminal &terminal) const
virtual int index() const
Definition Terminal.cc:274
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition Terminal.cc:240

References immediateRegisterSymbol(), TTAProgram::Terminal::immediateUnit(), and TTAProgram::Terminal::index().

Referenced by CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateInstruction(), immediateRegisterSymbol(), CompiledSimulation::immediateUnitRegisterValue(), and moveOperandSymbol().

Here is the call graph for this function:

◆ jumpTargetSetterSymbol()

std::string CompiledSimSymbolGenerator::jumpTargetSetterSymbol ( InstructionAddress  address) const

Generates name for jump target setting function

Parameters
addressaddress of the simulate function to be set

Definition at line 367 of file CompiledSimSymbolGenerator.cc.

368 {
369 return "setJumpTargetFor_" + Conversion::toString(address);
370}

References Conversion::toString().

Here is the call graph for this function:

◆ moveOperandSymbol()

std::string CompiledSimSymbolGenerator::moveOperandSymbol ( const TTAProgram::Terminal terminal,
const TTAProgram::Move move 
) const

Generates an unique symbol name for a given move operand (terminal)

Parameters
terminalThe operand terminal
moveThe move
Returns
a string containing the generated symbol name

Definition at line 228 of file CompiledSimSymbolGenerator.cc.

230 {
231
232 if (terminal.isGPR()) {
233 return registerSymbol(terminal);
234 } else if (terminal.isImmediateRegister()) {
235 return immediateRegisterSymbol(terminal);
236 } else if (terminal.isImmediate()) {
237 int value = terminal.value().unsignedValue();
238 const Bus& bus = move.bus();
239 if (bus.signExtends()) {
240 value = MathTools::signExtendTo(value, bus.immediateWidth());
241 }
242 else if (bus.zeroExtends()) {
243 value = MathTools::zeroExtendTo(value, bus.immediateWidth());
244 }
245 return "(int)" + Conversion::toString(value) + "u";
246 } else {
247 return portSymbol(terminal.port());
248 }
249}
std::string registerSymbol(const TTAProgram::Terminal &terminal) const
static SLongWord signExtendTo(SLongWord value, int width)
static ULongWord zeroExtendTo(ULongWord value, int width)
unsigned int unsignedValue() const
Definition SimValue.cc:919
int immediateWidth() const
Definition Bus.cc:160
bool signExtends() const
Definition Bus.cc:171
bool zeroExtends() const
Definition Bus.cc:182
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual SimValue value() const
Definition Terminal.cc:178
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378
virtual bool isImmediate() const
Definition Terminal.cc:63

References TTAProgram::Move::bus(), immediateRegisterSymbol(), TTAMachine::Bus::immediateWidth(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediate(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Terminal::port(), portSymbol(), registerSymbol(), TTAMachine::Bus::signExtends(), MathTools::signExtendTo(), Conversion::toString(), SimValue::unsignedValue(), TTAProgram::Terminal::value(), TTAMachine::Bus::zeroExtends(), and MathTools::zeroExtendTo().

Referenced by CompiledSimMove::copyFromBusCode(), CompiledSimMove::copyToBusCode(), and CompiledSimCodeGenerator::generateInstruction().

Here is the call graph for this function:

◆ operationContextSymbol()

std::string CompiledSimSymbolGenerator::operationContextSymbol ( const TTAMachine::FunctionUnit fu) const

Generates an unique symbol name for a given operation context

Parameters
fuThe given function unit
Returns
a string containing the generated symbol name

Definition at line 258 of file CompiledSimSymbolGenerator.cc.

259 {
260 return prefix_ + "FU_" + fu.name() + "_context";
261}

References TTAMachine::Component::name(), and prefix_.

Referenced by CompiledSimCodeGenerator::generateConstructorCode(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::handleOperation(), and CompiledSimCodeGenerator::handleOperationWithoutDag().

Here is the call graph for this function:

◆ operationSymbol()

std::string CompiledSimSymbolGenerator::operationSymbol ( const std::string &  operationName,
const TTAMachine::FunctionUnit fu 
) const

Generates an unique symbol name for a FU's operation

Parameters
operationNameName of the operation
fuThe function unit containing the operation
Returns
The generated operation symbol string

Definition at line 333 of file CompiledSimSymbolGenerator.cc.

335 {
336 return prefix_ + "op_" + fu.name() + "_" + operationName;
337}

References TTAMachine::Component::name(), and prefix_.

Referenced by CompiledSimCodeGenerator::generateConstructorCode(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), and CompiledSimCodeGenerator::handleOperationWithoutDag().

Here is the call graph for this function:

◆ operator=()

CompiledSimSymbolGenerator & CompiledSimSymbolGenerator::operator= ( const CompiledSimSymbolGenerator )
private

Assignment not allowed.

◆ portSymbol()

std::string CompiledSimSymbolGenerator::portSymbol ( const TTAMachine::Port port) const

Generates an unique symbol name for the given port

Converts a TTA unit's port to a unique symbol name that can be later referred as a SimValue variable in the generated C/C++ code.

Parameters
portA port of the TTA unit
Returns
A string containing the generated symbol name

Definition at line 117 of file CompiledSimSymbolGenerator.cc.

117 {
118 string symbolName;
119 // just speed opt. no need to reserve more at every append.
120 symbolName = prefix_;
121 symbolName.reserve(40);
122 Unit* unit = port.parentUnit();
123 if (dynamic_cast<const FunctionUnit*>(unit) != NULL) {
124 symbolName += "FU_";
125 if (dynamic_cast<const ControlUnit*>(unit) != NULL) {
126 symbolName += "GCU_";
127 }
128 } else if (dynamic_cast<const RegisterFile*>(unit) != NULL) {
129 symbolName += "RF_";
130 if (dynamic_cast<const ImmediateUnit*>(unit) != NULL) {
131 symbolName += "IU_";
132 }
133 } else {
134 symbolName += "unknown_";
135 }
136
137 symbolName += unit->name();
138 symbolName += "_";
139 symbolName += port.name();
140 return symbolName;
141}
Unit * parentUnit() const
virtual std::string name() const
Definition Port.cc:141

References TTAMachine::Component::name(), TTAMachine::Port::name(), TTAMachine::Port::parentUnit(), and prefix_.

Referenced by CompiledSimulation::FUPortValue(), FUResultSymbol(), CompiledSimCodeGenerator::generateAddFUResult(), CompiledSimCodeGenerator::generateFUOutputUpdater(), CompiledSimCodeGenerator::generateGuardCondition(), CompiledSimCodeGenerator::generateGuardRead(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateLoadTrigger(), CompiledSimCodeGenerator::generateStoreTrigger(), CompiledSimCodeGenerator::generateTriggerCode(), CompiledSimCodeGenerator::handleJump(), CompiledSimCodeGenerator::handleOperationWithoutDag(), moveOperandSymbol(), and returnAddressSymbol().

Here is the call graph for this function:

◆ registerSymbol() [1/2]

std::string CompiledSimSymbolGenerator::registerSymbol ( const TTAMachine::RegisterFile rf,
int  index 
) const

Generates an unique symbol name for a RF register

Parameters
rfThe given register file
indexThe index of the register
Returns
A string containing the generated symbol name

Definition at line 163 of file CompiledSimSymbolGenerator.cc.

165 {
166 return prefix_ + "RF_" +
167 DisassemblyRegister::registerName(rf, index, '_');
168}

References prefix_, and DisassemblyRegister::registerName().

Here is the call graph for this function:

◆ registerSymbol() [2/2]

std::string CompiledSimSymbolGenerator::registerSymbol ( const TTAProgram::Terminal terminal) const

Generates an unique symbol name for a RF register of the terminal

Parameters
terminalGiven terminal
Returns
A string containing the generated symbol name

Definition at line 150 of file CompiledSimSymbolGenerator.cc.

151 {
152 return registerSymbol(terminal.registerFile(), terminal.index());
153}
virtual const TTAMachine::RegisterFile & registerFile() const
Definition Terminal.cc:225

References TTAProgram::Terminal::index(), TTAProgram::Terminal::registerFile(), and registerSymbol().

Referenced by CompiledSimCodeGenerator::CompiledSimCodeGenerator(), CompiledSimCodeGenerator::generateGuardCondition(), CompiledSimCodeGenerator::generateGuardRead(), CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateInstruction(), moveOperandSymbol(), CompiledSimulation::registerFileValue(), and registerSymbol().

Here is the call graph for this function:

◆ returnAddressSymbol()

std::string CompiledSimSymbolGenerator::returnAddressSymbol ( const TTAMachine::ControlUnit gcu) const

Generates a symbol name for the GCU's return address

Returns
A symbol name for the GCU's return address

Definition at line 215 of file CompiledSimSymbolGenerator.cc.

216 {
217 return portSymbol(*gcu.returnAddressPort());
218}
SpecialRegisterPort * returnAddressPort() const

References portSymbol(), and TTAMachine::ControlUnit::returnAddressPort().

Referenced by CompiledSimCodeGenerator::handleJump().

Here is the call graph for this function:

◆ targetMemorySymbol()

std::string CompiledSimSymbolGenerator::targetMemorySymbol ( const TTAMachine::FunctionUnit fu) const

Generates an unique symbol name for the given FU's memory space

Parameters
fuNamegiven function unit
Returns
A string containing the generated symbol name

Definition at line 282 of file CompiledSimSymbolGenerator.cc.

283 {
284 return prefix_ + fu.name() + "_target_memory";
285}

References TTAMachine::Component::name(), and prefix_.

Here is the call graph for this function:

◆ timeStamp()

std::string CompiledSimSymbolGenerator::timeStamp ( ) const

Generates a timestamp

Note
Should not be printed to the simulation sources as this makes ccache useless. There's always a cache miss due to the changing timestamp.
Returns
a string containing the timestamp

Definition at line 101 of file CompiledSimSymbolGenerator.cc.

101 {
102 time_t rawTime;
103 time(&rawTime);
104 return string(ctime(&rawTime));
105}

Member Data Documentation

◆ globalSymbolSuffix_

TCEString CompiledSimSymbolGenerator::globalSymbolSuffix_
private

Suffix used for the generated global function symbols.

Definition at line 133 of file CompiledSimSymbolGenerator.hh.

Referenced by basicBlockSymbol().

◆ prefix_

TCEString CompiledSimSymbolGenerator::prefix_
private

The documentation for this class was generated from the following files: