Use roc_target over target_lexicon

Tailors a target class for our needs.
Replaces tons of uses across the entire compiler.
This is a base for later adding new targets like thumb.
This commit is contained in:
Brendan Hansknecht 2024-03-21 21:54:58 -07:00
parent 185262510c
commit 6dc5bfb1b7
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
72 changed files with 1008 additions and 1371 deletions

View file

@ -31,8 +31,7 @@ use crate::layout::{ReturnMethod, WasmLayout};
use crate::low_level::{call_higher_order_lowlevel, LowLevelCall};
use crate::storage::{AddressValue, Storage, StoredValue, StoredVarKind};
use crate::{
copy_memory, CopyMemoryConfig, Env, DEBUG_SETTINGS, MEMORY_NAME, PTR_SIZE, PTR_TYPE,
TARGET_INFO,
copy_memory, CopyMemoryConfig, Env, DEBUG_SETTINGS, MEMORY_NAME, PTR_SIZE, PTR_TYPE, TARGET,
};
#[derive(Clone, Copy, Debug)]
@ -1651,8 +1650,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
return;
}
let stores_tag_id_as_data = union_layout.stores_tag_id_as_data(TARGET_INFO);
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET_INFO);
let stores_tag_id_as_data = union_layout.stores_tag_id_as_data(TARGET);
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET);
let (data_size, data_alignment) =
union_layout.data_size_and_alignment(self.layout_interner);
@ -1774,7 +1773,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
}
};
if union_layout.stores_tag_id_as_data(TARGET_INFO) {
if union_layout.stores_tag_id_as_data(TARGET) {
let id_offset = union_layout.tag_id_offset(self.layout_interner).unwrap();
let id_align = union_layout.discriminant().alignment_bytes();
@ -1788,7 +1787,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
U0 | U1 | U8 => self.code_builder.i32_load8_u(id_align, id_offset),
U16 => self.code_builder.i32_load16_u(id_align, id_offset),
}
} else if union_layout.stores_tag_id_in_pointer(TARGET_INFO) {
} else if union_layout.stores_tag_id_in_pointer(TARGET) {
self.storage
.load_symbols(&mut self.code_builder, &[structure]);
self.code_builder.i32_const(3);
@ -1847,7 +1846,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
StoredValue::Local { local_id, .. } => (local_id, 0),
};
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET_INFO);
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET);
let from_addr_val = if stores_tag_id_in_pointer {
self.code_builder.get_local(tag_local_id);
@ -1912,7 +1911,7 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
StoredValue::Local { local_id, .. } => (*local_id, 0),
};
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET_INFO);
let stores_tag_id_in_pointer = union_layout.stores_tag_id_in_pointer(TARGET);
let from_offset = tag_offset + field_offset;

View file

@ -18,16 +18,16 @@ use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_mono::code_gen_help::CodeGenHelp;
use roc_mono::ir::{Proc, ProcLayout};
use roc_mono::layout::{LayoutIds, STLayoutInterner};
use roc_target::TargetInfo;
use roc_target::Target;
use roc_wasm_module::parse::ParseError;
use roc_wasm_module::{Align, LocalId, ValueType, WasmModule};
use crate::backend::{ProcLookupData, ProcSource, WasmBackend};
use crate::code_builder::CodeBuilder;
const TARGET_INFO: TargetInfo = TargetInfo::default_wasm32();
const TARGET: Target = Target::Wasm32;
const PTR_SIZE: u32 = {
let value = TARGET_INFO.ptr_width() as u32;
let value = TARGET.ptr_width() as u32;
// const assert that our pointer width is actually 4
// the code relies on the pointer width being exactly 4
@ -135,7 +135,7 @@ pub fn build_app_module<'a, 'r>(
host_to_app_map,
host_module,
fn_index_offset,
CodeGenHelp::new(env.arena, TargetInfo::default_wasm32(), env.module_id),
CodeGenHelp::new(env.arena, Target::Wasm32, env.module_id),
);
if DEBUG_SETTINGS.user_procs_ir {