use RocUnion constants for tag index

This commit is contained in:
Folkert 2022-07-22 16:14:38 +02:00
parent 366429303c
commit 4977d1c65e
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 20 additions and 20 deletions

View file

@ -65,7 +65,7 @@ use std::convert::TryInto;
use std::path::Path;
use target_lexicon::{Architecture, OperatingSystem, Triple};
use super::convert::zig_with_overflow_roc_dec;
use super::convert::{zig_with_overflow_roc_dec, RocUnion};
#[inline(always)]
fn print_fn_verification_output() -> bool {
@ -1162,9 +1162,6 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
}
}
pub const TAG_ID_INDEX: u32 = 1;
pub const TAG_DATA_INDEX: u32 = 0;
pub fn struct_from_fields<'a, 'ctx, 'env, I>(
env: &Env<'a, 'ctx, 'env>,
struct_type: StructType<'ctx>,
@ -1599,7 +1596,7 @@ fn build_wrapped_tag<'a, 'ctx, 'env>(
if union_layout.stores_tag_id_as_data(env.target_info) {
let tag_id_ptr = builder
.build_struct_gep(raw_data_ptr, TAG_ID_INDEX, "tag_id_index")
.build_struct_gep(raw_data_ptr, RocUnion::TAG_ID_INDEX, "tag_id_index")
.unwrap();
let tag_id_type = basic_type_from_layout(env, &tag_id_layout).into_int_type();
@ -1608,7 +1605,7 @@ fn build_wrapped_tag<'a, 'ctx, 'env>(
.build_store(tag_id_ptr, tag_id_type.const_int(tag_id as u64, false));
let opaque_struct_ptr = builder
.build_struct_gep(raw_data_ptr, TAG_DATA_INDEX, "tag_data_index")
.build_struct_gep(raw_data_ptr, RocUnion::TAG_DATA_INDEX, "tag_data_index")
.unwrap();
struct_pointer_from_fields(
@ -1758,7 +1755,7 @@ fn build_tag<'a, 'ctx, 'env>(
// store the tag id
let tag_id_ptr = env
.builder
.build_struct_gep(result_alloca, TAG_ID_INDEX, "tag_id_ptr")
.build_struct_gep(result_alloca, RocUnion::TAG_ID_INDEX, "tag_id_ptr")
.unwrap();
let tag_id_intval = tag_id_type.const_int(tag_id as u64, false);
@ -1771,7 +1768,7 @@ fn build_tag<'a, 'ctx, 'env>(
let struct_opaque_ptr = env
.builder
.build_struct_gep(result_alloca, TAG_DATA_INDEX, "opaque_data_ptr")
.build_struct_gep(result_alloca, RocUnion::TAG_DATA_INDEX, "opaque_data_ptr")
.unwrap();
let struct_ptr = env.builder.build_pointer_cast(
struct_opaque_ptr,
@ -2178,7 +2175,7 @@ fn lookup_at_index_ptr2<'a, 'ctx, 'env>(
.into_pointer_value();
let data_ptr = builder
.build_struct_gep(ptr, TAG_DATA_INDEX, "at_index_struct_gep_tag")
.build_struct_gep(ptr, RocUnion::TAG_DATA_INDEX, "at_index_struct_gep_tag")
.unwrap();
let elem_ptr = builder
@ -3263,7 +3260,7 @@ fn get_tag_id_wrapped<'a, 'ctx, 'env>(
) -> IntValue<'ctx> {
let tag_id_ptr = env
.builder
.build_struct_gep(from_value, TAG_ID_INDEX, "tag_id_ptr")
.build_struct_gep(from_value, RocUnion::TAG_ID_INDEX, "tag_id_ptr")
.unwrap();
env.builder
@ -3276,7 +3273,7 @@ pub fn get_tag_id_non_recursive<'a, 'ctx, 'env>(
tag: StructValue<'ctx>,
) -> IntValue<'ctx> {
env.builder
.build_extract_value(tag, TAG_ID_INDEX, "get_tag_id")
.build_extract_value(tag, RocUnion::TAG_ID_INDEX, "get_tag_id")
.unwrap()
.into_int_value()
}