OpenASIP  2.0
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. More...
 
CompiledSimSymbolGeneratoroperator= (const CompiledSimSymbolGenerator &)
 Assignment not allowed. More...
 

Private Attributes

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

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 }

◆ ~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 }

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 }

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 }

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 }

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 }

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

Referenced by CompiledSimCodeGenerator::generateHeaderAndMainCode(), CompiledSimCodeGenerator::generateInstruction(), 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 }

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 }

References TTAMachine::Port::name(), TTAMachine::Component::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 }

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

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

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 }

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:
TTAMachine::Bus::immediateWidth
int immediateWidth() const
Definition: Bus.cc:160
CompiledSimSymbolGenerator::immediateRegisterSymbol
std::string immediateRegisterSymbol(const TTAProgram::Terminal &terminal) const
Definition: CompiledSimSymbolGenerator.cc:178
CompiledSimSymbolGenerator::prefix_
TCEString prefix_
Prefix used for generated variable symbols.
Definition: CompiledSimSymbolGenerator.hh:130
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
TTAMachine::Bus::zeroExtends
bool zeroExtends() const
Definition: Bus.cc:182
TTAProgram::Terminal::registerFile
virtual const TTAMachine::RegisterFile & registerFile() const
Definition: Terminal.cc:225
CompiledSimSymbolGenerator::portSymbol
std::string portSymbol(const TTAMachine::Port &port) const
Definition: CompiledSimSymbolGenerator.cc:117
TTAMachine::Bus
Definition: Bus.hh:53
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
CompiledSimSymbolGenerator::globalSymbolSuffix_
TCEString globalSymbolSuffix_
Suffix used for the generated global function symbols.
Definition: CompiledSimSymbolGenerator.hh:133
Conversion::toString
static std::string toString(const T &source)
TTAMachine::Bus::signExtends
bool signExtends() const
Definition: Bus.cc:171
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
TTAMachine::Unit
Definition: Unit.hh:51
MathTools::zeroExtendTo
static ULongWord zeroExtendTo(ULongWord value, int width)
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
CompiledSimSymbolGenerator::registerSymbol
std::string registerSymbol(const TTAProgram::Terminal &terminal) const
Definition: CompiledSimSymbolGenerator.cc:150
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
TTAProgram::Terminal::value
virtual SimValue value() const
Definition: Terminal.cc:178
TTAProgram::Terminal::immediateUnit
virtual const TTAMachine::ImmediateUnit & immediateUnit() const
Definition: Terminal.cc:240
SimValue::unsignedValue
unsigned int unsignedValue() const
Definition: SimValue.cc:919
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
DisassemblyRegister::registerName
static TCEString registerName(const TTAMachine::RegisterFile &rf, int index, char delim='.')
Definition: DisassemblyRegister.cc:95
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAMachine::ControlUnit::returnAddressPort
SpecialRegisterPort * returnAddressPort() const
Definition: ControlUnit.cc:307
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63
MathTools::signExtendTo
static SLongWord signExtendTo(SLongWord value, int width)
TTAMachine::Port::parentUnit
Unit * parentUnit() const
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50