Add deref_to_val to deref into final value and return the chain as well in binops

This commit is contained in:
Pragyansh Chaturvedi
2025-10-09 21:47:28 +05:30
parent c596213b2a
commit 23afb0bd33

View File

@ -19,6 +19,24 @@ def recursive_dereferencer(var, builder):
raise TypeError(f"Unsupported type for dereferencing: {var.type}")
def deref_to_val(var, builder):
"""Dereference a variable to get its value and pointer chain."""
logger.info(f"Dereferencing {var}, type is {var.type}")
chain = [var]
cur = var
while isinstance(cur.type, ir.PointerType):
cur = builder.load(cur)
chain.append(cur)
if isinstance(cur.type, ir.IntType):
logger.info(f"dereference chain: {chain}")
return cur, chain
else:
raise TypeError(f"Unsupported type for dereferencing: {cur.type}")
def get_operand_value(operand, builder, local_sym_tab):
"""Extract the value from an operand, handling variables and constants."""
if isinstance(operand, ast.Name):