llvmkit_asmparser/lib.rs
1#![forbid(unsafe_code)]
2//! `.ll` (LLVM IR) lexer and parser.
3//!
4//! The crate's module layout mirrors the LLVM 22.1.4 `AsmParser` source tree
5//! (`include/llvm/AsmParser/*.h` + `lib/AsmParser/*.cpp`). One Rust file per
6//! C++ translation unit; header-only C++ files map to a Rust file of the
7//! same stem.
8//!
9//! | Rust module | LLVM source | Status |
10//! |------------------------------|----------------------------------------|----------|
11//! | [`ll_lexer`] | `LLLexer.h` + `LLLexer.cpp` | done |
12//! | [`ll_token`] | `LLToken.h` | done |
13//! | [`file_loc`] | `FileLoc.h` | done |
14//! | [`numbered_values`] | `NumberedValues.h` | done |
15//! | [`slot_mapping`] | `SlotMapping.h` | done |
16//! | [`asm_parser_context`] | `AsmParserContext.h` + `.cpp` | done |
17//! | [`parse_error`] | `LLParser.{h,cpp}` diagnostic surface | seeded |
18//! | [`ll_parser`] | `LLParser.h` + `LLParser.cpp` (subset) | seeded |
19//! | [`parser`] | `Parser.h` + `Parser.cpp` | seeded |
20//!
21//! The substrate listed as `done` is the support layer the parser-first
22//! roadmap pulls in alongside `LLParser`; it ships before the parser core
23//! so Sessions 2-3 can wire their resolution / location pipelines against
24//! a stable interface (Roadmap section 10.5 forward-reference typestate).
25
26pub mod asm_parser_context;
27pub mod file_loc;
28pub mod ll_lexer;
29pub mod ll_parser;
30pub mod ll_token;
31pub mod module_summary;
32pub mod numbered_values;
33pub mod parse_error;
34pub mod parser;
35pub mod slot_mapping;
36
37use std::io::{self, Read};
38
39/// Drain `r` into a fresh `Vec<u8>`. Convenience helper for the common case
40/// where a caller has any `Read` source and wants to feed it to
41/// [`ll_lexer::Lexer::new`].
42///
43/// The lexer itself takes a borrowed slice — no I/O traits in its signature
44/// — so this is the recommended boundary between `Read` sources and the
45/// lexer.
46pub fn read_to_owned<R: Read>(mut r: R) -> io::Result<Vec<u8>> {
47 let mut buf = Vec::new();
48 r.read_to_end(&mut buf)?;
49 Ok(buf)
50}