Skip to main content

sleigh/
lib.rs

1#![warn(missing_docs)]
2#![warn(unreachable_pub)]
3#![doc = include_str!("../README.md")]
4//!
5//! # Pipeline
6//!
7//! ```text
8//! SLEIGH spec (.sla)
9//!   └─ source/          ← file I/O, include resolution, preprocessing
10//!        ↓
11//!   syntax/             ← Pest grammar → SleighFile AST (unresolved names)
12//!        ↓
13//!   resolve.rs          ← SleighFile → SpecBuilder (symbol IDs resolved)
14//!        ↓
15//!   builder.rs          ← SpecBuilder → Spec (concretized patterns + p-code)
16//!        │  uses pmacro/  (expression AST, typed IDs, macro expansion)
17//!        ↓
18//!   CompiledSpec
19//!        ↓  HOT PATH
20//!   walker.rs           ← pattern matching → ConstructorInstance
21//!        ↓
22//!   runtime/pcode/traverse.rs ← splices built sub-tables and delay slots
23//!   runtime/pcode/view.rs     ← resolves each template node in place
24//!        ↓
25//!   PcodeAst, or flat p-code streamed straight into a consumer's sink
26//! ```
27//!
28
29/// Section annotations read from `#@key value` comments in specification
30/// source, for tooling that wants to group constructors the language itself
31/// has no way to group.
32pub mod annotate;
33pub mod bitrange;
34pub mod compile;
35pub mod diagnostic;
36/// Tolerant lexical classification of SLEIGH text, for highlighting.
37pub mod highlight;
38/// Read-only views over the compiled specification's *symbolic* structures.
39///
40/// **Unstable.** Behind the `unstable-introspect` feature and exempt from this
41/// crate's semantic versioning, for the same reason [`syntax`] is: these are
42/// the compiler's own representations. `wazabin-metal` is the intended
43/// consumer.
44#[cfg(feature = "unstable-introspect")]
45pub mod introspect;
46pub mod pcode_error;
47pub mod runtime;
48pub mod semantics;
49pub mod source;
50/// SLEIGH source AST, for tooling that works on specification text.
51///
52/// **Unstable.** Behind the `unstable-syntax` feature and exempt from this
53/// crate's semantic versioning: it is the shape the compiler's own front end
54/// happens to use, and it changes whenever the front end does. `wazabin-sleigh-fmt`
55/// is the intended consumer.
56#[cfg(feature = "unstable-syntax")]
57pub mod syntax;
58#[cfg(not(feature = "unstable-syntax"))]
59pub(crate) mod syntax;
60
61mod action;
62pub(crate) mod builder;
63mod constraint;
64mod constructor;
65mod instance;
66mod lint;
67pub(crate) mod objects;
68mod pattern;
69mod pmacro;
70pub(crate) mod raw_parsing;
71mod register_map;
72mod resolve;
73pub(crate) mod spec;
74pub(crate) mod token;
75mod tree;
76
77/// Fixed-width size/offset type for serialized SLEIGH structures.
78///
79/// Must stay `u32` so that specs built on x86_64 deserialize correctly on
80/// 32-bit targets such as wasm32 (where `usize` is only 4 bytes).
81pub type Size = u32;
82
83pub use annotate::Annotations;
84pub use bitrange::BitRange;
85pub use compile::{CompileOptions, Compiler};
86pub use diagnostic::{CompileError, Diagnostic, DiagnosticCode, DiagnosticLabel, Severity};
87pub use objects::field::{FieldId, FieldTableId};
88pub use pcode_error::{PcodeError, PcodeErrorTy, PcodeResult};
89pub use pcode_types::{
90    BitRangeInfo, InstructionPcode, LabelId, Opcode, PcodeLowerError, PcodeLoweringContext,
91    PcodeOp, PcodePlan, PcodeSink, RegisterId, SPACE_CONST, Space, SpaceId, SpaceType, Varnode,
92    lower_instruction,
93};
94pub use register_map::RegisterSlice;
95pub use runtime::{
96    CompiledSpec, ConstructorMatch, Context, ContextBytes, ContextDatabase, ContextEffect,
97    ContextError, ContextScope, DecodeError, Decoder, DelaySlotError, Exclusion, FieldRef,
98    Instruction, ParamField, RegisterField, RegisterRef, Shape, SpaceRef, SpecFingerprint,
99    SymbolKind, SymbolRef, TableRef, TokenRef,
100};
101pub use semantics::{
102    Builtin, EmitError, InstructionInfo, LocalVarId, PcodeAst, PcodeBinaryOp, PcodeBinop,
103    PcodeDelaySlot, PcodeExpr, PcodeExprKind, PcodeIdent, PcodeLoad, PcodeRange, PcodeSpaceRef,
104    PcodeStatement, PcodeStatementKind, PcodeTarget, PcodeUnaryOp, RangeParam, SemanticsSink,
105};
106pub use source::{
107    BytePos, FileId, FormatChunk, FormatChunkKind, FormatError, FormatLine, FormatLineKind,
108    IncludeEdge, MacroDefinition, MacroDefinitionId, MacroExpansion, MacroExpansionId,
109    PreparedSourceId, PreprocessOptions, SourceDb, SourceOrigin, Span,
110};
111pub use syntax::{AnalysisResult, analyze};
112
113/// The source AST, re-exported at the crate root for `wazabin-sleigh-fmt`.
114///
115/// **Unstable**, like the module itself: see [`syntax`].
116#[cfg(feature = "unstable-syntax")]
117pub use syntax::{
118    AlignmentDef, AttachStrDef, AttachValDef, AttachVarDef, BitRangeDef, BitRangeItem,
119    ConstructorDef, ContextDef, EndiannessDef, FieldDef, IncludeDirective, MacroDef, ParseResult,
120    PcodeOpDef, RegisterDef, SleighFile, SleighItem, SourceIndex, SpaceDef, TokenDef, TriviaToken,
121    UnresolvedAction, UnresolvedDisplayToken, UnresolvedExpr, WithBlockDef, parse,
122};
123pub use token::BitRangeFieldId;
124
125#[cfg(test)]
126mod tests;