This commit is contained in:
Sergey Pepyakin 2018-06-29 14:24:02 +03:00
parent b94f9f2ab7
commit 856a34ca25
2 changed files with 14 additions and 14 deletions

View File

@ -4,7 +4,7 @@ use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::collections::HashMap; use std::collections::HashMap;
use parity_wasm::elements::{External, InitExpr, Internal, Opcode, ResizableLimits, Type}; use parity_wasm::elements::{External, InitExpr, Internal, Instruction, ResizableLimits, Type};
use {Module, Error, Signature, MemoryInstance, RuntimeValue, TableInstance}; use {Module, Error, Signature, MemoryInstance, RuntimeValue, TableInstance};
use imports::ImportResolver; use imports::ImportResolver;
use global::{GlobalInstance, GlobalRef}; use global::{GlobalInstance, GlobalRef};
@ -708,11 +708,11 @@ fn eval_init_expr(init_expr: &InitExpr, module: &ModuleInstance) -> RuntimeValue
"Due to validation `code`.len() should be 2" "Due to validation `code`.len() should be 2"
); );
match code[0] { match code[0] {
Opcode::I32Const(v) => v.into(), Instruction::I32Const(v) => v.into(),
Opcode::I64Const(v) => v.into(), Instruction::I64Const(v) => v.into(),
Opcode::F32Const(v) => RuntimeValue::decode_f32(v), Instruction::F32Const(v) => RuntimeValue::decode_f32(v),
Opcode::F64Const(v) => RuntimeValue::decode_f64(v), Instruction::F64Const(v) => RuntimeValue::decode_f64(v),
Opcode::GetGlobal(idx) => { Instruction::GetGlobal(idx) => {
let global = module.global_by_index(idx).expect( let global = module.global_by_index(idx).expect(
"Due to validation global should exists in module", "Due to validation global should exists in module",
); );

View File

@ -1,5 +1,5 @@
use std::u32; use std::u32;
use parity_wasm::elements::{Opcode, BlockType, ValueType, TableElementType, Func, FuncBody}; use parity_wasm::elements::{Instruction, BlockType, ValueType, TableElementType, Func, FuncBody};
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use validation::context::ModuleContext; use validation::context::ModuleContext;
@ -196,17 +196,17 @@ impl FunctionReader {
Ok(context.into_code()) Ok(context.into_code())
} }
fn read_function_body(context: &mut FunctionValidationContext, body: &[Opcode]) -> Result<(), Error> { fn read_function_body(context: &mut FunctionValidationContext, body: &[Instruction]) -> Result<(), Error> {
let body_len = body.len(); let body_len = body.len();
if body_len == 0 { if body_len == 0 {
return Err(Error("Non-empty function body expected".into())); return Err(Error("Non-empty function body expected".into()));
} }
loop { loop {
let opcode = &body[context.position]; let instruction = &body[context.position];
let outcome = FunctionReader::read_instruction(context, opcode) let outcome = FunctionReader::read_instruction(context, instruction)
.map_err(|err| Error(format!("At instruction {:?}(@{}): {}", opcode, context.position, err)))?; .map_err(|err| Error(format!("At instruction {:?}(@{}): {}", instruction, context.position, err)))?;
match outcome { match outcome {
Outcome::NextInstruction => (), Outcome::NextInstruction => (),
@ -223,9 +223,9 @@ impl FunctionReader {
} }
} }
fn read_instruction(context: &mut FunctionValidationContext, opcode: &Opcode) -> Result<Outcome, Error> { fn read_instruction(context: &mut FunctionValidationContext, instruction: &Instruction) -> Result<Outcome, Error> {
use self::Opcode::*; use self::Instruction::*;
match *opcode { match *instruction {
// Nop instruction doesn't do anything. It is safe to just skip it. // Nop instruction doesn't do anything. It is safe to just skip it.
Nop => {}, Nop => {},