mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-28 14:11:57 +00:00
global builder to module
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use super::invoke::{Invoke, Identity};
|
||||
use super::code::{self, SignaturesBuilder, FunctionBuilder};
|
||||
use super::{import, export};
|
||||
use super::{import, export, global};
|
||||
use elements;
|
||||
|
||||
/// Module builder
|
||||
@ -248,12 +248,18 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
||||
self
|
||||
}
|
||||
|
||||
/// With inserted import entry
|
||||
/// With inserted export entry
|
||||
pub fn with_export(mut self, entry: elements::ExportEntry) -> Self {
|
||||
self.module.export.entries_mut().push(entry);
|
||||
self
|
||||
}
|
||||
|
||||
/// With inserted global entry
|
||||
pub fn with_global(mut self, entry: elements::GlobalEntry) -> Self {
|
||||
self.module.global.entries_mut().push(entry);
|
||||
self
|
||||
}
|
||||
|
||||
/// Import entry builder
|
||||
pub fn import(self) -> import::ImportBuilder<Self> {
|
||||
import::ImportBuilder::with_callback(self)
|
||||
@ -264,6 +270,11 @@ impl<F> ModuleBuilder<F> where F: Invoke<elements::Module> {
|
||||
export::ExportBuilder::with_callback(self)
|
||||
}
|
||||
|
||||
/// Glboal entry builder
|
||||
pub fn global(self) -> global::GlobalBuilder<Self> {
|
||||
global::GlobalBuilder::with_callback(self)
|
||||
}
|
||||
|
||||
/// Build module (final step)
|
||||
pub fn build(self) -> F::Result {
|
||||
self.callback.invoke(self.module.into())
|
||||
@ -323,6 +334,16 @@ impl<F> Invoke<elements::ExportEntry> for ModuleBuilder<F>
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Invoke<elements::GlobalEntry> for ModuleBuilder<F>
|
||||
where F: Invoke<elements::Module>
|
||||
{
|
||||
type Result = Self;
|
||||
|
||||
fn invoke(self, entry: elements::GlobalEntry) -> Self::Result {
|
||||
self.with_global(entry)
|
||||
}
|
||||
}
|
||||
|
||||
/// Start new module builder
|
||||
pub fn module() -> ModuleBuilder {
|
||||
ModuleBuilder::new()
|
||||
@ -366,4 +387,13 @@ mod tests {
|
||||
|
||||
assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global() {
|
||||
let module = module()
|
||||
.global().value_type().i64().mutable().init_expr(::elements::Opcode::I64Const(5)).build()
|
||||
.build();
|
||||
|
||||
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user