Path: blob/main/cranelift/reader/src/testfile.rs
2450 views
//! Data structures representing a parsed test file.1//!2//! A test file is a `.clif` file which contains test commands and settings for running a3//! file-based test case.4//!56use crate::error::Location;7use crate::isaspec::IsaSpec;8use crate::sourcemap::SourceMap;9use crate::testcommand::TestCommand;10use cranelift_codegen::ir::Function;11use cranelift_codegen::ir::entities::AnyEntity;1213/// A parsed test case.14///15/// This is the result of parsing a `.clif` file which contains a number of test commands and ISA16/// specs followed by the functions that should be tested.17pub struct TestFile<'a> {18/// `test foo ...` lines.19pub commands: Vec<TestCommand<'a>>,20/// `isa bar ...` lines.21pub isa_spec: IsaSpec,22/// `feature ...` lines23pub features: Vec<Feature<'a>>,24/// Comments appearing before the first function.25/// These are all tagged as 'Function' scope for lack of a better entity.26pub preamble_comments: Vec<Comment<'a>>,27/// Parsed functions and additional details about each function.28pub functions: Vec<(Function, Details<'a>)>,29}3031/// Additional details about a function parsed from a text string.32/// These are useful for detecting test commands embedded in comments etc.33/// The details to not affect the semantics of the function.34#[derive(Debug)]35pub struct Details<'a> {36/// Location of the `function` keyword that begins this function.37pub location: Location,38/// Annotation comments that appeared inside or after the function.39pub comments: Vec<Comment<'a>>,40/// Mapping of entity numbers to source locations.41pub map: SourceMap,42}4344/// A comment in a parsed function.45///46/// The comment belongs to the immediately preceding entity, whether that is a block header, and47/// instruction, or one of the preamble declarations.48///49/// Comments appearing inside the function but before the preamble, as well as comments appearing50/// after the function are tagged as `AnyEntity::Function`.51#[derive(Clone, PartialEq, Eq, Debug)]52pub struct Comment<'a> {53/// The entity this comment is attached to.54/// Comments always follow their entity.55pub entity: AnyEntity,56/// Text of the comment, including the leading `;`.57pub text: &'a str,58}5960/// A cranelift feature in a test file preamble.61///62/// This represents the expectation of the test case. Before running any of the63/// functions of the test file, the feature set should be compared with the64/// feature set used to compile Cranelift. If there is any differences, then the65/// test file should be skipped.66#[derive(PartialEq, Eq, Debug)]67pub enum Feature<'a> {68/// `feature "..."` lines69With(&'a str),70/// `feature ! "..."` lines.71Without(&'a str),72}737475