misc cleanup suggestions

This commit is contained in:
Brendan Hansknecht 2023-11-29 21:05:56 -08:00
parent b62c9667d5
commit 1f14aa84a2
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
4 changed files with 31 additions and 49 deletions

View file

@ -897,20 +897,7 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
let function = self.module.get_function("roc_panic").unwrap();
let tag_id = self.context.i32_type().const_int(tag as u32 as u64, false);
let msg = match env.target_info.ptr_width() {
PtrWidth::Bytes4 => {
// we need to pass the message by reference, but we currently hold the value.
let alloca = env
.builder
.new_build_alloca(message.get_type(), "alloca_panic_msg");
env.builder.new_build_store(alloca, message);
alloca.into()
}
PtrWidth::Bytes8 => {
// string is already held by reference
message
}
};
let msg = self.string_to_arg(env, message);
let call = self
.builder
@ -927,35 +914,8 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
) {
let function = self.module.get_function("roc_dbg").unwrap();
let loc = match env.target_info.ptr_width() {
PtrWidth::Bytes4 => {
// we need to pass the location by reference, but we currently hold the value.
let alloca = env
.builder
.new_build_alloca(location.get_type(), "alloca_dbg_location");
env.builder.new_build_store(alloca, location);
alloca.into()
}
PtrWidth::Bytes8 => {
// string is already held by reference
location
}
};
let msg = match env.target_info.ptr_width() {
PtrWidth::Bytes4 => {
// we need to pass the message by reference, but we currently hold the value.
let alloca = env
.builder
.new_build_alloca(message.get_type(), "alloca_dbg_msg");
env.builder.new_build_store(alloca, message);
alloca.into()
}
PtrWidth::Bytes8 => {
// string is already held by reference
message
}
};
let loc = self.string_to_arg(env, location);
let msg = self.string_to_arg(env, message);
let call = self
.builder
@ -964,6 +924,27 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
call.set_call_convention(C_CALL_CONV);
}
fn string_to_arg(
&self,
env: &Env<'a, 'ctx, 'env>,
string: BasicValueEnum<'ctx>,
) -> BasicValueEnum<'ctx> {
match env.target_info.ptr_width() {
PtrWidth::Bytes4 => {
// we need to pass the string by reference, but we currently hold the value.
let alloca = env
.builder
.new_build_alloca(string.get_type(), "alloca_string");
env.builder.new_build_store(alloca, string);
alloca.into()
}
PtrWidth::Bytes8 => {
// string is already held by reference
string
}
}
}
pub fn new_debug_info(module: &Module<'ctx>) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) {
module.create_debug_info_builder(
true,