mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-29 22:51:56 +00:00
code builder initial
This commit is contained in:
@ -177,6 +177,40 @@ impl<F> SignaturesBuilder<F> where F: Invoke<SignatureBindings> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FunctionDefinition {
|
||||
pub signature: Signature,
|
||||
pub code: elements::FuncBody,
|
||||
}
|
||||
|
||||
impl Default for FunctionDefinition {
|
||||
fn default() -> Self {
|
||||
FunctionDefinition {
|
||||
signature: Signature::TypeReference(0),
|
||||
code: elements::FuncBody::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FunctionBuilder<F=Identity> {
|
||||
callback: F,
|
||||
code: FunctionDefinition,
|
||||
}
|
||||
|
||||
impl FunctionBuilder {
|
||||
pub fn new() -> Self {
|
||||
FunctionBuilder::with_callback(Identity)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> FunctionBuilder<F> where F: Invoke<FunctionDefinition> {
|
||||
pub fn with_callback(callback: F) -> Self {
|
||||
FunctionBuilder {
|
||||
callback: callback,
|
||||
code: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// New function builder.
|
||||
pub fn signatures() -> SignaturesBuilder {
|
||||
SignaturesBuilder::new()
|
||||
|
@ -68,6 +68,11 @@ impl FuncBody {
|
||||
FuncBody { locals: locals, opcodes: opcodes }
|
||||
}
|
||||
|
||||
/// List of individual opcodes
|
||||
pub fn empty() -> Self {
|
||||
FuncBody { locals: Vec::new(), opcodes: Opcodes::empty() }
|
||||
}
|
||||
|
||||
/// Locals declared in function body.
|
||||
pub fn locals(&self) -> &[Local] { &self.locals }
|
||||
|
||||
|
@ -15,6 +15,11 @@ impl Opcodes {
|
||||
Opcodes(elements)
|
||||
}
|
||||
|
||||
/// Empty expression with only `Opcode::End` opcode
|
||||
pub fn empty() -> Self {
|
||||
Opcodes(vec![Opcode::End])
|
||||
}
|
||||
|
||||
/// List of individual opcodes
|
||||
pub fn elements(&self) -> &[Opcode] { &self.0 }
|
||||
}
|
||||
|
Reference in New Issue
Block a user