diff --git a/cranelift/src/libreader/lib.rs b/cranelift/src/libreader/lib.rs index 519fee7eed..d435b4ac3b 100644 --- a/cranelift/src/libreader/lib.rs +++ b/cranelift/src/libreader/lib.rs @@ -5,9 +5,11 @@ extern crate cretonne; -pub use parser::{Result, parse_functions}; +pub use parser::{Result, parse_functions, parse_test}; pub use testcommand::{TestCommand, TestOption}; +pub use testfile::TestFile; mod lexer; mod parser; mod testcommand; +mod testfile; diff --git a/cranelift/src/libreader/parser.rs b/cranelift/src/libreader/parser.rs index 2ae1629c80..e9d77c67d7 100644 --- a/cranelift/src/libreader/parser.rs +++ b/cranelift/src/libreader/parser.rs @@ -18,6 +18,7 @@ use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64}; use cretonne::ir::entities::{NO_EBB, NO_VALUE}; use cretonne::ir::instructions::{InstructionFormat, InstructionData, VariableArgs, JumpData, BranchData, ReturnData}; +use testfile::TestFile; pub use lexer::Location; @@ -28,6 +29,14 @@ pub fn parse_functions(text: &str) -> Result> { Parser::new(text).parse_function_list() } +/// Parse the entire `text` as a test case file. +/// +/// The returned `TestFile` contains direct references to substrings of `text`. +pub fn parse_test<'a>(text: &'a str) -> Result> { + Parser::new(text); + unimplemented!() +} + /// A parse error is returned when the parse failed. #[derive(Debug)] pub struct Error { diff --git a/cranelift/src/libreader/testfile.rs b/cranelift/src/libreader/testfile.rs new file mode 100644 index 0000000000..34eddb4c6b --- /dev/null +++ b/cranelift/src/libreader/testfile.rs @@ -0,0 +1,40 @@ +//! Data structures representing a parsed test file. +//! +//! A test file is a `.cton` file which contains test commands and settings for running a +//! file-based test case. +//! + +use cretonne::ir::Function; +use cretonne::ir::entities::AnyEntity; +use testcommand::TestCommand; + +/// A parsed test case. +/// +/// This is the result of parsing a `.cton` file which contains a number of test commands followed +/// by the functions that should be tested. +#[derive(Debug)] +pub struct TestFile<'a> { + pub commands: Vec>, + pub functions: Vec>, +} + +/// A function parsed from a text string along with other details that are useful for running +/// tests. +#[derive(Debug)] +pub struct DetailedFunction<'a> { + pub function: Function, + pub comments: Vec>, +} + +/// A comment in a parsed function. +/// +/// The comment belongs to the immediately preceeding entity, whether that is an EBB header, and +/// instruction, or one of the preamble declarations. +/// +/// Comments appearing inside the function but before the preamble, as well as comments appearing +/// after the function are tagged as `AnyEntity::Function`. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct Comment<'a> { + pub entity: AnyEntity, + pub text: &'a str, +}