Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Commit 12d07bd

Browse files
feat: rewriting the gas-estimation to be linear (#37)
1 parent 6f08c7d commit 12d07bd

10 files changed

+985
-1093
lines changed

Cargo.lock

+152-143
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/svm-gas/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ publish = false
1010
[dependencies]
1111
parity-wasm = "0.40.2"
1212
log = "0.4"
13-
wasmparser = "0.39.2"
1413

1514
[dev-dependencies]
1615
wabt = "0.7.4"

crates/svm-gas/src/code_reader.rs

+2-48
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use crate::program::Program;
44
use std::collections::HashMap;
55

66
use parity_wasm::elements::{ImportCountType, Module};
7-
use wasmparser::{Operator, Parser, ParserState, WasmDecoder};
87

9-
#[allow(unused)]
10-
pub(crate) fn read_program(wasm: &[u8]) -> Program {
8+
/// Reads wasm input and contruct a `Program` struct
9+
pub fn read_program(wasm: &[u8]) -> Program {
1110
let mut functions = HashMap::new();
1211

1312
let module: Module = parity_wasm::deserialize_buffer(wasm).unwrap();
@@ -27,48 +26,3 @@ pub(crate) fn read_program(wasm: &[u8]) -> Program {
2726
imported_count,
2827
}
2928
}
30-
31-
#[allow(unused)]
32-
pub(crate) fn parse_program(wasm: &[u8]) -> HashMap<FuncIndex, Vec<Operator>> {
33-
let mut parser = Parser::new(wasm);
34-
let mut function_readers = Vec::new();
35-
36-
while !(parser.eof()) {
37-
match parser.read() {
38-
ParserState::BeginFunctionBody { .. } => {
39-
while !(parser.eof()) {
40-
let reader = parser.create_binary_reader();
41-
function_readers.push(reader);
42-
}
43-
}
44-
_ => continue,
45-
}
46-
}
47-
48-
for (i, reader) in function_readers.iter_mut().enumerate() {
49-
while let Ok(ref op) = reader.read_operator() {
50-
//
51-
}
52-
}
53-
54-
panic!()
55-
56-
// let mut functions = HashMap::new();
57-
//
58-
// let module: Module = parity_wasm::deserialize_buffer(wasm).unwrap();
59-
//
60-
// let code_section = module.code_section().expect("no code section");
61-
// let imported_count = module.import_count(ImportCountType::Function) as u32;
62-
//
63-
// for (i, func_body) in code_section.bodies().iter().enumerate() {
64-
// let fn_idx = FuncIndex((i as u32) + imported_count);
65-
// let fn_body = FuncBody(func_body.code().clone());
66-
//
67-
// functions.insert(fn_idx, fn_body);
68-
// }
69-
//
70-
// Program {
71-
// functions,
72-
// imported_count,
73-
// }
74-
}

crates/svm-gas/src/cursor.rs

-35
This file was deleted.

0 commit comments

Comments
 (0)