Implement string equality operator using IRRT and optimise LLVM implementation #561

Merged
sb10q merged 9 commits from ramtej/nac3:feature/string-equality into master 2024-12-30 13:02:09 +08:00
Showing only changes of commit cc18586363 - Show all commits

View File

@ -2076,6 +2076,7 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
let rhs = rhs.into_struct_value(); let rhs = rhs.into_struct_value();
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let llvm_usize = generator.get_size_type(ctx.ctx);
let plhs = generator.gen_var_alloc(ctx, lhs.get_type().into(), None).unwrap(); let plhs = generator.gen_var_alloc(ctx, lhs.get_type().into(), None).unwrap();
ctx.builder.build_store(plhs, lhs).unwrap(); ctx.builder.build_store(plhs, lhs).unwrap();
@ -2084,23 +2085,23 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
let lhs_ptr = ctx.build_in_bounds_gep_and_load( let lhs_ptr = ctx.build_in_bounds_gep_and_load(
plhs, plhs,
&[llvm_i32.const_zero(), llvm_i32.const_zero()], &[llvm_usize.const_zero(), llvm_i32.const_zero()],
None, None,
).into_pointer_value(); ).into_pointer_value();
let lhs_len = ctx.build_in_bounds_gep_and_load( let lhs_len = ctx.build_in_bounds_gep_and_load(
plhs, plhs,
&[llvm_i32.const_zero(), llvm_i32.const_int(1, false)], &[llvm_usize.const_zero(), llvm_i32.const_int(1, false)],
None, None,
).into_int_value(); ).into_int_value();
let rhs_ptr = ctx.build_in_bounds_gep_and_load( let rhs_ptr = ctx.build_in_bounds_gep_and_load(
prhs, prhs,
&[llvm_i32.const_zero(), llvm_i32.const_zero()], &[llvm_usize.const_zero(), llvm_i32.const_zero()],
None, None,
).into_pointer_value(); ).into_pointer_value();
let rhs_len = ctx.build_in_bounds_gep_and_load( let rhs_len = ctx.build_in_bounds_gep_and_load(
prhs, prhs,
&[llvm_i32.const_zero(), llvm_i32.const_int(1, false)], &[llvm_usize.const_zero(), llvm_i32.const_int(1, false)],
None, None,
).into_int_value(); ).into_int_value();
let result = call_string_eq(generator, ctx, lhs_ptr, lhs_len, rhs_ptr, rhs_len); let result = call_string_eq(generator, ctx, lhs_ptr, lhs_len, rhs_ptr, rhs_len);