aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-01-17 14:00:49 +0000
committergingerBill <bill@gingerbill.org>2018-01-17 14:00:49 +0000
commit9428d86f2b5cb1eea5e4f6e50d3ba72a5dc1769b (patch)
treecbbfb1f3c915f1f5633ec2841710ee4342fae892 /src
parentddebf0daf2d73faaecbfbc77892d9bdb51adcee2 (diff)
Specific sized booleans: b8, b16, b32, b64
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp24
-rw-r--r--src/ir_print.cpp8
-rw-r--r--src/types.cpp9
3 files changed, 30 insertions, 11 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index e68eb1a26..61014247b 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -3019,8 +3019,18 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return value;
}
+
+ // bool <-> llvm bool
+ if (is_type_boolean(src) && dst == t_llvm_bool) {
+ return ir_emit(proc, ir_instr_conv(proc, irConv_trunc, value, src_type, t));
+ }
+ if (src == t_llvm_bool && is_type_boolean(dst)) {
+ return ir_emit(proc, ir_instr_conv(proc, irConv_zext, value, src_type, t));
+ }
+
// integer -> integer
- if (is_type_integer(src) && is_type_integer(dst)) {
+ if ((is_type_integer(src) && is_type_integer(dst)) ||
+ (is_type_boolean(src) && is_type_boolean(dst))) {
GB_ASSERT(src->kind == Type_Basic &&
dst->kind == Type_Basic);
i64 sz = type_size_of(proc->module->allocator, default_type(src));
@@ -3044,13 +3054,6 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return ir_emit(proc, ir_instr_conv(proc, kind, value, src_type, t));
}
- // bool <-> llvm bool
- if (is_type_boolean(src) && dst == t_llvm_bool) {
- return ir_emit(proc, ir_instr_conv(proc, irConv_trunc, value, src_type, t));
- }
- if (src == t_llvm_bool && is_type_boolean(dst)) {
- return ir_emit(proc, ir_instr_conv(proc, irConv_zext, value, src_type, t));
- }
// boolean -> integer
if (is_type_boolean(src) && is_type_integer(dst)) {
@@ -3062,7 +3065,6 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return ir_emit_comp(proc, Token_NotEq, value, v_zero);
}
-
// float -> float
if (is_type_float(src) && is_type_float(dst)) {
gbAllocator a = proc->module->allocator;
@@ -7870,6 +7872,10 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
ir_emit_comment(proc, str_lit("Type_Info_Basic"));
switch (t->Basic.kind) {
case Basic_bool:
+ case Basic_b8:
+ case Basic_b16:
+ case Basic_b32:
+ case Basic_b64:
tag = ir_emit_conv(proc, variant_ptr, t_type_info_boolean_ptr);
break;
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index 02b502605..52815d3f1 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -269,8 +269,12 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) {
switch (t->kind) {
case Type_Basic:
switch (t->Basic.kind) {
- case Basic_bool: ir_write_string(f, "i8"); return;
- case Basic_llvm_bool: ir_write_string(f, "i1"); return;
+ case Basic_llvm_bool: ir_write_string(f, "i1"); return;
+ case Basic_bool: ir_write_string(f, "i8"); return;
+ case Basic_b8: ir_write_string(f, "i8"); return;
+ case Basic_b16: ir_write_string(f, "i16"); return;
+ case Basic_b32: ir_write_string(f, "i32"); return;
+ case Basic_b64: ir_write_string(f, "i64"); return;
case Basic_i8: ir_write_string(f, "i8"); return;
case Basic_u8: ir_write_string(f, "i8"); return;
diff --git a/src/types.cpp b/src/types.cpp
index 68912adbb..eb673232f 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -6,6 +6,11 @@ enum BasicKind {
Basic_llvm_bool,
Basic_bool,
+ Basic_b8,
+ Basic_b16,
+ Basic_b32,
+ Basic_b64,
+
Basic_i8,
Basic_u8,
Basic_i16,
@@ -238,6 +243,10 @@ gb_global Type basic_types[] = {
{Type_Basic, {Basic_llvm_bool, BasicFlag_Boolean, 1, STR_LIT("llvm bool")}},
{Type_Basic, {Basic_bool, BasicFlag_Boolean, 1, STR_LIT("bool")}},
+ {Type_Basic, {Basic_b8, BasicFlag_Boolean, 1, STR_LIT("b8")}},
+ {Type_Basic, {Basic_b16, BasicFlag_Boolean, 2, STR_LIT("b16")}},
+ {Type_Basic, {Basic_b32, BasicFlag_Boolean, 4, STR_LIT("b32")}},
+ {Type_Basic, {Basic_b64, BasicFlag_Boolean, 8, STR_LIT("b64")}},
{Type_Basic, {Basic_i8, BasicFlag_Integer, 1, STR_LIT("i8")}},
{Type_Basic, {Basic_u8, BasicFlag_Integer | BasicFlag_Unsigned, 1, STR_LIT("u8")}},