llvmkit-asmparser
Lexer and parser for LLVM textual IR (.ll).
The Rust files mirror llvm/lib/AsmParser/ and llvm/include/llvm/AsmParser/
file-for-file: LLLexer.{h,cpp} → ll_lexer.rs, LLToken.h → ll_token.rs.
Tracking LLVM 22.1.4.
What's implemented
.lllexer — borrows from a pre-loaded&[u8]; tokens carryCow<[u8]>payloads that allocate only when an escape sequence actually changes bytes..llparser — recursive-descent, one-token lookahead. Builds into an existingModule<'ctx, _, Unverified>fromllvmkit-ir; the'ctxbrand prevents cross-module mixing at compile time. Coverstarget datalayout/target triple,source_filename,module asm, type definitions, globals, declarations, definitions, function attributes/comdats/header operands, metadata and debug records, use-list directives, summaries, every shipped opcode, and representedConstantExprforms needed by upstream fixtures, including folded vector GEP, bitcast, cast, and select cases. Remaining parser work is tracked by the workspace roadmap rather than by empty parser stubs.
Bitcode is out of scope for this crate today; see the workspace
README for the roadmap.
Usage
use Lexer;
let mut lex = from;
while let Some = lex.next
For a Read-based entry point, use the read_to_owned helper:
use ;
use File;
let bytes = read_to_owned?;
let lex = new;
# Ok::
End-to-end examples:
cargo run --example lex_file -- examples/demo.llcargo run --example parse_file -- examples/parser_demo.ll
The parser example prints the round-tripped module via the AsmWriter on
success and a (line:col) diagnostic with a caret underline on failure.
Parser corpus
tests/parser_corpus.rs reads tests/fixtures/parser_corpus_manifest.txt.
Each row names an llvmkit fixture, its upstream provenance, optional
expect=<file> canonical AsmWriter output, and status=pass|xfail-parse|xfail-verify.
The xfail-* rows are the explicit allowlist for upstream-negative or
not-yet-supported shapes; passing rows must parse, verify, and match the
checked-in expected output when one is listed. Fixture comments cite upstream
inputs as provenance, not as a claim that upstream's FileCheck text is identical
to llvmkit's current expected output.
License
Apache-2.0 WITH LLVM-exception (same as upstream LLVM). See the workspace
LICENSE.