Estimate capacity.
This commit is contained in:
parent
e7381bfdde
commit
98570fc1d7
|
@ -1,7 +1,7 @@
|
|||
#[allow(unused_imports)]
|
||||
use alloc::prelude::v1::*;
|
||||
|
||||
use parity_wasm::elements::{BlockType, Instruction};
|
||||
use parity_wasm::elements::{BlockType, Instruction, FuncBody};
|
||||
|
||||
use validation::func::{
|
||||
require_label, top_label, BlockFrame, FunctionValidationContext, StackValueType, StartedWith,
|
||||
|
@ -69,9 +69,10 @@ pub struct Compiler {
|
|||
|
||||
impl FuncValidator for Compiler {
|
||||
type Output = isa::Instructions;
|
||||
fn new(_module: &FunctionValidationContext) -> Self {
|
||||
fn new(_ctx: &FunctionValidationContext, body: &FuncBody) -> Self {
|
||||
let code_len = body.code().elements().len();
|
||||
let mut compiler = Compiler {
|
||||
sink: Sink::with_instruction_capacity(0), // TODO: Estimate instruction count.
|
||||
sink: Sink::with_instruction_capacity(code_len),
|
||||
label_stack: Vec::new(),
|
||||
};
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ pub fn drive<T: FuncValidator>(
|
|||
result_ty,
|
||||
);
|
||||
|
||||
let mut validator = T::new(&context);
|
||||
let mut validator = T::new(&context, body);
|
||||
|
||||
for (position, instruction) in code.iter().enumerate() {
|
||||
validator
|
||||
|
|
|
@ -35,7 +35,7 @@ use std::collections::HashSet;
|
|||
use self::context::ModuleContextBuilder;
|
||||
use parity_wasm::elements::{
|
||||
BlockType, External, GlobalEntry, GlobalType, InitExpr, Instruction, Internal, MemoryType,
|
||||
Module, ResizableLimits, TableType, Type, ValueType,
|
||||
Module, ResizableLimits, TableType, Type, ValueType, FuncBody,
|
||||
};
|
||||
|
||||
pub mod context;
|
||||
|
@ -83,7 +83,10 @@ pub trait Validator {
|
|||
|
||||
pub trait FuncValidator {
|
||||
type Output;
|
||||
fn new(ctx: &func::FunctionValidationContext) -> Self;
|
||||
fn new(
|
||||
ctx: &func::FunctionValidationContext,
|
||||
body: &FuncBody,
|
||||
) -> Self;
|
||||
fn next_instruction(
|
||||
&mut self,
|
||||
ctx: &mut func::FunctionValidationContext,
|
||||
|
@ -119,7 +122,7 @@ pub struct PlainFuncValidator;
|
|||
impl FuncValidator for PlainFuncValidator {
|
||||
type Output = ();
|
||||
|
||||
fn new(_ctx: &func::FunctionValidationContext) -> PlainFuncValidator {
|
||||
fn new(_ctx: &func::FunctionValidationContext, _body: &FuncBody) -> PlainFuncValidator {
|
||||
PlainFuncValidator
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue