From 4df39a3111066b2764b66d017e99c7ac50edc96d Mon Sep 17 00:00:00 2001 From: John Ring Date: Thu, 9 Jul 2026 22:37:31 -0400 Subject: [PATCH] Add grammar specs and sync pretty printer colour scheme Add docs/grammars (token + AST tree specs shared with johnhringiv.com) and update pretty.rs to keep its colour mapping in sync with docs/grammars/ast-tree.json. Co-Authored-By: Claude Opus 4.8 --- docs/grammars/README.md | 125 +++++++++++++++ docs/grammars/ast-tree.json | 198 ++++++++++++++++++++++++ docs/grammars/package.json | 33 ++++ docs/grammars/tokens.json | 42 +++++ src/pretty.rs | 301 ++++++++++++++++++++++-------------- 5 files changed, 580 insertions(+), 119 deletions(-) create mode 100644 docs/grammars/README.md create mode 100644 docs/grammars/ast-tree.json create mode 100644 docs/grammars/package.json create mode 100644 docs/grammars/tokens.json diff --git a/docs/grammars/README.md b/docs/grammars/README.md new file mode 100644 index 0000000..6ed92d4 --- /dev/null +++ b/docs/grammars/README.md @@ -0,0 +1,125 @@ +# NCC Output Grammars + +TextMate grammars for syntax-highlighting NCC's debug/intermediate output. They +mirror what the compiler actually prints, so pasted compiler dumps can be +colourised instead of guessed. + +**Primary consumer: [johnhringiv.com](https://johnhringiv.com).** The website +highlights ncc output in blog write-ups with [Shiki](https://shiki.style/) using +the **vitesse-dark** theme. The website copy of these grammars is kept identical +to this folder; treat this repo as the source of truth and copy downstream. + +| File | Highlights | Produced by | +| --- | --- | --- | +| [`tokens.json`](tokens.json) | `Processed tokens: [...]` token dump | `ncc file.c --lex` | +| [`ast-tree.json`](ast-tree.json) | The tree-view IRs at every stage | `ncc file.c --parse` / `--validate` / `--tacky` / `--codegen` | +| [`package.json`](package.json) | VS Code / JetBrains bundle manifest so the folder imports as a TextMate bundle | — | + +## Source of truth + +These grammars are derived from the code, not vice-versa. When the relevant +enums or pretty-printer change, update the grammar: + +- **`tokens.json`** ← the `Token` enum in [`src/lexer.rs`](../../src/lexer.rs). + Tokens are printed with Rust's `{:?}`, so the matched words are the exact + variant names (`IntKeyword`, `Negation`, `BitwiseLeftShiftAssign`, …) and the + payload forms `Identifier("…")` / `ConstantInt("…")` etc. + +- **`ast-tree.json`** ← the `ItfDisplay` implementations in + [`src/pretty.rs`](../../src/pretty.rs), plus the enums they format + (`parser`, `validate`, `tacky`, `codegen`). + +## Colour scheme ⇄ `pretty.rs` + +`src/pretty.rs` colours the tree view for the **terminal** (ANSI truecolor); +these grammars re-colour the *same* text for the **web** (Shiki, vitesse-dark). +They are meant to agree, so the grammar's scope names track the vitesse-dark +roles. The authoritative palette (RGB constants + which node gets which colour) +lives in the doc comment at the top of `pretty.rs`. In summary: + +| Role | Colour | Examples | +| --- | --- | --- | +| Declarations | teal | `Program`, `FunctionDefinition`, `VarDeclaration` | +| Instructions / opcodes & expression nodes | gold | `Mov`, `Binary`, `Copy`, `Cast`, `Assignment` | +| Control flow | green | `Return`, `If`, `While`, `Conditional`, `None` | +| Operators & condition codes | muted red | `Add`, `Sub`, `NotEqual`, `E`, `NE`, `LE` | +| Names & jump labels (incl. `Data` global name) | olive | function names, `-> break_loop.0` | +| Locals / temporaries & `Pseudo` payload | cream | `temp.1`, `i.1` | +| Numbers / offsets & `Imm` immediates | cyan | `-4`, `Imm(3)` | +| Registers & `Pseudo` keyword | indigo | `AX`, `R10`, `SP`, `XMM0` | +| Memory-operand keywords | tan | `Stack(…)`, `Data(…)` | + +The key idea is that **operands are coloured by storage class** — immediate +(cyan), register (indigo), memory (tan) — so a spill to memory (the expensive, +interesting event when reading codegen) stands out at a glance. + +Two intentional parity gaps between the grammar and `pretty.rs`: + +- Parser `Constant(Int(0))` literals are gold in `pretty.rs` but teal + (`constant.numeric`, the number/immediate family) in the grammar — the gold + isn't reachable from a flat vitesse scope, and teal is the more internally + consistent choice. +- Flat text can't distinguish some nodes the AST can: e.g. a temporary on the + right of `->` (`Copy 5 -> i.1`) is coloured like a jump label, because targets + share the `name.N` shape (`break_loop.0`) and the two are indistinguishable + without the tree. + +### Potential: align `-S` with this palette + +The `-S` flag (emit x86-64 assembly) is a **separate** colour path — it renders +real assembly via iced-x86's formatter, mapped to named 16-colour ANSI in +`get_color` (`src/main.rs`), not the vitesse truecolor constants above. It isn't +consumed by these grammars (assembly is highlighted with a stock `asm` grammar +downstream), so nothing needs to change. But the two terminal views disagree on +the same concepts — registers are indigo here vs `blue` in `-S`, instructions +gold vs `magenta` mnemonics, labels olive vs `green` (numbers already agree at +cyan). A future consistency pass could point `get_color` at these constants +(Register→indigo, Mnemonic→gold, Number→cyan, Label→olive), which would require +exposing the palette from `pretty.rs` (make the `const`s `pub` or lift them into +a shared module). Fine as-is for now. + +## Multiple compiler versions, on purpose + +Blog snippets are **pinned to the compiler version each post is written about** — +they are *not* refreshed to track `ncc`. So the grammar must highlight several +historical output formats at once, permanently. This is a standing design +constraint, not tech debt: + +- `AllocateStack` / `DeallocateStack` — older stack-allocation form (current + `ncc` emits `Binary Sub Imm(n) -> SP`). Kept as an always-on rule. +- `Constant(0)` — older bare parser-literal form (current `ncc` emits + `Constant(Int(0))`). The parser-constant rule matches both. + +When the compiler changes an output format, **add** the new form to the grammar; +don't replace the old one, or posts about earlier versions lose their +highlighting. + +## Notes / known limitations + +- TextMate matching is first-match-wins per position, so order matters: + payload operands (`Imm(…)`, `Stack(…)`, …), size markers (``/``/``), + registers, and the `Label(…)` / `FunctionDefinition:` headers are matched + before the bare keyword lists. In particular a register destination + (`Mov R10 -> AX`) is matched *before* the arrow-target rule so it is coloured + as a register, not a jump label. +- Trailing `# …` annotations are matched as comments, so hand-annotated pastes + (`Copy a -> b # note`) don't mis-highlight words inside the note. +- `Return` prints as a statement (parser/validate) and as a TACKY instruction; + both are highlighted with one scope. The single-letter condition codes + (`E`, `A`, `B`, `G`, `L`) are matched as whole words after the + ``/``/`` size markers have been consumed. +- The grammars only cover language features NCC currently implements + (`int`/`long`/`unsigned int`/`unsigned long`/`double`, the operators and + statements in the source, the SSE conversion/`XMM` machinery for `double`). + No pointers, structs, chars, etc. — add them here when the compiler grows + them. + +## Regenerating / sanity-checking + +```bash +cargo build --release +./target/release/ncc file.c --tacky | sed 's/\x1b\[[0-9;]*m//g' # strip ANSI to see raw labels +``` + +Compare the bare node/keyword words against the alternations in +`ast-tree.json`; every emitted label should fall into exactly one scope. diff --git a/docs/grammars/ast-tree.json b/docs/grammars/ast-tree.json new file mode 100644 index 0000000..91a2479 --- /dev/null +++ b/docs/grammars/ast-tree.json @@ -0,0 +1,198 @@ +{ + "name": "ast-tree", + "scopeName": "source.ast-tree", + "_comment": "TextMate grammar for NCC's tree-view pretty printer (src/pretty.rs) covering --parse, --validate, --tacky and --codegen output. Scope names are chosen to track the vitesse-dark colour roles documented at the top of src/pretty.rs. Earlier patterns win, so payload-carrying and size markers are matched before bare keywords.", + "patterns": [ + { + "comment": "Comment lines", + "name": "comment.line.ast-tree", + "match": "^\\s*#.*$" + }, + { + "comment": "Trailing annotations (e.g. `Copy a -> b # Store result`). Matched before the keyword rules so words inside a comment (like the legacy `Store`) are not mis-highlighted as instructions.", + "name": "comment.line.ast-tree", + "match": "#.*$" + }, + { + "comment": "Box-drawing characters used for the tree", + "name": "punctuation.tree.ast-tree", + "match": "[\\u251c\\u2514\\u2502\\u2500\\u250c\\u2510\\u2518\\u252c\\u2534\\u253c]+" + }, + { + "comment": "TACKY/codegen dataflow arrow (src -> dst)", + "name": "punctuation.arrow.ast-tree", + "match": "->" + }, + { + "comment": "Assembly operand size marker (longword) / (quadword) / (double)", + "name": "storage.modifier.size.ast-tree", + "match": "<[LQD]>" + }, + { + "comment": "Imm() immediate operand. Keyword coloured teal (constant.numeric) so the immediate reads as one constant together with its number.", + "match": "\\b(Imm)\\((-?[0-9]+)\\)", + "captures": { + "1": { "name": "constant.numeric.operand.ast-tree" }, + "2": { "name": "constant.numeric.immediate.ast-tree" } + } + }, + { + "comment": "Stack() operand", + "match": "\\b(Stack)\\((-?[0-9]+)\\)", + "captures": { + "1": { "name": "constant.other.operand.ast-tree" }, + "2": { "name": "constant.numeric.ast-tree" } + } + }, + { + "comment": "Pseudo() operand — pseudo-register (pre-allocation virtual register). Keyword shares the indigo register colour since it is register-class, not memory.", + "match": "\\b(Pseudo)\\(([^)]*)\\)", + "captures": { + "1": { "name": "type.identifier.register.ast-tree" }, + "2": { "name": "string.other.temporary.ast-tree" } + } + }, + { + "comment": "Data() operand — static/global symbol. Keyword tan (memory); the global name uses the olive names colour (a global name is a name), avoiding a clash with the control-flow green.", + "match": "\\b(Data)\\(([^)]*)\\)", + "captures": { + "1": { "name": "constant.other.operand.ast-tree" }, + "2": { "name": "entity.name.function.data.ast-tree" } + } + }, + { + "comment": "Parser/validated Constant literal. Matches both the current typed form Constant(Int(0)) / Long / UInt / ULong / Double and the older bare form Constant(0) (blog snippets are pinned to the compiler version each post covers, so both formats persist). Teal (constant.numeric) so parser constants join the immediate/number 'constant' family across all stages, instead of the green that clashed with control-flow.", + "name": "constant.numeric.constant.ast-tree", + "match": "\\bConstant\\((?:(?:Int|Long|UInt|ULong|Double)\\([^)]*\\)|-?[0-9]+)\\)" + }, + { + "comment": "TACKY Const debug value: ConstInt/ConstLong/ConstUInt/ConstULong/ConstDouble(...)", + "name": "constant.numeric.ast-tree", + "match": "\\bConst(?:Int|Long|UInt|ULong|Double)\\([^)]*\\)" + }, + { + "comment": "Static initializer value: IntInit/LongInit/UIntInit/ULongInit/DoubleInit(...)", + "name": "constant.numeric.ast-tree", + "match": "\\b(?:Int|Long|UInt|ULong|Double)Init\\([^)]*\\)" + }, + { + "comment": "Identifier(\"name\") leaf", + "name": "entity.name.function.ast-tree", + "match": "\\bIdentifier\\(\"[^\"]*\"\\)" + }, + { + "comment": "Label() TACKY/codegen instruction with its label payload", + "match": "\\b(Label)\\(([^)]*)\\)", + "captures": { + "1": { "name": "support.function.ast-tree" }, + "2": { "name": "entity.name.label.ast-tree" } + } + }, + { + "comment": "FunctionDefinition: header (TACKY/codegen)", + "match": "\\b(FunctionDefinition)(:)\\s*([A-Za-z_][A-Za-z0-9_]*)", + "captures": { + "1": { "name": "entity.name.class.ast-tree" }, + "2": { "name": "punctuation.separator.ast-tree" }, + "3": { "name": "entity.name.function.ast-tree" } + } + }, + { + "comment": "StaticVariable: header", + "match": "\\b(StaticVariable)(:)\\s*([A-Za-z_][A-Za-z0-9_]*)", + "captures": { + "1": { "name": "entity.name.class.ast-tree" }, + "2": { "name": "punctuation.separator.ast-tree" }, + "3": { "name": "entity.name.function.ast-tree" } + } + }, + { + "comment": "CPU registers (System V scratch/arg set + SSE XMM). Matched BEFORE the arrow-target rule so a register on the right of `->` (e.g. `Mov R10 -> AX`) is coloured as a register, not mis-scoped as a jump label. Indigo gives registers their own hue, clearly separated from teal immediates/numbers and warm tan memory operands (Stack/Data).", + "name": "type.identifier.register.ast-tree", + "match": "\\b(AX|CX|DX|DI|SI|R8|R9|R10|R11|SP|XMM[0-9]+)\\b" + }, + { + "comment": "Renamed locals / temporaries: name.. Dusty-rose (the best clean/unstyled hue this warm theme offers that is distinct from instruction gold / memory tan; the cooler options in vitesse-dark all carry bold/italic diff-markup styling). Matched BEFORE the arrow-target rule so a temporary destination (`Copy x -> temp.1`) gets the same colour as when it appears as a source — otherwise the same variable renders two different colours. Real jump targets (else_label, end_label) have no .N suffix, so they still fall through to the arrow-target rule and stay label-coloured.", + "name": "string.other.temporary.ast-tree", + "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\.[0-9]+\\b" + }, + { + "comment": "Jump / branch target following an arrow", + "name": "entity.name.label.ast-tree", + "match": "(?<=->\\s)[A-Za-z_][A-Za-z0-9_.]*" + }, + { + "comment": "FunCall / Call instruction followed by its callee name", + "match": "\\b(FunCall|Call)\\s+([A-Za-z_][A-Za-z0-9_]*)", + "captures": { + "1": { "name": "support.function.ast-tree" }, + "2": { "name": "entity.name.function.ast-tree" } + } + }, + { + "comment": "Top-level / declaration nodes (teal)", + "name": "entity.name.class.ast-tree", + "match": "\\b(Program|FunctionDefinition|FunDeclaration|VarDeclaration|StaticVariable|FunType)\\b" + }, + { + "comment": "TACKY & codegen instructions and parser/validated expression nodes (teal)", + "name": "support.function.ast-tree", + "match": "\\b(Mov|Movsx|MovZeroExtend|Cvttsd2si|Cvtsi2sd|Binary|Unary|Cmp|Idiv|Div|Cdq|Jmp|JmpCC|SetCC|Push|Call|Ret|Copy|Jump|JumpIfZero|JumpIfNotZero|FunCall|SignExtend|Truncate|ZeroExtend|DoubleToInt|DoubleToUInt|IntToDouble|UIntToDouble|Cast|CompoundAssignment|Assignment|PostFix|PreFix|FunctionCall)\\b" + }, + { + "comment": "Older-form instructions NOT emitted by the current NCC. Blog snippets are pinned to the compiler version each post covers, so this output is permanent (not a snippet to regenerate). Today's compiler lowers stack allocation to `Binary Sub Imm(n) -> SP` instead of AllocateStack/DeallocateStack; the grammar must highlight both across the post history.", + "name": "support.function.ast-tree", + "match": "\\b(AllocateStack|DeallocateStack)\\b" + }, + { + "comment": "Statement / control-flow nodes (teal-green)", + "name": "keyword.control.ast-tree", + "match": "\\b(Return|Expression|If|Null|Goto|Labeled|Compound|Break|Continue|While|DoWhile|For|Switch|Case|Default|Conditional|None)\\b" + }, + { + "comment": "Storage class / linkage markers", + "name": "storage.modifier.ast-tree", + "match": "\\b(storage_class:\\s*(?:static|extern)|static|extern|global|local)\\b" + }, + { + "comment": "Types", + "name": "storage.type.ast-tree", + "match": "\\b(Int|Long|UInt|ULong|Double|FunType)\\b" + }, + { + "comment": "Operators across parser, TACKY and codegen op enums", + "name": "keyword.operator.ast-tree", + "match": "\\b(BitwiseComplement|Negate|Not|Neg|Subtract|Sub|Add|Multiply|Mult|DivDouble|Divide|Remainder|BitwiseAnd|BitwiseOr|BitwiseXOr|BitwiseLeftShift|BitwiseRightShift|BitAnd|BitOr|BitXOr|BitShl|BitSar|BitShr|Shr|And|Or|Equal|NotEqual|LessThan|LessOrEqual|GreaterThan|GreaterOrEqual|Increment|Decrement)\\b" + }, + { + "comment": "Condition codes (longer names first; sizes / already consumed above)", + "name": "keyword.operator.condition.ast-tree", + "match": "\\b(NE|AE|BE|GE|LE|E|A|B|G|L)\\b" + }, + { + "comment": "Branch labels carried inline, e.g. [label: 0] or [break_loop.0]", + "name": "entity.name.label.ast-tree", + "match": "\\[(?:label:\\s*)?[A-Za-z0-9_.]*\\]" + }, + { + "comment": "Child field labels (uncoloured in the printer; highlighted here for readability)", + "name": "variable.parameter.label.ast-tree", + "match": "\\b(name|type|return|params|init|args|condition|then|else|body|post|expr|stmt|target_type|cases|align):" + }, + { + "comment": "Vector length header, e.g. [3]", + "name": "constant.numeric.ast-tree", + "match": "\\[[0-9]+\\]" + }, + { + "comment": "Bare integers (offsets, alignments, loop labels)", + "name": "constant.numeric.ast-tree", + "match": "\\b-?[0-9]+\\b" + }, + { + "comment": "Any remaining quoted string", + "name": "string.quoted.double.ast-tree", + "match": "\"[^\"]*\"" + } + ] +} diff --git a/docs/grammars/package.json b/docs/grammars/package.json new file mode 100644 index 0000000..4f6c50c --- /dev/null +++ b/docs/grammars/package.json @@ -0,0 +1,33 @@ +{ + "name": "ncc-output-grammars", + "displayName": "NCC Output Grammars", + "version": "0.1.0", + "description": "TextMate grammars for NCC's --lex token dump and --parse/--validate/--tacky/--codegen tree view. Importable as a TextMate bundle in JetBrains IDEs and VS Code.", + "engines": { "vscode": "*" }, + "contributes": { + "languages": [ + { + "id": "ncc-tokens", + "aliases": ["NCC Tokens"], + "extensions": [".ncctok"] + }, + { + "id": "ncc-ast-tree", + "aliases": ["NCC AST Tree"], + "extensions": [".nccir"] + } + ], + "grammars": [ + { + "language": "ncc-tokens", + "scopeName": "source.tokens", + "path": "./tokens.json" + }, + { + "language": "ncc-ast-tree", + "scopeName": "source.ast-tree", + "path": "./ast-tree.json" + } + ] + } +} diff --git a/docs/grammars/tokens.json b/docs/grammars/tokens.json new file mode 100644 index 0000000..fb3dd55 --- /dev/null +++ b/docs/grammars/tokens.json @@ -0,0 +1,42 @@ +{ + "name": "tokens", + "scopeName": "source.tokens", + "_comment": "TextMate grammar for NCC's `--lex` output (`Processed tokens: [...]`). Variant names mirror `Token` in src/lexer.rs and are printed via Rust's `{:?}` Debug. Keep in sync with the `Token` enum.", + "patterns": [ + { + "comment": "Leading 'Processed tokens:' header and comment lines", + "name": "comment.line.tokens", + "match": "^\\s*#.*$" + }, + { + "comment": "Identifier(\"name\") — carries the source spelling", + "name": "entity.name.function.tokens", + "match": "\\bIdentifier\\(\"[^\"]*\"\\)" + }, + { + "comment": "Constant tokens: ConstantInt/Long/UnsignedInt/UnsignedLong/Double(\"...\")", + "name": "constant.numeric.tokens", + "match": "\\bConstant(?:UnsignedLong|UnsignedInt|Long|Int|Double)\\(\"[^\"]*\"\\)" + }, + { + "comment": "Keywords — every *Keyword variant of Token", + "name": "keyword.control.tokens", + "match": "\\b(IntKeyword|VoidKeyword|ReturnKeyword|IfKeyword|ElseKeyword|GotoKeyword|DoKeyword|WhileKeyword|ForKeyword|BreakKeyword|ContinueKeyword|SwitchKeyword|DefaultKeyword|CaseKeyword|StaticKeyword|ExternKeyword|LongKeyword|SignedKeyword|UnsignedKeyword|DoubleKeyword)\\b" + }, + { + "comment": "Operators (compound *Assign names listed implicitly via word boundaries)", + "name": "keyword.operator.tokens", + "match": "\\b(BitwiseComplement|Negation|Plus|Asterisk|Division|Modulus|BitwiseAndAssign|BitwiseOrAssign|BitwiseXOrAssign|BitwiseLeftShiftAssign|BitwiseRightShiftAssign|BitwiseAnd|BitwiseOr|BitwiseXOr|BitwiseLeftShift|BitwiseRightShift|LogicalNot|LogicalAnd|LogicalOr|Equal|NotEqual|LessThanOrEqual|GreaterThanOrEqual|LessThan|GreaterThan|Assignment|PlusAssign|MinusAssign|AsteriskAssign|DivisionAssign|ModulusAssign|Decrement|Increment|QuestionMark|Colon)\\b" + }, + { + "comment": "Delimiters and punctuation", + "name": "punctuation.tokens", + "match": "\\b(OpenParen|CloseParen|OpenBrace|CloseBrace|Semicolon|Comma)\\b" + }, + { + "comment": "List brackets / commas around the token vector", + "name": "punctuation.bracket.tokens", + "match": "[\\[\\],]" + } + ] +} diff --git a/src/pretty.rs b/src/pretty.rs index b54608a..5280ea3 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -3,16 +3,15 @@ use std::fmt; use colored::Colorize; use crate::codegen::{ - AssemblyType, BinaryOp, CondCode, FunctionDefinition as CodegenFunctionDefinition, - Instruction as CodegenInstruction, Operand, Program as CodegenProgram, Reg, UnaryOp, + AssemblyType, FunctionDefinition as CodegenFunctionDefinition, Instruction as CodegenInstruction, Operand, + Program as CodegenProgram, Reg, }; use crate::parser::{ - AssignOp, BinOp as ParserBinOp, BlockItem, Const, Declaration, Expr, ForInit, FunDeclaration, Identifier, IncDec, - Program as ParserProgram, SpannedStmt, Stmt, StorageClass, SwitchIntType, Type, UnaryOp as ParserUnaryOp, - VarDeclaration, + BlockItem, Const, Declaration, Expr, ForInit, FunDeclaration, Identifier, Program as ParserProgram, SpannedStmt, + Stmt, StorageClass, SwitchIntType, Type, VarDeclaration, }; use crate::tacky::{ - BinOp, FunctionDefinition as TackyFunctionDefinition, Instruction as TackyInstruction, Program as TackyProgram, + FunctionDefinition as TackyFunctionDefinition, Instruction as TackyInstruction, Program as TackyProgram, StaticVariable, Val, VarInit, }; use crate::validate::{ @@ -28,21 +27,20 @@ use crate::validate::{ // highlighting for the compiler's AST pretty printer across all stages: // Parser, Tacky IR, and Codegen. // -// Color Mapping: +// Color Mapping (kept in sync with docs/grammars/ast-tree.json — see +// docs/grammars/README.md, "Colour scheme ⇄ pretty.rs"): // -// 1. TEAL (93, 169, 148) - Instructions & Declarations -// - Instructions: Mov, Binary, Copy, Jump, Call, Label, Return (Tacky), etc. -// - Declarations: Program, FunctionDefinition, VarDeclaration, FunDeclaration -// - Expression types: PostFix, Assignment, Conditional, Unary, Binary (Parser) +// 1. TEAL (93, 169, 148) - Declarations +// - Program, FunctionDefinition, FunDeclaration, VarDeclaration, StaticVariable // -// 2. TEAL_GREEN (77, 147, 117) - Control Flow & Registers -// - Control flow keywords: Return, If, While, For, Break, Continue, Switch, etc. -// - CPU Registers: AX, R10, SP, BP, etc. +// 2. TEAL_GREEN (77, 147, 117) - Control Flow +// - Return, If, While, For, Break, Continue, Switch, Conditional, None, etc. +// (control-flow only — registers moved to INDIGO) // // 3. MUTED_RED (203, 118, 118) - Operators & Type Qualifiers // - Operators: Add, Multiply, NotEqual, BitwiseAnd, Increment, etc. -// - Operand type keywords: Imm, Stack, Data, Pseudo // - Condition codes: E, NE, L, LE, G, GE, etc. +// (operand keywords moved to storage-class colours below) // // 4. YELLOW_GREEN (128, 166, 101) - Names & Labels // - Function names and identifiers @@ -52,18 +50,29 @@ use crate::validate::{ // 5. CREAM (219, 215, 202) - Variables // - Local variable names // - Temporary variables (temp.1, binary_left.2, etc.) -// - Pseudo register names +// - Pseudo register names (the payload of Pseudo(...)) // -// 6. CYAN_TEAL (76, 154, 145) - Numeric Values -// - Integer literals -// - Immediate values -// - Stack offsets (-4, -8, etc.) -// - Memory offsets and allocation sizes +// 6. CYAN_TEAL (76, 154, 145) - Numeric Values & immediates +// - Integer literals, stack/memory offsets, allocation sizes +// - Imm(...) immediate operands — keyword AND value, so the whole Imm(1) +// reads as one constant (immediate storage class) // // 7. YELLOW_GOLD (230, 204, 119) - String Constants // - Constant expressions in Parser AST // - String literal values // +// 8. INDIGO (104, 114, 171) - Registers (register storage class) +// - CPU registers: AX, R10, SP, XMM0, etc. +// - Pseudo(...) keyword (a pseudo-register is register-class) +// +// 9. TAN (201, 144, 118) - Memory operands (memory storage class) +// - Stack(...) and Data(...) keywords (spills and globals) +// +// 10. GOLD_INSTR (184, 169, 101) - Instructions / opcodes & expression nodes +// - TACKY/codegen instructions: Mov, Binary, Copy, Jump, Call, Ret, Label, etc. +// - Parser/validated expression nodes: Cast, Unary, Binary, Assignment, +// CompoundAssignment, PostFix, PreFix, FunctionCall +// // ============================================================================= const TEAL_GREEN: (u8, u8, u8) = (77, 147, 117); // s5: #4d9375 @@ -73,6 +82,9 @@ const YELLOW_GREEN: (u8, u8, u8) = (128, 166, 101); // s3: #80a665 const CREAM: (u8, u8, u8) = (219, 215, 202); // s4: #dbd7caee const CYAN_TEAL: (u8, u8, u8) = (76, 154, 145); // s18: #4c9a91 const YELLOW_GOLD: (u8, u8, u8) = (230, 204, 119); // s17: #e6cc77 +const INDIGO: (u8, u8, u8) = (104, 114, 171); // s28: #6872ab — registers & pseudo-registers +const TAN: (u8, u8, u8) = (201, 144, 118); // s2: #c99076 — memory operands (Stack, Data) +const GOLD_INSTR: (u8, u8, u8) = (184, 169, 101); // s10: #b8a965 — instructions/opcodes & expression nodes #[derive(Clone)] pub struct Node { @@ -141,22 +153,11 @@ macro_rules! colored_node { }; } -// Operators and condition codes (muted red) -colored_node!( - MUTED_RED.0, MUTED_RED.1, MUTED_RED.2; - ParserUnaryOp, - ParserBinOp, - AssignOp, - IncDec, // Parser - BinOp, // Tacky - UnaryOp, - BinaryOp, - CondCode, // Codegen -); +// Operators and condition codes are coloured inline via `op_str` (muted red). -// Registers (teal-green) +// Registers (indigo) colored_node!( - TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2; + INDIGO.0, INDIGO.1, INDIGO.2; Reg, ); @@ -301,7 +302,7 @@ impl ItfDisplay for Vec { let children: Vec = self.iter().map(|item| item.itf_node()).collect(); Node::branch( format!("[{}]", self.len()) - .truecolor(TEAL.0, TEAL.1, TEAL.2) + .truecolor(CYAN_TEAL.0, CYAN_TEAL.1, CYAN_TEAL.2) .to_string(), children, ) @@ -318,7 +319,7 @@ impl ItfDisplay for ForInit { ForInit::InitDecl(decl) => decl.itf_node(), ForInit::InitExp(opt_expr) => match opt_expr { Some(expr) => expr.itf_node(), - None => Node::leaf("None".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string()), + None => Node::leaf("None".truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2).to_string()), }, } } @@ -390,42 +391,62 @@ impl ItfDisplay for Expr { } Expr::Var(id, _span) => id.itf_node(), Expr::Cast(target_type, e) => Node::branch( - "Cast".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Cast".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2).to_string(), vec![ Node::branch("target_type:", vec![target_type.itf_node()]), Node::branch("expr:", vec![e.itf_node()]), ], ), Expr::Unary(op, e, _span) => Node::branch( - format!("Unary ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "Unary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), Expr::Binary(op, e1, e2, _span) => Node::branch( - format!("Binary ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "Binary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e1.itf_node(), e2.itf_node()], ), Expr::Assignment(lhs, rhs, _span) => Node::branch( - "Assignment".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Assignment" + .truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2) + .to_string(), vec![lhs.itf_node(), rhs.itf_node()], ), Expr::CompoundAssignment(op, lhs, rhs, _span) => Node::branch( - format!("CompoundAssignment ({op:?})") - .truecolor(TEAL.0, TEAL.1, TEAL.2) - .to_string(), + format!( + "{} ({})", + "CompoundAssignment".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![lhs.itf_node(), rhs.itf_node()], ), Expr::PostFixOp(op, e, _span) => Node::branch( - format!("PostFix ({op:?})") - .truecolor(TEAL.0, TEAL.1, TEAL.2) - .to_string(), + format!( + "{} ({})", + "PostFix".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), Expr::PreFixOp(op, e, _span) => Node::branch( - format!("PreFix ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "PreFix".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), Expr::Conditional(condition, then_expr, else_expr) => Node::branch( - "Conditional".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Conditional" + .truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2) + .to_string(), vec![ Node::branch("condition:", vec![condition.itf_node()]), Node::branch("then:", vec![then_expr.itf_node()]), @@ -438,7 +459,12 @@ impl ItfDisplay for Expr { let arg_nodes: Vec = args.iter().map(|a| a.itf_node()).collect(); children.push(Node::branch("args:", arg_nodes)); } - Node::branch("FunctionCall".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), children) + Node::branch( + "FunctionCall" + .truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2) + .to_string(), + children, + ) } } } @@ -750,42 +776,62 @@ impl ItfDisplay for ValidatedExpr { } ValidatedExpr::Var(id) => id.itf_node(), ValidatedExpr::Cast(target_type, e) => Node::branch( - "Cast".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Cast".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2).to_string(), vec![ Node::branch("target_type:", vec![target_type.itf_node()]), Node::branch("expr:", vec![e.itf_node()]), ], ), ValidatedExpr::Unary(op, e) => Node::branch( - format!("Unary ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "Unary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), ValidatedExpr::Binary(op, e1, e2) => Node::branch( - format!("Binary ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "Binary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e1.itf_node(), e2.itf_node()], ), ValidatedExpr::Assignment(lhs, rhs) => Node::branch( - "Assignment".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Assignment" + .truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2) + .to_string(), vec![lhs.itf_node(), rhs.itf_node()], ), ValidatedExpr::CompoundAssignment(op, lhs, rhs, _inner_type) => Node::branch( - format!("CompoundAssignment ({op:?})") - .truecolor(TEAL.0, TEAL.1, TEAL.2) - .to_string(), + format!( + "{} ({})", + "CompoundAssignment".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![lhs.itf_node(), rhs.itf_node()], ), ValidatedExpr::PostFixOp(op, e) => Node::branch( - format!("PostFix ({op:?})") - .truecolor(TEAL.0, TEAL.1, TEAL.2) - .to_string(), + format!( + "{} ({})", + "PostFix".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), ValidatedExpr::PreFixOp(op, e) => Node::branch( - format!("PreFix ({op:?})").truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + format!( + "{} ({})", + "PreFix".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op) + ), vec![e.itf_node()], ), ValidatedExpr::Conditional(cond, then_expr, else_expr) => Node::branch( - "Conditional".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), + "Conditional" + .truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2) + .to_string(), vec![ Node::branch("condition:", vec![cond.itf_node()]), Node::branch("then:", vec![then_expr.itf_node()]), @@ -798,7 +844,12 @@ impl ItfDisplay for ValidatedExpr { let arg_nodes: Vec = args.iter().map(|a| a.itf_node()).collect(); children.push(Node::branch("args:", arg_nodes)); } - Node::branch("FunctionCall".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string(), children) + Node::branch( + "FunctionCall" + .truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2) + .to_string(), + children, + ) } } } @@ -999,7 +1050,7 @@ impl ItfDisplay for ValidatedForInit { ValidatedForInit::InitDecl(decl) => decl.itf_node(), ValidatedForInit::InitExp(opt_expr) => match opt_expr { Some(expr) => expr.itf_node(), - None => Node::leaf("None".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string()), + None => Node::leaf("None".truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2).to_string()), }, } } @@ -1032,60 +1083,70 @@ fn val_str(v: &Val) -> String { } } +// Format an operator or condition code (Debug) in the operator colour (muted red), +// matching the grammar's `keyword.operator` scope across every stage. +fn op_str(op: impl std::fmt::Debug) -> String { + format!("{op:?}") + .truecolor(MUTED_RED.0, MUTED_RED.1, MUTED_RED.2) + .to_string() +} + impl ItfDisplay for TackyInstruction { fn itf_node(&self) -> Node { match self { - TackyInstruction::Return(v) => { - Node::leaf(format!("{} {}", "Return".truecolor(TEAL.0, TEAL.1, TEAL.2), val_str(v))) - } + TackyInstruction::Return(v) => Node::leaf(format!( + "{} {}", + "Return".truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2), + val_str(v) + )), TackyInstruction::Unary { op, src, dst } => Node::leaf(format!( - "{} {:?} {} -> {}", - "Unary".truecolor(TEAL.0, TEAL.1, TEAL.2), - op, + "{} {} {} -> {}", + "Unary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op), val_str(src), val_str(dst) )), TackyInstruction::Binary { op, src1, src2, dst } => Node::leaf(format!( - "{} {:?} {}, {} -> {}", - "Binary".truecolor(TEAL.0, TEAL.1, TEAL.2), - op, + "{} {} {}, {} -> {}", + "Binary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(op), val_str(src1), val_str(src2), val_str(dst) )), TackyInstruction::Copy { src, dst } => Node::leaf(format!( "{} {} -> {}", - "Copy".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Copy".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::Jump { target } => Node::leaf(format!( "{} -> {}", - "Jump".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Jump".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), target.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), TackyInstruction::JumpIfZero { condition, target } => Node::leaf(format!( "{} {} -> {}", - "JumpIfZero".truecolor(TEAL.0, TEAL.1, TEAL.2), + "JumpIfZero".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(condition), target.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), TackyInstruction::JumpIfNotZero { condition, target } => Node::leaf(format!( "{} {} -> {}", - "JumpIfNotZero".truecolor(TEAL.0, TEAL.1, TEAL.2), + "JumpIfNotZero".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(condition), target.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), TackyInstruction::Label(lbl) => Node::leaf(format!( "{}({})", - "Label".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Label".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), lbl.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), TackyInstruction::FunCall { fun_name, args, dst } => { let args_str = args.iter().map(val_str).collect::>().join(", "); Node::leaf(format!( "{} {}({}) -> {}", - "FunCall".truecolor(TEAL.0, TEAL.1, TEAL.2), + "FunCall".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), fun_name.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2), args_str, val_str(dst) @@ -1093,43 +1154,43 @@ impl ItfDisplay for TackyInstruction { } TackyInstruction::SignExtend { src, dst } => Node::leaf(format!( "{} {} -> {}", - "SignExtend".truecolor(TEAL.0, TEAL.1, TEAL.2), + "SignExtend".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::Truncate { src, dst } => Node::leaf(format!( "{} {} -> {}", - "Truncate".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Truncate".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::ZeroExtend { src, dst } => Node::leaf(format!( "{} {} -> {}", - "ZeroExtend".truecolor(TEAL.0, TEAL.1, TEAL.2), + "ZeroExtend".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::DoubleToInt { src, dst } => Node::leaf(format!( "{} {} -> {}", - "DoubleToInt".truecolor(TEAL.0, TEAL.1, TEAL.2), + "DoubleToInt".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::DoubleToUInt { src, dst } => Node::leaf(format!( "{} {} -> {}", - "DoubleToUInt".truecolor(TEAL.0, TEAL.1, TEAL.2), + "DoubleToUInt".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::IntToDouble { src, dst } => Node::leaf(format!( "{} {} -> {}", - "IntToDouble".truecolor(TEAL.0, TEAL.1, TEAL.2), + "IntToDouble".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), TackyInstruction::UIntToDouble { src, dst } => Node::leaf(format!( "{} {} -> {}", - "UIntToDouble".truecolor(TEAL.0, TEAL.1, TEAL.2), + "UIntToDouble".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), val_str(src), val_str(dst) )), @@ -1204,27 +1265,27 @@ fn size_str(size: &AssemblyType) -> String { // Helper to format Operand compactly as string fn operand_str(op: &Operand) -> String { match op { + // Operands are coloured by storage class: immediate (teal, keyword + value read as one + // constant), register (indigo), memory — Stack/Data (tan). See docs/grammars/README.md. Operand::Imm(i) => format!( "{}({})", - "Imm".truecolor(MUTED_RED.0, MUTED_RED.1, MUTED_RED.2), + "Imm".truecolor(CYAN_TEAL.0, CYAN_TEAL.1, CYAN_TEAL.2), i.to_string().truecolor(CYAN_TEAL.0, CYAN_TEAL.1, CYAN_TEAL.2) ), - Operand::Reg(r) => format!("{:?}", r) - .truecolor(TEAL_GREEN.0, TEAL_GREEN.1, TEAL_GREEN.2) - .to_string(), + Operand::Reg(r) => format!("{:?}", r).truecolor(INDIGO.0, INDIGO.1, INDIGO.2).to_string(), Operand::Pseudo(s) => format!( "{}({})", - "Pseudo".truecolor(MUTED_RED.0, MUTED_RED.1, MUTED_RED.2), + "Pseudo".truecolor(INDIGO.0, INDIGO.1, INDIGO.2), s.truecolor(CREAM.0, CREAM.1, CREAM.2) ), Operand::Stack(o) => format!( "{}({})", - "Stack".truecolor(MUTED_RED.0, MUTED_RED.1, MUTED_RED.2), + "Stack".truecolor(TAN.0, TAN.1, TAN.2), o.to_string().truecolor(CYAN_TEAL.0, CYAN_TEAL.1, CYAN_TEAL.2) ), Operand::Data(s) => format!( "{}({})", - "Data".truecolor(MUTED_RED.0, MUTED_RED.1, MUTED_RED.2), + "Data".truecolor(TAN.0, TAN.1, TAN.2), s.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) ), } @@ -1241,107 +1302,109 @@ impl ItfDisplay for CodegenInstruction { match self { CodegenInstruction::Mov { src, dst, size } => Node::leaf(format!( "{}<{}> {} -> {}", - "Mov".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Mov".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(src), operand_str(dst) )), CodegenInstruction::Movsx { src, dst } => Node::leaf(format!( "{} {} -> {}", - "Movsx".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Movsx".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), operand_str(src), operand_str(dst) )), CodegenInstruction::MovZeroExtend { src, dst } => Node::leaf(format!( "{} {} -> {}", - "MovZeroExtend".truecolor(TEAL.0, TEAL.1, TEAL.2), + "MovZeroExtend".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), operand_str(src), operand_str(dst) )), CodegenInstruction::Cvttsd2si { src, dst, size } => Node::leaf(format!( "{}<{}> {} -> {}", - "Cvttsd2si".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Cvttsd2si".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(src), operand_str(dst) )), CodegenInstruction::Cvtsi2sd { src, dst, size } => Node::leaf(format!( "{}<{}> {} -> {}", - "Cvtsi2sd".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Cvtsi2sd".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(src), operand_str(dst) )), CodegenInstruction::Unary { op, dst, size } => Node::leaf(format!( - "{}<{}> {:?} {}", - "Unary".truecolor(TEAL.0, TEAL.1, TEAL.2), + "{}<{}> {} {}", + "Unary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), - op, + op_str(op), operand_str(dst) )), CodegenInstruction::Binary { op, src, dst, size } => Node::leaf(format!( - "{}<{}> {:?} {} -> {}", - "Binary".truecolor(TEAL.0, TEAL.1, TEAL.2), + "{}<{}> {} {} -> {}", + "Binary".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), - op, + op_str(op), operand_str(src), operand_str(dst) )), CodegenInstruction::Cmp { v1, v2, size } => Node::leaf(format!( "{}<{}> {}, {}", - "Cmp".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Cmp".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(v1), operand_str(v2) )), CodegenInstruction::Idiv(op, size) => Node::leaf(format!( "{}<{}> {}", - "Idiv".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Idiv".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(op) )), CodegenInstruction::Div(op, size) => Node::leaf(format!( "{}<{}> {}", - "Div".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Div".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size), operand_str(op) )), CodegenInstruction::Cdq(size) => Node::leaf(format!( "{}<{}>", - "Cdq".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Cdq".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), size_str(size) )), CodegenInstruction::Jmp(label) => Node::leaf(format!( "{} -> {}", - "Jmp".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Jmp".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), label.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), CodegenInstruction::JmpCC { code, label } => Node::leaf(format!( - "{} {:?} -> {}", - "JmpCC".truecolor(TEAL.0, TEAL.1, TEAL.2), - code, + "{} {} -> {}", + "JmpCC".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(code), label.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), CodegenInstruction::SetCC { code, op } => Node::leaf(format!( - "{} {:?} {}", - "SetCC".truecolor(TEAL.0, TEAL.1, TEAL.2), - code, + "{} {} {}", + "SetCC".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), + op_str(code), operand_str(op) )), CodegenInstruction::Label(l) => Node::leaf(format!( "{}({})", - "Label".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Label".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), l.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), - CodegenInstruction::Ret => Node::leaf("Ret".truecolor(TEAL.0, TEAL.1, TEAL.2).to_string()), + CodegenInstruction::Ret => { + Node::leaf("Ret".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2).to_string()) + } CodegenInstruction::Push(op) => Node::leaf(format!( "{} {}", - "Push".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Push".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), operand_str(op) )), CodegenInstruction::Call(name) => Node::leaf(format!( "{} {}", - "Call".truecolor(TEAL.0, TEAL.1, TEAL.2), + "Call".truecolor(GOLD_INSTR.0, GOLD_INSTR.1, GOLD_INSTR.2), name.0.truecolor(YELLOW_GREEN.0, YELLOW_GREEN.1, YELLOW_GREEN.2) )), }