From 86da6439d12f2cafc263576464577641bff02e11 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 22 Jan 2019 15:15:17 +0300 Subject: [PATCH] data and elements --- src/graph.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/graph.rs b/src/graph.rs index dcfc32e..89d090b 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -48,14 +48,20 @@ struct Table { limits: elements::ResizableLimits, } +enum SegmentLocation { + Passive, + Default(Vec), + WithIndex(u32, Vec), +} + struct DataSegment { - offset_expr: Vec, - data: Vec, + location: SegmentLocation, + value: Vec, } struct ElementSegment { - offset_expr: Vec, - data: Vec, + location: SegmentLocation, + value: Vec, } enum ExportLocal { @@ -180,6 +186,44 @@ impl Module { res.exports.push(Export { local: local, name: e.field().to_owned() }) } }, + elements::Section::Start(start_func) => { + res.start = Some(res.funcs.clone_ref(*start_func as usize)); + }, + elements::Section::Element(element_section) => { + for element_segment in element_section.entries() { + + // let location = if element_segment.passive() { + // SegmentLocation::Passive + // } else if element_segment.index() == 0 { + // // TODO: transform instructions + // SegmentLocation::Default(Vec::new()) + // } else { + // // TODO: transform instructions + // SegmentLocation::WithIndex(element_segment.index(), Vec::new()) + // }; + + // TODO: transform instructions + // TODO: update parity-wasm and uncomment the above + let location = SegmentLocation::Default(Vec::new()); + + res.elements.push(ElementSegment { + value: element_segment.members().to_vec(), + location: location, + }); + } + }, + elements::Section::Data(data_section) => { + for data_segment in data_section.entries() { + // TODO: transform instructions + // TODO: update parity-wasm and uncomment the above + let location = SegmentLocation::Default(Vec::new()); + + res.data.push(DataSegment { + value: data_segment.value().to_vec(), + location: location, + }); + } + } _ => continue, } }