zig0

my attempts at zig bootstrapping in C
Log | Files | Refs | README | LICENSE

zir.h (30756B) - Raw


      1 // zir.h — ZIR data structures, ported from lib/std/zig/Zir.zig.
      2 #ifndef _ZIG0_ZIR_H__
      3 #define _ZIG0_ZIR_H__
      4 
      5 #include "common.h"
      6 #include <stdbool.h>
      7 #include <stdint.h>
      8 
      9 // --- ZIR instruction tags (uint8_t) ---
     10 // Matches Zir.Inst.Tag enum order from Zir.zig.
     11 
     12 #define ZIR_INST_FOREACH_TAG(TAG)                                             \
     13     TAG(ZIR_INST_ADD)                                                         \
     14     TAG(ZIR_INST_ADDWRAP)                                                     \
     15     TAG(ZIR_INST_ADD_SAT)                                                     \
     16     TAG(ZIR_INST_ADD_UNSAFE)                                                  \
     17     TAG(ZIR_INST_SUB)                                                         \
     18     TAG(ZIR_INST_SUBWRAP)                                                     \
     19     TAG(ZIR_INST_SUB_SAT)                                                     \
     20     TAG(ZIR_INST_MUL)                                                         \
     21     TAG(ZIR_INST_MULWRAP)                                                     \
     22     TAG(ZIR_INST_MUL_SAT)                                                     \
     23     TAG(ZIR_INST_DIV_EXACT)                                                   \
     24     TAG(ZIR_INST_DIV_FLOOR)                                                   \
     25     TAG(ZIR_INST_DIV_TRUNC)                                                   \
     26     TAG(ZIR_INST_MOD)                                                         \
     27     TAG(ZIR_INST_REM)                                                         \
     28     TAG(ZIR_INST_MOD_REM)                                                     \
     29     TAG(ZIR_INST_SHL)                                                         \
     30     TAG(ZIR_INST_SHL_EXACT)                                                   \
     31     TAG(ZIR_INST_SHL_SAT)                                                     \
     32     TAG(ZIR_INST_SHR)                                                         \
     33     TAG(ZIR_INST_SHR_EXACT)                                                   \
     34     TAG(ZIR_INST_PARAM)                                                       \
     35     TAG(ZIR_INST_PARAM_COMPTIME)                                              \
     36     TAG(ZIR_INST_PARAM_ANYTYPE)                                               \
     37     TAG(ZIR_INST_PARAM_ANYTYPE_COMPTIME)                                      \
     38     TAG(ZIR_INST_ARRAY_CAT)                                                   \
     39     TAG(ZIR_INST_ARRAY_MUL)                                                   \
     40     TAG(ZIR_INST_ARRAY_TYPE)                                                  \
     41     TAG(ZIR_INST_ARRAY_TYPE_SENTINEL)                                         \
     42     TAG(ZIR_INST_VECTOR_TYPE)                                                 \
     43     TAG(ZIR_INST_ELEM_TYPE)                                                   \
     44     TAG(ZIR_INST_INDEXABLE_PTR_ELEM_TYPE)                                     \
     45     TAG(ZIR_INST_SPLAT_OP_RESULT_TY)                                          \
     46     TAG(ZIR_INST_INDEXABLE_PTR_LEN)                                           \
     47     TAG(ZIR_INST_ANYFRAME_TYPE)                                               \
     48     TAG(ZIR_INST_AS_NODE)                                                     \
     49     TAG(ZIR_INST_AS_SHIFT_OPERAND)                                            \
     50     TAG(ZIR_INST_BIT_AND)                                                     \
     51     TAG(ZIR_INST_BITCAST)                                                     \
     52     TAG(ZIR_INST_BIT_NOT)                                                     \
     53     TAG(ZIR_INST_BIT_OR)                                                      \
     54     TAG(ZIR_INST_BLOCK)                                                       \
     55     TAG(ZIR_INST_BLOCK_COMPTIME)                                              \
     56     TAG(ZIR_INST_BLOCK_INLINE)                                                \
     57     TAG(ZIR_INST_DECLARATION)                                                 \
     58     TAG(ZIR_INST_SUSPEND_BLOCK)                                               \
     59     TAG(ZIR_INST_BOOL_NOT)                                                    \
     60     TAG(ZIR_INST_BOOL_BR_AND)                                                 \
     61     TAG(ZIR_INST_BOOL_BR_OR)                                                  \
     62     TAG(ZIR_INST_BREAK)                                                       \
     63     TAG(ZIR_INST_BREAK_INLINE)                                                \
     64     TAG(ZIR_INST_SWITCH_CONTINUE)                                             \
     65     TAG(ZIR_INST_CHECK_COMPTIME_CONTROL_FLOW)                                 \
     66     TAG(ZIR_INST_CALL)                                                        \
     67     TAG(ZIR_INST_FIELD_CALL)                                                  \
     68     TAG(ZIR_INST_BUILTIN_CALL)                                                \
     69     TAG(ZIR_INST_CMP_LT)                                                      \
     70     TAG(ZIR_INST_CMP_LTE)                                                     \
     71     TAG(ZIR_INST_CMP_EQ)                                                      \
     72     TAG(ZIR_INST_CMP_GTE)                                                     \
     73     TAG(ZIR_INST_CMP_GT)                                                      \
     74     TAG(ZIR_INST_CMP_NEQ)                                                     \
     75     TAG(ZIR_INST_CONDBR)                                                      \
     76     TAG(ZIR_INST_CONDBR_INLINE)                                               \
     77     TAG(ZIR_INST_TRY)                                                         \
     78     TAG(ZIR_INST_TRY_PTR)                                                     \
     79     TAG(ZIR_INST_ERROR_SET_DECL)                                              \
     80     TAG(ZIR_INST_DBG_STMT)                                                    \
     81     TAG(ZIR_INST_DBG_VAR_PTR)                                                 \
     82     TAG(ZIR_INST_DBG_VAR_VAL)                                                 \
     83     TAG(ZIR_INST_DECL_REF)                                                    \
     84     TAG(ZIR_INST_DECL_VAL)                                                    \
     85     TAG(ZIR_INST_LOAD)                                                        \
     86     TAG(ZIR_INST_DIV)                                                         \
     87     TAG(ZIR_INST_ELEM_PTR_NODE)                                               \
     88     TAG(ZIR_INST_ELEM_PTR)                                                    \
     89     TAG(ZIR_INST_ELEM_VAL_NODE)                                               \
     90     TAG(ZIR_INST_ELEM_VAL)                                                    \
     91     TAG(ZIR_INST_ELEM_VAL_IMM)                                                \
     92     TAG(ZIR_INST_ENSURE_RESULT_USED)                                          \
     93     TAG(ZIR_INST_ENSURE_RESULT_NON_ERROR)                                     \
     94     TAG(ZIR_INST_ENSURE_ERR_UNION_PAYLOAD_VOID)                               \
     95     TAG(ZIR_INST_ERROR_UNION_TYPE)                                            \
     96     TAG(ZIR_INST_ERROR_VALUE)                                                 \
     97     TAG(ZIR_INST_EXPORT)                                                      \
     98     TAG(ZIR_INST_FIELD_PTR)                                                   \
     99     TAG(ZIR_INST_FIELD_VAL)                                                   \
    100     TAG(ZIR_INST_FIELD_PTR_NAMED)                                             \
    101     TAG(ZIR_INST_FIELD_VAL_NAMED)                                             \
    102     TAG(ZIR_INST_FUNC)                                                        \
    103     TAG(ZIR_INST_FUNC_INFERRED)                                               \
    104     TAG(ZIR_INST_FUNC_FANCY)                                                  \
    105     TAG(ZIR_INST_IMPORT)                                                      \
    106     TAG(ZIR_INST_INT)                                                         \
    107     TAG(ZIR_INST_INT_BIG)                                                     \
    108     TAG(ZIR_INST_FLOAT)                                                       \
    109     TAG(ZIR_INST_FLOAT128)                                                    \
    110     TAG(ZIR_INST_INT_TYPE)                                                    \
    111     TAG(ZIR_INST_IS_NON_NULL)                                                 \
    112     TAG(ZIR_INST_IS_NON_NULL_PTR)                                             \
    113     TAG(ZIR_INST_IS_NON_ERR)                                                  \
    114     TAG(ZIR_INST_IS_NON_ERR_PTR)                                              \
    115     TAG(ZIR_INST_RET_IS_NON_ERR)                                              \
    116     TAG(ZIR_INST_LOOP)                                                        \
    117     TAG(ZIR_INST_REPEAT)                                                      \
    118     TAG(ZIR_INST_REPEAT_INLINE)                                               \
    119     TAG(ZIR_INST_FOR_LEN)                                                     \
    120     TAG(ZIR_INST_MERGE_ERROR_SETS)                                            \
    121     TAG(ZIR_INST_REF)                                                         \
    122     TAG(ZIR_INST_RET_NODE)                                                    \
    123     TAG(ZIR_INST_RET_LOAD)                                                    \
    124     TAG(ZIR_INST_RET_IMPLICIT)                                                \
    125     TAG(ZIR_INST_RET_ERR_VALUE)                                               \
    126     TAG(ZIR_INST_RET_ERR_VALUE_CODE)                                          \
    127     TAG(ZIR_INST_RET_PTR)                                                     \
    128     TAG(ZIR_INST_RET_TYPE)                                                    \
    129     TAG(ZIR_INST_PTR_TYPE)                                                    \
    130     TAG(ZIR_INST_SLICE_START)                                                 \
    131     TAG(ZIR_INST_SLICE_END)                                                   \
    132     TAG(ZIR_INST_SLICE_SENTINEL)                                              \
    133     TAG(ZIR_INST_SLICE_LENGTH)                                                \
    134     TAG(ZIR_INST_SLICE_SENTINEL_TY)                                           \
    135     TAG(ZIR_INST_STORE_NODE)                                                  \
    136     TAG(ZIR_INST_STORE_TO_INFERRED_PTR)                                       \
    137     TAG(ZIR_INST_STR)                                                         \
    138     TAG(ZIR_INST_NEGATE)                                                      \
    139     TAG(ZIR_INST_NEGATE_WRAP)                                                 \
    140     TAG(ZIR_INST_TYPEOF)                                                      \
    141     TAG(ZIR_INST_TYPEOF_BUILTIN)                                              \
    142     TAG(ZIR_INST_TYPEOF_LOG2_INT_TYPE)                                        \
    143     TAG(ZIR_INST_UNREACHABLE)                                                 \
    144     TAG(ZIR_INST_XOR)                                                         \
    145     TAG(ZIR_INST_OPTIONAL_TYPE)                                               \
    146     TAG(ZIR_INST_OPTIONAL_PAYLOAD_SAFE)                                       \
    147     TAG(ZIR_INST_OPTIONAL_PAYLOAD_UNSAFE)                                     \
    148     TAG(ZIR_INST_OPTIONAL_PAYLOAD_SAFE_PTR)                                   \
    149     TAG(ZIR_INST_OPTIONAL_PAYLOAD_UNSAFE_PTR)                                 \
    150     TAG(ZIR_INST_ERR_UNION_PAYLOAD_UNSAFE)                                    \
    151     TAG(ZIR_INST_ERR_UNION_PAYLOAD_UNSAFE_PTR)                                \
    152     TAG(ZIR_INST_ERR_UNION_CODE)                                              \
    153     TAG(ZIR_INST_ERR_UNION_CODE_PTR)                                          \
    154     TAG(ZIR_INST_ENUM_LITERAL)                                                \
    155     TAG(ZIR_INST_DECL_LITERAL)                                                \
    156     TAG(ZIR_INST_DECL_LITERAL_NO_COERCE)                                      \
    157     TAG(ZIR_INST_SWITCH_BLOCK)                                                \
    158     TAG(ZIR_INST_SWITCH_BLOCK_REF)                                            \
    159     TAG(ZIR_INST_SWITCH_BLOCK_ERR_UNION)                                      \
    160     TAG(ZIR_INST_VALIDATE_DEREF)                                              \
    161     TAG(ZIR_INST_VALIDATE_DESTRUCTURE)                                        \
    162     TAG(ZIR_INST_FIELD_TYPE_REF)                                              \
    163     TAG(ZIR_INST_OPT_EU_BASE_PTR_INIT)                                        \
    164     TAG(ZIR_INST_COERCE_PTR_ELEM_TY)                                          \
    165     TAG(ZIR_INST_VALIDATE_REF_TY)                                             \
    166     TAG(ZIR_INST_VALIDATE_CONST)                                              \
    167     TAG(ZIR_INST_STRUCT_INIT_EMPTY)                                           \
    168     TAG(ZIR_INST_STRUCT_INIT_EMPTY_RESULT)                                    \
    169     TAG(ZIR_INST_STRUCT_INIT_EMPTY_REF_RESULT)                                \
    170     TAG(ZIR_INST_STRUCT_INIT_ANON)                                            \
    171     TAG(ZIR_INST_STRUCT_INIT)                                                 \
    172     TAG(ZIR_INST_STRUCT_INIT_REF)                                             \
    173     TAG(ZIR_INST_VALIDATE_STRUCT_INIT_TY)                                     \
    174     TAG(ZIR_INST_VALIDATE_STRUCT_INIT_RESULT_TY)                              \
    175     TAG(ZIR_INST_VALIDATE_PTR_STRUCT_INIT)                                    \
    176     TAG(ZIR_INST_STRUCT_INIT_FIELD_TYPE)                                      \
    177     TAG(ZIR_INST_STRUCT_INIT_FIELD_PTR)                                       \
    178     TAG(ZIR_INST_ARRAY_INIT_ANON)                                             \
    179     TAG(ZIR_INST_ARRAY_INIT)                                                  \
    180     TAG(ZIR_INST_ARRAY_INIT_REF)                                              \
    181     TAG(ZIR_INST_VALIDATE_ARRAY_INIT_TY)                                      \
    182     TAG(ZIR_INST_VALIDATE_ARRAY_INIT_RESULT_TY)                               \
    183     TAG(ZIR_INST_VALIDATE_ARRAY_INIT_REF_TY)                                  \
    184     TAG(ZIR_INST_VALIDATE_PTR_ARRAY_INIT)                                     \
    185     TAG(ZIR_INST_ARRAY_INIT_ELEM_TYPE)                                        \
    186     TAG(ZIR_INST_ARRAY_INIT_ELEM_PTR)                                         \
    187     TAG(ZIR_INST_UNION_INIT)                                                  \
    188     TAG(ZIR_INST_TYPE_INFO)                                                   \
    189     TAG(ZIR_INST_SIZE_OF)                                                     \
    190     TAG(ZIR_INST_BIT_SIZE_OF)                                                 \
    191     TAG(ZIR_INST_INT_FROM_PTR)                                                \
    192     TAG(ZIR_INST_COMPILE_ERROR)                                               \
    193     TAG(ZIR_INST_SET_EVAL_BRANCH_QUOTA)                                       \
    194     TAG(ZIR_INST_INT_FROM_ENUM)                                               \
    195     TAG(ZIR_INST_ALIGN_OF)                                                    \
    196     TAG(ZIR_INST_INT_FROM_BOOL)                                               \
    197     TAG(ZIR_INST_EMBED_FILE)                                                  \
    198     TAG(ZIR_INST_ERROR_NAME)                                                  \
    199     TAG(ZIR_INST_PANIC)                                                       \
    200     TAG(ZIR_INST_TRAP)                                                        \
    201     TAG(ZIR_INST_SET_RUNTIME_SAFETY)                                          \
    202     TAG(ZIR_INST_SQRT)                                                        \
    203     TAG(ZIR_INST_SIN)                                                         \
    204     TAG(ZIR_INST_COS)                                                         \
    205     TAG(ZIR_INST_TAN)                                                         \
    206     TAG(ZIR_INST_EXP)                                                         \
    207     TAG(ZIR_INST_EXP2)                                                        \
    208     TAG(ZIR_INST_LOG)                                                         \
    209     TAG(ZIR_INST_LOG2)                                                        \
    210     TAG(ZIR_INST_LOG10)                                                       \
    211     TAG(ZIR_INST_ABS)                                                         \
    212     TAG(ZIR_INST_FLOOR)                                                       \
    213     TAG(ZIR_INST_CEIL)                                                        \
    214     TAG(ZIR_INST_TRUNC)                                                       \
    215     TAG(ZIR_INST_ROUND)                                                       \
    216     TAG(ZIR_INST_TAG_NAME)                                                    \
    217     TAG(ZIR_INST_TYPE_NAME)                                                   \
    218     TAG(ZIR_INST_FRAME_TYPE)                                                  \
    219     TAG(ZIR_INST_INT_FROM_FLOAT)                                              \
    220     TAG(ZIR_INST_FLOAT_FROM_INT)                                              \
    221     TAG(ZIR_INST_PTR_FROM_INT)                                                \
    222     TAG(ZIR_INST_ENUM_FROM_INT)                                               \
    223     TAG(ZIR_INST_FLOAT_CAST)                                                  \
    224     TAG(ZIR_INST_INT_CAST)                                                    \
    225     TAG(ZIR_INST_PTR_CAST)                                                    \
    226     TAG(ZIR_INST_TRUNCATE)                                                    \
    227     TAG(ZIR_INST_HAS_DECL)                                                    \
    228     TAG(ZIR_INST_HAS_FIELD)                                                   \
    229     TAG(ZIR_INST_CLZ)                                                         \
    230     TAG(ZIR_INST_CTZ)                                                         \
    231     TAG(ZIR_INST_POP_COUNT)                                                   \
    232     TAG(ZIR_INST_BYTE_SWAP)                                                   \
    233     TAG(ZIR_INST_BIT_REVERSE)                                                 \
    234     TAG(ZIR_INST_BIT_OFFSET_OF)                                               \
    235     TAG(ZIR_INST_OFFSET_OF)                                                   \
    236     TAG(ZIR_INST_SPLAT)                                                       \
    237     TAG(ZIR_INST_REDUCE)                                                      \
    238     TAG(ZIR_INST_SHUFFLE)                                                     \
    239     TAG(ZIR_INST_ATOMIC_LOAD)                                                 \
    240     TAG(ZIR_INST_ATOMIC_RMW)                                                  \
    241     TAG(ZIR_INST_ATOMIC_STORE)                                                \
    242     TAG(ZIR_INST_MUL_ADD)                                                     \
    243     TAG(ZIR_INST_MEMCPY)                                                      \
    244     TAG(ZIR_INST_MEMMOVE)                                                     \
    245     TAG(ZIR_INST_MEMSET)                                                      \
    246     TAG(ZIR_INST_MIN)                                                         \
    247     TAG(ZIR_INST_MAX)                                                         \
    248     TAG(ZIR_INST_C_IMPORT)                                                    \
    249     TAG(ZIR_INST_ALLOC)                                                       \
    250     TAG(ZIR_INST_ALLOC_MUT)                                                   \
    251     TAG(ZIR_INST_ALLOC_COMPTIME_MUT)                                          \
    252     TAG(ZIR_INST_ALLOC_INFERRED)                                              \
    253     TAG(ZIR_INST_ALLOC_INFERRED_MUT)                                          \
    254     TAG(ZIR_INST_ALLOC_INFERRED_COMPTIME)                                     \
    255     TAG(ZIR_INST_ALLOC_INFERRED_COMPTIME_MUT)                                 \
    256     TAG(ZIR_INST_RESOLVE_INFERRED_ALLOC)                                      \
    257     TAG(ZIR_INST_MAKE_PTR_CONST)                                              \
    258     TAG(ZIR_INST_RESUME)                                                      \
    259     TAG(ZIR_INST_DEFER)                                                       \
    260     TAG(ZIR_INST_DEFER_ERR_CODE)                                              \
    261     TAG(ZIR_INST_SAVE_ERR_RET_INDEX)                                          \
    262     TAG(ZIR_INST_RESTORE_ERR_RET_INDEX_UNCONDITIONAL)                         \
    263     TAG(ZIR_INST_RESTORE_ERR_RET_INDEX_FN_ENTRY)                              \
    264     TAG(ZIR_INST_EXTENDED)
    265 
    266 #define ZIR_GENERATE_ENUM(e) e,
    267 typedef enum { ZIR_INST_FOREACH_TAG(ZIR_GENERATE_ENUM) } ZirInstTag;
    268 
    269 // --- ZIR extended opcodes (uint16_t) ---
    270 // Matches Zir.Inst.Extended enum order from Zir.zig.
    271 
    272 #define ZIR_EXT_FOREACH_TAG(TAG)                                              \
    273     TAG(ZIR_EXT_STRUCT_DECL)                                                  \
    274     TAG(ZIR_EXT_ENUM_DECL)                                                    \
    275     TAG(ZIR_EXT_UNION_DECL)                                                   \
    276     TAG(ZIR_EXT_OPAQUE_DECL)                                                  \
    277     TAG(ZIR_EXT_TUPLE_DECL)                                                   \
    278     TAG(ZIR_EXT_THIS)                                                         \
    279     TAG(ZIR_EXT_RET_ADDR)                                                     \
    280     TAG(ZIR_EXT_BUILTIN_SRC)                                                  \
    281     TAG(ZIR_EXT_ERROR_RETURN_TRACE)                                           \
    282     TAG(ZIR_EXT_FRAME)                                                        \
    283     TAG(ZIR_EXT_FRAME_ADDRESS)                                                \
    284     TAG(ZIR_EXT_ALLOC)                                                        \
    285     TAG(ZIR_EXT_BUILTIN_EXTERN)                                               \
    286     TAG(ZIR_EXT_ASM)                                                          \
    287     TAG(ZIR_EXT_ASM_EXPR)                                                     \
    288     TAG(ZIR_EXT_COMPILE_LOG)                                                  \
    289     TAG(ZIR_EXT_TYPEOF_PEER)                                                  \
    290     TAG(ZIR_EXT_MIN_MULTI)                                                    \
    291     TAG(ZIR_EXT_MAX_MULTI)                                                    \
    292     TAG(ZIR_EXT_ADD_WITH_OVERFLOW)                                            \
    293     TAG(ZIR_EXT_SUB_WITH_OVERFLOW)                                            \
    294     TAG(ZIR_EXT_MUL_WITH_OVERFLOW)                                            \
    295     TAG(ZIR_EXT_SHL_WITH_OVERFLOW)                                            \
    296     TAG(ZIR_EXT_C_UNDEF)                                                      \
    297     TAG(ZIR_EXT_C_INCLUDE)                                                    \
    298     TAG(ZIR_EXT_C_DEFINE)                                                     \
    299     TAG(ZIR_EXT_WASM_MEMORY_SIZE)                                             \
    300     TAG(ZIR_EXT_WASM_MEMORY_GROW)                                             \
    301     TAG(ZIR_EXT_PREFETCH)                                                     \
    302     TAG(ZIR_EXT_SET_FLOAT_MODE)                                               \
    303     TAG(ZIR_EXT_ERROR_CAST)                                                   \
    304     TAG(ZIR_EXT_BREAKPOINT)                                                   \
    305     TAG(ZIR_EXT_DISABLE_INSTRUMENTATION)                                      \
    306     TAG(ZIR_EXT_DISABLE_INTRINSICS)                                           \
    307     TAG(ZIR_EXT_SELECT)                                                       \
    308     TAG(ZIR_EXT_INT_FROM_ERROR)                                               \
    309     TAG(ZIR_EXT_ERROR_FROM_INT)                                               \
    310     TAG(ZIR_EXT_REIFY)                                                        \
    311     TAG(ZIR_EXT_CMPXCHG)                                                      \
    312     TAG(ZIR_EXT_C_VA_ARG)                                                     \
    313     TAG(ZIR_EXT_C_VA_COPY)                                                    \
    314     TAG(ZIR_EXT_C_VA_END)                                                     \
    315     TAG(ZIR_EXT_C_VA_START)                                                   \
    316     TAG(ZIR_EXT_PTR_CAST_FULL)                                                \
    317     TAG(ZIR_EXT_PTR_CAST_NO_DEST)                                             \
    318     TAG(ZIR_EXT_WORK_ITEM_ID)                                                 \
    319     TAG(ZIR_EXT_WORK_GROUP_SIZE)                                              \
    320     TAG(ZIR_EXT_WORK_GROUP_ID)                                                \
    321     TAG(ZIR_EXT_IN_COMPTIME)                                                  \
    322     TAG(ZIR_EXT_RESTORE_ERR_RET_INDEX)                                        \
    323     TAG(ZIR_EXT_CLOSURE_GET)                                                  \
    324     TAG(ZIR_EXT_VALUE_PLACEHOLDER)                                            \
    325     TAG(ZIR_EXT_FIELD_PARENT_PTR)                                             \
    326     TAG(ZIR_EXT_BUILTIN_VALUE)                                                \
    327     TAG(ZIR_EXT_BRANCH_HINT)                                                  \
    328     TAG(ZIR_EXT_INPLACE_ARITH_RESULT_TY)                                      \
    329     TAG(ZIR_EXT_DBG_EMPTY_STMT)                                               \
    330     TAG(ZIR_EXT_ASTGEN_ERROR)
    331 
    332 #define ZIR_EXT_GENERATE_ENUM(e) e,
    333 typedef enum { ZIR_EXT_FOREACH_TAG(ZIR_EXT_GENERATE_ENUM) } ZirInstExtended;
    334 
    335 // --- ZIR instruction data (8-byte union) ---
    336 // Matches Zir.Inst.Data union from Zir.zig.
    337 
    338 typedef uint32_t ZirInstIndex;
    339 typedef uint32_t ZirInstRef;
    340 
    341 typedef union {
    342     struct {
    343         uint16_t opcode;
    344         uint16_t small;
    345         uint32_t operand;
    346     } extended;
    347     struct {
    348         int32_t src_node;
    349         ZirInstRef operand;
    350     } un_node;
    351     struct {
    352         int32_t src_tok;
    353         ZirInstRef operand;
    354     } un_tok;
    355     struct {
    356         int32_t src_node;
    357         uint32_t payload_index;
    358     } pl_node;
    359     struct {
    360         int32_t src_tok;
    361         uint32_t payload_index;
    362     } pl_tok;
    363     struct {
    364         ZirInstRef lhs;
    365         ZirInstRef rhs;
    366     } bin;
    367     struct {
    368         uint32_t start;
    369         uint32_t len;
    370     } str;
    371     struct {
    372         uint32_t start;
    373         int32_t src_tok;
    374     } str_tok;
    375     int32_t tok;
    376     int32_t node;
    377     uint64_t int_val;
    378     double float_val;
    379     struct {
    380         uint8_t flags;
    381         uint8_t size;
    382         uint16_t _pad;
    383         uint32_t payload_index;
    384     } ptr_type;
    385     struct {
    386         int32_t src_node;
    387         uint16_t bit_count;
    388         uint8_t signedness;
    389         uint8_t _pad;
    390     } int_type;
    391     struct {
    392         int32_t src_node;
    393         uint32_t _pad;
    394     } unreachable_data;
    395     struct {
    396         ZirInstRef operand;
    397         uint32_t payload_index;
    398     } break_data;
    399     struct {
    400         uint32_t line;
    401         uint32_t column;
    402     } dbg_stmt;
    403     struct {
    404         int32_t src_node;
    405         ZirInstIndex inst;
    406     } inst_node;
    407     struct {
    408         uint32_t str;
    409         ZirInstRef operand;
    410     } str_op;
    411     struct {
    412         uint32_t index;
    413         uint32_t len;
    414     } defer_data;
    415     struct {
    416         ZirInstRef err_code;
    417         uint32_t payload_index;
    418     } defer_err_code;
    419     struct {
    420         ZirInstRef operand;
    421         uint32_t _pad;
    422     } save_err_ret_index;
    423     struct {
    424         ZirInstRef operand;
    425         uint32_t idx;
    426     } elem_val_imm;
    427     struct {
    428         uint32_t src_node;
    429         uint32_t payload_index;
    430     } declaration;
    431 } ZirInstData;
    432 
    433 // --- ZIR built-in refs ---
    434 // Matches Zir.Inst.Ref enum from Zir.zig.
    435 // Values below REF_START_INDEX are InternPool indices.
    436 
    437 #define ZIR_REF_START_INDEX 124
    438 #define ZIR_REF_NONE UINT32_MAX
    439 #define ZIR_MAIN_STRUCT_INST 0
    440 
    441 // Zir.Inst.Ref enum values (matching Zig enum order in Zir.zig).
    442 // Types (0-103).
    443 #define ZIR_REF_U1_TYPE 2
    444 #define ZIR_REF_U8_TYPE 3
    445 #define ZIR_REF_I8_TYPE 4
    446 #define ZIR_REF_U16_TYPE 5
    447 #define ZIR_REF_I16_TYPE 6
    448 #define ZIR_REF_U29_TYPE 7
    449 #define ZIR_REF_U32_TYPE 8
    450 #define ZIR_REF_I32_TYPE 9
    451 #define ZIR_REF_U64_TYPE 10
    452 #define ZIR_REF_I64_TYPE 11
    453 #define ZIR_REF_U128_TYPE 13
    454 #define ZIR_REF_I128_TYPE 14
    455 #define ZIR_REF_USIZE_TYPE 16
    456 #define ZIR_REF_ISIZE_TYPE 17
    457 #define ZIR_REF_C_CHAR_TYPE 18
    458 #define ZIR_REF_C_SHORT_TYPE 19
    459 #define ZIR_REF_C_USHORT_TYPE 20
    460 #define ZIR_REF_C_INT_TYPE 21
    461 #define ZIR_REF_C_UINT_TYPE 22
    462 #define ZIR_REF_C_LONG_TYPE 23
    463 #define ZIR_REF_C_ULONG_TYPE 24
    464 #define ZIR_REF_C_LONGLONG_TYPE 25
    465 #define ZIR_REF_C_ULONGLONG_TYPE 26
    466 #define ZIR_REF_C_LONGDOUBLE_TYPE 27
    467 #define ZIR_REF_F16_TYPE 28
    468 #define ZIR_REF_F32_TYPE 29
    469 #define ZIR_REF_F64_TYPE 30
    470 #define ZIR_REF_F80_TYPE 31
    471 #define ZIR_REF_F128_TYPE 32
    472 #define ZIR_REF_ANYOPAQUE_TYPE 33
    473 #define ZIR_REF_BOOL_TYPE 34
    474 #define ZIR_REF_VOID_TYPE 35
    475 #define ZIR_REF_TYPE_TYPE 36
    476 #define ZIR_REF_ANYERROR_TYPE 37
    477 #define ZIR_REF_COMPTIME_INT_TYPE 38
    478 #define ZIR_REF_COMPTIME_FLOAT_TYPE 39
    479 #define ZIR_REF_NORETURN_TYPE 40
    480 #define ZIR_REF_ANYFRAME_TYPE 41
    481 #define ZIR_REF_NULL_TYPE 42
    482 #define ZIR_REF_UNDEFINED_TYPE 43
    483 #define ZIR_REF_ENUM_LITERAL_TYPE 44
    484 #define ZIR_REF_PTR_USIZE_TYPE 45
    485 #define ZIR_REF_PTR_CONST_COMPTIME_INT_TYPE 46
    486 #define ZIR_REF_MANYPTR_U8_TYPE 47
    487 #define ZIR_REF_MANYPTR_CONST_U8_TYPE 48
    488 #define ZIR_REF_MANYPTR_CONST_U8_SENTINEL_0_TYPE 49
    489 #define ZIR_REF_SLICE_CONST_U8_TYPE 50
    490 #define ZIR_REF_SLICE_CONST_U8_SENTINEL_0_TYPE 51
    491 #define ZIR_REF_ANYERROR_VOID_ERROR_UNION_TYPE 100
    492 #define ZIR_REF_GENERIC_POISON_TYPE 102
    493 #define ZIR_REF_EMPTY_TUPLE_TYPE 103
    494 // Values (104-123).
    495 #define ZIR_REF_UNDEF 104
    496 #define ZIR_REF_UNDEF_BOOL 105
    497 #define ZIR_REF_UNDEF_USIZE 106
    498 #define ZIR_REF_UNDEF_U1 107
    499 #define ZIR_REF_ZERO 108
    500 #define ZIR_REF_ZERO_USIZE 109
    501 #define ZIR_REF_ZERO_U1 110
    502 #define ZIR_REF_ZERO_U8 111
    503 #define ZIR_REF_ONE 112
    504 #define ZIR_REF_ONE_USIZE 113
    505 #define ZIR_REF_ONE_U1 114
    506 #define ZIR_REF_ONE_U8 115
    507 #define ZIR_REF_FOUR_U8 116
    508 #define ZIR_REF_NEGATIVE_ONE 117
    509 #define ZIR_REF_VOID_VALUE 118
    510 #define ZIR_REF_UNREACHABLE_VALUE 119
    511 #define ZIR_REF_NULL_VALUE 120
    512 #define ZIR_REF_BOOL_TRUE 121
    513 #define ZIR_REF_BOOL_FALSE 122
    514 #define ZIR_REF_EMPTY_TUPLE 123
    515 
    516 // Ast.Node.OptionalOffset.none = maxInt(i32).
    517 #define AST_NODE_OFFSET_NONE ((int32_t)0x7FFFFFFF)
    518 
    519 // --- Extra indices reserved at the start of extra[] ---
    520 // Matches Zir.ExtraIndex enum from Zir.zig.
    521 
    522 #define ZIR_EXTRA_COMPILE_ERRORS 0
    523 #define ZIR_EXTRA_IMPORTS 1
    524 #define ZIR_EXTRA_RESERVED_COUNT 2
    525 
    526 // --- Zir output structure ---
    527 
    528 typedef struct {
    529     uint32_t inst_len;
    530     uint32_t inst_cap;
    531     ZirInstTag* inst_tags;
    532     ZirInstData* inst_datas;
    533     uint32_t extra_len;
    534     uint32_t extra_cap;
    535     uint32_t* extra;
    536     uint32_t string_bytes_len;
    537     uint32_t string_bytes_cap;
    538     uint8_t* string_bytes;
    539     bool has_compile_errors;
    540 } Zir;
    541 
    542 void zirDeinit(Zir* zir);
    543 
    544 #endif