Interactive reference for the S3 flow processor assembler. A classical three-stage compiler—parser, semantic analyzer, code generator—targeting the S3 DPU's instruction set across 8 hardware flavours.
| Construct | Syntax | Purpose |
|---|---|---|
import | import "file.flash" | Transitive module inclusion (deduplicated) |
const | const X = 8'd42 | Named immediate with explicit bit width |
var | var foo = meta[7:0] | Named memory-mapped variable |
struct | struct S { f: 8; } | Bit-precise structure (no implicit padding) |
union | union U { a: 8; b: 16; } | Overlapping fields at same offset |
enum | enum E { A, B=3 } | Named constants with auto-increment |
cond | cond c = f & 0xF == 0x1 | 4-bit condition for conditional execution |
handler | handler H { mov … } | Block of grouped instructions |
flow | flow { mask … match … action H } | Packet classification → handler mapping |
target | target S3 | Hardware target declaration |
flavour | flavour PTA_ACTION | Hardware sub-configuration |
8'd42 — 8-bit decimal16'hFFFF — 16-bit hex4'b1010 — 4-bit binary0xFF — auto-sized hex0xFF_FFThree addressing modes: range meta[7:0], base+count cs[0,16], typed meta @ 0 : MyStruct.
| Struct | Fields | Role |
|---|---|---|
Workspace | units, known_paths, report | Root container — all parsed files |
CompilationUnit | path, rep_path, program, report | Single parsed file |
WorkItem | canonical_path, rep_path | BFS queue entry |
import declarationsHandles diamond imports correctly — if A→B and A→C both import D, file D is parsed only once.
Keywords
Operators & Punctuation
Values
} on error| Field | Type | Purpose |
|---|---|---|
scanner | Scanner | Token source |
ignore_newlines | bool | Off in structs, on in handlers |
buffered_token | Option<Token> | Single-token lookahead |
report | Vec<ReportItem> | Parse errors and warnings |
| Function | Grammar |
|---|---|
parse_program() | program_item* |
parse_handler_def() | handler IDENT { handler_item* } |
parse_instruction() | OPCODE operand* (if condition)? |
parse_struct_def() | struct IDENT? { member* } |
parse_cond_expr() | base & mask == value |
parse_immediate() | size'radix_digits |
parse_flow_decl() | flow { mask M match V action A } |
parse_enum_def() | enum IDENT { variant* } |
recover_to_next_program_item() — skip to next keywordrecover_past_current_instruction() — skip to newline or braceSpan for precise error messages. Supports 11 top-level declaration types.| Variant | Struct | Description |
|---|---|---|
ConstDef | name, value | Named constant with explicit bit width |
EnumDef | name, variants[] | Enum with auto-incrementing values |
CondDef | name, value | Symbolic condition expression |
ObjectDef | name, value | Memory-mapped variable |
StructDef | name?, members[] | Named or anonymous struct |
UnionDef | name?, members[] | Named or anonymous union |
HandlerDef | name, items[] | Instruction handler block |
FlowDecl | mask, match, action | Packet classification rule |
ImportDecl | path | File import |
TargetDecl | kind | Hardware target (S3) |
FlavourDecl | flavour | Hardware sub-configuration |
Instruction = opcode + operands (Op::Addr, Op::Ref, Op::Imm) + optional condition. Handler items include GroupBreak (--) and Next boundaries.
| Field | Type | Purpose |
|---|---|---|
constants | HashMap<String, Definition<Imm>> | Named constants & enum values |
layouts | HashMap<String, ObjectLayout> | Struct/union memory layouts |
objects | HashMap<String, Definition<Object>> | Memory-mapped variables |
conditions | HashMap<String, Definition<Condition>> | Symbolic conditions |
handlers | HashMap<String, Definition<Handler>> | Compiled handlers with groups |
flows | Vec<Flow> | Packet classification rules |
target | &'static Target | Hardware configuration |
flavour | Option<FlavourDecl> | Selected hardware flavour |
| # | Stage | Action |
|---|---|---|
| 1 | process_constant_definitions | Evaluate const declarations, check duplicates |
| 2 | process_enum_definitions | Expand enums to qualified constants (E::V) |
| 3 | process_type_definitions | Compute recursive struct/union layouts, detect cycles |
| 4 | process_object_definitions | Create objects with layout, check memory overlap |
| 5 | process_condition_definitions | Validate: 4-bit aligned, 4-bit wide, meta-only |
| 6 | process_handlers | Validate instructions, resolve operands, group & schedule |
| 7 | process_flows | Validate handler refs, resolve mask/match values |
Every model artifact is wrapped in Definition<T> adding name, source_file, and span for precise error messages.
| Mode | Trigger | Mechanism |
|---|---|---|
| Manual | -- separators in source | User places group boundaries explicitly |
| Automatic | No separators | Compiler builds dependency graph and schedules |
Nodes = instructions. Edges = RAW (Read-After-Write) data dependencies detected by checking if source operands overlap destinations via bit-range intersection.
| Type | Selector | Align | Purpose |
|---|---|---|---|
| Message | msg | 8-bit | Input packet buffer |
| CS | cs | 8-bit | Context store |
| Meta | meta | 4-bit | HW + SW metadata |
| Output | out | 4-bit | Output vector |
| Struct | Purpose |
|---|---|
Chunk | Contiguous bit range: mem_type + low_bit + high_bit |
Memory | Full descriptor: type + bit_size + access_align |
IntervalMap<T> | Sorted intervals with binary-search overlap detection |
ObjectLayout | Recursive struct layout with drill-down into nested fields |
| Variant | Content | Example |
|---|---|---|
Arg::Addr(Chunk) | Memory range | meta[7:0] |
Arg::Imm(Imm) | Sized immediate | 8'd42 |
Condition { base: Chunk, mask: u8, match_value: u8 } — 4-bit condition from meta memory for conditional execution.
encode(handler) — iterate instruction groupsencode_instr_group() — write 2B descriptor + instruction bytesalu_instruction_encoding() → 14-byte encodingload/store_instruction_encoding() → 10-byte encodingcondition_encoding() → 14-bit conditionprocess_flows() → TCAM entrieswrite_combined_json() → JSON output with metadataComposer::paste(bits, count, low_bit) — places arbitrary bit-width fields at arbitrary offsets into a byte array, handling cross-byte alignment. The core primitive for all encoding.
| Code | Type |
|---|---|
0b0000 | Message |
0b0001 | Context Store |
0b0010 | Metadata |
0b0100 | Immediate |
0b0111 | Output |
0b1000 | Sequence (extended immediate) |
Packs to 45-byte (353-bit) register: valid[352] | mask[351:184] | match[183:16] | num_groups[15:8] | mem_addr[7:0].
| Constant | Value | Meaning |
|---|---|---|
INSTR_TYPE_ALU | 0b0000 | ALU instruction |
INSTR_TYPE_LOAD | 0b0010 | Memory load |
INSTR_TYPE_STORE | 0b0011 | Memory store |
INSTR_TYPE_CUSTOM | 0b0100 | Custom instruction |
V = Valid, L = Last group, H = Halt. ALU# = count, Cust# = custom count, LS = load/store present.
| Constant | Value |
|---|---|
ALU_INSTRUCTION_SIZE | 14 bytes |
LS_INSTRUCTION_SIZE | 10 bytes |
ALU_OPERAND_FIELD_WIDTH | 22 bits |
LOAD_LATENCY_GROUPS | 5 cycles |
| Category | Opcodes |
|---|---|
| ALU — Data | mov movm add adds sub subs nop |
| ALU — Logic | or and xor not |
| ALU — Shift | sll srl |
| ALU — Compare | cmp cmpm rngcmp wrngcmp drngcmp sumcmp |
| Load / Store | load store |
| Constraint | Value |
|---|---|
| Max ALU / group | 8 |
| Max custom / group | 7 |
| Max load-store / group | 1 |
| Max operand width | 64 bits |
| Condition width | 4 bits |
| Issue slots | 8 |
| Flavour | Cores | TCAM | Instr Mem | Key Feature |
|---|---|---|---|---|
SGE_KEYGEN | 4 | 32 | 128 | 1 KB HW metadata |
SGE_ACTION | 4 | 96 | 256 | 848-bit output |
PTA_KEYGEN | 4 | 16 | 96 | Key-as-output |
PTA_ACTION | 4 | 32 | 128 | Data memory access |
PTA_ACU_KEYGEN | 2 | 16 | 96 | Reduced cores |
PTA_ACU_ACTION | 2 | 24 | 128 | 720-bit output |
RNIC_KEYGEN | 1 | 32 | 32 | Custom instructions |
RNIC_ACTION | 1 | 64 | 64 | TCAM index output |
| Type | Fields | Purpose |
|---|---|---|
Location | line, col (u32) | 1-based source position |
Span | start, end | Range of source characters |
Spanned | trait | Anything with source location |
Note | span, message | Diagnostic with position |
ReportItem | Error / Warning / Info | Classified diagnostic |
Either<T,U> | Left, Right | Sum type |
Each stage collects ReportItems. After each stage, the report is printed. Any Error halts compilation. Format: file:line:col: error: message.
analyze() builds the Model, then encode() produces the Artifact.The run_analysis_stage! macro wraps each stage: iterates units, calls the stage, checks for errors, prints reports, aborts early if needed.
| Script | Purpose |
|---|---|
c_header_to_flash.py | C/C++ structs → Flash (auto union detection, nested deps) |
flash_to_c_header.py | Flash structs → C/C++ headers |
| Target | Action |
|---|---|
make | cargo build --release |
make test | cargo test |
make install | Deploy binary + config to $SDKDIR/bin/ |
make clean | cargo clean |
../configs/s3_flavours.json defines all 8 flavour specs: memory widths, TCAM depth, instruction memory, core counts.