mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
Get rid of some overcomplicated Data section stuff
Currently a Wasm module can only have one memory The Data Segment spec allows for more in future But the format is confusing enough already without that! Let's just get rid of that complexity, we don't need it.
This commit is contained in:
parent
c57d99c1ac
commit
1b91fd9533
1 changed files with 4 additions and 16 deletions
|
@ -476,18 +476,11 @@ impl<'a> CodeSection<'a> {
|
|||
|
||||
pub enum DataMode {
|
||||
/// A data segment that auto-initialises on instantiation
|
||||
Active { memidx: u32, offset: ConstExpr },
|
||||
Active { offset: ConstExpr },
|
||||
/// A data segment that can be initialised with the `memory.init` instruction
|
||||
Passive,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
enum DataModeEncoding {
|
||||
DefaultMemoryActive = 0,
|
||||
Passive = 1,
|
||||
ExplicitMemoryActive = 2,
|
||||
}
|
||||
|
||||
pub struct DataSegment<'a> {
|
||||
mode: DataMode,
|
||||
init: Vec<'a, u8>,
|
||||
|
@ -496,17 +489,12 @@ pub struct DataSegment<'a> {
|
|||
impl Serialize for DataSegment<'_> {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
match &self.mode {
|
||||
DataMode::Active { memidx, offset } => {
|
||||
if *memidx == 0 {
|
||||
buffer.append_u8(DataModeEncoding::DefaultMemoryActive as u8);
|
||||
} else {
|
||||
buffer.append_u8(DataModeEncoding::ExplicitMemoryActive as u8);
|
||||
buffer.encode_u32(*memidx);
|
||||
}
|
||||
DataMode::Active { offset } => {
|
||||
buffer.append_u8(0);
|
||||
offset.serialize(buffer);
|
||||
}
|
||||
DataMode::Passive => {
|
||||
buffer.append_u8(DataModeEncoding::Passive as u8);
|
||||
buffer.append_u8(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue