diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-17 12:48:12 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-17 12:48:12 +0100 |
| commit | 7840c1b89f3e6a7b3d962e6f5e96aab77a3ddc3b (patch) | |
| tree | 1bc20a32934327cd1e3dce278c7bdd3ccf4982aa /src/llvm_backend_general.cpp | |
| parent | 0428d5ae2e8fc3e814a968698a6550e86aea9d5c (diff) | |
Change `__dynamic_map_get` and `__dynamic_map_set` to use separate parameters rather than take a singular struct
Diffstat (limited to 'src/llvm_backend_general.cpp')
| -rw-r--r-- | src/llvm_backend_general.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 1f8fccdcb..55b09cbfc 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -383,6 +383,21 @@ Type *lb_addr_type(lbAddr const &addr) { return type_deref(addr.addr.type); } +lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) { + Type *map_type = base_type(type_deref(map_ptr.type)); + lbValue h = lb_gen_map_header(p, map_ptr, map_type); + + lbValue key_ptr = {}; + auto args = array_make<lbValue>(permanent_allocator(), 3); + args[0] = h; + args[1] = lb_gen_map_key_hash(p, key, map_type->Map.key, &key_ptr); + args[2] = key_ptr; + + lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args); + + return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value)); +} + lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { if (addr.addr.value == nullptr) { GB_PANIC("Illegal addr -> nullptr"); @@ -390,19 +405,8 @@ lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { } switch (addr.kind) { - case lbAddr_Map: { - Type *map_type = base_type(addr.map.type); - lbValue h = lb_gen_map_header(p, addr.addr, map_type); - lbValue key = lb_gen_map_hash(p, addr.map.key, map_type->Map.key); - - auto args = array_make<lbValue>(permanent_allocator(), 2); - args[0] = h; - args[1] = key; - - lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args); - - return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value)); - } + case lbAddr_Map: + return lb_internal_dynamic_map_get_ptr(p, addr.addr, addr.map.key); case lbAddr_RelativePointer: { Type *rel_ptr = base_type(lb_addr_type(addr)); @@ -1059,16 +1063,11 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) { } else if (addr.kind == lbAddr_Map) { - Type *map_type = base_type(addr.map.type); + Type *map_type = base_type(type_deref(addr.addr.type)); + GB_ASSERT(map_type->kind == Type_Map); lbAddr v = lb_add_local_generated(p, map_type->Map.lookup_result_type, true); - lbValue h = lb_gen_map_header(p, addr.addr, map_type); - lbValue key = lb_gen_map_hash(p, addr.map.key, map_type->Map.key); - - auto args = array_make<lbValue>(permanent_allocator(), 2); - args[0] = h; - args[1] = key; - lbValue ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args); + lbValue ptr = lb_internal_dynamic_map_get_ptr(p, addr.addr, addr.map.key); lbValue ok = lb_emit_conv(p, lb_emit_comp_against_nil(p, Token_NotEq, ptr), t_bool); lb_emit_store(p, lb_emit_struct_ep(p, v.addr, 1), ok); |