final phase

This commit is contained in:
Folkert 2022-01-26 15:44:24 +01:00
parent 0ed259a80d
commit c663a35e16
27 changed files with 222 additions and 183 deletions

View file

@ -10,6 +10,7 @@ use morphic_lib::UpdateMode;
use roc_builtins::bitcode::{self, IntWidth};
use roc_module::symbol::Symbol;
use roc_mono::layout::{Builtin, Layout};
use roc_target::PtrWidth;
use super::build::load_symbol;
@ -79,10 +80,9 @@ fn str_symbol_to_c_abi<'a, 'ctx, 'env>(
) -> IntValue<'ctx> {
let string = load_symbol(scope, &symbol);
let target_type = match env.target_info {
8 => env.context.i128_type().into(),
4 => env.context.i64_type().into(),
_ => unreachable!(),
let target_type = match env.target_info.ptr_width() {
PtrWidth::Bytes8 => env.context.i128_type().into(),
PtrWidth::Bytes4 => env.context.i64_type().into(),
};
complex_bitcast(env.builder, string, target_type, "str_to_c_abi").into_int_value()
@ -96,10 +96,9 @@ pub fn str_to_c_abi<'a, 'ctx, 'env>(
env.builder.build_store(cell, value);
let target_type = match env.target_info {
8 => env.context.i128_type(),
4 => env.context.i64_type(),
_ => unreachable!(),
let target_type = match env.target_info.ptr_width() {
PtrWidth::Bytes8 => env.context.i128_type(),
PtrWidth::Bytes4 => env.context.i64_type(),
};
let target_type_ptr = env
@ -310,20 +309,19 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>(
let builder = env.builder;
let ctx = env.context;
let fields = match env.target_info {
8 | 4 => [
let fields = match env.target_info.ptr_width() {
PtrWidth::Bytes4 | PtrWidth::Bytes8 => [
env.ptr_int().into(),
super::convert::zig_str_type(env).into(),
env.context.bool_type().into(),
ctx.i8_type().into(),
],
_ => unreachable!(),
};
let record_type = env.context.struct_type(&fields, false);
match env.target_info {
8 | 4 => {
match env.target_info.ptr_width() {
PtrWidth::Bytes4 | PtrWidth::Bytes8 => {
let result_ptr_cast = env
.builder
.build_bitcast(
@ -337,7 +335,6 @@ fn decode_from_utf8_result<'a, 'ctx, 'env>(
.build_load(result_ptr_cast, "load_utf8_validate_bytes_result")
.into_struct_value()
}
_ => unreachable!(),
}
}