use std::cell::RefCell; use std::collections::HashMap; use std::sync::atomic::AtomicU32; pub use parse_instr::parse_instructions; use crate::asm::data::literal::{ConstantName, RegisterAlias, Value}; use crate::asm::data::Register; use crate::asm::error::CrsnError; use crate::asm::instr::Op; use crate::asm::parse::sexp_expect::expect_list; use crate::module::CrsnExtension; pub mod parse_cond; pub mod parse_instr; pub mod parse_data; pub mod sexp_expect; pub mod parse_op; pub mod arg_parser; pub mod parse_routine; pub struct ParserContext<'a> { /// Extension modules pub parsers: &'a [Box], /// Mutable state pub state: RefCell, } pub struct ParserState { /// Register aliases within the routine pub reg_aliases: HashMap, /// The old reg aliases map is pushed here when entering a routine definition pub reg_alias_stack: Vec>, /// Global constants pub constants: HashMap, } pub fn parse(source: &str, parsers: &ParserContext) -> Result, CrsnError> { let items = expect_list(Some(sexp::parse(source)?), true)?; let label_num = AtomicU32::new(0); parse_instructions(items.into_iter(), parsers)? .flatten(&label_num) }