mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
extra target/codegen config
This commit is contained in:
parent
4d726925bd
commit
f838a94c00
3 changed files with 66 additions and 36 deletions
|
@ -1,7 +1,7 @@
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_build::{
|
use roc_build::{
|
||||||
link::{link, preprocess_host_wasm32, rebuild_host, LinkType, LinkingStrategy},
|
link::{link, preprocess_host_wasm32, rebuild_host, LinkType, LinkingStrategy},
|
||||||
program::{self, Problems},
|
program::{self, CodeGenOptions, Problems},
|
||||||
};
|
};
|
||||||
use roc_builtins::bitcode;
|
use roc_builtins::bitcode;
|
||||||
use roc_collections::VecMap;
|
use roc_collections::VecMap;
|
||||||
|
@ -62,8 +62,7 @@ pub fn build_file<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
target: &Triple,
|
target: &Triple,
|
||||||
app_module_path: PathBuf,
|
app_module_path: PathBuf,
|
||||||
opt_level: OptLevel,
|
code_gen_options: CodeGenOptions,
|
||||||
emit_debug_info: bool,
|
|
||||||
emit_timings: bool,
|
emit_timings: bool,
|
||||||
link_type: LinkType,
|
link_type: LinkType,
|
||||||
linking_strategy: LinkingStrategy,
|
linking_strategy: LinkingStrategy,
|
||||||
|
@ -123,7 +122,7 @@ pub fn build_file<'a>(
|
||||||
|
|
||||||
match roc_target::OperatingSystem::from(target.operating_system) {
|
match roc_target::OperatingSystem::from(target.operating_system) {
|
||||||
Wasi => {
|
Wasi => {
|
||||||
if matches!(opt_level, OptLevel::Development) {
|
if matches!(code_gen_options.opt_level, OptLevel::Development) {
|
||||||
("wasm", "wasm", Some("wasm"))
|
("wasm", "wasm", Some("wasm"))
|
||||||
} else {
|
} else {
|
||||||
("zig", "bc", Some("wasm"))
|
("zig", "bc", Some("wasm"))
|
||||||
|
@ -182,7 +181,7 @@ pub fn build_file<'a>(
|
||||||
};
|
};
|
||||||
|
|
||||||
let rebuild_thread = spawn_rebuild_thread(
|
let rebuild_thread = spawn_rebuild_thread(
|
||||||
opt_level,
|
code_gen_options.opt_level,
|
||||||
linking_strategy,
|
linking_strategy,
|
||||||
prebuilt,
|
prebuilt,
|
||||||
host_input_path.clone(),
|
host_input_path.clone(),
|
||||||
|
@ -272,8 +271,7 @@ pub fn build_file<'a>(
|
||||||
loaded,
|
loaded,
|
||||||
&app_module_path,
|
&app_module_path,
|
||||||
target,
|
target,
|
||||||
opt_level,
|
code_gen_options,
|
||||||
emit_debug_info,
|
|
||||||
&preprocessed_host_path,
|
&preprocessed_host_path,
|
||||||
wasm_dev_stack_bytes,
|
wasm_dev_stack_bytes,
|
||||||
);
|
);
|
||||||
|
@ -352,7 +350,7 @@ pub fn build_file<'a>(
|
||||||
|
|
||||||
let str_host_obj_path = bitcode::get_builtins_host_obj_path();
|
let str_host_obj_path = bitcode::get_builtins_host_obj_path();
|
||||||
|
|
||||||
if matches!(opt_level, OptLevel::Development) {
|
if matches!(code_gen_options.backend, program::CodeGenBackend::Assembly) {
|
||||||
inputs.push(&str_host_obj_path);
|
inputs.push(&str_host_obj_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use build::BuiltFile;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use clap::{Arg, ArgMatches, Command, ValueSource};
|
use clap::{Arg, ArgMatches, Command, ValueSource};
|
||||||
use roc_build::link::{LinkType, LinkingStrategy};
|
use roc_build::link::{LinkType, LinkingStrategy};
|
||||||
use roc_build::program::Problems;
|
use roc_build::program::{CodeGenBackend, CodeGenOptions, Problems};
|
||||||
use roc_collections::VecMap;
|
use roc_collections::VecMap;
|
||||||
use roc_error_macros::{internal_error, user_error};
|
use roc_error_macros::{internal_error, user_error};
|
||||||
use roc_intern::SingleThreadedInterner;
|
use roc_intern::SingleThreadedInterner;
|
||||||
|
@ -465,16 +465,30 @@ pub fn build(
|
||||||
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
||||||
let opt_level = match (
|
|
||||||
matches.is_present(FLAG_OPTIMIZE),
|
let code_gen_backend = if matches!(triple.architecture, Architecture::Wasm32) {
|
||||||
matches.is_present(FLAG_OPT_SIZE),
|
CodeGenBackend::Wasm
|
||||||
matches.is_present(FLAG_DEV),
|
} else {
|
||||||
) {
|
match matches.is_present(FLAG_DEV) {
|
||||||
(true, false, false) => OptLevel::Optimize,
|
true => CodeGenBackend::Assembly,
|
||||||
(false, true, false) => OptLevel::Size,
|
false => CodeGenBackend::Llvm,
|
||||||
(false, false, true) => OptLevel::Development,
|
}
|
||||||
(false, false, false) => OptLevel::Normal,
|
};
|
||||||
_ => user_error!("build can be only one of `--dev`, `--optimize`, or `--opt-size`"),
|
|
||||||
|
let opt_level = if let BuildConfig::BuildAndRunIfNoErrors = config {
|
||||||
|
OptLevel::Development
|
||||||
|
} else {
|
||||||
|
match (
|
||||||
|
matches.is_present(FLAG_OPTIMIZE),
|
||||||
|
matches.is_present(FLAG_OPT_SIZE),
|
||||||
|
) {
|
||||||
|
(true, false) => OptLevel::Optimize,
|
||||||
|
(false, true) => OptLevel::Size,
|
||||||
|
(false, false) => OptLevel::Normal,
|
||||||
|
(true, true) => {
|
||||||
|
user_error!("build can be only one of `--optimize` and `--opt-size`")
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let emit_debug_info = matches.is_present(FLAG_DEBUG);
|
let emit_debug_info = matches.is_present(FLAG_DEBUG);
|
||||||
let emit_timings = matches.is_present(FLAG_TIME);
|
let emit_timings = matches.is_present(FLAG_TIME);
|
||||||
|
@ -490,7 +504,7 @@ pub fn build(
|
||||||
};
|
};
|
||||||
|
|
||||||
let wasm_dev_backend = matches!(opt_level, OptLevel::Development)
|
let wasm_dev_backend = matches!(opt_level, OptLevel::Development)
|
||||||
&& matches!(triple.architecture, Architecture::Wasm32);
|
&& matches!(code_gen_backend, CodeGenBackend::Wasm);
|
||||||
|
|
||||||
let linking_strategy = if wasm_dev_backend {
|
let linking_strategy = if wasm_dev_backend {
|
||||||
LinkingStrategy::Additive
|
LinkingStrategy::Additive
|
||||||
|
@ -541,12 +555,18 @@ pub fn build(
|
||||||
BuildAndRunIfNoErrors => BuildOrdering::BuildIfChecks,
|
BuildAndRunIfNoErrors => BuildOrdering::BuildIfChecks,
|
||||||
_ => BuildOrdering::AlwaysBuild,
|
_ => BuildOrdering::AlwaysBuild,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let code_gen_options = CodeGenOptions {
|
||||||
|
backend: code_gen_backend,
|
||||||
|
opt_level,
|
||||||
|
emit_debug_info,
|
||||||
|
};
|
||||||
|
|
||||||
let res_binary_path = build_file(
|
let res_binary_path = build_file(
|
||||||
&arena,
|
&arena,
|
||||||
&triple,
|
&triple,
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
opt_level,
|
code_gen_options,
|
||||||
emit_debug_info,
|
|
||||||
emit_timings,
|
emit_timings,
|
||||||
link_type,
|
link_type,
|
||||||
linking_strategy,
|
linking_strategy,
|
||||||
|
@ -838,8 +858,6 @@ fn roc_run_native<I: IntoIterator<Item = S>, S: AsRef<OsStr>>(
|
||||||
.chain([std::ptr::null()])
|
.chain([std::ptr::null()])
|
||||||
.collect_in(arena);
|
.collect_in(arena);
|
||||||
|
|
||||||
let opt_level = OptLevel::Development;
|
|
||||||
|
|
||||||
match opt_level {
|
match opt_level {
|
||||||
OptLevel::Development => roc_run_native_debug(
|
OptLevel::Development => roc_run_native_debug(
|
||||||
arena,
|
arena,
|
||||||
|
|
|
@ -173,33 +173,47 @@ impl Deref for CodeObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum CodeGenBackend {
|
||||||
|
Assembly,
|
||||||
|
Llvm,
|
||||||
|
Wasm,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct CodeGenOptions {
|
||||||
|
pub backend: CodeGenBackend,
|
||||||
|
pub opt_level: OptLevel,
|
||||||
|
pub emit_debug_info: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn gen_from_mono_module(
|
pub fn gen_from_mono_module(
|
||||||
arena: &bumpalo::Bump,
|
arena: &bumpalo::Bump,
|
||||||
loaded: MonomorphizedModule,
|
loaded: MonomorphizedModule,
|
||||||
roc_file_path: &Path,
|
roc_file_path: &Path,
|
||||||
target: &target_lexicon::Triple,
|
target: &target_lexicon::Triple,
|
||||||
opt_level: OptLevel,
|
code_gen_options: CodeGenOptions,
|
||||||
emit_debug_info: bool,
|
|
||||||
preprocessed_host_path: &Path,
|
preprocessed_host_path: &Path,
|
||||||
wasm_dev_stack_bytes: Option<u32>,
|
wasm_dev_stack_bytes: Option<u32>,
|
||||||
) -> (CodeObject, CodeGenTiming) {
|
) -> (CodeObject, CodeGenTiming) {
|
||||||
match opt_level {
|
match code_gen_options.backend {
|
||||||
OptLevel::Normal | OptLevel::Size | OptLevel::Optimize => gen_from_mono_module_llvm(
|
CodeGenBackend::Assembly => gen_from_mono_module_dev(
|
||||||
arena,
|
|
||||||
loaded,
|
|
||||||
roc_file_path,
|
|
||||||
target,
|
|
||||||
opt_level,
|
|
||||||
emit_debug_info,
|
|
||||||
),
|
|
||||||
OptLevel::Development => gen_from_mono_module_dev(
|
|
||||||
arena,
|
arena,
|
||||||
loaded,
|
loaded,
|
||||||
target,
|
target,
|
||||||
preprocessed_host_path,
|
preprocessed_host_path,
|
||||||
wasm_dev_stack_bytes,
|
wasm_dev_stack_bytes,
|
||||||
),
|
),
|
||||||
|
CodeGenBackend::Llvm => gen_from_mono_module_llvm(
|
||||||
|
arena,
|
||||||
|
loaded,
|
||||||
|
roc_file_path,
|
||||||
|
target,
|
||||||
|
code_gen_options.opt_level,
|
||||||
|
code_gen_options.emit_debug_info,
|
||||||
|
),
|
||||||
|
CodeGenBackend::Wasm => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue