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

@ -1,7 +1,7 @@
use roc_parse::ast::Expr;
use roc_repl_eval::{ReplApp, ReplAppMemory};
use roc_std::RocStr;
use roc_target::TargetInfo;
use roc_target::Target;
pub(crate) struct ExpectMemory {
pub(crate) start: *const u8,
@ -118,7 +118,7 @@ impl<'a> ReplApp<'a> for ExpectReplApp<'a> {
fn call_function_returns_roc_str<T, F>(
&mut self,
_target_info: TargetInfo,
_target: Target,
main_fn_name: &str,
transform: F,
) -> Option<T>

View file

@ -8,7 +8,7 @@ use {
},
roc_parse::ast::Expr,
roc_repl_eval::{eval::jit_to_ast, ReplAppMemory},
roc_target::TargetInfo,
roc_target::Target,
roc_types::subs::{Subs, Variable},
};
@ -23,7 +23,7 @@ use app::{ExpectMemory, ExpectReplApp};
#[cfg(not(windows))]
#[allow(clippy::too_many_arguments)]
pub fn get_values<'a>(
target_info: TargetInfo,
target: Target,
arena: &'a bumpalo::Bump,
subs: &Subs,
interns: &'a Interns,
@ -58,7 +58,7 @@ pub fn get_values<'a>(
app.offset = start;
// TODO: pass layout_cache to jit_to_ast directly
let mut layout_cache = LayoutCache::new(layout_interner.fork(), target_info);
let mut layout_cache = LayoutCache::new(layout_interner.fork(), target);
let layout = layout_cache.from_var(arena, variable, subs).unwrap();
let proc_layout = ProcLayout {
@ -76,7 +76,7 @@ pub fn get_values<'a>(
subs,
interns,
layout_interner.fork(),
target_info,
target,
);
app.offset += layout_cache.interner.stack_size_and_alignment(layout).0 as usize;
@ -102,17 +102,13 @@ mod test {
use crate::run::expect_mono_module_to_dylib;
use super::*;
fn run_expect_test(source: &str, expected: &str) {
let arena = bumpalo::Bump::new();
let arena = &arena;
let triple = Triple::host();
let target = &triple;
let target = Triple::host().into();
let opt_level = roc_mono::ir::OptLevel::Normal;
let target_info = TargetInfo::from(target);
let function_kind = FunctionKind::LambdaSet;
// Step 1: compile the app and generate the .o file
@ -122,7 +118,7 @@ mod test {
std::fs::write(&filename, source).unwrap();
let load_config = LoadConfig {
target_info,
target,
function_kind,
render: RenderTarget::ColorTerminal,
palette: DEFAULT_PALETTE,
@ -150,14 +146,9 @@ mod test {
let interns = loaded.interns.clone();
let (dy_lib, expects_by_module, layout_interner) = expect_mono_module_to_dylib(
arena,
target.clone(),
loaded,
opt_level,
LlvmBackendMode::CliTest,
)
.unwrap();
let (dy_lib, expects_by_module, layout_interner) =
expect_mono_module_to_dylib(arena, target, loaded, opt_level, LlvmBackendMode::CliTest)
.unwrap();
let arena = &bumpalo::Bump::new();
let interns = arena.alloc(interns);

View file

@ -26,9 +26,8 @@ use roc_mono::{
};
use roc_region::all::Region;
use roc_reporting::{error::expect::Renderer, report::RenderTarget};
use roc_target::TargetInfo;
use roc_target::Target;
use roc_types::subs::Subs;
use target_lexicon::Triple;
pub struct ExpectMemory<'a> {
ptr: *mut u8,
@ -469,7 +468,7 @@ fn render_expect_failure<'a>(
offset: usize,
) -> std::io::Result<usize> {
// we always run programs as the host
let target_info = (&target_lexicon::Triple::host()).into();
let target = target_lexicon::Triple::host().into();
let frame = ExpectFrame::at_offset(start, offset);
let module_id = frame.module_id;
@ -487,7 +486,7 @@ fn render_expect_failure<'a>(
let symbols = split_expect_lookups(&data.subs, current);
let (offset, expressions, variables) = crate::get_values(
target_info,
target,
arena,
&data.subs,
interns,
@ -613,7 +612,7 @@ pub struct ExpectFunctions<'a> {
pub fn expect_mono_module_to_dylib<'a>(
arena: &'a Bump,
target: Triple,
target: Target,
loaded: MonomorphizedModule<'a>,
opt_level: OptLevel,
mode: LlvmBackendMode,
@ -625,8 +624,6 @@ pub fn expect_mono_module_to_dylib<'a>(
),
libloading::Error,
> {
let target_info = TargetInfo::from(&target);
let MonomorphizedModule {
toplevel_expects,
procedures,
@ -638,7 +635,7 @@ pub fn expect_mono_module_to_dylib<'a>(
let context = Context::create();
let builder = context.create_builder();
let module = arena.alloc(roc_gen_llvm::llvm::build::module_from_builtins(
&target, &context, "",
target, &context, "",
));
let module = arena.alloc(module);
@ -656,7 +653,7 @@ pub fn expect_mono_module_to_dylib<'a>(
context: &context,
interns,
module,
target_info,
target,
mode,
// important! we don't want any procedures to get the C calling convention
exposed_to_host: MutSet::default(),
@ -753,6 +750,6 @@ pub fn expect_mono_module_to_dylib<'a>(
env.module.print_to_file(path).unwrap();
}
llvm_module_to_dylib(env.module, &target, opt_level)
llvm_module_to_dylib(env.module, target, opt_level)
.map(|dy_lib| (dy_lib, modules_expects, layout_interner))
}