Skip to content

Commit

Permalink
Allow Assignable and non-assignable events to co-exist, format
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Boronski <[email protected]>
  • Loading branch information
kboronski-ant committed Oct 18, 2023
1 parent fac02e2 commit 4518d7e
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 44 deletions.
2 changes: 1 addition & 1 deletion include/verilated_fst_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void VerilatedFst::configure(const VerilatedTraceConfig& config) {
// so always inline them.

VL_ATTR_ALWINLINE
void VerilatedFstBuffer::emitEvent(uint32_t code, VlEventHandle newval) {
void VerilatedFstBuffer::emitEvent(uint32_t code, const VlEventBase* newval) {
VL_DEBUG_IFDEF(assert(m_symbolp[code]););
fstWriterEmitValueChange(m_fst, m_symbolp[code], "1");
}
Expand Down
2 changes: 1 addition & 1 deletion include/verilated_fst_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class VerilatedFstBuffer VL_NOT_FINAL {

// Implementations of duck-typed methods for VerilatedTraceBuffer. These are
// called from only one place (the full* methods), so always inline them.
VL_ATTR_ALWINLINE void emitEvent(uint32_t code, VlEventHandle newval);
VL_ATTR_ALWINLINE void emitEvent(uint32_t code, const VlEventBase* newval);
VL_ATTR_ALWINLINE void emitBit(uint32_t code, CData newval);
VL_ATTR_ALWINLINE void emitCData(uint32_t code, CData newval, int bits);
VL_ATTR_ALWINLINE void emitSData(uint32_t code, SData newval, int bits);
Expand Down
6 changes: 3 additions & 3 deletions include/verilated_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class VerilatedTraceBuffer VL_NOT_FINAL : public T_Buffer {
void fullQData(uint32_t* oldp, QData newval, int bits);
void fullWData(uint32_t* oldp, const WData* newvalp, int bits);
void fullDouble(uint32_t* oldp, double newval);
void fullEvent(uint32_t* oldp, VlEventHandle newval);
void fullEvent(uint32_t* oldp, const VlEventBase* newval);

// In non-offload mode, these are called directly by the trace callbacks,
// and are called chg*. In offload mode, they are called by the worker
Expand Down Expand Up @@ -460,7 +460,7 @@ class VerilatedTraceBuffer VL_NOT_FINAL : public T_Buffer {
}
}
}
VL_ATTR_ALWINLINE void chgEvent(uint32_t* oldp, VlEventHandle newval) {
VL_ATTR_ALWINLINE void chgEvent(uint32_t* oldp, const VlEventBase* newval) {
fullEvent(oldp, newval);
}
VL_ATTR_ALWINLINE void chgDouble(uint32_t* oldp, double newval) {
Expand Down Expand Up @@ -541,7 +541,7 @@ class VerilatedTraceOffloadBuffer final : public VerilatedTraceBuffer<T_Buffer>
m_offloadBufferWritep += 4;
VL_DEBUG_IF(assert(m_offloadBufferWritep <= m_offloadBufferEndp););
}
void chgEvent(uint32_t code, VlEventHandle newval) {
void chgEvent(uint32_t code, const VlEventBase* newval) {
m_offloadBufferWritep[0] = VerilatedTraceOffloadCommand::CHG_EVENT;
m_offloadBufferWritep[1] = code;
m_offloadBufferWritep += 2;
Expand Down
4 changes: 2 additions & 2 deletions include/verilated_trace_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void VerilatedTrace<VL_SUB_T, VL_BUF_T>::offloadWorkerThreadMain() {
continue;
case VerilatedTraceOffloadCommand::CHG_EVENT:
VL_TRACE_OFFLOAD_DEBUG("Command CHG_EVENT " << top);
traceBufp->chgEvent(oldp, *reinterpret_cast<const VlEventHandle*>(readp));
traceBufp->chgEvent(oldp, reinterpret_cast<const VlEventBase*>(readp));
continue;

//===
Expand Down Expand Up @@ -839,7 +839,7 @@ void VerilatedTraceBuffer<VL_BUF_T>::fullBit(uint32_t* oldp, CData newval) {
}

template <>
void VerilatedTraceBuffer<VL_BUF_T>::fullEvent(uint32_t* oldp, VlEventHandle newval) {
void VerilatedTraceBuffer<VL_BUF_T>::fullEvent(uint32_t* oldp, const VlEventBase* newval) {
const uint32_t code = oldp - m_sigs_oldvalp;
*oldp = 1; // Do we really store an "event" ?
emitEvent(code, newval);
Expand Down
70 changes: 43 additions & 27 deletions include/verilated_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,52 +163,68 @@ class VlTriggerVec final {
//===================================================================
// SystemVerilog event type

class VlEvent final {
class VlEventBase VL_NOT_FINAL {
public:
virtual ~VlEventBase() = default;

virtual void fire() = 0;
virtual bool isFired() const = 0;
virtual bool isTriggered() const = 0;
virtual void clearFired() = 0;
virtual void clearTriggered() = 0;
};

class VlEvent final : public VlEventBase {
// MEMBERS
bool m_fired = false; // Fired on this scheduling iteration
bool m_triggered = false; // Triggered state of event persisting until next time step

public:
// CONSTRUCTOR
VlEvent() = default;
~VlEvent() = default;
~VlEvent() override = default;

friend std::string VL_TO_STRING(const VlEvent& e);
#ifdef VL_EVENT_ASSIGN
friend class VlEventHandle;
#else
friend class VlAssignableEvent;
// METHODS
void fire() { m_fired = m_triggered = true; }
bool isFired() const { return m_fired; }
bool isTriggered() const { return m_triggered; }
void clearFired() { m_fired = false; }
void clearTriggered() { m_triggered = false; }
#endif
void fire() override { m_fired = m_triggered = true; }
bool isFired() const override { return m_fired; }
bool isTriggered() const override { return m_triggered; }
void clearFired() override { m_fired = false; }
void clearTriggered() override { m_triggered = false; }
};

inline std::string VL_TO_STRING(const VlEvent& e) {
return std::string{"triggered="} + (e.m_triggered ? "true" : "false");
}

#ifdef VL_EVENT_ASSIGN
class VlEventHandle final : public std::shared_ptr<VlEvent> {
class VlAssignableEvent final : public std::shared_ptr<VlEvent>, public VlEventBase {
public:
// Constructor
VlEventHandle()
VlAssignableEvent()
: std::shared_ptr<VlEvent>(new VlEvent) {}
~VlAssignableEvent() override = default;

// METHODS
void fire() { (*this)->m_fired = (*this)->m_triggered = true; }
bool isFired() const { return (*this)->m_fired; }
bool isTriggered() const { return (*this)->m_triggered; }
void clearFired() { (*this)->m_fired = false; }
void clearTriggered() { (*this)->m_triggered = false; }
void fire() override { (*this)->m_fired = (*this)->m_triggered = true; }
bool isFired() const override { return (*this)->m_fired; }
bool isTriggered() const override { return (*this)->m_triggered; }
void clearFired() override { (*this)->m_fired = false; }
void clearTriggered() override { (*this)->m_triggered = false; }
};

inline std::string VL_TO_STRING(const VlEventHandle& e) { return "&{ " + VL_TO_STRING(*e) + " }"; }
#else
using VlEventHandle = VlEvent;
#endif
inline std::string VL_TO_STRING(const VlEventBase& e);

inline std::string VL_TO_STRING(const VlEvent& e) {
return std::string{"triggered="} + (e.isTriggered() ? "true" : "false");
}

inline std::string VL_TO_STRING(const VlAssignableEvent& e) {
return "&{ " + VL_TO_STRING(*e) + " }";
}

inline std::string VL_TO_STRING(const VlEventBase& e) {
if (const VlAssignableEvent& assignable = dynamic_cast<const VlAssignableEvent&>(e)) {
return VL_TO_STRING(assignable);
}
return std::string{"triggered="} + (e.isTriggered() ? "true" : "false");
}

//===================================================================
// Random
Expand Down
4 changes: 2 additions & 2 deletions include/verilated_vcd_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ void VerilatedVcdBuffer::finishLine(uint32_t code, char* writep) {
// so always inline them.

VL_ATTR_ALWINLINE
void VerilatedVcdBuffer::emitEvent(uint32_t code, VlEventHandle newval) {
const bool triggered = newval.isTriggered();
void VerilatedVcdBuffer::emitEvent(uint32_t code, const VlEventBase* newval) {
const bool triggered = newval->isTriggered();
// TODO : It seems that untriggered events are not filtered
// should be tested before this last step
if (triggered) {
Expand Down
2 changes: 1 addition & 1 deletion include/verilated_vcd_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class VerilatedVcdBuffer VL_NOT_FINAL {
// Implementation of VerilatedTraceBuffer interface
// Implementations of duck-typed methods for VerilatedTraceBuffer. These are
// called from only one place (the full* methods), so always inline them.
VL_ATTR_ALWINLINE void emitEvent(uint32_t code, VlEventHandle newval);
VL_ATTR_ALWINLINE void emitEvent(uint32_t code, const VlEventBase* newval);
VL_ATTR_ALWINLINE void emitBit(uint32_t code, CData newval);
VL_ATTR_ALWINLINE void emitCData(uint32_t code, CData newval, int bits);
VL_ATTR_ALWINLINE void emitSData(uint32_t code, SData newval, int bits);
Expand Down
2 changes: 1 addition & 1 deletion src/V3Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class VEdgeType final {
ET_BOTHEDGE, // POSEDGE | NEGEDGE (i.e.: 'edge' in Verilog)
ET_POSEDGE,
ET_NEGEDGE,
ET_EVENT, // VlEvent::isFired
ET_EVENT, // VlEventBase::isFired
// Involving an expression
ET_TRUE,
//
Expand Down
2 changes: 1 addition & 1 deletion src/V3AstNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ AstNodeDType::CTypeRecursed AstNodeDType::cTypeRecurse(bool compound) const {
} else if (bdtypep->isProcessRef()) {
info.m_type = "VlProcessRef";
} else if (bdtypep->isEvent()) {
info.m_type = "VlEventHandle";
info.m_type = v3Global.assignsEvents() ? "VlAssignableEvent" : "VlEvent";
} else if (dtypep->widthMin() <= 8) { // Handle unpacked arrays; not bdtypep->width
info.m_type = "CData" + bitvec;
} else if (dtypep->widthMin() <= 16) {
Expand Down
3 changes: 3 additions & 0 deletions src/V3EmitCImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,9 @@ class EmitCTrace final : EmitCFunc {
void emitTraceValue(AstTraceInc* nodep, int arrayindex) {
if (AstVarRef* const varrefp = VN_CAST(nodep->valuep(), VarRef)) {
AstVar* const varp = varrefp->varp();
if (varp->isEvent()) {
puts("&");
}
puts("(");
if (emitTraceIsScBigUint(nodep)) {
puts("(uint32_t*)");
Expand Down
10 changes: 7 additions & 3 deletions src/V3EmitCSyms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ void EmitCSyms::emitSymHdr() {
}
if (v3Global.hasEvents()) {
if (v3Global.assignsEvents()) {
puts("std::vector<VlEventHandle> __Vm_triggeredEvents;\n");
puts("std::vector<VlAssignableEvent> __Vm_triggeredEvents;\n");
} else {
puts("std::vector<VlEventHandle*> __Vm_triggeredEvents;\n");
puts("std::vector<VlEvent*> __Vm_triggeredEvents;\n");
}
}
if (v3Global.hasClasses()) puts("VlDeleter __Vm_deleter;\n");
Expand Down Expand Up @@ -538,7 +538,11 @@ void EmitCSyms::emitSymHdr() {
puts("const char* name() { return TOP.name(); }\n");

if (v3Global.hasEvents()) {
puts("void enqueueTriggeredEventForClearing(VlEventHandle& event) {\n");
if (v3Global.assignsEvents()) {
puts("void enqueueTriggeredEventForClearing(VlAssignableEvent& event) {\n");
} else {
puts("void enqueueTriggeredEventForClearing(VlEvent& event) {\n");
}
puts("#ifdef VL_DEBUG\n");
puts("if (VL_UNLIKELY(!event.isTriggered())) {\n");
puts("VL_FATAL_MT(__FILE__, __LINE__, __FILE__, \"event passed to "
Expand Down
4 changes: 2 additions & 2 deletions src/V3Width.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4320,8 +4320,8 @@ class WidthVisitor final : public VNVisitor {
<< asgnp->warnMore()
<< "Static event "
"scheduling won't be able to handle this.\n"
<< asgnp->warnMore() <<
"... Suggest move the event into a "
<< asgnp->warnMore()
<< "... Suggest move the event into a "
"completely dynamic context, eg. a class, and "
"reference it only from such context.");
}
Expand Down

0 comments on commit 4518d7e

Please sign in to comment.