562 lines
31 KiB
C
562 lines
31 KiB
C
// zir.h — ZIR data structures, ported from lib/std/zig/Zir.zig.
|
|
#ifndef _ZIG0_ZIR_H__
|
|
#define _ZIG0_ZIR_H__
|
|
|
|
#include "common.h"
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
// --- ZIR instruction tags (uint8_t) ---
|
|
// Matches Zir.Inst.Tag enum order from Zir.zig.
|
|
|
|
#define ZIR_INST_FOREACH_TAG(TAG) \
|
|
TAG(ZIR_INST_ADD) \
|
|
TAG(ZIR_INST_ADDWRAP) \
|
|
TAG(ZIR_INST_ADD_SAT) \
|
|
TAG(ZIR_INST_ADD_UNSAFE) \
|
|
TAG(ZIR_INST_SUB) \
|
|
TAG(ZIR_INST_SUBWRAP) \
|
|
TAG(ZIR_INST_SUB_SAT) \
|
|
TAG(ZIR_INST_MUL) \
|
|
TAG(ZIR_INST_MULWRAP) \
|
|
TAG(ZIR_INST_MUL_SAT) \
|
|
TAG(ZIR_INST_DIV_EXACT) \
|
|
TAG(ZIR_INST_DIV_FLOOR) \
|
|
TAG(ZIR_INST_DIV_TRUNC) \
|
|
TAG(ZIR_INST_MOD) \
|
|
TAG(ZIR_INST_REM) \
|
|
TAG(ZIR_INST_MOD_REM) \
|
|
TAG(ZIR_INST_SHL) \
|
|
TAG(ZIR_INST_SHL_EXACT) \
|
|
TAG(ZIR_INST_SHL_SAT) \
|
|
TAG(ZIR_INST_SHR) \
|
|
TAG(ZIR_INST_SHR_EXACT) \
|
|
TAG(ZIR_INST_PARAM) \
|
|
TAG(ZIR_INST_PARAM_COMPTIME) \
|
|
TAG(ZIR_INST_PARAM_ANYTYPE) \
|
|
TAG(ZIR_INST_PARAM_ANYTYPE_COMPTIME) \
|
|
TAG(ZIR_INST_ARRAY_CAT) \
|
|
TAG(ZIR_INST_ARRAY_MUL) \
|
|
TAG(ZIR_INST_ARRAY_TYPE) \
|
|
TAG(ZIR_INST_ARRAY_TYPE_SENTINEL) \
|
|
TAG(ZIR_INST_VECTOR_TYPE) \
|
|
TAG(ZIR_INST_ELEM_TYPE) \
|
|
TAG(ZIR_INST_INDEXABLE_PTR_ELEM_TYPE) \
|
|
TAG(ZIR_INST_SPLAT_OP_RESULT_TY) \
|
|
TAG(ZIR_INST_INDEXABLE_PTR_LEN) \
|
|
TAG(ZIR_INST_ANYFRAME_TYPE) \
|
|
TAG(ZIR_INST_AS_NODE) \
|
|
TAG(ZIR_INST_AS_SHIFT_OPERAND) \
|
|
TAG(ZIR_INST_BIT_AND) \
|
|
TAG(ZIR_INST_BITCAST) \
|
|
TAG(ZIR_INST_BIT_NOT) \
|
|
TAG(ZIR_INST_BIT_OR) \
|
|
TAG(ZIR_INST_BLOCK) \
|
|
TAG(ZIR_INST_BLOCK_COMPTIME) \
|
|
TAG(ZIR_INST_BLOCK_INLINE) \
|
|
TAG(ZIR_INST_DECLARATION) \
|
|
TAG(ZIR_INST_SUSPEND_BLOCK) \
|
|
TAG(ZIR_INST_BOOL_NOT) \
|
|
TAG(ZIR_INST_BOOL_BR_AND) \
|
|
TAG(ZIR_INST_BOOL_BR_OR) \
|
|
TAG(ZIR_INST_BREAK) \
|
|
TAG(ZIR_INST_BREAK_INLINE) \
|
|
TAG(ZIR_INST_SWITCH_CONTINUE) \
|
|
TAG(ZIR_INST_CHECK_COMPTIME_CONTROL_FLOW) \
|
|
TAG(ZIR_INST_CALL) \
|
|
TAG(ZIR_INST_FIELD_CALL) \
|
|
TAG(ZIR_INST_BUILTIN_CALL) \
|
|
TAG(ZIR_INST_CMP_LT) \
|
|
TAG(ZIR_INST_CMP_LTE) \
|
|
TAG(ZIR_INST_CMP_EQ) \
|
|
TAG(ZIR_INST_CMP_GTE) \
|
|
TAG(ZIR_INST_CMP_GT) \
|
|
TAG(ZIR_INST_CMP_NEQ) \
|
|
TAG(ZIR_INST_CONDBR) \
|
|
TAG(ZIR_INST_CONDBR_INLINE) \
|
|
TAG(ZIR_INST_TRY) \
|
|
TAG(ZIR_INST_TRY_PTR) \
|
|
TAG(ZIR_INST_ERROR_SET_DECL) \
|
|
TAG(ZIR_INST_DBG_STMT) \
|
|
TAG(ZIR_INST_DBG_VAR_PTR) \
|
|
TAG(ZIR_INST_DBG_VAR_VAL) \
|
|
TAG(ZIR_INST_DECL_REF) \
|
|
TAG(ZIR_INST_DECL_VAL) \
|
|
TAG(ZIR_INST_LOAD) \
|
|
TAG(ZIR_INST_DIV) \
|
|
TAG(ZIR_INST_ELEM_PTR_NODE) \
|
|
TAG(ZIR_INST_ELEM_PTR) \
|
|
TAG(ZIR_INST_ELEM_VAL_NODE) \
|
|
TAG(ZIR_INST_ELEM_VAL) \
|
|
TAG(ZIR_INST_ELEM_VAL_IMM) \
|
|
TAG(ZIR_INST_ENSURE_RESULT_USED) \
|
|
TAG(ZIR_INST_ENSURE_RESULT_NON_ERROR) \
|
|
TAG(ZIR_INST_ENSURE_ERR_UNION_PAYLOAD_VOID) \
|
|
TAG(ZIR_INST_ERROR_UNION_TYPE) \
|
|
TAG(ZIR_INST_ERROR_VALUE) \
|
|
TAG(ZIR_INST_EXPORT) \
|
|
TAG(ZIR_INST_FIELD_PTR) \
|
|
TAG(ZIR_INST_FIELD_VAL) \
|
|
TAG(ZIR_INST_FIELD_PTR_NAMED) \
|
|
TAG(ZIR_INST_FIELD_VAL_NAMED) \
|
|
TAG(ZIR_INST_FUNC) \
|
|
TAG(ZIR_INST_FUNC_INFERRED) \
|
|
TAG(ZIR_INST_FUNC_FANCY) \
|
|
TAG(ZIR_INST_IMPORT) \
|
|
TAG(ZIR_INST_INT) \
|
|
TAG(ZIR_INST_INT_BIG) \
|
|
TAG(ZIR_INST_FLOAT) \
|
|
TAG(ZIR_INST_FLOAT128) \
|
|
TAG(ZIR_INST_INT_TYPE) \
|
|
TAG(ZIR_INST_IS_NON_NULL) \
|
|
TAG(ZIR_INST_IS_NON_NULL_PTR) \
|
|
TAG(ZIR_INST_IS_NON_ERR) \
|
|
TAG(ZIR_INST_IS_NON_ERR_PTR) \
|
|
TAG(ZIR_INST_RET_IS_NON_ERR) \
|
|
TAG(ZIR_INST_LOOP) \
|
|
TAG(ZIR_INST_REPEAT) \
|
|
TAG(ZIR_INST_REPEAT_INLINE) \
|
|
TAG(ZIR_INST_FOR_LEN) \
|
|
TAG(ZIR_INST_MERGE_ERROR_SETS) \
|
|
TAG(ZIR_INST_REF) \
|
|
TAG(ZIR_INST_RET_NODE) \
|
|
TAG(ZIR_INST_RET_LOAD) \
|
|
TAG(ZIR_INST_RET_IMPLICIT) \
|
|
TAG(ZIR_INST_RET_ERR_VALUE) \
|
|
TAG(ZIR_INST_RET_ERR_VALUE_CODE) \
|
|
TAG(ZIR_INST_RET_PTR) \
|
|
TAG(ZIR_INST_RET_TYPE) \
|
|
TAG(ZIR_INST_PTR_TYPE) \
|
|
TAG(ZIR_INST_SLICE_START) \
|
|
TAG(ZIR_INST_SLICE_END) \
|
|
TAG(ZIR_INST_SLICE_SENTINEL) \
|
|
TAG(ZIR_INST_SLICE_LENGTH) \
|
|
TAG(ZIR_INST_SLICE_SENTINEL_TY) \
|
|
TAG(ZIR_INST_STORE_NODE) \
|
|
TAG(ZIR_INST_STORE_TO_INFERRED_PTR) \
|
|
TAG(ZIR_INST_STR) \
|
|
TAG(ZIR_INST_NEGATE) \
|
|
TAG(ZIR_INST_NEGATE_WRAP) \
|
|
TAG(ZIR_INST_TYPEOF) \
|
|
TAG(ZIR_INST_TYPEOF_BUILTIN) \
|
|
TAG(ZIR_INST_TYPEOF_LOG2_INT_TYPE) \
|
|
TAG(ZIR_INST_UNREACHABLE) \
|
|
TAG(ZIR_INST_XOR) \
|
|
TAG(ZIR_INST_OPTIONAL_TYPE) \
|
|
TAG(ZIR_INST_OPTIONAL_PAYLOAD_SAFE) \
|
|
TAG(ZIR_INST_OPTIONAL_PAYLOAD_UNSAFE) \
|
|
TAG(ZIR_INST_OPTIONAL_PAYLOAD_SAFE_PTR) \
|
|
TAG(ZIR_INST_OPTIONAL_PAYLOAD_UNSAFE_PTR) \
|
|
TAG(ZIR_INST_ERR_UNION_PAYLOAD_UNSAFE) \
|
|
TAG(ZIR_INST_ERR_UNION_PAYLOAD_UNSAFE_PTR) \
|
|
TAG(ZIR_INST_ERR_UNION_CODE) \
|
|
TAG(ZIR_INST_ERR_UNION_CODE_PTR) \
|
|
TAG(ZIR_INST_ENUM_LITERAL) \
|
|
TAG(ZIR_INST_DECL_LITERAL) \
|
|
TAG(ZIR_INST_DECL_LITERAL_NO_COERCE) \
|
|
TAG(ZIR_INST_SWITCH_BLOCK) \
|
|
TAG(ZIR_INST_SWITCH_BLOCK_REF) \
|
|
TAG(ZIR_INST_SWITCH_BLOCK_ERR_UNION) \
|
|
TAG(ZIR_INST_VALIDATE_DEREF) \
|
|
TAG(ZIR_INST_VALIDATE_DESTRUCTURE) \
|
|
TAG(ZIR_INST_FIELD_TYPE_REF) \
|
|
TAG(ZIR_INST_OPT_EU_BASE_PTR_INIT) \
|
|
TAG(ZIR_INST_COERCE_PTR_ELEM_TY) \
|
|
TAG(ZIR_INST_VALIDATE_REF_TY) \
|
|
TAG(ZIR_INST_VALIDATE_CONST) \
|
|
TAG(ZIR_INST_STRUCT_INIT_EMPTY) \
|
|
TAG(ZIR_INST_STRUCT_INIT_EMPTY_RESULT) \
|
|
TAG(ZIR_INST_STRUCT_INIT_EMPTY_REF_RESULT) \
|
|
TAG(ZIR_INST_STRUCT_INIT_ANON) \
|
|
TAG(ZIR_INST_STRUCT_INIT) \
|
|
TAG(ZIR_INST_STRUCT_INIT_REF) \
|
|
TAG(ZIR_INST_VALIDATE_STRUCT_INIT_TY) \
|
|
TAG(ZIR_INST_VALIDATE_STRUCT_INIT_RESULT_TY) \
|
|
TAG(ZIR_INST_VALIDATE_PTR_STRUCT_INIT) \
|
|
TAG(ZIR_INST_STRUCT_INIT_FIELD_TYPE) \
|
|
TAG(ZIR_INST_STRUCT_INIT_FIELD_PTR) \
|
|
TAG(ZIR_INST_ARRAY_INIT_ANON) \
|
|
TAG(ZIR_INST_ARRAY_INIT) \
|
|
TAG(ZIR_INST_ARRAY_INIT_REF) \
|
|
TAG(ZIR_INST_VALIDATE_ARRAY_INIT_TY) \
|
|
TAG(ZIR_INST_VALIDATE_ARRAY_INIT_RESULT_TY) \
|
|
TAG(ZIR_INST_VALIDATE_ARRAY_INIT_REF_TY) \
|
|
TAG(ZIR_INST_VALIDATE_PTR_ARRAY_INIT) \
|
|
TAG(ZIR_INST_ARRAY_INIT_ELEM_TYPE) \
|
|
TAG(ZIR_INST_ARRAY_INIT_ELEM_PTR) \
|
|
TAG(ZIR_INST_UNION_INIT) \
|
|
TAG(ZIR_INST_TYPE_INFO) \
|
|
TAG(ZIR_INST_SIZE_OF) \
|
|
TAG(ZIR_INST_BIT_SIZE_OF) \
|
|
TAG(ZIR_INST_INT_FROM_PTR) \
|
|
TAG(ZIR_INST_COMPILE_ERROR) \
|
|
TAG(ZIR_INST_SET_EVAL_BRANCH_QUOTA) \
|
|
TAG(ZIR_INST_INT_FROM_ENUM) \
|
|
TAG(ZIR_INST_ALIGN_OF) \
|
|
TAG(ZIR_INST_INT_FROM_BOOL) \
|
|
TAG(ZIR_INST_EMBED_FILE) \
|
|
TAG(ZIR_INST_ERROR_NAME) \
|
|
TAG(ZIR_INST_PANIC) \
|
|
TAG(ZIR_INST_TRAP) \
|
|
TAG(ZIR_INST_SET_RUNTIME_SAFETY) \
|
|
TAG(ZIR_INST_SQRT) \
|
|
TAG(ZIR_INST_SIN) \
|
|
TAG(ZIR_INST_COS) \
|
|
TAG(ZIR_INST_TAN) \
|
|
TAG(ZIR_INST_EXP) \
|
|
TAG(ZIR_INST_EXP2) \
|
|
TAG(ZIR_INST_LOG) \
|
|
TAG(ZIR_INST_LOG2) \
|
|
TAG(ZIR_INST_LOG10) \
|
|
TAG(ZIR_INST_ABS) \
|
|
TAG(ZIR_INST_FLOOR) \
|
|
TAG(ZIR_INST_CEIL) \
|
|
TAG(ZIR_INST_TRUNC) \
|
|
TAG(ZIR_INST_ROUND) \
|
|
TAG(ZIR_INST_TAG_NAME) \
|
|
TAG(ZIR_INST_TYPE_NAME) \
|
|
TAG(ZIR_INST_FRAME_TYPE) \
|
|
TAG(ZIR_INST_INT_FROM_FLOAT) \
|
|
TAG(ZIR_INST_FLOAT_FROM_INT) \
|
|
TAG(ZIR_INST_PTR_FROM_INT) \
|
|
TAG(ZIR_INST_ENUM_FROM_INT) \
|
|
TAG(ZIR_INST_FLOAT_CAST) \
|
|
TAG(ZIR_INST_INT_CAST) \
|
|
TAG(ZIR_INST_PTR_CAST) \
|
|
TAG(ZIR_INST_TRUNCATE) \
|
|
TAG(ZIR_INST_HAS_DECL) \
|
|
TAG(ZIR_INST_HAS_FIELD) \
|
|
TAG(ZIR_INST_CLZ) \
|
|
TAG(ZIR_INST_CTZ) \
|
|
TAG(ZIR_INST_POP_COUNT) \
|
|
TAG(ZIR_INST_BYTE_SWAP) \
|
|
TAG(ZIR_INST_BIT_REVERSE) \
|
|
TAG(ZIR_INST_BIT_OFFSET_OF) \
|
|
TAG(ZIR_INST_OFFSET_OF) \
|
|
TAG(ZIR_INST_SPLAT) \
|
|
TAG(ZIR_INST_REDUCE) \
|
|
TAG(ZIR_INST_SHUFFLE) \
|
|
TAG(ZIR_INST_ATOMIC_LOAD) \
|
|
TAG(ZIR_INST_ATOMIC_RMW) \
|
|
TAG(ZIR_INST_ATOMIC_STORE) \
|
|
TAG(ZIR_INST_MUL_ADD) \
|
|
TAG(ZIR_INST_MEMCPY) \
|
|
TAG(ZIR_INST_MEMMOVE) \
|
|
TAG(ZIR_INST_MEMSET) \
|
|
TAG(ZIR_INST_MIN) \
|
|
TAG(ZIR_INST_MAX) \
|
|
TAG(ZIR_INST_C_IMPORT) \
|
|
TAG(ZIR_INST_ALLOC) \
|
|
TAG(ZIR_INST_ALLOC_MUT) \
|
|
TAG(ZIR_INST_ALLOC_COMPTIME_MUT) \
|
|
TAG(ZIR_INST_ALLOC_INFERRED) \
|
|
TAG(ZIR_INST_ALLOC_INFERRED_MUT) \
|
|
TAG(ZIR_INST_ALLOC_INFERRED_COMPTIME) \
|
|
TAG(ZIR_INST_ALLOC_INFERRED_COMPTIME_MUT) \
|
|
TAG(ZIR_INST_RESOLVE_INFERRED_ALLOC) \
|
|
TAG(ZIR_INST_MAKE_PTR_CONST) \
|
|
TAG(ZIR_INST_RESUME) \
|
|
TAG(ZIR_INST_DEFER) \
|
|
TAG(ZIR_INST_DEFER_ERR_CODE) \
|
|
TAG(ZIR_INST_SAVE_ERR_RET_INDEX) \
|
|
TAG(ZIR_INST_RESTORE_ERR_RET_INDEX_UNCONDITIONAL) \
|
|
TAG(ZIR_INST_RESTORE_ERR_RET_INDEX_FN_ENTRY) \
|
|
TAG(ZIR_INST_EXTENDED)
|
|
|
|
#define ZIR_GENERATE_ENUM(e) e,
|
|
typedef enum { ZIR_INST_FOREACH_TAG(ZIR_GENERATE_ENUM) } ZirInstTag;
|
|
|
|
// --- ZIR extended opcodes (uint16_t) ---
|
|
// Matches Zir.Inst.Extended enum order from Zir.zig.
|
|
|
|
#define ZIR_EXT_FOREACH_TAG(TAG) \
|
|
TAG(ZIR_EXT_STRUCT_DECL) \
|
|
TAG(ZIR_EXT_ENUM_DECL) \
|
|
TAG(ZIR_EXT_UNION_DECL) \
|
|
TAG(ZIR_EXT_OPAQUE_DECL) \
|
|
TAG(ZIR_EXT_TUPLE_DECL) \
|
|
TAG(ZIR_EXT_THIS) \
|
|
TAG(ZIR_EXT_RET_ADDR) \
|
|
TAG(ZIR_EXT_BUILTIN_SRC) \
|
|
TAG(ZIR_EXT_ERROR_RETURN_TRACE) \
|
|
TAG(ZIR_EXT_FRAME) \
|
|
TAG(ZIR_EXT_FRAME_ADDRESS) \
|
|
TAG(ZIR_EXT_ALLOC) \
|
|
TAG(ZIR_EXT_BUILTIN_EXTERN) \
|
|
TAG(ZIR_EXT_ASM) \
|
|
TAG(ZIR_EXT_ASM_EXPR) \
|
|
TAG(ZIR_EXT_COMPILE_LOG) \
|
|
TAG(ZIR_EXT_TYPEOF_PEER) \
|
|
TAG(ZIR_EXT_MIN_MULTI) \
|
|
TAG(ZIR_EXT_MAX_MULTI) \
|
|
TAG(ZIR_EXT_ADD_WITH_OVERFLOW) \
|
|
TAG(ZIR_EXT_SUB_WITH_OVERFLOW) \
|
|
TAG(ZIR_EXT_MUL_WITH_OVERFLOW) \
|
|
TAG(ZIR_EXT_SHL_WITH_OVERFLOW) \
|
|
TAG(ZIR_EXT_C_UNDEF) \
|
|
TAG(ZIR_EXT_C_INCLUDE) \
|
|
TAG(ZIR_EXT_C_DEFINE) \
|
|
TAG(ZIR_EXT_WASM_MEMORY_SIZE) \
|
|
TAG(ZIR_EXT_WASM_MEMORY_GROW) \
|
|
TAG(ZIR_EXT_PREFETCH) \
|
|
TAG(ZIR_EXT_SET_FLOAT_MODE) \
|
|
TAG(ZIR_EXT_ERROR_CAST) \
|
|
TAG(ZIR_EXT_BREAKPOINT) \
|
|
TAG(ZIR_EXT_DISABLE_INSTRUMENTATION) \
|
|
TAG(ZIR_EXT_DISABLE_INTRINSICS) \
|
|
TAG(ZIR_EXT_SELECT) \
|
|
TAG(ZIR_EXT_INT_FROM_ERROR) \
|
|
TAG(ZIR_EXT_ERROR_FROM_INT) \
|
|
TAG(ZIR_EXT_REIFY) \
|
|
TAG(ZIR_EXT_CMPXCHG) \
|
|
TAG(ZIR_EXT_C_VA_ARG) \
|
|
TAG(ZIR_EXT_C_VA_COPY) \
|
|
TAG(ZIR_EXT_C_VA_END) \
|
|
TAG(ZIR_EXT_C_VA_START) \
|
|
TAG(ZIR_EXT_PTR_CAST_FULL) \
|
|
TAG(ZIR_EXT_PTR_CAST_NO_DEST) \
|
|
TAG(ZIR_EXT_WORK_ITEM_ID) \
|
|
TAG(ZIR_EXT_WORK_GROUP_SIZE) \
|
|
TAG(ZIR_EXT_WORK_GROUP_ID) \
|
|
TAG(ZIR_EXT_IN_COMPTIME) \
|
|
TAG(ZIR_EXT_RESTORE_ERR_RET_INDEX) \
|
|
TAG(ZIR_EXT_CLOSURE_GET) \
|
|
TAG(ZIR_EXT_VALUE_PLACEHOLDER) \
|
|
TAG(ZIR_EXT_FIELD_PARENT_PTR) \
|
|
TAG(ZIR_EXT_BUILTIN_VALUE) \
|
|
TAG(ZIR_EXT_BRANCH_HINT) \
|
|
TAG(ZIR_EXT_INPLACE_ARITH_RESULT_TY) \
|
|
TAG(ZIR_EXT_DBG_EMPTY_STMT) \
|
|
TAG(ZIR_EXT_ASTGEN_ERROR)
|
|
|
|
#define ZIR_EXT_GENERATE_ENUM(e) e,
|
|
typedef enum { ZIR_EXT_FOREACH_TAG(ZIR_EXT_GENERATE_ENUM) } ZirInstExtended;
|
|
|
|
// --- ZIR instruction data (8-byte union) ---
|
|
// Matches Zir.Inst.Data union from Zir.zig.
|
|
|
|
typedef uint32_t ZirInstIndex;
|
|
typedef uint32_t ZirInstRef;
|
|
|
|
typedef union {
|
|
struct {
|
|
uint16_t opcode;
|
|
uint16_t small;
|
|
uint32_t operand;
|
|
} extended;
|
|
struct {
|
|
int32_t src_node;
|
|
ZirInstRef operand;
|
|
} un_node;
|
|
struct {
|
|
int32_t src_tok;
|
|
ZirInstRef operand;
|
|
} un_tok;
|
|
struct {
|
|
int32_t src_node;
|
|
uint32_t payload_index;
|
|
} pl_node;
|
|
struct {
|
|
int32_t src_tok;
|
|
uint32_t payload_index;
|
|
} pl_tok;
|
|
struct {
|
|
ZirInstRef lhs;
|
|
ZirInstRef rhs;
|
|
} bin;
|
|
struct {
|
|
uint32_t start;
|
|
uint32_t len;
|
|
} str;
|
|
struct {
|
|
uint32_t start;
|
|
int32_t src_tok;
|
|
} str_tok;
|
|
int32_t tok;
|
|
int32_t node;
|
|
uint64_t int_val;
|
|
double float_val;
|
|
struct {
|
|
uint8_t flags;
|
|
uint8_t size;
|
|
uint16_t _pad;
|
|
uint32_t payload_index;
|
|
} ptr_type;
|
|
struct {
|
|
int32_t src_node;
|
|
uint16_t bit_count;
|
|
uint8_t signedness;
|
|
uint8_t _pad;
|
|
} int_type;
|
|
struct {
|
|
int32_t src_node;
|
|
uint32_t _pad;
|
|
} unreachable_data;
|
|
struct {
|
|
ZirInstRef operand;
|
|
uint32_t payload_index;
|
|
} break_data;
|
|
struct {
|
|
uint32_t line;
|
|
uint32_t column;
|
|
} dbg_stmt;
|
|
struct {
|
|
int32_t src_node;
|
|
ZirInstIndex inst;
|
|
} inst_node;
|
|
struct {
|
|
uint32_t str;
|
|
ZirInstRef operand;
|
|
} str_op;
|
|
struct {
|
|
uint32_t index;
|
|
uint32_t len;
|
|
} defer_data;
|
|
struct {
|
|
ZirInstRef err_code;
|
|
uint32_t payload_index;
|
|
} defer_err_code;
|
|
struct {
|
|
ZirInstRef operand;
|
|
uint32_t _pad;
|
|
} save_err_ret_index;
|
|
struct {
|
|
ZirInstRef operand;
|
|
uint32_t idx;
|
|
} elem_val_imm;
|
|
struct {
|
|
uint32_t src_node;
|
|
uint32_t payload_index;
|
|
} declaration;
|
|
} ZirInstData;
|
|
|
|
// --- ZIR built-in refs ---
|
|
// Matches Zir.Inst.Ref enum from Zir.zig.
|
|
// Values below REF_START_INDEX are InternPool indices.
|
|
|
|
#define ZIR_REF_START_INDEX 124
|
|
#define ZIR_REF_NONE UINT32_MAX
|
|
#define ZIR_MAIN_STRUCT_INST 0
|
|
|
|
// Zir.Inst.Ref enum values (matching Zig enum order in Zir.zig).
|
|
// Types (0-103).
|
|
#define ZIR_REF_U1_TYPE 2
|
|
#define ZIR_REF_U8_TYPE 3
|
|
#define ZIR_REF_I8_TYPE 4
|
|
#define ZIR_REF_U16_TYPE 5
|
|
#define ZIR_REF_I16_TYPE 6
|
|
#define ZIR_REF_U29_TYPE 7
|
|
#define ZIR_REF_U32_TYPE 8
|
|
#define ZIR_REF_I32_TYPE 9
|
|
#define ZIR_REF_U64_TYPE 10
|
|
#define ZIR_REF_I64_TYPE 11
|
|
#define ZIR_REF_U128_TYPE 13
|
|
#define ZIR_REF_I128_TYPE 14
|
|
#define ZIR_REF_USIZE_TYPE 16
|
|
#define ZIR_REF_ISIZE_TYPE 17
|
|
#define ZIR_REF_C_CHAR_TYPE 18
|
|
#define ZIR_REF_C_SHORT_TYPE 19
|
|
#define ZIR_REF_C_USHORT_TYPE 20
|
|
#define ZIR_REF_C_INT_TYPE 21
|
|
#define ZIR_REF_C_UINT_TYPE 22
|
|
#define ZIR_REF_C_LONG_TYPE 23
|
|
#define ZIR_REF_C_ULONG_TYPE 24
|
|
#define ZIR_REF_C_LONGLONG_TYPE 25
|
|
#define ZIR_REF_C_ULONGLONG_TYPE 26
|
|
#define ZIR_REF_C_LONGDOUBLE_TYPE 27
|
|
#define ZIR_REF_F16_TYPE 28
|
|
#define ZIR_REF_F32_TYPE 29
|
|
#define ZIR_REF_F64_TYPE 30
|
|
#define ZIR_REF_F80_TYPE 31
|
|
#define ZIR_REF_F128_TYPE 32
|
|
#define ZIR_REF_ANYOPAQUE_TYPE 33
|
|
#define ZIR_REF_BOOL_TYPE 34
|
|
#define ZIR_REF_VOID_TYPE 35
|
|
#define ZIR_REF_TYPE_TYPE 36
|
|
#define ZIR_REF_ANYERROR_TYPE 37
|
|
#define ZIR_REF_COMPTIME_INT_TYPE 38
|
|
#define ZIR_REF_COMPTIME_FLOAT_TYPE 39
|
|
#define ZIR_REF_NORETURN_TYPE 40
|
|
#define ZIR_REF_ANYFRAME_TYPE 41
|
|
#define ZIR_REF_NULL_TYPE 42
|
|
#define ZIR_REF_UNDEFINED_TYPE 43
|
|
#define ZIR_REF_ENUM_LITERAL_TYPE 44
|
|
#define ZIR_REF_PTR_USIZE_TYPE 45
|
|
#define ZIR_REF_PTR_CONST_COMPTIME_INT_TYPE 46
|
|
#define ZIR_REF_MANYPTR_U8_TYPE 47
|
|
#define ZIR_REF_MANYPTR_CONST_U8_TYPE 48
|
|
#define ZIR_REF_MANYPTR_CONST_U8_SENTINEL_0_TYPE 49
|
|
#define ZIR_REF_SLICE_CONST_U8_TYPE 50
|
|
#define ZIR_REF_SLICE_CONST_U8_SENTINEL_0_TYPE 51
|
|
#define ZIR_REF_ANYERROR_VOID_ERROR_UNION_TYPE 100
|
|
#define ZIR_REF_GENERIC_POISON_TYPE 102
|
|
#define ZIR_REF_EMPTY_TUPLE_TYPE 103
|
|
// Values (104-123).
|
|
#define ZIR_REF_UNDEF 104
|
|
#define ZIR_REF_UNDEF_BOOL 105
|
|
#define ZIR_REF_UNDEF_USIZE 106
|
|
#define ZIR_REF_UNDEF_U1 107
|
|
#define ZIR_REF_ZERO 108
|
|
#define ZIR_REF_ZERO_USIZE 109
|
|
#define ZIR_REF_ZERO_U1 110
|
|
#define ZIR_REF_ZERO_U8 111
|
|
#define ZIR_REF_ONE 112
|
|
#define ZIR_REF_ONE_USIZE 113
|
|
#define ZIR_REF_ONE_U1 114
|
|
#define ZIR_REF_ONE_U8 115
|
|
#define ZIR_REF_FOUR_U8 116
|
|
#define ZIR_REF_NEGATIVE_ONE 117
|
|
#define ZIR_REF_VOID_VALUE 118
|
|
#define ZIR_REF_UNREACHABLE_VALUE 119
|
|
#define ZIR_REF_NULL_VALUE 120
|
|
#define ZIR_REF_BOOL_TRUE 121
|
|
#define ZIR_REF_BOOL_FALSE 122
|
|
#define ZIR_REF_EMPTY_TUPLE 123
|
|
|
|
// Zir.Inst.BuiltinValue enum (Zir.zig:3476-3494).
|
|
#define ZIR_BUILTIN_VALUE_ATOMIC_ORDER 0
|
|
#define ZIR_BUILTIN_VALUE_ATOMIC_RMW_OP 1
|
|
#define ZIR_BUILTIN_VALUE_CALLING_CONVENTION 2
|
|
#define ZIR_BUILTIN_VALUE_ADDRESS_SPACE 3
|
|
#define ZIR_BUILTIN_VALUE_FLOAT_MODE 4
|
|
#define ZIR_BUILTIN_VALUE_REDUCE_OP 5
|
|
#define ZIR_BUILTIN_VALUE_CALL_MODIFIER 6
|
|
#define ZIR_BUILTIN_VALUE_PREFETCH_OPTIONS 7
|
|
#define ZIR_BUILTIN_VALUE_EXPORT_OPTIONS 8
|
|
#define ZIR_BUILTIN_VALUE_EXTERN_OPTIONS 9
|
|
#define ZIR_BUILTIN_VALUE_TYPE_INFO 10
|
|
#define ZIR_BUILTIN_VALUE_BRANCH_HINT 11
|
|
#define ZIR_BUILTIN_VALUE_CLOBBERS 12
|
|
#define ZIR_BUILTIN_VALUE_CALLING_CONVENTION_C 13
|
|
#define ZIR_BUILTIN_VALUE_CALLING_CONVENTION_INLINE 14
|
|
|
|
// Ast.Node.OptionalOffset.none = maxInt(i32).
|
|
#define AST_NODE_OFFSET_NONE ((int32_t)0x7FFFFFFF)
|
|
|
|
// --- Extra indices reserved at the start of extra[] ---
|
|
// Matches Zir.ExtraIndex enum from Zir.zig.
|
|
|
|
#define ZIR_EXTRA_COMPILE_ERRORS 0
|
|
#define ZIR_EXTRA_IMPORTS 1
|
|
#define ZIR_EXTRA_RESERVED_COUNT 2
|
|
|
|
// --- Zir output structure ---
|
|
|
|
typedef struct {
|
|
uint32_t inst_len;
|
|
uint32_t inst_cap;
|
|
ZirInstTag* inst_tags;
|
|
ZirInstData* inst_datas;
|
|
uint32_t extra_len;
|
|
uint32_t extra_cap;
|
|
uint32_t* extra;
|
|
uint32_t string_bytes_len;
|
|
uint32_t string_bytes_cap;
|
|
uint8_t* string_bytes;
|
|
bool has_compile_errors;
|
|
} Zir;
|
|
|
|
void zirDeinit(Zir* zir);
|
|
|
|
#endif
|