mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Skip relocations for test_wrapper since we don't run a linker on it anyway.
This commit is contained in:
parent
b541802819
commit
99b08ad395
4 changed files with 26 additions and 87 deletions
|
@ -441,7 +441,8 @@ impl<'a> CodeBuilder<'a> {
|
||||||
self.code.push(immediate);
|
self.code.push(immediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inst_imm32(&mut self, opcode: u8, pops: usize, push: bool, immediate: u32) {
|
// public for use in test code
|
||||||
|
pub fn inst_imm32(&mut self, opcode: u8, pops: usize, push: bool, immediate: u32) {
|
||||||
self.inst(opcode, pops, push);
|
self.inst(opcode, pops, push);
|
||||||
self.code.encode_u32(immediate);
|
self.code.encode_u32(immediate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@ pub mod code_builder;
|
||||||
pub mod from_wasm32_memory;
|
pub mod from_wasm32_memory;
|
||||||
mod layout;
|
mod layout;
|
||||||
pub mod module_builder;
|
pub mod module_builder;
|
||||||
|
pub mod opcodes;
|
||||||
pub mod serialize;
|
pub mod serialize;
|
||||||
mod storage;
|
mod storage;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
mod opcodes;
|
|
||||||
|
|
||||||
use bumpalo::{self, collections::Vec, Bump};
|
use bumpalo::{self, collections::Vec, Bump};
|
||||||
use parity_wasm::builder;
|
use parity_wasm::builder;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,10 @@ pub fn helper_wasm<'a, T: Wasm32TestResult>(
|
||||||
|
|
||||||
debug_assert_eq!(exposed_to_host.len(), 1);
|
debug_assert_eq!(exposed_to_host.len(), 1);
|
||||||
let main_fn_symbol = loaded.entry_point.symbol;
|
let main_fn_symbol = loaded.entry_point.symbol;
|
||||||
let main_fn_index = procedures.keys().position(|(s, _)| *s == main_fn_symbol).unwrap();
|
let main_fn_index = procedures
|
||||||
|
.keys()
|
||||||
|
.position(|(s, _)| *s == main_fn_symbol)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let exposed_to_host = exposed_to_host.keys().copied().collect::<MutSet<_>>();
|
let exposed_to_host = exposed_to_host.keys().copied().collect::<MutSet<_>>();
|
||||||
|
|
||||||
|
@ -110,7 +113,6 @@ pub fn helper_wasm<'a, T: Wasm32TestResult>(
|
||||||
&mut code_section_bytes,
|
&mut code_section_bytes,
|
||||||
TEST_WRAPPER_NAME,
|
TEST_WRAPPER_NAME,
|
||||||
main_fn_index as u32,
|
main_fn_index as u32,
|
||||||
main_fn_symbol
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut parity_module = builder.build();
|
let mut parity_module = builder.build();
|
||||||
|
|
|
@ -4,7 +4,6 @@ use parity_wasm::elements::Internal;
|
||||||
use roc_gen_wasm::code_builder::{Align, CodeBuilder, ValueType};
|
use roc_gen_wasm::code_builder::{Align, CodeBuilder, ValueType};
|
||||||
use roc_gen_wasm::from_wasm32_memory::FromWasm32Memory;
|
use roc_gen_wasm::from_wasm32_memory::FromWasm32Memory;
|
||||||
use roc_gen_wasm::{serialize::SerialBuffer, LocalId};
|
use roc_gen_wasm::{serialize::SerialBuffer, LocalId};
|
||||||
use roc_module::symbol::Symbol;
|
|
||||||
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
use roc_std::{RocDec, RocList, RocOrder, RocStr};
|
||||||
|
|
||||||
pub trait Wasm32TestResult {
|
pub trait Wasm32TestResult {
|
||||||
|
@ -14,7 +13,6 @@ pub trait Wasm32TestResult {
|
||||||
code_section_bytes: &mut std::vec::Vec<u8>,
|
code_section_bytes: &mut std::vec::Vec<u8>,
|
||||||
wrapper_name: &str,
|
wrapper_name: &str,
|
||||||
main_fn_index: u32,
|
main_fn_index: u32,
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
) {
|
||||||
let signature = builder::signature()
|
let signature = builder::signature()
|
||||||
.with_result(parity_wasm::elements::ValueType::I32)
|
.with_result(parity_wasm::elements::ValueType::I32)
|
||||||
|
@ -30,7 +28,7 @@ pub trait Wasm32TestResult {
|
||||||
module_builder.push_export(export);
|
module_builder.push_export(export);
|
||||||
|
|
||||||
let mut code_builder = CodeBuilder::new(arena);
|
let mut code_builder = CodeBuilder::new(arena);
|
||||||
Self::build_wrapper_body(&mut code_builder, main_fn_index, main_fn_symbol);
|
Self::build_wrapper_body(&mut code_builder, main_fn_index);
|
||||||
|
|
||||||
code_builder.serialize(code_section_bytes);
|
code_builder.serialize(code_section_bytes);
|
||||||
|
|
||||||
|
@ -43,27 +41,20 @@ pub trait Wasm32TestResult {
|
||||||
code_section_bytes.overwrite_padded_u32(5, num_procs + 1);
|
code_section_bytes.overwrite_padded_u32(5, num_procs + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32);
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! build_wrapper_body_primitive {
|
macro_rules! build_wrapper_body_primitive {
|
||||||
($store_instruction: ident, $align: expr) => {
|
($store_instruction: ident, $align: expr) => {
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
let frame_pointer_id = LocalId(0);
|
let frame_pointer_id = LocalId(0);
|
||||||
let frame_pointer = Some(frame_pointer_id);
|
let frame_pointer = Some(frame_pointer_id);
|
||||||
let local_types = &[ValueType::I32];
|
let local_types = &[ValueType::I32];
|
||||||
let frame_size = 8;
|
let frame_size = 8;
|
||||||
|
|
||||||
code_builder.get_local(frame_pointer_id);
|
code_builder.get_local(frame_pointer_id);
|
||||||
code_builder.call(main_fn_index, main_fn_symbol, 0, true);
|
// Raw "call" instruction. Don't bother with symbol & relocation since we're not going to link.
|
||||||
|
code_builder.inst_imm32(roc_gen_wasm::opcodes::CALL, 0, true, main_fn_index);
|
||||||
code_builder.$store_instruction($align, 0);
|
code_builder.$store_instruction($align, 0);
|
||||||
code_builder.get_local(frame_pointer_id);
|
code_builder.get_local(frame_pointer_id);
|
||||||
|
|
||||||
|
@ -83,7 +74,6 @@ macro_rules! wasm_test_result_primitive {
|
||||||
fn build_wrapper_body_stack_memory(
|
fn build_wrapper_body_stack_memory(
|
||||||
code_builder: &mut CodeBuilder,
|
code_builder: &mut CodeBuilder,
|
||||||
main_fn_index: u32,
|
main_fn_index: u32,
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
size: usize,
|
size: usize,
|
||||||
) {
|
) {
|
||||||
let local_id = LocalId(0);
|
let local_id = LocalId(0);
|
||||||
|
@ -91,7 +81,8 @@ fn build_wrapper_body_stack_memory(
|
||||||
let frame_pointer = Some(local_id);
|
let frame_pointer = Some(local_id);
|
||||||
|
|
||||||
code_builder.get_local(local_id);
|
code_builder.get_local(local_id);
|
||||||
code_builder.call(main_fn_index, main_fn_symbol, 0, true);
|
// Raw "call" instruction. Don't bother with symbol & relocation since we're not going to link.
|
||||||
|
code_builder.inst_imm32(roc_gen_wasm::opcodes::CALL, 0, true, main_fn_index);
|
||||||
code_builder.get_local(local_id);
|
code_builder.get_local(local_id);
|
||||||
code_builder.finalize(local_types, size as i32, frame_pointer);
|
code_builder.finalize(local_types, size as i32, frame_pointer);
|
||||||
}
|
}
|
||||||
|
@ -99,15 +90,10 @@ fn build_wrapper_body_stack_memory(
|
||||||
macro_rules! wasm_test_result_stack_memory {
|
macro_rules! wasm_test_result_stack_memory {
|
||||||
($type_name: ident) => {
|
($type_name: ident) => {
|
||||||
impl Wasm32TestResult for $type_name {
|
impl Wasm32TestResult for $type_name {
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
$type_name::ACTUAL_WIDTH,
|
$type_name::ACTUAL_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -136,12 +122,8 @@ wasm_test_result_stack_memory!(RocDec);
|
||||||
wasm_test_result_stack_memory!(RocStr);
|
wasm_test_result_stack_memory!(RocStr);
|
||||||
|
|
||||||
impl<T: Wasm32TestResult> Wasm32TestResult for RocList<T> {
|
impl<T: Wasm32TestResult> Wasm32TestResult for RocList<T> {
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
build_wrapper_body_stack_memory(code_builder, main_fn_index, 12)
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(code_builder, main_fn_index, main_fn_symbol, 12)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,17 +135,8 @@ impl<T, const N: usize> Wasm32TestResult for [T; N]
|
||||||
where
|
where
|
||||||
T: Wasm32TestResult + FromWasm32Memory,
|
T: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
build_wrapper_body_stack_memory(code_builder, main_fn_index, N * T::ACTUAL_WIDTH)
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
|
||||||
code_builder,
|
|
||||||
main_fn_index,
|
|
||||||
main_fn_symbol,
|
|
||||||
N * T::ACTUAL_WIDTH,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,15 +145,10 @@ where
|
||||||
T: Wasm32TestResult + FromWasm32Memory,
|
T: Wasm32TestResult + FromWasm32Memory,
|
||||||
U: Wasm32TestResult + FromWasm32Memory,
|
U: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH,
|
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -192,15 +160,10 @@ where
|
||||||
U: Wasm32TestResult + FromWasm32Memory,
|
U: Wasm32TestResult + FromWasm32Memory,
|
||||||
V: Wasm32TestResult + FromWasm32Memory,
|
V: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH,
|
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -213,15 +176,10 @@ where
|
||||||
V: Wasm32TestResult + FromWasm32Memory,
|
V: Wasm32TestResult + FromWasm32Memory,
|
||||||
W: Wasm32TestResult + FromWasm32Memory,
|
W: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH,
|
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -235,15 +193,10 @@ where
|
||||||
W: Wasm32TestResult + FromWasm32Memory,
|
W: Wasm32TestResult + FromWasm32Memory,
|
||||||
X: Wasm32TestResult + FromWasm32Memory,
|
X: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH + X::ACTUAL_WIDTH,
|
T::ACTUAL_WIDTH + U::ACTUAL_WIDTH + V::ACTUAL_WIDTH + W::ACTUAL_WIDTH + X::ACTUAL_WIDTH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -258,15 +211,10 @@ where
|
||||||
X: Wasm32TestResult + FromWasm32Memory,
|
X: Wasm32TestResult + FromWasm32Memory,
|
||||||
Y: Wasm32TestResult + FromWasm32Memory,
|
Y: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH
|
T::ACTUAL_WIDTH
|
||||||
+ U::ACTUAL_WIDTH
|
+ U::ACTUAL_WIDTH
|
||||||
+ V::ACTUAL_WIDTH
|
+ V::ACTUAL_WIDTH
|
||||||
|
@ -287,15 +235,10 @@ where
|
||||||
Y: Wasm32TestResult + FromWasm32Memory,
|
Y: Wasm32TestResult + FromWasm32Memory,
|
||||||
Z: Wasm32TestResult + FromWasm32Memory,
|
Z: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH
|
T::ACTUAL_WIDTH
|
||||||
+ U::ACTUAL_WIDTH
|
+ U::ACTUAL_WIDTH
|
||||||
+ V::ACTUAL_WIDTH
|
+ V::ACTUAL_WIDTH
|
||||||
|
@ -318,15 +261,10 @@ where
|
||||||
Z: Wasm32TestResult + FromWasm32Memory,
|
Z: Wasm32TestResult + FromWasm32Memory,
|
||||||
A: Wasm32TestResult + FromWasm32Memory,
|
A: Wasm32TestResult + FromWasm32Memory,
|
||||||
{
|
{
|
||||||
fn build_wrapper_body(
|
fn build_wrapper_body(code_builder: &mut CodeBuilder, main_fn_index: u32) {
|
||||||
code_builder: &mut CodeBuilder,
|
|
||||||
main_fn_index: u32,
|
|
||||||
main_fn_symbol: Symbol,
|
|
||||||
) {
|
|
||||||
build_wrapper_body_stack_memory(
|
build_wrapper_body_stack_memory(
|
||||||
code_builder,
|
code_builder,
|
||||||
main_fn_index,
|
main_fn_index,
|
||||||
main_fn_symbol,
|
|
||||||
T::ACTUAL_WIDTH
|
T::ACTUAL_WIDTH
|
||||||
+ U::ACTUAL_WIDTH
|
+ U::ACTUAL_WIDTH
|
||||||
+ V::ACTUAL_WIDTH
|
+ V::ACTUAL_WIDTH
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue