From 5beab5bc17f9fa1f2340b491e073cfb973ad2e2b Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 2 Dec 2020 08:25:27 +0000 Subject: cxxrtl: provide a way to perform unobtrusive power-on reset. Although it is always possible to destroy and recreate the design to simulate a power-on reset, this has two drawbacks: * Black boxes are also destroyed and recreated, which causes them to reacquire their resources, which might be costly and/or erase important state. * Pointers into the design are invalidated and have to be acquired again, which is costly and might be very inconvenient if they are captured elsewhere (especially through the C API). --- backends/cxxrtl/cxxrtl.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'backends/cxxrtl/cxxrtl.h') diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index 41089a153..4528a7d8f 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -96,9 +96,11 @@ struct value : public expr_base> { explicit constexpr value(Init ...init) : data{init...} {} value(const value &) = default; - value(value &&) = default; value &operator=(const value &) = default; + value(value &&) = default; + value &operator=(value &&) = default; + // A (no-op) helper that forces the cast to value<>. CXXRTL_ALWAYS_INLINE const value &val() const { @@ -647,10 +649,16 @@ struct wire { template explicit constexpr wire(Init ...init) : curr{init...}, next{init...} {} + // Copying and copy-assigning values is natural. If, however, a value is replaced with a wire, + // e.g. because a module is built with a different optimization level, then existing code could + // unintentionally copy a wire instead, which would create a subtle but serious bug. To make sure + // this doesn't happen, prohibit copying and copy-assigning wires. wire(const wire &) = delete; - wire(wire &&) = default; wire &operator=(const wire &) = delete; + wire(wire &&) = default; + wire &operator=(wire &&) = default; + template CXXRTL_ALWAYS_INLINE IntegerT get() const { @@ -692,6 +700,9 @@ struct memory { memory(const memory &) = delete; memory &operator=(const memory &) = delete; + memory(memory &&) = default; + memory &operator=(memory &&) = default; + // The only way to get the compiler to put the initializer in .rodata and do not copy it on stack is to stuff it // into a plain array. You'd think an std::initializer_list would work here, but it doesn't, because you can't // construct an initializer_list in a constexpr (or something) and so if you try to do that the whole thing is @@ -815,7 +826,7 @@ struct metadata { typedef std::map metadata_map; -// Helper class to disambiguate values/wires and their aliases. +// Tag class to disambiguate values/wires and their aliases. struct debug_alias {}; // This structure is intended for consumption via foreign function interfaces, like Python's ctypes. @@ -965,13 +976,25 @@ struct debug_items { } }; +// Tag class to disambiguate module move constructor and module constructor that takes black boxes +// out of another instance of the module. +struct adopt {}; + struct module { module() {} virtual ~module() {} + // Modules with black boxes cannot be copied. Although not all designs include black boxes, + // delete the copy constructor and copy assignment operator to make sure that any downstream + // code that manipulates modules doesn't accidentally depend on their availability. module(const module &) = delete; module &operator=(const module &) = delete; + module(module &&) = default; + module &operator=(module &&) = default; + + virtual void reset() = 0; + virtual bool eval() = 0; virtual bool commit() = 0; -- cgit v1.2.3