Add string16 and cstring16 (UTF-16 based strings)

This commit is contained in:
gingerBill
2025-08-02 11:00:15 +01:00
parent 710203eadb
commit 2561427dd3
25 changed files with 873 additions and 62 deletions

View File

@@ -1812,6 +1812,37 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
return type;
}
case Basic_cstring: return LLVMPointerType(LLVMInt8TypeInContext(ctx), 0);
case Basic_string16:
{
char const *name = "..string16";
LLVMTypeRef type = LLVMGetTypeByName(m->mod, name);
if (type != nullptr) {
return type;
}
type = LLVMStructCreateNamed(ctx, name);
if (build_context.metrics.ptr_size < build_context.metrics.int_size) {
GB_ASSERT(build_context.metrics.ptr_size == 4);
GB_ASSERT(build_context.metrics.int_size == 8);
LLVMTypeRef fields[3] = {
LLVMPointerType(lb_type(m, t_u16), 0),
lb_type(m, t_i32),
lb_type(m, t_int),
};
LLVMStructSetBody(type, fields, 3, false);
} else {
LLVMTypeRef fields[2] = {
LLVMPointerType(lb_type(m, t_u16), 0),
lb_type(m, t_int),
};
LLVMStructSetBody(type, fields, 2, false);
}
return type;
}
case Basic_cstring16: return LLVMPointerType(LLVMInt16TypeInContext(ctx), 0);
case Basic_any:
{
char const *name = "..any";