aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-08-02 12:51:08 +0100
committergingerBill <gingerBill@users.noreply.github.com>2025-08-02 12:51:08 +0100
commit7c281a9614d815fda4c3ac5fd53ce940662c3264 (patch)
tree0b3bb09f6c69270f92e9f60870caf24752b08c7d /src/llvm_backend_expr.cpp
parentc631a8eff59f8c4f76b1a39d1ca04b9fdf0cb85c (diff)
Fix [^]u16 <-> cstring16 conversions
Diffstat (limited to 'src/llvm_backend_expr.cpp')
-rw-r--r--src/llvm_backend_expr.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index 8ad6a5a1c..f58e2d9ac 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -2330,6 +2330,21 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
return res;
}
+ // [^]u16 <-> cstring16
+ if (is_type_u16_multi_ptr(src) && is_type_cstring16(dst)) {
+ return lb_emit_transmute(p, value, t);
+ }
+ if (is_type_cstring16(src) && is_type_u16_multi_ptr(dst)) {
+ return lb_emit_transmute(p, value, t);
+ }
+ if (is_type_u16_ptr(src) && is_type_cstring16(dst)) {
+ return lb_emit_transmute(p, value, t);
+ }
+ if (is_type_cstring16(src) && is_type_u16_ptr(dst)) {
+ return lb_emit_transmute(p, value, t);
+ }
+
+
// []u16 <-> string16
if (is_type_u16_slice(src) && is_type_string16(dst)) {
return lb_emit_transmute(p, value, t);
@@ -2753,7 +2768,53 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left
return lb_compare_records(p, op_kind, left, right, b);
}
+
+ if (is_type_string16(a) || is_type_cstring16(a)) {
+ if (is_type_cstring16(a) && is_type_cstring16(b)) {
+ left = lb_emit_conv(p, left, t_cstring16);
+ right = lb_emit_conv(p, right, t_cstring16);
+ char const *runtime_procedure = nullptr;
+ switch (op_kind) {
+ case Token_CmpEq: runtime_procedure = "cstring16_eq"; break;
+ case Token_NotEq: runtime_procedure = "cstring16_ne"; break;
+ case Token_Lt: runtime_procedure = "cstring16_lt"; break;
+ case Token_Gt: runtime_procedure = "cstring16_gt"; break;
+ case Token_LtEq: runtime_procedure = "cstring16_le"; break;
+ case Token_GtEq: runtime_procedure = "cstring16_ge"; break;
+ }
+ GB_ASSERT(runtime_procedure != nullptr);
+
+ auto args = array_make<lbValue>(permanent_allocator(), 2);
+ args[0] = left;
+ args[1] = right;
+ return lb_emit_runtime_call(p, runtime_procedure, args);
+ }
+
+
+ if (is_type_cstring16(a) ^ is_type_cstring16(b)) {
+ left = lb_emit_conv(p, left, t_string);
+ right = lb_emit_conv(p, right, t_string);
+ }
+
+ char const *runtime_procedure = nullptr;
+ switch (op_kind) {
+ case Token_CmpEq: runtime_procedure = "string16_eq"; break;
+ case Token_NotEq: runtime_procedure = "string16_ne"; break;
+ case Token_Lt: runtime_procedure = "string16_lt"; break;
+ case Token_Gt: runtime_procedure = "string16_gt"; break;
+ case Token_LtEq: runtime_procedure = "string16_le"; break;
+ case Token_GtEq: runtime_procedure = "string16_ge"; break;
+ }
+ GB_ASSERT(runtime_procedure != nullptr);
+
+ auto args = array_make<lbValue>(permanent_allocator(), 2);
+ args[0] = left;
+ args[1] = right;
+ return lb_emit_runtime_call(p, runtime_procedure, args);
+ }
+
if (is_type_string(a)) {
+
if (is_type_cstring(a) && is_type_cstring(b)) {
left = lb_emit_conv(p, left, t_cstring);
right = lb_emit_conv(p, right, t_cstring);