diff options
| author | gingerBill <bill@gingerbill.org> | 2023-07-14 17:03:28 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-07-14 17:03:28 +0100 |
| commit | b17ebeb6f66f5f7e24b5a1ca32baf6855185eea8 (patch) | |
| tree | 7bd29503373b95258ef1bf248de6ce6e50dac43b /src/tilde_const.cpp | |
| parent | a8afcf1ca950eded2d9c45750debd287f7998d1c (diff) | |
Mock out more of the addr related stuff
Diffstat (limited to 'src/tilde_const.cpp')
| -rw-r--r-- | src/tilde_const.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/tilde_const.cpp b/src/tilde_const.cpp index e59c6f8ab..6f9736554 100644 --- a/src/tilde_const.cpp +++ b/src/tilde_const.cpp @@ -1,5 +1,45 @@ +gb_internal cgValue cg_const_nil(cgProcedure *p, Type *type) { + Type *original_type = type; + type = core_type(type); + i64 size = type_size_of(type); + i64 align = type_align_of(type); + TB_DataType dt = cg_data_type(type); + if (TB_IS_VOID_TYPE(dt)) { + TB_Module *m = p->module->mod; + char name[32] = {}; + gb_snprintf(name, 31, "cnil$%u", 1+p->module->const_nil_guid.fetch_add(1)); + TB_Global *global = tb_global_create(m, name, nullptr, TB_LINKAGE_PRIVATE); + tb_global_set_storage(m, tb_module_get_rdata(m), global, size, align, 0); + + TB_Symbol *symbol = cast(TB_Symbol *)global; + TB_Node *node = tb_inst_get_symbol_address(p->func, symbol); + return cg_lvalue_addr(node, type); + } + + if (is_type_internally_pointer_like(type)) { + return cg_value(tb_inst_ptr(p->func, 0), type); + } else if (is_type_integer(type) || is_type_boolean(type) || is_type_bit_set(type)) { + return cg_value(tb_inst_uint(p->func, dt, 0), type); + } else if (is_type_float(type)) { + switch (size) { + case 2: + return cg_value(tb_inst_uint(p->func, dt, 0), type); + case 4: + return cg_value(tb_inst_float32(p->func, 0), type); + case 8: + return cg_value(tb_inst_float64(p->func, 0), type); + } + } + GB_PANIC("TODO(bill): cg_const_nil %s", type_to_string(original_type)); + return {}; +} + gb_internal cgValue cg_const_value(cgProcedure *p, Type *type, ExactValue const &value) { TB_Node *node = nullptr; + if (value.kind == ExactValue_Invalid) { + return cg_const_nil(p, type); + } + return cg_value(node, type); }
\ No newline at end of file |