CIRCT  19.0.0git
signals-runtime-wrappers.cpp
Go to the documentation of this file.
1 //===- signals-runtime-wrappers.cpp - Runtime library implementation ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the runtime library used in LLHD simulation.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 using namespace llvm;
19 using namespace circt::llhd::sim;
20 
21 //===----------------------------------------------------------------------===//
22 // Runtime interface
23 //===----------------------------------------------------------------------===//
24 
25 int allocSignal(State *state, int index, char *owner, uint8_t *value,
26  int64_t size) {
27  assert(state && "alloc_signal: state not found");
28  std::string sOwner(owner);
29 
30  return state->addSignalData(index, sOwner, value, size);
31 }
32 
33 void addSigArrayElements(State *state, unsigned index, unsigned size,
34  unsigned numElements) {
35  for (size_t i = 0; i < numElements; ++i)
36  state->addSignalElement(index, size * i, size);
37 }
38 
39 void addSigStructElement(State *state, unsigned index, unsigned offset,
40  unsigned size) {
41  state->addSignalElement(index, offset, size);
42 }
43 
44 void allocProc(State *state, char *owner, ProcState *procState) {
45  assert(state && "alloc_proc: state not found");
46  std::string sOwner(owner);
47  state->addProcPtr(sOwner, procState);
48 }
49 
50 void allocEntity(State *state, char *owner, uint8_t *entityState) {
51  assert(state && "alloc_entity: state not found");
52  auto it = state->getInstanceIterator(owner);
53  (*it).entityState = entityState;
54 }
55 
56 void driveSignal(State *state, SignalDetail *detail, uint8_t *value,
57  uint64_t width, int time, int delta, int eps) {
58  assert(state && "drive_signal: state not found");
59 
60  auto globalIndex = detail->globalIndex;
61  auto offset = detail->offset;
62 
63  int bitOffset =
64  (detail->value - state->signals[globalIndex].getValue()) * 8 + offset;
65 
66  // Spawn a new event.
67  state->queue.insertOrUpdate(state->time + Time(time, delta, eps), globalIndex,
68  bitOffset, value, width);
69 }
70 
71 void llhdSuspend(State *state, ProcState *procState, int time, int delta,
72  int eps) {
73  // Add a new scheduled wake up if a time is specified.
74  if (time || delta || eps) {
75  Time sTime(time, delta, eps);
76  state->pushQueue(sTime, procState->inst);
77  }
78 }
assert(baseType &&"element must be base type")
MlirType uint64_t numElements
Definition: CHIRRTL.cpp:30
int32_t width
Definition: FIRRTL.cpp:36
The simulator's internal representation of time.
Definition: State.h:30
void insertOrUpdate(Time time, int index, int bitOffset, uint8_t *bytes, unsigned width)
Check wheter a slot for the given time already exists.
Definition: State.cpp:102
void addSigArrayElements(State *state, unsigned index, unsigned size, unsigned numElements)
Add offset and size information for the elements of an array signal.
void llhdSuspend(State *state, ProcState *procState, int time, int delta, int eps)
Suspend a process.
void driveSignal(State *state, SignalDetail *detail, uint8_t *value, uint64_t width, int time, int delta, int eps)
Drive a value onto a signal.
void addSigStructElement(State *state, unsigned index, unsigned offset, unsigned size)
Add offset and size information for one element of a struct signal.
void allocEntity(State *state, char *owner, uint8_t *entityState)
Add allocated entity state to the given instance.
int allocSignal(State *state, int index, char *owner, uint8_t *value, int64_t size)
Allocate a new signal.
void allocProc(State *state, char *owner, ProcState *procState)
Add allocated constructs to a process instance.
State structure for process persistence across suspension.
Definition: State.h:269
Detail structure that can be easily accessed by the lowered code.
Definition: State.h:68
The simulator's state.
Definition: State.h:306
void pushQueue(Time time, unsigned inst)
Push a new scheduled wakeup event in the event queue.
Definition: State.cpp:224
llvm::SmallVector< Signal, 0 > signals
Definition: State.h:349
void addProcPtr(std::string name, ProcState *procStatePtr)
Add a pointer to the process persistence state to a process instance.
Definition: State.cpp:246
llvm::SmallVectorTemplateCommon< Instance >::iterator getInstanceIterator(std::string instName)
Find an instance in the instances list by name and return an iterator for it.
Definition: State.cpp:231
int addSignalData(int index, std::string owner, uint8_t *value, uint64_t size)
Definition: State.cpp:254
UpdateQueue queue
Definition: State.h:350
void addSignalElement(unsigned, unsigned, unsigned)
Definition: State.cpp:276