|
10 | 10 | logger = logging.getLogger(__name__) |
11 | 11 |
|
12 | 12 |
|
13 | | -# NOTE: ScratchPoolManager is now in context.py |
14 | | - |
15 | | - |
16 | | -def get_ptr_from_arg(arg, compilation_context, builder, local_sym_tab): |
17 | | - """Helper to get a pointer value from an argument.""" |
18 | | - # This is a bit duplicative of logic in eval_expr but simplified for helpers |
19 | | - # We might need to handle more cases here or defer to eval_expr |
20 | | - |
21 | | - # Simple check for name |
22 | | - if isinstance(arg, ast.Name): |
23 | | - if arg.id in local_sym_tab: |
24 | | - sym = local_sym_tab[arg.id] |
25 | | - if isinstance(sym.ir_type, ir.PointerType): |
26 | | - return builder.load(sym.var) |
27 | | - # If it's an array/struct we might need GEP depending on how it was allocated |
28 | | - # For now assume load returns the pointer/value |
29 | | - return builder.load(sym.var) |
30 | | - |
31 | | - # Use eval_expr for general case |
32 | | - val = eval_expr(None, compilation_context, builder, arg, local_sym_tab) |
33 | | - if val and isinstance(val[0].type, ir.PointerType): |
34 | | - return val[0] |
35 | | - |
36 | | - return None |
37 | | - |
38 | | - |
39 | 13 | # ============================================================================ |
40 | 14 | # Argument Preparation |
41 | 15 | # ============================================================================ |
@@ -77,10 +51,7 @@ def get_or_create_ptr_from_arg( |
77 | 51 | sz = None |
78 | 52 | if isinstance(arg, ast.Name): |
79 | 53 | # Stack space is already allocated |
80 | | - if arg.id in local_sym_tab: |
81 | | - ptr = local_sym_tab[arg.id].var |
82 | | - else: |
83 | | - raise ValueError(f"Variable '{arg.id}' not found") |
| 54 | + ptr = get_var_ptr_from_name(arg.id, local_sym_tab) |
84 | 55 | elif isinstance(arg, ast.Constant) and isinstance(arg.value, int): |
85 | 56 | int_width = 64 # Default to i64 |
86 | 57 | if expected_type and isinstance(expected_type, ir.IntType): |
@@ -337,6 +308,22 @@ def _is_char_array(ir_type): |
337 | 308 | ) |
338 | 309 |
|
339 | 310 |
|
| 311 | +def get_ptr_from_arg(arg, func, compilation_context, builder, local_sym_tab): |
| 312 | + """Evaluate argument and return pointer value""" |
| 313 | + |
| 314 | + result = eval_expr(func, compilation_context, builder, arg, local_sym_tab) |
| 315 | + |
| 316 | + if not result: |
| 317 | + raise ValueError("Failed to evaluate argument") |
| 318 | + |
| 319 | + val, val_type = result |
| 320 | + |
| 321 | + if not isinstance(val_type, ir.PointerType): |
| 322 | + raise ValueError(f"Expected pointer type, got {val_type}") |
| 323 | + |
| 324 | + return val, val_type |
| 325 | + |
| 326 | + |
340 | 327 | def get_int_value_from_arg(arg, func, compilation_context, builder, local_sym_tab): |
341 | 328 | """Evaluate argument and return integer value""" |
342 | 329 |
|
|
0 commit comments