Build a name-to-type map from a module's ports and wires
Equations
- One or more equations did not get rendered due to their size.
Instances For
Look up bit-width for a name in the type map
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert HWType to a C scalar type string. For wide
integers (> 64 bits) and arrays we return a base scalar
type; the surrounding declaration adds the array
dimensions (see emitFieldDecl).
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.Backend.CSim.emitScalarBase Sparkle.IR.Type.HWType.bit = "uint8_t"
- Sparkle.Backend.CSim.emitScalarBase (Sparkle.IR.Type.HWType.array size elemType) = Sparkle.Backend.CSim.emitScalarBase elemType
Instances For
Total array length suffix for a HWType, e.g. [3] for a
96-bit wide type, [8][3] for array 8 (bitVector 96),
or empty for a single ≤ 64-bit scalar.
Emit a C field/local declaration like uint32_t foo[3] —
the type goes on the left, the array dimensions on the
right of the name (C array syntax).
Equations
- Sparkle.Backend.CSim.emitFieldDecl ty name = toString (Sparkle.Backend.CSim.emitScalarBase ty) ++ toString " " ++ toString name ++ toString (Sparkle.Backend.CSim.emitArraySuffix ty)
Instances For
For situations where a parameter or declaration needs just the type and dimensions but no identifier, used by casts.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a bit mask expression for the given width
Equations
- One or more equations did not get rendered due to their size.
Instances For
Wrap an expression with a mask if the width requires it
Equations
- One or more equations did not get rendered due to their size.
Instances For
Check if an IR expression produces a result that is already correctly masked. Invariant: every assignment applies a mask, so .ref reads yield masked values.
Convert Operator to C operator symbol
Equations
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.and = "&"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.or = "|"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.xor = "^"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.not = "~"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.add = "+"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.sub = "-"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.mul = "*"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.eq = "=="
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.lt_u = "<"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.lt_s = "<"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.le_u = "<="
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.le_s = "<="
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.gt_u = ">"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.gt_s = ">"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.ge_u = ">="
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.ge_s = ">="
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.shl = "<<"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.shr = ">>"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.asr = ">>"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.neg = "-"
- Sparkle.Backend.CSim.emitCOperator Sparkle.IR.AST.Operator.mux = "?"
Instances For
Best-effort width inference for an expression
Convert IR expression to C expression.
Wide (> 64 bit) values are represented as uint32_t[N]
arrays in declarations. In expression contexts an "rvalue
array" doesn't really exist in C, so the only ways we
produce wide expressions are:
.refto a wide variable — emits the bare identifier, which C decays to a pointer in most contexts; the wide-assign code below indexes it slot-by-slot rather than copying..constwith width > 64 — emits a C99 compound literal(uint32_t[N]){w0, w1, …}, which is a valid rvalue only at statement scope..concatover wide totals — same compound-literal shape.
All wide assignments (see emitStmt) must therefore
either:
(a) be element-wise slot writes (lhs[j] = …), or
(b) wrap the RHS in memcpy(lhs, RHS, sizeof(lhs))
when RHS is a compound literal — lhs = RHS on a
C array is rejected by the compiler.
Equations
- One or more equations did not get rendered due to their size.
Emit a C reset value for a register init.
For ≤ 64-bit widths returns a scalar cast.
For wide (> 64-bit) widths returns a list of slot
assignments like lhs[0] = 0x…u; lhs[1] = 0x…u; since
C does not let you assign a compound literal to an
array-typed lvalue. The caller (register reset path)
threads these through resetBody.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a MUX chain as if-else block for better branch prediction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Split a statement into declaration/eval/tick/reset parts
Collect all wire name references from an IR expression
Collect all wire names referenced in tick() bodies.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Emit a complete C struct + static helpers for a module. Returns the full C source fragment (no includes; callers add those at design level).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert a full design to C simulation code (no JIT wrapper)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert a single module to C simulation code with includes
Equations
- Sparkle.Backend.CSim.toC m = "#include <stdint.h>\n" ++ "#include <stdlib.h>\n" ++ "#include <string.h>\n\n" ++ Sparkle.Backend.CSim.emitModule m
Instances For
JIT FFI wrapper #
Each .so exports exactly ONE symbol — jit_vtable — which
returns a pointer to a JitVTable containing function
pointers for every operation. Everything else is static,
so dlsym cannot reach it. This sidesteps the collision-on-
shared-symbol problem from Issue #70: two .so files with the
same internal jit_eval cannot conflict because neither
publishes that name.
Generate the self-contained JIT wrapper .c for a Design.
The output is a single translation unit containing:
- Per-module struct + static helpers from
toCDesign. - The
JitVTablestruct definition. - Static trampolines that adapt
void*ctx to the top-module's typedstruct Top*and call the appropriatesparkle_<top>_*helper. - The
JitVTableinstance pre-populated with those trampolines. - The single externally-visible
jit_vtable()accessor function.
The top-level .so therefore exports jit_vtable and
nothing else (other than the unavoidable glibc init/fini
stubs).
Equations
- One or more equations did not get rendered due to their size.