Expand description
§tpt-uir-text
Human-readable textual format for the TPT Unified Intermediate Representation (TPT-UIR).
This crate provides a hand-written lexer and recursive-descent parser (no
nom/pest) plus a pretty-printer. It complements the binary formats in
tpt-uir-serde and tpt-uir-flatbuffers.
§Installation
Not yet on crates.io — depend on it via git or a path within this workspace:
[dependencies]
tpt-uir-text = { git = "https://github.com/tpt-solutions/tpt-uir", package = "tpt-uir-text" }§Format
- Blocks start with
^bb<n>and may declare arguments:^bb0(%0: tensor<f32, shape<1, n>>, %1: index): - Operations:
#<id>: %<result> = "dialect.op"(%operands) { attrs } [nested regions] - Types:
index,tensor<scalar, shape<dims>> - Shapes:
shape<d0, d1, ...>where a dim is128(fixed),n(symbolic), orm:1024(bounded) - Quantization:
quant<block_size, bytes_per_block, num_blocks, scales?> - Attributes:
key = valuewith valuesi64,f64,"string",tensor<...>,shape<...>,opname("dialect.op"), orquant<...>
§Example
use tpt_uir_core::{OpName, Region, Block, Operation, validate_region, Type};
use tpt_uir_text::{to_text, parse_text, Pretty};
let region = Region {
blocks: vec![Block {
arguments: vec![(0u32, Type::Index)],
operations: vec![Operation {
id: 1,
op_name: OpName::parse("core.add").unwrap(),
operands: vec![0],
results: vec![1],
regions: vec![],
attributes: vec![],
}],
}],
};
let text = to_text(®ion);
let back = parse_text(&text).unwrap();
assert_eq!(region, back);
assert!(validate_region(&back).is_ok());See CHANGELOG.md for release notes.
§License
Licensed under either of MIT or Apache-2.0 at your option.
Re-exports§
pub use parse::parse as parse_text_raw;
Modules§
- lex
- Lexer for the TPT-UIR textual format.
- parse
- Recursive-descent parser for the TPT-UIR textual format.
- Pretty-printing of the TPT-UIR IR into the textual format.
Structs§
- Parse
Error - Error produced while parsing the textual TPT-UIR format.
- Pretty
- Wrapper that pretty-prints a
Regionvia itsDisplayimplementation.
Functions§
- parse_
text - Parse a textual TPT-UIR string into a
Region. - to_text
- Serialize a
Regionto the textual TPT-UIR format.