Skip to content

Commit

Permalink
refactor(codegen): re-export module wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Dec 23, 2023
1 parent 95b6990 commit eed4d9d
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 44 deletions.
14 changes: 11 additions & 3 deletions codegen/src/codegen/code/mod.rs → codegen/src/codegen/code.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Table for the code section.
pub use func::ExtFunc;
use indexmap::IndexMap;

mod func;

/// Code section for EVM.
#[derive(Clone, Default, Debug)]
pub struct Code {
Expand Down Expand Up @@ -68,3 +65,14 @@ impl Code {
code
}
}

/// External function in code section.
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
pub struct ExtFunc {
/// Stack input.
pub stack_out: u8,
/// Stack output.
pub stack_in: u8,
/// The bytecode of the external function.
pub bytecode: Vec<u8>,
}
27 changes: 0 additions & 27 deletions codegen/src/codegen/code/func.rs

This file was deleted.

5 changes: 4 additions & 1 deletion codegen/src/codegen/constructor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Contract constructor.
use crate::{wasm, Buffer, Function, JumpTable, MacroAssembler, Result, ToLSBytes};
use crate::{
wasm::{self, ToLSBytes},
Buffer, Function, JumpTable, MacroAssembler, Result,
};

/// Contract constructor.
///
Expand Down
5 changes: 3 additions & 2 deletions codegen/src/codegen/dispatcher.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Code generator for EVM dispatcher.
use crate::{
codegen::code::ExtFunc, wasm, Data, Error, Exports, Functions, Imports, JumpTable,
MacroAssembler, Result, ToLSBytes,
codegen::code::ExtFunc,
wasm::{self, Data, Exports, Functions, Imports, ToLSBytes},
Error, JumpTable, MacroAssembler, Result,
};
use wasmparser::{FuncType, Operator};
use zabi::Abi;
Expand Down
3 changes: 2 additions & 1 deletion codegen/src/codegen/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{
local::{LocalSlot, LocalSlotType, Locals},
masm::MacroAssembler,
validator::ValidateThenVisit,
Buffer, Data, Error, Imports, Result,
wasm::{Data, Imports},
Buffer, Error, Result,
};
use wasmparser::{FuncType, FuncValidator, LocalsReader, OperatorsReader, ValidatorResources};

Expand Down
3 changes: 2 additions & 1 deletion codegen/src/jump/relocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use crate::{
jump::{relocate, JumpTable},
Buffer, Error, Result, ToLSBytes, BUFFER_LIMIT,
wasm::ToLSBytes,
Buffer, Error, Result, BUFFER_LIMIT,
};
use opcodes::ShangHai as OpCode;

Expand Down
1 change: 0 additions & 1 deletion codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub use crate::{
local::{LocalSlot, Locals},
masm::MacroAssembler,
result::{Error, Result},
wasm::{Data, Exports, Functions, HostFunc, Imports, ToLSBytes, Type},
};
use smallvec::SmallVec;

Expand Down
5 changes: 4 additions & 1 deletion codegen/src/local.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! WASM local slot.
use crate::{Error, Result, ToLSBytes, Type};
use crate::{
wasm::{ToLSBytes, Type},
Error, Result,
};
use smallvec::SmallVec;
use wasmparser::ValType;

Expand Down
2 changes: 1 addition & 1 deletion codegen/src/masm/integer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Integer instructions

use crate::{MacroAssembler, Result, ToLSBytes};
use crate::{wasm::ToLSBytes, MacroAssembler, Result};
use wasmparser::{Ieee32, Ieee64};

impl MacroAssembler {
Expand Down
6 changes: 5 additions & 1 deletion codegen/src/masm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! MacroAssembler used by the code generation.
use crate::{asm::Assembler, Error, Result, ToLSBytes, Type};
use crate::{
asm::Assembler,
wasm::{ToLSBytes, Type},
Error, Result,
};
use smallvec::SmallVec;
use std::ops::{Deref, DerefMut};

Expand Down
2 changes: 1 addition & 1 deletion codegen/src/masm/ret.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Return handlers
use crate::{Error, MacroAssembler, Result, ToLSBytes};
use crate::{wasm::ToLSBytes, Error, MacroAssembler, Result};
use wasmparser::ValType;

impl MacroAssembler {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/visitor/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! System instructions
use crate::{masm::MemoryInfo, Error, Function, Result, ToLSBytes};
use crate::{masm::MemoryInfo, wasm::ToLSBytes, Error, Function, Result};

impl Function {
/// Parse log data from the bytecode.
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/wasm/func.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Function handler
use crate::{Error, Exports, Result};
use crate::{wasm::Exports, Error, Result};
use std::{
collections::BTreeMap,
ops::{Deref, DerefMut},
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use crate::{parser::Parser, Config, Error, Result};
use zabi::Abi;
use zingen::{
wasm, Buffer, Constructor, Data, Dispatcher, Function, Imports, JumpTable, BUFFER_LIMIT,
wasm::{self, Data, Imports},
Buffer, Constructor, Dispatcher, Function, JumpTable, BUFFER_LIMIT,
};

/// Zink Compiler
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasmparser::{
Data, DataKind, Export, ExternalKind, Import, Operator, Payload, SectionLimited, TypeRef,
ValidPayload, Validator,
};
use zingen::{wasm, Data as DataSet, Exports, Functions, HostFunc, Imports};
use zingen::wasm::{self, Data as DataSet, Exports, Functions, HostFunc, Imports};

/// WASM module parser
#[derive(Default)]
Expand Down

0 comments on commit eed4d9d

Please sign in to comment.