Skip to content
Permalink
Browse files

feat: rewriting the gas-estimation to be linear (#37)

  • Loading branch information
YaronWittenstein committed Nov 13, 2019
1 parent 6f08c7d commit 12d07bd86198828f98a1e5a1b8a5001ec39dfe99

Large diffs are not rendered by default.

@@ -10,7 +10,6 @@ publish = false
[dependencies]
parity-wasm = "0.40.2"
log = "0.4"
wasmparser = "0.39.2"

[dev-dependencies]
wabt = "0.7.4"
@@ -4,10 +4,9 @@ use crate::program::Program;
use std::collections::HashMap;

use parity_wasm::elements::{ImportCountType, Module};
use wasmparser::{Operator, Parser, ParserState, WasmDecoder};

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

let module: Module = parity_wasm::deserialize_buffer(wasm).unwrap();
@@ -27,48 +26,3 @@ pub(crate) fn read_program(wasm: &[u8]) -> Program {
imported_count,
}
}

#[allow(unused)]
pub(crate) fn parse_program(wasm: &[u8]) -> HashMap<FuncIndex, Vec<Operator>> {
let mut parser = Parser::new(wasm);
let mut function_readers = Vec::new();

while !(parser.eof()) {
match parser.read() {
ParserState::BeginFunctionBody { .. } => {
while !(parser.eof()) {
let reader = parser.create_binary_reader();
function_readers.push(reader);
}
}
_ => continue,
}
}

for (i, reader) in function_readers.iter_mut().enumerate() {
while let Ok(ref op) = reader.read_operator() {
//
}
}

panic!()

// let mut functions = HashMap::new();
//
// let module: Module = parity_wasm::deserialize_buffer(wasm).unwrap();
//
// let code_section = module.code_section().expect("no code section");
// let imported_count = module.import_count(ImportCountType::Function) as u32;
//
// for (i, func_body) in code_section.bodies().iter().enumerate() {
// let fn_idx = FuncIndex((i as u32) + imported_count);
// let fn_body = FuncBody(func_body.code().clone());
//
// functions.insert(fn_idx, fn_body);
// }
//
// Program {
// functions,
// imported_count,
// }
}

This file was deleted.

0 comments on commit 12d07bd

Please sign in to comment.
You can’t perform that action at this time.