Skip to content

Commit

Permalink
fix lint warnings and add wasm2wat verification to integration_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ejrgilbert committed May 3, 2024
1 parent f33ed52 commit 518fed6
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 253 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: supplypike/setup-bin@v4
with:
uri: 'https://github.com/WebAssembly/wabt/releases/download/1.0.34/wabt-1.0.34-ubuntu.tar.gz'
name: 'wabt'
version: '1.0.34'
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
91 changes: 36 additions & 55 deletions src/generator/emitters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn emit_stmt(table: &mut SymbolTable, module_data: &mut ModuleData, mem_id: &Mem
} else {
is_success &= emit_expr(table, module_data, mem_id, curr_mem_offset, expr, instr_builder, index);

if let Expr::VarId { name } = var_id {
return if let Expr::VarId { name } = var_id {
let var_rec_id = match table.lookup(name) {
Some(rec_id) => rec_id.clone(),
_ => {
Expand Down Expand Up @@ -124,23 +124,23 @@ fn emit_stmt(table: &mut SymbolTable, module_data: &mut ModuleData, mem_id: &Mem
unimplemented!()
}
}
return is_success;
is_success
},
Some(ty) => {
error!("Incorrect variable record, expected Record::Var, found: {:?}", ty);
is_success &= false;
return is_success
is_success
},
None => {
error!("Variable symbol does not exist!");
is_success &= false;
return is_success
is_success
}
}
} else {
error!("Expected VarId.");
is_success &= false;
return is_success
is_success
}
}
}
Expand Down Expand Up @@ -577,6 +577,16 @@ impl WasmRewritingEmitter {
is_success
}

fn override_var_val(&mut self, rec_id: &usize, val: Option<Value>) {
let mut rec = self.table.get_record_mut(&rec_id);
match &mut rec {
Some(Record::Var { value, .. }) => {
*value = val;
}
_ => {}
}
}

fn preprocess_instr(&mut self, instr: &Instr, function: &mut Function) -> Option<Vec<ValType>> {
if function.name.to_lowercase() == "call" {
if let Instr::Call(func) = &instr {
Expand Down Expand Up @@ -617,17 +627,11 @@ impl WasmRewritingEmitter {
return Some(params);
}
};
let mut rec = self.table.get_record_mut(&rec_id);
match &mut rec {
Some(Record::Var { value, .. }) => {
*value = Some(Value::Str {
ty: DataType::Str,
val: func_kind.to_string(),
addr: None
});
}
_ => {}
}
self.override_var_val(&rec_id, Some(Value::Str {
ty: DataType::Str,
val: func_kind.to_string(),
addr: None
}));

let tuple = function.globals.get_mut("target_fn_type").unwrap();
tuple.2 = Some(Value::Str {
Expand All @@ -643,17 +647,12 @@ impl WasmRewritingEmitter {
return Some(params);
}
};
let mut rec = self.table.get_record_mut(&rec_id);
match &mut rec {
Some(Record::Var { value, .. }) => {
*value = Some(Value::Str {
ty: DataType::Str,
val: module.clone(),
addr: None
});
}
_ => {}
}
self.override_var_val(&rec_id, Some(Value::Str {
ty: DataType::Str,
val: module.clone(),
addr: None
}));

let tuple = function.globals.get_mut("target_imp_module").unwrap();
tuple.2 = Some(Value::Str {
ty: DataType::Str,
Expand All @@ -668,17 +667,12 @@ impl WasmRewritingEmitter {
return Some(params);
}
};
let mut rec = self.table.get_record_mut(&rec_id);
match &mut rec {
Some(Record::Var { value, .. }) => {
*value = Some(Value::Str {
ty: DataType::Str,
val: name.clone(),
addr: None
});
}
_ => {}
}
self.override_var_val(&rec_id, Some(Value::Str {
ty: DataType::Str,
val: name.clone(),
addr: None
}));

let tuple = function.globals.get_mut("target_imp_name").unwrap();
tuple.2 = Some(Value::Str {
ty: DataType::Str,
Expand Down Expand Up @@ -1030,28 +1024,15 @@ impl WasmRewritingEmitter {
};

if let Some(f_call_id) = func_call_id {
// we need to inject an alternate call to the specified fn name!
// replace the arguments
self.emit_params(&emitted_params, func_id, &instr_seq_id, index);

// This MUST be `self.app_wasm` so we're mutating what will be the instrumented application.
let func = self.app_wasm.funcs.get_mut(func_id).kind.unwrap_local_mut();
let func_builder = func.builder_mut();
let mut instr_seq = func_builder.instr_seq(*instr_seq_id);

// we need to inject an alternate call to the specified fn name!
// replace the arguments
if let Some(params) = emitted_params {
for (_param_name, param_rec_id) in params.iter() {
let param_rec = self.table.get_record_mut(&param_rec_id);
if let Some(Record::Var { addr: Some(VarAddr::Local {addr}), .. }) = param_rec {
instr_seq.instr_at(*index, walrus::ir::LocalGet {
local: addr.clone()
});
*index += 1;
} else {
error!("Could not inject alternate call to function, something went wrong...");
exit(1);
}
}
}

// inject call
instr_seq.instr_at(*index, walrus::ir::Call {
func: f_call_id.clone()
Expand Down
4 changes: 2 additions & 2 deletions src/generator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn assert_simplified_predicate(pred: &Expr) {
fn basic_run(script: &str) {
match tests::get_ast(script) {
Some(whamm) => {
let mut table = verifier::verify(&whamm);
let mut table = verifier::verify(&whamm, false);
table.reset();

let pred = get_pred(&whamm);
Expand Down Expand Up @@ -210,7 +210,7 @@ wasm::call:alt /

match tests::get_ast(script) {
Some(whamm) => {
let mut table = verifier::verify(&whamm);
let mut table = verifier::verify(&whamm, false);
table.reset();

let pred = get_pred(&whamm);
Expand Down
Loading

0 comments on commit 518fed6

Please sign in to comment.