mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Merge pull request #1994 from rtfeldman/wasm-long-string-literal
Wasm long string literal
This commit is contained in:
commit
64bb206d01
4 changed files with 21 additions and 58 deletions
|
@ -626,8 +626,8 @@ impl<'a> WasmBackend<'a> {
|
||||||
self.lookup_string_constant(string, sym, layout);
|
self.lookup_string_constant(string, sym, layout);
|
||||||
|
|
||||||
self.code_builder.get_local(local_id);
|
self.code_builder.get_local(local_id);
|
||||||
self.code_builder.insert_memory_relocation(linker_sym_index);
|
self.code_builder
|
||||||
self.code_builder.i32_const(elements_addr as i32);
|
.i32_const_mem_addr(elements_addr, linker_sym_index);
|
||||||
self.code_builder.i32_store(Align::Bytes4, offset);
|
self.code_builder.i32_store(Align::Bytes4, offset);
|
||||||
|
|
||||||
self.code_builder.get_local(local_id);
|
self.code_builder.get_local(local_id);
|
||||||
|
|
|
@ -9,7 +9,7 @@ use super::opcodes::{OpCode, OpCode::*};
|
||||||
use super::serialize::{SerialBuffer, Serialize};
|
use super::serialize::{SerialBuffer, Serialize};
|
||||||
use crate::{round_up_to_alignment, FRAME_ALIGNMENT_BYTES, STACK_POINTER_GLOBAL_ID};
|
use crate::{round_up_to_alignment, FRAME_ALIGNMENT_BYTES, STACK_POINTER_GLOBAL_ID};
|
||||||
|
|
||||||
const ENABLE_DEBUG_LOG: bool = true;
|
const ENABLE_DEBUG_LOG: bool = false;
|
||||||
macro_rules! log_instruction {
|
macro_rules! log_instruction {
|
||||||
($($x: expr),+) => {
|
($($x: expr),+) => {
|
||||||
if ENABLE_DEBUG_LOG { println!($($x,)*); }
|
if ENABLE_DEBUG_LOG { println!($($x,)*); }
|
||||||
|
@ -572,11 +572,14 @@ impl<'a> CodeBuilder<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a linker relocation for a memory address
|
/// Insert a const reference to a memory address
|
||||||
pub fn insert_memory_relocation(&mut self, symbol_index: u32) {
|
pub fn i32_const_mem_addr(&mut self, addr: u32, symbol_index: u32) {
|
||||||
|
self.inst_base(I32CONST, 0, true);
|
||||||
|
let offset = self.code.len() as u32;
|
||||||
|
self.code.encode_padded_u32(addr);
|
||||||
self.relocations.push(RelocationEntry::Offset {
|
self.relocations.push(RelocationEntry::Offset {
|
||||||
type_id: OffsetRelocType::MemoryAddrLeb,
|
type_id: OffsetRelocType::MemoryAddrLeb,
|
||||||
offset: self.code.len() as u32,
|
offset,
|
||||||
symbol_index,
|
symbol_index,
|
||||||
addend: 0,
|
addend: 0,
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,6 +29,8 @@ pub enum SectionId {
|
||||||
Element = 9,
|
Element = 9,
|
||||||
Code = 10,
|
Code = 10,
|
||||||
Data = 11,
|
Data = 11,
|
||||||
|
/// DataCount section is unused. Only needed for single-pass validation of
|
||||||
|
/// memory.init and data.drop, which we don't use
|
||||||
DataCount = 12,
|
DataCount = 12,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,42 +527,6 @@ impl Serialize for DataSection<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************
|
|
||||||
*
|
|
||||||
* Data Count section
|
|
||||||
*
|
|
||||||
* Pre-declares the number of segments in the Data section.
|
|
||||||
* This helps the runtime to validate the module in a single pass.
|
|
||||||
* The order of sections is DataCount -> Code -> Data
|
|
||||||
*
|
|
||||||
*******************************************************************/
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct DataCountSection {
|
|
||||||
count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DataCountSection {
|
|
||||||
fn new(data_section: &DataSection<'_>) -> Self {
|
|
||||||
let count = data_section
|
|
||||||
.segments
|
|
||||||
.iter()
|
|
||||||
.filter(|seg| !seg.init.is_empty())
|
|
||||||
.count() as u32;
|
|
||||||
DataCountSection { count }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for DataCountSection {
|
|
||||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
|
||||||
if self.count > 0 {
|
|
||||||
let header_indices = write_section_header(buffer, SectionId::DataCount);
|
|
||||||
buffer.encode_u32(self.count);
|
|
||||||
update_section_size(buffer, header_indices);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
*
|
*
|
||||||
* Module
|
* Module
|
||||||
|
@ -658,11 +624,6 @@ impl<'a> WasmModule<'a> {
|
||||||
counter.serialize_and_count(buffer, &self.start);
|
counter.serialize_and_count(buffer, &self.start);
|
||||||
counter.serialize_and_count(buffer, &self.element);
|
counter.serialize_and_count(buffer, &self.element);
|
||||||
|
|
||||||
// Data Count section forward-declares the size of the Data section
|
|
||||||
// so that Code section can be validated in one pass
|
|
||||||
let data_count_section = DataCountSection::new(&self.data);
|
|
||||||
counter.serialize_and_count(buffer, &data_count_section);
|
|
||||||
|
|
||||||
// Code section is the only one with relocations so we can stop counting
|
// Code section is the only one with relocations so we can stop counting
|
||||||
let code_section_index = counter.section_index;
|
let code_section_index = counter.section_index;
|
||||||
let code_section_body_index = self
|
let code_section_body_index = self
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Wasm pointers are only 32bit. This effects RocStr.
|
// Wasm pointers are only 32bit. This effects RocStr.
|
||||||
// These are versions of the str tests assuming 32bit pointers.
|
// These are versions of the str tests assuming 32bit pointers.
|
||||||
#![cfg(not(feature = "gen-dev"))]
|
#![cfg(feature = "gen-wasm")]
|
||||||
|
|
||||||
// TODO: We need to make these tests work with the llvm wasm backend.
|
// TODO: We need to make these tests work with the llvm wasm backend.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ use crate::helpers::wasm::assert_evals_to;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
// use roc_std::RocStr;
|
use roc_std::RocStr;
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn str_split_bigger_delimiter_small_str() {
|
// fn str_split_bigger_delimiter_small_str() {
|
||||||
|
@ -287,15 +287,14 @@ fn small_str_zeroed_literal() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix linking errors for undefined symbols roc_alloc, roc_dealloc
|
#[test]
|
||||||
// #[test]
|
fn long_str_literal() {
|
||||||
// fn long_str_literal() {
|
assert_evals_to!(
|
||||||
// assert_evals_to!(
|
"\"0123456789 123456789 123456789\"",
|
||||||
// "\"0123456789 123456789 123456789\"",
|
RocStr::from_slice(b"0123456789 123456789 123456789"),
|
||||||
// RocStr::from_slice(b"0123456789 123456789 123456789"),
|
RocStr
|
||||||
// RocStr
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn small_str_concat_empty_first_arg() {
|
// fn small_str_concat_empty_first_arg() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue