Skip to content

Commit

Permalink
run cargo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Jan 9, 2024
1 parent 652430d commit cba9e0d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
60 changes: 34 additions & 26 deletions crates/replay_gen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub fn generate_standalone(wasm_path: &Path, code: &Replay) -> std::io::Result<(
let mut current = 0;
for r in func.results.iter() {
let ty = code.func_idx_to_ty.get(&(funcidx as usize)).unwrap();
let param_tys = ty.params.clone();
let _param_tys = ty.params.clone();
let new_c = current + r.reps;
let res = match r.results.get(0) {
Some(v) => format!(
Expand All @@ -240,7 +240,7 @@ pub fn generate_standalone(wasm_path: &Path, code: &Replay) -> std::io::Result<(
current = new_c;
}
let ty = code.func_idx_to_ty.get(&(funcidx as usize)).unwrap();
let param_tys = ty.params.clone();
let _param_tys = ty.params.clone();
let default_return = match ty.results.get(0) {
Some(v) => match v {
ValType::I32 => "(i32.const 0)",
Expand Down Expand Up @@ -306,14 +306,14 @@ pub fn generate_standalone(wasm_path: &Path, code: &Replay) -> std::io::Result<(
"("
};

let to_write = (first_part.to_string()
let to_write = first_part.to_string()
+ &format!(
"{}{} {:?}){})",
hack_for_diff_format,
&valty_to_const(&global.value),
&global.initial,
fourth_part
));
);
write(stream, &to_write)?;
write(stream, "\n")?;
}
Expand Down Expand Up @@ -374,15 +374,19 @@ fn hostevent_to_js(event: &HostEvent) -> String {
.join(",")
}
let str = match event {
HostEvent::ExportCall { idx, name, params } => {
HostEvent::ExportCall {
idx: _,
name,
params,
} => {
format!(
"instance.exports.{}({})\n",
name,
write_params_string(&params)
)
}
HostEvent::ExportCallTable {
idx,
idx: _,
table_name,
funcidx,
params,
Expand Down Expand Up @@ -432,8 +436,8 @@ fn hostevent_to_js(event: &HostEvent) -> String {
}
}
HostEvent::MutateTable {
tableidx,
funcidx,
tableidx: _,
funcidx: _,
idx,
func_import,
func_name,
Expand All @@ -454,7 +458,7 @@ fn hostevent_to_js(event: &HostEvent) -> String {
js_string
}
HostEvent::GrowTable {
idx,
idx: _,
amount,
import,
name,
Expand All @@ -466,7 +470,7 @@ fn hostevent_to_js(event: &HostEvent) -> String {
}
}
HostEvent::MutateGlobal {
idx,
idx: _,
value,
valtype,
import,
Expand All @@ -492,7 +496,11 @@ fn hostevent_to_js(event: &HostEvent) -> String {

fn hostevent_to_wat(event: &HostEvent, code: &Replay) -> String {
let str = match event {
HostEvent::ExportCall { idx, name, params } => {
HostEvent::ExportCall {
idx,
name: _,
params,
} => {
let ty = code.func_idx_to_ty.get(&(*idx as usize)).unwrap();
let param_tys = ty.params.clone();
let result_count = ty.results.len();
Expand All @@ -507,8 +515,8 @@ fn hostevent_to_wat(event: &HostEvent, code: &Replay) -> String {
}
HostEvent::ExportCallTable {
idx,
table_name,
funcidx,
table_name: _,
funcidx: _,
params,
} => {
let ty = code.func_idx_to_ty.get(&(*idx as usize)).unwrap();
Expand All @@ -526,8 +534,8 @@ fn hostevent_to_wat(event: &HostEvent, code: &Replay) -> String {
HostEvent::MutateMemory {
addr,
data,
import,
name,
import: _,
name: _,
} => {
let mut js_string = String::new();
for (j, byte) in data.iter().enumerate() {
Expand All @@ -539,39 +547,39 @@ fn hostevent_to_wat(event: &HostEvent, code: &Replay) -> String {
}
HostEvent::GrowMemory {
amount,
import,
name,
import: _,
name: _,
} => {
format!("(memory.grow (i32.const {})) (drop)\n", amount)
}
HostEvent::MutateTable {
tableidx,
funcidx,
idx,
func_import,
func_name,
import,
name,
func_import: _,
func_name: _,
import: _,
name: _,
} => {
format!(
"(table.set {} (i32.const {}) (ref.func {}))",
tableidx, idx, funcidx
)
}
HostEvent::GrowTable {
idx,
idx: _,
amount,
import,
name,
import: _,
name: _,
} => {
format!("(table.grow (i32.const {})) (drop)\n", amount)
}
HostEvent::MutateGlobal {
idx,
value,
valtype,
import,
name,
import: _,
name: _,
} => {
let valtype = match valtype {
ValType::I32 => "i32.const",
Expand Down
2 changes: 1 addition & 1 deletion crates/replay_gen/src/irgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl IRGenerator {
for i in module.imports.iter() {
match i.kind {
walrus::ImportKind::Function(f) => {
let ty = module.types.get(module.funcs.get(f).ty());
let _ty = module.types.get(module.funcs.get(f).ty());
func_imports.insert(
f.index() as i32,
Function {
Expand Down
5 changes: 2 additions & 3 deletions crates/replay_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod tests {
use core::panic;

use crate::{
codegen::generate_javascript, irgen::IRGenerator, opt::merge_fn_results,
trace::encode_trace,
};

Expand Down Expand Up @@ -98,10 +97,10 @@ mod tests {
use std::io;
use std::io::BufRead;
use std::io::Read;
use std::io::{Seek, SeekFrom};


use std::path::Path;
use tempfile::tempfile;


fn visit_dirs(dir: &Path) -> io::Result<()> {
if dir.is_dir() {
Expand Down
6 changes: 3 additions & 3 deletions crates/replay_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::fs::File;
use std::io::{self, BufRead, Write};
use std::io::{self, BufRead};
use std::path::Path;
use std::process::Command;

use std::{env, fs};

use replay_gen::codegen::{generate_javascript, generate_standalone, write};
use replay_gen::codegen::{generate_javascript, generate_standalone};
use replay_gen::irgen::IRGenerator;
use replay_gen::opt::merge_fn_results;
use replay_gen::trace;
Expand Down
18 changes: 0 additions & 18 deletions crates/replay_gen/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,6 @@ impl From<walrus::ValType> for ValType {
}
}

fn from_short_str(s: &str) -> Result<ValType, ()> {
match s {
"i" => Ok(ValType::I32),
"I" => Ok(ValType::I64),
"f" => Ok(ValType::F32),
"F" => Ok(ValType::F64),
_ => Err(()),
}
}

fn join_vec(args: &Vec<F64>) -> String {
args.iter()
.map(|x| x.to_string())
Expand Down Expand Up @@ -217,14 +207,6 @@ fn test_parse_number() {
assert_ne!(s, parse_number(s).unwrap().to_string());
}

fn parse_tys(s: &str) -> Vec<ValType> {
let mut tys = vec![];
for ty in s.chars() {
tys.push(from_short_str(&ty.to_string()).unwrap());
}
tys
}

#[derive(Debug)]
pub enum ErrorKind {
LegacyTrace,
Expand Down

0 comments on commit cba9e0d

Please sign in to comment.