Expand description
Abstract syntax tree for the .ud source language.
This crate is the source of truth for what .ud looks like. The
pretty-printer in emit produces the canonical text form; both
the decompiler (which builds an AST and emits it) and the parser
(which reads text and builds an AST) speak in terms of these types.
Round-trip property at the source level:
For any AST built by a producer,
parse(emit(ast)) == ast. For any text in canonical form,emit(parse(text)) == text.
Producers must therefore avoid AST shapes the pretty-printer would
re-canonicalise into a different shape (e.g. mismatched ordering of
module.fields). The pretty-printer is deterministic; the parser
is the source of permissiveness (multiple whitespace conventions,
all canonicalised on emit).
Structs§
- Attribute
- A
#[key=value]annotation. Attributes live on structural elements (functions, conditionals, …) and carry metadata that is either: - Epilogue
Params - Structured breakdown of a function epilogue. Mirrors
PrologueParams. - Field
- One
name: valueentry inside a@moduleor nested block. - FnDecl
- A function declaration.
- Jump
Table Entry - One entry inside an
Item::JumpTableblock: a case index and the address it dispatches to. The case ordering is the encoded table order — entries lower in source-text order render at(addr + i * entry_size). - Local
Decl - One
let name: type;entry at the head of a function body. - Module
- The
@module { … }block at the top of every file. - Note
Entry - One entry inside an
Item::Notesblock. Mirrors the structure of an ELF note (Elf64_Nhdr+ name + desc, each padded to a 4-byte boundary). - Param
- One typed parameter in a function signature.
- Prologue
Params - Structured breakdown of a function prologue. Lets the source language carry semantic information (which registers got saved, whether a frame was set up, how much stack the function reserves, whether CET protection is on) instead of an opaque byte blob.
- Signature
- A function signature: parameter list + return type.
- UdFile
- A complete
.udfile: a@module { … }header followed by zero or more top-level items.
Enums§
- Attr
Value - Right-hand side of an attribute. Kept small on purpose — every new variant has to round-trip through emit + parse + lower.
- Item
- An item in the file: at the top level, or nested inside an
Item::Section. - Local
Kind - Stmt
- A statement inside a function body.
- Type
- A type expressible in
.udsource. - Value
- A value that can appear on the right-hand side of a
Field.
Functions§
- emit
- Format an entire AST as canonical
.udtext. Trailing newline is included; the file always ends in\n.