mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Factor out build_string_literal
This commit is contained in:
parent
f29b85e244
commit
a9f8c2ddec
1 changed files with 22 additions and 17 deletions
|
@ -750,7 +750,15 @@ pub fn build_exp_literal<'a, 'ctx, 'env>(
|
||||||
}
|
}
|
||||||
Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(),
|
Bool(b) => env.context.bool_type().const_int(*b as u64, false).into(),
|
||||||
Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(),
|
Byte(b) => env.context.i8_type().const_int(*b as u64, false).into(),
|
||||||
Str(str_literal) => {
|
Str(str_literal) => build_string_literal(env, parent, &str_literal),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_string_literal<'a, 'ctx, 'env>(
|
||||||
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
parent: FunctionValue<'ctx>,
|
||||||
|
str_literal: &str,
|
||||||
|
) -> BasicValueEnum<'ctx> {
|
||||||
if str_literal.len() < env.small_str_bytes() as usize {
|
if str_literal.len() < env.small_str_bytes() as usize {
|
||||||
match env.small_str_bytes() {
|
match env.small_str_bytes() {
|
||||||
24 => small_str_ptr_width_8(env, parent, str_literal).into(),
|
24 => small_str_ptr_width_8(env, parent, str_literal).into(),
|
||||||
|
@ -761,16 +769,13 @@ pub fn build_exp_literal<'a, 'ctx, 'env>(
|
||||||
let ptr = define_global_str_literal_ptr(env, str_literal);
|
let ptr = define_global_str_literal_ptr(env, str_literal);
|
||||||
let number_of_elements = env.ptr_int().const_int(str_literal.len() as u64, false);
|
let number_of_elements = env.ptr_int().const_int(str_literal.len() as u64, false);
|
||||||
|
|
||||||
let alloca =
|
let alloca = const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements);
|
||||||
const_str_alloca_ptr(env, parent, ptr, number_of_elements, number_of_elements);
|
|
||||||
|
|
||||||
match env.target_info.ptr_width() {
|
match env.target_info.ptr_width() {
|
||||||
PtrWidth::Bytes4 => env.builder.build_load(alloca, "load_const_str"),
|
PtrWidth::Bytes4 => env.builder.build_load(alloca, "load_const_str"),
|
||||||
PtrWidth::Bytes8 => alloca.into(),
|
PtrWidth::Bytes8 => alloca.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_str_alloca_ptr<'a, 'ctx, 'env>(
|
fn const_str_alloca_ptr<'a, 'ctx, 'env>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue