forked from MightyPork/crsn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
948 B
34 lines
948 B
use std::cell::RefCell;
|
|
use std::sync::Arc;
|
|
|
|
use crate::asm::parse::{ParserContext, ParserState};
|
|
use crate::module::CrsnExtension;
|
|
use crate::runtime::program::Program;
|
|
|
|
pub mod data;
|
|
pub mod error;
|
|
pub mod instr;
|
|
pub mod parse;
|
|
pub mod patches;
|
|
|
|
/// Parse a program from string and assemble a low level instruction sequence from it.
|
|
pub fn assemble(source: &str, parsers: Arc<Vec<Box<dyn CrsnExtension>>>) -> Result<Arc<Program>, error::CrsnError> {
|
|
let pcx = ParserContext {
|
|
parsers: &parsers,
|
|
state: RefCell::new(ParserState {
|
|
reg_aliases: Default::default(),
|
|
reg_alias_stack: vec![],
|
|
constants: Default::default(),
|
|
}),
|
|
};
|
|
|
|
let ops = parse::parse(source, &pcx)?;
|
|
|
|
trace!("--- Compiled program ---");
|
|
for (n, op) in ops.iter().enumerate() {
|
|
trace!("{:04} : {:?}", n, op);
|
|
}
|
|
trace!("------------------------");
|
|
|
|
Ok(Program::new(ops, parsers)?)
|
|
}
|
|
|