14 #ifndef CIRCT_DIALECT_LLHD_SIMULATOR_STATE_H
15 #define CIRCT_DIALECT_LLHD_SIMULATOR_STATE_H
17 #include "llvm/ADT/APInt.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
112 return std::regex_match(
name, std::regex(
"(sig)?[0-9]*"));
136 void store(uint8_t *v, uint64_t s) {
150 const uint8_t *newVal =
reinterpret_cast<const uint8_t *
>(v);
151 if (*
value == *newVal)
157 const uint16_t *newVal =
reinterpret_cast<const uint16_t *
>(v);
158 if (*(uint16_t *)
value == *newVal)
160 *(uint16_t *)
value = *newVal;
164 const uint32_t *newVal =
reinterpret_cast<const uint32_t *
>(v);
165 if (*(uint32_t *)
value == *newVal)
167 *(uint32_t *)
value = *newVal;
171 if (*(uint64_t *)
value == *v)
173 *(uint64_t *)
value = *v;
201 std::vector<std::pair<unsigned, unsigned>>
elements;
223 llvm::SmallVector<std::pair<unsigned, unsigned>, 32>
changes;
225 llvm::SmallVector<std::pair<unsigned, llvm::APInt>, 32>
buffers;
322 llvm::SmallVectorTemplateCommon<Instance>::iterator
326 int addSignal(std::string name, std::string owner);
328 int addSignalData(
int index, std::string owner, uint8_t *value,
338 void dumpSignal(llvm::raw_ostream &out,
int index);
The simulator's internal representation of a signal.
Signal(std::string name, std::string owner, uint8_t *value, uint64_t size)
Construct a signal with the given name, owner and initial value.
void store(uint8_t *v, uint64_t s)
Store JIT allocated signal pointer and size.
bool isValidSigName() const
void pushInstanceIndex(unsigned i)
Signal(Signal &&)=default
Default move constructor.
std::vector< unsigned > instanceIndices
bool operator==(const Signal &rhs) const
Returns true if the signals match in name, owner, size and value.
std::string getOwner() const
Signal(std::string name, std::string owner)
Construct an "empty" signal.
std::vector< std::pair< unsigned, unsigned > > elements
void pushElement(std::pair< unsigned, unsigned > val)
size_t getElementSize() const
uint8_t * getValue() const
std::string getName() const
bool isOwner(const std::string &rhs) const
bool updateWhenChanged(const uint64_t *v)
Update signal value when it is changed, the width of incoming signal value and the stored signal valu...
~Signal()
Free 'value' since it is allocated using 'malloc' in the LLVM code generated by LLHDToLLVM.
const std::vector< unsigned > & getTriggeredInstanceIndices() const
bool operator<(const Signal &rhs) const
Returns true if the owner name is lexically smaller than rhs's owner, or the name is lexically smalle...
std::string toHexString() const
Return the value of the signal in hexadecimal string format.
The simulator's internal representation of time.
Time operator+(const Time &rhs) const
Add two time values.
bool operator==(const Time &rhs) const
Return true if all the time values are equal.
Time()=default
Empty (zero) time constructor. All the time values are defaulted to 0.
std::string toString() const
Get the stored time in a printable format.
bool operator<(const Time &rhs) const
Compare the time values in order of time, delta, eps.
uint64_t time
Simulation real time.
Time(uint64_t time, uint64_t delta, uint64_t eps)
Construct with given time values.
This is equivalent to and std::priorityQueue<Slot> ordered using the greater operator,...
const Slot & top()
Get a reference to the current top of the queue (the earliest event available).
llvm::SmallVector< unsigned, 4 > unused
void insertOrUpdate(Time time, int index, int bitOffset, uint8_t *bytes, unsigned width)
Check wheter a slot for the given time already exists.
void pop()
Pop the current top of the queue.
Slot & getOrCreateSlot(Time time)
Return a reference to a slot with the given timestamp.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
The simulator internal representation of an instance.
~Instance()
Free procState and entityState since they are allocated using 'malloc' in the LLVM code generated in ...
Instance(std::string name)
void(* unitFPtr)(void **)
llvm::SmallVector< SignalDetail, 0 > sensitivityList
State structure for process persistence across suspension.
Detail structure that can be easily accessed by the lowered code.
The simulator's internal representation of one queue slot.
void insertChange(int index, int bitOffset, uint8_t *bytes, unsigned width)
Insert a change.
bool operator>(const Slot &rhs) const
Returns true if the slot's time is greater than the compared slot's time.
llvm::SmallVector< std::pair< unsigned, unsigned >, 32 > changes
llvm::SmallVector< unsigned, 4 > scheduled
Slot(Time time)
Create a new empty slot.
bool operator<(const Slot &rhs) const
Returns true if the slot's time is smaller than the compared slot's time.
llvm::SmallVector< std::pair< unsigned, llvm::APInt >, 32 > buffers
llvm::SmallVector< Instance, 0 > instances
void pushQueue(Time time, unsigned inst)
Push a new scheduled wakeup event in the event queue.
llvm::SmallVector< Signal, 0 > signals
void dumpSignal(llvm::raw_ostream &out, int index)
Dump a signal to the out stream.
State()=default
Construct a new empty (at 0 time) state.
void dumpLayout()
Dump the instance layout. Used for testing purposes.
Slot popQueue()
Pop the head of the queue and update the simulation time.
void addProcPtr(std::string name, ProcState *procStatePtr)
Add a pointer to the process persistence state to a process instance.
llvm::SmallVectorTemplateCommon< Instance >::iterator getInstanceIterator(std::string instName)
Find an instance in the instances list by name and return an iterator for it.
int addSignalData(int index, std::string owner, uint8_t *value, uint64_t size)
void dumpSignalTriggers()
Dump the instances each signal triggers. Used for testing purposes.
int addSignal(std::string name, std::string owner)
Add a new signal to the state. Returns the index of the new signal.
~State()
State destructor, ensures all malloc'd regions stored in the state are correctly free'd.
void addSignalElement(unsigned, unsigned, unsigned)