|
| 1 | +/* |
| 2 | + * lir_types_c.h -- C-compatible struct definitions for LIR core types |
| 3 | + * |
| 4 | + * Phase B5: Provides C-visible struct layouts that match the C++ struct |
| 5 | + * memory layout exactly. C files include this header to access LIR struct |
| 6 | + * fields directly, without going through the C++ headers. |
| 7 | + * |
| 8 | + * IMPORTANT: Field names, types, and ORDER must match the corresponding |
| 9 | + * C++ struct definitions in block.h and function.h exactly. Any mismatch |
| 10 | + * causes undefined behavior when C code accesses objects created by C++. |
| 11 | + * |
| 12 | + * Currently covers: LirBasicBlock (block.h), LirFunction (function.h). |
| 13 | + * Instruction and OperandBase are accessed via opaque pointers (void*) |
| 14 | + * through lir_c_api.h until their C++ internals are converted. |
| 15 | + */ |
| 16 | + |
| 17 | +#ifndef JIT_LIR_TYPES_C_H |
| 18 | +#define JIT_LIR_TYPES_C_H |
| 19 | + |
| 20 | +#include <stddef.h> |
| 21 | +#include <stdint.h> |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" { |
| 25 | +#endif |
| 26 | + |
| 27 | +/* Forward declarations for types that remain opaque in C */ |
| 28 | +typedef struct LirInstruction LirInstruction; |
| 29 | + |
| 30 | +/* CodeSection enum — must match codegen::CodeSection in code_section.h */ |
| 31 | +typedef enum { |
| 32 | + LIR_SECTION_HOT = 0, |
| 33 | + LIR_SECTION_COLD = 1 |
| 34 | +} LirCodeSection; |
| 35 | + |
| 36 | +/* |
| 37 | + * LirBasicBlock — C-visible layout of jit::lir::BasicBlock (block.h) |
| 38 | + * |
| 39 | + * Field order MUST match block.h lines 175-191 exactly. |
| 40 | + * No vtable (no virtual methods). |
| 41 | + */ |
| 42 | +typedef struct LirBasicBlock { |
| 43 | + int id_; |
| 44 | + struct LirFunction* func_; |
| 45 | + |
| 46 | + struct LirBasicBlock** successors_; |
| 47 | + size_t num_succs_; |
| 48 | + size_t succs_capacity_; |
| 49 | + |
| 50 | + struct LirBasicBlock** predecessors_; |
| 51 | + size_t num_preds_; |
| 52 | + size_t preds_capacity_; |
| 53 | + |
| 54 | + /* Intrusive doubly-linked list of instructions */ |
| 55 | + LirInstruction* instr_head_; |
| 56 | + LirInstruction* instr_tail_; |
| 57 | + size_t num_instrs_; |
| 58 | + |
| 59 | + LirCodeSection section_; |
| 60 | +} LirBasicBlock; |
| 61 | + |
| 62 | +/* |
| 63 | + * LirFunction — C-visible layout of jit::lir::Function (function.h) |
| 64 | + * |
| 65 | + * Field order MUST match function.h lines 63-74 exactly. |
| 66 | + * No vtable (no virtual methods). |
| 67 | + * |
| 68 | + * Note: hir_func_ is an opaque pointer to the HIR Function (C++ only). |
| 69 | + * C code should not dereference it. |
| 70 | + */ |
| 71 | +typedef struct LirFunction { |
| 72 | + const void* hir_func_; /* const hir::Function* — opaque in C */ |
| 73 | + |
| 74 | + struct LirBasicBlock** blocks_; |
| 75 | + size_t num_blocks_; |
| 76 | + size_t blocks_capacity_; |
| 77 | + |
| 78 | + int next_id_; |
| 79 | +} LirFunction; |
| 80 | + |
| 81 | +#ifdef __cplusplus |
| 82 | +} /* extern "C" */ |
| 83 | +#endif |
| 84 | + |
| 85 | +#endif /* JIT_LIR_TYPES_C_H */ |
0 commit comments