Skip to main content

Crate ud_ast

Crate ud_ast 

Source
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:
EpilogueParams
Structured breakdown of a function epilogue. Mirrors PrologueParams.
Field
One name: value entry inside a @module or nested block.
FnDecl
A function declaration.
JumpTableEntry
One entry inside an Item::JumpTable block: 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).
LocalDecl
One let name: type; entry at the head of a function body.
Module
The @module { … } block at the top of every file.
NoteEntry
One entry inside an Item::Notes block. 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.
PrologueParams
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 .ud file: a @module { … } header followed by zero or more top-level items.

Enums§

AttrValue
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.
LocalKind
Stmt
A statement inside a function body.
Type
A type expressible in .ud source.
Value
A value that can appear on the right-hand side of a Field.

Functions§

emit
Format an entire AST as canonical .ud text. Trailing newline is included; the file always ends in \n.