Skip to content

Commit

Permalink
Merge pull request #13 from ejrgilbert/task/reorganize_code
Browse files Browse the repository at this point in the history
Task/reorganize code
  • Loading branch information
ejrgilbert authored May 3, 2024
2 parents 0983327 + 04c3658 commit a30efe1
Show file tree
Hide file tree
Showing 29 changed files with 428 additions and 489 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/apps/* linguist-vendored
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Cargo.lock
*.pdb

# Ignore the huge test files
tests/apps/*
tests/apps/*.wat
output/
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</picture>

# whamm! #
![build](https://github.com/ejrgilbert/whamm/actions/workflows/rust.yml/badge.svg)

## Debugging Wasm? Put some `whamm!` on it! ##

Expand All @@ -24,12 +25,12 @@ cargo test parser # Only run the tests for the `parser` module
cargo test -- --nocapture # With stdout tracing
```

To run project (there are example MMScripts in `tests/mmscripts` folder):
To run project (there are example Whammys in `tests/whammys` folder):
```shell
cargo run -- --app <path_to_app_wasm> --mm <path_to_mmscript> <path_for_compiled_output>
cargo run -- --app <path_to_app_wasm> --mm <path_to_whammy> <path_for_compiled_output>
```

To specify log level:
```shell
RUST_LOG={ error | warn | info | debug | trace | off } cargo run -- --app <path_to_app_wasm> --mm <path_to_mmscript> <path_for_compiled_output>
RUST_LOG={ error | warn | info | debug | trace | off } cargo run -- --app <path_to_app_wasm> --mm <path_to_whammy> <path_for_compiled_output>
```
26 changes: 14 additions & 12 deletions src/generator/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::collections::HashMap;
use log::trace;
use crate::generator::emitters::Emitter;
use crate::parser::types::{DataType, MMScript, Whamm, WhammVisitorMut, Expr, Function, Module, Op, Probe, Provider, Statement, Value};
use crate::parser::types::{DataType, Whammy, Whamm, WhammVisitorMut, Expr, Function, Module, Op, Probe, Provider, Statement, Value};

/// The code generator traverses the AST and calls the passed emitter to
/// emit some instruction/code/function/etc.
Expand Down Expand Up @@ -50,9 +50,9 @@ impl WhammVisitorMut<bool> for CodeGenerator {
is_success &= self.visit_fn(f);
});
// DO NOT inject globals (used by compiler)
// inject mmscripts
whamm.mmscripts.iter_mut().for_each(|mmscript| {
is_success &= self.visit_mmscript(mmscript);
// inject whammys
whamm.whammys.iter_mut().for_each(|whammy| {
is_success &= self.visit_whammy(whammy);
});

trace!("Exiting: CodeGenerator::visit_whamm");
Expand All @@ -61,24 +61,24 @@ impl WhammVisitorMut<bool> for CodeGenerator {
is_success
}

fn visit_mmscript(&mut self, mmscript: &mut MMScript) -> bool {
trace!("Entering: CodeGenerator::visit_mmscript");
fn visit_whammy(&mut self, whammy: &mut Whammy) -> bool {
trace!("Entering: CodeGenerator::visit_whammy");
self.emitter.enter_scope();
self.context_name += &format!(":{}", mmscript.name.clone());
let mut is_success = self.emitter.emit_mmscript(mmscript);
self.context_name += &format!(":{}", whammy.name.clone());
let mut is_success = self.emitter.emit_whammy(whammy);

// visit fns
mmscript.fns.iter_mut().for_each(| f | {
whammy.fns.iter_mut().for_each(| f | {
is_success &= self.visit_fn(f);
});
// inject globals
is_success &= self.visit_globals(&mmscript.globals);
is_success &= self.visit_globals(&whammy.globals);
// inject providers
mmscript.providers.iter_mut().for_each(|(_name, provider)| {
whammy.providers.iter_mut().for_each(|(_name, provider)| {
is_success &= self.visit_provider(provider);
});

trace!("Exiting: CodeGenerator::visit_mmscript");
trace!("Exiting: CodeGenerator::visit_whammy");
self.emitter.exit_scope();
// Remove from `context_name`
self.context_name = self.context_name[..self.context_name.rfind(":").unwrap()].to_string();
Expand All @@ -104,6 +104,8 @@ impl WhammVisitorMut<bool> for CodeGenerator {
// At this point we've traversed the entire tree to generate necessary
// globals and fns!
// Now, we emit_provider which will do the actual instrumentation step!
// TODO -- this isn't flexible at all...need to visit with the generator to help generalize
// the visiting logic
self.emitter.reset_children();
is_success &= self.emitter.emit_provider(&self.context_name, provider);

Expand Down
Loading

0 comments on commit a30efe1

Please sign in to comment.