Allocate twice for map lookups

This commit is contained in:
Pragyansh Chaturvedi
2025-10-10 06:09:46 +05:30
parent 489244a015
commit 047f361ea9
2 changed files with 15 additions and 3 deletions

View File

@ -55,10 +55,12 @@ def store_through_chain(value, chain, builder):
def handle_binary_op_impl(rval, builder, local_sym_tab):
op = rval.op
left, _, _ = get_operand_value(rval.left, builder, local_sym_tab)
right, _, _ = get_operand_value(rval.right, builder, local_sym_tab)
left, lchain, _ = get_operand_value(rval.left, builder, local_sym_tab)
right, rchain, _ = get_operand_value(rval.right, builder, local_sym_tab)
logger.info(f"left is {left}, right is {right}, op is {op}")
logger.info(f"left chain: {lchain}, right chain: {rchain}")
# Map AST operation nodes to LLVM IR builder methods
op_map = {
ast.Add: builder.add,

View File

@ -455,10 +455,17 @@ def allocate_mem(
f"Pre-allocated variable {var_name} for struct {call_type}"
)
elif isinstance(rval.func, ast.Attribute):
# Map method call
ir_type = ir.PointerType(ir.IntType(64))
var = builder.alloca(ir_type, name=var_name)
# declare an intermediate ptr type for map lookup
ir_type = ir.IntType(64)
var_tmp = builder.alloca(ir_type, name=f"{var_name}_tmp")
# var.align = ir_type.width // 8
logger.info(f"Pre-allocated variable {var_name} for map")
logger.info(
f"Pre-allocated variable {var_name} and {var_name}_tmp for map"
)
else:
logger.info("Unsupported assignment call function type")
continue
@ -496,6 +503,9 @@ def allocate_mem(
local_sym_tab[var_name] = LocalSymbol(var, ir_type, call_type)
else:
local_sym_tab[var_name] = LocalSymbol(var, ir_type)
if var_tmp:
local_sym_tab[f"{var_name}_tmp"] = LocalSymbol(var_tmp, ir_type)
return local_sym_tab