Skip to content

Commit

Permalink
Rename 'whammy' to 'script'
Browse files Browse the repository at this point in the history
  • Loading branch information
ejrgilbert committed May 29, 2024
1 parent c76395f commit 3bc64e8
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 169 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ cargo test parser # Only run the tests for the `parser` module
cargo test -- --nocapture # With stdout tracing
```

To run project (there are example Whammys in `tests/whammys` folder):
To run project (there are example Scripts in `tests/scripts` folder):
```shell
cargo run -- instr --app <path_to_app_wasm> --whammy <path_to_whammy> <path_for_compiled_output>
cargo run -- instr --app <path_to_app_wasm> --script <path_to_script> <path_for_compiled_output>
```

To specify log level:
```shell
RUST_LOG={ error | warn | info | debug | trace | off } cargo run -- --app <path_to_app_wasm> --whammy <path_to_whammy> <path_for_compiled_output>
RUST_LOG={ error | warn | info | debug | trace | off } cargo run -- --app <path_to_app_wasm> --script <path_to_script> <path_for_compiled_output>
```

To visually debug the decision tree used during Wasm bytecode emission:
```shell
cargo run -- vis-whammy --whammy <path_to_whammy>
cargo run -- vis-script --script <path_to_script>
```

## Available Packages ##
Expand Down
26 changes: 13 additions & 13 deletions src/behavior/builder_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::behavior::tree::{ActionWithChildType, BehaviorTree, DecoratorType};

use std::collections::HashMap;
use crate::parser::types as parser_types;
use parser_types::{DataType, Whammy, Whamm, WhammVisitor, Expr, Fn, Event, Package, Op, Probe, Provider, Statement, Value};
use parser_types::{DataType, Script, Whamm, WhammVisitor, Expr, Fn, Event, Package, Op, Probe, Provider, Statement, Value};

use log::{debug, trace};
use regex::Regex;
Expand Down Expand Up @@ -301,8 +301,8 @@ impl WhammVisitor<()> for BehaviorTreeBuilder<'_> {
// visit globals
self.visit_provided_globals(&whamm.globals);

// visit whammys
whamm.whammys.iter().for_each(| whammy | self.visit_whammy(whammy));
// visit scripts
whamm.scripts.iter().for_each(| script | self.visit_script(script));

// self.tree.exit_scope();

Expand All @@ -312,22 +312,22 @@ impl WhammVisitor<()> for BehaviorTreeBuilder<'_> {
self.context_name = "".to_string();
}

fn visit_whammy(&mut self, whammy: &Whammy) -> () {
trace!("Entering: BehaviorTreeBuilder::visit_whammy");
self.context_name += &format!(":{}", whammy.name.clone());
fn visit_script(&mut self, script: &Script) -> () {
trace!("Entering: BehaviorTreeBuilder::visit_script");
self.context_name += &format!(":{}", script.name.clone());

self.tree.enter_scope(self.context_name.clone(), whammy.name.clone(), self.err);
self.tree.enter_scope(self.context_name.clone(), script.name.clone(), self.err);

// visit globals
self.visit_globals(&whammy.globals);
self.visit_globals(&script.globals);

whammy.providers.iter().for_each(| (_name, provider) | {
script.providers.iter().for_each(| (_name, provider) | {
self.visit_provider(provider)
});

self.tree.exit_scope(self.err);

trace!("Exiting: BehaviorTreeBuilder::visit_whammy");
trace!("Exiting: BehaviorTreeBuilder::visit_script");
// Remove from `context_name`
self.context_name = self.context_name[..self.context_name.rfind(":").unwrap()].to_string();
}
Expand Down Expand Up @@ -358,7 +358,7 @@ impl WhammVisitor<()> for BehaviorTreeBuilder<'_> {
self.context_name += &format!(":{}", package.name.clone());
self.add_package_to_ast(package.name.clone());

if self.is_in_context(r"whamm:whammy([0-9]+):wasm:bytecode") {
if self.is_in_context(r"whamm:script([0-9]+):wasm:bytecode") {
self.visit_bytecode_package(package);
} else {
if let Some(loc) = &package.loc {
Expand All @@ -378,7 +378,7 @@ impl WhammVisitor<()> for BehaviorTreeBuilder<'_> {
self.context_name += &format!(":{}", event.name.clone());
self.add_event_to_ast(event.name.clone());

if self.is_in_context(r"whamm:whammy([0-9]+):wasm:bytecode:(.*)") {
if self.is_in_context(r"whamm:script([0-9]+):wasm:bytecode:(.*)") {
self.visit_bytecode_event(event);
} else {
if let Some(loc) = &event.loc {
Expand All @@ -404,7 +404,7 @@ impl WhammVisitor<()> for BehaviorTreeBuilder<'_> {
global_names: probe.globals.keys().cloned().collect(),
}, self.err);

if self.is_in_context(r"whamm:whammy([0-9]+):wasm:bytecode:(.*)") {
if self.is_in_context(r"whamm:script([0-9]+):wasm:bytecode:(.*)") {
self.visit_bytecode_probe(probe);
} else {
self.err.unexpected_error(true, Some(format!("Probe not supported! {}", self.context_name)), None);
Expand Down
18 changes: 9 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Args, Parser, Subcommand};

/// `whamm` instruments a Wasm application with the Probes defined in the specified Whammy.
/// `whamm` instruments a Wasm application with the Probes defined in the specified Script.
#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
pub struct WhammCli {
Expand Down Expand Up @@ -49,13 +49,13 @@ pub(crate) enum Cmd {
output_path: String,
},

/// To visualize the generated behavior tree from the specified `whammy`
VisWhammy {
/// The path to the `whammy` file we want to visualize.
/// To visualize the generated behavior tree from the specified `script`
VisScript {
/// The path to the `script` file we want to visualize.
#[clap(short, long, value_parser)]
whammy: String,
script: String,

/// Whether to run the verifier on the specified whammy
/// Whether to run the verifier on the specified script
#[clap(long, short, action, default_value = "false")] // TODO -- change this default value to true when I have this implemented
run_verifier: bool,

Expand All @@ -75,9 +75,9 @@ pub struct InstrArgs {
/// The path to the application's Wasm module we want to instrument.
#[arg(short, long, value_parser)]
pub app: String,
/// The path to the Whammy containing the instrumentation Probe definitions.
/// The path to the Script containing the instrumentation Probe definitions.
#[arg(short, long, value_parser)]
pub whammy: String,
pub script: String,
/// The path that the instrumented version of the Wasm app should be output to.
#[arg(short, long, value_parser, default_value = "./output/output.wasm")]
pub output_path: String,
Expand All @@ -86,7 +86,7 @@ pub struct InstrArgs {
#[arg(short, long, action, default_value = "false")]
pub virgil: bool,

/// Whether to run the verifier on the specified whammy
/// Whether to run the verifier on the specified script
#[arg(long, short, action, default_value = "false")] // TODO -- change this default value to true when I have this implemented
pub run_verifier: bool
}
Expand Down
18 changes: 9 additions & 9 deletions src/common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const ERR_UNDERLINE_CHAR: char = '^';
const INFO_UNDERLINE_CHAR: char = '-';

pub struct ErrorGen {
whammy_path: String,
script_path: String,
script_text: String,
max_errors: i32,
errors: Vec<WhammError>,
Expand All @@ -21,9 +21,9 @@ pub struct ErrorGen {
pub has_errors: bool
}
impl ErrorGen {
pub fn new(whammy_path: String, script_text: String, max_errors: i32) -> Self {
pub fn new(script_path: String, script_text: String, max_errors: i32) -> Self {
Self {
whammy_path,
script_path,
script_text,
max_errors,
errors: vec![],
Expand Down Expand Up @@ -58,7 +58,7 @@ impl ErrorGen {
pub fn report(&mut self) {
// Report the most-recent error first
self.errors.iter_mut().for_each(|error| {
error.report(&self.script_text, &self.whammy_path);
error.report(&self.script_text, &self.script_path);
});
self.errors.clear();
}
Expand Down Expand Up @@ -451,7 +451,7 @@ impl WhammError {
}

/// report this error to the console, including color highlighting
pub fn report(&mut self, script: &String, whammy_path: &String) {
pub fn report(&mut self, script: &String, script_path: &String) {
let spacing = self.spacing();
let message = self.ty.message();

Expand All @@ -466,7 +466,7 @@ impl WhammError {
err_loc.message = Some(message.clone().to_string());
}

print_preamble(&err_loc.line_col, whammy_path, &spacing, &mut buffer);
print_preamble(&err_loc.line_col, script_path, &spacing, &mut buffer);
print_empty(&spacing, &mut buffer);
let err_start = match &err_loc.line_col {
LineColLocation::Pos((line, _)) => line,
Expand Down Expand Up @@ -499,7 +499,7 @@ impl WhammError {
} else {
// This error isn't tied to a specific code location
blue(false, format!(" --> "), &mut buffer);
blue(false, format!("{whammy_path}\n\n"), &mut buffer);
blue(false, format!("{script_path}\n\n"), &mut buffer);
}
writer.print(&buffer).expect("Uh oh, something went wrong while printing to terminal");
buffer.reset().expect("Uh oh, something went wrong while printing to terminal");
Expand Down Expand Up @@ -648,14 +648,14 @@ impl ErrorType {
}


fn print_preamble(line_col: &LineColLocation, whammy_path: &String, s: &String, buffer: &mut Buffer) {
fn print_preamble(line_col: &LineColLocation, script_path: &String, s: &String, buffer: &mut Buffer) {
let (ls, c) = match line_col {
LineColLocation::Pos(line_col) => line_col,
LineColLocation::Span(start_line_col, _) => start_line_col
};

blue(false, format!("{s}--> "), buffer);
blue(false, format!("{whammy_path}:"), buffer);
blue(false, format!("{script_path}:"), buffer);
blue(false, format!("{ls}:{c}\n"), buffer);
}

Expand Down
8 changes: 4 additions & 4 deletions src/generator/emitters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ impl Emitter for WasmRewritingEmitter {
}

fn define_compiler_var(&mut self, context: &String, var_name: &String) -> Result<bool, WhammError> {
let regex = Regex::new(r"whamm:whammy([0-9]+):wasm:bytecode").unwrap();
let regex = Regex::new(r"whamm:script([0-9]+):wasm:bytecode").unwrap();
return if let Some(_caps) = regex.captures(context) {
match var_name.as_str() {
"new_target_fn_name" => {
Expand Down Expand Up @@ -1127,12 +1127,12 @@ impl Emitter for WasmRewritingEmitter {
}

// emit non-provided fn
// only when we're supporting user-defined fns in whammy...
// only when we're supporting user-defined fns in script...
unimplemented!();
}

fn emit_formal_param(&mut self, _param: &(Expr, DataType)) -> bool {
// only when we're supporting user-defined fns in whammy...
// only when we're supporting user-defined fns in script...
unimplemented!();
}

Expand All @@ -1148,7 +1148,7 @@ impl Emitter for WasmRewritingEmitter {
return match rec {
Some(Record::Var { addr: _addr, .. }) => {
// emit global variable and set addr in symbol table
// only when we're supporting user-defined globals in whammy...
// only when we're supporting user-defined globals in script...
unimplemented!();
},
Some(ty) => {
Expand Down
22 changes: 11 additions & 11 deletions src/generator/init_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use log::{trace, warn};
use crate::common::error::ErrorGen;
use crate::generator::emitters::Emitter;
use crate::parser::types::{DataType, Whammy, Whamm, WhammVisitorMut, Expr, Event, Package, Op, Probe, Provider, Statement, Value, Global, ProvidedFunctionality};
use crate::parser::types::{DataType, Script, Whamm, WhammVisitorMut, Expr, Event, Package, Op, Probe, Provider, Statement, Value, Global, ProvidedFunctionality};

/// Serves as the first phase of instrumenting a module by setting up
/// the groundwork.
Expand Down Expand Up @@ -72,9 +72,9 @@ impl WhammVisitorMut<bool> for InitGenerator<'_> {
});
// inject globals
is_success &= self.visit_provided_globals(&whamm.globals);
// visit whammys
whamm.whammys.iter_mut().for_each(|whammy| {
is_success &= self.visit_whammy(whammy);
// visit scripts
whamm.scripts.iter_mut().for_each(|script| {
is_success &= self.visit_script(script);
});

trace!("Exiting: CodeGenerator::visit_whamm");
Expand All @@ -83,27 +83,27 @@ impl WhammVisitorMut<bool> for InitGenerator<'_> {
is_success
}

fn visit_whammy(&mut self, whammy: &mut Whammy) -> bool {
trace!("Entering: CodeGenerator::visit_whammy");
fn visit_script(&mut self, script: &mut Script) -> bool {
trace!("Entering: CodeGenerator::visit_script");
match self.emitter.enter_scope() {
Err(e) => self.err.add_error(e),
_ => {}
}
self.context_name += &format!(":{}", whammy.name.clone());
self.context_name += &format!(":{}", script.name.clone());
let mut is_success = true;

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

trace!("Exiting: CodeGenerator::visit_whammy");
trace!("Exiting: CodeGenerator::visit_script");
match self.emitter.exit_scope() {
Err(e) => self.err.add_error(e),
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/instr_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl InstrGenerator<'_, '_> {

let mut spec_split = context.split(":");
if let Some(_whamm) = spec_split.next() {
if let Some(_whammy) = spec_split.next() {
if let Some(_script) = spec_split.next() {
if let Some(provider) = spec_split.next() {
self.curr_provider_name = provider.to_string();
if let Some(package) = spec_split.next() {
Expand Down
4 changes: 2 additions & 2 deletions src/generator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn get_rec<'a>(table: &'a mut SymbolTable, name: &str) -> Option<&'a mut Record>
}

fn get_pred(whamm: &Whamm) -> &Expr {
whamm.whammys.get(0).unwrap()
whamm.scripts.get(0).unwrap()
.providers.get("wasm").unwrap()
.packages.get("bytecode").unwrap()
.events.get("call").unwrap()
Expand Down Expand Up @@ -73,7 +73,7 @@ fn hardcode_compiler_constants(table: &mut SymbolTable, err: &mut ErrorGen) {
},
_ => {}
}
move_through_scopes_til_match(ScopeType::Whammy, table, err);
move_through_scopes_til_match(ScopeType::Script, table, err);
println!("Scope name: {}", table.get_curr_scope().unwrap().name);
// enter wasm scope
match table.enter_scope() {
Expand Down
Loading

0 comments on commit 3bc64e8

Please sign in to comment.