Restructuring into multiple crates and projects

This commit is contained in:
Henrik Böving
2021-03-05 19:10:18 +01:00
parent 00d0d7aba3
commit d67eda2edc
26 changed files with 6467 additions and 76 deletions

28
hm-asm-web/src/lib.rs Normal file
View File

@@ -0,0 +1,28 @@
use pest::Parser;
use wasm_bindgen::prelude::*;
use hm_asm_simulator::{
generate::generate_binary,
parse::{parse_asm, AsmParser, Rule},
};
#[wasm_bindgen]
pub fn simulate(code: &str, cycles: usize) -> JsValue {
let instructions = parse_asm(
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
);
let states = hm_asm_simulator::simulate::simulate(instructions, cycles);
JsValue::from_serde(&states).unwrap()
}
#[wasm_bindgen]
pub fn assemble(code: &str) -> JsValue {
let instructions = parse_asm(
AsmParser::parse(Rule::program, &code).unwrap_or_else(|e| panic!("{}", e)),
);
let binary = generate_binary(instructions);
JsValue::from_serde(&binary).unwrap()
}