Merge pull request #2436 from dalance/fix_generate
[yosys.git] / backends / cxxrtl / cxxrtl_capi.h
index 385d6dcf386080c80a878ac34a9979807984bb8d..2df2b7287f44719b5377b208fa243a6df882cfa1 100644 (file)
@@ -52,9 +52,23 @@ typedef struct _cxxrtl_handle *cxxrtl_handle;
 // The `design` is consumed by this operation and cannot be used afterwards.
 cxxrtl_handle cxxrtl_create(cxxrtl_toplevel design);
 
+// Create a design handle at a given hierarchy position from a design toplevel.
+//
+// This operation is similar to `cxxrtl_create`, except the full hierarchical name of every object
+// is prepended with `root`.
+cxxrtl_handle cxxrtl_create_at(cxxrtl_toplevel design, const char *root);
+
 // Release all resources used by a design and its handle.
 void cxxrtl_destroy(cxxrtl_handle handle);
 
+// Reinitialize the design, replacing the internal state with the reset values while preserving
+// black boxes.
+//
+// This operation is essentially equivalent to a power-on reset. Values, wires, and memories are
+// returned to their reset state while preserving the state of black boxes and keeping all of
+// the interior pointers obtained with e.g. `cxxrtl_get` valid.
+void cxxrtl_reset(cxxrtl_handle handle);
+
 // Evaluate the design, propagating changes on inputs to the `next` value of internal state and
 // output wires.
 //
@@ -114,6 +128,18 @@ enum cxxrtl_type {
        // pointer is always NULL.
        CXXRTL_ALIAS = 3,
 
+       // Outlines correspond to netlist nodes that were optimized in a way that makes them inaccessible
+       // outside of a module's `eval()` function. At the highest debug information level, every inlined
+       // node has a corresponding outline object.
+       //
+       // Outlines can be inspected via the `curr` pointer and can never be modified; the `next` pointer
+       // is always NULL. Unlike all other objects, the bits of an outline object are meaningful only
+       // after a call to `cxxrtl_outline_eval` and until any subsequent modification to the netlist.
+       // Observing this requirement is the responsibility of the caller; it is not enforced.
+       //
+       // Outlines always correspond to combinatorial netlist nodes that are not ports.
+       CXXRTL_OUTLINE = 4,
+
        // More object types may be added in the future, but the existing ones will never change.
 };
 
@@ -157,8 +183,8 @@ enum cxxrtl_flag {
 
        // Node has bits that are driven by a combinatorial cell or another node.
        //
-       // This flag can be set on objects of type `CXXRTL_VALUE` and `CXXRTL_WIRE`. It may be combined
-       // with `CXXRTL_DRIVEN_SYNC` and `CXXRTL_UNDRIVEN`, as well as other flags.
+       // This flag can be set on objects of type `CXXRTL_VALUE`, `CXXRTL_WIRE`, and `CXXRTL_OUTLINE`.
+       // It may be combined with `CXXRTL_DRIVEN_SYNC` and `CXXRTL_UNDRIVEN`, as well as other flags.
        //
        // This flag is set on objects that have bits connected to the output of a combinatorial cell,
        // or directly to another node. For designs without combinatorial loops, writing to such bits
@@ -179,8 +205,8 @@ enum cxxrtl_flag {
 
 // Description of a simulated object.
 //
-// The `data` array can be accessed directly to inspect and, if applicable, modify the bits
-// stored in the object.
+// The `curr` and `next` arrays can be accessed directly to inspect and, if applicable, modify
+// the bits stored in the object.
 struct cxxrtl_object {
        // Type of the object.
        //
@@ -217,6 +243,12 @@ struct cxxrtl_object {
        uint32_t *curr;
        uint32_t *next;
 
+       // Opaque reference to an outline. Only meaningful for outline objects.
+       //
+       // See the documentation of `cxxrtl_outline` for details. When creating a `cxxrtl_object`, set
+       // this field to NULL.
+       struct _cxxrtl_outline *outline;
+
        // More description fields may be added in the future, but the existing ones will never change.
 };
 
@@ -240,7 +272,7 @@ struct cxxrtl_object *cxxrtl_get_parts(cxxrtl_handle handle, const char *name, s
 // This function is a shortcut for the most common use of `cxxrtl_get_parts`. It asserts that,
 // if the object exists, it consists of a single part. If assertions are disabled, it returns NULL
 // for multi-part objects.
-inline struct cxxrtl_object *cxxrtl_get(cxxrtl_handle handle, const char *name) {
+static inline struct cxxrtl_object *cxxrtl_get(cxxrtl_handle handle, const char *name) {
        size_t parts = 0;
        struct cxxrtl_object *object = cxxrtl_get_parts(handle, name, &parts);
        assert(object == NULL || parts == 1);
@@ -258,6 +290,20 @@ void cxxrtl_enum(cxxrtl_handle handle, void *data,
                  void (*callback)(void *data, const char *name,
                                   struct cxxrtl_object *object, size_t parts));
 
+// Opaque reference to an outline.
+//
+// An outline is a group of outline objects that are evaluated simultaneously. The identity of
+// an outline can be compared to determine whether any two objects belong to the same outline.
+typedef struct _cxxrtl_outline *cxxrtl_outline;
+
+// Evaluate an outline.
+//
+// After evaluating an outline, the bits of every outline object contained in it are consistent
+// with the current state of the netlist. In general, any further modification to the netlist
+// causes every outline object to become stale, after which the corresponding outline must be
+// re-evaluated, otherwise the bits read from that object are meaningless.
+void cxxrtl_outline_eval(cxxrtl_outline outline);
+
 #ifdef __cplusplus
 }
 #endif