| ... | ... | @@ -17,31 +17,33 @@ |
| 17 | 17 | |
| 18 | 18 | #include <errno.h> |
| 19 | 19 | |
| 20 | | struct IrExecContext { |
| 21 | | ZigList<ZigValue *> mem_slot_list; |
| 20 | struct IrBuilderSrc { |
| 21 | CodeGen *codegen; |
| 22 | IrExecutableSrc *exec; |
| 23 | IrBasicBlockSrc *current_basic_block; |
| 24 | AstNode *main_block_node; |
| 22 | 25 | }; |
| 23 | 26 | |
| 24 | | struct IrBuilder { |
| 27 | struct IrBuilderGen { |
| 25 | 28 | CodeGen *codegen; |
| 26 | | IrExecutable *exec; |
| 27 | | IrBasicBlock *current_basic_block; |
| 28 | | AstNode *main_block_node; |
| 29 | IrExecutableGen *exec; |
| 30 | IrBasicBlockGen *current_basic_block; |
| 29 | 31 | }; |
| 30 | 32 | |
| 31 | 33 | struct IrAnalyze { |
| 32 | 34 | CodeGen *codegen; |
| 33 | | IrBuilder old_irb; |
| 34 | | IrBuilder new_irb; |
| 35 | | IrExecContext exec_context; |
| 35 | IrBuilderSrc old_irb; |
| 36 | IrBuilderGen new_irb; |
| 36 | 37 | size_t old_bb_index; |
| 37 | 38 | size_t instruction_index; |
| 38 | 39 | ZigType *explicit_return_type; |
| 39 | 40 | AstNode *explicit_return_type_source_node; |
| 40 | | ZigList<IrInstruction *> src_implicit_return_type_list; |
| 41 | ZigList<IrInstGen *> src_implicit_return_type_list; |
| 41 | 42 | ZigList<IrSuspendPosition> resume_stack; |
| 42 | | IrBasicBlock *const_predecessor_bb; |
| 43 | IrBasicBlockSrc *const_predecessor_bb; |
| 43 | 44 | size_t ref_count; |
| 44 | 45 | size_t break_debug_id; // for debugging purposes |
| 46 | IrInstGen *return_ptr; |
| 45 | 47 | |
| 46 | 48 | // For the purpose of using in a debugger |
| 47 | 49 | void dump(); |
| ... | ... | @@ -206,412 +208,538 @@ struct DbgIrBreakPoint { |
| 206 | 208 | DbgIrBreakPoint dbg_ir_breakpoints_buf[20]; |
| 207 | 209 | size_t dbg_ir_breakpoints_count = 0; |
| 208 | 210 | |
| 209 | | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 210 | | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, |
| 211 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope); |
| 212 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, |
| 211 | 213 | ResultLoc *result_loc); |
| 212 | | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); |
| 213 | | static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr, |
| 214 | | IrInstruction *value, ZigType *expected_type); |
| 215 | | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr, |
| 214 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type); |
| 215 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 216 | IrInstGen *value, ZigType *expected_type); |
| 217 | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, |
| 216 | 218 | ResultLoc *result_loc); |
| 217 | | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 218 | | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 219 | | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing); |
| 220 | | static void ir_assert(bool ok, IrInstruction *source_instruction); |
| 221 | | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); |
| 222 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 223 | | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc); |
| 224 | | static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc); |
| 219 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg); |
| 220 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 221 | IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src, |
| 222 | ZigType *container_type, bool initializing); |
| 223 | static void ir_assert(bool ok, IrInst* source_instruction); |
| 224 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); |
| 225 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| 226 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 227 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); |
| 228 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); |
| 225 | 229 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 226 | 230 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| 227 | 231 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val); |
| 228 | 232 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); |
| 229 | 233 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 230 | 234 | ZigValue *out_val, ZigValue *ptr_val); |
| 231 | | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 232 | | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on); |
| 233 | | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); |
| 235 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 236 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); |
| 237 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); |
| 234 | 238 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 235 | | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 239 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 236 | 240 | ZigType *ptr_type); |
| 237 | | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 241 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 238 | 242 | ZigType *dest_type); |
| 239 | | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 240 | | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 241 | | bool non_null_comptime, bool allow_discard); |
| 242 | | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 243 | | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 244 | | bool non_null_comptime, bool allow_discard); |
| 245 | | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 246 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing); |
| 247 | | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 248 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing); |
| 249 | | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 250 | | IrInstruction *base_ptr, bool initializing); |
| 251 | | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 252 | | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const); |
| 253 | | static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 254 | | IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node, |
| 243 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 244 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 245 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 246 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 247 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 248 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 249 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 250 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 251 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 252 | IrInstGen *base_ptr, bool initializing); |
| 253 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 254 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const); |
| 255 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 256 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 255 | 257 | LVal lval, ResultLoc *parent_result_loc); |
| 256 | 258 | static void ir_reset_result(ResultLoc *result_loc); |
| 257 | | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 259 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name, |
| 258 | 260 | Scope *scope, AstNode *source_node, Buf *out_bare_name); |
| 259 | | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, |
| 261 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, |
| 260 | 262 | ResultLoc *parent_result_loc); |
| 261 | | static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 262 | | TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing); |
| 263 | | static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 264 | | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 263 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 264 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing); |
| 265 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 266 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type); |
| 265 | 267 | static ResultLoc *no_result_loc(void); |
| 266 | | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value); |
| 268 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value); |
| 269 | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr); |
| 270 | |
| 271 | static void destroy_instruction_src(IrInstSrc *inst) { |
| 272 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 273 | const char *name = ir_inst_src_type_str(inst->id); |
| 274 | #else |
| 275 | const char *name = nullptr; |
| 276 | #endif |
| 277 | switch (inst->id) { |
| 278 | case IrInstSrcIdInvalid: |
| 279 | zig_unreachable(); |
| 280 | case IrInstSrcIdReturn: |
| 281 | return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name); |
| 282 | case IrInstSrcIdConst: |
| 283 | return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name); |
| 284 | case IrInstSrcIdBinOp: |
| 285 | return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name); |
| 286 | case IrInstSrcIdMergeErrSets: |
| 287 | return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name); |
| 288 | case IrInstSrcIdDeclVar: |
| 289 | return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name); |
| 290 | case IrInstSrcIdCall: |
| 291 | return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name); |
| 292 | case IrInstSrcIdCallExtra: |
| 293 | return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name); |
| 294 | case IrInstSrcIdUnOp: |
| 295 | return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name); |
| 296 | case IrInstSrcIdCondBr: |
| 297 | return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name); |
| 298 | case IrInstSrcIdBr: |
| 299 | return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name); |
| 300 | case IrInstSrcIdPhi: |
| 301 | return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name); |
| 302 | case IrInstSrcIdContainerInitList: |
| 303 | return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name); |
| 304 | case IrInstSrcIdContainerInitFields: |
| 305 | return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name); |
| 306 | case IrInstSrcIdUnreachable: |
| 307 | return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name); |
| 308 | case IrInstSrcIdElemPtr: |
| 309 | return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name); |
| 310 | case IrInstSrcIdVarPtr: |
| 311 | return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name); |
| 312 | case IrInstSrcIdLoadPtr: |
| 313 | return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name); |
| 314 | case IrInstSrcIdStorePtr: |
| 315 | return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name); |
| 316 | case IrInstSrcIdTypeOf: |
| 317 | return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name); |
| 318 | case IrInstSrcIdFieldPtr: |
| 319 | return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name); |
| 320 | case IrInstSrcIdSetCold: |
| 321 | return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name); |
| 322 | case IrInstSrcIdSetRuntimeSafety: |
| 323 | return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name); |
| 324 | case IrInstSrcIdSetFloatMode: |
| 325 | return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name); |
| 326 | case IrInstSrcIdArrayType: |
| 327 | return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name); |
| 328 | case IrInstSrcIdSliceType: |
| 329 | return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name); |
| 330 | case IrInstSrcIdAnyFrameType: |
| 331 | return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name); |
| 332 | case IrInstSrcIdAsm: |
| 333 | return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name); |
| 334 | case IrInstSrcIdSizeOf: |
| 335 | return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name); |
| 336 | case IrInstSrcIdTestNonNull: |
| 337 | return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name); |
| 338 | case IrInstSrcIdOptionalUnwrapPtr: |
| 339 | return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name); |
| 340 | case IrInstSrcIdPopCount: |
| 341 | return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name); |
| 342 | case IrInstSrcIdClz: |
| 343 | return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name); |
| 344 | case IrInstSrcIdCtz: |
| 345 | return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name); |
| 346 | case IrInstSrcIdBswap: |
| 347 | return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name); |
| 348 | case IrInstSrcIdBitReverse: |
| 349 | return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name); |
| 350 | case IrInstSrcIdSwitchBr: |
| 351 | return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name); |
| 352 | case IrInstSrcIdSwitchVar: |
| 353 | return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name); |
| 354 | case IrInstSrcIdSwitchElseVar: |
| 355 | return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name); |
| 356 | case IrInstSrcIdSwitchTarget: |
| 357 | return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name); |
| 358 | case IrInstSrcIdImport: |
| 359 | return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name); |
| 360 | case IrInstSrcIdRef: |
| 361 | return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name); |
| 362 | case IrInstSrcIdCompileErr: |
| 363 | return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name); |
| 364 | case IrInstSrcIdCompileLog: |
| 365 | return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name); |
| 366 | case IrInstSrcIdErrName: |
| 367 | return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name); |
| 368 | case IrInstSrcIdCImport: |
| 369 | return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name); |
| 370 | case IrInstSrcIdCInclude: |
| 371 | return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name); |
| 372 | case IrInstSrcIdCDefine: |
| 373 | return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name); |
| 374 | case IrInstSrcIdCUndef: |
| 375 | return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name); |
| 376 | case IrInstSrcIdEmbedFile: |
| 377 | return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name); |
| 378 | case IrInstSrcIdCmpxchg: |
| 379 | return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name); |
| 380 | case IrInstSrcIdFence: |
| 381 | return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name); |
| 382 | case IrInstSrcIdTruncate: |
| 383 | return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name); |
| 384 | case IrInstSrcIdIntCast: |
| 385 | return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name); |
| 386 | case IrInstSrcIdFloatCast: |
| 387 | return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name); |
| 388 | case IrInstSrcIdErrSetCast: |
| 389 | return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name); |
| 390 | case IrInstSrcIdFromBytes: |
| 391 | return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name); |
| 392 | case IrInstSrcIdToBytes: |
| 393 | return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name); |
| 394 | case IrInstSrcIdIntToFloat: |
| 395 | return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name); |
| 396 | case IrInstSrcIdFloatToInt: |
| 397 | return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name); |
| 398 | case IrInstSrcIdBoolToInt: |
| 399 | return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name); |
| 400 | case IrInstSrcIdIntType: |
| 401 | return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name); |
| 402 | case IrInstSrcIdVectorType: |
| 403 | return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name); |
| 404 | case IrInstSrcIdShuffleVector: |
| 405 | return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name); |
| 406 | case IrInstSrcIdSplat: |
| 407 | return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name); |
| 408 | case IrInstSrcIdBoolNot: |
| 409 | return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name); |
| 410 | case IrInstSrcIdMemset: |
| 411 | return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name); |
| 412 | case IrInstSrcIdMemcpy: |
| 413 | return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name); |
| 414 | case IrInstSrcIdSlice: |
| 415 | return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name); |
| 416 | case IrInstSrcIdMemberCount: |
| 417 | return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name); |
| 418 | case IrInstSrcIdMemberType: |
| 419 | return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name); |
| 420 | case IrInstSrcIdMemberName: |
| 421 | return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name); |
| 422 | case IrInstSrcIdBreakpoint: |
| 423 | return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name); |
| 424 | case IrInstSrcIdReturnAddress: |
| 425 | return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name); |
| 426 | case IrInstSrcIdFrameAddress: |
| 427 | return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name); |
| 428 | case IrInstSrcIdFrameHandle: |
| 429 | return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name); |
| 430 | case IrInstSrcIdFrameType: |
| 431 | return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name); |
| 432 | case IrInstSrcIdFrameSize: |
| 433 | return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name); |
| 434 | case IrInstSrcIdAlignOf: |
| 435 | return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name); |
| 436 | case IrInstSrcIdOverflowOp: |
| 437 | return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name); |
| 438 | case IrInstSrcIdTestErr: |
| 439 | return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name); |
| 440 | case IrInstSrcIdUnwrapErrCode: |
| 441 | return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name); |
| 442 | case IrInstSrcIdUnwrapErrPayload: |
| 443 | return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name); |
| 444 | case IrInstSrcIdFnProto: |
| 445 | return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name); |
| 446 | case IrInstSrcIdTestComptime: |
| 447 | return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name); |
| 448 | case IrInstSrcIdPtrCast: |
| 449 | return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name); |
| 450 | case IrInstSrcIdBitCast: |
| 451 | return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name); |
| 452 | case IrInstSrcIdPtrToInt: |
| 453 | return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name); |
| 454 | case IrInstSrcIdIntToPtr: |
| 455 | return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name); |
| 456 | case IrInstSrcIdIntToEnum: |
| 457 | return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name); |
| 458 | case IrInstSrcIdIntToErr: |
| 459 | return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name); |
| 460 | case IrInstSrcIdErrToInt: |
| 461 | return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name); |
| 462 | case IrInstSrcIdCheckSwitchProngs: |
| 463 | return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name); |
| 464 | case IrInstSrcIdCheckStatementIsVoid: |
| 465 | return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name); |
| 466 | case IrInstSrcIdTypeName: |
| 467 | return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name); |
| 468 | case IrInstSrcIdTagName: |
| 469 | return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name); |
| 470 | case IrInstSrcIdPtrType: |
| 471 | return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name); |
| 472 | case IrInstSrcIdDeclRef: |
| 473 | return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name); |
| 474 | case IrInstSrcIdPanic: |
| 475 | return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name); |
| 476 | case IrInstSrcIdFieldParentPtr: |
| 477 | return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name); |
| 478 | case IrInstSrcIdByteOffsetOf: |
| 479 | return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name); |
| 480 | case IrInstSrcIdBitOffsetOf: |
| 481 | return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name); |
| 482 | case IrInstSrcIdTypeInfo: |
| 483 | return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name); |
| 484 | case IrInstSrcIdType: |
| 485 | return destroy(reinterpret_cast<IrInstSrcType *>(inst), name); |
| 486 | case IrInstSrcIdHasField: |
| 487 | return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name); |
| 488 | case IrInstSrcIdTypeId: |
| 489 | return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name); |
| 490 | case IrInstSrcIdSetEvalBranchQuota: |
| 491 | return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name); |
| 492 | case IrInstSrcIdAlignCast: |
| 493 | return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name); |
| 494 | case IrInstSrcIdImplicitCast: |
| 495 | return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name); |
| 496 | case IrInstSrcIdResolveResult: |
| 497 | return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name); |
| 498 | case IrInstSrcIdResetResult: |
| 499 | return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name); |
| 500 | case IrInstSrcIdOpaqueType: |
| 501 | return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name); |
| 502 | case IrInstSrcIdSetAlignStack: |
| 503 | return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name); |
| 504 | case IrInstSrcIdArgType: |
| 505 | return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name); |
| 506 | case IrInstSrcIdTagType: |
| 507 | return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name); |
| 508 | case IrInstSrcIdExport: |
| 509 | return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name); |
| 510 | case IrInstSrcIdErrorReturnTrace: |
| 511 | return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name); |
| 512 | case IrInstSrcIdErrorUnion: |
| 513 | return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name); |
| 514 | case IrInstSrcIdAtomicRmw: |
| 515 | return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name); |
| 516 | case IrInstSrcIdSaveErrRetAddr: |
| 517 | return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name); |
| 518 | case IrInstSrcIdAddImplicitReturnType: |
| 519 | return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name); |
| 520 | case IrInstSrcIdFloatOp: |
| 521 | return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name); |
| 522 | case IrInstSrcIdMulAdd: |
| 523 | return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name); |
| 524 | case IrInstSrcIdAtomicLoad: |
| 525 | return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name); |
| 526 | case IrInstSrcIdAtomicStore: |
| 527 | return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name); |
| 528 | case IrInstSrcIdEnumToInt: |
| 529 | return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name); |
| 530 | case IrInstSrcIdCheckRuntimeScope: |
| 531 | return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name); |
| 532 | case IrInstSrcIdHasDecl: |
| 533 | return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name); |
| 534 | case IrInstSrcIdUndeclaredIdent: |
| 535 | return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name); |
| 536 | case IrInstSrcIdAlloca: |
| 537 | return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name); |
| 538 | case IrInstSrcIdEndExpr: |
| 539 | return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name); |
| 540 | case IrInstSrcIdUnionInitNamedField: |
| 541 | return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name); |
| 542 | case IrInstSrcIdSuspendBegin: |
| 543 | return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name); |
| 544 | case IrInstSrcIdSuspendFinish: |
| 545 | return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name); |
| 546 | case IrInstSrcIdResume: |
| 547 | return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name); |
| 548 | case IrInstSrcIdAwait: |
| 549 | return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name); |
| 550 | case IrInstSrcIdSpillBegin: |
| 551 | return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name); |
| 552 | case IrInstSrcIdSpillEnd: |
| 553 | return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name); |
| 554 | case IrInstSrcIdCallArgs: |
| 555 | return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name); |
| 556 | } |
| 557 | zig_unreachable(); |
| 558 | } |
| 267 | 559 | |
| 268 | | static void destroy_instruction(IrInstruction *inst) { |
| 560 | void destroy_instruction_gen(IrInstGen *inst) { |
| 269 | 561 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 270 | | const char *name = ir_instruction_type_str(inst->id); |
| 562 | const char *name = ir_inst_gen_type_str(inst->id); |
| 271 | 563 | #else |
| 272 | 564 | const char *name = nullptr; |
| 273 | 565 | #endif |
| 274 | 566 | switch (inst->id) { |
| 275 | | case IrInstructionIdInvalid: |
| 567 | case IrInstGenIdInvalid: |
| 276 | 568 | zig_unreachable(); |
| 277 | | case IrInstructionIdReturn: |
| 278 | | return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name); |
| 279 | | case IrInstructionIdConst: |
| 280 | | return destroy(reinterpret_cast<IrInstructionConst *>(inst), name); |
| 281 | | case IrInstructionIdBinOp: |
| 282 | | return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name); |
| 283 | | case IrInstructionIdMergeErrSets: |
| 284 | | return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name); |
| 285 | | case IrInstructionIdDeclVarSrc: |
| 286 | | return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name); |
| 287 | | case IrInstructionIdCast: |
| 288 | | return destroy(reinterpret_cast<IrInstructionCast *>(inst), name); |
| 289 | | case IrInstructionIdCallSrc: |
| 290 | | return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name); |
| 291 | | case IrInstructionIdCallSrcArgs: |
| 292 | | return destroy(reinterpret_cast<IrInstructionCallSrcArgs *>(inst), name); |
| 293 | | case IrInstructionIdCallExtra: |
| 294 | | return destroy(reinterpret_cast<IrInstructionCallExtra *>(inst), name); |
| 295 | | case IrInstructionIdCallGen: |
| 296 | | return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name); |
| 297 | | case IrInstructionIdUnOp: |
| 298 | | return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name); |
| 299 | | case IrInstructionIdCondBr: |
| 300 | | return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name); |
| 301 | | case IrInstructionIdBr: |
| 302 | | return destroy(reinterpret_cast<IrInstructionBr *>(inst), name); |
| 303 | | case IrInstructionIdPhi: |
| 304 | | return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name); |
| 305 | | case IrInstructionIdContainerInitList: |
| 306 | | return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name); |
| 307 | | case IrInstructionIdContainerInitFields: |
| 308 | | return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name); |
| 309 | | case IrInstructionIdUnreachable: |
| 310 | | return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name); |
| 311 | | case IrInstructionIdElemPtr: |
| 312 | | return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name); |
| 313 | | case IrInstructionIdVarPtr: |
| 314 | | return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name); |
| 315 | | case IrInstructionIdReturnPtr: |
| 316 | | return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name); |
| 317 | | case IrInstructionIdLoadPtr: |
| 318 | | return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name); |
| 319 | | case IrInstructionIdLoadPtrGen: |
| 320 | | return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name); |
| 321 | | case IrInstructionIdStorePtr: |
| 322 | | return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name); |
| 323 | | case IrInstructionIdVectorStoreElem: |
| 324 | | return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name); |
| 325 | | case IrInstructionIdTypeOf: |
| 326 | | return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name); |
| 327 | | case IrInstructionIdFieldPtr: |
| 328 | | return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name); |
| 329 | | case IrInstructionIdStructFieldPtr: |
| 330 | | return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name); |
| 331 | | case IrInstructionIdUnionFieldPtr: |
| 332 | | return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name); |
| 333 | | case IrInstructionIdSetCold: |
| 334 | | return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name); |
| 335 | | case IrInstructionIdSetRuntimeSafety: |
| 336 | | return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name); |
| 337 | | case IrInstructionIdSetFloatMode: |
| 338 | | return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name); |
| 339 | | case IrInstructionIdArrayType: |
| 340 | | return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name); |
| 341 | | case IrInstructionIdSliceType: |
| 342 | | return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name); |
| 343 | | case IrInstructionIdAnyFrameType: |
| 344 | | return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name); |
| 345 | | case IrInstructionIdAsmSrc: |
| 346 | | return destroy(reinterpret_cast<IrInstructionAsmSrc *>(inst), name); |
| 347 | | case IrInstructionIdAsmGen: |
| 348 | | return destroy(reinterpret_cast<IrInstructionAsmGen *>(inst), name); |
| 349 | | case IrInstructionIdSizeOf: |
| 350 | | return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name); |
| 351 | | case IrInstructionIdTestNonNull: |
| 352 | | return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name); |
| 353 | | case IrInstructionIdOptionalUnwrapPtr: |
| 354 | | return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name); |
| 355 | | case IrInstructionIdPopCount: |
| 356 | | return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name); |
| 357 | | case IrInstructionIdClz: |
| 358 | | return destroy(reinterpret_cast<IrInstructionClz *>(inst), name); |
| 359 | | case IrInstructionIdCtz: |
| 360 | | return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name); |
| 361 | | case IrInstructionIdBswap: |
| 362 | | return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name); |
| 363 | | case IrInstructionIdBitReverse: |
| 364 | | return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name); |
| 365 | | case IrInstructionIdSwitchBr: |
| 366 | | return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name); |
| 367 | | case IrInstructionIdSwitchVar: |
| 368 | | return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name); |
| 369 | | case IrInstructionIdSwitchElseVar: |
| 370 | | return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name); |
| 371 | | case IrInstructionIdSwitchTarget: |
| 372 | | return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name); |
| 373 | | case IrInstructionIdUnionTag: |
| 374 | | return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name); |
| 375 | | case IrInstructionIdImport: |
| 376 | | return destroy(reinterpret_cast<IrInstructionImport *>(inst), name); |
| 377 | | case IrInstructionIdRef: |
| 378 | | return destroy(reinterpret_cast<IrInstructionRef *>(inst), name); |
| 379 | | case IrInstructionIdRefGen: |
| 380 | | return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name); |
| 381 | | case IrInstructionIdCompileErr: |
| 382 | | return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name); |
| 383 | | case IrInstructionIdCompileLog: |
| 384 | | return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name); |
| 385 | | case IrInstructionIdErrName: |
| 386 | | return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name); |
| 387 | | case IrInstructionIdCImport: |
| 388 | | return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name); |
| 389 | | case IrInstructionIdCInclude: |
| 390 | | return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name); |
| 391 | | case IrInstructionIdCDefine: |
| 392 | | return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name); |
| 393 | | case IrInstructionIdCUndef: |
| 394 | | return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name); |
| 395 | | case IrInstructionIdEmbedFile: |
| 396 | | return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name); |
| 397 | | case IrInstructionIdCmpxchgSrc: |
| 398 | | return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name); |
| 399 | | case IrInstructionIdCmpxchgGen: |
| 400 | | return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name); |
| 401 | | case IrInstructionIdFence: |
| 402 | | return destroy(reinterpret_cast<IrInstructionFence *>(inst), name); |
| 403 | | case IrInstructionIdTruncate: |
| 404 | | return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name); |
| 405 | | case IrInstructionIdIntCast: |
| 406 | | return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name); |
| 407 | | case IrInstructionIdFloatCast: |
| 408 | | return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name); |
| 409 | | case IrInstructionIdErrSetCast: |
| 410 | | return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name); |
| 411 | | case IrInstructionIdFromBytes: |
| 412 | | return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name); |
| 413 | | case IrInstructionIdToBytes: |
| 414 | | return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name); |
| 415 | | case IrInstructionIdIntToFloat: |
| 416 | | return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name); |
| 417 | | case IrInstructionIdFloatToInt: |
| 418 | | return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name); |
| 419 | | case IrInstructionIdBoolToInt: |
| 420 | | return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name); |
| 421 | | case IrInstructionIdIntType: |
| 422 | | return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name); |
| 423 | | case IrInstructionIdVectorType: |
| 424 | | return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name); |
| 425 | | case IrInstructionIdShuffleVector: |
| 426 | | return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name); |
| 427 | | case IrInstructionIdSplatSrc: |
| 428 | | return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name); |
| 429 | | case IrInstructionIdSplatGen: |
| 430 | | return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name); |
| 431 | | case IrInstructionIdBoolNot: |
| 432 | | return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name); |
| 433 | | case IrInstructionIdMemset: |
| 434 | | return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name); |
| 435 | | case IrInstructionIdMemcpy: |
| 436 | | return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name); |
| 437 | | case IrInstructionIdSliceSrc: |
| 438 | | return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name); |
| 439 | | case IrInstructionIdSliceGen: |
| 440 | | return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name); |
| 441 | | case IrInstructionIdMemberCount: |
| 442 | | return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name); |
| 443 | | case IrInstructionIdMemberType: |
| 444 | | return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name); |
| 445 | | case IrInstructionIdMemberName: |
| 446 | | return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name); |
| 447 | | case IrInstructionIdBreakpoint: |
| 448 | | return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name); |
| 449 | | case IrInstructionIdReturnAddress: |
| 450 | | return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name); |
| 451 | | case IrInstructionIdFrameAddress: |
| 452 | | return destroy(reinterpret_cast<IrInstructionFrameAddress *>(inst), name); |
| 453 | | case IrInstructionIdFrameHandle: |
| 454 | | return destroy(reinterpret_cast<IrInstructionFrameHandle *>(inst), name); |
| 455 | | case IrInstructionIdFrameType: |
| 456 | | return destroy(reinterpret_cast<IrInstructionFrameType *>(inst), name); |
| 457 | | case IrInstructionIdFrameSizeSrc: |
| 458 | | return destroy(reinterpret_cast<IrInstructionFrameSizeSrc *>(inst), name); |
| 459 | | case IrInstructionIdFrameSizeGen: |
| 460 | | return destroy(reinterpret_cast<IrInstructionFrameSizeGen *>(inst), name); |
| 461 | | case IrInstructionIdAlignOf: |
| 462 | | return destroy(reinterpret_cast<IrInstructionAlignOf *>(inst), name); |
| 463 | | case IrInstructionIdOverflowOp: |
| 464 | | return destroy(reinterpret_cast<IrInstructionOverflowOp *>(inst), name); |
| 465 | | case IrInstructionIdTestErrSrc: |
| 466 | | return destroy(reinterpret_cast<IrInstructionTestErrSrc *>(inst), name); |
| 467 | | case IrInstructionIdTestErrGen: |
| 468 | | return destroy(reinterpret_cast<IrInstructionTestErrGen *>(inst), name); |
| 469 | | case IrInstructionIdUnwrapErrCode: |
| 470 | | return destroy(reinterpret_cast<IrInstructionUnwrapErrCode *>(inst), name); |
| 471 | | case IrInstructionIdUnwrapErrPayload: |
| 472 | | return destroy(reinterpret_cast<IrInstructionUnwrapErrPayload *>(inst), name); |
| 473 | | case IrInstructionIdOptionalWrap: |
| 474 | | return destroy(reinterpret_cast<IrInstructionOptionalWrap *>(inst), name); |
| 475 | | case IrInstructionIdErrWrapCode: |
| 476 | | return destroy(reinterpret_cast<IrInstructionErrWrapCode *>(inst), name); |
| 477 | | case IrInstructionIdErrWrapPayload: |
| 478 | | return destroy(reinterpret_cast<IrInstructionErrWrapPayload *>(inst), name); |
| 479 | | case IrInstructionIdFnProto: |
| 480 | | return destroy(reinterpret_cast<IrInstructionFnProto *>(inst), name); |
| 481 | | case IrInstructionIdTestComptime: |
| 482 | | return destroy(reinterpret_cast<IrInstructionTestComptime *>(inst), name); |
| 483 | | case IrInstructionIdPtrCastSrc: |
| 484 | | return destroy(reinterpret_cast<IrInstructionPtrCastSrc *>(inst), name); |
| 485 | | case IrInstructionIdPtrCastGen: |
| 486 | | return destroy(reinterpret_cast<IrInstructionPtrCastGen *>(inst), name); |
| 487 | | case IrInstructionIdBitCastSrc: |
| 488 | | return destroy(reinterpret_cast<IrInstructionBitCastSrc *>(inst), name); |
| 489 | | case IrInstructionIdBitCastGen: |
| 490 | | return destroy(reinterpret_cast<IrInstructionBitCastGen *>(inst), name); |
| 491 | | case IrInstructionIdWidenOrShorten: |
| 492 | | return destroy(reinterpret_cast<IrInstructionWidenOrShorten *>(inst), name); |
| 493 | | case IrInstructionIdPtrToInt: |
| 494 | | return destroy(reinterpret_cast<IrInstructionPtrToInt *>(inst), name); |
| 495 | | case IrInstructionIdIntToPtr: |
| 496 | | return destroy(reinterpret_cast<IrInstructionIntToPtr *>(inst), name); |
| 497 | | case IrInstructionIdIntToEnum: |
| 498 | | return destroy(reinterpret_cast<IrInstructionIntToEnum *>(inst), name); |
| 499 | | case IrInstructionIdIntToErr: |
| 500 | | return destroy(reinterpret_cast<IrInstructionIntToErr *>(inst), name); |
| 501 | | case IrInstructionIdErrToInt: |
| 502 | | return destroy(reinterpret_cast<IrInstructionErrToInt *>(inst), name); |
| 503 | | case IrInstructionIdCheckSwitchProngs: |
| 504 | | return destroy(reinterpret_cast<IrInstructionCheckSwitchProngs *>(inst), name); |
| 505 | | case IrInstructionIdCheckStatementIsVoid: |
| 506 | | return destroy(reinterpret_cast<IrInstructionCheckStatementIsVoid *>(inst), name); |
| 507 | | case IrInstructionIdTypeName: |
| 508 | | return destroy(reinterpret_cast<IrInstructionTypeName *>(inst), name); |
| 509 | | case IrInstructionIdTagName: |
| 510 | | return destroy(reinterpret_cast<IrInstructionTagName *>(inst), name); |
| 511 | | case IrInstructionIdPtrType: |
| 512 | | return destroy(reinterpret_cast<IrInstructionPtrType *>(inst), name); |
| 513 | | case IrInstructionIdDeclRef: |
| 514 | | return destroy(reinterpret_cast<IrInstructionDeclRef *>(inst), name); |
| 515 | | case IrInstructionIdPanic: |
| 516 | | return destroy(reinterpret_cast<IrInstructionPanic *>(inst), name); |
| 517 | | case IrInstructionIdFieldParentPtr: |
| 518 | | return destroy(reinterpret_cast<IrInstructionFieldParentPtr *>(inst), name); |
| 519 | | case IrInstructionIdByteOffsetOf: |
| 520 | | return destroy(reinterpret_cast<IrInstructionByteOffsetOf *>(inst), name); |
| 521 | | case IrInstructionIdBitOffsetOf: |
| 522 | | return destroy(reinterpret_cast<IrInstructionBitOffsetOf *>(inst), name); |
| 523 | | case IrInstructionIdTypeInfo: |
| 524 | | return destroy(reinterpret_cast<IrInstructionTypeInfo *>(inst), name); |
| 525 | | case IrInstructionIdType: |
| 526 | | return destroy(reinterpret_cast<IrInstructionType *>(inst), name); |
| 527 | | case IrInstructionIdHasField: |
| 528 | | return destroy(reinterpret_cast<IrInstructionHasField *>(inst), name); |
| 529 | | case IrInstructionIdTypeId: |
| 530 | | return destroy(reinterpret_cast<IrInstructionTypeId *>(inst), name); |
| 531 | | case IrInstructionIdSetEvalBranchQuota: |
| 532 | | return destroy(reinterpret_cast<IrInstructionSetEvalBranchQuota *>(inst), name); |
| 533 | | case IrInstructionIdAlignCast: |
| 534 | | return destroy(reinterpret_cast<IrInstructionAlignCast *>(inst), name); |
| 535 | | case IrInstructionIdImplicitCast: |
| 536 | | return destroy(reinterpret_cast<IrInstructionImplicitCast *>(inst), name); |
| 537 | | case IrInstructionIdResolveResult: |
| 538 | | return destroy(reinterpret_cast<IrInstructionResolveResult *>(inst), name); |
| 539 | | case IrInstructionIdResetResult: |
| 540 | | return destroy(reinterpret_cast<IrInstructionResetResult *>(inst), name); |
| 541 | | case IrInstructionIdOpaqueType: |
| 542 | | return destroy(reinterpret_cast<IrInstructionOpaqueType *>(inst), name); |
| 543 | | case IrInstructionIdSetAlignStack: |
| 544 | | return destroy(reinterpret_cast<IrInstructionSetAlignStack *>(inst), name); |
| 545 | | case IrInstructionIdArgType: |
| 546 | | return destroy(reinterpret_cast<IrInstructionArgType *>(inst), name); |
| 547 | | case IrInstructionIdTagType: |
| 548 | | return destroy(reinterpret_cast<IrInstructionTagType *>(inst), name); |
| 549 | | case IrInstructionIdExport: |
| 550 | | return destroy(reinterpret_cast<IrInstructionExport *>(inst), name); |
| 551 | | case IrInstructionIdErrorReturnTrace: |
| 552 | | return destroy(reinterpret_cast<IrInstructionErrorReturnTrace *>(inst), name); |
| 553 | | case IrInstructionIdErrorUnion: |
| 554 | | return destroy(reinterpret_cast<IrInstructionErrorUnion *>(inst), name); |
| 555 | | case IrInstructionIdAtomicRmw: |
| 556 | | return destroy(reinterpret_cast<IrInstructionAtomicRmw *>(inst), name); |
| 557 | | case IrInstructionIdSaveErrRetAddr: |
| 558 | | return destroy(reinterpret_cast<IrInstructionSaveErrRetAddr *>(inst), name); |
| 559 | | case IrInstructionIdAddImplicitReturnType: |
| 560 | | return destroy(reinterpret_cast<IrInstructionAddImplicitReturnType *>(inst), name); |
| 561 | | case IrInstructionIdFloatOp: |
| 562 | | return destroy(reinterpret_cast<IrInstructionFloatOp *>(inst), name); |
| 563 | | case IrInstructionIdMulAdd: |
| 564 | | return destroy(reinterpret_cast<IrInstructionMulAdd *>(inst), name); |
| 565 | | case IrInstructionIdAtomicLoad: |
| 566 | | return destroy(reinterpret_cast<IrInstructionAtomicLoad *>(inst), name); |
| 567 | | case IrInstructionIdAtomicStore: |
| 568 | | return destroy(reinterpret_cast<IrInstructionAtomicStore *>(inst), name); |
| 569 | | case IrInstructionIdEnumToInt: |
| 570 | | return destroy(reinterpret_cast<IrInstructionEnumToInt *>(inst), name); |
| 571 | | case IrInstructionIdCheckRuntimeScope: |
| 572 | | return destroy(reinterpret_cast<IrInstructionCheckRuntimeScope *>(inst), name); |
| 573 | | case IrInstructionIdDeclVarGen: |
| 574 | | return destroy(reinterpret_cast<IrInstructionDeclVarGen *>(inst), name); |
| 575 | | case IrInstructionIdArrayToVector: |
| 576 | | return destroy(reinterpret_cast<IrInstructionArrayToVector *>(inst), name); |
| 577 | | case IrInstructionIdVectorToArray: |
| 578 | | return destroy(reinterpret_cast<IrInstructionVectorToArray *>(inst), name); |
| 579 | | case IrInstructionIdPtrOfArrayToSlice: |
| 580 | | return destroy(reinterpret_cast<IrInstructionPtrOfArrayToSlice *>(inst), name); |
| 581 | | case IrInstructionIdAssertZero: |
| 582 | | return destroy(reinterpret_cast<IrInstructionAssertZero *>(inst), name); |
| 583 | | case IrInstructionIdAssertNonNull: |
| 584 | | return destroy(reinterpret_cast<IrInstructionAssertNonNull *>(inst), name); |
| 585 | | case IrInstructionIdResizeSlice: |
| 586 | | return destroy(reinterpret_cast<IrInstructionResizeSlice *>(inst), name); |
| 587 | | case IrInstructionIdHasDecl: |
| 588 | | return destroy(reinterpret_cast<IrInstructionHasDecl *>(inst), name); |
| 589 | | case IrInstructionIdUndeclaredIdent: |
| 590 | | return destroy(reinterpret_cast<IrInstructionUndeclaredIdent *>(inst), name); |
| 591 | | case IrInstructionIdAllocaSrc: |
| 592 | | return destroy(reinterpret_cast<IrInstructionAllocaSrc *>(inst), name); |
| 593 | | case IrInstructionIdAllocaGen: |
| 594 | | return destroy(reinterpret_cast<IrInstructionAllocaGen *>(inst), name); |
| 595 | | case IrInstructionIdEndExpr: |
| 596 | | return destroy(reinterpret_cast<IrInstructionEndExpr *>(inst), name); |
| 597 | | case IrInstructionIdUnionInitNamedField: |
| 598 | | return destroy(reinterpret_cast<IrInstructionUnionInitNamedField *>(inst), name); |
| 599 | | case IrInstructionIdSuspendBegin: |
| 600 | | return destroy(reinterpret_cast<IrInstructionSuspendBegin *>(inst), name); |
| 601 | | case IrInstructionIdSuspendFinish: |
| 602 | | return destroy(reinterpret_cast<IrInstructionSuspendFinish *>(inst), name); |
| 603 | | case IrInstructionIdResume: |
| 604 | | return destroy(reinterpret_cast<IrInstructionResume *>(inst), name); |
| 605 | | case IrInstructionIdAwaitSrc: |
| 606 | | return destroy(reinterpret_cast<IrInstructionAwaitSrc *>(inst), name); |
| 607 | | case IrInstructionIdAwaitGen: |
| 608 | | return destroy(reinterpret_cast<IrInstructionAwaitGen *>(inst), name); |
| 609 | | case IrInstructionIdSpillBegin: |
| 610 | | return destroy(reinterpret_cast<IrInstructionSpillBegin *>(inst), name); |
| 611 | | case IrInstructionIdSpillEnd: |
| 612 | | return destroy(reinterpret_cast<IrInstructionSpillEnd *>(inst), name); |
| 613 | | case IrInstructionIdVectorExtractElem: |
| 614 | | return destroy(reinterpret_cast<IrInstructionVectorExtractElem *>(inst), name); |
| 569 | case IrInstGenIdReturn: |
| 570 | return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name); |
| 571 | case IrInstGenIdConst: |
| 572 | return destroy(reinterpret_cast<IrInstGenConst *>(inst), name); |
| 573 | case IrInstGenIdBinOp: |
| 574 | return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name); |
| 575 | case IrInstGenIdCast: |
| 576 | return destroy(reinterpret_cast<IrInstGenCast *>(inst), name); |
| 577 | case IrInstGenIdCall: |
| 578 | return destroy(reinterpret_cast<IrInstGenCall *>(inst), name); |
| 579 | case IrInstGenIdCondBr: |
| 580 | return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name); |
| 581 | case IrInstGenIdBr: |
| 582 | return destroy(reinterpret_cast<IrInstGenBr *>(inst), name); |
| 583 | case IrInstGenIdPhi: |
| 584 | return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name); |
| 585 | case IrInstGenIdUnreachable: |
| 586 | return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name); |
| 587 | case IrInstGenIdElemPtr: |
| 588 | return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name); |
| 589 | case IrInstGenIdVarPtr: |
| 590 | return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name); |
| 591 | case IrInstGenIdReturnPtr: |
| 592 | return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name); |
| 593 | case IrInstGenIdLoadPtr: |
| 594 | return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name); |
| 595 | case IrInstGenIdStorePtr: |
| 596 | return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name); |
| 597 | case IrInstGenIdVectorStoreElem: |
| 598 | return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name); |
| 599 | case IrInstGenIdStructFieldPtr: |
| 600 | return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name); |
| 601 | case IrInstGenIdUnionFieldPtr: |
| 602 | return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name); |
| 603 | case IrInstGenIdAsm: |
| 604 | return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name); |
| 605 | case IrInstGenIdTestNonNull: |
| 606 | return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name); |
| 607 | case IrInstGenIdOptionalUnwrapPtr: |
| 608 | return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name); |
| 609 | case IrInstGenIdPopCount: |
| 610 | return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name); |
| 611 | case IrInstGenIdClz: |
| 612 | return destroy(reinterpret_cast<IrInstGenClz *>(inst), name); |
| 613 | case IrInstGenIdCtz: |
| 614 | return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name); |
| 615 | case IrInstGenIdBswap: |
| 616 | return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name); |
| 617 | case IrInstGenIdBitReverse: |
| 618 | return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name); |
| 619 | case IrInstGenIdSwitchBr: |
| 620 | return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name); |
| 621 | case IrInstGenIdUnionTag: |
| 622 | return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name); |
| 623 | case IrInstGenIdRef: |
| 624 | return destroy(reinterpret_cast<IrInstGenRef *>(inst), name); |
| 625 | case IrInstGenIdErrName: |
| 626 | return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name); |
| 627 | case IrInstGenIdCmpxchg: |
| 628 | return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name); |
| 629 | case IrInstGenIdFence: |
| 630 | return destroy(reinterpret_cast<IrInstGenFence *>(inst), name); |
| 631 | case IrInstGenIdTruncate: |
| 632 | return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name); |
| 633 | case IrInstGenIdShuffleVector: |
| 634 | return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name); |
| 635 | case IrInstGenIdSplat: |
| 636 | return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name); |
| 637 | case IrInstGenIdBoolNot: |
| 638 | return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name); |
| 639 | case IrInstGenIdMemset: |
| 640 | return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name); |
| 641 | case IrInstGenIdMemcpy: |
| 642 | return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name); |
| 643 | case IrInstGenIdSlice: |
| 644 | return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name); |
| 645 | case IrInstGenIdBreakpoint: |
| 646 | return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name); |
| 647 | case IrInstGenIdReturnAddress: |
| 648 | return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name); |
| 649 | case IrInstGenIdFrameAddress: |
| 650 | return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name); |
| 651 | case IrInstGenIdFrameHandle: |
| 652 | return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name); |
| 653 | case IrInstGenIdFrameSize: |
| 654 | return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name); |
| 655 | case IrInstGenIdOverflowOp: |
| 656 | return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name); |
| 657 | case IrInstGenIdTestErr: |
| 658 | return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name); |
| 659 | case IrInstGenIdUnwrapErrCode: |
| 660 | return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name); |
| 661 | case IrInstGenIdUnwrapErrPayload: |
| 662 | return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name); |
| 663 | case IrInstGenIdOptionalWrap: |
| 664 | return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name); |
| 665 | case IrInstGenIdErrWrapCode: |
| 666 | return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name); |
| 667 | case IrInstGenIdErrWrapPayload: |
| 668 | return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name); |
| 669 | case IrInstGenIdPtrCast: |
| 670 | return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name); |
| 671 | case IrInstGenIdBitCast: |
| 672 | return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name); |
| 673 | case IrInstGenIdWidenOrShorten: |
| 674 | return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name); |
| 675 | case IrInstGenIdPtrToInt: |
| 676 | return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name); |
| 677 | case IrInstGenIdIntToPtr: |
| 678 | return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name); |
| 679 | case IrInstGenIdIntToEnum: |
| 680 | return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name); |
| 681 | case IrInstGenIdIntToErr: |
| 682 | return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name); |
| 683 | case IrInstGenIdErrToInt: |
| 684 | return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name); |
| 685 | case IrInstGenIdTagName: |
| 686 | return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name); |
| 687 | case IrInstGenIdPanic: |
| 688 | return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name); |
| 689 | case IrInstGenIdFieldParentPtr: |
| 690 | return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name); |
| 691 | case IrInstGenIdAlignCast: |
| 692 | return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name); |
| 693 | case IrInstGenIdErrorReturnTrace: |
| 694 | return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name); |
| 695 | case IrInstGenIdAtomicRmw: |
| 696 | return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name); |
| 697 | case IrInstGenIdSaveErrRetAddr: |
| 698 | return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name); |
| 699 | case IrInstGenIdFloatOp: |
| 700 | return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name); |
| 701 | case IrInstGenIdMulAdd: |
| 702 | return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name); |
| 703 | case IrInstGenIdAtomicLoad: |
| 704 | return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name); |
| 705 | case IrInstGenIdAtomicStore: |
| 706 | return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name); |
| 707 | case IrInstGenIdDeclVar: |
| 708 | return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name); |
| 709 | case IrInstGenIdArrayToVector: |
| 710 | return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name); |
| 711 | case IrInstGenIdVectorToArray: |
| 712 | return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name); |
| 713 | case IrInstGenIdPtrOfArrayToSlice: |
| 714 | return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name); |
| 715 | case IrInstGenIdAssertZero: |
| 716 | return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name); |
| 717 | case IrInstGenIdAssertNonNull: |
| 718 | return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name); |
| 719 | case IrInstGenIdResizeSlice: |
| 720 | return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name); |
| 721 | case IrInstGenIdAlloca: |
| 722 | return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name); |
| 723 | case IrInstGenIdSuspendBegin: |
| 724 | return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name); |
| 725 | case IrInstGenIdSuspendFinish: |
| 726 | return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name); |
| 727 | case IrInstGenIdResume: |
| 728 | return destroy(reinterpret_cast<IrInstGenResume *>(inst), name); |
| 729 | case IrInstGenIdAwait: |
| 730 | return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name); |
| 731 | case IrInstGenIdSpillBegin: |
| 732 | return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name); |
| 733 | case IrInstGenIdSpillEnd: |
| 734 | return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name); |
| 735 | case IrInstGenIdVectorExtractElem: |
| 736 | return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name); |
| 737 | case IrInstGenIdBinaryNot: |
| 738 | return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name); |
| 739 | case IrInstGenIdNegation: |
| 740 | return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name); |
| 741 | case IrInstGenIdNegationWrapping: |
| 742 | return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name); |
| 615 | 743 | } |
| 616 | 744 | zig_unreachable(); |
| 617 | 745 | } |
| ... | ... | @@ -627,20 +755,19 @@ static void ira_deref(IrAnalyze *ira) { |
| 627 | 755 | assert(ira->ref_count != 0); |
| 628 | 756 | |
| 629 | 757 | for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) { |
| 630 | | IrBasicBlock *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i]; |
| 758 | IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i]; |
| 631 | 759 | for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) { |
| 632 | | IrInstruction *pass1_inst = pass1_bb->instruction_list.items[inst_i]; |
| 633 | | destroy_instruction(pass1_inst); |
| 760 | IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i]; |
| 761 | destroy_instruction_src(pass1_inst); |
| 634 | 762 | } |
| 635 | | destroy(pass1_bb, "IrBasicBlock"); |
| 763 | destroy(pass1_bb, "IrBasicBlockSrc"); |
| 636 | 764 | } |
| 637 | 765 | ira->old_irb.exec->basic_block_list.deinit(); |
| 638 | 766 | ira->old_irb.exec->tld_list.deinit(); |
| 639 | 767 | // cannot destroy here because of var->owner_exec |
| 640 | | //destroy(ira->old_irb.exec, "IrExecutablePass1"); |
| 768 | //destroy(ira->old_irb.exec, "IrExecutableSrc"); |
| 641 | 769 | ira->src_implicit_return_type_list.deinit(); |
| 642 | 770 | ira->resume_stack.deinit(); |
| 643 | | ira->exec_context.mem_slot_list.deinit(); |
| 644 | 771 | destroy(ira, "IrAnalyze"); |
| 645 | 772 | } |
| 646 | 773 | |
| ... | ... | @@ -754,7 +881,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 754 | 881 | case ZigTypeIdComptimeFloat: |
| 755 | 882 | case ZigTypeIdComptimeInt: |
| 756 | 883 | case ZigTypeIdEnumLiteral: |
| 757 | | case ZigTypeIdPointer: |
| 758 | 884 | case ZigTypeIdUndefined: |
| 759 | 885 | case ZigTypeIdNull: |
| 760 | 886 | case ZigTypeIdBoundFn: |
| ... | ... | @@ -763,6 +889,8 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 763 | 889 | case ZigTypeIdAnyFrame: |
| 764 | 890 | case ZigTypeIdFn: |
| 765 | 891 | return true; |
| 892 | case ZigTypeIdPointer: |
| 893 | return expected->data.pointer.inferred_struct_field == actual->data.pointer.inferred_struct_field; |
| 766 | 894 | case ZigTypeIdFloat: |
| 767 | 895 | return expected->data.floating.bit_count == actual->data.floating.bit_count; |
| 768 | 896 | case ZigTypeIdInt: |
| ... | ... | @@ -785,7 +913,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 785 | 913 | zig_unreachable(); |
| 786 | 914 | } |
| 787 | 915 | |
| 788 | | static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 916 | static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) { |
| 789 | 917 | if (exec->is_inline) |
| 790 | 918 | return true; |
| 791 | 919 | |
| ... | ... | @@ -801,29 +929,35 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 801 | 929 | return false; |
| 802 | 930 | } |
| 803 | 931 | |
| 804 | | static void ir_instruction_append(IrBasicBlock *basic_block, IrInstruction *instruction) { |
| 932 | static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instruction) { |
| 933 | assert(basic_block); |
| 934 | assert(instruction); |
| 935 | basic_block->instruction_list.append(instruction); |
| 936 | } |
| 937 | |
| 938 | static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruction) { |
| 805 | 939 | assert(basic_block); |
| 806 | 940 | assert(instruction); |
| 807 | 941 | basic_block->instruction_list.append(instruction); |
| 808 | 942 | } |
| 809 | 943 | |
| 810 | | static size_t exec_next_debug_id(IrExecutable *exec) { |
| 944 | static size_t exec_next_debug_id(IrExecutableSrc *exec) { |
| 811 | 945 | size_t result = exec->next_debug_id; |
| 812 | 946 | exec->next_debug_id += 1; |
| 813 | 947 | return result; |
| 814 | 948 | } |
| 815 | 949 | |
| 816 | | static size_t exec_next_mem_slot(IrExecutable *exec) { |
| 817 | | size_t result = exec->mem_slot_count; |
| 818 | | exec->mem_slot_count += 1; |
| 950 | static size_t exec_next_debug_id_gen(IrExecutableGen *exec) { |
| 951 | size_t result = exec->next_debug_id; |
| 952 | exec->next_debug_id += 1; |
| 819 | 953 | return result; |
| 820 | 954 | } |
| 821 | 955 | |
| 822 | | static ZigFn *exec_fn_entry(IrExecutable *exec) { |
| 956 | static ZigFn *exec_fn_entry(IrExecutableSrc *exec) { |
| 823 | 957 | return exec->fn_entry; |
| 824 | 958 | } |
| 825 | 959 | |
| 826 | | static Buf *exec_c_import_buf(IrExecutable *exec) { |
| 960 | static Buf *exec_c_import_buf(IrExecutableSrc *exec) { |
| 827 | 961 | return exec->c_import_buf; |
| 828 | 962 | } |
| 829 | 963 | |
| ... | ... | @@ -831,1002 +965,1343 @@ static bool value_is_comptime(ZigValue *const_val) { |
| 831 | 965 | return const_val->special != ConstValSpecialRuntime; |
| 832 | 966 | } |
| 833 | 967 | |
| 834 | | static bool instr_is_comptime(IrInstruction *instruction) { |
| 968 | static bool instr_is_comptime(IrInstGen *instruction) { |
| 835 | 969 | return value_is_comptime(instruction->value); |
| 836 | 970 | } |
| 837 | 971 | |
| 838 | | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 839 | | return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable; |
| 972 | static bool instr_is_unreachable(IrInstSrc *instruction) { |
| 973 | return instruction->is_noreturn; |
| 840 | 974 | } |
| 841 | 975 | |
| 842 | | static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) { |
| 843 | | new_bb->other = old_bb; |
| 844 | | old_bb->other = new_bb; |
| 976 | static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) { |
| 977 | new_bb->parent = old_bb; |
| 978 | old_bb->child = new_bb; |
| 845 | 979 | } |
| 846 | 980 | |
| 847 | | static void ir_ref_bb(IrBasicBlock *bb) { |
| 981 | static void ir_ref_bb(IrBasicBlockSrc *bb) { |
| 848 | 982 | bb->ref_count += 1; |
| 849 | 983 | } |
| 850 | 984 | |
| 851 | | static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) { |
| 852 | | assert(instruction->id != IrInstructionIdInvalid); |
| 853 | | instruction->ref_count += 1; |
| 854 | | if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction)) |
| 985 | static void ir_ref_bb_gen(IrBasicBlockGen *bb) { |
| 986 | bb->ref_count += 1; |
| 987 | } |
| 988 | |
| 989 | static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) { |
| 990 | assert(instruction->id != IrInstSrcIdInvalid); |
| 991 | instruction->base.ref_count += 1; |
| 992 | if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction) |
| 993 | && instruction->id != IrInstSrcIdConst) |
| 994 | { |
| 855 | 995 | ir_ref_bb(instruction->owner_bb); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | static void ir_ref_inst_gen(IrInstGen *instruction, IrBasicBlockGen *cur_bb) { |
| 1000 | assert(instruction->id != IrInstGenIdInvalid); |
| 1001 | instruction->base.ref_count += 1; |
| 1002 | if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction)) |
| 1003 | ir_ref_bb_gen(instruction->owner_bb); |
| 856 | 1004 | } |
| 857 | 1005 | |
| 858 | 1006 | static void ir_ref_var(ZigVar *var) { |
| 859 | 1007 | var->ref_count += 1; |
| 860 | 1008 | } |
| 861 | 1009 | |
| 1010 | static void create_result_ptr(CodeGen *codegen, ZigType *expected_type, |
| 1011 | ZigValue **out_result, ZigValue **out_result_ptr) |
| 1012 | { |
| 1013 | ZigValue *result = create_const_vals(1); |
| 1014 | ZigValue *result_ptr = create_const_vals(1); |
| 1015 | result->special = ConstValSpecialUndef; |
| 1016 | result->type = expected_type; |
| 1017 | result_ptr->special = ConstValSpecialStatic; |
| 1018 | result_ptr->type = get_pointer_to_type(codegen, result->type, false); |
| 1019 | result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 1020 | result_ptr->data.x_ptr.special = ConstPtrSpecialRef; |
| 1021 | result_ptr->data.x_ptr.data.ref.pointee = result; |
| 1022 | |
| 1023 | *out_result = result; |
| 1024 | *out_result_ptr = result_ptr; |
| 1025 | } |
| 1026 | |
| 862 | 1027 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { |
| 863 | | ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, |
| 864 | | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, |
| 865 | | node, nullptr, ira->new_irb.exec, nullptr, UndefBad); |
| 1028 | Error err; |
| 1029 | |
| 1030 | ZigValue *result; |
| 1031 | ZigValue *result_ptr; |
| 1032 | create_result_ptr(ira->codegen, ira->codegen->builtin_types.entry_type, &result, &result_ptr); |
| 866 | 1033 | |
| 1034 | if ((err = ir_eval_const_value(ira->codegen, scope, node, result_ptr, |
| 1035 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 1036 | nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad))) |
| 1037 | { |
| 1038 | return ira->codegen->builtin_types.entry_invalid; |
| 1039 | } |
| 867 | 1040 | if (type_is_invalid(result->type)) |
| 868 | 1041 | return ira->codegen->builtin_types.entry_invalid; |
| 869 | 1042 | |
| 870 | 1043 | assert(result->special != ConstValSpecialRuntime); |
| 871 | | return result->data.x_type; |
| 1044 | ZigType *res_type = result->data.x_type; |
| 1045 | |
| 1046 | destroy(result_ptr, "ZigValue"); |
| 1047 | destroy(result, "ZigValue"); |
| 1048 | |
| 1049 | return res_type; |
| 872 | 1050 | } |
| 873 | 1051 | |
| 874 | | static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { |
| 875 | | IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock"); |
| 1052 | static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) { |
| 1053 | IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc"); |
| 876 | 1054 | result->scope = scope; |
| 877 | 1055 | result->name_hint = name_hint; |
| 878 | 1056 | result->debug_id = exec_next_debug_id(irb->exec); |
| 879 | | result->index = SIZE_MAX; // set later |
| 1057 | result->index = UINT32_MAX; // set later |
| 1058 | return result; |
| 1059 | } |
| 1060 | |
| 1061 | static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) { |
| 1062 | IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen"); |
| 1063 | result->scope = scope; |
| 1064 | result->name_hint = name_hint; |
| 1065 | result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec); |
| 1066 | result->index = UINT32_MAX; // set later |
| 880 | 1067 | return result; |
| 881 | 1068 | } |
| 882 | 1069 | |
| 883 | | static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) { |
| 884 | | IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint); |
| 1070 | static IrBasicBlockGen *ir_build_bb_from(IrAnalyze *ira, IrBasicBlockSrc *other_bb) { |
| 1071 | IrBasicBlockGen *new_bb = ir_create_basic_block_gen(ira, other_bb->scope, other_bb->name_hint); |
| 885 | 1072 | ir_link_new_bb(new_bb, other_bb); |
| 886 | 1073 | return new_bb; |
| 887 | 1074 | } |
| 888 | 1075 | |
| 889 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) { |
| 890 | | return IrInstructionIdDeclVarSrc; |
| 1076 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) { |
| 1077 | return IrInstSrcIdDeclVar; |
| 1078 | } |
| 1079 | |
| 1080 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBr *) { |
| 1081 | return IrInstSrcIdBr; |
| 1082 | } |
| 1083 | |
| 1084 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCondBr *) { |
| 1085 | return IrInstSrcIdCondBr; |
| 1086 | } |
| 1087 | |
| 1088 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchBr *) { |
| 1089 | return IrInstSrcIdSwitchBr; |
| 1090 | } |
| 1091 | |
| 1092 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchVar *) { |
| 1093 | return IrInstSrcIdSwitchVar; |
| 1094 | } |
| 1095 | |
| 1096 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchElseVar *) { |
| 1097 | return IrInstSrcIdSwitchElseVar; |
| 1098 | } |
| 1099 | |
| 1100 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchTarget *) { |
| 1101 | return IrInstSrcIdSwitchTarget; |
| 1102 | } |
| 1103 | |
| 1104 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPhi *) { |
| 1105 | return IrInstSrcIdPhi; |
| 1106 | } |
| 1107 | |
| 1108 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnOp *) { |
| 1109 | return IrInstSrcIdUnOp; |
| 1110 | } |
| 1111 | |
| 1112 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBinOp *) { |
| 1113 | return IrInstSrcIdBinOp; |
| 1114 | } |
| 1115 | |
| 1116 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMergeErrSets *) { |
| 1117 | return IrInstSrcIdMergeErrSets; |
| 1118 | } |
| 1119 | |
| 1120 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcLoadPtr *) { |
| 1121 | return IrInstSrcIdLoadPtr; |
| 1122 | } |
| 1123 | |
| 1124 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcStorePtr *) { |
| 1125 | return IrInstSrcIdStorePtr; |
| 1126 | } |
| 1127 | |
| 1128 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldPtr *) { |
| 1129 | return IrInstSrcIdFieldPtr; |
| 1130 | } |
| 1131 | |
| 1132 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcElemPtr *) { |
| 1133 | return IrInstSrcIdElemPtr; |
| 1134 | } |
| 1135 | |
| 1136 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcVarPtr *) { |
| 1137 | return IrInstSrcIdVarPtr; |
| 1138 | } |
| 1139 | |
| 1140 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCall *) { |
| 1141 | return IrInstSrcIdCall; |
| 1142 | } |
| 1143 | |
| 1144 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallArgs *) { |
| 1145 | return IrInstSrcIdCallArgs; |
| 1146 | } |
| 1147 | |
| 1148 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallExtra *) { |
| 1149 | return IrInstSrcIdCallExtra; |
| 1150 | } |
| 1151 | |
| 1152 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcConst *) { |
| 1153 | return IrInstSrcIdConst; |
| 1154 | } |
| 1155 | |
| 1156 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturn *) { |
| 1157 | return IrInstSrcIdReturn; |
| 1158 | } |
| 1159 | |
| 1160 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitList *) { |
| 1161 | return IrInstSrcIdContainerInitList; |
| 1162 | } |
| 1163 | |
| 1164 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitFields *) { |
| 1165 | return IrInstSrcIdContainerInitFields; |
| 1166 | } |
| 1167 | |
| 1168 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnreachable *) { |
| 1169 | return IrInstSrcIdUnreachable; |
| 1170 | } |
| 1171 | |
| 1172 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeOf *) { |
| 1173 | return IrInstSrcIdTypeOf; |
| 1174 | } |
| 1175 | |
| 1176 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetCold *) { |
| 1177 | return IrInstSrcIdSetCold; |
| 1178 | } |
| 1179 | |
| 1180 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetRuntimeSafety *) { |
| 1181 | return IrInstSrcIdSetRuntimeSafety; |
| 1182 | } |
| 1183 | |
| 1184 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetFloatMode *) { |
| 1185 | return IrInstSrcIdSetFloatMode; |
| 1186 | } |
| 1187 | |
| 1188 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcArrayType *) { |
| 1189 | return IrInstSrcIdArrayType; |
| 1190 | } |
| 1191 | |
| 1192 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAnyFrameType *) { |
| 1193 | return IrInstSrcIdAnyFrameType; |
| 1194 | } |
| 1195 | |
| 1196 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSliceType *) { |
| 1197 | return IrInstSrcIdSliceType; |
| 1198 | } |
| 1199 | |
| 1200 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAsm *) { |
| 1201 | return IrInstSrcIdAsm; |
| 1202 | } |
| 1203 | |
| 1204 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSizeOf *) { |
| 1205 | return IrInstSrcIdSizeOf; |
| 1206 | } |
| 1207 | |
| 1208 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestNonNull *) { |
| 1209 | return IrInstSrcIdTestNonNull; |
| 1210 | } |
| 1211 | |
| 1212 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOptionalUnwrapPtr *) { |
| 1213 | return IrInstSrcIdOptionalUnwrapPtr; |
| 1214 | } |
| 1215 | |
| 1216 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcClz *) { |
| 1217 | return IrInstSrcIdClz; |
| 1218 | } |
| 1219 | |
| 1220 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCtz *) { |
| 1221 | return IrInstSrcIdCtz; |
| 1222 | } |
| 1223 | |
| 1224 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPopCount *) { |
| 1225 | return IrInstSrcIdPopCount; |
| 1226 | } |
| 1227 | |
| 1228 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBswap *) { |
| 1229 | return IrInstSrcIdBswap; |
| 1230 | } |
| 1231 | |
| 1232 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitReverse *) { |
| 1233 | return IrInstSrcIdBitReverse; |
| 891 | 1234 | } |
| 892 | 1235 | |
| 893 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) { |
| 894 | | return IrInstructionIdDeclVarGen; |
| 1236 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcImport *) { |
| 1237 | return IrInstSrcIdImport; |
| 895 | 1238 | } |
| 896 | 1239 | |
| 897 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) { |
| 898 | | return IrInstructionIdCondBr; |
| 1240 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCImport *) { |
| 1241 | return IrInstSrcIdCImport; |
| 899 | 1242 | } |
| 900 | 1243 | |
| 901 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) { |
| 902 | | return IrInstructionIdBr; |
| 1244 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCInclude *) { |
| 1245 | return IrInstSrcIdCInclude; |
| 903 | 1246 | } |
| 904 | 1247 | |
| 905 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) { |
| 906 | | return IrInstructionIdSwitchBr; |
| 1248 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCDefine *) { |
| 1249 | return IrInstSrcIdCDefine; |
| 907 | 1250 | } |
| 908 | 1251 | |
| 909 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) { |
| 910 | | return IrInstructionIdSwitchVar; |
| 1252 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCUndef *) { |
| 1253 | return IrInstSrcIdCUndef; |
| 911 | 1254 | } |
| 912 | 1255 | |
| 913 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) { |
| 914 | | return IrInstructionIdSwitchElseVar; |
| 1256 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcRef *) { |
| 1257 | return IrInstSrcIdRef; |
| 915 | 1258 | } |
| 916 | 1259 | |
| 917 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) { |
| 918 | | return IrInstructionIdSwitchTarget; |
| 1260 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileErr *) { |
| 1261 | return IrInstSrcIdCompileErr; |
| 919 | 1262 | } |
| 920 | 1263 | |
| 921 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) { |
| 922 | | return IrInstructionIdPhi; |
| 1264 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileLog *) { |
| 1265 | return IrInstSrcIdCompileLog; |
| 923 | 1266 | } |
| 924 | 1267 | |
| 925 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) { |
| 926 | | return IrInstructionIdUnOp; |
| 1268 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrName *) { |
| 1269 | return IrInstSrcIdErrName; |
| 927 | 1270 | } |
| 928 | 1271 | |
| 929 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) { |
| 930 | | return IrInstructionIdBinOp; |
| 1272 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEmbedFile *) { |
| 1273 | return IrInstSrcIdEmbedFile; |
| 931 | 1274 | } |
| 932 | 1275 | |
| 933 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) { |
| 934 | | return IrInstructionIdMergeErrSets; |
| 1276 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCmpxchg *) { |
| 1277 | return IrInstSrcIdCmpxchg; |
| 935 | 1278 | } |
| 936 | 1279 | |
| 937 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) { |
| 938 | | return IrInstructionIdExport; |
| 1280 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFence *) { |
| 1281 | return IrInstSrcIdFence; |
| 939 | 1282 | } |
| 940 | 1283 | |
| 941 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) { |
| 942 | | return IrInstructionIdLoadPtr; |
| 1284 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTruncate *) { |
| 1285 | return IrInstSrcIdTruncate; |
| 943 | 1286 | } |
| 944 | 1287 | |
| 945 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) { |
| 946 | | return IrInstructionIdLoadPtrGen; |
| 1288 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntCast *) { |
| 1289 | return IrInstSrcIdIntCast; |
| 947 | 1290 | } |
| 948 | 1291 | |
| 949 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) { |
| 950 | | return IrInstructionIdStorePtr; |
| 1292 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatCast *) { |
| 1293 | return IrInstSrcIdFloatCast; |
| 951 | 1294 | } |
| 952 | 1295 | |
| 953 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) { |
| 954 | | return IrInstructionIdVectorStoreElem; |
| 1296 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToFloat *) { |
| 1297 | return IrInstSrcIdIntToFloat; |
| 955 | 1298 | } |
| 956 | 1299 | |
| 957 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) { |
| 958 | | return IrInstructionIdFieldPtr; |
| 1300 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatToInt *) { |
| 1301 | return IrInstSrcIdFloatToInt; |
| 959 | 1302 | } |
| 960 | 1303 | |
| 961 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) { |
| 962 | | return IrInstructionIdStructFieldPtr; |
| 1304 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) { |
| 1305 | return IrInstSrcIdBoolToInt; |
| 963 | 1306 | } |
| 964 | 1307 | |
| 965 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) { |
| 966 | | return IrInstructionIdUnionFieldPtr; |
| 1308 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) { |
| 1309 | return IrInstSrcIdIntType; |
| 967 | 1310 | } |
| 968 | 1311 | |
| 969 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) { |
| 970 | | return IrInstructionIdElemPtr; |
| 1312 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) { |
| 1313 | return IrInstSrcIdVectorType; |
| 971 | 1314 | } |
| 972 | 1315 | |
| 973 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) { |
| 974 | | return IrInstructionIdVarPtr; |
| 1316 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) { |
| 1317 | return IrInstSrcIdShuffleVector; |
| 975 | 1318 | } |
| 976 | 1319 | |
| 977 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) { |
| 978 | | return IrInstructionIdReturnPtr; |
| 1320 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) { |
| 1321 | return IrInstSrcIdSplat; |
| 979 | 1322 | } |
| 980 | 1323 | |
| 981 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) { |
| 982 | | return IrInstructionIdCallSrc; |
| 1324 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) { |
| 1325 | return IrInstSrcIdBoolNot; |
| 983 | 1326 | } |
| 984 | 1327 | |
| 985 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) { |
| 986 | | return IrInstructionIdCallSrcArgs; |
| 1328 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) { |
| 1329 | return IrInstSrcIdMemset; |
| 987 | 1330 | } |
| 988 | 1331 | |
| 989 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) { |
| 990 | | return IrInstructionIdCallExtra; |
| 1332 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) { |
| 1333 | return IrInstSrcIdMemcpy; |
| 991 | 1334 | } |
| 992 | 1335 | |
| 993 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) { |
| 994 | | return IrInstructionIdCallGen; |
| 1336 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) { |
| 1337 | return IrInstSrcIdSlice; |
| 995 | 1338 | } |
| 996 | 1339 | |
| 997 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) { |
| 998 | | return IrInstructionIdConst; |
| 1340 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) { |
| 1341 | return IrInstSrcIdMemberCount; |
| 999 | 1342 | } |
| 1000 | 1343 | |
| 1001 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) { |
| 1002 | | return IrInstructionIdReturn; |
| 1344 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) { |
| 1345 | return IrInstSrcIdMemberType; |
| 1003 | 1346 | } |
| 1004 | 1347 | |
| 1005 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) { |
| 1006 | | return IrInstructionIdCast; |
| 1348 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) { |
| 1349 | return IrInstSrcIdMemberName; |
| 1007 | 1350 | } |
| 1008 | 1351 | |
| 1009 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) { |
| 1010 | | return IrInstructionIdResizeSlice; |
| 1352 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) { |
| 1353 | return IrInstSrcIdBreakpoint; |
| 1011 | 1354 | } |
| 1012 | 1355 | |
| 1013 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) { |
| 1014 | | return IrInstructionIdContainerInitList; |
| 1356 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) { |
| 1357 | return IrInstSrcIdReturnAddress; |
| 1015 | 1358 | } |
| 1016 | 1359 | |
| 1017 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) { |
| 1018 | | return IrInstructionIdContainerInitFields; |
| 1360 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) { |
| 1361 | return IrInstSrcIdFrameAddress; |
| 1019 | 1362 | } |
| 1020 | 1363 | |
| 1021 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) { |
| 1022 | | return IrInstructionIdUnreachable; |
| 1364 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) { |
| 1365 | return IrInstSrcIdFrameHandle; |
| 1023 | 1366 | } |
| 1024 | 1367 | |
| 1025 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) { |
| 1026 | | return IrInstructionIdTypeOf; |
| 1368 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) { |
| 1369 | return IrInstSrcIdFrameType; |
| 1027 | 1370 | } |
| 1028 | 1371 | |
| 1029 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) { |
| 1030 | | return IrInstructionIdSetCold; |
| 1372 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) { |
| 1373 | return IrInstSrcIdFrameSize; |
| 1031 | 1374 | } |
| 1032 | 1375 | |
| 1033 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) { |
| 1034 | | return IrInstructionIdSetRuntimeSafety; |
| 1376 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) { |
| 1377 | return IrInstSrcIdAlignOf; |
| 1035 | 1378 | } |
| 1036 | 1379 | |
| 1037 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) { |
| 1038 | | return IrInstructionIdSetFloatMode; |
| 1380 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) { |
| 1381 | return IrInstSrcIdOverflowOp; |
| 1039 | 1382 | } |
| 1040 | 1383 | |
| 1041 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) { |
| 1042 | | return IrInstructionIdArrayType; |
| 1384 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) { |
| 1385 | return IrInstSrcIdTestErr; |
| 1043 | 1386 | } |
| 1044 | 1387 | |
| 1045 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) { |
| 1046 | | return IrInstructionIdAnyFrameType; |
| 1388 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) { |
| 1389 | return IrInstSrcIdMulAdd; |
| 1047 | 1390 | } |
| 1048 | 1391 | |
| 1049 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) { |
| 1050 | | return IrInstructionIdSliceType; |
| 1392 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) { |
| 1393 | return IrInstSrcIdFloatOp; |
| 1051 | 1394 | } |
| 1052 | 1395 | |
| 1053 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) { |
| 1054 | | return IrInstructionIdAsmSrc; |
| 1396 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) { |
| 1397 | return IrInstSrcIdUnwrapErrCode; |
| 1055 | 1398 | } |
| 1056 | 1399 | |
| 1057 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) { |
| 1058 | | return IrInstructionIdAsmGen; |
| 1400 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) { |
| 1401 | return IrInstSrcIdUnwrapErrPayload; |
| 1059 | 1402 | } |
| 1060 | 1403 | |
| 1061 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) { |
| 1062 | | return IrInstructionIdSizeOf; |
| 1404 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) { |
| 1405 | return IrInstSrcIdFnProto; |
| 1063 | 1406 | } |
| 1064 | 1407 | |
| 1065 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) { |
| 1066 | | return IrInstructionIdTestNonNull; |
| 1408 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) { |
| 1409 | return IrInstSrcIdTestComptime; |
| 1067 | 1410 | } |
| 1068 | 1411 | |
| 1069 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) { |
| 1070 | | return IrInstructionIdOptionalUnwrapPtr; |
| 1412 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) { |
| 1413 | return IrInstSrcIdPtrCast; |
| 1071 | 1414 | } |
| 1072 | 1415 | |
| 1073 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) { |
| 1074 | | return IrInstructionIdClz; |
| 1416 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) { |
| 1417 | return IrInstSrcIdBitCast; |
| 1075 | 1418 | } |
| 1076 | 1419 | |
| 1077 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) { |
| 1078 | | return IrInstructionIdCtz; |
| 1420 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) { |
| 1421 | return IrInstSrcIdIntToPtr; |
| 1079 | 1422 | } |
| 1080 | 1423 | |
| 1081 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) { |
| 1082 | | return IrInstructionIdPopCount; |
| 1424 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) { |
| 1425 | return IrInstSrcIdPtrToInt; |
| 1083 | 1426 | } |
| 1084 | 1427 | |
| 1085 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) { |
| 1086 | | return IrInstructionIdBswap; |
| 1428 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) { |
| 1429 | return IrInstSrcIdIntToEnum; |
| 1087 | 1430 | } |
| 1088 | 1431 | |
| 1089 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) { |
| 1090 | | return IrInstructionIdBitReverse; |
| 1432 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) { |
| 1433 | return IrInstSrcIdEnumToInt; |
| 1091 | 1434 | } |
| 1092 | 1435 | |
| 1093 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) { |
| 1094 | | return IrInstructionIdUnionTag; |
| 1436 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) { |
| 1437 | return IrInstSrcIdIntToErr; |
| 1095 | 1438 | } |
| 1096 | 1439 | |
| 1097 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) { |
| 1098 | | return IrInstructionIdImport; |
| 1440 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) { |
| 1441 | return IrInstSrcIdErrToInt; |
| 1099 | 1442 | } |
| 1100 | 1443 | |
| 1101 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) { |
| 1102 | | return IrInstructionIdCImport; |
| 1444 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) { |
| 1445 | return IrInstSrcIdCheckSwitchProngs; |
| 1103 | 1446 | } |
| 1104 | 1447 | |
| 1105 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) { |
| 1106 | | return IrInstructionIdCInclude; |
| 1448 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) { |
| 1449 | return IrInstSrcIdCheckStatementIsVoid; |
| 1107 | 1450 | } |
| 1108 | 1451 | |
| 1109 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) { |
| 1110 | | return IrInstructionIdCDefine; |
| 1452 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) { |
| 1453 | return IrInstSrcIdTypeName; |
| 1111 | 1454 | } |
| 1112 | 1455 | |
| 1113 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) { |
| 1114 | | return IrInstructionIdCUndef; |
| 1456 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) { |
| 1457 | return IrInstSrcIdDeclRef; |
| 1115 | 1458 | } |
| 1116 | 1459 | |
| 1117 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 1118 | | return IrInstructionIdRef; |
| 1460 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) { |
| 1461 | return IrInstSrcIdPanic; |
| 1119 | 1462 | } |
| 1120 | 1463 | |
| 1121 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) { |
| 1122 | | return IrInstructionIdRefGen; |
| 1464 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) { |
| 1465 | return IrInstSrcIdTagName; |
| 1123 | 1466 | } |
| 1124 | 1467 | |
| 1125 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 1126 | | return IrInstructionIdCompileErr; |
| 1468 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) { |
| 1469 | return IrInstSrcIdTagType; |
| 1127 | 1470 | } |
| 1128 | 1471 | |
| 1129 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) { |
| 1130 | | return IrInstructionIdCompileLog; |
| 1472 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) { |
| 1473 | return IrInstSrcIdFieldParentPtr; |
| 1131 | 1474 | } |
| 1132 | 1475 | |
| 1133 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) { |
| 1134 | | return IrInstructionIdErrName; |
| 1476 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) { |
| 1477 | return IrInstSrcIdByteOffsetOf; |
| 1135 | 1478 | } |
| 1136 | 1479 | |
| 1137 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) { |
| 1138 | | return IrInstructionIdEmbedFile; |
| 1480 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) { |
| 1481 | return IrInstSrcIdBitOffsetOf; |
| 1139 | 1482 | } |
| 1140 | 1483 | |
| 1141 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) { |
| 1142 | | return IrInstructionIdCmpxchgSrc; |
| 1484 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) { |
| 1485 | return IrInstSrcIdTypeInfo; |
| 1143 | 1486 | } |
| 1144 | 1487 | |
| 1145 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) { |
| 1146 | | return IrInstructionIdCmpxchgGen; |
| 1488 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) { |
| 1489 | return IrInstSrcIdType; |
| 1147 | 1490 | } |
| 1148 | 1491 | |
| 1149 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) { |
| 1150 | | return IrInstructionIdFence; |
| 1492 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) { |
| 1493 | return IrInstSrcIdHasField; |
| 1151 | 1494 | } |
| 1152 | 1495 | |
| 1153 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) { |
| 1154 | | return IrInstructionIdTruncate; |
| 1496 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) { |
| 1497 | return IrInstSrcIdTypeId; |
| 1155 | 1498 | } |
| 1156 | 1499 | |
| 1157 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) { |
| 1158 | | return IrInstructionIdIntCast; |
| 1500 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) { |
| 1501 | return IrInstSrcIdSetEvalBranchQuota; |
| 1159 | 1502 | } |
| 1160 | 1503 | |
| 1161 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) { |
| 1162 | | return IrInstructionIdFloatCast; |
| 1504 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) { |
| 1505 | return IrInstSrcIdPtrType; |
| 1163 | 1506 | } |
| 1164 | 1507 | |
| 1165 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) { |
| 1166 | | return IrInstructionIdErrSetCast; |
| 1508 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) { |
| 1509 | return IrInstSrcIdAlignCast; |
| 1167 | 1510 | } |
| 1168 | 1511 | |
| 1169 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) { |
| 1170 | | return IrInstructionIdToBytes; |
| 1512 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) { |
| 1513 | return IrInstSrcIdImplicitCast; |
| 1171 | 1514 | } |
| 1172 | 1515 | |
| 1173 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) { |
| 1174 | | return IrInstructionIdFromBytes; |
| 1516 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) { |
| 1517 | return IrInstSrcIdResolveResult; |
| 1175 | 1518 | } |
| 1176 | 1519 | |
| 1177 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) { |
| 1178 | | return IrInstructionIdIntToFloat; |
| 1520 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) { |
| 1521 | return IrInstSrcIdResetResult; |
| 1179 | 1522 | } |
| 1180 | 1523 | |
| 1181 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) { |
| 1182 | | return IrInstructionIdFloatToInt; |
| 1524 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) { |
| 1525 | return IrInstSrcIdOpaqueType; |
| 1183 | 1526 | } |
| 1184 | 1527 | |
| 1185 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) { |
| 1186 | | return IrInstructionIdBoolToInt; |
| 1528 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) { |
| 1529 | return IrInstSrcIdSetAlignStack; |
| 1187 | 1530 | } |
| 1188 | 1531 | |
| 1189 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) { |
| 1190 | | return IrInstructionIdIntType; |
| 1532 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) { |
| 1533 | return IrInstSrcIdArgType; |
| 1191 | 1534 | } |
| 1192 | 1535 | |
| 1193 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) { |
| 1194 | | return IrInstructionIdVectorType; |
| 1536 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) { |
| 1537 | return IrInstSrcIdExport; |
| 1195 | 1538 | } |
| 1196 | 1539 | |
| 1197 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) { |
| 1198 | | return IrInstructionIdShuffleVector; |
| 1540 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) { |
| 1541 | return IrInstSrcIdErrorReturnTrace; |
| 1199 | 1542 | } |
| 1200 | 1543 | |
| 1201 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) { |
| 1202 | | return IrInstructionIdSplatSrc; |
| 1544 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) { |
| 1545 | return IrInstSrcIdErrorUnion; |
| 1203 | 1546 | } |
| 1204 | 1547 | |
| 1205 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) { |
| 1206 | | return IrInstructionIdSplatGen; |
| 1548 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) { |
| 1549 | return IrInstSrcIdAtomicRmw; |
| 1207 | 1550 | } |
| 1208 | 1551 | |
| 1209 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) { |
| 1210 | | return IrInstructionIdBoolNot; |
| 1552 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) { |
| 1553 | return IrInstSrcIdAtomicLoad; |
| 1211 | 1554 | } |
| 1212 | 1555 | |
| 1213 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) { |
| 1214 | | return IrInstructionIdMemset; |
| 1556 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) { |
| 1557 | return IrInstSrcIdAtomicStore; |
| 1215 | 1558 | } |
| 1216 | 1559 | |
| 1217 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) { |
| 1218 | | return IrInstructionIdMemcpy; |
| 1560 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) { |
| 1561 | return IrInstSrcIdSaveErrRetAddr; |
| 1219 | 1562 | } |
| 1220 | 1563 | |
| 1221 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) { |
| 1222 | | return IrInstructionIdSliceSrc; |
| 1564 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) { |
| 1565 | return IrInstSrcIdAddImplicitReturnType; |
| 1223 | 1566 | } |
| 1224 | 1567 | |
| 1225 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) { |
| 1226 | | return IrInstructionIdSliceGen; |
| 1568 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) { |
| 1569 | return IrInstSrcIdErrSetCast; |
| 1227 | 1570 | } |
| 1228 | 1571 | |
| 1229 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) { |
| 1230 | | return IrInstructionIdMemberCount; |
| 1572 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) { |
| 1573 | return IrInstSrcIdToBytes; |
| 1231 | 1574 | } |
| 1232 | 1575 | |
| 1233 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) { |
| 1234 | | return IrInstructionIdMemberType; |
| 1576 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) { |
| 1577 | return IrInstSrcIdFromBytes; |
| 1235 | 1578 | } |
| 1236 | 1579 | |
| 1237 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) { |
| 1238 | | return IrInstructionIdMemberName; |
| 1580 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) { |
| 1581 | return IrInstSrcIdCheckRuntimeScope; |
| 1239 | 1582 | } |
| 1240 | 1583 | |
| 1241 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) { |
| 1242 | | return IrInstructionIdBreakpoint; |
| 1584 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) { |
| 1585 | return IrInstSrcIdHasDecl; |
| 1243 | 1586 | } |
| 1244 | 1587 | |
| 1245 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) { |
| 1246 | | return IrInstructionIdReturnAddress; |
| 1588 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) { |
| 1589 | return IrInstSrcIdUndeclaredIdent; |
| 1247 | 1590 | } |
| 1248 | 1591 | |
| 1249 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) { |
| 1250 | | return IrInstructionIdFrameAddress; |
| 1592 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) { |
| 1593 | return IrInstSrcIdAlloca; |
| 1251 | 1594 | } |
| 1252 | 1595 | |
| 1253 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) { |
| 1254 | | return IrInstructionIdFrameHandle; |
| 1596 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) { |
| 1597 | return IrInstSrcIdEndExpr; |
| 1255 | 1598 | } |
| 1256 | 1599 | |
| 1257 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) { |
| 1258 | | return IrInstructionIdFrameType; |
| 1600 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) { |
| 1601 | return IrInstSrcIdUnionInitNamedField; |
| 1259 | 1602 | } |
| 1260 | 1603 | |
| 1261 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) { |
| 1262 | | return IrInstructionIdFrameSizeSrc; |
| 1604 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) { |
| 1605 | return IrInstSrcIdSuspendBegin; |
| 1263 | 1606 | } |
| 1264 | 1607 | |
| 1265 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) { |
| 1266 | | return IrInstructionIdFrameSizeGen; |
| 1608 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) { |
| 1609 | return IrInstSrcIdSuspendFinish; |
| 1267 | 1610 | } |
| 1268 | 1611 | |
| 1269 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) { |
| 1270 | | return IrInstructionIdAlignOf; |
| 1612 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) { |
| 1613 | return IrInstSrcIdAwait; |
| 1271 | 1614 | } |
| 1272 | 1615 | |
| 1273 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) { |
| 1274 | | return IrInstructionIdOverflowOp; |
| 1616 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) { |
| 1617 | return IrInstSrcIdResume; |
| 1275 | 1618 | } |
| 1276 | 1619 | |
| 1277 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) { |
| 1278 | | return IrInstructionIdTestErrSrc; |
| 1620 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) { |
| 1621 | return IrInstSrcIdSpillBegin; |
| 1279 | 1622 | } |
| 1280 | 1623 | |
| 1281 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) { |
| 1282 | | return IrInstructionIdTestErrGen; |
| 1624 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) { |
| 1625 | return IrInstSrcIdSpillEnd; |
| 1283 | 1626 | } |
| 1284 | 1627 | |
| 1285 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) { |
| 1286 | | return IrInstructionIdMulAdd; |
| 1628 | |
| 1629 | static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) { |
| 1630 | return IrInstGenIdDeclVar; |
| 1631 | } |
| 1632 | |
| 1633 | static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) { |
| 1634 | return IrInstGenIdBr; |
| 1635 | } |
| 1636 | |
| 1637 | static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) { |
| 1638 | return IrInstGenIdCondBr; |
| 1639 | } |
| 1640 | |
| 1641 | static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) { |
| 1642 | return IrInstGenIdSwitchBr; |
| 1643 | } |
| 1644 | |
| 1645 | static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) { |
| 1646 | return IrInstGenIdPhi; |
| 1647 | } |
| 1648 | |
| 1649 | static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) { |
| 1650 | return IrInstGenIdBinaryNot; |
| 1651 | } |
| 1652 | |
| 1653 | static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) { |
| 1654 | return IrInstGenIdNegation; |
| 1655 | } |
| 1656 | |
| 1657 | static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) { |
| 1658 | return IrInstGenIdNegationWrapping; |
| 1659 | } |
| 1660 | |
| 1661 | static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) { |
| 1662 | return IrInstGenIdBinOp; |
| 1663 | } |
| 1664 | |
| 1665 | static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) { |
| 1666 | return IrInstGenIdLoadPtr; |
| 1667 | } |
| 1668 | |
| 1669 | static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) { |
| 1670 | return IrInstGenIdStorePtr; |
| 1671 | } |
| 1672 | |
| 1673 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) { |
| 1674 | return IrInstGenIdVectorStoreElem; |
| 1675 | } |
| 1676 | |
| 1677 | static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) { |
| 1678 | return IrInstGenIdStructFieldPtr; |
| 1679 | } |
| 1680 | |
| 1681 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) { |
| 1682 | return IrInstGenIdUnionFieldPtr; |
| 1683 | } |
| 1684 | |
| 1685 | static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) { |
| 1686 | return IrInstGenIdElemPtr; |
| 1687 | } |
| 1688 | |
| 1689 | static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) { |
| 1690 | return IrInstGenIdVarPtr; |
| 1691 | } |
| 1692 | |
| 1693 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) { |
| 1694 | return IrInstGenIdReturnPtr; |
| 1695 | } |
| 1696 | |
| 1697 | static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) { |
| 1698 | return IrInstGenIdCall; |
| 1699 | } |
| 1700 | |
| 1701 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) { |
| 1702 | return IrInstGenIdReturn; |
| 1287 | 1703 | } |
| 1288 | 1704 | |
| 1289 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) { |
| 1290 | | return IrInstructionIdUnwrapErrCode; |
| 1705 | static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) { |
| 1706 | return IrInstGenIdCast; |
| 1291 | 1707 | } |
| 1292 | 1708 | |
| 1293 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) { |
| 1294 | | return IrInstructionIdUnwrapErrPayload; |
| 1709 | static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) { |
| 1710 | return IrInstGenIdResizeSlice; |
| 1295 | 1711 | } |
| 1296 | 1712 | |
| 1297 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) { |
| 1298 | | return IrInstructionIdOptionalWrap; |
| 1713 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) { |
| 1714 | return IrInstGenIdUnreachable; |
| 1299 | 1715 | } |
| 1300 | 1716 | |
| 1301 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) { |
| 1302 | | return IrInstructionIdErrWrapPayload; |
| 1717 | static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) { |
| 1718 | return IrInstGenIdAsm; |
| 1303 | 1719 | } |
| 1304 | 1720 | |
| 1305 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) { |
| 1306 | | return IrInstructionIdErrWrapCode; |
| 1721 | static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) { |
| 1722 | return IrInstGenIdTestNonNull; |
| 1307 | 1723 | } |
| 1308 | 1724 | |
| 1309 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) { |
| 1310 | | return IrInstructionIdFnProto; |
| 1725 | static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) { |
| 1726 | return IrInstGenIdOptionalUnwrapPtr; |
| 1311 | 1727 | } |
| 1312 | 1728 | |
| 1313 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) { |
| 1314 | | return IrInstructionIdTestComptime; |
| 1729 | static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) { |
| 1730 | return IrInstGenIdOptionalWrap; |
| 1315 | 1731 | } |
| 1316 | 1732 | |
| 1317 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) { |
| 1318 | | return IrInstructionIdPtrCastSrc; |
| 1733 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) { |
| 1734 | return IrInstGenIdUnionTag; |
| 1319 | 1735 | } |
| 1320 | 1736 | |
| 1321 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) { |
| 1322 | | return IrInstructionIdPtrCastGen; |
| 1737 | static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) { |
| 1738 | return IrInstGenIdClz; |
| 1323 | 1739 | } |
| 1324 | 1740 | |
| 1325 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) { |
| 1326 | | return IrInstructionIdBitCastSrc; |
| 1741 | static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) { |
| 1742 | return IrInstGenIdCtz; |
| 1327 | 1743 | } |
| 1328 | 1744 | |
| 1329 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) { |
| 1330 | | return IrInstructionIdBitCastGen; |
| 1745 | static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) { |
| 1746 | return IrInstGenIdPopCount; |
| 1331 | 1747 | } |
| 1332 | 1748 | |
| 1333 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) { |
| 1334 | | return IrInstructionIdWidenOrShorten; |
| 1749 | static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) { |
| 1750 | return IrInstGenIdBswap; |
| 1335 | 1751 | } |
| 1336 | 1752 | |
| 1337 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) { |
| 1338 | | return IrInstructionIdPtrToInt; |
| 1753 | static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) { |
| 1754 | return IrInstGenIdBitReverse; |
| 1339 | 1755 | } |
| 1340 | 1756 | |
| 1341 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) { |
| 1342 | | return IrInstructionIdIntToPtr; |
| 1757 | static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) { |
| 1758 | return IrInstGenIdRef; |
| 1343 | 1759 | } |
| 1344 | 1760 | |
| 1345 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) { |
| 1346 | | return IrInstructionIdIntToEnum; |
| 1761 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) { |
| 1762 | return IrInstGenIdErrName; |
| 1347 | 1763 | } |
| 1348 | 1764 | |
| 1349 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) { |
| 1350 | | return IrInstructionIdEnumToInt; |
| 1765 | static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) { |
| 1766 | return IrInstGenIdCmpxchg; |
| 1351 | 1767 | } |
| 1352 | 1768 | |
| 1353 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) { |
| 1354 | | return IrInstructionIdIntToErr; |
| 1769 | static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) { |
| 1770 | return IrInstGenIdFence; |
| 1355 | 1771 | } |
| 1356 | 1772 | |
| 1357 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) { |
| 1358 | | return IrInstructionIdErrToInt; |
| 1773 | static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) { |
| 1774 | return IrInstGenIdTruncate; |
| 1359 | 1775 | } |
| 1360 | 1776 | |
| 1361 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) { |
| 1362 | | return IrInstructionIdCheckSwitchProngs; |
| 1777 | static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) { |
| 1778 | return IrInstGenIdShuffleVector; |
| 1363 | 1779 | } |
| 1364 | 1780 | |
| 1365 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) { |
| 1366 | | return IrInstructionIdCheckStatementIsVoid; |
| 1781 | static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) { |
| 1782 | return IrInstGenIdSplat; |
| 1367 | 1783 | } |
| 1368 | 1784 | |
| 1369 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) { |
| 1370 | | return IrInstructionIdTypeName; |
| 1785 | static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) { |
| 1786 | return IrInstGenIdBoolNot; |
| 1371 | 1787 | } |
| 1372 | 1788 | |
| 1373 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) { |
| 1374 | | return IrInstructionIdDeclRef; |
| 1789 | static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) { |
| 1790 | return IrInstGenIdMemset; |
| 1375 | 1791 | } |
| 1376 | 1792 | |
| 1377 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) { |
| 1378 | | return IrInstructionIdPanic; |
| 1793 | static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) { |
| 1794 | return IrInstGenIdMemcpy; |
| 1379 | 1795 | } |
| 1380 | 1796 | |
| 1381 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) { |
| 1382 | | return IrInstructionIdTagName; |
| 1797 | static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) { |
| 1798 | return IrInstGenIdSlice; |
| 1383 | 1799 | } |
| 1384 | 1800 | |
| 1385 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) { |
| 1386 | | return IrInstructionIdTagType; |
| 1801 | static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) { |
| 1802 | return IrInstGenIdBreakpoint; |
| 1387 | 1803 | } |
| 1388 | 1804 | |
| 1389 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) { |
| 1390 | | return IrInstructionIdFieldParentPtr; |
| 1805 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) { |
| 1806 | return IrInstGenIdReturnAddress; |
| 1391 | 1807 | } |
| 1392 | 1808 | |
| 1393 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) { |
| 1394 | | return IrInstructionIdByteOffsetOf; |
| 1809 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) { |
| 1810 | return IrInstGenIdFrameAddress; |
| 1395 | 1811 | } |
| 1396 | 1812 | |
| 1397 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) { |
| 1398 | | return IrInstructionIdBitOffsetOf; |
| 1813 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) { |
| 1814 | return IrInstGenIdFrameHandle; |
| 1399 | 1815 | } |
| 1400 | 1816 | |
| 1401 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) { |
| 1402 | | return IrInstructionIdTypeInfo; |
| 1817 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) { |
| 1818 | return IrInstGenIdFrameSize; |
| 1403 | 1819 | } |
| 1404 | 1820 | |
| 1405 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) { |
| 1406 | | return IrInstructionIdType; |
| 1821 | static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) { |
| 1822 | return IrInstGenIdOverflowOp; |
| 1407 | 1823 | } |
| 1408 | 1824 | |
| 1409 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) { |
| 1410 | | return IrInstructionIdHasField; |
| 1825 | static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) { |
| 1826 | return IrInstGenIdTestErr; |
| 1411 | 1827 | } |
| 1412 | 1828 | |
| 1413 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) { |
| 1414 | | return IrInstructionIdTypeId; |
| 1829 | static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) { |
| 1830 | return IrInstGenIdMulAdd; |
| 1415 | 1831 | } |
| 1416 | 1832 | |
| 1417 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) { |
| 1418 | | return IrInstructionIdSetEvalBranchQuota; |
| 1833 | static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) { |
| 1834 | return IrInstGenIdFloatOp; |
| 1419 | 1835 | } |
| 1420 | 1836 | |
| 1421 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) { |
| 1422 | | return IrInstructionIdPtrType; |
| 1837 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) { |
| 1838 | return IrInstGenIdUnwrapErrCode; |
| 1423 | 1839 | } |
| 1424 | 1840 | |
| 1425 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) { |
| 1426 | | return IrInstructionIdAlignCast; |
| 1841 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) { |
| 1842 | return IrInstGenIdUnwrapErrPayload; |
| 1427 | 1843 | } |
| 1428 | 1844 | |
| 1429 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) { |
| 1430 | | return IrInstructionIdImplicitCast; |
| 1845 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) { |
| 1846 | return IrInstGenIdErrWrapCode; |
| 1431 | 1847 | } |
| 1432 | 1848 | |
| 1433 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) { |
| 1434 | | return IrInstructionIdResolveResult; |
| 1849 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) { |
| 1850 | return IrInstGenIdErrWrapPayload; |
| 1435 | 1851 | } |
| 1436 | 1852 | |
| 1437 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) { |
| 1438 | | return IrInstructionIdResetResult; |
| 1853 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) { |
| 1854 | return IrInstGenIdPtrCast; |
| 1439 | 1855 | } |
| 1440 | 1856 | |
| 1441 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) { |
| 1442 | | return IrInstructionIdPtrOfArrayToSlice; |
| 1857 | static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) { |
| 1858 | return IrInstGenIdBitCast; |
| 1443 | 1859 | } |
| 1444 | 1860 | |
| 1445 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { |
| 1446 | | return IrInstructionIdOpaqueType; |
| 1861 | static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) { |
| 1862 | return IrInstGenIdWidenOrShorten; |
| 1447 | 1863 | } |
| 1448 | 1864 | |
| 1449 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) { |
| 1450 | | return IrInstructionIdSetAlignStack; |
| 1865 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) { |
| 1866 | return IrInstGenIdIntToPtr; |
| 1451 | 1867 | } |
| 1452 | 1868 | |
| 1453 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) { |
| 1454 | | return IrInstructionIdArgType; |
| 1869 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) { |
| 1870 | return IrInstGenIdPtrToInt; |
| 1455 | 1871 | } |
| 1456 | 1872 | |
| 1457 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) { |
| 1458 | | return IrInstructionIdErrorReturnTrace; |
| 1873 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) { |
| 1874 | return IrInstGenIdIntToEnum; |
| 1459 | 1875 | } |
| 1460 | 1876 | |
| 1461 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) { |
| 1462 | | return IrInstructionIdErrorUnion; |
| 1877 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) { |
| 1878 | return IrInstGenIdIntToErr; |
| 1463 | 1879 | } |
| 1464 | 1880 | |
| 1465 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) { |
| 1466 | | return IrInstructionIdAtomicRmw; |
| 1881 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) { |
| 1882 | return IrInstGenIdErrToInt; |
| 1467 | 1883 | } |
| 1468 | 1884 | |
| 1469 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) { |
| 1470 | | return IrInstructionIdAtomicLoad; |
| 1885 | static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) { |
| 1886 | return IrInstGenIdPanic; |
| 1471 | 1887 | } |
| 1472 | 1888 | |
| 1473 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) { |
| 1474 | | return IrInstructionIdAtomicStore; |
| 1889 | static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) { |
| 1890 | return IrInstGenIdTagName; |
| 1475 | 1891 | } |
| 1476 | 1892 | |
| 1477 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) { |
| 1478 | | return IrInstructionIdSaveErrRetAddr; |
| 1893 | static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) { |
| 1894 | return IrInstGenIdFieldParentPtr; |
| 1479 | 1895 | } |
| 1480 | 1896 | |
| 1481 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) { |
| 1482 | | return IrInstructionIdAddImplicitReturnType; |
| 1897 | static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) { |
| 1898 | return IrInstGenIdAlignCast; |
| 1483 | 1899 | } |
| 1484 | 1900 | |
| 1485 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) { |
| 1486 | | return IrInstructionIdFloatOp; |
| 1901 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) { |
| 1902 | return IrInstGenIdErrorReturnTrace; |
| 1487 | 1903 | } |
| 1488 | 1904 | |
| 1489 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) { |
| 1490 | | return IrInstructionIdCheckRuntimeScope; |
| 1905 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) { |
| 1906 | return IrInstGenIdAtomicRmw; |
| 1491 | 1907 | } |
| 1492 | 1908 | |
| 1493 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) { |
| 1494 | | return IrInstructionIdVectorToArray; |
| 1909 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) { |
| 1910 | return IrInstGenIdAtomicLoad; |
| 1495 | 1911 | } |
| 1496 | 1912 | |
| 1497 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) { |
| 1498 | | return IrInstructionIdArrayToVector; |
| 1913 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) { |
| 1914 | return IrInstGenIdAtomicStore; |
| 1499 | 1915 | } |
| 1500 | 1916 | |
| 1501 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) { |
| 1502 | | return IrInstructionIdAssertZero; |
| 1917 | static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) { |
| 1918 | return IrInstGenIdSaveErrRetAddr; |
| 1503 | 1919 | } |
| 1504 | 1920 | |
| 1505 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) { |
| 1506 | | return IrInstructionIdAssertNonNull; |
| 1921 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) { |
| 1922 | return IrInstGenIdVectorToArray; |
| 1507 | 1923 | } |
| 1508 | 1924 | |
| 1509 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { |
| 1510 | | return IrInstructionIdHasDecl; |
| 1925 | static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) { |
| 1926 | return IrInstGenIdArrayToVector; |
| 1511 | 1927 | } |
| 1512 | 1928 | |
| 1513 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) { |
| 1514 | | return IrInstructionIdUndeclaredIdent; |
| 1929 | static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) { |
| 1930 | return IrInstGenIdAssertZero; |
| 1515 | 1931 | } |
| 1516 | 1932 | |
| 1517 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) { |
| 1518 | | return IrInstructionIdAllocaSrc; |
| 1933 | static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) { |
| 1934 | return IrInstGenIdAssertNonNull; |
| 1519 | 1935 | } |
| 1520 | 1936 | |
| 1521 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) { |
| 1522 | | return IrInstructionIdAllocaGen; |
| 1937 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) { |
| 1938 | return IrInstGenIdPtrOfArrayToSlice; |
| 1523 | 1939 | } |
| 1524 | 1940 | |
| 1525 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) { |
| 1526 | | return IrInstructionIdEndExpr; |
| 1941 | static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) { |
| 1942 | return IrInstGenIdSuspendBegin; |
| 1527 | 1943 | } |
| 1528 | 1944 | |
| 1529 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) { |
| 1530 | | return IrInstructionIdUnionInitNamedField; |
| 1945 | static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) { |
| 1946 | return IrInstGenIdSuspendFinish; |
| 1531 | 1947 | } |
| 1532 | 1948 | |
| 1533 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) { |
| 1534 | | return IrInstructionIdSuspendBegin; |
| 1949 | static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) { |
| 1950 | return IrInstGenIdAwait; |
| 1535 | 1951 | } |
| 1536 | 1952 | |
| 1537 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) { |
| 1538 | | return IrInstructionIdSuspendFinish; |
| 1953 | static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) { |
| 1954 | return IrInstGenIdResume; |
| 1539 | 1955 | } |
| 1540 | 1956 | |
| 1541 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) { |
| 1542 | | return IrInstructionIdAwaitSrc; |
| 1957 | static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) { |
| 1958 | return IrInstGenIdSpillBegin; |
| 1543 | 1959 | } |
| 1544 | 1960 | |
| 1545 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) { |
| 1546 | | return IrInstructionIdAwaitGen; |
| 1961 | static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) { |
| 1962 | return IrInstGenIdSpillEnd; |
| 1547 | 1963 | } |
| 1548 | 1964 | |
| 1549 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) { |
| 1550 | | return IrInstructionIdResume; |
| 1965 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) { |
| 1966 | return IrInstGenIdVectorExtractElem; |
| 1551 | 1967 | } |
| 1552 | 1968 | |
| 1553 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) { |
| 1554 | | return IrInstructionIdSpillBegin; |
| 1969 | static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) { |
| 1970 | return IrInstGenIdAlloca; |
| 1555 | 1971 | } |
| 1556 | 1972 | |
| 1557 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) { |
| 1558 | | return IrInstructionIdSpillEnd; |
| 1973 | static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) { |
| 1974 | return IrInstGenIdConst; |
| 1559 | 1975 | } |
| 1560 | 1976 | |
| 1561 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) { |
| 1562 | | return IrInstructionIdVectorExtractElem; |
| 1977 | template<typename T> |
| 1978 | static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 1979 | const char *name = nullptr; |
| 1980 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1981 | T *dummy = nullptr; |
| 1982 | name = ir_inst_src_type_str(ir_inst_id(dummy)); |
| 1983 | #endif |
| 1984 | T *special_instruction = allocate<T>(1, name); |
| 1985 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1986 | special_instruction->base.base.scope = scope; |
| 1987 | special_instruction->base.base.source_node = source_node; |
| 1988 | special_instruction->base.base.debug_id = exec_next_debug_id(irb->exec); |
| 1989 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1990 | return special_instruction; |
| 1563 | 1991 | } |
| 1564 | 1992 | |
| 1565 | 1993 | template<typename T> |
| 1566 | | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1994 | static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1567 | 1995 | const char *name = nullptr; |
| 1568 | 1996 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1569 | 1997 | T *dummy = nullptr; |
| 1570 | | name = ir_instruction_type_str(ir_instruction_id(dummy)); |
| 1998 | name = ir_inst_gen_type_str(ir_inst_id(dummy)); |
| 1571 | 1999 | #endif |
| 1572 | 2000 | T *special_instruction = allocate<T>(1, name); |
| 1573 | | special_instruction->base.id = ir_instruction_id(special_instruction); |
| 1574 | | special_instruction->base.scope = scope; |
| 1575 | | special_instruction->base.source_node = source_node; |
| 1576 | | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 2001 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 2002 | special_instruction->base.base.scope = scope; |
| 2003 | special_instruction->base.base.source_node = source_node; |
| 2004 | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1577 | 2005 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1578 | 2006 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 1579 | 2007 | return special_instruction; |
| 1580 | 2008 | } |
| 1581 | 2009 | |
| 1582 | 2010 | template<typename T> |
| 1583 | | static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2011 | static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1584 | 2012 | const char *name = nullptr; |
| 1585 | 2013 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1586 | 2014 | T *dummy = nullptr; |
| 1587 | | name = ir_instruction_type_str(ir_instruction_id(dummy)); |
| 2015 | name = ir_inst_gen_type_str(ir_inst_id(dummy)); |
| 1588 | 2016 | #endif |
| 1589 | 2017 | T *special_instruction = allocate<T>(1, name); |
| 1590 | | special_instruction->base.id = ir_instruction_id(special_instruction); |
| 1591 | | special_instruction->base.scope = scope; |
| 1592 | | special_instruction->base.source_node = source_node; |
| 1593 | | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 2018 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 2019 | special_instruction->base.base.scope = scope; |
| 2020 | special_instruction->base.base.source_node = source_node; |
| 2021 | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1594 | 2022 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1595 | 2023 | return special_instruction; |
| 1596 | 2024 | } |
| 1597 | 2025 | |
| 1598 | 2026 | template<typename T> |
| 1599 | | static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2027 | static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 1600 | 2028 | T *special_instruction = ir_create_instruction<T>(irb, scope, source_node); |
| 1601 | 2029 | ir_instruction_append(irb->current_basic_block, &special_instruction->base); |
| 1602 | 2030 | return special_instruction; |
| 1603 | 2031 | } |
| 1604 | 2032 | |
| 1605 | | static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type, |
| 1606 | | IrInstruction *value, CastOp cast_op) |
| 2033 | template<typename T> |
| 2034 | static T *ir_build_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2035 | T *special_instruction = ir_create_inst_gen<T>(irb, scope, source_node); |
| 2036 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2037 | return special_instruction; |
| 2038 | } |
| 2039 | |
| 2040 | template<typename T> |
| 2041 | static T *ir_build_inst_noreturn(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2042 | T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node); |
| 2043 | special_instruction->base.value = irb->codegen->intern.for_unreachable(); |
| 2044 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2045 | return special_instruction; |
| 2046 | } |
| 2047 | |
| 2048 | template<typename T> |
| 2049 | static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2050 | T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node); |
| 2051 | special_instruction->base.value = irb->codegen->intern.for_void(); |
| 2052 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2053 | return special_instruction; |
| 2054 | } |
| 2055 | |
| 2056 | IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn, |
| 2057 | ZigType *var_type, const char *name_hint) |
| 1607 | 2058 | { |
| 1608 | | IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node); |
| 1609 | | cast_instruction->dest_type = dest_type; |
| 1610 | | cast_instruction->value = value; |
| 1611 | | cast_instruction->cast_op = cast_op; |
| 2059 | IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1); |
| 2060 | alloca_gen->base.id = IrInstGenIdAlloca; |
| 2061 | alloca_gen->base.base.source_node = source_node; |
| 2062 | alloca_gen->base.base.scope = scope; |
| 2063 | alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 2064 | alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false); |
| 2065 | alloca_gen->base.base.ref_count = 1; |
| 2066 | alloca_gen->name_hint = name_hint; |
| 2067 | fn->alloca_gen_list.append(alloca_gen); |
| 2068 | return &alloca_gen->base; |
| 2069 | } |
| 1612 | 2070 | |
| 1613 | | ir_ref_instruction(value, irb->current_basic_block); |
| 2071 | static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type, |
| 2072 | IrInstGen *value, CastOp cast_op) |
| 2073 | { |
| 2074 | IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2075 | inst->base.value->type = dest_type; |
| 2076 | inst->value = value; |
| 2077 | inst->cast_op = cast_op; |
| 2078 | |
| 2079 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 1614 | 2080 | |
| 1615 | | return &cast_instruction->base; |
| 2081 | return &inst->base; |
| 1616 | 2082 | } |
| 1617 | 2083 | |
| 1618 | | static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition, |
| 1619 | | IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) |
| 2084 | static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition, |
| 2085 | IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime) |
| 1620 | 2086 | { |
| 1621 | | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); |
| 1622 | | cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1623 | | cond_br_instruction->base.value->special = ConstValSpecialStatic; |
| 1624 | | cond_br_instruction->condition = condition; |
| 1625 | | cond_br_instruction->then_block = then_block; |
| 1626 | | cond_br_instruction->else_block = else_block; |
| 1627 | | cond_br_instruction->is_comptime = is_comptime; |
| 2087 | IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node); |
| 2088 | inst->base.is_noreturn = true; |
| 2089 | inst->condition = condition; |
| 2090 | inst->then_block = then_block; |
| 2091 | inst->else_block = else_block; |
| 2092 | inst->is_comptime = is_comptime; |
| 1628 | 2093 | |
| 1629 | 2094 | ir_ref_instruction(condition, irb->current_basic_block); |
| 1630 | 2095 | ir_ref_bb(then_block); |
| 1631 | 2096 | ir_ref_bb(else_block); |
| 1632 | 2097 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 1633 | 2098 | |
| 1634 | | return &cond_br_instruction->base; |
| 2099 | return &inst->base; |
| 1635 | 2100 | } |
| 1636 | 2101 | |
| 1637 | | static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1638 | | IrInstruction *operand) |
| 2102 | static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition, |
| 2103 | IrBasicBlockGen *then_block, IrBasicBlockGen *else_block) |
| 1639 | 2104 | { |
| 1640 | | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 1641 | | return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1642 | | return_instruction->base.value->special = ConstValSpecialStatic; |
| 1643 | | return_instruction->operand = operand; |
| 2105 | IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2106 | inst->condition = condition; |
| 2107 | inst->then_block = then_block; |
| 2108 | inst->else_block = else_block; |
| 2109 | |
| 2110 | ir_ref_inst_gen(condition, ira->new_irb.current_basic_block); |
| 2111 | ir_ref_bb_gen(then_block); |
| 2112 | ir_ref_bb_gen(else_block); |
| 2113 | |
| 2114 | return &inst->base; |
| 2115 | } |
| 2116 | |
| 2117 | static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) { |
| 2118 | IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node); |
| 2119 | inst->base.is_noreturn = true; |
| 2120 | inst->operand = operand; |
| 1644 | 2121 | |
| 1645 | 2122 | if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); |
| 1646 | 2123 | |
| 1647 | | return &return_instruction->base; |
| 2124 | return &inst->base; |
| 2125 | } |
| 2126 | |
| 2127 | static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) { |
| 2128 | IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, |
| 2129 | source_inst->scope, source_inst->source_node); |
| 2130 | inst->operand = operand; |
| 2131 | |
| 2132 | if (operand != nullptr) ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2133 | |
| 2134 | return &inst->base; |
| 1648 | 2135 | } |
| 1649 | 2136 | |
| 1650 | | static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1651 | | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 2137 | static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2138 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1652 | 2139 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1653 | | const_instruction->base.value = irb->codegen->intern.for_void(); |
| 2140 | const_instruction->value = irb->codegen->intern.for_void(); |
| 1654 | 2141 | return &const_instruction->base; |
| 1655 | 2142 | } |
| 1656 | 2143 | |
| 1657 | | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1658 | | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 2144 | static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2145 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1659 | 2146 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1660 | | const_instruction->base.value = irb->codegen->intern.for_undefined(); |
| 2147 | const_instruction->value = irb->codegen->intern.for_undefined(); |
| 1661 | 2148 | return &const_instruction->base; |
| 1662 | 2149 | } |
| 1663 | 2150 | |
| 1664 | | static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1665 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1666 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1667 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1668 | | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 2151 | static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 2152 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2153 | const_instruction->value = create_const_vals(1); |
| 2154 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 2155 | const_instruction->value->special = ConstValSpecialStatic; |
| 2156 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1669 | 2157 | return &const_instruction->base; |
| 1670 | 2158 | } |
| 1671 | 2159 | |
| 1672 | | static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { |
| 1673 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1674 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1675 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1676 | | bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint); |
| 2160 | static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { |
| 2161 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2162 | const_instruction->value = create_const_vals(1); |
| 2163 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 2164 | const_instruction->value->special = ConstValSpecialStatic; |
| 2165 | bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint); |
| 1677 | 2166 | return &const_instruction->base; |
| 1678 | 2167 | } |
| 1679 | 2168 | |
| 1680 | | static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { |
| 1681 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1682 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float; |
| 1683 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1684 | | bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat); |
| 2169 | static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { |
| 2170 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2171 | const_instruction->value = create_const_vals(1); |
| 2172 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float; |
| 2173 | const_instruction->value->special = ConstValSpecialStatic; |
| 2174 | bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat); |
| 1685 | 2175 | return &const_instruction->base; |
| 1686 | 2176 | } |
| 1687 | 2177 | |
| 1688 | | static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1689 | | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 2178 | static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2179 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1690 | 2180 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1691 | | const_instruction->base.value = irb->codegen->intern.for_null(); |
| 2181 | const_instruction->value = irb->codegen->intern.for_null(); |
| 1692 | 2182 | return &const_instruction->base; |
| 1693 | 2183 | } |
| 1694 | 2184 | |
| 1695 | | static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1696 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1697 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize; |
| 1698 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1699 | | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 2185 | static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 2186 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2187 | const_instruction->value = create_const_vals(1); |
| 2188 | const_instruction->value->type = irb->codegen->builtin_types.entry_usize; |
| 2189 | const_instruction->value->special = ConstValSpecialStatic; |
| 2190 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1700 | 2191 | return &const_instruction->base; |
| 1701 | 2192 | } |
| 1702 | 2193 | |
| 1703 | | static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2194 | static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 1704 | 2195 | ZigType *type_entry) |
| 1705 | 2196 | { |
| 1706 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1707 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1708 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1709 | | const_instruction->base.value->data.x_type = type_entry; |
| 2197 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2198 | const_instruction->value = create_const_vals(1); |
| 2199 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; |
| 2200 | const_instruction->value->special = ConstValSpecialStatic; |
| 2201 | const_instruction->value->data.x_type = type_entry; |
| 1710 | 2202 | return &const_instruction->base; |
| 1711 | 2203 | } |
| 1712 | 2204 | |
| 1713 | | static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2205 | static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 1714 | 2206 | ZigType *type_entry) |
| 1715 | 2207 | { |
| 1716 | | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 2208 | IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 1717 | 2209 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1718 | 2210 | return instruction; |
| 1719 | 2211 | } |
| 1720 | 2212 | |
| 1721 | | static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 1722 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1723 | | const_instruction->base.value->type = fn_entry->type_entry; |
| 1724 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1725 | | const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 1726 | | const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 1727 | | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction; |
| 1728 | | return &const_instruction->base; |
| 1729 | | } |
| 1730 | | |
| 1731 | | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) { |
| 1732 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1733 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1734 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1735 | | const_instruction->base.value->data.x_type = import; |
| 1736 | | return &const_instruction->base; |
| 1737 | | } |
| 1738 | | |
| 1739 | | static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { |
| 1740 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1741 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool; |
| 1742 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1743 | | const_instruction->base.value->data.x_bool = value; |
| 2213 | static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) { |
| 2214 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2215 | const_instruction->value = create_const_vals(1); |
| 2216 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; |
| 2217 | const_instruction->value->special = ConstValSpecialStatic; |
| 2218 | const_instruction->value->data.x_type = import; |
| 1744 | 2219 | return &const_instruction->base; |
| 1745 | 2220 | } |
| 1746 | 2221 | |
| 1747 | | static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 1748 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1749 | | const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal; |
| 1750 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1751 | | const_instruction->base.value->data.x_enum_literal = name; |
| 2222 | static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) { |
| 2223 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2224 | const_instruction->value = create_const_vals(1); |
| 2225 | const_instruction->value->type = irb->codegen->builtin_types.entry_bool; |
| 2226 | const_instruction->value->special = ConstValSpecialStatic; |
| 2227 | const_instruction->value->data.x_bool = value; |
| 1752 | 2228 | return &const_instruction->base; |
| 1753 | 2229 | } |
| 1754 | 2230 | |
| 1755 | | static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1756 | | ZigFn *fn_entry, IrInstruction *first_arg) |
| 1757 | | { |
| 1758 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1759 | | const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry); |
| 1760 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1761 | | const_instruction->base.value->data.x_bound_fn.fn = fn_entry; |
| 1762 | | const_instruction->base.value->data.x_bound_fn.first_arg = first_arg; |
| 2231 | static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 2232 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2233 | const_instruction->value = create_const_vals(1); |
| 2234 | const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal; |
| 2235 | const_instruction->value->special = ConstValSpecialStatic; |
| 2236 | const_instruction->value->data.x_enum_literal = name; |
| 1763 | 2237 | return &const_instruction->base; |
| 1764 | 2238 | } |
| 1765 | 2239 | |
| 1766 | | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1767 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1768 | | init_const_str_lit(irb->codegen, const_instruction->base.value, str); |
| 2240 | static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 2241 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2242 | const_instruction->value = create_const_vals(1); |
| 2243 | init_const_str_lit(irb->codegen, const_instruction->value, str); |
| 1769 | 2244 | |
| 1770 | 2245 | return &const_instruction->base; |
| 1771 | 2246 | } |
| 1772 | 2247 | |
| 1773 | | static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1774 | | IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str); |
| 2248 | static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 2249 | IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str); |
| 1775 | 2250 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1776 | 2251 | return instruction; |
| 1777 | 2252 | } |
| 1778 | 2253 | |
| 1779 | | static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 1780 | | IrInstruction *op1, IrInstruction *op2, bool safety_check_on) |
| 2254 | static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 2255 | IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on) |
| 1781 | 2256 | { |
| 1782 | | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node); |
| 1783 | | bin_op_instruction->op_id = op_id; |
| 1784 | | bin_op_instruction->op1 = op1; |
| 1785 | | bin_op_instruction->op2 = op2; |
| 1786 | | bin_op_instruction->safety_check_on = safety_check_on; |
| 2257 | IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node); |
| 2258 | inst->op_id = op_id; |
| 2259 | inst->op1 = op1; |
| 2260 | inst->op2 = op2; |
| 2261 | inst->safety_check_on = safety_check_on; |
| 1787 | 2262 | |
| 1788 | 2263 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1789 | 2264 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1790 | 2265 | |
| 1791 | | return &bin_op_instruction->base; |
| 2266 | return &inst->base; |
| 1792 | 2267 | } |
| 1793 | 2268 | |
| 1794 | | static IrInstruction *ir_build_bin_op_gen(IrAnalyze *ira, IrInstruction *source_instr, ZigType *res_type, |
| 1795 | | IrBinOp op_id, IrInstruction *op1, IrInstruction *op2, bool safety_check_on) |
| 2269 | static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type, |
| 2270 | IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on) |
| 1796 | 2271 | { |
| 1797 | | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb, |
| 2272 | IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb, |
| 1798 | 2273 | source_instr->scope, source_instr->source_node); |
| 1799 | | bin_op_instruction->base.value->type = res_type; |
| 1800 | | bin_op_instruction->op_id = op_id; |
| 1801 | | bin_op_instruction->op1 = op1; |
| 1802 | | bin_op_instruction->op2 = op2; |
| 1803 | | bin_op_instruction->safety_check_on = safety_check_on; |
| 2274 | inst->base.value->type = res_type; |
| 2275 | inst->op_id = op_id; |
| 2276 | inst->op1 = op1; |
| 2277 | inst->op2 = op2; |
| 2278 | inst->safety_check_on = safety_check_on; |
| 1804 | 2279 | |
| 1805 | | ir_ref_instruction(op1, ira->new_irb.current_basic_block); |
| 1806 | | ir_ref_instruction(op2, ira->new_irb.current_basic_block); |
| 2280 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 2281 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 1807 | 2282 | |
| 1808 | | return &bin_op_instruction->base; |
| 2283 | return &inst->base; |
| 1809 | 2284 | } |
| 1810 | 2285 | |
| 1811 | 2286 | |
| 1812 | | static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1813 | | IrInstruction *op1, IrInstruction *op2, Buf *type_name) |
| 2287 | static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2288 | IrInstSrc *op1, IrInstSrc *op2, Buf *type_name) |
| 1814 | 2289 | { |
| 1815 | | IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node); |
| 1816 | | merge_err_sets_instruction->op1 = op1; |
| 1817 | | merge_err_sets_instruction->op2 = op2; |
| 1818 | | merge_err_sets_instruction->type_name = type_name; |
| 2290 | IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node); |
| 2291 | inst->op1 = op1; |
| 2292 | inst->op2 = op2; |
| 2293 | inst->type_name = type_name; |
| 1819 | 2294 | |
| 1820 | 2295 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1821 | 2296 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1822 | 2297 | |
| 1823 | | return &merge_err_sets_instruction->base; |
| 2298 | return &inst->base; |
| 1824 | 2299 | } |
| 1825 | 2300 | |
| 1826 | | static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 2301 | static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 1827 | 2302 | ScopeFnDef *crossed_fndef_scope) |
| 1828 | 2303 | { |
| 1829 | | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 2304 | IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node); |
| 1830 | 2305 | instruction->var = var; |
| 1831 | 2306 | instruction->crossed_fndef_scope = crossed_fndef_scope; |
| 1832 | 2307 | |
| ... | ... | @@ -1835,22 +2310,30 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode * |
| 1835 | 2310 | return &instruction->base; |
| 1836 | 2311 | } |
| 1837 | 2312 | |
| 1838 | | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 2313 | static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 1839 | 2314 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); |
| 1840 | 2315 | } |
| 1841 | 2316 | |
| 1842 | | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 1843 | | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, |
| 1844 | | source_instruction->scope, source_instruction->source_node); |
| 2317 | static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 2318 | IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2319 | instruction->var = var; |
| 2320 | |
| 2321 | ir_ref_var(var); |
| 2322 | |
| 2323 | return &instruction->base; |
| 2324 | } |
| 2325 | |
| 2326 | static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 2327 | IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb, scope, source_node); |
| 1845 | 2328 | instruction->base.value->type = ty; |
| 1846 | 2329 | return &instruction->base; |
| 1847 | 2330 | } |
| 1848 | 2331 | |
| 1849 | | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1850 | | IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len, |
| 2332 | static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2333 | IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len, |
| 1851 | 2334 | AstNode *init_array_type_source_node) |
| 1852 | 2335 | { |
| 1853 | | IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node); |
| 2336 | IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node); |
| 1854 | 2337 | instruction->array_ptr = array_ptr; |
| 1855 | 2338 | instruction->elem_index = elem_index; |
| 1856 | 2339 | instruction->safety_check_on = safety_check_on; |
| ... | ... | @@ -1863,10 +2346,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 1863 | 2346 | return &instruction->base; |
| 1864 | 2347 | } |
| 1865 | 2348 | |
| 1866 | | static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1867 | | IrInstruction *container_ptr, IrInstruction *field_name_expr, bool initializing) |
| 2349 | static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2350 | IrInstGen *array_ptr, IrInstGen *elem_index, bool safety_check_on, ZigType *return_type) |
| 2351 | { |
| 2352 | IrInstGenElemPtr *instruction = ir_build_inst_gen<IrInstGenElemPtr>(&ira->new_irb, scope, source_node); |
| 2353 | instruction->base.value->type = return_type; |
| 2354 | instruction->array_ptr = array_ptr; |
| 2355 | instruction->elem_index = elem_index; |
| 2356 | instruction->safety_check_on = safety_check_on; |
| 2357 | |
| 2358 | ir_ref_inst_gen(array_ptr, ira->new_irb.current_basic_block); |
| 2359 | ir_ref_inst_gen(elem_index, ira->new_irb.current_basic_block); |
| 2360 | |
| 2361 | return &instruction->base; |
| 2362 | } |
| 2363 | |
| 2364 | static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2365 | IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing) |
| 1868 | 2366 | { |
| 1869 | | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 2367 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); |
| 1870 | 2368 | instruction->container_ptr = container_ptr; |
| 1871 | 2369 | instruction->field_name_buffer = nullptr; |
| 1872 | 2370 | instruction->field_name_expr = field_name_expr; |
| ... | ... | @@ -1878,10 +2376,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop |
| 1878 | 2376 | return &instruction->base; |
| 1879 | 2377 | } |
| 1880 | 2378 | |
| 1881 | | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1882 | | IrInstruction *container_ptr, Buf *field_name, bool initializing) |
| 2379 | static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2380 | IrInstSrc *container_ptr, Buf *field_name, bool initializing) |
| 1883 | 2381 | { |
| 1884 | | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 2382 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); |
| 1885 | 2383 | instruction->container_ptr = container_ptr; |
| 1886 | 2384 | instruction->field_name_buffer = field_name; |
| 1887 | 2385 | instruction->field_name_expr = nullptr; |
| ... | ... | @@ -1892,10 +2390,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1892 | 2390 | return &instruction->base; |
| 1893 | 2391 | } |
| 1894 | 2392 | |
| 1895 | | static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1896 | | IrInstruction *container_type, IrInstruction *field_name) |
| 2393 | static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2394 | IrInstSrc *container_type, IrInstSrc *field_name) |
| 1897 | 2395 | { |
| 1898 | | IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node); |
| 2396 | IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node); |
| 1899 | 2397 | instruction->container_type = container_type; |
| 1900 | 2398 | instruction->field_name = field_name; |
| 1901 | 2399 | |
| ... | ... | @@ -1905,36 +2403,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode * |
| 1905 | 2403 | return &instruction->base; |
| 1906 | 2404 | } |
| 1907 | 2405 | |
| 1908 | | static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1909 | | IrInstruction *struct_ptr, TypeStructField *field) |
| 2406 | static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 2407 | IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type) |
| 1910 | 2408 | { |
| 1911 | | IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node); |
| 1912 | | instruction->struct_ptr = struct_ptr; |
| 1913 | | instruction->field = field; |
| 2409 | IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2410 | inst->base.value->type = ptr_type; |
| 2411 | inst->struct_ptr = struct_ptr; |
| 2412 | inst->field = field; |
| 1914 | 2413 | |
| 1915 | | ir_ref_instruction(struct_ptr, irb->current_basic_block); |
| 2414 | ir_ref_inst_gen(struct_ptr, ira->new_irb.current_basic_block); |
| 1916 | 2415 | |
| 1917 | | return &instruction->base; |
| 2416 | return &inst->base; |
| 1918 | 2417 | } |
| 1919 | 2418 | |
| 1920 | | static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1921 | | IrInstruction *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing) |
| 2419 | static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 2420 | IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type) |
| 1922 | 2421 | { |
| 1923 | | IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node); |
| 1924 | | instruction->initializing = initializing; |
| 1925 | | instruction->safety_check_on = safety_check_on; |
| 1926 | | instruction->union_ptr = union_ptr; |
| 1927 | | instruction->field = field; |
| 2422 | IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb, |
| 2423 | source_instr->scope, source_instr->source_node); |
| 2424 | inst->base.value->type = ptr_type; |
| 2425 | inst->initializing = initializing; |
| 2426 | inst->safety_check_on = safety_check_on; |
| 2427 | inst->union_ptr = union_ptr; |
| 2428 | inst->field = field; |
| 1928 | 2429 | |
| 1929 | | ir_ref_instruction(union_ptr, irb->current_basic_block); |
| 2430 | ir_ref_inst_gen(union_ptr, ira->new_irb.current_basic_block); |
| 1930 | 2431 | |
| 1931 | | return &instruction->base; |
| 2432 | return &inst->base; |
| 1932 | 2433 | } |
| 1933 | 2434 | |
| 1934 | | static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1935 | | IrInstruction *options, IrInstruction *fn_ref, IrInstruction *args, ResultLoc *result_loc) |
| 2435 | static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2436 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc) |
| 1936 | 2437 | { |
| 1937 | | IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node); |
| 2438 | IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node); |
| 1938 | 2439 | call_instruction->options = options; |
| 1939 | 2440 | call_instruction->fn_ref = fn_ref; |
| 1940 | 2441 | call_instruction->args = args; |
| ... | ... | @@ -1947,11 +2448,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode |
| 1947 | 2448 | return &call_instruction->base; |
| 1948 | 2449 | } |
| 1949 | 2450 | |
| 1950 | | static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1951 | | IrInstruction *options, IrInstruction *fn_ref, IrInstruction **args_ptr, size_t args_len, |
| 2451 | static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2452 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len, |
| 1952 | 2453 | ResultLoc *result_loc) |
| 1953 | 2454 | { |
| 1954 | | IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node); |
| 2455 | IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node); |
| 1955 | 2456 | call_instruction->options = options; |
| 1956 | 2457 | call_instruction->fn_ref = fn_ref; |
| 1957 | 2458 | call_instruction->args_ptr = args_ptr; |
| ... | ... | @@ -1966,12 +2467,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo |
| 1966 | 2467 | return &call_instruction->base; |
| 1967 | 2468 | } |
| 1968 | 2469 | |
| 1969 | | static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1970 | | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1971 | | IrInstruction *ret_ptr, CallModifier modifier, bool is_async_call_builtin, |
| 1972 | | IrInstruction *new_stack, ResultLoc *result_loc) |
| 2470 | static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2471 | ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args, |
| 2472 | IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin, |
| 2473 | IrInstSrc *new_stack, ResultLoc *result_loc) |
| 1973 | 2474 | { |
| 1974 | | IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node); |
| 2475 | IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node); |
| 1975 | 2476 | call_instruction->fn_entry = fn_entry; |
| 1976 | 2477 | call_instruction->fn_ref = fn_ref; |
| 1977 | 2478 | call_instruction->args = args; |
| ... | ... | @@ -1991,12 +2492,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s |
| 1991 | 2492 | return &call_instruction->base; |
| 1992 | 2493 | } |
| 1993 | 2494 | |
| 1994 | | static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 1995 | | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1996 | | CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin, |
| 1997 | | IrInstruction *result_loc, ZigType *return_type) |
| 2495 | static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2496 | ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args, |
| 2497 | CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin, |
| 2498 | IrInstGen *result_loc, ZigType *return_type) |
| 1998 | 2499 | { |
| 1999 | | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, |
| 2500 | IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb, |
| 2000 | 2501 | source_instruction->scope, source_instruction->source_node); |
| 2001 | 2502 | call_instruction->base.value->type = return_type; |
| 2002 | 2503 | call_instruction->fn_entry = fn_entry; |
| ... | ... | @@ -2008,23 +2509,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so |
| 2008 | 2509 | call_instruction->new_stack = new_stack; |
| 2009 | 2510 | call_instruction->result_loc = result_loc; |
| 2010 | 2511 | |
| 2011 | | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); |
| 2512 | if (fn_ref != nullptr) ir_ref_inst_gen(fn_ref, ira->new_irb.current_basic_block); |
| 2012 | 2513 | for (size_t i = 0; i < arg_count; i += 1) |
| 2013 | | ir_ref_instruction(args[i], ira->new_irb.current_basic_block); |
| 2014 | | if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block); |
| 2015 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 2514 | ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block); |
| 2515 | if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block); |
| 2516 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2016 | 2517 | |
| 2017 | 2518 | return call_instruction; |
| 2018 | 2519 | } |
| 2019 | 2520 | |
| 2020 | | static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2021 | | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values, |
| 2521 | static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2522 | size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values, |
| 2022 | 2523 | ResultLocPeerParent *peer_parent) |
| 2023 | 2524 | { |
| 2024 | 2525 | assert(incoming_count != 0); |
| 2025 | 2526 | assert(incoming_count != SIZE_MAX); |
| 2026 | 2527 | |
| 2027 | | IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node); |
| 2528 | IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node); |
| 2028 | 2529 | phi_instruction->incoming_count = incoming_count; |
| 2029 | 2530 | phi_instruction->incoming_blocks = incoming_blocks; |
| 2030 | 2531 | phi_instruction->incoming_values = incoming_values; |
| ... | ... | @@ -2038,56 +2539,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source |
| 2038 | 2539 | return &phi_instruction->base; |
| 2039 | 2540 | } |
| 2040 | 2541 | |
| 2041 | | static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2042 | | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 2542 | static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count, |
| 2543 | IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type) |
| 2043 | 2544 | { |
| 2044 | | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node); |
| 2045 | | br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 2046 | | br_instruction->base.value->special = ConstValSpecialStatic; |
| 2047 | | br_instruction->dest_block = dest_block; |
| 2048 | | br_instruction->is_comptime = is_comptime; |
| 2545 | assert(incoming_count != 0); |
| 2546 | assert(incoming_count != SIZE_MAX); |
| 2049 | 2547 | |
| 2050 | | ir_ref_bb(dest_block); |
| 2051 | | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 2548 | IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb, |
| 2549 | source_instr->scope, source_instr->source_node); |
| 2550 | phi_instruction->base.value->type = result_type; |
| 2551 | phi_instruction->incoming_count = incoming_count; |
| 2552 | phi_instruction->incoming_blocks = incoming_blocks; |
| 2553 | phi_instruction->incoming_values = incoming_values; |
| 2052 | 2554 | |
| 2053 | | return &br_instruction->base; |
| 2054 | | } |
| 2555 | for (size_t i = 0; i < incoming_count; i += 1) { |
| 2556 | ir_ref_bb_gen(incoming_blocks[i]); |
| 2557 | ir_ref_inst_gen(incoming_values[i], ira->new_irb.current_basic_block); |
| 2558 | } |
| 2055 | 2559 | |
| 2056 | | static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2057 | | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 2058 | | { |
| 2059 | | IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_comptime); |
| 2060 | | ir_instruction_append(irb->current_basic_block, instruction); |
| 2061 | | return instruction; |
| 2560 | return &phi_instruction->base; |
| 2062 | 2561 | } |
| 2063 | 2562 | |
| 2064 | | static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2065 | | IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 2066 | | IrInstruction *sentinel, IrInstruction *align_value, |
| 2067 | | uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) |
| 2563 | static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2564 | IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime) |
| 2068 | 2565 | { |
| 2069 | | IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node); |
| 2070 | | ptr_type_of_instruction->sentinel = sentinel; |
| 2071 | | ptr_type_of_instruction->align_value = align_value; |
| 2072 | | ptr_type_of_instruction->child_type = child_type; |
| 2073 | | ptr_type_of_instruction->is_const = is_const; |
| 2074 | | ptr_type_of_instruction->is_volatile = is_volatile; |
| 2075 | | ptr_type_of_instruction->ptr_len = ptr_len; |
| 2076 | | ptr_type_of_instruction->bit_offset_start = bit_offset_start; |
| 2077 | | ptr_type_of_instruction->host_int_bytes = host_int_bytes; |
| 2078 | | ptr_type_of_instruction->is_allow_zero = is_allow_zero; |
| 2566 | IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node); |
| 2567 | inst->base.is_noreturn = true; |
| 2568 | inst->dest_block = dest_block; |
| 2569 | inst->is_comptime = is_comptime; |
| 2079 | 2570 | |
| 2080 | | if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block); |
| 2081 | | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2082 | | ir_ref_instruction(child_type, irb->current_basic_block); |
| 2571 | ir_ref_bb(dest_block); |
| 2572 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 2573 | |
| 2574 | return &inst->base; |
| 2575 | } |
| 2576 | |
| 2577 | static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) { |
| 2578 | IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2579 | inst->dest_block = dest_block; |
| 2580 | |
| 2581 | ir_ref_bb_gen(dest_block); |
| 2582 | |
| 2583 | return &inst->base; |
| 2584 | } |
| 2585 | |
| 2586 | static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2587 | IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 2588 | IrInstSrc *sentinel, IrInstSrc *align_value, |
| 2589 | uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) |
| 2590 | { |
| 2591 | IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node); |
| 2592 | inst->sentinel = sentinel; |
| 2593 | inst->align_value = align_value; |
| 2594 | inst->child_type = child_type; |
| 2595 | inst->is_const = is_const; |
| 2596 | inst->is_volatile = is_volatile; |
| 2597 | inst->ptr_len = ptr_len; |
| 2598 | inst->bit_offset_start = bit_offset_start; |
| 2599 | inst->host_int_bytes = host_int_bytes; |
| 2600 | inst->is_allow_zero = is_allow_zero; |
| 2083 | 2601 | |
| 2084 | | return &ptr_type_of_instruction->base; |
| 2602 | if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block); |
| 2603 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2604 | ir_ref_instruction(child_type, irb->current_basic_block); |
| 2605 | |
| 2606 | return &inst->base; |
| 2085 | 2607 | } |
| 2086 | 2608 | |
| 2087 | | static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2088 | | IrInstruction *value, LVal lval, ResultLoc *result_loc) |
| 2609 | static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2610 | IrInstSrc *value, LVal lval, ResultLoc *result_loc) |
| 2089 | 2611 | { |
| 2090 | | IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 2612 | IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node); |
| 2091 | 2613 | instruction->op_id = op_id; |
| 2092 | 2614 | instruction->value = value; |
| 2093 | 2615 | instruction->lval = lval; |
| ... | ... | @@ -2098,18 +2620,55 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode |
| 2098 | 2620 | return &instruction->base; |
| 2099 | 2621 | } |
| 2100 | 2622 | |
| 2101 | | static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2102 | | IrInstruction *value) |
| 2623 | static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2624 | IrInstSrc *value) |
| 2103 | 2625 | { |
| 2104 | 2626 | return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr); |
| 2105 | 2627 | } |
| 2106 | 2628 | |
| 2107 | | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2108 | | size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc, |
| 2629 | static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) { |
| 2630 | IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb, |
| 2631 | source_instr->scope, source_instr->source_node); |
| 2632 | instruction->base.value->type = expr_type; |
| 2633 | instruction->operand = operand; |
| 2634 | |
| 2635 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2636 | |
| 2637 | return &instruction->base; |
| 2638 | } |
| 2639 | |
| 2640 | static IrInstGen *ir_build_negation_wrapping(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 2641 | ZigType *expr_type) |
| 2642 | { |
| 2643 | IrInstGenNegationWrapping *instruction = ir_build_inst_gen<IrInstGenNegationWrapping>(&ira->new_irb, |
| 2644 | source_instr->scope, source_instr->source_node); |
| 2645 | instruction->base.value->type = expr_type; |
| 2646 | instruction->operand = operand; |
| 2647 | |
| 2648 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2649 | |
| 2650 | return &instruction->base; |
| 2651 | } |
| 2652 | |
| 2653 | static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 2654 | ZigType *expr_type) |
| 2655 | { |
| 2656 | IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb, |
| 2657 | source_instr->scope, source_instr->source_node); |
| 2658 | instruction->base.value->type = expr_type; |
| 2659 | instruction->operand = operand; |
| 2660 | |
| 2661 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2662 | |
| 2663 | return &instruction->base; |
| 2664 | } |
| 2665 | |
| 2666 | static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2667 | size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc, |
| 2109 | 2668 | AstNode *init_array_type_source_node) |
| 2110 | 2669 | { |
| 2111 | | IrInstructionContainerInitList *container_init_list_instruction = |
| 2112 | | ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node); |
| 2670 | IrInstSrcContainerInitList *container_init_list_instruction = |
| 2671 | ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node); |
| 2113 | 2672 | container_init_list_instruction->item_count = item_count; |
| 2114 | 2673 | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; |
| 2115 | 2674 | container_init_list_instruction->result_loc = result_loc; |
| ... | ... | @@ -2123,11 +2682,11 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, |
| 2123 | 2682 | return &container_init_list_instruction->base; |
| 2124 | 2683 | } |
| 2125 | 2684 | |
| 2126 | | static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2127 | | size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc) |
| 2685 | static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2686 | size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc) |
| 2128 | 2687 | { |
| 2129 | | IrInstructionContainerInitFields *container_init_fields_instruction = |
| 2130 | | ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node); |
| 2688 | IrInstSrcContainerInitFields *container_init_fields_instruction = |
| 2689 | ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node); |
| 2131 | 2690 | container_init_fields_instruction->field_count = field_count; |
| 2132 | 2691 | container_init_fields_instruction->fields = fields; |
| 2133 | 2692 | container_init_fields_instruction->result_loc = result_loc; |
| ... | ... | @@ -2140,20 +2699,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 2140 | 2699 | return &container_init_fields_instruction->base; |
| 2141 | 2700 | } |
| 2142 | 2701 | |
| 2143 | | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2144 | | IrInstructionUnreachable *unreachable_instruction = |
| 2145 | | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| 2146 | | unreachable_instruction->base.value->special = ConstValSpecialStatic; |
| 2147 | | unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 2148 | | return &unreachable_instruction->base; |
| 2702 | static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2703 | IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node); |
| 2704 | inst->base.is_noreturn = true; |
| 2705 | return &inst->base; |
| 2149 | 2706 | } |
| 2150 | 2707 | |
| 2151 | | static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2152 | | IrInstruction *ptr, IrInstruction *value) |
| 2708 | static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 2709 | IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2710 | return &inst->base; |
| 2711 | } |
| 2712 | |
| 2713 | static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2714 | IrInstSrc *ptr, IrInstSrc *value) |
| 2153 | 2715 | { |
| 2154 | | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| 2155 | | instruction->base.value->special = ConstValSpecialStatic; |
| 2156 | | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 2716 | IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node); |
| 2157 | 2717 | instruction->ptr = ptr; |
| 2158 | 2718 | instruction->value = value; |
| 2159 | 2719 | |
| ... | ... | @@ -2163,76 +2723,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A |
| 2163 | 2723 | return instruction; |
| 2164 | 2724 | } |
| 2165 | 2725 | |
| 2166 | | static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2167 | | IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *value) |
| 2726 | static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) { |
| 2727 | IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb, |
| 2728 | source_instr->scope, source_instr->source_node); |
| 2729 | instruction->ptr = ptr; |
| 2730 | instruction->value = value; |
| 2731 | |
| 2732 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 2733 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2734 | |
| 2735 | return &instruction->base; |
| 2736 | } |
| 2737 | |
| 2738 | static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst, |
| 2739 | IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value) |
| 2168 | 2740 | { |
| 2169 | | IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>( |
| 2170 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2171 | | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2741 | IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>( |
| 2742 | &ira->new_irb, src_inst->scope, src_inst->source_node); |
| 2172 | 2743 | inst->vector_ptr = vector_ptr; |
| 2173 | 2744 | inst->index = index; |
| 2174 | 2745 | inst->value = value; |
| 2175 | 2746 | |
| 2176 | | ir_ref_instruction(vector_ptr, ira->new_irb.current_basic_block); |
| 2177 | | ir_ref_instruction(index, ira->new_irb.current_basic_block); |
| 2178 | | ir_ref_instruction(value, ira->new_irb.current_basic_block); |
| 2747 | ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block); |
| 2748 | ir_ref_inst_gen(index, ira->new_irb.current_basic_block); |
| 2749 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2179 | 2750 | |
| 2180 | 2751 | return &inst->base; |
| 2181 | 2752 | } |
| 2182 | 2753 | |
| 2183 | | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2184 | | ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) |
| 2754 | static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2755 | ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr) |
| 2185 | 2756 | { |
| 2186 | | IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node); |
| 2187 | | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 2188 | | decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 2189 | | decl_var_instruction->var = var; |
| 2190 | | decl_var_instruction->align_value = align_value; |
| 2191 | | decl_var_instruction->ptr = ptr; |
| 2757 | IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node); |
| 2758 | inst->var = var; |
| 2759 | inst->align_value = align_value; |
| 2760 | inst->ptr = ptr; |
| 2192 | 2761 | |
| 2193 | 2762 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2194 | 2763 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 2195 | 2764 | |
| 2196 | | return &decl_var_instruction->base; |
| 2765 | return &inst->base; |
| 2197 | 2766 | } |
| 2198 | 2767 | |
| 2199 | | static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2200 | | ZigVar *var, IrInstruction *var_ptr) |
| 2768 | static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2769 | ZigVar *var, IrInstGen *var_ptr) |
| 2201 | 2770 | { |
| 2202 | | IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb, |
| 2771 | IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb, |
| 2203 | 2772 | source_instruction->scope, source_instruction->source_node); |
| 2204 | | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 2205 | | decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2206 | | decl_var_instruction->var = var; |
| 2207 | | decl_var_instruction->var_ptr = var_ptr; |
| 2773 | inst->base.value->special = ConstValSpecialStatic; |
| 2774 | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2775 | inst->var = var; |
| 2776 | inst->var_ptr = var_ptr; |
| 2208 | 2777 | |
| 2209 | | ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block); |
| 2778 | ir_ref_inst_gen(var_ptr, ira->new_irb.current_basic_block); |
| 2210 | 2779 | |
| 2211 | | return &decl_var_instruction->base; |
| 2780 | return &inst->base; |
| 2212 | 2781 | } |
| 2213 | 2782 | |
| 2214 | | static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2215 | | IrInstruction *operand, ZigType *ty, IrInstruction *result_loc) |
| 2783 | static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction, |
| 2784 | IrInstGen *operand, ZigType *ty, IrInstGen *result_loc) |
| 2216 | 2785 | { |
| 2217 | | IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, |
| 2786 | IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb, |
| 2218 | 2787 | source_instruction->scope, source_instruction->source_node); |
| 2219 | 2788 | instruction->base.value->type = ty; |
| 2220 | 2789 | instruction->operand = operand; |
| 2221 | 2790 | instruction->result_loc = result_loc; |
| 2222 | 2791 | |
| 2223 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 2224 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 2792 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2793 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2225 | 2794 | |
| 2226 | 2795 | return &instruction->base; |
| 2227 | 2796 | } |
| 2228 | 2797 | |
| 2229 | | static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2230 | | IrInstruction *target, IrInstruction *options) |
| 2798 | static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2799 | IrInstSrc *target, IrInstSrc *options) |
| 2231 | 2800 | { |
| 2232 | | IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( |
| 2801 | IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>( |
| 2233 | 2802 | irb, scope, source_node); |
| 2234 | | export_instruction->base.value->special = ConstValSpecialStatic; |
| 2235 | | export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 2236 | 2803 | export_instruction->target = target; |
| 2237 | 2804 | export_instruction->options = options; |
| 2238 | 2805 | |
| ... | ... | @@ -2242,8 +2809,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2242 | 2809 | return &export_instruction->base; |
| 2243 | 2810 | } |
| 2244 | 2811 | |
| 2245 | | static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { |
| 2246 | | IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node); |
| 2812 | static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) { |
| 2813 | IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node); |
| 2247 | 2814 | instruction->ptr = ptr; |
| 2248 | 2815 | |
| 2249 | 2816 | ir_ref_instruction(ptr, irb->current_basic_block); |
| ... | ... | @@ -2251,8 +2818,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 2251 | 2818 | return &instruction->base; |
| 2252 | 2819 | } |
| 2253 | 2820 | |
| 2254 | | static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 2255 | | IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node); |
| 2821 | static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2822 | IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc) |
| 2823 | { |
| 2824 | IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>( |
| 2825 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2826 | instruction->base.value->type = ty; |
| 2827 | instruction->ptr = ptr; |
| 2828 | instruction->result_loc = result_loc; |
| 2829 | |
| 2830 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 2831 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2832 | |
| 2833 | return &instruction->base; |
| 2834 | } |
| 2835 | |
| 2836 | static IrInstSrc *ir_build_typeof(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 2837 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node); |
| 2256 | 2838 | instruction->value = value; |
| 2257 | 2839 | |
| 2258 | 2840 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2260,8 +2842,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2260 | 2842 | return &instruction->base; |
| 2261 | 2843 | } |
| 2262 | 2844 | |
| 2263 | | static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) { |
| 2264 | | IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node); |
| 2845 | static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) { |
| 2846 | IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node); |
| 2265 | 2847 | instruction->is_cold = is_cold; |
| 2266 | 2848 | |
| 2267 | 2849 | ir_ref_instruction(is_cold, irb->current_basic_block); |
| ... | ... | @@ -2269,21 +2851,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s |
| 2269 | 2851 | return &instruction->base; |
| 2270 | 2852 | } |
| 2271 | 2853 | |
| 2272 | | static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2273 | | IrInstruction *safety_on) |
| 2854 | static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2855 | IrInstSrc *safety_on) |
| 2274 | 2856 | { |
| 2275 | | IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node); |
| 2276 | | instruction->safety_on = safety_on; |
| 2857 | IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node); |
| 2858 | inst->safety_on = safety_on; |
| 2277 | 2859 | |
| 2278 | 2860 | ir_ref_instruction(safety_on, irb->current_basic_block); |
| 2279 | 2861 | |
| 2280 | | return &instruction->base; |
| 2862 | return &inst->base; |
| 2281 | 2863 | } |
| 2282 | 2864 | |
| 2283 | | static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2284 | | IrInstruction *mode_value) |
| 2865 | static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2866 | IrInstSrc *mode_value) |
| 2285 | 2867 | { |
| 2286 | | IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node); |
| 2868 | IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node); |
| 2287 | 2869 | instruction->mode_value = mode_value; |
| 2288 | 2870 | |
| 2289 | 2871 | ir_ref_instruction(mode_value, irb->current_basic_block); |
| ... | ... | @@ -2291,10 +2873,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN |
| 2291 | 2873 | return &instruction->base; |
| 2292 | 2874 | } |
| 2293 | 2875 | |
| 2294 | | static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size, |
| 2295 | | IrInstruction *sentinel, IrInstruction *child_type) |
| 2876 | static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size, |
| 2877 | IrInstSrc *sentinel, IrInstSrc *child_type) |
| 2296 | 2878 | { |
| 2297 | | IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node); |
| 2879 | IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node); |
| 2298 | 2880 | instruction->size = size; |
| 2299 | 2881 | instruction->sentinel = sentinel; |
| 2300 | 2882 | instruction->child_type = child_type; |
| ... | ... | @@ -2306,10 +2888,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode |
| 2306 | 2888 | return &instruction->base; |
| 2307 | 2889 | } |
| 2308 | 2890 | |
| 2309 | | static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2310 | | IrInstruction *payload_type) |
| 2891 | static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2892 | IrInstSrc *payload_type) |
| 2311 | 2893 | { |
| 2312 | | IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node); |
| 2894 | IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node); |
| 2313 | 2895 | instruction->payload_type = payload_type; |
| 2314 | 2896 | |
| 2315 | 2897 | if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block); |
| ... | ... | @@ -2317,11 +2899,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo |
| 2317 | 2899 | return &instruction->base; |
| 2318 | 2900 | } |
| 2319 | 2901 | |
| 2320 | | static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2321 | | IrInstruction *child_type, bool is_const, bool is_volatile, |
| 2322 | | IrInstruction *sentinel, IrInstruction *align_value, bool is_allow_zero) |
| 2902 | static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2903 | IrInstSrc *child_type, bool is_const, bool is_volatile, |
| 2904 | IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero) |
| 2323 | 2905 | { |
| 2324 | | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node); |
| 2906 | IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node); |
| 2325 | 2907 | instruction->is_const = is_const; |
| 2326 | 2908 | instruction->is_volatile = is_volatile; |
| 2327 | 2909 | instruction->child_type = child_type; |
| ... | ... | @@ -2336,11 +2918,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode |
| 2336 | 2918 | return &instruction->base; |
| 2337 | 2919 | } |
| 2338 | 2920 | |
| 2339 | | static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2340 | | IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types, |
| 2921 | static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2922 | IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types, |
| 2341 | 2923 | ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global) |
| 2342 | 2924 | { |
| 2343 | | IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node); |
| 2925 | IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node); |
| 2344 | 2926 | instruction->asm_template = asm_template; |
| 2345 | 2927 | instruction->input_list = input_list; |
| 2346 | 2928 | instruction->output_types = output_types; |
| ... | ... | @@ -2351,24 +2933,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so |
| 2351 | 2933 | |
| 2352 | 2934 | assert(source_node->type == NodeTypeAsmExpr); |
| 2353 | 2935 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 2354 | | IrInstruction *output_type = output_types[i]; |
| 2936 | IrInstSrc *output_type = output_types[i]; |
| 2355 | 2937 | if (output_type) ir_ref_instruction(output_type, irb->current_basic_block); |
| 2356 | 2938 | } |
| 2357 | 2939 | |
| 2358 | 2940 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 2359 | | IrInstruction *input_value = input_list[i]; |
| 2941 | IrInstSrc *input_value = input_list[i]; |
| 2360 | 2942 | ir_ref_instruction(input_value, irb->current_basic_block); |
| 2361 | 2943 | } |
| 2362 | 2944 | |
| 2363 | 2945 | return &instruction->base; |
| 2364 | 2946 | } |
| 2365 | 2947 | |
| 2366 | | static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2948 | static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2367 | 2949 | Buf *asm_template, AsmToken *token_list, size_t token_list_len, |
| 2368 | | IrInstruction **input_list, IrInstruction **output_types, ZigVar **output_vars, size_t return_count, |
| 2369 | | bool has_side_effects) |
| 2950 | IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count, |
| 2951 | bool has_side_effects, ZigType *return_type) |
| 2370 | 2952 | { |
| 2371 | | IrInstructionAsmGen *instruction = ir_build_instruction<IrInstructionAsmGen>(&ira->new_irb, scope, source_node); |
| 2953 | IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2954 | instruction->base.value->type = return_type; |
| 2372 | 2955 | instruction->asm_template = asm_template; |
| 2373 | 2956 | instruction->token_list = token_list; |
| 2374 | 2957 | instruction->token_list_len = token_list_len; |
| ... | ... | @@ -2378,22 +2961,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so |
| 2378 | 2961 | instruction->return_count = return_count; |
| 2379 | 2962 | instruction->has_side_effects = has_side_effects; |
| 2380 | 2963 | |
| 2381 | | assert(source_node->type == NodeTypeAsmExpr); |
| 2382 | | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 2383 | | IrInstruction *output_type = output_types[i]; |
| 2384 | | if (output_type) ir_ref_instruction(output_type, ira->new_irb.current_basic_block); |
| 2964 | assert(source_instr->source_node->type == NodeTypeAsmExpr); |
| 2965 | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) { |
| 2966 | IrInstGen *output_type = output_types[i]; |
| 2967 | if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block); |
| 2385 | 2968 | } |
| 2386 | 2969 | |
| 2387 | | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 2388 | | IrInstruction *input_value = input_list[i]; |
| 2389 | | ir_ref_instruction(input_value, ira->new_irb.current_basic_block); |
| 2970 | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) { |
| 2971 | IrInstGen *input_value = input_list[i]; |
| 2972 | ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block); |
| 2390 | 2973 | } |
| 2391 | 2974 | |
| 2392 | 2975 | return &instruction->base; |
| 2393 | 2976 | } |
| 2394 | 2977 | |
| 2395 | | static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value, bool bit_size) { |
| 2396 | | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node); |
| 2978 | static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value, |
| 2979 | bool bit_size) |
| 2980 | { |
| 2981 | IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node); |
| 2397 | 2982 | instruction->type_value = type_value; |
| 2398 | 2983 | instruction->bit_size = bit_size; |
| 2399 | 2984 | |
| ... | ... | @@ -2402,8 +2987,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so |
| 2402 | 2987 | return &instruction->base; |
| 2403 | 2988 | } |
| 2404 | 2989 | |
| 2405 | | static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 2406 | | IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node); |
| 2990 | static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2991 | IrInstSrc *value) |
| 2992 | { |
| 2993 | IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node); |
| 2407 | 2994 | instruction->value = value; |
| 2408 | 2995 | |
| 2409 | 2996 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2411,10 +2998,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod |
| 2411 | 2998 | return &instruction->base; |
| 2412 | 2999 | } |
| 2413 | 3000 | |
| 2414 | | static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2415 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 3001 | static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 3002 | IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb, |
| 3003 | source_instr->scope, source_instr->source_node); |
| 3004 | inst->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3005 | inst->value = value; |
| 3006 | |
| 3007 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 3008 | |
| 3009 | return &inst->base; |
| 3010 | } |
| 3011 | |
| 3012 | static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3013 | IrInstSrc *base_ptr, bool safety_check_on, bool initializing) |
| 2416 | 3014 | { |
| 2417 | | IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node); |
| 3015 | IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node); |
| 2418 | 3016 | instruction->base_ptr = base_ptr; |
| 2419 | 3017 | instruction->safety_check_on = safety_check_on; |
| 2420 | 3018 | instruction->initializing = initializing; |
| ... | ... | @@ -2424,113 +3022,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, |
| 2424 | 3022 | return &instruction->base; |
| 2425 | 3023 | } |
| 2426 | 3024 | |
| 2427 | | static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty, |
| 2428 | | IrInstruction *operand, IrInstruction *result_loc) |
| 3025 | static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3026 | IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type) |
| 2429 | 3027 | { |
| 2430 | | IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>( |
| 3028 | IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb, |
| 3029 | source_instr->scope, source_instr->source_node); |
| 3030 | inst->base.value->type = result_type; |
| 3031 | inst->base_ptr = base_ptr; |
| 3032 | inst->safety_check_on = safety_check_on; |
| 3033 | inst->initializing = initializing; |
| 3034 | |
| 3035 | ir_ref_inst_gen(base_ptr, ira->new_irb.current_basic_block); |
| 3036 | |
| 3037 | return &inst->base; |
| 3038 | } |
| 3039 | |
| 3040 | static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty, |
| 3041 | IrInstGen *operand, IrInstGen *result_loc) |
| 3042 | { |
| 3043 | IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>( |
| 2431 | 3044 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2432 | 3045 | instruction->base.value->type = result_ty; |
| 2433 | 3046 | instruction->operand = operand; |
| 2434 | 3047 | instruction->result_loc = result_loc; |
| 2435 | 3048 | |
| 2436 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 2437 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3049 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3050 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2438 | 3051 | |
| 2439 | 3052 | return &instruction->base; |
| 2440 | 3053 | } |
| 2441 | 3054 | |
| 2442 | | static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2443 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 3055 | static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction, |
| 3056 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 2444 | 3057 | { |
| 2445 | | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( |
| 3058 | IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>( |
| 2446 | 3059 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2447 | 3060 | instruction->base.value->type = result_type; |
| 2448 | 3061 | instruction->operand = operand; |
| 2449 | 3062 | instruction->result_loc = result_loc; |
| 2450 | 3063 | |
| 2451 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 2452 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3064 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3065 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2453 | 3066 | |
| 2454 | 3067 | return &instruction->base; |
| 2455 | 3068 | } |
| 2456 | 3069 | |
| 2457 | | static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2458 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 3070 | static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction, |
| 3071 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 2459 | 3072 | { |
| 2460 | | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( |
| 3073 | IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>( |
| 2461 | 3074 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2462 | 3075 | instruction->base.value->type = result_type; |
| 2463 | 3076 | instruction->operand = operand; |
| 2464 | 3077 | instruction->result_loc = result_loc; |
| 2465 | 3078 | |
| 2466 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 2467 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3079 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3080 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2468 | 3081 | |
| 2469 | 3082 | return &instruction->base; |
| 2470 | 3083 | } |
| 2471 | 3084 | |
| 2472 | | static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) { |
| 2473 | | IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node); |
| 3085 | static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3086 | IrInstSrc *op) |
| 3087 | { |
| 3088 | IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node); |
| 2474 | 3089 | instruction->type = type; |
| 2475 | 3090 | instruction->op = op; |
| 2476 | 3091 | |
| 2477 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3092 | ir_ref_instruction(type, irb->current_basic_block); |
| 2478 | 3093 | ir_ref_instruction(op, irb->current_basic_block); |
| 2479 | 3094 | |
| 2480 | 3095 | return &instruction->base; |
| 2481 | 3096 | } |
| 2482 | 3097 | |
| 2483 | | static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) { |
| 2484 | | IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node); |
| 3098 | static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 3099 | IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb, |
| 3100 | source_instr->scope, source_instr->source_node); |
| 3101 | instruction->base.value->type = result_type; |
| 3102 | instruction->op = op; |
| 3103 | |
| 3104 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3105 | |
| 3106 | return &instruction->base; |
| 3107 | } |
| 3108 | |
| 3109 | static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3110 | IrInstSrc *op) |
| 3111 | { |
| 3112 | IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node); |
| 2485 | 3113 | instruction->type = type; |
| 2486 | 3114 | instruction->op = op; |
| 2487 | 3115 | |
| 2488 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3116 | ir_ref_instruction(type, irb->current_basic_block); |
| 2489 | 3117 | ir_ref_instruction(op, irb->current_basic_block); |
| 2490 | 3118 | |
| 2491 | 3119 | return &instruction->base; |
| 2492 | 3120 | } |
| 2493 | 3121 | |
| 2494 | | static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) { |
| 2495 | | IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node); |
| 3122 | static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 3123 | IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb, |
| 3124 | source_instr->scope, source_instr->source_node); |
| 3125 | instruction->base.value->type = result_type; |
| 3126 | instruction->op = op; |
| 3127 | |
| 3128 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3129 | |
| 3130 | return &instruction->base; |
| 3131 | } |
| 3132 | |
| 3133 | static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3134 | IrInstSrc *op) |
| 3135 | { |
| 3136 | IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node); |
| 2496 | 3137 | instruction->type = type; |
| 2497 | 3138 | instruction->op = op; |
| 2498 | 3139 | |
| 2499 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3140 | ir_ref_instruction(type, irb->current_basic_block); |
| 2500 | 3141 | ir_ref_instruction(op, irb->current_basic_block); |
| 2501 | 3142 | |
| 2502 | 3143 | return &instruction->base; |
| 2503 | 3144 | } |
| 2504 | 3145 | |
| 2505 | | static IrInstruction *ir_build_bswap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) { |
| 2506 | | IrInstructionBswap *instruction = ir_build_instruction<IrInstructionBswap>(irb, scope, source_node); |
| 3146 | static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, |
| 3147 | IrInstGen *op) |
| 3148 | { |
| 3149 | IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb, |
| 3150 | source_instr->scope, source_instr->source_node); |
| 3151 | instruction->base.value->type = result_type; |
| 3152 | instruction->op = op; |
| 3153 | |
| 3154 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3155 | |
| 3156 | return &instruction->base; |
| 3157 | } |
| 3158 | |
| 3159 | static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3160 | IrInstSrc *op) |
| 3161 | { |
| 3162 | IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node); |
| 2507 | 3163 | instruction->type = type; |
| 2508 | 3164 | instruction->op = op; |
| 2509 | 3165 | |
| 2510 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3166 | ir_ref_instruction(type, irb->current_basic_block); |
| 2511 | 3167 | ir_ref_instruction(op, irb->current_basic_block); |
| 2512 | 3168 | |
| 2513 | 3169 | return &instruction->base; |
| 2514 | 3170 | } |
| 2515 | 3171 | |
| 2516 | | static IrInstruction *ir_build_bit_reverse(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) { |
| 2517 | | IrInstructionBitReverse *instruction = ir_build_instruction<IrInstructionBitReverse>(irb, scope, source_node); |
| 3172 | static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type, |
| 3173 | IrInstGen *op) |
| 3174 | { |
| 3175 | IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb, |
| 3176 | source_instr->scope, source_instr->source_node); |
| 3177 | instruction->base.value->type = op_type; |
| 3178 | instruction->op = op; |
| 3179 | |
| 3180 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3181 | |
| 3182 | return &instruction->base; |
| 3183 | } |
| 3184 | |
| 3185 | static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3186 | IrInstSrc *op) |
| 3187 | { |
| 3188 | IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node); |
| 2518 | 3189 | instruction->type = type; |
| 2519 | 3190 | instruction->op = op; |
| 2520 | 3191 | |
| 2521 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3192 | ir_ref_instruction(type, irb->current_basic_block); |
| 2522 | 3193 | ir_ref_instruction(op, irb->current_basic_block); |
| 2523 | 3194 | |
| 2524 | 3195 | return &instruction->base; |
| 2525 | 3196 | } |
| 2526 | 3197 | |
| 2527 | | static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value, |
| 2528 | | IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime, |
| 2529 | | IrInstruction *switch_prongs_void) |
| 3198 | static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type, |
| 3199 | IrInstGen *op) |
| 2530 | 3200 | { |
| 2531 | | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); |
| 2532 | | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 2533 | | instruction->base.value->special = ConstValSpecialStatic; |
| 3201 | IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb, |
| 3202 | source_instr->scope, source_instr->source_node); |
| 3203 | instruction->base.value->type = int_type; |
| 3204 | instruction->op = op; |
| 3205 | |
| 3206 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3207 | |
| 3208 | return &instruction->base; |
| 3209 | } |
| 3210 | |
| 3211 | static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3212 | IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases, |
| 3213 | IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void) |
| 3214 | { |
| 3215 | IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node); |
| 3216 | instruction->base.is_noreturn = true; |
| 2534 | 3217 | instruction->target_value = target_value; |
| 2535 | 3218 | instruction->else_block = else_block; |
| 2536 | 3219 | instruction->case_count = case_count; |
| ... | ... | @@ -2539,9 +3222,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2539 | 3222 | instruction->switch_prongs_void = switch_prongs_void; |
| 2540 | 3223 | |
| 2541 | 3224 | ir_ref_instruction(target_value, irb->current_basic_block); |
| 2542 | | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 3225 | ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 2543 | 3226 | ir_ref_bb(else_block); |
| 2544 | | if (switch_prongs_void) ir_ref_instruction(switch_prongs_void, irb->current_basic_block); |
| 3227 | ir_ref_instruction(switch_prongs_void, irb->current_basic_block); |
| 2545 | 3228 | |
| 2546 | 3229 | for (size_t i = 0; i < case_count; i += 1) { |
| 2547 | 3230 | ir_ref_instruction(cases[i].value, irb->current_basic_block); |
| ... | ... | @@ -2551,10 +3234,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2551 | 3234 | return instruction; |
| 2552 | 3235 | } |
| 2553 | 3236 | |
| 2554 | | static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2555 | | IrInstruction *target_value_ptr) |
| 3237 | static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3238 | IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases) |
| 2556 | 3239 | { |
| 2557 | | IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node); |
| 3240 | IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb, |
| 3241 | source_instr->scope, source_instr->source_node); |
| 3242 | instruction->target_value = target_value; |
| 3243 | instruction->else_block = else_block; |
| 3244 | instruction->case_count = case_count; |
| 3245 | instruction->cases = cases; |
| 3246 | |
| 3247 | ir_ref_inst_gen(target_value, ira->new_irb.current_basic_block); |
| 3248 | ir_ref_bb_gen(else_block); |
| 3249 | |
| 3250 | for (size_t i = 0; i < case_count; i += 1) { |
| 3251 | ir_ref_inst_gen(cases[i].value, ira->new_irb.current_basic_block); |
| 3252 | ir_ref_bb_gen(cases[i].block); |
| 3253 | } |
| 3254 | |
| 3255 | return instruction; |
| 3256 | } |
| 3257 | |
| 3258 | static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3259 | IrInstSrc *target_value_ptr) |
| 3260 | { |
| 3261 | IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node); |
| 2558 | 3262 | instruction->target_value_ptr = target_value_ptr; |
| 2559 | 3263 | |
| 2560 | 3264 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| ... | ... | @@ -2562,10 +3266,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo |
| 2562 | 3266 | return &instruction->base; |
| 2563 | 3267 | } |
| 2564 | 3268 | |
| 2565 | | static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2566 | | IrInstruction *target_value_ptr, IrInstruction **prongs_ptr, size_t prongs_len) |
| 3269 | static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3270 | IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len) |
| 2567 | 3271 | { |
| 2568 | | IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node); |
| 3272 | IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node); |
| 2569 | 3273 | instruction->target_value_ptr = target_value_ptr; |
| 2570 | 3274 | instruction->prongs_ptr = prongs_ptr; |
| 2571 | 3275 | instruction->prongs_len = prongs_len; |
| ... | ... | @@ -2579,10 +3283,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode |
| 2579 | 3283 | } |
| 2580 | 3284 | |
| 2581 | 3285 | // For this instruction the switch_br must be set later. |
| 2582 | | static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2583 | | IrInstruction *target_value_ptr) |
| 3286 | static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3287 | IrInstSrc *target_value_ptr) |
| 2584 | 3288 | { |
| 2585 | | IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node); |
| 3289 | IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node); |
| 2586 | 3290 | instruction->target_value_ptr = target_value_ptr; |
| 2587 | 3291 | |
| 2588 | 3292 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| ... | ... | @@ -2590,17 +3294,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop |
| 2590 | 3294 | return instruction; |
| 2591 | 3295 | } |
| 2592 | 3296 | |
| 2593 | | static IrInstruction *ir_build_union_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 2594 | | IrInstructionUnionTag *instruction = ir_build_instruction<IrInstructionUnionTag>(irb, scope, source_node); |
| 3297 | static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 3298 | ZigType *tag_type) |
| 3299 | { |
| 3300 | IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb, |
| 3301 | source_instr->scope, source_instr->source_node); |
| 2595 | 3302 | instruction->value = value; |
| 3303 | instruction->base.value->type = tag_type; |
| 2596 | 3304 | |
| 2597 | | ir_ref_instruction(value, irb->current_basic_block); |
| 3305 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2598 | 3306 | |
| 2599 | 3307 | return &instruction->base; |
| 2600 | 3308 | } |
| 2601 | 3309 | |
| 2602 | | static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 2603 | | IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node); |
| 3310 | static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3311 | IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node); |
| 2604 | 3312 | instruction->name = name; |
| 2605 | 3313 | |
| 2606 | 3314 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2608,10 +3316,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2608 | 3316 | return &instruction->base; |
| 2609 | 3317 | } |
| 2610 | 3318 | |
| 2611 | | static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, |
| 3319 | static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value, |
| 2612 | 3320 | bool is_const, bool is_volatile) |
| 2613 | 3321 | { |
| 2614 | | IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node); |
| 3322 | IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node); |
| 2615 | 3323 | instruction->value = value; |
| 2616 | 3324 | instruction->is_const = is_const; |
| 2617 | 3325 | instruction->is_volatile = is_volatile; |
| ... | ... | @@ -2621,23 +3329,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source |
| 2621 | 3329 | return &instruction->base; |
| 2622 | 3330 | } |
| 2623 | 3331 | |
| 2624 | | static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type, |
| 2625 | | IrInstruction *operand, IrInstruction *result_loc) |
| 3332 | static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3333 | IrInstGen *operand, IrInstGen *result_loc) |
| 2626 | 3334 | { |
| 2627 | | IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, |
| 3335 | IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb, |
| 2628 | 3336 | source_instruction->scope, source_instruction->source_node); |
| 2629 | 3337 | instruction->base.value->type = result_type; |
| 2630 | 3338 | instruction->operand = operand; |
| 2631 | 3339 | instruction->result_loc = result_loc; |
| 2632 | 3340 | |
| 2633 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 2634 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3341 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3342 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2635 | 3343 | |
| 2636 | 3344 | return &instruction->base; |
| 2637 | 3345 | } |
| 2638 | 3346 | |
| 2639 | | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 2640 | | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); |
| 3347 | static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 3348 | IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node); |
| 2641 | 3349 | instruction->msg = msg; |
| 2642 | 3350 | |
| 2643 | 3351 | ir_ref_instruction(msg, irb->current_basic_block); |
| ... | ... | @@ -2645,10 +3353,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode |
| 2645 | 3353 | return &instruction->base; |
| 2646 | 3354 | } |
| 2647 | 3355 | |
| 2648 | | static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2649 | | size_t msg_count, IrInstruction **msg_list) |
| 3356 | static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3357 | size_t msg_count, IrInstSrc **msg_list) |
| 2650 | 3358 | { |
| 2651 | | IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node); |
| 3359 | IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node); |
| 2652 | 3360 | instruction->msg_count = msg_count; |
| 2653 | 3361 | instruction->msg_list = msg_list; |
| 2654 | 3362 | |
| ... | ... | @@ -2659,8 +3367,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode |
| 2659 | 3367 | return &instruction->base; |
| 2660 | 3368 | } |
| 2661 | 3369 | |
| 2662 | | static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 2663 | | IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node); |
| 3370 | static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 3371 | IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node); |
| 2664 | 3372 | instruction->value = value; |
| 2665 | 3373 | |
| 2666 | 3374 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2668,13 +3376,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s |
| 2668 | 3376 | return &instruction->base; |
| 2669 | 3377 | } |
| 2670 | 3378 | |
| 2671 | | static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2672 | | IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node); |
| 3379 | static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 3380 | ZigType *str_type) |
| 3381 | { |
| 3382 | IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb, |
| 3383 | source_instr->scope, source_instr->source_node); |
| 3384 | instruction->base.value->type = str_type; |
| 3385 | instruction->value = value; |
| 3386 | |
| 3387 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 3388 | |
| 2673 | 3389 | return &instruction->base; |
| 2674 | 3390 | } |
| 2675 | 3391 | |
| 2676 | | static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 2677 | | IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node); |
| 3392 | static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3393 | IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node); |
| 3394 | return &instruction->base; |
| 3395 | } |
| 3396 | |
| 3397 | static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3398 | IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node); |
| 2678 | 3399 | instruction->name = name; |
| 2679 | 3400 | |
| 2680 | 3401 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2682,8 +3403,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode * |
| 2682 | 3403 | return &instruction->base; |
| 2683 | 3404 | } |
| 2684 | 3405 | |
| 2685 | | static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name, IrInstruction *value) { |
| 2686 | | IrInstructionCDefine *instruction = ir_build_instruction<IrInstructionCDefine>(irb, scope, source_node); |
| 3406 | static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) { |
| 3407 | IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node); |
| 2687 | 3408 | instruction->name = name; |
| 2688 | 3409 | instruction->value = value; |
| 2689 | 3410 | |
| ... | ... | @@ -2693,8 +3414,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s |
| 2693 | 3414 | return &instruction->base; |
| 2694 | 3415 | } |
| 2695 | 3416 | |
| 2696 | | static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 2697 | | IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node); |
| 3417 | static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3418 | IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node); |
| 2698 | 3419 | instruction->name = name; |
| 2699 | 3420 | |
| 2700 | 3421 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2702,8 +3423,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so |
| 2702 | 3423 | return &instruction->base; |
| 2703 | 3424 | } |
| 2704 | 3425 | |
| 2705 | | static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 2706 | | IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node); |
| 3426 | static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3427 | IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node); |
| 2707 | 3428 | instruction->name = name; |
| 2708 | 3429 | |
| 2709 | 3430 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2711,11 +3432,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode |
| 2711 | 3432 | return &instruction->base; |
| 2712 | 3433 | } |
| 2713 | 3434 | |
| 2714 | | static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2715 | | IrInstruction *type_value, IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, |
| 2716 | | IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, ResultLoc *result_loc) |
| 3435 | static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3436 | IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value, |
| 3437 | IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc) |
| 2717 | 3438 | { |
| 2718 | | IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node); |
| 3439 | IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node); |
| 2719 | 3440 | instruction->type_value = type_value; |
| 2720 | 3441 | instruction->ptr = ptr; |
| 2721 | 3442 | instruction->cmp_value = cmp_value; |
| ... | ... | @@ -2735,11 +3456,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode |
| 2735 | 3456 | return &instruction->base; |
| 2736 | 3457 | } |
| 2737 | 3458 | |
| 2738 | | static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type, |
| 2739 | | IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, |
| 2740 | | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstruction *result_loc) |
| 3459 | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3460 | IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value, |
| 3461 | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc) |
| 2741 | 3462 | { |
| 2742 | | IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb, |
| 3463 | IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb, |
| 2743 | 3464 | source_instruction->scope, source_instruction->source_node); |
| 2744 | 3465 | instruction->base.value->type = result_type; |
| 2745 | 3466 | instruction->ptr = ptr; |
| ... | ... | @@ -2750,26 +3471,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source |
| 2750 | 3471 | instruction->is_weak = is_weak; |
| 2751 | 3472 | instruction->result_loc = result_loc; |
| 2752 | 3473 | |
| 2753 | | ir_ref_instruction(ptr, ira->new_irb.current_basic_block); |
| 2754 | | ir_ref_instruction(cmp_value, ira->new_irb.current_basic_block); |
| 2755 | | ir_ref_instruction(new_value, ira->new_irb.current_basic_block); |
| 2756 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3474 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3475 | ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block); |
| 3476 | ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block); |
| 3477 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2757 | 3478 | |
| 2758 | 3479 | return &instruction->base; |
| 2759 | 3480 | } |
| 2760 | 3481 | |
| 2761 | | static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *order_value, AtomicOrder order) { |
| 2762 | | IrInstructionFence *instruction = ir_build_instruction<IrInstructionFence>(irb, scope, source_node); |
| 2763 | | instruction->order_value = order_value; |
| 3482 | static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) { |
| 3483 | IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node); |
| 2764 | 3484 | instruction->order = order; |
| 2765 | 3485 | |
| 2766 | | ir_ref_instruction(order_value, irb->current_basic_block); |
| 3486 | ir_ref_instruction(order, irb->current_basic_block); |
| 3487 | |
| 3488 | return &instruction->base; |
| 3489 | } |
| 3490 | |
| 3491 | static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) { |
| 3492 | IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb, |
| 3493 | source_instr->scope, source_instr->source_node); |
| 3494 | instruction->order = order; |
| 2767 | 3495 | |
| 2768 | 3496 | return &instruction->base; |
| 2769 | 3497 | } |
| 2770 | 3498 | |
| 2771 | | static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2772 | | IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node); |
| 3499 | static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3500 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3501 | { |
| 3502 | IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node); |
| 2773 | 3503 | instruction->dest_type = dest_type; |
| 2774 | 3504 | instruction->target = target; |
| 2775 | 3505 | |
| ... | ... | @@ -2779,8 +3509,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s |
| 2779 | 3509 | return &instruction->base; |
| 2780 | 3510 | } |
| 2781 | 3511 | |
| 2782 | | static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2783 | | IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node); |
| 3512 | static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type, |
| 3513 | IrInstGen *target) |
| 3514 | { |
| 3515 | IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb, |
| 3516 | source_instr->scope, source_instr->source_node); |
| 3517 | instruction->base.value->type = dest_type; |
| 3518 | instruction->target = target; |
| 3519 | |
| 3520 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3521 | |
| 3522 | return &instruction->base; |
| 3523 | } |
| 3524 | |
| 3525 | static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 3526 | IrInstSrc *target) |
| 3527 | { |
| 3528 | IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node); |
| 2784 | 3529 | instruction->dest_type = dest_type; |
| 2785 | 3530 | instruction->target = target; |
| 2786 | 3531 | |
| ... | ... | @@ -2790,8 +3535,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s |
| 2790 | 3535 | return &instruction->base; |
| 2791 | 3536 | } |
| 2792 | 3537 | |
| 2793 | | static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2794 | | IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node); |
| 3538 | static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 3539 | IrInstSrc *target) |
| 3540 | { |
| 3541 | IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node); |
| 2795 | 3542 | instruction->dest_type = dest_type; |
| 2796 | 3543 | instruction->target = target; |
| 2797 | 3544 | |
| ... | ... | @@ -2801,8 +3548,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode |
| 2801 | 3548 | return &instruction->base; |
| 2802 | 3549 | } |
| 2803 | 3550 | |
| 2804 | | static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2805 | | IrInstructionErrSetCast *instruction = ir_build_instruction<IrInstructionErrSetCast>(irb, scope, source_node); |
| 3551 | static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3552 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3553 | { |
| 3554 | IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node); |
| 2806 | 3555 | instruction->dest_type = dest_type; |
| 2807 | 3556 | instruction->target = target; |
| 2808 | 3557 | |
| ... | ... | @@ -2812,10 +3561,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod |
| 2812 | 3561 | return &instruction->base; |
| 2813 | 3562 | } |
| 2814 | 3563 | |
| 2815 | | static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target, |
| 3564 | static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target, |
| 2816 | 3565 | ResultLoc *result_loc) |
| 2817 | 3566 | { |
| 2818 | | IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node); |
| 3567 | IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node); |
| 2819 | 3568 | instruction->target = target; |
| 2820 | 3569 | instruction->result_loc = result_loc; |
| 2821 | 3570 | |
| ... | ... | @@ -2824,10 +3573,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s |
| 2824 | 3573 | return &instruction->base; |
| 2825 | 3574 | } |
| 2826 | 3575 | |
| 2827 | | static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2828 | | IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc) |
| 3576 | static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3577 | IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc) |
| 2829 | 3578 | { |
| 2830 | | IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node); |
| 3579 | IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node); |
| 2831 | 3580 | instruction->dest_child_type = dest_child_type; |
| 2832 | 3581 | instruction->target = target; |
| 2833 | 3582 | instruction->result_loc = result_loc; |
| ... | ... | @@ -2838,8 +3587,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode |
| 2838 | 3587 | return &instruction->base; |
| 2839 | 3588 | } |
| 2840 | 3589 | |
| 2841 | | static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2842 | | IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node); |
| 3590 | static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3591 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3592 | { |
| 3593 | IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node); |
| 2843 | 3594 | instruction->dest_type = dest_type; |
| 2844 | 3595 | instruction->target = target; |
| 2845 | 3596 | |
| ... | ... | @@ -2849,8 +3600,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod |
| 2849 | 3600 | return &instruction->base; |
| 2850 | 3601 | } |
| 2851 | 3602 | |
| 2852 | | static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2853 | | IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node); |
| 3603 | static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3604 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3605 | { |
| 3606 | IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node); |
| 2854 | 3607 | instruction->dest_type = dest_type; |
| 2855 | 3608 | instruction->target = target; |
| 2856 | 3609 | |
| ... | ... | @@ -2860,8 +3613,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod |
| 2860 | 3613 | return &instruction->base; |
| 2861 | 3614 | } |
| 2862 | 3615 | |
| 2863 | | static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) { |
| 2864 | | IrInstructionBoolToInt *instruction = ir_build_instruction<IrInstructionBoolToInt>(irb, scope, source_node); |
| 3616 | static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 3617 | IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node); |
| 2865 | 3618 | instruction->target = target; |
| 2866 | 3619 | |
| 2867 | 3620 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -2869,8 +3622,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 2869 | 3622 | return &instruction->base; |
| 2870 | 3623 | } |
| 2871 | 3624 | |
| 2872 | | static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) { |
| 2873 | | IrInstructionIntType *instruction = ir_build_instruction<IrInstructionIntType>(irb, scope, source_node); |
| 3625 | static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed, |
| 3626 | IrInstSrc *bit_count) |
| 3627 | { |
| 3628 | IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node); |
| 2874 | 3629 | instruction->is_signed = is_signed; |
| 2875 | 3630 | instruction->bit_count = bit_count; |
| 2876 | 3631 | |
| ... | ... | @@ -2880,10 +3635,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 2880 | 3635 | return &instruction->base; |
| 2881 | 3636 | } |
| 2882 | 3637 | |
| 2883 | | static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len, |
| 2884 | | IrInstruction *elem_type) |
| 3638 | static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len, |
| 3639 | IrInstSrc *elem_type) |
| 2885 | 3640 | { |
| 2886 | | IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node); |
| 3641 | IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node); |
| 2887 | 3642 | instruction->len = len; |
| 2888 | 3643 | instruction->elem_type = elem_type; |
| 2889 | 3644 | |
| ... | ... | @@ -2893,18 +3648,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode |
| 2893 | 3648 | return &instruction->base; |
| 2894 | 3649 | } |
| 2895 | 3650 | |
| 2896 | | static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2897 | | IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask) |
| 3651 | static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3652 | IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask) |
| 2898 | 3653 | { |
| 2899 | | IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node); |
| 3654 | IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node); |
| 2900 | 3655 | instruction->scalar_type = scalar_type; |
| 2901 | 3656 | instruction->a = a; |
| 2902 | 3657 | instruction->b = b; |
| 2903 | 3658 | instruction->mask = mask; |
| 2904 | 3659 | |
| 2905 | | if (scalar_type != nullptr) { |
| 2906 | | ir_ref_instruction(scalar_type, irb->current_basic_block); |
| 2907 | | } |
| 3660 | if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block); |
| 2908 | 3661 | ir_ref_instruction(a, irb->current_basic_block); |
| 2909 | 3662 | ir_ref_instruction(b, irb->current_basic_block); |
| 2910 | 3663 | ir_ref_instruction(mask, irb->current_basic_block); |
| ... | ... | @@ -2912,10 +3665,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN |
| 2912 | 3665 | return &instruction->base; |
| 2913 | 3666 | } |
| 2914 | 3667 | |
| 2915 | | static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2916 | | IrInstruction *len, IrInstruction *scalar) |
| 3668 | static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 3669 | ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask) |
| 2917 | 3670 | { |
| 2918 | | IrInstructionSplatSrc *instruction = ir_build_instruction<IrInstructionSplatSrc>(irb, scope, source_node); |
| 3671 | IrInstGenShuffleVector *inst = ir_build_inst_gen<IrInstGenShuffleVector>(&ira->new_irb, scope, source_node); |
| 3672 | inst->base.value->type = result_type; |
| 3673 | inst->a = a; |
| 3674 | inst->b = b; |
| 3675 | inst->mask = mask; |
| 3676 | |
| 3677 | ir_ref_inst_gen(a, ira->new_irb.current_basic_block); |
| 3678 | ir_ref_inst_gen(b, ira->new_irb.current_basic_block); |
| 3679 | ir_ref_inst_gen(mask, ira->new_irb.current_basic_block); |
| 3680 | |
| 3681 | return &inst->base; |
| 3682 | } |
| 3683 | |
| 3684 | static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3685 | IrInstSrc *len, IrInstSrc *scalar) |
| 3686 | { |
| 3687 | IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node); |
| 2919 | 3688 | instruction->len = len; |
| 2920 | 3689 | instruction->scalar = scalar; |
| 2921 | 3690 | |
| ... | ... | @@ -2925,8 +3694,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode * |
| 2925 | 3694 | return &instruction->base; |
| 2926 | 3695 | } |
| 2927 | 3696 | |
| 2928 | | static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 2929 | | IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node); |
| 3697 | static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3698 | IrInstGen *scalar) |
| 3699 | { |
| 3700 | IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>( |
| 3701 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3702 | instruction->base.value->type = result_type; |
| 3703 | instruction->scalar = scalar; |
| 3704 | |
| 3705 | ir_ref_inst_gen(scalar, ira->new_irb.current_basic_block); |
| 3706 | |
| 3707 | return &instruction->base; |
| 3708 | } |
| 3709 | |
| 3710 | static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 3711 | IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node); |
| 2930 | 3712 | instruction->value = value; |
| 2931 | 3713 | |
| 2932 | 3714 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2934,10 +3716,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s |
| 2934 | 3716 | return &instruction->base; |
| 2935 | 3717 | } |
| 2936 | 3718 | |
| 2937 | | static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2938 | | IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count) |
| 3719 | static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 3720 | IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb, |
| 3721 | source_instr->scope, source_instr->source_node); |
| 3722 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3723 | instruction->value = value; |
| 3724 | |
| 3725 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 3726 | |
| 3727 | return &instruction->base; |
| 3728 | } |
| 3729 | |
| 3730 | static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3731 | IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count) |
| 2939 | 3732 | { |
| 2940 | | IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node); |
| 3733 | IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node); |
| 2941 | 3734 | instruction->dest_ptr = dest_ptr; |
| 2942 | 3735 | instruction->byte = byte; |
| 2943 | 3736 | instruction->count = count; |
| ... | ... | @@ -2949,10 +3742,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2949 | 3742 | return &instruction->base; |
| 2950 | 3743 | } |
| 2951 | 3744 | |
| 2952 | | static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2953 | | IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count) |
| 3745 | static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3746 | IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count) |
| 2954 | 3747 | { |
| 2955 | | IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node); |
| 3748 | IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb, |
| 3749 | source_instr->scope, source_instr->source_node); |
| 3750 | instruction->dest_ptr = dest_ptr; |
| 3751 | instruction->byte = byte; |
| 3752 | instruction->count = count; |
| 3753 | |
| 3754 | ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block); |
| 3755 | ir_ref_inst_gen(byte, ira->new_irb.current_basic_block); |
| 3756 | ir_ref_inst_gen(count, ira->new_irb.current_basic_block); |
| 3757 | |
| 3758 | return &instruction->base; |
| 3759 | } |
| 3760 | |
| 3761 | static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3762 | IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count) |
| 3763 | { |
| 3764 | IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node); |
| 2956 | 3765 | instruction->dest_ptr = dest_ptr; |
| 2957 | 3766 | instruction->src_ptr = src_ptr; |
| 2958 | 3767 | instruction->count = count; |
| ... | ... | @@ -2964,11 +3773,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2964 | 3773 | return &instruction->base; |
| 2965 | 3774 | } |
| 2966 | 3775 | |
| 2967 | | static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2968 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel, |
| 3776 | static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3777 | IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count) |
| 3778 | { |
| 3779 | IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb, |
| 3780 | source_instr->scope, source_instr->source_node); |
| 3781 | instruction->dest_ptr = dest_ptr; |
| 3782 | instruction->src_ptr = src_ptr; |
| 3783 | instruction->count = count; |
| 3784 | |
| 3785 | ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block); |
| 3786 | ir_ref_inst_gen(src_ptr, ira->new_irb.current_basic_block); |
| 3787 | ir_ref_inst_gen(count, ira->new_irb.current_basic_block); |
| 3788 | |
| 3789 | return &instruction->base; |
| 3790 | } |
| 3791 | |
| 3792 | static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3793 | IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel, |
| 2969 | 3794 | bool safety_check_on, ResultLoc *result_loc) |
| 2970 | 3795 | { |
| 2971 | | IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node); |
| 3796 | IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node); |
| 2972 | 3797 | instruction->ptr = ptr; |
| 2973 | 3798 | instruction->start = start; |
| 2974 | 3799 | instruction->end = end; |
| ... | ... | @@ -2984,23 +3809,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode * |
| 2984 | 3809 | return &instruction->base; |
| 2985 | 3810 | } |
| 2986 | 3811 | |
| 2987 | | static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type, |
| 2988 | | IrInstruction *scalar) |
| 2989 | | { |
| 2990 | | IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>( |
| 2991 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2992 | | instruction->base.value->type = result_type; |
| 2993 | | instruction->scalar = scalar; |
| 2994 | | |
| 2995 | | ir_ref_instruction(scalar, ira->new_irb.current_basic_block); |
| 2996 | | |
| 2997 | | return &instruction->base; |
| 2998 | | } |
| 2999 | | |
| 3000 | | static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *slice_type, |
| 3001 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on, IrInstruction *result_loc) |
| 3812 | static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type, |
| 3813 | IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc) |
| 3002 | 3814 | { |
| 3003 | | IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>( |
| 3815 | IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>( |
| 3004 | 3816 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3005 | 3817 | instruction->base.value->type = slice_type; |
| 3006 | 3818 | instruction->ptr = ptr; |
| ... | ... | @@ -3009,16 +3821,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i |
| 3009 | 3821 | instruction->safety_check_on = safety_check_on; |
| 3010 | 3822 | instruction->result_loc = result_loc; |
| 3011 | 3823 | |
| 3012 | | ir_ref_instruction(ptr, ira->new_irb.current_basic_block); |
| 3013 | | ir_ref_instruction(start, ira->new_irb.current_basic_block); |
| 3014 | | if (end) ir_ref_instruction(end, ira->new_irb.current_basic_block); |
| 3015 | | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 3824 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3825 | ir_ref_inst_gen(start, ira->new_irb.current_basic_block); |
| 3826 | if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block); |
| 3827 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3016 | 3828 | |
| 3017 | 3829 | return &instruction->base; |
| 3018 | 3830 | } |
| 3019 | 3831 | |
| 3020 | | static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) { |
| 3021 | | IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node); |
| 3832 | static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) { |
| 3833 | IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node); |
| 3022 | 3834 | instruction->container = container; |
| 3023 | 3835 | |
| 3024 | 3836 | ir_ref_instruction(container, irb->current_basic_block); |
| ... | ... | @@ -3026,10 +3838,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod |
| 3026 | 3838 | return &instruction->base; |
| 3027 | 3839 | } |
| 3028 | 3840 | |
| 3029 | | static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3030 | | IrInstruction *container_type, IrInstruction *member_index) |
| 3841 | static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3842 | IrInstSrc *container_type, IrInstSrc *member_index) |
| 3031 | 3843 | { |
| 3032 | | IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node); |
| 3844 | IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node); |
| 3033 | 3845 | instruction->container_type = container_type; |
| 3034 | 3846 | instruction->member_index = member_index; |
| 3035 | 3847 | |
| ... | ... | @@ -3039,10 +3851,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode |
| 3039 | 3851 | return &instruction->base; |
| 3040 | 3852 | } |
| 3041 | 3853 | |
| 3042 | | static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3043 | | IrInstruction *container_type, IrInstruction *member_index) |
| 3854 | static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3855 | IrInstSrc *container_type, IrInstSrc *member_index) |
| 3044 | 3856 | { |
| 3045 | | IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node); |
| 3857 | IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node); |
| 3046 | 3858 | instruction->container_type = container_type; |
| 3047 | 3859 | instruction->member_index = member_index; |
| 3048 | 3860 | |
| ... | ... | @@ -3052,65 +3864,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode |
| 3052 | 3864 | return &instruction->base; |
| 3053 | 3865 | } |
| 3054 | 3866 | |
| 3055 | | static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3056 | | IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node); |
| 3867 | static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3868 | IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node); |
| 3057 | 3869 | return &instruction->base; |
| 3058 | 3870 | } |
| 3059 | 3871 | |
| 3060 | | static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3061 | | IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node); |
| 3872 | static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3873 | IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb, |
| 3874 | source_instr->scope, source_instr->source_node); |
| 3062 | 3875 | return &instruction->base; |
| 3063 | 3876 | } |
| 3064 | 3877 | |
| 3065 | | static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3066 | | IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node); |
| 3878 | static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3879 | IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node); |
| 3067 | 3880 | return &instruction->base; |
| 3068 | 3881 | } |
| 3069 | 3882 | |
| 3070 | | static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3071 | | IrInstructionFrameHandle *instruction = ir_build_instruction<IrInstructionFrameHandle>(irb, scope, source_node); |
| 3072 | | return &instruction->base; |
| 3883 | static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3884 | IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3885 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3886 | return &inst->base; |
| 3887 | } |
| 3888 | |
| 3889 | static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3890 | IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node); |
| 3891 | return &inst->base; |
| 3892 | } |
| 3893 | |
| 3894 | static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3895 | IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3896 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3897 | return &inst->base; |
| 3898 | } |
| 3899 | |
| 3900 | static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3901 | IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node); |
| 3902 | return &inst->base; |
| 3903 | } |
| 3904 | |
| 3905 | static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) { |
| 3906 | IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3907 | inst->base.value->type = ty; |
| 3908 | return &inst->base; |
| 3073 | 3909 | } |
| 3074 | 3910 | |
| 3075 | | static IrInstruction *ir_build_frame_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) { |
| 3076 | | IrInstructionFrameType *instruction = ir_build_instruction<IrInstructionFrameType>(irb, scope, source_node); |
| 3077 | | instruction->fn = fn; |
| 3911 | static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 3912 | IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node); |
| 3913 | inst->fn = fn; |
| 3078 | 3914 | |
| 3079 | 3915 | ir_ref_instruction(fn, irb->current_basic_block); |
| 3080 | 3916 | |
| 3081 | | return &instruction->base; |
| 3917 | return &inst->base; |
| 3082 | 3918 | } |
| 3083 | 3919 | |
| 3084 | | static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) { |
| 3085 | | IrInstructionFrameSizeSrc *instruction = ir_build_instruction<IrInstructionFrameSizeSrc>(irb, scope, source_node); |
| 3086 | | instruction->fn = fn; |
| 3920 | static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 3921 | IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node); |
| 3922 | inst->fn = fn; |
| 3087 | 3923 | |
| 3088 | 3924 | ir_ref_instruction(fn, irb->current_basic_block); |
| 3089 | 3925 | |
| 3090 | | return &instruction->base; |
| 3926 | return &inst->base; |
| 3091 | 3927 | } |
| 3092 | 3928 | |
| 3093 | | static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) |
| 3929 | static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn) |
| 3094 | 3930 | { |
| 3095 | | IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node); |
| 3096 | | instruction->fn = fn; |
| 3931 | IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3932 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3933 | inst->fn = fn; |
| 3097 | 3934 | |
| 3098 | | ir_ref_instruction(fn, irb->current_basic_block); |
| 3935 | ir_ref_inst_gen(fn, ira->new_irb.current_basic_block); |
| 3099 | 3936 | |
| 3100 | | return &instruction->base; |
| 3937 | return &inst->base; |
| 3101 | 3938 | } |
| 3102 | 3939 | |
| 3103 | | static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3104 | | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, |
| 3105 | | IrInstruction *result_ptr, ZigType *result_ptr_type) |
| 3940 | static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3941 | IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr) |
| 3106 | 3942 | { |
| 3107 | | IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node); |
| 3943 | IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node); |
| 3108 | 3944 | instruction->op = op; |
| 3109 | 3945 | instruction->type_value = type_value; |
| 3110 | 3946 | instruction->op1 = op1; |
| 3111 | 3947 | instruction->op2 = op2; |
| 3112 | 3948 | instruction->result_ptr = result_ptr; |
| 3113 | | instruction->result_ptr_type = result_ptr_type; |
| 3114 | 3949 | |
| 3115 | 3950 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 3116 | 3951 | ir_ref_instruction(op1, irb->current_basic_block); |
| ... | ... | @@ -3120,49 +3955,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 3120 | 3955 | return &instruction->base; |
| 3121 | 3956 | } |
| 3122 | 3957 | |
| 3958 | static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3959 | IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr, |
| 3960 | ZigType *result_ptr_type) |
| 3961 | { |
| 3962 | IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb, |
| 3963 | source_instr->scope, source_instr->source_node); |
| 3964 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3965 | instruction->op = op; |
| 3966 | instruction->op1 = op1; |
| 3967 | instruction->op2 = op2; |
| 3968 | instruction->result_ptr = result_ptr; |
| 3969 | instruction->result_ptr_type = result_ptr_type; |
| 3123 | 3970 | |
| 3124 | | //TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign, |
| 3125 | | // lround, llround, lrint, llrint |
| 3126 | | // So far this is only non-complicated type functions. |
| 3127 | | const char *float_op_to_name(BuiltinFnId op) { |
| 3128 | | switch (op) { |
| 3129 | | case BuiltinFnIdSqrt: |
| 3130 | | return "sqrt"; |
| 3131 | | case BuiltinFnIdSin: |
| 3132 | | return "sin"; |
| 3133 | | case BuiltinFnIdCos: |
| 3134 | | return "cos"; |
| 3135 | | case BuiltinFnIdExp: |
| 3136 | | return "exp"; |
| 3137 | | case BuiltinFnIdExp2: |
| 3138 | | return "exp2"; |
| 3139 | | case BuiltinFnIdLog: |
| 3140 | | return "log"; |
| 3141 | | case BuiltinFnIdLog10: |
| 3142 | | return "log10"; |
| 3143 | | case BuiltinFnIdLog2: |
| 3144 | | return "log2"; |
| 3145 | | case BuiltinFnIdFabs: |
| 3146 | | return "fabs"; |
| 3147 | | case BuiltinFnIdFloor: |
| 3148 | | return "floor"; |
| 3149 | | case BuiltinFnIdCeil: |
| 3150 | | return "ceil"; |
| 3151 | | case BuiltinFnIdTrunc: |
| 3152 | | return "trunc"; |
| 3153 | | case BuiltinFnIdNearbyInt: |
| 3154 | | return "nearbyint"; |
| 3155 | | case BuiltinFnIdRound: |
| 3156 | | return "round"; |
| 3157 | | default: |
| 3158 | | zig_unreachable(); |
| 3159 | | } |
| 3971 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 3972 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 3973 | ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block); |
| 3974 | |
| 3975 | return &instruction->base; |
| 3160 | 3976 | } |
| 3161 | 3977 | |
| 3162 | | static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *operand, |
| 3978 | static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand, |
| 3163 | 3979 | BuiltinFnId fn_id) |
| 3164 | 3980 | { |
| 3165 | | IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node); |
| 3981 | IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node); |
| 3166 | 3982 | instruction->operand = operand; |
| 3167 | 3983 | instruction->fn_id = fn_id; |
| 3168 | 3984 | |
| ... | ... | @@ -3171,9 +3987,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s |
| 3171 | 3987 | return &instruction->base; |
| 3172 | 3988 | } |
| 3173 | 3989 | |
| 3174 | | static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3175 | | IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, IrInstruction *op3) { |
| 3176 | | IrInstructionMulAdd *instruction = ir_build_instruction<IrInstructionMulAdd>(irb, scope, source_node); |
| 3990 | static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 3991 | BuiltinFnId fn_id, ZigType *operand_type) |
| 3992 | { |
| 3993 | IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb, |
| 3994 | source_instr->scope, source_instr->source_node); |
| 3995 | instruction->base.value->type = operand_type; |
| 3996 | instruction->operand = operand; |
| 3997 | instruction->fn_id = fn_id; |
| 3998 | |
| 3999 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 4000 | |
| 4001 | return &instruction->base; |
| 4002 | } |
| 4003 | |
| 4004 | static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4005 | IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3) |
| 4006 | { |
| 4007 | IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node); |
| 3177 | 4008 | instruction->type_value = type_value; |
| 3178 | 4009 | instruction->op1 = op1; |
| 3179 | 4010 | instruction->op2 = op2; |
| ... | ... | @@ -3187,8 +4018,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so |
| 3187 | 4018 | return &instruction->base; |
| 3188 | 4019 | } |
| 3189 | 4020 | |
| 3190 | | static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) { |
| 3191 | | IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node); |
| 4021 | static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2, |
| 4022 | IrInstGen *op3, ZigType *expr_type) |
| 4023 | { |
| 4024 | IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb, |
| 4025 | source_instr->scope, source_instr->source_node); |
| 4026 | instruction->base.value->type = expr_type; |
| 4027 | instruction->op1 = op1; |
| 4028 | instruction->op2 = op2; |
| 4029 | instruction->op3 = op3; |
| 4030 | |
| 4031 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 4032 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 4033 | ir_ref_inst_gen(op3, ira->new_irb.current_basic_block); |
| 4034 | |
| 4035 | return &instruction->base; |
| 4036 | } |
| 4037 | |
| 4038 | static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4039 | IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node); |
| 3192 | 4040 | instruction->type_value = type_value; |
| 3193 | 4041 | |
| 3194 | 4042 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3196,10 +4044,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s |
| 3196 | 4044 | return &instruction->base; |
| 3197 | 4045 | } |
| 3198 | 4046 | |
| 3199 | | static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3200 | | IrInstruction *base_ptr, bool resolve_err_set, bool base_ptr_is_payload) |
| 4047 | static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4048 | IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload) |
| 3201 | 4049 | { |
| 3202 | | IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node); |
| 4050 | IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node); |
| 3203 | 4051 | instruction->base_ptr = base_ptr; |
| 3204 | 4052 | instruction->resolve_err_set = resolve_err_set; |
| 3205 | 4053 | instruction->base_ptr_is_payload = base_ptr_is_payload; |
| ... | ... | @@ -3209,48 +4057,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod |
| 3209 | 4057 | return &instruction->base; |
| 3210 | 4058 | } |
| 3211 | 4059 | |
| 3212 | | static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3213 | | IrInstruction *err_union) |
| 3214 | | { |
| 3215 | | IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>( |
| 4060 | static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) { |
| 4061 | IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>( |
| 3216 | 4062 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3217 | 4063 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3218 | 4064 | instruction->err_union = err_union; |
| 3219 | 4065 | |
| 3220 | | ir_ref_instruction(err_union, ira->new_irb.current_basic_block); |
| 4066 | ir_ref_inst_gen(err_union, ira->new_irb.current_basic_block); |
| 3221 | 4067 | |
| 3222 | 4068 | return &instruction->base; |
| 3223 | 4069 | } |
| 3224 | 4070 | |
| 3225 | | static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3226 | | IrInstruction *err_union_ptr) |
| 4071 | static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4072 | IrInstSrc *err_union_ptr) |
| 3227 | 4073 | { |
| 3228 | | IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node); |
| 3229 | | instruction->err_union_ptr = err_union_ptr; |
| 4074 | IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node); |
| 4075 | inst->err_union_ptr = err_union_ptr; |
| 3230 | 4076 | |
| 3231 | 4077 | ir_ref_instruction(err_union_ptr, irb->current_basic_block); |
| 3232 | 4078 | |
| 3233 | | return &instruction->base; |
| 4079 | return &inst->base; |
| 3234 | 4080 | } |
| 3235 | 4081 | |
| 3236 | | static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3237 | | IrInstruction *value, bool safety_check_on, bool initializing) |
| 4082 | static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4083 | IrInstGen *err_union_ptr, ZigType *result_type) |
| 3238 | 4084 | { |
| 3239 | | IrInstructionUnwrapErrPayload *instruction = ir_build_instruction<IrInstructionUnwrapErrPayload>(irb, scope, source_node); |
| 3240 | | instruction->value = value; |
| 3241 | | instruction->safety_check_on = safety_check_on; |
| 3242 | | instruction->initializing = initializing; |
| 4085 | IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node); |
| 4086 | inst->base.value->type = result_type; |
| 4087 | inst->err_union_ptr = err_union_ptr; |
| 4088 | |
| 4089 | ir_ref_inst_gen(err_union_ptr, ira->new_irb.current_basic_block); |
| 4090 | |
| 4091 | return &inst->base; |
| 4092 | } |
| 4093 | |
| 4094 | static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4095 | IrInstSrc *value, bool safety_check_on, bool initializing) |
| 4096 | { |
| 4097 | IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node); |
| 4098 | inst->value = value; |
| 4099 | inst->safety_check_on = safety_check_on; |
| 4100 | inst->initializing = initializing; |
| 3243 | 4101 | |
| 3244 | 4102 | ir_ref_instruction(value, irb->current_basic_block); |
| 3245 | 4103 | |
| 3246 | | return &instruction->base; |
| 4104 | return &inst->base; |
| 3247 | 4105 | } |
| 3248 | 4106 | |
| 3249 | | static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3250 | | IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value, |
| 3251 | | IrInstruction *return_type, bool is_var_args) |
| 4107 | static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4108 | IrInstGen *value, bool safety_check_on, bool initializing, ZigType *result_type) |
| 3252 | 4109 | { |
| 3253 | | IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node); |
| 4110 | IrInstGenUnwrapErrPayload *inst = ir_build_inst_gen<IrInstGenUnwrapErrPayload>(&ira->new_irb, scope, source_node); |
| 4111 | inst->base.value->type = result_type; |
| 4112 | inst->value = value; |
| 4113 | inst->safety_check_on = safety_check_on; |
| 4114 | inst->initializing = initializing; |
| 4115 | |
| 4116 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 4117 | |
| 4118 | return &inst->base; |
| 4119 | } |
| 4120 | |
| 4121 | static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4122 | IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value, |
| 4123 | IrInstSrc *return_type, bool is_var_args) |
| 4124 | { |
| 4125 | IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node); |
| 3254 | 4126 | instruction->param_types = param_types; |
| 3255 | 4127 | instruction->align_value = align_value; |
| 3256 | 4128 | instruction->callconv_value = callconv_value; |
| ... | ... | @@ -3270,8 +4142,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s |
| 3270 | 4142 | return &instruction->base; |
| 3271 | 4143 | } |
| 3272 | 4144 | |
| 3273 | | static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 3274 | | IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node); |
| 4145 | static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 4146 | IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node); |
| 3275 | 4147 | instruction->value = value; |
| 3276 | 4148 | |
| 3277 | 4149 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -3279,10 +4151,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo |
| 3279 | 4151 | return &instruction->base; |
| 3280 | 4152 | } |
| 3281 | 4153 | |
| 3282 | | static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3283 | | IrInstruction *dest_type, IrInstruction *ptr, bool safety_check_on) |
| 4154 | static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4155 | IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on) |
| 3284 | 4156 | { |
| 3285 | | IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>( |
| 4157 | IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>( |
| 3286 | 4158 | irb, scope, source_node); |
| 3287 | 4159 | instruction->dest_type = dest_type; |
| 3288 | 4160 | instruction->ptr = ptr; |
| ... | ... | @@ -3294,39 +4166,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod |
| 3294 | 4166 | return &instruction->base; |
| 3295 | 4167 | } |
| 3296 | 4168 | |
| 3297 | | static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3298 | | ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on) |
| 4169 | static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4170 | ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on) |
| 3299 | 4171 | { |
| 3300 | | IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>( |
| 4172 | IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>( |
| 3301 | 4173 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3302 | 4174 | instruction->base.value->type = ptr_type; |
| 3303 | 4175 | instruction->ptr = ptr; |
| 3304 | 4176 | instruction->safety_check_on = safety_check_on; |
| 3305 | 4177 | |
| 3306 | | ir_ref_instruction(ptr, ira->new_irb.current_basic_block); |
| 3307 | | |
| 3308 | | return &instruction->base; |
| 3309 | | } |
| 3310 | | |
| 3311 | | static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3312 | | IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc) |
| 3313 | | { |
| 3314 | | IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>( |
| 3315 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3316 | | instruction->base.value->type = ty; |
| 3317 | | instruction->ptr = ptr; |
| 3318 | | instruction->result_loc = result_loc; |
| 3319 | | |
| 3320 | | ir_ref_instruction(ptr, ira->new_irb.current_basic_block); |
| 3321 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 4178 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3322 | 4179 | |
| 3323 | 4180 | return &instruction->base; |
| 3324 | 4181 | } |
| 3325 | 4182 | |
| 3326 | | static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3327 | | IrInstruction *operand, ResultLocCast *result_loc_cast) |
| 4183 | static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4184 | IrInstSrc *operand, ResultLocCast *result_loc_cast) |
| 3328 | 4185 | { |
| 3329 | | IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node); |
| 4186 | IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node); |
| 3330 | 4187 | instruction->operand = operand; |
| 3331 | 4188 | instruction->result_loc_cast = result_loc_cast; |
| 3332 | 4189 | |
| ... | ... | @@ -3335,10 +4192,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo |
| 3335 | 4192 | return &instruction->base; |
| 3336 | 4193 | } |
| 3337 | 4194 | |
| 3338 | | static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3339 | | IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast) |
| 4195 | static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4196 | IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast) |
| 3340 | 4197 | { |
| 3341 | | IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node); |
| 4198 | IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node); |
| 3342 | 4199 | instruction->operand = operand; |
| 3343 | 4200 | instruction->result_loc_bit_cast = result_loc_bit_cast; |
| 3344 | 4201 | |
| ... | ... | @@ -3347,62 +4204,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod |
| 3347 | 4204 | return &instruction->base; |
| 3348 | 4205 | } |
| 3349 | 4206 | |
| 3350 | | static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3351 | | IrInstruction *operand, ZigType *ty) |
| 4207 | static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4208 | IrInstGen *operand, ZigType *ty) |
| 3352 | 4209 | { |
| 3353 | | IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>( |
| 4210 | IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>( |
| 3354 | 4211 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3355 | 4212 | instruction->base.value->type = ty; |
| 3356 | 4213 | instruction->operand = operand; |
| 3357 | 4214 | |
| 3358 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 4215 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3359 | 4216 | |
| 3360 | 4217 | return &instruction->base; |
| 3361 | 4218 | } |
| 3362 | 4219 | |
| 3363 | | static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3364 | | IrInstruction *target) |
| 4220 | static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4221 | ZigType *result_type) |
| 3365 | 4222 | { |
| 3366 | | IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>( |
| 3367 | | irb, scope, source_node); |
| 3368 | | instruction->target = target; |
| 4223 | IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node); |
| 4224 | inst->base.value->type = result_type; |
| 4225 | inst->target = target; |
| 3369 | 4226 | |
| 3370 | | ir_ref_instruction(target, irb->current_basic_block); |
| 4227 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3371 | 4228 | |
| 3372 | | return &instruction->base; |
| 4229 | return &inst->base; |
| 3373 | 4230 | } |
| 3374 | 4231 | |
| 3375 | | static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3376 | | IrInstruction *dest_type, IrInstruction *target) |
| 4232 | static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4233 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3377 | 4234 | { |
| 3378 | | IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>( |
| 3379 | | irb, scope, source_node); |
| 4235 | IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node); |
| 3380 | 4236 | instruction->dest_type = dest_type; |
| 3381 | 4237 | instruction->target = target; |
| 3382 | 4238 | |
| 3383 | | if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block); |
| 4239 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 3384 | 4240 | ir_ref_instruction(target, irb->current_basic_block); |
| 3385 | 4241 | |
| 3386 | 4242 | return &instruction->base; |
| 3387 | 4243 | } |
| 3388 | 4244 | |
| 3389 | | static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3390 | | IrInstruction *target) |
| 4245 | static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4246 | IrInstGen *target, ZigType *ptr_type) |
| 3391 | 4247 | { |
| 3392 | | IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>( |
| 3393 | | irb, scope, source_node); |
| 4248 | IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node); |
| 4249 | instruction->base.value->type = ptr_type; |
| 3394 | 4250 | instruction->target = target; |
| 3395 | 4251 | |
| 3396 | | ir_ref_instruction(target, irb->current_basic_block); |
| 4252 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3397 | 4253 | |
| 3398 | 4254 | return &instruction->base; |
| 3399 | 4255 | } |
| 3400 | 4256 | |
| 3401 | | static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3402 | | IrInstruction *dest_type, IrInstruction *target) |
| 4257 | static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4258 | IrInstSrc *target) |
| 3403 | 4259 | { |
| 3404 | | IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>( |
| 3405 | | irb, scope, source_node); |
| 4260 | IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node); |
| 4261 | inst->target = target; |
| 4262 | |
| 4263 | ir_ref_instruction(target, irb->current_basic_block); |
| 4264 | |
| 4265 | return &inst->base; |
| 4266 | } |
| 4267 | |
| 4268 | static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 4269 | IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4270 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 4271 | inst->target = target; |
| 4272 | |
| 4273 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4274 | |
| 4275 | return &inst->base; |
| 4276 | } |
| 4277 | |
| 4278 | static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4279 | IrInstSrc *dest_type, IrInstSrc *target) |
| 4280 | { |
| 4281 | IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node); |
| 3406 | 4282 | instruction->dest_type = dest_type; |
| 3407 | 4283 | instruction->target = target; |
| 3408 | 4284 | |
| ... | ... | @@ -3412,12 +4288,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode |
| 3412 | 4288 | return &instruction->base; |
| 3413 | 4289 | } |
| 3414 | 4290 | |
| 4291 | static IrInstGen *ir_build_int_to_enum_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4292 | ZigType *dest_type, IrInstGen *target) |
| 4293 | { |
| 4294 | IrInstGenIntToEnum *instruction = ir_build_inst_gen<IrInstGenIntToEnum>(&ira->new_irb, scope, source_node); |
| 4295 | instruction->base.value->type = dest_type; |
| 4296 | instruction->target = target; |
| 4297 | |
| 4298 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3415 | 4299 | |
| 4300 | return &instruction->base; |
| 4301 | } |
| 3416 | 4302 | |
| 3417 | | static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3418 | | IrInstruction *target) |
| 4303 | static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4304 | IrInstSrc *target) |
| 3419 | 4305 | { |
| 3420 | | IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>( |
| 4306 | IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>( |
| 3421 | 4307 | irb, scope, source_node); |
| 3422 | 4308 | instruction->target = target; |
| 3423 | 4309 | |
| ... | ... | @@ -3426,11 +4312,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 3426 | 4312 | return &instruction->base; |
| 3427 | 4313 | } |
| 3428 | 4314 | |
| 3429 | | static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3430 | | IrInstruction *target) |
| 4315 | static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4316 | IrInstSrc *target) |
| 3431 | 4317 | { |
| 3432 | | IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>( |
| 3433 | | irb, scope, source_node); |
| 4318 | IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node); |
| 3434 | 4319 | instruction->target = target; |
| 3435 | 4320 | |
| 3436 | 4321 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -3438,10 +4323,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode |
| 3438 | 4323 | return &instruction->base; |
| 3439 | 4324 | } |
| 3440 | 4325 | |
| 3441 | | static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3442 | | IrInstruction *target) |
| 4326 | static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4327 | ZigType *wanted_type) |
| 4328 | { |
| 4329 | IrInstGenIntToErr *instruction = ir_build_inst_gen<IrInstGenIntToErr>(&ira->new_irb, scope, source_node); |
| 4330 | instruction->base.value->type = wanted_type; |
| 4331 | instruction->target = target; |
| 4332 | |
| 4333 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4334 | |
| 4335 | return &instruction->base; |
| 4336 | } |
| 4337 | |
| 4338 | static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4339 | IrInstSrc *target) |
| 3443 | 4340 | { |
| 3444 | | IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>( |
| 4341 | IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>( |
| 3445 | 4342 | irb, scope, source_node); |
| 3446 | 4343 | instruction->target = target; |
| 3447 | 4344 | |
| ... | ... | @@ -3450,11 +4347,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 3450 | 4347 | return &instruction->base; |
| 3451 | 4348 | } |
| 3452 | 4349 | |
| 3453 | | static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3454 | | IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count, |
| 4350 | static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4351 | ZigType *wanted_type) |
| 4352 | { |
| 4353 | IrInstGenErrToInt *instruction = ir_build_inst_gen<IrInstGenErrToInt>(&ira->new_irb, scope, source_node); |
| 4354 | instruction->base.value->type = wanted_type; |
| 4355 | instruction->target = target; |
| 4356 | |
| 4357 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4358 | |
| 4359 | return &instruction->base; |
| 4360 | } |
| 4361 | |
| 4362 | static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4363 | IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count, |
| 3455 | 4364 | bool have_else_prong, bool have_underscore_prong) |
| 3456 | 4365 | { |
| 3457 | | IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>( |
| 4366 | IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>( |
| 3458 | 4367 | irb, scope, source_node); |
| 3459 | 4368 | instruction->target_value = target_value; |
| 3460 | 4369 | instruction->ranges = ranges; |
| ... | ... | @@ -3471,10 +4380,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, |
| 3471 | 4380 | return &instruction->base; |
| 3472 | 4381 | } |
| 3473 | 4382 | |
| 3474 | | static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3475 | | IrInstruction* statement_value) |
| 4383 | static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4384 | IrInstSrc* statement_value) |
| 3476 | 4385 | { |
| 3477 | | IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>( |
| 4386 | IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>( |
| 3478 | 4387 | irb, scope, source_node); |
| 3479 | 4388 | instruction->statement_value = statement_value; |
| 3480 | 4389 | |
| ... | ... | @@ -3483,11 +4392,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc |
| 3483 | 4392 | return &instruction->base; |
| 3484 | 4393 | } |
| 3485 | 4394 | |
| 3486 | | static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3487 | | IrInstruction *type_value) |
| 4395 | static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4396 | IrInstSrc *type_value) |
| 3488 | 4397 | { |
| 3489 | | IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>( |
| 3490 | | irb, scope, source_node); |
| 4398 | IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node); |
| 3491 | 4399 | instruction->type_value = type_value; |
| 3492 | 4400 | |
| 3493 | 4401 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3495,18 +4403,17 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode * |
| 3495 | 4403 | return &instruction->base; |
| 3496 | 4404 | } |
| 3497 | 4405 | |
| 3498 | | static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { |
| 3499 | | IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node); |
| 4406 | static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { |
| 4407 | IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node); |
| 3500 | 4408 | instruction->tld = tld; |
| 3501 | 4409 | instruction->lval = lval; |
| 3502 | 4410 | |
| 3503 | 4411 | return &instruction->base; |
| 3504 | 4412 | } |
| 3505 | 4413 | |
| 3506 | | static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 3507 | | IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node); |
| 3508 | | instruction->base.value->special = ConstValSpecialStatic; |
| 3509 | | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 4414 | static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 4415 | IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node); |
| 4416 | instruction->base.is_noreturn = true; |
| 3510 | 4417 | instruction->msg = msg; |
| 3511 | 4418 | |
| 3512 | 4419 | ir_ref_instruction(msg, irb->current_basic_block); |
| ... | ... | @@ -3514,10 +4421,18 @@ static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *sour |
| 3514 | 4421 | return &instruction->base; |
| 3515 | 4422 | } |
| 3516 | 4423 | |
| 3517 | | static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3518 | | IrInstruction *target) |
| 3519 | | { |
| 3520 | | IrInstructionTagName *instruction = ir_build_instruction<IrInstructionTagName>(irb, scope, source_node); |
| 4424 | static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) { |
| 4425 | IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb, |
| 4426 | source_instr->scope, source_instr->source_node); |
| 4427 | instruction->msg = msg; |
| 4428 | |
| 4429 | ir_ref_inst_gen(msg, ira->new_irb.current_basic_block); |
| 4430 | |
| 4431 | return &instruction->base; |
| 4432 | } |
| 4433 | |
| 4434 | static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 4435 | IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node); |
| 3521 | 4436 | instruction->target = target; |
| 3522 | 4437 | |
| 3523 | 4438 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -3525,10 +4440,23 @@ static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *s |
| 3525 | 4440 | return &instruction->base; |
| 3526 | 4441 | } |
| 3527 | 4442 | |
| 3528 | | static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3529 | | IrInstruction *target) |
| 4443 | static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target, |
| 4444 | ZigType *result_type) |
| 3530 | 4445 | { |
| 3531 | | IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node); |
| 4446 | IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb, |
| 4447 | source_instr->scope, source_instr->source_node); |
| 4448 | instruction->base.value->type = result_type; |
| 4449 | instruction->target = target; |
| 4450 | |
| 4451 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4452 | |
| 4453 | return &instruction->base; |
| 4454 | } |
| 4455 | |
| 4456 | static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4457 | IrInstSrc *target) |
| 4458 | { |
| 4459 | IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node); |
| 3532 | 4460 | instruction->target = target; |
| 3533 | 4461 | |
| 3534 | 4462 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -3536,27 +4464,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 3536 | 4464 | return &instruction->base; |
| 3537 | 4465 | } |
| 3538 | 4466 | |
| 3539 | | static IrInstruction *ir_build_field_parent_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3540 | | IrInstruction *type_value, IrInstruction *field_name, IrInstruction *field_ptr, TypeStructField *field) |
| 4467 | static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4468 | IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr) |
| 3541 | 4469 | { |
| 3542 | | IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>( |
| 4470 | IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>( |
| 3543 | 4471 | irb, scope, source_node); |
| 3544 | | instruction->type_value = type_value; |
| 3545 | | instruction->field_name = field_name; |
| 3546 | | instruction->field_ptr = field_ptr; |
| 3547 | | instruction->field = field; |
| 4472 | inst->type_value = type_value; |
| 4473 | inst->field_name = field_name; |
| 4474 | inst->field_ptr = field_ptr; |
| 3548 | 4475 | |
| 3549 | 4476 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 3550 | 4477 | ir_ref_instruction(field_name, irb->current_basic_block); |
| 3551 | 4478 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 3552 | 4479 | |
| 3553 | | return &instruction->base; |
| 4480 | return &inst->base; |
| 3554 | 4481 | } |
| 3555 | 4482 | |
| 3556 | | static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3557 | | IrInstruction *type_value, IrInstruction *field_name) |
| 4483 | static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4484 | IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type) |
| 3558 | 4485 | { |
| 3559 | | IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node); |
| 4486 | IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb, |
| 4487 | source_instr->scope, source_instr->source_node); |
| 4488 | inst->base.value->type = result_type; |
| 4489 | inst->field_ptr = field_ptr; |
| 4490 | inst->field = field; |
| 4491 | |
| 4492 | ir_ref_inst_gen(field_ptr, ira->new_irb.current_basic_block); |
| 4493 | |
| 4494 | return &inst->base; |
| 4495 | } |
| 4496 | |
| 4497 | static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4498 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 4499 | { |
| 4500 | IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node); |
| 3560 | 4501 | instruction->type_value = type_value; |
| 3561 | 4502 | instruction->field_name = field_name; |
| 3562 | 4503 | |
| ... | ... | @@ -3566,10 +4507,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN |
| 3566 | 4507 | return &instruction->base; |
| 3567 | 4508 | } |
| 3568 | 4509 | |
| 3569 | | static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3570 | | IrInstruction *type_value, IrInstruction *field_name) |
| 4510 | static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4511 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 3571 | 4512 | { |
| 3572 | | IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node); |
| 4513 | IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node); |
| 3573 | 4514 | instruction->type_value = type_value; |
| 3574 | 4515 | instruction->field_name = field_name; |
| 3575 | 4516 | |
| ... | ... | @@ -3579,9 +4520,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo |
| 3579 | 4520 | return &instruction->base; |
| 3580 | 4521 | } |
| 3581 | 4522 | |
| 3582 | | static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3583 | | IrInstruction *type_value) { |
| 3584 | | IrInstructionTypeInfo *instruction = ir_build_instruction<IrInstructionTypeInfo>(irb, scope, source_node); |
| 4523 | static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4524 | IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node); |
| 3585 | 4525 | instruction->type_value = type_value; |
| 3586 | 4526 | |
| 3587 | 4527 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3589,8 +4529,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode * |
| 3589 | 4529 | return &instruction->base; |
| 3590 | 4530 | } |
| 3591 | 4531 | |
| 3592 | | static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) { |
| 3593 | | IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node); |
| 4532 | static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) { |
| 4533 | IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node); |
| 3594 | 4534 | instruction->type_info = type_info; |
| 3595 | 4535 | |
| 3596 | 4536 | ir_ref_instruction(type_info, irb->current_basic_block); |
| ... | ... | @@ -3598,10 +4538,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 3598 | 4538 | return &instruction->base; |
| 3599 | 4539 | } |
| 3600 | 4540 | |
| 3601 | | static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3602 | | IrInstruction *type_value) |
| 3603 | | { |
| 3604 | | IrInstructionTypeId *instruction = ir_build_instruction<IrInstructionTypeId>(irb, scope, source_node); |
| 4541 | static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4542 | IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node); |
| 3605 | 4543 | instruction->type_value = type_value; |
| 3606 | 4544 | |
| 3607 | 4545 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3609,10 +4547,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so |
| 3609 | 4547 | return &instruction->base; |
| 3610 | 4548 | } |
| 3611 | 4549 | |
| 3612 | | static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3613 | | IrInstruction *new_quota) |
| 4550 | static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4551 | IrInstSrc *new_quota) |
| 3614 | 4552 | { |
| 3615 | | IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node); |
| 4553 | IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node); |
| 3616 | 4554 | instruction->new_quota = new_quota; |
| 3617 | 4555 | |
| 3618 | 4556 | ir_ref_instruction(new_quota, irb->current_basic_block); |
| ... | ... | @@ -3620,23 +4558,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop |
| 3620 | 4558 | return &instruction->base; |
| 3621 | 4559 | } |
| 3622 | 4560 | |
| 3623 | | static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3624 | | IrInstruction *align_bytes, IrInstruction *target) |
| 4561 | static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4562 | IrInstSrc *align_bytes, IrInstSrc *target) |
| 3625 | 4563 | { |
| 3626 | | IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node); |
| 4564 | IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node); |
| 3627 | 4565 | instruction->align_bytes = align_bytes; |
| 3628 | 4566 | instruction->target = target; |
| 3629 | 4567 | |
| 3630 | | if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 4568 | ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 3631 | 4569 | ir_ref_instruction(target, irb->current_basic_block); |
| 3632 | 4570 | |
| 3633 | 4571 | return &instruction->base; |
| 3634 | 4572 | } |
| 3635 | 4573 | |
| 3636 | | static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3637 | | ResultLoc *result_loc, IrInstruction *ty) |
| 4574 | static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4575 | ZigType *result_type) |
| 4576 | { |
| 4577 | IrInstGenAlignCast *instruction = ir_build_inst_gen<IrInstGenAlignCast>(&ira->new_irb, scope, source_node); |
| 4578 | instruction->base.value->type = result_type; |
| 4579 | instruction->target = target; |
| 4580 | |
| 4581 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4582 | |
| 4583 | return &instruction->base; |
| 4584 | } |
| 4585 | |
| 4586 | static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4587 | ResultLoc *result_loc, IrInstSrc *ty) |
| 3638 | 4588 | { |
| 3639 | | IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node); |
| 4589 | IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node); |
| 3640 | 4590 | instruction->result_loc = result_loc; |
| 3641 | 4591 | instruction->ty = ty; |
| 3642 | 4592 | |
| ... | ... | @@ -3645,25 +4595,26 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN |
| 3645 | 4595 | return &instruction->base; |
| 3646 | 4596 | } |
| 3647 | 4597 | |
| 3648 | | static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 4598 | static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3649 | 4599 | ResultLoc *result_loc) |
| 3650 | 4600 | { |
| 3651 | | IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node); |
| 4601 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node); |
| 3652 | 4602 | instruction->result_loc = result_loc; |
| 4603 | instruction->base.is_gen = true; |
| 3653 | 4604 | |
| 3654 | 4605 | return &instruction->base; |
| 3655 | 4606 | } |
| 3656 | 4607 | |
| 3657 | | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3658 | | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| 4608 | static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4609 | IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node); |
| 3659 | 4610 | |
| 3660 | 4611 | return &instruction->base; |
| 3661 | 4612 | } |
| 3662 | 4613 | |
| 3663 | | static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3664 | | IrInstruction *align_bytes) |
| 4614 | static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4615 | IrInstSrc *align_bytes) |
| 3665 | 4616 | { |
| 3666 | | IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node); |
| 4617 | IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node); |
| 3667 | 4618 | instruction->align_bytes = align_bytes; |
| 3668 | 4619 | |
| 3669 | 4620 | ir_ref_instruction(align_bytes, irb->current_basic_block); |
| ... | ... | @@ -3671,10 +4622,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast |
| 3671 | 4622 | return &instruction->base; |
| 3672 | 4623 | } |
| 3673 | 4624 | |
| 3674 | | static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3675 | | IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var) |
| 4625 | static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4626 | IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var) |
| 3676 | 4627 | { |
| 3677 | | IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node); |
| 4628 | IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node); |
| 3678 | 4629 | instruction->fn_type = fn_type; |
| 3679 | 4630 | instruction->arg_index = arg_index; |
| 3680 | 4631 | instruction->allow_var = allow_var; |
| ... | ... | @@ -3685,17 +4636,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 3685 | 4636 | return &instruction->base; |
| 3686 | 4637 | } |
| 3687 | 4638 | |
| 3688 | | static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) { |
| 3689 | | IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node); |
| 3690 | | instruction->optional = optional; |
| 4639 | static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4640 | IrInstErrorReturnTraceOptional optional) |
| 4641 | { |
| 4642 | IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node); |
| 4643 | inst->optional = optional; |
| 3691 | 4644 | |
| 3692 | | return &instruction->base; |
| 4645 | return &inst->base; |
| 4646 | } |
| 4647 | |
| 4648 | static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4649 | IrInstErrorReturnTraceOptional optional, ZigType *result_type) |
| 4650 | { |
| 4651 | IrInstGenErrorReturnTrace *inst = ir_build_inst_gen<IrInstGenErrorReturnTrace>(&ira->new_irb, scope, source_node); |
| 4652 | inst->base.value->type = result_type; |
| 4653 | inst->optional = optional; |
| 4654 | |
| 4655 | return &inst->base; |
| 3693 | 4656 | } |
| 3694 | 4657 | |
| 3695 | | static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3696 | | IrInstruction *err_set, IrInstruction *payload) |
| 4658 | static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4659 | IrInstSrc *err_set, IrInstSrc *payload) |
| 3697 | 4660 | { |
| 3698 | | IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node); |
| 4661 | IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node); |
| 3699 | 4662 | instruction->err_set = err_set; |
| 3700 | 4663 | instruction->payload = payload; |
| 3701 | 4664 | |
| ... | ... | @@ -3705,85 +4668,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode |
| 3705 | 4668 | return &instruction->base; |
| 3706 | 4669 | } |
| 3707 | 4670 | |
| 3708 | | static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3709 | | IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand, |
| 3710 | | IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering) |
| 4671 | static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4672 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand, |
| 4673 | IrInstSrc *ordering) |
| 3711 | 4674 | { |
| 3712 | | IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node); |
| 4675 | IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node); |
| 3713 | 4676 | instruction->operand_type = operand_type; |
| 3714 | 4677 | instruction->ptr = ptr; |
| 3715 | 4678 | instruction->op = op; |
| 3716 | 4679 | instruction->operand = operand; |
| 3717 | 4680 | instruction->ordering = ordering; |
| 3718 | | instruction->resolved_op = resolved_op; |
| 3719 | | instruction->resolved_ordering = resolved_ordering; |
| 3720 | 4681 | |
| 3721 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4682 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3722 | 4683 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3723 | | if (op != nullptr) ir_ref_instruction(op, irb->current_basic_block); |
| 4684 | ir_ref_instruction(op, irb->current_basic_block); |
| 3724 | 4685 | ir_ref_instruction(operand, irb->current_basic_block); |
| 3725 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4686 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 4687 | |
| 4688 | return &instruction->base; |
| 4689 | } |
| 4690 | |
| 4691 | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4692 | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type) |
| 4693 | { |
| 4694 | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4695 | instruction->base.value->type = operand_type; |
| 4696 | instruction->ptr = ptr; |
| 4697 | instruction->op = op; |
| 4698 | instruction->operand = operand; |
| 4699 | instruction->ordering = ordering; |
| 4700 | |
| 4701 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4702 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3726 | 4703 | |
| 3727 | 4704 | return &instruction->base; |
| 3728 | 4705 | } |
| 3729 | 4706 | |
| 3730 | | static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3731 | | IrInstruction *operand_type, IrInstruction *ptr, |
| 3732 | | IrInstruction *ordering, AtomicOrder resolved_ordering) |
| 4707 | static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4708 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering) |
| 3733 | 4709 | { |
| 3734 | | IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node); |
| 4710 | IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node); |
| 3735 | 4711 | instruction->operand_type = operand_type; |
| 3736 | 4712 | instruction->ptr = ptr; |
| 3737 | 4713 | instruction->ordering = ordering; |
| 3738 | | instruction->resolved_ordering = resolved_ordering; |
| 3739 | 4714 | |
| 3740 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4715 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3741 | 4716 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3742 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4717 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 4718 | |
| 4719 | return &instruction->base; |
| 4720 | } |
| 4721 | |
| 4722 | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4723 | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type) |
| 4724 | { |
| 4725 | IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb, |
| 4726 | source_instr->scope, source_instr->source_node); |
| 4727 | instruction->base.value->type = operand_type; |
| 4728 | instruction->ptr = ptr; |
| 4729 | instruction->ordering = ordering; |
| 4730 | |
| 4731 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3743 | 4732 | |
| 3744 | 4733 | return &instruction->base; |
| 3745 | 4734 | } |
| 3746 | 4735 | |
| 3747 | | static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3748 | | IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value, |
| 3749 | | IrInstruction *ordering, AtomicOrder resolved_ordering) |
| 4736 | static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4737 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering) |
| 3750 | 4738 | { |
| 3751 | | IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node); |
| 4739 | IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node); |
| 3752 | 4740 | instruction->operand_type = operand_type; |
| 3753 | 4741 | instruction->ptr = ptr; |
| 3754 | 4742 | instruction->value = value; |
| 3755 | 4743 | instruction->ordering = ordering; |
| 3756 | | instruction->resolved_ordering = resolved_ordering; |
| 3757 | 4744 | |
| 3758 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4745 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3759 | 4746 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3760 | 4747 | ir_ref_instruction(value, irb->current_basic_block); |
| 3761 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4748 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 3762 | 4749 | |
| 3763 | 4750 | return &instruction->base; |
| 3764 | 4751 | } |
| 3765 | 4752 | |
| 3766 | | static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3767 | | IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node); |
| 4753 | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4754 | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering) |
| 4755 | { |
| 4756 | IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb, |
| 4757 | source_instr->scope, source_instr->source_node); |
| 4758 | instruction->ptr = ptr; |
| 4759 | instruction->value = value; |
| 4760 | instruction->ordering = ordering; |
| 4761 | |
| 4762 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4763 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 4764 | |
| 3768 | 4765 | return &instruction->base; |
| 3769 | 4766 | } |
| 3770 | 4767 | |
| 3771 | | static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3772 | | IrInstruction *value, ResultLocReturn *result_loc_ret) |
| 4768 | static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4769 | IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node); |
| 4770 | return &inst->base; |
| 4771 | } |
| 4772 | |
| 4773 | static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 4774 | IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb, |
| 4775 | source_instr->scope, source_instr->source_node); |
| 4776 | return &inst->base; |
| 4777 | } |
| 4778 | |
| 4779 | static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4780 | IrInstSrc *value, ResultLocReturn *result_loc_ret) |
| 3773 | 4781 | { |
| 3774 | | IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node); |
| 3775 | | instruction->value = value; |
| 3776 | | instruction->result_loc_ret = result_loc_ret; |
| 4782 | IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node); |
| 4783 | inst->value = value; |
| 4784 | inst->result_loc_ret = result_loc_ret; |
| 3777 | 4785 | |
| 3778 | 4786 | ir_ref_instruction(value, irb->current_basic_block); |
| 3779 | 4787 | |
| 3780 | | return &instruction->base; |
| 4788 | return &inst->base; |
| 3781 | 4789 | } |
| 3782 | 4790 | |
| 3783 | | static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3784 | | IrInstruction *container, IrInstruction *name) |
| 4791 | static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4792 | IrInstSrc *container, IrInstSrc *name) |
| 3785 | 4793 | { |
| 3786 | | IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node); |
| 4794 | IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node); |
| 3787 | 4795 | instruction->container = container; |
| 3788 | 4796 | instruction->name = name; |
| 3789 | 4797 | |
| ... | ... | @@ -3793,17 +4801,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 3793 | 4801 | return &instruction->base; |
| 3794 | 4802 | } |
| 3795 | 4803 | |
| 3796 | | static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3797 | | Buf *name) |
| 3798 | | { |
| 3799 | | IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node); |
| 4804 | static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 4805 | IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node); |
| 3800 | 4806 | instruction->name = name; |
| 3801 | 4807 | |
| 3802 | 4808 | return &instruction->base; |
| 3803 | 4809 | } |
| 3804 | 4810 | |
| 3805 | | static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) { |
| 3806 | | IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node); |
| 4811 | static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) { |
| 4812 | IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node); |
| 3807 | 4813 | instruction->scope_is_comptime = scope_is_comptime; |
| 3808 | 4814 | instruction->is_comptime = is_comptime; |
| 3809 | 4815 | |
| ... | ... | @@ -3813,10 +4819,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, |
| 3813 | 4819 | return &instruction->base; |
| 3814 | 4820 | } |
| 3815 | 4821 | |
| 3816 | | static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3817 | | IrInstruction *union_type, IrInstruction *field_name, IrInstruction *field_result_loc, IrInstruction *result_loc) |
| 4822 | static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4823 | IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc) |
| 3818 | 4824 | { |
| 3819 | | IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node); |
| 4825 | IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node); |
| 3820 | 4826 | instruction->union_type = union_type; |
| 3821 | 4827 | instruction->field_name = field_name; |
| 3822 | 4828 | instruction->field_result_loc = field_result_loc; |
| ... | ... | @@ -3831,79 +4837,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco |
| 3831 | 4837 | } |
| 3832 | 4838 | |
| 3833 | 4839 | |
| 3834 | | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3835 | | ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc) |
| 4840 | static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction, |
| 4841 | ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc) |
| 3836 | 4842 | { |
| 3837 | | IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, |
| 4843 | IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb, |
| 3838 | 4844 | source_instruction->scope, source_instruction->source_node); |
| 3839 | 4845 | instruction->base.value->type = result_type; |
| 3840 | 4846 | instruction->vector = vector; |
| 3841 | 4847 | instruction->result_loc = result_loc; |
| 3842 | 4848 | |
| 3843 | | ir_ref_instruction(vector, ira->new_irb.current_basic_block); |
| 3844 | | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 4849 | ir_ref_inst_gen(vector, ira->new_irb.current_basic_block); |
| 4850 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3845 | 4851 | |
| 3846 | 4852 | return &instruction->base; |
| 3847 | 4853 | } |
| 3848 | 4854 | |
| 3849 | | static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3850 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 4855 | static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction, |
| 4856 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 3851 | 4857 | { |
| 3852 | | IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb, |
| 4858 | IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb, |
| 3853 | 4859 | source_instruction->scope, source_instruction->source_node); |
| 3854 | 4860 | instruction->base.value->type = result_type; |
| 3855 | 4861 | instruction->operand = operand; |
| 3856 | 4862 | instruction->result_loc = result_loc; |
| 3857 | 4863 | |
| 3858 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 3859 | | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 4864 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 4865 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3860 | 4866 | |
| 3861 | 4867 | return &instruction->base; |
| 3862 | 4868 | } |
| 3863 | 4869 | |
| 3864 | | static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3865 | | IrInstruction *array, ZigType *result_type) |
| 4870 | static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction, |
| 4871 | IrInstGen *array, ZigType *result_type) |
| 3866 | 4872 | { |
| 3867 | | IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb, |
| 4873 | IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb, |
| 3868 | 4874 | source_instruction->scope, source_instruction->source_node); |
| 3869 | 4875 | instruction->base.value->type = result_type; |
| 3870 | 4876 | instruction->array = array; |
| 3871 | 4877 | |
| 3872 | | ir_ref_instruction(array, ira->new_irb.current_basic_block); |
| 4878 | ir_ref_inst_gen(array, ira->new_irb.current_basic_block); |
| 3873 | 4879 | |
| 3874 | 4880 | return &instruction->base; |
| 3875 | 4881 | } |
| 3876 | 4882 | |
| 3877 | | static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3878 | | IrInstruction *target) |
| 4883 | static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction, |
| 4884 | IrInstGen *target) |
| 3879 | 4885 | { |
| 3880 | | IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb, |
| 4886 | IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb, |
| 3881 | 4887 | source_instruction->scope, source_instruction->source_node); |
| 3882 | 4888 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3883 | 4889 | instruction->target = target; |
| 3884 | 4890 | |
| 3885 | | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| 4891 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3886 | 4892 | |
| 3887 | 4893 | return &instruction->base; |
| 3888 | 4894 | } |
| 3889 | 4895 | |
| 3890 | | static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3891 | | IrInstruction *target) |
| 4896 | static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction, |
| 4897 | IrInstGen *target) |
| 3892 | 4898 | { |
| 3893 | | IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb, |
| 4899 | IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb, |
| 3894 | 4900 | source_instruction->scope, source_instruction->source_node); |
| 3895 | 4901 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3896 | 4902 | instruction->target = target; |
| 3897 | 4903 | |
| 3898 | | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| 4904 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3899 | 4905 | |
| 3900 | 4906 | return &instruction->base; |
| 3901 | 4907 | } |
| 3902 | 4908 | |
| 3903 | | static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3904 | | IrInstruction *align, const char *name_hint, IrInstruction *is_comptime) |
| 4909 | static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4910 | IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime) |
| 3905 | 4911 | { |
| 3906 | | IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node); |
| 4912 | IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node); |
| 3907 | 4913 | instruction->base.is_gen = true; |
| 3908 | 4914 | instruction->align = align; |
| 3909 | 4915 | instruction->name_hint = name_hint; |
| ... | ... | @@ -3915,10 +4921,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode |
| 3915 | 4921 | return &instruction->base; |
| 3916 | 4922 | } |
| 3917 | 4923 | |
| 3918 | | static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 4924 | static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 3919 | 4925 | uint32_t align, const char *name_hint) |
| 3920 | 4926 | { |
| 3921 | | IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb, |
| 4927 | IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb, |
| 3922 | 4928 | source_instruction->scope, source_instruction->source_node); |
| 3923 | 4929 | instruction->align = align; |
| 3924 | 4930 | instruction->name_hint = name_hint; |
| ... | ... | @@ -3926,10 +4932,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction |
| 3926 | 4932 | return instruction; |
| 3927 | 4933 | } |
| 3928 | 4934 | |
| 3929 | | static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3930 | | IrInstruction *value, ResultLoc *result_loc) |
| 4935 | static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4936 | IrInstSrc *value, ResultLoc *result_loc) |
| 3931 | 4937 | { |
| 3932 | | IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node); |
| 4938 | IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node); |
| 3933 | 4939 | instruction->base.is_gen = true; |
| 3934 | 4940 | instruction->value = value; |
| 3935 | 4941 | instruction->result_loc = result_loc; |
| ... | ... | @@ -3939,29 +4945,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s |
| 3939 | 4945 | return &instruction->base; |
| 3940 | 4946 | } |
| 3941 | 4947 | |
| 3942 | | static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3943 | | IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node); |
| 3944 | | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 4948 | static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4949 | return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node); |
| 4950 | } |
| 3945 | 4951 | |
| 3946 | | return instruction; |
| 4952 | static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 4953 | IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb, |
| 4954 | source_instr->scope, source_instr->source_node); |
| 4955 | return &inst->base; |
| 3947 | 4956 | } |
| 3948 | 4957 | |
| 3949 | | static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3950 | | IrInstructionSuspendBegin *begin) |
| 4958 | static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4959 | IrInstSrcSuspendBegin *begin) |
| 3951 | 4960 | { |
| 3952 | | IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node); |
| 3953 | | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3954 | | instruction->begin = begin; |
| 4961 | IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node); |
| 4962 | inst->begin = begin; |
| 3955 | 4963 | |
| 3956 | 4964 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| 3957 | 4965 | |
| 3958 | | return &instruction->base; |
| 4966 | return &inst->base; |
| 4967 | } |
| 4968 | |
| 4969 | static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) { |
| 4970 | IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb, |
| 4971 | source_instr->scope, source_instr->source_node); |
| 4972 | inst->begin = begin; |
| 4973 | |
| 4974 | ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block); |
| 4975 | |
| 4976 | return &inst->base; |
| 3959 | 4977 | } |
| 3960 | 4978 | |
| 3961 | | static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3962 | | IrInstruction *frame, ResultLoc *result_loc) |
| 4979 | static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4980 | IrInstSrc *frame, ResultLoc *result_loc) |
| 3963 | 4981 | { |
| 3964 | | IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node); |
| 4982 | IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node); |
| 3965 | 4983 | instruction->frame = frame; |
| 3966 | 4984 | instruction->result_loc = result_loc; |
| 3967 | 4985 | |
| ... | ... | @@ -3970,24 +4988,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode * |
| 3970 | 4988 | return &instruction->base; |
| 3971 | 4989 | } |
| 3972 | 4990 | |
| 3973 | | static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3974 | | IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc) |
| 4991 | static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4992 | IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc) |
| 3975 | 4993 | { |
| 3976 | | IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb, |
| 4994 | IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb, |
| 3977 | 4995 | source_instruction->scope, source_instruction->source_node); |
| 3978 | 4996 | instruction->base.value->type = result_type; |
| 3979 | 4997 | instruction->frame = frame; |
| 3980 | 4998 | instruction->result_loc = result_loc; |
| 3981 | 4999 | |
| 3982 | | ir_ref_instruction(frame, ira->new_irb.current_basic_block); |
| 3983 | | if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 5000 | ir_ref_inst_gen(frame, ira->new_irb.current_basic_block); |
| 5001 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3984 | 5002 | |
| 3985 | 5003 | return instruction; |
| 3986 | 5004 | } |
| 3987 | 5005 | |
| 3988 | | static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) { |
| 3989 | | IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node); |
| 3990 | | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 5006 | static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) { |
| 5007 | IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node); |
| 3991 | 5008 | instruction->frame = frame; |
| 3992 | 5009 | |
| 3993 | 5010 | ir_ref_instruction(frame, irb->current_basic_block); |
| ... | ... | @@ -3995,12 +5012,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou |
| 3995 | 5012 | return &instruction->base; |
| 3996 | 5013 | } |
| 3997 | 5014 | |
| 3998 | | static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3999 | | IrInstruction *operand, SpillId spill_id) |
| 5015 | static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) { |
| 5016 | IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb, |
| 5017 | source_instr->scope, source_instr->source_node); |
| 5018 | instruction->frame = frame; |
| 5019 | |
| 5020 | ir_ref_inst_gen(frame, ira->new_irb.current_basic_block); |
| 5021 | |
| 5022 | return &instruction->base; |
| 5023 | } |
| 5024 | |
| 5025 | static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 5026 | IrInstSrc *operand, SpillId spill_id) |
| 4000 | 5027 | { |
| 4001 | | IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node); |
| 4002 | | instruction->base.value->special = ConstValSpecialStatic; |
| 4003 | | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 5028 | IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node); |
| 4004 | 5029 | instruction->operand = operand; |
| 4005 | 5030 | instruction->spill_id = spill_id; |
| 4006 | 5031 | |
| ... | ... | @@ -4009,10 +5034,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop |
| 4009 | 5034 | return instruction; |
| 4010 | 5035 | } |
| 4011 | 5036 | |
| 4012 | | static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 4013 | | IrInstructionSpillBegin *begin) |
| 5037 | static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 5038 | SpillId spill_id) |
| 5039 | { |
| 5040 | IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb, |
| 5041 | source_instr->scope, source_instr->source_node); |
| 5042 | instruction->operand = operand; |
| 5043 | instruction->spill_id = spill_id; |
| 5044 | |
| 5045 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 5046 | |
| 5047 | return &instruction->base; |
| 5048 | } |
| 5049 | |
| 5050 | static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 5051 | IrInstSrcSpillBegin *begin) |
| 4014 | 5052 | { |
| 4015 | | IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node); |
| 5053 | IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node); |
| 4016 | 5054 | instruction->begin = begin; |
| 4017 | 5055 | |
| 4018 | 5056 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| ... | ... | @@ -4020,22 +5058,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode * |
| 4020 | 5058 | return &instruction->base; |
| 4021 | 5059 | } |
| 4022 | 5060 | |
| 4023 | | static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction, |
| 4024 | | IrInstruction *vector, IrInstruction *index) |
| 5061 | static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin, |
| 5062 | ZigType *result_type) |
| 5063 | { |
| 5064 | IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb, |
| 5065 | source_instr->scope, source_instr->source_node); |
| 5066 | instruction->base.value->type = result_type; |
| 5067 | instruction->begin = begin; |
| 5068 | |
| 5069 | ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block); |
| 5070 | |
| 5071 | return &instruction->base; |
| 5072 | } |
| 5073 | |
| 5074 | static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction, |
| 5075 | IrInstGen *vector, IrInstGen *index) |
| 4025 | 5076 | { |
| 4026 | | IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>( |
| 5077 | IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>( |
| 4027 | 5078 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 4028 | 5079 | instruction->base.value->type = vector->value->type->data.vector.elem_type; |
| 4029 | 5080 | instruction->vector = vector; |
| 4030 | 5081 | instruction->index = index; |
| 4031 | 5082 | |
| 4032 | | ir_ref_instruction(vector, ira->new_irb.current_basic_block); |
| 4033 | | ir_ref_instruction(index, ira->new_irb.current_basic_block); |
| 5083 | ir_ref_inst_gen(vector, ira->new_irb.current_basic_block); |
| 5084 | ir_ref_inst_gen(index, ira->new_irb.current_basic_block); |
| 4034 | 5085 | |
| 4035 | 5086 | return &instruction->base; |
| 4036 | 5087 | } |
| 4037 | 5088 | |
| 4038 | | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 5089 | static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 4039 | 5090 | results[ReturnKindUnconditional] = 0; |
| 4040 | 5091 | results[ReturnKindError] = 0; |
| 4041 | 5092 | |
| ... | ... | @@ -4072,12 +5123,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 4072 | 5123 | } |
| 4073 | 5124 | } |
| 4074 | 5125 | |
| 4075 | | static IrInstruction *ir_mark_gen(IrInstruction *instruction) { |
| 5126 | static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) { |
| 4076 | 5127 | instruction->is_gen = true; |
| 4077 | 5128 | return instruction; |
| 4078 | 5129 | } |
| 4079 | 5130 | |
| 4080 | | static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) { |
| 5131 | static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) { |
| 4081 | 5132 | Scope *scope = inner_scope; |
| 4082 | 5133 | bool is_noreturn = false; |
| 4083 | 5134 | while (scope != outer_scope) { |
| ... | ... | @@ -4094,11 +5145,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 4094 | 5145 | { |
| 4095 | 5146 | AstNode *defer_expr_node = defer_node->data.defer.expr; |
| 4096 | 5147 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 4097 | | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 4098 | | if (defer_expr_value != irb->codegen->invalid_instruction) { |
| 4099 | | if (defer_expr_value->value->type != nullptr && |
| 4100 | | defer_expr_value->value->type->id == ZigTypeIdUnreachable) |
| 4101 | | { |
| 5148 | IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 5149 | if (defer_expr_value != irb->codegen->invalid_inst_src) { |
| 5150 | if (defer_expr_value->is_noreturn) { |
| 4102 | 5151 | is_noreturn = true; |
| 4103 | 5152 | } else { |
| 4104 | 5153 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, |
| ... | ... | @@ -4130,13 +5179,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 4130 | 5179 | return is_noreturn; |
| 4131 | 5180 | } |
| 4132 | 5181 | |
| 4133 | | static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 5182 | static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) { |
| 4134 | 5183 | assert(basic_block); |
| 5184 | irb->current_basic_block = basic_block; |
| 5185 | } |
| 4135 | 5186 | |
| 5187 | static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { |
| 5188 | assert(basic_block); |
| 4136 | 5189 | irb->current_basic_block = basic_block; |
| 4137 | 5190 | } |
| 4138 | 5191 | |
| 4139 | | static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 5192 | static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { |
| 4140 | 5193 | basic_block->index = irb->exec->basic_block_list.length; |
| 4141 | 5194 | irb->exec->basic_block_list.append(basic_block); |
| 4142 | 5195 | ir_set_cursor_at_end(irb, basic_block); |
| ... | ... | @@ -4166,22 +5219,16 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 4166 | 5219 | return nullptr; |
| 4167 | 5220 | } |
| 4168 | 5221 | |
| 4169 | | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5222 | static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4170 | 5223 | assert(node->type == NodeTypeReturnExpr); |
| 4171 | 5224 | |
| 4172 | | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 4173 | | if (!fn_entry) { |
| 4174 | | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); |
| 4175 | | return irb->codegen->invalid_instruction; |
| 4176 | | } |
| 4177 | | |
| 4178 | 5225 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); |
| 4179 | 5226 | if (scope_defer_expr) { |
| 4180 | 5227 | if (!scope_defer_expr->reported_err) { |
| 4181 | 5228 | add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression")); |
| 4182 | 5229 | scope_defer_expr->reported_err = true; |
| 4183 | 5230 | } |
| 4184 | | return irb->codegen->invalid_instruction; |
| 5231 | return irb->codegen->invalid_inst_src; |
| 4185 | 5232 | } |
| 4186 | 5233 | |
| 4187 | 5234 | Scope *outer_scope = irb->exec->begin_scope; |
| ... | ... | @@ -4194,15 +5241,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4194 | 5241 | result_loc_ret->base.id = ResultLocIdReturn; |
| 4195 | 5242 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| 4196 | 5243 | |
| 4197 | | IrInstruction *return_value; |
| 5244 | IrInstSrc *return_value; |
| 4198 | 5245 | if (expr_node) { |
| 4199 | 5246 | // Temporarily set this so that if we return a type it gets the name of the function |
| 4200 | 5247 | ZigFn *prev_name_fn = irb->exec->name_fn; |
| 4201 | 5248 | irb->exec->name_fn = exec_fn_entry(irb->exec); |
| 4202 | 5249 | return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base); |
| 4203 | 5250 | irb->exec->name_fn = prev_name_fn; |
| 4204 | | if (return_value == irb->codegen->invalid_instruction) |
| 4205 | | return irb->codegen->invalid_instruction; |
| 5251 | if (return_value == irb->codegen->invalid_inst_src) |
| 5252 | return irb->codegen->invalid_inst_src; |
| 4206 | 5253 | } else { |
| 4207 | 5254 | return_value = ir_build_const_void(irb, scope, node); |
| 4208 | 5255 | } |
| ... | ... | @@ -4215,22 +5262,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4215 | 5262 | if (!have_err_defers && !irb->codegen->have_err_ret_tracing) { |
| 4216 | 5263 | // only generate unconditional defers |
| 4217 | 5264 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 4218 | | IrInstruction *result = ir_build_return(irb, scope, node, return_value); |
| 5265 | IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value); |
| 4219 | 5266 | result_loc_ret->base.source_instruction = result; |
| 4220 | 5267 | return result; |
| 4221 | 5268 | } |
| 4222 | 5269 | bool should_inline = ir_should_inline(irb->exec, scope); |
| 4223 | 5270 | |
| 4224 | | IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); |
| 4225 | | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); |
| 5271 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); |
| 5272 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); |
| 4226 | 5273 | |
| 4227 | 5274 | if (!have_err_defers) { |
| 4228 | 5275 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 4229 | 5276 | } |
| 4230 | 5277 | |
| 4231 | | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true); |
| 5278 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true); |
| 4232 | 5279 | |
| 4233 | | IrInstruction *is_comptime; |
| 5280 | IrInstSrc *is_comptime; |
| 4234 | 5281 | if (should_inline) { |
| 4235 | 5282 | is_comptime = ir_build_const_bool(irb, scope, node, should_inline); |
| 4236 | 5283 | } else { |
| ... | ... | @@ -4238,14 +5285,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4238 | 5285 | } |
| 4239 | 5286 | |
| 4240 | 5287 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime)); |
| 4241 | | IrBasicBlock *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt"); |
| 5288 | IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt"); |
| 4242 | 5289 | |
| 4243 | 5290 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 4244 | 5291 | if (have_err_defers) { |
| 4245 | 5292 | ir_gen_defers_for_block(irb, scope, outer_scope, true); |
| 4246 | 5293 | } |
| 4247 | 5294 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 4248 | | ir_build_save_err_ret_addr(irb, scope, node); |
| 5295 | ir_build_save_err_ret_addr_src(irb, scope, node); |
| 4249 | 5296 | } |
| 4250 | 5297 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); |
| 4251 | 5298 | |
| ... | ... | @@ -4256,21 +5303,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4256 | 5303 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); |
| 4257 | 5304 | |
| 4258 | 5305 | ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block); |
| 4259 | | IrInstruction *result = ir_build_return(irb, scope, node, return_value); |
| 5306 | IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value); |
| 4260 | 5307 | result_loc_ret->base.source_instruction = result; |
| 4261 | 5308 | return result; |
| 4262 | 5309 | } |
| 4263 | 5310 | case ReturnKindError: |
| 4264 | 5311 | { |
| 4265 | 5312 | assert(expr_node); |
| 4266 | | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 4267 | | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 4268 | | return irb->codegen->invalid_instruction; |
| 4269 | | IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false); |
| 4270 | | |
| 4271 | | IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); |
| 4272 | | IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); |
| 4273 | | IrInstruction *is_comptime; |
| 5313 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 5314 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 5315 | return irb->codegen->invalid_inst_src; |
| 5316 | IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false); |
| 5317 | |
| 5318 | IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); |
| 5319 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); |
| 5320 | IrInstSrc *is_comptime; |
| 4274 | 5321 | bool should_inline = ir_should_inline(irb->exec, scope); |
| 4275 | 5322 | if (should_inline) { |
| 4276 | 5323 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| ... | ... | @@ -4280,10 +5327,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4280 | 5327 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime)); |
| 4281 | 5328 | |
| 4282 | 5329 | ir_set_cursor_at_end_and_append_block(irb, return_block); |
| 4283 | | IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); |
| 4284 | | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 5330 | IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr); |
| 5331 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 4285 | 5332 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr)); |
| 4286 | | IrInstructionSpillBegin *spill_begin = ir_build_spill_begin(irb, scope, node, err_val, |
| 5333 | IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val, |
| 4287 | 5334 | SpillIdRetErrCode); |
| 4288 | 5335 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| 4289 | 5336 | result_loc_ret->base.id = ResultLocIdReturn; |
| ... | ... | @@ -4291,15 +5338,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4291 | 5338 | ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base); |
| 4292 | 5339 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { |
| 4293 | 5340 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 4294 | | ir_build_save_err_ret_addr(irb, scope, node); |
| 5341 | ir_build_save_err_ret_addr_src(irb, scope, node); |
| 4295 | 5342 | } |
| 4296 | | err_val = ir_build_spill_end(irb, scope, node, spill_begin); |
| 4297 | | IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val); |
| 5343 | err_val = ir_build_spill_end_src(irb, scope, node, spill_begin); |
| 5344 | IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val); |
| 4298 | 5345 | result_loc_ret->base.source_instruction = ret_inst; |
| 4299 | 5346 | } |
| 4300 | 5347 | |
| 4301 | 5348 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 4302 | | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false, false); |
| 5349 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false); |
| 4303 | 5350 | if (lval == LValPtr) |
| 4304 | 5351 | return unwrapped_ptr; |
| 4305 | 5352 | else |
| ... | ... | @@ -4310,19 +5357,18 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4310 | 5357 | } |
| 4311 | 5358 | |
| 4312 | 5359 | static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, |
| 4313 | | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime, |
| 5360 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime, |
| 4314 | 5361 | bool skip_name_check) |
| 4315 | 5362 | { |
| 4316 | 5363 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); |
| 4317 | 5364 | variable_entry->parent_scope = parent_scope; |
| 4318 | 5365 | variable_entry->shadowable = is_shadowable; |
| 4319 | | variable_entry->mem_slot_index = SIZE_MAX; |
| 4320 | 5366 | variable_entry->is_comptime = is_comptime; |
| 4321 | 5367 | variable_entry->src_arg_index = SIZE_MAX; |
| 4322 | 5368 | variable_entry->const_value = create_const_vals(1); |
| 4323 | 5369 | |
| 4324 | 5370 | if (is_comptime != nullptr) { |
| 4325 | | is_comptime->ref_count += 1; |
| 5371 | is_comptime->base.ref_count += 1; |
| 4326 | 5372 | } |
| 4327 | 5373 | |
| 4328 | 5374 | if (name) { |
| ... | ... | @@ -4372,15 +5418,14 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 4372 | 5418 | |
| 4373 | 5419 | // Set name to nullptr to make the variable anonymous (not visible to programmer). |
| 4374 | 5420 | // After you call this function var->child_scope has the variable in scope |
| 4375 | | static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, |
| 4376 | | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime) |
| 5421 | static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name, |
| 5422 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime) |
| 4377 | 5423 | { |
| 4378 | 5424 | bool is_underscored = name ? buf_eql_str(name, "_") : false; |
| 4379 | 5425 | ZigVar *var = create_local_var(irb->codegen, node, scope, |
| 4380 | 5426 | (is_underscored ? nullptr : name), src_is_const, gen_is_const, |
| 4381 | 5427 | (is_underscored ? true : is_shadowable), is_comptime, false); |
| 4382 | 5428 | if (is_comptime != nullptr || gen_is_const) { |
| 4383 | | var->mem_slot_index = exec_next_mem_slot(irb->exec); |
| 4384 | 5429 | var->owner_exec = irb->exec; |
| 4385 | 5430 | } |
| 4386 | 5431 | assert(var->child_scope); |
| ... | ... | @@ -4396,13 +5441,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) { |
| 4396 | 5441 | return result; |
| 4397 | 5442 | } |
| 4398 | 5443 | |
| 4399 | | static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node, LVal lval, |
| 5444 | static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval, |
| 4400 | 5445 | ResultLoc *result_loc) |
| 4401 | 5446 | { |
| 4402 | 5447 | assert(block_node->type == NodeTypeBlock); |
| 4403 | 5448 | |
| 4404 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 4405 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 5449 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 5450 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 4406 | 5451 | |
| 4407 | 5452 | ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope); |
| 4408 | 5453 | |
| ... | ... | @@ -4438,11 +5483,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4438 | 5483 | } |
| 4439 | 5484 | |
| 4440 | 5485 | bool is_continuation_unreachable = false; |
| 4441 | | IrInstruction *noreturn_return_value = nullptr; |
| 5486 | IrInstSrc *noreturn_return_value = nullptr; |
| 4442 | 5487 | for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { |
| 4443 | 5488 | AstNode *statement_node = block_node->data.block.statements.at(i); |
| 4444 | 5489 | |
| 4445 | | IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope); |
| 5490 | IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope); |
| 4446 | 5491 | is_continuation_unreachable = instr_is_unreachable(statement_value); |
| 4447 | 5492 | if (is_continuation_unreachable) { |
| 4448 | 5493 | // keep the last noreturn statement value around in case we need to return it |
| ... | ... | @@ -4450,15 +5495,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4450 | 5495 | } |
| 4451 | 5496 | // This logic must be kept in sync with |
| 4452 | 5497 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 4453 | | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) { |
| 5498 | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) { |
| 4454 | 5499 | // defer starts a new scope |
| 4455 | 5500 | child_scope = statement_node->data.defer.child_scope; |
| 4456 | 5501 | assert(child_scope); |
| 4457 | | } else if (statement_value->id == IrInstructionIdDeclVarSrc) { |
| 5502 | } else if (statement_value->id == IrInstSrcIdDeclVar) { |
| 4458 | 5503 | // variable declarations start a new scope |
| 4459 | | IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value; |
| 5504 | IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value; |
| 4460 | 5505 | child_scope = decl_var_instruction->var->child_scope; |
| 4461 | | } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) { |
| 5506 | } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) { |
| 4462 | 5507 | // this statement's value must be void |
| 4463 | 5508 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value)); |
| 4464 | 5509 | } |
| ... | ... | @@ -4474,12 +5519,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4474 | 5519 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; |
| 4475 | 5520 | } |
| 4476 | 5521 | ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block); |
| 4477 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 5522 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 4478 | 5523 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 4479 | 5524 | return ir_expr_wrap(irb, parent_scope, phi, result_loc); |
| 4480 | 5525 | } else { |
| 4481 | 5526 | incoming_blocks.append(irb->current_basic_block); |
| 4482 | | IrInstruction *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)); |
| 5527 | IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)); |
| 4483 | 5528 | |
| 4484 | 5529 | if (scope_block->peer_parent != nullptr) { |
| 4485 | 5530 | ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent); |
| ... | ... | @@ -4499,15 +5544,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4499 | 5544 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 4500 | 5545 | } |
| 4501 | 5546 | |
| 4502 | | IrInstruction *result; |
| 5547 | IrInstSrc *result; |
| 4503 | 5548 | if (block_node->data.block.name != nullptr) { |
| 4504 | 5549 | ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); |
| 4505 | 5550 | ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block); |
| 4506 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 5551 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 4507 | 5552 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 4508 | 5553 | result = ir_expr_wrap(irb, parent_scope, phi, result_loc); |
| 4509 | 5554 | } else { |
| 4510 | | IrInstruction *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); |
| 5555 | IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); |
| 4511 | 5556 | result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc); |
| 4512 | 5557 | } |
| 4513 | 5558 | if (!is_return_from_fn) |
| ... | ... | @@ -4517,31 +5562,35 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4517 | 5562 | // only generate unconditional defers |
| 4518 | 5563 | |
| 4519 | 5564 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); |
| 5565 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| 5566 | result_loc_ret->base.id = ResultLocIdReturn; |
| 5567 | ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base); |
| 5568 | ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base)); |
| 4520 | 5569 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 4521 | | return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result)); |
| 5570 | return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result)); |
| 4522 | 5571 | } |
| 4523 | 5572 | |
| 4524 | | static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 5573 | static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 4525 | 5574 | Scope *inner_scope = scope; |
| 4526 | 5575 | if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) { |
| 4527 | 5576 | inner_scope = create_comptime_scope(irb->codegen, node, scope); |
| 4528 | 5577 | } |
| 4529 | 5578 | |
| 4530 | | IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope); |
| 4531 | | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope); |
| 5579 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope); |
| 5580 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope); |
| 4532 | 5581 | |
| 4533 | | if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction) |
| 4534 | | return irb->codegen->invalid_instruction; |
| 5582 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) |
| 5583 | return irb->codegen->invalid_inst_src; |
| 4535 | 5584 | |
| 4536 | 5585 | return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 4537 | 5586 | } |
| 4538 | 5587 | |
| 4539 | | static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4540 | | IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 4541 | | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5588 | static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5589 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5590 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4542 | 5591 | |
| 4543 | | if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction) |
| 4544 | | return irb->codegen->invalid_instruction; |
| 5592 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) |
| 5593 | return irb->codegen->invalid_inst_src; |
| 4545 | 5594 | |
| 4546 | 5595 | // TODO only pass type_name when the || operator is the top level AST node in the var decl expr |
| 4547 | 5596 | Buf bare_name = BUF_INIT; |
| ... | ... | @@ -4550,10 +5599,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod |
| 4550 | 5599 | return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name); |
| 4551 | 5600 | } |
| 4552 | 5601 | |
| 4553 | | static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4554 | | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 4555 | | if (lvalue == irb->codegen->invalid_instruction) |
| 4556 | | return irb->codegen->invalid_instruction; |
| 5602 | static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5603 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5604 | if (lvalue == irb->codegen->invalid_inst_src) |
| 5605 | return irb->codegen->invalid_inst_src; |
| 4557 | 5606 | |
| 4558 | 5607 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction"); |
| 4559 | 5608 | result_loc_inst->base.id = ResultLocIdInstruction; |
| ... | ... | @@ -4561,49 +5610,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) |
| 4561 | 5610 | ir_ref_instruction(lvalue, irb->current_basic_block); |
| 4562 | 5611 | ir_build_reset_result(irb, scope, node, &result_loc_inst->base); |
| 4563 | 5612 | |
| 4564 | | IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, |
| 5613 | IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, |
| 4565 | 5614 | &result_loc_inst->base); |
| 4566 | | if (rvalue == irb->codegen->invalid_instruction) |
| 4567 | | return irb->codegen->invalid_instruction; |
| 5615 | if (rvalue == irb->codegen->invalid_inst_src) |
| 5616 | return irb->codegen->invalid_inst_src; |
| 4568 | 5617 | |
| 4569 | 5618 | return ir_build_const_void(irb, scope, node); |
| 4570 | 5619 | } |
| 4571 | 5620 | |
| 4572 | | static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4573 | | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 4574 | | if (lvalue == irb->codegen->invalid_instruction) |
| 5621 | static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5622 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5623 | if (lvalue == irb->codegen->invalid_inst_src) |
| 4575 | 5624 | return lvalue; |
| 4576 | | IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 4577 | | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4578 | | if (op2 == irb->codegen->invalid_instruction) |
| 5625 | IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 5626 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5627 | if (op2 == irb->codegen->invalid_inst_src) |
| 4579 | 5628 | return op2; |
| 4580 | | IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr); |
| 5629 | IrInstSrc *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr); |
| 4581 | 5630 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 4582 | 5631 | return ir_build_const_void(irb, scope, node); |
| 4583 | 5632 | } |
| 4584 | 5633 | |
| 4585 | | static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 4586 | | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 4587 | | if (lvalue == irb->codegen->invalid_instruction) |
| 5634 | static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 5635 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5636 | if (lvalue == irb->codegen->invalid_inst_src) |
| 4588 | 5637 | return lvalue; |
| 4589 | | IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 4590 | | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4591 | | if (op2 == irb->codegen->invalid_instruction) |
| 5638 | IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 5639 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5640 | if (op2 == irb->codegen->invalid_inst_src) |
| 4592 | 5641 | return op2; |
| 4593 | | IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 5642 | IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 4594 | 5643 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 4595 | 5644 | return ir_build_const_void(irb, scope, node); |
| 4596 | 5645 | } |
| 4597 | 5646 | |
| 4598 | | static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5647 | static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4599 | 5648 | assert(node->type == NodeTypeBinOpExpr); |
| 4600 | 5649 | |
| 4601 | | IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 4602 | | if (val1 == irb->codegen->invalid_instruction) |
| 4603 | | return irb->codegen->invalid_instruction; |
| 4604 | | IrBasicBlock *post_val1_block = irb->current_basic_block; |
| 5650 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5651 | if (val1 == irb->codegen->invalid_inst_src) |
| 5652 | return irb->codegen->invalid_inst_src; |
| 5653 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; |
| 4605 | 5654 | |
| 4606 | | IrInstruction *is_comptime; |
| 5655 | IrInstSrc *is_comptime; |
| 4607 | 5656 | if (ir_should_inline(irb->exec, scope)) { |
| 4608 | 5657 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 4609 | 5658 | } else { |
| ... | ... | @@ -4611,41 +5660,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node |
| 4611 | 5660 | } |
| 4612 | 5661 | |
| 4613 | 5662 | // block for when val1 == false |
| 4614 | | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); |
| 5663 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); |
| 4615 | 5664 | // block for when val1 == true (don't even evaluate the second part) |
| 4616 | | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); |
| 5665 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); |
| 4617 | 5666 | |
| 4618 | 5667 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 4619 | 5668 | |
| 4620 | 5669 | ir_set_cursor_at_end_and_append_block(irb, false_block); |
| 4621 | | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4622 | | if (val2 == irb->codegen->invalid_instruction) |
| 4623 | | return irb->codegen->invalid_instruction; |
| 4624 | | IrBasicBlock *post_val2_block = irb->current_basic_block; |
| 5670 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5671 | if (val2 == irb->codegen->invalid_inst_src) |
| 5672 | return irb->codegen->invalid_inst_src; |
| 5673 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; |
| 4625 | 5674 | |
| 4626 | 5675 | ir_build_br(irb, scope, node, true_block, is_comptime); |
| 4627 | 5676 | |
| 4628 | 5677 | ir_set_cursor_at_end_and_append_block(irb, true_block); |
| 4629 | 5678 | |
| 4630 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2, "IrInstruction *"); |
| 5679 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *"); |
| 4631 | 5680 | incoming_values[0] = val1; |
| 4632 | 5681 | incoming_values[1] = val2; |
| 4633 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5682 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4634 | 5683 | incoming_blocks[0] = post_val1_block; |
| 4635 | 5684 | incoming_blocks[1] = post_val2_block; |
| 4636 | 5685 | |
| 4637 | 5686 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 4638 | 5687 | } |
| 4639 | 5688 | |
| 4640 | | static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5689 | static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4641 | 5690 | assert(node->type == NodeTypeBinOpExpr); |
| 4642 | 5691 | |
| 4643 | | IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 4644 | | if (val1 == irb->codegen->invalid_instruction) |
| 4645 | | return irb->codegen->invalid_instruction; |
| 4646 | | IrBasicBlock *post_val1_block = irb->current_basic_block; |
| 5692 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5693 | if (val1 == irb->codegen->invalid_inst_src) |
| 5694 | return irb->codegen->invalid_inst_src; |
| 5695 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; |
| 4647 | 5696 | |
| 4648 | | IrInstruction *is_comptime; |
| 5697 | IrInstSrc *is_comptime; |
| 4649 | 5698 | if (ir_should_inline(irb->exec, scope)) { |
| 4650 | 5699 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 4651 | 5700 | } else { |
| ... | ... | @@ -4653,34 +5702,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 4653 | 5702 | } |
| 4654 | 5703 | |
| 4655 | 5704 | // block for when val1 == true |
| 4656 | | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); |
| 5705 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); |
| 4657 | 5706 | // block for when val1 == false (don't even evaluate the second part) |
| 4658 | | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); |
| 5707 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); |
| 4659 | 5708 | |
| 4660 | 5709 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 4661 | 5710 | |
| 4662 | 5711 | ir_set_cursor_at_end_and_append_block(irb, true_block); |
| 4663 | | IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4664 | | if (val2 == irb->codegen->invalid_instruction) |
| 4665 | | return irb->codegen->invalid_instruction; |
| 4666 | | IrBasicBlock *post_val2_block = irb->current_basic_block; |
| 5712 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5713 | if (val2 == irb->codegen->invalid_inst_src) |
| 5714 | return irb->codegen->invalid_inst_src; |
| 5715 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; |
| 4667 | 5716 | |
| 4668 | 5717 | ir_build_br(irb, scope, node, false_block, is_comptime); |
| 4669 | 5718 | |
| 4670 | 5719 | ir_set_cursor_at_end_and_append_block(irb, false_block); |
| 4671 | 5720 | |
| 4672 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5721 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 4673 | 5722 | incoming_values[0] = val1; |
| 4674 | 5723 | incoming_values[1] = val2; |
| 4675 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5724 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4676 | 5725 | incoming_blocks[0] = post_val1_block; |
| 4677 | 5726 | incoming_blocks[1] = post_val2_block; |
| 4678 | 5727 | |
| 4679 | 5728 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 4680 | 5729 | } |
| 4681 | 5730 | |
| 4682 | | static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst, |
| 4683 | | IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime) |
| 5731 | static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, |
| 5732 | IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 4684 | 5733 | { |
| 4685 | 5734 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 4686 | 5735 | peer_parent->base.id = ResultLocIdPeerParent; |
| ... | ... | @@ -4690,17 +5739,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction |
| 4690 | 5739 | peer_parent->is_comptime = is_comptime; |
| 4691 | 5740 | peer_parent->parent = parent; |
| 4692 | 5741 | |
| 4693 | | IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop(); |
| 4694 | | ir_assert(popped_inst == cond_br_inst, cond_br_inst); |
| 5742 | IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop(); |
| 5743 | ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base); |
| 4695 | 5744 | |
| 4696 | | ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base); |
| 5745 | ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base); |
| 4697 | 5746 | irb->current_basic_block->instruction_list.append(popped_inst); |
| 4698 | 5747 | |
| 4699 | 5748 | return peer_parent; |
| 4700 | 5749 | } |
| 4701 | 5750 | |
| 4702 | | static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst, |
| 4703 | | IrBasicBlock *else_block, IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime) |
| 5751 | static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, |
| 5752 | IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 4704 | 5753 | { |
| 4705 | 5754 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime); |
| 4706 | 5755 | |
| ... | ... | @@ -4713,7 +5762,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr |
| 4713 | 5762 | return peer_parent; |
| 4714 | 5763 | } |
| 4715 | 5764 | |
| 4716 | | static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 5765 | static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 4717 | 5766 | ResultLoc *result_loc) |
| 4718 | 5767 | { |
| 4719 | 5768 | assert(node->type == NodeTypeBinOpExpr); |
| ... | ... | @@ -4721,73 +5770,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4721 | 5770 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 4722 | 5771 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 4723 | 5772 | |
| 4724 | | IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 4725 | | if (maybe_ptr == irb->codegen->invalid_instruction) |
| 4726 | | return irb->codegen->invalid_instruction; |
| 5773 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 5774 | if (maybe_ptr == irb->codegen->invalid_inst_src) |
| 5775 | return irb->codegen->invalid_inst_src; |
| 4727 | 5776 | |
| 4728 | | IrInstruction *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr); |
| 4729 | | IrInstruction *is_non_null = ir_build_test_nonnull(irb, parent_scope, node, maybe_val); |
| 5777 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr); |
| 5778 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val); |
| 4730 | 5779 | |
| 4731 | | IrInstruction *is_comptime; |
| 5780 | IrInstSrc *is_comptime; |
| 4732 | 5781 | if (ir_should_inline(irb->exec, parent_scope)) { |
| 4733 | 5782 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); |
| 4734 | 5783 | } else { |
| 4735 | 5784 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null); |
| 4736 | 5785 | } |
| 4737 | 5786 | |
| 4738 | | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull"); |
| 4739 | | IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull"); |
| 4740 | | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); |
| 4741 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 5787 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull"); |
| 5788 | IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull"); |
| 5789 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); |
| 5790 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 4742 | 5791 | |
| 4743 | 5792 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, |
| 4744 | 5793 | result_loc, is_comptime); |
| 4745 | 5794 | |
| 4746 | 5795 | ir_set_cursor_at_end_and_append_block(irb, null_block); |
| 4747 | | IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone, |
| 5796 | IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone, |
| 4748 | 5797 | &peer_parent->peers.at(0)->base); |
| 4749 | | if (null_result == irb->codegen->invalid_instruction) |
| 4750 | | return irb->codegen->invalid_instruction; |
| 4751 | | IrBasicBlock *after_null_block = irb->current_basic_block; |
| 5798 | if (null_result == irb->codegen->invalid_inst_src) |
| 5799 | return irb->codegen->invalid_inst_src; |
| 5800 | IrBasicBlockSrc *after_null_block = irb->current_basic_block; |
| 4752 | 5801 | if (!instr_is_unreachable(null_result)) |
| 4753 | 5802 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 4754 | 5803 | |
| 4755 | 5804 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 4756 | | IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false); |
| 4757 | | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 5805 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false); |
| 5806 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 4758 | 5807 | ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); |
| 4759 | | IrBasicBlock *after_ok_block = irb->current_basic_block; |
| 5808 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; |
| 4760 | 5809 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 4761 | 5810 | |
| 4762 | 5811 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 4763 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5812 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 4764 | 5813 | incoming_values[0] = null_result; |
| 4765 | 5814 | incoming_values[1] = unwrapped_payload; |
| 4766 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5815 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4767 | 5816 | incoming_blocks[0] = after_null_block; |
| 4768 | 5817 | incoming_blocks[1] = after_ok_block; |
| 4769 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 5818 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 4770 | 5819 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 4771 | 5820 | } |
| 4772 | 5821 | |
| 4773 | | static IrInstruction *ir_gen_error_union(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 5822 | static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 4774 | 5823 | assert(node->type == NodeTypeBinOpExpr); |
| 4775 | 5824 | |
| 4776 | 5825 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 4777 | 5826 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 4778 | 5827 | |
| 4779 | | IrInstruction *err_set = ir_gen_node(irb, op1_node, parent_scope); |
| 4780 | | if (err_set == irb->codegen->invalid_instruction) |
| 4781 | | return irb->codegen->invalid_instruction; |
| 5828 | IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope); |
| 5829 | if (err_set == irb->codegen->invalid_inst_src) |
| 5830 | return irb->codegen->invalid_inst_src; |
| 4782 | 5831 | |
| 4783 | | IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope); |
| 4784 | | if (payload == irb->codegen->invalid_instruction) |
| 4785 | | return irb->codegen->invalid_instruction; |
| 5832 | IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope); |
| 5833 | if (payload == irb->codegen->invalid_inst_src) |
| 5834 | return irb->codegen->invalid_inst_src; |
| 4786 | 5835 | |
| 4787 | 5836 | return ir_build_error_union(irb, parent_scope, node, err_set, payload); |
| 4788 | 5837 | } |
| 4789 | 5838 | |
| 4790 | | static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5839 | static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4791 | 5840 | assert(node->type == NodeTypeBinOpExpr); |
| 4792 | 5841 | |
| 4793 | 5842 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; |
| ... | ... | @@ -4880,30 +5929,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4880 | 5929 | zig_unreachable(); |
| 4881 | 5930 | } |
| 4882 | 5931 | |
| 4883 | | static IrInstruction *ir_gen_int_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5932 | static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4884 | 5933 | assert(node->type == NodeTypeIntLiteral); |
| 4885 | 5934 | |
| 4886 | 5935 | return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint); |
| 4887 | 5936 | } |
| 4888 | 5937 | |
| 4889 | | static IrInstruction *ir_gen_float_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5938 | static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4890 | 5939 | assert(node->type == NodeTypeFloatLiteral); |
| 4891 | 5940 | |
| 4892 | 5941 | if (node->data.float_literal.overflow) { |
| 4893 | 5942 | add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type")); |
| 4894 | | return irb->codegen->invalid_instruction; |
| 5943 | return irb->codegen->invalid_inst_src; |
| 4895 | 5944 | } |
| 4896 | 5945 | |
| 4897 | 5946 | return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat); |
| 4898 | 5947 | } |
| 4899 | 5948 | |
| 4900 | | static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5949 | static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4901 | 5950 | assert(node->type == NodeTypeCharLiteral); |
| 4902 | 5951 | |
| 4903 | 5952 | return ir_build_const_uint(irb, scope, node, node->data.char_literal.value); |
| 4904 | 5953 | } |
| 4905 | 5954 | |
| 4906 | | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5955 | static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4907 | 5956 | assert(node->type == NodeTypeNullLiteral); |
| 4908 | 5957 | |
| 4909 | 5958 | return ir_build_const_null(irb, scope, node); |
| ... | ... | @@ -4921,11 +5970,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 4921 | 5970 | init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); |
| 4922 | 5971 | tld_var->base.resolution = TldResolutionInvalid; |
| 4923 | 5972 | tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, |
| 4924 | | g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 5973 | g->invalid_inst_gen->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4925 | 5974 | scope_decls->decl_table.put(var_name, &tld_var->base); |
| 4926 | 5975 | } |
| 4927 | 5976 | |
| 4928 | | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5977 | static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4929 | 5978 | Error err; |
| 4930 | 5979 | assert(node->type == NodeTypeSymbol); |
| 4931 | 5980 | |
| ... | ... | @@ -4933,15 +5982,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4933 | 5982 | |
| 4934 | 5983 | if (buf_eql_str(variable_name, "_")) { |
| 4935 | 5984 | if (lval == LValPtr) { |
| 4936 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); |
| 4937 | | const_instruction->base.value->type = get_pointer_to_type(irb->codegen, |
| 5985 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node); |
| 5986 | const_instruction->value = create_const_vals(1); |
| 5987 | const_instruction->value->type = get_pointer_to_type(irb->codegen, |
| 4938 | 5988 | irb->codegen->builtin_types.entry_void, false); |
| 4939 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 4940 | | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 5989 | const_instruction->value->special = ConstValSpecialStatic; |
| 5990 | const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4941 | 5991 | return &const_instruction->base; |
| 4942 | 5992 | } else { |
| 4943 | 5993 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| 4944 | | return irb->codegen->invalid_instruction; |
| 5994 | return irb->codegen->invalid_inst_src; |
| 4945 | 5995 | } |
| 4946 | 5996 | } |
| 4947 | 5997 | |
| ... | ... | @@ -4951,13 +6001,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4951 | 6001 | add_node_error(irb->codegen, node, |
| 4952 | 6002 | buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535", |
| 4953 | 6003 | buf_ptr(variable_name))); |
| 4954 | | return irb->codegen->invalid_instruction; |
| 6004 | return irb->codegen->invalid_inst_src; |
| 4955 | 6005 | } |
| 4956 | 6006 | assert(err == ErrorPrimitiveTypeNotFound); |
| 4957 | 6007 | } else { |
| 4958 | | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 6008 | IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 4959 | 6009 | if (lval == LValPtr) { |
| 4960 | | return ir_build_ref(irb, scope, node, value, false, false); |
| 6010 | return ir_build_ref_src(irb, scope, node, value, false, false); |
| 4961 | 6011 | } else { |
| 4962 | 6012 | return ir_expr_wrap(irb, scope, value, result_loc); |
| 4963 | 6013 | } |
| ... | ... | @@ -4966,7 +6016,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4966 | 6016 | ScopeFnDef *crossed_fndef_scope; |
| 4967 | 6017 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope); |
| 4968 | 6018 | if (var) { |
| 4969 | | IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); |
| 6019 | IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); |
| 4970 | 6020 | if (lval == LValPtr) { |
| 4971 | 6021 | return var_ptr; |
| 4972 | 6022 | } else { |
| ... | ... | @@ -4976,7 +6026,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4976 | 6026 | |
| 4977 | 6027 | Tld *tld = find_decl(irb->codegen, scope, variable_name); |
| 4978 | 6028 | if (tld) { |
| 4979 | | IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval); |
| 6029 | IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval); |
| 4980 | 6030 | if (lval == LValPtr) { |
| 4981 | 6031 | return decl_ref; |
| 4982 | 6032 | } else { |
| ... | ... | @@ -4987,50 +6037,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4987 | 6037 | if (get_container_scope(node->owner)->any_imports_failed) { |
| 4988 | 6038 | // skip the error message since we had a failing import in this file |
| 4989 | 6039 | // if an import breaks we don't need redundant undeclared identifier errors |
| 4990 | | return irb->codegen->invalid_instruction; |
| 6040 | return irb->codegen->invalid_inst_src; |
| 4991 | 6041 | } |
| 4992 | 6042 | |
| 4993 | 6043 | return ir_build_undeclared_identifier(irb, scope, node, variable_name); |
| 4994 | 6044 | } |
| 4995 | 6045 | |
| 4996 | | static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 6046 | static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 4997 | 6047 | ResultLoc *result_loc) |
| 4998 | 6048 | { |
| 4999 | 6049 | assert(node->type == NodeTypeArrayAccessExpr); |
| 5000 | 6050 | |
| 5001 | 6051 | AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; |
| 5002 | | IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr); |
| 5003 | | if (array_ref_instruction == irb->codegen->invalid_instruction) |
| 6052 | IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr); |
| 6053 | if (array_ref_instruction == irb->codegen->invalid_inst_src) |
| 5004 | 6054 | return array_ref_instruction; |
| 5005 | 6055 | |
| 5006 | 6056 | AstNode *subscript_node = node->data.array_access_expr.subscript; |
| 5007 | | IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope); |
| 5008 | | if (subscript_instruction == irb->codegen->invalid_instruction) |
| 6057 | IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope); |
| 6058 | if (subscript_instruction == irb->codegen->invalid_inst_src) |
| 5009 | 6059 | return subscript_instruction; |
| 5010 | 6060 | |
| 5011 | | IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, |
| 6061 | IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, |
| 5012 | 6062 | subscript_instruction, true, PtrLenSingle, nullptr); |
| 5013 | 6063 | if (lval == LValPtr) |
| 5014 | 6064 | return ptr_instruction; |
| 5015 | 6065 | |
| 5016 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 6066 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 5017 | 6067 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 5018 | 6068 | } |
| 5019 | 6069 | |
| 5020 | | static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 6070 | static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5021 | 6071 | assert(node->type == NodeTypeFieldAccessExpr); |
| 5022 | 6072 | |
| 5023 | 6073 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; |
| 5024 | 6074 | Buf *field_name = node->data.field_access_expr.field_name; |
| 5025 | 6075 | |
| 5026 | | IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr); |
| 5027 | | if (container_ref_instruction == irb->codegen->invalid_instruction) |
| 6076 | IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr); |
| 6077 | if (container_ref_instruction == irb->codegen->invalid_inst_src) |
| 5028 | 6078 | return container_ref_instruction; |
| 5029 | 6079 | |
| 5030 | 6080 | return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false); |
| 5031 | 6081 | } |
| 5032 | 6082 | |
| 5033 | | static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) { |
| 6083 | static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) { |
| 5034 | 6084 | assert(node->type == NodeTypeFnCallExpr); |
| 5035 | 6085 | |
| 5036 | 6086 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -5039,26 +6089,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode * |
| 5039 | 6089 | AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3); |
| 5040 | 6090 | |
| 5041 | 6091 | |
| 5042 | | IrInstruction *type_value = ir_gen_node(irb, type_node, scope); |
| 5043 | | if (type_value == irb->codegen->invalid_instruction) |
| 5044 | | return irb->codegen->invalid_instruction; |
| 6092 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); |
| 6093 | if (type_value == irb->codegen->invalid_inst_src) |
| 6094 | return irb->codegen->invalid_inst_src; |
| 5045 | 6095 | |
| 5046 | | IrInstruction *op1 = ir_gen_node(irb, op1_node, scope); |
| 5047 | | if (op1 == irb->codegen->invalid_instruction) |
| 5048 | | return irb->codegen->invalid_instruction; |
| 6096 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); |
| 6097 | if (op1 == irb->codegen->invalid_inst_src) |
| 6098 | return irb->codegen->invalid_inst_src; |
| 5049 | 6099 | |
| 5050 | | IrInstruction *op2 = ir_gen_node(irb, op2_node, scope); |
| 5051 | | if (op2 == irb->codegen->invalid_instruction) |
| 5052 | | return irb->codegen->invalid_instruction; |
| 6100 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); |
| 6101 | if (op2 == irb->codegen->invalid_inst_src) |
| 6102 | return irb->codegen->invalid_inst_src; |
| 5053 | 6103 | |
| 5054 | | IrInstruction *result_ptr = ir_gen_node(irb, result_ptr_node, scope); |
| 5055 | | if (result_ptr == irb->codegen->invalid_instruction) |
| 5056 | | return irb->codegen->invalid_instruction; |
| 6104 | IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope); |
| 6105 | if (result_ptr == irb->codegen->invalid_inst_src) |
| 6106 | return irb->codegen->invalid_inst_src; |
| 5057 | 6107 | |
| 5058 | | return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr); |
| 6108 | return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr); |
| 5059 | 6109 | } |
| 5060 | 6110 | |
| 5061 | | static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 6111 | static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5062 | 6112 | assert(node->type == NodeTypeFnCallExpr); |
| 5063 | 6113 | |
| 5064 | 6114 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -5066,26 +6116,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node |
| 5066 | 6116 | AstNode *op2_node = node->data.fn_call_expr.params.at(2); |
| 5067 | 6117 | AstNode *op3_node = node->data.fn_call_expr.params.at(3); |
| 5068 | 6118 | |
| 5069 | | IrInstruction *type_value = ir_gen_node(irb, type_node, scope); |
| 5070 | | if (type_value == irb->codegen->invalid_instruction) |
| 5071 | | return irb->codegen->invalid_instruction; |
| 6119 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); |
| 6120 | if (type_value == irb->codegen->invalid_inst_src) |
| 6121 | return irb->codegen->invalid_inst_src; |
| 5072 | 6122 | |
| 5073 | | IrInstruction *op1 = ir_gen_node(irb, op1_node, scope); |
| 5074 | | if (op1 == irb->codegen->invalid_instruction) |
| 5075 | | return irb->codegen->invalid_instruction; |
| 6123 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); |
| 6124 | if (op1 == irb->codegen->invalid_inst_src) |
| 6125 | return irb->codegen->invalid_inst_src; |
| 5076 | 6126 | |
| 5077 | | IrInstruction *op2 = ir_gen_node(irb, op2_node, scope); |
| 5078 | | if (op2 == irb->codegen->invalid_instruction) |
| 5079 | | return irb->codegen->invalid_instruction; |
| 6127 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); |
| 6128 | if (op2 == irb->codegen->invalid_inst_src) |
| 6129 | return irb->codegen->invalid_inst_src; |
| 5080 | 6130 | |
| 5081 | | IrInstruction *op3 = ir_gen_node(irb, op3_node, scope); |
| 5082 | | if (op3 == irb->codegen->invalid_instruction) |
| 5083 | | return irb->codegen->invalid_instruction; |
| 6131 | IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope); |
| 6132 | if (op3 == irb->codegen->invalid_inst_src) |
| 6133 | return irb->codegen->invalid_inst_src; |
| 5084 | 6134 | |
| 5085 | | return ir_build_mul_add(irb, scope, node, type_value, op1, op2, op3); |
| 6135 | return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3); |
| 5086 | 6136 | } |
| 5087 | 6137 | |
| 5088 | | static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) { |
| 6138 | static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) { |
| 5089 | 6139 | for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { |
| 5090 | 6140 | if (it_scope->id == ScopeIdDecls) { |
| 5091 | 6141 | ScopeDecls *decls_scope = (ScopeDecls *)it_scope; |
| ... | ... | @@ -5100,7 +6150,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no |
| 5100 | 6150 | zig_unreachable(); |
| 5101 | 6151 | } |
| 5102 | 6152 | |
| 5103 | | static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *await_node, AstNode *call_node, |
| 6153 | static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node, |
| 5104 | 6154 | LVal lval, ResultLoc *result_loc) |
| 5105 | 6155 | { |
| 5106 | 6156 | size_t arg_offset = 3; |
| ... | ... | @@ -5108,71 +6158,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a |
| 5108 | 6158 | add_node_error(irb->codegen, call_node, |
| 5109 | 6159 | buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, |
| 5110 | 6160 | arg_offset, call_node->data.fn_call_expr.params.length)); |
| 5111 | | return irb->codegen->invalid_instruction; |
| 6161 | return irb->codegen->invalid_inst_src; |
| 5112 | 6162 | } |
| 5113 | 6163 | |
| 5114 | 6164 | AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0); |
| 5115 | | IrInstruction *bytes = ir_gen_node(irb, bytes_node, scope); |
| 5116 | | if (bytes == irb->codegen->invalid_instruction) |
| 6165 | IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope); |
| 6166 | if (bytes == irb->codegen->invalid_inst_src) |
| 5117 | 6167 | return bytes; |
| 5118 | 6168 | |
| 5119 | 6169 | AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1); |
| 5120 | | IrInstruction *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope); |
| 5121 | | if (ret_ptr == irb->codegen->invalid_instruction) |
| 6170 | IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope); |
| 6171 | if (ret_ptr == irb->codegen->invalid_inst_src) |
| 5122 | 6172 | return ret_ptr; |
| 5123 | 6173 | |
| 5124 | 6174 | AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2); |
| 5125 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 5126 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 6175 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6176 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 5127 | 6177 | return fn_ref; |
| 5128 | 6178 | |
| 5129 | 6179 | size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset; |
| 5130 | | IrInstruction **args = allocate<IrInstruction*>(arg_count); |
| 6180 | IrInstSrc **args = allocate<IrInstSrc*>(arg_count); |
| 5131 | 6181 | for (size_t i = 0; i < arg_count; i += 1) { |
| 5132 | 6182 | AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset); |
| 5133 | | IrInstruction *arg = ir_gen_node(irb, arg_node, scope); |
| 5134 | | if (arg == irb->codegen->invalid_instruction) |
| 6183 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); |
| 6184 | if (arg == irb->codegen->invalid_inst_src) |
| 5135 | 6185 | return arg; |
| 5136 | 6186 | args[i] = arg; |
| 5137 | 6187 | } |
| 5138 | 6188 | |
| 5139 | 6189 | CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone; |
| 5140 | 6190 | bool is_async_call_builtin = true; |
| 5141 | | IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, |
| 6191 | IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, |
| 5142 | 6192 | ret_ptr, modifier, is_async_call_builtin, bytes, result_loc); |
| 5143 | 6193 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 5144 | 6194 | } |
| 5145 | 6195 | |
| 5146 | | static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 5147 | | AstNode *fn_ref_node, CallModifier modifier, IrInstruction *options, |
| 6196 | static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 6197 | AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options, |
| 5148 | 6198 | AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc) |
| 5149 | 6199 | { |
| 5150 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 5151 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 6200 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6201 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 5152 | 6202 | return fn_ref; |
| 5153 | 6203 | |
| 5154 | | IrInstruction *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref); |
| 6204 | IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref); |
| 5155 | 6205 | |
| 5156 | | IrInstruction **args = allocate<IrInstruction*>(args_len); |
| 6206 | IrInstSrc **args = allocate<IrInstSrc*>(args_len); |
| 5157 | 6207 | for (size_t i = 0; i < args_len; i += 1) { |
| 5158 | 6208 | AstNode *arg_node = args_ptr[i]; |
| 5159 | 6209 | |
| 5160 | | IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i); |
| 5161 | | IrInstruction *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true); |
| 6210 | IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i); |
| 6211 | IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true); |
| 5162 | 6212 | ResultLoc *no_result = no_result_loc(); |
| 5163 | 6213 | ir_build_reset_result(irb, scope, source_node, no_result); |
| 5164 | 6214 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result); |
| 5165 | 6215 | |
| 5166 | | IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base); |
| 5167 | | if (arg == irb->codegen->invalid_instruction) |
| 6216 | IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base); |
| 6217 | if (arg == irb->codegen->invalid_inst_src) |
| 5168 | 6218 | return arg; |
| 5169 | 6219 | |
| 5170 | 6220 | args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast); |
| 5171 | 6221 | } |
| 5172 | 6222 | |
| 5173 | | IrInstruction *fn_call; |
| 6223 | IrInstSrc *fn_call; |
| 5174 | 6224 | if (options != nullptr) { |
| 5175 | | fn_call = ir_build_call_src_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc); |
| 6225 | fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc); |
| 5176 | 6226 | } else { |
| 5177 | 6227 | fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr, |
| 5178 | 6228 | modifier, false, nullptr, result_loc); |
| ... | ... | @@ -5180,7 +6230,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast |
| 5180 | 6230 | return ir_lval_wrap(irb, scope, fn_call, lval, result_loc); |
| 5181 | 6231 | } |
| 5182 | 6232 | |
| 5183 | | static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 6233 | static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 5184 | 6234 | ResultLoc *result_loc) |
| 5185 | 6235 | { |
| 5186 | 6236 | assert(node->type == NodeTypeFnCallExpr); |
| ... | ... | @@ -5192,7 +6242,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5192 | 6242 | if (!entry) { |
| 5193 | 6243 | add_node_error(irb->codegen, node, |
| 5194 | 6244 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); |
| 5195 | | return irb->codegen->invalid_instruction; |
| 6245 | return irb->codegen->invalid_inst_src; |
| 5196 | 6246 | } |
| 5197 | 6247 | |
| 5198 | 6248 | BuiltinFnEntry *builtin_fn = entry->value; |
| ... | ... | @@ -5202,7 +6252,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5202 | 6252 | add_node_error(irb->codegen, node, |
| 5203 | 6253 | buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, |
| 5204 | 6254 | builtin_fn->param_count, actual_param_count)); |
| 5205 | | return irb->codegen->invalid_instruction; |
| 6255 | return irb->codegen->invalid_inst_src; |
| 5206 | 6256 | } |
| 5207 | 6257 | |
| 5208 | 6258 | switch (builtin_fn->id) { |
| ... | ... | @@ -5213,197 +6263,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5213 | 6263 | Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope); |
| 5214 | 6264 | |
| 5215 | 6265 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); |
| 5216 | | IrInstruction *arg = ir_gen_node(irb, arg_node, sub_scope); |
| 5217 | | if (arg == irb->codegen->invalid_instruction) |
| 6266 | IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope); |
| 6267 | if (arg == irb->codegen->invalid_inst_src) |
| 5218 | 6268 | return arg; |
| 5219 | 6269 | |
| 5220 | | IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg); |
| 6270 | IrInstSrc *type_of = ir_build_typeof(irb, scope, node, arg); |
| 5221 | 6271 | return ir_lval_wrap(irb, scope, type_of, lval, result_loc); |
| 5222 | 6272 | } |
| 5223 | 6273 | case BuiltinFnIdSetCold: |
| 5224 | 6274 | { |
| 5225 | 6275 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5226 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5227 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6276 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6277 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5228 | 6278 | return arg0_value; |
| 5229 | 6279 | |
| 5230 | | IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); |
| 6280 | IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); |
| 5231 | 6281 | return ir_lval_wrap(irb, scope, set_cold, lval, result_loc); |
| 5232 | 6282 | } |
| 5233 | 6283 | case BuiltinFnIdSetRuntimeSafety: |
| 5234 | 6284 | { |
| 5235 | 6285 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5236 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5237 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6286 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6287 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5238 | 6288 | return arg0_value; |
| 5239 | 6289 | |
| 5240 | | IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); |
| 6290 | IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); |
| 5241 | 6291 | return ir_lval_wrap(irb, scope, set_safety, lval, result_loc); |
| 5242 | 6292 | } |
| 5243 | 6293 | case BuiltinFnIdSetFloatMode: |
| 5244 | 6294 | { |
| 5245 | 6295 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5246 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5247 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6296 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6297 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5248 | 6298 | return arg0_value; |
| 5249 | 6299 | |
| 5250 | | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 6300 | IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 5251 | 6301 | return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc); |
| 5252 | 6302 | } |
| 5253 | 6303 | case BuiltinFnIdSizeof: |
| 5254 | 6304 | case BuiltinFnIdBitSizeof: |
| 5255 | 6305 | { |
| 5256 | 6306 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5257 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5258 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6307 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6308 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5259 | 6309 | return arg0_value; |
| 5260 | 6310 | |
| 5261 | | IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); |
| 6311 | IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); |
| 5262 | 6312 | return ir_lval_wrap(irb, scope, size_of, lval, result_loc); |
| 5263 | 6313 | } |
| 5264 | 6314 | case BuiltinFnIdImport: |
| 5265 | 6315 | { |
| 5266 | 6316 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5267 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5268 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6317 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6318 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5269 | 6319 | return arg0_value; |
| 5270 | 6320 | |
| 5271 | | IrInstruction *import = ir_build_import(irb, scope, node, arg0_value); |
| 6321 | IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value); |
| 5272 | 6322 | return ir_lval_wrap(irb, scope, import, lval, result_loc); |
| 5273 | 6323 | } |
| 5274 | 6324 | case BuiltinFnIdCImport: |
| 5275 | 6325 | { |
| 5276 | | IrInstruction *c_import = ir_build_c_import(irb, scope, node); |
| 6326 | IrInstSrc *c_import = ir_build_c_import(irb, scope, node); |
| 5277 | 6327 | return ir_lval_wrap(irb, scope, c_import, lval, result_loc); |
| 5278 | 6328 | } |
| 5279 | 6329 | case BuiltinFnIdCInclude: |
| 5280 | 6330 | { |
| 5281 | 6331 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5282 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5283 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6332 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6333 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5284 | 6334 | return arg0_value; |
| 5285 | 6335 | |
| 5286 | 6336 | if (!exec_c_import_buf(irb->exec)) { |
| 5287 | 6337 | add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block")); |
| 5288 | | return irb->codegen->invalid_instruction; |
| 6338 | return irb->codegen->invalid_inst_src; |
| 5289 | 6339 | } |
| 5290 | 6340 | |
| 5291 | | IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value); |
| 6341 | IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value); |
| 5292 | 6342 | return ir_lval_wrap(irb, scope, c_include, lval, result_loc); |
| 5293 | 6343 | } |
| 5294 | 6344 | case BuiltinFnIdCDefine: |
| 5295 | 6345 | { |
| 5296 | 6346 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5297 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5298 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6347 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6348 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5299 | 6349 | return arg0_value; |
| 5300 | 6350 | |
| 5301 | 6351 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5302 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5303 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6352 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6353 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5304 | 6354 | return arg1_value; |
| 5305 | 6355 | |
| 5306 | 6356 | if (!exec_c_import_buf(irb->exec)) { |
| 5307 | 6357 | add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block")); |
| 5308 | | return irb->codegen->invalid_instruction; |
| 6358 | return irb->codegen->invalid_inst_src; |
| 5309 | 6359 | } |
| 5310 | 6360 | |
| 5311 | | IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); |
| 6361 | IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); |
| 5312 | 6362 | return ir_lval_wrap(irb, scope, c_define, lval, result_loc); |
| 5313 | 6363 | } |
| 5314 | 6364 | case BuiltinFnIdCUndef: |
| 5315 | 6365 | { |
| 5316 | 6366 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5317 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5318 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6367 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6368 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5319 | 6369 | return arg0_value; |
| 5320 | 6370 | |
| 5321 | 6371 | if (!exec_c_import_buf(irb->exec)) { |
| 5322 | 6372 | add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block")); |
| 5323 | | return irb->codegen->invalid_instruction; |
| 6373 | return irb->codegen->invalid_inst_src; |
| 5324 | 6374 | } |
| 5325 | 6375 | |
| 5326 | | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 6376 | IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 5327 | 6377 | return ir_lval_wrap(irb, scope, c_undef, lval, result_loc); |
| 5328 | 6378 | } |
| 5329 | 6379 | case BuiltinFnIdCompileErr: |
| 5330 | 6380 | { |
| 5331 | 6381 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5332 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5333 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6382 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6383 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5334 | 6384 | return arg0_value; |
| 5335 | 6385 | |
| 5336 | | IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); |
| 6386 | IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); |
| 5337 | 6387 | return ir_lval_wrap(irb, scope, compile_err, lval, result_loc); |
| 5338 | 6388 | } |
| 5339 | 6389 | case BuiltinFnIdCompileLog: |
| 5340 | 6390 | { |
| 5341 | | IrInstruction **args = allocate<IrInstruction*>(actual_param_count); |
| 6391 | IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count); |
| 5342 | 6392 | |
| 5343 | 6393 | for (size_t i = 0; i < actual_param_count; i += 1) { |
| 5344 | 6394 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); |
| 5345 | 6395 | args[i] = ir_gen_node(irb, arg_node, scope); |
| 5346 | | if (args[i] == irb->codegen->invalid_instruction) |
| 5347 | | return irb->codegen->invalid_instruction; |
| 6396 | if (args[i] == irb->codegen->invalid_inst_src) |
| 6397 | return irb->codegen->invalid_inst_src; |
| 5348 | 6398 | } |
| 5349 | 6399 | |
| 5350 | | IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); |
| 6400 | IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); |
| 5351 | 6401 | return ir_lval_wrap(irb, scope, compile_log, lval, result_loc); |
| 5352 | 6402 | } |
| 5353 | 6403 | case BuiltinFnIdErrName: |
| 5354 | 6404 | { |
| 5355 | 6405 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5356 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5357 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6406 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6407 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5358 | 6408 | return arg0_value; |
| 5359 | 6409 | |
| 5360 | | IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value); |
| 6410 | IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value); |
| 5361 | 6411 | return ir_lval_wrap(irb, scope, err_name, lval, result_loc); |
| 5362 | 6412 | } |
| 5363 | 6413 | case BuiltinFnIdEmbedFile: |
| 5364 | 6414 | { |
| 5365 | 6415 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5366 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5367 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6416 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6417 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5368 | 6418 | return arg0_value; |
| 5369 | 6419 | |
| 5370 | | IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); |
| 6420 | IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); |
| 5371 | 6421 | return ir_lval_wrap(irb, scope, embed_file, lval, result_loc); |
| 5372 | 6422 | } |
| 5373 | 6423 | case BuiltinFnIdCmpxchgWeak: |
| 5374 | 6424 | case BuiltinFnIdCmpxchgStrong: |
| 5375 | 6425 | { |
| 5376 | 6426 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5377 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5378 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6427 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6428 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5379 | 6429 | return arg0_value; |
| 5380 | 6430 | |
| 5381 | 6431 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5382 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5383 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6432 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6433 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5384 | 6434 | return arg1_value; |
| 5385 | 6435 | |
| 5386 | 6436 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5387 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 5388 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 6437 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6438 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5389 | 6439 | return arg2_value; |
| 5390 | 6440 | |
| 5391 | 6441 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 5392 | | IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 5393 | | if (arg3_value == irb->codegen->invalid_instruction) |
| 6442 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6443 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 5394 | 6444 | return arg3_value; |
| 5395 | 6445 | |
| 5396 | 6446 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); |
| 5397 | | IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 5398 | | if (arg4_value == irb->codegen->invalid_instruction) |
| 6447 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 6448 | if (arg4_value == irb->codegen->invalid_inst_src) |
| 5399 | 6449 | return arg4_value; |
| 5400 | 6450 | |
| 5401 | 6451 | AstNode *arg5_node = node->data.fn_call_expr.params.at(5); |
| 5402 | | IrInstruction *arg5_value = ir_gen_node(irb, arg5_node, scope); |
| 5403 | | if (arg5_value == irb->codegen->invalid_instruction) |
| 6452 | IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope); |
| 6453 | if (arg5_value == irb->codegen->invalid_inst_src) |
| 5404 | 6454 | return arg5_value; |
| 5405 | 6455 | |
| 5406 | | IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, |
| 6456 | IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, |
| 5407 | 6457 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak), |
| 5408 | 6458 | result_loc); |
| 5409 | 6459 | return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc); |
| ... | ... | @@ -5411,86 +6461,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5411 | 6461 | case BuiltinFnIdFence: |
| 5412 | 6462 | { |
| 5413 | 6463 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5414 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5415 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6464 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6465 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5416 | 6466 | return arg0_value; |
| 5417 | 6467 | |
| 5418 | | IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered); |
| 6468 | IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value); |
| 5419 | 6469 | return ir_lval_wrap(irb, scope, fence, lval, result_loc); |
| 5420 | 6470 | } |
| 5421 | 6471 | case BuiltinFnIdDivExact: |
| 5422 | 6472 | { |
| 5423 | 6473 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5424 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5425 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6474 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6475 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5426 | 6476 | return arg0_value; |
| 5427 | 6477 | |
| 5428 | 6478 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5429 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5430 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6479 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6480 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5431 | 6481 | return arg1_value; |
| 5432 | 6482 | |
| 5433 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 6483 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 5434 | 6484 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5435 | 6485 | } |
| 5436 | 6486 | case BuiltinFnIdDivTrunc: |
| 5437 | 6487 | { |
| 5438 | 6488 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5439 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5440 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6489 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6490 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5441 | 6491 | return arg0_value; |
| 5442 | 6492 | |
| 5443 | 6493 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5444 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5445 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6494 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6495 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5446 | 6496 | return arg1_value; |
| 5447 | 6497 | |
| 5448 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 6498 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 5449 | 6499 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5450 | 6500 | } |
| 5451 | 6501 | case BuiltinFnIdDivFloor: |
| 5452 | 6502 | { |
| 5453 | 6503 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5454 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5455 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6504 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6505 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5456 | 6506 | return arg0_value; |
| 5457 | 6507 | |
| 5458 | 6508 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5459 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5460 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6509 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6510 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5461 | 6511 | return arg1_value; |
| 5462 | 6512 | |
| 5463 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 6513 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 5464 | 6514 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5465 | 6515 | } |
| 5466 | 6516 | case BuiltinFnIdRem: |
| 5467 | 6517 | { |
| 5468 | 6518 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5469 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5470 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6519 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6520 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5471 | 6521 | return arg0_value; |
| 5472 | 6522 | |
| 5473 | 6523 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5474 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5475 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6524 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6525 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5476 | 6526 | return arg1_value; |
| 5477 | 6527 | |
| 5478 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 6528 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 5479 | 6529 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5480 | 6530 | } |
| 5481 | 6531 | case BuiltinFnIdMod: |
| 5482 | 6532 | { |
| 5483 | 6533 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5484 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5485 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6534 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6535 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5486 | 6536 | return arg0_value; |
| 5487 | 6537 | |
| 5488 | 6538 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5489 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5490 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6539 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6540 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5491 | 6541 | return arg1_value; |
| 5492 | 6542 | |
| 5493 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 6543 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 5494 | 6544 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5495 | 6545 | } |
| 5496 | 6546 | case BuiltinFnIdSqrt: |
| ... | ... | @@ -5509,406 +6559,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5509 | 6559 | case BuiltinFnIdRound: |
| 5510 | 6560 | { |
| 5511 | 6561 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5512 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5513 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6562 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6563 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5514 | 6564 | return arg0_value; |
| 5515 | 6565 | |
| 5516 | | IrInstruction *inst = ir_build_float_op(irb, scope, node, arg0_value, builtin_fn->id); |
| 6566 | IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id); |
| 5517 | 6567 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 5518 | 6568 | } |
| 5519 | 6569 | case BuiltinFnIdTruncate: |
| 5520 | 6570 | { |
| 5521 | 6571 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5522 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5523 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6572 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6573 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5524 | 6574 | return arg0_value; |
| 5525 | 6575 | |
| 5526 | 6576 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5527 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5528 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6577 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6578 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5529 | 6579 | return arg1_value; |
| 5530 | 6580 | |
| 5531 | | IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); |
| 6581 | IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); |
| 5532 | 6582 | return ir_lval_wrap(irb, scope, truncate, lval, result_loc); |
| 5533 | 6583 | } |
| 5534 | 6584 | case BuiltinFnIdIntCast: |
| 5535 | 6585 | { |
| 5536 | 6586 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5537 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5538 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6587 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6588 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5539 | 6589 | return arg0_value; |
| 5540 | 6590 | |
| 5541 | 6591 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5542 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5543 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6592 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6593 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5544 | 6594 | return arg1_value; |
| 5545 | 6595 | |
| 5546 | | IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); |
| 6596 | IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); |
| 5547 | 6597 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5548 | 6598 | } |
| 5549 | 6599 | case BuiltinFnIdFloatCast: |
| 5550 | 6600 | { |
| 5551 | 6601 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5552 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5553 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6602 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6603 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5554 | 6604 | return arg0_value; |
| 5555 | 6605 | |
| 5556 | 6606 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5557 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5558 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6607 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6608 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5559 | 6609 | return arg1_value; |
| 5560 | 6610 | |
| 5561 | | IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); |
| 6611 | IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); |
| 5562 | 6612 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5563 | 6613 | } |
| 5564 | 6614 | case BuiltinFnIdErrSetCast: |
| 5565 | 6615 | { |
| 5566 | 6616 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5567 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5568 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6617 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6618 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5569 | 6619 | return arg0_value; |
| 5570 | 6620 | |
| 5571 | 6621 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5572 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5573 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6622 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6623 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5574 | 6624 | return arg1_value; |
| 5575 | 6625 | |
| 5576 | | IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); |
| 6626 | IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); |
| 5577 | 6627 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5578 | 6628 | } |
| 5579 | 6629 | case BuiltinFnIdFromBytes: |
| 5580 | 6630 | { |
| 5581 | 6631 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5582 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5583 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6632 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6633 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5584 | 6634 | return arg0_value; |
| 5585 | 6635 | |
| 5586 | 6636 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5587 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5588 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6637 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6638 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5589 | 6639 | return arg1_value; |
| 5590 | 6640 | |
| 5591 | | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc); |
| 6641 | IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc); |
| 5592 | 6642 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5593 | 6643 | } |
| 5594 | 6644 | case BuiltinFnIdToBytes: |
| 5595 | 6645 | { |
| 5596 | 6646 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5597 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5598 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6647 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6648 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5599 | 6649 | return arg0_value; |
| 5600 | 6650 | |
| 5601 | | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc); |
| 6651 | IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc); |
| 5602 | 6652 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5603 | 6653 | } |
| 5604 | 6654 | case BuiltinFnIdIntToFloat: |
| 5605 | 6655 | { |
| 5606 | 6656 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5607 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5608 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6657 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6658 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5609 | 6659 | return arg0_value; |
| 5610 | 6660 | |
| 5611 | 6661 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5612 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5613 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6662 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6663 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5614 | 6664 | return arg1_value; |
| 5615 | 6665 | |
| 5616 | | IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); |
| 6666 | IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); |
| 5617 | 6667 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5618 | 6668 | } |
| 5619 | 6669 | case BuiltinFnIdFloatToInt: |
| 5620 | 6670 | { |
| 5621 | 6671 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5622 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5623 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6672 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6673 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5624 | 6674 | return arg0_value; |
| 5625 | 6675 | |
| 5626 | 6676 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5627 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5628 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6677 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6678 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5629 | 6679 | return arg1_value; |
| 5630 | 6680 | |
| 5631 | | IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); |
| 6681 | IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); |
| 5632 | 6682 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5633 | 6683 | } |
| 5634 | 6684 | case BuiltinFnIdErrToInt: |
| 5635 | 6685 | { |
| 5636 | 6686 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5637 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5638 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6687 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6688 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5639 | 6689 | return arg0_value; |
| 5640 | 6690 | |
| 5641 | | IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value); |
| 6691 | IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value); |
| 5642 | 6692 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5643 | 6693 | } |
| 5644 | 6694 | case BuiltinFnIdIntToErr: |
| 5645 | 6695 | { |
| 5646 | 6696 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5647 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5648 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6697 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6698 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5649 | 6699 | return arg0_value; |
| 5650 | 6700 | |
| 5651 | | IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value); |
| 6701 | IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value); |
| 5652 | 6702 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5653 | 6703 | } |
| 5654 | 6704 | case BuiltinFnIdBoolToInt: |
| 5655 | 6705 | { |
| 5656 | 6706 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5657 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5658 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6707 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6708 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5659 | 6709 | return arg0_value; |
| 5660 | 6710 | |
| 5661 | | IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value); |
| 6711 | IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value); |
| 5662 | 6712 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5663 | 6713 | } |
| 5664 | 6714 | case BuiltinFnIdIntType: |
| 5665 | 6715 | { |
| 5666 | 6716 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5667 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5668 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6717 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6718 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5669 | 6719 | return arg0_value; |
| 5670 | 6720 | |
| 5671 | 6721 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5672 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5673 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6722 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6723 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5674 | 6724 | return arg1_value; |
| 5675 | 6725 | |
| 5676 | | IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); |
| 6726 | IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); |
| 5677 | 6727 | return ir_lval_wrap(irb, scope, int_type, lval, result_loc); |
| 5678 | 6728 | } |
| 5679 | 6729 | case BuiltinFnIdVectorType: |
| 5680 | 6730 | { |
| 5681 | 6731 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5682 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5683 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6732 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6733 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5684 | 6734 | return arg0_value; |
| 5685 | 6735 | |
| 5686 | 6736 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5687 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5688 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6737 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6738 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5689 | 6739 | return arg1_value; |
| 5690 | 6740 | |
| 5691 | | IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); |
| 6741 | IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); |
| 5692 | 6742 | return ir_lval_wrap(irb, scope, vector_type, lval, result_loc); |
| 5693 | 6743 | } |
| 5694 | 6744 | case BuiltinFnIdShuffle: |
| 5695 | 6745 | { |
| 5696 | 6746 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5697 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5698 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6747 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6748 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5699 | 6749 | return arg0_value; |
| 5700 | 6750 | |
| 5701 | 6751 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5702 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5703 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6752 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6753 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5704 | 6754 | return arg1_value; |
| 5705 | 6755 | |
| 5706 | 6756 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5707 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 5708 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 6757 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6758 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5709 | 6759 | return arg2_value; |
| 5710 | 6760 | |
| 5711 | 6761 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 5712 | | IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 5713 | | if (arg3_value == irb->codegen->invalid_instruction) |
| 6762 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6763 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 5714 | 6764 | return arg3_value; |
| 5715 | 6765 | |
| 5716 | | IrInstruction *shuffle_vector = ir_build_shuffle_vector(irb, scope, node, |
| 6766 | IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node, |
| 5717 | 6767 | arg0_value, arg1_value, arg2_value, arg3_value); |
| 5718 | 6768 | return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc); |
| 5719 | 6769 | } |
| 5720 | 6770 | case BuiltinFnIdSplat: |
| 5721 | 6771 | { |
| 5722 | 6772 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5723 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5724 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6773 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6774 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5725 | 6775 | return arg0_value; |
| 5726 | 6776 | |
| 5727 | 6777 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5728 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5729 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6778 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6779 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5730 | 6780 | return arg1_value; |
| 5731 | 6781 | |
| 5732 | | IrInstruction *splat = ir_build_splat_src(irb, scope, node, |
| 6782 | IrInstSrc *splat = ir_build_splat_src(irb, scope, node, |
| 5733 | 6783 | arg0_value, arg1_value); |
| 5734 | 6784 | return ir_lval_wrap(irb, scope, splat, lval, result_loc); |
| 5735 | 6785 | } |
| 5736 | 6786 | case BuiltinFnIdMemcpy: |
| 5737 | 6787 | { |
| 5738 | 6788 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5739 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5740 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6789 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6790 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5741 | 6791 | return arg0_value; |
| 5742 | 6792 | |
| 5743 | 6793 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5744 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5745 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6794 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6795 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5746 | 6796 | return arg1_value; |
| 5747 | 6797 | |
| 5748 | 6798 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5749 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 5750 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 6799 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6800 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5751 | 6801 | return arg2_value; |
| 5752 | 6802 | |
| 5753 | | IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6803 | IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5754 | 6804 | return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc); |
| 5755 | 6805 | } |
| 5756 | 6806 | case BuiltinFnIdMemset: |
| 5757 | 6807 | { |
| 5758 | 6808 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5759 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5760 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6809 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6810 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5761 | 6811 | return arg0_value; |
| 5762 | 6812 | |
| 5763 | 6813 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5764 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5765 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6814 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6815 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5766 | 6816 | return arg1_value; |
| 5767 | 6817 | |
| 5768 | 6818 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 5769 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 5770 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 6819 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6820 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5771 | 6821 | return arg2_value; |
| 5772 | 6822 | |
| 5773 | | IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6823 | IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5774 | 6824 | return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc); |
| 5775 | 6825 | } |
| 5776 | 6826 | case BuiltinFnIdMemberCount: |
| 5777 | 6827 | { |
| 5778 | 6828 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5779 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5780 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6829 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6830 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5781 | 6831 | return arg0_value; |
| 5782 | 6832 | |
| 5783 | | IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value); |
| 6833 | IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value); |
| 5784 | 6834 | return ir_lval_wrap(irb, scope, member_count, lval, result_loc); |
| 5785 | 6835 | } |
| 5786 | 6836 | case BuiltinFnIdMemberType: |
| 5787 | 6837 | { |
| 5788 | 6838 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5789 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5790 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6839 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6840 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5791 | 6841 | return arg0_value; |
| 5792 | 6842 | |
| 5793 | 6843 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5794 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5795 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6844 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6845 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5796 | 6846 | return arg1_value; |
| 5797 | 6847 | |
| 5798 | 6848 | |
| 5799 | | IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); |
| 6849 | IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); |
| 5800 | 6850 | return ir_lval_wrap(irb, scope, member_type, lval, result_loc); |
| 5801 | 6851 | } |
| 5802 | 6852 | case BuiltinFnIdMemberName: |
| 5803 | 6853 | { |
| 5804 | 6854 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5805 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5806 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6855 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6856 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5807 | 6857 | return arg0_value; |
| 5808 | 6858 | |
| 5809 | 6859 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5810 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5811 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6860 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6861 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5812 | 6862 | return arg1_value; |
| 5813 | 6863 | |
| 5814 | 6864 | |
| 5815 | | IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); |
| 6865 | IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); |
| 5816 | 6866 | return ir_lval_wrap(irb, scope, member_name, lval, result_loc); |
| 5817 | 6867 | } |
| 5818 | 6868 | case BuiltinFnIdField: |
| 5819 | 6869 | { |
| 5820 | 6870 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5821 | | IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr); |
| 5822 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6871 | IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr); |
| 6872 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5823 | 6873 | return arg0_value; |
| 5824 | 6874 | |
| 5825 | 6875 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5826 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5827 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6876 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6877 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5828 | 6878 | return arg1_value; |
| 5829 | 6879 | |
| 5830 | | IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, |
| 6880 | IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, |
| 5831 | 6881 | arg0_value, arg1_value, false); |
| 5832 | 6882 | |
| 5833 | 6883 | if (lval == LValPtr) |
| 5834 | 6884 | return ptr_instruction; |
| 5835 | 6885 | |
| 5836 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 6886 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 5837 | 6887 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 5838 | 6888 | } |
| 5839 | 6889 | case BuiltinFnIdHasField: |
| 5840 | 6890 | { |
| 5841 | 6891 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5842 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5843 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6892 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6893 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5844 | 6894 | return arg0_value; |
| 5845 | 6895 | |
| 5846 | 6896 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5847 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5848 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 6897 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6898 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5849 | 6899 | return arg1_value; |
| 5850 | 6900 | |
| 5851 | | IrInstruction *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value); |
| 6901 | IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value); |
| 5852 | 6902 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); |
| 5853 | 6903 | } |
| 5854 | 6904 | case BuiltinFnIdTypeInfo: |
| 5855 | 6905 | { |
| 5856 | 6906 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5857 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5858 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6907 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6908 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5859 | 6909 | return arg0_value; |
| 5860 | 6910 | |
| 5861 | | IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value); |
| 6911 | IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value); |
| 5862 | 6912 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); |
| 5863 | 6913 | } |
| 5864 | 6914 | case BuiltinFnIdType: |
| 5865 | 6915 | { |
| 5866 | 6916 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); |
| 5867 | | IrInstruction *arg = ir_gen_node(irb, arg_node, scope); |
| 5868 | | if (arg == irb->codegen->invalid_instruction) |
| 6917 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); |
| 6918 | if (arg == irb->codegen->invalid_inst_src) |
| 5869 | 6919 | return arg; |
| 5870 | 6920 | |
| 5871 | | IrInstruction *type = ir_build_type(irb, scope, node, arg); |
| 6921 | IrInstSrc *type = ir_build_type(irb, scope, node, arg); |
| 5872 | 6922 | return ir_lval_wrap(irb, scope, type, lval, result_loc); |
| 5873 | 6923 | } |
| 5874 | 6924 | case BuiltinFnIdBreakpoint: |
| 5875 | 6925 | return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc); |
| 5876 | 6926 | case BuiltinFnIdReturnAddress: |
| 5877 | | return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc); |
| 6927 | return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc); |
| 5878 | 6928 | case BuiltinFnIdFrameAddress: |
| 5879 | | return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc); |
| 6929 | return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc); |
| 5880 | 6930 | case BuiltinFnIdFrameHandle: |
| 5881 | 6931 | if (!irb->exec->fn_entry) { |
| 5882 | 6932 | add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition")); |
| 5883 | | return irb->codegen->invalid_instruction; |
| 6933 | return irb->codegen->invalid_inst_src; |
| 5884 | 6934 | } |
| 5885 | | return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc); |
| 6935 | return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc); |
| 5886 | 6936 | case BuiltinFnIdFrameType: { |
| 5887 | 6937 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5888 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5889 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6938 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6939 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5890 | 6940 | return arg0_value; |
| 5891 | 6941 | |
| 5892 | | IrInstruction *frame_type = ir_build_frame_type(irb, scope, node, arg0_value); |
| 6942 | IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value); |
| 5893 | 6943 | return ir_lval_wrap(irb, scope, frame_type, lval, result_loc); |
| 5894 | 6944 | } |
| 5895 | 6945 | case BuiltinFnIdFrameSize: { |
| 5896 | 6946 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5897 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5898 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6947 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6948 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5899 | 6949 | return arg0_value; |
| 5900 | 6950 | |
| 5901 | | IrInstruction *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value); |
| 6951 | IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value); |
| 5902 | 6952 | return ir_lval_wrap(irb, scope, frame_size, lval, result_loc); |
| 5903 | 6953 | } |
| 5904 | 6954 | case BuiltinFnIdAlignOf: |
| 5905 | 6955 | { |
| 5906 | 6956 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5907 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5908 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6957 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6958 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5909 | 6959 | return arg0_value; |
| 5910 | 6960 | |
| 5911 | | IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value); |
| 6961 | IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value); |
| 5912 | 6962 | return ir_lval_wrap(irb, scope, align_of, lval, result_loc); |
| 5913 | 6963 | } |
| 5914 | 6964 | case BuiltinFnIdAddWithOverflow: |
| ... | ... | @@ -5924,173 +6974,175 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5924 | 6974 | case BuiltinFnIdTypeName: |
| 5925 | 6975 | { |
| 5926 | 6976 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5927 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5928 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6977 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6978 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5929 | 6979 | return arg0_value; |
| 5930 | 6980 | |
| 5931 | | IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value); |
| 6981 | IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value); |
| 5932 | 6982 | return ir_lval_wrap(irb, scope, type_name, lval, result_loc); |
| 5933 | 6983 | } |
| 5934 | 6984 | case BuiltinFnIdPanic: |
| 5935 | 6985 | { |
| 5936 | 6986 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5937 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5938 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6987 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6988 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5939 | 6989 | return arg0_value; |
| 5940 | 6990 | |
| 5941 | | IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value); |
| 6991 | IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value); |
| 5942 | 6992 | return ir_lval_wrap(irb, scope, panic, lval, result_loc); |
| 5943 | 6993 | } |
| 5944 | 6994 | case BuiltinFnIdPtrCast: |
| 5945 | 6995 | { |
| 5946 | 6996 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 5947 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 5948 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 6997 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6998 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5949 | 6999 | return arg0_value; |
| 5950 | 7000 | |
| 5951 | 7001 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5952 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 5953 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7002 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7003 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5954 | 7004 | return arg1_value; |
| 5955 | 7005 | |
| 5956 | | IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); |
| 7006 | IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); |
| 5957 | 7007 | return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc); |
| 5958 | 7008 | } |
| 5959 | 7009 | case BuiltinFnIdBitCast: |
| 5960 | 7010 | { |
| 5961 | 7011 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); |
| 5962 | | IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 5963 | | if (dest_type == irb->codegen->invalid_instruction) |
| 7012 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 7013 | if (dest_type == irb->codegen->invalid_inst_src) |
| 5964 | 7014 | return dest_type; |
| 5965 | 7015 | |
| 5966 | 7016 | ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1); |
| 5967 | 7017 | result_loc_bit_cast->base.id = ResultLocIdBitCast; |
| 5968 | 7018 | result_loc_bit_cast->base.source_instruction = dest_type; |
| 7019 | result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const; |
| 5969 | 7020 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 5970 | 7021 | result_loc_bit_cast->parent = result_loc; |
| 5971 | 7022 | |
| 5972 | 7023 | ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base); |
| 5973 | 7024 | |
| 5974 | 7025 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5975 | | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 7026 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 5976 | 7027 | &result_loc_bit_cast->base); |
| 5977 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7028 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5978 | 7029 | return arg1_value; |
| 5979 | 7030 | |
| 5980 | | IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 7031 | IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 5981 | 7032 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); |
| 5982 | 7033 | } |
| 5983 | 7034 | case BuiltinFnIdAs: |
| 5984 | 7035 | { |
| 5985 | 7036 | AstNode *dest_type_node = node->data.fn_call_expr.params.at(0); |
| 5986 | | IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 5987 | | if (dest_type == irb->codegen->invalid_instruction) |
| 7037 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 7038 | if (dest_type == irb->codegen->invalid_inst_src) |
| 5988 | 7039 | return dest_type; |
| 5989 | 7040 | |
| 5990 | 7041 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc); |
| 5991 | 7042 | |
| 5992 | 7043 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5993 | | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 7044 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 5994 | 7045 | &result_loc_cast->base); |
| 5995 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7046 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5996 | 7047 | return arg1_value; |
| 5997 | 7048 | |
| 5998 | | IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); |
| 7049 | IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); |
| 5999 | 7050 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6000 | 7051 | } |
| 6001 | 7052 | case BuiltinFnIdIntToPtr: |
| 6002 | 7053 | { |
| 6003 | 7054 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6004 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6005 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7055 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7056 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6006 | 7057 | return arg0_value; |
| 6007 | 7058 | |
| 6008 | 7059 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6009 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6010 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7060 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7061 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6011 | 7062 | return arg1_value; |
| 6012 | 7063 | |
| 6013 | | IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value); |
| 7064 | IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value); |
| 6014 | 7065 | return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc); |
| 6015 | 7066 | } |
| 6016 | 7067 | case BuiltinFnIdPtrToInt: |
| 6017 | 7068 | { |
| 6018 | 7069 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6019 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6020 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7070 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7071 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6021 | 7072 | return arg0_value; |
| 6022 | 7073 | |
| 6023 | | IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value); |
| 7074 | IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value); |
| 6024 | 7075 | return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc); |
| 6025 | 7076 | } |
| 6026 | 7077 | case BuiltinFnIdTagName: |
| 6027 | 7078 | { |
| 6028 | 7079 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6029 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6030 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7080 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7081 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6031 | 7082 | return arg0_value; |
| 6032 | 7083 | |
| 6033 | | IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, arg0_value); |
| 7084 | IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value); |
| 6034 | 7085 | return ir_lval_wrap(irb, scope, tag_name, lval, result_loc); |
| 6035 | 7086 | } |
| 6036 | 7087 | case BuiltinFnIdTagType: |
| 6037 | 7088 | { |
| 6038 | 7089 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6039 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6040 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7090 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7091 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6041 | 7092 | return arg0_value; |
| 6042 | 7093 | |
| 6043 | | IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); |
| 7094 | IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); |
| 6044 | 7095 | return ir_lval_wrap(irb, scope, tag_type, lval, result_loc); |
| 6045 | 7096 | } |
| 6046 | 7097 | case BuiltinFnIdFieldParentPtr: |
| 6047 | 7098 | { |
| 6048 | 7099 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6049 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6050 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7100 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7101 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6051 | 7102 | return arg0_value; |
| 6052 | 7103 | |
| 6053 | 7104 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6054 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6055 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7105 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7106 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6056 | 7107 | return arg1_value; |
| 6057 | 7108 | |
| 6058 | 7109 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 6059 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6060 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 7110 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7111 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6061 | 7112 | return arg2_value; |
| 6062 | 7113 | |
| 6063 | | IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr); |
| 7114 | IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node, |
| 7115 | arg0_value, arg1_value, arg2_value); |
| 6064 | 7116 | return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc); |
| 6065 | 7117 | } |
| 6066 | 7118 | case BuiltinFnIdByteOffsetOf: |
| 6067 | 7119 | { |
| 6068 | 7120 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6069 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6070 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7121 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7122 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6071 | 7123 | return arg0_value; |
| 6072 | 7124 | |
| 6073 | 7125 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6074 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6075 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7126 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7127 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6076 | 7128 | return arg1_value; |
| 6077 | 7129 | |
| 6078 | | IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 7130 | IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 6079 | 7131 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 6080 | 7132 | } |
| 6081 | 7133 | case BuiltinFnIdBitOffsetOf: |
| 6082 | 7134 | { |
| 6083 | 7135 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6084 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6085 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7136 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7137 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6086 | 7138 | return arg0_value; |
| 6087 | 7139 | |
| 6088 | 7140 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6089 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6090 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7141 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7142 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6091 | 7143 | return arg1_value; |
| 6092 | 7144 | |
| 6093 | | IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 7145 | IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 6094 | 7146 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 6095 | 7147 | } |
| 6096 | 7148 | case BuiltinFnIdNewStackCall: |
| ... | ... | @@ -6099,45 +7151,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6099 | 7151 | add_node_error(irb->codegen, node, |
| 6100 | 7152 | buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize, |
| 6101 | 7153 | node->data.fn_call_expr.params.length)); |
| 6102 | | return irb->codegen->invalid_instruction; |
| 7154 | return irb->codegen->invalid_inst_src; |
| 6103 | 7155 | } |
| 6104 | 7156 | |
| 6105 | 7157 | AstNode *new_stack_node = node->data.fn_call_expr.params.at(0); |
| 6106 | | IrInstruction *new_stack = ir_gen_node(irb, new_stack_node, scope); |
| 6107 | | if (new_stack == irb->codegen->invalid_instruction) |
| 7158 | IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope); |
| 7159 | if (new_stack == irb->codegen->invalid_inst_src) |
| 6108 | 7160 | return new_stack; |
| 6109 | 7161 | |
| 6110 | 7162 | AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1); |
| 6111 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6112 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 7163 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 7164 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 6113 | 7165 | return fn_ref; |
| 6114 | 7166 | |
| 6115 | 7167 | size_t arg_count = node->data.fn_call_expr.params.length - 2; |
| 6116 | 7168 | |
| 6117 | | IrInstruction **args = allocate<IrInstruction*>(arg_count); |
| 7169 | IrInstSrc **args = allocate<IrInstSrc*>(arg_count); |
| 6118 | 7170 | for (size_t i = 0; i < arg_count; i += 1) { |
| 6119 | 7171 | AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2); |
| 6120 | 7172 | args[i] = ir_gen_node(irb, arg_node, scope); |
| 6121 | | if (args[i] == irb->codegen->invalid_instruction) |
| 7173 | if (args[i] == irb->codegen->invalid_inst_src) |
| 6122 | 7174 | return args[i]; |
| 6123 | 7175 | } |
| 6124 | 7176 | |
| 6125 | | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, |
| 7177 | IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, |
| 6126 | 7178 | nullptr, CallModifierNone, false, new_stack, result_loc); |
| 6127 | 7179 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 6128 | 7180 | } |
| 6129 | 7181 | case BuiltinFnIdCall: { |
| 6130 | 7182 | // Cast the options parameter to the options type |
| 6131 | 7183 | ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions"); |
| 6132 | | IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 7184 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 6133 | 7185 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); |
| 6134 | 7186 | |
| 6135 | 7187 | AstNode *options_node = node->data.fn_call_expr.params.at(0); |
| 6136 | | IrInstruction *options_inner = ir_gen_node_extra(irb, options_node, scope, |
| 7188 | IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope, |
| 6137 | 7189 | LValNone, &result_loc_cast->base); |
| 6138 | | if (options_inner == irb->codegen->invalid_instruction) |
| 7190 | if (options_inner == irb->codegen->invalid_inst_src) |
| 6139 | 7191 | return options_inner; |
| 6140 | | IrInstruction *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast); |
| 7192 | IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast); |
| 6141 | 7193 | |
| 6142 | 7194 | AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1); |
| 6143 | 7195 | AstNode *args_node = node->data.fn_call_expr.params.at(2); |
| ... | ... | @@ -6153,18 +7205,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6153 | 7205 | } else { |
| 6154 | 7206 | exec_add_error_node(irb->codegen, irb->exec, args_node, |
| 6155 | 7207 | buf_sprintf("TODO: @call with anon struct literal")); |
| 6156 | | return irb->codegen->invalid_instruction; |
| 7208 | return irb->codegen->invalid_inst_src; |
| 6157 | 7209 | } |
| 6158 | 7210 | } else { |
| 6159 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6160 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 7211 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 7212 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 6161 | 7213 | return fn_ref; |
| 6162 | 7214 | |
| 6163 | | IrInstruction *args = ir_gen_node(irb, args_node, scope); |
| 6164 | | if (args == irb->codegen->invalid_instruction) |
| 7215 | IrInstSrc *args = ir_gen_node(irb, args_node, scope); |
| 7216 | if (args == irb->codegen->invalid_inst_src) |
| 6165 | 7217 | return args; |
| 6166 | 7218 | |
| 6167 | | IrInstruction *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc); |
| 7219 | IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc); |
| 6168 | 7220 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 6169 | 7221 | } |
| 6170 | 7222 | } |
| ... | ... | @@ -6173,237 +7225,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6173 | 7225 | case BuiltinFnIdTypeId: |
| 6174 | 7226 | { |
| 6175 | 7227 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6176 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6177 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7228 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7229 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6178 | 7230 | return arg0_value; |
| 6179 | 7231 | |
| 6180 | | IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value); |
| 7232 | IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value); |
| 6181 | 7233 | return ir_lval_wrap(irb, scope, type_id, lval, result_loc); |
| 6182 | 7234 | } |
| 6183 | 7235 | case BuiltinFnIdShlExact: |
| 6184 | 7236 | { |
| 6185 | 7237 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6186 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6187 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7238 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7239 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6188 | 7240 | return arg0_value; |
| 6189 | 7241 | |
| 6190 | 7242 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6191 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6192 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7243 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7244 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6193 | 7245 | return arg1_value; |
| 6194 | 7246 | |
| 6195 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 7247 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 6196 | 7248 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 6197 | 7249 | } |
| 6198 | 7250 | case BuiltinFnIdShrExact: |
| 6199 | 7251 | { |
| 6200 | 7252 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6201 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6202 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7253 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7254 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6203 | 7255 | return arg0_value; |
| 6204 | 7256 | |
| 6205 | 7257 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6206 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6207 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7258 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7259 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6208 | 7260 | return arg1_value; |
| 6209 | 7261 | |
| 6210 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 7262 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 6211 | 7263 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 6212 | 7264 | } |
| 6213 | 7265 | case BuiltinFnIdSetEvalBranchQuota: |
| 6214 | 7266 | { |
| 6215 | 7267 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6216 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6217 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7268 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7269 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6218 | 7270 | return arg0_value; |
| 6219 | 7271 | |
| 6220 | | IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 7272 | IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 6221 | 7273 | return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc); |
| 6222 | 7274 | } |
| 6223 | 7275 | case BuiltinFnIdAlignCast: |
| 6224 | 7276 | { |
| 6225 | 7277 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6226 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6227 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7278 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7279 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6228 | 7280 | return arg0_value; |
| 6229 | 7281 | |
| 6230 | 7282 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6231 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6232 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7283 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7284 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6233 | 7285 | return arg1_value; |
| 6234 | 7286 | |
| 6235 | | IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); |
| 7287 | IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value); |
| 6236 | 7288 | return ir_lval_wrap(irb, scope, align_cast, lval, result_loc); |
| 6237 | 7289 | } |
| 6238 | 7290 | case BuiltinFnIdOpaqueType: |
| 6239 | 7291 | { |
| 6240 | | IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node); |
| 7292 | IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node); |
| 6241 | 7293 | return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc); |
| 6242 | 7294 | } |
| 6243 | 7295 | case BuiltinFnIdThis: |
| 6244 | 7296 | { |
| 6245 | | IrInstruction *this_inst = ir_gen_this(irb, scope, node); |
| 7297 | IrInstSrc *this_inst = ir_gen_this(irb, scope, node); |
| 6246 | 7298 | return ir_lval_wrap(irb, scope, this_inst, lval, result_loc); |
| 6247 | 7299 | } |
| 6248 | 7300 | case BuiltinFnIdSetAlignStack: |
| 6249 | 7301 | { |
| 6250 | 7302 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6251 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6252 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7303 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7304 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6253 | 7305 | return arg0_value; |
| 6254 | 7306 | |
| 6255 | | IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); |
| 7307 | IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); |
| 6256 | 7308 | return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc); |
| 6257 | 7309 | } |
| 6258 | 7310 | case BuiltinFnIdArgType: |
| 6259 | 7311 | { |
| 6260 | 7312 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6261 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6262 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7313 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7314 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6263 | 7315 | return arg0_value; |
| 6264 | 7316 | |
| 6265 | 7317 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6266 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6267 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7318 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7319 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6268 | 7320 | return arg1_value; |
| 6269 | 7321 | |
| 6270 | | IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false); |
| 7322 | IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false); |
| 6271 | 7323 | return ir_lval_wrap(irb, scope, arg_type, lval, result_loc); |
| 6272 | 7324 | } |
| 6273 | 7325 | case BuiltinFnIdExport: |
| 6274 | 7326 | { |
| 6275 | 7327 | // Cast the options parameter to the options type |
| 6276 | 7328 | ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions"); |
| 6277 | | IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 7329 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 6278 | 7330 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); |
| 6279 | 7331 | |
| 6280 | 7332 | AstNode *target_node = node->data.fn_call_expr.params.at(0); |
| 6281 | | IrInstruction *target_value = ir_gen_node(irb, target_node, scope); |
| 6282 | | if (target_value == irb->codegen->invalid_instruction) |
| 7333 | IrInstSrc *target_value = ir_gen_node(irb, target_node, scope); |
| 7334 | if (target_value == irb->codegen->invalid_inst_src) |
| 6283 | 7335 | return target_value; |
| 6284 | 7336 | |
| 6285 | 7337 | AstNode *options_node = node->data.fn_call_expr.params.at(1); |
| 6286 | | IrInstruction *options_value = ir_gen_node_extra(irb, options_node, |
| 7338 | IrInstSrc *options_value = ir_gen_node_extra(irb, options_node, |
| 6287 | 7339 | scope, LValNone, &result_loc_cast->base); |
| 6288 | | if (options_value == irb->codegen->invalid_instruction) |
| 7340 | if (options_value == irb->codegen->invalid_inst_src) |
| 6289 | 7341 | return options_value; |
| 6290 | 7342 | |
| 6291 | | IrInstruction *casted_options_value = ir_build_implicit_cast( |
| 7343 | IrInstSrc *casted_options_value = ir_build_implicit_cast( |
| 6292 | 7344 | irb, scope, options_node, options_value, result_loc_cast); |
| 6293 | 7345 | |
| 6294 | | IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value); |
| 7346 | IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value); |
| 6295 | 7347 | return ir_lval_wrap(irb, scope, ir_export, lval, result_loc); |
| 6296 | 7348 | } |
| 6297 | 7349 | case BuiltinFnIdErrorReturnTrace: |
| 6298 | 7350 | { |
| 6299 | | IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null); |
| 7351 | IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node, |
| 7352 | IrInstErrorReturnTraceNull); |
| 6300 | 7353 | return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc); |
| 6301 | 7354 | } |
| 6302 | 7355 | case BuiltinFnIdAtomicRmw: |
| 6303 | 7356 | { |
| 6304 | 7357 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6305 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6306 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7358 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7359 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6307 | 7360 | return arg0_value; |
| 6308 | 7361 | |
| 6309 | 7362 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6310 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6311 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7363 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7364 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6312 | 7365 | return arg1_value; |
| 6313 | 7366 | |
| 6314 | 7367 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 6315 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6316 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 7368 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7369 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6317 | 7370 | return arg2_value; |
| 6318 | 7371 | |
| 6319 | 7372 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 6320 | | IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6321 | | if (arg3_value == irb->codegen->invalid_instruction) |
| 7373 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 7374 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 6322 | 7375 | return arg3_value; |
| 6323 | 7376 | |
| 6324 | 7377 | AstNode *arg4_node = node->data.fn_call_expr.params.at(4); |
| 6325 | | IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 6326 | | if (arg4_value == irb->codegen->invalid_instruction) |
| 7378 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 7379 | if (arg4_value == irb->codegen->invalid_inst_src) |
| 6327 | 7380 | return arg4_value; |
| 6328 | 7381 | |
| 6329 | | IrInstruction *inst = ir_build_atomic_rmw(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value, |
| 6330 | | arg4_value, |
| 6331 | | // these 2 values don't mean anything since we passed non-null values for other args |
| 6332 | | AtomicRmwOp_xchg, AtomicOrderMonotonic); |
| 7382 | IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node, |
| 7383 | arg0_value, arg1_value, arg2_value, arg3_value, arg4_value); |
| 6333 | 7384 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6334 | 7385 | } |
| 6335 | 7386 | case BuiltinFnIdAtomicLoad: |
| 6336 | 7387 | { |
| 6337 | 7388 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6338 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6339 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7389 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7390 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6340 | 7391 | return arg0_value; |
| 6341 | 7392 | |
| 6342 | 7393 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6343 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6344 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7394 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7395 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6345 | 7396 | return arg1_value; |
| 6346 | 7397 | |
| 6347 | 7398 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 6348 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6349 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 7399 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7400 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6350 | 7401 | return arg2_value; |
| 6351 | 7402 | |
| 6352 | | IrInstruction *inst = ir_build_atomic_load(irb, scope, node, arg0_value, arg1_value, arg2_value, |
| 6353 | | // this value does not mean anything since we passed non-null values for other arg |
| 6354 | | AtomicOrderMonotonic); |
| 7403 | IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6355 | 7404 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6356 | 7405 | } |
| 6357 | 7406 | case BuiltinFnIdAtomicStore: |
| 6358 | 7407 | { |
| 6359 | 7408 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6360 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6361 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7409 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7410 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6362 | 7411 | return arg0_value; |
| 6363 | 7412 | |
| 6364 | 7413 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6365 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6366 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7414 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7415 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6367 | 7416 | return arg1_value; |
| 6368 | 7417 | |
| 6369 | 7418 | AstNode *arg2_node = node->data.fn_call_expr.params.at(2); |
| 6370 | | IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6371 | | if (arg2_value == irb->codegen->invalid_instruction) |
| 7419 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7420 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6372 | 7421 | return arg2_value; |
| 6373 | 7422 | |
| 6374 | 7423 | AstNode *arg3_node = node->data.fn_call_expr.params.at(3); |
| 6375 | | IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6376 | | if (arg3_value == irb->codegen->invalid_instruction) |
| 7424 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 7425 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 6377 | 7426 | return arg3_value; |
| 6378 | 7427 | |
| 6379 | | IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value, |
| 6380 | | // this value does not mean anything since we passed non-null values for other arg |
| 6381 | | AtomicOrderMonotonic); |
| 7428 | IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value, |
| 7429 | arg2_value, arg3_value); |
| 6382 | 7430 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6383 | 7431 | } |
| 6384 | 7432 | case BuiltinFnIdIntToEnum: |
| 6385 | 7433 | { |
| 6386 | 7434 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6387 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6388 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7435 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7436 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6389 | 7437 | return arg0_value; |
| 6390 | 7438 | |
| 6391 | 7439 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6392 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6393 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7440 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7441 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6394 | 7442 | return arg1_value; |
| 6395 | 7443 | |
| 6396 | | IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value); |
| 7444 | IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value); |
| 6397 | 7445 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6398 | 7446 | } |
| 6399 | 7447 | case BuiltinFnIdEnumToInt: |
| 6400 | 7448 | { |
| 6401 | 7449 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6402 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6403 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7450 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7451 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6404 | 7452 | return arg0_value; |
| 6405 | 7453 | |
| 6406 | | IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value); |
| 7454 | IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value); |
| 6407 | 7455 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6408 | 7456 | } |
| 6409 | 7457 | case BuiltinFnIdCtz: |
| ... | ... | @@ -6413,16 +7461,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6413 | 7461 | case BuiltinFnIdBitReverse: |
| 6414 | 7462 | { |
| 6415 | 7463 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6416 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6417 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7464 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7465 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6418 | 7466 | return arg0_value; |
| 6419 | 7467 | |
| 6420 | 7468 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6421 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6422 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7469 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7470 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6423 | 7471 | return arg1_value; |
| 6424 | 7472 | |
| 6425 | | IrInstruction *result; |
| 7473 | IrInstSrc *result; |
| 6426 | 7474 | switch (builtin_fn->id) { |
| 6427 | 7475 | case BuiltinFnIdCtz: |
| 6428 | 7476 | result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value); |
| ... | ... | @@ -6447,28 +7495,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6447 | 7495 | case BuiltinFnIdHasDecl: |
| 6448 | 7496 | { |
| 6449 | 7497 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 6450 | | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6451 | | if (arg0_value == irb->codegen->invalid_instruction) |
| 7498 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7499 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6452 | 7500 | return arg0_value; |
| 6453 | 7501 | |
| 6454 | 7502 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 6455 | | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6456 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7503 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7504 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6457 | 7505 | return arg1_value; |
| 6458 | 7506 | |
| 6459 | | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 7507 | IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 6460 | 7508 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); |
| 6461 | 7509 | } |
| 6462 | 7510 | case BuiltinFnIdUnionInit: |
| 6463 | 7511 | { |
| 6464 | 7512 | AstNode *union_type_node = node->data.fn_call_expr.params.at(0); |
| 6465 | | IrInstruction *union_type_inst = ir_gen_node(irb, union_type_node, scope); |
| 6466 | | if (union_type_inst == irb->codegen->invalid_instruction) |
| 7513 | IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope); |
| 7514 | if (union_type_inst == irb->codegen->invalid_inst_src) |
| 6467 | 7515 | return union_type_inst; |
| 6468 | 7516 | |
| 6469 | 7517 | AstNode *name_node = node->data.fn_call_expr.params.at(1); |
| 6470 | | IrInstruction *name_inst = ir_gen_node(irb, name_node, scope); |
| 6471 | | if (name_inst == irb->codegen->invalid_instruction) |
| 7518 | IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope); |
| 7519 | if (name_inst == irb->codegen->invalid_inst_src) |
| 6472 | 7520 | return name_inst; |
| 6473 | 7521 | |
| 6474 | 7522 | AstNode *init_node = node->data.fn_call_expr.params.at(2); |
| ... | ... | @@ -6480,7 +7528,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6480 | 7528 | zig_unreachable(); |
| 6481 | 7529 | } |
| 6482 | 7530 | |
| 6483 | | static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7531 | static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6484 | 7532 | ResultLoc *result_loc) |
| 6485 | 7533 | { |
| 6486 | 7534 | assert(node->type == NodeTypeFnCallExpr); |
| ... | ... | @@ -6493,16 +7541,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node |
| 6493 | 7541 | nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc); |
| 6494 | 7542 | } |
| 6495 | 7543 | |
| 6496 | | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7544 | static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6497 | 7545 | ResultLoc *result_loc) |
| 6498 | 7546 | { |
| 6499 | 7547 | assert(node->type == NodeTypeIfBoolExpr); |
| 6500 | 7548 | |
| 6501 | | IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); |
| 6502 | | if (condition == irb->codegen->invalid_instruction) |
| 6503 | | return irb->codegen->invalid_instruction; |
| 7549 | IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); |
| 7550 | if (condition == irb->codegen->invalid_inst_src) |
| 7551 | return irb->codegen->invalid_inst_src; |
| 6504 | 7552 | |
| 6505 | | IrInstruction *is_comptime; |
| 7553 | IrInstSrc *is_comptime; |
| 6506 | 7554 | if (ir_should_inline(irb->exec, scope)) { |
| 6507 | 7555 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 6508 | 7556 | } else { |
| ... | ... | @@ -6512,11 +7560,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 6512 | 7560 | AstNode *then_node = node->data.if_bool_expr.then_block; |
| 6513 | 7561 | AstNode *else_node = node->data.if_bool_expr.else_node; |
| 6514 | 7562 | |
| 6515 | | IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then"); |
| 6516 | | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else"); |
| 6517 | | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf"); |
| 7563 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then"); |
| 7564 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else"); |
| 7565 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf"); |
| 6518 | 7566 | |
| 6519 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition, |
| 7567 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition, |
| 6520 | 7568 | then_block, else_block, is_comptime); |
| 6521 | 7569 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 6522 | 7570 | result_loc, is_comptime); |
| ... | ... | @@ -6524,70 +7572,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 6524 | 7572 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 6525 | 7573 | |
| 6526 | 7574 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 6527 | | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval, |
| 7575 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval, |
| 6528 | 7576 | &peer_parent->peers.at(0)->base); |
| 6529 | | if (then_expr_result == irb->codegen->invalid_instruction) |
| 6530 | | return irb->codegen->invalid_instruction; |
| 6531 | | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 7577 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7578 | return irb->codegen->invalid_inst_src; |
| 7579 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 6532 | 7580 | if (!instr_is_unreachable(then_expr_result)) |
| 6533 | 7581 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 6534 | 7582 | |
| 6535 | 7583 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 6536 | | IrInstruction *else_expr_result; |
| 7584 | IrInstSrc *else_expr_result; |
| 6537 | 7585 | if (else_node) { |
| 6538 | 7586 | else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); |
| 6539 | | if (else_expr_result == irb->codegen->invalid_instruction) |
| 6540 | | return irb->codegen->invalid_instruction; |
| 7587 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7588 | return irb->codegen->invalid_inst_src; |
| 6541 | 7589 | } else { |
| 6542 | 7590 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 6543 | 7591 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 6544 | 7592 | } |
| 6545 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 7593 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 6546 | 7594 | if (!instr_is_unreachable(else_expr_result)) |
| 6547 | 7595 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 6548 | 7596 | |
| 6549 | 7597 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 6550 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 7598 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 6551 | 7599 | incoming_values[0] = then_expr_result; |
| 6552 | 7600 | incoming_values[1] = else_expr_result; |
| 6553 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 7601 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 6554 | 7602 | incoming_blocks[0] = after_then_block; |
| 6555 | 7603 | incoming_blocks[1] = after_else_block; |
| 6556 | 7604 | |
| 6557 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7605 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 6558 | 7606 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 6559 | 7607 | } |
| 6560 | 7608 | |
| 6561 | | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| 7609 | static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| 6562 | 7610 | assert(node->type == NodeTypePrefixOpExpr); |
| 6563 | 7611 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 6564 | 7612 | |
| 6565 | | IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 6566 | | if (value == irb->codegen->invalid_instruction) |
| 7613 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 7614 | if (value == irb->codegen->invalid_inst_src) |
| 6567 | 7615 | return value; |
| 6568 | 7616 | |
| 6569 | 7617 | return ir_build_un_op(irb, scope, node, op_id, value); |
| 6570 | 7618 | } |
| 6571 | 7619 | |
| 6572 | | static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 7620 | static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 6573 | 7621 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone); |
| 6574 | 7622 | } |
| 6575 | 7623 | |
| 6576 | | static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) { |
| 6577 | | if (inst == irb->codegen->invalid_instruction) return inst; |
| 6578 | | ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc); |
| 7624 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) { |
| 7625 | if (inst == irb->codegen->invalid_inst_src) return inst; |
| 7626 | ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc); |
| 6579 | 7627 | return inst; |
| 6580 | 7628 | } |
| 6581 | 7629 | |
| 6582 | | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, |
| 7630 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, |
| 6583 | 7631 | ResultLoc *result_loc) |
| 6584 | 7632 | { |
| 6585 | 7633 | // This logic must be kept in sync with |
| 6586 | 7634 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 6587 | | if (value == irb->codegen->invalid_instruction || |
| 7635 | if (value == irb->codegen->invalid_inst_src || |
| 6588 | 7636 | instr_is_unreachable(value) || |
| 6589 | | value->source_node->type == NodeTypeDefer || |
| 6590 | | value->id == IrInstructionIdDeclVarSrc) |
| 7637 | value->base.source_node->type == NodeTypeDefer || |
| 7638 | value->id == IrInstSrcIdDeclVar) |
| 6591 | 7639 | { |
| 6592 | 7640 | return value; |
| 6593 | 7641 | } |
| ... | ... | @@ -6595,7 +7643,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction * |
| 6595 | 7643 | if (lval == LValPtr) { |
| 6596 | 7644 | // We needed a pointer to a value, but we got a value. So we create |
| 6597 | 7645 | // an instruction which just makes a pointer of it. |
| 6598 | | return ir_build_ref(irb, scope, value->source_node, value, false, false); |
| 7646 | return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false); |
| 6599 | 7647 | } else if (result_loc != nullptr) { |
| 6600 | 7648 | return ir_expr_wrap(irb, scope, value, result_loc); |
| 6601 | 7649 | } else { |
| ... | ... | @@ -6618,7 +7666,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) { |
| 6618 | 7666 | } |
| 6619 | 7667 | } |
| 6620 | 7668 | |
| 6621 | | static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7669 | static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6622 | 7670 | assert(node->type == NodeTypePointerType); |
| 6623 | 7671 | |
| 6624 | 7672 | PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id); |
| ... | ... | @@ -6630,26 +7678,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6630 | 7678 | AstNode *expr_node = node->data.pointer_type.op_expr; |
| 6631 | 7679 | AstNode *align_expr = node->data.pointer_type.align_expr; |
| 6632 | 7680 | |
| 6633 | | IrInstruction *sentinel; |
| 7681 | IrInstSrc *sentinel; |
| 6634 | 7682 | if (sentinel_expr != nullptr) { |
| 6635 | 7683 | sentinel = ir_gen_node(irb, sentinel_expr, scope); |
| 6636 | | if (sentinel == irb->codegen->invalid_instruction) |
| 7684 | if (sentinel == irb->codegen->invalid_inst_src) |
| 6637 | 7685 | return sentinel; |
| 6638 | 7686 | } else { |
| 6639 | 7687 | sentinel = nullptr; |
| 6640 | 7688 | } |
| 6641 | 7689 | |
| 6642 | | IrInstruction *align_value; |
| 7690 | IrInstSrc *align_value; |
| 6643 | 7691 | if (align_expr != nullptr) { |
| 6644 | 7692 | align_value = ir_gen_node(irb, align_expr, scope); |
| 6645 | | if (align_value == irb->codegen->invalid_instruction) |
| 7693 | if (align_value == irb->codegen->invalid_inst_src) |
| 6646 | 7694 | return align_value; |
| 6647 | 7695 | } else { |
| 6648 | 7696 | align_value = nullptr; |
| 6649 | 7697 | } |
| 6650 | 7698 | |
| 6651 | | IrInstruction *child_type = ir_gen_node(irb, expr_node, scope); |
| 6652 | | if (child_type == irb->codegen->invalid_instruction) |
| 7699 | IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope); |
| 7700 | if (child_type == irb->codegen->invalid_inst_src) |
| 6653 | 7701 | return child_type; |
| 6654 | 7702 | |
| 6655 | 7703 | uint32_t bit_offset_start = 0; |
| ... | ... | @@ -6659,7 +7707,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6659 | 7707 | bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10); |
| 6660 | 7708 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6661 | 7709 | buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf))); |
| 6662 | | return irb->codegen->invalid_instruction; |
| 7710 | return irb->codegen->invalid_inst_src; |
| 6663 | 7711 | } |
| 6664 | 7712 | bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start); |
| 6665 | 7713 | } |
| ... | ... | @@ -6671,7 +7719,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6671 | 7719 | bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10); |
| 6672 | 7720 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6673 | 7721 | buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf))); |
| 6674 | | return irb->codegen->invalid_instruction; |
| 7722 | return irb->codegen->invalid_inst_src; |
| 6675 | 7723 | } |
| 6676 | 7724 | host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes); |
| 6677 | 7725 | } |
| ... | ... | @@ -6679,43 +7727,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6679 | 7727 | if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) { |
| 6680 | 7728 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6681 | 7729 | buf_sprintf("bit offset starts after end of host integer")); |
| 6682 | | return irb->codegen->invalid_instruction; |
| 7730 | return irb->codegen->invalid_inst_src; |
| 6683 | 7731 | } |
| 6684 | 7732 | |
| 6685 | 7733 | return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile, |
| 6686 | 7734 | ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero); |
| 6687 | 7735 | } |
| 6688 | 7736 | |
| 6689 | | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 7737 | static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 6690 | 7738 | AstNode *expr_node, LVal lval, ResultLoc *result_loc) |
| 6691 | 7739 | { |
| 6692 | | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 6693 | | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 6694 | | return irb->codegen->invalid_instruction; |
| 7740 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 7741 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 7742 | return irb->codegen->invalid_inst_src; |
| 6695 | 7743 | |
| 6696 | | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true, false); |
| 6697 | | if (payload_ptr == irb->codegen->invalid_instruction) |
| 6698 | | return irb->codegen->invalid_instruction; |
| 7744 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false); |
| 7745 | if (payload_ptr == irb->codegen->invalid_inst_src) |
| 7746 | return irb->codegen->invalid_inst_src; |
| 6699 | 7747 | |
| 6700 | 7748 | if (lval == LValPtr) |
| 6701 | 7749 | return payload_ptr; |
| 6702 | 7750 | |
| 6703 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 7751 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 6704 | 7752 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 6705 | 7753 | } |
| 6706 | 7754 | |
| 6707 | | static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7755 | static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6708 | 7756 | assert(node->type == NodeTypePrefixOpExpr); |
| 6709 | 7757 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 6710 | 7758 | |
| 6711 | | IrInstruction *value = ir_gen_node(irb, expr_node, scope); |
| 6712 | | if (value == irb->codegen->invalid_instruction) |
| 6713 | | return irb->codegen->invalid_instruction; |
| 7759 | IrInstSrc *value = ir_gen_node(irb, expr_node, scope); |
| 7760 | if (value == irb->codegen->invalid_inst_src) |
| 7761 | return irb->codegen->invalid_inst_src; |
| 6714 | 7762 | |
| 6715 | 7763 | return ir_build_bool_not(irb, scope, node, value); |
| 6716 | 7764 | } |
| 6717 | 7765 | |
| 6718 | | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7766 | static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6719 | 7767 | ResultLoc *result_loc) |
| 6720 | 7768 | { |
| 6721 | 7769 | assert(node->type == NodeTypePrefixOpExpr); |
| ... | ... | @@ -6743,12 +7791,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 6743 | 7791 | zig_unreachable(); |
| 6744 | 7792 | } |
| 6745 | 7793 | |
| 6746 | | static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 6747 | | IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node, |
| 7794 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 7795 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 6748 | 7796 | LVal lval, ResultLoc *parent_result_loc) |
| 6749 | 7797 | { |
| 6750 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type); |
| 6751 | | IrInstruction *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr, |
| 7798 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type); |
| 7799 | IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr, |
| 6752 | 7800 | field_name, true); |
| 6753 | 7801 | |
| 6754 | 7802 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| ... | ... | @@ -6757,18 +7805,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo |
| 6757 | 7805 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 6758 | 7806 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6759 | 7807 | |
| 6760 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7808 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6761 | 7809 | &result_loc_inst->base); |
| 6762 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7810 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6763 | 7811 | return expr_value; |
| 6764 | 7812 | |
| 6765 | | IrInstruction *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type, |
| 7813 | IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type, |
| 6766 | 7814 | field_name, field_ptr, container_ptr); |
| 6767 | 7815 | |
| 6768 | 7816 | return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc); |
| 6769 | 7817 | } |
| 6770 | 7818 | |
| 6771 | | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7819 | static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6772 | 7820 | ResultLoc *parent_result_loc) |
| 6773 | 7821 | { |
| 6774 | 7822 | assert(node->type == NodeTypeContainerInitExpr); |
| ... | ... | @@ -6780,42 +7828,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6780 | 7828 | ResultLoc *child_result_loc; |
| 6781 | 7829 | AstNode *init_array_type_source_node; |
| 6782 | 7830 | if (container_init_expr->type != nullptr) { |
| 6783 | | IrInstruction *container_type; |
| 7831 | IrInstSrc *container_type; |
| 6784 | 7832 | if (container_init_expr->type->type == NodeTypeInferredArrayType) { |
| 6785 | 7833 | if (kind == ContainerInitKindStruct) { |
| 6786 | 7834 | add_node_error(irb->codegen, container_init_expr->type, |
| 6787 | 7835 | buf_sprintf("initializing array with struct syntax")); |
| 6788 | | return irb->codegen->invalid_instruction; |
| 7836 | return irb->codegen->invalid_inst_src; |
| 6789 | 7837 | } |
| 6790 | | IrInstruction *sentinel; |
| 7838 | IrInstSrc *sentinel; |
| 6791 | 7839 | if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) { |
| 6792 | 7840 | sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope); |
| 6793 | | if (sentinel == irb->codegen->invalid_instruction) |
| 7841 | if (sentinel == irb->codegen->invalid_inst_src) |
| 6794 | 7842 | return sentinel; |
| 6795 | 7843 | } else { |
| 6796 | 7844 | sentinel = nullptr; |
| 6797 | 7845 | } |
| 6798 | 7846 | |
| 6799 | | IrInstruction *elem_type = ir_gen_node(irb, |
| 7847 | IrInstSrc *elem_type = ir_gen_node(irb, |
| 6800 | 7848 | container_init_expr->type->data.inferred_array_type.child_type, scope); |
| 6801 | | if (elem_type == irb->codegen->invalid_instruction) |
| 7849 | if (elem_type == irb->codegen->invalid_inst_src) |
| 6802 | 7850 | return elem_type; |
| 6803 | 7851 | size_t item_count = container_init_expr->entries.length; |
| 6804 | | IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 7852 | IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 6805 | 7853 | container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type); |
| 6806 | 7854 | } else { |
| 6807 | 7855 | container_type = ir_gen_node(irb, container_init_expr->type, scope); |
| 6808 | | if (container_type == irb->codegen->invalid_instruction) |
| 7856 | if (container_type == irb->codegen->invalid_inst_src) |
| 6809 | 7857 | return container_type; |
| 6810 | 7858 | } |
| 6811 | 7859 | |
| 6812 | 7860 | result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc); |
| 6813 | 7861 | child_result_loc = &result_loc_cast->base; |
| 6814 | | init_array_type_source_node = container_type->source_node; |
| 7862 | init_array_type_source_node = container_type->base.source_node; |
| 6815 | 7863 | } else { |
| 6816 | 7864 | child_result_loc = parent_result_loc; |
| 6817 | 7865 | if (parent_result_loc->source_instruction != nullptr) { |
| 6818 | | init_array_type_source_node = parent_result_loc->source_instruction->source_node; |
| 7866 | init_array_type_source_node = parent_result_loc->source_instruction->base.source_node; |
| 6819 | 7867 | } else { |
| 6820 | 7868 | init_array_type_source_node = node; |
| 6821 | 7869 | } |
| ... | ... | @@ -6823,11 +7871,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6823 | 7871 | |
| 6824 | 7872 | switch (kind) { |
| 6825 | 7873 | case ContainerInitKindStruct: { |
| 6826 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 7874 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6827 | 7875 | nullptr); |
| 6828 | 7876 | |
| 6829 | 7877 | size_t field_count = container_init_expr->entries.length; |
| 6830 | | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count); |
| 7878 | IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count); |
| 6831 | 7879 | for (size_t i = 0; i < field_count; i += 1) { |
| 6832 | 7880 | AstNode *entry_node = container_init_expr->entries.at(i); |
| 6833 | 7881 | assert(entry_node->type == NodeTypeStructValueField); |
| ... | ... | @@ -6835,7 +7883,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6835 | 7883 | Buf *name = entry_node->data.struct_val_field.name; |
| 6836 | 7884 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 6837 | 7885 | |
| 6838 | | IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true); |
| 7886 | IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true); |
| 6839 | 7887 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6840 | 7888 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 6841 | 7889 | result_loc_inst->base.source_instruction = field_ptr; |
| ... | ... | @@ -6843,16 +7891,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6843 | 7891 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 6844 | 7892 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6845 | 7893 | |
| 6846 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7894 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6847 | 7895 | &result_loc_inst->base); |
| 6848 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7896 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6849 | 7897 | return expr_value; |
| 6850 | 7898 | |
| 6851 | 7899 | fields[i].name = name; |
| 6852 | 7900 | fields[i].source_node = entry_node; |
| 6853 | 7901 | fields[i].result_loc = field_ptr; |
| 6854 | 7902 | } |
| 6855 | | IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count, |
| 7903 | IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count, |
| 6856 | 7904 | fields, container_ptr); |
| 6857 | 7905 | |
| 6858 | 7906 | if (result_loc_cast != nullptr) { |
| ... | ... | @@ -6863,15 +7911,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6863 | 7911 | case ContainerInitKindArray: { |
| 6864 | 7912 | size_t item_count = container_init_expr->entries.length; |
| 6865 | 7913 | |
| 6866 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 7914 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6867 | 7915 | nullptr); |
| 6868 | 7916 | |
| 6869 | | IrInstruction **result_locs = allocate<IrInstruction *>(item_count); |
| 7917 | IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count); |
| 6870 | 7918 | for (size_t i = 0; i < item_count; i += 1) { |
| 6871 | 7919 | AstNode *expr_node = container_init_expr->entries.at(i); |
| 6872 | 7920 | |
| 6873 | | IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i); |
| 6874 | | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, |
| 7921 | IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i); |
| 7922 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, |
| 6875 | 7923 | elem_index, false, PtrLenSingle, init_array_type_source_node); |
| 6876 | 7924 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6877 | 7925 | result_loc_inst->base.id = ResultLocIdInstruction; |
| ... | ... | @@ -6880,14 +7928,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6880 | 7928 | ir_ref_instruction(elem_ptr, irb->current_basic_block); |
| 6881 | 7929 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6882 | 7930 | |
| 6883 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7931 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6884 | 7932 | &result_loc_inst->base); |
| 6885 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7933 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6886 | 7934 | return expr_value; |
| 6887 | 7935 | |
| 6888 | 7936 | result_locs[i] = elem_ptr; |
| 6889 | 7937 | } |
| 6890 | | IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count, |
| 7938 | IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count, |
| 6891 | 7939 | result_locs, container_ptr, init_array_type_source_node); |
| 6892 | 7940 | if (result_loc_cast != nullptr) { |
| 6893 | 7941 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); |
| ... | ... | @@ -6898,19 +7946,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6898 | 7946 | zig_unreachable(); |
| 6899 | 7947 | } |
| 6900 | 7948 | |
| 6901 | | static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) { |
| 7949 | static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) { |
| 6902 | 7950 | ResultLocVar *result_loc_var = allocate<ResultLocVar>(1); |
| 6903 | 7951 | result_loc_var->base.id = ResultLocIdVar; |
| 6904 | 7952 | result_loc_var->base.source_instruction = alloca; |
| 6905 | 7953 | result_loc_var->base.allow_write_through_const = true; |
| 6906 | 7954 | result_loc_var->var = var; |
| 6907 | 7955 | |
| 6908 | | ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base); |
| 7956 | ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base); |
| 6909 | 7957 | |
| 6910 | 7958 | return result_loc_var; |
| 6911 | 7959 | } |
| 6912 | 7960 | |
| 6913 | | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, |
| 7961 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, |
| 6914 | 7962 | ResultLoc *parent_result_loc) |
| 6915 | 7963 | { |
| 6916 | 7964 | ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1); |
| ... | ... | @@ -6920,37 +7968,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de |
| 6920 | 7968 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 6921 | 7969 | result_loc_cast->parent = parent_result_loc; |
| 6922 | 7970 | |
| 6923 | | ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base); |
| 7971 | ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base); |
| 6924 | 7972 | |
| 6925 | 7973 | return result_loc_cast; |
| 6926 | 7974 | } |
| 6927 | 7975 | |
| 6928 | | static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 6929 | | IrInstruction *init, const char *name_hint, IrInstruction *is_comptime) |
| 7976 | static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 7977 | IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime) |
| 6930 | 7978 | { |
| 6931 | | IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); |
| 7979 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); |
| 6932 | 7980 | ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var); |
| 6933 | 7981 | ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base); |
| 6934 | 7982 | ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca); |
| 6935 | 7983 | } |
| 6936 | 7984 | |
| 6937 | | static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7985 | static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6938 | 7986 | assert(node->type == NodeTypeVariableDeclaration); |
| 6939 | 7987 | |
| 6940 | 7988 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; |
| 6941 | 7989 | |
| 6942 | 7990 | if (buf_eql_str(variable_declaration->symbol, "_")) { |
| 6943 | 7991 | add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol")); |
| 6944 | | return irb->codegen->invalid_instruction; |
| 7992 | return irb->codegen->invalid_inst_src; |
| 6945 | 7993 | } |
| 6946 | 7994 | |
| 6947 | 7995 | // Used for the type expr and the align expr |
| 6948 | 7996 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| 6949 | 7997 | |
| 6950 | | IrInstruction *type_instruction; |
| 7998 | IrInstSrc *type_instruction; |
| 6951 | 7999 | if (variable_declaration->type != nullptr) { |
| 6952 | 8000 | type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope); |
| 6953 | | if (type_instruction == irb->codegen->invalid_instruction) |
| 8001 | if (type_instruction == irb->codegen->invalid_inst_src) |
| 6954 | 8002 | return type_instruction; |
| 6955 | 8003 | } else { |
| 6956 | 8004 | type_instruction = nullptr; |
| ... | ... | @@ -6961,22 +8009,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6961 | 8009 | bool is_extern = variable_declaration->is_extern; |
| 6962 | 8010 | |
| 6963 | 8011 | bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime; |
| 6964 | | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar); |
| 8012 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar); |
| 6965 | 8013 | ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol, |
| 6966 | 8014 | is_const, is_const, is_shadowable, is_comptime); |
| 6967 | | // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node |
| 8015 | // we detect IrInstSrcDeclVar in gen_block to make sure the next node |
| 6968 | 8016 | // is inside var->child_scope |
| 6969 | 8017 | |
| 6970 | 8018 | if (!is_extern && !variable_declaration->expr) { |
| 6971 | 8019 | var->var_type = irb->codegen->builtin_types.entry_invalid; |
| 6972 | 8020 | add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized")); |
| 6973 | | return irb->codegen->invalid_instruction; |
| 8021 | return irb->codegen->invalid_inst_src; |
| 6974 | 8022 | } |
| 6975 | 8023 | |
| 6976 | | IrInstruction *align_value = nullptr; |
| 8024 | IrInstSrc *align_value = nullptr; |
| 6977 | 8025 | if (variable_declaration->align_expr != nullptr) { |
| 6978 | 8026 | align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope); |
| 6979 | | if (align_value == irb->codegen->invalid_instruction) |
| 8027 | if (align_value == irb->codegen->invalid_inst_src) |
| 6980 | 8028 | return align_value; |
| 6981 | 8029 | } |
| 6982 | 8030 | |
| ... | ... | @@ -6988,7 +8036,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6988 | 8036 | // Parser should ensure that this never happens |
| 6989 | 8037 | assert(variable_declaration->threadlocal_tok == nullptr); |
| 6990 | 8038 | |
| 6991 | | IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value, |
| 8039 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value, |
| 6992 | 8040 | buf_ptr(variable_declaration->symbol), is_comptime); |
| 6993 | 8041 | |
| 6994 | 8042 | // Create a result location for the initialization expression. |
| ... | ... | @@ -7006,19 +8054,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7006 | 8054 | Scope *init_scope = is_comptime_scalar ? |
| 7007 | 8055 | create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope; |
| 7008 | 8056 | |
| 7009 | | // Temporarily set the name of the IrExecutable to the VariableDeclaration |
| 8057 | // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration |
| 7010 | 8058 | // so that the struct or enum from the init expression inherits the name. |
| 7011 | 8059 | Buf *old_exec_name = irb->exec->name; |
| 7012 | 8060 | irb->exec->name = variable_declaration->symbol; |
| 7013 | | IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope, |
| 8061 | IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope, |
| 7014 | 8062 | LValNone, init_result_loc); |
| 7015 | 8063 | irb->exec->name = old_exec_name; |
| 7016 | 8064 | |
| 7017 | | if (init_value == irb->codegen->invalid_instruction) |
| 7018 | | return irb->codegen->invalid_instruction; |
| 8065 | if (init_value == irb->codegen->invalid_inst_src) |
| 8066 | return irb->codegen->invalid_inst_src; |
| 7019 | 8067 | |
| 7020 | 8068 | if (result_loc_cast != nullptr) { |
| 7021 | | IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node, |
| 8069 | IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node, |
| 7022 | 8070 | init_value, result_loc_cast); |
| 7023 | 8071 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); |
| 7024 | 8072 | } |
| ... | ... | @@ -7026,7 +8074,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7026 | 8074 | return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca); |
| 7027 | 8075 | } |
| 7028 | 8076 | |
| 7029 | | static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8077 | static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7030 | 8078 | ResultLoc *result_loc) |
| 7031 | 8079 | { |
| 7032 | 8080 | assert(node->type == NodeTypeWhileExpr); |
| ... | ... | @@ -7034,15 +8082,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7034 | 8082 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; |
| 7035 | 8083 | AstNode *else_node = node->data.while_expr.else_node; |
| 7036 | 8084 | |
| 7037 | | IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond"); |
| 7038 | | IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody"); |
| 7039 | | IrBasicBlock *continue_block = continue_expr_node ? |
| 8085 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond"); |
| 8086 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody"); |
| 8087 | IrBasicBlockSrc *continue_block = continue_expr_node ? |
| 7040 | 8088 | ir_create_basic_block(irb, scope, "WhileContinue") : cond_block; |
| 7041 | | IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd"); |
| 7042 | | IrBasicBlock *else_block = else_node ? |
| 8089 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd"); |
| 8090 | IrBasicBlockSrc *else_block = else_node ? |
| 7043 | 8091 | ir_create_basic_block(irb, scope, "WhileElse") : end_block; |
| 7044 | 8092 | |
| 7045 | | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 8093 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, |
| 7046 | 8094 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); |
| 7047 | 8095 | ir_build_br(irb, scope, node, cond_block, is_comptime); |
| 7048 | 8096 | |
| ... | ... | @@ -7063,15 +8111,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7063 | 8111 | } else { |
| 7064 | 8112 | payload_scope = subexpr_scope; |
| 7065 | 8113 | } |
| 7066 | | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 8114 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, payload_scope); |
| 8115 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 7067 | 8116 | LValPtr, nullptr); |
| 7068 | | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 8117 | if (err_val_ptr == irb->codegen->invalid_inst_src) |
| 7069 | 8118 | return err_val_ptr; |
| 7070 | | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, |
| 8119 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, |
| 7071 | 8120 | true, false); |
| 7072 | | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 7073 | | IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 7074 | | IrInstruction *cond_br_inst; |
| 8121 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8122 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8123 | IrInstSrc *cond_br_inst; |
| 7075 | 8124 | if (!instr_is_unreachable(is_err)) { |
| 7076 | 8125 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err, |
| 7077 | 8126 | else_block, body_block, is_comptime); |
| ... | ... | @@ -7086,15 +8135,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7086 | 8135 | |
| 7087 | 8136 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7088 | 8137 | if (var_symbol) { |
| 7089 | | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, |
| 8138 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, &spill_scope->base, symbol_node, |
| 7090 | 8139 | err_val_ptr, false, false); |
| 7091 | | IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ? |
| 7092 | | ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8140 | IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ? |
| 8141 | ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 7093 | 8142 | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 7094 | 8143 | } |
| 7095 | 8144 | |
| 7096 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7097 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8145 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8146 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7098 | 8147 | |
| 7099 | 8148 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope); |
| 7100 | 8149 | loop_scope->break_block = end_block; |
| ... | ... | @@ -7104,12 +8153,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7104 | 8153 | loop_scope->incoming_values = &incoming_values; |
| 7105 | 8154 | loop_scope->lval = lval; |
| 7106 | 8155 | loop_scope->peer_parent = peer_parent; |
| 8156 | loop_scope->spill_scope = spill_scope; |
| 7107 | 8157 | |
| 7108 | 8158 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7109 | 8159 | // it's actually in break statements, handled similarly to return statements. |
| 7110 | 8160 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 7111 | | IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 7112 | | if (body_result == irb->codegen->invalid_instruction) |
| 8161 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8162 | if (body_result == irb->codegen->invalid_inst_src) |
| 7113 | 8163 | return body_result; |
| 7114 | 8164 | |
| 7115 | 8165 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7119,8 +8169,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7119 | 8169 | |
| 7120 | 8170 | if (continue_expr_node) { |
| 7121 | 8171 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 7122 | | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); |
| 7123 | | if (expr_result == irb->codegen->invalid_instruction) |
| 8172 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); |
| 8173 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7124 | 8174 | return expr_result; |
| 7125 | 8175 | if (!instr_is_unreachable(expr_result)) { |
| 7126 | 8176 | ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7136,7 +8186,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7136 | 8186 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, |
| 7137 | 8187 | true, false, false, is_comptime); |
| 7138 | 8188 | Scope *err_scope = err_var->child_scope; |
| 7139 | | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); |
| 8189 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr); |
| 7140 | 8190 | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr); |
| 7141 | 8191 | |
| 7142 | 8192 | if (peer_parent->peers.length != 0) { |
| ... | ... | @@ -7144,12 +8194,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7144 | 8194 | } |
| 7145 | 8195 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7146 | 8196 | peer_parent->peers.append(peer_result); |
| 7147 | | IrInstruction *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base); |
| 7148 | | if (else_result == irb->codegen->invalid_instruction) |
| 8197 | IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base); |
| 8198 | if (else_result == irb->codegen->invalid_inst_src) |
| 7149 | 8199 | return else_result; |
| 7150 | 8200 | if (!instr_is_unreachable(else_result)) |
| 7151 | 8201 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7152 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8202 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7153 | 8203 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7154 | 8204 | if (else_result) { |
| 7155 | 8205 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7162,7 +8212,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7162 | 8212 | peer_parent->peers.last()->next_bb = end_block; |
| 7163 | 8213 | } |
| 7164 | 8214 | |
| 7165 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8215 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7166 | 8216 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7167 | 8217 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7168 | 8218 | } else if (var_symbol != nullptr) { |
| ... | ... | @@ -7174,15 +8224,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7174 | 8224 | ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, |
| 7175 | 8225 | true, false, false, is_comptime); |
| 7176 | 8226 | Scope *child_scope = payload_var->child_scope; |
| 7177 | | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 8227 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, child_scope); |
| 8228 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 7178 | 8229 | LValPtr, nullptr); |
| 7179 | | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 8230 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) |
| 7180 | 8231 | return maybe_val_ptr; |
| 7181 | | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); |
| 7182 | | IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node->data.while_expr.condition, maybe_val); |
| 7183 | | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 7184 | | IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 7185 | | IrInstruction *cond_br_inst; |
| 8232 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); |
| 8233 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val); |
| 8234 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8235 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8236 | IrInstSrc *cond_br_inst; |
| 7186 | 8237 | if (!instr_is_unreachable(is_non_null)) { |
| 7187 | 8238 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null, |
| 7188 | 8239 | body_block, else_block, is_comptime); |
| ... | ... | @@ -7196,13 +8247,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7196 | 8247 | is_comptime); |
| 7197 | 8248 | |
| 7198 | 8249 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7199 | | IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false); |
| 7200 | | IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ? |
| 7201 | | ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8250 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, &spill_scope->base, symbol_node, maybe_val_ptr, false, false); |
| 8251 | IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ? |
| 8252 | ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 7202 | 8253 | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 7203 | 8254 | |
| 7204 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7205 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8255 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8256 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7206 | 8257 | |
| 7207 | 8258 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); |
| 7208 | 8259 | loop_scope->break_block = end_block; |
| ... | ... | @@ -7212,12 +8263,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7212 | 8263 | loop_scope->incoming_values = &incoming_values; |
| 7213 | 8264 | loop_scope->lval = lval; |
| 7214 | 8265 | loop_scope->peer_parent = peer_parent; |
| 8266 | loop_scope->spill_scope = spill_scope; |
| 7215 | 8267 | |
| 7216 | 8268 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7217 | 8269 | // it's actually in break statements, handled similarly to return statements. |
| 7218 | 8270 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 7219 | | IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 7220 | | if (body_result == irb->codegen->invalid_instruction) |
| 8271 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8272 | if (body_result == irb->codegen->invalid_inst_src) |
| 7221 | 8273 | return body_result; |
| 7222 | 8274 | |
| 7223 | 8275 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7227,8 +8279,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7227 | 8279 | |
| 7228 | 8280 | if (continue_expr_node) { |
| 7229 | 8281 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 7230 | | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); |
| 7231 | | if (expr_result == irb->codegen->invalid_instruction) |
| 8282 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); |
| 8283 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7232 | 8284 | return expr_result; |
| 7233 | 8285 | if (!instr_is_unreachable(expr_result)) { |
| 7234 | 8286 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7236,7 +8288,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7236 | 8288 | } |
| 7237 | 8289 | } |
| 7238 | 8290 | |
| 7239 | | IrInstruction *else_result = nullptr; |
| 8291 | IrInstSrc *else_result = nullptr; |
| 7240 | 8292 | if (else_node) { |
| 7241 | 8293 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7242 | 8294 | |
| ... | ... | @@ -7246,12 +8298,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7246 | 8298 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7247 | 8299 | peer_parent->peers.append(peer_result); |
| 7248 | 8300 | else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base); |
| 7249 | | if (else_result == irb->codegen->invalid_instruction) |
| 8301 | if (else_result == irb->codegen->invalid_inst_src) |
| 7250 | 8302 | return else_result; |
| 7251 | 8303 | if (!instr_is_unreachable(else_result)) |
| 7252 | 8304 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7253 | 8305 | } |
| 7254 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8306 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7255 | 8307 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7256 | 8308 | if (else_result) { |
| 7257 | 8309 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7264,17 +8316,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7264 | 8316 | peer_parent->peers.last()->next_bb = end_block; |
| 7265 | 8317 | } |
| 7266 | 8318 | |
| 7267 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8319 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7268 | 8320 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7269 | 8321 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7270 | 8322 | } else { |
| 7271 | 8323 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 7272 | | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 7273 | | if (cond_val == irb->codegen->invalid_instruction) |
| 8324 | IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 8325 | if (cond_val == irb->codegen->invalid_inst_src) |
| 7274 | 8326 | return cond_val; |
| 7275 | | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 7276 | | IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 7277 | | IrInstruction *cond_br_inst; |
| 8327 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8328 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8329 | IrInstSrc *cond_br_inst; |
| 7278 | 8330 | if (!instr_is_unreachable(cond_val)) { |
| 7279 | 8331 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, |
| 7280 | 8332 | body_block, else_block, is_comptime); |
| ... | ... | @@ -7288,8 +8340,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7288 | 8340 | is_comptime); |
| 7289 | 8341 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7290 | 8342 | |
| 7291 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7292 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8343 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8344 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7293 | 8345 | |
| 7294 | 8346 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 7295 | 8347 | |
| ... | ... | @@ -7305,8 +8357,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7305 | 8357 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7306 | 8358 | // it's actually in break statements, handled similarly to return statements. |
| 7307 | 8359 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 7308 | | IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 7309 | | if (body_result == irb->codegen->invalid_instruction) |
| 8360 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8361 | if (body_result == irb->codegen->invalid_inst_src) |
| 7310 | 8362 | return body_result; |
| 7311 | 8363 | |
| 7312 | 8364 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7316,8 +8368,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7316 | 8368 | |
| 7317 | 8369 | if (continue_expr_node) { |
| 7318 | 8370 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 7319 | | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope); |
| 7320 | | if (expr_result == irb->codegen->invalid_instruction) |
| 8371 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope); |
| 8372 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7321 | 8373 | return expr_result; |
| 7322 | 8374 | if (!instr_is_unreachable(expr_result)) { |
| 7323 | 8375 | ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7325,7 +8377,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7325 | 8377 | } |
| 7326 | 8378 | } |
| 7327 | 8379 | |
| 7328 | | IrInstruction *else_result = nullptr; |
| 8380 | IrInstSrc *else_result = nullptr; |
| 7329 | 8381 | if (else_node) { |
| 7330 | 8382 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7331 | 8383 | |
| ... | ... | @@ -7336,12 +8388,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7336 | 8388 | peer_parent->peers.append(peer_result); |
| 7337 | 8389 | |
| 7338 | 8390 | else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base); |
| 7339 | | if (else_result == irb->codegen->invalid_instruction) |
| 8391 | if (else_result == irb->codegen->invalid_inst_src) |
| 7340 | 8392 | return else_result; |
| 7341 | 8393 | if (!instr_is_unreachable(else_result)) |
| 7342 | 8394 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7343 | 8395 | } |
| 7344 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8396 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7345 | 8397 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7346 | 8398 | if (else_result) { |
| 7347 | 8399 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7354,13 +8406,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7354 | 8406 | peer_parent->peers.last()->next_bb = end_block; |
| 7355 | 8407 | } |
| 7356 | 8408 | |
| 7357 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8409 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7358 | 8410 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7359 | 8411 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7360 | 8412 | } |
| 7361 | 8413 | } |
| 7362 | 8414 | |
| 7363 | | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 8415 | static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 7364 | 8416 | ResultLoc *result_loc) |
| 7365 | 8417 | { |
| 7366 | 8418 | assert(node->type == NodeTypeForExpr); |
| ... | ... | @@ -7373,17 +8425,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7373 | 8425 | |
| 7374 | 8426 | if (!elem_node) { |
| 7375 | 8427 | add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter")); |
| 7376 | | return irb->codegen->invalid_instruction; |
| 8428 | return irb->codegen->invalid_inst_src; |
| 7377 | 8429 | } |
| 7378 | 8430 | assert(elem_node->type == NodeTypeSymbol); |
| 7379 | 8431 | |
| 7380 | 8432 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope); |
| 7381 | 8433 | |
| 7382 | | IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr); |
| 7383 | | if (array_val_ptr == irb->codegen->invalid_instruction) |
| 8434 | IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr); |
| 8435 | if (array_val_ptr == irb->codegen->invalid_inst_src) |
| 7384 | 8436 | return array_val_ptr; |
| 7385 | 8437 | |
| 7386 | | IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 8438 | IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 7387 | 8439 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); |
| 7388 | 8440 | |
| 7389 | 8441 | AstNode *index_var_source_node; |
| ... | ... | @@ -7400,50 +8452,49 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7400 | 8452 | index_var_name = "i"; |
| 7401 | 8453 | } |
| 7402 | 8454 | |
| 7403 | | IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0); |
| 8455 | IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0); |
| 7404 | 8456 | build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime); |
| 7405 | 8457 | parent_scope = index_var->child_scope; |
| 7406 | 8458 | |
| 7407 | | IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1); |
| 7408 | | IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var); |
| 8459 | IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1); |
| 8460 | IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var); |
| 7409 | 8461 | |
| 7410 | 8462 | |
| 7411 | | IrBasicBlock *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond"); |
| 7412 | | IrBasicBlock *body_block = ir_create_basic_block(irb, parent_scope, "ForBody"); |
| 7413 | | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd"); |
| 7414 | | IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block; |
| 7415 | | IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); |
| 8463 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond"); |
| 8464 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody"); |
| 8465 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd"); |
| 8466 | IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block; |
| 8467 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); |
| 7416 | 8468 | |
| 7417 | 8469 | Buf *len_field_name = buf_create_from_str("len"); |
| 7418 | | IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false); |
| 7419 | | IrInstruction *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref); |
| 8470 | IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false); |
| 8471 | IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref); |
| 7420 | 8472 | ir_build_br(irb, parent_scope, node, cond_block, is_comptime); |
| 7421 | 8473 | |
| 7422 | 8474 | ir_set_cursor_at_end_and_append_block(irb, cond_block); |
| 7423 | | IrInstruction *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr); |
| 7424 | | IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 7425 | | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 7426 | | IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); |
| 7427 | | IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 8475 | IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr); |
| 8476 | IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 8477 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8478 | IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); |
| 8479 | IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 7428 | 8480 | body_block, else_block, is_comptime)); |
| 7429 | 8481 | |
| 7430 | 8482 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime); |
| 7431 | 8483 | |
| 7432 | 8484 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7433 | | Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base; |
| 7434 | | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false, |
| 7435 | | PtrLenSingle, nullptr); |
| 8485 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, &spill_scope->base, node, array_val_ptr, index_val, |
| 8486 | false, PtrLenSingle, nullptr); |
| 7436 | 8487 | // TODO make it an error to write to element variable or i variable. |
| 7437 | 8488 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; |
| 7438 | 8489 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| 7439 | 8490 | Scope *child_scope = elem_var->child_scope; |
| 7440 | 8491 | |
| 7441 | | IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ? |
| 7442 | | ir_build_ref(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr; |
| 8492 | IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ? |
| 8493 | ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr; |
| 7443 | 8494 | ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr); |
| 7444 | 8495 | |
| 7445 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7446 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8496 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8497 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7447 | 8498 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); |
| 7448 | 8499 | loop_scope->break_block = end_block; |
| 7449 | 8500 | loop_scope->continue_block = continue_block; |
| ... | ... | @@ -7457,9 +8508,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7457 | 8508 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7458 | 8509 | // it's actually in break statements, handled similarly to return statements. |
| 7459 | 8510 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 7460 | | IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 7461 | | if (body_result == irb->codegen->invalid_instruction) |
| 7462 | | return irb->codegen->invalid_instruction; |
| 8511 | IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 8512 | if (body_result == irb->codegen->invalid_inst_src) |
| 8513 | return irb->codegen->invalid_inst_src; |
| 7463 | 8514 | |
| 7464 | 8515 | if (!instr_is_unreachable(body_result)) { |
| 7465 | 8516 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result)); |
| ... | ... | @@ -7467,11 +8518,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7467 | 8518 | } |
| 7468 | 8519 | |
| 7469 | 8520 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 7470 | | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 8521 | IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 7471 | 8522 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; |
| 7472 | 8523 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 7473 | 8524 | |
| 7474 | | IrInstruction *else_result = nullptr; |
| 8525 | IrInstSrc *else_result = nullptr; |
| 7475 | 8526 | if (else_node) { |
| 7476 | 8527 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7477 | 8528 | |
| ... | ... | @@ -7481,12 +8532,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7481 | 8532 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7482 | 8533 | peer_parent->peers.append(peer_result); |
| 7483 | 8534 | else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base); |
| 7484 | | if (else_result == irb->codegen->invalid_instruction) |
| 8535 | if (else_result == irb->codegen->invalid_inst_src) |
| 7485 | 8536 | return else_result; |
| 7486 | 8537 | if (!instr_is_unreachable(else_result)) |
| 7487 | 8538 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 7488 | 8539 | } |
| 7489 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8540 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7490 | 8541 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7491 | 8542 | |
| 7492 | 8543 | if (else_result) { |
| ... | ... | @@ -7500,29 +8551,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7500 | 8551 | peer_parent->peers.last()->next_bb = end_block; |
| 7501 | 8552 | } |
| 7502 | 8553 | |
| 7503 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, |
| 8554 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, |
| 7504 | 8555 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7505 | 8556 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 7506 | 8557 | } |
| 7507 | 8558 | |
| 7508 | | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8559 | static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7509 | 8560 | assert(node->type == NodeTypeBoolLiteral); |
| 7510 | 8561 | return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value); |
| 7511 | 8562 | } |
| 7512 | 8563 | |
| 7513 | | static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8564 | static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7514 | 8565 | assert(node->type == NodeTypeEnumLiteral); |
| 7515 | 8566 | Buf *name = &node->data.enum_literal.identifier->data.str_lit.str; |
| 7516 | 8567 | return ir_build_const_enum_literal(irb, scope, node, name); |
| 7517 | 8568 | } |
| 7518 | 8569 | |
| 7519 | | static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8570 | static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7520 | 8571 | assert(node->type == NodeTypeStringLiteral); |
| 7521 | 8572 | |
| 7522 | 8573 | return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf); |
| 7523 | 8574 | } |
| 7524 | 8575 | |
| 7525 | | static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8576 | static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7526 | 8577 | assert(node->type == NodeTypeArrayType); |
| 7527 | 8578 | |
| 7528 | 8579 | AstNode *size_node = node->data.array_type.size; |
| ... | ... | @@ -7535,10 +8586,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7535 | 8586 | |
| 7536 | 8587 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| 7537 | 8588 | |
| 7538 | | IrInstruction *sentinel; |
| 8589 | IrInstSrc *sentinel; |
| 7539 | 8590 | if (sentinel_expr != nullptr) { |
| 7540 | 8591 | sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope); |
| 7541 | | if (sentinel == irb->codegen->invalid_instruction) |
| 8592 | if (sentinel == irb->codegen->invalid_inst_src) |
| 7542 | 8593 | return sentinel; |
| 7543 | 8594 | } else { |
| 7544 | 8595 | sentinel = nullptr; |
| ... | ... | @@ -7547,42 +8598,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7547 | 8598 | if (size_node) { |
| 7548 | 8599 | if (is_const) { |
| 7549 | 8600 | add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type")); |
| 7550 | | return irb->codegen->invalid_instruction; |
| 8601 | return irb->codegen->invalid_inst_src; |
| 7551 | 8602 | } |
| 7552 | 8603 | if (is_volatile) { |
| 7553 | 8604 | add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); |
| 7554 | | return irb->codegen->invalid_instruction; |
| 8605 | return irb->codegen->invalid_inst_src; |
| 7555 | 8606 | } |
| 7556 | 8607 | if (is_allow_zero) { |
| 7557 | 8608 | add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type")); |
| 7558 | | return irb->codegen->invalid_instruction; |
| 8609 | return irb->codegen->invalid_inst_src; |
| 7559 | 8610 | } |
| 7560 | 8611 | if (align_expr != nullptr) { |
| 7561 | 8612 | add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type")); |
| 7562 | | return irb->codegen->invalid_instruction; |
| 8613 | return irb->codegen->invalid_inst_src; |
| 7563 | 8614 | } |
| 7564 | 8615 | |
| 7565 | | IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope); |
| 7566 | | if (size_value == irb->codegen->invalid_instruction) |
| 8616 | IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope); |
| 8617 | if (size_value == irb->codegen->invalid_inst_src) |
| 7567 | 8618 | return size_value; |
| 7568 | 8619 | |
| 7569 | | IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 7570 | | if (child_type == irb->codegen->invalid_instruction) |
| 8620 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 8621 | if (child_type == irb->codegen->invalid_inst_src) |
| 7571 | 8622 | return child_type; |
| 7572 | 8623 | |
| 7573 | 8624 | return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type); |
| 7574 | 8625 | } else { |
| 7575 | | IrInstruction *align_value; |
| 8626 | IrInstSrc *align_value; |
| 7576 | 8627 | if (align_expr != nullptr) { |
| 7577 | 8628 | align_value = ir_gen_node(irb, align_expr, comptime_scope); |
| 7578 | | if (align_value == irb->codegen->invalid_instruction) |
| 8629 | if (align_value == irb->codegen->invalid_inst_src) |
| 7579 | 8630 | return align_value; |
| 7580 | 8631 | } else { |
| 7581 | 8632 | align_value = nullptr; |
| 7582 | 8633 | } |
| 7583 | 8634 | |
| 7584 | | IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 7585 | | if (child_type == irb->codegen->invalid_instruction) |
| 8635 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 8636 | if (child_type == irb->codegen->invalid_inst_src) |
| 7586 | 8637 | return child_type; |
| 7587 | 8638 | |
| 7588 | 8639 | return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel, |
| ... | ... | @@ -7590,15 +8641,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7590 | 8641 | } |
| 7591 | 8642 | } |
| 7592 | 8643 | |
| 7593 | | static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8644 | static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7594 | 8645 | assert(node->type == NodeTypeAnyFrameType); |
| 7595 | 8646 | |
| 7596 | 8647 | AstNode *payload_type_node = node->data.anyframe_type.payload_type; |
| 7597 | | IrInstruction *payload_type_value = nullptr; |
| 8648 | IrInstSrc *payload_type_value = nullptr; |
| 7598 | 8649 | |
| 7599 | 8650 | if (payload_type_node != nullptr) { |
| 7600 | 8651 | payload_type_value = ir_gen_node(irb, payload_type_node, scope); |
| 7601 | | if (payload_type_value == irb->codegen->invalid_instruction) |
| 8652 | if (payload_type_value == irb->codegen->invalid_inst_src) |
| 7602 | 8653 | return payload_type_value; |
| 7603 | 8654 | |
| 7604 | 8655 | } |
| ... | ... | @@ -7606,7 +8657,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode |
| 7606 | 8657 | return ir_build_anyframe_type(irb, scope, node, payload_type_value); |
| 7607 | 8658 | } |
| 7608 | 8659 | |
| 7609 | | static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8660 | static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7610 | 8661 | assert(node->type == NodeTypeUndefinedLiteral); |
| 7611 | 8662 | return ir_build_const_undefined(irb, scope, node); |
| 7612 | 8663 | } |
| ... | ... | @@ -7723,13 +8774,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_ |
| 7723 | 8774 | return SIZE_MAX; |
| 7724 | 8775 | } |
| 7725 | 8776 | |
| 7726 | | static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8777 | static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7727 | 8778 | assert(node->type == NodeTypeAsmExpr); |
| 7728 | 8779 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; |
| 7729 | 8780 | |
| 7730 | | IrInstruction *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope); |
| 7731 | | if (asm_template == irb->codegen->invalid_instruction) |
| 7732 | | return irb->codegen->invalid_instruction; |
| 8781 | IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope); |
| 8782 | if (asm_template == irb->codegen->invalid_inst_src) |
| 8783 | return irb->codegen->invalid_inst_src; |
| 7733 | 8784 | |
| 7734 | 8785 | bool is_volatile = asm_expr->volatile_token != nullptr; |
| 7735 | 8786 | bool in_fn_scope = (scope_fn_entry(scope) != nullptr); |
| ... | ... | @@ -7738,7 +8789,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7738 | 8789 | if (is_volatile) { |
| 7739 | 8790 | add_token_error(irb->codegen, node->owner, asm_expr->volatile_token, |
| 7740 | 8791 | buf_sprintf("volatile is meaningless on global assembly")); |
| 7741 | | return irb->codegen->invalid_instruction; |
| 8792 | return irb->codegen->invalid_inst_src; |
| 7742 | 8793 | } |
| 7743 | 8794 | |
| 7744 | 8795 | if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 || |
| ... | ... | @@ -7746,34 +8797,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7746 | 8797 | { |
| 7747 | 8798 | add_node_error(irb->codegen, node, |
| 7748 | 8799 | buf_sprintf("global assembly cannot have inputs, outputs, or clobbers")); |
| 7749 | | return irb->codegen->invalid_instruction; |
| 8800 | return irb->codegen->invalid_inst_src; |
| 7750 | 8801 | } |
| 7751 | 8802 | |
| 7752 | 8803 | return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr, |
| 7753 | 8804 | nullptr, 0, is_volatile, true); |
| 7754 | 8805 | } |
| 7755 | 8806 | |
| 7756 | | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 7757 | | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); |
| 8807 | IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length); |
| 8808 | IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length); |
| 7758 | 8809 | ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length); |
| 7759 | 8810 | size_t return_count = 0; |
| 7760 | 8811 | if (!is_volatile && asm_expr->output_list.length == 0) { |
| 7761 | 8812 | add_node_error(irb->codegen, node, |
| 7762 | 8813 | buf_sprintf("assembly expression with no output must be marked volatile")); |
| 7763 | | return irb->codegen->invalid_instruction; |
| 8814 | return irb->codegen->invalid_inst_src; |
| 7764 | 8815 | } |
| 7765 | 8816 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 7766 | 8817 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 7767 | 8818 | if (asm_output->return_type) { |
| 7768 | 8819 | return_count += 1; |
| 7769 | 8820 | |
| 7770 | | IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope); |
| 7771 | | if (return_type == irb->codegen->invalid_instruction) |
| 7772 | | return irb->codegen->invalid_instruction; |
| 8821 | IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope); |
| 8822 | if (return_type == irb->codegen->invalid_inst_src) |
| 8823 | return irb->codegen->invalid_inst_src; |
| 7773 | 8824 | if (return_count > 1) { |
| 7774 | 8825 | add_node_error(irb->codegen, node, |
| 7775 | 8826 | buf_sprintf("inline assembly allows up to one output value")); |
| 7776 | | return irb->codegen->invalid_instruction; |
| 8827 | return irb->codegen->invalid_inst_src; |
| 7777 | 8828 | } |
| 7778 | 8829 | output_types[i] = return_type; |
| 7779 | 8830 | } else { |
| ... | ... | @@ -7786,7 +8837,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7786 | 8837 | } else { |
| 7787 | 8838 | add_node_error(irb->codegen, node, |
| 7788 | 8839 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); |
| 7789 | | return irb->codegen->invalid_instruction; |
| 8840 | return irb->codegen->invalid_inst_src; |
| 7790 | 8841 | } |
| 7791 | 8842 | } |
| 7792 | 8843 | |
| ... | ... | @@ -7796,14 +8847,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7796 | 8847 | buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported." |
| 7797 | 8848 | " Compiler TODO: see https://github.com/ziglang/zig/issues/215", |
| 7798 | 8849 | buf_ptr(asm_output->asm_symbolic_name), modifier)); |
| 7799 | | return irb->codegen->invalid_instruction; |
| 8850 | return irb->codegen->invalid_inst_src; |
| 7800 | 8851 | } |
| 7801 | 8852 | } |
| 7802 | 8853 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 7803 | 8854 | AsmInput *asm_input = asm_expr->input_list.at(i); |
| 7804 | | IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope); |
| 7805 | | if (input_value == irb->codegen->invalid_instruction) |
| 7806 | | return irb->codegen->invalid_instruction; |
| 8855 | IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope); |
| 8856 | if (input_value == irb->codegen->invalid_inst_src) |
| 8857 | return irb->codegen->invalid_inst_src; |
| 7807 | 8858 | |
| 7808 | 8859 | input_list[i] = input_value; |
| 7809 | 8860 | } |
| ... | ... | @@ -7812,7 +8863,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7812 | 8863 | output_vars, return_count, is_volatile, false); |
| 7813 | 8864 | } |
| 7814 | 8865 | |
| 7815 | | static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8866 | static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7816 | 8867 | ResultLoc *result_loc) |
| 7817 | 8868 | { |
| 7818 | 8869 | assert(node->type == NodeTypeIfOptional); |
| ... | ... | @@ -7823,24 +8874,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 7823 | 8874 | AstNode *else_node = node->data.test_expr.else_node; |
| 7824 | 8875 | bool var_is_ptr = node->data.test_expr.var_is_ptr; |
| 7825 | 8876 | |
| 7826 | | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 7827 | | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 8877 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 8878 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) |
| 7828 | 8879 | return maybe_val_ptr; |
| 7829 | 8880 | |
| 7830 | | IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); |
| 7831 | | IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val); |
| 8881 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); |
| 8882 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val); |
| 7832 | 8883 | |
| 7833 | | IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen"); |
| 7834 | | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse"); |
| 7835 | | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf"); |
| 8884 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen"); |
| 8885 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse"); |
| 8886 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf"); |
| 7836 | 8887 | |
| 7837 | | IrInstruction *is_comptime; |
| 8888 | IrInstSrc *is_comptime; |
| 7838 | 8889 | if (ir_should_inline(irb->exec, scope)) { |
| 7839 | 8890 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 7840 | 8891 | } else { |
| 7841 | 8892 | is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null); |
| 7842 | 8893 | } |
| 7843 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 8894 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 7844 | 8895 | then_block, else_block, is_comptime); |
| 7845 | 8896 | |
| 7846 | 8897 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| ... | ... | @@ -7856,48 +8907,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 7856 | 8907 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7857 | 8908 | var_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 7858 | 8909 | |
| 7859 | | IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false); |
| 7860 | | IrInstruction *var_ptr = var_is_ptr ? ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 8910 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false); |
| 8911 | IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 7861 | 8912 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr); |
| 7862 | 8913 | var_scope = var->child_scope; |
| 7863 | 8914 | } else { |
| 7864 | 8915 | var_scope = subexpr_scope; |
| 7865 | 8916 | } |
| 7866 | | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 8917 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 7867 | 8918 | &peer_parent->peers.at(0)->base); |
| 7868 | | if (then_expr_result == irb->codegen->invalid_instruction) |
| 8919 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7869 | 8920 | return then_expr_result; |
| 7870 | | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 8921 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 7871 | 8922 | if (!instr_is_unreachable(then_expr_result)) |
| 7872 | 8923 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7873 | 8924 | |
| 7874 | 8925 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7875 | | IrInstruction *else_expr_result; |
| 8926 | IrInstSrc *else_expr_result; |
| 7876 | 8927 | if (else_node) { |
| 7877 | 8928 | else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base); |
| 7878 | | if (else_expr_result == irb->codegen->invalid_instruction) |
| 8929 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7879 | 8930 | return else_expr_result; |
| 7880 | 8931 | } else { |
| 7881 | 8932 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 7882 | 8933 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 7883 | 8934 | } |
| 7884 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8935 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7885 | 8936 | if (!instr_is_unreachable(else_expr_result)) |
| 7886 | 8937 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7887 | 8938 | |
| 7888 | 8939 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 7889 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 8940 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 7890 | 8941 | incoming_values[0] = then_expr_result; |
| 7891 | 8942 | incoming_values[1] = else_expr_result; |
| 7892 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 8943 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 7893 | 8944 | incoming_blocks[0] = after_then_block; |
| 7894 | 8945 | incoming_blocks[1] = after_else_block; |
| 7895 | 8946 | |
| 7896 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 8947 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7897 | 8948 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7898 | 8949 | } |
| 7899 | 8950 | |
| 7900 | | static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8951 | static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7901 | 8952 | ResultLoc *result_loc) |
| 7902 | 8953 | { |
| 7903 | 8954 | assert(node->type == NodeTypeIfErrorExpr); |
| ... | ... | @@ -7910,20 +8961,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7910 | 8961 | Buf *var_symbol = node->data.if_err_expr.var_symbol; |
| 7911 | 8962 | Buf *err_symbol = node->data.if_err_expr.err_symbol; |
| 7912 | 8963 | |
| 7913 | | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 7914 | | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 8964 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 8965 | if (err_val_ptr == irb->codegen->invalid_inst_src) |
| 7915 | 8966 | return err_val_ptr; |
| 7916 | 8967 | |
| 7917 | | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 7918 | | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false); |
| 8968 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 8969 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false); |
| 7919 | 8970 | |
| 7920 | | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk"); |
| 7921 | | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse"); |
| 7922 | | IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd"); |
| 8971 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk"); |
| 8972 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse"); |
| 8973 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd"); |
| 7923 | 8974 | |
| 7924 | 8975 | bool force_comptime = ir_should_inline(irb->exec, scope); |
| 7925 | | IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); |
| 7926 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 8976 | IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); |
| 8977 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 7927 | 8978 | |
| 7928 | 8979 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 7929 | 8980 | result_loc, is_comptime); |
| ... | ... | @@ -7934,29 +8985,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7934 | 8985 | Scope *var_scope; |
| 7935 | 8986 | if (var_symbol) { |
| 7936 | 8987 | bool is_shadowable = false; |
| 7937 | | IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); |
| 8988 | IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); |
| 7938 | 8989 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7939 | 8990 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); |
| 7940 | 8991 | |
| 7941 | | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false, false); |
| 7942 | | IrInstruction *var_ptr = var_is_ptr ? |
| 7943 | | ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 8992 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false); |
| 8993 | IrInstSrc *var_ptr = var_is_ptr ? |
| 8994 | ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 7944 | 8995 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr); |
| 7945 | 8996 | var_scope = var->child_scope; |
| 7946 | 8997 | } else { |
| 7947 | 8998 | var_scope = subexpr_scope; |
| 7948 | 8999 | } |
| 7949 | | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 9000 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 7950 | 9001 | &peer_parent->peers.at(0)->base); |
| 7951 | | if (then_expr_result == irb->codegen->invalid_instruction) |
| 9002 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7952 | 9003 | return then_expr_result; |
| 7953 | | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 9004 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 7954 | 9005 | if (!instr_is_unreachable(then_expr_result)) |
| 7955 | 9006 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7956 | 9007 | |
| 7957 | 9008 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7958 | 9009 | |
| 7959 | | IrInstruction *else_expr_result; |
| 9010 | IrInstSrc *else_expr_result; |
| 7960 | 9011 | if (else_node) { |
| 7961 | 9012 | Scope *err_var_scope; |
| 7962 | 9013 | if (err_symbol) { |
| ... | ... | @@ -7965,40 +9016,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7965 | 9016 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7966 | 9017 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 7967 | 9018 | |
| 7968 | | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 9019 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr); |
| 7969 | 9020 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr); |
| 7970 | 9021 | err_var_scope = var->child_scope; |
| 7971 | 9022 | } else { |
| 7972 | 9023 | err_var_scope = subexpr_scope; |
| 7973 | 9024 | } |
| 7974 | 9025 | else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base); |
| 7975 | | if (else_expr_result == irb->codegen->invalid_instruction) |
| 9026 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7976 | 9027 | return else_expr_result; |
| 7977 | 9028 | } else { |
| 7978 | 9029 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 7979 | 9030 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 7980 | 9031 | } |
| 7981 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 9032 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7982 | 9033 | if (!instr_is_unreachable(else_expr_result)) |
| 7983 | 9034 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7984 | 9035 | |
| 7985 | 9036 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 7986 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 9037 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 7987 | 9038 | incoming_values[0] = then_expr_result; |
| 7988 | 9039 | incoming_values[1] = else_expr_result; |
| 7989 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 9040 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 7990 | 9041 | incoming_blocks[0] = after_then_block; |
| 7991 | 9042 | incoming_blocks[1] = after_else_block; |
| 7992 | 9043 | |
| 7993 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 9044 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7994 | 9045 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7995 | 9046 | } |
| 7996 | 9047 | |
| 7997 | | static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node, |
| 7998 | | IrBasicBlock *end_block, IrInstruction *is_comptime, IrInstruction *var_is_comptime, |
| 7999 | | IrInstruction *target_value_ptr, IrInstruction **prong_values, size_t prong_values_len, |
| 8000 | | ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values, |
| 8001 | | IrInstructionSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc) |
| 9048 | static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node, |
| 9049 | IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime, |
| 9050 | IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len, |
| 9051 | ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values, |
| 9052 | IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc) |
| 8002 | 9053 | { |
| 8003 | 9054 | assert(switch_node->type == NodeTypeSwitchExpr); |
| 8004 | 9055 | assert(prong_node->type == NodeTypeSwitchProng); |
| ... | ... | @@ -8016,28 +9067,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 8016 | 9067 | ZigVar *var = ir_create_var(irb, var_symbol_node, scope, |
| 8017 | 9068 | var_name, is_const, is_const, is_shadowable, var_is_comptime); |
| 8018 | 9069 | child_scope = var->child_scope; |
| 8019 | | IrInstruction *var_ptr; |
| 9070 | IrInstSrc *var_ptr; |
| 8020 | 9071 | if (out_switch_else_var != nullptr) { |
| 8021 | | IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node, |
| 9072 | IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node, |
| 8022 | 9073 | target_value_ptr); |
| 8023 | 9074 | *out_switch_else_var = switch_else_var; |
| 8024 | | IrInstruction *payload_ptr = &switch_else_var->base; |
| 8025 | | var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 9075 | IrInstSrc *payload_ptr = &switch_else_var->base; |
| 9076 | var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8026 | 9077 | } else if (prong_values != nullptr) { |
| 8027 | | IrInstruction *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, |
| 9078 | IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, |
| 8028 | 9079 | prong_values, prong_values_len); |
| 8029 | | var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 9080 | var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8030 | 9081 | } else { |
| 8031 | 9082 | var_ptr = var_is_ptr ? |
| 8032 | | ir_build_ref(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr; |
| 9083 | ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr; |
| 8033 | 9084 | } |
| 8034 | 9085 | ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr); |
| 8035 | 9086 | } else { |
| 8036 | 9087 | child_scope = scope; |
| 8037 | 9088 | } |
| 8038 | 9089 | |
| 8039 | | IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc); |
| 8040 | | if (expr_result == irb->codegen->invalid_instruction) |
| 9090 | IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc); |
| 9091 | if (expr_result == irb->codegen->invalid_inst_src) |
| 8041 | 9092 | return false; |
| 8042 | 9093 | if (!instr_is_unreachable(expr_result)) |
| 8043 | 9094 | ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime)); |
| ... | ... | @@ -8046,25 +9097,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 8046 | 9097 | return true; |
| 8047 | 9098 | } |
| 8048 | 9099 | |
| 8049 | | static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 9100 | static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 8050 | 9101 | ResultLoc *result_loc) |
| 8051 | 9102 | { |
| 8052 | 9103 | assert(node->type == NodeTypeSwitchExpr); |
| 8053 | 9104 | |
| 8054 | 9105 | AstNode *target_node = node->data.switch_expr.expr; |
| 8055 | | IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 8056 | | if (target_value_ptr == irb->codegen->invalid_instruction) |
| 9106 | IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 9107 | if (target_value_ptr == irb->codegen->invalid_inst_src) |
| 8057 | 9108 | return target_value_ptr; |
| 8058 | | IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 9109 | IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 8059 | 9110 | |
| 8060 | | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); |
| 8061 | | IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); |
| 9111 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); |
| 9112 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); |
| 8062 | 9113 | |
| 8063 | 9114 | size_t prong_count = node->data.switch_expr.prongs.length; |
| 8064 | | ZigList<IrInstructionSwitchBrCase> cases = {0}; |
| 9115 | ZigList<IrInstSrcSwitchBrCase> cases = {0}; |
| 8065 | 9116 | |
| 8066 | | IrInstruction *is_comptime; |
| 8067 | | IrInstruction *var_is_comptime; |
| 9117 | IrInstSrc *is_comptime; |
| 9118 | IrInstSrc *var_is_comptime; |
| 8068 | 9119 | if (ir_should_inline(irb->exec, scope)) { |
| 8069 | 9120 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 8070 | 9121 | var_is_comptime = is_comptime; |
| ... | ... | @@ -8073,11 +9124,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8073 | 9124 | var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr); |
| 8074 | 9125 | } |
| 8075 | 9126 | |
| 8076 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 8077 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8078 | | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; |
| 9127 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 9128 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 9129 | ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0}; |
| 8079 | 9130 | |
| 8080 | | IrInstructionSwitchElseVar *switch_else_var = nullptr; |
| 9131 | IrInstSrcSwitchElseVar *switch_else_var = nullptr; |
| 8081 | 9132 | |
| 8082 | 9133 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 8083 | 9134 | peer_parent->base.id = ResultLocIdPeerParent; |
| ... | ... | @@ -8099,7 +9150,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8099 | 9150 | if (prong_node->data.switch_prong.any_items_are_range) { |
| 8100 | 9151 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8101 | 9152 | |
| 8102 | | IrInstruction *ok_bit = nullptr; |
| 9153 | IrInstSrc *ok_bit = nullptr; |
| 8103 | 9154 | AstNode *last_item_node = nullptr; |
| 8104 | 9155 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 8105 | 9156 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| ... | ... | @@ -8108,23 +9159,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8108 | 9159 | AstNode *start_node = item_node->data.switch_range.start; |
| 8109 | 9160 | AstNode *end_node = item_node->data.switch_range.end; |
| 8110 | 9161 | |
| 8111 | | IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope); |
| 8112 | | if (start_value == irb->codegen->invalid_instruction) |
| 8113 | | return irb->codegen->invalid_instruction; |
| 9162 | IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope); |
| 9163 | if (start_value == irb->codegen->invalid_inst_src) |
| 9164 | return irb->codegen->invalid_inst_src; |
| 8114 | 9165 | |
| 8115 | | IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope); |
| 8116 | | if (end_value == irb->codegen->invalid_instruction) |
| 8117 | | return irb->codegen->invalid_instruction; |
| 9166 | IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope); |
| 9167 | if (end_value == irb->codegen->invalid_inst_src) |
| 9168 | return irb->codegen->invalid_inst_src; |
| 8118 | 9169 | |
| 8119 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9170 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8120 | 9171 | check_range->start = start_value; |
| 8121 | 9172 | check_range->end = end_value; |
| 8122 | 9173 | |
| 8123 | | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 9174 | IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 8124 | 9175 | target_value, start_value, false); |
| 8125 | | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 9176 | IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 8126 | 9177 | target_value, end_value, false); |
| 8127 | | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 9178 | IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 8128 | 9179 | lower_range_ok, upper_range_ok, false); |
| 8129 | 9180 | if (ok_bit) { |
| 8130 | 9181 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); |
| ... | ... | @@ -8132,15 +9183,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8132 | 9183 | ok_bit = both_ok; |
| 8133 | 9184 | } |
| 8134 | 9185 | } else { |
| 8135 | | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 8136 | | if (item_value == irb->codegen->invalid_instruction) |
| 8137 | | return irb->codegen->invalid_instruction; |
| 9186 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 9187 | if (item_value == irb->codegen->invalid_inst_src) |
| 9188 | return irb->codegen->invalid_inst_src; |
| 8138 | 9189 | |
| 8139 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9190 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8140 | 9191 | check_range->start = item_value; |
| 8141 | 9192 | check_range->end = item_value; |
| 8142 | 9193 | |
| 8143 | | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 9194 | IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 8144 | 9195 | item_value, target_value, false); |
| 8145 | 9196 | if (ok_bit) { |
| 8146 | 9197 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); |
| ... | ... | @@ -8150,12 +9201,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8150 | 9201 | } |
| 8151 | 9202 | } |
| 8152 | 9203 | |
| 8153 | | IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); |
| 8154 | | IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); |
| 9204 | IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); |
| 9205 | IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); |
| 8155 | 9206 | |
| 8156 | 9207 | assert(ok_bit); |
| 8157 | 9208 | assert(last_item_node); |
| 8158 | | IrInstruction *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, |
| 9209 | IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, |
| 8159 | 9210 | range_block_yes, range_block_no, is_comptime)); |
| 8160 | 9211 | if (peer_parent->base.source_instruction == nullptr) { |
| 8161 | 9212 | peer_parent->base.source_instruction = br_inst; |
| ... | ... | @@ -8170,7 +9221,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8170 | 9221 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, |
| 8171 | 9222 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 8172 | 9223 | { |
| 8173 | | return irb->codegen->invalid_instruction; |
| 9224 | return irb->codegen->invalid_inst_src; |
| 8174 | 9225 | } |
| 8175 | 9226 | |
| 8176 | 9227 | ir_set_cursor_at_end_and_append_block(irb, range_block_no); |
| ... | ... | @@ -8181,7 +9232,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8181 | 9232 | buf_sprintf("multiple else prongs in switch expression")); |
| 8182 | 9233 | add_error_note(irb->codegen, msg, else_prong, |
| 8183 | 9234 | buf_sprintf("previous else prong is here")); |
| 8184 | | return irb->codegen->invalid_instruction; |
| 9235 | return irb->codegen->invalid_inst_src; |
| 8185 | 9236 | } |
| 8186 | 9237 | else_prong = prong_node; |
| 8187 | 9238 | } else if (prong_item_count == 1 && |
| ... | ... | @@ -8192,7 +9243,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8192 | 9243 | buf_sprintf("multiple '_' prongs in switch expression")); |
| 8193 | 9244 | add_error_note(irb->codegen, msg, underscore_prong, |
| 8194 | 9245 | buf_sprintf("previous '_' prong is here")); |
| 8195 | | return irb->codegen->invalid_instruction; |
| 9246 | return irb->codegen->invalid_inst_src; |
| 8196 | 9247 | } |
| 8197 | 9248 | underscore_prong = prong_node; |
| 8198 | 9249 | } else { |
| ... | ... | @@ -8207,11 +9258,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8207 | 9258 | else |
| 8208 | 9259 | add_error_note(irb->codegen, msg, underscore_prong, |
| 8209 | 9260 | buf_sprintf("'_' prong is here")); |
| 8210 | | return irb->codegen->invalid_instruction; |
| 9261 | return irb->codegen->invalid_inst_src; |
| 8211 | 9262 | } |
| 8212 | 9263 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8213 | 9264 | |
| 8214 | | IrBasicBlock *prev_block = irb->current_basic_block; |
| 9265 | IrBasicBlockSrc *prev_block = irb->current_basic_block; |
| 8215 | 9266 | if (peer_parent->peers.length > 0) { |
| 8216 | 9267 | peer_parent->peers.last()->next_bb = else_block; |
| 8217 | 9268 | } |
| ... | ... | @@ -8221,7 +9272,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8221 | 9272 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, |
| 8222 | 9273 | &switch_else_var, LValNone, &this_peer_result_loc->base)) |
| 8223 | 9274 | { |
| 8224 | | return irb->codegen->invalid_instruction; |
| 9275 | return irb->codegen->invalid_inst_src; |
| 8225 | 9276 | } |
| 8226 | 9277 | ir_set_cursor_at_end(irb, prev_block); |
| 8227 | 9278 | } |
| ... | ... | @@ -8240,29 +9291,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8240 | 9291 | |
| 8241 | 9292 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8242 | 9293 | |
| 8243 | | IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); |
| 8244 | | IrInstruction **items = allocate<IrInstruction *>(prong_item_count); |
| 9294 | IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); |
| 9295 | IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count); |
| 8245 | 9296 | |
| 8246 | 9297 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 8247 | 9298 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 8248 | 9299 | assert(item_node->type != NodeTypeSwitchRange); |
| 8249 | 9300 | |
| 8250 | | IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 8251 | | if (item_value == irb->codegen->invalid_instruction) |
| 8252 | | return irb->codegen->invalid_instruction; |
| 9301 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 9302 | if (item_value == irb->codegen->invalid_inst_src) |
| 9303 | return irb->codegen->invalid_inst_src; |
| 8253 | 9304 | |
| 8254 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9305 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8255 | 9306 | check_range->start = item_value; |
| 8256 | 9307 | check_range->end = item_value; |
| 8257 | 9308 | |
| 8258 | | IrInstructionSwitchBrCase *this_case = cases.add_one(); |
| 9309 | IrInstSrcSwitchBrCase *this_case = cases.add_one(); |
| 8259 | 9310 | this_case->value = item_value; |
| 8260 | 9311 | this_case->block = prong_block; |
| 8261 | 9312 | |
| 8262 | 9313 | items[item_i] = item_value; |
| 8263 | 9314 | } |
| 8264 | 9315 | |
| 8265 | | IrBasicBlock *prev_block = irb->current_basic_block; |
| 9316 | IrBasicBlockSrc *prev_block = irb->current_basic_block; |
| 8266 | 9317 | if (peer_parent->peers.length > 0) { |
| 8267 | 9318 | peer_parent->peers.last()->next_bb = prong_block; |
| 8268 | 9319 | } |
| ... | ... | @@ -8272,21 +9323,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8272 | 9323 | is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count, |
| 8273 | 9324 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 8274 | 9325 | { |
| 8275 | | return irb->codegen->invalid_instruction; |
| 9326 | return irb->codegen->invalid_inst_src; |
| 8276 | 9327 | } |
| 8277 | 9328 | |
| 8278 | 9329 | ir_set_cursor_at_end(irb, prev_block); |
| 8279 | 9330 | |
| 8280 | 9331 | } |
| 8281 | 9332 | |
| 8282 | | IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, |
| 9333 | IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, |
| 8283 | 9334 | check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr); |
| 8284 | 9335 | |
| 8285 | | IrInstruction *br_instruction; |
| 9336 | IrInstSrc *br_instruction; |
| 8286 | 9337 | if (cases.length == 0) { |
| 8287 | 9338 | br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime); |
| 8288 | 9339 | } else { |
| 8289 | | IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, scope, node, target_value, else_block, |
| 9340 | IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block, |
| 8290 | 9341 | cases.length, cases.items, is_comptime, switch_prongs_void); |
| 8291 | 9342 | if (switch_else_var != nullptr) { |
| 8292 | 9343 | switch_else_var->switch_br = switch_br; |
| ... | ... | @@ -8314,7 +9365,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8314 | 9365 | |
| 8315 | 9366 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 8316 | 9367 | assert(incoming_blocks.length == incoming_values.length); |
| 8317 | | IrInstruction *result_instruction; |
| 9368 | IrInstSrc *result_instruction; |
| 8318 | 9369 | if (incoming_blocks.length == 0) { |
| 8319 | 9370 | result_instruction = ir_build_const_void(irb, scope, node); |
| 8320 | 9371 | } else { |
| ... | ... | @@ -8324,7 +9375,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8324 | 9375 | return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc); |
| 8325 | 9376 | } |
| 8326 | 9377 | |
| 8327 | | static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) { |
| 9378 | static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) { |
| 8328 | 9379 | assert(node->type == NodeTypeCompTime); |
| 8329 | 9380 | |
| 8330 | 9381 | Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope); |
| ... | ... | @@ -8332,28 +9383,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo |
| 8332 | 9383 | return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr); |
| 8333 | 9384 | } |
| 8334 | 9385 | |
| 8335 | | static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { |
| 8336 | | IrInstruction *is_comptime; |
| 9386 | static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { |
| 9387 | IrInstSrc *is_comptime; |
| 8337 | 9388 | if (ir_should_inline(irb->exec, break_scope)) { |
| 8338 | 9389 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); |
| 8339 | 9390 | } else { |
| 8340 | 9391 | is_comptime = block_scope->is_comptime; |
| 8341 | 9392 | } |
| 8342 | 9393 | |
| 8343 | | IrInstruction *result_value; |
| 9394 | IrInstSrc *result_value; |
| 8344 | 9395 | if (node->data.break_expr.expr) { |
| 8345 | 9396 | ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent); |
| 8346 | 9397 | block_scope->peer_parent->peers.append(peer_result); |
| 8347 | 9398 | |
| 8348 | 9399 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval, |
| 8349 | 9400 | &peer_result->base); |
| 8350 | | if (result_value == irb->codegen->invalid_instruction) |
| 8351 | | return irb->codegen->invalid_instruction; |
| 9401 | if (result_value == irb->codegen->invalid_inst_src) |
| 9402 | return irb->codegen->invalid_inst_src; |
| 8352 | 9403 | } else { |
| 8353 | 9404 | result_value = ir_build_const_void(irb, break_scope, node); |
| 8354 | 9405 | } |
| 8355 | 9406 | |
| 8356 | | IrBasicBlock *dest_block = block_scope->end_block; |
| 9407 | IrBasicBlockSrc *dest_block = block_scope->end_block; |
| 8357 | 9408 | ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false); |
| 8358 | 9409 | |
| 8359 | 9410 | block_scope->incoming_blocks->append(irb->current_basic_block); |
| ... | ... | @@ -8361,7 +9412,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop |
| 8361 | 9412 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); |
| 8362 | 9413 | } |
| 8363 | 9414 | |
| 8364 | | static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) { |
| 9415 | static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) { |
| 8365 | 9416 | assert(node->type == NodeTypeBreak); |
| 8366 | 9417 | |
| 8367 | 9418 | // Search up the scope. We'll find one of these things first: |
| ... | ... | @@ -8376,14 +9427,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8376 | 9427 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 8377 | 9428 | if (node->data.break_expr.name != nullptr) { |
| 8378 | 9429 | add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name))); |
| 8379 | | return irb->codegen->invalid_instruction; |
| 9430 | return irb->codegen->invalid_inst_src; |
| 8380 | 9431 | } else { |
| 8381 | 9432 | add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop")); |
| 8382 | | return irb->codegen->invalid_instruction; |
| 9433 | return irb->codegen->invalid_inst_src; |
| 8383 | 9434 | } |
| 8384 | 9435 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 8385 | 9436 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression")); |
| 8386 | | return irb->codegen->invalid_instruction; |
| 9437 | return irb->codegen->invalid_inst_src; |
| 8387 | 9438 | } else if (search_scope->id == ScopeIdLoop) { |
| 8388 | 9439 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 8389 | 9440 | if (node->data.break_expr.name == nullptr || |
| ... | ... | @@ -8402,32 +9453,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8402 | 9453 | } |
| 8403 | 9454 | } else if (search_scope->id == ScopeIdSuspend) { |
| 8404 | 9455 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block")); |
| 8405 | | return irb->codegen->invalid_instruction; |
| 9456 | return irb->codegen->invalid_inst_src; |
| 8406 | 9457 | } |
| 8407 | 9458 | search_scope = search_scope->parent; |
| 8408 | 9459 | } |
| 8409 | 9460 | |
| 8410 | | IrInstruction *is_comptime; |
| 9461 | IrInstSrc *is_comptime; |
| 8411 | 9462 | if (ir_should_inline(irb->exec, break_scope)) { |
| 8412 | 9463 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); |
| 8413 | 9464 | } else { |
| 8414 | 9465 | is_comptime = loop_scope->is_comptime; |
| 8415 | 9466 | } |
| 8416 | 9467 | |
| 8417 | | IrInstruction *result_value; |
| 9468 | IrInstSrc *result_value; |
| 8418 | 9469 | if (node->data.break_expr.expr) { |
| 8419 | 9470 | ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent); |
| 8420 | 9471 | loop_scope->peer_parent->peers.append(peer_result); |
| 8421 | 9472 | |
| 8422 | 9473 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, |
| 8423 | 9474 | loop_scope->lval, &peer_result->base); |
| 8424 | | if (result_value == irb->codegen->invalid_instruction) |
| 8425 | | return irb->codegen->invalid_instruction; |
| 9475 | if (result_value == irb->codegen->invalid_inst_src) |
| 9476 | return irb->codegen->invalid_inst_src; |
| 8426 | 9477 | } else { |
| 8427 | 9478 | result_value = ir_build_const_void(irb, break_scope, node); |
| 8428 | 9479 | } |
| 8429 | 9480 | |
| 8430 | | IrBasicBlock *dest_block = loop_scope->break_block; |
| 9481 | IrBasicBlockSrc *dest_block = loop_scope->break_block; |
| 8431 | 9482 | ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false); |
| 8432 | 9483 | |
| 8433 | 9484 | loop_scope->incoming_blocks->append(irb->current_basic_block); |
| ... | ... | @@ -8435,7 +9486,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8435 | 9486 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); |
| 8436 | 9487 | } |
| 8437 | 9488 | |
| 8438 | | static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, AstNode *node) { |
| 9489 | static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) { |
| 8439 | 9490 | assert(node->type == NodeTypeContinue); |
| 8440 | 9491 | |
| 8441 | 9492 | // Search up the scope. We'll find one of these things first: |
| ... | ... | @@ -8451,14 +9502,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8451 | 9502 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 8452 | 9503 | if (node->data.continue_expr.name != nullptr) { |
| 8453 | 9504 | add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name))); |
| 8454 | | return irb->codegen->invalid_instruction; |
| 9505 | return irb->codegen->invalid_inst_src; |
| 8455 | 9506 | } else { |
| 8456 | 9507 | add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop")); |
| 8457 | | return irb->codegen->invalid_instruction; |
| 9508 | return irb->codegen->invalid_inst_src; |
| 8458 | 9509 | } |
| 8459 | 9510 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 8460 | 9511 | add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression")); |
| 8461 | | return irb->codegen->invalid_instruction; |
| 9512 | return irb->codegen->invalid_inst_src; |
| 8462 | 9513 | } else if (search_scope->id == ScopeIdLoop) { |
| 8463 | 9514 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 8464 | 9515 | if (node->data.continue_expr.name == nullptr || |
| ... | ... | @@ -8474,7 +9525,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8474 | 9525 | search_scope = search_scope->parent; |
| 8475 | 9526 | } |
| 8476 | 9527 | |
| 8477 | | IrInstruction *is_comptime; |
| 9528 | IrInstSrc *is_comptime; |
| 8478 | 9529 | if (ir_should_inline(irb->exec, continue_scope)) { |
| 8479 | 9530 | is_comptime = ir_build_const_bool(irb, continue_scope, node, true); |
| 8480 | 9531 | } else { |
| ... | ... | @@ -8486,17 +9537,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8486 | 9537 | ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime)); |
| 8487 | 9538 | } |
| 8488 | 9539 | |
| 8489 | | IrBasicBlock *dest_block = loop_scope->continue_block; |
| 9540 | IrBasicBlockSrc *dest_block = loop_scope->continue_block; |
| 8490 | 9541 | ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false); |
| 8491 | 9542 | return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime)); |
| 8492 | 9543 | } |
| 8493 | 9544 | |
| 8494 | | static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 9545 | static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 8495 | 9546 | assert(node->type == NodeTypeErrorType); |
| 8496 | 9547 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set); |
| 8497 | 9548 | } |
| 8498 | 9549 | |
| 8499 | | static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9550 | static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8500 | 9551 | assert(node->type == NodeTypeDefer); |
| 8501 | 9552 | |
| 8502 | 9553 | ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope); |
| ... | ... | @@ -8508,7 +9559,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8508 | 9559 | return ir_build_const_void(irb, parent_scope, node); |
| 8509 | 9560 | } |
| 8510 | 9561 | |
| 8511 | | static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 9562 | static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 8512 | 9563 | assert(node->type == NodeTypeSliceExpr); |
| 8513 | 9564 | |
| 8514 | 9565 | AstNodeSliceExpr *slice_expr = &node->data.slice_expr; |
| ... | ... | @@ -8517,38 +9568,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, |
| 8517 | 9568 | AstNode *end_node = slice_expr->end; |
| 8518 | 9569 | AstNode *sentinel_node = slice_expr->sentinel; |
| 8519 | 9570 | |
| 8520 | | IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr); |
| 8521 | | if (ptr_value == irb->codegen->invalid_instruction) |
| 8522 | | return irb->codegen->invalid_instruction; |
| 9571 | IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr); |
| 9572 | if (ptr_value == irb->codegen->invalid_inst_src) |
| 9573 | return irb->codegen->invalid_inst_src; |
| 8523 | 9574 | |
| 8524 | | IrInstruction *start_value = ir_gen_node(irb, start_node, scope); |
| 8525 | | if (start_value == irb->codegen->invalid_instruction) |
| 8526 | | return irb->codegen->invalid_instruction; |
| 9575 | IrInstSrc *start_value = ir_gen_node(irb, start_node, scope); |
| 9576 | if (start_value == irb->codegen->invalid_inst_src) |
| 9577 | return irb->codegen->invalid_inst_src; |
| 8527 | 9578 | |
| 8528 | | IrInstruction *end_value; |
| 9579 | IrInstSrc *end_value; |
| 8529 | 9580 | if (end_node) { |
| 8530 | 9581 | end_value = ir_gen_node(irb, end_node, scope); |
| 8531 | | if (end_value == irb->codegen->invalid_instruction) |
| 8532 | | return irb->codegen->invalid_instruction; |
| 9582 | if (end_value == irb->codegen->invalid_inst_src) |
| 9583 | return irb->codegen->invalid_inst_src; |
| 8533 | 9584 | } else { |
| 8534 | 9585 | end_value = nullptr; |
| 8535 | 9586 | } |
| 8536 | 9587 | |
| 8537 | | IrInstruction *sentinel_value; |
| 9588 | IrInstSrc *sentinel_value; |
| 8538 | 9589 | if (sentinel_node) { |
| 8539 | 9590 | sentinel_value = ir_gen_node(irb, sentinel_node, scope); |
| 8540 | | if (sentinel_value == irb->codegen->invalid_instruction) |
| 8541 | | return irb->codegen->invalid_instruction; |
| 9591 | if (sentinel_value == irb->codegen->invalid_inst_src) |
| 9592 | return irb->codegen->invalid_inst_src; |
| 8542 | 9593 | } else { |
| 8543 | 9594 | sentinel_value = nullptr; |
| 8544 | 9595 | } |
| 8545 | 9596 | |
| 8546 | | IrInstruction *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value, |
| 9597 | IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value, |
| 8547 | 9598 | sentinel_value, true, result_loc); |
| 8548 | 9599 | return ir_lval_wrap(irb, scope, slice, lval, result_loc); |
| 8549 | 9600 | } |
| 8550 | 9601 | |
| 8551 | | static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 9602 | static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 8552 | 9603 | ResultLoc *result_loc) |
| 8553 | 9604 | { |
| 8554 | 9605 | assert(node->type == NodeTypeCatchExpr); |
| ... | ... | @@ -8562,29 +9613,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8562 | 9613 | assert(var_node->type == NodeTypeSymbol); |
| 8563 | 9614 | Buf *var_name = var_node->data.symbol_expr.symbol; |
| 8564 | 9615 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 8565 | | return irb->codegen->invalid_instruction; |
| 9616 | return irb->codegen->invalid_inst_src; |
| 8566 | 9617 | } |
| 8567 | 9618 | return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc); |
| 8568 | 9619 | } |
| 8569 | 9620 | |
| 8570 | 9621 | |
| 8571 | | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 8572 | | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 8573 | | return irb->codegen->invalid_instruction; |
| 9622 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 9623 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 9624 | return irb->codegen->invalid_inst_src; |
| 8574 | 9625 | |
| 8575 | | IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false); |
| 9626 | IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false); |
| 8576 | 9627 | |
| 8577 | | IrInstruction *is_comptime; |
| 9628 | IrInstSrc *is_comptime; |
| 8578 | 9629 | if (ir_should_inline(irb->exec, parent_scope)) { |
| 8579 | 9630 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); |
| 8580 | 9631 | } else { |
| 8581 | 9632 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err); |
| 8582 | 9633 | } |
| 8583 | 9634 | |
| 8584 | | IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); |
| 8585 | | IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); |
| 8586 | | IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 8587 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 9635 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); |
| 9636 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); |
| 9637 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 9638 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 8588 | 9639 | |
| 8589 | 9640 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc, |
| 8590 | 9641 | is_comptime); |
| ... | ... | @@ -8600,33 +9651,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8600 | 9651 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name, |
| 8601 | 9652 | is_const, is_const, is_shadowable, is_comptime); |
| 8602 | 9653 | err_scope = var->child_scope; |
| 8603 | | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); |
| 9654 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr); |
| 8604 | 9655 | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr); |
| 8605 | 9656 | } else { |
| 8606 | 9657 | err_scope = subexpr_scope; |
| 8607 | 9658 | } |
| 8608 | | IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); |
| 8609 | | if (err_result == irb->codegen->invalid_instruction) |
| 8610 | | return irb->codegen->invalid_instruction; |
| 8611 | | IrBasicBlock *after_err_block = irb->current_basic_block; |
| 9659 | IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); |
| 9660 | if (err_result == irb->codegen->invalid_inst_src) |
| 9661 | return irb->codegen->invalid_inst_src; |
| 9662 | IrBasicBlockSrc *after_err_block = irb->current_basic_block; |
| 8612 | 9663 | if (!instr_is_unreachable(err_result)) |
| 8613 | 9664 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 8614 | 9665 | |
| 8615 | 9666 | ir_set_cursor_at_end_and_append_block(irb, ok_block); |
| 8616 | | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false); |
| 8617 | | IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 9667 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false); |
| 9668 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 8618 | 9669 | ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base); |
| 8619 | | IrBasicBlock *after_ok_block = irb->current_basic_block; |
| 9670 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; |
| 8620 | 9671 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 8621 | 9672 | |
| 8622 | 9673 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 8623 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 9674 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 8624 | 9675 | incoming_values[0] = err_result; |
| 8625 | 9676 | incoming_values[1] = unwrapped_payload; |
| 8626 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 9677 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 8627 | 9678 | incoming_blocks[0] = after_err_block; |
| 8628 | 9679 | incoming_blocks[1] = after_ok_block; |
| 8629 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 9680 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 8630 | 9681 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 8631 | 9682 | } |
| 8632 | 9683 | |
| ... | ... | @@ -8644,7 +9695,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o |
| 8644 | 9695 | return true; |
| 8645 | 9696 | } |
| 8646 | 9697 | |
| 8647 | | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 9698 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name, |
| 8648 | 9699 | Scope *scope, AstNode *source_node, Buf *out_bare_name) |
| 8649 | 9700 | { |
| 8650 | 9701 | if (exec != nullptr && exec->name) { |
| ... | ... | @@ -8673,7 +9724,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 8673 | 9724 | } |
| 8674 | 9725 | } |
| 8675 | 9726 | |
| 8676 | | static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9727 | static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8677 | 9728 | assert(node->type == NodeTypeContainerDecl); |
| 8678 | 9729 | |
| 8679 | 9730 | ContainerKind kind = node->data.container_decl.kind; |
| ... | ... | @@ -8798,7 +9849,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) { |
| 8798 | 9849 | } |
| 8799 | 9850 | } |
| 8800 | 9851 | |
| 8801 | | static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9852 | static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8802 | 9853 | assert(node->type == NodeTypeErrorSetDecl); |
| 8803 | 9854 | |
| 8804 | 9855 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| ... | ... | @@ -8841,7 +9892,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 8841 | 9892 | buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); |
| 8842 | 9893 | add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node), |
| 8843 | 9894 | buf_sprintf("other error here")); |
| 8844 | | return irb->codegen->invalid_instruction; |
| 9895 | return irb->codegen->invalid_inst_src; |
| 8845 | 9896 | } |
| 8846 | 9897 | errors[err->value] = err; |
| 8847 | 9898 | } |
| ... | ... | @@ -8849,11 +9900,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 8849 | 9900 | return ir_build_const_type(irb, parent_scope, node, err_set_type); |
| 8850 | 9901 | } |
| 8851 | 9902 | |
| 8852 | | static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9903 | static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8853 | 9904 | assert(node->type == NodeTypeFnProto); |
| 8854 | 9905 | |
| 8855 | 9906 | size_t param_count = node->data.fn_proto.params.length; |
| 8856 | | IrInstruction **param_types = allocate<IrInstruction*>(param_count); |
| 9907 | IrInstSrc **param_types = allocate<IrInstSrc*>(param_count); |
| 8857 | 9908 | |
| 8858 | 9909 | bool is_var_args = false; |
| 8859 | 9910 | for (size_t i = 0; i < param_count; i += 1) { |
| ... | ... | @@ -8864,59 +9915,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 8864 | 9915 | } |
| 8865 | 9916 | if (param_node->data.param_decl.var_token == nullptr) { |
| 8866 | 9917 | AstNode *type_node = param_node->data.param_decl.type; |
| 8867 | | IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope); |
| 8868 | | if (type_value == irb->codegen->invalid_instruction) |
| 8869 | | return irb->codegen->invalid_instruction; |
| 9918 | IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope); |
| 9919 | if (type_value == irb->codegen->invalid_inst_src) |
| 9920 | return irb->codegen->invalid_inst_src; |
| 8870 | 9921 | param_types[i] = type_value; |
| 8871 | 9922 | } else { |
| 8872 | 9923 | param_types[i] = nullptr; |
| 8873 | 9924 | } |
| 8874 | 9925 | } |
| 8875 | 9926 | |
| 8876 | | IrInstruction *align_value = nullptr; |
| 9927 | IrInstSrc *align_value = nullptr; |
| 8877 | 9928 | if (node->data.fn_proto.align_expr != nullptr) { |
| 8878 | 9929 | align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope); |
| 8879 | | if (align_value == irb->codegen->invalid_instruction) |
| 8880 | | return irb->codegen->invalid_instruction; |
| 9930 | if (align_value == irb->codegen->invalid_inst_src) |
| 9931 | return irb->codegen->invalid_inst_src; |
| 8881 | 9932 | } |
| 8882 | 9933 | |
| 8883 | | IrInstruction *callconv_value = nullptr; |
| 9934 | IrInstSrc *callconv_value = nullptr; |
| 8884 | 9935 | if (node->data.fn_proto.callconv_expr != nullptr) { |
| 8885 | 9936 | callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope); |
| 8886 | | if (callconv_value == irb->codegen->invalid_instruction) |
| 8887 | | return irb->codegen->invalid_instruction; |
| 9937 | if (callconv_value == irb->codegen->invalid_inst_src) |
| 9938 | return irb->codegen->invalid_inst_src; |
| 8888 | 9939 | } |
| 8889 | 9940 | |
| 8890 | | IrInstruction *return_type; |
| 9941 | IrInstSrc *return_type; |
| 8891 | 9942 | if (node->data.fn_proto.return_var_token == nullptr) { |
| 8892 | 9943 | if (node->data.fn_proto.return_type == nullptr) { |
| 8893 | 9944 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); |
| 8894 | 9945 | } else { |
| 8895 | 9946 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); |
| 8896 | | if (return_type == irb->codegen->invalid_instruction) |
| 8897 | | return irb->codegen->invalid_instruction; |
| 9947 | if (return_type == irb->codegen->invalid_inst_src) |
| 9948 | return irb->codegen->invalid_inst_src; |
| 8898 | 9949 | } |
| 8899 | 9950 | } else { |
| 8900 | 9951 | add_node_error(irb->codegen, node, |
| 8901 | 9952 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); |
| 8902 | | return irb->codegen->invalid_instruction; |
| 9953 | return irb->codegen->invalid_inst_src; |
| 8903 | 9954 | //return_type = nullptr; |
| 8904 | 9955 | } |
| 8905 | 9956 | |
| 8906 | 9957 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); |
| 8907 | 9958 | } |
| 8908 | 9959 | |
| 8909 | | static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 9960 | static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 8910 | 9961 | assert(node->type == NodeTypeResume); |
| 8911 | 9962 | |
| 8912 | | IrInstruction *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr); |
| 8913 | | if (target_inst == irb->codegen->invalid_instruction) |
| 8914 | | return irb->codegen->invalid_instruction; |
| 9963 | IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr); |
| 9964 | if (target_inst == irb->codegen->invalid_inst_src) |
| 9965 | return irb->codegen->invalid_inst_src; |
| 8915 | 9966 | |
| 8916 | | return ir_build_resume(irb, scope, node, target_inst); |
| 9967 | return ir_build_resume_src(irb, scope, node, target_inst); |
| 8917 | 9968 | } |
| 8918 | 9969 | |
| 8919 | | static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 9970 | static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 8920 | 9971 | ResultLoc *result_loc) |
| 8921 | 9972 | { |
| 8922 | 9973 | assert(node->type == NodeTypeAwaitExpr); |
| ... | ... | @@ -8937,7 +9988,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 8937 | 9988 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 8938 | 9989 | if (!fn_entry) { |
| 8939 | 9990 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); |
| 8940 | | return irb->codegen->invalid_instruction; |
| 9991 | return irb->codegen->invalid_inst_src; |
| 8941 | 9992 | } |
| 8942 | 9993 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope); |
| 8943 | 9994 | if (existing_suspend_scope) { |
| ... | ... | @@ -8946,24 +9997,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 8946 | 9997 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here")); |
| 8947 | 9998 | existing_suspend_scope->reported_err = true; |
| 8948 | 9999 | } |
| 8949 | | return irb->codegen->invalid_instruction; |
| 10000 | return irb->codegen->invalid_inst_src; |
| 8950 | 10001 | } |
| 8951 | 10002 | |
| 8952 | | IrInstruction *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 8953 | | if (target_inst == irb->codegen->invalid_instruction) |
| 8954 | | return irb->codegen->invalid_instruction; |
| 10003 | IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 10004 | if (target_inst == irb->codegen->invalid_inst_src) |
| 10005 | return irb->codegen->invalid_inst_src; |
| 8955 | 10006 | |
| 8956 | | IrInstruction *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc); |
| 10007 | IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc); |
| 8957 | 10008 | return ir_lval_wrap(irb, scope, await_inst, lval, result_loc); |
| 8958 | 10009 | } |
| 8959 | 10010 | |
| 8960 | | static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 10011 | static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8961 | 10012 | assert(node->type == NodeTypeSuspend); |
| 8962 | 10013 | |
| 8963 | 10014 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 8964 | 10015 | if (!fn_entry) { |
| 8965 | 10016 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); |
| 8966 | | return irb->codegen->invalid_instruction; |
| 10017 | return irb->codegen->invalid_inst_src; |
| 8967 | 10018 | } |
| 8968 | 10019 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope); |
| 8969 | 10020 | if (existing_suspend_scope) { |
| ... | ... | @@ -8972,21 +10023,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod |
| 8972 | 10023 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here")); |
| 8973 | 10024 | existing_suspend_scope->reported_err = true; |
| 8974 | 10025 | } |
| 8975 | | return irb->codegen->invalid_instruction; |
| 10026 | return irb->codegen->invalid_inst_src; |
| 8976 | 10027 | } |
| 8977 | 10028 | |
| 8978 | | IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node); |
| 10029 | IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node); |
| 8979 | 10030 | if (node->data.suspend.block != nullptr) { |
| 8980 | 10031 | ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope); |
| 8981 | 10032 | Scope *child_scope = &suspend_scope->base; |
| 8982 | | IrInstruction *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope); |
| 10033 | IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope); |
| 8983 | 10034 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res)); |
| 8984 | 10035 | } |
| 8985 | 10036 | |
| 8986 | | return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin)); |
| 10037 | return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin)); |
| 8987 | 10038 | } |
| 8988 | 10039 | |
| 8989 | | static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope, |
| 10040 | static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope, |
| 8990 | 10041 | LVal lval, ResultLoc *result_loc) |
| 8991 | 10042 | { |
| 8992 | 10043 | assert(scope); |
| ... | ... | @@ -9035,39 +10086,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 9035 | 10086 | return ir_gen_return(irb, scope, node, lval, result_loc); |
| 9036 | 10087 | case NodeTypeFieldAccessExpr: |
| 9037 | 10088 | { |
| 9038 | | IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node); |
| 9039 | | if (ptr_instruction == irb->codegen->invalid_instruction) |
| 10089 | IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node); |
| 10090 | if (ptr_instruction == irb->codegen->invalid_inst_src) |
| 9040 | 10091 | return ptr_instruction; |
| 9041 | 10092 | if (lval == LValPtr) |
| 9042 | 10093 | return ptr_instruction; |
| 9043 | 10094 | |
| 9044 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 10095 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 9045 | 10096 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 9046 | 10097 | } |
| 9047 | 10098 | case NodeTypePtrDeref: { |
| 9048 | 10099 | AstNode *expr_node = node->data.ptr_deref_expr.target; |
| 9049 | | IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 9050 | | if (value == irb->codegen->invalid_instruction) |
| 10100 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 10101 | if (value == irb->codegen->invalid_inst_src) |
| 9051 | 10102 | return value; |
| 9052 | 10103 | |
| 9053 | 10104 | // We essentially just converted any lvalue from &(x.*) to (&x).*; |
| 9054 | 10105 | // this inhibits checking that x is a pointer later, so we directly |
| 9055 | 10106 | // record whether the pointer check is needed |
| 9056 | | IrInstruction *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc); |
| 10107 | IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc); |
| 9057 | 10108 | return ir_expr_wrap(irb, scope, un_op, result_loc); |
| 9058 | 10109 | } |
| 9059 | 10110 | case NodeTypeUnwrapOptional: { |
| 9060 | 10111 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| 9061 | 10112 | |
| 9062 | | IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 9063 | | if (maybe_ptr == irb->codegen->invalid_instruction) |
| 9064 | | return irb->codegen->invalid_instruction; |
| 10113 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 10114 | if (maybe_ptr == irb->codegen->invalid_inst_src) |
| 10115 | return irb->codegen->invalid_inst_src; |
| 9065 | 10116 | |
| 9066 | | IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false); |
| 10117 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false); |
| 9067 | 10118 | if (lval == LValPtr) |
| 9068 | 10119 | return unwrapped_ptr; |
| 9069 | 10120 | |
| 9070 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 10121 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 9071 | 10122 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 9072 | 10123 | } |
| 9073 | 10124 | case NodeTypeBoolLiteral: |
| ... | ... | @@ -9125,7 +10176,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 9125 | 10176 | case NodeTypeInferredArrayType: |
| 9126 | 10177 | add_node_error(irb->codegen, node, |
| 9127 | 10178 | buf_sprintf("inferred array size invalid here")); |
| 9128 | | return irb->codegen->invalid_instruction; |
| 10179 | return irb->codegen->invalid_inst_src; |
| 9129 | 10180 | case NodeTypeVarFieldType: |
| 9130 | 10181 | return ir_lval_wrap(irb, scope, |
| 9131 | 10182 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc); |
| ... | ... | @@ -9139,7 +10190,7 @@ static ResultLoc *no_result_loc(void) { |
| 9139 | 10190 | return &result_loc_none->base; |
| 9140 | 10191 | } |
| 9141 | 10192 | |
| 9142 | | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, |
| 10193 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, |
| 9143 | 10194 | ResultLoc *result_loc) |
| 9144 | 10195 | { |
| 9145 | 10196 | if (result_loc == nullptr) { |
| ... | ... | @@ -9156,8 +10207,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc |
| 9156 | 10207 | } else { |
| 9157 | 10208 | child_scope = &create_expr_scope(irb->codegen, node, scope)->base; |
| 9158 | 10209 | } |
| 9159 | | IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc); |
| 9160 | | if (result == irb->codegen->invalid_instruction) { |
| 10210 | IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc); |
| 10211 | if (result == irb->codegen->invalid_inst_src) { |
| 9161 | 10212 | if (irb->exec->first_err_trace_msg == nullptr) { |
| 9162 | 10213 | irb->exec->first_err_trace_msg = irb->codegen->trace_err; |
| 9163 | 10214 | } |
| ... | ... | @@ -9165,11 +10216,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc |
| 9165 | 10216 | return result; |
| 9166 | 10217 | } |
| 9167 | 10218 | |
| 9168 | | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) { |
| 10219 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) { |
| 9169 | 10220 | return ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 9170 | 10221 | } |
| 9171 | 10222 | |
| 9172 | | static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) { |
| 10223 | static void invalidate_exec(IrExecutableSrc *exec, ErrorMsg *msg) { |
| 10224 | if (exec->first_err_trace_msg != nullptr) |
| 10225 | return; |
| 10226 | |
| 10227 | exec->first_err_trace_msg = msg; |
| 10228 | |
| 10229 | for (size_t i = 0; i < exec->tld_list.length; i += 1) { |
| 10230 | exec->tld_list.items[i]->resolution = TldResolutionInvalid; |
| 10231 | } |
| 10232 | } |
| 10233 | |
| 10234 | static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) { |
| 9173 | 10235 | if (exec->first_err_trace_msg != nullptr) |
| 9174 | 10236 | return; |
| 9175 | 10237 | |
| ... | ... | @@ -9183,24 +10245,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) { |
| 9183 | 10245 | invalidate_exec(exec->source_exec, msg); |
| 9184 | 10246 | } |
| 9185 | 10247 | |
| 9186 | | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) { |
| 10248 | |
| 10249 | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable) { |
| 9187 | 10250 | assert(node->owner); |
| 9188 | 10251 | |
| 9189 | | IrBuilder ir_builder = {0}; |
| 9190 | | IrBuilder *irb = &ir_builder; |
| 10252 | IrBuilderSrc ir_builder = {0}; |
| 10253 | IrBuilderSrc *irb = &ir_builder; |
| 9191 | 10254 | |
| 9192 | 10255 | irb->codegen = codegen; |
| 9193 | 10256 | irb->exec = ir_executable; |
| 9194 | 10257 | irb->main_block_node = node; |
| 9195 | 10258 | |
| 9196 | | IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry"); |
| 10259 | IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry"); |
| 9197 | 10260 | ir_set_cursor_at_end_and_append_block(irb, entry_block); |
| 9198 | 10261 | // Entry block gets a reference because we enter it to begin. |
| 9199 | 10262 | ir_ref_bb(irb->current_basic_block); |
| 9200 | 10263 | |
| 9201 | | IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 10264 | IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 9202 | 10265 | |
| 9203 | | if (result == irb->codegen->invalid_instruction) |
| 10266 | if (result == irb->codegen->invalid_inst_src) |
| 9204 | 10267 | return false; |
| 9205 | 10268 | |
| 9206 | 10269 | if (irb->exec->first_err_trace_msg != nullptr) { |
| ... | ... | @@ -9209,9 +10272,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 9209 | 10272 | } |
| 9210 | 10273 | |
| 9211 | 10274 | if (!instr_is_unreachable(result)) { |
| 9212 | | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr)); |
| 10275 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr)); |
| 9213 | 10276 | // no need for save_err_ret_addr because this cannot return error |
| 9214 | | ir_mark_gen(ir_build_return(irb, scope, result->source_node, result)); |
| 10277 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| 10278 | result_loc_ret->base.id = ResultLocIdReturn; |
| 10279 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| 10280 | ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base)); |
| 10281 | ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result)); |
| 9215 | 10282 | } |
| 9216 | 10283 | |
| 9217 | 10284 | return true; |
| ... | ... | @@ -9220,7 +10287,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 9220 | 10287 | bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { |
| 9221 | 10288 | assert(fn_entry); |
| 9222 | 10289 | |
| 9223 | | IrExecutable *ir_executable = fn_entry->ir_executable; |
| 10290 | IrExecutableSrc *ir_executable = fn_entry->ir_executable; |
| 9224 | 10291 | AstNode *body_node = fn_entry->body_node; |
| 9225 | 10292 | |
| 9226 | 10293 | assert(fn_entry->child_scope); |
| ... | ... | @@ -9228,14 +10295,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { |
| 9228 | 10295 | return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable); |
| 9229 | 10296 | } |
| 9230 | 10297 | |
| 9231 | | static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) { |
| 10298 | static void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) { |
| 10299 | if (!exec || !exec->source_node || limit < 0) return; |
| 10300 | add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here")); |
| 10301 | |
| 10302 | ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1); |
| 10303 | } |
| 10304 | |
| 10305 | static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutableSrc *exec, ErrorMsg *err_msg, int limit) { |
| 9232 | 10306 | if (!exec || !exec->source_node || limit < 0) return; |
| 9233 | 10307 | add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here")); |
| 9234 | 10308 | |
| 9235 | | ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1); |
| 10309 | ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1); |
| 9236 | 10310 | } |
| 9237 | 10311 | |
| 9238 | | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) { |
| 10312 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg) { |
| 9239 | 10313 | ErrorMsg *err_msg = add_node_error(codegen, source_node, msg); |
| 9240 | 10314 | invalidate_exec(exec, err_msg); |
| 9241 | 10315 | if (exec->parent_exec) { |
| ... | ... | @@ -9244,26 +10318,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo |
| 9244 | 10318 | return err_msg; |
| 9245 | 10319 | } |
| 9246 | 10320 | |
| 10321 | static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) { |
| 10322 | ErrorMsg *err_msg = add_node_error(codegen, source_node, msg); |
| 10323 | invalidate_exec_gen(exec, err_msg); |
| 10324 | if (exec->parent_exec) { |
| 10325 | ir_add_call_stack_errors_gen(codegen, exec, err_msg, 10); |
| 10326 | } |
| 10327 | return err_msg; |
| 10328 | } |
| 10329 | |
| 9247 | 10330 | static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) { |
| 9248 | | return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg); |
| 10331 | return exec_add_error_node_gen(ira->codegen, ira->new_irb.exec, source_node, msg); |
| 9249 | 10332 | } |
| 9250 | 10333 | |
| 9251 | 10334 | static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) { |
| 9252 | 10335 | if (ira != nullptr) |
| 9253 | | return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg); |
| 10336 | return exec_add_error_node_gen(codegen, ira->new_irb.exec, source_node, msg); |
| 9254 | 10337 | else |
| 9255 | 10338 | return add_node_error(codegen, source_node, msg); |
| 9256 | 10339 | } |
| 9257 | 10340 | |
| 9258 | | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { |
| 10341 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) { |
| 9259 | 10342 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 9260 | 10343 | } |
| 9261 | 10344 | |
| 9262 | | static void ir_assert(bool ok, IrInstruction *source_instruction) { |
| 10345 | static void ir_assert(bool ok, IrInst *source_instruction) { |
| 9263 | 10346 | if (ok) return; |
| 9264 | 10347 | src_assert(ok, source_instruction->source_node); |
| 9265 | 10348 | } |
| 9266 | 10349 | |
| 10350 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction) { |
| 10351 | if (ok) return; |
| 10352 | src_assert(ok, source_instruction->base.source_node); |
| 10353 | } |
| 10354 | |
| 9267 | 10355 | // This function takes a comptime ptr and makes the child const value conform to the type |
| 9268 | 10356 | // described by the pointer. |
| 9269 | 10357 | static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| ... | ... | @@ -9309,43 +10397,37 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va |
| 9309 | 10397 | return val; |
| 9310 | 10398 | } |
| 9311 | 10399 | |
| 9312 | | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 9313 | | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 10400 | static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *exec) { |
| 10401 | IrBasicBlockGen *bb = exec->basic_block_list.at(0); |
| 9314 | 10402 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| 9315 | | IrInstruction *instruction = bb->instruction_list.at(i); |
| 9316 | | if (instruction->id == IrInstructionIdReturn) { |
| 9317 | | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; |
| 9318 | | IrInstruction *operand = ret_inst->operand; |
| 9319 | | if (operand->value->special == ConstValSpecialRuntime) { |
| 9320 | | exec_add_error_node(codegen, exec, operand->source_node, |
| 9321 | | buf_sprintf("unable to evaluate constant expression")); |
| 9322 | | return codegen->invalid_instruction->value; |
| 9323 | | } |
| 9324 | | return operand->value; |
| 9325 | | } else if (ir_has_side_effects(instruction)) { |
| 10403 | IrInstGen *instruction = bb->instruction_list.at(i); |
| 10404 | if (instruction->id == IrInstGenIdReturn) { |
| 10405 | return ErrorNone; |
| 10406 | } else if (ir_inst_gen_has_side_effects(instruction)) { |
| 9326 | 10407 | if (instr_is_comptime(instruction)) { |
| 9327 | 10408 | switch (instruction->id) { |
| 9328 | | case IrInstructionIdUnwrapErrPayload: |
| 9329 | | case IrInstructionIdUnionFieldPtr: |
| 10409 | case IrInstGenIdUnwrapErrPayload: |
| 10410 | case IrInstGenIdOptionalUnwrapPtr: |
| 10411 | case IrInstGenIdUnionFieldPtr: |
| 9330 | 10412 | continue; |
| 9331 | 10413 | default: |
| 9332 | 10414 | break; |
| 9333 | 10415 | } |
| 9334 | 10416 | } |
| 9335 | | if (get_scope_typeof(instruction->scope) != nullptr) { |
| 10417 | if (get_scope_typeof(instruction->base.scope) != nullptr) { |
| 9336 | 10418 | // doesn't count, it's inside a @TypeOf() |
| 9337 | 10419 | continue; |
| 9338 | 10420 | } |
| 9339 | | exec_add_error_node(codegen, exec, instruction->source_node, |
| 10421 | exec_add_error_node_gen(codegen, exec, instruction->base.source_node, |
| 9340 | 10422 | buf_sprintf("unable to evaluate constant expression")); |
| 9341 | | return codegen->invalid_instruction->value; |
| 10423 | return ErrorSemanticAnalyzeFail; |
| 9342 | 10424 | } |
| 9343 | 10425 | } |
| 9344 | 10426 | zig_unreachable(); |
| 9345 | 10427 | } |
| 9346 | 10428 | |
| 9347 | | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 9348 | | if (ir_should_inline(ira->new_irb.exec, source_instruction->scope)) { |
| 10429 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) { |
| 10430 | if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) { |
| 9349 | 10431 | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); |
| 9350 | 10432 | return false; |
| 9351 | 10433 | } |
| ... | ... | @@ -10079,7 +11161,39 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) { |
| 10079 | 11161 | } |
| 10080 | 11162 | } |
| 10081 | 11163 | |
| 10082 | | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type, |
| 11164 | static void value_to_bigfloat(BigFloat *out, ZigValue *val) { |
| 11165 | switch (val->type->id) { |
| 11166 | case ZigTypeIdInt: |
| 11167 | case ZigTypeIdComptimeInt: |
| 11168 | bigfloat_init_bigint(out, &val->data.x_bigint); |
| 11169 | return; |
| 11170 | case ZigTypeIdComptimeFloat: |
| 11171 | *out = val->data.x_bigfloat; |
| 11172 | return; |
| 11173 | case ZigTypeIdFloat: switch (val->type->data.floating.bit_count) { |
| 11174 | case 16: |
| 11175 | bigfloat_init_16(out, val->data.x_f16); |
| 11176 | return; |
| 11177 | case 32: |
| 11178 | bigfloat_init_32(out, val->data.x_f32); |
| 11179 | return; |
| 11180 | case 64: |
| 11181 | bigfloat_init_64(out, val->data.x_f64); |
| 11182 | return; |
| 11183 | case 80: |
| 11184 | zig_panic("TODO"); |
| 11185 | case 128: |
| 11186 | bigfloat_init_128(out, val->data.x_f128); |
| 11187 | return; |
| 11188 | default: |
| 11189 | zig_unreachable(); |
| 11190 | } |
| 11191 | default: |
| 11192 | zig_unreachable(); |
| 11193 | } |
| 11194 | } |
| 11195 | |
| 11196 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type, |
| 10083 | 11197 | bool explicit_cast) |
| 10084 | 11198 | { |
| 10085 | 11199 | if (type_is_invalid(other_type)) { |
| ... | ... | @@ -10173,7 +11287,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10173 | 11287 | } |
| 10174 | 11288 | Buf *val_buf = buf_alloc(); |
| 10175 | 11289 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10176 | | ir_add_error(ira, instruction, |
| 11290 | ir_add_error_node(ira, instruction->base.source_node, |
| 10177 | 11291 | buf_sprintf("integer value %s has no representation in type '%s'", |
| 10178 | 11292 | buf_ptr(val_buf), |
| 10179 | 11293 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10268,7 +11382,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10268 | 11382 | } |
| 10269 | 11383 | Buf *val_buf = buf_alloc(); |
| 10270 | 11384 | float_append_buf(val_buf, const_val); |
| 10271 | | ir_add_error(ira, instruction, |
| 11385 | ir_add_error_node(ira, instruction->base.source_node, |
| 10272 | 11386 | buf_sprintf("cast of value %s to type '%s' loses information", |
| 10273 | 11387 | buf_ptr(val_buf), |
| 10274 | 11388 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10277,7 +11391,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10277 | 11391 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 10278 | 11392 | Buf *val_buf = buf_alloc(); |
| 10279 | 11393 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10280 | | ir_add_error(ira, instruction, |
| 11394 | ir_add_error_node(ira, instruction->base.source_node, |
| 10281 | 11395 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 10282 | 11396 | buf_ptr(val_buf), |
| 10283 | 11397 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10298,7 +11412,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10298 | 11412 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 10299 | 11413 | Buf *val_buf = buf_alloc(); |
| 10300 | 11414 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10301 | | ir_add_error(ira, instruction, |
| 11415 | ir_add_error_node(ira, instruction->base.source_node, |
| 10302 | 11416 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 10303 | 11417 | buf_ptr(val_buf), |
| 10304 | 11418 | buf_ptr(&child_type->name))); |
| ... | ... | @@ -10321,7 +11435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10321 | 11435 | Buf *val_buf = buf_alloc(); |
| 10322 | 11436 | float_append_buf(val_buf, const_val); |
| 10323 | 11437 | |
| 10324 | | ir_add_error(ira, instruction, |
| 11438 | ir_add_error_node(ira, instruction->base.source_node, |
| 10325 | 11439 | buf_sprintf("fractional component prevents float value %s from being casted to type '%s'", |
| 10326 | 11440 | buf_ptr(val_buf), |
| 10327 | 11441 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10351,7 +11465,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10351 | 11465 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10352 | 11466 | } |
| 10353 | 11467 | |
| 10354 | | ir_add_error(ira, instruction, |
| 11468 | ir_add_error_node(ira, instruction->base.source_node, |
| 10355 | 11469 | buf_sprintf("%s value %s cannot be coerced to type '%s'", |
| 10356 | 11470 | num_lit_str, |
| 10357 | 11471 | buf_ptr(val_buf), |
| ... | ... | @@ -10805,11 +11919,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * |
| 10805 | 11919 | } |
| 10806 | 11920 | |
| 10807 | 11921 | static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, |
| 10808 | | IrInstruction **instructions, size_t instruction_count) |
| 11922 | IrInstGen **instructions, size_t instruction_count) |
| 10809 | 11923 | { |
| 10810 | 11924 | Error err; |
| 10811 | 11925 | assert(instruction_count >= 1); |
| 10812 | | IrInstruction *prev_inst; |
| 11926 | IrInstGen *prev_inst; |
| 10813 | 11927 | size_t i = 0; |
| 10814 | 11928 | for (;;) { |
| 10815 | 11929 | prev_inst = instructions[i]; |
| ... | ... | @@ -10829,7 +11943,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10829 | 11943 | size_t errors_count = 0; |
| 10830 | 11944 | ZigType *err_set_type = nullptr; |
| 10831 | 11945 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10832 | | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { |
| 11946 | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) { |
| 10833 | 11947 | return ira->codegen->builtin_types.entry_invalid; |
| 10834 | 11948 | } |
| 10835 | 11949 | if (type_is_global_error_set(prev_inst->value->type)) { |
| ... | ... | @@ -10849,7 +11963,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10849 | 11963 | bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); |
| 10850 | 11964 | bool convert_to_const_slice = false; |
| 10851 | 11965 | for (; i < instruction_count; i += 1) { |
| 10852 | | IrInstruction *cur_inst = instructions[i]; |
| 11966 | IrInstGen *cur_inst = instructions[i]; |
| 10853 | 11967 | ZigType *cur_type = cur_inst->value->type; |
| 10854 | 11968 | ZigType *prev_type = prev_inst->value->type; |
| 10855 | 11969 | |
| ... | ... | @@ -10871,14 +11985,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10871 | 11985 | } |
| 10872 | 11986 | |
| 10873 | 11987 | if (prev_type->id == ZigTypeIdErrorSet) { |
| 10874 | | ir_assert(err_set_type != nullptr, prev_inst); |
| 11988 | ir_assert_gen(err_set_type != nullptr, prev_inst); |
| 10875 | 11989 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 10876 | 11990 | if (type_is_global_error_set(err_set_type)) { |
| 10877 | 11991 | continue; |
| 10878 | 11992 | } |
| 10879 | 11993 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 10880 | 11994 | cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 10881 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 11995 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 10882 | 11996 | return ira->codegen->builtin_types.entry_invalid; |
| 10883 | 11997 | } |
| 10884 | 11998 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -10946,7 +12060,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10946 | 12060 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 10947 | 12061 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 10948 | 12062 | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 10949 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 12063 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 10950 | 12064 | return ira->codegen->builtin_types.entry_invalid; |
| 10951 | 12065 | } |
| 10952 | 12066 | if (!allow_infer && type_is_global_error_set(cur_err_set_type)) { |
| ... | ... | @@ -11001,7 +12115,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11001 | 12115 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 11002 | 12116 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 11003 | 12117 | cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 11004 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 12118 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 11005 | 12119 | return ira->codegen->builtin_types.entry_invalid; |
| 11006 | 12120 | } |
| 11007 | 12121 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -11024,7 +12138,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11024 | 12138 | err_set_type = cur_type; |
| 11025 | 12139 | } |
| 11026 | 12140 | |
| 11027 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) { |
| 12141 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) { |
| 11028 | 12142 | return ira->codegen->builtin_types.entry_invalid; |
| 11029 | 12143 | } |
| 11030 | 12144 | |
| ... | ... | @@ -11087,11 +12201,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11087 | 12201 | bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 11088 | 12202 | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 11089 | 12203 | |
| 11090 | | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 12204 | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) { |
| 11091 | 12205 | return ira->codegen->builtin_types.entry_invalid; |
| 11092 | 12206 | } |
| 11093 | 12207 | |
| 11094 | | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 12208 | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 11095 | 12209 | return ira->codegen->builtin_types.entry_invalid; |
| 11096 | 12210 | } |
| 11097 | 12211 | |
| ... | ... | @@ -11268,7 +12382,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11268 | 12382 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 11269 | 12383 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 11270 | 12384 | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 11271 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 12385 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 11272 | 12386 | return ira->codegen->builtin_types.entry_invalid; |
| 11273 | 12387 | } |
| 11274 | 12388 | if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) || |
| ... | ... | @@ -11463,9 +12577,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11463 | 12577 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 11464 | 12578 | buf_sprintf("incompatible types: '%s' and '%s'", |
| 11465 | 12579 | buf_ptr(&prev_type->name), buf_ptr(&cur_type->name))); |
| 11466 | | add_error_note(ira->codegen, msg, prev_inst->source_node, |
| 12580 | add_error_note(ira->codegen, msg, prev_inst->base.source_node, |
| 11467 | 12581 | buf_sprintf("type '%s' here", buf_ptr(&prev_type->name))); |
| 11468 | | add_error_note(ira->codegen, msg, cur_inst->source_node, |
| 12582 | add_error_note(ira->codegen, msg, cur_inst->base.source_node, |
| 11469 | 12583 | buf_sprintf("type '%s' here", buf_ptr(&cur_type->name))); |
| 11470 | 12584 | |
| 11471 | 12585 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11535,7 +12649,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11535 | 12649 | } |
| 11536 | 12650 | } |
| 11537 | 12651 | |
| 11538 | | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 12652 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr, |
| 11539 | 12653 | CastOp cast_op, |
| 11540 | 12654 | ZigValue *other_val, ZigType *other_type, |
| 11541 | 12655 | ZigValue *const_val, ZigType *new_type) |
| ... | ... | @@ -11635,58 +12749,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 11635 | 12749 | return true; |
| 11636 | 12750 | } |
| 11637 | 12751 | |
| 11638 | | static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) { |
| 11639 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11640 | | old_instruction->scope, old_instruction->source_node); |
| 11641 | | IrInstruction *new_instruction = &const_instruction->base; |
| 12752 | static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) { |
| 12753 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12754 | inst->scope, inst->source_node); |
| 12755 | IrInstGen *new_instruction = &const_instruction->base; |
| 11642 | 12756 | new_instruction->value->type = ty; |
| 11643 | 12757 | new_instruction->value->special = ConstValSpecialStatic; |
| 11644 | 12758 | return new_instruction; |
| 11645 | 12759 | } |
| 11646 | 12760 | |
| 11647 | | static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 11648 | | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb, |
| 12761 | static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) { |
| 12762 | IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, |
| 11649 | 12763 | old_instruction->scope, old_instruction->source_node); |
| 11650 | 12764 | return &const_instruction->base; |
| 11651 | 12765 | } |
| 11652 | 12766 | |
| 11653 | | // This function initializes the new IrInstruction with the provided ZigValue, |
| 12767 | // This function initializes the new IrInstGen with the provided ZigValue, |
| 11654 | 12768 | // rather than creating a new one. |
| 11655 | | static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) { |
| 11656 | | IrInstruction *result = ir_const_noval(ira, old_instruction); |
| 12769 | static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) { |
| 12770 | IrInstGen *result = ir_const_noval(ira, old_instruction); |
| 11657 | 12771 | result->value = val; |
| 11658 | 12772 | return result; |
| 11659 | 12773 | } |
| 11660 | 12774 | |
| 11661 | | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 12775 | static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 11662 | 12776 | ZigType *wanted_type, CastOp cast_op) |
| 11663 | 12777 | { |
| 11664 | 12778 | if (instr_is_comptime(value) || !type_has_bits(wanted_type)) { |
| 11665 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12779 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11666 | 12780 | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type, |
| 11667 | 12781 | result->value, wanted_type)) |
| 11668 | 12782 | { |
| 11669 | | return ira->codegen->invalid_instruction; |
| 12783 | return ira->codegen->invalid_inst_gen; |
| 11670 | 12784 | } |
| 11671 | 12785 | return result; |
| 11672 | 12786 | } else { |
| 11673 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); |
| 11674 | | result->value->type = wanted_type; |
| 11675 | | return result; |
| 12787 | return ir_build_cast(ira, source_instr, wanted_type, value, cast_op); |
| 11676 | 12788 | } |
| 11677 | 12789 | } |
| 11678 | 12790 | |
| 11679 | | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 11680 | | IrInstruction *value, ZigType *wanted_type) |
| 12791 | static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12792 | IrInstGen *value, ZigType *wanted_type) |
| 11681 | 12793 | { |
| 11682 | | assert(value->value->type->id == ZigTypeIdPointer); |
| 12794 | ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr); |
| 11683 | 12795 | |
| 11684 | 12796 | Error err; |
| 11685 | 12797 | |
| 11686 | 12798 | if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type, |
| 11687 | 12799 | ResolveStatusAlignmentKnown))) |
| 11688 | 12800 | { |
| 11689 | | return ira->codegen->invalid_instruction; |
| 12801 | return ira->codegen->invalid_inst_gen; |
| 11690 | 12802 | } |
| 11691 | 12803 | |
| 11692 | 12804 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type)); |
| ... | ... | @@ -11694,9 +12806,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 11694 | 12806 | if (instr_is_comptime(value)) { |
| 11695 | 12807 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node); |
| 11696 | 12808 | if (pointee == nullptr) |
| 11697 | | return ira->codegen->invalid_instruction; |
| 12809 | return ira->codegen->invalid_inst_gen; |
| 11698 | 12810 | if (pointee->special != ConstValSpecialRuntime) { |
| 11699 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12811 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11700 | 12812 | result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11701 | 12813 | result->value->data.x_ptr.mut = value->value->data.x_ptr.mut; |
| 11702 | 12814 | result->value->data.x_ptr.data.base_array.array_val = pointee; |
| ... | ... | @@ -11705,70 +12817,71 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 11705 | 12817 | } |
| 11706 | 12818 | } |
| 11707 | 12819 | |
| 11708 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11709 | | wanted_type, value, CastOpBitCast); |
| 11710 | | result->value->type = wanted_type; |
| 11711 | | return result; |
| 12820 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 11712 | 12821 | } |
| 11713 | 12822 | |
| 11714 | | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 11715 | | IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc) |
| 12823 | static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr, |
| 12824 | IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc) |
| 11716 | 12825 | { |
| 11717 | 12826 | Error err; |
| 11718 | 12827 | |
| 11719 | 12828 | if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type, |
| 11720 | 12829 | ResolveStatusAlignmentKnown))) |
| 11721 | 12830 | { |
| 11722 | | return ira->codegen->invalid_instruction; |
| 12831 | return ira->codegen->invalid_inst_gen; |
| 11723 | 12832 | } |
| 11724 | 12833 | |
| 11725 | 12834 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| 11726 | 12835 | |
| 11727 | 12836 | if (instr_is_comptime(array_ptr)) { |
| 11728 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); |
| 12837 | ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 12838 | if (array_ptr_val == nullptr) |
| 12839 | return ira->codegen->invalid_inst_gen; |
| 12840 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node); |
| 11729 | 12841 | if (pointee == nullptr) |
| 11730 | | return ira->codegen->invalid_instruction; |
| 12842 | return ira->codegen->invalid_inst_gen; |
| 11731 | 12843 | if (pointee->special != ConstValSpecialRuntime) { |
| 11732 | | assert(array_ptr->value->type->id == ZigTypeIdPointer); |
| 11733 | | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; |
| 12844 | assert(array_ptr_val->type->id == ZigTypeIdPointer); |
| 12845 | ZigType *array_type = array_ptr_val->type->data.pointer.child_type; |
| 11734 | 12846 | assert(is_slice(wanted_type)); |
| 11735 | 12847 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 11736 | 12848 | |
| 11737 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12849 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11738 | 12850 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11739 | | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; |
| 12851 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 11740 | 12852 | result->value->type = wanted_type; |
| 11741 | 12853 | return result; |
| 11742 | 12854 | } |
| 11743 | 12855 | } |
| 11744 | 12856 | |
| 11745 | 12857 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11746 | | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, |
| 11747 | | false, true); |
| 11748 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12858 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 12859 | if (type_is_invalid(result_loc_inst->value->type) || |
| 12860 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 12861 | { |
| 11749 | 12862 | return result_loc_inst; |
| 11750 | 12863 | } |
| 11751 | 12864 | return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); |
| 11752 | 12865 | } |
| 11753 | 12866 | |
| 11754 | | static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| 12867 | static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) { |
| 11755 | 12868 | assert(old_bb); |
| 11756 | 12869 | |
| 11757 | | if (old_bb->other) { |
| 11758 | | if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) { |
| 11759 | | return old_bb->other; |
| 12870 | if (old_bb->child) { |
| 12871 | if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) { |
| 12872 | return old_bb->child; |
| 11760 | 12873 | } |
| 11761 | 12874 | } |
| 11762 | 12875 | |
| 11763 | | IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb); |
| 12876 | IrBasicBlockGen *new_bb = ir_build_bb_from(ira, old_bb); |
| 11764 | 12877 | new_bb->ref_instruction = ref_old_instruction; |
| 11765 | 12878 | |
| 11766 | 12879 | return new_bb; |
| 11767 | 12880 | } |
| 11768 | 12881 | |
| 11769 | | static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| 12882 | static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) { |
| 11770 | 12883 | assert(ref_old_instruction != nullptr); |
| 11771 | | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 12884 | IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 11772 | 12885 | if (new_bb->must_be_comptime_source_instr) { |
| 11773 | 12886 | ErrorMsg *msg = ir_add_error(ira, ref_old_instruction, |
| 11774 | 12887 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| ... | ... | @@ -11779,24 +12892,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, |
| 11779 | 12892 | return new_bb; |
| 11780 | 12893 | } |
| 11781 | 12894 | |
| 11782 | | static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) { |
| 11783 | | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr); |
| 12895 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) { |
| 12896 | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr); |
| 11784 | 12897 | ira->instruction_index = 0; |
| 11785 | 12898 | ira->old_irb.current_basic_block = old_bb; |
| 11786 | 12899 | ira->const_predecessor_bb = const_predecessor_bb; |
| 11787 | 12900 | ira->old_bb_index = old_bb->index; |
| 11788 | 12901 | } |
| 11789 | 12902 | |
| 11790 | | static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb, |
| 12903 | static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBlockSrc *next_bb, |
| 11791 | 12904 | IrSuspendPosition *suspend_pos) |
| 11792 | 12905 | { |
| 11793 | 12906 | if (ira->codegen->verbose_ir) { |
| 11794 | | fprintf(stderr, "suspend %s_%zu %s_%zu #%" PRIu32 " (%zu,%zu)\n", |
| 12907 | fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n", |
| 11795 | 12908 | ira->old_irb.current_basic_block->name_hint, |
| 11796 | 12909 | ira->old_irb.current_basic_block->debug_id, |
| 11797 | 12910 | ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint, |
| 11798 | 12911 | ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id, |
| 11799 | | ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id, |
| 12912 | ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id, |
| 11800 | 12913 | ira->old_bb_index, ira->instruction_index); |
| 11801 | 12914 | } |
| 11802 | 12915 | suspend_pos->basic_block_index = ira->old_bb_index; |
| ... | ... | @@ -11811,13 +12924,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction |
| 11811 | 12924 | assert(ira->old_irb.current_basic_block == next_bb); |
| 11812 | 12925 | ira->instruction_index = 0; |
| 11813 | 12926 | ira->const_predecessor_bb = nullptr; |
| 11814 | | next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction); |
| 11815 | | ira->new_irb.current_basic_block = next_bb->other; |
| 12927 | next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction); |
| 12928 | ira->new_irb.current_basic_block = next_bb->child; |
| 11816 | 12929 | } |
| 11817 | 12930 | return ira->codegen->unreach_instruction; |
| 11818 | 12931 | } |
| 11819 | 12932 | |
| 11820 | | static IrInstruction *ira_resume(IrAnalyze *ira) { |
| 12933 | static IrInstGen *ira_resume(IrAnalyze *ira) { |
| 11821 | 12934 | IrSuspendPosition pos = ira->resume_stack.pop(); |
| 11822 | 12935 | if (ira->codegen->verbose_ir) { |
| 11823 | 12936 | fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index); |
| ... | ... | @@ -11830,12 +12943,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) { |
| 11830 | 12943 | ira->instruction_index = pos.instruction_index; |
| 11831 | 12944 | assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length); |
| 11832 | 12945 | if (ira->codegen->verbose_ir) { |
| 11833 | | fprintf(stderr, "%s_%zu #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint, |
| 12946 | fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint, |
| 11834 | 12947 | ira->old_irb.current_basic_block->debug_id, |
| 11835 | | ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id); |
| 12948 | ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id); |
| 11836 | 12949 | } |
| 11837 | 12950 | ira->const_predecessor_bb = nullptr; |
| 11838 | | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other; |
| 12951 | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child; |
| 11839 | 12952 | assert(ira->new_irb.current_basic_block != nullptr); |
| 11840 | 12953 | return ira->codegen->unreach_instruction; |
| 11841 | 12954 | } |
| ... | ... | @@ -11846,8 +12959,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11846 | 12959 | bool need_repeat = true; |
| 11847 | 12960 | for (;;) { |
| 11848 | 12961 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 11849 | | IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| 11850 | | if (old_bb->other == nullptr && old_bb->suspend_instruction_ref == nullptr) { |
| 12962 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| 12963 | if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) { |
| 11851 | 12964 | ira->old_bb_index += 1; |
| 11852 | 12965 | continue; |
| 11853 | 12966 | } |
| ... | ... | @@ -11855,8 +12968,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11855 | 12968 | // if it's a suspended block, |
| 11856 | 12969 | // then skip it |
| 11857 | 12970 | if (old_bb->suspended || |
| 11858 | | (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) || |
| 11859 | | (old_bb->other != nullptr && old_bb->other->already_appended)) |
| 12971 | (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) || |
| 12972 | (old_bb->child != nullptr && old_bb->child->already_appended)) |
| 11860 | 12973 | { |
| 11861 | 12974 | ira->old_bb_index += 1; |
| 11862 | 12975 | continue; |
| ... | ... | @@ -11870,10 +12983,10 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11870 | 12983 | return; |
| 11871 | 12984 | } |
| 11872 | 12985 | |
| 11873 | | if (old_bb->other == nullptr) { |
| 11874 | | old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref); |
| 12986 | if (old_bb->child == nullptr) { |
| 12987 | old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref); |
| 11875 | 12988 | } |
| 11876 | | ira->new_irb.current_basic_block = old_bb->other; |
| 12989 | ira->new_irb.current_basic_block = old_bb->child; |
| 11877 | 12990 | ir_start_bb(ira, old_bb, nullptr); |
| 11878 | 12991 | return; |
| 11879 | 12992 | } |
| ... | ... | @@ -11893,16 +13006,16 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 11893 | 13006 | if (!ira->new_irb.current_basic_block->already_appended) { |
| 11894 | 13007 | ira->new_irb.current_basic_block->already_appended = true; |
| 11895 | 13008 | if (ira->codegen->verbose_ir) { |
| 11896 | | fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint, |
| 13009 | fprintf(stderr, "append new bb %s_%" PRIu32 "\n", ira->new_irb.current_basic_block->name_hint, |
| 11897 | 13010 | ira->new_irb.current_basic_block->debug_id); |
| 11898 | 13011 | } |
| 11899 | 13012 | ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block); |
| 11900 | 13013 | } |
| 11901 | 13014 | ira->instruction_index += 1; |
| 11902 | 13015 | while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) { |
| 11903 | | IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 13016 | IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 11904 | 13017 | if (!next_instruction->is_gen) { |
| 11905 | | ir_add_error(ira, next_instruction, buf_sprintf("unreachable code")); |
| 13018 | ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code")); |
| 11906 | 13019 | break; |
| 11907 | 13020 | } |
| 11908 | 13021 | ira->instruction_index += 1; |
| ... | ... | @@ -11911,7 +13024,7 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 11911 | 13024 | ir_start_next_bb(ira); |
| 11912 | 13025 | } |
| 11913 | 13026 | |
| 11914 | | static IrInstruction *ir_unreach_error(IrAnalyze *ira) { |
| 13027 | static IrInstGen *ir_unreach_error(IrAnalyze *ira) { |
| 11915 | 13028 | ira->old_bb_index = SIZE_MAX; |
| 11916 | 13029 | if (ira->new_irb.exec->first_err_trace_msg == nullptr) { |
| 11917 | 13030 | ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err; |
| ... | ... | @@ -11919,7 +13032,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) { |
| 11919 | 13032 | return ira->codegen->unreach_instruction; |
| 11920 | 13033 | } |
| 11921 | 13034 | |
| 11922 | | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 13035 | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) { |
| 11923 | 13036 | size_t *bbc = ira->new_irb.exec->backward_branch_count; |
| 11924 | 13037 | size_t *quota = ira->new_irb.exec->backward_branch_quota; |
| 11925 | 13038 | |
| ... | ... | @@ -11938,66 +13051,85 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 11938 | 13051 | return true; |
| 11939 | 13052 | } |
| 11940 | 13053 | |
| 11941 | | static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { |
| 13054 | static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) { |
| 11942 | 13055 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { |
| 11943 | 13056 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 11944 | 13057 | return ir_unreach_error(ira); |
| 11945 | 13058 | } |
| 11946 | 13059 | |
| 11947 | | old_bb->other = ira->old_irb.current_basic_block->other; |
| 13060 | old_bb->child = ira->old_irb.current_basic_block->child; |
| 11948 | 13061 | ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block); |
| 11949 | 13062 | return ira->codegen->unreach_instruction; |
| 11950 | 13063 | } |
| 11951 | 13064 | |
| 11952 | | static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { |
| 13065 | static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) { |
| 11953 | 13066 | if (instruction->value->type->id == ZigTypeIdUnreachable) |
| 11954 | 13067 | ir_finish_bb(ira); |
| 11955 | 13068 | return instruction; |
| 11956 | 13069 | } |
| 11957 | 13070 | |
| 11958 | | static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11959 | | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 13071 | static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) { |
| 13072 | IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry); |
| 13073 | result->value->special = ConstValSpecialStatic; |
| 13074 | result->value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 13075 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 13076 | result->value->data.x_ptr.special = ConstPtrSpecialFunction; |
| 13077 | return result; |
| 13078 | } |
| 13079 | |
| 13080 | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg, |
| 13081 | IrInst *first_arg_src) |
| 13082 | { |
| 13083 | IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry)); |
| 13084 | result->value->data.x_bound_fn.fn = fn_entry; |
| 13085 | result->value->data.x_bound_fn.first_arg = first_arg; |
| 13086 | result->value->data.x_bound_fn.first_arg_src = first_arg_src; |
| 13087 | return result; |
| 13088 | } |
| 13089 | |
| 13090 | static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 13091 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 11960 | 13092 | result->value->data.x_type = ty; |
| 11961 | 13093 | return result; |
| 11962 | 13094 | } |
| 11963 | 13095 | |
| 11964 | | static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) { |
| 11965 | | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 13096 | static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) { |
| 13097 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 11966 | 13098 | result->value->data.x_bool = value; |
| 11967 | 13099 | return result; |
| 11968 | 13100 | } |
| 11969 | 13101 | |
| 11970 | | static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11971 | | IrInstruction *result = ir_const(ira, source_instruction, ty); |
| 13102 | static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 13103 | IrInstGen *result = ir_const(ira, source_instruction, ty); |
| 11972 | 13104 | result->value->special = ConstValSpecialUndef; |
| 11973 | 13105 | return result; |
| 11974 | 13106 | } |
| 11975 | 13107 | |
| 11976 | | static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11977 | | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 13108 | static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) { |
| 13109 | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 11978 | 13110 | result->value = ira->codegen->intern.for_unreachable(); |
| 11979 | 13111 | return result; |
| 11980 | 13112 | } |
| 11981 | 13113 | |
| 11982 | | static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11983 | | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 13114 | static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) { |
| 13115 | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 11984 | 13116 | result->value = ira->codegen->intern.for_void(); |
| 11985 | 13117 | return result; |
| 11986 | 13118 | } |
| 11987 | 13119 | |
| 11988 | | static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { |
| 11989 | | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 13120 | static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) { |
| 13121 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 11990 | 13122 | bigint_init_unsigned(&result->value->data.x_bigint, value); |
| 11991 | 13123 | return result; |
| 11992 | 13124 | } |
| 11993 | 13125 | |
| 11994 | | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13126 | static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction, |
| 11995 | 13127 | ZigValue *pointee, ZigType *pointee_type, |
| 11996 | 13128 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 11997 | 13129 | { |
| 11998 | 13130 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 11999 | 13131 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 12000 | | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 13132 | IrInstGen *const_instr = ir_const(ira, instruction, ptr_type); |
| 12001 | 13133 | ZigValue *const_val = const_instr->value; |
| 12002 | 13134 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 12003 | 13135 | const_val->data.x_ptr.mut = ptr_mut; |
| ... | ... | @@ -12005,7 +13137,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 12005 | 13137 | return const_instr; |
| 12006 | 13138 | } |
| 12007 | 13139 | |
| 12008 | | static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 13140 | static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 12009 | 13141 | ZigValue *val, UndefAllowed undef_allowed) |
| 12010 | 13142 | { |
| 12011 | 13143 | Error err; |
| ... | ... | @@ -12017,14 +13149,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 12017 | 13149 | if (!type_has_bits(val->type)) |
| 12018 | 13150 | return ErrorNone; |
| 12019 | 13151 | |
| 12020 | | exec_add_error_node(codegen, exec, source_node, |
| 13152 | exec_add_error_node_gen(codegen, exec, source_node, |
| 12021 | 13153 | buf_sprintf("unable to evaluate constant expression")); |
| 12022 | 13154 | return ErrorSemanticAnalyzeFail; |
| 12023 | 13155 | case ConstValSpecialUndef: |
| 12024 | 13156 | if (undef_allowed == UndefOk || undef_allowed == LazyOk) |
| 12025 | 13157 | return ErrorNone; |
| 12026 | 13158 | |
| 12027 | | exec_add_error_node(codegen, exec, source_node, |
| 13159 | exec_add_error_node_gen(codegen, exec, source_node, |
| 12028 | 13160 | buf_sprintf("use of undefined value here causes undefined behavior")); |
| 12029 | 13161 | return ErrorSemanticAnalyzeFail; |
| 12030 | 13162 | case ConstValSpecialLazy: |
| ... | ... | @@ -12039,9 +13171,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 12039 | 13171 | } |
| 12040 | 13172 | } |
| 12041 | 13173 | |
| 12042 | | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 13174 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) { |
| 12043 | 13175 | Error err; |
| 12044 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, |
| 13176 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 12045 | 13177 | value->value, undef_allowed))) |
| 12046 | 13178 | { |
| 12047 | 13179 | return nullptr; |
| ... | ... | @@ -12049,17 +13181,19 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll |
| 12049 | 13181 | return value->value; |
| 12050 | 13182 | } |
| 12051 | 13183 | |
| 12052 | | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12053 | | ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 13184 | Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 13185 | ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 12054 | 13186 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 12055 | | IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| 13187 | IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| 12056 | 13188 | { |
| 12057 | 13189 | Error err; |
| 12058 | 13190 | |
| 12059 | | if (expected_type != nullptr && type_is_invalid(expected_type)) |
| 12060 | | return codegen->invalid_instruction->value; |
| 13191 | src_assert(return_ptr->type->id == ZigTypeIdPointer, source_node); |
| 13192 | |
| 13193 | if (type_is_invalid(return_ptr->type)) |
| 13194 | return ErrorSemanticAnalyzeFail; |
| 12061 | 13195 | |
| 12062 | | IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1"); |
| 13196 | IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc"); |
| 12063 | 13197 | ir_executable->source_node = source_node; |
| 12064 | 13198 | ir_executable->parent_exec = parent_exec; |
| 12065 | 13199 | ir_executable->name = exec_name; |
| ... | ... | @@ -12069,21 +13203,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12069 | 13203 | ir_executable->begin_scope = scope; |
| 12070 | 13204 | |
| 12071 | 13205 | if (!ir_gen(codegen, node, scope, ir_executable)) |
| 12072 | | return codegen->invalid_instruction->value; |
| 13206 | return ErrorSemanticAnalyzeFail; |
| 12073 | 13207 | |
| 12074 | 13208 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 12075 | 13209 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 12076 | | return codegen->invalid_instruction->value; |
| 13210 | return ErrorSemanticAnalyzeFail; |
| 12077 | 13211 | } |
| 12078 | 13212 | |
| 12079 | 13213 | if (codegen->verbose_ir) { |
| 12080 | 13214 | fprintf(stderr, "\nSource: "); |
| 12081 | 13215 | ast_render(stderr, node, 4); |
| 12082 | 13216 | fprintf(stderr, "\n{ // (IR)\n"); |
| 12083 | | ir_print(codegen, stderr, ir_executable, 2, IrPassSrc); |
| 13217 | ir_print_src(codegen, stderr, ir_executable, 2); |
| 12084 | 13218 | fprintf(stderr, "}\n"); |
| 12085 | 13219 | } |
| 12086 | | IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2"); |
| 13220 | IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen"); |
| 12087 | 13221 | analyzed_executable->source_node = source_node; |
| 12088 | 13222 | analyzed_executable->parent_exec = parent_exec; |
| 12089 | 13223 | analyzed_executable->source_exec = ir_executable; |
| ... | ... | @@ -12094,33 +13228,36 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12094 | 13228 | analyzed_executable->backward_branch_count = backward_branch_count; |
| 12095 | 13229 | analyzed_executable->backward_branch_quota = backward_branch_quota; |
| 12096 | 13230 | analyzed_executable->begin_scope = scope; |
| 12097 | | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); |
| 13231 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, |
| 13232 | return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr); |
| 12098 | 13233 | if (type_is_invalid(result_type)) { |
| 12099 | | return codegen->invalid_instruction->value; |
| 13234 | return ErrorSemanticAnalyzeFail; |
| 12100 | 13235 | } |
| 12101 | 13236 | |
| 12102 | 13237 | if (codegen->verbose_ir) { |
| 12103 | 13238 | fprintf(stderr, "{ // (analyzed)\n"); |
| 12104 | | ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen); |
| 13239 | ir_print_gen(codegen, stderr, analyzed_executable, 2); |
| 12105 | 13240 | fprintf(stderr, "}\n"); |
| 12106 | 13241 | } |
| 12107 | 13242 | |
| 12108 | | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 12109 | | if (type_is_invalid(result->type)) |
| 12110 | | return codegen->invalid_instruction->value; |
| 13243 | if ((err = ir_exec_scan_for_side_effects(codegen, analyzed_executable))) |
| 13244 | return err; |
| 12111 | 13245 | |
| 13246 | ZigValue *result = const_ptr_pointee(nullptr, codegen, return_ptr, source_node); |
| 13247 | if (result == nullptr) |
| 13248 | return ErrorSemanticAnalyzeFail; |
| 12112 | 13249 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 12113 | | return codegen->invalid_instruction->value; |
| 13250 | return err; |
| 12114 | 13251 | |
| 12115 | | return result; |
| 13252 | return ErrorNone; |
| 12116 | 13253 | } |
| 12117 | 13254 | |
| 12118 | | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { |
| 13255 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) { |
| 12119 | 13256 | if (type_is_invalid(err_value->value->type)) |
| 12120 | 13257 | return nullptr; |
| 12121 | 13258 | |
| 12122 | 13259 | if (err_value->value->type->id != ZigTypeIdErrorSet) { |
| 12123 | | ir_add_error(ira, err_value, |
| 13260 | ir_add_error_node(ira, err_value->base.source_node, |
| 12124 | 13261 | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); |
| 12125 | 13262 | return nullptr; |
| 12126 | 13263 | } |
| ... | ... | @@ -12133,7 +13270,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu |
| 12133 | 13270 | return const_val->data.x_err_set; |
| 12134 | 13271 | } |
| 12135 | 13272 | |
| 12136 | | static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 13273 | static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 12137 | 13274 | ZigValue *val) |
| 12138 | 13275 | { |
| 12139 | 13276 | Error err; |
| ... | ... | @@ -12144,18 +13281,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN |
| 12144 | 13281 | return val->data.x_type; |
| 12145 | 13282 | } |
| 12146 | 13283 | |
| 12147 | | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { |
| 13284 | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) { |
| 12148 | 13285 | if (type_is_invalid(type_value->value->type)) |
| 12149 | 13286 | return nullptr; |
| 12150 | 13287 | |
| 12151 | 13288 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 12152 | | ir_add_error(ira, type_value, |
| 13289 | ir_add_error_node(ira, type_value->base.source_node, |
| 12153 | 13290 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); |
| 12154 | 13291 | return nullptr; |
| 12155 | 13292 | } |
| 12156 | 13293 | |
| 12157 | 13294 | Error err; |
| 12158 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, |
| 13295 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node, |
| 12159 | 13296 | type_value->value, LazyOk))) |
| 12160 | 13297 | { |
| 12161 | 13298 | return nullptr; |
| ... | ... | @@ -12164,17 +13301,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) |
| 12164 | 13301 | return type_value->value; |
| 12165 | 13302 | } |
| 12166 | 13303 | |
| 12167 | | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 13304 | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 12168 | 13305 | ZigValue *val = ir_resolve_type_lazy(ira, type_value); |
| 12169 | 13306 | if (val == nullptr) |
| 12170 | 13307 | return ira->codegen->builtin_types.entry_invalid; |
| 12171 | 13308 | |
| 12172 | | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val); |
| 13309 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val); |
| 12173 | 13310 | } |
| 12174 | 13311 | |
| 12175 | | static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *elem_type) { |
| 13312 | static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) { |
| 12176 | 13313 | if (!is_valid_vector_elem_type(elem_type)) { |
| 12177 | | ir_add_error(ira, source_instr, |
| 13314 | ir_add_error_node(ira, source_node, |
| 12178 | 13315 | buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid", |
| 12179 | 13316 | buf_ptr(&elem_type->name))); |
| 12180 | 13317 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -12182,28 +13319,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_ |
| 12182 | 13319 | return ErrorNone; |
| 12183 | 13320 | } |
| 12184 | 13321 | |
| 12185 | | static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstruction *elem_type_value) { |
| 13322 | static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type_value) { |
| 12186 | 13323 | Error err; |
| 12187 | 13324 | ZigType *elem_type = ir_resolve_type(ira, elem_type_value); |
| 12188 | 13325 | if (type_is_invalid(elem_type)) |
| 12189 | 13326 | return ira->codegen->builtin_types.entry_invalid; |
| 12190 | | if ((err = ir_validate_vector_elem_type(ira, elem_type_value, elem_type))) |
| 13327 | if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type))) |
| 12191 | 13328 | return ira->codegen->builtin_types.entry_invalid; |
| 12192 | 13329 | return elem_type; |
| 12193 | 13330 | } |
| 12194 | 13331 | |
| 12195 | | static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 13332 | static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 12196 | 13333 | ZigType *ty = ir_resolve_type(ira, type_value); |
| 12197 | 13334 | if (type_is_invalid(ty)) |
| 12198 | 13335 | return ira->codegen->builtin_types.entry_invalid; |
| 12199 | 13336 | |
| 12200 | 13337 | if (ty->id != ZigTypeIdInt) { |
| 12201 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13338 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12202 | 13339 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name))); |
| 12203 | 13340 | if (ty->id == ZigTypeIdVector && |
| 12204 | 13341 | ty->data.vector.elem_type->id == ZigTypeIdInt) |
| 12205 | 13342 | { |
| 12206 | | add_error_note(ira->codegen, msg, type_value->source_node, |
| 13343 | add_error_note(ira->codegen, msg, type_value->base.source_node, |
| 12207 | 13344 | buf_sprintf("represent vectors with their element types, i.e. '%s'", |
| 12208 | 13345 | buf_ptr(&ty->data.vector.elem_type->name))); |
| 12209 | 13346 | } |
| ... | ... | @@ -12213,12 +13350,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 12213 | 13350 | return ty; |
| 12214 | 13351 | } |
| 12215 | 13352 | |
| 12216 | | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) { |
| 13353 | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) { |
| 12217 | 13354 | if (type_is_invalid(type_value->value->type)) |
| 12218 | 13355 | return ira->codegen->builtin_types.entry_invalid; |
| 12219 | 13356 | |
| 12220 | 13357 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 12221 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13358 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12222 | 13359 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); |
| 12223 | 13360 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 12224 | 13361 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| ... | ... | @@ -12232,7 +13369,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour |
| 12232 | 13369 | assert(const_val->data.x_type != nullptr); |
| 12233 | 13370 | ZigType *result_type = const_val->data.x_type; |
| 12234 | 13371 | if (result_type->id != ZigTypeIdErrorSet) { |
| 12235 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13372 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12236 | 13373 | buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name))); |
| 12237 | 13374 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 12238 | 13375 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| ... | ... | @@ -12241,15 +13378,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour |
| 12241 | 13378 | return result_type; |
| 12242 | 13379 | } |
| 12243 | 13380 | |
| 12244 | | static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 12245 | | if (fn_value == ira->codegen->invalid_instruction) |
| 12246 | | return nullptr; |
| 12247 | | |
| 13381 | static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) { |
| 12248 | 13382 | if (type_is_invalid(fn_value->value->type)) |
| 12249 | 13383 | return nullptr; |
| 12250 | 13384 | |
| 12251 | 13385 | if (fn_value->value->type->id != ZigTypeIdFn) { |
| 12252 | | ir_add_error_node(ira, fn_value->source_node, |
| 13386 | ir_add_error_node(ira, fn_value->base.source_node, |
| 12253 | 13387 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); |
| 12254 | 13388 | return nullptr; |
| 12255 | 13389 | } |
| ... | ... | @@ -12265,22 +13399,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 12265 | 13399 | return const_val->data.x_ptr.data.fn.fn_entry; |
| 12266 | 13400 | } |
| 12267 | 13401 | |
| 12268 | | static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 12269 | | ZigType *wanted_type, ResultLoc *result_loc) |
| 13402 | static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 13403 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 12270 | 13404 | { |
| 12271 | 13405 | assert(wanted_type->id == ZigTypeIdOptional); |
| 12272 | 13406 | |
| 12273 | 13407 | if (instr_is_comptime(value)) { |
| 12274 | 13408 | ZigType *payload_type = wanted_type->data.maybe.child_type; |
| 12275 | | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 13409 | IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 12276 | 13410 | if (type_is_invalid(casted_payload->value->type)) |
| 12277 | | return ira->codegen->invalid_instruction; |
| 13411 | return ira->codegen->invalid_inst_gen; |
| 12278 | 13412 | |
| 12279 | 13413 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 12280 | 13414 | if (!val) |
| 12281 | | return ira->codegen->invalid_instruction; |
| 13415 | return ira->codegen->invalid_inst_gen; |
| 12282 | 13416 | |
| 12283 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13417 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12284 | 13418 | source_instr->scope, source_instr->source_node); |
| 12285 | 13419 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 12286 | 13420 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| ... | ... | @@ -12295,40 +13429,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 12295 | 13429 | if (result_loc == nullptr && handle_is_ptr(wanted_type)) { |
| 12296 | 13430 | result_loc = no_result_loc(); |
| 12297 | 13431 | } |
| 12298 | | IrInstruction *result_loc_inst = nullptr; |
| 13432 | IrInstGen *result_loc_inst = nullptr; |
| 12299 | 13433 | if (result_loc != nullptr) { |
| 12300 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 12301 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13434 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13435 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13436 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13437 | { |
| 12302 | 13438 | return result_loc_inst; |
| 12303 | 13439 | } |
| 12304 | 13440 | } |
| 12305 | | IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13441 | IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12306 | 13442 | result->value->data.rh_maybe = RuntimeHintOptionalNonNull; |
| 12307 | 13443 | return result; |
| 12308 | 13444 | } |
| 12309 | 13445 | |
| 12310 | | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 12311 | | IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 13446 | static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr, |
| 13447 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 12312 | 13448 | { |
| 12313 | 13449 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 12314 | 13450 | |
| 12315 | 13451 | ZigType *payload_type = wanted_type->data.error_union.payload_type; |
| 12316 | 13452 | ZigType *err_set_type = wanted_type->data.error_union.err_set_type; |
| 12317 | 13453 | if (instr_is_comptime(value)) { |
| 12318 | | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 13454 | IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 12319 | 13455 | if (type_is_invalid(casted_payload->value->type)) |
| 12320 | | return ira->codegen->invalid_instruction; |
| 13456 | return ira->codegen->invalid_inst_gen; |
| 12321 | 13457 | |
| 12322 | | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 12323 | | if (!val) |
| 12324 | | return ira->codegen->invalid_instruction; |
| 13458 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 13459 | if (val == nullptr) |
| 13460 | return ira->codegen->invalid_inst_gen; |
| 12325 | 13461 | |
| 12326 | 13462 | ZigValue *err_set_val = create_const_vals(1); |
| 12327 | 13463 | err_set_val->type = err_set_type; |
| 12328 | 13464 | err_set_val->special = ConstValSpecialStatic; |
| 12329 | 13465 | err_set_val->data.x_err_set = nullptr; |
| 12330 | 13466 | |
| 12331 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13467 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12332 | 13468 | source_instr->scope, source_instr->source_node); |
| 12333 | 13469 | const_instruction->base.value->type = wanted_type; |
| 12334 | 13470 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12337,23 +13473,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 12337 | 13473 | return &const_instruction->base; |
| 12338 | 13474 | } |
| 12339 | 13475 | |
| 12340 | | IrInstruction *result_loc_inst; |
| 13476 | IrInstGen *result_loc_inst; |
| 12341 | 13477 | if (handle_is_ptr(wanted_type)) { |
| 12342 | 13478 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12343 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 12344 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13479 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13480 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13481 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 12345 | 13482 | return result_loc_inst; |
| 12346 | 13483 | } |
| 12347 | 13484 | } else { |
| 12348 | 13485 | result_loc_inst = nullptr; |
| 12349 | 13486 | } |
| 12350 | 13487 | |
| 12351 | | IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13488 | IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12352 | 13489 | result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 12353 | 13490 | return result; |
| 12354 | 13491 | } |
| 12355 | 13492 | |
| 12356 | | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 13493 | static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 12357 | 13494 | ZigType *wanted_type) |
| 12358 | 13495 | { |
| 12359 | 13496 | assert(value->value->type->id == ZigTypeIdErrorSet); |
| ... | ... | @@ -12362,10 +13499,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12362 | 13499 | if (instr_is_comptime(value)) { |
| 12363 | 13500 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12364 | 13501 | if (!val) |
| 12365 | | return ira->codegen->invalid_instruction; |
| 13502 | return ira->codegen->invalid_inst_gen; |
| 12366 | 13503 | |
| 12367 | 13504 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 12368 | | return ira->codegen->invalid_instruction; |
| 13505 | return ira->codegen->invalid_inst_gen; |
| 12369 | 13506 | } |
| 12370 | 13507 | if (!type_is_global_error_set(wanted_type)) { |
| 12371 | 13508 | bool subset = false; |
| ... | ... | @@ -12379,11 +13516,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12379 | 13516 | ir_add_error(ira, source_instr, |
| 12380 | 13517 | buf_sprintf("error.%s not a member of error set '%s'", |
| 12381 | 13518 | buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name))); |
| 12382 | | return ira->codegen->invalid_instruction; |
| 13519 | return ira->codegen->invalid_inst_gen; |
| 12383 | 13520 | } |
| 12384 | 13521 | } |
| 12385 | 13522 | |
| 12386 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13523 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12387 | 13524 | source_instr->scope, source_instr->source_node); |
| 12388 | 13525 | const_instruction->base.value->type = wanted_type; |
| 12389 | 13526 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12391,18 +13528,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12391 | 13528 | return &const_instruction->base; |
| 12392 | 13529 | } |
| 12393 | 13530 | |
| 12394 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet); |
| 12395 | | result->value->type = wanted_type; |
| 12396 | | return result; |
| 13531 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet); |
| 12397 | 13532 | } |
| 12398 | 13533 | |
| 12399 | | static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr, |
| 12400 | | IrInstruction *frame_ptr, ZigType *wanted_type) |
| 13534 | static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 13535 | IrInstGen *frame_ptr, ZigType *wanted_type) |
| 12401 | 13536 | { |
| 12402 | 13537 | if (instr_is_comptime(frame_ptr)) { |
| 12403 | 13538 | ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); |
| 12404 | 13539 | if (ptr_val == nullptr) |
| 12405 | | return ira->codegen->invalid_instruction; |
| 13540 | return ira->codegen->invalid_inst_gen; |
| 12406 | 13541 | |
| 12407 | 13542 | ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr); |
| 12408 | 13543 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| ... | ... | @@ -12410,44 +13545,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc |
| 12410 | 13545 | } |
| 12411 | 13546 | } |
| 12412 | 13547 | |
| 12413 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 12414 | | wanted_type, frame_ptr, CastOpBitCast); |
| 12415 | | result->value->type = wanted_type; |
| 12416 | | return result; |
| 13548 | return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast); |
| 12417 | 13549 | } |
| 12418 | 13550 | |
| 12419 | | static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr, |
| 12420 | | IrInstruction *value, ZigType *wanted_type) |
| 13551 | static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 13552 | IrInstGen *value, ZigType *wanted_type) |
| 12421 | 13553 | { |
| 12422 | 13554 | if (instr_is_comptime(value)) { |
| 12423 | 13555 | zig_panic("TODO comptime anyframe->T to anyframe"); |
| 12424 | 13556 | } |
| 12425 | 13557 | |
| 12426 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 12427 | | wanted_type, value, CastOpBitCast); |
| 12428 | | result->value->type = wanted_type; |
| 12429 | | return result; |
| 13558 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 12430 | 13559 | } |
| 12431 | 13560 | |
| 12432 | 13561 | |
| 12433 | | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 13562 | static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 12434 | 13563 | ZigType *wanted_type, ResultLoc *result_loc) |
| 12435 | 13564 | { |
| 12436 | 13565 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 12437 | 13566 | |
| 12438 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 13567 | IrInstGen *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 12439 | 13568 | |
| 12440 | 13569 | if (instr_is_comptime(casted_value)) { |
| 12441 | 13570 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 12442 | 13571 | if (!val) |
| 12443 | | return ira->codegen->invalid_instruction; |
| 13572 | return ira->codegen->invalid_inst_gen; |
| 12444 | 13573 | |
| 12445 | 13574 | ZigValue *err_set_val = create_const_vals(1); |
| 12446 | 13575 | err_set_val->special = ConstValSpecialStatic; |
| 12447 | 13576 | err_set_val->type = wanted_type->data.error_union.err_set_type; |
| 12448 | 13577 | err_set_val->data.x_err_set = val->data.x_err_set; |
| 12449 | 13578 | |
| 12450 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13579 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12451 | 13580 | source_instr->scope, source_instr->source_node); |
| 12452 | 13581 | const_instruction->base.value->type = wanted_type; |
| 12453 | 13582 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12456,11 +13585,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 12456 | 13585 | return &const_instruction->base; |
| 12457 | 13586 | } |
| 12458 | 13587 | |
| 12459 | | IrInstruction *result_loc_inst; |
| 13588 | IrInstGen *result_loc_inst; |
| 12460 | 13589 | if (handle_is_ptr(wanted_type)) { |
| 12461 | 13590 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12462 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 12463 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13591 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 13592 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13593 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13594 | { |
| 12464 | 13595 | return result_loc_inst; |
| 12465 | 13596 | } |
| 12466 | 13597 | } else { |
| ... | ... | @@ -12468,19 +13599,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 12468 | 13599 | } |
| 12469 | 13600 | |
| 12470 | 13601 | |
| 12471 | | IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13602 | IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12472 | 13603 | result->value->data.rh_error_union = RuntimeHintErrorUnionError; |
| 12473 | 13604 | return result; |
| 12474 | 13605 | } |
| 12475 | 13606 | |
| 12476 | | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 13607 | static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) { |
| 12477 | 13608 | assert(wanted_type->id == ZigTypeIdOptional); |
| 12478 | 13609 | assert(instr_is_comptime(value)); |
| 12479 | 13610 | |
| 12480 | 13611 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12481 | 13612 | assert(val != nullptr); |
| 12482 | 13613 | |
| 12483 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13614 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12484 | 13615 | result->value->special = ConstValSpecialStatic; |
| 12485 | 13616 | if (get_codegen_ptr_type(wanted_type) != nullptr) { |
| 12486 | 13617 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| ... | ... | @@ -12492,8 +13623,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 12492 | 13623 | return result; |
| 12493 | 13624 | } |
| 12494 | 13625 | |
| 12495 | | static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr, |
| 12496 | | IrInstruction *value, ZigType *wanted_type) |
| 13626 | static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr, |
| 13627 | IrInstGen *value, ZigType *wanted_type) |
| 12497 | 13628 | { |
| 12498 | 13629 | assert(wanted_type->id == ZigTypeIdPointer); |
| 12499 | 13630 | assert(wanted_type->data.pointer.ptr_len == PtrLenC); |
| ... | ... | @@ -12502,48 +13633,53 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction |
| 12502 | 13633 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12503 | 13634 | assert(val != nullptr); |
| 12504 | 13635 | |
| 12505 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13636 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12506 | 13637 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 12507 | 13638 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 12508 | 13639 | return result; |
| 12509 | 13640 | } |
| 12510 | 13641 | |
| 12511 | | static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 12512 | | bool is_const, bool is_volatile) |
| 13642 | static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 13643 | ZigType *elem_type, bool is_const, bool is_volatile) |
| 12513 | 13644 | { |
| 12514 | 13645 | Error err; |
| 12515 | 13646 | |
| 12516 | | if (type_is_invalid(value->value->type)) |
| 12517 | | return ira->codegen->invalid_instruction; |
| 13647 | if (type_is_invalid(elem_type)) |
| 13648 | return ira->codegen->invalid_inst_gen; |
| 12518 | 13649 | |
| 12519 | 13650 | if (instr_is_comptime(value)) { |
| 12520 | 13651 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 12521 | 13652 | if (!val) |
| 12522 | | return ira->codegen->invalid_instruction; |
| 12523 | | return ir_get_const_ptr(ira, source_instruction, val, value->value->type, |
| 13653 | return ira->codegen->invalid_inst_gen; |
| 13654 | return ir_get_const_ptr(ira, source_instruction, val, elem_type, |
| 12524 | 13655 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 12525 | 13656 | } |
| 12526 | 13657 | |
| 12527 | | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type, |
| 13658 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, elem_type, |
| 12528 | 13659 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 12529 | 13660 | |
| 12530 | 13661 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) |
| 12531 | | return ira->codegen->invalid_instruction; |
| 13662 | return ira->codegen->invalid_inst_gen; |
| 12532 | 13663 | |
| 12533 | | IrInstruction *result_loc; |
| 12534 | | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { |
| 12535 | | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, |
| 12536 | | false, true); |
| 13664 | IrInstGen *result_loc; |
| 13665 | if (type_has_bits(ptr_type) && !handle_is_ptr(elem_type)) { |
| 13666 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true); |
| 12537 | 13667 | } else { |
| 12538 | 13668 | result_loc = nullptr; |
| 12539 | 13669 | } |
| 12540 | 13670 | |
| 12541 | | IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 13671 | IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 12542 | 13672 | new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; |
| 12543 | 13673 | return new_instruction; |
| 12544 | 13674 | } |
| 12545 | 13675 | |
| 12546 | | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) { |
| 13676 | static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 13677 | bool is_const, bool is_volatile) |
| 13678 | { |
| 13679 | return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile); |
| 13680 | } |
| 13681 | |
| 13682 | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) { |
| 12547 | 13683 | assert(union_type->id == ZigTypeIdUnion); |
| 12548 | 13684 | |
| 12549 | 13685 | Error err; |
| ... | ... | @@ -12555,36 +13691,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_ |
| 12555 | 13691 | assert(union_type->data.unionation.tag_type != nullptr); |
| 12556 | 13692 | return union_type->data.unionation.tag_type; |
| 12557 | 13693 | } else { |
| 12558 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union '%s' has no tag", |
| 13694 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union '%s' has no tag", |
| 12559 | 13695 | buf_ptr(&union_type->name))); |
| 12560 | 13696 | add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here")); |
| 12561 | 13697 | return ira->codegen->builtin_types.entry_invalid; |
| 12562 | 13698 | } |
| 12563 | 13699 | } |
| 12564 | 13700 | |
| 12565 | | static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target) { |
| 13701 | static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 12566 | 13702 | Error err; |
| 12567 | 13703 | |
| 12568 | | IrInstruction *enum_target; |
| 13704 | IrInstGen *enum_target; |
| 12569 | 13705 | ZigType *enum_type; |
| 12570 | 13706 | if (target->value->type->id == ZigTypeIdUnion) { |
| 12571 | | enum_type = ir_resolve_union_tag_type(ira, target, target->value->type); |
| 13707 | enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type); |
| 12572 | 13708 | if (type_is_invalid(enum_type)) |
| 12573 | | return ira->codegen->invalid_instruction; |
| 13709 | return ira->codegen->invalid_inst_gen; |
| 12574 | 13710 | enum_target = ir_implicit_cast(ira, target, enum_type); |
| 12575 | 13711 | if (type_is_invalid(enum_target->value->type)) |
| 12576 | | return ira->codegen->invalid_instruction; |
| 13712 | return ira->codegen->invalid_inst_gen; |
| 12577 | 13713 | } else if (target->value->type->id == ZigTypeIdEnum) { |
| 12578 | 13714 | enum_target = target; |
| 12579 | 13715 | enum_type = target->value->type; |
| 12580 | 13716 | } else { |
| 12581 | | ir_add_error(ira, target, |
| 13717 | ir_add_error_node(ira, target->base.source_node, |
| 12582 | 13718 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); |
| 12583 | | return ira->codegen->invalid_instruction; |
| 13719 | return ira->codegen->invalid_inst_gen; |
| 12584 | 13720 | } |
| 12585 | 13721 | |
| 12586 | 13722 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown))) |
| 12587 | | return ira->codegen->invalid_instruction; |
| 13723 | return ira->codegen->invalid_inst_gen; |
| 12588 | 13724 | |
| 12589 | 13725 | ZigType *tag_type = enum_type->data.enumeration.tag_int_type; |
| 12590 | 13726 | assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt); |
| ... | ... | @@ -12593,7 +13729,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12593 | 13729 | if (enum_type->data.enumeration.layout == ContainerLayoutAuto && |
| 12594 | 13730 | enum_type->data.enumeration.src_field_count == 1) |
| 12595 | 13731 | { |
| 12596 | | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 13732 | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 12597 | 13733 | init_const_bigint(result->value, tag_type, |
| 12598 | 13734 | &enum_type->data.enumeration.fields[0].value); |
| 12599 | 13735 | return result; |
| ... | ... | @@ -12602,20 +13738,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12602 | 13738 | if (instr_is_comptime(enum_target)) { |
| 12603 | 13739 | ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 12604 | 13740 | if (!val) |
| 12605 | | return ira->codegen->invalid_instruction; |
| 12606 | | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 13741 | return ira->codegen->invalid_inst_gen; |
| 13742 | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 12607 | 13743 | init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); |
| 12608 | 13744 | return result; |
| 12609 | 13745 | } |
| 12610 | 13746 | |
| 12611 | | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12612 | | source_instr->source_node, enum_target); |
| 12613 | | result->value->type = tag_type; |
| 12614 | | return result; |
| 13747 | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type); |
| 12615 | 13748 | } |
| 12616 | 13749 | |
| 12617 | | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, |
| 12618 | | IrInstruction *target, ZigType *wanted_type) |
| 13750 | static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 13751 | IrInstGen *target, ZigType *wanted_type) |
| 12619 | 13752 | { |
| 12620 | 13753 | assert(target->value->type->id == ZigTypeIdUnion); |
| 12621 | 13754 | assert(wanted_type->id == ZigTypeIdEnum); |
| ... | ... | @@ -12624,8 +13757,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12624 | 13757 | if (instr_is_comptime(target)) { |
| 12625 | 13758 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12626 | 13759 | if (!val) |
| 12627 | | return ira->codegen->invalid_instruction; |
| 12628 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13760 | return ira->codegen->invalid_inst_gen; |
| 13761 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12629 | 13762 | result->value->special = ConstValSpecialStatic; |
| 12630 | 13763 | result->value->type = wanted_type; |
| 12631 | 13764 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); |
| ... | ... | @@ -12636,7 +13769,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12636 | 13769 | if (wanted_type->data.enumeration.layout == ContainerLayoutAuto && |
| 12637 | 13770 | wanted_type->data.enumeration.src_field_count == 1) |
| 12638 | 13771 | { |
| 12639 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13772 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12640 | 13773 | result->value->special = ConstValSpecialStatic; |
| 12641 | 13774 | result->value->type = wanted_type; |
| 12642 | 13775 | TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; |
| ... | ... | @@ -12644,48 +13777,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12644 | 13777 | return result; |
| 12645 | 13778 | } |
| 12646 | 13779 | |
| 12647 | | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, |
| 12648 | | source_instr->source_node, target); |
| 12649 | | result->value->type = wanted_type; |
| 12650 | | return result; |
| 13780 | return ir_build_union_tag(ira, source_instr, target, wanted_type); |
| 12651 | 13781 | } |
| 12652 | 13782 | |
| 12653 | | static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr, |
| 12654 | | IrInstruction *target, ZigType *wanted_type) |
| 13783 | static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr, |
| 13784 | IrInstGen *target, ZigType *wanted_type) |
| 12655 | 13785 | { |
| 12656 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13786 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12657 | 13787 | result->value->special = ConstValSpecialUndef; |
| 12658 | 13788 | return result; |
| 12659 | 13789 | } |
| 12660 | 13790 | |
| 12661 | | static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr, |
| 12662 | | IrInstruction *uncasted_target, ZigType *wanted_type) |
| 13791 | static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 13792 | IrInstGen *uncasted_target, ZigType *wanted_type) |
| 12663 | 13793 | { |
| 12664 | 13794 | Error err; |
| 12665 | 13795 | assert(wanted_type->id == ZigTypeIdUnion); |
| 12666 | 13796 | |
| 12667 | 13797 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown))) |
| 12668 | | return ira->codegen->invalid_instruction; |
| 13798 | return ira->codegen->invalid_inst_gen; |
| 12669 | 13799 | |
| 12670 | | IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 13800 | IrInstGen *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 12671 | 13801 | if (type_is_invalid(target->value->type)) |
| 12672 | | return ira->codegen->invalid_instruction; |
| 13802 | return ira->codegen->invalid_inst_gen; |
| 12673 | 13803 | |
| 12674 | 13804 | if (instr_is_comptime(target)) { |
| 12675 | 13805 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12676 | 13806 | if (!val) |
| 12677 | | return ira->codegen->invalid_instruction; |
| 13807 | return ira->codegen->invalid_inst_gen; |
| 12678 | 13808 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 12679 | 13809 | assert(union_field != nullptr); |
| 12680 | 13810 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); |
| 12681 | 13811 | if (field_type == nullptr) |
| 12682 | | return ira->codegen->invalid_instruction; |
| 13812 | return ira->codegen->invalid_inst_gen; |
| 12683 | 13813 | if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown))) |
| 12684 | | return ira->codegen->invalid_instruction; |
| 13814 | return ira->codegen->invalid_inst_gen; |
| 12685 | 13815 | |
| 12686 | 13816 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 12687 | 13817 | case OnePossibleValueInvalid: |
| 12688 | | return ira->codegen->invalid_instruction; |
| 13818 | return ira->codegen->invalid_inst_gen; |
| 12689 | 13819 | case OnePossibleValueNo: { |
| 12690 | 13820 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 12691 | 13821 | union_field->enum_field->decl_index); |
| ... | ... | @@ -12696,13 +13826,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12696 | 13826 | buf_ptr(union_field->name))); |
| 12697 | 13827 | add_error_note(ira->codegen, msg, field_node, |
| 12698 | 13828 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); |
| 12699 | | return ira->codegen->invalid_instruction; |
| 13829 | return ira->codegen->invalid_inst_gen; |
| 12700 | 13830 | } |
| 12701 | 13831 | case OnePossibleValueYes: |
| 12702 | 13832 | break; |
| 12703 | 13833 | } |
| 12704 | 13834 | |
| 12705 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13835 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12706 | 13836 | result->value->special = ConstValSpecialStatic; |
| 12707 | 13837 | result->value->type = wanted_type; |
| 12708 | 13838 | bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); |
| ... | ... | @@ -12715,9 +13845,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12715 | 13845 | // if the union has all fields 0 bits, we can do it |
| 12716 | 13846 | // and in fact it's a noop cast because the union value is just the enum value |
| 12717 | 13847 | if (wanted_type->data.unionation.gen_field_count == 0) { |
| 12718 | | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop); |
| 12719 | | result->value->type = wanted_type; |
| 12720 | | return result; |
| 13848 | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop); |
| 12721 | 13849 | } |
| 12722 | 13850 | |
| 12723 | 13851 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| ... | ... | @@ -12727,10 +13855,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12727 | 13855 | TypeUnionField *union_field = &wanted_type->data.unionation.fields[i]; |
| 12728 | 13856 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); |
| 12729 | 13857 | if (field_type == nullptr) |
| 12730 | | return ira->codegen->invalid_instruction; |
| 13858 | return ira->codegen->invalid_inst_gen; |
| 12731 | 13859 | bool has_bits; |
| 12732 | 13860 | if ((err = type_has_bits2(ira->codegen, field_type, &has_bits))) |
| 12733 | | return ira->codegen->invalid_instruction; |
| 13861 | return ira->codegen->invalid_inst_gen; |
| 12734 | 13862 | if (has_bits) { |
| 12735 | 13863 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i); |
| 12736 | 13864 | add_error_note(ira->codegen, msg, field_node, |
| ... | ... | @@ -12739,23 +13867,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12739 | 13867 | buf_ptr(&field_type->name))); |
| 12740 | 13868 | } |
| 12741 | 13869 | } |
| 12742 | | return ira->codegen->invalid_instruction; |
| 13870 | return ira->codegen->invalid_inst_gen; |
| 12743 | 13871 | } |
| 12744 | 13872 | |
| 12745 | | static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, |
| 12746 | | IrInstruction *target, ZigType *wanted_type) |
| 13873 | static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr, |
| 13874 | IrInstGen *target, ZigType *wanted_type) |
| 12747 | 13875 | { |
| 12748 | 13876 | assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); |
| 12749 | 13877 | |
| 12750 | 13878 | if (instr_is_comptime(target)) { |
| 12751 | 13879 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12752 | 13880 | if (!val) |
| 12753 | | return ira->codegen->invalid_instruction; |
| 13881 | return ira->codegen->invalid_inst_gen; |
| 12754 | 13882 | if (wanted_type->id == ZigTypeIdInt) { |
| 12755 | 13883 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { |
| 12756 | 13884 | ir_add_error(ira, source_instr, |
| 12757 | 13885 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| 12758 | | return ira->codegen->invalid_instruction; |
| 13886 | return ira->codegen->invalid_inst_gen; |
| 12759 | 13887 | } |
| 12760 | 13888 | if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count, |
| 12761 | 13889 | wanted_type->data.integral.is_signed)) |
| ... | ... | @@ -12763,10 +13891,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12763 | 13891 | ir_add_error(ira, source_instr, |
| 12764 | 13892 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| 12765 | 13893 | buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name))); |
| 12766 | | return ira->codegen->invalid_instruction; |
| 13894 | return ira->codegen->invalid_inst_gen; |
| 12767 | 13895 | } |
| 12768 | 13896 | } |
| 12769 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13897 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12770 | 13898 | result->value->type = wanted_type; |
| 12771 | 13899 | if (wanted_type->id == ZigTypeIdInt) { |
| 12772 | 13900 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| ... | ... | @@ -12783,19 +13911,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12783 | 13911 | assert(wanted_type->id == ZigTypeIdInt); |
| 12784 | 13912 | assert(type_has_bits(target->value->type)); |
| 12785 | 13913 | ir_build_assert_zero(ira, source_instr, target); |
| 12786 | | IrInstruction *result = ir_const_unsigned(ira, source_instr, 0); |
| 13914 | IrInstGen *result = ir_const_unsigned(ira, source_instr, 0); |
| 12787 | 13915 | result->value->type = wanted_type; |
| 12788 | 13916 | return result; |
| 12789 | 13917 | } |
| 12790 | 13918 | |
| 12791 | | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12792 | | source_instr->source_node, target); |
| 12793 | | result->value->type = wanted_type; |
| 12794 | | return result; |
| 13919 | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 12795 | 13920 | } |
| 12796 | 13921 | |
| 12797 | | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, |
| 12798 | | IrInstruction *target, ZigType *wanted_type) |
| 13922 | static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 13923 | IrInstGen *target, ZigType *wanted_type) |
| 12799 | 13924 | { |
| 12800 | 13925 | Error err; |
| 12801 | 13926 | assert(wanted_type->id == ZigTypeIdEnum); |
| ... | ... | @@ -12803,14 +13928,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12803 | 13928 | ZigType *actual_type = target->value->type; |
| 12804 | 13929 | |
| 12805 | 13930 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) |
| 12806 | | return ira->codegen->invalid_instruction; |
| 13931 | return ira->codegen->invalid_inst_gen; |
| 12807 | 13932 | |
| 12808 | 13933 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { |
| 12809 | 13934 | ir_add_error(ira, source_instr, |
| 12810 | 13935 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", |
| 12811 | 13936 | buf_ptr(&actual_type->name), |
| 12812 | 13937 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); |
| 12813 | | return ira->codegen->invalid_instruction; |
| 13938 | return ira->codegen->invalid_inst_gen; |
| 12814 | 13939 | } |
| 12815 | 13940 | |
| 12816 | 13941 | assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt); |
| ... | ... | @@ -12818,7 +13943,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12818 | 13943 | if (instr_is_comptime(target)) { |
| 12819 | 13944 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12820 | 13945 | if (!val) |
| 12821 | | return ira->codegen->invalid_instruction; |
| 13946 | return ira->codegen->invalid_inst_gen; |
| 12822 | 13947 | |
| 12823 | 13948 | TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint); |
| 12824 | 13949 | if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) { |
| ... | ... | @@ -12829,28 +13954,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12829 | 13954 | buf_ptr(&wanted_type->name), buf_ptr(val_buf))); |
| 12830 | 13955 | add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node, |
| 12831 | 13956 | buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name))); |
| 12832 | | return ira->codegen->invalid_instruction; |
| 13957 | return ira->codegen->invalid_inst_gen; |
| 12833 | 13958 | } |
| 12834 | 13959 | |
| 12835 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13960 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12836 | 13961 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); |
| 12837 | 13962 | return result; |
| 12838 | 13963 | } |
| 12839 | 13964 | |
| 12840 | | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, |
| 12841 | | source_instr->source_node, nullptr, target); |
| 12842 | | result->value->type = wanted_type; |
| 12843 | | return result; |
| 13965 | return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target); |
| 12844 | 13966 | } |
| 12845 | 13967 | |
| 12846 | | static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, |
| 12847 | | IrInstruction *target, ZigType *wanted_type) |
| 13968 | static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr, |
| 13969 | IrInstGen *target, ZigType *wanted_type) |
| 12848 | 13970 | { |
| 12849 | 13971 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12850 | 13972 | if (!val) |
| 12851 | | return ira->codegen->invalid_instruction; |
| 13973 | return ira->codegen->invalid_inst_gen; |
| 12852 | 13974 | |
| 12853 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13975 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12854 | 13976 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 12855 | 13977 | float_init_float(result->value, val); |
| 12856 | 13978 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -12861,7 +13983,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 12861 | 13983 | return result; |
| 12862 | 13984 | } |
| 12863 | 13985 | |
| 12864 | | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 13986 | static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 12865 | 13987 | ZigType *wanted_type) |
| 12866 | 13988 | { |
| 12867 | 13989 | assert(target->value->type->id == ZigTypeIdInt); |
| ... | ... | @@ -12871,12 +13993,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12871 | 13993 | if (instr_is_comptime(target)) { |
| 12872 | 13994 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12873 | 13995 | if (!val) |
| 12874 | | return ira->codegen->invalid_instruction; |
| 13996 | return ira->codegen->invalid_inst_gen; |
| 12875 | 13997 | |
| 12876 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13998 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12877 | 13999 | |
| 12878 | 14000 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 12879 | | return ira->codegen->invalid_instruction; |
| 14001 | return ira->codegen->invalid_inst_gen; |
| 12880 | 14002 | } |
| 12881 | 14003 | |
| 12882 | 14004 | if (type_is_global_error_set(wanted_type)) { |
| ... | ... | @@ -12888,7 +14010,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12888 | 14010 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 12889 | 14011 | ir_add_error(ira, source_instr, |
| 12890 | 14012 | buf_sprintf("integer value %s represents no error", buf_ptr(val_buf))); |
| 12891 | | return ira->codegen->invalid_instruction; |
| 14013 | return ira->codegen->invalid_inst_gen; |
| 12892 | 14014 | } |
| 12893 | 14015 | |
| 12894 | 14016 | size_t index = bigint_as_usize(&val->data.x_bigint); |
| ... | ... | @@ -12912,7 +14034,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12912 | 14034 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 12913 | 14035 | ir_add_error(ira, source_instr, |
| 12914 | 14036 | buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name))); |
| 12915 | | return ira->codegen->invalid_instruction; |
| 14037 | return ira->codegen->invalid_inst_gen; |
| 12916 | 14038 | } |
| 12917 | 14039 | |
| 12918 | 14040 | result->value->data.x_err_set = err; |
| ... | ... | @@ -12920,12 +14042,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12920 | 14042 | } |
| 12921 | 14043 | } |
| 12922 | 14044 | |
| 12923 | | IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12924 | | result->value->type = wanted_type; |
| 12925 | | return result; |
| 14045 | return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 12926 | 14046 | } |
| 12927 | 14047 | |
| 12928 | | static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 14048 | static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 12929 | 14049 | ZigType *wanted_type) |
| 12930 | 14050 | { |
| 12931 | 14051 | assert(wanted_type->id == ZigTypeIdInt); |
| ... | ... | @@ -12935,9 +14055,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12935 | 14055 | if (instr_is_comptime(target)) { |
| 12936 | 14056 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12937 | 14057 | if (!val) |
| 12938 | | return ira->codegen->invalid_instruction; |
| 14058 | return ira->codegen->invalid_inst_gen; |
| 12939 | 14059 | |
| 12940 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14060 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12941 | 14061 | |
| 12942 | 14062 | ErrorTableEntry *err; |
| 12943 | 14063 | if (err_type->id == ZigTypeIdErrorUnion) { |
| ... | ... | @@ -12957,7 +14077,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12957 | 14077 | ir_add_error_node(ira, source_instr->source_node, |
| 12958 | 14078 | buf_sprintf("error code '%s' does not fit in '%s'", |
| 12959 | 14079 | buf_ptr(&err->name), buf_ptr(&wanted_type->name))); |
| 12960 | | return ira->codegen->invalid_instruction; |
| 14080 | return ira->codegen->invalid_inst_gen; |
| 12961 | 14081 | } |
| 12962 | 14082 | |
| 12963 | 14083 | return result; |
| ... | ... | @@ -12973,14 +14093,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12973 | 14093 | } |
| 12974 | 14094 | if (!type_is_global_error_set(err_set_type)) { |
| 12975 | 14095 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) { |
| 12976 | | return ira->codegen->invalid_instruction; |
| 14096 | return ira->codegen->invalid_inst_gen; |
| 12977 | 14097 | } |
| 12978 | 14098 | if (err_set_type->data.error_set.err_count == 0) { |
| 12979 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14099 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12980 | 14100 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 12981 | 14101 | return result; |
| 12982 | 14102 | } else if (err_set_type->data.error_set.err_count == 1) { |
| 12983 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14103 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12984 | 14104 | ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; |
| 12985 | 14105 | bigint_init_unsigned(&result->value->data.x_bigint, err->value); |
| 12986 | 14106 | return result; |
| ... | ... | @@ -12992,21 +14112,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12992 | 14112 | if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) { |
| 12993 | 14113 | ir_add_error_node(ira, source_instr->source_node, |
| 12994 | 14114 | buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name))); |
| 12995 | | return ira->codegen->invalid_instruction; |
| 14115 | return ira->codegen->invalid_inst_gen; |
| 12996 | 14116 | } |
| 12997 | 14117 | |
| 12998 | | IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12999 | | result->value->type = wanted_type; |
| 13000 | | return result; |
| 14118 | return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 13001 | 14119 | } |
| 13002 | 14120 | |
| 13003 | | static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 14121 | static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 13004 | 14122 | ZigType *wanted_type) |
| 13005 | 14123 | { |
| 13006 | 14124 | assert(wanted_type->id == ZigTypeIdPointer); |
| 13007 | 14125 | Error err; |
| 13008 | 14126 | if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13009 | | return ira->codegen->invalid_instruction; |
| 14127 | return ira->codegen->invalid_inst_gen; |
| 13010 | 14128 | assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const); |
| 13011 | 14129 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type)); |
| 13012 | 14130 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| ... | ... | @@ -13016,12 +14134,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13016 | 14134 | if (instr_is_comptime(target)) { |
| 13017 | 14135 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 13018 | 14136 | if (!val) |
| 13019 | | return ira->codegen->invalid_instruction; |
| 14137 | return ira->codegen->invalid_inst_gen; |
| 13020 | 14138 | |
| 13021 | 14139 | assert(val->type->id == ZigTypeIdPointer); |
| 13022 | 14140 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 13023 | 14141 | if (pointee == nullptr) |
| 13024 | | return ira->codegen->invalid_instruction; |
| 14142 | return ira->codegen->invalid_inst_gen; |
| 13025 | 14143 | if (pointee->special != ConstValSpecialRuntime) { |
| 13026 | 14144 | ZigValue *array_val = create_const_vals(1); |
| 13027 | 14145 | array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -13031,7 +14149,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13031 | 14149 | array_val->parent.id = ConstParentIdScalar; |
| 13032 | 14150 | array_val->parent.data.p_scalar.scalar_val = pointee; |
| 13033 | 14151 | |
| 13034 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 14152 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 13035 | 14153 | source_instr->scope, source_instr->source_node); |
| 13036 | 14154 | const_instruction->base.value->type = wanted_type; |
| 13037 | 14155 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -13043,10 +14161,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13043 | 14161 | } |
| 13044 | 14162 | |
| 13045 | 14163 | // pointer to array and pointer to single item are represented the same way at runtime |
| 13046 | | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, |
| 13047 | | wanted_type, target, CastOpBitCast); |
| 13048 | | result->value->type = wanted_type; |
| 13049 | | return result; |
| 14164 | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast); |
| 13050 | 14165 | } |
| 13051 | 14166 | |
| 13052 | 14167 | static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result, |
| ... | ... | @@ -13234,12 +14349,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 13234 | 14349 | } |
| 13235 | 14350 | } |
| 13236 | 14351 | |
| 13237 | | static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr, |
| 13238 | | IrInstruction *array, ZigType *vector_type) |
| 14352 | static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr, |
| 14353 | IrInstGen *array, ZigType *vector_type) |
| 13239 | 14354 | { |
| 13240 | 14355 | if (instr_is_comptime(array)) { |
| 13241 | 14356 | // arrays and vectors have the same ZigValue representation |
| 13242 | | IrInstruction *result = ir_const(ira, source_instr, vector_type); |
| 14357 | IrInstGen *result = ir_const(ira, source_instr, vector_type); |
| 13243 | 14358 | copy_const_val(result->value, array->value); |
| 13244 | 14359 | result->value->type = vector_type; |
| 13245 | 14360 | return result; |
| ... | ... | @@ -13247,12 +14362,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 13247 | 14362 | return ir_build_array_to_vector(ira, source_instr, array, vector_type); |
| 13248 | 14363 | } |
| 13249 | 14364 | |
| 13250 | | static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr, |
| 13251 | | IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc) |
| 14365 | static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 14366 | IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc) |
| 13252 | 14367 | { |
| 13253 | 14368 | if (instr_is_comptime(vector)) { |
| 13254 | 14369 | // arrays and vectors have the same ZigValue representation |
| 13255 | | IrInstruction *result = ir_const(ira, source_instr, array_type); |
| 14370 | IrInstGen *result = ir_const(ira, source_instr, array_type); |
| 13256 | 14371 | copy_const_val(result->value, vector->value); |
| 13257 | 14372 | result->value->type = array_type; |
| 13258 | 14373 | return result; |
| ... | ... | @@ -13260,18 +14375,17 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 13260 | 14375 | if (result_loc == nullptr) { |
| 13261 | 14376 | result_loc = no_result_loc(); |
| 13262 | 14377 | } |
| 13263 | | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 13264 | | true, false, true); |
| 13265 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 14378 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true); |
| 14379 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 13266 | 14380 | return result_loc_inst; |
| 13267 | 14381 | } |
| 13268 | 14382 | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); |
| 13269 | 14383 | } |
| 13270 | 14384 | |
| 13271 | | static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 13272 | | IrInstruction *integer, ZigType *dest_type) |
| 14385 | static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 14386 | IrInstGen *integer, ZigType *dest_type) |
| 13273 | 14387 | { |
| 13274 | | IrInstruction *unsigned_integer; |
| 14388 | IrInstGen *unsigned_integer; |
| 13275 | 14389 | if (instr_is_comptime(integer)) { |
| 13276 | 14390 | unsigned_integer = integer; |
| 13277 | 14391 | } else { |
| ... | ... | @@ -13284,7 +14398,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 13284 | 14398 | buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", |
| 13285 | 14399 | buf_ptr(&integer->value->type->name), |
| 13286 | 14400 | buf_ptr(&dest_type->name))); |
| 13287 | | return ira->codegen->invalid_instruction; |
| 14401 | return ira->codegen->invalid_inst_gen; |
| 13288 | 14402 | } |
| 13289 | 14403 | |
| 13290 | 14404 | if (integer->value->type->data.integral.is_signed) { |
| ... | ... | @@ -13292,7 +14406,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 13292 | 14406 | integer->value->type->data.integral.bit_count); |
| 13293 | 14407 | unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); |
| 13294 | 14408 | if (type_is_invalid(unsigned_integer->value->type)) |
| 13295 | | return ira->codegen->invalid_instruction; |
| 14409 | return ira->codegen->invalid_inst_gen; |
| 13296 | 14410 | } else { |
| 13297 | 14411 | unsigned_integer = integer; |
| 13298 | 14412 | } |
| ... | ... | @@ -13312,14 +14426,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) { |
| 13312 | 14426 | return false; |
| 13313 | 14427 | } |
| 13314 | 14428 | |
| 13315 | | static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 14429 | static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 13316 | 14430 | ZigType *enum_type) |
| 13317 | 14431 | { |
| 13318 | 14432 | assert(enum_type->id == ZigTypeIdEnum); |
| 13319 | 14433 | |
| 13320 | 14434 | Error err; |
| 13321 | 14435 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown))) |
| 13322 | | return ira->codegen->invalid_instruction; |
| 14436 | return ira->codegen->invalid_inst_gen; |
| 13323 | 14437 | |
| 13324 | 14438 | TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); |
| 13325 | 14439 | if (field == nullptr) { |
| ... | ... | @@ -13327,40 +14441,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou |
| 13327 | 14441 | buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); |
| 13328 | 14442 | add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, |
| 13329 | 14443 | buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); |
| 13330 | | return ira->codegen->invalid_instruction; |
| 14444 | return ira->codegen->invalid_inst_gen; |
| 13331 | 14445 | } |
| 13332 | | IrInstruction *result = ir_const(ira, source_instr, enum_type); |
| 14446 | IrInstGen *result = ir_const(ira, source_instr, enum_type); |
| 13333 | 14447 | bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); |
| 13334 | 14448 | |
| 13335 | 14449 | return result; |
| 13336 | 14450 | } |
| 13337 | 14451 | |
| 13338 | | static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr, |
| 13339 | | IrInstruction *value, ZigType *wanted_type) |
| 14452 | static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 14453 | IrInstGen *value, ZigType *wanted_type) |
| 13340 | 14454 | { |
| 13341 | 14455 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array")); |
| 13342 | | return ira->codegen->invalid_instruction; |
| 14456 | return ira->codegen->invalid_inst_gen; |
| 13343 | 14457 | } |
| 13344 | 14458 | |
| 13345 | | static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr, |
| 13346 | | IrInstruction *value, ZigType *wanted_type) |
| 14459 | static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr, |
| 14460 | IrInstGen *value, ZigType *wanted_type) |
| 13347 | 14461 | { |
| 13348 | 14462 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct")); |
| 13349 | | return ira->codegen->invalid_instruction; |
| 14463 | return ira->codegen->invalid_inst_gen; |
| 13350 | 14464 | } |
| 13351 | 14465 | |
| 13352 | | static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr, |
| 13353 | | IrInstruction *value, ZigType *wanted_type) |
| 14466 | static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 14467 | IrInstGen *value, ZigType *wanted_type) |
| 13354 | 14468 | { |
| 13355 | 14469 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union")); |
| 13356 | | return ira->codegen->invalid_instruction; |
| 14470 | return ira->codegen->invalid_inst_gen; |
| 13357 | 14471 | } |
| 13358 | 14472 | |
| 13359 | 14473 | // Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work, |
| 13360 | 14474 | // otherwise return ErrorNone. Does not emit any instructions. |
| 13361 | 14475 | // Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the |
| 13362 | 14476 | // pointer types' alignments if both of the pointer types are ABI aligned. |
| 13363 | | static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigType *dest_ptr_type, |
| 14477 | static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type, |
| 13364 | 14478 | ZigType *src_ptr_type, AstNode *src_source_node) |
| 13365 | 14479 | { |
| 13366 | 14480 | Error err; |
| ... | ... | @@ -13394,37 +14508,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT |
| 13394 | 14508 | return ErrorNone; |
| 13395 | 14509 | } |
| 13396 | 14510 | |
| 13397 | | static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr, |
| 13398 | | IrInstruction *struct_operand, TypeStructField *field) |
| 14511 | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr, |
| 14512 | IrInstGen *struct_operand, TypeStructField *field) |
| 13399 | 14513 | { |
| 13400 | | IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 14514 | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 13401 | 14515 | if (type_is_invalid(struct_ptr->value->type)) |
| 13402 | | return ira->codegen->invalid_instruction; |
| 13403 | | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 14516 | return ira->codegen->invalid_inst_gen; |
| 14517 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 13404 | 14518 | struct_operand->value->type, false); |
| 13405 | 14519 | if (type_is_invalid(field_ptr->value->type)) |
| 13406 | | return ira->codegen->invalid_instruction; |
| 14520 | return ira->codegen->invalid_inst_gen; |
| 13407 | 14521 | return ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 13408 | 14522 | } |
| 13409 | 14523 | |
| 13410 | | static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr, |
| 13411 | | IrInstruction *optional_operand, bool safety_check_on) |
| 14524 | static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr, |
| 14525 | IrInstGen *optional_operand, bool safety_check_on) |
| 13412 | 14526 | { |
| 13413 | | IrInstruction *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false); |
| 13414 | | IrInstruction *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr, |
| 14527 | IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false); |
| 14528 | IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr, |
| 13415 | 14529 | safety_check_on, false); |
| 13416 | 14530 | return ir_get_deref(ira, source_instr, payload_ptr, nullptr); |
| 13417 | 14531 | } |
| 13418 | 14532 | |
| 13419 | | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 13420 | | ZigType *wanted_type, IrInstruction *value) |
| 14533 | static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 14534 | ZigType *wanted_type, IrInstGen *value) |
| 13421 | 14535 | { |
| 13422 | 14536 | Error err; |
| 13423 | 14537 | ZigType *actual_type = value->value->type; |
| 13424 | 14538 | AstNode *source_node = source_instr->source_node; |
| 13425 | 14539 | |
| 13426 | 14540 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| 13427 | | return ira->codegen->invalid_instruction; |
| 14541 | return ira->codegen->invalid_inst_gen; |
| 13428 | 14542 | } |
| 13429 | 14543 | |
| 13430 | 14544 | // This means the wanted type is anything. |
| ... | ... | @@ -13436,7 +14550,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13436 | 14550 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type, |
| 13437 | 14551 | source_node, false); |
| 13438 | 14552 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 13439 | | return ira->codegen->invalid_instruction; |
| 14553 | return ira->codegen->invalid_inst_gen; |
| 13440 | 14554 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 13441 | 14555 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop); |
| 13442 | 14556 | } |
| ... | ... | @@ -13470,7 +14584,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13470 | 14584 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { |
| 13471 | 14585 | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 13472 | 14586 | } else { |
| 13473 | | return ira->codegen->invalid_instruction; |
| 14587 | return ira->codegen->invalid_inst_gen; |
| 13474 | 14588 | } |
| 13475 | 14589 | } else if ( |
| 13476 | 14590 | wanted_child_type->id == ZigTypeIdPointer && |
| ... | ... | @@ -13480,18 +14594,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13480 | 14594 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13481 | 14595 | { |
| 13482 | 14596 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13483 | | return ira->codegen->invalid_instruction; |
| 14597 | return ira->codegen->invalid_inst_gen; |
| 13484 | 14598 | if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13485 | | return ira->codegen->invalid_instruction; |
| 14599 | return ira->codegen->invalid_inst_gen; |
| 13486 | 14600 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) && |
| 13487 | 14601 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 13488 | 14602 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 13489 | 14603 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 13490 | 14604 | { |
| 13491 | | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 14605 | IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 13492 | 14606 | wanted_child_type); |
| 13493 | 14607 | if (type_is_invalid(cast1->value->type)) |
| 13494 | | return ira->codegen->invalid_instruction; |
| 14608 | return ira->codegen->invalid_inst_gen; |
| 13495 | 14609 | return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); |
| 13496 | 14610 | } |
| 13497 | 14611 | } |
| ... | ... | @@ -13509,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13509 | 14623 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 13510 | 14624 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 13511 | 14625 | } else { |
| 13512 | | return ira->codegen->invalid_instruction; |
| 14626 | return ira->codegen->invalid_inst_gen; |
| 13513 | 14627 | } |
| 13514 | 14628 | } |
| 13515 | 14629 | } |
| ... | ... | @@ -13525,13 +14639,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13525 | 14639 | actual_type->id == ZigTypeIdComptimeInt || |
| 13526 | 14640 | actual_type->id == ZigTypeIdComptimeFloat) |
| 13527 | 14641 | { |
| 13528 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 14642 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13529 | 14643 | if (type_is_invalid(cast1->value->type)) |
| 13530 | | return ira->codegen->invalid_instruction; |
| 14644 | return ira->codegen->invalid_inst_gen; |
| 13531 | 14645 | |
| 13532 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14646 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13533 | 14647 | if (type_is_invalid(cast2->value->type)) |
| 13534 | | return ira->codegen->invalid_instruction; |
| 14648 | return ira->codegen->invalid_inst_gen; |
| 13535 | 14649 | |
| 13536 | 14650 | return cast2; |
| 13537 | 14651 | } |
| ... | ... | @@ -13546,13 +14660,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13546 | 14660 | wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) |
| 13547 | 14661 | { |
| 13548 | 14662 | if (value->value->special == ConstValSpecialUndef) { |
| 13549 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14663 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13550 | 14664 | result->value->special = ConstValSpecialUndef; |
| 13551 | 14665 | return result; |
| 13552 | 14666 | } |
| 13553 | 14667 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 13554 | 14668 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 13555 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14669 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13556 | 14670 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13557 | 14671 | copy_const_val(result->value, value->value); |
| 13558 | 14672 | result->value->type = wanted_type; |
| ... | ... | @@ -13561,7 +14675,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13561 | 14675 | } |
| 13562 | 14676 | return result; |
| 13563 | 14677 | } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { |
| 13564 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14678 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13565 | 14679 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13566 | 14680 | BigFloat bf; |
| 13567 | 14681 | bigfloat_init_bigint(&bf, &value->value->data.x_bigint); |
| ... | ... | @@ -13573,7 +14687,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13573 | 14687 | } |
| 13574 | 14688 | zig_unreachable(); |
| 13575 | 14689 | } else { |
| 13576 | | return ira->codegen->invalid_instruction; |
| 14690 | return ira->codegen->invalid_inst_gen; |
| 13577 | 14691 | } |
| 13578 | 14692 | } |
| 13579 | 14693 | |
| ... | ... | @@ -13609,13 +14723,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13609 | 14723 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 13610 | 14724 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13611 | 14725 | { |
| 13612 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 14726 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13613 | 14727 | if (type_is_invalid(cast1->value->type)) |
| 13614 | | return ira->codegen->invalid_instruction; |
| 14728 | return ira->codegen->invalid_inst_gen; |
| 13615 | 14729 | |
| 13616 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14730 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13617 | 14731 | if (type_is_invalid(cast2->value->type)) |
| 13618 | | return ira->codegen->invalid_instruction; |
| 14732 | return ira->codegen->invalid_inst_gen; |
| 13619 | 14733 | |
| 13620 | 14734 | return cast2; |
| 13621 | 14735 | } |
| ... | ... | @@ -13636,9 +14750,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13636 | 14750 | actual_array_type->data.array.sentinel))) |
| 13637 | 14751 | { |
| 13638 | 14752 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13639 | | return ira->codegen->invalid_instruction; |
| 14753 | return ira->codegen->invalid_inst_gen; |
| 13640 | 14754 | if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13641 | | return ira->codegen->invalid_instruction; |
| 14755 | return ira->codegen->invalid_inst_gen; |
| 13642 | 14756 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) && |
| 13643 | 14757 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 13644 | 14758 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| ... | ... | @@ -13679,24 +14793,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13679 | 14793 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, |
| 13680 | 14794 | ResolveStatusAlignmentKnown))) |
| 13681 | 14795 | { |
| 13682 | | return ira->codegen->invalid_instruction; |
| 14796 | return ira->codegen->invalid_inst_gen; |
| 13683 | 14797 | } |
| 13684 | 14798 | if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type, |
| 13685 | 14799 | ResolveStatusAlignmentKnown))) |
| 13686 | 14800 | { |
| 13687 | | return ira->codegen->invalid_instruction; |
| 14801 | return ira->codegen->invalid_inst_gen; |
| 13688 | 14802 | } |
| 13689 | 14803 | ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type); |
| 13690 | 14804 | } |
| 13691 | 14805 | if (ok_align) { |
| 13692 | 14806 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 13693 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 14807 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 13694 | 14808 | if (type_is_invalid(cast1->value->type)) |
| 13695 | | return ira->codegen->invalid_instruction; |
| 14809 | return ira->codegen->invalid_inst_gen; |
| 13696 | 14810 | |
| 13697 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14811 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13698 | 14812 | if (type_is_invalid(cast2->value->type)) |
| 13699 | | return ira->codegen->invalid_instruction; |
| 14813 | return ira->codegen->invalid_inst_gen; |
| 13700 | 14814 | |
| 13701 | 14815 | return cast2; |
| 13702 | 14816 | } else { |
| ... | ... | @@ -13731,12 +14845,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13731 | 14845 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, |
| 13732 | 14846 | ResolveStatusAlignmentKnown))) |
| 13733 | 14847 | { |
| 13734 | | return ira->codegen->invalid_instruction; |
| 14848 | return ira->codegen->invalid_inst_gen; |
| 13735 | 14849 | } |
| 13736 | 14850 | if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type, |
| 13737 | 14851 | ResolveStatusAlignmentKnown))) |
| 13738 | 14852 | { |
| 13739 | | return ira->codegen->invalid_instruction; |
| 14853 | return ira->codegen->invalid_inst_gen; |
| 13740 | 14854 | } |
| 13741 | 14855 | ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type); |
| 13742 | 14856 | } |
| ... | ... | @@ -13777,7 +14891,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13777 | 14891 | } |
| 13778 | 14892 | } |
| 13779 | 14893 | if (ok) { |
| 13780 | | IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); |
| 14894 | IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); |
| 13781 | 14895 | if (anyframe_type == wanted_type) |
| 13782 | 14896 | return cast1; |
| 13783 | 14897 | return ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| ... | ... | @@ -13832,28 +14946,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13832 | 14946 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 13833 | 14947 | (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum)) |
| 13834 | 14948 | { |
| 13835 | | IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 13836 | | if (result == ira->codegen->invalid_instruction) |
| 14949 | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 14950 | if (type_is_invalid(result->value->type)) |
| 13837 | 14951 | return result; |
| 13838 | 14952 | |
| 13839 | | return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr); |
| 14953 | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 13840 | 14954 | } |
| 13841 | 14955 | |
| 13842 | 14956 | // cast from enum literal to error union when payload is an enum |
| 13843 | 14957 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 13844 | 14958 | (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum)) |
| 13845 | 14959 | { |
| 13846 | | IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 13847 | | if (result == ira->codegen->invalid_instruction) |
| 14960 | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 14961 | if (type_is_invalid(result->value->type)) |
| 13848 | 14962 | return result; |
| 13849 | 14963 | |
| 13850 | | return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr); |
| 14964 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 13851 | 14965 | } |
| 13852 | 14966 | |
| 13853 | 14967 | // cast from union to the enum type of the union |
| 13854 | 14968 | if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { |
| 13855 | 14969 | if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown))) |
| 13856 | | return ira->codegen->invalid_instruction; |
| 14970 | return ira->codegen->invalid_inst_gen; |
| 13857 | 14971 | |
| 13858 | 14972 | if (actual_type->data.unionation.tag_type == wanted_type) { |
| 13859 | 14973 | return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type); |
| ... | ... | @@ -13881,8 +14995,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13881 | 14995 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 13882 | 14996 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| 13883 | 14997 | { |
| 13884 | | if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node))) |
| 13885 | | return ira->codegen->invalid_instruction; |
| 14998 | if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node))) |
| 14999 | return ira->codegen->invalid_inst_gen; |
| 13886 | 15000 | |
| 13887 | 15001 | return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type); |
| 13888 | 15002 | } |
| ... | ... | @@ -13905,7 +15019,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13905 | 15019 | slice_ptr_type->data.pointer.sentinel)))) |
| 13906 | 15020 | { |
| 13907 | 15021 | TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index]; |
| 13908 | | IrInstruction *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field); |
| 15022 | IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field); |
| 13909 | 15023 | return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type); |
| 13910 | 15024 | } |
| 13911 | 15025 | } |
| ... | ... | @@ -13925,7 +15039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13925 | 15039 | dest_ptr_type = wanted_type->data.maybe.child_type; |
| 13926 | 15040 | } |
| 13927 | 15041 | if (dest_ptr_type != nullptr) { |
| 13928 | | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); |
| 15042 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 13929 | 15043 | } |
| 13930 | 15044 | } |
| 13931 | 15045 | |
| ... | ... | @@ -13936,7 +15050,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13936 | 15050 | { |
| 13937 | 15051 | bool has_bits; |
| 13938 | 15052 | if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits))) |
| 13939 | | return ira->codegen->invalid_instruction; |
| 15053 | return ira->codegen->invalid_inst_gen; |
| 13940 | 15054 | if (!has_bits) { |
| 13941 | 15055 | return ir_get_ref(ira, source_instr, value, false, false); |
| 13942 | 15056 | } |
| ... | ... | @@ -13967,7 +15081,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13967 | 15081 | actual_type->data.pointer.child_type, source_node, |
| 13968 | 15082 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 13969 | 15083 | { |
| 13970 | | return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true); |
| 15084 | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true); |
| 13971 | 15085 | } |
| 13972 | 15086 | |
| 13973 | 15087 | // cast from integer to C pointer |
| ... | ... | @@ -14003,9 +15117,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14003 | 15117 | |
| 14004 | 15118 | // T to ?U, where T implicitly casts to U |
| 14005 | 15119 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) { |
| 14006 | | IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 15120 | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 14007 | 15121 | if (type_is_invalid(cast1->value->type)) |
| 14008 | | return ira->codegen->invalid_instruction; |
| 15122 | return ira->codegen->invalid_inst_gen; |
| 14009 | 15123 | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 14010 | 15124 | } |
| 14011 | 15125 | |
| ... | ... | @@ -14013,9 +15127,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14013 | 15127 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion && |
| 14014 | 15128 | actual_type->id != ZigTypeIdErrorSet) |
| 14015 | 15129 | { |
| 14016 | | IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 15130 | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 14017 | 15131 | if (type_is_invalid(cast1->value->type)) |
| 14018 | | return ira->codegen->invalid_instruction; |
| 15132 | return ira->codegen->invalid_inst_gen; |
| 14019 | 15133 | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 14020 | 15134 | } |
| 14021 | 15135 | |
| ... | ... | @@ -14024,14 +15138,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14024 | 15138 | buf_ptr(&wanted_type->name), |
| 14025 | 15139 | buf_ptr(&actual_type->name))); |
| 14026 | 15140 | report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg); |
| 14027 | | return ira->codegen->invalid_instruction; |
| 15141 | return ira->codegen->invalid_inst_gen; |
| 14028 | 15142 | } |
| 14029 | 15143 | |
| 14030 | | static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr, |
| 14031 | | IrInstruction *value, ZigType *expected_type) |
| 15144 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 15145 | IrInstGen *value, ZigType *expected_type) |
| 14032 | 15146 | { |
| 14033 | 15147 | assert(value); |
| 14034 | | assert(value != ira->codegen->invalid_instruction); |
| 14035 | 15148 | assert(!expected_type || !type_is_invalid(expected_type)); |
| 14036 | 15149 | assert(value->value->type); |
| 14037 | 15150 | assert(!type_is_invalid(value->value->type)); |
| ... | ... | @@ -14045,17 +15158,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou |
| 14045 | 15158 | return ir_analyze_cast(ira, value_source_instr, expected_type, value); |
| 14046 | 15159 | } |
| 14047 | 15160 | |
| 14048 | | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { |
| 14049 | | return ir_implicit_cast2(ira, value, value, expected_type); |
| 15161 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) { |
| 15162 | return ir_implicit_cast2(ira, &value->base, value, expected_type); |
| 14050 | 15163 | } |
| 14051 | 15164 | |
| 14052 | | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 14053 | | ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 15165 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) { |
| 15166 | ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 14054 | 15167 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 14055 | 15168 | if (elem_type != g->builtin_types.entry_var) |
| 14056 | 15169 | return elem_type; |
| 14057 | 15170 | |
| 14058 | | if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) |
| 15171 | if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value)) |
| 14059 | 15172 | return g->builtin_types.entry_invalid; |
| 14060 | 15173 | |
| 14061 | 15174 | assert(value_is_comptime(ptr->value)); |
| ... | ... | @@ -14063,28 +15176,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 14063 | 15176 | return pointee->type; |
| 14064 | 15177 | } |
| 14065 | 15178 | |
| 14066 | | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr, |
| 15179 | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr, |
| 14067 | 15180 | ResultLoc *result_loc) |
| 14068 | 15181 | { |
| 14069 | 15182 | Error err; |
| 14070 | 15183 | ZigType *ptr_type = ptr->value->type; |
| 14071 | 15184 | if (type_is_invalid(ptr_type)) |
| 14072 | | return ira->codegen->invalid_instruction; |
| 15185 | return ira->codegen->invalid_inst_gen; |
| 14073 | 15186 | |
| 14074 | 15187 | if (ptr_type->id != ZigTypeIdPointer) { |
| 14075 | 15188 | ir_add_error_node(ira, source_instruction->source_node, |
| 14076 | 15189 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 14077 | 15190 | buf_ptr(&ptr_type->name))); |
| 14078 | | return ira->codegen->invalid_instruction; |
| 15191 | return ira->codegen->invalid_inst_gen; |
| 14079 | 15192 | } |
| 14080 | 15193 | |
| 14081 | 15194 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 14082 | 15195 | if (type_is_invalid(child_type)) |
| 14083 | | return ira->codegen->invalid_instruction; |
| 15196 | return ira->codegen->invalid_inst_gen; |
| 14084 | 15197 | // if the child type has one possible value, the deref is comptime |
| 14085 | 15198 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 14086 | 15199 | case OnePossibleValueInvalid: |
| 14087 | | return ira->codegen->invalid_instruction; |
| 15200 | return ira->codegen->invalid_inst_gen; |
| 14088 | 15201 | case OnePossibleValueYes: |
| 14089 | 15202 | return ir_const_move(ira, source_instruction, |
| 14090 | 15203 | get_the_one_possible_value(ira->codegen, child_type)); |
| ... | ... | @@ -14093,8 +15206,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14093 | 15206 | } |
| 14094 | 15207 | if (instr_is_comptime(ptr)) { |
| 14095 | 15208 | if (ptr->value->special == ConstValSpecialUndef) { |
| 14096 | | ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); |
| 14097 | | return ira->codegen->invalid_instruction; |
| 15209 | ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value")); |
| 15210 | return ira->codegen->invalid_inst_gen; |
| 14098 | 15211 | } |
| 14099 | 15212 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 14100 | 15213 | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| ... | ... | @@ -14102,12 +15215,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14102 | 15215 | child_type = pointee->type; |
| 14103 | 15216 | } |
| 14104 | 15217 | if (pointee->special != ConstValSpecialRuntime) { |
| 14105 | | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 15218 | IrInstGen *result = ir_const(ira, source_instruction, child_type); |
| 14106 | 15219 | |
| 14107 | 15220 | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, |
| 14108 | 15221 | ptr->value))) |
| 14109 | 15222 | { |
| 14110 | | return ira->codegen->invalid_instruction; |
| 15223 | return ira->codegen->invalid_inst_gen; |
| 14111 | 15224 | } |
| 14112 | 15225 | result->value->type = child_type; |
| 14113 | 15226 | return result; |
| ... | ... | @@ -14116,38 +15229,37 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14116 | 15229 | } |
| 14117 | 15230 | |
| 14118 | 15231 | // if the instruction is a const ref instruction we can skip it |
| 14119 | | if (ptr->id == IrInstructionIdRef) { |
| 14120 | | IrInstructionRef *ref_inst = reinterpret_cast<IrInstructionRef *>(ptr); |
| 14121 | | return ref_inst->value; |
| 15232 | if (ptr->id == IrInstGenIdRef) { |
| 15233 | IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr); |
| 15234 | return ref_inst->operand; |
| 14122 | 15235 | } |
| 14123 | 15236 | |
| 14124 | 15237 | // If the instruction is a element pointer instruction to a vector, we emit |
| 14125 | 15238 | // vector element extract instruction rather than load pointer. If the |
| 14126 | 15239 | // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been |
| 14127 | | // possible to implement this in the codegen for IrInstructionLoadPtrGen. |
| 15240 | // possible to implement this in the codegen for IrInstGenLoadPtr. |
| 14128 | 15241 | // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error |
| 14129 | 15242 | // if the vector index cannot be determined right here, right now, because |
| 14130 | 15243 | // the type information does not contain enough information to actually |
| 14131 | 15244 | // perform a dereference. |
| 14132 | 15245 | if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 14133 | | if (ptr->id == IrInstructionIdElemPtr) { |
| 14134 | | IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; |
| 14135 | | IrInstruction *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr, |
| 15246 | if (ptr->id == IrInstGenIdElemPtr) { |
| 15247 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 15248 | IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base, |
| 14136 | 15249 | elem_ptr->array_ptr, nullptr); |
| 14137 | | IrInstruction *elem_index = elem_ptr->elem_index; |
| 15250 | IrInstGen *elem_index = elem_ptr->elem_index; |
| 14138 | 15251 | return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index); |
| 14139 | 15252 | } |
| 14140 | | ir_add_error(ira, ptr, |
| 15253 | ir_add_error(ira, &ptr->base, |
| 14141 | 15254 | buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name))); |
| 14142 | | return ira->codegen->invalid_instruction; |
| 15255 | return ira->codegen->invalid_inst_gen; |
| 14143 | 15256 | } |
| 14144 | 15257 | |
| 14145 | | IrInstruction *result_loc_inst; |
| 15258 | IrInstGen *result_loc_inst; |
| 14146 | 15259 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 14147 | 15260 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 14148 | | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| 14149 | | true, false, true); |
| 14150 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 15261 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true); |
| 15262 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 14151 | 15263 | return result_loc_inst; |
| 14152 | 15264 | } |
| 14153 | 15265 | } else { |
| ... | ... | @@ -14157,7 +15269,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14157 | 15269 | return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst); |
| 14158 | 15270 | } |
| 14159 | 15271 | |
| 14160 | | static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 15272 | static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 14161 | 15273 | ZigValue *const_val, uint32_t *out) |
| 14162 | 15274 | { |
| 14163 | 15275 | Error err; |
| ... | ... | @@ -14166,12 +15278,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 14166 | 15278 | |
| 14167 | 15279 | uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint); |
| 14168 | 15280 | if (align_bytes == 0) { |
| 14169 | | exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1")); |
| 15281 | exec_add_error_node_gen(codegen, exec, source_node, buf_sprintf("alignment must be >= 1")); |
| 14170 | 15282 | return false; |
| 14171 | 15283 | } |
| 14172 | 15284 | |
| 14173 | 15285 | if (!is_power_of_2(align_bytes)) { |
| 14174 | | exec_add_error_node(codegen, exec, source_node, |
| 15286 | exec_add_error_node_gen(codegen, exec, source_node, |
| 14175 | 15287 | buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes)); |
| 14176 | 15288 | return false; |
| 14177 | 15289 | } |
| ... | ... | @@ -14180,7 +15292,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 14180 | 15292 | return true; |
| 14181 | 15293 | } |
| 14182 | 15294 | |
| 14183 | | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { |
| 15295 | static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_type, uint32_t *out) { |
| 14184 | 15296 | if (type_is_invalid(value->value->type)) |
| 14185 | 15297 | return false; |
| 14186 | 15298 | |
| ... | ... | @@ -14201,19 +15313,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem |
| 14201 | 15313 | } |
| 14202 | 15314 | } |
| 14203 | 15315 | |
| 14204 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 15316 | IrInstGen *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 14205 | 15317 | if (type_is_invalid(casted_value->value->type)) |
| 14206 | 15318 | return false; |
| 14207 | 15319 | |
| 14208 | | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, |
| 15320 | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 14209 | 15321 | casted_value->value, out); |
| 14210 | 15322 | } |
| 14211 | 15323 | |
| 14212 | | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { |
| 15324 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstGen *value, ZigType *int_type, uint64_t *out) { |
| 14213 | 15325 | if (type_is_invalid(value->value->type)) |
| 14214 | 15326 | return false; |
| 14215 | 15327 | |
| 14216 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type); |
| 15328 | IrInstGen *casted_value = ir_implicit_cast(ira, value, int_type); |
| 14217 | 15329 | if (type_is_invalid(casted_value->value->type)) |
| 14218 | 15330 | return false; |
| 14219 | 15331 | |
| ... | ... | @@ -14225,15 +15337,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i |
| 14225 | 15337 | return true; |
| 14226 | 15338 | } |
| 14227 | 15339 | |
| 14228 | | static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) { |
| 15340 | static bool ir_resolve_usize(IrAnalyze *ira, IrInstGen *value, uint64_t *out) { |
| 14229 | 15341 | return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out); |
| 14230 | 15342 | } |
| 14231 | 15343 | |
| 14232 | | static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 15344 | static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) { |
| 14233 | 15345 | if (type_is_invalid(value->value->type)) |
| 14234 | 15346 | return false; |
| 14235 | 15347 | |
| 14236 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 15348 | IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 14237 | 15349 | if (type_is_invalid(casted_value->value->type)) |
| 14238 | 15350 | return false; |
| 14239 | 15351 | |
| ... | ... | @@ -14245,7 +15357,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 14245 | 15357 | return true; |
| 14246 | 15358 | } |
| 14247 | 15359 | |
| 14248 | | static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 15360 | static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) { |
| 14249 | 15361 | if (!value) { |
| 14250 | 15362 | *out = false; |
| 14251 | 15363 | return true; |
| ... | ... | @@ -14253,13 +15365,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) |
| 14253 | 15365 | return ir_resolve_bool(ira, value, out); |
| 14254 | 15366 | } |
| 14255 | 15367 | |
| 14256 | | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { |
| 15368 | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstGen *value, AtomicOrder *out) { |
| 14257 | 15369 | if (type_is_invalid(value->value->type)) |
| 14258 | 15370 | return false; |
| 14259 | 15371 | |
| 14260 | 15372 | ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder"); |
| 14261 | 15373 | |
| 14262 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 15374 | IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 14263 | 15375 | if (type_is_invalid(casted_value->value->type)) |
| 14264 | 15376 | return false; |
| 14265 | 15377 | |
| ... | ... | @@ -14271,13 +15383,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 14271 | 15383 | return true; |
| 14272 | 15384 | } |
| 14273 | 15385 | |
| 14274 | | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) { |
| 15386 | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstGen *value, AtomicRmwOp *out) { |
| 14275 | 15387 | if (type_is_invalid(value->value->type)) |
| 14276 | 15388 | return false; |
| 14277 | 15389 | |
| 14278 | 15390 | ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp"); |
| 14279 | 15391 | |
| 14280 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 15392 | IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 14281 | 15393 | if (type_is_invalid(casted_value->value->type)) |
| 14282 | 15394 | return false; |
| 14283 | 15395 | |
| ... | ... | @@ -14289,13 +15401,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 14289 | 15401 | return true; |
| 14290 | 15402 | } |
| 14291 | 15403 | |
| 14292 | | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) { |
| 15404 | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstGen *value, GlobalLinkageId *out) { |
| 14293 | 15405 | if (type_is_invalid(value->value->type)) |
| 14294 | 15406 | return false; |
| 14295 | 15407 | |
| 14296 | 15408 | ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage"); |
| 14297 | 15409 | |
| 14298 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 15410 | IrInstGen *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 14299 | 15411 | if (type_is_invalid(casted_value->value->type)) |
| 14300 | 15412 | return false; |
| 14301 | 15413 | |
| ... | ... | @@ -14307,13 +15419,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 14307 | 15419 | return true; |
| 14308 | 15420 | } |
| 14309 | 15421 | |
| 14310 | | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) { |
| 15422 | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstGen *value, FloatMode *out) { |
| 14311 | 15423 | if (type_is_invalid(value->value->type)) |
| 14312 | 15424 | return false; |
| 14313 | 15425 | |
| 14314 | 15426 | ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode"); |
| 14315 | 15427 | |
| 14316 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 15428 | IrInstGen *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 14317 | 15429 | if (type_is_invalid(casted_value->value->type)) |
| 14318 | 15430 | return false; |
| 14319 | 15431 | |
| ... | ... | @@ -14325,14 +15437,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 14325 | 15437 | return true; |
| 14326 | 15438 | } |
| 14327 | 15439 | |
| 14328 | | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 15440 | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) { |
| 14329 | 15441 | if (type_is_invalid(value->value->type)) |
| 14330 | 15442 | return nullptr; |
| 14331 | 15443 | |
| 14332 | 15444 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 14333 | 15445 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 14334 | 15446 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 14335 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 15447 | IrInstGen *casted_value = ir_implicit_cast(ira, value, str_type); |
| 14336 | 15448 | if (type_is_invalid(casted_value->value->type)) |
| 14337 | 15449 | return nullptr; |
| 14338 | 15450 | |
| ... | ... | @@ -14356,7 +15468,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 14356 | 15468 | size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; |
| 14357 | 15469 | ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; |
| 14358 | 15470 | if (char_val->special == ConstValSpecialUndef) { |
| 14359 | | ir_add_error(ira, casted_value, buf_sprintf("use of undefined value")); |
| 15471 | ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value")); |
| 14360 | 15472 | return nullptr; |
| 14361 | 15473 | } |
| 14362 | 15474 | uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint); |
| ... | ... | @@ -14367,10 +15479,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 14367 | 15479 | return result; |
| 14368 | 15480 | } |
| 14369 | 15481 | |
| 14370 | | static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 14371 | | IrInstructionAddImplicitReturnType *instruction) |
| 15482 | static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 15483 | IrInstSrcAddImplicitReturnType *instruction) |
| 14372 | 15484 | { |
| 14373 | | IrInstruction *value = instruction->value->child; |
| 15485 | IrInstGen *value = instruction->value->child; |
| 14374 | 15486 | if (type_is_invalid(value->value->type)) |
| 14375 | 15487 | return ir_unreach_error(ira); |
| 14376 | 15488 | |
| ... | ... | @@ -14378,15 +15490,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 14378 | 15490 | ira->src_implicit_return_type_list.append(value); |
| 14379 | 15491 | } |
| 14380 | 15492 | |
| 14381 | | return ir_const_void(ira, &instruction->base); |
| 15493 | return ir_const_void(ira, &instruction->base.base); |
| 14382 | 15494 | } |
| 14383 | 15495 | |
| 14384 | | static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { |
| 14385 | | IrInstruction *operand = instruction->operand->child; |
| 15496 | static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) { |
| 15497 | IrInstGen *operand = instruction->operand->child; |
| 14386 | 15498 | if (type_is_invalid(operand->value->type)) |
| 14387 | 15499 | return ir_unreach_error(ira); |
| 14388 | 15500 | |
| 14389 | | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 15501 | IrInstGen *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 14390 | 15502 | if (type_is_invalid(casted_operand->value->type)) { |
| 14391 | 15503 | AstNode *source_node = ira->explicit_return_type_source_node; |
| 14392 | 15504 | if (source_node != nullptr) { |
| ... | ... | @@ -14401,9 +15513,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 14401 | 15513 | handle_is_ptr(ira->explicit_return_type)) |
| 14402 | 15514 | { |
| 14403 | 15515 | // result location mechanism took care of it. |
| 14404 | | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 14405 | | instruction->base.source_node, nullptr); |
| 14406 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 15516 | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr); |
| 14407 | 15517 | return ir_finish_anal(ira, result); |
| 14408 | 15518 | } |
| 14409 | 15519 | |
| ... | ... | @@ -14411,47 +15521,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 14411 | 15521 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 14412 | 15522 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 14413 | 15523 | { |
| 14414 | | ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable")); |
| 15524 | ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable")); |
| 14415 | 15525 | return ir_unreach_error(ira); |
| 14416 | 15526 | } |
| 14417 | 15527 | |
| 14418 | | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 14419 | | instruction->base.source_node, casted_operand); |
| 14420 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 15528 | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand); |
| 14421 | 15529 | return ir_finish_anal(ira, result); |
| 14422 | 15530 | } |
| 14423 | 15531 | |
| 14424 | | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 14425 | | return ir_const_move(ira, &instruction->base, instruction->base.value); |
| 15532 | static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) { |
| 15533 | return ir_const_move(ira, &instruction->base.base, instruction->value); |
| 14426 | 15534 | } |
| 14427 | 15535 | |
| 14428 | | static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 14429 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 15536 | static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 15537 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 14430 | 15538 | if (type_is_invalid(op1->value->type)) |
| 14431 | | return ira->codegen->invalid_instruction; |
| 15539 | return ira->codegen->invalid_inst_gen; |
| 14432 | 15540 | |
| 14433 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 15541 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 14434 | 15542 | if (type_is_invalid(op2->value->type)) |
| 14435 | | return ira->codegen->invalid_instruction; |
| 15543 | return ira->codegen->invalid_inst_gen; |
| 14436 | 15544 | |
| 14437 | 15545 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 14438 | 15546 | |
| 14439 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 14440 | | if (casted_op1 == ira->codegen->invalid_instruction) |
| 14441 | | return ira->codegen->invalid_instruction; |
| 15547 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 15548 | if (type_is_invalid(casted_op1->value->type)) |
| 15549 | return ira->codegen->invalid_inst_gen; |
| 14442 | 15550 | |
| 14443 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type); |
| 14444 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 14445 | | return ira->codegen->invalid_instruction; |
| 15551 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type); |
| 15552 | if (type_is_invalid(casted_op2->value->type)) |
| 15553 | return ira->codegen->invalid_inst_gen; |
| 14446 | 15554 | |
| 14447 | 15555 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 14448 | 15556 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 14449 | 15557 | if (op1_val == nullptr) |
| 14450 | | return ira->codegen->invalid_instruction; |
| 15558 | return ira->codegen->invalid_inst_gen; |
| 14451 | 15559 | |
| 14452 | 15560 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 14453 | 15561 | if (op2_val == nullptr) |
| 14454 | | return ira->codegen->invalid_instruction; |
| 15562 | return ira->codegen->invalid_inst_gen; |
| 14455 | 15563 | |
| 14456 | 15564 | assert(casted_op1->value->type->id == ZigTypeIdBool); |
| 14457 | 15565 | assert(casted_op2->value->type->id == ZigTypeIdBool); |
| ... | ... | @@ -14463,14 +15571,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 14463 | 15571 | } else { |
| 14464 | 15572 | zig_unreachable(); |
| 14465 | 15573 | } |
| 14466 | | return ir_const_bool(ira, &bin_op_instruction->base, result_bool); |
| 15574 | return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool); |
| 14467 | 15575 | } |
| 14468 | 15576 | |
| 14469 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14470 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 15577 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type, |
| 14471 | 15578 | bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 14472 | | result->value->type = bool_type; |
| 14473 | | return result; |
| 14474 | 15579 | } |
| 14475 | 15580 | |
| 14476 | 15581 | static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { |
| ... | ... | @@ -14535,12 +15640,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) { |
| 14535 | 15640 | } |
| 14536 | 15641 | } |
| 14537 | 15642 | |
| 14538 | | static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 14539 | | ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, |
| 14540 | | bool one_possible_value) { |
| 15643 | static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 15644 | ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id, |
| 15645 | bool one_possible_value) |
| 15646 | { |
| 14541 | 15647 | if (op1_val->special == ConstValSpecialUndef || |
| 14542 | 15648 | op2_val->special == ConstValSpecialUndef) |
| 14543 | | return ir_const_undef(ira, &bin_op_instruction->base, resolved_type); |
| 15649 | return ir_const_undef(ira, &bin_op_instruction->base.base, resolved_type); |
| 14544 | 15650 | if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) { |
| 14545 | 15651 | if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14546 | 15652 | op1_val->data.x_ptr.special == ConstPtrSpecialNull) && |
| ... | ... | @@ -14560,7 +15666,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t |
| 14560 | 15666 | cmp_result = CmpEQ; |
| 14561 | 15667 | } |
| 14562 | 15668 | bool answer = resolve_cmp_op_id(op_id, cmp_result); |
| 14563 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 15669 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 14564 | 15670 | } |
| 14565 | 15671 | } else { |
| 14566 | 15672 | bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val); |
| ... | ... | @@ -14572,15 +15678,33 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t |
| 14572 | 15678 | } else { |
| 14573 | 15679 | zig_unreachable(); |
| 14574 | 15680 | } |
| 14575 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 15681 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 14576 | 15682 | } |
| 14577 | 15683 | zig_unreachable(); |
| 14578 | 15684 | } |
| 14579 | 15685 | |
| 14580 | 15686 | // Returns ErrorNotLazy when the value cannot be determined |
| 14581 | | static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { |
| 15687 | static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val, Cmp *result) { |
| 14582 | 15688 | Error err; |
| 14583 | 15689 | |
| 15690 | switch (type_has_one_possible_value(codegen, val->type)) { |
| 15691 | case OnePossibleValueInvalid: |
| 15692 | return ErrorSemanticAnalyzeFail; |
| 15693 | case OnePossibleValueNo: |
| 15694 | break; |
| 15695 | case OnePossibleValueYes: |
| 15696 | switch (val->type->id) { |
| 15697 | case ZigTypeIdInt: |
| 15698 | src_assert(val->type->data.integral.bit_count == 0, source_node); |
| 15699 | *result = CmpEQ; |
| 15700 | return ErrorNone; |
| 15701 | case ZigTypeIdUndefined: |
| 15702 | return ErrorNotLazy; |
| 15703 | default: |
| 15704 | zig_unreachable(); |
| 15705 | } |
| 15706 | } |
| 15707 | |
| 14584 | 15708 | switch (val->special) { |
| 14585 | 15709 | case ConstValSpecialRuntime: |
| 14586 | 15710 | case ConstValSpecialUndef: |
| ... | ... | @@ -14626,7 +15750,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { |
| 14626 | 15750 | zig_unreachable(); |
| 14627 | 15751 | } |
| 14628 | 15752 | |
| 14629 | | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source_instr, |
| 15753 | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 14630 | 15754 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 14631 | 15755 | { |
| 14632 | 15756 | Error err; |
| ... | ... | @@ -14634,12 +15758,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source |
| 14634 | 15758 | // Before resolving the values, we special case comparisons against zero. These can often |
| 14635 | 15759 | // be done without resolving lazy values, preventing potential dependency loops. |
| 14636 | 15760 | Cmp op1_cmp_zero; |
| 14637 | | if ((err = lazy_cmp_zero(source_instr->source_node, op1_val, &op1_cmp_zero))) { |
| 15761 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) { |
| 14638 | 15762 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14639 | 15763 | return ira->codegen->trace_err; |
| 14640 | 15764 | } |
| 14641 | 15765 | Cmp op2_cmp_zero; |
| 14642 | | if ((err = lazy_cmp_zero(source_instr->source_node, op2_val, &op2_cmp_zero))) { |
| 15766 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) { |
| 14643 | 15767 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14644 | 15768 | return ira->codegen->trace_err; |
| 14645 | 15769 | } |
| ... | ... | @@ -14704,14 +15828,14 @@ never_mind_just_calculate_it_normally: |
| 14704 | 15828 | return nullptr; |
| 14705 | 15829 | } |
| 14706 | 15830 | if (op1_val->type->id == ZigTypeIdComptimeFloat) { |
| 14707 | | IrInstruction *tmp = ir_const_noval(ira, source_instr); |
| 15831 | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 14708 | 15832 | tmp->value = op1_val; |
| 14709 | | IrInstruction *casted = ir_implicit_cast(ira, tmp, op2_val->type); |
| 15833 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type); |
| 14710 | 15834 | op1_val = casted->value; |
| 14711 | 15835 | } else if (op2_val->type->id == ZigTypeIdComptimeFloat) { |
| 14712 | | IrInstruction *tmp = ir_const_noval(ira, source_instr); |
| 15836 | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 14713 | 15837 | tmp->value = op2_val; |
| 14714 | | IrInstruction *casted = ir_implicit_cast(ira, tmp, op1_val->type); |
| 15838 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type); |
| 14715 | 15839 | op2_val = casted->value; |
| 14716 | 15840 | } |
| 14717 | 15841 | Cmp cmp_result = float_cmp(op1_val, op2_val); |
| ... | ... | @@ -14723,38 +15847,49 @@ never_mind_just_calculate_it_normally: |
| 14723 | 15847 | bool op1_is_int = op1_val->type->id == ZigTypeIdInt || op1_val->type->id == ZigTypeIdComptimeInt; |
| 14724 | 15848 | bool op2_is_int = op2_val->type->id == ZigTypeIdInt || op2_val->type->id == ZigTypeIdComptimeInt; |
| 14725 | 15849 | |
| 14726 | | BigInt *op1_bigint; |
| 14727 | | BigInt *op2_bigint; |
| 14728 | | bool need_to_free_op1_bigint = false; |
| 14729 | | bool need_to_free_op2_bigint = false; |
| 14730 | | if (op1_is_float) { |
| 14731 | | op1_bigint = allocate<BigInt>(1, "BigInt"); |
| 14732 | | need_to_free_op1_bigint = true; |
| 14733 | | float_init_bigint(op1_bigint, op1_val); |
| 14734 | | } else { |
| 14735 | | assert(op1_is_int); |
| 14736 | | op1_bigint = &op1_val->data.x_bigint; |
| 15850 | if (op1_is_int && op2_is_int) { |
| 15851 | Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 15852 | out_val->special = ConstValSpecialStatic; |
| 15853 | out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result); |
| 15854 | |
| 15855 | return nullptr; |
| 14737 | 15856 | } |
| 14738 | | if (op2_is_float) { |
| 14739 | | op2_bigint = allocate<BigInt>(1, "BigInt"); |
| 14740 | | need_to_free_op2_bigint = true; |
| 14741 | | float_init_bigint(op2_bigint, op2_val); |
| 15857 | |
| 15858 | // Handle the case where one of the two operands is a fp value and the other |
| 15859 | // is an integer value |
| 15860 | ZigValue *float_val; |
| 15861 | if (op1_is_int && op2_is_float) { |
| 15862 | float_val = op2_val; |
| 15863 | } else if (op1_is_float && op2_is_int) { |
| 15864 | float_val = op1_val; |
| 14742 | 15865 | } else { |
| 14743 | | assert(op2_is_int); |
| 14744 | | op2_bigint = &op2_val->data.x_bigint; |
| 15866 | zig_unreachable(); |
| 15867 | } |
| 15868 | |
| 15869 | // They can never be equal if the fp value has a non-zero decimal part |
| 15870 | if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) { |
| 15871 | if (float_has_fraction(float_val)) { |
| 15872 | out_val->special = ConstValSpecialStatic; |
| 15873 | out_val->data.x_bool = op_id == IrBinOpCmpNotEq; |
| 15874 | return nullptr; |
| 15875 | } |
| 14745 | 15876 | } |
| 14746 | 15877 | |
| 14747 | | Cmp cmp_result = bigint_cmp(op1_bigint, op2_bigint); |
| 15878 | // Cast the integer operand into a fp value to perform the comparison |
| 15879 | BigFloat op1_bigfloat; |
| 15880 | BigFloat op2_bigfloat; |
| 15881 | value_to_bigfloat(&op1_bigfloat, op1_val); |
| 15882 | value_to_bigfloat(&op2_bigfloat, op2_val); |
| 15883 | |
| 15884 | Cmp cmp_result = bigfloat_cmp(&op1_bigfloat, &op2_bigfloat); |
| 14748 | 15885 | out_val->special = ConstValSpecialStatic; |
| 14749 | 15886 | out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result); |
| 14750 | 15887 | |
| 14751 | | if (need_to_free_op1_bigint) destroy(op1_bigint, "BigInt"); |
| 14752 | | if (need_to_free_op2_bigint) destroy(op2_bigint, "BigInt"); |
| 14753 | 15888 | return nullptr; |
| 14754 | 15889 | } |
| 14755 | 15890 | |
| 14756 | | static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr, |
| 14757 | | IrInstruction *op1, IrInstruction *op2, IrBinOp op_id) |
| 15891 | static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr, |
| 15892 | IrInstGen *op1, IrInstGen *op2, IrBinOp op_id) |
| 14758 | 15893 | { |
| 14759 | 15894 | Error err; |
| 14760 | 15895 | |
| ... | ... | @@ -14767,7 +15902,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14767 | 15902 | ir_add_error(ira, source_instr, |
| 14768 | 15903 | buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32, |
| 14769 | 15904 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); |
| 14770 | | return ira->codegen->invalid_instruction; |
| 15905 | return ira->codegen->invalid_inst_gen; |
| 14771 | 15906 | } |
| 14772 | 15907 | result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type); |
| 14773 | 15908 | op1_scalar_type = op1->value->type->data.vector.elem_type; |
| ... | ... | @@ -14776,13 +15911,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14776 | 15911 | ir_add_error(ira, source_instr, |
| 14777 | 15912 | buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'", |
| 14778 | 15913 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 14779 | | return ira->codegen->invalid_instruction; |
| 15914 | return ira->codegen->invalid_inst_gen; |
| 14780 | 15915 | } |
| 14781 | 15916 | |
| 14782 | 15917 | bool opv_op1; |
| 14783 | 15918 | switch (type_has_one_possible_value(ira->codegen, op1->value->type)) { |
| 14784 | 15919 | case OnePossibleValueInvalid: |
| 14785 | | return ira->codegen->invalid_instruction; |
| 15920 | return ira->codegen->invalid_inst_gen; |
| 14786 | 15921 | case OnePossibleValueYes: |
| 14787 | 15922 | opv_op1 = true; |
| 14788 | 15923 | break; |
| ... | ... | @@ -14793,7 +15928,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14793 | 15928 | bool opv_op2; |
| 14794 | 15929 | switch (type_has_one_possible_value(ira->codegen, op2->value->type)) { |
| 14795 | 15930 | case OnePossibleValueInvalid: |
| 14796 | | return ira->codegen->invalid_instruction; |
| 15931 | return ira->codegen->invalid_inst_gen; |
| 14797 | 15932 | case OnePossibleValueYes: |
| 14798 | 15933 | opv_op2 = true; |
| 14799 | 15934 | break; |
| ... | ... | @@ -14803,22 +15938,22 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14803 | 15938 | } |
| 14804 | 15939 | Cmp op1_cmp_zero; |
| 14805 | 15940 | bool have_op1_cmp_zero = false; |
| 14806 | | if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) { |
| 14807 | | if (err != ErrorNotLazy) return ira->codegen->invalid_instruction; |
| 15941 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) { |
| 15942 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 14808 | 15943 | } else { |
| 14809 | 15944 | have_op1_cmp_zero = true; |
| 14810 | 15945 | } |
| 14811 | 15946 | Cmp op2_cmp_zero; |
| 14812 | 15947 | bool have_op2_cmp_zero = false; |
| 14813 | | if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) { |
| 14814 | | if (err != ErrorNotLazy) return ira->codegen->invalid_instruction; |
| 15948 | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) { |
| 15949 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 14815 | 15950 | } else { |
| 14816 | 15951 | have_op2_cmp_zero = true; |
| 14817 | 15952 | } |
| 14818 | 15953 | if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) || |
| 14819 | 15954 | (have_op1_cmp_zero && have_op2_cmp_zero)) |
| 14820 | 15955 | { |
| 14821 | | IrInstruction *result_instruction = ir_const(ira, source_instr, result_type); |
| 15956 | IrInstGen *result_instruction = ir_const(ira, source_instr, result_type); |
| 14822 | 15957 | ZigValue *out_val = result_instruction->value; |
| 14823 | 15958 | if (result_type->id == ZigTypeIdVector) { |
| 14824 | 15959 | size_t len = result_type->data.vector.len; |
| ... | ... | @@ -14836,7 +15971,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14836 | 15971 | if (msg != nullptr) { |
| 14837 | 15972 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 14838 | 15973 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 14839 | | return ira->codegen->invalid_instruction; |
| 15974 | return ira->codegen->invalid_inst_gen; |
| 14840 | 15975 | } |
| 14841 | 15976 | } |
| 14842 | 15977 | out_val->type = result_type; |
| ... | ... | @@ -14845,7 +15980,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14845 | 15980 | if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id, |
| 14846 | 15981 | op2->value, out_val) != nullptr) |
| 14847 | 15982 | { |
| 14848 | | return ira->codegen->invalid_instruction; |
| 15983 | return ira->codegen->invalid_inst_gen; |
| 14849 | 15984 | } |
| 14850 | 15985 | } |
| 14851 | 15986 | return result_instruction; |
| ... | ... | @@ -14939,10 +16074,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14939 | 16074 | } |
| 14940 | 16075 | ZigType *dest_type = (result_type->id == ZigTypeIdVector) ? |
| 14941 | 16076 | get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type; |
| 14942 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 14943 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 16077 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 16078 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 14944 | 16079 | if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type)) |
| 14945 | | return ira->codegen->invalid_instruction; |
| 16080 | return ira->codegen->invalid_inst_gen; |
| 14946 | 16081 | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 14947 | 16082 | } |
| 14948 | 16083 | |
| ... | ... | @@ -14972,12 +16107,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14972 | 16107 | if (instr_is_comptime(op1)) { |
| 14973 | 16108 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk); |
| 14974 | 16109 | if (op1_val == nullptr) |
| 14975 | | return ira->codegen->invalid_instruction; |
| 16110 | return ira->codegen->invalid_inst_gen; |
| 14976 | 16111 | if (op1_val->special == ConstValSpecialUndef) |
| 14977 | 16112 | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 14978 | 16113 | if (result_type->id == ZigTypeIdVector) { |
| 14979 | | ir_add_error(ira, op1, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 14980 | | return ira->codegen->invalid_instruction; |
| 16114 | ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 16115 | return ira->codegen->invalid_inst_gen; |
| 14981 | 16116 | } |
| 14982 | 16117 | bool is_unsigned; |
| 14983 | 16118 | if (op1_is_float) { |
| ... | ... | @@ -15016,12 +16151,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 15016 | 16151 | if (instr_is_comptime(op2)) { |
| 15017 | 16152 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk); |
| 15018 | 16153 | if (op2_val == nullptr) |
| 15019 | | return ira->codegen->invalid_instruction; |
| 16154 | return ira->codegen->invalid_inst_gen; |
| 15020 | 16155 | if (op2_val->special == ConstValSpecialUndef) |
| 15021 | 16156 | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 15022 | 16157 | if (result_type->id == ZigTypeIdVector) { |
| 15023 | | ir_add_error(ira, op2, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 15024 | | return ira->codegen->invalid_instruction; |
| 16158 | ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 16159 | return ira->codegen->invalid_inst_gen; |
| 15025 | 16160 | } |
| 15026 | 16161 | bool is_unsigned; |
| 15027 | 16162 | if (op2_is_float) { |
| ... | ... | @@ -15062,35 +16197,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 15062 | 16197 | ZigType *dest_type = (result_type->id == ZigTypeIdVector) ? |
| 15063 | 16198 | get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type; |
| 15064 | 16199 | |
| 15065 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 16200 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 15066 | 16201 | if (type_is_invalid(casted_op1->value->type)) |
| 15067 | | return ira->codegen->invalid_instruction; |
| 15068 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 16202 | return ira->codegen->invalid_inst_gen; |
| 16203 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 15069 | 16204 | if (type_is_invalid(casted_op2->value->type)) |
| 15070 | | return ira->codegen->invalid_instruction; |
| 16205 | return ira->codegen->invalid_inst_gen; |
| 15071 | 16206 | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 15072 | 16207 | } |
| 15073 | 16208 | |
| 15074 | | static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 15075 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 16209 | static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16210 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 15076 | 16211 | if (type_is_invalid(op1->value->type)) |
| 15077 | | return ira->codegen->invalid_instruction; |
| 16212 | return ira->codegen->invalid_inst_gen; |
| 15078 | 16213 | |
| 15079 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 16214 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 15080 | 16215 | if (type_is_invalid(op2->value->type)) |
| 15081 | | return ira->codegen->invalid_instruction; |
| 16216 | return ira->codegen->invalid_inst_gen; |
| 15082 | 16217 | |
| 15083 | | AstNode *source_node = bin_op_instruction->base.source_node; |
| 16218 | AstNode *source_node = bin_op_instruction->base.base.source_node; |
| 15084 | 16219 | |
| 15085 | 16220 | IrBinOp op_id = bin_op_instruction->op_id; |
| 15086 | 16221 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 15087 | 16222 | if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) { |
| 15088 | | return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq)); |
| 16223 | return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq)); |
| 15089 | 16224 | } else if (is_equality_cmp && |
| 15090 | 16225 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || |
| 15091 | 16226 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) |
| 15092 | 16227 | { |
| 15093 | | IrInstruction *maybe_op; |
| 16228 | IrInstGen *maybe_op; |
| 15094 | 16229 | if (op1->value->type->id == ZigTypeIdNull) { |
| 15095 | 16230 | maybe_op = op2; |
| 15096 | 16231 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| ... | ... | @@ -15101,21 +16236,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15101 | 16236 | if (instr_is_comptime(maybe_op)) { |
| 15102 | 16237 | ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); |
| 15103 | 16238 | if (!maybe_val) |
| 15104 | | return ira->codegen->invalid_instruction; |
| 16239 | return ira->codegen->invalid_inst_gen; |
| 15105 | 16240 | bool is_null = optional_value_is_null(maybe_val); |
| 15106 | 16241 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 15107 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16242 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15108 | 16243 | } |
| 15109 | 16244 | |
| 15110 | | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 15111 | | source_node, maybe_op); |
| 15112 | | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 16245 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op); |
| 15113 | 16246 | |
| 15114 | 16247 | if (op_id == IrBinOpCmpEq) { |
| 15115 | | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 15116 | | bin_op_instruction->base.source_node, is_non_null); |
| 15117 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15118 | | return result; |
| 16248 | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 15119 | 16249 | } else { |
| 15120 | 16250 | return is_non_null; |
| 15121 | 16251 | } |
| ... | ... | @@ -15125,7 +16255,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15125 | 16255 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer && |
| 15126 | 16256 | op1->value->type->data.pointer.ptr_len == PtrLenC))) |
| 15127 | 16257 | { |
| 15128 | | IrInstruction *c_ptr_op; |
| 16258 | IrInstGen *c_ptr_op; |
| 15129 | 16259 | if (op1->value->type->id == ZigTypeIdNull) { |
| 15130 | 16260 | c_ptr_op = op2; |
| 15131 | 16261 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| ... | ... | @@ -15136,24 +16266,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15136 | 16266 | if (instr_is_comptime(c_ptr_op)) { |
| 15137 | 16267 | ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); |
| 15138 | 16268 | if (!c_ptr_val) |
| 15139 | | return ira->codegen->invalid_instruction; |
| 16269 | return ira->codegen->invalid_inst_gen; |
| 15140 | 16270 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 15141 | | return ir_const_undef(ira, &bin_op_instruction->base, ira->codegen->builtin_types.entry_bool); |
| 16271 | return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool); |
| 15142 | 16272 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 15143 | 16273 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 15144 | 16274 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 15145 | 16275 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 15146 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16276 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15147 | 16277 | } |
| 15148 | | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 15149 | | source_node, c_ptr_op); |
| 15150 | | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 16278 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op); |
| 15151 | 16279 | |
| 15152 | 16280 | if (op_id == IrBinOpCmpEq) { |
| 15153 | | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 15154 | | bin_op_instruction->base.source_node, is_non_null); |
| 15155 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15156 | | return result; |
| 16281 | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 15157 | 16282 | } else { |
| 15158 | 16283 | return is_non_null; |
| 15159 | 16284 | } |
| ... | ... | @@ -15161,61 +16286,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15161 | 16286 | ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; |
| 15162 | 16287 | ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", |
| 15163 | 16288 | buf_ptr(&non_null_type->name))); |
| 15164 | | return ira->codegen->invalid_instruction; |
| 16289 | return ira->codegen->invalid_inst_gen; |
| 15165 | 16290 | } else if (is_equality_cmp && ( |
| 15166 | 16291 | (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) || |
| 15167 | 16292 | (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion))) |
| 15168 | 16293 | { |
| 15169 | 16294 | // Support equality comparison between a union's tag value and a enum literal |
| 15170 | | IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; |
| 15171 | | IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; |
| 16295 | IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; |
| 16296 | IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; |
| 15172 | 16297 | |
| 15173 | 16298 | ZigType *tag_type = union_val->value->type->data.unionation.tag_type; |
| 15174 | 16299 | assert(tag_type != nullptr); |
| 15175 | 16300 | |
| 15176 | | IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 16301 | IrInstGen *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 15177 | 16302 | if (type_is_invalid(casted_union->value->type)) |
| 15178 | | return ira->codegen->invalid_instruction; |
| 16303 | return ira->codegen->invalid_inst_gen; |
| 15179 | 16304 | |
| 15180 | | IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 16305 | IrInstGen *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 15181 | 16306 | if (type_is_invalid(casted_val->value->type)) |
| 15182 | | return ira->codegen->invalid_instruction; |
| 16307 | return ira->codegen->invalid_inst_gen; |
| 15183 | 16308 | |
| 15184 | 16309 | if (instr_is_comptime(casted_union)) { |
| 15185 | 16310 | ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); |
| 15186 | 16311 | if (!const_union_val) |
| 15187 | | return ira->codegen->invalid_instruction; |
| 16312 | return ira->codegen->invalid_inst_gen; |
| 15188 | 16313 | |
| 15189 | 16314 | ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); |
| 15190 | 16315 | if (!const_enum_val) |
| 15191 | | return ira->codegen->invalid_instruction; |
| 16316 | return ira->codegen->invalid_inst_gen; |
| 15192 | 16317 | |
| 15193 | 16318 | Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag); |
| 15194 | 16319 | bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ; |
| 15195 | 16320 | |
| 15196 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16321 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15197 | 16322 | } |
| 15198 | 16323 | |
| 15199 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15200 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16324 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 15201 | 16325 | op_id, casted_union, casted_val, bin_op_instruction->safety_check_on); |
| 15202 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15203 | | |
| 15204 | | return result; |
| 15205 | 16326 | } |
| 15206 | 16327 | |
| 15207 | 16328 | if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) { |
| 15208 | 16329 | if (!is_equality_cmp) { |
| 15209 | 16330 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 15210 | | return ira->codegen->invalid_instruction; |
| 16331 | return ira->codegen->invalid_inst_gen; |
| 15211 | 16332 | } |
| 15212 | 16333 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node); |
| 15213 | 16334 | if (type_is_invalid(intersect_type)) { |
| 15214 | | return ira->codegen->invalid_instruction; |
| 16335 | return ira->codegen->invalid_inst_gen; |
| 15215 | 16336 | } |
| 15216 | 16337 | |
| 15217 | 16338 | if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) { |
| 15218 | | return ira->codegen->invalid_instruction; |
| 16339 | return ira->codegen->invalid_inst_gen; |
| 15219 | 16340 | } |
| 15220 | 16341 | |
| 15221 | 16342 | // exception if one of the operators has the type of the empty error set, we allow the comparison |
| ... | ... | @@ -15232,7 +16353,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15232 | 16353 | } else { |
| 15233 | 16354 | zig_unreachable(); |
| 15234 | 16355 | } |
| 15235 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16356 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15236 | 16357 | } |
| 15237 | 16358 | |
| 15238 | 16359 | if (!type_is_global_error_set(intersect_type)) { |
| ... | ... | @@ -15240,7 +16361,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15240 | 16361 | ir_add_error_node(ira, source_node, |
| 15241 | 16362 | buf_sprintf("error sets '%s' and '%s' have no common errors", |
| 15242 | 16363 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 15243 | | return ira->codegen->invalid_instruction; |
| 16364 | return ira->codegen->invalid_inst_gen; |
| 15244 | 16365 | } |
| 15245 | 16366 | if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) { |
| 15246 | 16367 | bool are_equal = true; |
| ... | ... | @@ -15252,17 +16373,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15252 | 16373 | } else { |
| 15253 | 16374 | zig_unreachable(); |
| 15254 | 16375 | } |
| 15255 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16376 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15256 | 16377 | } |
| 15257 | 16378 | } |
| 15258 | 16379 | |
| 15259 | 16380 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15260 | 16381 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15261 | 16382 | if (op1_val == nullptr) |
| 15262 | | return ira->codegen->invalid_instruction; |
| 16383 | return ira->codegen->invalid_inst_gen; |
| 15263 | 16384 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15264 | 16385 | if (op2_val == nullptr) |
| 15265 | | return ira->codegen->invalid_instruction; |
| 16386 | return ira->codegen->invalid_inst_gen; |
| 15266 | 16387 | |
| 15267 | 16388 | bool answer; |
| 15268 | 16389 | bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value; |
| ... | ... | @@ -15274,27 +16395,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15274 | 16395 | zig_unreachable(); |
| 15275 | 16396 | } |
| 15276 | 16397 | |
| 15277 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16398 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15278 | 16399 | } |
| 15279 | 16400 | |
| 15280 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15281 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16401 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 15282 | 16402 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 15283 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15284 | | return result; |
| 15285 | 16403 | } |
| 15286 | 16404 | |
| 15287 | 16405 | if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) { |
| 15288 | 16406 | // This operation allows any combination of integer and float types, regardless of the |
| 15289 | 16407 | // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for |
| 15290 | 16408 | // numeric types. |
| 15291 | | return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base, op1, op2, op_id); |
| 16409 | return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id); |
| 15292 | 16410 | } |
| 15293 | 16411 | |
| 15294 | | IrInstruction *instructions[] = {op1, op2}; |
| 16412 | IrInstGen *instructions[] = {op1, op2}; |
| 15295 | 16413 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 15296 | 16414 | if (type_is_invalid(resolved_type)) |
| 15297 | | return ira->codegen->invalid_instruction; |
| 16415 | return ira->codegen->invalid_inst_gen; |
| 15298 | 16416 | |
| 15299 | 16417 | bool operator_allowed; |
| 15300 | 16418 | switch (resolved_type->id) { |
| ... | ... | @@ -15342,21 +16460,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15342 | 16460 | if (!operator_allowed) { |
| 15343 | 16461 | ir_add_error_node(ira, source_node, |
| 15344 | 16462 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); |
| 15345 | | return ira->codegen->invalid_instruction; |
| 16463 | return ira->codegen->invalid_inst_gen; |
| 15346 | 16464 | } |
| 15347 | 16465 | |
| 15348 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 15349 | | if (casted_op1 == ira->codegen->invalid_instruction) |
| 15350 | | return ira->codegen->invalid_instruction; |
| 16466 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 16467 | if (type_is_invalid(casted_op1->value->type)) |
| 16468 | return ira->codegen->invalid_inst_gen; |
| 15351 | 16469 | |
| 15352 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 15353 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 15354 | | return ira->codegen->invalid_instruction; |
| 16470 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 16471 | if (type_is_invalid(casted_op2->value->type)) |
| 16472 | return ira->codegen->invalid_inst_gen; |
| 15355 | 16473 | |
| 15356 | 16474 | bool one_possible_value; |
| 15357 | 16475 | switch (type_has_one_possible_value(ira->codegen, resolved_type)) { |
| 15358 | 16476 | case OnePossibleValueInvalid: |
| 15359 | | return ira->codegen->invalid_instruction; |
| 16477 | return ira->codegen->invalid_inst_gen; |
| 15360 | 16478 | case OnePossibleValueYes: |
| 15361 | 16479 | one_possible_value = true; |
| 15362 | 16480 | break; |
| ... | ... | @@ -15368,20 +16486,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15368 | 16486 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 15369 | 16487 | ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 15370 | 16488 | if (op1_val == nullptr) |
| 15371 | | return ira->codegen->invalid_instruction; |
| 16489 | return ira->codegen->invalid_inst_gen; |
| 15372 | 16490 | ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 15373 | 16491 | if (op2_val == nullptr) |
| 15374 | | return ira->codegen->invalid_instruction; |
| 16492 | return ira->codegen->invalid_inst_gen; |
| 15375 | 16493 | if (resolved_type->id != ZigTypeIdVector) |
| 15376 | 16494 | return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value); |
| 15377 | | IrInstruction *result = ir_const(ira, &bin_op_instruction->base, |
| 16495 | IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base, |
| 15378 | 16496 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); |
| 15379 | 16497 | result->value->data.x_array.data.s_none.elements = |
| 15380 | 16498 | create_const_vals(resolved_type->data.vector.len); |
| 15381 | 16499 | |
| 15382 | 16500 | expand_undef_array(ira->codegen, result->value); |
| 15383 | 16501 | for (size_t i = 0;i < resolved_type->data.vector.len;i++) { |
| 15384 | | IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 16502 | IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 15385 | 16503 | &op1_val->data.x_array.data.s_none.elements[i], |
| 15386 | 16504 | &op2_val->data.x_array.data.s_none.elements[i], |
| 15387 | 16505 | bin_op_instruction, op_id, one_possible_value); |
| ... | ... | @@ -15390,19 +16508,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15390 | 16508 | return result; |
| 15391 | 16509 | } |
| 15392 | 16510 | |
| 15393 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15394 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16511 | ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ? |
| 16512 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) : |
| 16513 | ira->codegen->builtin_types.entry_bool; |
| 16514 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type, |
| 15395 | 16515 | op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 15396 | | if (resolved_type->id == ZigTypeIdVector) { |
| 15397 | | result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len, |
| 15398 | | ira->codegen->builtin_types.entry_bool); |
| 15399 | | } else { |
| 15400 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15401 | | } |
| 15402 | | return result; |
| 15403 | 16516 | } |
| 15404 | 16517 | |
| 15405 | | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 16518 | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 15406 | 16519 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 15407 | 16520 | { |
| 15408 | 16521 | bool is_int; |
| ... | ... | @@ -15582,10 +16695,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in |
| 15582 | 16695 | } |
| 15583 | 16696 | |
| 15584 | 16697 | // This works on operands that have already been checked to be comptime known. |
| 15585 | | static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr, |
| 16698 | static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr, |
| 15586 | 16699 | ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) |
| 15587 | 16700 | { |
| 15588 | | IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry); |
| 16701 | IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry); |
| 15589 | 16702 | ZigValue *out_val = result_instruction->value; |
| 15590 | 16703 | if (type_entry->id == ZigTypeIdVector) { |
| 15591 | 16704 | expand_undef_array(ira->codegen, op1_val); |
| ... | ... | @@ -15606,43 +16719,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 15606 | 16719 | if (msg != nullptr) { |
| 15607 | 16720 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 15608 | 16721 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 15609 | | return ira->codegen->invalid_instruction; |
| 16722 | return ira->codegen->invalid_inst_gen; |
| 15610 | 16723 | } |
| 15611 | 16724 | } |
| 15612 | 16725 | out_val->type = type_entry; |
| 15613 | 16726 | out_val->special = ConstValSpecialStatic; |
| 15614 | 16727 | } else { |
| 15615 | 16728 | if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) { |
| 15616 | | return ira->codegen->invalid_instruction; |
| 16729 | return ira->codegen->invalid_inst_gen; |
| 15617 | 16730 | } |
| 15618 | 16731 | } |
| 15619 | 16732 | return ir_implicit_cast(ira, result_instruction, type_entry); |
| 15620 | 16733 | } |
| 15621 | 16734 | |
| 15622 | | static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 15623 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 16735 | static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16736 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 15624 | 16737 | if (type_is_invalid(op1->value->type)) |
| 15625 | | return ira->codegen->invalid_instruction; |
| 16738 | return ira->codegen->invalid_inst_gen; |
| 15626 | 16739 | |
| 15627 | 16740 | if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) { |
| 15628 | | ir_add_error(ira, bin_op_instruction->op1, |
| 16741 | ir_add_error(ira, &bin_op_instruction->op1->base, |
| 15629 | 16742 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 15630 | 16743 | buf_ptr(&op1->value->type->name))); |
| 15631 | | return ira->codegen->invalid_instruction; |
| 16744 | return ira->codegen->invalid_inst_gen; |
| 15632 | 16745 | } |
| 15633 | 16746 | |
| 15634 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 16747 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 15635 | 16748 | if (type_is_invalid(op2->value->type)) |
| 15636 | | return ira->codegen->invalid_instruction; |
| 16749 | return ira->codegen->invalid_inst_gen; |
| 15637 | 16750 | |
| 15638 | 16751 | if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) { |
| 15639 | | ir_add_error(ira, bin_op_instruction->op2, |
| 16752 | ir_add_error(ira, &bin_op_instruction->op2->base, |
| 15640 | 16753 | buf_sprintf("shift amount has to be an integer type, but found '%s'", |
| 15641 | 16754 | buf_ptr(&op2->value->type->name))); |
| 15642 | | return ira->codegen->invalid_instruction; |
| 16755 | return ira->codegen->invalid_inst_gen; |
| 15643 | 16756 | } |
| 15644 | 16757 | |
| 15645 | | IrInstruction *casted_op2; |
| 16758 | IrInstGen *casted_op2; |
| 15646 | 16759 | IrBinOp op_id = bin_op_instruction->op_id; |
| 15647 | 16760 | if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 15648 | 16761 | casted_op2 = op2; |
| ... | ... | @@ -15654,8 +16767,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 15654 | 16767 | if (casted_op2->value->data.x_bigint.is_negative) { |
| 15655 | 16768 | Buf *val_buf = buf_alloc(); |
| 15656 | 16769 | bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10); |
| 15657 | | ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 15658 | | return ira->codegen->invalid_instruction; |
| 16770 | ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 16771 | return ira->codegen->invalid_inst_gen; |
| 15659 | 16772 | } |
| 15660 | 16773 | } else { |
| 15661 | 16774 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| ... | ... | @@ -15665,57 +16778,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 15665 | 16778 | |
| 15666 | 16779 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15667 | 16780 | if (op2_val == nullptr) |
| 15668 | | return ira->codegen->invalid_instruction; |
| 16781 | return ira->codegen->invalid_inst_gen; |
| 15669 | 16782 | if (!bigint_fits_in_bits(&op2_val->data.x_bigint, |
| 15670 | 16783 | shift_amt_type->data.integral.bit_count, |
| 15671 | 16784 | op2_val->data.x_bigint.is_negative)) { |
| 15672 | 16785 | Buf *val_buf = buf_alloc(); |
| 15673 | 16786 | bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10); |
| 15674 | 16787 | ErrorMsg* msg = ir_add_error(ira, |
| 15675 | | &bin_op_instruction->base, |
| 16788 | &bin_op_instruction->base.base, |
| 15676 | 16789 | buf_sprintf("RHS of shift is too large for LHS type")); |
| 15677 | 16790 | add_error_note( |
| 15678 | 16791 | ira->codegen, |
| 15679 | 16792 | msg, |
| 15680 | | op2->source_node, |
| 16793 | op2->base.source_node, |
| 15681 | 16794 | buf_sprintf("value %s cannot fit into type %s", |
| 15682 | 16795 | buf_ptr(val_buf), |
| 15683 | 16796 | buf_ptr(&shift_amt_type->name))); |
| 15684 | | return ira->codegen->invalid_instruction; |
| 16797 | return ira->codegen->invalid_inst_gen; |
| 15685 | 16798 | } |
| 15686 | 16799 | } |
| 15687 | 16800 | |
| 15688 | 16801 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); |
| 15689 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 15690 | | return ira->codegen->invalid_instruction; |
| 16802 | if (type_is_invalid(casted_op2->value->type)) |
| 16803 | return ira->codegen->invalid_inst_gen; |
| 15691 | 16804 | } |
| 15692 | 16805 | |
| 15693 | 16806 | if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { |
| 15694 | 16807 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15695 | 16808 | if (op1_val == nullptr) |
| 15696 | | return ira->codegen->invalid_instruction; |
| 16809 | return ira->codegen->invalid_inst_gen; |
| 15697 | 16810 | |
| 15698 | 16811 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15699 | 16812 | if (op2_val == nullptr) |
| 15700 | | return ira->codegen->invalid_instruction; |
| 16813 | return ira->codegen->invalid_inst_gen; |
| 15701 | 16814 | |
| 15702 | | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val); |
| 16815 | return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1->value->type, op1_val, op_id, op2_val); |
| 15703 | 16816 | } else if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 15704 | | ir_add_error(ira, &bin_op_instruction->base, |
| 16817 | ir_add_error(ira, &bin_op_instruction->base.base, |
| 15705 | 16818 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 15706 | | return ira->codegen->invalid_instruction; |
| 16819 | return ira->codegen->invalid_inst_gen; |
| 15707 | 16820 | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) { |
| 15708 | | IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope, |
| 15709 | | bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop); |
| 15710 | | result->value->type = op1->value->type; |
| 15711 | | return result; |
| 16821 | return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop); |
| 15712 | 16822 | } |
| 15713 | 16823 | |
| 15714 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, |
| 15715 | | bin_op_instruction->base.source_node, op_id, |
| 15716 | | op1, casted_op2, bin_op_instruction->safety_check_on); |
| 15717 | | result->value->type = op1->value->type; |
| 15718 | | return result; |
| 16824 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type, |
| 16825 | op_id, op1, casted_op2, bin_op_instruction->safety_check_on); |
| 15719 | 16826 | } |
| 15720 | 16827 | |
| 15721 | 16828 | static bool ok_float_op(IrBinOp op) { |
| ... | ... | @@ -15779,24 +16886,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) { |
| 15779 | 16886 | zig_unreachable(); |
| 15780 | 16887 | } |
| 15781 | 16888 | |
| 15782 | | static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16889 | static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 15783 | 16890 | Error err; |
| 15784 | 16891 | |
| 15785 | | IrInstruction *op1 = instruction->op1->child; |
| 16892 | IrInstGen *op1 = instruction->op1->child; |
| 15786 | 16893 | if (type_is_invalid(op1->value->type)) |
| 15787 | | return ira->codegen->invalid_instruction; |
| 16894 | return ira->codegen->invalid_inst_gen; |
| 15788 | 16895 | |
| 15789 | | IrInstruction *op2 = instruction->op2->child; |
| 16896 | IrInstGen *op2 = instruction->op2->child; |
| 15790 | 16897 | if (type_is_invalid(op2->value->type)) |
| 15791 | | return ira->codegen->invalid_instruction; |
| 16898 | return ira->codegen->invalid_inst_gen; |
| 15792 | 16899 | |
| 15793 | 16900 | IrBinOp op_id = instruction->op_id; |
| 15794 | 16901 | |
| 15795 | 16902 | // look for pointer math |
| 15796 | 16903 | if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) { |
| 15797 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 16904 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 15798 | 16905 | if (type_is_invalid(casted_op2->value->type)) |
| 15799 | | return ira->codegen->invalid_instruction; |
| 16906 | return ira->codegen->invalid_inst_gen; |
| 15800 | 16907 | |
| 15801 | 16908 | // If either operand is undef, result is undef. |
| 15802 | 16909 | ZigValue *op1_val = nullptr; |
| ... | ... | @@ -15804,28 +16911,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15804 | 16911 | if (instr_is_comptime(op1)) { |
| 15805 | 16912 | op1_val = ir_resolve_const(ira, op1, UndefOk); |
| 15806 | 16913 | if (op1_val == nullptr) |
| 15807 | | return ira->codegen->invalid_instruction; |
| 16914 | return ira->codegen->invalid_inst_gen; |
| 15808 | 16915 | if (op1_val->special == ConstValSpecialUndef) |
| 15809 | | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 16916 | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 15810 | 16917 | } |
| 15811 | 16918 | if (instr_is_comptime(casted_op2)) { |
| 15812 | 16919 | op2_val = ir_resolve_const(ira, casted_op2, UndefOk); |
| 15813 | 16920 | if (op2_val == nullptr) |
| 15814 | | return ira->codegen->invalid_instruction; |
| 16921 | return ira->codegen->invalid_inst_gen; |
| 15815 | 16922 | if (op2_val->special == ConstValSpecialUndef) |
| 15816 | | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 16923 | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 15817 | 16924 | } |
| 15818 | 16925 | |
| 15819 | 16926 | ZigType *elem_type = op1->value->type->data.pointer.child_type; |
| 15820 | 16927 | if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) |
| 15821 | | return ira->codegen->invalid_instruction; |
| 16928 | return ira->codegen->invalid_inst_gen; |
| 15822 | 16929 | |
| 15823 | 16930 | // NOTE: this variable is meaningful iff op2_val is not null! |
| 15824 | 16931 | uint64_t byte_offset; |
| 15825 | 16932 | if (op2_val != nullptr) { |
| 15826 | 16933 | uint64_t elem_offset; |
| 15827 | 16934 | if (!ir_resolve_usize(ira, casted_op2, &elem_offset)) |
| 15828 | | return ira->codegen->invalid_instruction; |
| 16935 | return ira->codegen->invalid_inst_gen; |
| 15829 | 16936 | |
| 15830 | 16937 | byte_offset = type_size(ira->codegen, elem_type) * elem_offset; |
| 15831 | 16938 | } |
| ... | ... | @@ -15840,7 +16947,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15840 | 16947 | { |
| 15841 | 16948 | uint32_t align_bytes; |
| 15842 | 16949 | if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes))) |
| 15843 | | return ira->codegen->invalid_instruction; |
| 16950 | return ira->codegen->invalid_inst_gen; |
| 15844 | 16951 | |
| 15845 | 16952 | // If the addend is not a comptime-known value we can still count on |
| 15846 | 16953 | // it being a multiple of the type size |
| ... | ... | @@ -15869,23 +16976,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15869 | 16976 | } else { |
| 15870 | 16977 | zig_unreachable(); |
| 15871 | 16978 | } |
| 15872 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 16979 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 15873 | 16980 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 15874 | 16981 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 15875 | 16982 | result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 15876 | 16983 | return result; |
| 15877 | 16984 | } |
| 15878 | 16985 | |
| 15879 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 15880 | | instruction->base.source_node, op_id, op1, casted_op2, true); |
| 15881 | | result->value->type = result_type; |
| 15882 | | return result; |
| 16986 | return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true); |
| 15883 | 16987 | } |
| 15884 | 16988 | |
| 15885 | | IrInstruction *instructions[] = {op1, op2}; |
| 15886 | | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2); |
| 16989 | IrInstGen *instructions[] = {op1, op2}; |
| 16990 | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2); |
| 15887 | 16991 | if (type_is_invalid(resolved_type)) |
| 15888 | | return ira->codegen->invalid_instruction; |
| 16992 | return ira->codegen->invalid_inst_gen; |
| 15889 | 16993 | |
| 15890 | 16994 | bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; |
| 15891 | 16995 | bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; |
| ... | ... | @@ -15905,11 +17009,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15905 | 17009 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15906 | 17010 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15907 | 17011 | if (op1_val == nullptr) |
| 15908 | | return ira->codegen->invalid_instruction; |
| 17012 | return ira->codegen->invalid_inst_gen; |
| 15909 | 17013 | |
| 15910 | 17014 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15911 | 17015 | if (op2_val == nullptr) |
| 15912 | | return ira->codegen->invalid_instruction; |
| 17016 | return ira->codegen->invalid_inst_gen; |
| 15913 | 17017 | |
| 15914 | 17018 | if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) { |
| 15915 | 17019 | // the division by zero error will be caught later, but we don't have a |
| ... | ... | @@ -15928,11 +17032,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15928 | 17032 | } |
| 15929 | 17033 | } |
| 15930 | 17034 | if (!ok) { |
| 15931 | | ir_add_error(ira, &instruction->base, |
| 17035 | ir_add_error(ira, &instruction->base.base, |
| 15932 | 17036 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 15933 | 17037 | buf_ptr(&op1->value->type->name), |
| 15934 | 17038 | buf_ptr(&op2->value->type->name))); |
| 15935 | | return ira->codegen->invalid_instruction; |
| 17039 | return ira->codegen->invalid_inst_gen; |
| 15936 | 17040 | } |
| 15937 | 17041 | } else { |
| 15938 | 17042 | op_id = IrBinOpDivTrunc; |
| ... | ... | @@ -15943,12 +17047,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15943 | 17047 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15944 | 17048 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15945 | 17049 | if (op1_val == nullptr) |
| 15946 | | return ira->codegen->invalid_instruction; |
| 17050 | return ira->codegen->invalid_inst_gen; |
| 15947 | 17051 | |
| 15948 | 17052 | if (is_int) { |
| 15949 | 17053 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15950 | 17054 | if (op2_val == nullptr) |
| 15951 | | return ira->codegen->invalid_instruction; |
| 17055 | return ira->codegen->invalid_inst_gen; |
| 15952 | 17056 | |
| 15953 | 17057 | if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) { |
| 15954 | 17058 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -15962,13 +17066,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15962 | 17066 | ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ; |
| 15963 | 17067 | } |
| 15964 | 17068 | } else { |
| 15965 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 15966 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 15967 | | return ira->codegen->invalid_instruction; |
| 17069 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 17070 | if (type_is_invalid(casted_op2->value->type)) |
| 17071 | return ira->codegen->invalid_inst_gen; |
| 15968 | 17072 | |
| 15969 | 17073 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15970 | 17074 | if (op2_val == nullptr) |
| 15971 | | return ira->codegen->invalid_instruction; |
| 17075 | return ira->codegen->invalid_inst_gen; |
| 15972 | 17076 | |
| 15973 | 17077 | if (float_cmp_zero(casted_op2->value) == CmpEQ) { |
| 15974 | 17078 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -15984,11 +17088,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15984 | 17088 | } |
| 15985 | 17089 | } |
| 15986 | 17090 | if (!ok) { |
| 15987 | | ir_add_error(ira, &instruction->base, |
| 17091 | ir_add_error(ira, &instruction->base.base, |
| 15988 | 17092 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 15989 | 17093 | buf_ptr(&op1->value->type->name), |
| 15990 | 17094 | buf_ptr(&op2->value->type->name))); |
| 15991 | | return ira->codegen->invalid_instruction; |
| 17095 | return ira->codegen->invalid_inst_gen; |
| 15992 | 17096 | } |
| 15993 | 17097 | } |
| 15994 | 17098 | op_id = IrBinOpRemRem; |
| ... | ... | @@ -16008,12 +17112,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 16008 | 17112 | } |
| 16009 | 17113 | } |
| 16010 | 17114 | if (!ok) { |
| 16011 | | AstNode *source_node = instruction->base.source_node; |
| 17115 | AstNode *source_node = instruction->base.base.source_node; |
| 16012 | 17116 | ir_add_error_node(ira, source_node, |
| 16013 | 17117 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 16014 | 17118 | buf_ptr(&op1->value->type->name), |
| 16015 | 17119 | buf_ptr(&op2->value->type->name))); |
| 16016 | | return ira->codegen->invalid_instruction; |
| 17120 | return ira->codegen->invalid_inst_gen; |
| 16017 | 17121 | } |
| 16018 | 17122 | |
| 16019 | 17123 | if (resolved_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -16026,33 +17130,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 16026 | 17130 | } |
| 16027 | 17131 | } |
| 16028 | 17132 | |
| 16029 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 16030 | | if (casted_op1 == ira->codegen->invalid_instruction) |
| 16031 | | return ira->codegen->invalid_instruction; |
| 17133 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 17134 | if (type_is_invalid(casted_op1->value->type)) |
| 17135 | return ira->codegen->invalid_inst_gen; |
| 16032 | 17136 | |
| 16033 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 16034 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 16035 | | return ira->codegen->invalid_instruction; |
| 17137 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 17138 | if (type_is_invalid(casted_op2->value->type)) |
| 17139 | return ira->codegen->invalid_inst_gen; |
| 16036 | 17140 | |
| 16037 | 17141 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 16038 | 17142 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 16039 | 17143 | if (op1_val == nullptr) |
| 16040 | | return ira->codegen->invalid_instruction; |
| 17144 | return ira->codegen->invalid_inst_gen; |
| 16041 | 17145 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 16042 | 17146 | if (op2_val == nullptr) |
| 16043 | | return ira->codegen->invalid_instruction; |
| 17147 | return ira->codegen->invalid_inst_gen; |
| 16044 | 17148 | |
| 16045 | | return ir_analyze_math_op(ira, &instruction->base, resolved_type, op1_val, op_id, op2_val); |
| 17149 | return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val); |
| 16046 | 17150 | } |
| 16047 | 17151 | |
| 16048 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 16049 | | instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 16050 | | result->value->type = resolved_type; |
| 16051 | | return result; |
| 17152 | return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type, |
| 17153 | op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 16052 | 17154 | } |
| 16053 | 17155 | |
| 16054 | | static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr, |
| 16055 | | IrInstruction *op1, IrInstruction *op2) |
| 17156 | static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 17157 | IrInstGen *op1, IrInstGen *op2) |
| 16056 | 17158 | { |
| 16057 | 17159 | Error err; |
| 16058 | 17160 | ZigType *op1_type = op1->value->type; |
| ... | ... | @@ -16069,10 +17171,10 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16069 | 17171 | new_type->data.structure.special = StructSpecialInferredTuple; |
| 16070 | 17172 | new_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| 16071 | 17173 | |
| 16072 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope); |
| 17174 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope); |
| 16073 | 17175 | |
| 16074 | | IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 16075 | | new_type, nullptr, false, false, true); |
| 17176 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 17177 | new_type, nullptr, false, true); |
| 16076 | 17178 | uint32_t new_field_count = op1_field_count + op2_field_count; |
| 16077 | 17179 | |
| 16078 | 17180 | new_type->data.structure.src_field_count = new_field_count; |
| ... | ... | @@ -16095,13 +17197,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16095 | 17197 | new_field->is_comptime = src_field->is_comptime; |
| 16096 | 17198 | } |
| 16097 | 17199 | if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown))) |
| 16098 | | return ira->codegen->invalid_instruction; |
| 17200 | return ira->codegen->invalid_inst_gen; |
| 16099 | 17201 | |
| 16100 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 16101 | | IrInstruction *first_non_const_instruction = nullptr; |
| 17202 | ZigList<IrInstGen *> const_ptrs = {}; |
| 17203 | IrInstGen *first_non_const_instruction = nullptr; |
| 16102 | 17204 | for (uint32_t i = 0; i < new_field_count; i += 1) { |
| 16103 | 17205 | TypeStructField *dst_field = new_type->data.structure.fields[i]; |
| 16104 | | IrInstruction *src_struct_op; |
| 17206 | IrInstGen *src_struct_op; |
| 16105 | 17207 | TypeStructField *src_field; |
| 16106 | 17208 | if (i < op1_field_count) { |
| 16107 | 17209 | src_field = op1_type->data.structure.fields[i]; |
| ... | ... | @@ -16110,73 +17212,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16110 | 17212 | src_field = op2_type->data.structure.fields[i - op1_field_count]; |
| 16111 | 17213 | src_struct_op = op2; |
| 16112 | 17214 | } |
| 16113 | | IrInstruction *field_value = ir_analyze_struct_value_field_value(ira, source_instr, |
| 17215 | IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr, |
| 16114 | 17216 | src_struct_op, src_field); |
| 16115 | 17217 | if (type_is_invalid(field_value->value->type)) |
| 16116 | | return ira->codegen->invalid_instruction; |
| 16117 | | IrInstruction *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field, |
| 17218 | return ira->codegen->invalid_inst_gen; |
| 17219 | IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field, |
| 16118 | 17220 | new_struct_ptr, new_type, true); |
| 16119 | 17221 | if (type_is_invalid(dest_ptr->value->type)) |
| 16120 | | return ira->codegen->invalid_instruction; |
| 17222 | return ira->codegen->invalid_inst_gen; |
| 16121 | 17223 | if (instr_is_comptime(field_value)) { |
| 16122 | 17224 | const_ptrs.append(dest_ptr); |
| 16123 | 17225 | } else { |
| 16124 | 17226 | first_non_const_instruction = field_value; |
| 16125 | 17227 | } |
| 16126 | | IrInstruction *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value, |
| 17228 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value, |
| 16127 | 17229 | true); |
| 16128 | 17230 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 16129 | | return ira->codegen->invalid_instruction; |
| 17231 | return ira->codegen->invalid_inst_gen; |
| 16130 | 17232 | } |
| 16131 | 17233 | if (const_ptrs.length != new_field_count) { |
| 16132 | 17234 | new_struct_ptr->value->special = ConstValSpecialRuntime; |
| 16133 | 17235 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 16134 | | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 17236 | IrInstGen *elem_result_loc = const_ptrs.at(i); |
| 16135 | 17237 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 16136 | 17238 | if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) { |
| 16137 | 17239 | // This field will be generated comptime; no need to do this. |
| 16138 | 17240 | continue; |
| 16139 | 17241 | } |
| 16140 | | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 17242 | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 16141 | 17243 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 16142 | | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 17244 | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false); |
| 16143 | 17245 | } |
| 16144 | 17246 | } |
| 16145 | | IrInstruction *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 17247 | IrInstGen *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 16146 | 17248 | if (instr_is_comptime(result)) |
| 16147 | 17249 | return result; |
| 16148 | 17250 | |
| 16149 | 17251 | if (is_comptime) { |
| 16150 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 17252 | ir_add_error(ira, &first_non_const_instruction->base, |
| 16151 | 17253 | buf_sprintf("unable to evaluate constant expression")); |
| 16152 | | return ira->codegen->invalid_instruction; |
| 17254 | return ira->codegen->invalid_inst_gen; |
| 16153 | 17255 | } |
| 16154 | 17256 | |
| 16155 | 17257 | return result; |
| 16156 | 17258 | } |
| 16157 | 17259 | |
| 16158 | | static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16159 | | IrInstruction *op1 = instruction->op1->child; |
| 17260 | static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 17261 | IrInstGen *op1 = instruction->op1->child; |
| 16160 | 17262 | ZigType *op1_type = op1->value->type; |
| 16161 | 17263 | if (type_is_invalid(op1_type)) |
| 16162 | | return ira->codegen->invalid_instruction; |
| 17264 | return ira->codegen->invalid_inst_gen; |
| 16163 | 17265 | |
| 16164 | | IrInstruction *op2 = instruction->op2->child; |
| 17266 | IrInstGen *op2 = instruction->op2->child; |
| 16165 | 17267 | ZigType *op2_type = op2->value->type; |
| 16166 | 17268 | if (type_is_invalid(op2_type)) |
| 16167 | | return ira->codegen->invalid_instruction; |
| 17269 | return ira->codegen->invalid_inst_gen; |
| 16168 | 17270 | |
| 16169 | 17271 | if (is_tuple(op1_type) && is_tuple(op2_type)) { |
| 16170 | | return ir_analyze_tuple_cat(ira, &instruction->base, op1, op2); |
| 17272 | return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2); |
| 16171 | 17273 | } |
| 16172 | 17274 | |
| 16173 | 17275 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 16174 | 17276 | if (!op1_val) |
| 16175 | | return ira->codegen->invalid_instruction; |
| 17277 | return ira->codegen->invalid_inst_gen; |
| 16176 | 17278 | |
| 16177 | 17279 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 16178 | 17280 | if (!op2_val) |
| 16179 | | return ira->codegen->invalid_instruction; |
| 17281 | return ira->codegen->invalid_inst_gen; |
| 16180 | 17282 | |
| 16181 | 17283 | ZigValue *sentinel1 = nullptr; |
| 16182 | 17284 | ZigValue *op1_array_val; |
| ... | ... | @@ -16214,15 +17316,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16214 | 17316 | { |
| 16215 | 17317 | ZigType *array_type = op1_type->data.pointer.child_type; |
| 16216 | 17318 | child_type = array_type->data.array.child_type; |
| 16217 | | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node); |
| 17319 | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node); |
| 16218 | 17320 | if (op1_array_val == nullptr) |
| 16219 | | return ira->codegen->invalid_instruction; |
| 17321 | return ira->codegen->invalid_inst_gen; |
| 16220 | 17322 | op1_array_index = 0; |
| 16221 | 17323 | op1_array_end = array_type->data.array.len; |
| 16222 | 17324 | sentinel1 = array_type->data.array.sentinel; |
| 16223 | 17325 | } else { |
| 16224 | | ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 16225 | | return ira->codegen->invalid_instruction; |
| 17326 | ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 17327 | return ira->codegen->invalid_inst_gen; |
| 16226 | 17328 | } |
| 16227 | 17329 | |
| 16228 | 17330 | ZigValue *sentinel2 = nullptr; |
| ... | ... | @@ -16262,23 +17364,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16262 | 17364 | { |
| 16263 | 17365 | ZigType *array_type = op2_type->data.pointer.child_type; |
| 16264 | 17366 | op2_type_valid = array_type->data.array.child_type == child_type; |
| 16265 | | op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node); |
| 17367 | op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node); |
| 16266 | 17368 | if (op2_array_val == nullptr) |
| 16267 | | return ira->codegen->invalid_instruction; |
| 17369 | return ira->codegen->invalid_inst_gen; |
| 16268 | 17370 | op2_array_index = 0; |
| 16269 | 17371 | op2_array_end = array_type->data.array.len; |
| 16270 | 17372 | |
| 16271 | 17373 | sentinel2 = array_type->data.array.sentinel; |
| 16272 | 17374 | } else { |
| 16273 | | ir_add_error(ira, op2, |
| 17375 | ir_add_error(ira, &op2->base, |
| 16274 | 17376 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); |
| 16275 | | return ira->codegen->invalid_instruction; |
| 17377 | return ira->codegen->invalid_inst_gen; |
| 16276 | 17378 | } |
| 16277 | 17379 | if (!op2_type_valid) { |
| 16278 | | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 17380 | ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'", |
| 16279 | 17381 | buf_ptr(&child_type->name), |
| 16280 | 17382 | buf_ptr(&op2->value->type->name))); |
| 16281 | | return ira->codegen->invalid_instruction; |
| 17383 | return ira->codegen->invalid_inst_gen; |
| 16282 | 17384 | } |
| 16283 | 17385 | |
| 16284 | 17386 | ZigValue *sentinel; |
| ... | ... | @@ -16295,7 +17397,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16295 | 17397 | } |
| 16296 | 17398 | |
| 16297 | 17399 | // The type of result is populated in the following if blocks |
| 16298 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 17400 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16299 | 17401 | ZigValue *out_val = result->value; |
| 16300 | 17402 | |
| 16301 | 17403 | ZigValue *out_array_val; |
| ... | ... | @@ -16383,14 +17485,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16383 | 17485 | return result; |
| 16384 | 17486 | } |
| 16385 | 17487 | |
| 16386 | | static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16387 | | IrInstruction *op1 = instruction->op1->child; |
| 17488 | static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 17489 | IrInstGen *op1 = instruction->op1->child; |
| 16388 | 17490 | if (type_is_invalid(op1->value->type)) |
| 16389 | | return ira->codegen->invalid_instruction; |
| 17491 | return ira->codegen->invalid_inst_gen; |
| 16390 | 17492 | |
| 16391 | | IrInstruction *op2 = instruction->op2->child; |
| 17493 | IrInstGen *op2 = instruction->op2->child; |
| 16392 | 17494 | if (type_is_invalid(op2->value->type)) |
| 16393 | | return ira->codegen->invalid_instruction; |
| 17495 | return ira->codegen->invalid_inst_gen; |
| 16394 | 17496 | |
| 16395 | 17497 | bool want_ptr_to_array = false; |
| 16396 | 17498 | ZigType *array_type; |
| ... | ... | @@ -16399,49 +17501,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 16399 | 17501 | array_type = op1->value->type; |
| 16400 | 17502 | array_val = ir_resolve_const(ira, op1, UndefOk); |
| 16401 | 17503 | if (array_val == nullptr) |
| 16402 | | return ira->codegen->invalid_instruction; |
| 17504 | return ira->codegen->invalid_inst_gen; |
| 16403 | 17505 | } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 16404 | 17506 | op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) |
| 16405 | 17507 | { |
| 16406 | 17508 | array_type = op1->value->type->data.pointer.child_type; |
| 16407 | | IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr); |
| 17509 | IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr); |
| 16408 | 17510 | if (type_is_invalid(array_inst->value->type)) |
| 16409 | | return ira->codegen->invalid_instruction; |
| 17511 | return ira->codegen->invalid_inst_gen; |
| 16410 | 17512 | array_val = ir_resolve_const(ira, array_inst, UndefOk); |
| 16411 | 17513 | if (array_val == nullptr) |
| 16412 | | return ira->codegen->invalid_instruction; |
| 17514 | return ira->codegen->invalid_inst_gen; |
| 16413 | 17515 | want_ptr_to_array = true; |
| 16414 | 17516 | } else { |
| 16415 | | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 16416 | | return ira->codegen->invalid_instruction; |
| 17517 | ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 17518 | return ira->codegen->invalid_inst_gen; |
| 16417 | 17519 | } |
| 16418 | 17520 | |
| 16419 | 17521 | uint64_t mult_amt; |
| 16420 | 17522 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 16421 | | return ira->codegen->invalid_instruction; |
| 17523 | return ira->codegen->invalid_inst_gen; |
| 16422 | 17524 | |
| 16423 | 17525 | uint64_t old_array_len = array_type->data.array.len; |
| 16424 | 17526 | uint64_t new_array_len; |
| 16425 | 17527 | |
| 16426 | 17528 | if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) { |
| 16427 | | ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow")); |
| 16428 | | return ira->codegen->invalid_instruction; |
| 17529 | ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow")); |
| 17530 | return ira->codegen->invalid_inst_gen; |
| 16429 | 17531 | } |
| 16430 | 17532 | |
| 16431 | 17533 | ZigType *child_type = array_type->data.array.child_type; |
| 16432 | 17534 | ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len, |
| 16433 | 17535 | array_type->data.array.sentinel); |
| 16434 | 17536 | |
| 16435 | | IrInstruction *array_result; |
| 17537 | IrInstGen *array_result; |
| 16436 | 17538 | if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 16437 | | array_result = ir_const_undef(ira, &instruction->base, result_array_type); |
| 17539 | array_result = ir_const_undef(ira, &instruction->base.base, result_array_type); |
| 16438 | 17540 | } else { |
| 16439 | | array_result = ir_const(ira, &instruction->base, result_array_type); |
| 17541 | array_result = ir_const(ira, &instruction->base.base, result_array_type); |
| 16440 | 17542 | ZigValue *out_val = array_result->value; |
| 16441 | 17543 | |
| 16442 | 17544 | switch (type_has_one_possible_value(ira->codegen, result_array_type)) { |
| 16443 | 17545 | case OnePossibleValueInvalid: |
| 16444 | | return ira->codegen->invalid_instruction; |
| 17546 | return ira->codegen->invalid_inst_gen; |
| 16445 | 17547 | case OnePossibleValueYes: |
| 16446 | 17548 | goto skip_computation; |
| 16447 | 17549 | case OnePossibleValueNo: |
| ... | ... | @@ -16477,35 +17579,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 16477 | 17579 | } |
| 16478 | 17580 | skip_computation: |
| 16479 | 17581 | if (want_ptr_to_array) { |
| 16480 | | return ir_get_ref(ira, &instruction->base, array_result, true, false); |
| 17582 | return ir_get_ref(ira, &instruction->base.base, array_result, true, false); |
| 16481 | 17583 | } else { |
| 16482 | 17584 | return array_result; |
| 16483 | 17585 | } |
| 16484 | 17586 | } |
| 16485 | 17587 | |
| 16486 | | static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 16487 | | IrInstructionMergeErrSets *instruction) |
| 17588 | static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 17589 | IrInstSrcMergeErrSets *instruction) |
| 16488 | 17590 | { |
| 16489 | | ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child); |
| 17591 | ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child); |
| 16490 | 17592 | if (type_is_invalid(op1_type)) |
| 16491 | | return ira->codegen->invalid_instruction; |
| 17593 | return ira->codegen->invalid_inst_gen; |
| 16492 | 17594 | |
| 16493 | | ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op2->child); |
| 17595 | ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child); |
| 16494 | 17596 | if (type_is_invalid(op2_type)) |
| 16495 | | return ira->codegen->invalid_instruction; |
| 17597 | return ira->codegen->invalid_inst_gen; |
| 16496 | 17598 | |
| 16497 | 17599 | if (type_is_global_error_set(op1_type) || |
| 16498 | 17600 | type_is_global_error_set(op2_type)) |
| 16499 | 17601 | { |
| 16500 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set); |
| 17602 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set); |
| 16501 | 17603 | } |
| 16502 | 17604 | |
| 16503 | | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) { |
| 16504 | | return ira->codegen->invalid_instruction; |
| 17605 | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) { |
| 17606 | return ira->codegen->invalid_inst_gen; |
| 16505 | 17607 | } |
| 16506 | 17608 | |
| 16507 | | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) { |
| 16508 | | return ira->codegen->invalid_instruction; |
| 17609 | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) { |
| 17610 | return ira->codegen->invalid_inst_gen; |
| 16509 | 17611 | } |
| 16510 | 17612 | |
| 16511 | 17613 | size_t errors_count = ira->codegen->errors_by_index.length; |
| ... | ... | @@ -16518,11 +17620,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 16518 | 17620 | ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name); |
| 16519 | 17621 | deallocate(errors, errors_count, "ErrorTableEntry *"); |
| 16520 | 17622 | |
| 16521 | | return ir_const_type(ira, &instruction->base, result_type); |
| 17623 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 16522 | 17624 | } |
| 16523 | 17625 | |
| 16524 | 17626 | |
| 16525 | | static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 17627 | static IrInstGen *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16526 | 17628 | IrBinOp op_id = bin_op_instruction->op_id; |
| 16527 | 17629 | switch (op_id) { |
| 16528 | 17630 | case IrBinOpInvalid: |
| ... | ... | @@ -16567,41 +17669,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio |
| 16567 | 17669 | zig_unreachable(); |
| 16568 | 17670 | } |
| 16569 | 17671 | |
| 16570 | | static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16571 | | IrInstructionDeclVarSrc *decl_var_instruction) |
| 16572 | | { |
| 17672 | static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) { |
| 16573 | 17673 | Error err; |
| 16574 | 17674 | ZigVar *var = decl_var_instruction->var; |
| 16575 | 17675 | |
| 16576 | 17676 | ZigType *explicit_type = nullptr; |
| 16577 | | IrInstruction *var_type = nullptr; |
| 17677 | IrInstGen *var_type = nullptr; |
| 16578 | 17678 | if (decl_var_instruction->var_type != nullptr) { |
| 16579 | 17679 | var_type = decl_var_instruction->var_type->child; |
| 16580 | 17680 | ZigType *proposed_type = ir_resolve_type(ira, var_type); |
| 16581 | | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 17681 | explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type); |
| 16582 | 17682 | if (type_is_invalid(explicit_type)) { |
| 16583 | 17683 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16584 | | return ira->codegen->invalid_instruction; |
| 17684 | return ira->codegen->invalid_inst_gen; |
| 16585 | 17685 | } |
| 16586 | 17686 | } |
| 16587 | 17687 | |
| 16588 | | AstNode *source_node = decl_var_instruction->base.source_node; |
| 17688 | AstNode *source_node = decl_var_instruction->base.base.source_node; |
| 16589 | 17689 | |
| 16590 | 17690 | bool is_comptime_var = ir_get_var_is_comptime(var); |
| 16591 | 17691 | |
| 16592 | 17692 | bool var_class_requires_const = false; |
| 16593 | 17693 | |
| 16594 | | IrInstruction *var_ptr = decl_var_instruction->ptr->child; |
| 17694 | IrInstGen *var_ptr = decl_var_instruction->ptr->child; |
| 16595 | 17695 | // if this is null, a compiler error happened and did not initialize the variable. |
| 16596 | 17696 | // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. |
| 16597 | 17697 | if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) { |
| 16598 | | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base); |
| 17698 | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base); |
| 16599 | 17699 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16600 | | return ira->codegen->invalid_instruction; |
| 17700 | return ira->codegen->invalid_inst_gen; |
| 16601 | 17701 | } |
| 16602 | 17702 | |
| 16603 | 17703 | // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. |
| 16604 | | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 17704 | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base); |
| 16605 | 17705 | |
| 16606 | 17706 | ZigType *result_type = var_ptr->value->type->data.pointer.child_type; |
| 16607 | 17707 | if (type_is_invalid(result_type)) { |
| ... | ... | @@ -16612,7 +17712,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16612 | 17712 | |
| 16613 | 17713 | ZigValue *init_val = nullptr; |
| 16614 | 17714 | if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 16615 | | init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node); |
| 17715 | init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.base.source_node); |
| 16616 | 17716 | if (is_comptime_var) { |
| 16617 | 17717 | if (var->gen_is_const) { |
| 16618 | 17718 | var->const_value = init_val; |
| ... | ... | @@ -16639,7 +17739,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16639 | 17739 | case ReqCompTimeNo: |
| 16640 | 17740 | if (init_val != nullptr && value_is_comptime(init_val)) { |
| 16641 | 17741 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 16642 | | decl_var_instruction->base.source_node, init_val, UndefOk))) |
| 17742 | decl_var_instruction->base.base.source_node, init_val, UndefOk))) |
| 16643 | 17743 | { |
| 16644 | 17744 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 16645 | 17745 | } else if (init_val->type->id == ZigTypeIdFn && |
| ... | ... | @@ -16660,42 +17760,27 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16660 | 17760 | break; |
| 16661 | 17761 | } |
| 16662 | 17762 | |
| 16663 | | if (var->var_type != nullptr && !is_comptime_var) { |
| 16664 | | // This is at least the second time we've seen this variable declaration during analysis. |
| 16665 | | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| 16666 | | // We make a new variable so that it can hold a different type, and so the debug info can |
| 16667 | | // be distinct. |
| 16668 | | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| 16669 | | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, |
| 16670 | | var->shadowable, var->is_comptime, true); |
| 16671 | | new_var->owner_exec = var->owner_exec; |
| 16672 | | new_var->align_bytes = var->align_bytes; |
| 16673 | | if (var->mem_slot_index != SIZE_MAX) { |
| 16674 | | ZigValue *vals = create_const_vals(1); |
| 16675 | | new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; |
| 16676 | | ira->exec_context.mem_slot_list.append(vals); |
| 16677 | | } |
| 16678 | | |
| 16679 | | var->next_var = new_var; |
| 16680 | | var = new_var; |
| 17763 | while (var->next_var != nullptr) { |
| 17764 | var = var->next_var; |
| 16681 | 17765 | } |
| 16682 | 17766 | |
| 16683 | 17767 | // This must be done after possibly creating a new variable above |
| 16684 | 17768 | var->ref_count = 0; |
| 16685 | 17769 | |
| 17770 | var->ptr_instruction = var_ptr; |
| 16686 | 17771 | var->var_type = result_type; |
| 16687 | 17772 | assert(var->var_type); |
| 16688 | 17773 | |
| 16689 | 17774 | if (type_is_invalid(result_type)) { |
| 16690 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 17775 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16691 | 17776 | } |
| 16692 | 17777 | |
| 16693 | 17778 | if (decl_var_instruction->align_value == nullptr) { |
| 16694 | 17779 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) { |
| 16695 | 17780 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16696 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 17781 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16697 | 17782 | } |
| 16698 | | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 17783 | var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type); |
| 16699 | 17784 | } else { |
| 16700 | 17785 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) { |
| 16701 | 17786 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -16712,104 +17797,96 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16712 | 17797 | // we need a runtime ptr but we have a comptime val. |
| 16713 | 17798 | // since it's a comptime val there are no instructions for it. |
| 16714 | 17799 | // we memcpy the init value here |
| 16715 | | IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); |
| 17800 | IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr); |
| 16716 | 17801 | if (type_is_invalid(deref->value->type)) { |
| 16717 | 17802 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16718 | | return ira->codegen->invalid_instruction; |
| 17803 | return ira->codegen->invalid_inst_gen; |
| 16719 | 17804 | } |
| 16720 | 17805 | // If this assertion trips, something is wrong with the IR instructions, because |
| 16721 | 17806 | // we expected the above deref to return a constant value, but it created a runtime |
| 16722 | 17807 | // instruction. |
| 16723 | 17808 | assert(deref->value->special != ConstValSpecialRuntime); |
| 16724 | 17809 | var_ptr->value->special = ConstValSpecialRuntime; |
| 16725 | | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 17810 | ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false); |
| 16726 | 17811 | } |
| 16727 | | |
| 16728 | | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { |
| 16729 | | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); |
| 16730 | | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); |
| 16731 | | copy_const_val(mem_slot, init_val); |
| 16732 | | ira_ref(var->owner_exec->analysis); |
| 16733 | | |
| 16734 | | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| 16735 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 16736 | | } |
| 17812 | if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) { |
| 17813 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16737 | 17814 | } |
| 16738 | 17815 | } else if (is_comptime_var) { |
| 16739 | | ir_add_error(ira, &decl_var_instruction->base, |
| 17816 | ir_add_error(ira, &decl_var_instruction->base.base, |
| 16740 | 17817 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 16741 | 17818 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16742 | | return ira->codegen->invalid_instruction; |
| 17819 | return ira->codegen->invalid_inst_gen; |
| 16743 | 17820 | } |
| 16744 | 17821 | |
| 16745 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 17822 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 16746 | 17823 | if (fn_entry) |
| 16747 | 17824 | fn_entry->variable_list.append(var); |
| 16748 | 17825 | |
| 16749 | | return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr); |
| 17826 | return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr); |
| 16750 | 17827 | } |
| 16751 | 17828 | |
| 16752 | | static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { |
| 16753 | | IrInstruction *target = instruction->target->child; |
| 17829 | static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) { |
| 17830 | IrInstGen *target = instruction->target->child; |
| 16754 | 17831 | if (type_is_invalid(target->value->type)) |
| 16755 | | return ira->codegen->invalid_instruction; |
| 17832 | return ira->codegen->invalid_inst_gen; |
| 16756 | 17833 | |
| 16757 | | IrInstruction *options = instruction->options->child; |
| 17834 | IrInstGen *options = instruction->options->child; |
| 16758 | 17835 | if (type_is_invalid(options->value->type)) |
| 16759 | | return ira->codegen->invalid_instruction; |
| 17836 | return ira->codegen->invalid_inst_gen; |
| 16760 | 17837 | |
| 16761 | 17838 | ZigType *options_type = options->value->type; |
| 16762 | 17839 | assert(options_type->id == ZigTypeIdStruct); |
| 16763 | 17840 | |
| 16764 | 17841 | TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name")); |
| 16765 | | ir_assert(name_field != nullptr, &instruction->base); |
| 16766 | | IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field); |
| 17842 | ir_assert(name_field != nullptr, &instruction->base.base); |
| 17843 | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field); |
| 16767 | 17844 | if (type_is_invalid(name_inst->value->type)) |
| 16768 | | return ira->codegen->invalid_instruction; |
| 17845 | return ira->codegen->invalid_inst_gen; |
| 16769 | 17846 | |
| 16770 | 17847 | TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage")); |
| 16771 | | ir_assert(linkage_field != nullptr, &instruction->base); |
| 16772 | | IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field); |
| 17848 | ir_assert(linkage_field != nullptr, &instruction->base.base); |
| 17849 | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field); |
| 16773 | 17850 | if (type_is_invalid(linkage_inst->value->type)) |
| 16774 | | return ira->codegen->invalid_instruction; |
| 17851 | return ira->codegen->invalid_inst_gen; |
| 16775 | 17852 | |
| 16776 | 17853 | TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section")); |
| 16777 | | ir_assert(section_field != nullptr, &instruction->base); |
| 16778 | | IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field); |
| 17854 | ir_assert(section_field != nullptr, &instruction->base.base); |
| 17855 | IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field); |
| 16779 | 17856 | if (type_is_invalid(section_inst->value->type)) |
| 16780 | | return ira->codegen->invalid_instruction; |
| 17857 | return ira->codegen->invalid_inst_gen; |
| 16781 | 17858 | |
| 16782 | 17859 | // The `section` field is optional, we have to unwrap it first |
| 16783 | | IrInstruction *non_null_check = ir_analyze_test_non_null(ira, &instruction->base, section_inst); |
| 17860 | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst); |
| 16784 | 17861 | bool is_non_null; |
| 16785 | 17862 | if (!ir_resolve_bool(ira, non_null_check, &is_non_null)) |
| 16786 | | return ira->codegen->invalid_instruction; |
| 17863 | return ira->codegen->invalid_inst_gen; |
| 16787 | 17864 | |
| 16788 | | IrInstruction *section_str_inst = nullptr; |
| 17865 | IrInstGen *section_str_inst = nullptr; |
| 16789 | 17866 | if (is_non_null) { |
| 16790 | | section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false); |
| 17867 | section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false); |
| 16791 | 17868 | if (type_is_invalid(section_str_inst->value->type)) |
| 16792 | | return ira->codegen->invalid_instruction; |
| 17869 | return ira->codegen->invalid_inst_gen; |
| 16793 | 17870 | } |
| 16794 | 17871 | |
| 16795 | 17872 | // Resolve all the comptime values |
| 16796 | 17873 | Buf *symbol_name = ir_resolve_str(ira, name_inst); |
| 16797 | 17874 | if (!symbol_name) |
| 16798 | | return ira->codegen->invalid_instruction; |
| 17875 | return ira->codegen->invalid_inst_gen; |
| 16799 | 17876 | |
| 16800 | 17877 | if (buf_len(symbol_name) < 1) { |
| 16801 | | ir_add_error(ira, name_inst, |
| 17878 | ir_add_error(ira, &name_inst->base, |
| 16802 | 17879 | buf_sprintf("exported symbol name cannot be empty")); |
| 16803 | | return ira->codegen->invalid_instruction; |
| 17880 | return ira->codegen->invalid_inst_gen; |
| 16804 | 17881 | } |
| 16805 | 17882 | |
| 16806 | 17883 | GlobalLinkageId global_linkage_id; |
| 16807 | 17884 | if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id)) |
| 16808 | | return ira->codegen->invalid_instruction; |
| 17885 | return ira->codegen->invalid_inst_gen; |
| 16809 | 17886 | |
| 16810 | 17887 | Buf *section_name = nullptr; |
| 16811 | 17888 | if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst))) |
| 16812 | | return ira->codegen->invalid_instruction; |
| 17889 | return ira->codegen->invalid_inst_gen; |
| 16813 | 17890 | |
| 16814 | 17891 | // TODO: This function needs to be audited. |
| 16815 | 17892 | // It's not clear how all the different types are supposed to be handled. |
| ... | ... | @@ -16817,15 +17894,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16817 | 17894 | // in another file. |
| 16818 | 17895 | TldFn *tld_fn = allocate<TldFn>(1); |
| 16819 | 17896 | tld_fn->base.id = TldIdFn; |
| 16820 | | tld_fn->base.source_node = instruction->base.source_node; |
| 17897 | tld_fn->base.source_node = instruction->base.base.source_node; |
| 16821 | 17898 | |
| 16822 | 17899 | auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base); |
| 16823 | 17900 | if (entry) { |
| 16824 | 17901 | AstNode *other_export_node = entry->value->source_node; |
| 16825 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 17902 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 16826 | 17903 | buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name))); |
| 16827 | 17904 | add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here")); |
| 16828 | | return ira->codegen->invalid_instruction; |
| 17905 | return ira->codegen->invalid_inst_gen; |
| 16829 | 17906 | } |
| 16830 | 17907 | |
| 16831 | 17908 | Error err; |
| ... | ... | @@ -16841,12 +17918,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16841 | 17918 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 16842 | 17919 | switch (cc) { |
| 16843 | 17920 | case CallingConventionUnspecified: { |
| 16844 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17921 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16845 | 17922 | buf_sprintf("exported function must specify calling convention")); |
| 16846 | 17923 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 16847 | 17924 | } break; |
| 16848 | 17925 | case CallingConventionAsync: { |
| 16849 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17926 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16850 | 17927 | buf_sprintf("exported function cannot be async")); |
| 16851 | 17928 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 16852 | 17929 | } break; |
| ... | ... | @@ -16869,10 +17946,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16869 | 17946 | } break; |
| 16870 | 17947 | case ZigTypeIdStruct: |
| 16871 | 17948 | if (is_slice(target->value->type)) { |
| 16872 | | ir_add_error(ira, target, |
| 17949 | ir_add_error(ira, &target->base, |
| 16873 | 17950 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); |
| 16874 | 17951 | } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { |
| 16875 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17952 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16876 | 17953 | buf_sprintf("exported struct value must be declared extern")); |
| 16877 | 17954 | add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); |
| 16878 | 17955 | } else { |
| ... | ... | @@ -16881,7 +17958,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16881 | 17958 | break; |
| 16882 | 17959 | case ZigTypeIdUnion: |
| 16883 | 17960 | if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { |
| 16884 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17961 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16885 | 17962 | buf_sprintf("exported union value must be declared extern")); |
| 16886 | 17963 | add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 16887 | 17964 | } else { |
| ... | ... | @@ -16890,7 +17967,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16890 | 17967 | break; |
| 16891 | 17968 | case ZigTypeIdEnum: |
| 16892 | 17969 | if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { |
| 16893 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17970 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16894 | 17971 | buf_sprintf("exported enum value must be declared extern")); |
| 16895 | 17972 | add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 16896 | 17973 | } else { |
| ... | ... | @@ -16900,10 +17977,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16900 | 17977 | case ZigTypeIdArray: { |
| 16901 | 17978 | bool ok_type; |
| 16902 | 17979 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) |
| 16903 | | return ira->codegen->invalid_instruction; |
| 17980 | return ira->codegen->invalid_inst_gen; |
| 16904 | 17981 | |
| 16905 | 17982 | if (!ok_type) { |
| 16906 | | ir_add_error(ira, target, |
| 17983 | ir_add_error(ira, &target->base, |
| 16907 | 17984 | buf_sprintf("array element type '%s' not extern-compatible", |
| 16908 | 17985 | buf_ptr(&target->value->type->data.array.child_type->name))); |
| 16909 | 17986 | } else { |
| ... | ... | @@ -16918,31 +17995,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16918 | 17995 | zig_unreachable(); |
| 16919 | 17996 | case ZigTypeIdStruct: |
| 16920 | 17997 | if (is_slice(type_value)) { |
| 16921 | | ir_add_error(ira, target, |
| 17998 | ir_add_error(ira, &target->base, |
| 16922 | 17999 | buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); |
| 16923 | 18000 | } else if (type_value->data.structure.layout != ContainerLayoutExtern) { |
| 16924 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 18001 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16925 | 18002 | buf_sprintf("exported struct must be declared extern")); |
| 16926 | 18003 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); |
| 16927 | 18004 | } |
| 16928 | 18005 | break; |
| 16929 | 18006 | case ZigTypeIdUnion: |
| 16930 | 18007 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { |
| 16931 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 18008 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16932 | 18009 | buf_sprintf("exported union must be declared extern")); |
| 16933 | 18010 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); |
| 16934 | 18011 | } |
| 16935 | 18012 | break; |
| 16936 | 18013 | case ZigTypeIdEnum: |
| 16937 | 18014 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { |
| 16938 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 18015 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16939 | 18016 | buf_sprintf("exported enum must be declared extern")); |
| 16940 | 18017 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 16941 | 18018 | } |
| 16942 | 18019 | break; |
| 16943 | 18020 | case ZigTypeIdFn: { |
| 16944 | 18021 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 16945 | | ir_add_error(ira, target, |
| 18022 | ir_add_error(ira, &target->base, |
| 16946 | 18023 | buf_sprintf("exported function type must specify calling convention")); |
| 16947 | 18024 | } |
| 16948 | 18025 | } break; |
| ... | ... | @@ -16968,7 +18045,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16968 | 18045 | case ZigTypeIdOpaque: |
| 16969 | 18046 | case ZigTypeIdFnFrame: |
| 16970 | 18047 | case ZigTypeIdAnyFrame: |
| 16971 | | ir_add_error(ira, target, |
| 18048 | ir_add_error(ira, &target->base, |
| 16972 | 18049 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); |
| 16973 | 18050 | break; |
| 16974 | 18051 | } |
| ... | ... | @@ -16993,61 +18070,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16993 | 18070 | case ZigTypeIdEnumLiteral: |
| 16994 | 18071 | case ZigTypeIdFnFrame: |
| 16995 | 18072 | case ZigTypeIdAnyFrame: |
| 16996 | | ir_add_error(ira, target, |
| 18073 | ir_add_error(ira, &target->base, |
| 16997 | 18074 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); |
| 16998 | 18075 | break; |
| 16999 | 18076 | } |
| 17000 | 18077 | |
| 17001 | 18078 | // TODO audit the various ways to use @export |
| 17002 | | if (want_var_export && target->id == IrInstructionIdLoadPtrGen) { |
| 17003 | | IrInstructionLoadPtrGen *load_ptr = reinterpret_cast<IrInstructionLoadPtrGen *>(target); |
| 17004 | | if (load_ptr->ptr->id == IrInstructionIdVarPtr) { |
| 17005 | | IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr); |
| 18079 | if (want_var_export && target->id == IrInstGenIdLoadPtr) { |
| 18080 | IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target); |
| 18081 | if (load_ptr->ptr->id == IrInstGenIdVarPtr) { |
| 18082 | IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr); |
| 17006 | 18083 | ZigVar *var = var_ptr->var; |
| 17007 | 18084 | add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id); |
| 17008 | 18085 | var->section_name = section_name; |
| 17009 | 18086 | } |
| 17010 | 18087 | } |
| 17011 | 18088 | |
| 17012 | | return ir_const_void(ira, &instruction->base); |
| 18089 | return ir_const_void(ira, &instruction->base.base); |
| 17013 | 18090 | } |
| 17014 | 18091 | |
| 17015 | | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { |
| 18092 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) { |
| 17016 | 18093 | ZigFn *fn_entry = exec_fn_entry(exec); |
| 17017 | 18094 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 17018 | 18095 | } |
| 17019 | 18096 | |
| 17020 | | static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 17021 | | IrInstructionErrorReturnTrace *instruction) |
| 18097 | static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 18098 | IrInstSrcErrorReturnTrace *instruction) |
| 17022 | 18099 | { |
| 17023 | 18100 | ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false); |
| 17024 | | if (instruction->optional == IrInstructionErrorReturnTrace::Null) { |
| 18101 | if (instruction->optional == IrInstErrorReturnTraceNull) { |
| 17025 | 18102 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 17026 | | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 17027 | | IrInstruction *result = ir_const(ira, &instruction->base, optional_type); |
| 18103 | if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) { |
| 18104 | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); |
| 17028 | 18105 | ZigValue *out_val = result->value; |
| 17029 | 18106 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| 17030 | 18107 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 17031 | 18108 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| 17032 | 18109 | return result; |
| 17033 | 18110 | } |
| 17034 | | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 17035 | | instruction->base.source_node, instruction->optional); |
| 17036 | | new_instruction->value->type = optional_type; |
| 17037 | | return new_instruction; |
| 18111 | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 18112 | instruction->base.base.source_node, instruction->optional, optional_type); |
| 17038 | 18113 | } else { |
| 17039 | 18114 | assert(ira->codegen->have_err_ret_tracing); |
| 17040 | | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 17041 | | instruction->base.source_node, instruction->optional); |
| 17042 | | new_instruction->value->type = ptr_to_stack_trace_type; |
| 17043 | | return new_instruction; |
| 18115 | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 18116 | instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type); |
| 17044 | 18117 | } |
| 17045 | 18118 | } |
| 17046 | 18119 | |
| 17047 | | static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 17048 | | IrInstructionErrorUnion *instruction) |
| 17049 | | { |
| 17050 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 18120 | static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) { |
| 18121 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 17051 | 18122 | result->value->special = ConstValSpecialLazy; |
| 17052 | 18123 | |
| 17053 | 18124 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType"); |
| ... | ... | @@ -17057,24 +18128,25 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 17057 | 18128 | |
| 17058 | 18129 | lazy_err_union_type->err_set_type = instruction->err_set->child; |
| 17059 | 18130 | if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr) |
| 17060 | | return ira->codegen->invalid_instruction; |
| 18131 | return ira->codegen->invalid_inst_gen; |
| 17061 | 18132 | |
| 17062 | 18133 | lazy_err_union_type->payload_type = instruction->payload->child; |
| 17063 | 18134 | if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr) |
| 17064 | | return ira->codegen->invalid_instruction; |
| 18135 | return ira->codegen->invalid_inst_gen; |
| 17065 | 18136 | |
| 17066 | 18137 | return result; |
| 17067 | 18138 | } |
| 17068 | 18139 | |
| 17069 | | static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type, |
| 18140 | static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type, |
| 17070 | 18141 | uint32_t align, const char *name_hint, bool force_comptime) |
| 17071 | 18142 | { |
| 17072 | 18143 | Error err; |
| 17073 | 18144 | |
| 17074 | 18145 | ZigValue *pointee = create_const_vals(1); |
| 17075 | 18146 | pointee->special = ConstValSpecialUndef; |
| 18147 | pointee->llvm_align = align; |
| 17076 | 18148 | |
| 17077 | | IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 18149 | IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 17078 | 18150 | result->base.value->special = ConstValSpecialStatic; |
| 17079 | 18151 | result->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 17080 | 18152 | result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| ... | ... | @@ -17082,15 +18154,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17082 | 18154 | |
| 17083 | 18155 | bool var_type_has_bits; |
| 17084 | 18156 | if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits))) |
| 17085 | | return ira->codegen->invalid_instruction; |
| 18157 | return ira->codegen->invalid_inst_gen; |
| 17086 | 18158 | if (align != 0) { |
| 17087 | 18159 | if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown))) |
| 17088 | | return ira->codegen->invalid_instruction; |
| 18160 | return ira->codegen->invalid_inst_gen; |
| 17089 | 18161 | if (!var_type_has_bits) { |
| 17090 | 18162 | ir_add_error(ira, source_inst, |
| 17091 | 18163 | buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned", |
| 17092 | 18164 | name_hint, buf_ptr(&var_type->name))); |
| 17093 | | return ira->codegen->invalid_instruction; |
| 18165 | return ira->codegen->invalid_inst_gen; |
| 17094 | 18166 | } |
| 17095 | 18167 | } |
| 17096 | 18168 | assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid); |
| ... | ... | @@ -17099,15 +18171,16 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17099 | 18171 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 17100 | 18172 | PtrLenSingle, align, 0, 0, false); |
| 17101 | 18173 | |
| 17102 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 17103 | | if (fn_entry != nullptr) { |
| 17104 | | fn_entry->alloca_gen_list.append(result); |
| 18174 | if (!force_comptime) { |
| 18175 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 18176 | if (fn_entry != nullptr) { |
| 18177 | fn_entry->alloca_gen_list.append(result); |
| 18178 | } |
| 17105 | 18179 | } |
| 17106 | | result->base.is_gen = true; |
| 17107 | 18180 | return &result->base; |
| 17108 | 18181 | } |
| 17109 | 18182 | |
| 17110 | | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 18183 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 17111 | 18184 | ResultLoc *result_loc) |
| 17112 | 18185 | { |
| 17113 | 18186 | switch (result_loc->id) { |
| ... | ... | @@ -17150,7 +18223,7 @@ static bool type_can_bit_cast(ZigType *t) { |
| 17150 | 18223 | } |
| 17151 | 18224 | } |
| 17152 | 18225 | |
| 17153 | | static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { |
| 18226 | static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) { |
| 17154 | 18227 | ZigValue *undef_child = create_const_vals(1); |
| 17155 | 18228 | undef_child->type = ptr->value->type->data.pointer.child_type; |
| 17156 | 18229 | undef_child->special = ConstValSpecialUndef; |
| ... | ... | @@ -17189,16 +18262,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 17189 | 18262 | zig_unreachable(); |
| 17190 | 18263 | } |
| 17191 | 18264 | |
| 17192 | | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17193 | | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) |
| 18265 | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18266 | ResultLoc *result_loc, ZigType *value_type) |
| 17194 | 18267 | { |
| 17195 | 18268 | if (type_is_invalid(value_type)) |
| 17196 | | return ira->codegen->invalid_instruction; |
| 17197 | | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 18269 | return ira->codegen->invalid_inst_gen; |
| 18270 | IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 17198 | 18271 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 17199 | 18272 | PtrLenSingle, 0, 0, 0, false); |
| 17200 | 18273 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); |
| 17201 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 18274 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 17202 | 18275 | if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) { |
| 17203 | 18276 | fn_entry->alloca_gen_list.append(alloca_gen); |
| 17204 | 18277 | } |
| ... | ... | @@ -17207,10 +18280,25 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su |
| 17207 | 18280 | return result_loc->resolved_loc; |
| 17208 | 18281 | } |
| 17209 | 18282 | |
| 18283 | static bool result_loc_is_discard(ResultLoc *result_loc_pass1) { |
| 18284 | if (result_loc_pass1->id == ResultLocIdInstruction && |
| 18285 | result_loc_pass1->source_instruction->id == IrInstSrcIdConst) |
| 18286 | { |
| 18287 | IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction); |
| 18288 | if (value_is_comptime(const_inst->value) && |
| 18289 | const_inst->value->type->id == ZigTypeIdPointer && |
| 18290 | const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| 18291 | { |
| 18292 | return true; |
| 18293 | } |
| 18294 | } |
| 18295 | return false; |
| 18296 | } |
| 18297 | |
| 17210 | 18298 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 17211 | | static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17212 | | ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 17213 | | bool non_null_comptime, bool allow_discard) |
| 18299 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18300 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 18301 | bool allow_discard) |
| 17214 | 18302 | { |
| 17215 | 18303 | Error err; |
| 17216 | 18304 | if (result_loc->resolved_loc != nullptr) { |
| ... | ... | @@ -17230,54 +18318,56 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17230 | 18318 | return nullptr; |
| 17231 | 18319 | } |
| 17232 | 18320 | // need to return a result location and don't have one. use a stack allocation |
| 17233 | | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 17234 | | force_runtime, non_null_comptime); |
| 18321 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17235 | 18322 | } |
| 17236 | 18323 | case ResultLocIdVar: { |
| 17237 | 18324 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 17238 | | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); |
| 17239 | | |
| 18325 | assert(result_loc->source_instruction->id == IrInstSrcIdAlloca); |
| 18326 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); |
| 18327 | |
| 18328 | ZigVar *var = result_loc_var->var; |
| 18329 | if (var->var_type != nullptr && !ir_get_var_is_comptime(var)) { |
| 18330 | // This is at least the second time we've seen this variable declaration during analysis. |
| 18331 | // This means that this is actually a different variable due to, e.g. an inline while loop. |
| 18332 | // We make a new variable so that it can hold a different type, and so the debug info can |
| 18333 | // be distinct. |
| 18334 | ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, |
| 18335 | buf_create_from_str(var->name), var->src_is_const, var->gen_is_const, |
| 18336 | var->shadowable, var->is_comptime, true); |
| 18337 | new_var->owner_exec = var->owner_exec; |
| 18338 | new_var->align_bytes = var->align_bytes; |
| 18339 | |
| 18340 | var->next_var = new_var; |
| 18341 | var = new_var; |
| 18342 | } |
| 17240 | 18343 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { |
| 17241 | | ir_add_error(ira, result_loc->source_instruction, |
| 18344 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17242 | 18345 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); |
| 17243 | | return ira->codegen->invalid_instruction; |
| 18346 | return ira->codegen->invalid_inst_gen; |
| 17244 | 18347 | } |
| 17245 | | |
| 17246 | | IrInstructionAllocaSrc *alloca_src = |
| 17247 | | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| 17248 | | bool force_comptime; |
| 17249 | | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 17250 | | return ira->codegen->invalid_instruction; |
| 17251 | | bool is_comptime = force_comptime || (!force_runtime && value != nullptr && |
| 17252 | | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 17253 | | |
| 17254 | | if (alloca_src->base.child == nullptr || is_comptime) { |
| 18348 | if (alloca_src->base.child == nullptr || var->ptr_instruction == nullptr) { |
| 18349 | bool force_comptime; |
| 18350 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 18351 | return ira->codegen->invalid_inst_gen; |
| 17255 | 18352 | uint32_t align = 0; |
| 17256 | 18353 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 17257 | | return ira->codegen->invalid_instruction; |
| 18354 | return ira->codegen->invalid_inst_gen; |
| 17258 | 18355 | } |
| 17259 | | IrInstruction *alloca_gen; |
| 17260 | | if (is_comptime && value != nullptr) { |
| 17261 | | if (align > value->value->llvm_align) { |
| 17262 | | value->value->llvm_align = align; |
| 17263 | | } |
| 17264 | | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 17265 | | } else { |
| 17266 | | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, |
| 17267 | | alloca_src->name_hint, force_comptime); |
| 17268 | | if (force_runtime) { |
| 17269 | | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 17270 | | alloca_gen->value->special = ConstValSpecialRuntime; |
| 17271 | | } |
| 18356 | IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, |
| 18357 | align, alloca_src->name_hint, force_comptime); |
| 18358 | if (force_runtime) { |
| 18359 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 18360 | alloca_gen->value->special = ConstValSpecialRuntime; |
| 17272 | 18361 | } |
| 17273 | 18362 | if (alloca_src->base.child != nullptr && !result_loc->written) { |
| 17274 | | alloca_src->base.child->ref_count = 0; |
| 18363 | alloca_src->base.child->base.ref_count = 0; |
| 17275 | 18364 | } |
| 17276 | 18365 | alloca_src->base.child = alloca_gen; |
| 18366 | var->ptr_instruction = alloca_gen; |
| 17277 | 18367 | } |
| 17278 | 18368 | result_loc->written = true; |
| 17279 | | result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child; |
| 17280 | | return result_loc->resolved_loc; |
| 18369 | result_loc->resolved_loc = alloca_src->base.child; |
| 18370 | return alloca_src->base.child; |
| 17281 | 18371 | } |
| 17282 | 18372 | case ResultLocIdInstruction: { |
| 17283 | 18373 | result_loc->written = true; |
| ... | ... | @@ -17289,27 +18379,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17289 | 18379 | reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true; |
| 17290 | 18380 | ira->src_implicit_return_type_list.append(value); |
| 17291 | 18381 | } |
| 17292 | | if (!non_null_comptime) { |
| 17293 | | bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; |
| 17294 | | if (is_comptime) |
| 17295 | | return nullptr; |
| 17296 | | } |
| 17297 | | bool has_bits; |
| 17298 | | if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits))) |
| 17299 | | return ira->codegen->invalid_instruction; |
| 17300 | | if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) { |
| 17301 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 17302 | | if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) { |
| 17303 | | return nullptr; |
| 17304 | | } |
| 17305 | | } |
| 17306 | | |
| 17307 | | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); |
| 17308 | 18382 | result_loc->written = true; |
| 17309 | | result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type); |
| 17310 | | if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) { |
| 17311 | | set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc); |
| 17312 | | } |
| 18383 | result_loc->resolved_loc = ira->return_ptr; |
| 17313 | 18384 | return result_loc->resolved_loc; |
| 17314 | 18385 | } |
| 17315 | 18386 | case ResultLocIdPeer: { |
| ... | ... | @@ -17317,8 +18388,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17317 | 18388 | ResultLocPeerParent *peer_parent = result_peer->parent; |
| 17318 | 18389 | |
| 17319 | 18390 | if (peer_parent->peers.length == 1) { |
| 17320 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17321 | | value_type, value, force_runtime, non_null_comptime, true); |
| 18391 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18392 | value_type, value, force_runtime, true); |
| 17322 | 18393 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 17323 | 18394 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 17324 | 18395 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| ... | ... | @@ -17333,22 +18404,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17333 | 18404 | |
| 17334 | 18405 | bool is_condition_comptime; |
| 17335 | 18406 | if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime)) |
| 17336 | | return ira->codegen->invalid_instruction; |
| 18407 | return ira->codegen->invalid_inst_gen; |
| 17337 | 18408 | if (is_condition_comptime) { |
| 17338 | 18409 | peer_parent->skipped = true; |
| 17339 | | if (non_null_comptime) { |
| 17340 | | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17341 | | value_type, value, force_runtime, non_null_comptime, true); |
| 17342 | | } |
| 17343 | | return nullptr; |
| 18410 | return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18411 | value_type, value, force_runtime, true); |
| 17344 | 18412 | } |
| 17345 | 18413 | bool peer_parent_has_type; |
| 17346 | 18414 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| 17347 | | return ira->codegen->invalid_instruction; |
| 18415 | return ira->codegen->invalid_inst_gen; |
| 17348 | 18416 | if (peer_parent_has_type) { |
| 17349 | 18417 | peer_parent->skipped = true; |
| 17350 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17351 | | value_type, value, force_runtime || !is_condition_comptime, true, true); |
| 18418 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18419 | value_type, value, force_runtime || !is_condition_comptime, true); |
| 17352 | 18420 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17353 | 18421 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17354 | 18422 | { |
| ... | ... | @@ -17364,7 +18432,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17364 | 18432 | if (peer_parent->end_bb->suspend_instruction_ref == nullptr) { |
| 17365 | 18433 | peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr; |
| 17366 | 18434 | } |
| 17367 | | IrInstruction *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb, |
| 18435 | IrInstGen *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb, |
| 17368 | 18436 | &result_peer->suspend_pos); |
| 17369 | 18437 | if (result_peer->next_bb == nullptr) { |
| 17370 | 18438 | ir_start_next_bb(ira); |
| ... | ... | @@ -17372,8 +18440,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17372 | 18440 | return unreach_inst; |
| 17373 | 18441 | } |
| 17374 | 18442 | |
| 17375 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17376 | | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); |
| 18443 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18444 | peer_parent->resolved_type, nullptr, force_runtime, true); |
| 17377 | 18445 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17378 | 18446 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17379 | 18447 | { |
| ... | ... | @@ -17386,30 +18454,27 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17386 | 18454 | return result_loc->resolved_loc; |
| 17387 | 18455 | } |
| 17388 | 18456 | case ResultLocIdCast: { |
| 17389 | | if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime) |
| 17390 | | return nullptr; |
| 17391 | 18457 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 17392 | 18458 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| 17393 | 18459 | if (type_is_invalid(dest_type)) |
| 17394 | | return ira->codegen->invalid_instruction; |
| 18460 | return ira->codegen->invalid_inst_gen; |
| 17395 | 18461 | |
| 17396 | 18462 | if (dest_type == ira->codegen->builtin_types.entry_var) { |
| 17397 | | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 17398 | | force_runtime, non_null_comptime); |
| 18463 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17399 | 18464 | } |
| 17400 | 18465 | |
| 17401 | | IrInstruction *casted_value; |
| 18466 | IrInstGen *casted_value; |
| 17402 | 18467 | if (value != nullptr) { |
| 17403 | | casted_value = ir_implicit_cast(ira, value, dest_type); |
| 18468 | casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type); |
| 17404 | 18469 | if (type_is_invalid(casted_value->value->type)) |
| 17405 | | return ira->codegen->invalid_instruction; |
| 18470 | return ira->codegen->invalid_inst_gen; |
| 17406 | 18471 | dest_type = casted_value->value->type; |
| 17407 | 18472 | } else { |
| 17408 | 18473 | casted_value = nullptr; |
| 17409 | 18474 | } |
| 17410 | 18475 | |
| 17411 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 17412 | | dest_type, casted_value, force_runtime, non_null_comptime, true); |
| 18476 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 18477 | dest_type, casted_value, force_runtime, true); |
| 17413 | 18478 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17414 | 18479 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17415 | 18480 | { |
| ... | ... | @@ -17422,11 +18487,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17422 | 18487 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 17423 | 18488 | ResolveStatusAlignmentKnown))) |
| 17424 | 18489 | { |
| 17425 | | return ira->codegen->invalid_instruction; |
| 18490 | return ira->codegen->invalid_inst_gen; |
| 17426 | 18491 | } |
| 17427 | 18492 | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 17428 | 18493 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { |
| 17429 | | return ira->codegen->invalid_instruction; |
| 18494 | return ira->codegen->invalid_inst_gen; |
| 17430 | 18495 | } |
| 17431 | 18496 | if (!type_has_bits(value_type)) { |
| 17432 | 18497 | parent_ptr_align = 0; |
| ... | ... | @@ -17449,9 +18514,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17449 | 18514 | |
| 17450 | 18515 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 17451 | 18516 | parent_result_loc->value->type, ptr_type, |
| 17452 | | result_cast->base.source_instruction->source_node, false); |
| 18517 | result_cast->base.source_instruction->base.source_node, false); |
| 17453 | 18518 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 17454 | | return ira->codegen->invalid_instruction; |
| 18519 | return ira->codegen->invalid_inst_gen; |
| 17455 | 18520 | if (const_cast_result.id != ConstCastResultIdOk) { |
| 17456 | 18521 | if (allow_discard) { |
| 17457 | 18522 | return parent_result_loc; |
| ... | ... | @@ -17459,59 +18524,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17459 | 18524 | // We will not be able to provide a result location for this value. Create |
| 17460 | 18525 | // a new result location. |
| 17461 | 18526 | result_cast->parent->written = false; |
| 17462 | | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 17463 | | force_runtime, non_null_comptime); |
| 18527 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 17464 | 18528 | } |
| 17465 | 18529 | |
| 17466 | 18530 | result_loc->written = true; |
| 17467 | 18531 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 17468 | | ptr_type, result_cast->base.source_instruction, false); |
| 18532 | &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false); |
| 17469 | 18533 | return result_loc->resolved_loc; |
| 17470 | 18534 | } |
| 17471 | 18535 | case ResultLocIdBitCast: { |
| 17472 | 18536 | ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc); |
| 17473 | 18537 | ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child); |
| 17474 | 18538 | if (type_is_invalid(dest_type)) |
| 17475 | | return ira->codegen->invalid_instruction; |
| 18539 | return ira->codegen->invalid_inst_gen; |
| 17476 | 18540 | |
| 17477 | 18541 | if (get_codegen_ptr_type(dest_type) != nullptr) { |
| 17478 | | ir_add_error(ira, result_loc->source_instruction, |
| 18542 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17479 | 18543 | buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name))); |
| 17480 | | return ira->codegen->invalid_instruction; |
| 18544 | return ira->codegen->invalid_inst_gen; |
| 17481 | 18545 | } |
| 17482 | 18546 | |
| 17483 | 18547 | if (!type_can_bit_cast(dest_type)) { |
| 17484 | | ir_add_error(ira, result_loc->source_instruction, |
| 18548 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17485 | 18549 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 17486 | | return ira->codegen->invalid_instruction; |
| 18550 | return ira->codegen->invalid_inst_gen; |
| 17487 | 18551 | } |
| 17488 | 18552 | |
| 17489 | 18553 | if (get_codegen_ptr_type(value_type) != nullptr) { |
| 17490 | 18554 | ir_add_error(ira, suspend_source_instr, |
| 17491 | 18555 | buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name))); |
| 17492 | | return ira->codegen->invalid_instruction; |
| 18556 | return ira->codegen->invalid_inst_gen; |
| 17493 | 18557 | } |
| 17494 | 18558 | |
| 17495 | 18559 | if (!type_can_bit_cast(value_type)) { |
| 17496 | 18560 | ir_add_error(ira, suspend_source_instr, |
| 17497 | 18561 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name))); |
| 17498 | | return ira->codegen->invalid_instruction; |
| 18562 | return ira->codegen->invalid_inst_gen; |
| 17499 | 18563 | } |
| 17500 | 18564 | |
| 17501 | | IrInstruction *bitcasted_value; |
| 18565 | IrInstGen *bitcasted_value; |
| 17502 | 18566 | if (value != nullptr) { |
| 17503 | | bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type); |
| 18567 | bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type); |
| 17504 | 18568 | dest_type = bitcasted_value->value->type; |
| 17505 | 18569 | } else { |
| 17506 | 18570 | bitcasted_value = nullptr; |
| 17507 | 18571 | } |
| 17508 | 18572 | |
| 17509 | | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { |
| 18573 | if (bitcasted_value != nullptr && type_is_invalid(bitcasted_value->value->type)) { |
| 17510 | 18574 | return bitcasted_value; |
| 17511 | 18575 | } |
| 17512 | 18576 | |
| 17513 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 17514 | | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 18577 | bool parent_was_written = result_bit_cast->parent->written; |
| 18578 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 18579 | dest_type, bitcasted_value, force_runtime, true); |
| 17515 | 18580 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17516 | 18581 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 17517 | 18582 | { |
| ... | ... | @@ -17521,55 +18586,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17521 | 18586 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 17522 | 18587 | ZigType *child_type = parent_ptr_type->data.pointer.child_type; |
| 17523 | 18588 | |
| 17524 | | bool has_bits; |
| 17525 | | if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) { |
| 17526 | | return ira->codegen->invalid_instruction; |
| 17527 | | } |
| 17528 | | |
| 17529 | | // This happens when the bitCast result is assigned to _ |
| 17530 | | if (!has_bits) { |
| 18589 | if (result_loc_is_discard(result_bit_cast->parent)) { |
| 17531 | 18590 | assert(allow_discard); |
| 17532 | 18591 | return parent_result_loc; |
| 17533 | 18592 | } |
| 17534 | 18593 | |
| 17535 | | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) { |
| 17536 | | return ira->codegen->invalid_instruction; |
| 18594 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) { |
| 18595 | return ira->codegen->invalid_inst_gen; |
| 17537 | 18596 | } |
| 17538 | 18597 | |
| 17539 | | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 17540 | | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { |
| 17541 | | return ira->codegen->invalid_instruction; |
| 18598 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusSizeKnown))) { |
| 18599 | return ira->codegen->invalid_inst_gen; |
| 18600 | } |
| 18601 | |
| 18602 | if (child_type != ira->codegen->builtin_types.entry_var) { |
| 18603 | if (type_size(ira->codegen, child_type) != type_size(ira->codegen, value_type)) { |
| 18604 | // pointer cast won't work; we need a temporary location. |
| 18605 | result_bit_cast->parent->written = parent_was_written; |
| 18606 | result_loc->written = true; |
| 18607 | result_loc->resolved_loc = ir_resolve_result(ira, suspend_source_instr, no_result_loc(), |
| 18608 | value_type, bitcasted_value, force_runtime, true); |
| 18609 | return result_loc->resolved_loc; |
| 18610 | } |
| 17542 | 18611 | } |
| 18612 | uint64_t parent_ptr_align = 0; |
| 18613 | if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 17543 | 18614 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, |
| 17544 | 18615 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, |
| 17545 | 18616 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); |
| 17546 | 18617 | |
| 17547 | 18618 | result_loc->written = true; |
| 17548 | 18619 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 17549 | | ptr_type, result_bit_cast->base.source_instruction, false); |
| 18620 | &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false); |
| 17550 | 18621 | return result_loc->resolved_loc; |
| 17551 | 18622 | } |
| 17552 | 18623 | } |
| 17553 | 18624 | zig_unreachable(); |
| 17554 | 18625 | } |
| 17555 | 18626 | |
| 17556 | | static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 17557 | | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime, |
| 17558 | | bool non_null_comptime, bool allow_discard) |
| 18627 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18628 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 18629 | bool allow_discard) |
| 17559 | 18630 | { |
| 17560 | | Error err; |
| 17561 | | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && |
| 17562 | | instr_is_comptime(result_loc_pass1->source_instruction) && |
| 17563 | | result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer && |
| 17564 | | result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| 17565 | | { |
| 18631 | if (!allow_discard && result_loc_is_discard(result_loc_pass1)) { |
| 17566 | 18632 | result_loc_pass1 = no_result_loc(); |
| 17567 | 18633 | } |
| 17568 | | bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr; |
| 17569 | | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17570 | | value, force_runtime, non_null_comptime, allow_discard); |
| 17571 | | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| 18634 | bool was_written = result_loc_pass1->written; |
| 18635 | IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 18636 | value, force_runtime, allow_discard); |
| 18637 | if (result_loc == nullptr || result_loc->value->type->id == ZigTypeIdUnreachable || |
| 18638 | type_is_invalid(result_loc->value->type)) |
| 18639 | { |
| 17572 | 18640 | return result_loc; |
| 18641 | } |
| 17573 | 18642 | |
| 17574 | 18643 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && |
| 17575 | 18644 | result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) |
| ... | ... | @@ -17578,56 +18647,63 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17578 | 18647 | } |
| 17579 | 18648 | |
| 17580 | 18649 | InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field; |
| 17581 | | if (!was_already_resolved && isf != nullptr) { |
| 17582 | | // Now it's time to add the field to the struct type. |
| 17583 | | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 17584 | | uint32_t new_field_count = old_field_count + 1; |
| 17585 | | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; |
| 17586 | | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( |
| 17587 | | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); |
| 17588 | | |
| 17589 | | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 17590 | | field->name = isf->field_name; |
| 17591 | | field->type_entry = value_type; |
| 17592 | | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 17593 | | field->src_index = old_field_count; |
| 17594 | | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; |
| 17595 | | if (value && instr_is_comptime(value)) { |
| 17596 | | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 17597 | | if (!val) |
| 17598 | | return ira->codegen->invalid_instruction; |
| 17599 | | field->is_comptime = true; |
| 17600 | | field->init_val = create_const_vals(1); |
| 17601 | | copy_const_val(field->init_val, val); |
| 17602 | | return result_loc; |
| 17603 | | } |
| 17604 | | |
| 17605 | | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 17606 | | IrInstruction *casted_ptr; |
| 17607 | | if (instr_is_comptime(result_loc)) { |
| 17608 | | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| 17609 | | copy_const_val(casted_ptr->value, result_loc->value); |
| 17610 | | casted_ptr->value->type = struct_ptr_type; |
| 17611 | | } else { |
| 18650 | if (isf != nullptr) { |
| 18651 | TypeStructField *field; |
| 18652 | IrInstGen *casted_ptr; |
| 18653 | if (isf->already_resolved) { |
| 18654 | field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| 17612 | 18655 | casted_ptr = result_loc; |
| 17613 | | } |
| 17614 | | if (instr_is_comptime(casted_ptr)) { |
| 17615 | | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 17616 | | if (!ptr_val) |
| 17617 | | return ira->codegen->invalid_instruction; |
| 17618 | | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 17619 | | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| 17620 | | suspend_source_instr->source_node); |
| 17621 | | struct_val->special = ConstValSpecialStatic; |
| 17622 | | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, |
| 17623 | | old_field_count, new_field_count); |
| 18656 | } else { |
| 18657 | isf->already_resolved = true; |
| 18658 | // Now it's time to add the field to the struct type. |
| 18659 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| 18660 | uint32_t new_field_count = old_field_count + 1; |
| 18661 | isf->inferred_struct_type->data.structure.src_field_count = new_field_count; |
| 18662 | isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields( |
| 18663 | isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count); |
| 18664 | |
| 18665 | field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 18666 | field->name = isf->field_name; |
| 18667 | field->type_entry = value_type; |
| 18668 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 18669 | field->src_index = old_field_count; |
| 18670 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| 18671 | if (value && instr_is_comptime(value)) { |
| 18672 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 18673 | if (!val) |
| 18674 | return ira->codegen->invalid_inst_gen; |
| 18675 | field->is_comptime = true; |
| 18676 | field->init_val = create_const_vals(1); |
| 18677 | copy_const_val(field->init_val, val); |
| 18678 | return result_loc; |
| 18679 | } |
| 17624 | 18680 | |
| 17625 | | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| 17626 | | field_val->special = ConstValSpecialUndef; |
| 17627 | | field_val->type = field->type_entry; |
| 17628 | | field_val->parent.id = ConstParentIdStruct; |
| 17629 | | field_val->parent.data.p_struct.struct_val = struct_val; |
| 17630 | | field_val->parent.data.p_struct.field_index = old_field_count; |
| 18681 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 18682 | if (instr_is_comptime(result_loc)) { |
| 18683 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| 18684 | copy_const_val(casted_ptr->value, result_loc->value); |
| 18685 | casted_ptr->value->type = struct_ptr_type; |
| 18686 | } else { |
| 18687 | casted_ptr = result_loc; |
| 18688 | } |
| 18689 | if (instr_is_comptime(casted_ptr)) { |
| 18690 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 18691 | if (!ptr_val) |
| 18692 | return ira->codegen->invalid_inst_gen; |
| 18693 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 18694 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| 18695 | suspend_source_instr->source_node); |
| 18696 | struct_val->special = ConstValSpecialStatic; |
| 18697 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, |
| 18698 | old_field_count, new_field_count); |
| 18699 | |
| 18700 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| 18701 | field_val->special = ConstValSpecialUndef; |
| 18702 | field_val->type = field->type_entry; |
| 18703 | field_val->parent.id = ConstParentIdStruct; |
| 18704 | field_val->parent.data.p_struct.struct_val = struct_val; |
| 18705 | field_val->parent.data.p_struct.field_index = old_field_count; |
| 18706 | } |
| 17631 | 18707 | } |
| 17632 | 18708 | } |
| 17633 | 18709 | |
| ... | ... | @@ -17636,73 +18712,70 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17636 | 18712 | result_loc_pass1->resolved_loc = result_loc; |
| 17637 | 18713 | } |
| 17638 | 18714 | |
| 18715 | if (was_written) { |
| 18716 | return result_loc; |
| 18717 | } |
| 17639 | 18718 | |
| 17640 | 18719 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); |
| 17641 | 18720 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; |
| 17642 | 18721 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 17643 | | value_type->id != ZigTypeIdNull) |
| 18722 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| 17644 | 18723 | { |
| 17645 | | bool has_bits; |
| 17646 | | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) |
| 17647 | | return ira->codegen->invalid_instruction; |
| 17648 | | if (has_bits) { |
| 17649 | | result_loc_pass1->written = false; |
| 18724 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type); |
| 18725 | if (!same_comptime_repr) { |
| 18726 | result_loc_pass1->written = was_written; |
| 17650 | 18727 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); |
| 17651 | 18728 | } |
| 17652 | | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) { |
| 17653 | | bool has_bits; |
| 17654 | | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) |
| 17655 | | return ira->codegen->invalid_instruction; |
| 17656 | | if (has_bits) { |
| 17657 | | if (value_type->id == ZigTypeIdErrorSet) { |
| 17658 | | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); |
| 18729 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion && |
| 18730 | value_type->id != ZigTypeIdUndefined) |
| 18731 | { |
| 18732 | if (value_type->id == ZigTypeIdErrorSet) { |
| 18733 | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); |
| 18734 | } else { |
| 18735 | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| 18736 | result_loc, false, true); |
| 18737 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| 18738 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 18739 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| 18740 | { |
| 18741 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); |
| 17659 | 18742 | } else { |
| 17660 | | IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| 17661 | | result_loc, false, true); |
| 17662 | | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| 17663 | | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 17664 | | value_type->id != ZigTypeIdNull) { |
| 17665 | | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); |
| 17666 | | } else { |
| 17667 | | return unwrapped_err_ptr; |
| 17668 | | } |
| 18743 | return unwrapped_err_ptr; |
| 17669 | 18744 | } |
| 17670 | 18745 | } |
| 17671 | 18746 | } |
| 17672 | 18747 | return result_loc; |
| 17673 | 18748 | } |
| 17674 | 18749 | |
| 17675 | | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17676 | | IrInstructionResolveResult *instruction) |
| 17677 | | { |
| 18750 | static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) { |
| 17678 | 18751 | ZigType *implicit_elem_type; |
| 17679 | 18752 | if (instruction->ty == nullptr) { |
| 17680 | 18753 | if (instruction->result_loc->id == ResultLocIdCast) { |
| 17681 | 18754 | implicit_elem_type = ir_resolve_type(ira, |
| 17682 | 18755 | instruction->result_loc->source_instruction->child); |
| 17683 | 18756 | if (type_is_invalid(implicit_elem_type)) |
| 17684 | | return ira->codegen->invalid_instruction; |
| 18757 | return ira->codegen->invalid_inst_gen; |
| 17685 | 18758 | } else if (instruction->result_loc->id == ResultLocIdReturn) { |
| 17686 | 18759 | implicit_elem_type = ira->explicit_return_type; |
| 17687 | 18760 | if (type_is_invalid(implicit_elem_type)) |
| 17688 | | return ira->codegen->invalid_instruction; |
| 18761 | return ira->codegen->invalid_inst_gen; |
| 17689 | 18762 | } else { |
| 17690 | 18763 | implicit_elem_type = ira->codegen->builtin_types.entry_var; |
| 17691 | 18764 | } |
| 17692 | 18765 | if (implicit_elem_type == ira->codegen->builtin_types.entry_var) { |
| 17693 | 18766 | Buf *bare_name = buf_alloc(); |
| 17694 | 18767 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 17695 | | instruction->base.scope, instruction->base.source_node, bare_name); |
| 18768 | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| 17696 | 18769 | |
| 17697 | 18770 | StructSpecial struct_special = StructSpecialInferredStruct; |
| 17698 | | if (instruction->base.source_node->type == NodeTypeContainerInitExpr && |
| 17699 | | instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 18771 | if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr && |
| 18772 | instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 17700 | 18773 | { |
| 17701 | 18774 | struct_special = StructSpecialInferredTuple; |
| 17702 | 18775 | } |
| 17703 | 18776 | |
| 17704 | 18777 | ZigType *inferred_struct_type = get_partial_container_type(ira->codegen, |
| 17705 | | instruction->base.scope, ContainerKindStruct, instruction->base.source_node, |
| 18778 | instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node, |
| 17706 | 18779 | buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 17707 | 18780 | inferred_struct_type->data.structure.special = struct_special; |
| 17708 | 18781 | inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| ... | ... | @@ -17711,21 +18784,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17711 | 18784 | } else { |
| 17712 | 18785 | implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 17713 | 18786 | if (type_is_invalid(implicit_elem_type)) |
| 17714 | | return ira->codegen->invalid_instruction; |
| 18787 | return ira->codegen->invalid_inst_gen; |
| 17715 | 18788 | } |
| 17716 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 17717 | | implicit_elem_type, nullptr, false, true, true); |
| 18789 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 18790 | implicit_elem_type, nullptr, false, true); |
| 17718 | 18791 | if (result_loc != nullptr) |
| 17719 | 18792 | return result_loc; |
| 17720 | 18793 | |
| 17721 | | ZigFn *fn = exec_fn_entry(ira->new_irb.exec); |
| 18794 | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 17722 | 18795 | if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 17723 | 18796 | instruction->result_loc->id == ResultLocIdReturn) |
| 17724 | 18797 | { |
| 17725 | | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 17726 | | implicit_elem_type, nullptr, false, true, true); |
| 18798 | result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(), |
| 18799 | implicit_elem_type, nullptr, false, true); |
| 17727 | 18800 | if (result_loc != nullptr && |
| 17728 | | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 18801 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 17729 | 18802 | { |
| 17730 | 18803 | return result_loc; |
| 17731 | 18804 | } |
| ... | ... | @@ -17733,9 +18806,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17733 | 18806 | return result_loc; |
| 17734 | 18807 | } |
| 17735 | 18808 | |
| 17736 | | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); |
| 18809 | IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type); |
| 17737 | 18810 | result->value->special = ConstValSpecialUndef; |
| 17738 | | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); |
| 18811 | IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false); |
| 17739 | 18812 | ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 17740 | 18813 | return ptr; |
| 17741 | 18814 | } |
| ... | ... | @@ -17759,8 +18832,7 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 17759 | 18832 | break; |
| 17760 | 18833 | } |
| 17761 | 18834 | case ResultLocIdVar: { |
| 17762 | | IrInstructionAllocaSrc *alloca_src = |
| 17763 | | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| 18835 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); |
| 17764 | 18836 | alloca_src->base.child = nullptr; |
| 17765 | 18837 | break; |
| 17766 | 18838 | } |
| ... | ... | @@ -17776,18 +18848,18 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 17776 | 18848 | } |
| 17777 | 18849 | } |
| 17778 | 18850 | |
| 17779 | | static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) { |
| 18851 | static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) { |
| 17780 | 18852 | ir_reset_result(instruction->result_loc); |
| 17781 | | return ir_const_void(ira, &instruction->base); |
| 18853 | return ir_const_void(ira, &instruction->base.base); |
| 17782 | 18854 | } |
| 17783 | 18855 | |
| 17784 | | static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *source_instr, |
| 17785 | | ZigType *fn_ret_type, bool is_async_call_builtin, IrInstruction **args_ptr, size_t args_len, |
| 17786 | | IrInstruction *ret_ptr_uncasted) |
| 18856 | static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr, |
| 18857 | ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len, |
| 18858 | IrInstGen *ret_ptr_uncasted) |
| 17787 | 18859 | { |
| 17788 | 18860 | ir_assert(is_async_call_builtin, source_instr); |
| 17789 | 18861 | if (type_is_invalid(ret_ptr_uncasted->value->type)) |
| 17790 | | return ira->codegen->invalid_instruction; |
| 18862 | return ira->codegen->invalid_inst_gen; |
| 17791 | 18863 | if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { |
| 17792 | 18864 | // Result location will be inside the async frame. |
| 17793 | 18865 | return nullptr; |
| ... | ... | @@ -17795,57 +18867,58 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s |
| 17795 | 18867 | return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false)); |
| 17796 | 18868 | } |
| 17797 | 18869 | |
| 17798 | | static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *source_instr, ZigFn *fn_entry, |
| 17799 | | ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, |
| 17800 | | IrInstruction *casted_new_stack, bool is_async_call_builtin, IrInstruction *ret_ptr_uncasted, |
| 18870 | static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry, |
| 18871 | ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count, |
| 18872 | IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted, |
| 17801 | 18873 | ResultLoc *call_result_loc) |
| 17802 | 18874 | { |
| 17803 | 18875 | if (fn_entry == nullptr) { |
| 17804 | 18876 | if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) { |
| 17805 | | ir_add_error(ira, fn_ref, |
| 18877 | ir_add_error(ira, &fn_ref->base, |
| 17806 | 18878 | buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name))); |
| 17807 | | return ira->codegen->invalid_instruction; |
| 18879 | return ira->codegen->invalid_inst_gen; |
| 17808 | 18880 | } |
| 17809 | 18881 | if (casted_new_stack == nullptr) { |
| 17810 | | ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required")); |
| 17811 | | return ira->codegen->invalid_instruction; |
| 18882 | ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required")); |
| 18883 | return ira->codegen->invalid_inst_gen; |
| 17812 | 18884 | } |
| 17813 | 18885 | } |
| 17814 | 18886 | if (casted_new_stack != nullptr) { |
| 17815 | 18887 | ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type; |
| 17816 | | IrInstruction *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin, |
| 18888 | IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin, |
| 17817 | 18889 | casted_args, arg_count, ret_ptr_uncasted); |
| 17818 | 18890 | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) |
| 17819 | | return ira->codegen->invalid_instruction; |
| 18891 | return ira->codegen->invalid_inst_gen; |
| 17820 | 18892 | |
| 17821 | 18893 | ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); |
| 17822 | 18894 | |
| 17823 | | IrInstructionCallGen *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 18895 | IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 17824 | 18896 | arg_count, casted_args, CallModifierAsync, casted_new_stack, |
| 17825 | 18897 | is_async_call_builtin, ret_ptr, anyframe_type); |
| 17826 | 18898 | return &call_gen->base; |
| 17827 | 18899 | } else { |
| 17828 | 18900 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 17829 | | IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 17830 | | frame_type, nullptr, true, true, false); |
| 17831 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18901 | IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18902 | frame_type, nullptr, true, false); |
| 18903 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 17832 | 18904 | return result_loc; |
| 17833 | 18905 | } |
| 17834 | | result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); |
| 18906 | result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc, |
| 18907 | get_pointer_to_type(ira->codegen, frame_type, false)); |
| 17835 | 18908 | if (type_is_invalid(result_loc->value->type)) |
| 17836 | | return ira->codegen->invalid_instruction; |
| 18909 | return ira->codegen->invalid_inst_gen; |
| 17837 | 18910 | return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count, |
| 17838 | 18911 | casted_args, CallModifierAsync, casted_new_stack, |
| 17839 | 18912 | is_async_call_builtin, result_loc, frame_type)->base; |
| 17840 | 18913 | } |
| 17841 | 18914 | } |
| 17842 | 18915 | static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 17843 | | IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i) |
| 18916 | IrInstGen *arg, Scope **exec_scope, size_t *next_proto_i) |
| 17844 | 18917 | { |
| 17845 | 18918 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 17846 | 18919 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 17847 | 18920 | |
| 17848 | | IrInstruction *casted_arg; |
| 18921 | IrInstGen *casted_arg; |
| 17849 | 18922 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 17850 | 18923 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 17851 | 18924 | ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node); |
| ... | ... | @@ -17873,15 +18946,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 17873 | 18946 | } |
| 17874 | 18947 | |
| 17875 | 18948 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 17876 | | IrInstruction *arg, Scope **child_scope, size_t *next_proto_i, |
| 17877 | | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args, |
| 18949 | IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i, |
| 18950 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args, |
| 17878 | 18951 | ZigFn *impl_fn) |
| 17879 | 18952 | { |
| 17880 | 18953 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 17881 | 18954 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 17882 | 18955 | bool is_var_args = param_decl_node->data.param_decl.is_var_args; |
| 17883 | 18956 | bool arg_part_of_generic_id = false; |
| 17884 | | IrInstruction *casted_arg; |
| 18957 | IrInstGen *casted_arg; |
| 17885 | 18958 | if (is_var_args) { |
| 17886 | 18959 | arg_part_of_generic_id = true; |
| 17887 | 18960 | casted_arg = arg; |
| ... | ... | @@ -17892,7 +18965,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 17892 | 18965 | if (type_is_invalid(param_type)) |
| 17893 | 18966 | return false; |
| 17894 | 18967 | |
| 17895 | | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 18968 | casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type); |
| 17896 | 18969 | if (type_is_invalid(casted_arg->value->type)) |
| 17897 | 18970 | return false; |
| 17898 | 18971 | } else { |
| ... | ... | @@ -17941,7 +19014,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 17941 | 19014 | } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || |
| 17942 | 19015 | casted_arg->value->type->id == ZigTypeIdComptimeFloat) |
| 17943 | 19016 | { |
| 17944 | | ir_add_error(ira, casted_arg, |
| 19017 | ir_add_error(ira, &casted_arg->base, |
| 17945 | 19018 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| 17946 | 19019 | return false; |
| 17947 | 19020 | } |
| ... | ... | @@ -17958,47 +19031,33 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 17958 | 19031 | return true; |
| 17959 | 19032 | } |
| 17960 | 19033 | |
| 17961 | | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { |
| 19034 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 17962 | 19035 | while (var->next_var != nullptr) { |
| 17963 | 19036 | var = var->next_var; |
| 17964 | 19037 | } |
| 17965 | 19038 | |
| 17966 | | if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) { |
| 17967 | | assert(ira->codegen->errors.length != 0); |
| 17968 | | return ira->codegen->invalid_instruction; |
| 17969 | | } |
| 17970 | 19039 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) |
| 17971 | | return ira->codegen->invalid_instruction; |
| 19040 | return ira->codegen->invalid_inst_gen; |
| 17972 | 19041 | |
| 17973 | | ZigValue *mem_slot = nullptr; |
| 17974 | | |
| 17975 | | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 17976 | | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 17977 | 19042 | bool is_volatile = false; |
| 17978 | | |
| 17979 | | IrInstruction *result = ir_build_var_ptr(&ira->new_irb, |
| 17980 | | instruction->scope, instruction->source_node, var); |
| 17981 | | result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 19043 | ZigType *var_ptr_type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 17982 | 19044 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 17983 | 19045 | |
| 17984 | | if (linkage_makes_it_runtime || var->is_thread_local) |
| 17985 | | goto no_mem_slot; |
| 17986 | | |
| 17987 | | if (value_is_comptime(var->const_value)) { |
| 17988 | | mem_slot = var->const_value; |
| 17989 | | } else if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) { |
| 17990 | | // find the relevant exec_context |
| 17991 | | assert(var->owner_exec != nullptr); |
| 17992 | | assert(var->owner_exec->analysis != nullptr); |
| 17993 | | IrExecContext *exec_context = &var->owner_exec->analysis->exec_context; |
| 17994 | | assert(var->mem_slot_index < exec_context->mem_slot_list.length); |
| 17995 | | mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index); |
| 19046 | if (var->ptr_instruction != nullptr) { |
| 19047 | return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type); |
| 17996 | 19048 | } |
| 17997 | 19049 | |
| 17998 | | if (mem_slot != nullptr) { |
| 17999 | | switch (mem_slot->special) { |
| 19050 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 19051 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 19052 | |
| 19053 | IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var); |
| 19054 | result->value->type = var_ptr_type; |
| 19055 | |
| 19056 | if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) { |
| 19057 | ZigValue *val = var->const_value; |
| 19058 | switch (val->special) { |
| 18000 | 19059 | case ConstValSpecialRuntime: |
| 18001 | | goto no_mem_slot; |
| 19060 | break; |
| 18002 | 19061 | case ConstValSpecialStatic: // fallthrough |
| 18003 | 19062 | case ConstValSpecialLazy: // fallthrough |
| 18004 | 19063 | case ConstValSpecialUndef: { |
| ... | ... | @@ -18014,15 +19073,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 18014 | 19073 | result->value->special = ConstValSpecialStatic; |
| 18015 | 19074 | result->value->data.x_ptr.mut = ptr_mut; |
| 18016 | 19075 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 18017 | | result->value->data.x_ptr.data.ref.pointee = mem_slot; |
| 19076 | result->value->data.x_ptr.data.ref.pointee = val; |
| 18018 | 19077 | return result; |
| 18019 | 19078 | } |
| 18020 | 19079 | } |
| 18021 | | zig_unreachable(); |
| 18022 | 19080 | } |
| 18023 | 19081 | |
| 18024 | | no_mem_slot: |
| 18025 | | |
| 18026 | 19082 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 18027 | 19083 | result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 18028 | 19084 | |
| ... | ... | @@ -18030,7 +19086,7 @@ no_mem_slot: |
| 18030 | 19086 | } |
| 18031 | 19087 | |
| 18032 | 19088 | // This function is called when a comptime value becomes accessible at runtime. |
| 18033 | | static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) { |
| 19089 | static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) { |
| 18034 | 19090 | ir_assert(value_is_comptime(val), source_instr); |
| 18035 | 19091 | if (val->special == ConstValSpecialUndef) |
| 18036 | 19092 | return; |
| ... | ... | @@ -18043,8 +19099,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins |
| 18043 | 19099 | } |
| 18044 | 19100 | } |
| 18045 | 19101 | |
| 18046 | | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 18047 | | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 19102 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 19103 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const) |
| 18048 | 19104 | { |
| 18049 | 19105 | assert(ptr->value->type->id == ZigTypeIdPointer); |
| 18050 | 19106 | |
| ... | ... | @@ -18053,24 +19109,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18053 | 19109 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 18054 | 19110 | { |
| 18055 | 19111 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); |
| 18056 | | return ira->codegen->invalid_instruction; |
| 19112 | return ira->codegen->invalid_inst_gen; |
| 18057 | 19113 | } |
| 18058 | 19114 | return ir_const_void(ira, source_instr); |
| 18059 | 19115 | } |
| 18060 | 19116 | |
| 18061 | 19117 | if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { |
| 18062 | 19118 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 18063 | | return ira->codegen->invalid_instruction; |
| 19119 | return ira->codegen->invalid_inst_gen; |
| 18064 | 19120 | } |
| 18065 | 19121 | |
| 18066 | 19122 | ZigType *child_type = ptr->value->type->data.pointer.child_type; |
| 18067 | | IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type); |
| 18068 | | if (value == ira->codegen->invalid_instruction) |
| 18069 | | return ira->codegen->invalid_instruction; |
| 19123 | IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type); |
| 19124 | if (type_is_invalid(value->value->type)) |
| 19125 | return ira->codegen->invalid_inst_gen; |
| 18070 | 19126 | |
| 18071 | 19127 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 18072 | 19128 | case OnePossibleValueInvalid: |
| 18073 | | return ira->codegen->invalid_instruction; |
| 19129 | return ira->codegen->invalid_inst_gen; |
| 18074 | 19130 | case OnePossibleValueYes: |
| 18075 | 19131 | return ir_const_void(ira, source_instr); |
| 18076 | 19132 | case OnePossibleValueNo: |
| ... | ... | @@ -18080,7 +19136,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18080 | 19136 | if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 18081 | 19137 | if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 18082 | 19138 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 18083 | | return ira->codegen->invalid_instruction; |
| 19139 | return ira->codegen->invalid_inst_gen; |
| 18084 | 19140 | } |
| 18085 | 19141 | if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) || |
| 18086 | 19142 | ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar || |
| ... | ... | @@ -18089,7 +19145,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18089 | 19145 | if (instr_is_comptime(value)) { |
| 18090 | 19146 | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); |
| 18091 | 19147 | if (dest_val == nullptr) |
| 18092 | | return ira->codegen->invalid_instruction; |
| 19148 | return ira->codegen->invalid_inst_gen; |
| 18093 | 19149 | if (dest_val->special != ConstValSpecialRuntime) { |
| 18094 | 19150 | copy_const_val(dest_val, value->value); |
| 18095 | 19151 | |
| ... | ... | @@ -18109,7 +19165,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18109 | 19165 | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 18110 | 19166 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 18111 | 19167 | |
| 18112 | | return ira->codegen->invalid_instruction; |
| 19168 | return ira->codegen->invalid_inst_gen; |
| 18113 | 19169 | } |
| 18114 | 19170 | } |
| 18115 | 19171 | } |
| ... | ... | @@ -18122,15 +19178,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18122 | 19178 | |
| 18123 | 19179 | switch (type_requires_comptime(ira->codegen, child_type)) { |
| 18124 | 19180 | case ReqCompTimeInvalid: |
| 18125 | | return ira->codegen->invalid_instruction; |
| 19181 | return ira->codegen->invalid_inst_gen; |
| 18126 | 19182 | case ReqCompTimeYes: |
| 18127 | 19183 | switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) { |
| 18128 | 19184 | case OnePossibleValueInvalid: |
| 18129 | | return ira->codegen->invalid_instruction; |
| 19185 | return ira->codegen->invalid_inst_gen; |
| 18130 | 19186 | case OnePossibleValueNo: |
| 18131 | 19187 | ir_add_error(ira, source_instr, |
| 18132 | 19188 | buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name))); |
| 18133 | | return ira->codegen->invalid_instruction; |
| 19189 | return ira->codegen->invalid_inst_gen; |
| 18134 | 19190 | case OnePossibleValueYes: |
| 18135 | 19191 | return ir_const_void(ira, source_instr); |
| 18136 | 19192 | } |
| ... | ... | @@ -18144,30 +19200,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18144 | 19200 | } |
| 18145 | 19201 | |
| 18146 | 19202 | // If this is a store to a pointer with a runtime-known vector index, |
| 18147 | | // we have to figure out the IrInstruction which represents the index and |
| 18148 | | // emit a IrInstructionVectorStoreElem, or emit a compile error |
| 19203 | // we have to figure out the IrInstGen which represents the index and |
| 19204 | // emit a IrInstGenVectorStoreElem, or emit a compile error |
| 18149 | 19205 | // explaining why it is impossible for this store to work. Which is that |
| 18150 | 19206 | // the pointer address is of the vector; without the element index being known |
| 18151 | 19207 | // we cannot properly perform the insertion. |
| 18152 | 19208 | if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 18153 | | if (ptr->id == IrInstructionIdElemPtr) { |
| 18154 | | IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; |
| 19209 | if (ptr->id == IrInstGenIdElemPtr) { |
| 19210 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 18155 | 19211 | return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, |
| 18156 | 19212 | elem_ptr->elem_index, value); |
| 18157 | 19213 | } |
| 18158 | | ir_add_error(ira, ptr, |
| 19214 | ir_add_error(ira, &ptr->base, |
| 18159 | 19215 | buf_sprintf("unable to determine vector element index of type '%s'", |
| 18160 | 19216 | buf_ptr(&ptr->value->type->name))); |
| 18161 | | return ira->codegen->invalid_instruction; |
| 19217 | return ira->codegen->invalid_inst_gen; |
| 18162 | 19218 | } |
| 18163 | 19219 | |
| 18164 | | IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope, |
| 18165 | | source_instr->source_node, ptr, value); |
| 18166 | | return &store_ptr->base; |
| 19220 | return ir_build_store_ptr_gen(ira, source_instr, ptr, value); |
| 18167 | 19221 | } |
| 18168 | 19222 | |
| 18169 | | static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr, |
| 18170 | | IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry) |
| 19223 | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 19224 | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry) |
| 18171 | 19225 | { |
| 18172 | 19226 | if (new_stack == nullptr) |
| 18173 | 19227 | return nullptr; |
| ... | ... | @@ -18192,15 +19246,15 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so |
| 18192 | 19246 | false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false); |
| 18193 | 19247 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 18194 | 19248 | ira->codegen->need_frame_size_prefix_data = true; |
| 18195 | | return ir_implicit_cast(ira, new_stack, u8_slice); |
| 19249 | return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice); |
| 18196 | 19250 | } |
| 18197 | 19251 | } |
| 18198 | 19252 | |
| 18199 | | static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_instr, |
| 18200 | | ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, |
| 18201 | | IrInstruction *first_arg_ptr, CallModifier modifier, |
| 18202 | | IrInstruction *new_stack, bool is_async_call_builtin, |
| 18203 | | IrInstruction **args_ptr, size_t args_len, IrInstruction *ret_ptr, ResultLoc *call_result_loc) |
| 19253 | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19254 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19255 | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier, |
| 19256 | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, |
| 19257 | IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc) |
| 18204 | 19258 | { |
| 18205 | 19259 | Error err; |
| 18206 | 19260 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| ... | ... | @@ -18221,11 +19275,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18221 | 19275 | AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;; |
| 18222 | 19276 | |
| 18223 | 19277 | if (fn_type_id->cc == CallingConventionNaked) { |
| 18224 | | ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention")); |
| 19278 | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention")); |
| 18225 | 19279 | if (fn_proto_node) { |
| 18226 | 19280 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 18227 | 19281 | } |
| 18228 | | return ira->codegen->invalid_instruction; |
| 19282 | return ira->codegen->invalid_inst_gen; |
| 18229 | 19283 | } |
| 18230 | 19284 | |
| 18231 | 19285 | if (fn_type_id->is_var_args) { |
| ... | ... | @@ -18236,7 +19290,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18236 | 19290 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 18237 | 19291 | buf_sprintf("declared here")); |
| 18238 | 19292 | } |
| 18239 | | return ira->codegen->invalid_instruction; |
| 19293 | return ira->codegen->invalid_inst_gen; |
| 18240 | 19294 | } |
| 18241 | 19295 | } else if (src_param_count != call_param_count) { |
| 18242 | 19296 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| ... | ... | @@ -18245,18 +19299,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18245 | 19299 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 18246 | 19300 | buf_sprintf("declared here")); |
| 18247 | 19301 | } |
| 18248 | | return ira->codegen->invalid_instruction; |
| 19302 | return ira->codegen->invalid_inst_gen; |
| 18249 | 19303 | } |
| 18250 | 19304 | |
| 18251 | 19305 | if (modifier == CallModifierCompileTime) { |
| 18252 | 19306 | // No special handling is needed for compile time evaluation of generic functions. |
| 18253 | 19307 | if (!fn_entry || fn_entry->body_node == nullptr) { |
| 18254 | | ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression")); |
| 18255 | | return ira->codegen->invalid_instruction; |
| 19308 | ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression")); |
| 19309 | return ira->codegen->invalid_inst_gen; |
| 18256 | 19310 | } |
| 18257 | 19311 | |
| 18258 | 19312 | if (!ir_emit_backward_branch(ira, source_instr)) |
| 18259 | | return ira->codegen->invalid_instruction; |
| 19313 | return ira->codegen->invalid_inst_gen; |
| 18260 | 19314 | |
| 18261 | 19315 | // Fork a scope of the function with known values for the parameters. |
| 18262 | 19316 | Scope *exec_scope = &fn_entry->fndef_scope->base; |
| ... | ... | @@ -18269,47 +19323,40 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18269 | 19323 | if (fn_type_id->next_param_index >= 1) { |
| 18270 | 19324 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 18271 | 19325 | if (type_is_invalid(param_type)) |
| 18272 | | return ira->codegen->invalid_instruction; |
| 19326 | return ira->codegen->invalid_inst_gen; |
| 18273 | 19327 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 18274 | 19328 | } |
| 18275 | 19329 | |
| 18276 | | IrInstruction *first_arg; |
| 19330 | IrInstGen *first_arg; |
| 18277 | 19331 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 18278 | 19332 | first_arg = first_arg_ptr; |
| 18279 | 19333 | } else { |
| 18280 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19334 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18281 | 19335 | if (type_is_invalid(first_arg->value->type)) |
| 18282 | | return ira->codegen->invalid_instruction; |
| 19336 | return ira->codegen->invalid_inst_gen; |
| 18283 | 19337 | } |
| 18284 | 19338 | |
| 18285 | 19339 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i)) |
| 18286 | | return ira->codegen->invalid_instruction; |
| 18287 | | } |
| 18288 | | |
| 18289 | | if (fn_proto_node->data.fn_proto.is_var_args) { |
| 18290 | | ir_add_error(ira, source_instr, |
| 18291 | | buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313")); |
| 18292 | | return ira->codegen->invalid_instruction; |
| 19340 | return ira->codegen->invalid_inst_gen; |
| 18293 | 19341 | } |
| 18294 | 19342 | |
| 18295 | | |
| 18296 | 19343 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18297 | | IrInstruction *old_arg = args_ptr[call_i]; |
| 19344 | IrInstGen *old_arg = args_ptr[call_i]; |
| 18298 | 19345 | |
| 18299 | 19346 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| 18300 | | return ira->codegen->invalid_instruction; |
| 19347 | return ira->codegen->invalid_inst_gen; |
| 18301 | 19348 | } |
| 18302 | 19349 | |
| 18303 | 19350 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 18304 | 19351 | ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node); |
| 18305 | 19352 | if (type_is_invalid(specified_return_type)) |
| 18306 | | return ira->codegen->invalid_instruction; |
| 19353 | return ira->codegen->invalid_inst_gen; |
| 18307 | 19354 | ZigType *return_type; |
| 18308 | 19355 | ZigType *inferred_err_set_type = nullptr; |
| 18309 | 19356 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 18310 | 19357 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); |
| 18311 | 19358 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 18312 | | return ira->codegen->invalid_instruction; |
| 19359 | return ira->codegen->invalid_inst_gen; |
| 18313 | 19360 | return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 18314 | 19361 | } else { |
| 18315 | 19362 | return_type = specified_return_type; |
| ... | ... | @@ -18326,10 +19373,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18326 | 19373 | if (result == nullptr) { |
| 18327 | 19374 | // Analyze the fn body block like any other constant expression. |
| 18328 | 19375 | AstNode *body_node = fn_entry->body_node; |
| 18329 | | result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type, |
| 18330 | | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry, |
| 18331 | | nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, |
| 18332 | | UndefOk); |
| 19376 | ZigValue *result_ptr; |
| 19377 | create_result_ptr(ira->codegen, return_type, &result, &result_ptr); |
| 19378 | if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr, |
| 19379 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 19380 | fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, |
| 19381 | UndefOk))) |
| 19382 | { |
| 19383 | return ira->codegen->invalid_inst_gen; |
| 19384 | } |
| 19385 | destroy(result_ptr, "ZigValue"); |
| 19386 | result_ptr = nullptr; |
| 18333 | 19387 | |
| 18334 | 19388 | if (inferred_err_set_type != nullptr) { |
| 18335 | 19389 | inferred_err_set_type->data.error_set.incomplete = false; |
| ... | ... | @@ -18354,24 +19408,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18354 | 19408 | } |
| 18355 | 19409 | |
| 18356 | 19410 | if (type_is_invalid(result->type)) { |
| 18357 | | return ira->codegen->invalid_instruction; |
| 19411 | return ira->codegen->invalid_inst_gen; |
| 18358 | 19412 | } |
| 18359 | 19413 | } |
| 18360 | 19414 | |
| 18361 | | IrInstruction *new_instruction = ir_const_move(ira, source_instr, result); |
| 19415 | IrInstGen *new_instruction = ir_const_move(ira, source_instr, result); |
| 18362 | 19416 | return ir_finish_anal(ira, new_instruction); |
| 18363 | 19417 | } |
| 18364 | 19418 | |
| 18365 | 19419 | if (fn_type->data.fn.is_generic) { |
| 18366 | 19420 | if (!fn_entry) { |
| 18367 | | ir_add_error(ira, fn_ref, |
| 19421 | ir_add_error(ira, &fn_ref->base, |
| 18368 | 19422 | buf_sprintf("calling a generic function requires compile-time known function value")); |
| 18369 | | return ira->codegen->invalid_instruction; |
| 19423 | return ira->codegen->invalid_inst_gen; |
| 18370 | 19424 | } |
| 18371 | 19425 | |
| 18372 | 19426 | size_t new_fn_arg_count = first_arg_1_or_0 + args_len; |
| 18373 | 19427 | |
| 18374 | | IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count); |
| 19428 | IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count); |
| 18375 | 19429 | |
| 18376 | 19430 | // Fork a scope of the function with known values for the parameters. |
| 18377 | 19431 | Scope *parent_scope = fn_entry->fndef_scope->base.parent; |
| ... | ... | @@ -18400,50 +19454,57 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18400 | 19454 | if (fn_type_id->next_param_index >= 1) { |
| 18401 | 19455 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 18402 | 19456 | if (type_is_invalid(param_type)) |
| 18403 | | return ira->codegen->invalid_instruction; |
| 19457 | return ira->codegen->invalid_inst_gen; |
| 18404 | 19458 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 18405 | 19459 | } |
| 18406 | 19460 | |
| 18407 | | IrInstruction *first_arg; |
| 19461 | IrInstGen *first_arg; |
| 18408 | 19462 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 18409 | 19463 | first_arg = first_arg_ptr; |
| 18410 | 19464 | } else { |
| 18411 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19465 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18412 | 19466 | if (type_is_invalid(first_arg->value->type)) |
| 18413 | | return ira->codegen->invalid_instruction; |
| 19467 | return ira->codegen->invalid_inst_gen; |
| 18414 | 19468 | } |
| 18415 | 19469 | |
| 18416 | | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope, |
| 18417 | | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 19470 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, first_arg_ptr_src, |
| 19471 | &impl_fn->child_scope, &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 18418 | 19472 | { |
| 18419 | | return ira->codegen->invalid_instruction; |
| 19473 | return ira->codegen->invalid_inst_gen; |
| 18420 | 19474 | } |
| 18421 | 19475 | } |
| 18422 | 19476 | |
| 18423 | | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19477 | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 18424 | 19478 | assert(parent_fn_entry); |
| 18425 | 19479 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18426 | | IrInstruction *arg = args_ptr[call_i]; |
| 19480 | IrInstGen *arg = args_ptr[call_i]; |
| 18427 | 19481 | |
| 18428 | 19482 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); |
| 18429 | 19483 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 18430 | 19484 | |
| 18431 | | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, |
| 19485 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope, |
| 18432 | 19486 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 18433 | 19487 | { |
| 18434 | | return ira->codegen->invalid_instruction; |
| 19488 | return ira->codegen->invalid_inst_gen; |
| 18435 | 19489 | } |
| 18436 | 19490 | } |
| 18437 | 19491 | |
| 18438 | 19492 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { |
| 18439 | | ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 18440 | | fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen), |
| 18441 | | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 18442 | | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| 18443 | | nullptr, UndefBad); |
| 18444 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 19493 | ZigValue *align_result; |
| 19494 | ZigValue *result_ptr; |
| 19495 | create_result_ptr(ira->codegen, get_align_amt_type(ira->codegen), &align_result, &result_ptr); |
| 19496 | if ((err = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 19497 | fn_proto_node->data.fn_proto.align_expr, result_ptr, |
| 19498 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 19499 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| 19500 | nullptr, UndefBad))) |
| 19501 | { |
| 19502 | return ira->codegen->invalid_inst_gen; |
| 19503 | } |
| 19504 | IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, |
| 18445 | 19505 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 18446 | | copy_const_val(const_instruction->base.value, align_result); |
| 19506 | const_instruction->base.value = align_result; |
| 19507 | destroy(result_ptr, "ZigValue"); |
| 18447 | 19508 | |
| 18448 | 19509 | uint32_t align_bytes = 0; |
| 18449 | 19510 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | ... | @@ -18455,11 +19516,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18455 | 19516 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 18456 | 19517 | ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); |
| 18457 | 19518 | if (type_is_invalid(specified_return_type)) |
| 18458 | | return ira->codegen->invalid_instruction; |
| 19519 | return ira->codegen->invalid_inst_gen; |
| 18459 | 19520 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 18460 | 19521 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| 18461 | 19522 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 18462 | | return ira->codegen->invalid_instruction; |
| 19523 | return ira->codegen->invalid_inst_gen; |
| 18463 | 19524 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 18464 | 19525 | } else { |
| 18465 | 19526 | inst_fn_type_id.return_type = specified_return_type; |
| ... | ... | @@ -18469,10 +19530,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18469 | 19530 | case ReqCompTimeYes: |
| 18470 | 19531 | // Throw out our work and call the function as if it were comptime. |
| 18471 | 19532 | return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr, |
| 18472 | | CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len, |
| 18473 | | ret_ptr, call_result_loc); |
| 19533 | first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin, |
| 19534 | args_ptr, args_len, ret_ptr, call_result_loc); |
| 18474 | 19535 | case ReqCompTimeInvalid: |
| 18475 | | return ira->codegen->invalid_instruction; |
| 19536 | return ira->codegen->invalid_inst_gen; |
| 18476 | 19537 | case ReqCompTimeNo: |
| 18477 | 19538 | break; |
| 18478 | 19539 | } |
| ... | ... | @@ -18486,7 +19547,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18486 | 19547 | // finish instantiating the function |
| 18487 | 19548 | impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id); |
| 18488 | 19549 | if (type_is_invalid(impl_fn->type_entry)) |
| 18489 | | return ira->codegen->invalid_instruction; |
| 19550 | return ira->codegen->invalid_inst_gen; |
| 18490 | 19551 | |
| 18491 | 19552 | impl_fn->ir_executable->source_node = source_instr->source_node; |
| 18492 | 19553 | impl_fn->ir_executable->parent_exec = ira->new_irb.exec; |
| ... | ... | @@ -18504,25 +19565,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18504 | 19565 | parent_fn_entry->calls_or_awaits_errorable_fn = true; |
| 18505 | 19566 | } |
| 18506 | 19567 | |
| 18507 | | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 18508 | | is_async_call_builtin, impl_fn); |
| 19568 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 19569 | new_stack_src, is_async_call_builtin, impl_fn); |
| 18509 | 19570 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 18510 | | return ira->codegen->invalid_instruction; |
| 19571 | return ira->codegen->invalid_inst_gen; |
| 18511 | 19572 | |
| 18512 | 19573 | size_t impl_param_count = impl_fn_type_id->param_count; |
| 18513 | 19574 | if (modifier == CallModifierAsync) { |
| 18514 | | IrInstruction *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry, |
| 19575 | IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry, |
| 18515 | 19576 | nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, |
| 18516 | 19577 | call_result_loc); |
| 18517 | 19578 | return ir_finish_anal(ira, result); |
| 18518 | 19579 | } |
| 18519 | 19580 | |
| 18520 | | IrInstruction *result_loc; |
| 19581 | IrInstGen *result_loc; |
| 18521 | 19582 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 18522 | 19583 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18523 | | impl_fn_type_id->return_type, nullptr, true, true, false); |
| 19584 | impl_fn_type_id->return_type, nullptr, true, false); |
| 18524 | 19585 | if (result_loc != nullptr) { |
| 18525 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 19586 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18526 | 19587 | return result_loc; |
| 18527 | 19588 | } |
| 18528 | 19589 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| ... | ... | @@ -18538,7 +19599,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18538 | 19599 | result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type, |
| 18539 | 19600 | is_async_call_builtin, args_ptr, args_len, ret_ptr); |
| 18540 | 19601 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 18541 | | return ira->codegen->invalid_instruction; |
| 19602 | return ira->codegen->invalid_inst_gen; |
| 18542 | 19603 | } else { |
| 18543 | 19604 | result_loc = nullptr; |
| 18544 | 19605 | } |
| ... | ... | @@ -18547,11 +19608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18547 | 19608 | parent_fn_entry->inferred_async_node == nullptr && |
| 18548 | 19609 | modifier != CallModifierNoAsync) |
| 18549 | 19610 | { |
| 18550 | | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 19611 | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 18551 | 19612 | parent_fn_entry->inferred_async_fn = impl_fn; |
| 18552 | 19613 | } |
| 18553 | 19614 | |
| 18554 | | IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, |
| 19615 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, |
| 18555 | 19616 | impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack, |
| 18556 | 19617 | is_async_call_builtin, result_loc, impl_fn_type_id->return_type); |
| 18557 | 19618 | |
| ... | ... | @@ -18562,7 +19623,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18562 | 19623 | return ir_finish_anal(ira, &new_call_instruction->base); |
| 18563 | 19624 | } |
| 18564 | 19625 | |
| 18565 | | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19626 | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 18566 | 19627 | assert(fn_type_id->return_type != nullptr); |
| 18567 | 19628 | assert(parent_fn_entry != nullptr); |
| 18568 | 19629 | if (fn_type_can_fail(fn_type_id)) { |
| ... | ... | @@ -18570,46 +19631,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18570 | 19631 | } |
| 18571 | 19632 | |
| 18572 | 19633 | |
| 18573 | | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 19634 | IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count); |
| 18574 | 19635 | size_t next_arg_index = 0; |
| 18575 | 19636 | if (first_arg_ptr) { |
| 18576 | 19637 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 18577 | 19638 | |
| 18578 | 19639 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 18579 | 19640 | if (type_is_invalid(param_type)) |
| 18580 | | return ira->codegen->invalid_instruction; |
| 19641 | return ira->codegen->invalid_inst_gen; |
| 18581 | 19642 | |
| 18582 | | IrInstruction *first_arg; |
| 19643 | IrInstGen *first_arg; |
| 18583 | 19644 | if (param_type->id == ZigTypeIdPointer && |
| 18584 | 19645 | handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) |
| 18585 | 19646 | { |
| 18586 | 19647 | first_arg = first_arg_ptr; |
| 18587 | 19648 | } else { |
| 18588 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19649 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18589 | 19650 | if (type_is_invalid(first_arg->value->type)) |
| 18590 | | return ira->codegen->invalid_instruction; |
| 19651 | return ira->codegen->invalid_inst_gen; |
| 18591 | 19652 | } |
| 18592 | 19653 | |
| 18593 | | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 19654 | IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type); |
| 18594 | 19655 | if (type_is_invalid(casted_arg->value->type)) |
| 18595 | | return ira->codegen->invalid_instruction; |
| 19656 | return ira->codegen->invalid_inst_gen; |
| 18596 | 19657 | |
| 18597 | 19658 | casted_args[next_arg_index] = casted_arg; |
| 18598 | 19659 | next_arg_index += 1; |
| 18599 | 19660 | } |
| 18600 | 19661 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18601 | | IrInstruction *old_arg = args_ptr[call_i]; |
| 19662 | IrInstGen *old_arg = args_ptr[call_i]; |
| 18602 | 19663 | if (type_is_invalid(old_arg->value->type)) |
| 18603 | | return ira->codegen->invalid_instruction; |
| 19664 | return ira->codegen->invalid_inst_gen; |
| 18604 | 19665 | |
| 18605 | | IrInstruction *casted_arg; |
| 19666 | IrInstGen *casted_arg; |
| 18606 | 19667 | if (next_arg_index < src_param_count) { |
| 18607 | 19668 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 18608 | 19669 | if (type_is_invalid(param_type)) |
| 18609 | | return ira->codegen->invalid_instruction; |
| 19670 | return ira->codegen->invalid_inst_gen; |
| 18610 | 19671 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 18611 | 19672 | if (type_is_invalid(casted_arg->value->type)) |
| 18612 | | return ira->codegen->invalid_instruction; |
| 19673 | return ira->codegen->invalid_inst_gen; |
| 18613 | 19674 | } else { |
| 18614 | 19675 | casted_arg = old_arg; |
| 18615 | 19676 | } |
| ... | ... | @@ -18622,21 +19683,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18622 | 19683 | |
| 18623 | 19684 | ZigType *return_type = fn_type_id->return_type; |
| 18624 | 19685 | if (type_is_invalid(return_type)) |
| 18625 | | return ira->codegen->invalid_instruction; |
| 19686 | return ira->codegen->invalid_inst_gen; |
| 18626 | 19687 | |
| 18627 | 19688 | if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) { |
| 18628 | 19689 | ir_add_error(ira, source_instr, |
| 18629 | 19690 | buf_sprintf("no-inline call of inline function")); |
| 18630 | | return ira->codegen->invalid_instruction; |
| 19691 | return ira->codegen->invalid_inst_gen; |
| 18631 | 19692 | } |
| 18632 | 19693 | |
| 18633 | | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 19694 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src, |
| 18634 | 19695 | is_async_call_builtin, fn_entry); |
| 18635 | 19696 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 18636 | | return ira->codegen->invalid_instruction; |
| 19697 | return ira->codegen->invalid_inst_gen; |
| 18637 | 19698 | |
| 18638 | 19699 | if (modifier == CallModifierAsync) { |
| 18639 | | IrInstruction *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref, |
| 19700 | IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref, |
| 18640 | 19701 | casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc); |
| 18641 | 19702 | return ir_finish_anal(ira, result); |
| 18642 | 19703 | } |
| ... | ... | @@ -18645,16 +19706,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18645 | 19706 | parent_fn_entry->inferred_async_node == nullptr && |
| 18646 | 19707 | modifier != CallModifierNoAsync) |
| 18647 | 19708 | { |
| 18648 | | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 19709 | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 18649 | 19710 | parent_fn_entry->inferred_async_fn = fn_entry; |
| 18650 | 19711 | } |
| 18651 | 19712 | |
| 18652 | | IrInstruction *result_loc; |
| 19713 | IrInstGen *result_loc; |
| 18653 | 19714 | if (handle_is_ptr(return_type)) { |
| 18654 | 19715 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18655 | | return_type, nullptr, true, true, false); |
| 19716 | return_type, nullptr, true, false); |
| 18656 | 19717 | if (result_loc != nullptr) { |
| 18657 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 19718 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18658 | 19719 | return result_loc; |
| 18659 | 19720 | } |
| 18660 | 19721 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| ... | ... | @@ -18670,12 +19731,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18670 | 19731 | result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin, |
| 18671 | 19732 | args_ptr, args_len, ret_ptr); |
| 18672 | 19733 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 18673 | | return ira->codegen->invalid_instruction; |
| 19734 | return ira->codegen->invalid_inst_gen; |
| 18674 | 19735 | } else { |
| 18675 | 19736 | result_loc = nullptr; |
| 18676 | 19737 | } |
| 18677 | 19738 | |
| 18678 | | IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 19739 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 18679 | 19740 | call_param_count, casted_args, modifier, casted_new_stack, |
| 18680 | 19741 | is_async_call_builtin, result_loc, return_type); |
| 18681 | 19742 | if (get_scope_typeof(source_instr->scope) == nullptr) { |
| ... | ... | @@ -18684,62 +19745,65 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18684 | 19745 | return ir_finish_anal(ira, &new_call_instruction->base); |
| 18685 | 19746 | } |
| 18686 | 19747 | |
| 18687 | | static IrInstruction *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, |
| 18688 | | ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, |
| 18689 | | IrInstruction *first_arg_ptr, CallModifier modifier) |
| 19748 | static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction, |
| 19749 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19750 | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier) |
| 18690 | 19751 | { |
| 18691 | | IrInstruction *new_stack = nullptr; |
| 19752 | IrInstGen *new_stack = nullptr; |
| 19753 | IrInst *new_stack_src = nullptr; |
| 18692 | 19754 | if (call_instruction->new_stack) { |
| 18693 | 19755 | new_stack = call_instruction->new_stack->child; |
| 18694 | 19756 | if (type_is_invalid(new_stack->value->type)) |
| 18695 | | return ira->codegen->invalid_instruction; |
| 19757 | return ira->codegen->invalid_inst_gen; |
| 19758 | new_stack_src = &call_instruction->new_stack->base; |
| 18696 | 19759 | } |
| 18697 | | IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *"); |
| 19760 | IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *"); |
| 18698 | 19761 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 18699 | 19762 | args_ptr[i] = call_instruction->args[i]->child; |
| 18700 | 19763 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18701 | | return ira->codegen->invalid_instruction; |
| 19764 | return ira->codegen->invalid_inst_gen; |
| 18702 | 19765 | } |
| 18703 | | IrInstruction *ret_ptr = nullptr; |
| 19766 | IrInstGen *ret_ptr = nullptr; |
| 18704 | 19767 | if (call_instruction->ret_ptr != nullptr) { |
| 18705 | 19768 | ret_ptr = call_instruction->ret_ptr->child; |
| 18706 | 19769 | if (type_is_invalid(ret_ptr->value->type)) |
| 18707 | | return ira->codegen->invalid_instruction; |
| 19770 | return ira->codegen->invalid_inst_gen; |
| 18708 | 19771 | } |
| 18709 | | IrInstruction *result = ir_analyze_fn_call(ira, &call_instruction->base, fn_entry, fn_type, fn_ref, |
| 18710 | | first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin, |
| 18711 | | args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc); |
| 18712 | | deallocate(args_ptr, call_instruction->arg_count, "IrInstruction *"); |
| 19772 | IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref, |
| 19773 | first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src, |
| 19774 | call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr, |
| 19775 | call_instruction->result_loc); |
| 19776 | deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *"); |
| 18713 | 19777 | return result; |
| 18714 | 19778 | } |
| 18715 | 19779 | |
| 18716 | | static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *source_instr, |
| 18717 | | IrInstruction *pass1_options, IrInstruction *pass1_fn_ref, IrInstruction **args_ptr, size_t args_len, |
| 19780 | static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19781 | IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len, |
| 18718 | 19782 | ResultLoc *result_loc) |
| 18719 | 19783 | { |
| 18720 | | IrInstruction *options = pass1_options->child; |
| 19784 | IrInstGen *options = pass1_options->child; |
| 18721 | 19785 | if (type_is_invalid(options->value->type)) |
| 18722 | | return ira->codegen->invalid_instruction; |
| 19786 | return ira->codegen->invalid_inst_gen; |
| 18723 | 19787 | |
| 18724 | | IrInstruction *fn_ref = pass1_fn_ref->child; |
| 19788 | IrInstGen *fn_ref = pass1_fn_ref->child; |
| 18725 | 19789 | if (type_is_invalid(fn_ref->value->type)) |
| 18726 | | return ira->codegen->invalid_instruction; |
| 19790 | return ira->codegen->invalid_inst_gen; |
| 18727 | 19791 | |
| 18728 | 19792 | TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier")); |
| 18729 | 19793 | ir_assert(modifier_field != nullptr, source_instr); |
| 18730 | | IrInstruction *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field); |
| 19794 | IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field); |
| 18731 | 19795 | ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad); |
| 18732 | 19796 | if (modifier_val == nullptr) |
| 18733 | | return ira->codegen->invalid_instruction; |
| 19797 | return ira->codegen->invalid_inst_gen; |
| 18734 | 19798 | CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag); |
| 18735 | 19799 | |
| 18736 | | if (ir_should_inline(ira->new_irb.exec, source_instr->scope)) { |
| 19800 | if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) { |
| 18737 | 19801 | switch (modifier) { |
| 18738 | 19802 | case CallModifierBuiltin: |
| 18739 | 19803 | zig_unreachable(); |
| 18740 | 19804 | case CallModifierAsync: |
| 18741 | 19805 | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier")); |
| 18742 | | return ira->codegen->invalid_instruction; |
| 19806 | return ira->codegen->invalid_inst_gen; |
| 18743 | 19807 | case CallModifierCompileTime: |
| 18744 | 19808 | case CallModifierNone: |
| 18745 | 19809 | case CallModifierAlwaysInline: |
| ... | ... | @@ -18750,23 +19814,25 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18750 | 19814 | case CallModifierNeverInline: |
| 18751 | 19815 | ir_add_error(ira, source_instr, |
| 18752 | 19816 | buf_sprintf("unable to perform 'never_inline' call at compile-time")); |
| 18753 | | return ira->codegen->invalid_instruction; |
| 19817 | return ira->codegen->invalid_inst_gen; |
| 18754 | 19818 | case CallModifierNeverTail: |
| 18755 | 19819 | ir_add_error(ira, source_instr, |
| 18756 | 19820 | buf_sprintf("unable to perform 'never_tail' call at compile-time")); |
| 18757 | | return ira->codegen->invalid_instruction; |
| 19821 | return ira->codegen->invalid_inst_gen; |
| 18758 | 19822 | } |
| 18759 | 19823 | } |
| 18760 | 19824 | |
| 18761 | | IrInstruction *first_arg_ptr = nullptr; |
| 19825 | IrInstGen *first_arg_ptr = nullptr; |
| 19826 | IrInst *first_arg_ptr_src = nullptr; |
| 18762 | 19827 | ZigFn *fn = nullptr; |
| 18763 | 19828 | if (instr_is_comptime(fn_ref)) { |
| 18764 | 19829 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 18765 | 19830 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 18766 | 19831 | fn = fn_ref->value->data.x_bound_fn.fn; |
| 18767 | 19832 | first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 19833 | first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src; |
| 18768 | 19834 | if (type_is_invalid(first_arg_ptr->value->type)) |
| 18769 | | return ira->codegen->invalid_instruction; |
| 19835 | return ira->codegen->invalid_inst_gen; |
| 18770 | 19836 | } else { |
| 18771 | 19837 | fn = ir_resolve_fn(ira, fn_ref); |
| 18772 | 19838 | } |
| ... | ... | @@ -18778,9 +19844,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18778 | 19844 | case CallModifierAlwaysInline: |
| 18779 | 19845 | case CallModifierAsync: |
| 18780 | 19846 | if (fn == nullptr) { |
| 18781 | | ir_add_error(ira, modifier_inst, |
| 19847 | ir_add_error(ira, &modifier_inst->base, |
| 18782 | 19848 | buf_sprintf("the specified modifier requires a comptime-known function")); |
| 18783 | | return ira->codegen->invalid_instruction; |
| 19849 | return ira->codegen->invalid_inst_gen; |
| 18784 | 19850 | } |
| 18785 | 19851 | default: |
| 18786 | 19852 | break; |
| ... | ... | @@ -18790,120 +19856,121 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18790 | 19856 | |
| 18791 | 19857 | TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack")); |
| 18792 | 19858 | ir_assert(stack_field != nullptr, source_instr); |
| 18793 | | IrInstruction *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field); |
| 19859 | IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field); |
| 18794 | 19860 | if (type_is_invalid(opt_stack->value->type)) |
| 18795 | | return ira->codegen->invalid_instruction; |
| 19861 | return ira->codegen->invalid_inst_gen; |
| 18796 | 19862 | |
| 18797 | | IrInstruction *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack); |
| 19863 | IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack); |
| 18798 | 19864 | bool stack_is_non_null; |
| 18799 | 19865 | if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null)) |
| 18800 | | return ira->codegen->invalid_instruction; |
| 19866 | return ira->codegen->invalid_inst_gen; |
| 18801 | 19867 | |
| 18802 | | IrInstruction *stack = nullptr; |
| 19868 | IrInstGen *stack = nullptr; |
| 18803 | 19869 | if (stack_is_non_null) { |
| 18804 | 19870 | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); |
| 18805 | 19871 | if (type_is_invalid(stack->value->type)) |
| 18806 | | return ira->codegen->invalid_instruction; |
| 19872 | return ira->codegen->invalid_inst_gen; |
| 18807 | 19873 | } |
| 18808 | 19874 | |
| 18809 | | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, |
| 18810 | | modifier, stack, false, args_ptr, args_len, nullptr, result_loc); |
| 19875 | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 19876 | modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc); |
| 18811 | 19877 | } |
| 18812 | 19878 | |
| 18813 | | static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) { |
| 18814 | | IrInstruction *args = instruction->args->child; |
| 19879 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { |
| 19880 | IrInstGen *args = instruction->args->child; |
| 18815 | 19881 | ZigType *args_type = args->value->type; |
| 18816 | 19882 | if (type_is_invalid(args_type)) |
| 18817 | | return ira->codegen->invalid_instruction; |
| 19883 | return ira->codegen->invalid_inst_gen; |
| 18818 | 19884 | |
| 18819 | 19885 | if (args_type->id != ZigTypeIdStruct) { |
| 18820 | | ir_add_error(ira, args, |
| 19886 | ir_add_error(ira, &args->base, |
| 18821 | 19887 | buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name))); |
| 18822 | | return ira->codegen->invalid_instruction; |
| 19888 | return ira->codegen->invalid_inst_gen; |
| 18823 | 19889 | } |
| 18824 | 19890 | |
| 18825 | | IrInstruction **args_ptr = nullptr; |
| 19891 | IrInstGen **args_ptr = nullptr; |
| 18826 | 19892 | size_t args_len = 0; |
| 18827 | 19893 | |
| 18828 | 19894 | if (is_tuple(args_type)) { |
| 18829 | 19895 | args_len = args_type->data.structure.src_field_count; |
| 18830 | | args_ptr = allocate<IrInstruction *>(args_len, "IrInstruction *"); |
| 19896 | args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *"); |
| 18831 | 19897 | for (size_t i = 0; i < args_len; i += 1) { |
| 18832 | 19898 | TypeStructField *arg_field = args_type->data.structure.fields[i]; |
| 18833 | | args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base, args, arg_field); |
| 19899 | args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field); |
| 18834 | 19900 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18835 | | return ira->codegen->invalid_instruction; |
| 19901 | return ira->codegen->invalid_inst_gen; |
| 18836 | 19902 | } |
| 18837 | 19903 | } else { |
| 18838 | | ir_add_error(ira, args, buf_sprintf("TODO: struct args")); |
| 18839 | | return ira->codegen->invalid_instruction; |
| 19904 | ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args")); |
| 19905 | return ira->codegen->invalid_inst_gen; |
| 18840 | 19906 | } |
| 18841 | | IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options, |
| 19907 | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 18842 | 19908 | instruction->fn_ref, args_ptr, args_len, instruction->result_loc); |
| 18843 | | deallocate(args_ptr, args_len, "IrInstruction *"); |
| 19909 | deallocate(args_ptr, args_len, "IrInstGen *"); |
| 18844 | 19910 | return result; |
| 18845 | 19911 | } |
| 18846 | 19912 | |
| 18847 | | static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) { |
| 18848 | | IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *"); |
| 19913 | static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) { |
| 19914 | IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *"); |
| 18849 | 19915 | for (size_t i = 0; i < instruction->args_len; i += 1) { |
| 18850 | 19916 | args_ptr[i] = instruction->args_ptr[i]->child; |
| 18851 | 19917 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18852 | | return ira->codegen->invalid_instruction; |
| 19918 | return ira->codegen->invalid_inst_gen; |
| 18853 | 19919 | } |
| 18854 | 19920 | |
| 18855 | | IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options, |
| 19921 | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 18856 | 19922 | instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc); |
| 18857 | | deallocate(args_ptr, instruction->args_len, "IrInstruction *"); |
| 19923 | deallocate(args_ptr, instruction->args_len, "IrInstGen *"); |
| 18858 | 19924 | return result; |
| 18859 | 19925 | } |
| 18860 | 19926 | |
| 18861 | | static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) { |
| 18862 | | IrInstruction *fn_ref = call_instruction->fn_ref->child; |
| 19927 | static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) { |
| 19928 | IrInstGen *fn_ref = call_instruction->fn_ref->child; |
| 18863 | 19929 | if (type_is_invalid(fn_ref->value->type)) |
| 18864 | | return ira->codegen->invalid_instruction; |
| 19930 | return ira->codegen->invalid_inst_gen; |
| 18865 | 19931 | |
| 18866 | 19932 | bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) || |
| 18867 | | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 19933 | ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope); |
| 18868 | 19934 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 18869 | 19935 | |
| 18870 | 19936 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 18871 | 19937 | if (fn_ref->value->type->id == ZigTypeIdMetaType) { |
| 18872 | 19938 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 18873 | 19939 | if (ty == nullptr) |
| 18874 | | return ira->codegen->invalid_instruction; |
| 18875 | | ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node, |
| 19940 | return ira->codegen->invalid_inst_gen; |
| 19941 | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, |
| 18876 | 19942 | buf_sprintf("type '%s' not a function", buf_ptr(&ty->name))); |
| 18877 | | add_error_note(ira->codegen, msg, call_instruction->base.source_node, |
| 19943 | add_error_note(ira->codegen, msg, call_instruction->base.base.source_node, |
| 18878 | 19944 | buf_sprintf("use @as builtin for type coercion")); |
| 18879 | | return ira->codegen->invalid_instruction; |
| 19945 | return ira->codegen->invalid_inst_gen; |
| 18880 | 19946 | } else if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 18881 | 19947 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 18882 | 19948 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type; |
| 18883 | 19949 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 18884 | 19950 | return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_type, |
| 18885 | | fn_ref, nullptr, modifier); |
| 19951 | fn_ref, nullptr, nullptr, modifier); |
| 18886 | 19952 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 18887 | 19953 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 18888 | 19954 | ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn; |
| 18889 | | IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 19955 | IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 19956 | IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src; |
| 18890 | 19957 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 18891 | 19958 | return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 18892 | | fn_ref, first_arg_ptr, modifier); |
| 19959 | fn_ref, first_arg_ptr, first_arg_ptr_src, modifier); |
| 18893 | 19960 | } else { |
| 18894 | | ir_add_error_node(ira, fn_ref->source_node, |
| 19961 | ir_add_error(ira, &fn_ref->base, |
| 18895 | 19962 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 18896 | | return ira->codegen->invalid_instruction; |
| 19963 | return ira->codegen->invalid_inst_gen; |
| 18897 | 19964 | } |
| 18898 | 19965 | } |
| 18899 | 19966 | |
| 18900 | 19967 | if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 18901 | 19968 | return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type, |
| 18902 | | fn_ref, nullptr, modifier); |
| 19969 | fn_ref, nullptr, nullptr, modifier); |
| 18903 | 19970 | } else { |
| 18904 | | ir_add_error_node(ira, fn_ref->source_node, |
| 19971 | ir_add_error(ira, &fn_ref->base, |
| 18905 | 19972 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 18906 | | return ira->codegen->invalid_instruction; |
| 19973 | return ira->codegen->invalid_inst_gen; |
| 18907 | 19974 | } |
| 18908 | 19975 | } |
| 18909 | 19976 | |
| ... | ... | @@ -18992,8 +20059,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 18992 | 20059 | zig_unreachable(); |
| 18993 | 20060 | } |
| 18994 | 20061 | |
| 18995 | | static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 18996 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 20062 | static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 20063 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 18997 | 20064 | result->value->special = ConstValSpecialLazy; |
| 18998 | 20065 | |
| 18999 | 20066 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType"); |
| ... | ... | @@ -19003,12 +20070,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp |
| 19003 | 20070 | |
| 19004 | 20071 | lazy_opt_type->payload_type = instruction->value->child; |
| 19005 | 20072 | if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr) |
| 19006 | | return ira->codegen->invalid_instruction; |
| 20073 | return ira->codegen->invalid_inst_gen; |
| 19007 | 20074 | |
| 19008 | 20075 | return result; |
| 19009 | 20076 | } |
| 19010 | 20077 | |
| 19011 | | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type, |
| 20078 | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type, |
| 19012 | 20079 | ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op) |
| 19013 | 20080 | { |
| 19014 | 20081 | bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat); |
| ... | ... | @@ -19043,19 +20110,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i |
| 19043 | 20110 | return nullptr; |
| 19044 | 20111 | } |
| 19045 | 20112 | |
| 19046 | | static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 19047 | | IrInstruction *value = instruction->value->child; |
| 20113 | static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 20114 | IrInstGen *value = instruction->value->child; |
| 19048 | 20115 | ZigType *expr_type = value->value->type; |
| 19049 | 20116 | if (type_is_invalid(expr_type)) |
| 19050 | | return ira->codegen->invalid_instruction; |
| 20117 | return ira->codegen->invalid_inst_gen; |
| 19051 | 20118 | |
| 19052 | 20119 | if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt || |
| 19053 | 20120 | expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat || |
| 19054 | 20121 | expr_type->id == ZigTypeIdVector)) |
| 19055 | 20122 | { |
| 19056 | | ir_add_error(ira, &instruction->base, |
| 20123 | ir_add_error(ira, &instruction->base.base, |
| 19057 | 20124 | buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name))); |
| 19058 | | return ira->codegen->invalid_instruction; |
| 20125 | return ira->codegen->invalid_inst_gen; |
| 19059 | 20126 | } |
| 19060 | 20127 | |
| 19061 | 20128 | bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap); |
| ... | ... | @@ -19065,9 +20132,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 19065 | 20132 | if (instr_is_comptime(value)) { |
| 19066 | 20133 | ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad); |
| 19067 | 20134 | if (!operand_val) |
| 19068 | | return ira->codegen->invalid_instruction; |
| 20135 | return ira->codegen->invalid_inst_gen; |
| 19069 | 20136 | |
| 19070 | | IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type); |
| 20137 | IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type); |
| 19071 | 20138 | ZigValue *out_val = result_instruction->value; |
| 19072 | 20139 | if (expr_type->id == ZigTypeIdVector) { |
| 19073 | 20140 | expand_undef_array(ira->codegen, operand_val); |
| ... | ... | @@ -19079,63 +20146,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 19079 | 20146 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 19080 | 20147 | assert(scalar_operand_val->type == scalar_type); |
| 19081 | 20148 | assert(scalar_out_val->type == scalar_type); |
| 19082 | | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type, |
| 20149 | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, |
| 19083 | 20150 | scalar_operand_val, scalar_out_val, is_wrap_op); |
| 19084 | 20151 | if (msg != nullptr) { |
| 19085 | | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 20152 | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 19086 | 20153 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 19087 | | return ira->codegen->invalid_instruction; |
| 20154 | return ira->codegen->invalid_inst_gen; |
| 19088 | 20155 | } |
| 19089 | 20156 | } |
| 19090 | 20157 | out_val->type = expr_type; |
| 19091 | 20158 | out_val->special = ConstValSpecialStatic; |
| 19092 | 20159 | } else { |
| 19093 | | if (ir_eval_negation_scalar(ira, &instruction->base, scalar_type, operand_val, out_val, |
| 20160 | if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val, |
| 19094 | 20161 | is_wrap_op) != nullptr) |
| 19095 | 20162 | { |
| 19096 | | return ira->codegen->invalid_instruction; |
| 20163 | return ira->codegen->invalid_inst_gen; |
| 19097 | 20164 | } |
| 19098 | 20165 | } |
| 19099 | 20166 | return result_instruction; |
| 19100 | 20167 | } |
| 19101 | 20168 | |
| 19102 | | IrInstruction *result = ir_build_un_op(&ira->new_irb, |
| 19103 | | instruction->base.scope, instruction->base.source_node, |
| 19104 | | instruction->op_id, value); |
| 19105 | | result->value->type = expr_type; |
| 19106 | | return result; |
| 20169 | if (is_wrap_op) { |
| 20170 | return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type); |
| 20171 | } else { |
| 20172 | return ir_build_negation(ira, &instruction->base.base, value, expr_type); |
| 20173 | } |
| 19107 | 20174 | } |
| 19108 | 20175 | |
| 19109 | | static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 19110 | | IrInstruction *value = instruction->value->child; |
| 20176 | static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 20177 | IrInstGen *value = instruction->value->child; |
| 19111 | 20178 | ZigType *expr_type = value->value->type; |
| 19112 | 20179 | if (type_is_invalid(expr_type)) |
| 19113 | | return ira->codegen->invalid_instruction; |
| 20180 | return ira->codegen->invalid_inst_gen; |
| 19114 | 20181 | |
| 19115 | 20182 | if (expr_type->id == ZigTypeIdInt) { |
| 19116 | 20183 | if (instr_is_comptime(value)) { |
| 19117 | 20184 | ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 19118 | 20185 | if (target_const_val == nullptr) |
| 19119 | | return ira->codegen->invalid_instruction; |
| 20186 | return ira->codegen->invalid_inst_gen; |
| 19120 | 20187 | |
| 19121 | | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 20188 | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 19122 | 20189 | bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint, |
| 19123 | 20190 | expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); |
| 19124 | 20191 | return result; |
| 19125 | 20192 | } |
| 19126 | 20193 | |
| 19127 | | IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, |
| 19128 | | instruction->base.source_node, IrUnOpBinNot, value); |
| 19129 | | result->value->type = expr_type; |
| 19130 | | return result; |
| 20194 | return ir_build_binary_not(ira, &instruction->base.base, value, expr_type); |
| 19131 | 20195 | } |
| 19132 | 20196 | |
| 19133 | | ir_add_error(ira, &instruction->base, |
| 20197 | ir_add_error(ira, &instruction->base.base, |
| 19134 | 20198 | buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); |
| 19135 | | return ira->codegen->invalid_instruction; |
| 20199 | return ira->codegen->invalid_inst_gen; |
| 19136 | 20200 | } |
| 19137 | 20201 | |
| 19138 | | static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 20202 | static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 19139 | 20203 | IrUnOp op_id = instruction->op_id; |
| 19140 | 20204 | switch (op_id) { |
| 19141 | 20205 | case IrUnOpInvalid: |
| ... | ... | @@ -19146,26 +20210,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 19146 | 20210 | case IrUnOpNegationWrap: |
| 19147 | 20211 | return ir_analyze_negation(ira, instruction); |
| 19148 | 20212 | case IrUnOpDereference: { |
| 19149 | | IrInstruction *ptr = instruction->value->child; |
| 20213 | IrInstGen *ptr = instruction->value->child; |
| 19150 | 20214 | if (type_is_invalid(ptr->value->type)) |
| 19151 | | return ira->codegen->invalid_instruction; |
| 20215 | return ira->codegen->invalid_inst_gen; |
| 19152 | 20216 | ZigType *ptr_type = ptr->value->type; |
| 19153 | 20217 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 19154 | | ir_add_error_node(ira, instruction->base.source_node, |
| 20218 | ir_add_error_node(ira, instruction->base.base.source_node, |
| 19155 | 20219 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| 19156 | 20220 | buf_ptr(&ptr_type->name))); |
| 19157 | | return ira->codegen->invalid_instruction; |
| 20221 | return ira->codegen->invalid_inst_gen; |
| 19158 | 20222 | } |
| 19159 | 20223 | |
| 19160 | | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr, instruction->result_loc); |
| 19161 | | if (result == ira->codegen->invalid_instruction) |
| 19162 | | return ira->codegen->invalid_instruction; |
| 20224 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc); |
| 20225 | if (type_is_invalid(result->value->type)) |
| 20226 | return ira->codegen->invalid_inst_gen; |
| 19163 | 20227 | |
| 19164 | 20228 | // If the result needs to be an lvalue, type check it |
| 19165 | 20229 | if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) { |
| 19166 | | ir_add_error(ira, &instruction->base, |
| 20230 | ir_add_error(ira, &instruction->base.base, |
| 19167 | 20231 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); |
| 19168 | | return ira->codegen->invalid_instruction; |
| 20232 | return ira->codegen->invalid_inst_gen; |
| 19169 | 20233 | } |
| 19170 | 20234 | |
| 19171 | 20235 | return result; |
| ... | ... | @@ -19177,42 +20241,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 19177 | 20241 | } |
| 19178 | 20242 | |
| 19179 | 20243 | static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) { |
| 19180 | | IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index); |
| 20244 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index); |
| 19181 | 20245 | if (old_bb->in_resume_stack) return; |
| 19182 | 20246 | ira->resume_stack.append(pos); |
| 19183 | 20247 | old_bb->in_resume_stack = true; |
| 19184 | 20248 | } |
| 19185 | 20249 | |
| 19186 | | static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) { |
| 20250 | static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) { |
| 19187 | 20251 | if (ira->resume_stack.length != 0) { |
| 19188 | 20252 | ir_push_resume(ira, {old_bb->index, 0}); |
| 19189 | 20253 | } |
| 19190 | 20254 | } |
| 19191 | 20255 | |
| 19192 | | static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { |
| 19193 | | IrBasicBlock *old_dest_block = br_instruction->dest_block; |
| 20256 | static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) { |
| 20257 | IrBasicBlockSrc *old_dest_block = br_instruction->dest_block; |
| 19194 | 20258 | |
| 19195 | 20259 | bool is_comptime; |
| 19196 | 20260 | if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime)) |
| 19197 | 20261 | return ir_unreach_error(ira); |
| 19198 | 20262 | |
| 19199 | 20263 | if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr)) |
| 19200 | | return ir_inline_bb(ira, &br_instruction->base, old_dest_block); |
| 20264 | return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block); |
| 19201 | 20265 | |
| 19202 | | IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 20266 | IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base); |
| 19203 | 20267 | if (new_bb == nullptr) |
| 19204 | 20268 | return ir_unreach_error(ira); |
| 19205 | 20269 | |
| 19206 | 20270 | ir_push_resume_block(ira, old_dest_block); |
| 19207 | 20271 | |
| 19208 | | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 19209 | | br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr); |
| 19210 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20272 | IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb); |
| 19211 | 20273 | return ir_finish_anal(ira, result); |
| 19212 | 20274 | } |
| 19213 | 20275 | |
| 19214 | | static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 19215 | | IrInstruction *condition = cond_br_instruction->condition->child; |
| 20276 | static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) { |
| 20277 | IrInstGen *condition = cond_br_instruction->condition->child; |
| 19216 | 20278 | if (type_is_invalid(condition->value->type)) |
| 19217 | 20279 | return ir_unreach_error(ira); |
| 19218 | 20280 | |
| ... | ... | @@ -19221,7 +20283,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 19221 | 20283 | return ir_unreach_error(ira); |
| 19222 | 20284 | |
| 19223 | 20285 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 19224 | | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 20286 | IrInstGen *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 19225 | 20287 | if (type_is_invalid(casted_condition->value->type)) |
| 19226 | 20288 | return ir_unreach_error(ira); |
| 19227 | 20289 | |
| ... | ... | @@ -19230,67 +20292,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 19230 | 20292 | if (!ir_resolve_bool(ira, casted_condition, &cond_is_true)) |
| 19231 | 20293 | return ir_unreach_error(ira); |
| 19232 | 20294 | |
| 19233 | | IrBasicBlock *old_dest_block = cond_is_true ? |
| 20295 | IrBasicBlockSrc *old_dest_block = cond_is_true ? |
| 19234 | 20296 | cond_br_instruction->then_block : cond_br_instruction->else_block; |
| 19235 | 20297 | |
| 19236 | 20298 | if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr)) |
| 19237 | | return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block); |
| 20299 | return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block); |
| 19238 | 20300 | |
| 19239 | | IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base); |
| 20301 | IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base); |
| 19240 | 20302 | if (new_dest_block == nullptr) |
| 19241 | 20303 | return ir_unreach_error(ira); |
| 19242 | 20304 | |
| 19243 | 20305 | ir_push_resume_block(ira, old_dest_block); |
| 19244 | 20306 | |
| 19245 | | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 19246 | | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr); |
| 19247 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20307 | IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block); |
| 19248 | 20308 | return ir_finish_anal(ira, result); |
| 19249 | 20309 | } |
| 19250 | 20310 | |
| 19251 | 20311 | assert(cond_br_instruction->then_block != cond_br_instruction->else_block); |
| 19252 | | IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base); |
| 20312 | IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base); |
| 19253 | 20313 | if (new_then_block == nullptr) |
| 19254 | 20314 | return ir_unreach_error(ira); |
| 19255 | 20315 | |
| 19256 | | IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| 20316 | IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base); |
| 19257 | 20317 | if (new_else_block == nullptr) |
| 19258 | 20318 | return ir_unreach_error(ira); |
| 19259 | 20319 | |
| 19260 | 20320 | ir_push_resume_block(ira, cond_br_instruction->else_block); |
| 19261 | 20321 | ir_push_resume_block(ira, cond_br_instruction->then_block); |
| 19262 | 20322 | |
| 19263 | | IrInstruction *result = ir_build_cond_br(&ira->new_irb, |
| 19264 | | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, |
| 19265 | | casted_condition, new_then_block, new_else_block, nullptr); |
| 19266 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20323 | IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base, |
| 20324 | casted_condition, new_then_block, new_else_block); |
| 19267 | 20325 | return ir_finish_anal(ira, result); |
| 19268 | 20326 | } |
| 19269 | 20327 | |
| 19270 | | static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 19271 | | IrInstructionUnreachable *unreachable_instruction) |
| 20328 | static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 20329 | IrInstSrcUnreachable *unreachable_instruction) |
| 19272 | 20330 | { |
| 19273 | | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 19274 | | unreachable_instruction->base.scope, unreachable_instruction->base.source_node); |
| 19275 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20331 | IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base); |
| 19276 | 20332 | return ir_finish_anal(ira, result); |
| 19277 | 20333 | } |
| 19278 | 20334 | |
| 19279 | | static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { |
| 20335 | static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) { |
| 19280 | 20336 | Error err; |
| 19281 | 20337 | |
| 19282 | 20338 | if (ira->const_predecessor_bb) { |
| 19283 | 20339 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 19284 | | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| 20340 | IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i]; |
| 19285 | 20341 | if (predecessor != ira->const_predecessor_bb) |
| 19286 | 20342 | continue; |
| 19287 | | IrInstruction *value = phi_instruction->incoming_values[i]->child; |
| 20343 | IrInstGen *value = phi_instruction->incoming_values[i]->child; |
| 19288 | 20344 | assert(value->value->type); |
| 19289 | 20345 | if (type_is_invalid(value->value->type)) |
| 19290 | | return ira->codegen->invalid_instruction; |
| 20346 | return ira->codegen->invalid_inst_gen; |
| 19291 | 20347 | |
| 19292 | 20348 | if (value->value->special != ConstValSpecialRuntime) { |
| 19293 | | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 20349 | IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr); |
| 19294 | 20350 | copy_const_val(result->value, value->value); |
| 19295 | 20351 | return result; |
| 19296 | 20352 | } else { |
| ... | ... | @@ -19305,17 +20361,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19305 | 20361 | peer_parent->peers.length >= 2) |
| 19306 | 20362 | { |
| 19307 | 20363 | if (peer_parent->resolved_type == nullptr) { |
| 19308 | | IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length); |
| 20364 | IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length); |
| 19309 | 20365 | for (size_t i = 0; i < peer_parent->peers.length; i += 1) { |
| 19310 | 20366 | ResultLocPeer *this_peer = peer_parent->peers.at(i); |
| 19311 | 20367 | |
| 19312 | | IrInstruction *gen_instruction = this_peer->base.gen_instruction; |
| 20368 | IrInstGen *gen_instruction = this_peer->base.gen_instruction; |
| 19313 | 20369 | if (gen_instruction == nullptr) { |
| 19314 | 20370 | // unreachable instructions will cause implicit_elem_type to be null |
| 19315 | 20371 | if (this_peer->base.implicit_elem_type == nullptr) { |
| 19316 | | instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction); |
| 20372 | instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base); |
| 19317 | 20373 | } else { |
| 19318 | | instructions[i] = ir_const(ira, this_peer->base.source_instruction, |
| 20374 | instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base, |
| 19319 | 20375 | this_peer->base.implicit_elem_type); |
| 19320 | 20376 | instructions[i]->value->special = ConstValSpecialRuntime; |
| 19321 | 20377 | } |
| ... | ... | @@ -19324,34 +20380,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19324 | 20380 | } |
| 19325 | 20381 | |
| 19326 | 20382 | } |
| 19327 | | ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base, peer_parent->parent); |
| 20383 | ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent); |
| 19328 | 20384 | peer_parent->resolved_type = ir_resolve_peer_types(ira, |
| 19329 | | peer_parent->base.source_instruction->source_node, expected_type, instructions, |
| 20385 | peer_parent->base.source_instruction->base.source_node, expected_type, instructions, |
| 19330 | 20386 | peer_parent->peers.length); |
| 19331 | 20387 | if (type_is_invalid(peer_parent->resolved_type)) |
| 19332 | | return ira->codegen->invalid_instruction; |
| 20388 | return ira->codegen->invalid_inst_gen; |
| 19333 | 20389 | |
| 19334 | 20390 | // the logic below assumes there are no instructions in the new current basic block yet |
| 19335 | | ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base); |
| 20391 | ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base); |
| 19336 | 20392 | |
| 19337 | 20393 | // In case resolving the parent activates a suspend, do it now |
| 19338 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 19339 | | peer_parent->resolved_type, nullptr, false, false, true); |
| 20394 | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent, |
| 20395 | peer_parent->resolved_type, nullptr, false, true); |
| 19340 | 20396 | if (parent_result_loc != nullptr && |
| 19341 | | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) |
| 20397 | (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 19342 | 20398 | { |
| 19343 | 20399 | return parent_result_loc; |
| 19344 | 20400 | } |
| 19345 | 20401 | // If the above code generated any instructions in the current basic block, we need |
| 19346 | 20402 | // to move them to the peer parent predecessor. |
| 19347 | | ZigList<IrInstruction *> instrs_to_move = {}; |
| 20403 | ZigList<IrInstGen *> instrs_to_move = {}; |
| 19348 | 20404 | while (ira->new_irb.current_basic_block->instruction_list.length != 0) { |
| 19349 | 20405 | instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop()); |
| 19350 | 20406 | } |
| 19351 | 20407 | if (instrs_to_move.length != 0) { |
| 19352 | | IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 19353 | | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 19354 | | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base); |
| 20408 | IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 20409 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 20410 | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base); |
| 19355 | 20411 | while (instrs_to_move.length != 0) { |
| 19356 | 20412 | predecessor->instruction_list.append(instrs_to_move.pop()); |
| 19357 | 20413 | } |
| ... | ... | @@ -19360,7 +20416,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19360 | 20416 | } |
| 19361 | 20417 | |
| 19362 | 20418 | IrSuspendPosition suspend_pos; |
| 19363 | | ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos); |
| 20419 | ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos); |
| 19364 | 20420 | ir_push_resume(ira, suspend_pos); |
| 19365 | 20421 | |
| 19366 | 20422 | for (size_t i = 0; i < peer_parent->peers.length; i += 1) { |
| ... | ... | @@ -19376,34 +20432,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19376 | 20432 | return ira_resume(ira); |
| 19377 | 20433 | } |
| 19378 | 20434 | |
| 19379 | | ZigList<IrBasicBlock*> new_incoming_blocks = {0}; |
| 19380 | | ZigList<IrInstruction*> new_incoming_values = {0}; |
| 20435 | ZigList<IrBasicBlockGen*> new_incoming_blocks = {0}; |
| 20436 | ZigList<IrInstGen*> new_incoming_values = {0}; |
| 19381 | 20437 | |
| 19382 | 20438 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 19383 | | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| 20439 | IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i]; |
| 19384 | 20440 | if (predecessor->ref_count == 0) |
| 19385 | 20441 | continue; |
| 19386 | 20442 | |
| 19387 | 20443 | |
| 19388 | | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 20444 | IrInstSrc *old_value = phi_instruction->incoming_values[i]; |
| 19389 | 20445 | assert(old_value); |
| 19390 | | IrInstruction *new_value = old_value->child; |
| 19391 | | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 20446 | IrInstGen *new_value = old_value->child; |
| 20447 | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr) |
| 19392 | 20448 | continue; |
| 19393 | 20449 | |
| 19394 | 20450 | if (type_is_invalid(new_value->value->type)) |
| 19395 | | return ira->codegen->invalid_instruction; |
| 20451 | return ira->codegen->invalid_inst_gen; |
| 19396 | 20452 | |
| 19397 | 20453 | |
| 19398 | | assert(predecessor->other); |
| 19399 | | new_incoming_blocks.append(predecessor->other); |
| 20454 | assert(predecessor->child); |
| 20455 | new_incoming_blocks.append(predecessor->child); |
| 19400 | 20456 | new_incoming_values.append(new_value); |
| 19401 | 20457 | } |
| 19402 | 20458 | |
| 19403 | 20459 | if (new_incoming_blocks.length == 0) { |
| 19404 | | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 19405 | | phi_instruction->base.scope, phi_instruction->base.source_node); |
| 19406 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20460 | IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base); |
| 19407 | 20461 | return ir_finish_anal(ira, result); |
| 19408 | 20462 | } |
| 19409 | 20463 | |
| ... | ... | @@ -19415,7 +20469,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19415 | 20469 | if (peer_parent != nullptr) { |
| 19416 | 20470 | bool peer_parent_has_type; |
| 19417 | 20471 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| 19418 | | return ira->codegen->invalid_instruction; |
| 20472 | return ira->codegen->invalid_inst_gen; |
| 19419 | 20473 | if (peer_parent_has_type) { |
| 19420 | 20474 | if (peer_parent->parent->id == ResultLocIdReturn) { |
| 19421 | 20475 | resolved_type = ira->explicit_return_type; |
| ... | ... | @@ -19423,27 +20477,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19423 | 20477 | resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child); |
| 19424 | 20478 | } else if (peer_parent->parent->resolved_loc) { |
| 19425 | 20479 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; |
| 19426 | | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); |
| 20480 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base); |
| 19427 | 20481 | resolved_type = resolved_loc_ptr_type->data.pointer.child_type; |
| 19428 | 20482 | } |
| 19429 | 20483 | |
| 19430 | 20484 | if (resolved_type != nullptr && type_is_invalid(resolved_type)) |
| 19431 | | return ira->codegen->invalid_instruction; |
| 20485 | return ira->codegen->invalid_inst_gen; |
| 19432 | 20486 | } |
| 19433 | 20487 | } |
| 19434 | 20488 | |
| 19435 | 20489 | if (resolved_type == nullptr) { |
| 19436 | | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 20490 | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr, |
| 19437 | 20491 | new_incoming_values.items, new_incoming_values.length); |
| 19438 | 20492 | if (type_is_invalid(resolved_type)) |
| 19439 | | return ira->codegen->invalid_instruction; |
| 20493 | return ira->codegen->invalid_inst_gen; |
| 19440 | 20494 | } |
| 19441 | 20495 | |
| 19442 | 20496 | switch (type_has_one_possible_value(ira->codegen, resolved_type)) { |
| 19443 | 20497 | case OnePossibleValueInvalid: |
| 19444 | | return ira->codegen->invalid_instruction; |
| 20498 | return ira->codegen->invalid_inst_gen; |
| 19445 | 20499 | case OnePossibleValueYes: |
| 19446 | | return ir_const_move(ira, &phi_instruction->base, |
| 20500 | return ir_const_move(ira, &phi_instruction->base.base, |
| 19447 | 20501 | get_the_one_possible_value(ira->codegen, resolved_type)); |
| 19448 | 20502 | case OnePossibleValueNo: |
| 19449 | 20503 | break; |
| ... | ... | @@ -19451,11 +20505,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19451 | 20505 | |
| 19452 | 20506 | switch (type_requires_comptime(ira->codegen, resolved_type)) { |
| 19453 | 20507 | case ReqCompTimeInvalid: |
| 19454 | | return ira->codegen->invalid_instruction; |
| 20508 | return ira->codegen->invalid_inst_gen; |
| 19455 | 20509 | case ReqCompTimeYes: |
| 19456 | | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 20510 | ir_add_error(ira, &phi_instruction->base.base, |
| 19457 | 20511 | buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name))); |
| 19458 | | return ira->codegen->invalid_instruction; |
| 20512 | return ira->codegen->invalid_inst_gen; |
| 19459 | 20513 | case ReqCompTimeNo: |
| 19460 | 20514 | break; |
| 19461 | 20515 | } |
| ... | ... | @@ -19465,16 +20519,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19465 | 20519 | // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. |
| 19466 | 20520 | // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and |
| 19467 | 20521 | // then make sure the branch instruction is preserved. |
| 19468 | | IrBasicBlock *cur_bb = ira->new_irb.current_basic_block; |
| 20522 | IrBasicBlockGen *cur_bb = ira->new_irb.current_basic_block; |
| 19469 | 20523 | for (size_t i = 0; i < new_incoming_values.length; i += 1) { |
| 19470 | | IrInstruction *new_value = new_incoming_values.at(i); |
| 19471 | | IrBasicBlock *predecessor = new_incoming_blocks.at(i); |
| 19472 | | ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base); |
| 19473 | | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 19474 | | ir_set_cursor_at_end(&ira->new_irb, predecessor); |
| 19475 | | IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 20524 | IrInstGen *new_value = new_incoming_values.at(i); |
| 20525 | IrBasicBlockGen *predecessor = new_incoming_blocks.at(i); |
| 20526 | ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base); |
| 20527 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 20528 | ir_set_cursor_at_end_gen(&ira->new_irb, predecessor); |
| 20529 | IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 19476 | 20530 | if (type_is_invalid(casted_value->value->type)) { |
| 19477 | | return ira->codegen->invalid_instruction; |
| 20531 | return ira->codegen->invalid_inst_gen; |
| 19478 | 20532 | } |
| 19479 | 20533 | new_incoming_values.items[i] = casted_value; |
| 19480 | 20534 | predecessor->instruction_list.append(branch_instruction); |
| ... | ... | @@ -19485,12 +20539,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19485 | 20539 | all_stack_ptrs = false; |
| 19486 | 20540 | } |
| 19487 | 20541 | } |
| 19488 | | ir_set_cursor_at_end(&ira->new_irb, cur_bb); |
| 20542 | ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb); |
| 19489 | 20543 | |
| 19490 | | IrInstruction *result = ir_build_phi(&ira->new_irb, |
| 19491 | | phi_instruction->base.scope, phi_instruction->base.source_node, |
| 19492 | | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr); |
| 19493 | | result->value->type = resolved_type; |
| 20544 | IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base, |
| 20545 | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type); |
| 19494 | 20546 | |
| 19495 | 20547 | if (all_stack_ptrs) { |
| 19496 | 20548 | assert(result->value->special == ConstValSpecialRuntime); |
| ... | ... | @@ -19500,17 +20552,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19500 | 20552 | return result; |
| 19501 | 20553 | } |
| 19502 | 20554 | |
| 19503 | | static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 20555 | static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) { |
| 19504 | 20556 | ZigVar *var = instruction->var; |
| 19505 | | IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var); |
| 20557 | IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var); |
| 19506 | 20558 | if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) { |
| 19507 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 20559 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 19508 | 20560 | buf_sprintf("'%s' not accessible from inner function", var->name)); |
| 19509 | 20561 | add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node, |
| 19510 | 20562 | buf_sprintf("crossed function definition here")); |
| 19511 | 20563 | add_error_note(ira->codegen, msg, var->decl_node, |
| 19512 | 20564 | buf_sprintf("declared here")); |
| 19513 | | return ira->codegen->invalid_instruction; |
| 20565 | return ira->codegen->invalid_inst_gen; |
| 19514 | 20566 | } |
| 19515 | 20567 | return result; |
| 19516 | 20568 | } |
| ... | ... | @@ -19561,17 +20613,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 19561 | 20613 | ptr_type->data.pointer.allow_zero); |
| 19562 | 20614 | } |
| 19563 | 20615 | |
| 19564 | | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 20616 | static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemPtr *elem_ptr_instruction) { |
| 19565 | 20617 | Error err; |
| 19566 | | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 20618 | IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 19567 | 20619 | if (type_is_invalid(array_ptr->value->type)) |
| 19568 | | return ira->codegen->invalid_instruction; |
| 20620 | return ira->codegen->invalid_inst_gen; |
| 19569 | 20621 | |
| 19570 | 20622 | ZigValue *orig_array_ptr_val = array_ptr->value; |
| 19571 | 20623 | |
| 19572 | | IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; |
| 20624 | IrInstGen *elem_index = elem_ptr_instruction->elem_index->child; |
| 19573 | 20625 | if (type_is_invalid(elem_index->value->type)) |
| 19574 | | return ira->codegen->invalid_instruction; |
| 20626 | return ira->codegen->invalid_inst_gen; |
| 19575 | 20627 | |
| 19576 | 20628 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 19577 | 20629 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -19583,7 +20635,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19583 | 20635 | ZigType *return_type; |
| 19584 | 20636 | |
| 19585 | 20637 | if (type_is_invalid(array_type)) { |
| 19586 | | return ira->codegen->invalid_instruction; |
| 20638 | return ira->codegen->invalid_inst_gen; |
| 19587 | 20639 | } else if (array_type->id == ZigTypeIdArray || |
| 19588 | 20640 | (array_type->id == ZigTypeIdPointer && |
| 19589 | 20641 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| ... | ... | @@ -19594,15 +20646,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19594 | 20646 | ptr_type = ptr_type->data.pointer.child_type; |
| 19595 | 20647 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { |
| 19596 | 20648 | orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 19597 | | elem_ptr_instruction->base.source_node); |
| 20649 | elem_ptr_instruction->base.base.source_node); |
| 19598 | 20650 | if (orig_array_ptr_val == nullptr) |
| 19599 | | return ira->codegen->invalid_instruction; |
| 20651 | return ira->codegen->invalid_inst_gen; |
| 19600 | 20652 | } |
| 19601 | 20653 | } |
| 19602 | 20654 | if (array_type->data.array.len == 0) { |
| 19603 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20655 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19604 | 20656 | buf_sprintf("index 0 outside array of size 0")); |
| 19605 | | return ira->codegen->invalid_instruction; |
| 20657 | return ira->codegen->invalid_inst_gen; |
| 19606 | 20658 | } |
| 19607 | 20659 | ZigType *child_type = array_type->data.array.child_type; |
| 19608 | 20660 | if (ptr_type->data.pointer.host_int_bytes == 0) { |
| ... | ... | @@ -19613,7 +20665,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19613 | 20665 | } else { |
| 19614 | 20666 | uint64_t elem_val_scalar; |
| 19615 | 20667 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) |
| 19616 | | return ira->codegen->invalid_instruction; |
| 20668 | return ira->codegen->invalid_inst_gen; |
| 19617 | 20669 | |
| 19618 | 20670 | size_t bit_width = type_size_bits(ira->codegen, child_type); |
| 19619 | 20671 | size_t bit_offset = bit_width * elem_val_scalar; |
| ... | ... | @@ -19625,9 +20677,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19625 | 20677 | } |
| 19626 | 20678 | } else if (array_type->id == ZigTypeIdPointer) { |
| 19627 | 20679 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 19628 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20680 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19629 | 20681 | buf_sprintf("index of single-item pointer")); |
| 19630 | | return ira->codegen->invalid_instruction; |
| 20682 | return ira->codegen->invalid_inst_gen; |
| 19631 | 20683 | } |
| 19632 | 20684 | return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len); |
| 19633 | 20685 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -19641,38 +20693,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19641 | 20693 | array_type->data.structure.resolve_status == ResolveStatusBeingInferred) |
| 19642 | 20694 | { |
| 19643 | 20695 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 19644 | | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 20696 | IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 19645 | 20697 | if (type_is_invalid(casted_elem_index->value->type)) |
| 19646 | | return ira->codegen->invalid_instruction; |
| 19647 | | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base); |
| 20698 | return ira->codegen->invalid_inst_gen; |
| 20699 | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base); |
| 19648 | 20700 | Buf *field_name = buf_alloc(); |
| 19649 | 20701 | bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10); |
| 19650 | | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base, |
| 20702 | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base, |
| 19651 | 20703 | array_ptr, array_type); |
| 19652 | 20704 | } else if (is_tuple(array_type)) { |
| 19653 | 20705 | uint64_t elem_index_scalar; |
| 19654 | 20706 | if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar)) |
| 19655 | | return ira->codegen->invalid_instruction; |
| 20707 | return ira->codegen->invalid_inst_gen; |
| 19656 | 20708 | if (elem_index_scalar >= array_type->data.structure.src_field_count) { |
| 19657 | | ir_add_error(ira, &elem_ptr_instruction->base, buf_sprintf( |
| 20709 | ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf( |
| 19658 | 20710 | "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields", |
| 19659 | 20711 | elem_index_scalar, buf_ptr(&array_type->name), |
| 19660 | 20712 | array_type->data.structure.src_field_count)); |
| 19661 | | return ira->codegen->invalid_instruction; |
| 20713 | return ira->codegen->invalid_inst_gen; |
| 19662 | 20714 | } |
| 19663 | 20715 | TypeStructField *field = array_type->data.structure.fields[elem_index_scalar]; |
| 19664 | | return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base, field, array_ptr, |
| 20716 | return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr, |
| 19665 | 20717 | array_type, false); |
| 19666 | 20718 | } else { |
| 19667 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20719 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19668 | 20720 | buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name))); |
| 19669 | | return ira->codegen->invalid_instruction; |
| 20721 | return ira->codegen->invalid_inst_gen; |
| 19670 | 20722 | } |
| 19671 | 20723 | |
| 19672 | 20724 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 19673 | | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 19674 | | if (casted_elem_index == ira->codegen->invalid_instruction) |
| 19675 | | return ira->codegen->invalid_instruction; |
| 20725 | IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 20726 | if (type_is_invalid(casted_elem_index->value->type)) |
| 20727 | return ira->codegen->invalid_inst_gen; |
| 19676 | 20728 | |
| 19677 | 20729 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 19678 | 20730 | if (instr_is_comptime(casted_elem_index)) { |
| ... | ... | @@ -19681,15 +20733,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19681 | 20733 | uint64_t array_len = array_type->data.array.len; |
| 19682 | 20734 | if (index == array_len && array_type->data.array.sentinel != nullptr) { |
| 19683 | 20735 | ZigType *elem_type = array_type->data.array.child_type; |
| 19684 | | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); |
| 20736 | IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type); |
| 19685 | 20737 | copy_const_val(sentinel_elem->value, array_type->data.array.sentinel); |
| 19686 | | return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); |
| 20738 | return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false); |
| 19687 | 20739 | } |
| 19688 | 20740 | if (index >= array_len) { |
| 19689 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20741 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19690 | 20742 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, |
| 19691 | 20743 | index, array_len)); |
| 19692 | | return ira->codegen->invalid_instruction; |
| 20744 | return ira->codegen->invalid_inst_gen; |
| 19693 | 20745 | } |
| 19694 | 20746 | safety_check_on = false; |
| 19695 | 20747 | } |
| ... | ... | @@ -19705,7 +20757,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19705 | 20757 | // figure out the largest alignment possible |
| 19706 | 20758 | |
| 19707 | 20759 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 19708 | | return ira->codegen->invalid_instruction; |
| 20760 | return ira->codegen->invalid_inst_gen; |
| 19709 | 20761 | |
| 19710 | 20762 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 19711 | 20763 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| ... | ... | @@ -19729,15 +20781,17 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19729 | 20781 | return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align); |
| 19730 | 20782 | } |
| 19731 | 20783 | |
| 20784 | // TODO The `array_type->id == ZigTypeIdArray` exception here should not be an exception; |
| 20785 | // the `orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar` clause should be omitted completely. |
| 20786 | // However there are bugs to fix before this improvement can be made. |
| 19732 | 20787 | if (orig_array_ptr_val->special != ConstValSpecialRuntime && |
| 19733 | 20788 | orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 19734 | | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || |
| 19735 | | array_type->id == ZigTypeIdArray)) |
| 20789 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) |
| 19736 | 20790 | { |
| 19737 | 20791 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 19738 | | elem_ptr_instruction->base.source_node); |
| 20792 | elem_ptr_instruction->base.base.source_node); |
| 19739 | 20793 | if (array_ptr_val == nullptr) |
| 19740 | | return ira->codegen->invalid_instruction; |
| 20794 | return ira->codegen->invalid_inst_gen; |
| 19741 | 20795 | |
| 19742 | 20796 | if (array_ptr_val->special == ConstValSpecialUndef && |
| 19743 | 20797 | elem_ptr_instruction->init_array_type_source_node != nullptr) |
| ... | ... | @@ -19755,16 +20809,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19755 | 20809 | elem_val->parent.data.p_array.elem_index = i; |
| 19756 | 20810 | } |
| 19757 | 20811 | } else if (is_slice(array_type)) { |
| 19758 | | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 20812 | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base); |
| 19759 | 20813 | ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; |
| 19760 | 20814 | |
| 19761 | 20815 | if (type_is_invalid(actual_array_type)) |
| 19762 | | return ira->codegen->invalid_instruction; |
| 20816 | return ira->codegen->invalid_inst_gen; |
| 19763 | 20817 | if (actual_array_type->id != ZigTypeIdArray) { |
| 19764 | 20818 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 19765 | 20819 | buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'", |
| 19766 | 20820 | buf_ptr(&actual_array_type->name))); |
| 19767 | | return ira->codegen->invalid_instruction; |
| 20821 | return ira->codegen->invalid_inst_gen; |
| 19768 | 20822 | } |
| 19769 | 20823 | |
| 19770 | 20824 | ZigValue *array_init_val = create_const_vals(1); |
| ... | ... | @@ -19789,7 +20843,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19789 | 20843 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 19790 | 20844 | buf_sprintf("expected array type or [_], found '%s'", |
| 19791 | 20845 | buf_ptr(&array_type->name))); |
| 19792 | | return ira->codegen->invalid_instruction; |
| 20846 | return ira->codegen->invalid_inst_gen; |
| 19793 | 20847 | } |
| 19794 | 20848 | } |
| 19795 | 20849 | |
| ... | ... | @@ -19797,8 +20851,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19797 | 20851 | (array_type->id != ZigTypeIdPointer || |
| 19798 | 20852 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 19799 | 20853 | { |
| 20854 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 20855 | elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk))) |
| 20856 | { |
| 20857 | return ira->codegen->invalid_inst_gen; |
| 20858 | } |
| 19800 | 20859 | if (array_type->id == ZigTypeIdPointer) { |
| 19801 | | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 20860 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19802 | 20861 | ZigValue *out_val = result->value; |
| 19803 | 20862 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 19804 | 20863 | size_t new_index; |
| ... | ... | @@ -19867,33 +20926,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19867 | 20926 | zig_panic("TODO elem ptr on a null pointer"); |
| 19868 | 20927 | } |
| 19869 | 20928 | if (new_index >= mem_size) { |
| 19870 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20929 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19871 | 20930 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| 19872 | | return ira->codegen->invalid_instruction; |
| 20931 | return ira->codegen->invalid_inst_gen; |
| 19873 | 20932 | } |
| 19874 | 20933 | return result; |
| 19875 | 20934 | } else if (is_slice(array_type)) { |
| 19876 | 20935 | ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 19877 | | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base); |
| 20936 | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base); |
| 19878 | 20937 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 19879 | | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 19880 | | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, |
| 19881 | | elem_ptr_instruction->ptr_len, nullptr); |
| 19882 | | result->value->type = return_type; |
| 19883 | | return result; |
| 20938 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 20939 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false, |
| 20940 | return_type); |
| 19884 | 20941 | } |
| 19885 | 20942 | ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 19886 | | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 20943 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19887 | 20944 | ZigValue *out_val = result->value; |
| 19888 | 20945 | ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 19889 | 20946 | uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); |
| 19890 | 20947 | uint64_t full_slice_len = slice_len + |
| 19891 | 20948 | ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0); |
| 19892 | 20949 | if (index >= full_slice_len) { |
| 19893 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20950 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19894 | 20951 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 19895 | 20952 | index, slice_len)); |
| 19896 | | return ira->codegen->invalid_instruction; |
| 20953 | return ira->codegen->invalid_inst_gen; |
| 19897 | 20954 | } |
| 19898 | 20955 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 19899 | 20956 | switch (ptr_field->data.x_ptr.special) { |
| ... | ... | @@ -19913,7 +20970,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19913 | 20970 | { |
| 19914 | 20971 | ir_assert(new_index < |
| 19915 | 20972 | ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len, |
| 19916 | | &elem_ptr_instruction->base); |
| 20973 | &elem_ptr_instruction->base.base); |
| 19917 | 20974 | } |
| 19918 | 20975 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 19919 | 20976 | out_val->data.x_ptr.data.base_array.array_val = |
| ... | ... | @@ -19938,15 +20995,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19938 | 20995 | } |
| 19939 | 20996 | return result; |
| 19940 | 20997 | } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) { |
| 19941 | | IrInstruction *result; |
| 20998 | IrInstGen *result; |
| 19942 | 20999 | if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 19943 | | result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 19944 | | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, |
| 19945 | | false, elem_ptr_instruction->ptr_len, nullptr); |
| 19946 | | result->value->type = return_type; |
| 21000 | result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 21001 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, |
| 21002 | false, return_type); |
| 19947 | 21003 | result->value->special = ConstValSpecialStatic; |
| 19948 | 21004 | } else { |
| 19949 | | result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 21005 | result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19950 | 21006 | } |
| 19951 | 21007 | ZigValue *out_val = result->value; |
| 19952 | 21008 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| ... | ... | @@ -19972,19 +21028,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19972 | 21028 | // runtime known element index |
| 19973 | 21029 | switch (type_requires_comptime(ira->codegen, return_type)) { |
| 19974 | 21030 | case ReqCompTimeYes: |
| 19975 | | ir_add_error(ira, elem_index, |
| 21031 | ir_add_error(ira, &elem_index->base, |
| 19976 | 21032 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", |
| 19977 | 21033 | buf_ptr(&return_type->data.pointer.child_type->name))); |
| 19978 | | return ira->codegen->invalid_instruction; |
| 21034 | return ira->codegen->invalid_inst_gen; |
| 19979 | 21035 | case ReqCompTimeInvalid: |
| 19980 | | return ira->codegen->invalid_instruction; |
| 21036 | return ira->codegen->invalid_inst_gen; |
| 19981 | 21037 | case ReqCompTimeNo: |
| 19982 | 21038 | break; |
| 19983 | 21039 | } |
| 19984 | 21040 | |
| 19985 | 21041 | if (return_type->data.pointer.explicit_alignment != 0) { |
| 19986 | 21042 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 19987 | | return ira->codegen->invalid_instruction; |
| 21043 | return ira->codegen->invalid_inst_gen; |
| 19988 | 21044 | |
| 19989 | 21045 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 19990 | 21046 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| ... | ... | @@ -20002,16 +21058,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 20002 | 21058 | } |
| 20003 | 21059 | } |
| 20004 | 21060 | |
| 20005 | | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 20006 | | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, |
| 20007 | | elem_ptr_instruction->ptr_len, nullptr); |
| 20008 | | result->value->type = return_type; |
| 20009 | | return result; |
| 21061 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 21062 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type); |
| 20010 | 21063 | } |
| 20011 | 21064 | |
| 20012 | | static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20013 | | ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr, |
| 20014 | | IrInstruction *container_ptr, ZigType *container_type) |
| 21065 | static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 21066 | ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr, |
| 21067 | IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type) |
| 20015 | 21068 | { |
| 20016 | 21069 | if (!is_slice(bare_struct_type)) { |
| 20017 | 21070 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| ... | ... | @@ -20021,29 +21074,39 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20021 | 21074 | if (tld->id == TldIdFn) { |
| 20022 | 21075 | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 20023 | 21076 | if (tld->resolution == TldResolutionInvalid) |
| 20024 | | return ira->codegen->invalid_instruction; |
| 21077 | return ira->codegen->invalid_inst_gen; |
| 21078 | if (tld->resolution == TldResolutionResolving) |
| 21079 | return ir_error_dependency_loop(ira, source_instr); |
| 21080 | |
| 20025 | 21081 | TldFn *tld_fn = (TldFn *)tld; |
| 20026 | 21082 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 21083 | assert(fn_entry != nullptr); |
| 21084 | |
| 20027 | 21085 | if (type_is_invalid(fn_entry->type_entry)) |
| 20028 | | return ira->codegen->invalid_instruction; |
| 21086 | return ira->codegen->invalid_inst_gen; |
| 20029 | 21087 | |
| 20030 | | IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope, |
| 20031 | | source_instr->source_node, fn_entry, container_ptr); |
| 21088 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr, |
| 21089 | container_ptr_src); |
| 20032 | 21090 | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 20033 | 21091 | } else if (tld->id == TldIdVar) { |
| 20034 | 21092 | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 20035 | 21093 | if (tld->resolution == TldResolutionInvalid) |
| 20036 | | return ira->codegen->invalid_instruction; |
| 21094 | return ira->codegen->invalid_inst_gen; |
| 21095 | if (tld->resolution == TldResolutionResolving) |
| 21096 | return ir_error_dependency_loop(ira, source_instr); |
| 21097 | |
| 20037 | 21098 | TldVar *tld_var = (TldVar *)tld; |
| 20038 | 21099 | ZigVar *var = tld_var->var; |
| 21100 | assert(var != nullptr); |
| 21101 | |
| 20039 | 21102 | if (type_is_invalid(var->var_type)) |
| 20040 | | return ira->codegen->invalid_instruction; |
| 21103 | return ira->codegen->invalid_inst_gen; |
| 20041 | 21104 | |
| 20042 | 21105 | if (var->const_value->type->id == ZigTypeIdFn) { |
| 20043 | 21106 | ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 20044 | 21107 | ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry; |
| 20045 | | IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope, |
| 20046 | | source_instr->source_node, fn, container_ptr); |
| 21108 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr, |
| 21109 | container_ptr_src); |
| 20047 | 21110 | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 20048 | 21111 | } |
| 20049 | 21112 | } |
| ... | ... | @@ -20063,7 +21126,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20063 | 21126 | } |
| 20064 | 21127 | ir_add_error_node(ira, source_instr->source_node, |
| 20065 | 21128 | buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name))); |
| 20066 | | return ira->codegen->invalid_instruction; |
| 21129 | return ira->codegen->invalid_inst_gen; |
| 20067 | 21130 | } |
| 20068 | 21131 | |
| 20069 | 21132 | static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) { |
| ... | ... | @@ -20078,24 +21141,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty |
| 20078 | 21141 | field->type_entry, nullptr, UndefOk); |
| 20079 | 21142 | } |
| 20080 | 21143 | |
| 20081 | | static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 20082 | | TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing) |
| 21144 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 21145 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing) |
| 20083 | 21146 | { |
| 20084 | 21147 | Error err; |
| 20085 | 21148 | ZigType *field_type = resolve_struct_field_type(ira->codegen, field); |
| 20086 | 21149 | if (field_type == nullptr) |
| 20087 | | return ira->codegen->invalid_instruction; |
| 21150 | return ira->codegen->invalid_inst_gen; |
| 20088 | 21151 | if (field->is_comptime) { |
| 20089 | | IrInstruction *elem = ir_const(ira, source_instr, field_type); |
| 21152 | IrInstGen *elem = ir_const(ira, source_instr, field_type); |
| 20090 | 21153 | memoize_field_init_val(ira->codegen, struct_type, field); |
| 20091 | 21154 | copy_const_val(elem->value, field->init_val); |
| 20092 | | return ir_get_ref(ira, source_instr, elem, true, false); |
| 21155 | return ir_get_ref2(ira, source_instr, elem, field_type, true, false); |
| 20093 | 21156 | } |
| 20094 | 21157 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 20095 | 21158 | case OnePossibleValueInvalid: |
| 20096 | | return ira->codegen->invalid_instruction; |
| 21159 | return ira->codegen->invalid_inst_gen; |
| 20097 | 21160 | case OnePossibleValueYes: { |
| 20098 | | IrInstruction *elem = ir_const_move(ira, source_instr, |
| 21161 | IrInstGen *elem = ir_const_move(ira, source_instr, |
| 20099 | 21162 | get_the_one_possible_value(ira->codegen, field_type)); |
| 20100 | 21163 | return ir_get_ref(ira, source_instr, elem, false, false); |
| 20101 | 21164 | } |
| ... | ... | @@ -20113,7 +21176,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20113 | 21176 | (struct_type->data.structure.layout == ContainerLayoutAuto) ? |
| 20114 | 21177 | ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown; |
| 20115 | 21178 | if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status))) |
| 20116 | | return ira->codegen->invalid_instruction; |
| 21179 | return ira->codegen->invalid_inst_gen; |
| 20117 | 21180 | assert(struct_ptr->value->type->id == ZigTypeIdPointer); |
| 20118 | 21181 | uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host; |
| 20119 | 21182 | uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes; |
| ... | ... | @@ -20127,14 +21190,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20127 | 21190 | if (instr_is_comptime(struct_ptr)) { |
| 20128 | 21191 | ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); |
| 20129 | 21192 | if (!ptr_val) |
| 20130 | | return ira->codegen->invalid_instruction; |
| 21193 | return ira->codegen->invalid_inst_gen; |
| 20131 | 21194 | |
| 20132 | 21195 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 20133 | 21196 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20134 | 21197 | if (struct_val == nullptr) |
| 20135 | | return ira->codegen->invalid_instruction; |
| 21198 | return ira->codegen->invalid_inst_gen; |
| 20136 | 21199 | if (type_is_invalid(struct_val->type)) |
| 20137 | | return ira->codegen->invalid_instruction; |
| 21200 | return ira->codegen->invalid_inst_gen; |
| 20138 | 21201 | if (initializing && struct_val->special == ConstValSpecialUndef) { |
| 20139 | 21202 | struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count); |
| 20140 | 21203 | struct_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -20148,11 +21211,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20148 | 21211 | field_val->parent.data.p_struct.field_index = i; |
| 20149 | 21212 | } |
| 20150 | 21213 | } |
| 20151 | | IrInstruction *result; |
| 21214 | IrInstGen *result; |
| 20152 | 21215 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20153 | | result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, |
| 20154 | | source_instr->source_node, struct_ptr, field); |
| 20155 | | result->value->type = ptr_type; |
| 21216 | result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 20156 | 21217 | result->value->special = ConstValSpecialStatic; |
| 20157 | 21218 | } else { |
| 20158 | 21219 | result = ir_const(ira, source_instr, ptr_type); |
| ... | ... | @@ -20165,14 +21226,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20165 | 21226 | return result; |
| 20166 | 21227 | } |
| 20167 | 21228 | } |
| 20168 | | IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 20169 | | struct_ptr, field); |
| 20170 | | result->value->type = ptr_type; |
| 20171 | | return result; |
| 21229 | return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 20172 | 21230 | } |
| 20173 | 21231 | |
| 20174 | | static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 20175 | | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type) |
| 21232 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21233 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type) |
| 20176 | 21234 | { |
| 20177 | 21235 | // The type of the field is not available until a store using this pointer happens. |
| 20178 | 21236 | // So, here we create a special pointer type which has the inferred struct type and |
| ... | ... | @@ -20195,12 +21253,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 20195 | 21253 | if (instr_is_comptime(container_ptr)) { |
| 20196 | 21254 | ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20197 | 21255 | if (ptr_val == nullptr) |
| 20198 | | return ira->codegen->invalid_instruction; |
| 21256 | return ira->codegen->invalid_inst_gen; |
| 20199 | 21257 | |
| 20200 | | IrInstruction *result; |
| 21258 | IrInstGen *result; |
| 20201 | 21259 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20202 | | result = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 20203 | | source_instr->source_node, container_ptr_type, container_ptr, CastOpNoop); |
| 21260 | result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop); |
| 20204 | 21261 | } else { |
| 20205 | 21262 | result = ir_const(ira, source_instr, field_ptr_type); |
| 20206 | 21263 | } |
| ... | ... | @@ -20209,14 +21266,12 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 20209 | 21266 | return result; |
| 20210 | 21267 | } |
| 20211 | 21268 | |
| 20212 | | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 20213 | | source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop); |
| 20214 | | result->value->type = field_ptr_type; |
| 20215 | | return result; |
| 21269 | return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop); |
| 20216 | 21270 | } |
| 20217 | 21271 | |
| 20218 | | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 20219 | | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing) |
| 21272 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21273 | IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src, |
| 21274 | ZigType *container_type, bool initializing) |
| 20220 | 21275 | { |
| 20221 | 21276 | Error err; |
| 20222 | 21277 | |
| ... | ... | @@ -20229,7 +21284,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20229 | 21284 | } |
| 20230 | 21285 | |
| 20231 | 21286 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 20232 | | return ira->codegen->invalid_instruction; |
| 21287 | return ira->codegen->invalid_inst_gen; |
| 20233 | 21288 | |
| 20234 | 21289 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20235 | 21290 | if (bare_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -20238,13 +21293,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20238 | 21293 | return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing); |
| 20239 | 21294 | } else { |
| 20240 | 21295 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 20241 | | source_instr, container_ptr, container_type); |
| 21296 | source_instr, container_ptr, container_ptr_src, container_type); |
| 20242 | 21297 | } |
| 20243 | 21298 | } |
| 20244 | 21299 | |
| 20245 | 21300 | if (bare_type->id == ZigTypeIdEnum) { |
| 20246 | 21301 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 20247 | | source_instr, container_ptr, container_type); |
| 21302 | source_instr, container_ptr, container_ptr_src, container_type); |
| 20248 | 21303 | } |
| 20249 | 21304 | |
| 20250 | 21305 | if (bare_type->id == ZigTypeIdUnion) { |
| ... | ... | @@ -20254,27 +21309,27 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20254 | 21309 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 20255 | 21310 | if (field == nullptr) { |
| 20256 | 21311 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 20257 | | source_instr, container_ptr, container_type); |
| 21312 | source_instr, container_ptr, container_ptr_src, container_type); |
| 20258 | 21313 | } |
| 20259 | 21314 | |
| 20260 | 21315 | ZigType *field_type = resolve_union_field_type(ira->codegen, field); |
| 20261 | 21316 | if (field_type == nullptr) |
| 20262 | | return ira->codegen->invalid_instruction; |
| 21317 | return ira->codegen->invalid_inst_gen; |
| 20263 | 21318 | |
| 20264 | 21319 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 20265 | 21320 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 20266 | 21321 | if (instr_is_comptime(container_ptr)) { |
| 20267 | 21322 | ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20268 | 21323 | if (!ptr_val) |
| 20269 | | return ira->codegen->invalid_instruction; |
| 21324 | return ira->codegen->invalid_inst_gen; |
| 20270 | 21325 | |
| 20271 | 21326 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 20272 | 21327 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 20273 | 21328 | ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20274 | 21329 | if (union_val == nullptr) |
| 20275 | | return ira->codegen->invalid_instruction; |
| 21330 | return ira->codegen->invalid_inst_gen; |
| 20276 | 21331 | if (type_is_invalid(union_val->type)) |
| 20277 | | return ira->codegen->invalid_instruction; |
| 21332 | return ira->codegen->invalid_inst_gen; |
| 20278 | 21333 | |
| 20279 | 21334 | if (initializing) { |
| 20280 | 21335 | ZigValue *payload_val = create_const_vals(1); |
| ... | ... | @@ -20295,17 +21350,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20295 | 21350 | ir_add_error_node(ira, source_instr->source_node, |
| 20296 | 21351 | buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name), |
| 20297 | 21352 | buf_ptr(actual_field->name))); |
| 20298 | | return ira->codegen->invalid_instruction; |
| 21353 | return ira->codegen->invalid_inst_gen; |
| 20299 | 21354 | } |
| 20300 | 21355 | } |
| 20301 | 21356 | |
| 20302 | 21357 | ZigValue *payload_val = union_val->data.x_union.payload; |
| 20303 | 21358 | |
| 20304 | | IrInstruction *result; |
| 21359 | IrInstGen *result; |
| 20305 | 21360 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20306 | | result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 20307 | | source_instr->source_node, container_ptr, field, true, initializing); |
| 20308 | | result->value->type = ptr_type; |
| 21361 | result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, |
| 21362 | initializing, ptr_type); |
| 20309 | 21363 | result->value->special = ConstValSpecialStatic; |
| 20310 | 21364 | } else { |
| 20311 | 21365 | result = ir_const(ira, source_instr, ptr_type); |
| ... | ... | @@ -20318,10 +21372,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20318 | 21372 | } |
| 20319 | 21373 | } |
| 20320 | 21374 | |
| 20321 | | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 20322 | | source_instr->source_node, container_ptr, field, true, initializing); |
| 20323 | | result->value->type = ptr_type; |
| 20324 | | return result; |
| 21375 | return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type); |
| 20325 | 21376 | } |
| 20326 | 21377 | |
| 20327 | 21378 | zig_unreachable(); |
| ... | ... | @@ -20362,16 +21413,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 20362 | 21413 | link_lib->symbols.append(symbol_name); |
| 20363 | 21414 | } |
| 20364 | 21415 | |
| 20365 | | static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) { |
| 21416 | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) { |
| 20366 | 21417 | ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected")); |
| 20367 | | return ira->codegen->invalid_instruction; |
| 21418 | return ira->codegen->invalid_inst_gen; |
| 20368 | 21419 | } |
| 20369 | 21420 | |
| 20370 | | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 21421 | static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) { |
| 20371 | 21422 | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true); |
| 20372 | 21423 | if (tld->resolution == TldResolutionInvalid) { |
| 20373 | | return ira->codegen->invalid_instruction; |
| 21424 | return ira->codegen->invalid_inst_gen; |
| 20374 | 21425 | } |
| 21426 | if (tld->resolution == TldResolutionResolving) |
| 21427 | return ir_error_dependency_loop(ira, source_instruction); |
| 20375 | 21428 | |
| 20376 | 21429 | switch (tld->id) { |
| 20377 | 21430 | case TldIdContainer: |
| ... | ... | @@ -20381,9 +21434,8 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 20381 | 21434 | case TldIdVar: { |
| 20382 | 21435 | TldVar *tld_var = (TldVar *)tld; |
| 20383 | 21436 | ZigVar *var = tld_var->var; |
| 20384 | | if (var == nullptr) { |
| 20385 | | return ir_error_dependency_loop(ira, source_instruction); |
| 20386 | | } |
| 21437 | assert(var != nullptr); |
| 21438 | |
| 20387 | 21439 | if (tld_var->extern_lib_name != nullptr) { |
| 20388 | 21440 | add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name), |
| 20389 | 21441 | source_instruction->source_node); |
| ... | ... | @@ -20394,17 +21446,16 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 20394 | 21446 | case TldIdFn: { |
| 20395 | 21447 | TldFn *tld_fn = (TldFn *)tld; |
| 20396 | 21448 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 20397 | | assert(fn_entry->type_entry); |
| 21449 | assert(fn_entry->type_entry != nullptr); |
| 20398 | 21450 | |
| 20399 | 21451 | if (type_is_invalid(fn_entry->type_entry)) |
| 20400 | | return ira->codegen->invalid_instruction; |
| 21452 | return ira->codegen->invalid_inst_gen; |
| 20401 | 21453 | |
| 20402 | 21454 | if (tld_fn->extern_lib_name != nullptr) { |
| 20403 | 21455 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); |
| 20404 | 21456 | } |
| 20405 | 21457 | |
| 20406 | | IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope, |
| 20407 | | source_instruction->source_node, fn_entry); |
| 21458 | IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry); |
| 20408 | 21459 | return ir_get_ref(ira, source_instruction, fn_inst, true, false); |
| 20409 | 21460 | } |
| 20410 | 21461 | } |
| ... | ... | @@ -20422,40 +21473,44 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n |
| 20422 | 21473 | return nullptr; |
| 20423 | 21474 | } |
| 20424 | 21475 | |
| 20425 | | static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 21476 | static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFieldPtr *field_ptr_instruction) { |
| 20426 | 21477 | Error err; |
| 20427 | | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; |
| 21478 | IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child; |
| 20428 | 21479 | if (type_is_invalid(container_ptr->value->type)) |
| 20429 | | return ira->codegen->invalid_instruction; |
| 21480 | return ira->codegen->invalid_inst_gen; |
| 20430 | 21481 | |
| 20431 | 21482 | ZigType *container_type = container_ptr->value->type->data.pointer.child_type; |
| 20432 | 21483 | |
| 20433 | 21484 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 20434 | 21485 | if (!field_name) { |
| 20435 | | IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child; |
| 21486 | IrInstGen *field_name_expr = field_ptr_instruction->field_name_expr->child; |
| 20436 | 21487 | field_name = ir_resolve_str(ira, field_name_expr); |
| 20437 | 21488 | if (!field_name) |
| 20438 | | return ira->codegen->invalid_instruction; |
| 21489 | return ira->codegen->invalid_inst_gen; |
| 20439 | 21490 | } |
| 20440 | 21491 | |
| 20441 | 21492 | |
| 20442 | | AstNode *source_node = field_ptr_instruction->base.source_node; |
| 21493 | AstNode *source_node = field_ptr_instruction->base.base.source_node; |
| 20443 | 21494 | |
| 20444 | 21495 | if (type_is_invalid(container_type)) { |
| 20445 | | return ira->codegen->invalid_instruction; |
| 21496 | return ira->codegen->invalid_inst_gen; |
| 20446 | 21497 | } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) { |
| 20447 | | IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base, |
| 21498 | IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base, |
| 20448 | 21499 | container_type->data.structure.src_field_count); |
| 20449 | | return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false); |
| 21500 | return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false); |
| 20450 | 21501 | } else if (is_slice(container_type) || is_container_ref(container_type)) { |
| 20451 | 21502 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20452 | 21503 | if (container_type->id == ZigTypeIdPointer) { |
| 20453 | 21504 | ZigType *bare_type = container_ref_type(container_type); |
| 20454 | | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr); |
| 20455 | | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing); |
| 21505 | IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr); |
| 21506 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, |
| 21507 | container_child, &field_ptr_instruction->container_ptr->base, bare_type, |
| 21508 | field_ptr_instruction->initializing); |
| 20456 | 21509 | return result; |
| 20457 | 21510 | } else { |
| 20458 | | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing); |
| 21511 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, |
| 21512 | container_ptr, &field_ptr_instruction->container_ptr->base, container_type, |
| 21513 | field_ptr_instruction->initializing); |
| 20459 | 21514 | return result; |
| 20460 | 21515 | } |
| 20461 | 21516 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { |
| ... | ... | @@ -20470,42 +21525,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20470 | 21525 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 20471 | 21526 | bool ptr_is_const = true; |
| 20472 | 21527 | bool ptr_is_volatile = false; |
| 20473 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 21528 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val, |
| 20474 | 21529 | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20475 | 21530 | } else { |
| 20476 | 21531 | ir_add_error_node(ira, source_node, |
| 20477 | 21532 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), |
| 20478 | 21533 | buf_ptr(&container_type->name))); |
| 20479 | | return ira->codegen->invalid_instruction; |
| 21534 | return ira->codegen->invalid_inst_gen; |
| 20480 | 21535 | } |
| 20481 | 21536 | } else if (container_type->id == ZigTypeIdMetaType) { |
| 20482 | 21537 | ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20483 | 21538 | if (!container_ptr_val) |
| 20484 | | return ira->codegen->invalid_instruction; |
| 21539 | return ira->codegen->invalid_inst_gen; |
| 20485 | 21540 | |
| 20486 | 21541 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20487 | 21542 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 20488 | 21543 | if (child_val == nullptr) |
| 20489 | | return ira->codegen->invalid_instruction; |
| 21544 | return ira->codegen->invalid_inst_gen; |
| 20490 | 21545 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 20491 | | field_ptr_instruction->base.source_node, child_val, UndefBad))) |
| 21546 | field_ptr_instruction->base.base.source_node, child_val, UndefBad))) |
| 20492 | 21547 | { |
| 20493 | | return ira->codegen->invalid_instruction; |
| 21548 | return ira->codegen->invalid_inst_gen; |
| 20494 | 21549 | } |
| 20495 | 21550 | ZigType *child_type = child_val->data.x_type; |
| 20496 | 21551 | |
| 20497 | 21552 | if (type_is_invalid(child_type)) { |
| 20498 | | return ira->codegen->invalid_instruction; |
| 21553 | return ira->codegen->invalid_inst_gen; |
| 20499 | 21554 | } else if (is_container(child_type)) { |
| 20500 | 21555 | if (child_type->id == ZigTypeIdEnum) { |
| 20501 | 21556 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) |
| 20502 | | return ira->codegen->invalid_instruction; |
| 21557 | return ira->codegen->invalid_inst_gen; |
| 20503 | 21558 | |
| 20504 | 21559 | TypeEnumField *field = find_enum_type_field(child_type, field_name); |
| 20505 | 21560 | if (field) { |
| 20506 | 21561 | bool ptr_is_const = true; |
| 20507 | 21562 | bool ptr_is_volatile = false; |
| 20508 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21563 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20509 | 21564 | create_const_enum(child_type, &field->value), child_type, |
| 20510 | 21565 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20511 | 21566 | } |
| ... | ... | @@ -20514,37 +21569,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20514 | 21569 | Tld *tld = find_container_decl(ira->codegen, container_scope, field_name); |
| 20515 | 21570 | if (tld) { |
| 20516 | 21571 | if (tld->visib_mod == VisibModPrivate && |
| 20517 | | tld->import != get_scope_import(field_ptr_instruction->base.scope)) |
| 21572 | tld->import != get_scope_import(field_ptr_instruction->base.base.scope)) |
| 20518 | 21573 | { |
| 20519 | | ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base, |
| 21574 | ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20520 | 21575 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 20521 | 21576 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 20522 | | return ira->codegen->invalid_instruction; |
| 21577 | return ira->codegen->invalid_inst_gen; |
| 20523 | 21578 | } |
| 20524 | | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); |
| 21579 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld); |
| 20525 | 21580 | } |
| 20526 | 21581 | if (child_type->id == ZigTypeIdUnion && |
| 20527 | 21582 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || |
| 20528 | 21583 | child_type->data.unionation.decl_node->data.container_decl.auto_enum)) |
| 20529 | 21584 | { |
| 20530 | 21585 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) |
| 20531 | | return ira->codegen->invalid_instruction; |
| 21586 | return ira->codegen->invalid_inst_gen; |
| 20532 | 21587 | TypeUnionField *field = find_union_type_field(child_type, field_name); |
| 20533 | 21588 | if (field) { |
| 20534 | 21589 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 20535 | 21590 | bool ptr_is_const = true; |
| 20536 | 21591 | bool ptr_is_volatile = false; |
| 20537 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21592 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20538 | 21593 | create_const_enum(enum_type, &field->enum_field->value), enum_type, |
| 20539 | 21594 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20540 | 21595 | } |
| 20541 | 21596 | } |
| 20542 | 21597 | const char *container_name = (child_type == ira->codegen->root_import) ? |
| 20543 | 21598 | "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name))); |
| 20544 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21599 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20545 | 21600 | buf_sprintf("%s has no member called '%s'", |
| 20546 | 21601 | container_name, buf_ptr(field_name))); |
| 20547 | | return ira->codegen->invalid_instruction; |
| 21602 | return ira->codegen->invalid_inst_gen; |
| 20548 | 21603 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 20549 | 21604 | ErrorTableEntry *err_entry; |
| 20550 | 21605 | ZigType *err_set_type; |
| ... | ... | @@ -20554,7 +21609,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20554 | 21609 | err_entry = existing_entry->value; |
| 20555 | 21610 | } else { |
| 20556 | 21611 | err_entry = allocate<ErrorTableEntry>(1); |
| 20557 | | err_entry->decl_node = field_ptr_instruction->base.source_node; |
| 21612 | err_entry->decl_node = field_ptr_instruction->base.base.source_node; |
| 20558 | 21613 | buf_init_from_buf(&err_entry->name, field_name); |
| 20559 | 21614 | size_t error_value_count = ira->codegen->errors_by_index.length; |
| 20560 | 21615 | assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count)); |
| ... | ... | @@ -20564,19 +21619,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20564 | 21619 | } |
| 20565 | 21620 | if (err_entry->set_with_only_this_in_it == nullptr) { |
| 20566 | 21621 | err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen, |
| 20567 | | field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 21622 | field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node, |
| 20568 | 21623 | err_entry); |
| 20569 | 21624 | } |
| 20570 | 21625 | err_set_type = err_entry->set_with_only_this_in_it; |
| 20571 | 21626 | } else { |
| 20572 | | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { |
| 20573 | | return ira->codegen->invalid_instruction; |
| 21627 | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) { |
| 21628 | return ira->codegen->invalid_inst_gen; |
| 20574 | 21629 | } |
| 20575 | 21630 | err_entry = find_err_table_entry(child_type, field_name); |
| 20576 | 21631 | if (err_entry == nullptr) { |
| 20577 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21632 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20578 | 21633 | buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); |
| 20579 | | return ira->codegen->invalid_instruction; |
| 21634 | return ira->codegen->invalid_inst_gen; |
| 20580 | 21635 | } |
| 20581 | 21636 | err_set_type = child_type; |
| 20582 | 21637 | } |
| ... | ... | @@ -20587,13 +21642,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20587 | 21642 | |
| 20588 | 21643 | bool ptr_is_const = true; |
| 20589 | 21644 | bool ptr_is_volatile = false; |
| 20590 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 21645 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val, |
| 20591 | 21646 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20592 | 21647 | } else if (child_type->id == ZigTypeIdInt) { |
| 20593 | 21648 | if (buf_eql_str(field_name, "bit_count")) { |
| 20594 | 21649 | bool ptr_is_const = true; |
| 20595 | 21650 | bool ptr_is_volatile = false; |
| 20596 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21651 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20597 | 21652 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20598 | 21653 | child_type->data.integral.bit_count, false), |
| 20599 | 21654 | ira->codegen->builtin_types.entry_num_lit_int, |
| ... | ... | @@ -20601,36 +21656,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20601 | 21656 | } else if (buf_eql_str(field_name, "is_signed")) { |
| 20602 | 21657 | bool ptr_is_const = true; |
| 20603 | 21658 | bool ptr_is_volatile = false; |
| 20604 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21659 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20605 | 21660 | create_const_bool(ira->codegen, child_type->data.integral.is_signed), |
| 20606 | 21661 | ira->codegen->builtin_types.entry_bool, |
| 20607 | 21662 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20608 | 21663 | } else { |
| 20609 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21664 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20610 | 21665 | buf_sprintf("type '%s' has no member called '%s'", |
| 20611 | 21666 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20612 | | return ira->codegen->invalid_instruction; |
| 21667 | return ira->codegen->invalid_inst_gen; |
| 20613 | 21668 | } |
| 20614 | 21669 | } else if (child_type->id == ZigTypeIdFloat) { |
| 20615 | 21670 | if (buf_eql_str(field_name, "bit_count")) { |
| 20616 | 21671 | bool ptr_is_const = true; |
| 20617 | 21672 | bool ptr_is_volatile = false; |
| 20618 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21673 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20619 | 21674 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20620 | 21675 | child_type->data.floating.bit_count, false), |
| 20621 | 21676 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20622 | 21677 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20623 | 21678 | } else { |
| 20624 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21679 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20625 | 21680 | buf_sprintf("type '%s' has no member called '%s'", |
| 20626 | 21681 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20627 | | return ira->codegen->invalid_instruction; |
| 21682 | return ira->codegen->invalid_inst_gen; |
| 20628 | 21683 | } |
| 20629 | 21684 | } else if (child_type->id == ZigTypeIdPointer) { |
| 20630 | 21685 | if (buf_eql_str(field_name, "Child")) { |
| 20631 | 21686 | bool ptr_is_const = true; |
| 20632 | 21687 | bool ptr_is_volatile = false; |
| 20633 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21688 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20634 | 21689 | create_const_type(ira->codegen, child_type->data.pointer.child_type), |
| 20635 | 21690 | ira->codegen->builtin_types.entry_type, |
| 20636 | 21691 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| ... | ... | @@ -20640,75 +21695,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20640 | 21695 | if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type, |
| 20641 | 21696 | ResolveStatusAlignmentKnown))) |
| 20642 | 21697 | { |
| 20643 | | return ira->codegen->invalid_instruction; |
| 21698 | return ira->codegen->invalid_inst_gen; |
| 20644 | 21699 | } |
| 20645 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21700 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20646 | 21701 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20647 | 21702 | get_ptr_align(ira->codegen, child_type), false), |
| 20648 | 21703 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20649 | 21704 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20650 | 21705 | } else { |
| 20651 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21706 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20652 | 21707 | buf_sprintf("type '%s' has no member called '%s'", |
| 20653 | 21708 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20654 | | return ira->codegen->invalid_instruction; |
| 21709 | return ira->codegen->invalid_inst_gen; |
| 20655 | 21710 | } |
| 20656 | 21711 | } else if (child_type->id == ZigTypeIdArray) { |
| 20657 | 21712 | if (buf_eql_str(field_name, "Child")) { |
| 20658 | 21713 | bool ptr_is_const = true; |
| 20659 | 21714 | bool ptr_is_volatile = false; |
| 20660 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21715 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20661 | 21716 | create_const_type(ira->codegen, child_type->data.array.child_type), |
| 20662 | 21717 | ira->codegen->builtin_types.entry_type, |
| 20663 | 21718 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20664 | 21719 | } else if (buf_eql_str(field_name, "len")) { |
| 20665 | 21720 | bool ptr_is_const = true; |
| 20666 | 21721 | bool ptr_is_volatile = false; |
| 20667 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21722 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20668 | 21723 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20669 | 21724 | child_type->data.array.len, false), |
| 20670 | 21725 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20671 | 21726 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20672 | 21727 | } else { |
| 20673 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21728 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20674 | 21729 | buf_sprintf("type '%s' has no member called '%s'", |
| 20675 | 21730 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20676 | | return ira->codegen->invalid_instruction; |
| 21731 | return ira->codegen->invalid_inst_gen; |
| 20677 | 21732 | } |
| 20678 | 21733 | } else if (child_type->id == ZigTypeIdErrorUnion) { |
| 20679 | 21734 | if (buf_eql_str(field_name, "Payload")) { |
| 20680 | 21735 | bool ptr_is_const = true; |
| 20681 | 21736 | bool ptr_is_volatile = false; |
| 20682 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21737 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20683 | 21738 | create_const_type(ira->codegen, child_type->data.error_union.payload_type), |
| 20684 | 21739 | ira->codegen->builtin_types.entry_type, |
| 20685 | 21740 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20686 | 21741 | } else if (buf_eql_str(field_name, "ErrorSet")) { |
| 20687 | 21742 | bool ptr_is_const = true; |
| 20688 | 21743 | bool ptr_is_volatile = false; |
| 20689 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21744 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20690 | 21745 | create_const_type(ira->codegen, child_type->data.error_union.err_set_type), |
| 20691 | 21746 | ira->codegen->builtin_types.entry_type, |
| 20692 | 21747 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20693 | 21748 | } else { |
| 20694 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21749 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20695 | 21750 | buf_sprintf("type '%s' has no member called '%s'", |
| 20696 | 21751 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20697 | | return ira->codegen->invalid_instruction; |
| 21752 | return ira->codegen->invalid_inst_gen; |
| 20698 | 21753 | } |
| 20699 | 21754 | } else if (child_type->id == ZigTypeIdOptional) { |
| 20700 | 21755 | if (buf_eql_str(field_name, "Child")) { |
| 20701 | 21756 | bool ptr_is_const = true; |
| 20702 | 21757 | bool ptr_is_volatile = false; |
| 20703 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21758 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20704 | 21759 | create_const_type(ira->codegen, child_type->data.maybe.child_type), |
| 20705 | 21760 | ira->codegen->builtin_types.entry_type, |
| 20706 | 21761 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20707 | 21762 | } else { |
| 20708 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21763 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20709 | 21764 | buf_sprintf("type '%s' has no member called '%s'", |
| 20710 | 21765 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20711 | | return ira->codegen->invalid_instruction; |
| 21766 | return ira->codegen->invalid_inst_gen; |
| 20712 | 21767 | } |
| 20713 | 21768 | } else if (child_type->id == ZigTypeIdFn) { |
| 20714 | 21769 | if (buf_eql_str(field_name, "ReturnType")) { |
| ... | ... | @@ -20716,121 +21771,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20716 | 21771 | // Return type can only ever be null, if the function is generic |
| 20717 | 21772 | assert(child_type->data.fn.is_generic); |
| 20718 | 21773 | |
| 20719 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21774 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20720 | 21775 | buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name))); |
| 20721 | | return ira->codegen->invalid_instruction; |
| 21776 | return ira->codegen->invalid_inst_gen; |
| 20722 | 21777 | } |
| 20723 | 21778 | |
| 20724 | 21779 | bool ptr_is_const = true; |
| 20725 | 21780 | bool ptr_is_volatile = false; |
| 20726 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21781 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20727 | 21782 | create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type), |
| 20728 | 21783 | ira->codegen->builtin_types.entry_type, |
| 20729 | 21784 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20730 | 21785 | } else if (buf_eql_str(field_name, "is_var_args")) { |
| 20731 | 21786 | bool ptr_is_const = true; |
| 20732 | 21787 | bool ptr_is_volatile = false; |
| 20733 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21788 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20734 | 21789 | create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args), |
| 20735 | 21790 | ira->codegen->builtin_types.entry_bool, |
| 20736 | 21791 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20737 | 21792 | } else if (buf_eql_str(field_name, "arg_count")) { |
| 20738 | 21793 | bool ptr_is_const = true; |
| 20739 | 21794 | bool ptr_is_volatile = false; |
| 20740 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21795 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20741 | 21796 | create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count), |
| 20742 | 21797 | ira->codegen->builtin_types.entry_usize, |
| 20743 | 21798 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20744 | 21799 | } else { |
| 20745 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21800 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20746 | 21801 | buf_sprintf("type '%s' has no member called '%s'", |
| 20747 | 21802 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20748 | | return ira->codegen->invalid_instruction; |
| 21803 | return ira->codegen->invalid_inst_gen; |
| 20749 | 21804 | } |
| 20750 | 21805 | } else { |
| 20751 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21806 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20752 | 21807 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 20753 | | return ira->codegen->invalid_instruction; |
| 21808 | return ira->codegen->invalid_inst_gen; |
| 20754 | 21809 | } |
| 20755 | 21810 | } else if (field_ptr_instruction->initializing) { |
| 20756 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21811 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20757 | 21812 | buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name))); |
| 20758 | | return ira->codegen->invalid_instruction; |
| 21813 | return ira->codegen->invalid_inst_gen; |
| 20759 | 21814 | } else { |
| 20760 | | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 21815 | ir_add_error_node(ira, field_ptr_instruction->base.base.source_node, |
| 20761 | 21816 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 20762 | | return ira->codegen->invalid_instruction; |
| 21817 | return ira->codegen->invalid_inst_gen; |
| 20763 | 21818 | } |
| 20764 | 21819 | } |
| 20765 | 21820 | |
| 20766 | | static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) { |
| 20767 | | IrInstruction *ptr = instruction->ptr->child; |
| 21821 | static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) { |
| 21822 | IrInstGen *ptr = instruction->ptr->child; |
| 20768 | 21823 | if (type_is_invalid(ptr->value->type)) |
| 20769 | | return ira->codegen->invalid_instruction; |
| 21824 | return ira->codegen->invalid_inst_gen; |
| 20770 | 21825 | |
| 20771 | | IrInstruction *value = instruction->value->child; |
| 21826 | IrInstGen *value = instruction->value->child; |
| 20772 | 21827 | if (type_is_invalid(value->value->type)) |
| 20773 | | return ira->codegen->invalid_instruction; |
| 21828 | return ira->codegen->invalid_inst_gen; |
| 20774 | 21829 | |
| 20775 | | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| 21830 | return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const); |
| 20776 | 21831 | } |
| 20777 | 21832 | |
| 20778 | | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| 20779 | | IrInstruction *ptr = instruction->ptr->child; |
| 21833 | static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) { |
| 21834 | IrInstGen *ptr = instruction->ptr->child; |
| 20780 | 21835 | if (type_is_invalid(ptr->value->type)) |
| 20781 | | return ira->codegen->invalid_instruction; |
| 20782 | | return ir_get_deref(ira, &instruction->base, ptr, nullptr); |
| 21836 | return ira->codegen->invalid_inst_gen; |
| 21837 | return ir_get_deref(ira, &instruction->base.base, ptr, nullptr); |
| 20783 | 21838 | } |
| 20784 | 21839 | |
| 20785 | | static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 20786 | | IrInstruction *expr_value = typeof_instruction->value->child; |
| 21840 | static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) { |
| 21841 | IrInstGen *expr_value = typeof_instruction->value->child; |
| 20787 | 21842 | ZigType *type_entry = expr_value->value->type; |
| 20788 | 21843 | if (type_is_invalid(type_entry)) |
| 20789 | | return ira->codegen->invalid_instruction; |
| 20790 | | return ir_const_type(ira, &typeof_instruction->base, type_entry); |
| 21844 | return ira->codegen->invalid_inst_gen; |
| 21845 | return ir_const_type(ira, &typeof_instruction->base.base, type_entry); |
| 20791 | 21846 | } |
| 20792 | 21847 | |
| 20793 | | static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { |
| 21848 | static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) { |
| 20794 | 21849 | if (ira->new_irb.exec->is_inline) { |
| 20795 | 21850 | // ignore setCold when running functions at compile time |
| 20796 | | return ir_const_void(ira, &instruction->base); |
| 21851 | return ir_const_void(ira, &instruction->base.base); |
| 20797 | 21852 | } |
| 20798 | 21853 | |
| 20799 | | IrInstruction *is_cold_value = instruction->is_cold->child; |
| 21854 | IrInstGen *is_cold_value = instruction->is_cold->child; |
| 20800 | 21855 | bool want_cold; |
| 20801 | 21856 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 20802 | | return ira->codegen->invalid_instruction; |
| 21857 | return ira->codegen->invalid_inst_gen; |
| 20803 | 21858 | |
| 20804 | | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 21859 | ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope); |
| 20805 | 21860 | if (fn_entry == nullptr) { |
| 20806 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); |
| 20807 | | return ira->codegen->invalid_instruction; |
| 21861 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function")); |
| 21862 | return ira->codegen->invalid_inst_gen; |
| 20808 | 21863 | } |
| 20809 | 21864 | |
| 20810 | 21865 | if (fn_entry->set_cold_node != nullptr) { |
| 20811 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function")); |
| 21866 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function")); |
| 20812 | 21867 | add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here")); |
| 20813 | | return ira->codegen->invalid_instruction; |
| 21868 | return ira->codegen->invalid_inst_gen; |
| 20814 | 21869 | } |
| 20815 | 21870 | |
| 20816 | | fn_entry->set_cold_node = instruction->base.source_node; |
| 21871 | fn_entry->set_cold_node = instruction->base.base.source_node; |
| 20817 | 21872 | fn_entry->is_cold = want_cold; |
| 20818 | 21873 | |
| 20819 | | return ir_const_void(ira, &instruction->base); |
| 21874 | return ir_const_void(ira, &instruction->base.base); |
| 20820 | 21875 | } |
| 20821 | 21876 | |
| 20822 | | static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 20823 | | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 21877 | static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 21878 | IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction) |
| 20824 | 21879 | { |
| 20825 | 21880 | if (ira->new_irb.exec->is_inline) { |
| 20826 | 21881 | // ignore setRuntimeSafety when running functions at compile time |
| 20827 | | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 21882 | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 20828 | 21883 | } |
| 20829 | 21884 | |
| 20830 | 21885 | bool *safety_off_ptr; |
| 20831 | 21886 | AstNode **safety_set_node_ptr; |
| 20832 | 21887 | |
| 20833 | | Scope *scope = set_runtime_safety_instruction->base.scope; |
| 21888 | Scope *scope = set_runtime_safety_instruction->base.base.scope; |
| 20834 | 21889 | while (scope != nullptr) { |
| 20835 | 21890 | if (scope->id == ScopeIdBlock) { |
| 20836 | 21891 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -20856,36 +21911,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 20856 | 21911 | } |
| 20857 | 21912 | assert(scope != nullptr); |
| 20858 | 21913 | |
| 20859 | | IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child; |
| 21914 | IrInstGen *safety_on_value = set_runtime_safety_instruction->safety_on->child; |
| 20860 | 21915 | bool want_runtime_safety; |
| 20861 | 21916 | if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety)) |
| 20862 | | return ira->codegen->invalid_instruction; |
| 21917 | return ira->codegen->invalid_inst_gen; |
| 20863 | 21918 | |
| 20864 | | AstNode *source_node = set_runtime_safety_instruction->base.source_node; |
| 21919 | AstNode *source_node = set_runtime_safety_instruction->base.base.source_node; |
| 20865 | 21920 | if (*safety_set_node_ptr) { |
| 20866 | 21921 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 20867 | 21922 | buf_sprintf("runtime safety set twice for same scope")); |
| 20868 | 21923 | add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here")); |
| 20869 | | return ira->codegen->invalid_instruction; |
| 21924 | return ira->codegen->invalid_inst_gen; |
| 20870 | 21925 | } |
| 20871 | 21926 | *safety_set_node_ptr = source_node; |
| 20872 | 21927 | *safety_off_ptr = !want_runtime_safety; |
| 20873 | 21928 | |
| 20874 | | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 21929 | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 20875 | 21930 | } |
| 20876 | 21931 | |
| 20877 | | static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 20878 | | IrInstructionSetFloatMode *instruction) |
| 21932 | static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 21933 | IrInstSrcSetFloatMode *instruction) |
| 20879 | 21934 | { |
| 20880 | 21935 | if (ira->new_irb.exec->is_inline) { |
| 20881 | 21936 | // ignore setFloatMode when running functions at compile time |
| 20882 | | return ir_const_void(ira, &instruction->base); |
| 21937 | return ir_const_void(ira, &instruction->base.base); |
| 20883 | 21938 | } |
| 20884 | 21939 | |
| 20885 | 21940 | bool *fast_math_on_ptr; |
| 20886 | 21941 | AstNode **fast_math_set_node_ptr; |
| 20887 | 21942 | |
| 20888 | | Scope *scope = instruction->base.scope; |
| 21943 | Scope *scope = instruction->base.base.scope; |
| 20889 | 21944 | while (scope != nullptr) { |
| 20890 | 21945 | if (scope->id == ScopeIdBlock) { |
| 20891 | 21946 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -20911,42 +21966,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 20911 | 21966 | } |
| 20912 | 21967 | assert(scope != nullptr); |
| 20913 | 21968 | |
| 20914 | | IrInstruction *float_mode_value = instruction->mode_value->child; |
| 21969 | IrInstGen *float_mode_value = instruction->mode_value->child; |
| 20915 | 21970 | FloatMode float_mode_scalar; |
| 20916 | 21971 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) |
| 20917 | | return ira->codegen->invalid_instruction; |
| 21972 | return ira->codegen->invalid_inst_gen; |
| 20918 | 21973 | |
| 20919 | | AstNode *source_node = instruction->base.source_node; |
| 21974 | AstNode *source_node = instruction->base.base.source_node; |
| 20920 | 21975 | if (*fast_math_set_node_ptr) { |
| 20921 | 21976 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 20922 | 21977 | buf_sprintf("float mode set twice for same scope")); |
| 20923 | 21978 | add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here")); |
| 20924 | | return ira->codegen->invalid_instruction; |
| 21979 | return ira->codegen->invalid_inst_gen; |
| 20925 | 21980 | } |
| 20926 | 21981 | *fast_math_set_node_ptr = source_node; |
| 20927 | 21982 | *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized); |
| 20928 | 21983 | |
| 20929 | | return ir_const_void(ira, &instruction->base); |
| 21984 | return ir_const_void(ira, &instruction->base.base); |
| 20930 | 21985 | } |
| 20931 | 21986 | |
| 20932 | | static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, |
| 20933 | | IrInstructionAnyFrameType *instruction) |
| 20934 | | { |
| 21987 | static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) { |
| 20935 | 21988 | ZigType *payload_type = nullptr; |
| 20936 | 21989 | if (instruction->payload_type != nullptr) { |
| 20937 | 21990 | payload_type = ir_resolve_type(ira, instruction->payload_type->child); |
| 20938 | 21991 | if (type_is_invalid(payload_type)) |
| 20939 | | return ira->codegen->invalid_instruction; |
| 21992 | return ira->codegen->invalid_inst_gen; |
| 20940 | 21993 | } |
| 20941 | 21994 | |
| 20942 | 21995 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type); |
| 20943 | | return ir_const_type(ira, &instruction->base, any_frame_type); |
| 21996 | return ir_const_type(ira, &instruction->base.base, any_frame_type); |
| 20944 | 21997 | } |
| 20945 | 21998 | |
| 20946 | | static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 20947 | | IrInstructionSliceType *slice_type_instruction) |
| 20948 | | { |
| 20949 | | IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 21999 | static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) { |
| 22000 | IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 20950 | 22001 | result->value->special = ConstValSpecialLazy; |
| 20951 | 22002 | |
| 20952 | 22003 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType"); |
| ... | ... | @@ -20957,18 +22008,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 20957 | 22008 | if (slice_type_instruction->align_value != nullptr) { |
| 20958 | 22009 | lazy_slice_type->align_inst = slice_type_instruction->align_value->child; |
| 20959 | 22010 | if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr) |
| 20960 | | return ira->codegen->invalid_instruction; |
| 22011 | return ira->codegen->invalid_inst_gen; |
| 20961 | 22012 | } |
| 20962 | 22013 | |
| 20963 | 22014 | if (slice_type_instruction->sentinel != nullptr) { |
| 20964 | 22015 | lazy_slice_type->sentinel = slice_type_instruction->sentinel->child; |
| 20965 | 22016 | if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr) |
| 20966 | | return ira->codegen->invalid_instruction; |
| 22017 | return ira->codegen->invalid_inst_gen; |
| 20967 | 22018 | } |
| 20968 | 22019 | |
| 20969 | 22020 | lazy_slice_type->elem_type = slice_type_instruction->child_type->child; |
| 20970 | 22021 | if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr) |
| 20971 | | return ira->codegen->invalid_instruction; |
| 22022 | return ira->codegen->invalid_inst_gen; |
| 20972 | 22023 | |
| 20973 | 22024 | lazy_slice_type->is_const = slice_type_instruction->is_const; |
| 20974 | 22025 | lazy_slice_type->is_volatile = slice_type_instruction->is_volatile; |
| ... | ... | @@ -20977,31 +22028,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 20977 | 22028 | return result; |
| 20978 | 22029 | } |
| 20979 | 22030 | |
| 20980 | | static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) { |
| 22031 | static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) { |
| 20981 | 22032 | Error err; |
| 20982 | 22033 | |
| 20983 | | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 22034 | assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr); |
| 20984 | 22035 | |
| 20985 | | AstNode *node = asm_instruction->base.source_node; |
| 20986 | | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; |
| 22036 | AstNode *node = asm_instruction->base.base.source_node; |
| 22037 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr; |
| 20987 | 22038 | |
| 20988 | 22039 | Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child); |
| 20989 | 22040 | if (template_buf == nullptr) |
| 20990 | | return ira->codegen->invalid_instruction; |
| 22041 | return ira->codegen->invalid_inst_gen; |
| 20991 | 22042 | |
| 20992 | 22043 | if (asm_instruction->is_global) { |
| 20993 | 22044 | buf_append_char(&ira->codegen->global_asm, '\n'); |
| 20994 | 22045 | buf_append_buf(&ira->codegen->global_asm, template_buf); |
| 20995 | 22046 | |
| 20996 | | return ir_const_void(ira, &asm_instruction->base); |
| 22047 | return ir_const_void(ira, &asm_instruction->base.base); |
| 20997 | 22048 | } |
| 20998 | 22049 | |
| 20999 | | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base)) |
| 21000 | | return ira->codegen->invalid_instruction; |
| 22050 | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base)) |
| 22051 | return ira->codegen->invalid_inst_gen; |
| 21001 | 22052 | |
| 21002 | 22053 | ZigList<AsmToken> tok_list = {}; |
| 21003 | 22054 | if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) { |
| 21004 | | return ira->codegen->invalid_instruction; |
| 22055 | return ira->codegen->invalid_inst_gen; |
| 21005 | 22056 | } |
| 21006 | 22057 | |
| 21007 | 22058 | for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) { |
| ... | ... | @@ -21015,15 +22066,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 21015 | 22066 | add_node_error(ira->codegen, node, |
| 21016 | 22067 | buf_sprintf("could not find '%.*s' in the inputs or outputs", |
| 21017 | 22068 | len, ptr)); |
| 21018 | | return ira->codegen->invalid_instruction; |
| 22069 | return ira->codegen->invalid_inst_gen; |
| 21019 | 22070 | } |
| 21020 | 22071 | } |
| 21021 | 22072 | } |
| 21022 | 22073 | |
| 21023 | 22074 | // TODO validate the output types and variable types |
| 21024 | 22075 | |
| 21025 | | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 21026 | | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); |
| 22076 | IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length); |
| 22077 | IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length); |
| 21027 | 22078 | |
| 21028 | 22079 | ZigType *return_type = ira->codegen->builtin_types.entry_void; |
| 21029 | 22080 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| ... | ... | @@ -21032,39 +22083,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 21032 | 22083 | output_types[i] = asm_instruction->output_types[i]->child; |
| 21033 | 22084 | return_type = ir_resolve_type(ira, output_types[i]); |
| 21034 | 22085 | if (type_is_invalid(return_type)) |
| 21035 | | return ira->codegen->invalid_instruction; |
| 22086 | return ira->codegen->invalid_inst_gen; |
| 21036 | 22087 | } |
| 21037 | 22088 | } |
| 21038 | 22089 | |
| 21039 | 22090 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 21040 | | IrInstruction *const input_value = asm_instruction->input_list[i]->child; |
| 22091 | IrInstGen *const input_value = asm_instruction->input_list[i]->child; |
| 21041 | 22092 | if (type_is_invalid(input_value->value->type)) |
| 21042 | | return ira->codegen->invalid_instruction; |
| 22093 | return ira->codegen->invalid_inst_gen; |
| 21043 | 22094 | |
| 21044 | 22095 | if (instr_is_comptime(input_value) && |
| 21045 | 22096 | (input_value->value->type->id == ZigTypeIdComptimeInt || |
| 21046 | 22097 | input_value->value->type->id == ZigTypeIdComptimeFloat)) { |
| 21047 | | ir_add_error_node(ira, input_value->source_node, |
| 22098 | ir_add_error(ira, &input_value->base, |
| 21048 | 22099 | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); |
| 21049 | | return ira->codegen->invalid_instruction; |
| 22100 | return ira->codegen->invalid_inst_gen; |
| 21050 | 22101 | } |
| 21051 | 22102 | |
| 21052 | 22103 | input_list[i] = input_value; |
| 21053 | 22104 | } |
| 21054 | 22105 | |
| 21055 | | IrInstruction *result = ir_build_asm_gen(ira, |
| 21056 | | asm_instruction->base.scope, asm_instruction->base.source_node, |
| 22106 | return ir_build_asm_gen(ira, &asm_instruction->base.base, |
| 21057 | 22107 | template_buf, tok_list.items, tok_list.length, |
| 21058 | 22108 | input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, |
| 21059 | | asm_instruction->has_side_effects); |
| 21060 | | result->value->type = return_type; |
| 21061 | | return result; |
| 22109 | asm_instruction->has_side_effects, return_type); |
| 21062 | 22110 | } |
| 21063 | 22111 | |
| 21064 | | static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 21065 | | IrInstructionArrayType *array_type_instruction) |
| 21066 | | { |
| 21067 | | IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 22112 | static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) { |
| 22113 | IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 21068 | 22114 | result->value->special = ConstValSpecialLazy; |
| 21069 | 22115 | |
| 21070 | 22116 | LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType"); |
| ... | ... | @@ -21074,22 +22120,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 21074 | 22120 | |
| 21075 | 22121 | lazy_array_type->elem_type = array_type_instruction->child_type->child; |
| 21076 | 22122 | if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr) |
| 21077 | | return ira->codegen->invalid_instruction; |
| 22123 | return ira->codegen->invalid_inst_gen; |
| 21078 | 22124 | |
| 21079 | 22125 | if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length)) |
| 21080 | | return ira->codegen->invalid_instruction; |
| 22126 | return ira->codegen->invalid_inst_gen; |
| 21081 | 22127 | |
| 21082 | 22128 | if (array_type_instruction->sentinel != nullptr) { |
| 21083 | 22129 | lazy_array_type->sentinel = array_type_instruction->sentinel->child; |
| 21084 | 22130 | if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr) |
| 21085 | | return ira->codegen->invalid_instruction; |
| 22131 | return ira->codegen->invalid_inst_gen; |
| 21086 | 22132 | } |
| 21087 | 22133 | |
| 21088 | 22134 | return result; |
| 21089 | 22135 | } |
| 21090 | 22136 | |
| 21091 | | static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) { |
| 21092 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22137 | static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) { |
| 22138 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21093 | 22139 | result->value->special = ConstValSpecialLazy; |
| 21094 | 22140 | |
| 21095 | 22141 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf"); |
| ... | ... | @@ -21100,19 +22146,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi |
| 21100 | 22146 | |
| 21101 | 22147 | lazy_size_of->target_type = instruction->type_value->child; |
| 21102 | 22148 | if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr) |
| 21103 | | return ira->codegen->invalid_instruction; |
| 22149 | return ira->codegen->invalid_inst_gen; |
| 21104 | 22150 | |
| 21105 | 22151 | return result; |
| 21106 | 22152 | } |
| 21107 | 22153 | |
| 21108 | | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) { |
| 22154 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) { |
| 21109 | 22155 | ZigType *type_entry = value->value->type; |
| 21110 | 22156 | |
| 21111 | 22157 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { |
| 21112 | 22158 | if (instr_is_comptime(value)) { |
| 21113 | 22159 | ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); |
| 21114 | 22160 | if (c_ptr_val == nullptr) |
| 21115 | | return ira->codegen->invalid_instruction; |
| 22161 | return ira->codegen->invalid_inst_gen; |
| 21116 | 22162 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 21117 | 22163 | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 21118 | 22164 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| ... | ... | @@ -21121,25 +22167,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 21121 | 22167 | return ir_const_bool(ira, source_inst, !is_null); |
| 21122 | 22168 | } |
| 21123 | 22169 | |
| 21124 | | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 21125 | | source_inst->scope, source_inst->source_node, value); |
| 21126 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 21127 | | return result; |
| 22170 | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 21128 | 22171 | } else if (type_entry->id == ZigTypeIdOptional) { |
| 21129 | 22172 | if (instr_is_comptime(value)) { |
| 21130 | 22173 | ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk); |
| 21131 | 22174 | if (maybe_val == nullptr) |
| 21132 | | return ira->codegen->invalid_instruction; |
| 22175 | return ira->codegen->invalid_inst_gen; |
| 21133 | 22176 | if (maybe_val->special == ConstValSpecialUndef) |
| 21134 | 22177 | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 21135 | 22178 | |
| 21136 | 22179 | return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val)); |
| 21137 | 22180 | } |
| 21138 | 22181 | |
| 21139 | | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 21140 | | source_inst->scope, source_inst->source_node, value); |
| 21141 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 21142 | | return result; |
| 22182 | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 21143 | 22183 | } else if (type_entry->id == ZigTypeIdNull) { |
| 21144 | 22184 | return ir_const_bool(ira, source_inst, false); |
| 21145 | 22185 | } else { |
| ... | ... | @@ -21147,51 +22187,53 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 21147 | 22187 | } |
| 21148 | 22188 | } |
| 21149 | 22189 | |
| 21150 | | static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 21151 | | IrInstruction *value = instruction->value->child; |
| 22190 | static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) { |
| 22191 | IrInstGen *value = instruction->value->child; |
| 21152 | 22192 | if (type_is_invalid(value->value->type)) |
| 21153 | | return ira->codegen->invalid_instruction; |
| 22193 | return ira->codegen->invalid_inst_gen; |
| 21154 | 22194 | |
| 21155 | | return ir_analyze_test_non_null(ira, &instruction->base, value); |
| 22195 | return ir_analyze_test_non_null(ira, &instruction->base.base, value); |
| 21156 | 22196 | } |
| 21157 | 22197 | |
| 21158 | | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 21159 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 22198 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 22199 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 21160 | 22200 | { |
| 22201 | Error err; |
| 22202 | |
| 21161 | 22203 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); |
| 21162 | 22204 | if (type_is_invalid(type_entry)) |
| 21163 | | return ira->codegen->invalid_instruction; |
| 22205 | return ira->codegen->invalid_inst_gen; |
| 21164 | 22206 | |
| 21165 | 22207 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) { |
| 21166 | 22208 | if (instr_is_comptime(base_ptr)) { |
| 21167 | 22209 | ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 21168 | 22210 | if (!val) |
| 21169 | | return ira->codegen->invalid_instruction; |
| 22211 | return ira->codegen->invalid_inst_gen; |
| 21170 | 22212 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21171 | 22213 | ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 21172 | 22214 | if (c_ptr_val == nullptr) |
| 21173 | | return ira->codegen->invalid_instruction; |
| 22215 | return ira->codegen->invalid_inst_gen; |
| 21174 | 22216 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 21175 | 22217 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 21176 | 22218 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 21177 | 22219 | if (is_null) { |
| 21178 | 22220 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 21179 | | return ira->codegen->invalid_instruction; |
| 22221 | return ira->codegen->invalid_inst_gen; |
| 21180 | 22222 | } |
| 21181 | 22223 | return base_ptr; |
| 21182 | 22224 | } |
| 21183 | 22225 | } |
| 21184 | 22226 | if (!safety_check_on) |
| 21185 | 22227 | return base_ptr; |
| 21186 | | IrInstruction *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr); |
| 22228 | IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr); |
| 21187 | 22229 | ir_build_assert_non_null(ira, source_instr, c_ptr_val); |
| 21188 | 22230 | return base_ptr; |
| 21189 | 22231 | } |
| 21190 | 22232 | |
| 21191 | 22233 | if (type_entry->id != ZigTypeIdOptional) { |
| 21192 | | ir_add_error_node(ira, base_ptr->source_node, |
| 22234 | ir_add_error(ira, &base_ptr->base, |
| 21193 | 22235 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 21194 | | return ira->codegen->invalid_instruction; |
| 22236 | return ira->codegen->invalid_inst_gen; |
| 21195 | 22237 | } |
| 21196 | 22238 | |
| 21197 | 22239 | ZigType *child_type = type_entry->data.maybe.child_type; |
| ... | ... | @@ -21203,17 +22245,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21203 | 22245 | |
| 21204 | 22246 | if (instr_is_comptime(base_ptr)) { |
| 21205 | 22247 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 21206 | | if (!ptr_val) |
| 21207 | | return ira->codegen->invalid_instruction; |
| 22248 | if (ptr_val == nullptr) |
| 22249 | return ira->codegen->invalid_inst_gen; |
| 21208 | 22250 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21209 | 22251 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 21210 | 22252 | if (optional_val == nullptr) |
| 21211 | | return ira->codegen->invalid_instruction; |
| 22253 | return ira->codegen->invalid_inst_gen; |
| 21212 | 22254 | |
| 21213 | 22255 | if (initializing) { |
| 21214 | 22256 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 21215 | 22257 | case OnePossibleValueInvalid: |
| 21216 | | return ira->codegen->invalid_instruction; |
| 22258 | return ira->codegen->invalid_inst_gen; |
| 21217 | 22259 | case OnePossibleValueNo: |
| 21218 | 22260 | if (!same_comptime_repr) { |
| 21219 | 22261 | ZigValue *payload_val = create_const_vals(1); |
| ... | ... | @@ -21227,27 +22269,25 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21227 | 22269 | } |
| 21228 | 22270 | break; |
| 21229 | 22271 | case OnePossibleValueYes: { |
| 21230 | | ZigValue *pointee = create_const_vals(1); |
| 21231 | | pointee->special = ConstValSpecialStatic; |
| 21232 | | pointee->type = child_type; |
| 21233 | | pointee->parent.id = ConstParentIdOptionalPayload; |
| 21234 | | pointee->parent.data.p_optional_payload.optional_val = optional_val; |
| 21235 | | |
| 21236 | 22272 | optional_val->special = ConstValSpecialStatic; |
| 21237 | | optional_val->data.x_optional = pointee; |
| 22273 | optional_val->data.x_optional = get_the_one_possible_value(ira->codegen, child_type); |
| 21238 | 22274 | break; |
| 21239 | 22275 | } |
| 21240 | 22276 | } |
| 21241 | | } else if (optional_value_is_null(optional_val)) { |
| 21242 | | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 21243 | | return ira->codegen->invalid_instruction; |
| 22277 | } else { |
| 22278 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 22279 | source_instr->source_node, optional_val, UndefBad))) |
| 22280 | return ira->codegen->invalid_inst_gen; |
| 22281 | if (optional_value_is_null(optional_val)) { |
| 22282 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 22283 | return ira->codegen->invalid_inst_gen; |
| 22284 | } |
| 21244 | 22285 | } |
| 21245 | 22286 | |
| 21246 | | IrInstruction *result; |
| 22287 | IrInstGen *result; |
| 21247 | 22288 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21248 | | result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 21249 | | source_instr->source_node, base_ptr, false, initializing); |
| 21250 | | result->value->type = result_type; |
| 22289 | result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false, |
| 22290 | initializing, result_type); |
| 21251 | 22291 | result->value->special = ConstValSpecialStatic; |
| 21252 | 22292 | } else { |
| 21253 | 22293 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -21257,7 +22297,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21257 | 22297 | result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 21258 | 22298 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 21259 | 22299 | case OnePossibleValueInvalid: |
| 21260 | | return ira->codegen->invalid_instruction; |
| 22300 | return ira->codegen->invalid_inst_gen; |
| 21261 | 22301 | case OnePossibleValueNo: |
| 21262 | 22302 | if (same_comptime_repr) { |
| 21263 | 22303 | result_val->data.x_ptr.data.ref.pointee = optional_val; |
| ... | ... | @@ -21275,131 +22315,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21275 | 22315 | } |
| 21276 | 22316 | } |
| 21277 | 22317 | |
| 21278 | | IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 21279 | | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 21280 | | result->value->type = result_type; |
| 21281 | | return result; |
| 22318 | return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on, |
| 22319 | initializing, result_type); |
| 21282 | 22320 | } |
| 21283 | 22321 | |
| 21284 | | static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 21285 | | IrInstructionOptionalUnwrapPtr *instruction) |
| 22322 | static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 22323 | IrInstSrcOptionalUnwrapPtr *instruction) |
| 21286 | 22324 | { |
| 21287 | | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 22325 | IrInstGen *base_ptr = instruction->base_ptr->child; |
| 21288 | 22326 | if (type_is_invalid(base_ptr->value->type)) |
| 21289 | | return ira->codegen->invalid_instruction; |
| 22327 | return ira->codegen->invalid_inst_gen; |
| 21290 | 22328 | |
| 21291 | | return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr, |
| 22329 | return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr, |
| 21292 | 22330 | instruction->safety_check_on, false); |
| 21293 | 22331 | } |
| 21294 | 22332 | |
| 21295 | | static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) { |
| 22333 | static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) { |
| 21296 | 22334 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21297 | 22335 | if (type_is_invalid(int_type)) |
| 21298 | | return ira->codegen->invalid_instruction; |
| 22336 | return ira->codegen->invalid_inst_gen; |
| 21299 | 22337 | |
| 21300 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22338 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21301 | 22339 | if (type_is_invalid(op->value->type)) |
| 21302 | | return ira->codegen->invalid_instruction; |
| 22340 | return ira->codegen->invalid_inst_gen; |
| 21303 | 22341 | |
| 21304 | 22342 | if (int_type->data.integral.bit_count == 0) |
| 21305 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22343 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21306 | 22344 | |
| 21307 | 22345 | if (instr_is_comptime(op)) { |
| 21308 | 22346 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21309 | 22347 | if (val == nullptr) |
| 21310 | | return ira->codegen->invalid_instruction; |
| 22348 | return ira->codegen->invalid_inst_gen; |
| 21311 | 22349 | if (val->special == ConstValSpecialUndef) |
| 21312 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22350 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21313 | 22351 | size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 21314 | | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 22352 | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 21315 | 22353 | } |
| 21316 | 22354 | |
| 21317 | 22355 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 21318 | | IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope, |
| 21319 | | instruction->base.source_node, nullptr, op); |
| 21320 | | result->value->type = return_type; |
| 21321 | | return result; |
| 22356 | return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op); |
| 21322 | 22357 | } |
| 21323 | 22358 | |
| 21324 | | static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) { |
| 22359 | static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) { |
| 21325 | 22360 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21326 | 22361 | if (type_is_invalid(int_type)) |
| 21327 | | return ira->codegen->invalid_instruction; |
| 22362 | return ira->codegen->invalid_inst_gen; |
| 21328 | 22363 | |
| 21329 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22364 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21330 | 22365 | if (type_is_invalid(op->value->type)) |
| 21331 | | return ira->codegen->invalid_instruction; |
| 22366 | return ira->codegen->invalid_inst_gen; |
| 21332 | 22367 | |
| 21333 | 22368 | if (int_type->data.integral.bit_count == 0) |
| 21334 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22369 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21335 | 22370 | |
| 21336 | 22371 | if (instr_is_comptime(op)) { |
| 21337 | 22372 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21338 | 22373 | if (val == nullptr) |
| 21339 | | return ira->codegen->invalid_instruction; |
| 22374 | return ira->codegen->invalid_inst_gen; |
| 21340 | 22375 | if (val->special == ConstValSpecialUndef) |
| 21341 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22376 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21342 | 22377 | size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 21343 | | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 22378 | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 21344 | 22379 | } |
| 21345 | 22380 | |
| 21346 | 22381 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 21347 | | IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope, |
| 21348 | | instruction->base.source_node, nullptr, op); |
| 21349 | | result->value->type = return_type; |
| 21350 | | return result; |
| 22382 | return ir_build_clz_gen(ira, &instruction->base.base, return_type, op); |
| 21351 | 22383 | } |
| 21352 | 22384 | |
| 21353 | | static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { |
| 22385 | static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) { |
| 21354 | 22386 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21355 | 22387 | if (type_is_invalid(int_type)) |
| 21356 | | return ira->codegen->invalid_instruction; |
| 22388 | return ira->codegen->invalid_inst_gen; |
| 21357 | 22389 | |
| 21358 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22390 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21359 | 22391 | if (type_is_invalid(op->value->type)) |
| 21360 | | return ira->codegen->invalid_instruction; |
| 22392 | return ira->codegen->invalid_inst_gen; |
| 21361 | 22393 | |
| 21362 | 22394 | if (int_type->data.integral.bit_count == 0) |
| 21363 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22395 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21364 | 22396 | |
| 21365 | 22397 | if (instr_is_comptime(op)) { |
| 21366 | 22398 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21367 | 22399 | if (val == nullptr) |
| 21368 | | return ira->codegen->invalid_instruction; |
| 22400 | return ira->codegen->invalid_inst_gen; |
| 21369 | 22401 | if (val->special == ConstValSpecialUndef) |
| 21370 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22402 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21371 | 22403 | |
| 21372 | 22404 | if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) { |
| 21373 | 22405 | size_t result = bigint_popcount_unsigned(&val->data.x_bigint); |
| 21374 | | return ir_const_unsigned(ira, &instruction->base, result); |
| 22406 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 21375 | 22407 | } |
| 21376 | 22408 | size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count); |
| 21377 | | return ir_const_unsigned(ira, &instruction->base, result); |
| 22409 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 21378 | 22410 | } |
| 21379 | 22411 | |
| 21380 | 22412 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 21381 | | IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope, |
| 21382 | | instruction->base.source_node, nullptr, op); |
| 21383 | | result->value->type = return_type; |
| 21384 | | return result; |
| 22413 | return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op); |
| 21385 | 22414 | } |
| 21386 | 22415 | |
| 21387 | | static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| 22416 | static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) { |
| 21388 | 22417 | if (type_is_invalid(value->value->type)) |
| 21389 | | return ira->codegen->invalid_instruction; |
| 22418 | return ira->codegen->invalid_inst_gen; |
| 21390 | 22419 | |
| 21391 | 22420 | if (value->value->type->id != ZigTypeIdUnion) { |
| 21392 | | ir_add_error(ira, value, |
| 22421 | ir_add_error(ira, &value->base, |
| 21393 | 22422 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); |
| 21394 | | return ira->codegen->invalid_instruction; |
| 22423 | return ira->codegen->invalid_inst_gen; |
| 21395 | 22424 | } |
| 21396 | | if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 22425 | if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) { |
| 21397 | 22426 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); |
| 21398 | 22427 | if (value->value->type->data.unionation.decl_node != nullptr) { |
| 21399 | 22428 | add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, |
| 21400 | 22429 | buf_sprintf("declared here")); |
| 21401 | 22430 | } |
| 21402 | | return ira->codegen->invalid_instruction; |
| 22431 | return ira->codegen->invalid_inst_gen; |
| 21403 | 22432 | } |
| 21404 | 22433 | |
| 21405 | 22434 | ZigType *tag_type = value->value->type->data.unionation.tag_type; |
| ... | ... | @@ -21408,9 +22437,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 21408 | 22437 | if (instr_is_comptime(value)) { |
| 21409 | 22438 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 21410 | 22439 | if (!val) |
| 21411 | | return ira->codegen->invalid_instruction; |
| 22440 | return ira->codegen->invalid_inst_gen; |
| 21412 | 22441 | |
| 21413 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 22442 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 21414 | 22443 | source_instr->scope, source_instr->source_node); |
| 21415 | 22444 | const_instruction->base.value->type = tag_type; |
| 21416 | 22445 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -21418,15 +22447,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 21418 | 22447 | return &const_instruction->base; |
| 21419 | 22448 | } |
| 21420 | 22449 | |
| 21421 | | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 21422 | | result->value->type = tag_type; |
| 21423 | | return result; |
| 22450 | return ir_build_union_tag(ira, source_instr, value, tag_type); |
| 21424 | 22451 | } |
| 21425 | 22452 | |
| 21426 | | static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21427 | | IrInstructionSwitchBr *switch_br_instruction) |
| 22453 | static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 22454 | IrInstSrcSwitchBr *switch_br_instruction) |
| 21428 | 22455 | { |
| 21429 | | IrInstruction *target_value = switch_br_instruction->target_value->child; |
| 22456 | IrInstGen *target_value = switch_br_instruction->target_value->child; |
| 21430 | 22457 | if (type_is_invalid(target_value->value->type)) |
| 21431 | 22458 | return ir_unreach_error(ira); |
| 21432 | 22459 | |
| ... | ... | @@ -21441,21 +22468,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21441 | 22468 | |
| 21442 | 22469 | bool is_comptime; |
| 21443 | 22470 | if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime)) |
| 21444 | | return ira->codegen->invalid_instruction; |
| 22471 | return ira->codegen->invalid_inst_gen; |
| 21445 | 22472 | |
| 21446 | 22473 | if (is_comptime || instr_is_comptime(target_value)) { |
| 21447 | 22474 | ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad); |
| 21448 | 22475 | if (!target_val) |
| 21449 | 22476 | return ir_unreach_error(ira); |
| 21450 | 22477 | |
| 21451 | | IrBasicBlock *old_dest_block = switch_br_instruction->else_block; |
| 22478 | IrBasicBlockSrc *old_dest_block = switch_br_instruction->else_block; |
| 21452 | 22479 | for (size_t i = 0; i < case_count; i += 1) { |
| 21453 | | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 21454 | | IrInstruction *case_value = old_case->value->child; |
| 22480 | IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 22481 | IrInstGen *case_value = old_case->value->child; |
| 21455 | 22482 | if (type_is_invalid(case_value->value->type)) |
| 21456 | 22483 | return ir_unreach_error(ira); |
| 21457 | 22484 | |
| 21458 | | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 22485 | IrInstGen *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 21459 | 22486 | if (type_is_invalid(casted_case_value->value->type)) |
| 21460 | 22487 | return ir_unreach_error(ira); |
| 21461 | 22488 | |
| ... | ... | @@ -21470,23 +22497,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21470 | 22497 | } |
| 21471 | 22498 | |
| 21472 | 22499 | if (is_comptime || old_dest_block->ref_count == 1) { |
| 21473 | | return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block); |
| 22500 | return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block); |
| 21474 | 22501 | } else { |
| 21475 | | IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base); |
| 21476 | | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 21477 | | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 21478 | | new_dest_block, nullptr); |
| 21479 | | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 22502 | IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base); |
| 22503 | IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block); |
| 21480 | 22504 | return ir_finish_anal(ira, result); |
| 21481 | 22505 | } |
| 21482 | 22506 | } |
| 21483 | 22507 | |
| 21484 | | IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count); |
| 22508 | IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count); |
| 21485 | 22509 | for (size_t i = 0; i < case_count; i += 1) { |
| 21486 | | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 21487 | | IrInstructionSwitchBrCase *new_case = &cases[i]; |
| 21488 | | new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base); |
| 21489 | | new_case->value = ira->codegen->invalid_instruction; |
| 22510 | IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 22511 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 22512 | new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base); |
| 22513 | new_case->value = ira->codegen->invalid_inst_gen; |
| 21490 | 22514 | |
| 21491 | 22515 | // Calling ir_get_new_bb set the ref_instruction on the new basic block. |
| 21492 | 22516 | // However a switch br may branch to the same basic block which would trigger an |
| ... | ... | @@ -21494,12 +22518,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21494 | 22518 | // it back after the loop. |
| 21495 | 22519 | new_case->block->ref_instruction = nullptr; |
| 21496 | 22520 | |
| 21497 | | IrInstruction *old_value = old_case->value; |
| 21498 | | IrInstruction *new_value = old_value->child; |
| 22521 | IrInstSrc *old_value = old_case->value; |
| 22522 | IrInstGen *new_value = old_value->child; |
| 21499 | 22523 | if (type_is_invalid(new_value->value->type)) |
| 21500 | 22524 | continue; |
| 21501 | 22525 | |
| 21502 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 22526 | IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 21503 | 22527 | if (type_is_invalid(casted_new_value->value->type)) |
| 21504 | 22528 | continue; |
| 21505 | 22529 | |
| ... | ... | @@ -21510,47 +22534,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21510 | 22534 | } |
| 21511 | 22535 | |
| 21512 | 22536 | for (size_t i = 0; i < case_count; i += 1) { |
| 21513 | | IrInstructionSwitchBrCase *new_case = &cases[i]; |
| 21514 | | if (new_case->value == ira->codegen->invalid_instruction) |
| 22537 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 22538 | if (type_is_invalid(new_case->value->value->type)) |
| 21515 | 22539 | return ir_unreach_error(ira); |
| 21516 | | new_case->block->ref_instruction = &switch_br_instruction->base; |
| 22540 | new_case->block->ref_instruction = &switch_br_instruction->base.base; |
| 21517 | 22541 | } |
| 21518 | 22542 | |
| 21519 | | IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base); |
| 21520 | | IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb, |
| 21521 | | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 21522 | | target_value, new_else_block, case_count, cases, nullptr, nullptr); |
| 21523 | | switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable; |
| 22543 | IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base); |
| 22544 | IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base, |
| 22545 | target_value, new_else_block, case_count, cases); |
| 21524 | 22546 | return ir_finish_anal(ira, &switch_br->base); |
| 21525 | 22547 | } |
| 21526 | 22548 | |
| 21527 | | static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21528 | | IrInstructionSwitchTarget *switch_target_instruction) |
| 22549 | static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 22550 | IrInstSrcSwitchTarget *switch_target_instruction) |
| 21529 | 22551 | { |
| 21530 | 22552 | Error err; |
| 21531 | | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 22553 | IrInstGen *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 21532 | 22554 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21533 | | return ira->codegen->invalid_instruction; |
| 22555 | return ira->codegen->invalid_inst_gen; |
| 21534 | 22556 | |
| 21535 | 22557 | if (target_value_ptr->value->type->id == ZigTypeIdMetaType) { |
| 21536 | 22558 | assert(instr_is_comptime(target_value_ptr)); |
| 21537 | 22559 | ZigType *ptr_type = target_value_ptr->value->data.x_type; |
| 21538 | 22560 | assert(ptr_type->id == ZigTypeIdPointer); |
| 21539 | | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 22561 | return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type); |
| 21540 | 22562 | } |
| 21541 | 22563 | |
| 21542 | 22564 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 21543 | 22565 | ZigValue *pointee_val = nullptr; |
| 21544 | 22566 | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21545 | | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node); |
| 22567 | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node); |
| 21546 | 22568 | if (pointee_val == nullptr) |
| 21547 | | return ira->codegen->invalid_instruction; |
| 22569 | return ira->codegen->invalid_inst_gen; |
| 21548 | 22570 | |
| 21549 | 22571 | if (pointee_val->special == ConstValSpecialRuntime) |
| 21550 | 22572 | pointee_val = nullptr; |
| 21551 | 22573 | } |
| 21552 | 22574 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown))) |
| 21553 | | return ira->codegen->invalid_instruction; |
| 22575 | return ira->codegen->invalid_inst_gen; |
| 21554 | 22576 | |
| 21555 | 22577 | switch (target_type->id) { |
| 21556 | 22578 | case ZigTypeIdInvalid: |
| ... | ... | @@ -21567,13 +22589,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21567 | 22589 | case ZigTypeIdFn: |
| 21568 | 22590 | case ZigTypeIdErrorSet: { |
| 21569 | 22591 | if (pointee_val) { |
| 21570 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 22592 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr); |
| 21571 | 22593 | copy_const_val(result->value, pointee_val); |
| 21572 | 22594 | result->value->type = target_type; |
| 21573 | 22595 | return result; |
| 21574 | 22596 | } |
| 21575 | 22597 | |
| 21576 | | IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22598 | IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21577 | 22599 | result->value->type = target_type; |
| 21578 | 22600 | return result; |
| 21579 | 22601 | } |
| ... | ... | @@ -21582,52 +22604,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21582 | 22604 | if (!decl_node->data.container_decl.auto_enum && |
| 21583 | 22605 | decl_node->data.container_decl.init_arg_expr == nullptr) |
| 21584 | 22606 | { |
| 21585 | | ErrorMsg *msg = ir_add_error(ira, target_value_ptr, |
| 22607 | ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base, |
| 21586 | 22608 | buf_sprintf("switch on union which has no attached enum")); |
| 21587 | 22609 | add_error_note(ira->codegen, msg, decl_node, |
| 21588 | 22610 | buf_sprintf("consider 'union(enum)' here")); |
| 21589 | | return ira->codegen->invalid_instruction; |
| 22611 | return ira->codegen->invalid_inst_gen; |
| 21590 | 22612 | } |
| 21591 | 22613 | ZigType *tag_type = target_type->data.unionation.tag_type; |
| 21592 | 22614 | assert(tag_type != nullptr); |
| 21593 | 22615 | assert(tag_type->id == ZigTypeIdEnum); |
| 21594 | 22616 | if (pointee_val) { |
| 21595 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 22617 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 21596 | 22618 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 21597 | 22619 | return result; |
| 21598 | 22620 | } |
| 21599 | 22621 | if (tag_type->data.enumeration.src_field_count == 1) { |
| 21600 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 22622 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 21601 | 22623 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 21602 | 22624 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 21603 | 22625 | return result; |
| 21604 | 22626 | } |
| 21605 | 22627 | |
| 21606 | | IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22628 | IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21607 | 22629 | union_value->value->type = target_type; |
| 21608 | 22630 | |
| 21609 | | IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope, |
| 21610 | | switch_target_instruction->base.source_node, union_value); |
| 21611 | | union_tag_inst->value->type = tag_type; |
| 21612 | | return union_tag_inst; |
| 22631 | return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type); |
| 21613 | 22632 | } |
| 21614 | 22633 | case ZigTypeIdEnum: { |
| 21615 | 22634 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| 21616 | | return ira->codegen->invalid_instruction; |
| 22635 | return ira->codegen->invalid_inst_gen; |
| 21617 | 22636 | if (target_type->data.enumeration.src_field_count == 1) { |
| 21618 | 22637 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 21619 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 22638 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 21620 | 22639 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 21621 | 22640 | return result; |
| 21622 | 22641 | } |
| 21623 | 22642 | |
| 21624 | 22643 | if (pointee_val) { |
| 21625 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 22644 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 21626 | 22645 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 21627 | 22646 | return result; |
| 21628 | 22647 | } |
| 21629 | 22648 | |
| 21630 | | IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22649 | IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21631 | 22650 | enum_value->value->type = target_type; |
| 21632 | 22651 | return enum_value; |
| 21633 | 22652 | } |
| ... | ... | @@ -21643,17 +22662,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21643 | 22662 | case ZigTypeIdVector: |
| 21644 | 22663 | case ZigTypeIdFnFrame: |
| 21645 | 22664 | case ZigTypeIdAnyFrame: |
| 21646 | | ir_add_error(ira, &switch_target_instruction->base, |
| 22665 | ir_add_error(ira, &switch_target_instruction->base.base, |
| 21647 | 22666 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 21648 | | return ira->codegen->invalid_instruction; |
| 22667 | return ira->codegen->invalid_inst_gen; |
| 21649 | 22668 | } |
| 21650 | 22669 | zig_unreachable(); |
| 21651 | 22670 | } |
| 21652 | 22671 | |
| 21653 | | static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 21654 | | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 22672 | static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) { |
| 22673 | IrInstGen *target_value_ptr = instruction->target_value_ptr->child; |
| 21655 | 22674 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21656 | | return ira->codegen->invalid_instruction; |
| 22675 | return ira->codegen->invalid_inst_gen; |
| 21657 | 22676 | |
| 21658 | 22677 | ZigType *ref_type = target_value_ptr->value->type; |
| 21659 | 22678 | assert(ref_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -21664,62 +22683,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21664 | 22683 | assert(enum_type->id == ZigTypeIdEnum); |
| 21665 | 22684 | assert(instruction->prongs_len > 0); |
| 21666 | 22685 | |
| 21667 | | IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; |
| 22686 | IrInstGen *first_prong_value = instruction->prongs_ptr[0]->child; |
| 21668 | 22687 | if (type_is_invalid(first_prong_value->value->type)) |
| 21669 | | return ira->codegen->invalid_instruction; |
| 22688 | return ira->codegen->invalid_inst_gen; |
| 21670 | 22689 | |
| 21671 | | IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 22690 | IrInstGen *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 21672 | 22691 | if (type_is_invalid(first_casted_prong_value->value->type)) |
| 21673 | | return ira->codegen->invalid_instruction; |
| 22692 | return ira->codegen->invalid_inst_gen; |
| 21674 | 22693 | |
| 21675 | 22694 | ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| 21676 | 22695 | if (first_prong_val == nullptr) |
| 21677 | | return ira->codegen->invalid_instruction; |
| 22696 | return ira->codegen->invalid_inst_gen; |
| 21678 | 22697 | |
| 21679 | 22698 | TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag); |
| 21680 | 22699 | |
| 21681 | 22700 | ErrorMsg *invalid_payload_msg = nullptr; |
| 21682 | 22701 | for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) { |
| 21683 | | IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 22702 | IrInstGen *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 21684 | 22703 | if (type_is_invalid(this_prong_inst->value->type)) |
| 21685 | | return ira->codegen->invalid_instruction; |
| 22704 | return ira->codegen->invalid_inst_gen; |
| 21686 | 22705 | |
| 21687 | | IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 22706 | IrInstGen *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 21688 | 22707 | if (type_is_invalid(this_casted_prong_value->value->type)) |
| 21689 | | return ira->codegen->invalid_instruction; |
| 22708 | return ira->codegen->invalid_inst_gen; |
| 21690 | 22709 | |
| 21691 | 22710 | ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| 21692 | 22711 | if (this_prong == nullptr) |
| 21693 | | return ira->codegen->invalid_instruction; |
| 22712 | return ira->codegen->invalid_inst_gen; |
| 21694 | 22713 | |
| 21695 | 22714 | TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag); |
| 21696 | 22715 | ZigType *payload_type = payload_field->type_entry; |
| 21697 | 22716 | if (first_field->type_entry != payload_type) { |
| 21698 | 22717 | if (invalid_payload_msg == nullptr) { |
| 21699 | | invalid_payload_msg = ir_add_error(ira, &instruction->base, |
| 22718 | invalid_payload_msg = ir_add_error(ira, &instruction->base.base, |
| 21700 | 22719 | buf_sprintf("capture group with incompatible types")); |
| 21701 | | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node, |
| 22720 | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node, |
| 21702 | 22721 | buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name))); |
| 21703 | 22722 | } |
| 21704 | | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node, |
| 22723 | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node, |
| 21705 | 22724 | buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name))); |
| 21706 | 22725 | } |
| 21707 | 22726 | } |
| 21708 | 22727 | |
| 21709 | 22728 | if (invalid_payload_msg != nullptr) { |
| 21710 | | return ira->codegen->invalid_instruction; |
| 22729 | return ira->codegen->invalid_inst_gen; |
| 21711 | 22730 | } |
| 21712 | 22731 | |
| 21713 | 22732 | if (instr_is_comptime(target_value_ptr)) { |
| 21714 | 22733 | ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 21715 | 22734 | if (!target_value_ptr) |
| 21716 | | return ira->codegen->invalid_instruction; |
| 22735 | return ira->codegen->invalid_inst_gen; |
| 21717 | 22736 | |
| 21718 | | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); |
| 22737 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node); |
| 21719 | 22738 | if (pointee_val == nullptr) |
| 21720 | | return ira->codegen->invalid_instruction; |
| 22739 | return ira->codegen->invalid_inst_gen; |
| 21721 | 22740 | |
| 21722 | | IrInstruction *result = ir_const(ira, &instruction->base, |
| 22741 | IrInstGen *result = ir_const(ira, &instruction->base.base, |
| 21723 | 22742 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 21724 | 22743 | target_val_ptr->type->data.pointer.is_const)); |
| 21725 | 22744 | ZigValue *out_val = result->value; |
| ... | ... | @@ -21729,11 +22748,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21729 | 22748 | return result; |
| 21730 | 22749 | } |
| 21731 | 22750 | |
| 21732 | | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 21733 | | instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false); |
| 21734 | | result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 22751 | ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 21735 | 22752 | target_value_ptr->value->type->data.pointer.is_const); |
| 21736 | | return result; |
| 22753 | return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field, |
| 22754 | false, false, result_type); |
| 21737 | 22755 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| 21738 | 22756 | // construct an error set from the prong values |
| 21739 | 22757 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| ... | ... | @@ -21746,7 +22764,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21746 | 22764 | for (size_t i = 0; i < instruction->prongs_len; i += 1) { |
| 21747 | 22765 | ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child); |
| 21748 | 22766 | if (err == nullptr) |
| 21749 | | return ira->codegen->invalid_instruction; |
| 22767 | return ira->codegen->invalid_inst_gen; |
| 21750 | 22768 | error_list.append(err); |
| 21751 | 22769 | buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name)); |
| 21752 | 22770 | } |
| ... | ... | @@ -21762,29 +22780,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21762 | 22780 | ref_type->data.pointer.explicit_alignment, |
| 21763 | 22781 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 21764 | 22782 | ref_type->data.pointer.allow_zero); |
| 21765 | | return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type, |
| 21766 | | &instruction->base, false); |
| 22783 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22784 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 21767 | 22785 | } else { |
| 21768 | | ir_add_error(ira, &instruction->base, |
| 22786 | ir_add_error(ira, &instruction->base.base, |
| 21769 | 22787 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| 21770 | | return ira->codegen->invalid_instruction; |
| 22788 | return ira->codegen->invalid_inst_gen; |
| 21771 | 22789 | } |
| 21772 | 22790 | } |
| 21773 | 22791 | |
| 21774 | | static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21775 | | IrInstructionSwitchElseVar *instruction) |
| 22792 | static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 22793 | IrInstSrcSwitchElseVar *instruction) |
| 21776 | 22794 | { |
| 21777 | | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 22795 | IrInstGen *target_value_ptr = instruction->target_value_ptr->child; |
| 21778 | 22796 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21779 | | return ira->codegen->invalid_instruction; |
| 22797 | return ira->codegen->invalid_inst_gen; |
| 21780 | 22798 | |
| 21781 | 22799 | ZigType *ref_type = target_value_ptr->value->type; |
| 21782 | 22800 | assert(ref_type->id == ZigTypeIdPointer); |
| 21783 | 22801 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 21784 | 22802 | if (target_type->id == ZigTypeIdErrorSet) { |
| 21785 | 22803 | // make a new set that has the other cases removed |
| 21786 | | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) { |
| 21787 | | return ira->codegen->invalid_instruction; |
| 22804 | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) { |
| 22805 | return ira->codegen->invalid_inst_gen; |
| 21788 | 22806 | } |
| 21789 | 22807 | if (type_is_global_error_set(target_type)) { |
| 21790 | 22808 | // the type of the else capture variable still has to be the global error set. |
| ... | ... | @@ -21793,18 +22811,20 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21793 | 22811 | } |
| 21794 | 22812 | // Make note of the errors handled by other cases |
| 21795 | 22813 | ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| 21796 | | for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) { |
| 21797 | | IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; |
| 21798 | | IrInstruction *case_expr = br_case->value->child; |
| 22814 | // We may not have any case in the switch if this is a lone else |
| 22815 | const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0; |
| 22816 | for (size_t case_i = 0; case_i < switch_cases; case_i += 1) { |
| 22817 | IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; |
| 22818 | IrInstGen *case_expr = br_case->value->child; |
| 21799 | 22819 | if (case_expr->value->type->id == ZigTypeIdErrorSet) { |
| 21800 | 22820 | ErrorTableEntry *err = ir_resolve_error(ira, case_expr); |
| 21801 | 22821 | if (err == nullptr) |
| 21802 | | return ira->codegen->invalid_instruction; |
| 22822 | return ira->codegen->invalid_inst_gen; |
| 21803 | 22823 | errors[err->value] = err; |
| 21804 | 22824 | } else if (case_expr->value->type->id == ZigTypeIdMetaType) { |
| 21805 | 22825 | ZigType *err_set_type = ir_resolve_type(ira, case_expr); |
| 21806 | 22826 | if (type_is_invalid(err_set_type)) |
| 21807 | | return ira->codegen->invalid_instruction; |
| 22827 | return ira->codegen->invalid_inst_gen; |
| 21808 | 22828 | populate_error_set_table(errors, err_set_type); |
| 21809 | 22829 | } else { |
| 21810 | 22830 | zig_unreachable(); |
| ... | ... | @@ -21843,27 +22863,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21843 | 22863 | ref_type->data.pointer.explicit_alignment, |
| 21844 | 22864 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 21845 | 22865 | ref_type->data.pointer.allow_zero); |
| 21846 | | return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type, |
| 21847 | | &instruction->base, false); |
| 22866 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 22867 | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false); |
| 21848 | 22868 | } |
| 21849 | 22869 | |
| 21850 | 22870 | return target_value_ptr; |
| 21851 | 22871 | } |
| 21852 | 22872 | |
| 21853 | | static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { |
| 21854 | | IrInstruction *value = instruction->value->child; |
| 21855 | | return ir_analyze_union_tag(ira, &instruction->base, value); |
| 21856 | | } |
| 21857 | | |
| 21858 | | static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { |
| 22873 | static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_instruction) { |
| 21859 | 22874 | Error err; |
| 21860 | 22875 | |
| 21861 | | IrInstruction *name_value = import_instruction->name->child; |
| 22876 | IrInstGen *name_value = import_instruction->name->child; |
| 21862 | 22877 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 21863 | 22878 | if (!import_target_str) |
| 21864 | | return ira->codegen->invalid_instruction; |
| 22879 | return ira->codegen->invalid_inst_gen; |
| 21865 | 22880 | |
| 21866 | | AstNode *source_node = import_instruction->base.source_node; |
| 22881 | AstNode *source_node = import_instruction->base.base.source_node; |
| 21867 | 22882 | ZigType *import = source_node->owner; |
| 21868 | 22883 | |
| 21869 | 22884 | ZigType *target_import; |
| ... | ... | @@ -21876,48 +22891,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 21876 | 22891 | ir_add_error_node(ira, source_node, |
| 21877 | 22892 | buf_sprintf("import of file outside package path: '%s'", |
| 21878 | 22893 | buf_ptr(import_target_path))); |
| 21879 | | return ira->codegen->invalid_instruction; |
| 22894 | return ira->codegen->invalid_inst_gen; |
| 21880 | 22895 | } else if (err == ErrorFileNotFound) { |
| 21881 | 22896 | ir_add_error_node(ira, source_node, |
| 21882 | 22897 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); |
| 21883 | | return ira->codegen->invalid_instruction; |
| 22898 | return ira->codegen->invalid_inst_gen; |
| 21884 | 22899 | } else { |
| 21885 | 22900 | ir_add_error_node(ira, source_node, |
| 21886 | 22901 | buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); |
| 21887 | | return ira->codegen->invalid_instruction; |
| 22902 | return ira->codegen->invalid_inst_gen; |
| 21888 | 22903 | } |
| 21889 | 22904 | } |
| 21890 | 22905 | |
| 21891 | | return ir_const_type(ira, &import_instruction->base, target_import); |
| 22906 | return ir_const_type(ira, &import_instruction->base.base, target_import); |
| 21892 | 22907 | } |
| 21893 | 22908 | |
| 21894 | | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 21895 | | IrInstruction *value = ref_instruction->value->child; |
| 22909 | static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) { |
| 22910 | IrInstGen *value = ref_instruction->value->child; |
| 21896 | 22911 | if (type_is_invalid(value->value->type)) |
| 21897 | | return ira->codegen->invalid_instruction; |
| 21898 | | return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 22912 | return ira->codegen->invalid_inst_gen; |
| 22913 | return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 21899 | 22914 | } |
| 21900 | 22915 | |
| 21901 | | static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *source_instruction, |
| 21902 | | AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstruction *field_result_loc, |
| 21903 | | IrInstruction *result_loc) |
| 22916 | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction, |
| 22917 | AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc, |
| 22918 | IrInstGen *result_loc) |
| 21904 | 22919 | { |
| 21905 | 22920 | Error err; |
| 21906 | 22921 | assert(union_type->id == ZigTypeIdUnion); |
| 21907 | 22922 | |
| 21908 | 22923 | if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown))) |
| 21909 | | return ira->codegen->invalid_instruction; |
| 22924 | return ira->codegen->invalid_inst_gen; |
| 21910 | 22925 | |
| 21911 | 22926 | TypeUnionField *type_field = find_union_type_field(union_type, field_name); |
| 21912 | 22927 | if (type_field == nullptr) { |
| 21913 | 22928 | ir_add_error_node(ira, field_source_node, |
| 21914 | 22929 | buf_sprintf("no member named '%s' in union '%s'", |
| 21915 | 22930 | buf_ptr(field_name), buf_ptr(&union_type->name))); |
| 21916 | | return ira->codegen->invalid_instruction; |
| 22931 | return ira->codegen->invalid_inst_gen; |
| 21917 | 22932 | } |
| 21918 | 22933 | |
| 21919 | 22934 | if (type_is_invalid(type_field->type_entry)) |
| 21920 | | return ira->codegen->invalid_instruction; |
| 22935 | return ira->codegen->invalid_inst_gen; |
| 21921 | 22936 | |
| 21922 | 22937 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21923 | 22938 | if (instr_is_comptime(field_result_loc) && |
| ... | ... | @@ -21929,42 +22944,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc |
| 21929 | 22944 | } |
| 21930 | 22945 | } |
| 21931 | 22946 | |
| 21932 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope) |
| 22947 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope) |
| 21933 | 22948 | || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes; |
| 21934 | 22949 | |
| 21935 | | IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| 22950 | IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| 21936 | 22951 | if (is_comptime && !instr_is_comptime(result)) { |
| 21937 | | ir_add_error(ira, field_result_loc, |
| 22952 | ir_add_error(ira, &field_result_loc->base, |
| 21938 | 22953 | buf_sprintf("unable to evaluate constant expression")); |
| 21939 | | return ira->codegen->invalid_instruction; |
| 22954 | return ira->codegen->invalid_inst_gen; |
| 21940 | 22955 | } |
| 21941 | 22956 | return result; |
| 21942 | 22957 | } |
| 21943 | 22958 | |
| 21944 | | static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 21945 | | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields, |
| 21946 | | IrInstruction *result_loc) |
| 22959 | static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr, |
| 22960 | ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields, |
| 22961 | IrInstGen *result_loc) |
| 21947 | 22962 | { |
| 21948 | 22963 | Error err; |
| 21949 | 22964 | if (container_type->id == ZigTypeIdUnion) { |
| 21950 | 22965 | if (instr_field_count != 1) { |
| 21951 | | ir_add_error(ira, instruction, |
| 22966 | ir_add_error(ira, source_instr, |
| 21952 | 22967 | buf_sprintf("union initialization expects exactly one field")); |
| 21953 | | return ira->codegen->invalid_instruction; |
| 22968 | return ira->codegen->invalid_inst_gen; |
| 21954 | 22969 | } |
| 21955 | | IrInstructionContainerInitFieldsField *field = &fields[0]; |
| 21956 | | IrInstruction *field_result_loc = field->result_loc->child; |
| 22970 | IrInstSrcContainerInitFieldsField *field = &fields[0]; |
| 22971 | IrInstGen *field_result_loc = field->result_loc->child; |
| 21957 | 22972 | if (type_is_invalid(field_result_loc->value->type)) |
| 21958 | | return ira->codegen->invalid_instruction; |
| 22973 | return ira->codegen->invalid_inst_gen; |
| 21959 | 22974 | |
| 21960 | | return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name, |
| 22975 | return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name, |
| 21961 | 22976 | field_result_loc, result_loc); |
| 21962 | 22977 | } |
| 21963 | 22978 | if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) { |
| 21964 | | ir_add_error(ira, instruction, |
| 22979 | ir_add_error(ira, source_instr, |
| 21965 | 22980 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 21966 | 22981 | buf_ptr(&container_type->name))); |
| 21967 | | return ira->codegen->invalid_instruction; |
| 22982 | return ira->codegen->invalid_inst_gen; |
| 21968 | 22983 | } |
| 21969 | 22984 | |
| 21970 | 22985 | if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) { |
| ... | ... | @@ -21973,16 +22988,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 21973 | 22988 | } |
| 21974 | 22989 | |
| 21975 | 22990 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 21976 | | return ira->codegen->invalid_instruction; |
| 22991 | return ira->codegen->invalid_inst_gen; |
| 21977 | 22992 | |
| 21978 | 22993 | size_t actual_field_count = container_type->data.structure.src_field_count; |
| 21979 | 22994 | |
| 21980 | | IrInstruction *first_non_const_instruction = nullptr; |
| 22995 | IrInstGen *first_non_const_instruction = nullptr; |
| 21981 | 22996 | |
| 21982 | 22997 | AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count); |
| 21983 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 22998 | ZigList<IrInstGen *> const_ptrs = {}; |
| 21984 | 22999 | |
| 21985 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope) |
| 23000 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope) |
| 21986 | 23001 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; |
| 21987 | 23002 | |
| 21988 | 23003 | |
| ... | ... | @@ -21998,29 +23013,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 21998 | 23013 | // comptime-known values. |
| 21999 | 23014 | |
| 22000 | 23015 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 22001 | | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 23016 | IrInstSrcContainerInitFieldsField *field = &fields[i]; |
| 22002 | 23017 | |
| 22003 | | IrInstruction *field_result_loc = field->result_loc->child; |
| 23018 | IrInstGen *field_result_loc = field->result_loc->child; |
| 22004 | 23019 | if (type_is_invalid(field_result_loc->value->type)) |
| 22005 | | return ira->codegen->invalid_instruction; |
| 23020 | return ira->codegen->invalid_inst_gen; |
| 22006 | 23021 | |
| 22007 | 23022 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| 22008 | 23023 | if (!type_field) { |
| 22009 | 23024 | ir_add_error_node(ira, field->source_node, |
| 22010 | 23025 | buf_sprintf("no member named '%s' in struct '%s'", |
| 22011 | 23026 | buf_ptr(field->name), buf_ptr(&container_type->name))); |
| 22012 | | return ira->codegen->invalid_instruction; |
| 23027 | return ira->codegen->invalid_inst_gen; |
| 22013 | 23028 | } |
| 22014 | 23029 | |
| 22015 | 23030 | if (type_is_invalid(type_field->type_entry)) |
| 22016 | | return ira->codegen->invalid_instruction; |
| 23031 | return ira->codegen->invalid_inst_gen; |
| 22017 | 23032 | |
| 22018 | 23033 | size_t field_index = type_field->src_index; |
| 22019 | 23034 | AstNode *existing_assign_node = field_assign_nodes[field_index]; |
| 22020 | 23035 | if (existing_assign_node) { |
| 22021 | 23036 | ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field")); |
| 22022 | 23037 | add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here")); |
| 22023 | | return ira->codegen->invalid_instruction; |
| 23038 | return ira->codegen->invalid_inst_gen; |
| 22024 | 23039 | } |
| 22025 | 23040 | field_assign_nodes[field_index] = field->source_node; |
| 22026 | 23041 | |
| ... | ... | @@ -22041,20 +23056,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 22041 | 23056 | TypeStructField *field = container_type->data.structure.fields[i]; |
| 22042 | 23057 | memoize_field_init_val(ira->codegen, container_type, field); |
| 22043 | 23058 | if (field->init_val == nullptr) { |
| 22044 | | ir_add_error_node(ira, instruction->source_node, |
| 23059 | ir_add_error(ira, source_instr, |
| 22045 | 23060 | buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name))); |
| 22046 | 23061 | any_missing = true; |
| 22047 | 23062 | continue; |
| 22048 | 23063 | } |
| 22049 | 23064 | if (type_is_invalid(field->init_val->type)) |
| 22050 | | return ira->codegen->invalid_instruction; |
| 23065 | return ira->codegen->invalid_inst_gen; |
| 22051 | 23066 | |
| 22052 | | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 23067 | IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type); |
| 22053 | 23068 | copy_const_val(runtime_inst->value, field->init_val); |
| 22054 | 23069 | |
| 22055 | | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 23070 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc, |
| 22056 | 23071 | container_type, true); |
| 22057 | | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 23072 | ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false); |
| 22058 | 23073 | if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 22059 | 23074 | const_ptrs.append(field_ptr); |
| 22060 | 23075 | } else { |
| ... | ... | @@ -22062,39 +23077,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 22062 | 23077 | } |
| 22063 | 23078 | } |
| 22064 | 23079 | if (any_missing) |
| 22065 | | return ira->codegen->invalid_instruction; |
| 23080 | return ira->codegen->invalid_inst_gen; |
| 22066 | 23081 | |
| 22067 | 23082 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 22068 | 23083 | if (const_ptrs.length != actual_field_count) { |
| 22069 | 23084 | result_loc->value->special = ConstValSpecialRuntime; |
| 22070 | 23085 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 22071 | | IrInstruction *field_result_loc = const_ptrs.at(i); |
| 22072 | | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); |
| 23086 | IrInstGen *field_result_loc = const_ptrs.at(i); |
| 23087 | IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr); |
| 22073 | 23088 | field_result_loc->value->special = ConstValSpecialRuntime; |
| 22074 | | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 23089 | ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false); |
| 22075 | 23090 | } |
| 22076 | 23091 | } |
| 22077 | 23092 | } |
| 22078 | 23093 | |
| 22079 | | IrInstruction *result = ir_get_deref(ira, instruction, result_loc, nullptr); |
| 23094 | IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr); |
| 22080 | 23095 | |
| 22081 | 23096 | if (is_comptime && !instr_is_comptime(result)) { |
| 22082 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 23097 | ir_add_error_node(ira, first_non_const_instruction->base.source_node, |
| 22083 | 23098 | buf_sprintf("unable to evaluate constant expression")); |
| 22084 | | return ira->codegen->invalid_instruction; |
| 23099 | return ira->codegen->invalid_inst_gen; |
| 22085 | 23100 | } |
| 22086 | 23101 | |
| 22087 | 23102 | return result; |
| 22088 | 23103 | } |
| 22089 | 23104 | |
| 22090 | | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22091 | | IrInstructionContainerInitList *instruction) |
| 23105 | static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 23106 | IrInstSrcContainerInitList *instruction) |
| 22092 | 23107 | { |
| 22093 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 22094 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 23108 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23109 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22095 | 23110 | if (type_is_invalid(result_loc->value->type)) |
| 22096 | 23111 | return result_loc; |
| 22097 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 23112 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 22098 | 23113 | |
| 22099 | 23114 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 22100 | 23115 | |
| ... | ... | @@ -22104,24 +23119,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22104 | 23119 | ir_add_error_node(ira, instruction->init_array_type_source_node, |
| 22105 | 23120 | buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'", |
| 22106 | 23121 | buf_ptr(&container_type->name))); |
| 22107 | | return ira->codegen->invalid_instruction; |
| 23122 | return ira->codegen->invalid_inst_gen; |
| 22108 | 23123 | } |
| 22109 | 23124 | |
| 22110 | 23125 | if (container_type->id == ZigTypeIdVoid) { |
| 22111 | 23126 | if (elem_count != 0) { |
| 22112 | | ir_add_error_node(ira, instruction->base.source_node, |
| 23127 | ir_add_error_node(ira, instruction->base.base.source_node, |
| 22113 | 23128 | buf_sprintf("void expression expects no arguments")); |
| 22114 | | return ira->codegen->invalid_instruction; |
| 23129 | return ira->codegen->invalid_inst_gen; |
| 22115 | 23130 | } |
| 22116 | | return ir_const_void(ira, &instruction->base); |
| 23131 | return ir_const_void(ira, &instruction->base.base); |
| 22117 | 23132 | } |
| 22118 | 23133 | |
| 22119 | 23134 | if (container_type->id == ZigTypeIdStruct && elem_count == 0) { |
| 22120 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 22121 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 23135 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23136 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22122 | 23137 | if (type_is_invalid(result_loc->value->type)) |
| 22123 | 23138 | return result_loc; |
| 22124 | | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc); |
| 23139 | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc); |
| 22125 | 23140 | } |
| 22126 | 23141 | |
| 22127 | 23142 | if (container_type->id == ZigTypeIdArray) { |
| ... | ... | @@ -22129,10 +23144,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22129 | 23144 | if (container_type->data.array.len != elem_count) { |
| 22130 | 23145 | ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr); |
| 22131 | 23146 | |
| 22132 | | ir_add_error(ira, &instruction->base, |
| 23147 | ir_add_error(ira, &instruction->base.base, |
| 22133 | 23148 | buf_sprintf("expected %s literal, found %s literal", |
| 22134 | 23149 | buf_ptr(&container_type->name), buf_ptr(&literal_type->name))); |
| 22135 | | return ira->codegen->invalid_instruction; |
| 23150 | return ira->codegen->invalid_inst_gen; |
| 22136 | 23151 | } |
| 22137 | 23152 | } else if (container_type->id == ZigTypeIdStruct && |
| 22138 | 23153 | container_type->data.structure.resolve_status == ResolveStatusBeingInferred) |
| ... | ... | @@ -22142,17 +23157,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22142 | 23157 | } else if (container_type->id == ZigTypeIdVector) { |
| 22143 | 23158 | // OK |
| 22144 | 23159 | } else { |
| 22145 | | ir_add_error_node(ira, instruction->base.source_node, |
| 23160 | ir_add_error(ira, &instruction->base.base, |
| 22146 | 23161 | buf_sprintf("type '%s' does not support array initialization", |
| 22147 | 23162 | buf_ptr(&container_type->name))); |
| 22148 | | return ira->codegen->invalid_instruction; |
| 23163 | return ira->codegen->invalid_inst_gen; |
| 22149 | 23164 | } |
| 22150 | 23165 | |
| 22151 | 23166 | switch (type_has_one_possible_value(ira->codegen, container_type)) { |
| 22152 | 23167 | case OnePossibleValueInvalid: |
| 22153 | | return ira->codegen->invalid_instruction; |
| 23168 | return ira->codegen->invalid_inst_gen; |
| 22154 | 23169 | case OnePossibleValueYes: |
| 22155 | | return ir_const_move(ira, &instruction->base, |
| 23170 | return ir_const_move(ira, &instruction->base.base, |
| 22156 | 23171 | get_the_one_possible_value(ira->codegen, container_type)); |
| 22157 | 23172 | case OnePossibleValueNo: |
| 22158 | 23173 | break; |
| ... | ... | @@ -22161,16 +23176,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22161 | 23176 | bool is_comptime; |
| 22162 | 23177 | switch (type_requires_comptime(ira->codegen, container_type)) { |
| 22163 | 23178 | case ReqCompTimeInvalid: |
| 22164 | | return ira->codegen->invalid_instruction; |
| 23179 | return ira->codegen->invalid_inst_gen; |
| 22165 | 23180 | case ReqCompTimeNo: |
| 22166 | | is_comptime = ir_should_inline(ira->new_irb.exec, instruction->base.scope); |
| 23181 | is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope); |
| 22167 | 23182 | break; |
| 22168 | 23183 | case ReqCompTimeYes: |
| 22169 | 23184 | is_comptime = true; |
| 22170 | 23185 | break; |
| 22171 | 23186 | } |
| 22172 | 23187 | |
| 22173 | | IrInstruction *first_non_const_instruction = nullptr; |
| 23188 | IrInstGen *first_non_const_instruction = nullptr; |
| 22174 | 23189 | |
| 22175 | 23190 | // The Result Location Mechanism has already emitted runtime instructions to |
| 22176 | 23191 | // initialize runtime elements and has omitted instructions for the comptime |
| ... | ... | @@ -22179,12 +23194,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22179 | 23194 | // array initialization can be a comptime value, overwrite ConstPtrMutInfer with |
| 22180 | 23195 | // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the |
| 22181 | 23196 | // elements that have comptime-known values. |
| 22182 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 23197 | ZigList<IrInstGen *> const_ptrs = {}; |
| 22183 | 23198 | |
| 22184 | 23199 | for (size_t i = 0; i < elem_count; i += 1) { |
| 22185 | | IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 23200 | IrInstGen *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 22186 | 23201 | if (type_is_invalid(elem_result_loc->value->type)) |
| 22187 | | return ira->codegen->invalid_instruction; |
| 23202 | return ira->codegen->invalid_inst_gen; |
| 22188 | 23203 | |
| 22189 | 23204 | assert(elem_result_loc->value->type->id == ZigTypeIdPointer); |
| 22190 | 23205 | |
| ... | ... | @@ -22201,81 +23216,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22201 | 23216 | if (const_ptrs.length != elem_count) { |
| 22202 | 23217 | result_loc->value->special = ConstValSpecialRuntime; |
| 22203 | 23218 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 22204 | | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 23219 | IrInstGen *elem_result_loc = const_ptrs.at(i); |
| 22205 | 23220 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 22206 | 23221 | if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) { |
| 22207 | 23222 | // This field will be generated comptime; no need to do this. |
| 22208 | 23223 | continue; |
| 22209 | 23224 | } |
| 22210 | | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 23225 | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 22211 | 23226 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 22212 | | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 23227 | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false); |
| 22213 | 23228 | } |
| 22214 | 23229 | } |
| 22215 | 23230 | } |
| 22216 | 23231 | |
| 22217 | | IrInstruction *result = ir_get_deref(ira, &instruction->base, result_loc, nullptr); |
| 23232 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr); |
| 22218 | 23233 | if (instr_is_comptime(result)) |
| 22219 | 23234 | return result; |
| 22220 | 23235 | |
| 22221 | 23236 | if (is_comptime) { |
| 22222 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 23237 | ir_add_error(ira, &first_non_const_instruction->base, |
| 22223 | 23238 | buf_sprintf("unable to evaluate constant expression")); |
| 22224 | | return ira->codegen->invalid_instruction; |
| 23239 | return ira->codegen->invalid_inst_gen; |
| 22225 | 23240 | } |
| 22226 | 23241 | |
| 22227 | 23242 | ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; |
| 22228 | 23243 | if (is_slice(result_elem_type)) { |
| 22229 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 23244 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 22230 | 23245 | buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", |
| 22231 | 23246 | buf_ptr(&result_elem_type->name))); |
| 22232 | | add_error_note(ira->codegen, msg, first_non_const_instruction->source_node, |
| 23247 | add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node, |
| 22233 | 23248 | buf_sprintf("this value is not comptime-known")); |
| 22234 | | return ira->codegen->invalid_instruction; |
| 23249 | return ira->codegen->invalid_inst_gen; |
| 22235 | 23250 | } |
| 22236 | 23251 | return result; |
| 22237 | 23252 | } |
| 22238 | 23253 | |
| 22239 | | static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 22240 | | IrInstructionContainerInitFields *instruction) |
| 23254 | static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 23255 | IrInstSrcContainerInitFields *instruction) |
| 22241 | 23256 | { |
| 22242 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 22243 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 23257 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23258 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22244 | 23259 | if (type_is_invalid(result_loc->value->type)) |
| 22245 | 23260 | return result_loc; |
| 22246 | 23261 | |
| 22247 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 23262 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 22248 | 23263 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 22249 | 23264 | |
| 22250 | | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 23265 | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, |
| 22251 | 23266 | instruction->field_count, instruction->fields, result_loc); |
| 22252 | 23267 | } |
| 22253 | 23268 | |
| 22254 | | static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 22255 | | IrInstructionCompileErr *instruction) |
| 22256 | | { |
| 22257 | | IrInstruction *msg_value = instruction->msg->child; |
| 23269 | static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) { |
| 23270 | IrInstGen *msg_value = instruction->msg->child; |
| 22258 | 23271 | Buf *msg_buf = ir_resolve_str(ira, msg_value); |
| 22259 | 23272 | if (!msg_buf) |
| 22260 | | return ira->codegen->invalid_instruction; |
| 23273 | return ira->codegen->invalid_inst_gen; |
| 22261 | 23274 | |
| 22262 | | ir_add_error(ira, &instruction->base, msg_buf); |
| 23275 | ir_add_error(ira, &instruction->base.base, msg_buf); |
| 22263 | 23276 | |
| 22264 | | return ira->codegen->invalid_instruction; |
| 23277 | return ira->codegen->invalid_inst_gen; |
| 22265 | 23278 | } |
| 22266 | 23279 | |
| 22267 | | static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { |
| 23280 | static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) { |
| 22268 | 23281 | Buf buf = BUF_INIT; |
| 22269 | 23282 | fprintf(stderr, "| "); |
| 22270 | 23283 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| 22271 | | IrInstruction *msg = instruction->msg_list[i]->child; |
| 23284 | IrInstGen *msg = instruction->msg_list[i]->child; |
| 22272 | 23285 | if (type_is_invalid(msg->value->type)) |
| 22273 | | return ira->codegen->invalid_instruction; |
| 23286 | return ira->codegen->invalid_inst_gen; |
| 22274 | 23287 | buf_resize(&buf, 0); |
| 22275 | 23288 | if (msg->value->special == ConstValSpecialLazy) { |
| 22276 | 23289 | // Resolve any lazy value that's passed, we need its value |
| 22277 | | if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value)) |
| 22278 | | return ira->codegen->invalid_instruction; |
| 23290 | if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value)) |
| 23291 | return ira->codegen->invalid_inst_gen; |
| 22279 | 23292 | } |
| 22280 | 23293 | render_const_value(ira->codegen, &buf, msg->value); |
| 22281 | 23294 | const char *comma_str = (i != 0) ? ", " : ""; |
| ... | ... | @@ -22283,25 +23296,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 22283 | 23296 | } |
| 22284 | 23297 | fprintf(stderr, "\n"); |
| 22285 | 23298 | |
| 22286 | | auto *expr = &instruction->base.source_node->data.fn_call_expr; |
| 23299 | auto *expr = &instruction->base.base.source_node->data.fn_call_expr; |
| 22287 | 23300 | if (!expr->seen) { |
| 22288 | 23301 | // Here we bypass higher level functions such as ir_add_error because we do not want |
| 22289 | 23302 | // invalidate_exec to be called. |
| 22290 | | add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement")); |
| 23303 | add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement")); |
| 22291 | 23304 | } |
| 22292 | 23305 | expr->seen = true; |
| 22293 | 23306 | |
| 22294 | | return ir_const_void(ira, &instruction->base); |
| 23307 | return ir_const_void(ira, &instruction->base.base); |
| 22295 | 23308 | } |
| 22296 | 23309 | |
| 22297 | | static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 22298 | | IrInstruction *value = instruction->value->child; |
| 23310 | static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) { |
| 23311 | IrInstGen *value = instruction->value->child; |
| 22299 | 23312 | if (type_is_invalid(value->value->type)) |
| 22300 | | return ira->codegen->invalid_instruction; |
| 23313 | return ira->codegen->invalid_inst_gen; |
| 22301 | 23314 | |
| 22302 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 23315 | IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 22303 | 23316 | if (type_is_invalid(casted_value->value->type)) |
| 22304 | | return ira->codegen->invalid_instruction; |
| 23317 | return ira->codegen->invalid_inst_gen; |
| 22305 | 23318 | |
| 22306 | 23319 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 22307 | 23320 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| ... | ... | @@ -22309,13 +23322,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 22309 | 23322 | if (instr_is_comptime(casted_value)) { |
| 22310 | 23323 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 22311 | 23324 | if (val == nullptr) |
| 22312 | | return ira->codegen->invalid_instruction; |
| 23325 | return ira->codegen->invalid_inst_gen; |
| 22313 | 23326 | ErrorTableEntry *err = casted_value->value->data.x_err_set; |
| 22314 | 23327 | if (!err->cached_error_name_val) { |
| 22315 | 23328 | ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; |
| 22316 | 23329 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 22317 | 23330 | } |
| 22318 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23331 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22319 | 23332 | copy_const_val(result->value, err->cached_error_name_val); |
| 22320 | 23333 | result->value->type = str_type; |
| 22321 | 23334 | return result; |
| ... | ... | @@ -22323,20 +23336,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 22323 | 23336 | |
| 22324 | 23337 | ira->codegen->generate_error_name_table = true; |
| 22325 | 23338 | |
| 22326 | | IrInstruction *result = ir_build_err_name(&ira->new_irb, |
| 22327 | | instruction->base.scope, instruction->base.source_node, value); |
| 22328 | | result->value->type = str_type; |
| 22329 | | return result; |
| 23339 | return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type); |
| 22330 | 23340 | } |
| 22331 | 23341 | |
| 22332 | | static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 23342 | static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) { |
| 22333 | 23343 | Error err; |
| 22334 | | IrInstruction *target = instruction->target->child; |
| 23344 | IrInstGen *target = instruction->target->child; |
| 22335 | 23345 | if (type_is_invalid(target->value->type)) |
| 22336 | | return ira->codegen->invalid_instruction; |
| 23346 | return ira->codegen->invalid_inst_gen; |
| 22337 | 23347 | |
| 22338 | 23348 | if (target->value->type->id == ZigTypeIdEnumLiteral) { |
| 22339 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23349 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22340 | 23350 | Buf *field_name = target->value->data.x_enum_literal; |
| 22341 | 23351 | ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee; |
| 22342 | 23352 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true); |
| ... | ... | @@ -22344,86 +23354,88 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 22344 | 23354 | } |
| 22345 | 23355 | |
| 22346 | 23356 | if (target->value->type->id == ZigTypeIdUnion) { |
| 22347 | | target = ir_analyze_union_tag(ira, &instruction->base, target); |
| 23357 | target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen); |
| 22348 | 23358 | if (type_is_invalid(target->value->type)) |
| 22349 | | return ira->codegen->invalid_instruction; |
| 23359 | return ira->codegen->invalid_inst_gen; |
| 22350 | 23360 | } |
| 22351 | 23361 | |
| 22352 | | assert(target->value->type->id == ZigTypeIdEnum); |
| 23362 | if (target->value->type->id != ZigTypeIdEnum) { |
| 23363 | ir_add_error(ira, &target->base, |
| 23364 | buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target->value->type->name))); |
| 23365 | return ira->codegen->invalid_inst_gen; |
| 23366 | } |
| 22353 | 23367 | |
| 22354 | 23368 | if (target->value->type->data.enumeration.src_field_count == 1 && |
| 22355 | 23369 | !target->value->type->data.enumeration.non_exhaustive) { |
| 22356 | 23370 | TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0]; |
| 22357 | 23371 | ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee; |
| 22358 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23372 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22359 | 23373 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true); |
| 22360 | 23374 | return result; |
| 22361 | 23375 | } |
| 22362 | 23376 | |
| 22363 | 23377 | if (instr_is_comptime(target)) { |
| 22364 | 23378 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 22365 | | return ira->codegen->invalid_instruction; |
| 23379 | return ira->codegen->invalid_inst_gen; |
| 22366 | 23380 | if (target->value->type->data.enumeration.non_exhaustive) { |
| 22367 | | add_node_error(ira->codegen, instruction->base.source_node, |
| 23381 | ir_add_error(ira, &instruction->base.base, |
| 22368 | 23382 | buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991")); |
| 22369 | | return ira->codegen->invalid_instruction; |
| 23383 | return ira->codegen->invalid_inst_gen; |
| 22370 | 23384 | } |
| 22371 | 23385 | TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); |
| 22372 | 23386 | ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 22373 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23387 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22374 | 23388 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true); |
| 22375 | 23389 | return result; |
| 22376 | 23390 | } |
| 22377 | 23391 | |
| 22378 | | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, |
| 22379 | | instruction->base.source_node, target); |
| 22380 | 23392 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 22381 | 23393 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 22382 | 23394 | true, false, PtrLenUnknown, |
| 22383 | 23395 | 0, 0, 0, false); |
| 22384 | | result->value->type = get_slice_type(ira->codegen, u8_ptr_type); |
| 22385 | | return result; |
| 23396 | ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 23397 | return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type); |
| 22386 | 23398 | } |
| 22387 | 23399 | |
| 22388 | | static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22389 | | IrInstructionFieldParentPtr *instruction) |
| 23400 | static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 23401 | IrInstSrcFieldParentPtr *instruction) |
| 22390 | 23402 | { |
| 22391 | 23403 | Error err; |
| 22392 | | IrInstruction *type_value = instruction->type_value->child; |
| 23404 | IrInstGen *type_value = instruction->type_value->child; |
| 22393 | 23405 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| 22394 | 23406 | if (type_is_invalid(container_type)) |
| 22395 | | return ira->codegen->invalid_instruction; |
| 23407 | return ira->codegen->invalid_inst_gen; |
| 22396 | 23408 | |
| 22397 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23409 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22398 | 23410 | Buf *field_name = ir_resolve_str(ira, field_name_value); |
| 22399 | 23411 | if (!field_name) |
| 22400 | | return ira->codegen->invalid_instruction; |
| 23412 | return ira->codegen->invalid_inst_gen; |
| 22401 | 23413 | |
| 22402 | | IrInstruction *field_ptr = instruction->field_ptr->child; |
| 23414 | IrInstGen *field_ptr = instruction->field_ptr->child; |
| 22403 | 23415 | if (type_is_invalid(field_ptr->value->type)) |
| 22404 | | return ira->codegen->invalid_instruction; |
| 23416 | return ira->codegen->invalid_inst_gen; |
| 22405 | 23417 | |
| 22406 | 23418 | if (container_type->id != ZigTypeIdStruct) { |
| 22407 | | ir_add_error(ira, type_value, |
| 23419 | ir_add_error(ira, &type_value->base, |
| 22408 | 23420 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 22409 | | return ira->codegen->invalid_instruction; |
| 23421 | return ira->codegen->invalid_inst_gen; |
| 22410 | 23422 | } |
| 22411 | 23423 | |
| 22412 | 23424 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 22413 | | return ira->codegen->invalid_instruction; |
| 23425 | return ira->codegen->invalid_inst_gen; |
| 22414 | 23426 | |
| 22415 | 23427 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 22416 | 23428 | if (field == nullptr) { |
| 22417 | | ir_add_error(ira, field_name_value, |
| 23429 | ir_add_error(ira, &field_name_value->base, |
| 22418 | 23430 | buf_sprintf("struct '%s' has no field '%s'", |
| 22419 | 23431 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 22420 | | return ira->codegen->invalid_instruction; |
| 23432 | return ira->codegen->invalid_inst_gen; |
| 22421 | 23433 | } |
| 22422 | 23434 | |
| 22423 | 23435 | if (field_ptr->value->type->id != ZigTypeIdPointer) { |
| 22424 | | ir_add_error(ira, field_ptr, |
| 23436 | ir_add_error(ira, &field_ptr->base, |
| 22425 | 23437 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); |
| 22426 | | return ira->codegen->invalid_instruction; |
| 23438 | return ira->codegen->invalid_inst_gen; |
| 22427 | 23439 | } |
| 22428 | 23440 | |
| 22429 | 23441 | bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked); |
| ... | ... | @@ -22435,9 +23447,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22435 | 23447 | field_ptr->value->type->data.pointer.is_volatile, |
| 22436 | 23448 | PtrLenSingle, |
| 22437 | 23449 | field_ptr_align, 0, 0, false); |
| 22438 | | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 23450 | IrInstGen *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 22439 | 23451 | if (type_is_invalid(casted_field_ptr->value->type)) |
| 22440 | | return ira->codegen->invalid_instruction; |
| 23452 | return ira->codegen->invalid_inst_gen; |
| 22441 | 23453 | |
| 22442 | 23454 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 22443 | 23455 | casted_field_ptr->value->type->data.pointer.is_const, |
| ... | ... | @@ -22448,23 +23460,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22448 | 23460 | if (instr_is_comptime(casted_field_ptr)) { |
| 22449 | 23461 | ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| 22450 | 23462 | if (!field_ptr_val) |
| 22451 | | return ira->codegen->invalid_instruction; |
| 23463 | return ira->codegen->invalid_inst_gen; |
| 22452 | 23464 | |
| 22453 | 23465 | if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) { |
| 22454 | | ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct")); |
| 22455 | | return ira->codegen->invalid_instruction; |
| 23466 | ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct")); |
| 23467 | return ira->codegen->invalid_inst_gen; |
| 22456 | 23468 | } |
| 22457 | 23469 | |
| 22458 | 23470 | size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; |
| 22459 | 23471 | if (ptr_field_index != field->src_index) { |
| 22460 | | ir_add_error(ira, &instruction->base, |
| 23472 | ir_add_error(ira, &instruction->base.base, |
| 22461 | 23473 | buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", |
| 22462 | 23474 | buf_ptr(field->name), field->src_index, |
| 22463 | 23475 | ptr_field_index, buf_ptr(&container_type->name))); |
| 22464 | | return ira->codegen->invalid_instruction; |
| 23476 | return ira->codegen->invalid_inst_gen; |
| 22465 | 23477 | } |
| 22466 | 23478 | |
| 22467 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 23479 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 22468 | 23480 | ZigValue *out_val = result->value; |
| 22469 | 23481 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 22470 | 23482 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| ... | ... | @@ -22472,15 +23484,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22472 | 23484 | return result; |
| 22473 | 23485 | } |
| 22474 | 23486 | |
| 22475 | | IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, |
| 22476 | | instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); |
| 22477 | | result->value->type = result_type; |
| 22478 | | return result; |
| 23487 | return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type); |
| 22479 | 23488 | } |
| 22480 | 23489 | |
| 22481 | 23490 | static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22482 | | IrInstruction *type_value, |
| 22483 | | IrInstruction *field_name_value, |
| 23491 | IrInstGen *type_value, |
| 23492 | IrInstGen *field_name_value, |
| 22484 | 23493 | size_t *byte_offset) |
| 22485 | 23494 | { |
| 22486 | 23495 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -22496,21 +23505,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22496 | 23505 | return nullptr; |
| 22497 | 23506 | |
| 22498 | 23507 | if (container_type->id != ZigTypeIdStruct) { |
| 22499 | | ir_add_error(ira, type_value, |
| 23508 | ir_add_error(ira, &type_value->base, |
| 22500 | 23509 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 22501 | 23510 | return nullptr; |
| 22502 | 23511 | } |
| 22503 | 23512 | |
| 22504 | 23513 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 22505 | 23514 | if (field == nullptr) { |
| 22506 | | ir_add_error(ira, field_name_value, |
| 23515 | ir_add_error(ira, &field_name_value->base, |
| 22507 | 23516 | buf_sprintf("struct '%s' has no field '%s'", |
| 22508 | 23517 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 22509 | 23518 | return nullptr; |
| 22510 | 23519 | } |
| 22511 | 23520 | |
| 22512 | 23521 | if (!type_has_bits(field->type_entry)) { |
| 22513 | | ir_add_error(ira, field_name_value, |
| 23522 | ir_add_error(ira, &field_name_value->base, |
| 22514 | 23523 | buf_sprintf("zero-bit field '%s' in struct '%s' has no offset", |
| 22515 | 23524 | buf_ptr(field_name), buf_ptr(&container_type->name))); |
| 22516 | 23525 | return nullptr; |
| ... | ... | @@ -22520,36 +23529,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22520 | 23529 | return field; |
| 22521 | 23530 | } |
| 22522 | 23531 | |
| 22523 | | static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 22524 | | IrInstructionByteOffsetOf *instruction) |
| 22525 | | { |
| 22526 | | IrInstruction *type_value = instruction->type_value->child; |
| 23532 | static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) { |
| 23533 | IrInstGen *type_value = instruction->type_value->child; |
| 22527 | 23534 | if (type_is_invalid(type_value->value->type)) |
| 22528 | | return ira->codegen->invalid_instruction; |
| 23535 | return ira->codegen->invalid_inst_gen; |
| 22529 | 23536 | |
| 22530 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23537 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22531 | 23538 | size_t byte_offset = 0; |
| 22532 | 23539 | if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset)) |
| 22533 | | return ira->codegen->invalid_instruction; |
| 23540 | return ira->codegen->invalid_inst_gen; |
| 22534 | 23541 | |
| 22535 | 23542 | |
| 22536 | | return ir_const_unsigned(ira, &instruction->base, byte_offset); |
| 23543 | return ir_const_unsigned(ira, &instruction->base.base, byte_offset); |
| 22537 | 23544 | } |
| 22538 | 23545 | |
| 22539 | | static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 22540 | | IrInstructionBitOffsetOf *instruction) |
| 22541 | | { |
| 22542 | | IrInstruction *type_value = instruction->type_value->child; |
| 23546 | static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) { |
| 23547 | IrInstGen *type_value = instruction->type_value->child; |
| 22543 | 23548 | if (type_is_invalid(type_value->value->type)) |
| 22544 | | return ira->codegen->invalid_instruction; |
| 22545 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23549 | return ira->codegen->invalid_inst_gen; |
| 23550 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22546 | 23551 | size_t byte_offset = 0; |
| 22547 | 23552 | TypeStructField *field = nullptr; |
| 22548 | 23553 | if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset))) |
| 22549 | | return ira->codegen->invalid_instruction; |
| 23554 | return ira->codegen->invalid_inst_gen; |
| 22550 | 23555 | |
| 22551 | 23556 | size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host; |
| 22552 | | return ir_const_unsigned(ira, &instruction->base, bit_offset); |
| 23557 | return ir_const_unsigned(ira, &instruction->base.base, bit_offset); |
| 22553 | 23558 | } |
| 22554 | 23559 | |
| 22555 | 23560 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { |
| ... | ... | @@ -22597,7 +23602,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig |
| 22597 | 23602 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); |
| 22598 | 23603 | } |
| 22599 | 23604 | |
| 22600 | | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val, |
| 23605 | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val, |
| 22601 | 23606 | ScopeDecls *decls_scope) |
| 22602 | 23607 | { |
| 22603 | 23608 | Error err; |
| ... | ... | @@ -22628,11 +23633,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 22628 | 23633 | |
| 22629 | 23634 | while ((curr_entry = decl_it.next()) != nullptr) { |
| 22630 | 23635 | // If the declaration is unresolved, force it to be resolved again. |
| 22631 | | if (curr_entry->value->resolution == TldResolutionUnresolved) { |
| 22632 | | resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false); |
| 22633 | | if (curr_entry->value->resolution != TldResolutionOk) { |
| 22634 | | return ErrorSemanticAnalyzeFail; |
| 22635 | | } |
| 23636 | resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false); |
| 23637 | if (curr_entry->value->resolution == TldResolutionInvalid) { |
| 23638 | return ErrorSemanticAnalyzeFail; |
| 23639 | } |
| 23640 | |
| 23641 | if (curr_entry->value->resolution == TldResolutionResolving) { |
| 23642 | ir_error_dependency_loop(ira, source_instr); |
| 23643 | return ErrorSemanticAnalyzeFail; |
| 22636 | 23644 | } |
| 22637 | 23645 | |
| 22638 | 23646 | // Skip comptime blocks and test functions. |
| ... | ... | @@ -22689,6 +23697,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 22689 | 23697 | case TldIdVar: |
| 22690 | 23698 | { |
| 22691 | 23699 | ZigVar *var = ((TldVar *)curr_entry->value)->var; |
| 23700 | assert(var != nullptr); |
| 23701 | |
| 22692 | 23702 | if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown))) |
| 22693 | 23703 | return ErrorSemanticAnalyzeFail; |
| 22694 | 23704 | |
| ... | ... | @@ -22719,11 +23729,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 22719 | 23729 | |
| 22720 | 23730 | ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; |
| 22721 | 23731 | assert(!fn_entry->is_test); |
| 22722 | | |
| 22723 | | if (fn_entry->type_entry == nullptr) { |
| 22724 | | ir_error_dependency_loop(ira, source_instr); |
| 22725 | | return ErrorSemanticAnalyzeFail; |
| 22726 | | } |
| 23732 | assert(fn_entry->type_entry != nullptr); |
| 22727 | 23733 | |
| 22728 | 23734 | AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto; |
| 22729 | 23735 | |
| ... | ... | @@ -22955,7 +23961,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn |
| 22955 | 23961 | enum_field_val->data.x_struct.fields = inner_fields; |
| 22956 | 23962 | } |
| 22957 | 23963 | |
| 22958 | | static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 23964 | static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 22959 | 23965 | ZigValue **out) |
| 22960 | 23966 | { |
| 22961 | 23967 | Error err; |
| ... | ... | @@ -23543,22 +24549,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 23543 | 24549 | return ErrorNone; |
| 23544 | 24550 | } |
| 23545 | 24551 | |
| 23546 | | static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 23547 | | IrInstructionTypeInfo *instruction) |
| 23548 | | { |
| 24552 | static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) { |
| 23549 | 24553 | Error err; |
| 23550 | | IrInstruction *type_value = instruction->type_value->child; |
| 24554 | IrInstGen *type_value = instruction->type_value->child; |
| 23551 | 24555 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23552 | 24556 | if (type_is_invalid(type_entry)) |
| 23553 | | return ira->codegen->invalid_instruction; |
| 24557 | return ira->codegen->invalid_inst_gen; |
| 23554 | 24558 | |
| 23555 | 24559 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 23556 | 24560 | |
| 23557 | 24561 | ZigValue *payload; |
| 23558 | | if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload))) |
| 23559 | | return ira->codegen->invalid_instruction; |
| 24562 | if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload))) |
| 24563 | return ira->codegen->invalid_inst_gen; |
| 23560 | 24564 | |
| 23561 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 24565 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 23562 | 24566 | ZigValue *out_val = result->value; |
| 23563 | 24567 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 23564 | 24568 | out_val->data.x_union.payload = payload; |
| ... | ... | @@ -23582,15 +24586,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue |
| 23582 | 24586 | return val; |
| 23583 | 24587 | } |
| 23584 | 24588 | |
| 23585 | | static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value, |
| 24589 | static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value, |
| 23586 | 24590 | const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) |
| 23587 | 24591 | { |
| 23588 | 24592 | ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index); |
| 23589 | 24593 | if (field_val == nullptr) |
| 23590 | 24594 | return ErrorSemanticAnalyzeFail; |
| 23591 | 24595 | |
| 23592 | | IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val); |
| 23593 | | IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 24596 | IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val); |
| 24597 | IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 23594 | 24598 | get_optional_type(ira->codegen, elem_type)); |
| 23595 | 24599 | if (type_is_invalid(casted_field_inst->value->type)) |
| 23596 | 24600 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -23629,12 +24633,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, |
| 23629 | 24633 | { |
| 23630 | 24634 | ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); |
| 23631 | 24635 | if (value == nullptr) |
| 23632 | | return ira->codegen->invalid_instruction->value->type; |
| 24636 | return ira->codegen->invalid_inst_gen->value->type; |
| 23633 | 24637 | assert(value->type == ira->codegen->builtin_types.entry_type); |
| 23634 | 24638 | return value->data.x_type; |
| 23635 | 24639 | } |
| 23636 | 24640 | |
| 23637 | | static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) { |
| 24641 | static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) { |
| 23638 | 24642 | Error err; |
| 23639 | 24643 | switch (tagTypeId) { |
| 23640 | 24644 | case ZigTypeIdInvalid: |
| ... | ... | @@ -23650,21 +24654,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23650 | 24654 | case ZigTypeIdInt: { |
| 23651 | 24655 | assert(payload->special == ConstValSpecialStatic); |
| 23652 | 24656 | assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr)); |
| 23653 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1); |
| 24657 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1); |
| 23654 | 24658 | if (bi == nullptr) |
| 23655 | | return ira->codegen->invalid_instruction->value->type; |
| 24659 | return ira->codegen->invalid_inst_gen->value->type; |
| 23656 | 24660 | bool is_signed; |
| 23657 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed))) |
| 23658 | | return ira->codegen->invalid_instruction->value->type; |
| 24661 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed))) |
| 24662 | return ira->codegen->invalid_inst_gen->value->type; |
| 23659 | 24663 | return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi)); |
| 23660 | 24664 | } |
| 23661 | 24665 | case ZigTypeIdFloat: |
| 23662 | 24666 | { |
| 23663 | 24667 | assert(payload->special == ConstValSpecialStatic); |
| 23664 | 24668 | assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr)); |
| 23665 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0); |
| 24669 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0); |
| 23666 | 24670 | if (bi == nullptr) |
| 23667 | | return ira->codegen->invalid_instruction->value->type; |
| 24671 | return ira->codegen->invalid_inst_gen->value->type; |
| 23668 | 24672 | uint32_t bits = bigint_as_u32(bi); |
| 23669 | 24673 | switch (bits) { |
| 23670 | 24674 | case 16: return ira->codegen->builtin_types.entry_f16; |
| ... | ... | @@ -23672,48 +24676,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23672 | 24676 | case 64: return ira->codegen->builtin_types.entry_f64; |
| 23673 | 24677 | case 128: return ira->codegen->builtin_types.entry_f128; |
| 23674 | 24678 | } |
| 23675 | | ir_add_error(ira, instruction, |
| 23676 | | buf_sprintf("%d-bit float unsupported", bits)); |
| 23677 | | return ira->codegen->invalid_instruction->value->type; |
| 24679 | ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits)); |
| 24680 | return ira->codegen->invalid_inst_gen->value->type; |
| 23678 | 24681 | } |
| 23679 | 24682 | case ZigTypeIdPointer: |
| 23680 | 24683 | { |
| 23681 | 24684 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 23682 | 24685 | assert(payload->special == ConstValSpecialStatic); |
| 23683 | 24686 | assert(payload->type == type_info_pointer_type); |
| 23684 | | ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0); |
| 24687 | ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0); |
| 23685 | 24688 | assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); |
| 23686 | 24689 | BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); |
| 23687 | 24690 | PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); |
| 23688 | | ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4); |
| 24691 | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4); |
| 23689 | 24692 | if (type_is_invalid(elem_type)) |
| 23690 | | return ira->codegen->invalid_instruction->value->type; |
| 24693 | return ira->codegen->invalid_inst_gen->value->type; |
| 23691 | 24694 | ZigValue *sentinel; |
| 23692 | | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, |
| 24695 | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6, |
| 23693 | 24696 | elem_type, &sentinel))) |
| 23694 | 24697 | { |
| 23695 | | return ira->codegen->invalid_instruction->value->type; |
| 24698 | return ira->codegen->invalid_inst_gen->value->type; |
| 23696 | 24699 | } |
| 23697 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3); |
| 24700 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3); |
| 23698 | 24701 | if (bi == nullptr) |
| 23699 | | return ira->codegen->invalid_instruction->value->type; |
| 24702 | return ira->codegen->invalid_inst_gen->value->type; |
| 23700 | 24703 | |
| 23701 | 24704 | bool is_const; |
| 23702 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const))) |
| 23703 | | return ira->codegen->invalid_instruction->value->type; |
| 24705 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const))) |
| 24706 | return ira->codegen->invalid_inst_gen->value->type; |
| 23704 | 24707 | |
| 23705 | 24708 | bool is_volatile; |
| 23706 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2, |
| 24709 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2, |
| 23707 | 24710 | &is_volatile))) |
| 23708 | 24711 | { |
| 23709 | | return ira->codegen->invalid_instruction->value->type; |
| 24712 | return ira->codegen->invalid_inst_gen->value->type; |
| 23710 | 24713 | } |
| 23711 | 24714 | |
| 23712 | 24715 | bool is_allowzero; |
| 23713 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5, |
| 24716 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5, |
| 23714 | 24717 | &is_allowzero))) |
| 23715 | 24718 | { |
| 23716 | | return ira->codegen->invalid_instruction->value->type; |
| 24719 | return ira->codegen->invalid_inst_gen->value->type; |
| 23717 | 24720 | } |
| 23718 | 24721 | |
| 23719 | 24722 | |
| ... | ... | @@ -23734,18 +24737,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23734 | 24737 | case ZigTypeIdArray: { |
| 23735 | 24738 | assert(payload->special == ConstValSpecialStatic); |
| 23736 | 24739 | assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); |
| 23737 | | ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1); |
| 24740 | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1); |
| 23738 | 24741 | if (type_is_invalid(elem_type)) |
| 23739 | | return ira->codegen->invalid_instruction->value->type; |
| 24742 | return ira->codegen->invalid_inst_gen->value->type; |
| 23740 | 24743 | ZigValue *sentinel; |
| 23741 | | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, |
| 24744 | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2, |
| 23742 | 24745 | elem_type, &sentinel))) |
| 23743 | 24746 | { |
| 23744 | | return ira->codegen->invalid_instruction->value->type; |
| 24747 | return ira->codegen->invalid_inst_gen->value->type; |
| 23745 | 24748 | } |
| 23746 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0); |
| 24749 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0); |
| 23747 | 24750 | if (bi == nullptr) |
| 23748 | | return ira->codegen->invalid_instruction->value->type; |
| 24751 | return ira->codegen->invalid_inst_gen->value->type; |
| 23749 | 24752 | return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel); |
| 23750 | 24753 | } |
| 23751 | 24754 | case ZigTypeIdComptimeFloat: |
| ... | ... | @@ -23765,78 +24768,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23765 | 24768 | case ZigTypeIdAnyFrame: |
| 23766 | 24769 | case ZigTypeIdVector: |
| 23767 | 24770 | case ZigTypeIdEnumLiteral: |
| 23768 | | ir_add_error(ira, instruction, buf_sprintf( |
| 24771 | ir_add_error(ira, source_instr, buf_sprintf( |
| 23769 | 24772 | "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId))); |
| 23770 | | return ira->codegen->invalid_instruction->value->type; |
| 24773 | return ira->codegen->invalid_inst_gen->value->type; |
| 23771 | 24774 | case ZigTypeIdUnion: |
| 23772 | 24775 | case ZigTypeIdFn: |
| 23773 | 24776 | case ZigTypeIdBoundFn: |
| 23774 | 24777 | case ZigTypeIdStruct: |
| 23775 | | ir_add_error(ira, instruction, buf_sprintf( |
| 24778 | ir_add_error(ira, source_instr, buf_sprintf( |
| 23776 | 24779 | "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId))); |
| 23777 | | return ira->codegen->invalid_instruction->value->type; |
| 24780 | return ira->codegen->invalid_inst_gen->value->type; |
| 23778 | 24781 | } |
| 23779 | 24782 | zig_unreachable(); |
| 23780 | 24783 | } |
| 23781 | 24784 | |
| 23782 | | static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) { |
| 23783 | | IrInstruction *type_info_ir = instruction->type_info->child; |
| 23784 | | if (type_is_invalid(type_info_ir->value->type)) |
| 23785 | | return ira->codegen->invalid_instruction; |
| 24785 | static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) { |
| 24786 | IrInstGen *uncasted_type_info = instruction->type_info->child; |
| 24787 | if (type_is_invalid(uncasted_type_info->value->type)) |
| 24788 | return ira->codegen->invalid_inst_gen; |
| 23786 | 24789 | |
| 23787 | | IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 23788 | | if (type_is_invalid(casted_ir->value->type)) |
| 23789 | | return ira->codegen->invalid_instruction; |
| 24790 | IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 24791 | if (type_is_invalid(type_info->value->type)) |
| 24792 | return ira->codegen->invalid_inst_gen; |
| 23790 | 24793 | |
| 23791 | | ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); |
| 23792 | | if (!type_info_value) |
| 23793 | | return ira->codegen->invalid_instruction; |
| 23794 | | ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag)); |
| 23795 | | ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload); |
| 24794 | ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad); |
| 24795 | if (type_info_val == nullptr) |
| 24796 | return ira->codegen->invalid_inst_gen; |
| 24797 | ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag)); |
| 24798 | ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag, |
| 24799 | type_info_val->data.x_union.payload); |
| 23796 | 24800 | if (type_is_invalid(type)) |
| 23797 | | return ira->codegen->invalid_instruction; |
| 23798 | | return ir_const_type(ira, &instruction->base, type); |
| 24801 | return ira->codegen->invalid_inst_gen; |
| 24802 | return ir_const_type(ira, &instruction->base.base, type); |
| 23799 | 24803 | } |
| 23800 | 24804 | |
| 23801 | | static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 23802 | | IrInstructionTypeId *instruction) |
| 23803 | | { |
| 23804 | | IrInstruction *type_value = instruction->type_value->child; |
| 24805 | static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) { |
| 24806 | IrInstGen *type_value = instruction->type_value->child; |
| 23805 | 24807 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23806 | 24808 | if (type_is_invalid(type_entry)) |
| 23807 | | return ira->codegen->invalid_instruction; |
| 24809 | return ira->codegen->invalid_inst_gen; |
| 23808 | 24810 | |
| 23809 | 24811 | ZigType *result_type = get_builtin_type(ira->codegen, "TypeId"); |
| 23810 | 24812 | |
| 23811 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 24813 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 23812 | 24814 | bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry)); |
| 23813 | 24815 | return result; |
| 23814 | 24816 | } |
| 23815 | 24817 | |
| 23816 | | static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 23817 | | IrInstructionSetEvalBranchQuota *instruction) |
| 24818 | static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 24819 | IrInstSrcSetEvalBranchQuota *instruction) |
| 23818 | 24820 | { |
| 23819 | 24821 | uint64_t new_quota; |
| 23820 | 24822 | if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota)) |
| 23821 | | return ira->codegen->invalid_instruction; |
| 24823 | return ira->codegen->invalid_inst_gen; |
| 23822 | 24824 | |
| 23823 | 24825 | if (new_quota > *ira->new_irb.exec->backward_branch_quota) { |
| 23824 | 24826 | *ira->new_irb.exec->backward_branch_quota = new_quota; |
| 23825 | 24827 | } |
| 23826 | 24828 | |
| 23827 | | return ir_const_void(ira, &instruction->base); |
| 24829 | return ir_const_void(ira, &instruction->base.base); |
| 23828 | 24830 | } |
| 23829 | 24831 | |
| 23830 | | static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 23831 | | IrInstruction *type_value = instruction->type_value->child; |
| 24832 | static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) { |
| 24833 | IrInstGen *type_value = instruction->type_value->child; |
| 23832 | 24834 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23833 | 24835 | if (type_is_invalid(type_entry)) |
| 23834 | | return ira->codegen->invalid_instruction; |
| 24836 | return ira->codegen->invalid_inst_gen; |
| 23835 | 24837 | |
| 23836 | 24838 | if (!type_entry->cached_const_name_val) { |
| 23837 | 24839 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 23838 | 24840 | } |
| 23839 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24841 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 23840 | 24842 | copy_const_val(result->value, type_entry->cached_const_name_val); |
| 23841 | 24843 | return result; |
| 23842 | 24844 | } |
| ... | ... | @@ -23848,23 +24850,30 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf * |
| 23848 | 24850 | buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest)); |
| 23849 | 24851 | buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir)); |
| 23850 | 24852 | } |
| 23851 | | static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { |
| 24853 | static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) { |
| 23852 | 24854 | Error err; |
| 23853 | | AstNode *node = instruction->base.source_node; |
| 24855 | AstNode *node = instruction->base.base.source_node; |
| 23854 | 24856 | assert(node->type == NodeTypeFnCallExpr); |
| 23855 | 24857 | AstNode *block_node = node->data.fn_call_expr.params.at(0); |
| 23856 | 24858 | |
| 23857 | | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope); |
| 24859 | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope); |
| 23858 | 24860 | |
| 23859 | 24861 | // Execute the C import block like an inline function |
| 23860 | 24862 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 23861 | | ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 24863 | ZigValue *cimport_result; |
| 24864 | ZigValue *result_ptr; |
| 24865 | create_result_ptr(ira->codegen, void_type, &cimport_result, &result_ptr); |
| 24866 | if ((err = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, result_ptr, |
| 23862 | 24867 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 23863 | | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); |
| 24868 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad))) |
| 24869 | { |
| 24870 | return ira->codegen->invalid_inst_gen; |
| 24871 | } |
| 23864 | 24872 | if (type_is_invalid(cimport_result->type)) |
| 23865 | | return ira->codegen->invalid_instruction; |
| 24873 | return ira->codegen->invalid_inst_gen; |
| 24874 | destroy(result_ptr, "ZigValue"); |
| 23866 | 24875 | |
| 23867 | | ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope); |
| 24876 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope); |
| 23868 | 24877 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, |
| 23869 | 24878 | buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1); |
| 23870 | 24879 | |
| ... | ... | @@ -23876,7 +24885,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23876 | 24885 | CacheHash *cache_hash; |
| 23877 | 24886 | if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) { |
| 23878 | 24887 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err))); |
| 23879 | | return ira->codegen->invalid_instruction; |
| 24888 | return ira->codegen->invalid_inst_gen; |
| 23880 | 24889 | } |
| 23881 | 24890 | cache_buf(cache_hash, &cimport_scope->buf); |
| 23882 | 24891 | |
| ... | ... | @@ -23888,7 +24897,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23888 | 24897 | if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) { |
| 23889 | 24898 | if (err != ErrorInvalidFormat) { |
| 23890 | 24899 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err))); |
| 23891 | | return ira->codegen->invalid_instruction; |
| 24900 | return ira->codegen->invalid_inst_gen; |
| 23892 | 24901 | } |
| 23893 | 24902 | } |
| 23894 | 24903 | ira->codegen->caches_to_release.append(cache_hash); |
| ... | ... | @@ -23907,12 +24916,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23907 | 24916 | |
| 23908 | 24917 | if ((err = os_make_path(tmp_c_file_dir))) { |
| 23909 | 24918 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err))); |
| 23910 | | return ira->codegen->invalid_instruction; |
| 24919 | return ira->codegen->invalid_inst_gen; |
| 23911 | 24920 | } |
| 23912 | 24921 | |
| 23913 | 24922 | if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) { |
| 23914 | 24923 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err))); |
| 23915 | | return ira->codegen->invalid_instruction; |
| 24924 | return ira->codegen->invalid_inst_gen; |
| 23916 | 24925 | } |
| 23917 | 24926 | if (ira->codegen->verbose_cimport) { |
| 23918 | 24927 | fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path)); |
| ... | ... | @@ -23947,7 +24956,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23947 | 24956 | { |
| 23948 | 24957 | if (err != ErrorCCompileErrors) { |
| 23949 | 24958 | ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err))); |
| 23950 | | return ira->codegen->invalid_instruction; |
| 24959 | return ira->codegen->invalid_inst_gen; |
| 23951 | 24960 | } |
| 23952 | 24961 | |
| 23953 | 24962 | ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed")); |
| ... | ... | @@ -23968,7 +24977,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23968 | 24977 | } |
| 23969 | 24978 | } |
| 23970 | 24979 | |
| 23971 | | return ira->codegen->invalid_instruction; |
| 24980 | return ira->codegen->invalid_inst_gen; |
| 23972 | 24981 | } |
| 23973 | 24982 | if (ira->codegen->verbose_cimport) { |
| 23974 | 24983 | fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file)); |
| ... | ... | @@ -23976,29 +24985,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23976 | 24985 | |
| 23977 | 24986 | if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) { |
| 23978 | 24987 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err))); |
| 23979 | | return ira->codegen->invalid_instruction; |
| 24988 | return ira->codegen->invalid_inst_gen; |
| 23980 | 24989 | } |
| 23981 | 24990 | if ((err = cache_final(cache_hash, &tmp_c_file_digest))) { |
| 23982 | 24991 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err))); |
| 23983 | | return ira->codegen->invalid_instruction; |
| 24992 | return ira->codegen->invalid_inst_gen; |
| 23984 | 24993 | } |
| 23985 | 24994 | |
| 23986 | 24995 | ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path); |
| 23987 | 24996 | if ((err = os_make_path(out_zig_dir))) { |
| 23988 | 24997 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err))); |
| 23989 | | return ira->codegen->invalid_instruction; |
| 24998 | return ira->codegen->invalid_inst_gen; |
| 23990 | 24999 | } |
| 23991 | 25000 | FILE *out_file = fopen(buf_ptr(out_zig_path), "wb"); |
| 23992 | 25001 | if (out_file == nullptr) { |
| 23993 | 25002 | ir_add_error_node(ira, node, |
| 23994 | 25003 | buf_sprintf("C import failed: unable to open output file: %s", strerror(errno))); |
| 23995 | | return ira->codegen->invalid_instruction; |
| 25004 | return ira->codegen->invalid_inst_gen; |
| 23996 | 25005 | } |
| 23997 | 25006 | stage2_render_ast(ast, out_file); |
| 23998 | 25007 | if (fclose(out_file) != 0) { |
| 23999 | 25008 | ir_add_error_node(ira, node, |
| 24000 | 25009 | buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno))); |
| 24001 | | return ira->codegen->invalid_instruction; |
| 25010 | return ira->codegen->invalid_inst_gen; |
| 24002 | 25011 | } |
| 24003 | 25012 | |
| 24004 | 25013 | if (ira->codegen->verbose_cimport) { |
| ... | ... | @@ -24017,90 +25026,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 24017 | 25026 | if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) { |
| 24018 | 25027 | ir_add_error_node(ira, node, |
| 24019 | 25028 | buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err))); |
| 24020 | | return ira->codegen->invalid_instruction; |
| 25029 | return ira->codegen->invalid_inst_gen; |
| 24021 | 25030 | } |
| 24022 | 25031 | ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path, |
| 24023 | 25032 | import_code, SourceKindCImport); |
| 24024 | | return ir_const_type(ira, &instruction->base, child_import); |
| 25033 | return ir_const_type(ira, &instruction->base.base, child_import); |
| 24025 | 25034 | } |
| 24026 | 25035 | |
| 24027 | | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 24028 | | IrInstruction *name_value = instruction->name->child; |
| 25036 | static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) { |
| 25037 | IrInstGen *name_value = instruction->name->child; |
| 24029 | 25038 | if (type_is_invalid(name_value->value->type)) |
| 24030 | | return ira->codegen->invalid_instruction; |
| 25039 | return ira->codegen->invalid_inst_gen; |
| 24031 | 25040 | |
| 24032 | 25041 | Buf *include_name = ir_resolve_str(ira, name_value); |
| 24033 | 25042 | if (!include_name) |
| 24034 | | return ira->codegen->invalid_instruction; |
| 25043 | return ira->codegen->invalid_inst_gen; |
| 24035 | 25044 | |
| 24036 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 25045 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24037 | 25046 | // We check for this error in pass1 |
| 24038 | 25047 | assert(c_import_buf); |
| 24039 | 25048 | |
| 24040 | 25049 | buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name)); |
| 24041 | 25050 | |
| 24042 | | return ir_const_void(ira, &instruction->base); |
| 25051 | return ir_const_void(ira, &instruction->base.base); |
| 24043 | 25052 | } |
| 24044 | 25053 | |
| 24045 | | static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 24046 | | IrInstruction *name = instruction->name->child; |
| 25054 | static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) { |
| 25055 | IrInstGen *name = instruction->name->child; |
| 24047 | 25056 | if (type_is_invalid(name->value->type)) |
| 24048 | | return ira->codegen->invalid_instruction; |
| 25057 | return ira->codegen->invalid_inst_gen; |
| 24049 | 25058 | |
| 24050 | 25059 | Buf *define_name = ir_resolve_str(ira, name); |
| 24051 | 25060 | if (!define_name) |
| 24052 | | return ira->codegen->invalid_instruction; |
| 25061 | return ira->codegen->invalid_inst_gen; |
| 24053 | 25062 | |
| 24054 | | IrInstruction *value = instruction->value->child; |
| 25063 | IrInstGen *value = instruction->value->child; |
| 24055 | 25064 | if (type_is_invalid(value->value->type)) |
| 24056 | | return ira->codegen->invalid_instruction; |
| 25065 | return ira->codegen->invalid_inst_gen; |
| 24057 | 25066 | |
| 24058 | 25067 | Buf *define_value = nullptr; |
| 24059 | 25068 | // The second parameter is either a string or void (equivalent to "") |
| 24060 | 25069 | if (value->value->type->id != ZigTypeIdVoid) { |
| 24061 | 25070 | define_value = ir_resolve_str(ira, value); |
| 24062 | 25071 | if (!define_value) |
| 24063 | | return ira->codegen->invalid_instruction; |
| 25072 | return ira->codegen->invalid_inst_gen; |
| 24064 | 25073 | } |
| 24065 | 25074 | |
| 24066 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 25075 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24067 | 25076 | // We check for this error in pass1 |
| 24068 | 25077 | assert(c_import_buf); |
| 24069 | 25078 | |
| 24070 | 25079 | buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), |
| 24071 | 25080 | define_value ? buf_ptr(define_value) : ""); |
| 24072 | 25081 | |
| 24073 | | return ir_const_void(ira, &instruction->base); |
| 25082 | return ir_const_void(ira, &instruction->base.base); |
| 24074 | 25083 | } |
| 24075 | 25084 | |
| 24076 | | static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 24077 | | IrInstruction *name = instruction->name->child; |
| 25085 | static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) { |
| 25086 | IrInstGen *name = instruction->name->child; |
| 24078 | 25087 | if (type_is_invalid(name->value->type)) |
| 24079 | | return ira->codegen->invalid_instruction; |
| 25088 | return ira->codegen->invalid_inst_gen; |
| 24080 | 25089 | |
| 24081 | 25090 | Buf *undef_name = ir_resolve_str(ira, name); |
| 24082 | 25091 | if (!undef_name) |
| 24083 | | return ira->codegen->invalid_instruction; |
| 25092 | return ira->codegen->invalid_inst_gen; |
| 24084 | 25093 | |
| 24085 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 25094 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24086 | 25095 | // We check for this error in pass1 |
| 24087 | 25096 | assert(c_import_buf); |
| 24088 | 25097 | |
| 24089 | 25098 | buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name)); |
| 24090 | 25099 | |
| 24091 | | return ir_const_void(ira, &instruction->base); |
| 25100 | return ir_const_void(ira, &instruction->base.base); |
| 24092 | 25101 | } |
| 24093 | 25102 | |
| 24094 | | static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 24095 | | IrInstruction *name = instruction->name->child; |
| 25103 | static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) { |
| 25104 | IrInstGen *name = instruction->name->child; |
| 24096 | 25105 | if (type_is_invalid(name->value->type)) |
| 24097 | | return ira->codegen->invalid_instruction; |
| 25106 | return ira->codegen->invalid_inst_gen; |
| 24098 | 25107 | |
| 24099 | 25108 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| 24100 | 25109 | if (!rel_file_path) |
| 24101 | | return ira->codegen->invalid_instruction; |
| 25110 | return ira->codegen->invalid_inst_gen; |
| 24102 | 25111 | |
| 24103 | | ZigType *import = get_scope_import(instruction->base.scope); |
| 25112 | ZigType *import = get_scope_import(instruction->base.base.scope); |
| 24104 | 25113 | // figure out absolute path to resource |
| 24105 | 25114 | Buf source_dir_path = BUF_INIT; |
| 24106 | 25115 | os_path_dirname(import->data.structure.root_struct->path, &source_dir_path); |
| ... | ... | @@ -24117,93 +25126,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 24117 | 25126 | Error err; |
| 24118 | 25127 | if ((err = file_fetch(ira->codegen, file_path, file_contents))) { |
| 24119 | 25128 | if (err == ErrorFileNotFound) { |
| 24120 | | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 24121 | | return ira->codegen->invalid_instruction; |
| 25129 | ir_add_error(ira, &instruction->name->base, |
| 25130 | buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 25131 | return ira->codegen->invalid_inst_gen; |
| 24122 | 25132 | } else { |
| 24123 | | ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 24124 | | return ira->codegen->invalid_instruction; |
| 25133 | ir_add_error(ira, &instruction->name->base, |
| 25134 | buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 25135 | return ira->codegen->invalid_inst_gen; |
| 24125 | 25136 | } |
| 24126 | 25137 | } |
| 24127 | 25138 | |
| 24128 | 25139 | ZigType *result_type = get_array_type(ira->codegen, |
| 24129 | 25140 | ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr); |
| 24130 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 25141 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 24131 | 25142 | init_const_str_lit(ira->codegen, result->value, file_contents); |
| 24132 | 25143 | return result; |
| 24133 | 25144 | } |
| 24134 | 25145 | |
| 24135 | | static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) { |
| 25146 | static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) { |
| 24136 | 25147 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child); |
| 24137 | 25148 | if (type_is_invalid(operand_type)) |
| 24138 | | return ira->codegen->invalid_instruction; |
| 25149 | return ira->codegen->invalid_inst_gen; |
| 24139 | 25150 | |
| 24140 | 25151 | if (operand_type->id == ZigTypeIdFloat) { |
| 24141 | | ir_add_error(ira, instruction->type_value->child, |
| 25152 | ir_add_error(ira, &instruction->type_value->child->base, |
| 24142 | 25153 | buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name))); |
| 24143 | | return ira->codegen->invalid_instruction; |
| 25154 | return ira->codegen->invalid_inst_gen; |
| 24144 | 25155 | } |
| 24145 | 25156 | |
| 24146 | | IrInstruction *ptr = instruction->ptr->child; |
| 25157 | IrInstGen *ptr = instruction->ptr->child; |
| 24147 | 25158 | if (type_is_invalid(ptr->value->type)) |
| 24148 | | return ira->codegen->invalid_instruction; |
| 25159 | return ira->codegen->invalid_inst_gen; |
| 24149 | 25160 | |
| 24150 | 25161 | // TODO let this be volatile |
| 24151 | 25162 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 24152 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 25163 | IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type); |
| 24153 | 25164 | if (type_is_invalid(casted_ptr->value->type)) |
| 24154 | | return ira->codegen->invalid_instruction; |
| 25165 | return ira->codegen->invalid_inst_gen; |
| 24155 | 25166 | |
| 24156 | | IrInstruction *cmp_value = instruction->cmp_value->child; |
| 25167 | IrInstGen *cmp_value = instruction->cmp_value->child; |
| 24157 | 25168 | if (type_is_invalid(cmp_value->value->type)) |
| 24158 | | return ira->codegen->invalid_instruction; |
| 25169 | return ira->codegen->invalid_inst_gen; |
| 24159 | 25170 | |
| 24160 | | IrInstruction *new_value = instruction->new_value->child; |
| 25171 | IrInstGen *new_value = instruction->new_value->child; |
| 24161 | 25172 | if (type_is_invalid(new_value->value->type)) |
| 24162 | | return ira->codegen->invalid_instruction; |
| 25173 | return ira->codegen->invalid_inst_gen; |
| 24163 | 25174 | |
| 24164 | | IrInstruction *success_order_value = instruction->success_order_value->child; |
| 25175 | IrInstGen *success_order_value = instruction->success_order_value->child; |
| 24165 | 25176 | if (type_is_invalid(success_order_value->value->type)) |
| 24166 | | return ira->codegen->invalid_instruction; |
| 25177 | return ira->codegen->invalid_inst_gen; |
| 24167 | 25178 | |
| 24168 | 25179 | AtomicOrder success_order; |
| 24169 | 25180 | if (!ir_resolve_atomic_order(ira, success_order_value, &success_order)) |
| 24170 | | return ira->codegen->invalid_instruction; |
| 25181 | return ira->codegen->invalid_inst_gen; |
| 24171 | 25182 | |
| 24172 | | IrInstruction *failure_order_value = instruction->failure_order_value->child; |
| 25183 | IrInstGen *failure_order_value = instruction->failure_order_value->child; |
| 24173 | 25184 | if (type_is_invalid(failure_order_value->value->type)) |
| 24174 | | return ira->codegen->invalid_instruction; |
| 25185 | return ira->codegen->invalid_inst_gen; |
| 24175 | 25186 | |
| 24176 | 25187 | AtomicOrder failure_order; |
| 24177 | 25188 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 24178 | | return ira->codegen->invalid_instruction; |
| 25189 | return ira->codegen->invalid_inst_gen; |
| 24179 | 25190 | |
| 24180 | | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 25191 | IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type); |
| 24181 | 25192 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 24182 | | return ira->codegen->invalid_instruction; |
| 25193 | return ira->codegen->invalid_inst_gen; |
| 24183 | 25194 | |
| 24184 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 25195 | IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type); |
| 24185 | 25196 | if (type_is_invalid(casted_new_value->value->type)) |
| 24186 | | return ira->codegen->invalid_instruction; |
| 25197 | return ira->codegen->invalid_inst_gen; |
| 24187 | 25198 | |
| 24188 | 25199 | if (success_order < AtomicOrderMonotonic) { |
| 24189 | | ir_add_error(ira, success_order_value, |
| 25200 | ir_add_error(ira, &success_order_value->base, |
| 24190 | 25201 | buf_sprintf("success atomic ordering must be Monotonic or stricter")); |
| 24191 | | return ira->codegen->invalid_instruction; |
| 25202 | return ira->codegen->invalid_inst_gen; |
| 24192 | 25203 | } |
| 24193 | 25204 | if (failure_order < AtomicOrderMonotonic) { |
| 24194 | | ir_add_error(ira, failure_order_value, |
| 25205 | ir_add_error(ira, &failure_order_value->base, |
| 24195 | 25206 | buf_sprintf("failure atomic ordering must be Monotonic or stricter")); |
| 24196 | | return ira->codegen->invalid_instruction; |
| 25207 | return ira->codegen->invalid_inst_gen; |
| 24197 | 25208 | } |
| 24198 | 25209 | if (failure_order > success_order) { |
| 24199 | | ir_add_error(ira, failure_order_value, |
| 25210 | ir_add_error(ira, &failure_order_value->base, |
| 24200 | 25211 | buf_sprintf("failure atomic ordering must be no stricter than success")); |
| 24201 | | return ira->codegen->invalid_instruction; |
| 25212 | return ira->codegen->invalid_inst_gen; |
| 24202 | 25213 | } |
| 24203 | 25214 | if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) { |
| 24204 | | ir_add_error(ira, failure_order_value, |
| 25215 | ir_add_error(ira, &failure_order_value->base, |
| 24205 | 25216 | buf_sprintf("failure atomic ordering must not be Release or AcqRel")); |
| 24206 | | return ira->codegen->invalid_instruction; |
| 25217 | return ira->codegen->invalid_inst_gen; |
| 24207 | 25218 | } |
| 24208 | 25219 | |
| 24209 | 25220 | if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| ... | ... | @@ -24212,152 +25223,146 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 24212 | 25223 | } |
| 24213 | 25224 | |
| 24214 | 25225 | ZigType *result_type = get_optional_type(ira->codegen, operand_type); |
| 24215 | | IrInstruction *result_loc; |
| 25226 | IrInstGen *result_loc; |
| 24216 | 25227 | if (handle_is_ptr(result_type)) { |
| 24217 | | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24218 | | result_type, nullptr, true, false, true); |
| 24219 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 25228 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25229 | result_type, nullptr, true, true); |
| 25230 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 24220 | 25231 | return result_loc; |
| 24221 | 25232 | } |
| 24222 | 25233 | } else { |
| 24223 | 25234 | result_loc = nullptr; |
| 24224 | 25235 | } |
| 24225 | 25236 | |
| 24226 | | return ir_build_cmpxchg_gen(ira, &instruction->base, result_type, |
| 25237 | return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type, |
| 24227 | 25238 | casted_ptr, casted_cmp_value, casted_new_value, |
| 24228 | 25239 | success_order, failure_order, instruction->is_weak, result_loc); |
| 24229 | 25240 | } |
| 24230 | 25241 | |
| 24231 | | static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 24232 | | IrInstruction *order_value = instruction->order_value->child; |
| 24233 | | if (type_is_invalid(order_value->value->type)) |
| 24234 | | return ira->codegen->invalid_instruction; |
| 25242 | static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) { |
| 25243 | IrInstGen *order_inst = instruction->order->child; |
| 25244 | if (type_is_invalid(order_inst->value->type)) |
| 25245 | return ira->codegen->invalid_inst_gen; |
| 24235 | 25246 | |
| 24236 | 25247 | AtomicOrder order; |
| 24237 | | if (!ir_resolve_atomic_order(ira, order_value, &order)) |
| 24238 | | return ira->codegen->invalid_instruction; |
| 25248 | if (!ir_resolve_atomic_order(ira, order_inst, &order)) |
| 25249 | return ira->codegen->invalid_inst_gen; |
| 24239 | 25250 | |
| 24240 | 25251 | if (order < AtomicOrderAcquire) { |
| 24241 | | ir_add_error(ira, order_value, |
| 25252 | ir_add_error(ira, &order_inst->base, |
| 24242 | 25253 | buf_sprintf("atomic ordering must be Acquire or stricter")); |
| 24243 | | return ira->codegen->invalid_instruction; |
| 25254 | return ira->codegen->invalid_inst_gen; |
| 24244 | 25255 | } |
| 24245 | 25256 | |
| 24246 | | IrInstruction *result = ir_build_fence(&ira->new_irb, |
| 24247 | | instruction->base.scope, instruction->base.source_node, order_value, order); |
| 24248 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24249 | | return result; |
| 25257 | return ir_build_fence_gen(ira, &instruction->base.base, order); |
| 24250 | 25258 | } |
| 24251 | 25259 | |
| 24252 | | static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 24253 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 25260 | static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) { |
| 25261 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 24254 | 25262 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 24255 | 25263 | if (type_is_invalid(dest_type)) |
| 24256 | | return ira->codegen->invalid_instruction; |
| 25264 | return ira->codegen->invalid_inst_gen; |
| 24257 | 25265 | |
| 24258 | 25266 | if (dest_type->id != ZigTypeIdInt && |
| 24259 | 25267 | dest_type->id != ZigTypeIdComptimeInt) |
| 24260 | 25268 | { |
| 24261 | | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 24262 | | return ira->codegen->invalid_instruction; |
| 25269 | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25270 | return ira->codegen->invalid_inst_gen; |
| 24263 | 25271 | } |
| 24264 | 25272 | |
| 24265 | | IrInstruction *target = instruction->target->child; |
| 25273 | IrInstGen *target = instruction->target->child; |
| 24266 | 25274 | ZigType *src_type = target->value->type; |
| 24267 | 25275 | if (type_is_invalid(src_type)) |
| 24268 | | return ira->codegen->invalid_instruction; |
| 25276 | return ira->codegen->invalid_inst_gen; |
| 24269 | 25277 | |
| 24270 | 25278 | if (src_type->id != ZigTypeIdInt && |
| 24271 | 25279 | src_type->id != ZigTypeIdComptimeInt) |
| 24272 | 25280 | { |
| 24273 | | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 24274 | | return ira->codegen->invalid_instruction; |
| 25281 | ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 25282 | return ira->codegen->invalid_inst_gen; |
| 24275 | 25283 | } |
| 24276 | 25284 | |
| 24277 | 25285 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| 24278 | | return ir_implicit_cast(ira, target, dest_type); |
| 25286 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 24279 | 25287 | } |
| 24280 | 25288 | |
| 24281 | 25289 | if (instr_is_comptime(target)) { |
| 24282 | 25290 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 24283 | 25291 | if (val == nullptr) |
| 24284 | | return ira->codegen->invalid_instruction; |
| 25292 | return ira->codegen->invalid_inst_gen; |
| 24285 | 25293 | |
| 24286 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 25294 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 24287 | 25295 | bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, |
| 24288 | 25296 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 24289 | 25297 | return result; |
| 24290 | 25298 | } |
| 24291 | 25299 | |
| 24292 | 25300 | if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { |
| 24293 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 25301 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 24294 | 25302 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 24295 | 25303 | return result; |
| 24296 | 25304 | } |
| 24297 | 25305 | |
| 24298 | 25306 | if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) { |
| 24299 | 25307 | const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned"; |
| 24300 | | ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 24301 | | return ira->codegen->invalid_instruction; |
| 25308 | ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 25309 | return ira->codegen->invalid_inst_gen; |
| 24302 | 25310 | } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) { |
| 24303 | | ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 25311 | ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 24304 | 25312 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 24305 | | return ira->codegen->invalid_instruction; |
| 25313 | return ira->codegen->invalid_inst_gen; |
| 24306 | 25314 | } |
| 24307 | 25315 | |
| 24308 | | IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, |
| 24309 | | instruction->base.source_node, dest_type_value, target); |
| 24310 | | new_instruction->value->type = dest_type; |
| 24311 | | return new_instruction; |
| 25316 | return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target); |
| 24312 | 25317 | } |
| 24313 | 25318 | |
| 24314 | | static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 25319 | static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) { |
| 24315 | 25320 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24316 | 25321 | if (type_is_invalid(dest_type)) |
| 24317 | | return ira->codegen->invalid_instruction; |
| 25322 | return ira->codegen->invalid_inst_gen; |
| 24318 | 25323 | |
| 24319 | 25324 | if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) { |
| 24320 | | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 24321 | | return ira->codegen->invalid_instruction; |
| 25325 | ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25326 | return ira->codegen->invalid_inst_gen; |
| 24322 | 25327 | } |
| 24323 | 25328 | |
| 24324 | | IrInstruction *target = instruction->target->child; |
| 25329 | IrInstGen *target = instruction->target->child; |
| 24325 | 25330 | if (type_is_invalid(target->value->type)) |
| 24326 | | return ira->codegen->invalid_instruction; |
| 25331 | return ira->codegen->invalid_inst_gen; |
| 24327 | 25332 | |
| 24328 | 25333 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 24329 | | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 25334 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'", |
| 24330 | 25335 | buf_ptr(&target->value->type->name))); |
| 24331 | | return ira->codegen->invalid_instruction; |
| 25336 | return ira->codegen->invalid_inst_gen; |
| 24332 | 25337 | } |
| 24333 | 25338 | |
| 24334 | 25339 | if (instr_is_comptime(target)) { |
| 24335 | | return ir_implicit_cast(ira, target, dest_type); |
| 25340 | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 24336 | 25341 | } |
| 24337 | 25342 | |
| 24338 | 25343 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| 24339 | | ir_add_error(ira, instruction->target, buf_sprintf("attempt to cast runtime value to '%s'", |
| 25344 | ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'", |
| 24340 | 25345 | buf_ptr(&dest_type->name))); |
| 24341 | | return ira->codegen->invalid_instruction; |
| 25346 | return ira->codegen->invalid_inst_gen; |
| 24342 | 25347 | } |
| 24343 | 25348 | |
| 24344 | | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 25349 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 24345 | 25350 | } |
| 24346 | 25351 | |
| 24347 | | static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 25352 | static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) { |
| 24348 | 25353 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24349 | 25354 | if (type_is_invalid(dest_type)) |
| 24350 | | return ira->codegen->invalid_instruction; |
| 25355 | return ira->codegen->invalid_inst_gen; |
| 24351 | 25356 | |
| 24352 | 25357 | if (dest_type->id != ZigTypeIdFloat) { |
| 24353 | | ir_add_error(ira, instruction->dest_type, |
| 25358 | ir_add_error(ira, &instruction->dest_type->base, |
| 24354 | 25359 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 24355 | | return ira->codegen->invalid_instruction; |
| 25360 | return ira->codegen->invalid_inst_gen; |
| 24356 | 25361 | } |
| 24357 | 25362 | |
| 24358 | | IrInstruction *target = instruction->target->child; |
| 25363 | IrInstGen *target = instruction->target->child; |
| 24359 | 25364 | if (type_is_invalid(target->value->type)) |
| 24360 | | return ira->codegen->invalid_instruction; |
| 25365 | return ira->codegen->invalid_inst_gen; |
| 24361 | 25366 | |
| 24362 | 25367 | if (target->value->type->id == ZigTypeIdComptimeInt || |
| 24363 | 25368 | target->value->type->id == ZigTypeIdComptimeFloat) |
| ... | ... | @@ -24369,55 +25374,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 24369 | 25374 | } else { |
| 24370 | 25375 | op = CastOpNumLitToConcrete; |
| 24371 | 25376 | } |
| 24372 | | return ir_resolve_cast(ira, &instruction->base, target, dest_type, op); |
| 25377 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op); |
| 24373 | 25378 | } else { |
| 24374 | | return ira->codegen->invalid_instruction; |
| 25379 | return ira->codegen->invalid_inst_gen; |
| 24375 | 25380 | } |
| 24376 | 25381 | } |
| 24377 | 25382 | |
| 24378 | 25383 | if (target->value->type->id != ZigTypeIdFloat) { |
| 24379 | | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 25384 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'", |
| 24380 | 25385 | buf_ptr(&target->value->type->name))); |
| 24381 | | return ira->codegen->invalid_instruction; |
| 25386 | return ira->codegen->invalid_inst_gen; |
| 24382 | 25387 | } |
| 24383 | 25388 | |
| 24384 | | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 25389 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 24385 | 25390 | } |
| 24386 | 25391 | |
| 24387 | | static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 25392 | static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) { |
| 24388 | 25393 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24389 | 25394 | if (type_is_invalid(dest_type)) |
| 24390 | | return ira->codegen->invalid_instruction; |
| 25395 | return ira->codegen->invalid_inst_gen; |
| 24391 | 25396 | |
| 24392 | 25397 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 24393 | | ir_add_error(ira, instruction->dest_type, |
| 25398 | ir_add_error(ira, &instruction->dest_type->base, |
| 24394 | 25399 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 24395 | | return ira->codegen->invalid_instruction; |
| 25400 | return ira->codegen->invalid_inst_gen; |
| 24396 | 25401 | } |
| 24397 | 25402 | |
| 24398 | | IrInstruction *target = instruction->target->child; |
| 25403 | IrInstGen *target = instruction->target->child; |
| 24399 | 25404 | if (type_is_invalid(target->value->type)) |
| 24400 | | return ira->codegen->invalid_instruction; |
| 25405 | return ira->codegen->invalid_inst_gen; |
| 24401 | 25406 | |
| 24402 | 25407 | if (target->value->type->id != ZigTypeIdErrorSet) { |
| 24403 | | ir_add_error(ira, instruction->target, |
| 25408 | ir_add_error(ira, &instruction->target->base, |
| 24404 | 25409 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); |
| 24405 | | return ira->codegen->invalid_instruction; |
| 25410 | return ira->codegen->invalid_inst_gen; |
| 24406 | 25411 | } |
| 24407 | 25412 | |
| 24408 | | return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type); |
| 25413 | return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type); |
| 24409 | 25414 | } |
| 24410 | 25415 | |
| 24411 | | static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 25416 | static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) { |
| 24412 | 25417 | Error err; |
| 24413 | 25418 | |
| 24414 | 25419 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child); |
| 24415 | 25420 | if (type_is_invalid(dest_child_type)) |
| 24416 | | return ira->codegen->invalid_instruction; |
| 25421 | return ira->codegen->invalid_inst_gen; |
| 24417 | 25422 | |
| 24418 | | IrInstruction *target = instruction->target->child; |
| 25423 | IrInstGen *target = instruction->target->child; |
| 24419 | 25424 | if (type_is_invalid(target->value->type)) |
| 24420 | | return ira->codegen->invalid_instruction; |
| 25425 | return ira->codegen->invalid_inst_gen; |
| 24421 | 25426 | |
| 24422 | 25427 | bool src_ptr_const; |
| 24423 | 25428 | bool src_ptr_volatile; |
| ... | ... | @@ -24427,27 +25432,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24427 | 25432 | src_ptr_volatile = target->value->type->data.pointer.is_volatile; |
| 24428 | 25433 | |
| 24429 | 25434 | if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align))) |
| 24430 | | return ira->codegen->invalid_instruction; |
| 25435 | return ira->codegen->invalid_inst_gen; |
| 24431 | 25436 | } else if (is_slice(target->value->type)) { |
| 24432 | 25437 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 24433 | 25438 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 24434 | 25439 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 24435 | 25440 | |
| 24436 | 25441 | if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align))) |
| 24437 | | return ira->codegen->invalid_instruction; |
| 25442 | return ira->codegen->invalid_inst_gen; |
| 24438 | 25443 | } else { |
| 24439 | 25444 | src_ptr_const = true; |
| 24440 | 25445 | src_ptr_volatile = false; |
| 24441 | 25446 | |
| 24442 | 25447 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown))) |
| 24443 | | return ira->codegen->invalid_instruction; |
| 25448 | return ira->codegen->invalid_inst_gen; |
| 24444 | 25449 | |
| 24445 | 25450 | src_ptr_align = get_abi_alignment(ira->codegen, target->value->type); |
| 24446 | 25451 | } |
| 24447 | 25452 | |
| 24448 | 25453 | if (src_ptr_align != 0) { |
| 24449 | 25454 | if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown))) |
| 24450 | | return ira->codegen->invalid_instruction; |
| 25455 | return ira->codegen->invalid_inst_gen; |
| 24451 | 25456 | } |
| 24452 | 25457 | |
| 24453 | 25458 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, |
| ... | ... | @@ -24460,9 +25465,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24460 | 25465 | src_ptr_align, 0, 0, false); |
| 24461 | 25466 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 24462 | 25467 | |
| 24463 | | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 25468 | IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice); |
| 24464 | 25469 | if (type_is_invalid(casted_value->value->type)) |
| 24465 | | return ira->codegen->invalid_instruction; |
| 25470 | return ira->codegen->invalid_inst_gen; |
| 24466 | 25471 | |
| 24467 | 25472 | bool have_known_len = false; |
| 24468 | 25473 | uint64_t known_len; |
| ... | ... | @@ -24470,7 +25475,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24470 | 25475 | if (instr_is_comptime(casted_value)) { |
| 24471 | 25476 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 24472 | 25477 | if (!val) |
| 24473 | | return ira->codegen->invalid_instruction; |
| 25478 | return ira->codegen->invalid_inst_gen; |
| 24474 | 25479 | |
| 24475 | 25480 | ZigValue *len_val = val->data.x_struct.fields[slice_len_index]; |
| 24476 | 25481 | if (value_is_comptime(len_val)) { |
| ... | ... | @@ -24479,9 +25484,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24479 | 25484 | } |
| 24480 | 25485 | } |
| 24481 | 25486 | |
| 24482 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24483 | | dest_slice_type, nullptr, true, false, true); |
| 24484 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { |
| 25487 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25488 | dest_slice_type, nullptr, true, true); |
| 25489 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) { |
| 24485 | 25490 | return result_loc; |
| 24486 | 25491 | } |
| 24487 | 25492 | |
| ... | ... | @@ -24498,41 +25503,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24498 | 25503 | |
| 24499 | 25504 | if (have_known_len) { |
| 24500 | 25505 | if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown))) |
| 24501 | | return ira->codegen->invalid_instruction; |
| 25506 | return ira->codegen->invalid_inst_gen; |
| 24502 | 25507 | uint64_t child_type_size = type_size(ira->codegen, dest_child_type); |
| 24503 | 25508 | uint64_t remainder = known_len % child_type_size; |
| 24504 | 25509 | if (remainder != 0) { |
| 24505 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 25510 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 24506 | 25511 | buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch", |
| 24507 | 25512 | known_len, buf_ptr(&dest_slice_type->name))); |
| 24508 | | add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node, |
| 25513 | add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node, |
| 24509 | 25514 | buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64, |
| 24510 | 25515 | buf_ptr(&dest_child_type->name), child_type_size, remainder)); |
| 24511 | | return ira->codegen->invalid_instruction; |
| 25516 | return ira->codegen->invalid_inst_gen; |
| 24512 | 25517 | } |
| 24513 | 25518 | } |
| 24514 | 25519 | |
| 24515 | | return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc); |
| 25520 | return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc); |
| 24516 | 25521 | } |
| 24517 | 25522 | |
| 24518 | | static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 25523 | static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) { |
| 24519 | 25524 | Error err; |
| 24520 | 25525 | |
| 24521 | | IrInstruction *target = instruction->target->child; |
| 25526 | IrInstGen *target = instruction->target->child; |
| 24522 | 25527 | if (type_is_invalid(target->value->type)) |
| 24523 | | return ira->codegen->invalid_instruction; |
| 25528 | return ira->codegen->invalid_inst_gen; |
| 24524 | 25529 | |
| 24525 | 25530 | if (!is_slice(target->value->type)) { |
| 24526 | | ir_add_error(ira, instruction->target, |
| 25531 | ir_add_error(ira, &instruction->target->base, |
| 24527 | 25532 | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name))); |
| 24528 | | return ira->codegen->invalid_instruction; |
| 25533 | return ira->codegen->invalid_inst_gen; |
| 24529 | 25534 | } |
| 24530 | 25535 | |
| 24531 | 25536 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 24532 | 25537 | |
| 24533 | 25538 | uint32_t alignment; |
| 24534 | 25539 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| 24535 | | return ira->codegen->invalid_instruction; |
| 25540 | return ira->codegen->invalid_inst_gen; |
| 24536 | 25541 | |
| 24537 | 25542 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 24538 | 25543 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| ... | ... | @@ -24542,9 +25547,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 24542 | 25547 | if (instr_is_comptime(target)) { |
| 24543 | 25548 | ZigValue *target_val = ir_resolve_const(ira, target, UndefBad); |
| 24544 | 25549 | if (target_val == nullptr) |
| 24545 | | return ira->codegen->invalid_instruction; |
| 25550 | return ira->codegen->invalid_inst_gen; |
| 24546 | 25551 | |
| 24547 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type); |
| 25552 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type); |
| 24548 | 25553 | result->value->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 24549 | 25554 | |
| 24550 | 25555 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; |
| ... | ... | @@ -24564,13 +25569,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 24564 | 25569 | return result; |
| 24565 | 25570 | } |
| 24566 | 25571 | |
| 24567 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24568 | | dest_slice_type, nullptr, true, false, true); |
| 24569 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 25572 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25573 | dest_slice_type, nullptr, true, true); |
| 25574 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 24570 | 25575 | return result_loc; |
| 24571 | 25576 | } |
| 24572 | 25577 | |
| 24573 | | return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc); |
| 25578 | return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc); |
| 24574 | 25579 | } |
| 24575 | 25580 | |
| 24576 | 25581 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |
| ... | ... | @@ -24587,26 +25592,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali |
| 24587 | 25592 | return ErrorNone; |
| 24588 | 25593 | } |
| 24589 | 25594 | |
| 24590 | | static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 25595 | static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcIntToFloat *instruction) { |
| 24591 | 25596 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24592 | 25597 | if (type_is_invalid(dest_type)) |
| 24593 | | return ira->codegen->invalid_instruction; |
| 25598 | return ira->codegen->invalid_inst_gen; |
| 24594 | 25599 | |
| 24595 | | IrInstruction *target = instruction->target->child; |
| 25600 | IrInstGen *target = instruction->target->child; |
| 24596 | 25601 | if (type_is_invalid(target->value->type)) |
| 24597 | | return ira->codegen->invalid_instruction; |
| 25602 | return ira->codegen->invalid_inst_gen; |
| 24598 | 25603 | |
| 24599 | 25604 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 24600 | | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 25605 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'", |
| 24601 | 25606 | buf_ptr(&target->value->type->name))); |
| 24602 | | return ira->codegen->invalid_instruction; |
| 25607 | return ira->codegen->invalid_inst_gen; |
| 24603 | 25608 | } |
| 24604 | 25609 | |
| 24605 | | return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat); |
| 25610 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat); |
| 24606 | 25611 | } |
| 24607 | 25612 | |
| 24608 | | static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr, |
| 24609 | | ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node) |
| 25613 | static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr, |
| 25614 | ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node) |
| 24610 | 25615 | { |
| 24611 | 25616 | if (operand->value->type->id == ZigTypeIdComptimeInt) { |
| 24612 | 25617 | return ir_implicit_cast(ira, operand, dest_type); |
| ... | ... | @@ -24615,106 +25620,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou |
| 24615 | 25620 | if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) { |
| 24616 | 25621 | ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'", |
| 24617 | 25622 | buf_ptr(&operand->value->type->name))); |
| 24618 | | return ira->codegen->invalid_instruction; |
| 25623 | return ira->codegen->invalid_inst_gen; |
| 24619 | 25624 | } |
| 24620 | 25625 | |
| 24621 | 25626 | return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt); |
| 24622 | 25627 | } |
| 24623 | 25628 | |
| 24624 | | static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 25629 | static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) { |
| 24625 | 25630 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24626 | 25631 | if (type_is_invalid(dest_type)) |
| 24627 | | return ira->codegen->invalid_instruction; |
| 25632 | return ira->codegen->invalid_inst_gen; |
| 24628 | 25633 | |
| 24629 | | IrInstruction *operand = instruction->target->child; |
| 25634 | IrInstGen *operand = instruction->target->child; |
| 24630 | 25635 | if (type_is_invalid(operand->value->type)) |
| 24631 | | return ira->codegen->invalid_instruction; |
| 25636 | return ira->codegen->invalid_inst_gen; |
| 24632 | 25637 | |
| 24633 | | return ir_analyze_float_to_int(ira, &instruction->base, dest_type, operand, instruction->target->source_node); |
| 25638 | return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand, |
| 25639 | instruction->target->base.source_node); |
| 24634 | 25640 | } |
| 24635 | 25641 | |
| 24636 | | static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 24637 | | IrInstruction *target = instruction->target->child; |
| 25642 | static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) { |
| 25643 | IrInstGen *target = instruction->target->child; |
| 24638 | 25644 | if (type_is_invalid(target->value->type)) |
| 24639 | | return ira->codegen->invalid_instruction; |
| 25645 | return ira->codegen->invalid_inst_gen; |
| 24640 | 25646 | |
| 24641 | | IrInstruction *casted_target; |
| 25647 | IrInstGen *casted_target; |
| 24642 | 25648 | if (target->value->type->id == ZigTypeIdErrorSet) { |
| 24643 | 25649 | casted_target = target; |
| 24644 | 25650 | } else { |
| 24645 | 25651 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| 24646 | 25652 | if (type_is_invalid(casted_target->value->type)) |
| 24647 | | return ira->codegen->invalid_instruction; |
| 25653 | return ira->codegen->invalid_inst_gen; |
| 24648 | 25654 | } |
| 24649 | 25655 | |
| 24650 | | return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type); |
| 25656 | return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type); |
| 24651 | 25657 | } |
| 24652 | 25658 | |
| 24653 | | static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 24654 | | IrInstruction *target = instruction->target->child; |
| 25659 | static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) { |
| 25660 | IrInstGen *target = instruction->target->child; |
| 24655 | 25661 | if (type_is_invalid(target->value->type)) |
| 24656 | | return ira->codegen->invalid_instruction; |
| 25662 | return ira->codegen->invalid_inst_gen; |
| 24657 | 25663 | |
| 24658 | | IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 25664 | IrInstGen *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 24659 | 25665 | if (type_is_invalid(casted_target->value->type)) |
| 24660 | | return ira->codegen->invalid_instruction; |
| 25666 | return ira->codegen->invalid_inst_gen; |
| 24661 | 25667 | |
| 24662 | | return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 25668 | return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 24663 | 25669 | } |
| 24664 | 25670 | |
| 24665 | | static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 24666 | | IrInstruction *target = instruction->target->child; |
| 25671 | static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) { |
| 25672 | IrInstGen *target = instruction->target->child; |
| 24667 | 25673 | if (type_is_invalid(target->value->type)) |
| 24668 | | return ira->codegen->invalid_instruction; |
| 25674 | return ira->codegen->invalid_inst_gen; |
| 24669 | 25675 | |
| 24670 | 25676 | if (target->value->type->id != ZigTypeIdBool) { |
| 24671 | | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 25677 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'", |
| 24672 | 25678 | buf_ptr(&target->value->type->name))); |
| 24673 | | return ira->codegen->invalid_instruction; |
| 25679 | return ira->codegen->invalid_inst_gen; |
| 24674 | 25680 | } |
| 24675 | 25681 | |
| 24676 | 25682 | if (instr_is_comptime(target)) { |
| 24677 | 25683 | bool is_true; |
| 24678 | 25684 | if (!ir_resolve_bool(ira, target, &is_true)) |
| 24679 | | return ira->codegen->invalid_instruction; |
| 25685 | return ira->codegen->invalid_inst_gen; |
| 24680 | 25686 | |
| 24681 | | return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0); |
| 25687 | return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0); |
| 24682 | 25688 | } |
| 24683 | 25689 | |
| 24684 | 25690 | ZigType *u1_type = get_int_type(ira->codegen, false, 1); |
| 24685 | | return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt); |
| 25691 | return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt); |
| 24686 | 25692 | } |
| 24687 | 25693 | |
| 24688 | | static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { |
| 24689 | | IrInstruction *is_signed_value = instruction->is_signed->child; |
| 25694 | static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) { |
| 25695 | IrInstGen *is_signed_value = instruction->is_signed->child; |
| 24690 | 25696 | bool is_signed; |
| 24691 | 25697 | if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) |
| 24692 | | return ira->codegen->invalid_instruction; |
| 25698 | return ira->codegen->invalid_inst_gen; |
| 24693 | 25699 | |
| 24694 | | IrInstruction *bit_count_value = instruction->bit_count->child; |
| 25700 | IrInstGen *bit_count_value = instruction->bit_count->child; |
| 24695 | 25701 | uint64_t bit_count; |
| 24696 | 25702 | if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count)) |
| 24697 | | return ira->codegen->invalid_instruction; |
| 25703 | return ira->codegen->invalid_inst_gen; |
| 24698 | 25704 | |
| 24699 | | return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
| 25705 | return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
| 24700 | 25706 | } |
| 24701 | 25707 | |
| 24702 | | static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) { |
| 25708 | static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) { |
| 24703 | 25709 | uint64_t len; |
| 24704 | 25710 | if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len)) |
| 24705 | | return ira->codegen->invalid_instruction; |
| 25711 | return ira->codegen->invalid_inst_gen; |
| 24706 | 25712 | |
| 24707 | 25713 | ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child); |
| 24708 | 25714 | if (type_is_invalid(elem_type)) |
| 24709 | | return ira->codegen->invalid_instruction; |
| 25715 | return ira->codegen->invalid_inst_gen; |
| 24710 | 25716 | |
| 24711 | 25717 | ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type); |
| 24712 | 25718 | |
| 24713 | | return ir_const_type(ira, &instruction->base, vector_type); |
| 25719 | return ir_const_type(ira, &instruction->base.base, vector_type); |
| 24714 | 25720 | } |
| 24715 | 25721 | |
| 24716 | | static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr, |
| 24717 | | ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask) |
| 25722 | static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr, |
| 25723 | ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask) |
| 24718 | 25724 | { |
| 24719 | 25725 | ir_assert(source_instr && scalar_type && a && b && mask, source_instr); |
| 24720 | 25726 | ir_assert(is_valid_vector_elem_type(scalar_type), source_instr); |
| ... | ... | @@ -24725,15 +25731,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24725 | 25731 | } else if (mask->value->type->id == ZigTypeIdArray) { |
| 24726 | 25732 | len_mask = mask->value->type->data.array.len; |
| 24727 | 25733 | } else { |
| 24728 | | ir_add_error(ira, mask, |
| 25734 | ir_add_error(ira, &mask->base, |
| 24729 | 25735 | buf_sprintf("expected vector or array, found '%s'", |
| 24730 | 25736 | buf_ptr(&mask->value->type->name))); |
| 24731 | | return ira->codegen->invalid_instruction; |
| 25737 | return ira->codegen->invalid_inst_gen; |
| 24732 | 25738 | } |
| 24733 | 25739 | mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask, |
| 24734 | 25740 | ira->codegen->builtin_types.entry_i32)); |
| 24735 | 25741 | if (type_is_invalid(mask->value->type)) |
| 24736 | | return ira->codegen->invalid_instruction; |
| 25742 | return ira->codegen->invalid_inst_gen; |
| 24737 | 25743 | |
| 24738 | 25744 | uint32_t len_a; |
| 24739 | 25745 | if (a->value->type->id == ZigTypeIdVector) { |
| ... | ... | @@ -24743,11 +25749,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24743 | 25749 | } else if (a->value->type->id == ZigTypeIdUndefined) { |
| 24744 | 25750 | len_a = UINT32_MAX; |
| 24745 | 25751 | } else { |
| 24746 | | ir_add_error(ira, a, |
| 25752 | ir_add_error(ira, &a->base, |
| 24747 | 25753 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 24748 | 25754 | buf_ptr(&scalar_type->name), |
| 24749 | 25755 | buf_ptr(&a->value->type->name))); |
| 24750 | | return ira->codegen->invalid_instruction; |
| 25756 | return ira->codegen->invalid_inst_gen; |
| 24751 | 25757 | } |
| 24752 | 25758 | |
| 24753 | 25759 | uint32_t len_b; |
| ... | ... | @@ -24758,38 +25764,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24758 | 25764 | } else if (b->value->type->id == ZigTypeIdUndefined) { |
| 24759 | 25765 | len_b = UINT32_MAX; |
| 24760 | 25766 | } else { |
| 24761 | | ir_add_error(ira, b, |
| 25767 | ir_add_error(ira, &b->base, |
| 24762 | 25768 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 24763 | 25769 | buf_ptr(&scalar_type->name), |
| 24764 | 25770 | buf_ptr(&b->value->type->name))); |
| 24765 | | return ira->codegen->invalid_instruction; |
| 25771 | return ira->codegen->invalid_inst_gen; |
| 24766 | 25772 | } |
| 24767 | 25773 | |
| 24768 | 25774 | if (len_a == UINT32_MAX && len_b == UINT32_MAX) { |
| 24769 | | return ir_const_undef(ira, a, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 25775 | return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 24770 | 25776 | } |
| 24771 | 25777 | |
| 24772 | 25778 | if (len_a == UINT32_MAX) { |
| 24773 | 25779 | len_a = len_b; |
| 24774 | | a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 25780 | a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 24775 | 25781 | } else { |
| 24776 | 25782 | a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 24777 | 25783 | if (type_is_invalid(a->value->type)) |
| 24778 | | return ira->codegen->invalid_instruction; |
| 25784 | return ira->codegen->invalid_inst_gen; |
| 24779 | 25785 | } |
| 24780 | 25786 | |
| 24781 | 25787 | if (len_b == UINT32_MAX) { |
| 24782 | 25788 | len_b = len_a; |
| 24783 | | b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 25789 | b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 24784 | 25790 | } else { |
| 24785 | 25791 | b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 24786 | 25792 | if (type_is_invalid(b->value->type)) |
| 24787 | | return ira->codegen->invalid_instruction; |
| 25793 | return ira->codegen->invalid_inst_gen; |
| 24788 | 25794 | } |
| 24789 | 25795 | |
| 24790 | 25796 | ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk); |
| 24791 | 25797 | if (mask_val == nullptr) |
| 24792 | | return ira->codegen->invalid_instruction; |
| 25798 | return ira->codegen->invalid_inst_gen; |
| 24793 | 25799 | |
| 24794 | 25800 | expand_undef_array(ira->codegen, mask_val); |
| 24795 | 25801 | |
| ... | ... | @@ -24799,7 +25805,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24799 | 25805 | continue; |
| 24800 | 25806 | int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint); |
| 24801 | 25807 | uint32_t v; |
| 24802 | | IrInstruction *chosen_operand; |
| 25808 | IrInstGen *chosen_operand; |
| 24803 | 25809 | if (v_i32 >= 0) { |
| 24804 | 25810 | v = (uint32_t)v_i32; |
| 24805 | 25811 | chosen_operand = a; |
| ... | ... | @@ -24808,16 +25814,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24808 | 25814 | chosen_operand = b; |
| 24809 | 25815 | } |
| 24810 | 25816 | if (v >= chosen_operand->value->type->data.vector.len) { |
| 24811 | | ErrorMsg *msg = ir_add_error(ira, mask, |
| 25817 | ErrorMsg *msg = ir_add_error(ira, &mask->base, |
| 24812 | 25818 | buf_sprintf("mask index '%u' has out-of-bounds selection", i)); |
| 24813 | | add_error_note(ira->codegen, msg, chosen_operand->source_node, |
| 25819 | add_error_note(ira->codegen, msg, chosen_operand->base.source_node, |
| 24814 | 25820 | buf_sprintf("selected index '%u' out of bounds of %s", v, |
| 24815 | 25821 | buf_ptr(&chosen_operand->value->type->name))); |
| 24816 | 25822 | if (chosen_operand == a && v < len_a + len_b) { |
| 24817 | | add_error_note(ira->codegen, msg, b->source_node, |
| 25823 | add_error_note(ira->codegen, msg, b->base.source_node, |
| 24818 | 25824 | buf_create_from_str("selections from the second vector are specified with negative numbers")); |
| 24819 | 25825 | } |
| 24820 | | return ira->codegen->invalid_instruction; |
| 25826 | return ira->codegen->invalid_inst_gen; |
| 24821 | 25827 | } |
| 24822 | 25828 | } |
| 24823 | 25829 | |
| ... | ... | @@ -24825,16 +25831,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24825 | 25831 | if (instr_is_comptime(a) && instr_is_comptime(b)) { |
| 24826 | 25832 | ZigValue *a_val = ir_resolve_const(ira, a, UndefOk); |
| 24827 | 25833 | if (a_val == nullptr) |
| 24828 | | return ira->codegen->invalid_instruction; |
| 25834 | return ira->codegen->invalid_inst_gen; |
| 24829 | 25835 | |
| 24830 | 25836 | ZigValue *b_val = ir_resolve_const(ira, b, UndefOk); |
| 24831 | 25837 | if (b_val == nullptr) |
| 24832 | | return ira->codegen->invalid_instruction; |
| 25838 | return ira->codegen->invalid_inst_gen; |
| 24833 | 25839 | |
| 24834 | 25840 | expand_undef_array(ira->codegen, a_val); |
| 24835 | 25841 | expand_undef_array(ira->codegen, b_val); |
| 24836 | 25842 | |
| 24837 | | IrInstruction *result = ir_const(ira, source_instr, result_type); |
| 25843 | IrInstGen *result = ir_const(ira, source_instr, result_type); |
| 24838 | 25844 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 24839 | 25845 | for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { |
| 24840 | 25846 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| ... | ... | @@ -24866,7 +25872,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24866 | 25872 | uint32_t len_min = min(len_a, len_b); |
| 24867 | 25873 | uint32_t len_max = max(len_a, len_b); |
| 24868 | 25874 | |
| 24869 | | IrInstruction *expand_mask = ir_const(ira, mask, |
| 25875 | IrInstGen *expand_mask = ir_const(ira, &mask->base, |
| 24870 | 25876 | get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); |
| 24871 | 25877 | expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 24872 | 25878 | uint32_t i = 0; |
| ... | ... | @@ -24875,7 +25881,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24875 | 25881 | for (; i < len_max; i += 1) |
| 24876 | 25882 | bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 24877 | 25883 | |
| 24878 | | IrInstruction *undef = ir_const_undef(ira, source_instr, |
| 25884 | IrInstGen *undef = ir_const_undef(ira, source_instr, |
| 24879 | 25885 | get_vector_type(ira->codegen, len_min, scalar_type)); |
| 24880 | 25886 | |
| 24881 | 25887 | if (len_b < len_a) { |
| ... | ... | @@ -24885,62 +25891,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24885 | 25891 | } |
| 24886 | 25892 | } |
| 24887 | 25893 | |
| 24888 | | IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb, |
| 24889 | | source_instr->scope, source_instr->source_node, |
| 24890 | | nullptr, a, b, mask); |
| 24891 | | result->value->type = result_type; |
| 24892 | | return result; |
| 25894 | return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node, |
| 25895 | result_type, a, b, mask); |
| 24893 | 25896 | } |
| 24894 | 25897 | |
| 24895 | | static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) { |
| 24896 | | ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type); |
| 25898 | static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) { |
| 25899 | ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child); |
| 24897 | 25900 | if (type_is_invalid(scalar_type)) |
| 24898 | | return ira->codegen->invalid_instruction; |
| 25901 | return ira->codegen->invalid_inst_gen; |
| 24899 | 25902 | |
| 24900 | | IrInstruction *a = instruction->a->child; |
| 25903 | IrInstGen *a = instruction->a->child; |
| 24901 | 25904 | if (type_is_invalid(a->value->type)) |
| 24902 | | return ira->codegen->invalid_instruction; |
| 25905 | return ira->codegen->invalid_inst_gen; |
| 24903 | 25906 | |
| 24904 | | IrInstruction *b = instruction->b->child; |
| 25907 | IrInstGen *b = instruction->b->child; |
| 24905 | 25908 | if (type_is_invalid(b->value->type)) |
| 24906 | | return ira->codegen->invalid_instruction; |
| 25909 | return ira->codegen->invalid_inst_gen; |
| 24907 | 25910 | |
| 24908 | | IrInstruction *mask = instruction->mask->child; |
| 25911 | IrInstGen *mask = instruction->mask->child; |
| 24909 | 25912 | if (type_is_invalid(mask->value->type)) |
| 24910 | | return ira->codegen->invalid_instruction; |
| 25913 | return ira->codegen->invalid_inst_gen; |
| 24911 | 25914 | |
| 24912 | | return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask); |
| 25915 | return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask); |
| 24913 | 25916 | } |
| 24914 | 25917 | |
| 24915 | | static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) { |
| 25918 | static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) { |
| 24916 | 25919 | Error err; |
| 24917 | 25920 | |
| 24918 | | IrInstruction *len = instruction->len->child; |
| 25921 | IrInstGen *len = instruction->len->child; |
| 24919 | 25922 | if (type_is_invalid(len->value->type)) |
| 24920 | | return ira->codegen->invalid_instruction; |
| 25923 | return ira->codegen->invalid_inst_gen; |
| 24921 | 25924 | |
| 24922 | | IrInstruction *scalar = instruction->scalar->child; |
| 25925 | IrInstGen *scalar = instruction->scalar->child; |
| 24923 | 25926 | if (type_is_invalid(scalar->value->type)) |
| 24924 | | return ira->codegen->invalid_instruction; |
| 25927 | return ira->codegen->invalid_inst_gen; |
| 24925 | 25928 | |
| 24926 | 25929 | uint64_t len_u64; |
| 24927 | 25930 | if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64)) |
| 24928 | | return ira->codegen->invalid_instruction; |
| 25931 | return ira->codegen->invalid_inst_gen; |
| 24929 | 25932 | uint32_t len_int = len_u64; |
| 24930 | 25933 | |
| 24931 | | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type))) |
| 24932 | | return ira->codegen->invalid_instruction; |
| 25934 | if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type))) |
| 25935 | return ira->codegen->invalid_inst_gen; |
| 24933 | 25936 | |
| 24934 | 25937 | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); |
| 24935 | 25938 | |
| 24936 | 25939 | if (instr_is_comptime(scalar)) { |
| 24937 | 25940 | ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); |
| 24938 | 25941 | if (scalar_val == nullptr) |
| 24939 | | return ira->codegen->invalid_instruction; |
| 25942 | return ira->codegen->invalid_inst_gen; |
| 24940 | 25943 | if (scalar_val->special == ConstValSpecialUndef) |
| 24941 | | return ir_const_undef(ira, &instruction->base, return_type); |
| 25944 | return ir_const_undef(ira, &instruction->base.base, return_type); |
| 24942 | 25945 | |
| 24943 | | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 25946 | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 24944 | 25947 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 24945 | 25948 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 24946 | 25949 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val); |
| ... | ... | @@ -24948,48 +25951,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 24948 | 25951 | return result; |
| 24949 | 25952 | } |
| 24950 | 25953 | |
| 24951 | | return ir_build_splat_gen(ira, &instruction->base, return_type, scalar); |
| 25954 | return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar); |
| 24952 | 25955 | } |
| 24953 | 25956 | |
| 24954 | | static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 24955 | | IrInstruction *value = instruction->value->child; |
| 25957 | static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) { |
| 25958 | IrInstGen *value = instruction->value->child; |
| 24956 | 25959 | if (type_is_invalid(value->value->type)) |
| 24957 | | return ira->codegen->invalid_instruction; |
| 25960 | return ira->codegen->invalid_inst_gen; |
| 24958 | 25961 | |
| 24959 | 25962 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 24960 | 25963 | |
| 24961 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 25964 | IrInstGen *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 24962 | 25965 | if (type_is_invalid(casted_value->value->type)) |
| 24963 | | return ira->codegen->invalid_instruction; |
| 25966 | return ira->codegen->invalid_inst_gen; |
| 24964 | 25967 | |
| 24965 | 25968 | if (instr_is_comptime(casted_value)) { |
| 24966 | 25969 | ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad); |
| 24967 | 25970 | if (value == nullptr) |
| 24968 | | return ira->codegen->invalid_instruction; |
| 25971 | return ira->codegen->invalid_inst_gen; |
| 24969 | 25972 | |
| 24970 | | return ir_const_bool(ira, &instruction->base, !value->data.x_bool); |
| 25973 | return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool); |
| 24971 | 25974 | } |
| 24972 | 25975 | |
| 24973 | | IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, |
| 24974 | | instruction->base.source_node, casted_value); |
| 24975 | | result->value->type = bool_type; |
| 24976 | | return result; |
| 25976 | return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value); |
| 24977 | 25977 | } |
| 24978 | 25978 | |
| 24979 | | static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 25979 | static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) { |
| 24980 | 25980 | Error err; |
| 24981 | 25981 | |
| 24982 | | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 25982 | IrInstGen *dest_ptr = instruction->dest_ptr->child; |
| 24983 | 25983 | if (type_is_invalid(dest_ptr->value->type)) |
| 24984 | | return ira->codegen->invalid_instruction; |
| 25984 | return ira->codegen->invalid_inst_gen; |
| 24985 | 25985 | |
| 24986 | | IrInstruction *byte_value = instruction->byte->child; |
| 25986 | IrInstGen *byte_value = instruction->byte->child; |
| 24987 | 25987 | if (type_is_invalid(byte_value->value->type)) |
| 24988 | | return ira->codegen->invalid_instruction; |
| 25988 | return ira->codegen->invalid_inst_gen; |
| 24989 | 25989 | |
| 24990 | | IrInstruction *count_value = instruction->count->child; |
| 25990 | IrInstGen *count_value = instruction->count->child; |
| 24991 | 25991 | if (type_is_invalid(count_value->value->type)) |
| 24992 | | return ira->codegen->invalid_instruction; |
| 25992 | return ira->codegen->invalid_inst_gen; |
| 24993 | 25993 | |
| 24994 | 25994 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 24995 | 25995 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| ... | ... | @@ -25000,24 +26000,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25000 | 26000 | uint32_t dest_align; |
| 25001 | 26001 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 25002 | 26002 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 25003 | | return ira->codegen->invalid_instruction; |
| 26003 | return ira->codegen->invalid_inst_gen; |
| 25004 | 26004 | } else { |
| 25005 | 26005 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 25006 | 26006 | } |
| 25007 | 26007 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 25008 | 26008 | PtrLenUnknown, dest_align, 0, 0, false); |
| 25009 | 26009 | |
| 25010 | | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 26010 | IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 25011 | 26011 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 25012 | | return ira->codegen->invalid_instruction; |
| 26012 | return ira->codegen->invalid_inst_gen; |
| 25013 | 26013 | |
| 25014 | | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 26014 | IrInstGen *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 25015 | 26015 | if (type_is_invalid(casted_byte->value->type)) |
| 25016 | | return ira->codegen->invalid_instruction; |
| 26016 | return ira->codegen->invalid_inst_gen; |
| 25017 | 26017 | |
| 25018 | | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 26018 | IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 25019 | 26019 | if (type_is_invalid(casted_count->value->type)) |
| 25020 | | return ira->codegen->invalid_instruction; |
| 26020 | return ira->codegen->invalid_inst_gen; |
| 25021 | 26021 | |
| 25022 | 26022 | // TODO test this at comptime with u8 and non-u8 types |
| 25023 | 26023 | if (instr_is_comptime(casted_dest_ptr) && |
| ... | ... | @@ -25026,15 +26026,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25026 | 26026 | { |
| 25027 | 26027 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 25028 | 26028 | if (dest_ptr_val == nullptr) |
| 25029 | | return ira->codegen->invalid_instruction; |
| 26029 | return ira->codegen->invalid_inst_gen; |
| 25030 | 26030 | |
| 25031 | 26031 | ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); |
| 25032 | 26032 | if (byte_val == nullptr) |
| 25033 | | return ira->codegen->invalid_instruction; |
| 26033 | return ira->codegen->invalid_inst_gen; |
| 25034 | 26034 | |
| 25035 | 26035 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 25036 | 26036 | if (count_val == nullptr) |
| 25037 | | return ira->codegen->invalid_instruction; |
| 26037 | return ira->codegen->invalid_inst_gen; |
| 25038 | 26038 | |
| 25039 | 26039 | if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 25040 | 26040 | casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| ... | ... | @@ -25079,38 +26079,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25079 | 26079 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| 25080 | 26080 | size_t end = start + count; |
| 25081 | 26081 | if (end > bound_end) { |
| 25082 | | ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access")); |
| 25083 | | return ira->codegen->invalid_instruction; |
| 26082 | ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access")); |
| 26083 | return ira->codegen->invalid_inst_gen; |
| 25084 | 26084 | } |
| 25085 | 26085 | |
| 25086 | 26086 | for (size_t i = start; i < end; i += 1) { |
| 25087 | 26087 | copy_const_val(&dest_elements[i], byte_val); |
| 25088 | 26088 | } |
| 25089 | 26089 | |
| 25090 | | return ir_const_void(ira, &instruction->base); |
| 26090 | return ir_const_void(ira, &instruction->base.base); |
| 25091 | 26091 | } |
| 25092 | 26092 | } |
| 25093 | 26093 | |
| 25094 | | IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 25095 | | casted_dest_ptr, casted_byte, casted_count); |
| 25096 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25097 | | return result; |
| 26094 | return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count); |
| 25098 | 26095 | } |
| 25099 | 26096 | |
| 25100 | | static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 26097 | static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) { |
| 25101 | 26098 | Error err; |
| 25102 | 26099 | |
| 25103 | | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 26100 | IrInstGen *dest_ptr = instruction->dest_ptr->child; |
| 25104 | 26101 | if (type_is_invalid(dest_ptr->value->type)) |
| 25105 | | return ira->codegen->invalid_instruction; |
| 26102 | return ira->codegen->invalid_inst_gen; |
| 25106 | 26103 | |
| 25107 | | IrInstruction *src_ptr = instruction->src_ptr->child; |
| 26104 | IrInstGen *src_ptr = instruction->src_ptr->child; |
| 25108 | 26105 | if (type_is_invalid(src_ptr->value->type)) |
| 25109 | | return ira->codegen->invalid_instruction; |
| 26106 | return ira->codegen->invalid_inst_gen; |
| 25110 | 26107 | |
| 25111 | | IrInstruction *count_value = instruction->count->child; |
| 26108 | IrInstGen *count_value = instruction->count->child; |
| 25112 | 26109 | if (type_is_invalid(count_value->value->type)) |
| 25113 | | return ira->codegen->invalid_instruction; |
| 26110 | return ira->codegen->invalid_inst_gen; |
| 25114 | 26111 | |
| 25115 | 26112 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 25116 | 26113 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| ... | ... | @@ -25123,7 +26120,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25123 | 26120 | uint32_t dest_align; |
| 25124 | 26121 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 25125 | 26122 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 25126 | | return ira->codegen->invalid_instruction; |
| 26123 | return ira->codegen->invalid_inst_gen; |
| 25127 | 26124 | } else { |
| 25128 | 26125 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 25129 | 26126 | } |
| ... | ... | @@ -25131,7 +26128,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25131 | 26128 | uint32_t src_align; |
| 25132 | 26129 | if (src_uncasted_type->id == ZigTypeIdPointer) { |
| 25133 | 26130 | if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align))) |
| 25134 | | return ira->codegen->invalid_instruction; |
| 26131 | return ira->codegen->invalid_inst_gen; |
| 25135 | 26132 | } else { |
| 25136 | 26133 | src_align = get_abi_alignment(ira->codegen, u8); |
| 25137 | 26134 | } |
| ... | ... | @@ -25142,17 +26139,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25142 | 26139 | ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, |
| 25143 | 26140 | PtrLenUnknown, src_align, 0, 0, false); |
| 25144 | 26141 | |
| 25145 | | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 26142 | IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 25146 | 26143 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 25147 | | return ira->codegen->invalid_instruction; |
| 26144 | return ira->codegen->invalid_inst_gen; |
| 25148 | 26145 | |
| 25149 | | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 26146 | IrInstGen *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 25150 | 26147 | if (type_is_invalid(casted_src_ptr->value->type)) |
| 25151 | | return ira->codegen->invalid_instruction; |
| 26148 | return ira->codegen->invalid_inst_gen; |
| 25152 | 26149 | |
| 25153 | | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 26150 | IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 25154 | 26151 | if (type_is_invalid(casted_count->value->type)) |
| 25155 | | return ira->codegen->invalid_instruction; |
| 26152 | return ira->codegen->invalid_inst_gen; |
| 25156 | 26153 | |
| 25157 | 26154 | // TODO test this at comptime with u8 and non-u8 types |
| 25158 | 26155 | // TODO test with dest ptr being a global runtime variable |
| ... | ... | @@ -25162,15 +26159,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25162 | 26159 | { |
| 25163 | 26160 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 25164 | 26161 | if (dest_ptr_val == nullptr) |
| 25165 | | return ira->codegen->invalid_instruction; |
| 26162 | return ira->codegen->invalid_inst_gen; |
| 25166 | 26163 | |
| 25167 | 26164 | ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); |
| 25168 | 26165 | if (src_ptr_val == nullptr) |
| 25169 | | return ira->codegen->invalid_instruction; |
| 26166 | return ira->codegen->invalid_inst_gen; |
| 25170 | 26167 | |
| 25171 | 26168 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 25172 | 26169 | if (count_val == nullptr) |
| 25173 | | return ira->codegen->invalid_instruction; |
| 26170 | return ira->codegen->invalid_inst_gen; |
| 25174 | 26171 | |
| 25175 | 26172 | if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 25176 | 26173 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| ... | ... | @@ -25213,8 +26210,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25213 | 26210 | } |
| 25214 | 26211 | |
| 25215 | 26212 | if (dest_start + count > dest_end) { |
| 25216 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 25217 | | return ira->codegen->invalid_instruction; |
| 26213 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 26214 | return ira->codegen->invalid_inst_gen; |
| 25218 | 26215 | } |
| 25219 | 26216 | |
| 25220 | 26217 | ZigValue *src_elements; |
| ... | ... | @@ -25256,8 +26253,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25256 | 26253 | } |
| 25257 | 26254 | |
| 25258 | 26255 | if (src_start + count > src_end) { |
| 25259 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 25260 | | return ira->codegen->invalid_instruction; |
| 26256 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 26257 | return ira->codegen->invalid_inst_gen; |
| 25261 | 26258 | } |
| 25262 | 26259 | |
| 25263 | 26260 | // TODO check for noalias violations - this should be generalized to work for any function |
| ... | ... | @@ -25266,42 +26263,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25266 | 26263 | copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]); |
| 25267 | 26264 | } |
| 25268 | 26265 | |
| 25269 | | return ir_const_void(ira, &instruction->base); |
| 26266 | return ir_const_void(ira, &instruction->base.base); |
| 25270 | 26267 | } |
| 25271 | 26268 | } |
| 25272 | 26269 | |
| 25273 | | IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 25274 | | casted_dest_ptr, casted_src_ptr, casted_count); |
| 25275 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25276 | | return result; |
| 26270 | return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count); |
| 25277 | 26271 | } |
| 25278 | 26272 | |
| 25279 | | static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) { |
| 25280 | | IrInstruction *ptr_ptr = instruction->ptr->child; |
| 26273 | static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) { |
| 26274 | IrInstGen *ptr_ptr = instruction->ptr->child; |
| 25281 | 26275 | if (type_is_invalid(ptr_ptr->value->type)) |
| 25282 | | return ira->codegen->invalid_instruction; |
| 26276 | return ira->codegen->invalid_inst_gen; |
| 25283 | 26277 | |
| 25284 | 26278 | ZigType *ptr_ptr_type = ptr_ptr->value->type; |
| 25285 | 26279 | assert(ptr_ptr_type->id == ZigTypeIdPointer); |
| 25286 | 26280 | ZigType *array_type = ptr_ptr_type->data.pointer.child_type; |
| 25287 | 26281 | |
| 25288 | | IrInstruction *start = instruction->start->child; |
| 26282 | IrInstGen *start = instruction->start->child; |
| 25289 | 26283 | if (type_is_invalid(start->value->type)) |
| 25290 | | return ira->codegen->invalid_instruction; |
| 26284 | return ira->codegen->invalid_inst_gen; |
| 25291 | 26285 | |
| 25292 | 26286 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 25293 | | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 26287 | IrInstGen *casted_start = ir_implicit_cast(ira, start, usize); |
| 25294 | 26288 | if (type_is_invalid(casted_start->value->type)) |
| 25295 | | return ira->codegen->invalid_instruction; |
| 26289 | return ira->codegen->invalid_inst_gen; |
| 25296 | 26290 | |
| 25297 | | IrInstruction *end; |
| 26291 | IrInstGen *end; |
| 25298 | 26292 | if (instruction->end) { |
| 25299 | 26293 | end = instruction->end->child; |
| 25300 | 26294 | if (type_is_invalid(end->value->type)) |
| 25301 | | return ira->codegen->invalid_instruction; |
| 26295 | return ira->codegen->invalid_inst_gen; |
| 25302 | 26296 | end = ir_implicit_cast(ira, end, usize); |
| 25303 | 26297 | if (type_is_invalid(end->value->type)) |
| 25304 | | return ira->codegen->invalid_instruction; |
| 26298 | return ira->codegen->invalid_inst_gen; |
| 25305 | 26299 | } else { |
| 25306 | 26300 | end = nullptr; |
| 25307 | 26301 | } |
| ... | ... | @@ -25329,8 +26323,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25329 | 26323 | PtrLenUnknown, |
| 25330 | 26324 | array_type->data.pointer.explicit_alignment, 0, 0, false); |
| 25331 | 26325 | } else { |
| 25332 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); |
| 25333 | | return ira->codegen->invalid_instruction; |
| 26326 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer")); |
| 26327 | return ira->codegen->invalid_inst_gen; |
| 25334 | 26328 | } |
| 25335 | 26329 | } else { |
| 25336 | 26330 | elem_type = array_type->data.pointer.child_type; |
| ... | ... | @@ -25340,8 +26334,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25340 | 26334 | ZigType *maybe_sentineled_slice_ptr_type = array_type; |
| 25341 | 26335 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 25342 | 26336 | if (!end) { |
| 25343 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
| 25344 | | return ira->codegen->invalid_instruction; |
| 26337 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value")); |
| 26338 | return ira->codegen->invalid_inst_gen; |
| 25345 | 26339 | } |
| 25346 | 26340 | } |
| 25347 | 26341 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -25349,23 +26343,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25349 | 26343 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 25350 | 26344 | elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type; |
| 25351 | 26345 | } else { |
| 25352 | | ir_add_error(ira, &instruction->base, |
| 26346 | ir_add_error(ira, &instruction->base.base, |
| 25353 | 26347 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name))); |
| 25354 | | return ira->codegen->invalid_instruction; |
| 26348 | return ira->codegen->invalid_inst_gen; |
| 25355 | 26349 | } |
| 25356 | 26350 | |
| 25357 | 26351 | ZigType *return_type; |
| 25358 | 26352 | ZigValue *sentinel_val = nullptr; |
| 25359 | 26353 | if (instruction->sentinel) { |
| 25360 | | IrInstruction *uncasted_sentinel = instruction->sentinel->child; |
| 26354 | IrInstGen *uncasted_sentinel = instruction->sentinel->child; |
| 25361 | 26355 | if (type_is_invalid(uncasted_sentinel->value->type)) |
| 25362 | | return ira->codegen->invalid_instruction; |
| 25363 | | IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type); |
| 26356 | return ira->codegen->invalid_inst_gen; |
| 26357 | IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type); |
| 25364 | 26358 | if (type_is_invalid(sentinel->value->type)) |
| 25365 | | return ira->codegen->invalid_instruction; |
| 26359 | return ira->codegen->invalid_inst_gen; |
| 25366 | 26360 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 25367 | 26361 | if (sentinel_val == nullptr) |
| 25368 | | return ira->codegen->invalid_instruction; |
| 26362 | return ira->codegen->invalid_inst_gen; |
| 25369 | 26363 | ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val); |
| 25370 | 26364 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 25371 | 26365 | } else { |
| ... | ... | @@ -25387,9 +26381,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25387 | 26381 | if (array_type->id == ZigTypeIdPointer) { |
| 25388 | 26382 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 25389 | 26383 | assert(child_array_type->id == ZigTypeIdArray); |
| 25390 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26384 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25391 | 26385 | if (parent_ptr == nullptr) |
| 25392 | | return ira->codegen->invalid_instruction; |
| 26386 | return ira->codegen->invalid_inst_gen; |
| 25393 | 26387 | |
| 25394 | 26388 | |
| 25395 | 26389 | if (parent_ptr->special == ConstValSpecialUndef) { |
| ... | ... | @@ -25398,26 +26392,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25398 | 26392 | rel_end = SIZE_MAX; |
| 25399 | 26393 | ptr_is_undef = true; |
| 25400 | 26394 | } else { |
| 25401 | | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); |
| 26395 | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node); |
| 25402 | 26396 | if (array_val == nullptr) |
| 25403 | | return ira->codegen->invalid_instruction; |
| 26397 | return ira->codegen->invalid_inst_gen; |
| 25404 | 26398 | |
| 25405 | 26399 | rel_end = child_array_type->data.array.len; |
| 25406 | 26400 | abs_offset = 0; |
| 25407 | 26401 | } |
| 25408 | 26402 | } else { |
| 25409 | | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26403 | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25410 | 26404 | if (array_val == nullptr) |
| 25411 | | return ira->codegen->invalid_instruction; |
| 26405 | return ira->codegen->invalid_inst_gen; |
| 25412 | 26406 | rel_end = array_type->data.array.len; |
| 25413 | 26407 | parent_ptr = nullptr; |
| 25414 | 26408 | abs_offset = 0; |
| 25415 | 26409 | } |
| 25416 | 26410 | } else if (array_type->id == ZigTypeIdPointer) { |
| 25417 | 26411 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 25418 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26412 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25419 | 26413 | if (parent_ptr == nullptr) |
| 25420 | | return ira->codegen->invalid_instruction; |
| 26414 | return ira->codegen->invalid_inst_gen; |
| 25421 | 26415 | |
| 25422 | 26416 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 25423 | 26417 | array_val = nullptr; |
| ... | ... | @@ -25463,19 +26457,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25463 | 26457 | zig_panic("TODO slice of null ptr"); |
| 25464 | 26458 | } |
| 25465 | 26459 | } else if (is_slice(array_type)) { |
| 25466 | | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26460 | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25467 | 26461 | if (slice_ptr == nullptr) |
| 25468 | | return ira->codegen->invalid_instruction; |
| 26462 | return ira->codegen->invalid_inst_gen; |
| 25469 | 26463 | |
| 25470 | 26464 | if (slice_ptr->special == ConstValSpecialUndef) { |
| 25471 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| 25472 | | return ira->codegen->invalid_instruction; |
| 26465 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 26466 | return ira->codegen->invalid_inst_gen; |
| 25473 | 26467 | } |
| 25474 | 26468 | |
| 25475 | 26469 | parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 25476 | 26470 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 25477 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| 25478 | | return ira->codegen->invalid_instruction; |
| 26471 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 26472 | return ira->codegen->invalid_inst_gen; |
| 25479 | 26473 | } |
| 25480 | 26474 | |
| 25481 | 26475 | ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; |
| ... | ... | @@ -25518,37 +26512,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25518 | 26512 | |
| 25519 | 26513 | ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); |
| 25520 | 26514 | if (!start_val) |
| 25521 | | return ira->codegen->invalid_instruction; |
| 26515 | return ira->codegen->invalid_inst_gen; |
| 25522 | 26516 | |
| 25523 | 26517 | uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint); |
| 25524 | 26518 | if (!ptr_is_undef && start_scalar > rel_end) { |
| 25525 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 25526 | | return ira->codegen->invalid_instruction; |
| 26519 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 26520 | return ira->codegen->invalid_inst_gen; |
| 25527 | 26521 | } |
| 25528 | 26522 | |
| 25529 | 26523 | uint64_t end_scalar = rel_end; |
| 25530 | 26524 | if (end) { |
| 25531 | 26525 | ZigValue *end_val = ir_resolve_const(ira, end, UndefBad); |
| 25532 | 26526 | if (!end_val) |
| 25533 | | return ira->codegen->invalid_instruction; |
| 26527 | return ira->codegen->invalid_inst_gen; |
| 25534 | 26528 | end_scalar = bigint_as_u64(&end_val->data.x_bigint); |
| 25535 | 26529 | } |
| 25536 | 26530 | if (!ptr_is_undef) { |
| 25537 | 26531 | if (end_scalar > rel_end) { |
| 25538 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 25539 | | return ira->codegen->invalid_instruction; |
| 26532 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 26533 | return ira->codegen->invalid_inst_gen; |
| 25540 | 26534 | } |
| 25541 | 26535 | if (start_scalar > end_scalar) { |
| 25542 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end")); |
| 25543 | | return ira->codegen->invalid_instruction; |
| 26536 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end")); |
| 26537 | return ira->codegen->invalid_inst_gen; |
| 25544 | 26538 | } |
| 25545 | 26539 | } |
| 25546 | 26540 | if (ptr_is_undef && start_scalar != end_scalar) { |
| 25547 | | ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 25548 | | return ira->codegen->invalid_instruction; |
| 26541 | ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 26542 | return ira->codegen->invalid_inst_gen; |
| 25549 | 26543 | } |
| 25550 | 26544 | |
| 25551 | | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 26545 | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 25552 | 26546 | ZigValue *out_val = result->value; |
| 25553 | 26547 | out_val->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 25554 | 26548 | |
| ... | ... | @@ -25605,28 +26599,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25605 | 26599 | return result; |
| 25606 | 26600 | } |
| 25607 | 26601 | |
| 25608 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 25609 | | return_type, nullptr, true, false, true); |
| 25610 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 26602 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 26603 | return_type, nullptr, true, true); |
| 26604 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 25611 | 26605 | return result_loc; |
| 25612 | 26606 | } |
| 25613 | | return ir_build_slice_gen(ira, &instruction->base, return_type, |
| 26607 | return ir_build_slice_gen(ira, &instruction->base.base, return_type, |
| 25614 | 26608 | ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc); |
| 25615 | 26609 | } |
| 25616 | 26610 | |
| 25617 | | static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 26611 | static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) { |
| 25618 | 26612 | Error err; |
| 25619 | | IrInstruction *container = instruction->container->child; |
| 26613 | IrInstGen *container = instruction->container->child; |
| 25620 | 26614 | if (type_is_invalid(container->value->type)) |
| 25621 | | return ira->codegen->invalid_instruction; |
| 26615 | return ira->codegen->invalid_inst_gen; |
| 25622 | 26616 | ZigType *container_type = ir_resolve_type(ira, container); |
| 25623 | 26617 | |
| 25624 | 26618 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25625 | | return ira->codegen->invalid_instruction; |
| 26619 | return ira->codegen->invalid_inst_gen; |
| 25626 | 26620 | |
| 25627 | 26621 | uint64_t result; |
| 25628 | 26622 | if (type_is_invalid(container_type)) { |
| 25629 | | return ira->codegen->invalid_instruction; |
| 26623 | return ira->codegen->invalid_inst_gen; |
| 25630 | 26624 | } else if (container_type->id == ZigTypeIdEnum) { |
| 25631 | 26625 | result = container_type->data.enumeration.src_field_count; |
| 25632 | 26626 | } else if (container_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -25634,135 +26628,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst |
| 25634 | 26628 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25635 | 26629 | result = container_type->data.unionation.src_field_count; |
| 25636 | 26630 | } else if (container_type->id == ZigTypeIdErrorSet) { |
| 25637 | | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 25638 | | return ira->codegen->invalid_instruction; |
| 26631 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) { |
| 26632 | return ira->codegen->invalid_inst_gen; |
| 25639 | 26633 | } |
| 25640 | 26634 | if (type_is_global_error_set(container_type)) { |
| 25641 | | ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime")); |
| 25642 | | return ira->codegen->invalid_instruction; |
| 26635 | ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime")); |
| 26636 | return ira->codegen->invalid_inst_gen; |
| 25643 | 26637 | } |
| 25644 | 26638 | result = container_type->data.error_set.err_count; |
| 25645 | 26639 | } else { |
| 25646 | | ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 25647 | | return ira->codegen->invalid_instruction; |
| 26640 | ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 26641 | return ira->codegen->invalid_inst_gen; |
| 25648 | 26642 | } |
| 25649 | 26643 | |
| 25650 | | return ir_const_unsigned(ira, &instruction->base, result); |
| 26644 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 25651 | 26645 | } |
| 25652 | 26646 | |
| 25653 | | static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { |
| 26647 | static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) { |
| 25654 | 26648 | Error err; |
| 25655 | | IrInstruction *container_type_value = instruction->container_type->child; |
| 26649 | IrInstGen *container_type_value = instruction->container_type->child; |
| 25656 | 26650 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 25657 | 26651 | if (type_is_invalid(container_type)) |
| 25658 | | return ira->codegen->invalid_instruction; |
| 26652 | return ira->codegen->invalid_inst_gen; |
| 25659 | 26653 | |
| 25660 | 26654 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25661 | | return ira->codegen->invalid_instruction; |
| 26655 | return ira->codegen->invalid_inst_gen; |
| 25662 | 26656 | |
| 25663 | 26657 | |
| 25664 | 26658 | uint64_t member_index; |
| 25665 | | IrInstruction *index_value = instruction->member_index->child; |
| 26659 | IrInstGen *index_value = instruction->member_index->child; |
| 25666 | 26660 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 25667 | | return ira->codegen->invalid_instruction; |
| 26661 | return ira->codegen->invalid_inst_gen; |
| 25668 | 26662 | |
| 25669 | 26663 | if (container_type->id == ZigTypeIdStruct) { |
| 25670 | 26664 | if (member_index >= container_type->data.structure.src_field_count) { |
| 25671 | | ir_add_error(ira, index_value, |
| 26665 | ir_add_error(ira, &index_value->base, |
| 25672 | 26666 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25673 | 26667 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 25674 | | return ira->codegen->invalid_instruction; |
| 26668 | return ira->codegen->invalid_inst_gen; |
| 25675 | 26669 | } |
| 25676 | 26670 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 25677 | 26671 | |
| 25678 | | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 26672 | return ir_const_type(ira, &instruction->base.base, field->type_entry); |
| 25679 | 26673 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25680 | 26674 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 25681 | | ir_add_error(ira, index_value, |
| 26675 | ir_add_error(ira, &index_value->base, |
| 25682 | 26676 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25683 | 26677 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 25684 | | return ira->codegen->invalid_instruction; |
| 26678 | return ira->codegen->invalid_inst_gen; |
| 25685 | 26679 | } |
| 25686 | 26680 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 25687 | 26681 | |
| 25688 | | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 26682 | return ir_const_type(ira, &instruction->base.base, field->type_entry); |
| 25689 | 26683 | } else { |
| 25690 | | ir_add_error(ira, container_type_value, |
| 26684 | ir_add_error(ira, &container_type_value->base, |
| 25691 | 26685 | buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name))); |
| 25692 | | return ira->codegen->invalid_instruction; |
| 26686 | return ira->codegen->invalid_inst_gen; |
| 25693 | 26687 | } |
| 25694 | 26688 | } |
| 25695 | 26689 | |
| 25696 | | static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { |
| 26690 | static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) { |
| 25697 | 26691 | Error err; |
| 25698 | | IrInstruction *container_type_value = instruction->container_type->child; |
| 26692 | IrInstGen *container_type_value = instruction->container_type->child; |
| 25699 | 26693 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 25700 | 26694 | if (type_is_invalid(container_type)) |
| 25701 | | return ira->codegen->invalid_instruction; |
| 26695 | return ira->codegen->invalid_inst_gen; |
| 25702 | 26696 | |
| 25703 | 26697 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25704 | | return ira->codegen->invalid_instruction; |
| 26698 | return ira->codegen->invalid_inst_gen; |
| 25705 | 26699 | |
| 25706 | 26700 | uint64_t member_index; |
| 25707 | | IrInstruction *index_value = instruction->member_index->child; |
| 26701 | IrInstGen *index_value = instruction->member_index->child; |
| 25708 | 26702 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 25709 | | return ira->codegen->invalid_instruction; |
| 26703 | return ira->codegen->invalid_inst_gen; |
| 25710 | 26704 | |
| 25711 | 26705 | if (container_type->id == ZigTypeIdStruct) { |
| 25712 | 26706 | if (member_index >= container_type->data.structure.src_field_count) { |
| 25713 | | ir_add_error(ira, index_value, |
| 26707 | ir_add_error(ira, &index_value->base, |
| 25714 | 26708 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25715 | 26709 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 25716 | | return ira->codegen->invalid_instruction; |
| 26710 | return ira->codegen->invalid_inst_gen; |
| 25717 | 26711 | } |
| 25718 | 26712 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 25719 | 26713 | |
| 25720 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26714 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25721 | 26715 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25722 | 26716 | return result; |
| 25723 | 26717 | } else if (container_type->id == ZigTypeIdEnum) { |
| 25724 | 26718 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| 25725 | | ir_add_error(ira, index_value, |
| 26719 | ir_add_error(ira, &index_value->base, |
| 25726 | 26720 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25727 | 26721 | member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count)); |
| 25728 | | return ira->codegen->invalid_instruction; |
| 26722 | return ira->codegen->invalid_inst_gen; |
| 25729 | 26723 | } |
| 25730 | 26724 | TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; |
| 25731 | 26725 | |
| 25732 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26726 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25733 | 26727 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25734 | 26728 | return result; |
| 25735 | 26729 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25736 | 26730 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 25737 | | ir_add_error(ira, index_value, |
| 26731 | ir_add_error(ira, &index_value->base, |
| 25738 | 26732 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25739 | 26733 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 25740 | | return ira->codegen->invalid_instruction; |
| 26734 | return ira->codegen->invalid_inst_gen; |
| 25741 | 26735 | } |
| 25742 | 26736 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 25743 | 26737 | |
| 25744 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26738 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25745 | 26739 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25746 | 26740 | return result; |
| 25747 | 26741 | } else { |
| 25748 | | ir_add_error(ira, container_type_value, |
| 26742 | ir_add_error(ira, &container_type_value->base, |
| 25749 | 26743 | buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name))); |
| 25750 | | return ira->codegen->invalid_instruction; |
| 26744 | return ira->codegen->invalid_inst_gen; |
| 25751 | 26745 | } |
| 25752 | 26746 | } |
| 25753 | 26747 | |
| 25754 | | static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) { |
| 26748 | static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) { |
| 25755 | 26749 | Error err; |
| 25756 | 26750 | ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child); |
| 25757 | 26751 | if (type_is_invalid(container_type)) |
| 25758 | | return ira->codegen->invalid_instruction; |
| 26752 | return ira->codegen->invalid_inst_gen; |
| 25759 | 26753 | |
| 25760 | 26754 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown))) |
| 25761 | | return ira->codegen->invalid_instruction; |
| 26755 | return ira->codegen->invalid_inst_gen; |
| 25762 | 26756 | |
| 25763 | 26757 | Buf *field_name = ir_resolve_str(ira, instruction->field_name->child); |
| 25764 | 26758 | if (field_name == nullptr) |
| 25765 | | return ira->codegen->invalid_instruction; |
| 26759 | return ira->codegen->invalid_inst_gen; |
| 25766 | 26760 | |
| 25767 | 26761 | bool result; |
| 25768 | 26762 | if (container_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -25772,91 +26766,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc |
| 25772 | 26766 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25773 | 26767 | result = find_union_type_field(container_type, field_name) != nullptr; |
| 25774 | 26768 | } else { |
| 25775 | | ir_add_error(ira, instruction->container_type, |
| 26769 | ir_add_error(ira, &instruction->container_type->base, |
| 25776 | 26770 | buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name))); |
| 25777 | | return ira->codegen->invalid_instruction; |
| 26771 | return ira->codegen->invalid_inst_gen; |
| 25778 | 26772 | } |
| 25779 | | return ir_const_bool(ira, &instruction->base, result); |
| 26773 | return ir_const_bool(ira, &instruction->base.base, result); |
| 25780 | 26774 | } |
| 25781 | 26775 | |
| 25782 | | static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 25783 | | IrInstruction *result = ir_build_breakpoint(&ira->new_irb, |
| 25784 | | instruction->base.scope, instruction->base.source_node); |
| 25785 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25786 | | return result; |
| 26776 | static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) { |
| 26777 | return ir_build_breakpoint_gen(ira, &instruction->base.base); |
| 25787 | 26778 | } |
| 25788 | 26779 | |
| 25789 | | static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 25790 | | IrInstruction *result = ir_build_return_address(&ira->new_irb, |
| 25791 | | instruction->base.scope, instruction->base.source_node); |
| 25792 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25793 | | return result; |
| 26780 | static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) { |
| 26781 | return ir_build_return_address_gen(ira, &instruction->base.base); |
| 25794 | 26782 | } |
| 25795 | 26783 | |
| 25796 | | static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 25797 | | IrInstruction *result = ir_build_frame_address(&ira->new_irb, |
| 25798 | | instruction->base.scope, instruction->base.source_node); |
| 25799 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25800 | | return result; |
| 26784 | static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) { |
| 26785 | return ir_build_frame_address_gen(ira, &instruction->base.base); |
| 25801 | 26786 | } |
| 25802 | 26787 | |
| 25803 | | static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) { |
| 25804 | | ZigFn *fn = exec_fn_entry(ira->new_irb.exec); |
| 25805 | | ir_assert(fn != nullptr, &instruction->base); |
| 26788 | static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) { |
| 26789 | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 26790 | ir_assert(fn != nullptr, &instruction->base.base); |
| 25806 | 26791 | |
| 25807 | 26792 | if (fn->inferred_async_node == nullptr) { |
| 25808 | | fn->inferred_async_node = instruction->base.source_node; |
| 26793 | fn->inferred_async_node = instruction->base.base.source_node; |
| 25809 | 26794 | } |
| 25810 | 26795 | |
| 25811 | 26796 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn); |
| 25812 | 26797 | ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); |
| 25813 | 26798 | |
| 25814 | | IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 25815 | | result->value->type = ptr_frame_type; |
| 25816 | | return result; |
| 26799 | return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type); |
| 25817 | 26800 | } |
| 25818 | 26801 | |
| 25819 | | static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) { |
| 26802 | static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) { |
| 25820 | 26803 | ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child); |
| 25821 | 26804 | if (fn == nullptr) |
| 25822 | | return ira->codegen->invalid_instruction; |
| 26805 | return ira->codegen->invalid_inst_gen; |
| 25823 | 26806 | |
| 25824 | 26807 | if (fn->type_entry->data.fn.is_generic) { |
| 25825 | | ir_add_error(ira, &instruction->base, |
| 26808 | ir_add_error(ira, &instruction->base.base, |
| 25826 | 26809 | buf_sprintf("@Frame() of generic function")); |
| 25827 | | return ira->codegen->invalid_instruction; |
| 26810 | return ira->codegen->invalid_inst_gen; |
| 25828 | 26811 | } |
| 25829 | 26812 | |
| 25830 | 26813 | ZigType *ty = get_fn_frame_type(ira->codegen, fn); |
| 25831 | | return ir_const_type(ira, &instruction->base, ty); |
| 26814 | return ir_const_type(ira, &instruction->base.base, ty); |
| 25832 | 26815 | } |
| 25833 | 26816 | |
| 25834 | | static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) { |
| 25835 | | IrInstruction *fn = instruction->fn->child; |
| 26817 | static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) { |
| 26818 | IrInstGen *fn = instruction->fn->child; |
| 25836 | 26819 | if (type_is_invalid(fn->value->type)) |
| 25837 | | return ira->codegen->invalid_instruction; |
| 26820 | return ira->codegen->invalid_inst_gen; |
| 25838 | 26821 | |
| 25839 | 26822 | if (fn->value->type->id != ZigTypeIdFn) { |
| 25840 | | ir_add_error(ira, fn, |
| 26823 | ir_add_error(ira, &fn->base, |
| 25841 | 26824 | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); |
| 25842 | | return ira->codegen->invalid_instruction; |
| 26825 | return ira->codegen->invalid_inst_gen; |
| 25843 | 26826 | } |
| 25844 | 26827 | |
| 25845 | 26828 | ira->codegen->need_frame_size_prefix_data = true; |
| 25846 | 26829 | |
| 25847 | | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, |
| 25848 | | instruction->base.source_node, fn); |
| 25849 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25850 | | return result; |
| 26830 | return ir_build_frame_size_gen(ira, &instruction->base.base, fn); |
| 25851 | 26831 | } |
| 25852 | 26832 | |
| 25853 | | static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 26833 | static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) { |
| 25854 | 26834 | // Here we create a lazy value in order to avoid resolving the alignment of the type |
| 25855 | 26835 | // immediately. This avoids false positive dependency loops such as: |
| 25856 | 26836 | // const Node = struct { |
| 25857 | 26837 | // field: []align(@alignOf(Node)) Node, |
| 25858 | 26838 | // }; |
| 25859 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 26839 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 25860 | 26840 | result->value->special = ConstValSpecialLazy; |
| 25861 | 26841 | |
| 25862 | 26842 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf"); |
| ... | ... | @@ -25866,41 +26846,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 25866 | 26846 | |
| 25867 | 26847 | lazy_align_of->target_type = instruction->type_value->child; |
| 25868 | 26848 | if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr) |
| 25869 | | return ira->codegen->invalid_instruction; |
| 26849 | return ira->codegen->invalid_inst_gen; |
| 25870 | 26850 | |
| 25871 | 26851 | return result; |
| 25872 | 26852 | } |
| 25873 | 26853 | |
| 25874 | | static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 26854 | static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) { |
| 25875 | 26855 | Error err; |
| 25876 | 26856 | |
| 25877 | | IrInstruction *type_value = instruction->type_value->child; |
| 26857 | IrInstGen *type_value = instruction->type_value->child; |
| 25878 | 26858 | if (type_is_invalid(type_value->value->type)) |
| 25879 | | return ira->codegen->invalid_instruction; |
| 26859 | return ira->codegen->invalid_inst_gen; |
| 25880 | 26860 | |
| 25881 | 26861 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| 25882 | 26862 | if (type_is_invalid(dest_type)) |
| 25883 | | return ira->codegen->invalid_instruction; |
| 26863 | return ira->codegen->invalid_inst_gen; |
| 25884 | 26864 | |
| 25885 | 26865 | if (dest_type->id != ZigTypeIdInt) { |
| 25886 | | ir_add_error(ira, type_value, |
| 26866 | ir_add_error(ira, &type_value->base, |
| 25887 | 26867 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25888 | | return ira->codegen->invalid_instruction; |
| 26868 | return ira->codegen->invalid_inst_gen; |
| 25889 | 26869 | } |
| 25890 | 26870 | |
| 25891 | | IrInstruction *op1 = instruction->op1->child; |
| 26871 | IrInstGen *op1 = instruction->op1->child; |
| 25892 | 26872 | if (type_is_invalid(op1->value->type)) |
| 25893 | | return ira->codegen->invalid_instruction; |
| 26873 | return ira->codegen->invalid_inst_gen; |
| 25894 | 26874 | |
| 25895 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 26875 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 25896 | 26876 | if (type_is_invalid(casted_op1->value->type)) |
| 25897 | | return ira->codegen->invalid_instruction; |
| 26877 | return ira->codegen->invalid_inst_gen; |
| 25898 | 26878 | |
| 25899 | | IrInstruction *op2 = instruction->op2->child; |
| 26879 | IrInstGen *op2 = instruction->op2->child; |
| 25900 | 26880 | if (type_is_invalid(op2->value->type)) |
| 25901 | | return ira->codegen->invalid_instruction; |
| 26881 | return ira->codegen->invalid_inst_gen; |
| 25902 | 26882 | |
| 25903 | | IrInstruction *casted_op2; |
| 26883 | IrInstGen *casted_op2; |
| 25904 | 26884 | if (instruction->op == IrOverflowOpShl) { |
| 25905 | 26885 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 25906 | 26886 | dest_type->data.integral.bit_count - 1); |
| ... | ... | @@ -25909,17 +26889,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25909 | 26889 | casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 25910 | 26890 | } |
| 25911 | 26891 | if (type_is_invalid(casted_op2->value->type)) |
| 25912 | | return ira->codegen->invalid_instruction; |
| 26892 | return ira->codegen->invalid_inst_gen; |
| 25913 | 26893 | |
| 25914 | | IrInstruction *result_ptr = instruction->result_ptr->child; |
| 26894 | IrInstGen *result_ptr = instruction->result_ptr->child; |
| 25915 | 26895 | if (type_is_invalid(result_ptr->value->type)) |
| 25916 | | return ira->codegen->invalid_instruction; |
| 26896 | return ira->codegen->invalid_inst_gen; |
| 25917 | 26897 | |
| 25918 | 26898 | ZigType *expected_ptr_type; |
| 25919 | 26899 | if (result_ptr->value->type->id == ZigTypeIdPointer) { |
| 25920 | 26900 | uint32_t alignment; |
| 25921 | 26901 | if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment))) |
| 25922 | | return ira->codegen->invalid_instruction; |
| 26902 | return ira->codegen->invalid_inst_gen; |
| 25923 | 26903 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 25924 | 26904 | false, result_ptr->value->type->data.pointer.is_volatile, |
| 25925 | 26905 | PtrLenSingle, |
| ... | ... | @@ -25928,9 +26908,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25928 | 26908 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); |
| 25929 | 26909 | } |
| 25930 | 26910 | |
| 25931 | | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 26911 | IrInstGen *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 25932 | 26912 | if (type_is_invalid(casted_result_ptr->value->type)) |
| 25933 | | return ira->codegen->invalid_instruction; |
| 26913 | return ira->codegen->invalid_inst_gen; |
| 25934 | 26914 | |
| 25935 | 26915 | if (instr_is_comptime(casted_op1) && |
| 25936 | 26916 | instr_is_comptime(casted_op2) && |
| ... | ... | @@ -25938,22 +26918,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25938 | 26918 | { |
| 25939 | 26919 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 25940 | 26920 | if (op1_val == nullptr) |
| 25941 | | return ira->codegen->invalid_instruction; |
| 26921 | return ira->codegen->invalid_inst_gen; |
| 25942 | 26922 | |
| 25943 | 26923 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 25944 | 26924 | if (op2_val == nullptr) |
| 25945 | | return ira->codegen->invalid_instruction; |
| 26925 | return ira->codegen->invalid_inst_gen; |
| 25946 | 26926 | |
| 25947 | 26927 | ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); |
| 25948 | 26928 | if (result_val == nullptr) |
| 25949 | | return ira->codegen->invalid_instruction; |
| 26929 | return ira->codegen->invalid_inst_gen; |
| 25950 | 26930 | |
| 25951 | 26931 | BigInt *op1_bigint = &op1_val->data.x_bigint; |
| 25952 | 26932 | BigInt *op2_bigint = &op2_val->data.x_bigint; |
| 25953 | 26933 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, |
| 25954 | | casted_result_ptr->source_node); |
| 26934 | casted_result_ptr->base.source_node); |
| 25955 | 26935 | if (pointee_val == nullptr) |
| 25956 | | return ira->codegen->invalid_instruction; |
| 26936 | return ira->codegen->invalid_inst_gen; |
| 25957 | 26937 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 25958 | 26938 | switch (instruction->op) { |
| 25959 | 26939 | case IrOverflowOpAdd: |
| ... | ... | @@ -25980,17 +26960,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25980 | 26960 | dest_type->data.integral.is_signed); |
| 25981 | 26961 | } |
| 25982 | 26962 | pointee_val->special = ConstValSpecialStatic; |
| 25983 | | return ir_const_bool(ira, &instruction->base, result_bool); |
| 26963 | return ir_const_bool(ira, &instruction->base.base, result_bool); |
| 25984 | 26964 | } |
| 25985 | 26965 | |
| 25986 | | IrInstruction *result = ir_build_overflow_op(&ira->new_irb, |
| 25987 | | instruction->base.scope, instruction->base.source_node, |
| 25988 | | instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 25989 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 25990 | | return result; |
| 26966 | return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op, |
| 26967 | casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 25991 | 26968 | } |
| 25992 | 26969 | |
| 25993 | | static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type, |
| 26970 | static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type, |
| 25994 | 26971 | ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) { |
| 25995 | 26972 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 25996 | 26973 | f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value, |
| ... | ... | @@ -26017,61 +26994,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z |
| 26017 | 26994 | } |
| 26018 | 26995 | } |
| 26019 | 26996 | |
| 26020 | | static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) { |
| 26021 | | IrInstruction *type_value = instruction->type_value->child; |
| 26997 | static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) { |
| 26998 | IrInstGen *type_value = instruction->type_value->child; |
| 26022 | 26999 | if (type_is_invalid(type_value->value->type)) |
| 26023 | | return ira->codegen->invalid_instruction; |
| 27000 | return ira->codegen->invalid_inst_gen; |
| 26024 | 27001 | |
| 26025 | 27002 | ZigType *expr_type = ir_resolve_type(ira, type_value); |
| 26026 | 27003 | if (type_is_invalid(expr_type)) |
| 26027 | | return ira->codegen->invalid_instruction; |
| 27004 | return ira->codegen->invalid_inst_gen; |
| 26028 | 27005 | |
| 26029 | 27006 | // Only allow float types, and vectors of floats. |
| 26030 | 27007 | ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
| 26031 | 27008 | if (float_type->id != ZigTypeIdFloat) { |
| 26032 | | ir_add_error(ira, type_value, |
| 27009 | ir_add_error(ira, &type_value->base, |
| 26033 | 27010 | buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name))); |
| 26034 | | return ira->codegen->invalid_instruction; |
| 27011 | return ira->codegen->invalid_inst_gen; |
| 26035 | 27012 | } |
| 26036 | 27013 | |
| 26037 | | IrInstruction *op1 = instruction->op1->child; |
| 27014 | IrInstGen *op1 = instruction->op1->child; |
| 26038 | 27015 | if (type_is_invalid(op1->value->type)) |
| 26039 | | return ira->codegen->invalid_instruction; |
| 27016 | return ira->codegen->invalid_inst_gen; |
| 26040 | 27017 | |
| 26041 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 27018 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 26042 | 27019 | if (type_is_invalid(casted_op1->value->type)) |
| 26043 | | return ira->codegen->invalid_instruction; |
| 27020 | return ira->codegen->invalid_inst_gen; |
| 26044 | 27021 | |
| 26045 | | IrInstruction *op2 = instruction->op2->child; |
| 27022 | IrInstGen *op2 = instruction->op2->child; |
| 26046 | 27023 | if (type_is_invalid(op2->value->type)) |
| 26047 | | return ira->codegen->invalid_instruction; |
| 27024 | return ira->codegen->invalid_inst_gen; |
| 26048 | 27025 | |
| 26049 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 27026 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 26050 | 27027 | if (type_is_invalid(casted_op2->value->type)) |
| 26051 | | return ira->codegen->invalid_instruction; |
| 27028 | return ira->codegen->invalid_inst_gen; |
| 26052 | 27029 | |
| 26053 | | IrInstruction *op3 = instruction->op3->child; |
| 27030 | IrInstGen *op3 = instruction->op3->child; |
| 26054 | 27031 | if (type_is_invalid(op3->value->type)) |
| 26055 | | return ira->codegen->invalid_instruction; |
| 27032 | return ira->codegen->invalid_inst_gen; |
| 26056 | 27033 | |
| 26057 | | IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 27034 | IrInstGen *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 26058 | 27035 | if (type_is_invalid(casted_op3->value->type)) |
| 26059 | | return ira->codegen->invalid_instruction; |
| 27036 | return ira->codegen->invalid_inst_gen; |
| 26060 | 27037 | |
| 26061 | 27038 | if (instr_is_comptime(casted_op1) && |
| 26062 | 27039 | instr_is_comptime(casted_op2) && |
| 26063 | 27040 | instr_is_comptime(casted_op3)) { |
| 26064 | 27041 | ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 26065 | 27042 | if (!op1_const) |
| 26066 | | return ira->codegen->invalid_instruction; |
| 27043 | return ira->codegen->invalid_inst_gen; |
| 26067 | 27044 | ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); |
| 26068 | 27045 | if (!op2_const) |
| 26069 | | return ira->codegen->invalid_instruction; |
| 27046 | return ira->codegen->invalid_inst_gen; |
| 26070 | 27047 | ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); |
| 26071 | 27048 | if (!op3_const) |
| 26072 | | return ira->codegen->invalid_instruction; |
| 27049 | return ira->codegen->invalid_inst_gen; |
| 26073 | 27050 | |
| 26074 | | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 27051 | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 26075 | 27052 | ZigValue *out_val = result->value; |
| 26076 | 27053 | |
| 26077 | 27054 | if (expr_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -26102,63 +27079,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 26102 | 27079 | return result; |
| 26103 | 27080 | } |
| 26104 | 27081 | |
| 26105 | | IrInstruction *result = ir_build_mul_add(&ira->new_irb, |
| 26106 | | instruction->base.scope, instruction->base.source_node, |
| 26107 | | type_value, casted_op1, casted_op2, casted_op3); |
| 26108 | | result->value->type = expr_type; |
| 26109 | | return result; |
| 27082 | return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type); |
| 26110 | 27083 | } |
| 26111 | 27084 | |
| 26112 | | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { |
| 26113 | | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 27085 | static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) { |
| 27086 | IrInstGen *base_ptr = instruction->base_ptr->child; |
| 26114 | 27087 | if (type_is_invalid(base_ptr->value->type)) |
| 26115 | | return ira->codegen->invalid_instruction; |
| 27088 | return ira->codegen->invalid_inst_gen; |
| 26116 | 27089 | |
| 26117 | | IrInstruction *value; |
| 27090 | IrInstGen *value; |
| 26118 | 27091 | if (instruction->base_ptr_is_payload) { |
| 26119 | 27092 | value = base_ptr; |
| 26120 | 27093 | } else { |
| 26121 | | value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); |
| 27094 | value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr); |
| 26122 | 27095 | } |
| 26123 | 27096 | |
| 26124 | 27097 | ZigType *type_entry = value->value->type; |
| 26125 | 27098 | if (type_is_invalid(type_entry)) |
| 26126 | | return ira->codegen->invalid_instruction; |
| 27099 | return ira->codegen->invalid_inst_gen; |
| 26127 | 27100 | if (type_entry->id == ZigTypeIdErrorUnion) { |
| 26128 | 27101 | if (instr_is_comptime(value)) { |
| 26129 | 27102 | ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 26130 | 27103 | if (!err_union_val) |
| 26131 | | return ira->codegen->invalid_instruction; |
| 27104 | return ira->codegen->invalid_inst_gen; |
| 26132 | 27105 | |
| 26133 | 27106 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 26134 | 27107 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; |
| 26135 | | return ir_const_bool(ira, &instruction->base, (err != nullptr)); |
| 27108 | return ir_const_bool(ira, &instruction->base.base, (err != nullptr)); |
| 26136 | 27109 | } |
| 26137 | 27110 | } |
| 26138 | 27111 | |
| 26139 | 27112 | if (instruction->resolve_err_set) { |
| 26140 | 27113 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| 26141 | | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 26142 | | return ira->codegen->invalid_instruction; |
| 27114 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) { |
| 27115 | return ira->codegen->invalid_inst_gen; |
| 26143 | 27116 | } |
| 26144 | 27117 | if (!type_is_global_error_set(err_set_type) && |
| 26145 | 27118 | err_set_type->data.error_set.err_count == 0) |
| 26146 | 27119 | { |
| 26147 | 27120 | assert(!err_set_type->data.error_set.incomplete); |
| 26148 | | return ir_const_bool(ira, &instruction->base, false); |
| 27121 | return ir_const_bool(ira, &instruction->base.base, false); |
| 26149 | 27122 | } |
| 26150 | 27123 | } |
| 26151 | 27124 | |
| 26152 | | return ir_build_test_err_gen(ira, &instruction->base, value); |
| 27125 | return ir_build_test_err_gen(ira, &instruction->base.base, value); |
| 26153 | 27126 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 26154 | | return ir_const_bool(ira, &instruction->base, true); |
| 27127 | return ir_const_bool(ira, &instruction->base.base, true); |
| 26155 | 27128 | } else { |
| 26156 | | return ir_const_bool(ira, &instruction->base, false); |
| 27129 | return ir_const_bool(ira, &instruction->base.base, false); |
| 26157 | 27130 | } |
| 26158 | 27131 | } |
| 26159 | 27132 | |
| 26160 | | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 26161 | | IrInstruction *base_ptr, bool initializing) |
| 27133 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 27134 | IrInstGen *base_ptr, bool initializing) |
| 26162 | 27135 | { |
| 26163 | 27136 | ZigType *ptr_type = base_ptr->value->type; |
| 26164 | 27137 | |
| ... | ... | @@ -26167,12 +27140,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26167 | 27140 | |
| 26168 | 27141 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 26169 | 27142 | if (type_is_invalid(type_entry)) |
| 26170 | | return ira->codegen->invalid_instruction; |
| 27143 | return ira->codegen->invalid_inst_gen; |
| 26171 | 27144 | |
| 26172 | 27145 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 26173 | | ir_add_error(ira, base_ptr, |
| 27146 | ir_add_error(ira, &base_ptr->base, |
| 26174 | 27147 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 26175 | | return ira->codegen->invalid_instruction; |
| 27148 | return ira->codegen->invalid_inst_gen; |
| 26176 | 27149 | } |
| 26177 | 27150 | |
| 26178 | 27151 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| ... | ... | @@ -26183,13 +27156,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26183 | 27156 | if (instr_is_comptime(base_ptr)) { |
| 26184 | 27157 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 26185 | 27158 | if (!ptr_val) |
| 26186 | | return ira->codegen->invalid_instruction; |
| 27159 | return ira->codegen->invalid_inst_gen; |
| 26187 | 27160 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 26188 | 27161 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) |
| 26189 | 27162 | { |
| 26190 | 27163 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 26191 | 27164 | if (err_union_val == nullptr) |
| 26192 | | return ira->codegen->invalid_instruction; |
| 27165 | return ira->codegen->invalid_inst_gen; |
| 26193 | 27166 | |
| 26194 | 27167 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 26195 | 27168 | ZigValue *vals = create_const_vals(2); |
| ... | ... | @@ -26212,11 +27185,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26212 | 27185 | } |
| 26213 | 27186 | ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr); |
| 26214 | 27187 | |
| 26215 | | IrInstruction *result; |
| 27188 | IrInstGen *result; |
| 26216 | 27189 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26217 | | result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, |
| 26218 | | source_instr->source_node, base_ptr); |
| 26219 | | result->value->type = result_type; |
| 27190 | result = ir_build_unwrap_err_code_gen(ira, source_instr->scope, |
| 27191 | source_instr->source_node, base_ptr, result_type); |
| 26220 | 27192 | result->value->special = ConstValSpecialStatic; |
| 26221 | 27193 | } else { |
| 26222 | 27194 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -26229,23 +27201,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26229 | 27201 | } |
| 26230 | 27202 | } |
| 26231 | 27203 | |
| 26232 | | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 26233 | | source_instr->scope, source_instr->source_node, base_ptr); |
| 26234 | | result->value->type = result_type; |
| 26235 | | return result; |
| 27204 | return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type); |
| 26236 | 27205 | } |
| 26237 | 27206 | |
| 26238 | | static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 26239 | | IrInstructionUnwrapErrCode *instruction) |
| 26240 | | { |
| 26241 | | IrInstruction *base_ptr = instruction->err_union_ptr->child; |
| 27207 | static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) { |
| 27208 | IrInstGen *base_ptr = instruction->err_union_ptr->child; |
| 26242 | 27209 | if (type_is_invalid(base_ptr->value->type)) |
| 26243 | | return ira->codegen->invalid_instruction; |
| 26244 | | return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false); |
| 27210 | return ira->codegen->invalid_inst_gen; |
| 27211 | return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false); |
| 26245 | 27212 | } |
| 26246 | 27213 | |
| 26247 | | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 26248 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 27214 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 27215 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 26249 | 27216 | { |
| 26250 | 27217 | ZigType *ptr_type = base_ptr->value->type; |
| 26251 | 27218 | |
| ... | ... | @@ -26254,17 +27221,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26254 | 27221 | |
| 26255 | 27222 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 26256 | 27223 | if (type_is_invalid(type_entry)) |
| 26257 | | return ira->codegen->invalid_instruction; |
| 27224 | return ira->codegen->invalid_inst_gen; |
| 26258 | 27225 | |
| 26259 | 27226 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 26260 | | ir_add_error(ira, base_ptr, |
| 27227 | ir_add_error(ira, &base_ptr->base, |
| 26261 | 27228 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 26262 | | return ira->codegen->invalid_instruction; |
| 27229 | return ira->codegen->invalid_inst_gen; |
| 26263 | 27230 | } |
| 26264 | 27231 | |
| 26265 | 27232 | ZigType *payload_type = type_entry->data.error_union.payload_type; |
| 26266 | 27233 | if (type_is_invalid(payload_type)) |
| 26267 | | return ira->codegen->invalid_instruction; |
| 27234 | return ira->codegen->invalid_inst_gen; |
| 26268 | 27235 | |
| 26269 | 27236 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 26270 | 27237 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | ... | @@ -26273,11 +27240,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26273 | 27240 | if (instr_is_comptime(base_ptr)) { |
| 26274 | 27241 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 26275 | 27242 | if (!ptr_val) |
| 26276 | | return ira->codegen->invalid_instruction; |
| 27243 | return ira->codegen->invalid_inst_gen; |
| 26277 | 27244 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 26278 | 27245 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 26279 | 27246 | if (err_union_val == nullptr) |
| 26280 | | return ira->codegen->invalid_instruction; |
| 27247 | return ira->codegen->invalid_inst_gen; |
| 26281 | 27248 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 26282 | 27249 | ZigValue *vals = create_const_vals(2); |
| 26283 | 27250 | ZigValue *err_set_val = &vals[0]; |
| ... | ... | @@ -26300,14 +27267,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26300 | 27267 | if (err != nullptr) { |
| 26301 | 27268 | ir_add_error(ira, source_instr, |
| 26302 | 27269 | buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name))); |
| 26303 | | return ira->codegen->invalid_instruction; |
| 27270 | return ira->codegen->invalid_inst_gen; |
| 26304 | 27271 | } |
| 26305 | 27272 | |
| 26306 | | IrInstruction *result; |
| 27273 | IrInstGen *result; |
| 26307 | 27274 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26308 | | result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 26309 | | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 26310 | | result->value->type = result_type; |
| 27275 | result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope, |
| 27276 | source_instr->source_node, base_ptr, safety_check_on, initializing, result_type); |
| 26311 | 27277 | result->value->special = ConstValSpecialStatic; |
| 26312 | 27278 | } else { |
| 26313 | 27279 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -26320,28 +27286,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26320 | 27286 | } |
| 26321 | 27287 | } |
| 26322 | 27288 | |
| 26323 | | IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 26324 | | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 26325 | | result->value->type = result_type; |
| 26326 | | return result; |
| 27289 | return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node, |
| 27290 | base_ptr, safety_check_on, initializing, result_type); |
| 26327 | 27291 | } |
| 26328 | 27292 | |
| 26329 | | static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 26330 | | IrInstructionUnwrapErrPayload *instruction) |
| 27293 | static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 27294 | IrInstSrcUnwrapErrPayload *instruction) |
| 26331 | 27295 | { |
| 26332 | 27296 | assert(instruction->value->child); |
| 26333 | | IrInstruction *value = instruction->value->child; |
| 27297 | IrInstGen *value = instruction->value->child; |
| 26334 | 27298 | if (type_is_invalid(value->value->type)) |
| 26335 | | return ira->codegen->invalid_instruction; |
| 27299 | return ira->codegen->invalid_inst_gen; |
| 26336 | 27300 | |
| 26337 | | return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false); |
| 27301 | return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false); |
| 26338 | 27302 | } |
| 26339 | 27303 | |
| 26340 | | static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| 26341 | | AstNode *proto_node = instruction->base.source_node; |
| 27304 | static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) { |
| 27305 | AstNode *proto_node = instruction->base.base.source_node; |
| 26342 | 27306 | assert(proto_node->type == NodeTypeFnProto); |
| 26343 | 27307 | |
| 26344 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 27308 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 26345 | 27309 | result->value->special = ConstValSpecialLazy; |
| 26346 | 27310 | |
| 26347 | 27311 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType"); |
| ... | ... | @@ -26350,29 +27314,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 26350 | 27314 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 26351 | 27315 | |
| 26352 | 27316 | if (proto_node->data.fn_proto.auto_err_set) { |
| 26353 | | ir_add_error(ira, &instruction->base, |
| 27317 | ir_add_error(ira, &instruction->base.base, |
| 26354 | 27318 | buf_sprintf("inferring error set of return type valid only for function definitions")); |
| 26355 | | return ira->codegen->invalid_instruction; |
| 27319 | return ira->codegen->invalid_inst_gen; |
| 26356 | 27320 | } |
| 26357 | 27321 | |
| 26358 | 27322 | lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto); |
| 26359 | 27323 | if (instruction->callconv_value != nullptr) { |
| 26360 | 27324 | ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention"); |
| 26361 | 27325 | |
| 26362 | | IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type); |
| 27326 | IrInstGen *casted_value = ir_implicit_cast(ira, instruction->callconv_value->child, cc_enum_type); |
| 26363 | 27327 | if (type_is_invalid(casted_value->value->type)) |
| 26364 | | return ira->codegen->invalid_instruction; |
| 27328 | return ira->codegen->invalid_inst_gen; |
| 26365 | 27329 | |
| 26366 | 27330 | ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad); |
| 26367 | 27331 | if (const_value == nullptr) |
| 26368 | | return ira->codegen->invalid_instruction; |
| 27332 | return ira->codegen->invalid_inst_gen; |
| 26369 | 27333 | |
| 26370 | 27334 | lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag); |
| 26371 | 27335 | } |
| 26372 | 27336 | |
| 26373 | 27337 | size_t param_count = proto_node->data.fn_proto.params.length; |
| 26374 | 27338 | lazy_fn_type->proto_node = proto_node; |
| 26375 | | lazy_fn_type->param_types = allocate<IrInstruction *>(param_count); |
| 27339 | lazy_fn_type->param_types = allocate<IrInstGen *>(param_count); |
| 26376 | 27340 | |
| 26377 | 27341 | for (size_t param_index = 0; param_index < param_count; param_index += 1) { |
| 26378 | 27342 | AstNode *param_node = proto_node->data.fn_proto.params.at(param_index); |
| ... | ... | @@ -26397,63 +27361,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 26397 | 27361 | return result; |
| 26398 | 27362 | } |
| 26399 | 27363 | |
| 26400 | | IrInstruction *param_type_value = instruction->param_types[param_index]->child; |
| 27364 | IrInstGen *param_type_value = instruction->param_types[param_index]->child; |
| 26401 | 27365 | if (type_is_invalid(param_type_value->value->type)) |
| 26402 | | return ira->codegen->invalid_instruction; |
| 27366 | return ira->codegen->invalid_inst_gen; |
| 26403 | 27367 | if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr) |
| 26404 | | return ira->codegen->invalid_instruction; |
| 27368 | return ira->codegen->invalid_inst_gen; |
| 26405 | 27369 | lazy_fn_type->param_types[param_index] = param_type_value; |
| 26406 | 27370 | } |
| 26407 | 27371 | |
| 26408 | 27372 | if (instruction->align_value != nullptr) { |
| 26409 | 27373 | lazy_fn_type->align_inst = instruction->align_value->child; |
| 26410 | 27374 | if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr) |
| 26411 | | return ira->codegen->invalid_instruction; |
| 27375 | return ira->codegen->invalid_inst_gen; |
| 26412 | 27376 | } |
| 26413 | 27377 | |
| 26414 | 27378 | lazy_fn_type->return_type = instruction->return_type->child; |
| 26415 | 27379 | if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr) |
| 26416 | | return ira->codegen->invalid_instruction; |
| 27380 | return ira->codegen->invalid_inst_gen; |
| 26417 | 27381 | |
| 26418 | 27382 | return result; |
| 26419 | 27383 | } |
| 26420 | 27384 | |
| 26421 | | static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 26422 | | IrInstruction *value = instruction->value->child; |
| 27385 | static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) { |
| 27386 | IrInstGen *value = instruction->value->child; |
| 26423 | 27387 | if (type_is_invalid(value->value->type)) |
| 26424 | | return ira->codegen->invalid_instruction; |
| 27388 | return ira->codegen->invalid_inst_gen; |
| 26425 | 27389 | |
| 26426 | | return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); |
| 27390 | return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value)); |
| 26427 | 27391 | } |
| 26428 | 27392 | |
| 26429 | | static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26430 | | IrInstructionCheckSwitchProngs *instruction) |
| 27393 | static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 27394 | IrInstSrcCheckSwitchProngs *instruction) |
| 26431 | 27395 | { |
| 26432 | | IrInstruction *target_value = instruction->target_value->child; |
| 27396 | IrInstGen *target_value = instruction->target_value->child; |
| 26433 | 27397 | ZigType *switch_type = target_value->value->type; |
| 26434 | 27398 | if (type_is_invalid(switch_type)) |
| 26435 | | return ira->codegen->invalid_instruction; |
| 27399 | return ira->codegen->invalid_inst_gen; |
| 26436 | 27400 | |
| 26437 | 27401 | if (switch_type->id == ZigTypeIdEnum) { |
| 26438 | 27402 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; |
| 26439 | 27403 | field_prev_uses.init(switch_type->data.enumeration.src_field_count); |
| 26440 | 27404 | |
| 26441 | 27405 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26442 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27406 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26443 | 27407 | |
| 26444 | | IrInstruction *start_value_uncasted = range->start->child; |
| 27408 | IrInstGen *start_value_uncasted = range->start->child; |
| 26445 | 27409 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 26446 | | return ira->codegen->invalid_instruction; |
| 26447 | | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 27410 | return ira->codegen->invalid_inst_gen; |
| 27411 | IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 26448 | 27412 | if (type_is_invalid(start_value->value->type)) |
| 26449 | | return ira->codegen->invalid_instruction; |
| 27413 | return ira->codegen->invalid_inst_gen; |
| 26450 | 27414 | |
| 26451 | | IrInstruction *end_value_uncasted = range->end->child; |
| 27415 | IrInstGen *end_value_uncasted = range->end->child; |
| 26452 | 27416 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 26453 | | return ira->codegen->invalid_instruction; |
| 26454 | | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 27417 | return ira->codegen->invalid_inst_gen; |
| 27418 | IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 26455 | 27419 | if (type_is_invalid(end_value->value->type)) |
| 26456 | | return ira->codegen->invalid_instruction; |
| 27420 | return ira->codegen->invalid_inst_gen; |
| 26457 | 27421 | |
| 26458 | 27422 | assert(start_value->value->type->id == ZigTypeIdEnum); |
| 26459 | 27423 | BigInt start_index; |
| ... | ... | @@ -26464,7 +27428,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26464 | 27428 | bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); |
| 26465 | 27429 | |
| 26466 | 27430 | if (bigint_cmp(&start_index, &end_index) == CmpGT) { |
| 26467 | | ir_add_error(ira, start_value, |
| 27431 | ir_add_error(ira, &start_value->base, |
| 26468 | 27432 | buf_sprintf("range start value is greater than the end value")); |
| 26469 | 27433 | } |
| 26470 | 27434 | |
| ... | ... | @@ -26475,12 +27439,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26475 | 27439 | if (cmp == CmpGT) { |
| 26476 | 27440 | break; |
| 26477 | 27441 | } |
| 26478 | | auto entry = field_prev_uses.put_unique(field_index, start_value->source_node); |
| 27442 | auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node); |
| 26479 | 27443 | if (entry) { |
| 26480 | 27444 | AstNode *prev_node = entry->value; |
| 26481 | 27445 | TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index); |
| 26482 | 27446 | assert(enum_field != nullptr); |
| 26483 | | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 27447 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 26484 | 27448 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), |
| 26485 | 27449 | buf_ptr(enum_field->name))); |
| 26486 | 27450 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); |
| ... | ... | @@ -26490,7 +27454,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26490 | 27454 | } |
| 26491 | 27455 | if (instruction->have_underscore_prong) { |
| 26492 | 27456 | if (!switch_type->data.enumeration.non_exhaustive){ |
| 26493 | | ir_add_error(ira, &instruction->base, |
| 27457 | ir_add_error(ira, &instruction->base.base, |
| 26494 | 27458 | buf_sprintf("switch on non-exhaustive enum has `_` prong")); |
| 26495 | 27459 | } |
| 26496 | 27460 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -26500,14 +27464,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26500 | 27464 | |
| 26501 | 27465 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 26502 | 27466 | if (!entry) { |
| 26503 | | ir_add_error(ira, &instruction->base, |
| 27467 | ir_add_error(ira, &instruction->base.base, |
| 26504 | 27468 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 26505 | 27469 | buf_ptr(enum_field->name))); |
| 26506 | 27470 | } |
| 26507 | 27471 | } |
| 26508 | 27472 | } else if (!instruction->have_else_prong) { |
| 26509 | 27473 | if (switch_type->data.enumeration.non_exhaustive) { |
| 26510 | | ir_add_error(ira, &instruction->base, |
| 27474 | ir_add_error(ira, &instruction->base.base, |
| 26511 | 27475 | buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong")); |
| 26512 | 27476 | } |
| 26513 | 27477 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -26515,69 +27479,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26515 | 27479 | |
| 26516 | 27480 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 26517 | 27481 | if (!entry) { |
| 26518 | | ir_add_error(ira, &instruction->base, |
| 27482 | ir_add_error(ira, &instruction->base.base, |
| 26519 | 27483 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 26520 | 27484 | buf_ptr(enum_field->name))); |
| 26521 | 27485 | } |
| 26522 | 27486 | } |
| 26523 | 27487 | } |
| 26524 | 27488 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 26525 | | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 26526 | | return ira->codegen->invalid_instruction; |
| 27489 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) { |
| 27490 | return ira->codegen->invalid_inst_gen; |
| 26527 | 27491 | } |
| 26528 | 27492 | |
| 26529 | 27493 | size_t field_prev_uses_count = ira->codegen->errors_by_index.length; |
| 26530 | 27494 | AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *"); |
| 26531 | 27495 | |
| 26532 | 27496 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26533 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27497 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26534 | 27498 | |
| 26535 | | IrInstruction *start_value_uncasted = range->start->child; |
| 27499 | IrInstGen *start_value_uncasted = range->start->child; |
| 26536 | 27500 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 26537 | | return ira->codegen->invalid_instruction; |
| 26538 | | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 27501 | return ira->codegen->invalid_inst_gen; |
| 27502 | IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 26539 | 27503 | if (type_is_invalid(start_value->value->type)) |
| 26540 | | return ira->codegen->invalid_instruction; |
| 27504 | return ira->codegen->invalid_inst_gen; |
| 26541 | 27505 | |
| 26542 | | IrInstruction *end_value_uncasted = range->end->child; |
| 27506 | IrInstGen *end_value_uncasted = range->end->child; |
| 26543 | 27507 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 26544 | | return ira->codegen->invalid_instruction; |
| 26545 | | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 27508 | return ira->codegen->invalid_inst_gen; |
| 27509 | IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 26546 | 27510 | if (type_is_invalid(end_value->value->type)) |
| 26547 | | return ira->codegen->invalid_instruction; |
| 27511 | return ira->codegen->invalid_inst_gen; |
| 26548 | 27512 | |
| 26549 | | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 27513 | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 26550 | 27514 | uint32_t start_index = start_value->value->data.x_err_set->value; |
| 26551 | 27515 | |
| 26552 | | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 27516 | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 26553 | 27517 | uint32_t end_index = end_value->value->data.x_err_set->value; |
| 26554 | 27518 | |
| 26555 | 27519 | if (start_index != end_index) { |
| 26556 | | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| 26557 | | return ira->codegen->invalid_instruction; |
| 27520 | ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors")); |
| 27521 | return ira->codegen->invalid_inst_gen; |
| 26558 | 27522 | } |
| 26559 | 27523 | |
| 26560 | 27524 | AstNode *prev_node = field_prev_uses[start_index]; |
| 26561 | 27525 | if (prev_node != nullptr) { |
| 26562 | 27526 | Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name; |
| 26563 | | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 27527 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 26564 | 27528 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name))); |
| 26565 | 27529 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); |
| 26566 | 27530 | } |
| 26567 | | field_prev_uses[start_index] = start_value->source_node; |
| 27531 | field_prev_uses[start_index] = start_value->base.source_node; |
| 26568 | 27532 | } |
| 26569 | 27533 | if (!instruction->have_else_prong) { |
| 26570 | 27534 | if (type_is_global_error_set(switch_type)) { |
| 26571 | | ir_add_error(ira, &instruction->base, |
| 27535 | ir_add_error(ira, &instruction->base.base, |
| 26572 | 27536 | buf_sprintf("else prong required when switching on type 'anyerror'")); |
| 26573 | | return ira->codegen->invalid_instruction; |
| 27537 | return ira->codegen->invalid_inst_gen; |
| 26574 | 27538 | } else { |
| 26575 | 27539 | for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) { |
| 26576 | 27540 | ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i]; |
| 26577 | 27541 | |
| 26578 | 27542 | AstNode *prev_node = field_prev_uses[err_entry->value]; |
| 26579 | 27543 | if (prev_node == nullptr) { |
| 26580 | | ir_add_error(ira, &instruction->base, |
| 27544 | ir_add_error(ira, &instruction->base.base, |
| 26581 | 27545 | buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name))); |
| 26582 | 27546 | } |
| 26583 | 27547 | } |
| ... | ... | @@ -26588,44 +27552,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26588 | 27552 | } else if (switch_type->id == ZigTypeIdInt) { |
| 26589 | 27553 | RangeSet rs = {0}; |
| 26590 | 27554 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26591 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27555 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26592 | 27556 | |
| 26593 | | IrInstruction *start_value = range->start->child; |
| 27557 | IrInstGen *start_value = range->start->child; |
| 26594 | 27558 | if (type_is_invalid(start_value->value->type)) |
| 26595 | | return ira->codegen->invalid_instruction; |
| 26596 | | IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 27559 | return ira->codegen->invalid_inst_gen; |
| 27560 | IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 26597 | 27561 | if (type_is_invalid(casted_start_value->value->type)) |
| 26598 | | return ira->codegen->invalid_instruction; |
| 27562 | return ira->codegen->invalid_inst_gen; |
| 26599 | 27563 | |
| 26600 | | IrInstruction *end_value = range->end->child; |
| 27564 | IrInstGen *end_value = range->end->child; |
| 26601 | 27565 | if (type_is_invalid(end_value->value->type)) |
| 26602 | | return ira->codegen->invalid_instruction; |
| 26603 | | IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 27566 | return ira->codegen->invalid_inst_gen; |
| 27567 | IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 26604 | 27568 | if (type_is_invalid(casted_end_value->value->type)) |
| 26605 | | return ira->codegen->invalid_instruction; |
| 27569 | return ira->codegen->invalid_inst_gen; |
| 26606 | 27570 | |
| 26607 | 27571 | ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| 26608 | 27572 | if (!start_val) |
| 26609 | | return ira->codegen->invalid_instruction; |
| 27573 | return ira->codegen->invalid_inst_gen; |
| 26610 | 27574 | |
| 26611 | 27575 | ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); |
| 26612 | 27576 | if (!end_val) |
| 26613 | | return ira->codegen->invalid_instruction; |
| 27577 | return ira->codegen->invalid_inst_gen; |
| 26614 | 27578 | |
| 26615 | 27579 | assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); |
| 26616 | 27580 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| 26617 | 27581 | |
| 26618 | 27582 | if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) { |
| 26619 | | ir_add_error(ira, start_value, |
| 27583 | ir_add_error(ira, &start_value->base, |
| 26620 | 27584 | buf_sprintf("range start value is greater than the end value")); |
| 26621 | 27585 | } |
| 26622 | 27586 | |
| 26623 | 27587 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, |
| 26624 | | start_value->source_node); |
| 27588 | start_value->base.source_node); |
| 26625 | 27589 | if (prev_node != nullptr) { |
| 26626 | | ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value")); |
| 27590 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value")); |
| 26627 | 27591 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here")); |
| 26628 | | return ira->codegen->invalid_instruction; |
| 27592 | return ira->codegen->invalid_inst_gen; |
| 26629 | 27593 | } |
| 26630 | 27594 | } |
| 26631 | 27595 | if (!instruction->have_else_prong) { |
| ... | ... | @@ -26634,25 +27598,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26634 | 27598 | BigInt max_val; |
| 26635 | 27599 | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 26636 | 27600 | if (!rangeset_spans(&rs, &min_val, &max_val)) { |
| 26637 | | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 26638 | | return ira->codegen->invalid_instruction; |
| 27601 | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 27602 | return ira->codegen->invalid_inst_gen; |
| 26639 | 27603 | } |
| 26640 | 27604 | } |
| 26641 | 27605 | } else if (switch_type->id == ZigTypeIdBool) { |
| 26642 | 27606 | int seenTrue = 0; |
| 26643 | 27607 | int seenFalse = 0; |
| 26644 | 27608 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26645 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27609 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26646 | 27610 | |
| 26647 | | IrInstruction *value = range->start->child; |
| 27611 | IrInstGen *value = range->start->child; |
| 26648 | 27612 | |
| 26649 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 27613 | IrInstGen *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 26650 | 27614 | if (type_is_invalid(casted_value->value->type)) |
| 26651 | | return ira->codegen->invalid_instruction; |
| 27615 | return ira->codegen->invalid_inst_gen; |
| 26652 | 27616 | |
| 26653 | 27617 | ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 26654 | 27618 | if (!const_expr_val) |
| 26655 | | return ira->codegen->invalid_instruction; |
| 27619 | return ira->codegen->invalid_inst_gen; |
| 26656 | 27620 | |
| 26657 | 27621 | assert(const_expr_val->type->id == ZigTypeIdBool); |
| 26658 | 27622 | |
| ... | ... | @@ -26663,60 +27627,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26663 | 27627 | } |
| 26664 | 27628 | |
| 26665 | 27629 | if ((seenTrue > 1) || (seenFalse > 1)) { |
| 26666 | | ir_add_error(ira, value, buf_sprintf("duplicate switch value")); |
| 26667 | | return ira->codegen->invalid_instruction; |
| 27630 | ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value")); |
| 27631 | return ira->codegen->invalid_inst_gen; |
| 26668 | 27632 | } |
| 26669 | 27633 | } |
| 26670 | 27634 | if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) { |
| 26671 | | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 26672 | | return ira->codegen->invalid_instruction; |
| 27635 | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 27636 | return ira->codegen->invalid_inst_gen; |
| 26673 | 27637 | } |
| 26674 | 27638 | } else if (!instruction->have_else_prong) { |
| 26675 | | ir_add_error(ira, &instruction->base, |
| 27639 | ir_add_error(ira, &instruction->base.base, |
| 26676 | 27640 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |
| 26677 | | return ira->codegen->invalid_instruction; |
| 27641 | return ira->codegen->invalid_inst_gen; |
| 26678 | 27642 | } |
| 26679 | | return ir_const_void(ira, &instruction->base); |
| 27643 | return ir_const_void(ira, &instruction->base.base); |
| 26680 | 27644 | } |
| 26681 | 27645 | |
| 26682 | | static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 26683 | | IrInstructionCheckStatementIsVoid *instruction) |
| 27646 | static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 27647 | IrInstSrcCheckStatementIsVoid *instruction) |
| 26684 | 27648 | { |
| 26685 | | IrInstruction *statement_value = instruction->statement_value->child; |
| 27649 | IrInstGen *statement_value = instruction->statement_value->child; |
| 26686 | 27650 | ZigType *statement_type = statement_value->value->type; |
| 26687 | 27651 | if (type_is_invalid(statement_type)) |
| 26688 | | return ira->codegen->invalid_instruction; |
| 27652 | return ira->codegen->invalid_inst_gen; |
| 26689 | 27653 | |
| 26690 | 27654 | if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { |
| 26691 | | ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); |
| 27655 | ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); |
| 26692 | 27656 | } |
| 26693 | 27657 | |
| 26694 | | return ir_const_void(ira, &instruction->base); |
| 27658 | return ir_const_void(ira, &instruction->base.base); |
| 26695 | 27659 | } |
| 26696 | 27660 | |
| 26697 | | static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 26698 | | IrInstruction *msg = instruction->msg->child; |
| 27661 | static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) { |
| 27662 | IrInstGen *msg = instruction->msg->child; |
| 26699 | 27663 | if (type_is_invalid(msg->value->type)) |
| 26700 | 27664 | return ir_unreach_error(ira); |
| 26701 | 27665 | |
| 26702 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) { |
| 26703 | | ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time")); |
| 27666 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) { |
| 27667 | ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time")); |
| 26704 | 27668 | return ir_unreach_error(ira); |
| 26705 | 27669 | } |
| 26706 | 27670 | |
| 26707 | 27671 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 26708 | 27672 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 26709 | 27673 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 26710 | | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 27674 | IrInstGen *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 26711 | 27675 | if (type_is_invalid(casted_msg->value->type)) |
| 26712 | 27676 | return ir_unreach_error(ira); |
| 26713 | 27677 | |
| 26714 | | IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, |
| 26715 | | instruction->base.source_node, casted_msg); |
| 27678 | IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg); |
| 26716 | 27679 | return ir_finish_anal(ira, new_instruction); |
| 26717 | 27680 | } |
| 26718 | 27681 | |
| 26719 | | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 27682 | static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t align_bytes, bool safety_check_on) { |
| 26720 | 27683 | Error err; |
| 26721 | 27684 | |
| 26722 | 27685 | ZigType *target_type = target->value->type; |
| ... | ... | @@ -26728,7 +27691,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26728 | 27691 | if (target_type->id == ZigTypeIdPointer) { |
| 26729 | 27692 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); |
| 26730 | 27693 | if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes))) |
| 26731 | | return ira->codegen->invalid_instruction; |
| 27694 | return ira->codegen->invalid_inst_gen; |
| 26732 | 27695 | } else if (target_type->id == ZigTypeIdFn) { |
| 26733 | 27696 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 26734 | 27697 | old_align_bytes = fn_type_id.alignment; |
| ... | ... | @@ -26739,7 +27702,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26739 | 27702 | { |
| 26740 | 27703 | ZigType *ptr_type = target_type->data.maybe.child_type; |
| 26741 | 27704 | if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes))) |
| 26742 | | return ira->codegen->invalid_instruction; |
| 27705 | return ira->codegen->invalid_inst_gen; |
| 26743 | 27706 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); |
| 26744 | 27707 | |
| 26745 | 27708 | result_type = get_optional_type(ira->codegen, better_ptr_type); |
| ... | ... | @@ -26754,47 +27717,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26754 | 27717 | } else if (is_slice(target_type)) { |
| 26755 | 27718 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26756 | 27719 | if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes))) |
| 26757 | | return ira->codegen->invalid_instruction; |
| 27720 | return ira->codegen->invalid_inst_gen; |
| 26758 | 27721 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 26759 | 27722 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 26760 | 27723 | } else { |
| 26761 | | ir_add_error(ira, target, |
| 27724 | ir_add_error(ira, &target->base, |
| 26762 | 27725 | buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name))); |
| 26763 | | return ira->codegen->invalid_instruction; |
| 27726 | return ira->codegen->invalid_inst_gen; |
| 26764 | 27727 | } |
| 26765 | 27728 | |
| 26766 | 27729 | if (instr_is_comptime(target)) { |
| 26767 | 27730 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 26768 | 27731 | if (!val) |
| 26769 | | return ira->codegen->invalid_instruction; |
| 27732 | return ira->codegen->invalid_inst_gen; |
| 26770 | 27733 | |
| 26771 | 27734 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 26772 | 27735 | val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0) |
| 26773 | 27736 | { |
| 26774 | | ir_add_error(ira, target, |
| 27737 | ir_add_error(ira, &target->base, |
| 26775 | 27738 | buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes", |
| 26776 | 27739 | val->data.x_ptr.data.hard_coded_addr.addr, align_bytes)); |
| 26777 | | return ira->codegen->invalid_instruction; |
| 27740 | return ira->codegen->invalid_inst_gen; |
| 26778 | 27741 | } |
| 26779 | 27742 | |
| 26780 | | IrInstruction *result = ir_const(ira, target, result_type); |
| 27743 | IrInstGen *result = ir_const(ira, &target->base, result_type); |
| 26781 | 27744 | copy_const_val(result->value, val); |
| 26782 | 27745 | result->value->type = result_type; |
| 26783 | 27746 | return result; |
| 26784 | 27747 | } |
| 26785 | 27748 | |
| 26786 | | IrInstruction *result; |
| 26787 | 27749 | if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) { |
| 26788 | | result = ir_build_align_cast(&ira->new_irb, target->scope, target->source_node, nullptr, target); |
| 27750 | return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type); |
| 26789 | 27751 | } else { |
| 26790 | | result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop); |
| 27752 | return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop); |
| 26791 | 27753 | } |
| 26792 | | result->value->type = result_type; |
| 26793 | | return result; |
| 26794 | 27754 | } |
| 26795 | 27755 | |
| 26796 | | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 26797 | | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on) |
| 27756 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 27757 | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) |
| 26798 | 27758 | { |
| 26799 | 27759 | Error err; |
| 26800 | 27760 | |
| ... | ... | @@ -26810,52 +27770,52 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26810 | 27770 | |
| 26811 | 27771 | ZigType *src_ptr_type = get_src_ptr_type(src_type); |
| 26812 | 27772 | if (src_ptr_type == nullptr) { |
| 26813 | | ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 26814 | | return ira->codegen->invalid_instruction; |
| 27773 | ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 27774 | return ira->codegen->invalid_inst_gen; |
| 26815 | 27775 | } |
| 26816 | 27776 | |
| 26817 | 27777 | ZigType *dest_ptr_type = get_src_ptr_type(dest_type); |
| 26818 | 27778 | if (dest_ptr_type == nullptr) { |
| 26819 | 27779 | ir_add_error(ira, dest_type_src, |
| 26820 | 27780 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 26821 | | return ira->codegen->invalid_instruction; |
| 27781 | return ira->codegen->invalid_inst_gen; |
| 26822 | 27782 | } |
| 26823 | 27783 | |
| 26824 | 27784 | if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) { |
| 26825 | 27785 | ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier")); |
| 26826 | | return ira->codegen->invalid_instruction; |
| 27786 | return ira->codegen->invalid_inst_gen; |
| 26827 | 27787 | } |
| 26828 | 27788 | uint32_t src_align_bytes; |
| 26829 | 27789 | if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes))) |
| 26830 | | return ira->codegen->invalid_instruction; |
| 27790 | return ira->codegen->invalid_inst_gen; |
| 26831 | 27791 | |
| 26832 | 27792 | uint32_t dest_align_bytes; |
| 26833 | 27793 | if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes))) |
| 26834 | | return ira->codegen->invalid_instruction; |
| 27794 | return ira->codegen->invalid_inst_gen; |
| 26835 | 27795 | |
| 26836 | 27796 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 26837 | | return ira->codegen->invalid_instruction; |
| 27797 | return ira->codegen->invalid_inst_gen; |
| 26838 | 27798 | |
| 26839 | 27799 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown))) |
| 26840 | | return ira->codegen->invalid_instruction; |
| 27800 | return ira->codegen->invalid_inst_gen; |
| 26841 | 27801 | |
| 26842 | | if (type_has_bits(dest_type) && !type_has_bits(src_type)) { |
| 27802 | if (type_has_bits(dest_type) && !type_has_bits(src_type) && safety_check_on) { |
| 26843 | 27803 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 26844 | 27804 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", |
| 26845 | 27805 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 26846 | | add_error_note(ira->codegen, msg, ptr->source_node, |
| 27806 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 26847 | 27807 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); |
| 26848 | 27808 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 26849 | 27809 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); |
| 26850 | | return ira->codegen->invalid_instruction; |
| 27810 | return ira->codegen->invalid_inst_gen; |
| 26851 | 27811 | } |
| 26852 | 27812 | |
| 26853 | 27813 | if (instr_is_comptime(ptr)) { |
| 26854 | 27814 | bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type); |
| 26855 | 27815 | UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; |
| 26856 | 27816 | ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); |
| 26857 | | if (!val) |
| 26858 | | return ira->codegen->invalid_instruction; |
| 27817 | if (val == nullptr) |
| 27818 | return ira->codegen->invalid_inst_gen; |
| 26859 | 27819 | |
| 26860 | 27820 | if (value_is_comptime(val) && val->special != ConstValSpecialUndef) { |
| 26861 | 27821 | bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull || |
| ... | ... | @@ -26864,20 +27824,36 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26864 | 27824 | if (is_addr_zero && !dest_allows_addr_zero) { |
| 26865 | 27825 | ir_add_error(ira, source_instr, |
| 26866 | 27826 | buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name))); |
| 26867 | | return ira->codegen->invalid_instruction; |
| 27827 | return ira->codegen->invalid_inst_gen; |
| 26868 | 27828 | } |
| 26869 | 27829 | } |
| 26870 | 27830 | |
| 26871 | | IrInstruction *result; |
| 26872 | | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 27831 | IrInstGen *result; |
| 27832 | if (val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26873 | 27833 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 26874 | | |
| 26875 | | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 26876 | | return ira->codegen->invalid_instruction; |
| 26877 | 27834 | } else { |
| 26878 | 27835 | result = ir_const(ira, source_instr, dest_type); |
| 26879 | 27836 | } |
| 26880 | | copy_const_val(result->value, val); |
| 27837 | InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ? |
| 27838 | val->type->data.pointer.inferred_struct_field : nullptr; |
| 27839 | if (isf == nullptr) { |
| 27840 | copy_const_val(result->value, val); |
| 27841 | } else { |
| 27842 | // The destination value should have x_ptr struct pointing to underlying struct value |
| 27843 | result->value->data.x_ptr.mut = val->data.x_ptr.mut; |
| 27844 | TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| 27845 | assert(field != nullptr); |
| 27846 | if (field->is_comptime) { |
| 27847 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 27848 | result->value->data.x_ptr.data.ref.pointee = field->init_val; |
| 27849 | } else { |
| 27850 | assert(val->data.x_ptr.special == ConstPtrSpecialRef); |
| 27851 | result->value->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| 27852 | result->value->data.x_ptr.data.base_struct.struct_val = val->data.x_ptr.data.ref.pointee; |
| 27853 | result->value->data.x_ptr.data.base_struct.field_index = field->src_index; |
| 27854 | } |
| 27855 | result->value->special = ConstValSpecialStatic; |
| 27856 | } |
| 26881 | 27857 | result->value->type = dest_type; |
| 26882 | 27858 | |
| 26883 | 27859 | // Keep the bigger alignment, it can only help- |
| ... | ... | @@ -26891,41 +27867,41 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26891 | 27867 | |
| 26892 | 27868 | if (dest_align_bytes > src_align_bytes) { |
| 26893 | 27869 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 26894 | | add_error_note(ira->codegen, msg, ptr->source_node, |
| 27870 | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 26895 | 27871 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); |
| 26896 | 27872 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 26897 | 27873 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); |
| 26898 | | return ira->codegen->invalid_instruction; |
| 27874 | return ira->codegen->invalid_inst_gen; |
| 26899 | 27875 | } |
| 26900 | 27876 | |
| 26901 | | IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 27877 | IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 26902 | 27878 | |
| 26903 | 27879 | // Keep the bigger alignment, it can only help- |
| 26904 | 27880 | // unless the target is zero bits. |
| 26905 | | IrInstruction *result; |
| 27881 | IrInstGen *result; |
| 26906 | 27882 | if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { |
| 26907 | 27883 | result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); |
| 26908 | 27884 | if (type_is_invalid(result->value->type)) |
| 26909 | | return ira->codegen->invalid_instruction; |
| 27885 | return ira->codegen->invalid_inst_gen; |
| 26910 | 27886 | } else { |
| 26911 | 27887 | result = casted_ptr; |
| 26912 | 27888 | } |
| 26913 | 27889 | return result; |
| 26914 | 27890 | } |
| 26915 | 27891 | |
| 26916 | | static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) { |
| 26917 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 27892 | static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) { |
| 27893 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 26918 | 27894 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 26919 | 27895 | if (type_is_invalid(dest_type)) |
| 26920 | | return ira->codegen->invalid_instruction; |
| 27896 | return ira->codegen->invalid_inst_gen; |
| 26921 | 27897 | |
| 26922 | | IrInstruction *ptr = instruction->ptr->child; |
| 27898 | IrInstGen *ptr = instruction->ptr->child; |
| 26923 | 27899 | ZigType *src_type = ptr->value->type; |
| 26924 | 27900 | if (type_is_invalid(src_type)) |
| 26925 | | return ira->codegen->invalid_instruction; |
| 27901 | return ira->codegen->invalid_inst_gen; |
| 26926 | 27902 | |
| 26927 | | return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value, |
| 26928 | | instruction->safety_check_on); |
| 27903 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base, |
| 27904 | dest_type, &dest_type_value->base, instruction->safety_check_on); |
| 26929 | 27905 | } |
| 26930 | 27906 | |
| 26931 | 27907 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { |
| ... | ... | @@ -27255,7 +28231,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 27255 | 28231 | zig_unreachable(); |
| 27256 | 28232 | } |
| 27257 | 28233 | |
| 27258 | | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 28234 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 27259 | 28235 | ZigType *dest_type) |
| 27260 | 28236 | { |
| 27261 | 28237 | Error err; |
| ... | ... | @@ -27271,14 +28247,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27271 | 28247 | buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name))); |
| 27272 | 28248 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 27273 | 28249 | buf_sprintf("use @intToEnum for type coercion")); |
| 27274 | | return ira->codegen->invalid_instruction; |
| 28250 | return ira->codegen->invalid_inst_gen; |
| 27275 | 28251 | } |
| 27276 | 28252 | |
| 27277 | 28253 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown))) |
| 27278 | | return ira->codegen->invalid_instruction; |
| 28254 | return ira->codegen->invalid_inst_gen; |
| 27279 | 28255 | |
| 27280 | 28256 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown))) |
| 27281 | | return ira->codegen->invalid_instruction; |
| 28257 | return ira->codegen->invalid_inst_gen; |
| 27282 | 28258 | |
| 27283 | 28259 | uint64_t dest_size_bytes = type_size(ira->codegen, dest_type); |
| 27284 | 28260 | uint64_t src_size_bytes = type_size(ira->codegen, src_type); |
| ... | ... | @@ -27287,7 +28263,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27287 | 28263 | buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64, |
| 27288 | 28264 | buf_ptr(&dest_type->name), dest_size_bytes, |
| 27289 | 28265 | buf_ptr(&src_type->name), src_size_bytes)); |
| 27290 | | return ira->codegen->invalid_instruction; |
| 28266 | return ira->codegen->invalid_inst_gen; |
| 27291 | 28267 | } |
| 27292 | 28268 | |
| 27293 | 28269 | uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type); |
| ... | ... | @@ -27297,26 +28273,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27297 | 28273 | buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits", |
| 27298 | 28274 | buf_ptr(&dest_type->name), dest_size_bits, |
| 27299 | 28275 | buf_ptr(&src_type->name), src_size_bits)); |
| 27300 | | return ira->codegen->invalid_instruction; |
| 28276 | return ira->codegen->invalid_inst_gen; |
| 27301 | 28277 | } |
| 27302 | 28278 | |
| 27303 | 28279 | if (instr_is_comptime(value)) { |
| 27304 | 28280 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 27305 | 28281 | if (!val) |
| 27306 | | return ira->codegen->invalid_instruction; |
| 28282 | return ira->codegen->invalid_inst_gen; |
| 27307 | 28283 | |
| 27308 | | IrInstruction *result = ir_const(ira, source_instr, dest_type); |
| 28284 | IrInstGen *result = ir_const(ira, source_instr, dest_type); |
| 27309 | 28285 | uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); |
| 27310 | 28286 | buf_write_value_bytes(ira->codegen, buf, val); |
| 27311 | 28287 | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) |
| 27312 | | return ira->codegen->invalid_instruction; |
| 28288 | return ira->codegen->invalid_inst_gen; |
| 27313 | 28289 | return result; |
| 27314 | 28290 | } |
| 27315 | 28291 | |
| 27316 | 28292 | return ir_build_bit_cast_gen(ira, source_instr, value, dest_type); |
| 27317 | 28293 | } |
| 27318 | 28294 | |
| 27319 | | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 28295 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 27320 | 28296 | ZigType *ptr_type) |
| 27321 | 28297 | { |
| 27322 | 28298 | Error err; |
| ... | ... | @@ -27324,136 +28300,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 27324 | 28300 | ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr); |
| 27325 | 28301 | ir_assert(type_has_bits(ptr_type), source_instr); |
| 27326 | 28302 | |
| 27327 | | IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 28303 | IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 27328 | 28304 | if (type_is_invalid(casted_int->value->type)) |
| 27329 | | return ira->codegen->invalid_instruction; |
| 28305 | return ira->codegen->invalid_inst_gen; |
| 27330 | 28306 | |
| 27331 | 28307 | if (instr_is_comptime(casted_int)) { |
| 27332 | 28308 | ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad); |
| 27333 | 28309 | if (!val) |
| 27334 | | return ira->codegen->invalid_instruction; |
| 28310 | return ira->codegen->invalid_inst_gen; |
| 27335 | 28311 | |
| 27336 | 28312 | uint64_t addr = bigint_as_u64(&val->data.x_bigint); |
| 27337 | 28313 | if (!ptr_allows_addr_zero(ptr_type) && addr == 0) { |
| 27338 | 28314 | ir_add_error(ira, source_instr, |
| 27339 | 28315 | buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name))); |
| 27340 | | return ira->codegen->invalid_instruction; |
| 28316 | return ira->codegen->invalid_inst_gen; |
| 27341 | 28317 | } |
| 27342 | 28318 | |
| 27343 | 28319 | uint32_t align_bytes; |
| 27344 | 28320 | if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes))) |
| 27345 | | return ira->codegen->invalid_instruction; |
| 28321 | return ira->codegen->invalid_inst_gen; |
| 27346 | 28322 | |
| 27347 | 28323 | if (addr != 0 && addr % align_bytes != 0) { |
| 27348 | 28324 | ir_add_error(ira, source_instr, |
| 27349 | 28325 | buf_sprintf("pointer type '%s' requires aligned address", |
| 27350 | 28326 | buf_ptr(&ptr_type->name))); |
| 27351 | | return ira->codegen->invalid_instruction; |
| 28327 | return ira->codegen->invalid_inst_gen; |
| 27352 | 28328 | } |
| 27353 | 28329 | |
| 27354 | | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 28330 | IrInstGen *result = ir_const(ira, source_instr, ptr_type); |
| 27355 | 28331 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 27356 | 28332 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 27357 | 28333 | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 27358 | 28334 | return result; |
| 27359 | 28335 | } |
| 27360 | 28336 | |
| 27361 | | IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope, |
| 27362 | | source_instr->source_node, nullptr, casted_int); |
| 27363 | | result->value->type = ptr_type; |
| 27364 | | return result; |
| 28337 | return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type); |
| 27365 | 28338 | } |
| 27366 | 28339 | |
| 27367 | | static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { |
| 28340 | static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) { |
| 27368 | 28341 | Error err; |
| 27369 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 28342 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 27370 | 28343 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 27371 | 28344 | if (type_is_invalid(dest_type)) |
| 27372 | | return ira->codegen->invalid_instruction; |
| 28345 | return ira->codegen->invalid_inst_gen; |
| 27373 | 28346 | |
| 27374 | 28347 | // We explicitly check for the size, so we can use get_src_ptr_type |
| 27375 | 28348 | if (get_src_ptr_type(dest_type) == nullptr) { |
| 27376 | | ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 27377 | | return ira->codegen->invalid_instruction; |
| 28349 | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 28350 | return ira->codegen->invalid_inst_gen; |
| 27378 | 28351 | } |
| 27379 | 28352 | |
| 27380 | 28353 | bool has_bits; |
| 27381 | 28354 | if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits))) |
| 27382 | | return ira->codegen->invalid_instruction; |
| 28355 | return ira->codegen->invalid_inst_gen; |
| 27383 | 28356 | |
| 27384 | 28357 | if (!has_bits) { |
| 27385 | | ir_add_error(ira, dest_type_value, |
| 28358 | ir_add_error(ira, &dest_type_value->base, |
| 27386 | 28359 | buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name))); |
| 27387 | | return ira->codegen->invalid_instruction; |
| 28360 | return ira->codegen->invalid_inst_gen; |
| 27388 | 28361 | } |
| 27389 | 28362 | |
| 27390 | | IrInstruction *target = instruction->target->child; |
| 28363 | IrInstGen *target = instruction->target->child; |
| 27391 | 28364 | if (type_is_invalid(target->value->type)) |
| 27392 | | return ira->codegen->invalid_instruction; |
| 28365 | return ira->codegen->invalid_inst_gen; |
| 27393 | 28366 | |
| 27394 | | return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type); |
| 28367 | return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type); |
| 27395 | 28368 | } |
| 27396 | 28369 | |
| 27397 | | static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 27398 | | IrInstructionDeclRef *instruction) |
| 27399 | | { |
| 27400 | | IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); |
| 28370 | static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) { |
| 28371 | IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld); |
| 27401 | 28372 | if (type_is_invalid(ref_instruction->value->type)) { |
| 27402 | | return ira->codegen->invalid_instruction; |
| 28373 | return ira->codegen->invalid_inst_gen; |
| 27403 | 28374 | } |
| 27404 | 28375 | |
| 27405 | 28376 | if (instruction->lval == LValPtr) { |
| 27406 | 28377 | return ref_instruction; |
| 27407 | 28378 | } else { |
| 27408 | | return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr); |
| 28379 | return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr); |
| 27409 | 28380 | } |
| 27410 | 28381 | } |
| 27411 | 28382 | |
| 27412 | | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 28383 | static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtrToInt *instruction) { |
| 27413 | 28384 | Error err; |
| 27414 | | IrInstruction *target = instruction->target->child; |
| 28385 | IrInstGen *target = instruction->target->child; |
| 27415 | 28386 | if (type_is_invalid(target->value->type)) |
| 27416 | | return ira->codegen->invalid_instruction; |
| 28387 | return ira->codegen->invalid_inst_gen; |
| 27417 | 28388 | |
| 27418 | 28389 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 27419 | 28390 | |
| 27420 | 28391 | // We check size explicitly so we can use get_src_ptr_type here. |
| 27421 | 28392 | if (get_src_ptr_type(target->value->type) == nullptr) { |
| 27422 | | ir_add_error(ira, target, |
| 28393 | ir_add_error(ira, &target->base, |
| 27423 | 28394 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 27424 | | return ira->codegen->invalid_instruction; |
| 28395 | return ira->codegen->invalid_inst_gen; |
| 27425 | 28396 | } |
| 27426 | 28397 | |
| 27427 | 28398 | bool has_bits; |
| 27428 | 28399 | if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits))) |
| 27429 | | return ira->codegen->invalid_instruction; |
| 28400 | return ira->codegen->invalid_inst_gen; |
| 27430 | 28401 | |
| 27431 | 28402 | if (!has_bits) { |
| 27432 | | ir_add_error(ira, target, |
| 28403 | ir_add_error(ira, &target->base, |
| 27433 | 28404 | buf_sprintf("pointer to size 0 type has no address")); |
| 27434 | | return ira->codegen->invalid_instruction; |
| 28405 | return ira->codegen->invalid_inst_gen; |
| 27435 | 28406 | } |
| 27436 | 28407 | |
| 27437 | 28408 | if (instr_is_comptime(target)) { |
| 27438 | 28409 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 27439 | 28410 | if (!val) |
| 27440 | | return ira->codegen->invalid_instruction; |
| 28411 | return ira->codegen->invalid_inst_gen; |
| 27441 | 28412 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 27442 | | IrInstruction *result = ir_const(ira, &instruction->base, usize); |
| 28413 | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 27443 | 28414 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 27444 | 28415 | result->value->type = usize; |
| 27445 | 28416 | return result; |
| 27446 | 28417 | } |
| 27447 | 28418 | } |
| 27448 | 28419 | |
| 27449 | | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, |
| 27450 | | instruction->base.source_node, target); |
| 27451 | | result->value->type = usize; |
| 27452 | | return result; |
| 28420 | return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target); |
| 27453 | 28421 | } |
| 27454 | 28422 | |
| 27455 | | static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 27456 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 28423 | static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) { |
| 28424 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 27457 | 28425 | result->value->special = ConstValSpecialLazy; |
| 27458 | 28426 | |
| 27459 | 28427 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType"); |
| ... | ... | @@ -27464,17 +28432,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 27464 | 28432 | if (instruction->sentinel != nullptr) { |
| 27465 | 28433 | lazy_ptr_type->sentinel = instruction->sentinel->child; |
| 27466 | 28434 | if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr) |
| 27467 | | return ira->codegen->invalid_instruction; |
| 28435 | return ira->codegen->invalid_inst_gen; |
| 27468 | 28436 | } |
| 27469 | 28437 | |
| 27470 | 28438 | lazy_ptr_type->elem_type = instruction->child_type->child; |
| 27471 | 28439 | if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr) |
| 27472 | | return ira->codegen->invalid_instruction; |
| 28440 | return ira->codegen->invalid_inst_gen; |
| 27473 | 28441 | |
| 27474 | 28442 | if (instruction->align_value != nullptr) { |
| 27475 | 28443 | lazy_ptr_type->align_inst = instruction->align_value->child; |
| 27476 | 28444 | if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr) |
| 27477 | | return ira->codegen->invalid_instruction; |
| 28445 | return ira->codegen->invalid_inst_gen; |
| 27478 | 28446 | } |
| 27479 | 28447 | |
| 27480 | 28448 | lazy_ptr_type->ptr_len = instruction->ptr_len; |
| ... | ... | @@ -27487,10 +28455,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 27487 | 28455 | return result; |
| 27488 | 28456 | } |
| 27489 | 28457 | |
| 27490 | | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 27491 | | IrInstruction *target = instruction->target->child; |
| 28458 | static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) { |
| 28459 | IrInstGen *target = instruction->target->child; |
| 27492 | 28460 | if (type_is_invalid(target->value->type)) |
| 27493 | | return ira->codegen->invalid_instruction; |
| 28461 | return ira->codegen->invalid_inst_gen; |
| 27494 | 28462 | |
| 27495 | 28463 | ZigType *elem_type = nullptr; |
| 27496 | 28464 | if (is_slice(target->value->type)) { |
| ... | ... | @@ -27501,192 +28469,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 27501 | 28469 | } |
| 27502 | 28470 | |
| 27503 | 28471 | uint32_t align_bytes; |
| 27504 | | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 28472 | IrInstGen *align_bytes_inst = instruction->align_bytes->child; |
| 27505 | 28473 | if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes)) |
| 27506 | | return ira->codegen->invalid_instruction; |
| 28474 | return ira->codegen->invalid_inst_gen; |
| 27507 | 28475 | |
| 27508 | | IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); |
| 28476 | IrInstGen *result = ir_align_cast(ira, target, align_bytes, true); |
| 27509 | 28477 | if (type_is_invalid(result->value->type)) |
| 27510 | | return ira->codegen->invalid_instruction; |
| 28478 | return ira->codegen->invalid_inst_gen; |
| 27511 | 28479 | |
| 27512 | 28480 | return result; |
| 27513 | 28481 | } |
| 27514 | 28482 | |
| 27515 | | static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 28483 | static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) { |
| 27516 | 28484 | Buf *bare_name = buf_alloc(); |
| 27517 | | Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", |
| 27518 | | instruction->base.scope, instruction->base.source_node, bare_name); |
| 27519 | | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 27520 | | buf_ptr(full_name), bare_name); |
| 27521 | | return ir_const_type(ira, &instruction->base, result_type); |
| 28485 | Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque", |
| 28486 | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| 28487 | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope, |
| 28488 | instruction->base.base.source_node, buf_ptr(full_name), bare_name); |
| 28489 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 27522 | 28490 | } |
| 27523 | 28491 | |
| 27524 | | static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 28492 | static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstSrcSetAlignStack *instruction) { |
| 27525 | 28493 | uint32_t align_bytes; |
| 27526 | | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 28494 | IrInstGen *align_bytes_inst = instruction->align_bytes->child; |
| 27527 | 28495 | if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes)) |
| 27528 | | return ira->codegen->invalid_instruction; |
| 28496 | return ira->codegen->invalid_inst_gen; |
| 27529 | 28497 | |
| 27530 | 28498 | if (align_bytes > 256) { |
| 27531 | | ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 27532 | | return ira->codegen->invalid_instruction; |
| 28499 | ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 28500 | return ira->codegen->invalid_inst_gen; |
| 27533 | 28501 | } |
| 27534 | 28502 | |
| 27535 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28503 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 27536 | 28504 | if (fn_entry == nullptr) { |
| 27537 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); |
| 27538 | | return ira->codegen->invalid_instruction; |
| 28505 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function")); |
| 28506 | return ira->codegen->invalid_inst_gen; |
| 27539 | 28507 | } |
| 27540 | 28508 | if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) { |
| 27541 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function")); |
| 27542 | | return ira->codegen->invalid_instruction; |
| 28509 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function")); |
| 28510 | return ira->codegen->invalid_inst_gen; |
| 27543 | 28511 | } |
| 27544 | 28512 | |
| 27545 | 28513 | if (fn_entry->fn_inline == FnInlineAlways) { |
| 27546 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function")); |
| 27547 | | return ira->codegen->invalid_instruction; |
| 28514 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function")); |
| 28515 | return ira->codegen->invalid_inst_gen; |
| 27548 | 28516 | } |
| 27549 | 28517 | |
| 27550 | 28518 | if (fn_entry->set_alignstack_node != nullptr) { |
| 27551 | | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 28519 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 27552 | 28520 | buf_sprintf("alignstack set twice")); |
| 27553 | 28521 | add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here")); |
| 27554 | | return ira->codegen->invalid_instruction; |
| 28522 | return ira->codegen->invalid_inst_gen; |
| 27555 | 28523 | } |
| 27556 | 28524 | |
| 27557 | | fn_entry->set_alignstack_node = instruction->base.source_node; |
| 28525 | fn_entry->set_alignstack_node = instruction->base.base.source_node; |
| 27558 | 28526 | fn_entry->alignstack_value = align_bytes; |
| 27559 | 28527 | |
| 27560 | | return ir_const_void(ira, &instruction->base); |
| 28528 | return ir_const_void(ira, &instruction->base.base); |
| 27561 | 28529 | } |
| 27562 | 28530 | |
| 27563 | | static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { |
| 27564 | | IrInstruction *fn_type_inst = instruction->fn_type->child; |
| 28531 | static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) { |
| 28532 | IrInstGen *fn_type_inst = instruction->fn_type->child; |
| 27565 | 28533 | ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); |
| 27566 | 28534 | if (type_is_invalid(fn_type)) |
| 27567 | | return ira->codegen->invalid_instruction; |
| 28535 | return ira->codegen->invalid_inst_gen; |
| 27568 | 28536 | |
| 27569 | | IrInstruction *arg_index_inst = instruction->arg_index->child; |
| 28537 | IrInstGen *arg_index_inst = instruction->arg_index->child; |
| 27570 | 28538 | uint64_t arg_index; |
| 27571 | 28539 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) |
| 27572 | | return ira->codegen->invalid_instruction; |
| 28540 | return ira->codegen->invalid_inst_gen; |
| 27573 | 28541 | |
| 27574 | 28542 | if (fn_type->id == ZigTypeIdBoundFn) { |
| 27575 | 28543 | fn_type = fn_type->data.bound_fn.fn_type; |
| 27576 | 28544 | arg_index += 1; |
| 27577 | 28545 | } |
| 27578 | 28546 | if (fn_type->id != ZigTypeIdFn) { |
| 27579 | | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 27580 | | return ira->codegen->invalid_instruction; |
| 28547 | ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 28548 | return ira->codegen->invalid_inst_gen; |
| 27581 | 28549 | } |
| 27582 | 28550 | |
| 27583 | 28551 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| 27584 | 28552 | if (arg_index >= fn_type_id->param_count) { |
| 27585 | 28553 | if (instruction->allow_var) { |
| 27586 | 28554 | // TODO remove this with var args |
| 27587 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var); |
| 28555 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); |
| 27588 | 28556 | } |
| 27589 | | ir_add_error(ira, arg_index_inst, |
| 28557 | ir_add_error(ira, &arg_index_inst->base, |
| 27590 | 28558 | buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments", |
| 27591 | 28559 | arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count)); |
| 27592 | | return ira->codegen->invalid_instruction; |
| 28560 | return ira->codegen->invalid_inst_gen; |
| 27593 | 28561 | } |
| 27594 | 28562 | |
| 27595 | 28563 | ZigType *result_type = fn_type_id->param_info[arg_index].type; |
| 27596 | 28564 | if (result_type == nullptr) { |
| 27597 | 28565 | // Args are only unresolved if our function is generic. |
| 27598 | | ir_assert(fn_type->data.fn.is_generic, &instruction->base); |
| 28566 | ir_assert(fn_type->data.fn.is_generic, &instruction->base.base); |
| 27599 | 28567 | |
| 27600 | 28568 | if (instruction->allow_var) { |
| 27601 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var); |
| 28569 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); |
| 27602 | 28570 | } else { |
| 27603 | | ir_add_error(ira, arg_index_inst, |
| 28571 | ir_add_error(ira, &arg_index_inst->base, |
| 27604 | 28572 | buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic", |
| 27605 | 28573 | arg_index, buf_ptr(&fn_type->name))); |
| 27606 | | return ira->codegen->invalid_instruction; |
| 28574 | return ira->codegen->invalid_inst_gen; |
| 27607 | 28575 | } |
| 27608 | 28576 | } |
| 27609 | | return ir_const_type(ira, &instruction->base, result_type); |
| 28577 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 27610 | 28578 | } |
| 27611 | 28579 | |
| 27612 | | static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { |
| 28580 | static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) { |
| 27613 | 28581 | Error err; |
| 27614 | | IrInstruction *target_inst = instruction->target->child; |
| 28582 | IrInstGen *target_inst = instruction->target->child; |
| 27615 | 28583 | ZigType *enum_type = ir_resolve_type(ira, target_inst); |
| 27616 | 28584 | if (type_is_invalid(enum_type)) |
| 27617 | | return ira->codegen->invalid_instruction; |
| 28585 | return ira->codegen->invalid_inst_gen; |
| 27618 | 28586 | |
| 27619 | 28587 | if (enum_type->id == ZigTypeIdEnum) { |
| 27620 | 28588 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown))) |
| 27621 | | return ira->codegen->invalid_instruction; |
| 28589 | return ira->codegen->invalid_inst_gen; |
| 27622 | 28590 | |
| 27623 | | return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type); |
| 28591 | return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type); |
| 27624 | 28592 | } else if (enum_type->id == ZigTypeIdUnion) { |
| 27625 | | ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target, enum_type); |
| 28593 | ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type); |
| 27626 | 28594 | if (type_is_invalid(tag_type)) |
| 27627 | | return ira->codegen->invalid_instruction; |
| 27628 | | return ir_const_type(ira, &instruction->base, tag_type); |
| 28595 | return ira->codegen->invalid_inst_gen; |
| 28596 | return ir_const_type(ira, &instruction->base.base, tag_type); |
| 27629 | 28597 | } else { |
| 27630 | | ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'", |
| 28598 | ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'", |
| 27631 | 28599 | buf_ptr(&enum_type->name))); |
| 27632 | | return ira->codegen->invalid_instruction; |
| 28600 | return ira->codegen->invalid_inst_gen; |
| 27633 | 28601 | } |
| 27634 | 28602 | } |
| 27635 | 28603 | |
| 27636 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| 28604 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 27637 | 28605 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 27638 | 28606 | if (type_is_invalid(operand_type)) |
| 27639 | 28607 | return ira->codegen->builtin_types.entry_invalid; |
| 27640 | 28608 | |
| 27641 | 28609 | if (operand_type->id == ZigTypeIdInt) { |
| 27642 | 28610 | if (operand_type->data.integral.bit_count < 8) { |
| 27643 | | ir_add_error(ira, op, |
| 28611 | ir_add_error(ira, &op->base, |
| 27644 | 28612 | buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", |
| 27645 | 28613 | operand_type->data.integral.bit_count)); |
| 27646 | 28614 | return ira->codegen->builtin_types.entry_invalid; |
| 27647 | 28615 | } |
| 27648 | 28616 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27649 | 28617 | if (operand_type->data.integral.bit_count > max_atomic_bits) { |
| 27650 | | ir_add_error(ira, op, |
| 28618 | ir_add_error(ira, &op->base, |
| 27651 | 28619 | buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type", |
| 27652 | 28620 | max_atomic_bits, operand_type->data.integral.bit_count)); |
| 27653 | 28621 | return ira->codegen->builtin_types.entry_invalid; |
| 27654 | 28622 | } |
| 27655 | 28623 | if (!is_power_of_2(operand_type->data.integral.bit_count)) { |
| 27656 | | ir_add_error(ira, op, |
| 28624 | ir_add_error(ira, &op->base, |
| 27657 | 28625 | buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count)); |
| 27658 | 28626 | return ira->codegen->builtin_types.entry_invalid; |
| 27659 | 28627 | } |
| 27660 | 28628 | } else if (operand_type->id == ZigTypeIdEnum) { |
| 27661 | 28629 | ZigType *int_type = operand_type->data.enumeration.tag_int_type; |
| 27662 | 28630 | if (int_type->data.integral.bit_count < 8) { |
| 27663 | | ir_add_error(ira, op, |
| 28631 | ir_add_error(ira, &op->base, |
| 27664 | 28632 | buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type", |
| 27665 | 28633 | int_type->data.integral.bit_count)); |
| 27666 | 28634 | return ira->codegen->builtin_types.entry_invalid; |
| 27667 | 28635 | } |
| 27668 | 28636 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27669 | 28637 | if (int_type->data.integral.bit_count > max_atomic_bits) { |
| 27670 | | ir_add_error(ira, op, |
| 28638 | ir_add_error(ira, &op->base, |
| 27671 | 28639 | buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type", |
| 27672 | 28640 | max_atomic_bits, int_type->data.integral.bit_count)); |
| 27673 | 28641 | return ira->codegen->builtin_types.entry_invalid; |
| 27674 | 28642 | } |
| 27675 | 28643 | if (!is_power_of_2(int_type->data.integral.bit_count)) { |
| 27676 | | ir_add_error(ira, op, |
| 28644 | ir_add_error(ira, &op->base, |
| 27677 | 28645 | buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count)); |
| 27678 | 28646 | return ira->codegen->builtin_types.entry_invalid; |
| 27679 | 28647 | } |
| 27680 | 28648 | } else if (operand_type->id == ZigTypeIdFloat) { |
| 27681 | 28649 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27682 | 28650 | if (operand_type->data.floating.bit_count > max_atomic_bits) { |
| 27683 | | ir_add_error(ira, op, |
| 28651 | ir_add_error(ira, &op->base, |
| 27684 | 28652 | buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float", |
| 27685 | 28653 | max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count)); |
| 27686 | 28654 | return ira->codegen->builtin_types.entry_invalid; |
| 27687 | 28655 | } |
| 27688 | 28656 | } else if (get_codegen_ptr_type(operand_type) == nullptr) { |
| 27689 | | ir_add_error(ira, op, |
| 28657 | ir_add_error(ira, &op->base, |
| 27690 | 28658 | buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name))); |
| 27691 | 28659 | return ira->codegen->builtin_types.entry_invalid; |
| 27692 | 28660 | } |
| ... | ... | @@ -27694,172 +28662,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op |
| 27694 | 28662 | return operand_type; |
| 27695 | 28663 | } |
| 27696 | 28664 | |
| 27697 | | static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 28665 | static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) { |
| 27698 | 28666 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27699 | 28667 | if (type_is_invalid(operand_type)) |
| 27700 | | return ira->codegen->invalid_instruction; |
| 28668 | return ira->codegen->invalid_inst_gen; |
| 27701 | 28669 | |
| 27702 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28670 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27703 | 28671 | if (type_is_invalid(ptr_inst->value->type)) |
| 27704 | | return ira->codegen->invalid_instruction; |
| 28672 | return ira->codegen->invalid_inst_gen; |
| 27705 | 28673 | |
| 27706 | 28674 | // TODO let this be volatile |
| 27707 | 28675 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 27708 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28676 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27709 | 28677 | if (type_is_invalid(casted_ptr->value->type)) |
| 27710 | | return ira->codegen->invalid_instruction; |
| 28678 | return ira->codegen->invalid_inst_gen; |
| 27711 | 28679 | |
| 27712 | 28680 | AtomicRmwOp op; |
| 27713 | | if (instruction->op == nullptr) { |
| 27714 | | op = instruction->resolved_op; |
| 27715 | | } else { |
| 27716 | | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) { |
| 27717 | | return ira->codegen->invalid_instruction; |
| 27718 | | } |
| 28681 | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) { |
| 28682 | return ira->codegen->invalid_inst_gen; |
| 27719 | 28683 | } |
| 27720 | 28684 | |
| 27721 | 28685 | if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) { |
| 27722 | | ir_add_error(ira, instruction->op, |
| 28686 | ir_add_error(ira, &instruction->op->base, |
| 27723 | 28687 | buf_sprintf("@atomicRmw on enum only works with .Xchg")); |
| 27724 | | return ira->codegen->invalid_instruction; |
| 28688 | return ira->codegen->invalid_inst_gen; |
| 27725 | 28689 | } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) { |
| 27726 | | ir_add_error(ira, instruction->op, |
| 28690 | ir_add_error(ira, &instruction->op->base, |
| 27727 | 28691 | buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub")); |
| 27728 | | return ira->codegen->invalid_instruction; |
| 28692 | return ira->codegen->invalid_inst_gen; |
| 27729 | 28693 | } |
| 27730 | 28694 | |
| 27731 | | IrInstruction *operand = instruction->operand->child; |
| 28695 | IrInstGen *operand = instruction->operand->child; |
| 27732 | 28696 | if (type_is_invalid(operand->value->type)) |
| 27733 | | return ira->codegen->invalid_instruction; |
| 28697 | return ira->codegen->invalid_inst_gen; |
| 27734 | 28698 | |
| 27735 | | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 28699 | IrInstGen *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 27736 | 28700 | if (type_is_invalid(casted_operand->value->type)) |
| 27737 | | return ira->codegen->invalid_instruction; |
| 28701 | return ira->codegen->invalid_inst_gen; |
| 27738 | 28702 | |
| 27739 | 28703 | AtomicOrder ordering; |
| 27740 | | if (instruction->ordering == nullptr) { |
| 27741 | | ordering = instruction->resolved_ordering; |
| 27742 | | } else { |
| 27743 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27744 | | return ira->codegen->invalid_instruction; |
| 27745 | | if (ordering == AtomicOrderUnordered) { |
| 27746 | | ir_add_error(ira, instruction->ordering, |
| 27747 | | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 27748 | | return ira->codegen->invalid_instruction; |
| 27749 | | } |
| 28704 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28705 | return ira->codegen->invalid_inst_gen; |
| 28706 | if (ordering == AtomicOrderUnordered) { |
| 28707 | ir_add_error(ira, &instruction->ordering->base, |
| 28708 | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 28709 | return ira->codegen->invalid_inst_gen; |
| 27750 | 28710 | } |
| 27751 | 28711 | |
| 27752 | 28712 | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 27753 | 28713 | { |
| 27754 | | zig_panic("TODO compile-time execution of atomicRmw"); |
| 28714 | ir_add_error(ira, &instruction->base.base, |
| 28715 | buf_sprintf("compiler bug: TODO compile-time execution of @atomicRmw")); |
| 28716 | return ira->codegen->invalid_inst_gen; |
| 27755 | 28717 | } |
| 27756 | 28718 | |
| 27757 | | IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, |
| 27758 | | instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, |
| 27759 | | op, ordering); |
| 27760 | | result->value->type = operand_type; |
| 27761 | | return result; |
| 28719 | return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op, |
| 28720 | ordering, operand_type); |
| 27762 | 28721 | } |
| 27763 | 28722 | |
| 27764 | | static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 28723 | static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) { |
| 27765 | 28724 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27766 | 28725 | if (type_is_invalid(operand_type)) |
| 27767 | | return ira->codegen->invalid_instruction; |
| 28726 | return ira->codegen->invalid_inst_gen; |
| 27768 | 28727 | |
| 27769 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28728 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27770 | 28729 | if (type_is_invalid(ptr_inst->value->type)) |
| 27771 | | return ira->codegen->invalid_instruction; |
| 28730 | return ira->codegen->invalid_inst_gen; |
| 27772 | 28731 | |
| 27773 | 28732 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 27774 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28733 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27775 | 28734 | if (type_is_invalid(casted_ptr->value->type)) |
| 27776 | | return ira->codegen->invalid_instruction; |
| 28735 | return ira->codegen->invalid_inst_gen; |
| 27777 | 28736 | |
| 27778 | 28737 | AtomicOrder ordering; |
| 27779 | | if (instruction->ordering == nullptr) { |
| 27780 | | ordering = instruction->resolved_ordering; |
| 27781 | | } else { |
| 27782 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27783 | | return ira->codegen->invalid_instruction; |
| 27784 | | } |
| 28738 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28739 | return ira->codegen->invalid_inst_gen; |
| 27785 | 28740 | |
| 27786 | 28741 | if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) { |
| 27787 | | ir_assert(instruction->ordering != nullptr, &instruction->base); |
| 27788 | | ir_add_error(ira, instruction->ordering, |
| 28742 | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 28743 | ir_add_error(ira, &instruction->ordering->base, |
| 27789 | 28744 | buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel")); |
| 27790 | | return ira->codegen->invalid_instruction; |
| 28745 | return ira->codegen->invalid_inst_gen; |
| 27791 | 28746 | } |
| 27792 | 28747 | |
| 27793 | 28748 | if (instr_is_comptime(casted_ptr)) { |
| 27794 | | IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr); |
| 27795 | | ir_assert(result->value->type != nullptr, &instruction->base); |
| 28749 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr); |
| 28750 | ir_assert(result->value->type != nullptr, &instruction->base.base); |
| 27796 | 28751 | return result; |
| 27797 | 28752 | } |
| 27798 | 28753 | |
| 27799 | | IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, |
| 27800 | | instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); |
| 27801 | | result->value->type = operand_type; |
| 27802 | | return result; |
| 28754 | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type); |
| 27803 | 28755 | } |
| 27804 | 28756 | |
| 27805 | | static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) { |
| 28757 | static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) { |
| 27806 | 28758 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27807 | 28759 | if (type_is_invalid(operand_type)) |
| 27808 | | return ira->codegen->invalid_instruction; |
| 28760 | return ira->codegen->invalid_inst_gen; |
| 27809 | 28761 | |
| 27810 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28762 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27811 | 28763 | if (type_is_invalid(ptr_inst->value->type)) |
| 27812 | | return ira->codegen->invalid_instruction; |
| 28764 | return ira->codegen->invalid_inst_gen; |
| 27813 | 28765 | |
| 27814 | 28766 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 27815 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28767 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27816 | 28768 | if (type_is_invalid(casted_ptr->value->type)) |
| 27817 | | return ira->codegen->invalid_instruction; |
| 28769 | return ira->codegen->invalid_inst_gen; |
| 27818 | 28770 | |
| 27819 | | IrInstruction *value = instruction->value->child; |
| 28771 | IrInstGen *value = instruction->value->child; |
| 27820 | 28772 | if (type_is_invalid(value->value->type)) |
| 27821 | | return ira->codegen->invalid_instruction; |
| 28773 | return ira->codegen->invalid_inst_gen; |
| 27822 | 28774 | |
| 27823 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 28775 | IrInstGen *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 27824 | 28776 | if (type_is_invalid(casted_value->value->type)) |
| 27825 | | return ira->codegen->invalid_instruction; |
| 28777 | return ira->codegen->invalid_inst_gen; |
| 27826 | 28778 | |
| 27827 | 28779 | |
| 27828 | 28780 | AtomicOrder ordering; |
| 27829 | | if (instruction->ordering == nullptr) { |
| 27830 | | ordering = instruction->resolved_ordering; |
| 27831 | | } else { |
| 27832 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27833 | | return ira->codegen->invalid_instruction; |
| 27834 | | } |
| 28781 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28782 | return ira->codegen->invalid_inst_gen; |
| 27835 | 28783 | |
| 27836 | 28784 | if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) { |
| 27837 | | ir_assert(instruction->ordering != nullptr, &instruction->base); |
| 27838 | | ir_add_error(ira, instruction->ordering, |
| 28785 | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 28786 | ir_add_error(ira, &instruction->ordering->base, |
| 27839 | 28787 | buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel")); |
| 27840 | | return ira->codegen->invalid_instruction; |
| 28788 | return ira->codegen->invalid_inst_gen; |
| 27841 | 28789 | } |
| 27842 | 28790 | |
| 27843 | 28791 | if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { |
| 27844 | | IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false); |
| 28792 | IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false); |
| 27845 | 28793 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27846 | 28794 | return result; |
| 27847 | 28795 | } |
| 27848 | 28796 | |
| 27849 | | IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope, |
| 27850 | | instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering); |
| 27851 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27852 | | return result; |
| 28797 | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering); |
| 27853 | 28798 | } |
| 27854 | 28799 | |
| 27855 | | static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 27856 | | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 27857 | | instruction->base.source_node); |
| 27858 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27859 | | return result; |
| 28800 | static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) { |
| 28801 | return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base); |
| 27860 | 28802 | } |
| 27861 | 28803 | |
| 27862 | | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, BuiltinFnId fop, ZigType *float_type, |
| 28804 | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type, |
| 27863 | 28805 | ZigValue *op, ZigValue *out_val) |
| 27864 | 28806 | { |
| 27865 | 28807 | assert(ira && source_instr && float_type && out_val && op); |
| ... | ... | @@ -28072,30 +29014,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B |
| 28072 | 29014 | return nullptr; |
| 28073 | 29015 | } |
| 28074 | 29016 | |
| 28075 | | static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) { |
| 28076 | | IrInstruction *operand = instruction->operand->child; |
| 29017 | static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) { |
| 29018 | IrInstGen *operand = instruction->operand->child; |
| 28077 | 29019 | ZigType *operand_type = operand->value->type; |
| 28078 | 29020 | if (type_is_invalid(operand_type)) |
| 28079 | | return ira->codegen->invalid_instruction; |
| 29021 | return ira->codegen->invalid_inst_gen; |
| 28080 | 29022 | |
| 28081 | 29023 | // This instruction accepts floats and vectors of floats. |
| 28082 | 29024 | ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? |
| 28083 | 29025 | operand_type->data.vector.elem_type : operand_type; |
| 28084 | 29026 | |
| 28085 | 29027 | if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) { |
| 28086 | | ir_add_error(ira, operand, |
| 29028 | ir_add_error(ira, &operand->base, |
| 28087 | 29029 | buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name))); |
| 28088 | | return ira->codegen->invalid_instruction; |
| 29030 | return ira->codegen->invalid_inst_gen; |
| 28089 | 29031 | } |
| 28090 | 29032 | |
| 28091 | 29033 | if (instr_is_comptime(operand)) { |
| 28092 | 29034 | ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk); |
| 28093 | 29035 | if (operand_val == nullptr) |
| 28094 | | return ira->codegen->invalid_instruction; |
| 29036 | return ira->codegen->invalid_inst_gen; |
| 28095 | 29037 | if (operand_val->special == ConstValSpecialUndef) |
| 28096 | | return ir_const_undef(ira, &instruction->base, operand_type); |
| 29038 | return ir_const_undef(ira, &instruction->base.base, operand_type); |
| 28097 | 29039 | |
| 28098 | | IrInstruction *result = ir_const(ira, &instruction->base, operand_type); |
| 29040 | IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type); |
| 28099 | 29041 | ZigValue *out_val = result->value; |
| 28100 | 29042 | |
| 28101 | 29043 | if (operand_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -28106,47 +29048,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 28106 | 29048 | for (size_t i = 0; i < len; i += 1) { |
| 28107 | 29049 | ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i]; |
| 28108 | 29050 | ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 28109 | | ir_assert(elem_operand->type == scalar_type, &instruction->base); |
| 28110 | | ir_assert(float_out_val->type == scalar_type, &instruction->base); |
| 28111 | | ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type, |
| 29051 | ir_assert(elem_operand->type == scalar_type, &instruction->base.base); |
| 29052 | ir_assert(float_out_val->type == scalar_type, &instruction->base.base); |
| 29053 | ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 28112 | 29054 | elem_operand, float_out_val); |
| 28113 | 29055 | if (msg != nullptr) { |
| 28114 | | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 29056 | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 28115 | 29057 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 28116 | | return ira->codegen->invalid_instruction; |
| 29058 | return ira->codegen->invalid_inst_gen; |
| 28117 | 29059 | } |
| 28118 | 29060 | float_out_val->type = scalar_type; |
| 28119 | 29061 | } |
| 28120 | 29062 | out_val->type = operand_type; |
| 28121 | 29063 | out_val->special = ConstValSpecialStatic; |
| 28122 | 29064 | } else { |
| 28123 | | if (ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type, |
| 29065 | if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 28124 | 29066 | operand_val, out_val) != nullptr) |
| 28125 | 29067 | { |
| 28126 | | return ira->codegen->invalid_instruction; |
| 29068 | return ira->codegen->invalid_inst_gen; |
| 28127 | 29069 | } |
| 28128 | 29070 | } |
| 28129 | 29071 | return result; |
| 28130 | 29072 | } |
| 28131 | 29073 | |
| 28132 | | ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base); |
| 29074 | ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base); |
| 28133 | 29075 | |
| 28134 | | IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope, |
| 28135 | | instruction->base.source_node, operand, instruction->fn_id); |
| 28136 | | result->value->type = operand_type; |
| 28137 | | return result; |
| 29076 | return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type); |
| 28138 | 29077 | } |
| 28139 | 29078 | |
| 28140 | | static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) { |
| 29079 | static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) { |
| 28141 | 29080 | Error err; |
| 28142 | 29081 | |
| 28143 | 29082 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 28144 | 29083 | if (type_is_invalid(int_type)) |
| 28145 | | return ira->codegen->invalid_instruction; |
| 29084 | return ira->codegen->invalid_inst_gen; |
| 28146 | 29085 | |
| 28147 | | IrInstruction *uncasted_op = instruction->op->child; |
| 29086 | IrInstGen *uncasted_op = instruction->op->child; |
| 28148 | 29087 | if (type_is_invalid(uncasted_op->value->type)) |
| 28149 | | return ira->codegen->invalid_instruction; |
| 29088 | return ira->codegen->invalid_inst_gen; |
| 28150 | 29089 | |
| 28151 | 29090 | uint32_t vector_len; // UINT32_MAX means not a vector |
| 28152 | 29091 | if (uncasted_op->value->type->id == ZigTypeIdArray && |
| ... | ... | @@ -28162,28 +29101,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28162 | 29101 | bool is_vector = (vector_len != UINT32_MAX); |
| 28163 | 29102 | ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type; |
| 28164 | 29103 | |
| 28165 | | IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 29104 | IrInstGen *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 28166 | 29105 | if (type_is_invalid(op->value->type)) |
| 28167 | | return ira->codegen->invalid_instruction; |
| 29106 | return ira->codegen->invalid_inst_gen; |
| 28168 | 29107 | |
| 28169 | 29108 | if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0) |
| 28170 | 29109 | return op; |
| 28171 | 29110 | |
| 28172 | 29111 | if (int_type->data.integral.bit_count % 8 != 0) { |
| 28173 | | ir_add_error(ira, instruction->op, |
| 29112 | ir_add_error(ira, &instruction->op->base, |
| 28174 | 29113 | buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8", |
| 28175 | 29114 | buf_ptr(&int_type->name), int_type->data.integral.bit_count)); |
| 28176 | | return ira->codegen->invalid_instruction; |
| 29115 | return ira->codegen->invalid_inst_gen; |
| 28177 | 29116 | } |
| 28178 | 29117 | |
| 28179 | 29118 | if (instr_is_comptime(op)) { |
| 28180 | 29119 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 28181 | 29120 | if (val == nullptr) |
| 28182 | | return ira->codegen->invalid_instruction; |
| 29121 | return ira->codegen->invalid_inst_gen; |
| 28183 | 29122 | if (val->special == ConstValSpecialUndef) |
| 28184 | | return ir_const_undef(ira, &instruction->base, op_type); |
| 29123 | return ir_const_undef(ira, &instruction->base.base, op_type); |
| 28185 | 29124 | |
| 28186 | | IrInstruction *result = ir_const(ira, &instruction->base, op_type); |
| 29125 | IrInstGen *result = ir_const(ira, &instruction->base.base, op_type); |
| 28187 | 29126 | size_t buf_size = int_type->data.integral.bit_count / 8; |
| 28188 | 29127 | uint8_t *buf = allocate_nonzero<uint8_t>(buf_size); |
| 28189 | 29128 | if (is_vector) { |
| ... | ... | @@ -28191,10 +29130,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28191 | 29130 | result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 28192 | 29131 | for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { |
| 28193 | 29132 | ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 28194 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, |
| 29133 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node, |
| 28195 | 29134 | op_elem_val, UndefOk))) |
| 28196 | 29135 | { |
| 28197 | | return ira->codegen->invalid_instruction; |
| 29136 | return ira->codegen->invalid_inst_gen; |
| 28198 | 29137 | } |
| 28199 | 29138 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 28200 | 29139 | result_elem_val->type = int_type; |
| ... | ... | @@ -28216,23 +29155,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28216 | 29155 | return result; |
| 28217 | 29156 | } |
| 28218 | 29157 | |
| 28219 | | IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope, |
| 28220 | | instruction->base.source_node, nullptr, op); |
| 28221 | | result->value->type = op_type; |
| 28222 | | return result; |
| 29158 | return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op); |
| 28223 | 29159 | } |
| 28224 | 29160 | |
| 28225 | | static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) { |
| 29161 | static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) { |
| 28226 | 29162 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 28227 | 29163 | if (type_is_invalid(int_type)) |
| 28228 | | return ira->codegen->invalid_instruction; |
| 29164 | return ira->codegen->invalid_inst_gen; |
| 28229 | 29165 | |
| 28230 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 29166 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 28231 | 29167 | if (type_is_invalid(op->value->type)) |
| 28232 | | return ira->codegen->invalid_instruction; |
| 29168 | return ira->codegen->invalid_inst_gen; |
| 28233 | 29169 | |
| 28234 | 29170 | if (int_type->data.integral.bit_count == 0) { |
| 28235 | | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 29171 | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 28236 | 29172 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 28237 | 29173 | return result; |
| 28238 | 29174 | } |
| ... | ... | @@ -28240,11 +29176,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 28240 | 29176 | if (instr_is_comptime(op)) { |
| 28241 | 29177 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 28242 | 29178 | if (val == nullptr) |
| 28243 | | return ira->codegen->invalid_instruction; |
| 29179 | return ira->codegen->invalid_inst_gen; |
| 28244 | 29180 | if (val->special == ConstValSpecialUndef) |
| 28245 | | return ir_const_undef(ira, &instruction->base, int_type); |
| 29181 | return ir_const_undef(ira, &instruction->base.base, int_type); |
| 28246 | 29182 | |
| 28247 | | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 29183 | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 28248 | 29184 | size_t num_bits = int_type->data.integral.bit_count; |
| 28249 | 29185 | size_t buf_size = (num_bits + 7) / 8; |
| 28250 | 29186 | uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size); |
| ... | ... | @@ -28271,128 +29207,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 28271 | 29207 | return result; |
| 28272 | 29208 | } |
| 28273 | 29209 | |
| 28274 | | IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope, |
| 28275 | | instruction->base.source_node, nullptr, op); |
| 28276 | | result->value->type = int_type; |
| 28277 | | return result; |
| 29210 | return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op); |
| 28278 | 29211 | } |
| 28279 | 29212 | |
| 28280 | 29213 | |
| 28281 | | static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 28282 | | IrInstruction *target = instruction->target->child; |
| 29214 | static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) { |
| 29215 | IrInstGen *target = instruction->target->child; |
| 28283 | 29216 | if (type_is_invalid(target->value->type)) |
| 28284 | | return ira->codegen->invalid_instruction; |
| 29217 | return ira->codegen->invalid_inst_gen; |
| 28285 | 29218 | |
| 28286 | | return ir_analyze_enum_to_int(ira, &instruction->base, target); |
| 29219 | return ir_analyze_enum_to_int(ira, &instruction->base.base, target); |
| 28287 | 29220 | } |
| 28288 | 29221 | |
| 28289 | | static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { |
| 29222 | static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) { |
| 28290 | 29223 | Error err; |
| 28291 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 29224 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 28292 | 29225 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 28293 | 29226 | if (type_is_invalid(dest_type)) |
| 28294 | | return ira->codegen->invalid_instruction; |
| 29227 | return ira->codegen->invalid_inst_gen; |
| 28295 | 29228 | |
| 28296 | 29229 | if (dest_type->id != ZigTypeIdEnum) { |
| 28297 | | ir_add_error(ira, instruction->dest_type, |
| 29230 | ir_add_error(ira, &instruction->dest_type->base, |
| 28298 | 29231 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 28299 | | return ira->codegen->invalid_instruction; |
| 29232 | return ira->codegen->invalid_inst_gen; |
| 28300 | 29233 | } |
| 28301 | 29234 | |
| 28302 | 29235 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 28303 | | return ira->codegen->invalid_instruction; |
| 29236 | return ira->codegen->invalid_inst_gen; |
| 28304 | 29237 | |
| 28305 | 29238 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 28306 | 29239 | |
| 28307 | | IrInstruction *target = instruction->target->child; |
| 29240 | IrInstGen *target = instruction->target->child; |
| 28308 | 29241 | if (type_is_invalid(target->value->type)) |
| 28309 | | return ira->codegen->invalid_instruction; |
| 29242 | return ira->codegen->invalid_inst_gen; |
| 28310 | 29243 | |
| 28311 | | IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 29244 | IrInstGen *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 28312 | 29245 | if (type_is_invalid(casted_target->value->type)) |
| 28313 | | return ira->codegen->invalid_instruction; |
| 29246 | return ira->codegen->invalid_inst_gen; |
| 28314 | 29247 | |
| 28315 | | return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| 29248 | return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type); |
| 28316 | 29249 | } |
| 28317 | 29250 | |
| 28318 | | static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { |
| 28319 | | IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child; |
| 29251 | static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) { |
| 29252 | IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child; |
| 28320 | 29253 | bool scope_is_comptime; |
| 28321 | 29254 | if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime)) |
| 28322 | | return ira->codegen->invalid_instruction; |
| 29255 | return ira->codegen->invalid_inst_gen; |
| 28323 | 29256 | |
| 28324 | | IrInstruction *is_comptime_inst = instruction->is_comptime->child; |
| 29257 | IrInstGen *is_comptime_inst = instruction->is_comptime->child; |
| 28325 | 29258 | bool is_comptime; |
| 28326 | 29259 | if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime)) |
| 28327 | | return ira->codegen->invalid_instruction; |
| 29260 | return ira->codegen->invalid_inst_gen; |
| 28328 | 29261 | |
| 28329 | 29262 | if (!scope_is_comptime && is_comptime) { |
| 28330 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 29263 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 28331 | 29264 | buf_sprintf("comptime control flow inside runtime block")); |
| 28332 | | add_error_note(ira->codegen, msg, block_comptime_inst->source_node, |
| 29265 | add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node, |
| 28333 | 29266 | buf_sprintf("runtime block created here")); |
| 28334 | | return ira->codegen->invalid_instruction; |
| 29267 | return ira->codegen->invalid_inst_gen; |
| 28335 | 29268 | } |
| 28336 | 29269 | |
| 28337 | | return ir_const_void(ira, &instruction->base); |
| 29270 | return ir_const_void(ira, &instruction->base.base); |
| 28338 | 29271 | } |
| 28339 | 29272 | |
| 28340 | | static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) { |
| 29273 | static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) { |
| 28341 | 29274 | ZigType *container_type = ir_resolve_type(ira, instruction->container->child); |
| 28342 | 29275 | if (type_is_invalid(container_type)) |
| 28343 | | return ira->codegen->invalid_instruction; |
| 29276 | return ira->codegen->invalid_inst_gen; |
| 28344 | 29277 | |
| 28345 | 29278 | Buf *name = ir_resolve_str(ira, instruction->name->child); |
| 28346 | 29279 | if (name == nullptr) |
| 28347 | | return ira->codegen->invalid_instruction; |
| 29280 | return ira->codegen->invalid_inst_gen; |
| 28348 | 29281 | |
| 28349 | 29282 | if (!is_container(container_type)) { |
| 28350 | | ir_add_error(ira, instruction->container, |
| 29283 | ir_add_error(ira, &instruction->container->base, |
| 28351 | 29284 | buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name))); |
| 28352 | | return ira->codegen->invalid_instruction; |
| 29285 | return ira->codegen->invalid_inst_gen; |
| 28353 | 29286 | } |
| 28354 | 29287 | |
| 28355 | 29288 | ScopeDecls *container_scope = get_container_scope(container_type); |
| 28356 | 29289 | Tld *tld = find_container_decl(ira->codegen, container_scope, name); |
| 28357 | 29290 | if (tld == nullptr) |
| 28358 | | return ir_const_bool(ira, &instruction->base, false); |
| 29291 | return ir_const_bool(ira, &instruction->base.base, false); |
| 28359 | 29292 | |
| 28360 | | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) { |
| 28361 | | return ir_const_bool(ira, &instruction->base, false); |
| 29293 | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) { |
| 29294 | return ir_const_bool(ira, &instruction->base.base, false); |
| 28362 | 29295 | } |
| 28363 | 29296 | |
| 28364 | | return ir_const_bool(ira, &instruction->base, true); |
| 29297 | return ir_const_bool(ira, &instruction->base.base, true); |
| 28365 | 29298 | } |
| 28366 | 29299 | |
| 28367 | | static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) { |
| 29300 | static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) { |
| 28368 | 29301 | // put a variable of same name with invalid type in global scope |
| 28369 | 29302 | // so that future references to this same name will find a variable with an invalid type |
| 28370 | | populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 28371 | | instruction->name); |
| 28372 | | ir_add_error(ira, &instruction->base, |
| 29303 | populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope, |
| 29304 | instruction->base.base.source_node, instruction->name); |
| 29305 | ir_add_error(ira, &instruction->base.base, |
| 28373 | 29306 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name))); |
| 28374 | | return ira->codegen->invalid_instruction; |
| 29307 | return ira->codegen->invalid_inst_gen; |
| 28375 | 29308 | } |
| 28376 | 29309 | |
| 28377 | | static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { |
| 28378 | | IrInstruction *value = instruction->value->child; |
| 29310 | static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) { |
| 29311 | IrInstGen *value = instruction->value->child; |
| 28379 | 29312 | if (type_is_invalid(value->value->type)) |
| 28380 | | return ira->codegen->invalid_instruction; |
| 29313 | return ira->codegen->invalid_inst_gen; |
| 28381 | 29314 | |
| 28382 | 29315 | bool was_written = instruction->result_loc->written; |
| 28383 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 28384 | | value->value->type, value, false, false, true); |
| 29316 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 29317 | value->value->type, value, false, true); |
| 28385 | 29318 | if (result_loc != nullptr) { |
| 28386 | 29319 | if (type_is_invalid(result_loc->value->type)) |
| 28387 | | return ira->codegen->invalid_instruction; |
| 29320 | return ira->codegen->invalid_inst_gen; |
| 28388 | 29321 | if (result_loc->value->type->id == ZigTypeIdUnreachable) |
| 28389 | 29322 | return result_loc; |
| 28390 | 29323 | |
| 28391 | 29324 | if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { |
| 28392 | | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| 29325 | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value, |
| 28393 | 29326 | instruction->result_loc->allow_write_through_const); |
| 28394 | 29327 | if (type_is_invalid(store_ptr->value->type)) { |
| 28395 | | return ira->codegen->invalid_instruction; |
| 29328 | return ira->codegen->invalid_inst_gen; |
| 28396 | 29329 | } |
| 28397 | 29330 | } |
| 28398 | 29331 | |
| ... | ... | @@ -28407,106 +29340,100 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 28407 | 29340 | } |
| 28408 | 29341 | } |
| 28409 | 29342 | |
| 28410 | | return ir_const_void(ira, &instruction->base); |
| 29343 | return ir_const_void(ira, &instruction->base.base); |
| 28411 | 29344 | } |
| 28412 | 29345 | |
| 28413 | | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { |
| 28414 | | IrInstruction *operand = instruction->operand->child; |
| 29346 | static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) { |
| 29347 | IrInstGen *operand = instruction->operand->child; |
| 28415 | 29348 | if (type_is_invalid(operand->value->type)) |
| 28416 | 29349 | return operand; |
| 28417 | 29350 | |
| 28418 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 28419 | | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); |
| 28420 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 28421 | | return result_loc; |
| 28422 | | |
| 28423 | 29351 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); |
| 28424 | 29352 | if (type_is_invalid(dest_type)) |
| 28425 | | return ira->codegen->invalid_instruction; |
| 28426 | | return ir_implicit_cast2(ira, &instruction->base, operand, dest_type); |
| 29353 | return ira->codegen->invalid_inst_gen; |
| 29354 | return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type); |
| 28427 | 29355 | } |
| 28428 | 29356 | |
| 28429 | | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 28430 | | IrInstruction *operand = instruction->operand->child; |
| 29357 | static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) { |
| 29358 | IrInstGen *operand = instruction->operand->child; |
| 28431 | 29359 | if (type_is_invalid(operand->value->type)) |
| 28432 | 29360 | return operand; |
| 28433 | 29361 | |
| 28434 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 28435 | | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); |
| 28436 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 29362 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, |
| 29363 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true); |
| 29364 | if (result_loc != nullptr && |
| 29365 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 29366 | { |
| 28437 | 29367 | return result_loc; |
| 28438 | | |
| 28439 | | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { |
| 28440 | | return instruction->result_loc_bit_cast->parent->gen_instruction; |
| 28441 | 29368 | } |
| 28442 | 29369 | |
| 28443 | | return result_loc; |
| 29370 | ZigType *dest_type = ir_resolve_type(ira, |
| 29371 | instruction->result_loc_bit_cast->base.source_instruction->child); |
| 29372 | if (type_is_invalid(dest_type)) |
| 29373 | return ira->codegen->invalid_inst_gen; |
| 29374 | return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type); |
| 28444 | 29375 | } |
| 28445 | 29376 | |
| 28446 | | static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 28447 | | IrInstructionUnionInitNamedField *instruction) |
| 29377 | static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 29378 | IrInstSrcUnionInitNamedField *instruction) |
| 28448 | 29379 | { |
| 28449 | 29380 | ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child); |
| 28450 | 29381 | if (type_is_invalid(union_type)) |
| 28451 | | return ira->codegen->invalid_instruction; |
| 29382 | return ira->codegen->invalid_inst_gen; |
| 28452 | 29383 | |
| 28453 | 29384 | if (union_type->id != ZigTypeIdUnion) { |
| 28454 | | ir_add_error(ira, instruction->union_type, |
| 29385 | ir_add_error(ira, &instruction->union_type->base, |
| 28455 | 29386 | buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name))); |
| 28456 | | return ira->codegen->invalid_instruction; |
| 29387 | return ira->codegen->invalid_inst_gen; |
| 28457 | 29388 | } |
| 28458 | 29389 | |
| 28459 | 29390 | Buf *field_name = ir_resolve_str(ira, instruction->field_name->child); |
| 28460 | 29391 | if (field_name == nullptr) |
| 28461 | | return ira->codegen->invalid_instruction; |
| 29392 | return ira->codegen->invalid_inst_gen; |
| 28462 | 29393 | |
| 28463 | | IrInstruction *field_result_loc = instruction->field_result_loc->child; |
| 29394 | IrInstGen *field_result_loc = instruction->field_result_loc->child; |
| 28464 | 29395 | if (type_is_invalid(field_result_loc->value->type)) |
| 28465 | | return ira->codegen->invalid_instruction; |
| 29396 | return ira->codegen->invalid_inst_gen; |
| 28466 | 29397 | |
| 28467 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 29398 | IrInstGen *result_loc = instruction->result_loc->child; |
| 28468 | 29399 | if (type_is_invalid(result_loc->value->type)) |
| 28469 | | return ira->codegen->invalid_instruction; |
| 29400 | return ira->codegen->invalid_inst_gen; |
| 28470 | 29401 | |
| 28471 | | return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node, |
| 29402 | return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node, |
| 28472 | 29403 | union_type, field_name, field_result_loc, result_loc); |
| 28473 | 29404 | } |
| 28474 | 29405 | |
| 28475 | | static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) { |
| 28476 | | IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope, |
| 28477 | | instruction->base.source_node); |
| 28478 | | return &result->base; |
| 29406 | static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) { |
| 29407 | return ir_build_suspend_begin_gen(ira, &instruction->base.base); |
| 28479 | 29408 | } |
| 28480 | 29409 | |
| 28481 | | static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 28482 | | IrInstructionSuspendFinish *instruction) |
| 28483 | | { |
| 28484 | | IrInstruction *begin_base = instruction->begin->base.child; |
| 29410 | static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) { |
| 29411 | IrInstGen *begin_base = instruction->begin->base.child; |
| 28485 | 29412 | if (type_is_invalid(begin_base->value->type)) |
| 28486 | | return ira->codegen->invalid_instruction; |
| 28487 | | ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base); |
| 28488 | | IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base); |
| 29413 | return ira->codegen->invalid_inst_gen; |
| 29414 | ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base); |
| 29415 | IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base); |
| 28489 | 29416 | |
| 28490 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28491 | | ir_assert(fn_entry != nullptr, &instruction->base); |
| 29417 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 29418 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 28492 | 29419 | |
| 28493 | 29420 | if (fn_entry->inferred_async_node == nullptr) { |
| 28494 | | fn_entry->inferred_async_node = instruction->base.source_node; |
| 29421 | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 28495 | 29422 | } |
| 28496 | 29423 | |
| 28497 | | return ir_build_suspend_finish(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin); |
| 29424 | return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin); |
| 28498 | 29425 | } |
| 28499 | 29426 | |
| 28500 | | static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr, |
| 28501 | | IrInstruction *frame_ptr, ZigFn **target_fn) |
| 29427 | static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr, |
| 29428 | IrInstGen *frame_ptr, ZigFn **target_fn) |
| 28502 | 29429 | { |
| 28503 | 29430 | if (type_is_invalid(frame_ptr->value->type)) |
| 28504 | | return ira->codegen->invalid_instruction; |
| 29431 | return ira->codegen->invalid_inst_gen; |
| 28505 | 29432 | |
| 28506 | 29433 | *target_fn = nullptr; |
| 28507 | 29434 | |
| 28508 | 29435 | ZigType *result_type; |
| 28509 | | IrInstruction *frame; |
| 29436 | IrInstGen *frame; |
| 28510 | 29437 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 28511 | 29438 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 28512 | 29439 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| ... | ... | @@ -28529,38 +29456,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct |
| 28529 | 29456 | { |
| 28530 | 29457 | ir_add_error(ira, source_instr, |
| 28531 | 29458 | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); |
| 28532 | | return ira->codegen->invalid_instruction; |
| 29459 | return ira->codegen->invalid_inst_gen; |
| 28533 | 29460 | } else { |
| 28534 | 29461 | result_type = frame->value->type->data.any_frame.result_type; |
| 28535 | 29462 | } |
| 28536 | 29463 | } |
| 28537 | 29464 | |
| 28538 | 29465 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type); |
| 28539 | | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 29466 | IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 28540 | 29467 | if (type_is_invalid(casted_frame->value->type)) |
| 28541 | | return ira->codegen->invalid_instruction; |
| 29468 | return ira->codegen->invalid_inst_gen; |
| 28542 | 29469 | |
| 28543 | 29470 | return casted_frame; |
| 28544 | 29471 | } |
| 28545 | 29472 | |
| 28546 | | static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) { |
| 28547 | | IrInstruction *operand = instruction->frame->child; |
| 29473 | static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) { |
| 29474 | IrInstGen *operand = instruction->frame->child; |
| 28548 | 29475 | if (type_is_invalid(operand->value->type)) |
| 28549 | | return ira->codegen->invalid_instruction; |
| 29476 | return ira->codegen->invalid_inst_gen; |
| 28550 | 29477 | ZigFn *target_fn; |
| 28551 | | IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn); |
| 29478 | IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn); |
| 28552 | 29479 | if (type_is_invalid(frame->value->type)) |
| 28553 | | return ira->codegen->invalid_instruction; |
| 29480 | return ira->codegen->invalid_inst_gen; |
| 28554 | 29481 | |
| 28555 | 29482 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 28556 | 29483 | |
| 28557 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28558 | | ir_assert(fn_entry != nullptr, &instruction->base); |
| 29484 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 29485 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 28559 | 29486 | |
| 28560 | 29487 | // If it's not @Frame(func) then it's definitely a suspend point |
| 28561 | 29488 | if (target_fn == nullptr) { |
| 28562 | 29489 | if (fn_entry->inferred_async_node == nullptr) { |
| 28563 | | fn_entry->inferred_async_node = instruction->base.source_node; |
| 29490 | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 28564 | 29491 | } |
| 28565 | 29492 | } |
| 28566 | 29493 | |
| ... | ... | @@ -28568,402 +29495,368 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 28568 | 29495 | fn_entry->calls_or_awaits_errorable_fn = true; |
| 28569 | 29496 | } |
| 28570 | 29497 | |
| 28571 | | IrInstruction *result_loc; |
| 29498 | IrInstGen *result_loc; |
| 28572 | 29499 | if (type_has_bits(result_type)) { |
| 28573 | | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 28574 | | result_type, nullptr, true, true, true); |
| 28575 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 29500 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 29501 | result_type, nullptr, true, true); |
| 29502 | if (result_loc != nullptr && |
| 29503 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 29504 | { |
| 28576 | 29505 | return result_loc; |
| 29506 | } |
| 28577 | 29507 | } else { |
| 28578 | 29508 | result_loc = nullptr; |
| 28579 | 29509 | } |
| 28580 | 29510 | |
| 28581 | | IrInstructionAwaitGen *result = ir_build_await_gen(ira, &instruction->base, frame, result_type, result_loc); |
| 29511 | IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc); |
| 28582 | 29512 | result->target_fn = target_fn; |
| 28583 | 29513 | fn_entry->await_list.append(result); |
| 28584 | 29514 | return ir_finish_anal(ira, &result->base); |
| 28585 | 29515 | } |
| 28586 | 29516 | |
| 28587 | | static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) { |
| 28588 | | IrInstruction *frame_ptr = instruction->frame->child; |
| 29517 | static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) { |
| 29518 | IrInstGen *frame_ptr = instruction->frame->child; |
| 28589 | 29519 | if (type_is_invalid(frame_ptr->value->type)) |
| 28590 | | return ira->codegen->invalid_instruction; |
| 29520 | return ira->codegen->invalid_inst_gen; |
| 28591 | 29521 | |
| 28592 | | IrInstruction *frame; |
| 29522 | IrInstGen *frame; |
| 28593 | 29523 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 28594 | 29524 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 28595 | 29525 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 28596 | 29526 | { |
| 28597 | 29527 | frame = frame_ptr; |
| 28598 | 29528 | } else { |
| 28599 | | frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr); |
| 29529 | frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr); |
| 28600 | 29530 | } |
| 28601 | 29531 | |
| 28602 | 29532 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 28603 | | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 29533 | IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type); |
| 28604 | 29534 | if (type_is_invalid(casted_frame->value->type)) |
| 28605 | | return ira->codegen->invalid_instruction; |
| 29535 | return ira->codegen->invalid_inst_gen; |
| 28606 | 29536 | |
| 28607 | | return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame); |
| 29537 | return ir_build_resume_gen(ira, &instruction->base.base, casted_frame); |
| 28608 | 29538 | } |
| 28609 | 29539 | |
| 28610 | | static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) { |
| 28611 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) |
| 28612 | | return ir_const_void(ira, &instruction->base); |
| 29540 | static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) { |
| 29541 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) |
| 29542 | return ir_const_void(ira, &instruction->base.base); |
| 28613 | 29543 | |
| 28614 | | IrInstruction *operand = instruction->operand->child; |
| 29544 | IrInstGen *operand = instruction->operand->child; |
| 28615 | 29545 | if (type_is_invalid(operand->value->type)) |
| 28616 | | return ira->codegen->invalid_instruction; |
| 29546 | return ira->codegen->invalid_inst_gen; |
| 28617 | 29547 | |
| 28618 | 29548 | if (!type_has_bits(operand->value->type)) |
| 28619 | | return ir_const_void(ira, &instruction->base); |
| 29549 | return ir_const_void(ira, &instruction->base.base); |
| 28620 | 29550 | |
| 28621 | | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base); |
| 29551 | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base.base); |
| 28622 | 29552 | ira->new_irb.exec->need_err_code_spill = true; |
| 28623 | 29553 | |
| 28624 | | IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope, |
| 28625 | | instruction->base.source_node, operand, instruction->spill_id); |
| 28626 | | return &result->base; |
| 29554 | return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id); |
| 28627 | 29555 | } |
| 28628 | 29556 | |
| 28629 | | static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) { |
| 28630 | | IrInstruction *operand = instruction->begin->operand->child; |
| 29557 | static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) { |
| 29558 | IrInstGen *operand = instruction->begin->operand->child; |
| 28631 | 29559 | if (type_is_invalid(operand->value->type)) |
| 28632 | | return ira->codegen->invalid_instruction; |
| 29560 | return ira->codegen->invalid_inst_gen; |
| 28633 | 29561 | |
| 28634 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type)) |
| 29562 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || !type_has_bits(operand->value->type)) |
| 28635 | 29563 | return operand; |
| 28636 | 29564 | |
| 28637 | | ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base); |
| 28638 | | IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child); |
| 29565 | ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base); |
| 29566 | IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child); |
| 28639 | 29567 | |
| 28640 | | IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope, |
| 28641 | | instruction->base.source_node, begin); |
| 28642 | | result->value->type = operand->value->type; |
| 28643 | | return result; |
| 29568 | return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type); |
| 28644 | 29569 | } |
| 28645 | 29570 | |
| 28646 | | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { |
| 29571 | static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) { |
| 28647 | 29572 | switch (instruction->id) { |
| 28648 | | case IrInstructionIdInvalid: |
| 28649 | | case IrInstructionIdWidenOrShorten: |
| 28650 | | case IrInstructionIdStructFieldPtr: |
| 28651 | | case IrInstructionIdUnionFieldPtr: |
| 28652 | | case IrInstructionIdOptionalWrap: |
| 28653 | | case IrInstructionIdErrWrapCode: |
| 28654 | | case IrInstructionIdErrWrapPayload: |
| 28655 | | case IrInstructionIdCast: |
| 28656 | | case IrInstructionIdDeclVarGen: |
| 28657 | | case IrInstructionIdPtrCastGen: |
| 28658 | | case IrInstructionIdCmpxchgGen: |
| 28659 | | case IrInstructionIdArrayToVector: |
| 28660 | | case IrInstructionIdVectorToArray: |
| 28661 | | case IrInstructionIdPtrOfArrayToSlice: |
| 28662 | | case IrInstructionIdAssertZero: |
| 28663 | | case IrInstructionIdAssertNonNull: |
| 28664 | | case IrInstructionIdResizeSlice: |
| 28665 | | case IrInstructionIdLoadPtrGen: |
| 28666 | | case IrInstructionIdBitCastGen: |
| 28667 | | case IrInstructionIdCallGen: |
| 28668 | | case IrInstructionIdReturnPtr: |
| 28669 | | case IrInstructionIdAllocaGen: |
| 28670 | | case IrInstructionIdSliceGen: |
| 28671 | | case IrInstructionIdRefGen: |
| 28672 | | case IrInstructionIdTestErrGen: |
| 28673 | | case IrInstructionIdFrameSizeGen: |
| 28674 | | case IrInstructionIdAwaitGen: |
| 28675 | | case IrInstructionIdSplatGen: |
| 28676 | | case IrInstructionIdVectorExtractElem: |
| 28677 | | case IrInstructionIdVectorStoreElem: |
| 28678 | | case IrInstructionIdAsmGen: |
| 29573 | case IrInstSrcIdInvalid: |
| 28679 | 29574 | zig_unreachable(); |
| 28680 | 29575 | |
| 28681 | | case IrInstructionIdReturn: |
| 28682 | | return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction); |
| 28683 | | case IrInstructionIdConst: |
| 28684 | | return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction); |
| 28685 | | case IrInstructionIdUnOp: |
| 28686 | | return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction); |
| 28687 | | case IrInstructionIdBinOp: |
| 28688 | | return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction); |
| 28689 | | case IrInstructionIdMergeErrSets: |
| 28690 | | return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction); |
| 28691 | | case IrInstructionIdDeclVarSrc: |
| 28692 | | return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction); |
| 28693 | | case IrInstructionIdLoadPtr: |
| 28694 | | return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction); |
| 28695 | | case IrInstructionIdStorePtr: |
| 28696 | | return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction); |
| 28697 | | case IrInstructionIdElemPtr: |
| 28698 | | return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction); |
| 28699 | | case IrInstructionIdVarPtr: |
| 28700 | | return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction); |
| 28701 | | case IrInstructionIdFieldPtr: |
| 28702 | | return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction); |
| 28703 | | case IrInstructionIdCallSrc: |
| 28704 | | return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction); |
| 28705 | | case IrInstructionIdCallSrcArgs: |
| 28706 | | return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction); |
| 28707 | | case IrInstructionIdCallExtra: |
| 28708 | | return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction); |
| 28709 | | case IrInstructionIdBr: |
| 28710 | | return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction); |
| 28711 | | case IrInstructionIdCondBr: |
| 28712 | | return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction); |
| 28713 | | case IrInstructionIdUnreachable: |
| 28714 | | return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction); |
| 28715 | | case IrInstructionIdPhi: |
| 28716 | | return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction); |
| 28717 | | case IrInstructionIdTypeOf: |
| 28718 | | return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction); |
| 28719 | | case IrInstructionIdSetCold: |
| 28720 | | return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction); |
| 28721 | | case IrInstructionIdSetRuntimeSafety: |
| 28722 | | return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction); |
| 28723 | | case IrInstructionIdSetFloatMode: |
| 28724 | | return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction); |
| 28725 | | case IrInstructionIdAnyFrameType: |
| 28726 | | return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction); |
| 28727 | | case IrInstructionIdSliceType: |
| 28728 | | return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction); |
| 28729 | | case IrInstructionIdAsmSrc: |
| 28730 | | return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction); |
| 28731 | | case IrInstructionIdArrayType: |
| 28732 | | return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction); |
| 28733 | | case IrInstructionIdSizeOf: |
| 28734 | | return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction); |
| 28735 | | case IrInstructionIdTestNonNull: |
| 28736 | | return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction); |
| 28737 | | case IrInstructionIdOptionalUnwrapPtr: |
| 28738 | | return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction); |
| 28739 | | case IrInstructionIdClz: |
| 28740 | | return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction); |
| 28741 | | case IrInstructionIdCtz: |
| 28742 | | return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction); |
| 28743 | | case IrInstructionIdPopCount: |
| 28744 | | return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction); |
| 28745 | | case IrInstructionIdBswap: |
| 28746 | | return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction); |
| 28747 | | case IrInstructionIdBitReverse: |
| 28748 | | return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction); |
| 28749 | | case IrInstructionIdSwitchBr: |
| 28750 | | return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction); |
| 28751 | | case IrInstructionIdSwitchTarget: |
| 28752 | | return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction); |
| 28753 | | case IrInstructionIdSwitchVar: |
| 28754 | | return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction); |
| 28755 | | case IrInstructionIdSwitchElseVar: |
| 28756 | | return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction); |
| 28757 | | case IrInstructionIdUnionTag: |
| 28758 | | return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction); |
| 28759 | | case IrInstructionIdImport: |
| 28760 | | return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction); |
| 28761 | | case IrInstructionIdRef: |
| 28762 | | return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction); |
| 28763 | | case IrInstructionIdContainerInitList: |
| 28764 | | return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction); |
| 28765 | | case IrInstructionIdContainerInitFields: |
| 28766 | | return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction); |
| 28767 | | case IrInstructionIdCompileErr: |
| 28768 | | return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction); |
| 28769 | | case IrInstructionIdCompileLog: |
| 28770 | | return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction); |
| 28771 | | case IrInstructionIdErrName: |
| 28772 | | return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction); |
| 28773 | | case IrInstructionIdTypeName: |
| 28774 | | return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction); |
| 28775 | | case IrInstructionIdCImport: |
| 28776 | | return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction); |
| 28777 | | case IrInstructionIdCInclude: |
| 28778 | | return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction); |
| 28779 | | case IrInstructionIdCDefine: |
| 28780 | | return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction); |
| 28781 | | case IrInstructionIdCUndef: |
| 28782 | | return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction); |
| 28783 | | case IrInstructionIdEmbedFile: |
| 28784 | | return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction); |
| 28785 | | case IrInstructionIdCmpxchgSrc: |
| 28786 | | return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction); |
| 28787 | | case IrInstructionIdFence: |
| 28788 | | return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction); |
| 28789 | | case IrInstructionIdTruncate: |
| 28790 | | return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction); |
| 28791 | | case IrInstructionIdIntCast: |
| 28792 | | return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction); |
| 28793 | | case IrInstructionIdFloatCast: |
| 28794 | | return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction); |
| 28795 | | case IrInstructionIdErrSetCast: |
| 28796 | | return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction); |
| 28797 | | case IrInstructionIdFromBytes: |
| 28798 | | return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction); |
| 28799 | | case IrInstructionIdToBytes: |
| 28800 | | return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction); |
| 28801 | | case IrInstructionIdIntToFloat: |
| 28802 | | return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction); |
| 28803 | | case IrInstructionIdFloatToInt: |
| 28804 | | return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction); |
| 28805 | | case IrInstructionIdBoolToInt: |
| 28806 | | return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction); |
| 28807 | | case IrInstructionIdIntType: |
| 28808 | | return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction); |
| 28809 | | case IrInstructionIdVectorType: |
| 28810 | | return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction); |
| 28811 | | case IrInstructionIdShuffleVector: |
| 28812 | | return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction); |
| 28813 | | case IrInstructionIdSplatSrc: |
| 28814 | | return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction); |
| 28815 | | case IrInstructionIdBoolNot: |
| 28816 | | return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction); |
| 28817 | | case IrInstructionIdMemset: |
| 28818 | | return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction); |
| 28819 | | case IrInstructionIdMemcpy: |
| 28820 | | return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction); |
| 28821 | | case IrInstructionIdSliceSrc: |
| 28822 | | return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction); |
| 28823 | | case IrInstructionIdMemberCount: |
| 28824 | | return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction); |
| 28825 | | case IrInstructionIdMemberType: |
| 28826 | | return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction); |
| 28827 | | case IrInstructionIdMemberName: |
| 28828 | | return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction); |
| 28829 | | case IrInstructionIdBreakpoint: |
| 28830 | | return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction); |
| 28831 | | case IrInstructionIdReturnAddress: |
| 28832 | | return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction); |
| 28833 | | case IrInstructionIdFrameAddress: |
| 28834 | | return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction); |
| 28835 | | case IrInstructionIdFrameHandle: |
| 28836 | | return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction); |
| 28837 | | case IrInstructionIdFrameType: |
| 28838 | | return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction); |
| 28839 | | case IrInstructionIdFrameSizeSrc: |
| 28840 | | return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction); |
| 28841 | | case IrInstructionIdAlignOf: |
| 28842 | | return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction); |
| 28843 | | case IrInstructionIdOverflowOp: |
| 28844 | | return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction); |
| 28845 | | case IrInstructionIdTestErrSrc: |
| 28846 | | return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction); |
| 28847 | | case IrInstructionIdUnwrapErrCode: |
| 28848 | | return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction); |
| 28849 | | case IrInstructionIdUnwrapErrPayload: |
| 28850 | | return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction); |
| 28851 | | case IrInstructionIdFnProto: |
| 28852 | | return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction); |
| 28853 | | case IrInstructionIdTestComptime: |
| 28854 | | return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction); |
| 28855 | | case IrInstructionIdCheckSwitchProngs: |
| 28856 | | return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction); |
| 28857 | | case IrInstructionIdCheckStatementIsVoid: |
| 28858 | | return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction); |
| 28859 | | case IrInstructionIdDeclRef: |
| 28860 | | return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction); |
| 28861 | | case IrInstructionIdPanic: |
| 28862 | | return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction); |
| 28863 | | case IrInstructionIdPtrCastSrc: |
| 28864 | | return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction); |
| 28865 | | case IrInstructionIdIntToPtr: |
| 28866 | | return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction); |
| 28867 | | case IrInstructionIdPtrToInt: |
| 28868 | | return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction); |
| 28869 | | case IrInstructionIdTagName: |
| 28870 | | return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction); |
| 28871 | | case IrInstructionIdFieldParentPtr: |
| 28872 | | return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction); |
| 28873 | | case IrInstructionIdByteOffsetOf: |
| 28874 | | return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction); |
| 28875 | | case IrInstructionIdBitOffsetOf: |
| 28876 | | return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction); |
| 28877 | | case IrInstructionIdTypeInfo: |
| 28878 | | return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction); |
| 28879 | | case IrInstructionIdType: |
| 28880 | | return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction); |
| 28881 | | case IrInstructionIdHasField: |
| 28882 | | return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction); |
| 28883 | | case IrInstructionIdTypeId: |
| 28884 | | return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction); |
| 28885 | | case IrInstructionIdSetEvalBranchQuota: |
| 28886 | | return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction); |
| 28887 | | case IrInstructionIdPtrType: |
| 28888 | | return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction); |
| 28889 | | case IrInstructionIdAlignCast: |
| 28890 | | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); |
| 28891 | | case IrInstructionIdImplicitCast: |
| 28892 | | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| 28893 | | case IrInstructionIdResolveResult: |
| 28894 | | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); |
| 28895 | | case IrInstructionIdResetResult: |
| 28896 | | return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction); |
| 28897 | | case IrInstructionIdOpaqueType: |
| 28898 | | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 28899 | | case IrInstructionIdSetAlignStack: |
| 28900 | | return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction); |
| 28901 | | case IrInstructionIdArgType: |
| 28902 | | return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction); |
| 28903 | | case IrInstructionIdTagType: |
| 28904 | | return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction); |
| 28905 | | case IrInstructionIdExport: |
| 28906 | | return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction); |
| 28907 | | case IrInstructionIdErrorReturnTrace: |
| 28908 | | return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction); |
| 28909 | | case IrInstructionIdErrorUnion: |
| 28910 | | return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction); |
| 28911 | | case IrInstructionIdAtomicRmw: |
| 28912 | | return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction); |
| 28913 | | case IrInstructionIdAtomicLoad: |
| 28914 | | return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction); |
| 28915 | | case IrInstructionIdAtomicStore: |
| 28916 | | return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction); |
| 28917 | | case IrInstructionIdSaveErrRetAddr: |
| 28918 | | return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction); |
| 28919 | | case IrInstructionIdAddImplicitReturnType: |
| 28920 | | return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction); |
| 28921 | | case IrInstructionIdFloatOp: |
| 28922 | | return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction); |
| 28923 | | case IrInstructionIdMulAdd: |
| 28924 | | return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction); |
| 28925 | | case IrInstructionIdIntToErr: |
| 28926 | | return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction); |
| 28927 | | case IrInstructionIdErrToInt: |
| 28928 | | return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction); |
| 28929 | | case IrInstructionIdIntToEnum: |
| 28930 | | return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction); |
| 28931 | | case IrInstructionIdEnumToInt: |
| 28932 | | return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction); |
| 28933 | | case IrInstructionIdCheckRuntimeScope: |
| 28934 | | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); |
| 28935 | | case IrInstructionIdHasDecl: |
| 28936 | | return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction); |
| 28937 | | case IrInstructionIdUndeclaredIdent: |
| 28938 | | return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction); |
| 28939 | | case IrInstructionIdAllocaSrc: |
| 29576 | case IrInstSrcIdReturn: |
| 29577 | return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction); |
| 29578 | case IrInstSrcIdConst: |
| 29579 | return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction); |
| 29580 | case IrInstSrcIdUnOp: |
| 29581 | return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction); |
| 29582 | case IrInstSrcIdBinOp: |
| 29583 | return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction); |
| 29584 | case IrInstSrcIdMergeErrSets: |
| 29585 | return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction); |
| 29586 | case IrInstSrcIdDeclVar: |
| 29587 | return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction); |
| 29588 | case IrInstSrcIdLoadPtr: |
| 29589 | return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction); |
| 29590 | case IrInstSrcIdStorePtr: |
| 29591 | return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction); |
| 29592 | case IrInstSrcIdElemPtr: |
| 29593 | return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction); |
| 29594 | case IrInstSrcIdVarPtr: |
| 29595 | return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction); |
| 29596 | case IrInstSrcIdFieldPtr: |
| 29597 | return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction); |
| 29598 | case IrInstSrcIdCall: |
| 29599 | return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction); |
| 29600 | case IrInstSrcIdCallArgs: |
| 29601 | return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction); |
| 29602 | case IrInstSrcIdCallExtra: |
| 29603 | return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction); |
| 29604 | case IrInstSrcIdBr: |
| 29605 | return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction); |
| 29606 | case IrInstSrcIdCondBr: |
| 29607 | return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction); |
| 29608 | case IrInstSrcIdUnreachable: |
| 29609 | return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction); |
| 29610 | case IrInstSrcIdPhi: |
| 29611 | return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction); |
| 29612 | case IrInstSrcIdTypeOf: |
| 29613 | return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction); |
| 29614 | case IrInstSrcIdSetCold: |
| 29615 | return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction); |
| 29616 | case IrInstSrcIdSetRuntimeSafety: |
| 29617 | return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction); |
| 29618 | case IrInstSrcIdSetFloatMode: |
| 29619 | return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction); |
| 29620 | case IrInstSrcIdAnyFrameType: |
| 29621 | return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction); |
| 29622 | case IrInstSrcIdSliceType: |
| 29623 | return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction); |
| 29624 | case IrInstSrcIdAsm: |
| 29625 | return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction); |
| 29626 | case IrInstSrcIdArrayType: |
| 29627 | return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction); |
| 29628 | case IrInstSrcIdSizeOf: |
| 29629 | return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction); |
| 29630 | case IrInstSrcIdTestNonNull: |
| 29631 | return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction); |
| 29632 | case IrInstSrcIdOptionalUnwrapPtr: |
| 29633 | return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction); |
| 29634 | case IrInstSrcIdClz: |
| 29635 | return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction); |
| 29636 | case IrInstSrcIdCtz: |
| 29637 | return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction); |
| 29638 | case IrInstSrcIdPopCount: |
| 29639 | return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction); |
| 29640 | case IrInstSrcIdBswap: |
| 29641 | return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction); |
| 29642 | case IrInstSrcIdBitReverse: |
| 29643 | return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction); |
| 29644 | case IrInstSrcIdSwitchBr: |
| 29645 | return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction); |
| 29646 | case IrInstSrcIdSwitchTarget: |
| 29647 | return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction); |
| 29648 | case IrInstSrcIdSwitchVar: |
| 29649 | return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction); |
| 29650 | case IrInstSrcIdSwitchElseVar: |
| 29651 | return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction); |
| 29652 | case IrInstSrcIdImport: |
| 29653 | return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction); |
| 29654 | case IrInstSrcIdRef: |
| 29655 | return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction); |
| 29656 | case IrInstSrcIdContainerInitList: |
| 29657 | return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction); |
| 29658 | case IrInstSrcIdContainerInitFields: |
| 29659 | return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction); |
| 29660 | case IrInstSrcIdCompileErr: |
| 29661 | return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction); |
| 29662 | case IrInstSrcIdCompileLog: |
| 29663 | return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction); |
| 29664 | case IrInstSrcIdErrName: |
| 29665 | return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction); |
| 29666 | case IrInstSrcIdTypeName: |
| 29667 | return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction); |
| 29668 | case IrInstSrcIdCImport: |
| 29669 | return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction); |
| 29670 | case IrInstSrcIdCInclude: |
| 29671 | return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction); |
| 29672 | case IrInstSrcIdCDefine: |
| 29673 | return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction); |
| 29674 | case IrInstSrcIdCUndef: |
| 29675 | return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction); |
| 29676 | case IrInstSrcIdEmbedFile: |
| 29677 | return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction); |
| 29678 | case IrInstSrcIdCmpxchg: |
| 29679 | return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction); |
| 29680 | case IrInstSrcIdFence: |
| 29681 | return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction); |
| 29682 | case IrInstSrcIdTruncate: |
| 29683 | return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction); |
| 29684 | case IrInstSrcIdIntCast: |
| 29685 | return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction); |
| 29686 | case IrInstSrcIdFloatCast: |
| 29687 | return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction); |
| 29688 | case IrInstSrcIdErrSetCast: |
| 29689 | return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction); |
| 29690 | case IrInstSrcIdFromBytes: |
| 29691 | return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction); |
| 29692 | case IrInstSrcIdToBytes: |
| 29693 | return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction); |
| 29694 | case IrInstSrcIdIntToFloat: |
| 29695 | return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction); |
| 29696 | case IrInstSrcIdFloatToInt: |
| 29697 | return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction); |
| 29698 | case IrInstSrcIdBoolToInt: |
| 29699 | return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction); |
| 29700 | case IrInstSrcIdIntType: |
| 29701 | return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction); |
| 29702 | case IrInstSrcIdVectorType: |
| 29703 | return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction); |
| 29704 | case IrInstSrcIdShuffleVector: |
| 29705 | return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction); |
| 29706 | case IrInstSrcIdSplat: |
| 29707 | return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction); |
| 29708 | case IrInstSrcIdBoolNot: |
| 29709 | return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction); |
| 29710 | case IrInstSrcIdMemset: |
| 29711 | return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction); |
| 29712 | case IrInstSrcIdMemcpy: |
| 29713 | return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction); |
| 29714 | case IrInstSrcIdSlice: |
| 29715 | return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction); |
| 29716 | case IrInstSrcIdMemberCount: |
| 29717 | return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction); |
| 29718 | case IrInstSrcIdMemberType: |
| 29719 | return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction); |
| 29720 | case IrInstSrcIdMemberName: |
| 29721 | return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction); |
| 29722 | case IrInstSrcIdBreakpoint: |
| 29723 | return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction); |
| 29724 | case IrInstSrcIdReturnAddress: |
| 29725 | return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction); |
| 29726 | case IrInstSrcIdFrameAddress: |
| 29727 | return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction); |
| 29728 | case IrInstSrcIdFrameHandle: |
| 29729 | return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction); |
| 29730 | case IrInstSrcIdFrameType: |
| 29731 | return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction); |
| 29732 | case IrInstSrcIdFrameSize: |
| 29733 | return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction); |
| 29734 | case IrInstSrcIdAlignOf: |
| 29735 | return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction); |
| 29736 | case IrInstSrcIdOverflowOp: |
| 29737 | return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction); |
| 29738 | case IrInstSrcIdTestErr: |
| 29739 | return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction); |
| 29740 | case IrInstSrcIdUnwrapErrCode: |
| 29741 | return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction); |
| 29742 | case IrInstSrcIdUnwrapErrPayload: |
| 29743 | return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction); |
| 29744 | case IrInstSrcIdFnProto: |
| 29745 | return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction); |
| 29746 | case IrInstSrcIdTestComptime: |
| 29747 | return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction); |
| 29748 | case IrInstSrcIdCheckSwitchProngs: |
| 29749 | return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction); |
| 29750 | case IrInstSrcIdCheckStatementIsVoid: |
| 29751 | return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction); |
| 29752 | case IrInstSrcIdDeclRef: |
| 29753 | return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction); |
| 29754 | case IrInstSrcIdPanic: |
| 29755 | return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction); |
| 29756 | case IrInstSrcIdPtrCast: |
| 29757 | return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction); |
| 29758 | case IrInstSrcIdIntToPtr: |
| 29759 | return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction); |
| 29760 | case IrInstSrcIdPtrToInt: |
| 29761 | return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction); |
| 29762 | case IrInstSrcIdTagName: |
| 29763 | return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction); |
| 29764 | case IrInstSrcIdFieldParentPtr: |
| 29765 | return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction); |
| 29766 | case IrInstSrcIdByteOffsetOf: |
| 29767 | return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction); |
| 29768 | case IrInstSrcIdBitOffsetOf: |
| 29769 | return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction); |
| 29770 | case IrInstSrcIdTypeInfo: |
| 29771 | return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction); |
| 29772 | case IrInstSrcIdType: |
| 29773 | return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction); |
| 29774 | case IrInstSrcIdHasField: |
| 29775 | return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction); |
| 29776 | case IrInstSrcIdTypeId: |
| 29777 | return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction); |
| 29778 | case IrInstSrcIdSetEvalBranchQuota: |
| 29779 | return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction); |
| 29780 | case IrInstSrcIdPtrType: |
| 29781 | return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction); |
| 29782 | case IrInstSrcIdAlignCast: |
| 29783 | return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction); |
| 29784 | case IrInstSrcIdImplicitCast: |
| 29785 | return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction); |
| 29786 | case IrInstSrcIdResolveResult: |
| 29787 | return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction); |
| 29788 | case IrInstSrcIdResetResult: |
| 29789 | return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction); |
| 29790 | case IrInstSrcIdOpaqueType: |
| 29791 | return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction); |
| 29792 | case IrInstSrcIdSetAlignStack: |
| 29793 | return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction); |
| 29794 | case IrInstSrcIdArgType: |
| 29795 | return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction); |
| 29796 | case IrInstSrcIdTagType: |
| 29797 | return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction); |
| 29798 | case IrInstSrcIdExport: |
| 29799 | return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction); |
| 29800 | case IrInstSrcIdErrorReturnTrace: |
| 29801 | return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction); |
| 29802 | case IrInstSrcIdErrorUnion: |
| 29803 | return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction); |
| 29804 | case IrInstSrcIdAtomicRmw: |
| 29805 | return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction); |
| 29806 | case IrInstSrcIdAtomicLoad: |
| 29807 | return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction); |
| 29808 | case IrInstSrcIdAtomicStore: |
| 29809 | return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction); |
| 29810 | case IrInstSrcIdSaveErrRetAddr: |
| 29811 | return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction); |
| 29812 | case IrInstSrcIdAddImplicitReturnType: |
| 29813 | return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction); |
| 29814 | case IrInstSrcIdFloatOp: |
| 29815 | return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction); |
| 29816 | case IrInstSrcIdMulAdd: |
| 29817 | return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction); |
| 29818 | case IrInstSrcIdIntToErr: |
| 29819 | return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction); |
| 29820 | case IrInstSrcIdErrToInt: |
| 29821 | return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction); |
| 29822 | case IrInstSrcIdIntToEnum: |
| 29823 | return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction); |
| 29824 | case IrInstSrcIdEnumToInt: |
| 29825 | return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction); |
| 29826 | case IrInstSrcIdCheckRuntimeScope: |
| 29827 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction); |
| 29828 | case IrInstSrcIdHasDecl: |
| 29829 | return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction); |
| 29830 | case IrInstSrcIdUndeclaredIdent: |
| 29831 | return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction); |
| 29832 | case IrInstSrcIdAlloca: |
| 28940 | 29833 | return nullptr; |
| 28941 | | case IrInstructionIdEndExpr: |
| 28942 | | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); |
| 28943 | | case IrInstructionIdBitCastSrc: |
| 28944 | | return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction); |
| 28945 | | case IrInstructionIdUnionInitNamedField: |
| 28946 | | return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction); |
| 28947 | | case IrInstructionIdSuspendBegin: |
| 28948 | | return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction); |
| 28949 | | case IrInstructionIdSuspendFinish: |
| 28950 | | return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction); |
| 28951 | | case IrInstructionIdResume: |
| 28952 | | return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction); |
| 28953 | | case IrInstructionIdAwaitSrc: |
| 28954 | | return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction); |
| 28955 | | case IrInstructionIdSpillBegin: |
| 28956 | | return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction); |
| 28957 | | case IrInstructionIdSpillEnd: |
| 28958 | | return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction); |
| 29834 | case IrInstSrcIdEndExpr: |
| 29835 | return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction); |
| 29836 | case IrInstSrcIdBitCast: |
| 29837 | return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction); |
| 29838 | case IrInstSrcIdUnionInitNamedField: |
| 29839 | return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction); |
| 29840 | case IrInstSrcIdSuspendBegin: |
| 29841 | return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction); |
| 29842 | case IrInstSrcIdSuspendFinish: |
| 29843 | return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction); |
| 29844 | case IrInstSrcIdResume: |
| 29845 | return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction); |
| 29846 | case IrInstSrcIdAwait: |
| 29847 | return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction); |
| 29848 | case IrInstSrcIdSpillBegin: |
| 29849 | return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction); |
| 29850 | case IrInstSrcIdSpillEnd: |
| 29851 | return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction); |
| 28959 | 29852 | } |
| 28960 | 29853 | zig_unreachable(); |
| 28961 | 29854 | } |
| 28962 | 29855 | |
| 28963 | 29856 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 28964 | | // It emits a new IrExecutable which is partially evaluated IR code. |
| 28965 | | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 28966 | | ZigType *expected_type, AstNode *expected_type_source_node) |
| 29857 | // It emits to a new IrExecutableGen which is partially evaluated IR code. |
| 29858 | ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec, |
| 29859 | ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr) |
| 28967 | 29860 | { |
| 28968 | 29861 | assert(old_exec->first_err_trace_msg == nullptr); |
| 28969 | 29862 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); |
| ... | ... | @@ -28982,24 +29875,31 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 28982 | 29875 | ira->new_irb.codegen = codegen; |
| 28983 | 29876 | ira->new_irb.exec = new_exec; |
| 28984 | 29877 | |
| 28985 | | ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); |
| 28986 | | ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); |
| 28987 | | for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { |
| 28988 | | ira->exec_context.mem_slot_list.items[i] = &vals[i]; |
| 28989 | | } |
| 28990 | | |
| 28991 | | IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 28992 | | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 28993 | | ir_ref_bb(new_entry_bb); |
| 29878 | IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 29879 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 29880 | ir_ref_bb_gen(new_entry_bb); |
| 28994 | 29881 | ira->new_irb.current_basic_block = new_entry_bb; |
| 28995 | 29882 | ira->old_bb_index = 0; |
| 28996 | 29883 | |
| 28997 | 29884 | ir_start_bb(ira, old_entry_bb, nullptr); |
| 28998 | 29885 | |
| 29886 | if (result_ptr != nullptr) { |
| 29887 | assert(result_ptr->type->id == ZigTypeIdPointer); |
| 29888 | IrInstGenConst *const_inst = ir_create_inst_noval<IrInstGenConst>( |
| 29889 | &ira->new_irb, new_exec->begin_scope, new_exec->source_node); |
| 29890 | const_inst->base.value = result_ptr; |
| 29891 | ira->return_ptr = &const_inst->base; |
| 29892 | } else { |
| 29893 | assert(new_exec->begin_scope != nullptr); |
| 29894 | assert(new_exec->source_node != nullptr); |
| 29895 | ira->return_ptr = ir_build_return_ptr(ira, new_exec->begin_scope, new_exec->source_node, |
| 29896 | get_pointer_to_type(codegen, expected_type, false)); |
| 29897 | } |
| 29898 | |
| 28999 | 29899 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 29000 | | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 29900 | IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 29001 | 29901 | |
| 29002 | | if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) { |
| 29902 | if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { |
| 29003 | 29903 | ira->instruction_index += 1; |
| 29004 | 29904 | continue; |
| 29005 | 29905 | } |
| ... | ... | @@ -29008,14 +29908,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29008 | 29908 | fprintf(stderr, "~ "); |
| 29009 | 29909 | old_instruction->src(); |
| 29010 | 29910 | fprintf(stderr, "~ "); |
| 29011 | | ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc); |
| 29911 | ir_print_inst_src(codegen, stderr, old_instruction, 0); |
| 29012 | 29912 | bool want_break = false; |
| 29013 | | if (ira->break_debug_id == old_instruction->debug_id) { |
| 29913 | if (ira->break_debug_id == old_instruction->base.debug_id) { |
| 29014 | 29914 | want_break = true; |
| 29015 | | } else if (old_instruction->source_node != nullptr) { |
| 29915 | } else if (old_instruction->base.source_node != nullptr) { |
| 29016 | 29916 | for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) { |
| 29017 | | if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 && |
| 29018 | | buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path, |
| 29917 | if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 && |
| 29918 | buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path, |
| 29019 | 29919 | dbg_ir_breakpoints_buf[i].src_file)) |
| 29020 | 29920 | { |
| 29021 | 29921 | want_break = true; |
| ... | ... | @@ -29024,9 +29924,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29024 | 29924 | } |
| 29025 | 29925 | if (want_break) BREAKPOINT; |
| 29026 | 29926 | } |
| 29027 | | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 29927 | IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 29028 | 29928 | if (new_instruction != nullptr) { |
| 29029 | | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction); |
| 29929 | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base); |
| 29030 | 29930 | old_instruction->child = new_instruction; |
| 29031 | 29931 | |
| 29032 | 29932 | if (type_is_invalid(new_instruction->value->type)) { |
| ... | ... | @@ -29040,19 +29940,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29040 | 29940 | new_exec->first_err_trace_msg = ira->codegen->trace_err; |
| 29041 | 29941 | } |
| 29042 | 29942 | if (new_exec->first_err_trace_msg != nullptr && |
| 29043 | | !old_instruction->source_node->already_traced_this_node) |
| 29943 | !old_instruction->base.source_node->already_traced_this_node) |
| 29044 | 29944 | { |
| 29045 | | old_instruction->source_node->already_traced_this_node = true; |
| 29945 | old_instruction->base.source_node->already_traced_this_node = true; |
| 29046 | 29946 | new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg, |
| 29047 | | old_instruction->source_node, buf_create_from_str("referenced here")); |
| 29947 | old_instruction->base.source_node, buf_create_from_str("referenced here")); |
| 29048 | 29948 | } |
| 29049 | 29949 | return ira->codegen->builtin_types.entry_invalid; |
| 29050 | 29950 | } else if (ira->codegen->verbose_ir) { |
| 29051 | 29951 | fprintf(stderr, "-> "); |
| 29052 | | if (instr_is_unreachable(new_instruction)) { |
| 29952 | if (new_instruction->value->type->id == ZigTypeIdUnreachable) { |
| 29053 | 29953 | fprintf(stderr, "(noreturn)\n"); |
| 29054 | 29954 | } else { |
| 29055 | | ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen); |
| 29955 | ir_print_inst_gen(codegen, stderr, new_instruction, 0); |
| 29056 | 29956 | } |
| 29057 | 29957 | } |
| 29058 | 29958 | |
| ... | ... | @@ -29092,204 +29992,280 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29092 | 29992 | return res_type; |
| 29093 | 29993 | } |
| 29094 | 29994 | |
| 29095 | | bool ir_has_side_effects(IrInstruction *instruction) { |
| 29995 | bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { |
| 29096 | 29996 | switch (instruction->id) { |
| 29097 | | case IrInstructionIdInvalid: |
| 29997 | case IrInstGenIdInvalid: |
| 29098 | 29998 | zig_unreachable(); |
| 29099 | | case IrInstructionIdBr: |
| 29100 | | case IrInstructionIdCondBr: |
| 29101 | | case IrInstructionIdSwitchBr: |
| 29102 | | case IrInstructionIdDeclVarSrc: |
| 29103 | | case IrInstructionIdDeclVarGen: |
| 29104 | | case IrInstructionIdStorePtr: |
| 29105 | | case IrInstructionIdVectorStoreElem: |
| 29106 | | case IrInstructionIdCallExtra: |
| 29107 | | case IrInstructionIdCallSrc: |
| 29108 | | case IrInstructionIdCallSrcArgs: |
| 29109 | | case IrInstructionIdCallGen: |
| 29110 | | case IrInstructionIdReturn: |
| 29111 | | case IrInstructionIdUnreachable: |
| 29112 | | case IrInstructionIdSetCold: |
| 29113 | | case IrInstructionIdSetRuntimeSafety: |
| 29114 | | case IrInstructionIdSetFloatMode: |
| 29115 | | case IrInstructionIdImport: |
| 29116 | | case IrInstructionIdCompileErr: |
| 29117 | | case IrInstructionIdCompileLog: |
| 29118 | | case IrInstructionIdCImport: |
| 29119 | | case IrInstructionIdCInclude: |
| 29120 | | case IrInstructionIdCDefine: |
| 29121 | | case IrInstructionIdCUndef: |
| 29122 | | case IrInstructionIdFence: |
| 29123 | | case IrInstructionIdMemset: |
| 29124 | | case IrInstructionIdMemcpy: |
| 29125 | | case IrInstructionIdBreakpoint: |
| 29126 | | case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 29127 | | case IrInstructionIdCheckSwitchProngs: |
| 29128 | | case IrInstructionIdCheckStatementIsVoid: |
| 29129 | | case IrInstructionIdCheckRuntimeScope: |
| 29130 | | case IrInstructionIdPanic: |
| 29131 | | case IrInstructionIdSetEvalBranchQuota: |
| 29132 | | case IrInstructionIdPtrType: |
| 29133 | | case IrInstructionIdSetAlignStack: |
| 29134 | | case IrInstructionIdExport: |
| 29135 | | case IrInstructionIdSaveErrRetAddr: |
| 29136 | | case IrInstructionIdAddImplicitReturnType: |
| 29137 | | case IrInstructionIdAtomicRmw: |
| 29138 | | case IrInstructionIdAtomicStore: |
| 29139 | | case IrInstructionIdCmpxchgGen: |
| 29140 | | case IrInstructionIdCmpxchgSrc: |
| 29141 | | case IrInstructionIdAssertZero: |
| 29142 | | case IrInstructionIdAssertNonNull: |
| 29143 | | case IrInstructionIdResizeSlice: |
| 29144 | | case IrInstructionIdUndeclaredIdent: |
| 29145 | | case IrInstructionIdEndExpr: |
| 29146 | | case IrInstructionIdPtrOfArrayToSlice: |
| 29147 | | case IrInstructionIdSliceGen: |
| 29148 | | case IrInstructionIdOptionalWrap: |
| 29149 | | case IrInstructionIdVectorToArray: |
| 29150 | | case IrInstructionIdResetResult: |
| 29151 | | case IrInstructionIdSuspendBegin: |
| 29152 | | case IrInstructionIdSuspendFinish: |
| 29153 | | case IrInstructionIdResume: |
| 29154 | | case IrInstructionIdAwaitSrc: |
| 29155 | | case IrInstructionIdAwaitGen: |
| 29156 | | case IrInstructionIdSpillBegin: |
| 29999 | case IrInstGenIdBr: |
| 30000 | case IrInstGenIdCondBr: |
| 30001 | case IrInstGenIdSwitchBr: |
| 30002 | case IrInstGenIdDeclVar: |
| 30003 | case IrInstGenIdStorePtr: |
| 30004 | case IrInstGenIdVectorStoreElem: |
| 30005 | case IrInstGenIdCall: |
| 30006 | case IrInstGenIdReturn: |
| 30007 | case IrInstGenIdUnreachable: |
| 30008 | case IrInstGenIdFence: |
| 30009 | case IrInstGenIdMemset: |
| 30010 | case IrInstGenIdMemcpy: |
| 30011 | case IrInstGenIdBreakpoint: |
| 30012 | case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 30013 | case IrInstGenIdPanic: |
| 30014 | case IrInstGenIdSaveErrRetAddr: |
| 30015 | case IrInstGenIdAtomicRmw: |
| 30016 | case IrInstGenIdAtomicStore: |
| 30017 | case IrInstGenIdCmpxchg: |
| 30018 | case IrInstGenIdAssertZero: |
| 30019 | case IrInstGenIdAssertNonNull: |
| 30020 | case IrInstGenIdResizeSlice: |
| 30021 | case IrInstGenIdPtrOfArrayToSlice: |
| 30022 | case IrInstGenIdSlice: |
| 30023 | case IrInstGenIdOptionalWrap: |
| 30024 | case IrInstGenIdVectorToArray: |
| 30025 | case IrInstGenIdSuspendBegin: |
| 30026 | case IrInstGenIdSuspendFinish: |
| 30027 | case IrInstGenIdResume: |
| 30028 | case IrInstGenIdAwait: |
| 30029 | case IrInstGenIdSpillBegin: |
| 29157 | 30030 | return true; |
| 29158 | 30031 | |
| 29159 | | case IrInstructionIdPhi: |
| 29160 | | case IrInstructionIdUnOp: |
| 29161 | | case IrInstructionIdBinOp: |
| 29162 | | case IrInstructionIdMergeErrSets: |
| 29163 | | case IrInstructionIdLoadPtr: |
| 29164 | | case IrInstructionIdConst: |
| 29165 | | case IrInstructionIdCast: |
| 29166 | | case IrInstructionIdContainerInitList: |
| 29167 | | case IrInstructionIdContainerInitFields: |
| 29168 | | case IrInstructionIdUnionInitNamedField: |
| 29169 | | case IrInstructionIdFieldPtr: |
| 29170 | | case IrInstructionIdElemPtr: |
| 29171 | | case IrInstructionIdVarPtr: |
| 29172 | | case IrInstructionIdReturnPtr: |
| 29173 | | case IrInstructionIdTypeOf: |
| 29174 | | case IrInstructionIdStructFieldPtr: |
| 29175 | | case IrInstructionIdArrayType: |
| 29176 | | case IrInstructionIdSliceType: |
| 29177 | | case IrInstructionIdAnyFrameType: |
| 29178 | | case IrInstructionIdSizeOf: |
| 29179 | | case IrInstructionIdTestNonNull: |
| 29180 | | case IrInstructionIdOptionalUnwrapPtr: |
| 29181 | | case IrInstructionIdClz: |
| 29182 | | case IrInstructionIdCtz: |
| 29183 | | case IrInstructionIdPopCount: |
| 29184 | | case IrInstructionIdBswap: |
| 29185 | | case IrInstructionIdBitReverse: |
| 29186 | | case IrInstructionIdSwitchVar: |
| 29187 | | case IrInstructionIdSwitchElseVar: |
| 29188 | | case IrInstructionIdSwitchTarget: |
| 29189 | | case IrInstructionIdUnionTag: |
| 29190 | | case IrInstructionIdRef: |
| 29191 | | case IrInstructionIdEmbedFile: |
| 29192 | | case IrInstructionIdTruncate: |
| 29193 | | case IrInstructionIdIntType: |
| 29194 | | case IrInstructionIdVectorType: |
| 29195 | | case IrInstructionIdShuffleVector: |
| 29196 | | case IrInstructionIdSplatSrc: |
| 29197 | | case IrInstructionIdSplatGen: |
| 29198 | | case IrInstructionIdBoolNot: |
| 29199 | | case IrInstructionIdSliceSrc: |
| 29200 | | case IrInstructionIdMemberCount: |
| 29201 | | case IrInstructionIdMemberType: |
| 29202 | | case IrInstructionIdMemberName: |
| 29203 | | case IrInstructionIdAlignOf: |
| 29204 | | case IrInstructionIdReturnAddress: |
| 29205 | | case IrInstructionIdFrameAddress: |
| 29206 | | case IrInstructionIdFrameHandle: |
| 29207 | | case IrInstructionIdFrameType: |
| 29208 | | case IrInstructionIdFrameSizeSrc: |
| 29209 | | case IrInstructionIdFrameSizeGen: |
| 29210 | | case IrInstructionIdTestErrSrc: |
| 29211 | | case IrInstructionIdTestErrGen: |
| 29212 | | case IrInstructionIdFnProto: |
| 29213 | | case IrInstructionIdTestComptime: |
| 29214 | | case IrInstructionIdPtrCastSrc: |
| 29215 | | case IrInstructionIdPtrCastGen: |
| 29216 | | case IrInstructionIdBitCastSrc: |
| 29217 | | case IrInstructionIdBitCastGen: |
| 29218 | | case IrInstructionIdWidenOrShorten: |
| 29219 | | case IrInstructionIdPtrToInt: |
| 29220 | | case IrInstructionIdIntToPtr: |
| 29221 | | case IrInstructionIdIntToEnum: |
| 29222 | | case IrInstructionIdIntToErr: |
| 29223 | | case IrInstructionIdErrToInt: |
| 29224 | | case IrInstructionIdDeclRef: |
| 29225 | | case IrInstructionIdErrName: |
| 29226 | | case IrInstructionIdTypeName: |
| 29227 | | case IrInstructionIdTagName: |
| 29228 | | case IrInstructionIdFieldParentPtr: |
| 29229 | | case IrInstructionIdByteOffsetOf: |
| 29230 | | case IrInstructionIdBitOffsetOf: |
| 29231 | | case IrInstructionIdTypeInfo: |
| 29232 | | case IrInstructionIdType: |
| 29233 | | case IrInstructionIdHasField: |
| 29234 | | case IrInstructionIdTypeId: |
| 29235 | | case IrInstructionIdAlignCast: |
| 29236 | | case IrInstructionIdImplicitCast: |
| 29237 | | case IrInstructionIdResolveResult: |
| 29238 | | case IrInstructionIdOpaqueType: |
| 29239 | | case IrInstructionIdArgType: |
| 29240 | | case IrInstructionIdTagType: |
| 29241 | | case IrInstructionIdErrorReturnTrace: |
| 29242 | | case IrInstructionIdErrorUnion: |
| 29243 | | case IrInstructionIdFloatOp: |
| 29244 | | case IrInstructionIdMulAdd: |
| 29245 | | case IrInstructionIdAtomicLoad: |
| 29246 | | case IrInstructionIdIntCast: |
| 29247 | | case IrInstructionIdFloatCast: |
| 29248 | | case IrInstructionIdErrSetCast: |
| 29249 | | case IrInstructionIdIntToFloat: |
| 29250 | | case IrInstructionIdFloatToInt: |
| 29251 | | case IrInstructionIdBoolToInt: |
| 29252 | | case IrInstructionIdFromBytes: |
| 29253 | | case IrInstructionIdToBytes: |
| 29254 | | case IrInstructionIdEnumToInt: |
| 29255 | | case IrInstructionIdArrayToVector: |
| 29256 | | case IrInstructionIdHasDecl: |
| 29257 | | case IrInstructionIdAllocaSrc: |
| 29258 | | case IrInstructionIdAllocaGen: |
| 29259 | | case IrInstructionIdSpillEnd: |
| 29260 | | case IrInstructionIdVectorExtractElem: |
| 30032 | case IrInstGenIdPhi: |
| 30033 | case IrInstGenIdBinOp: |
| 30034 | case IrInstGenIdConst: |
| 30035 | case IrInstGenIdCast: |
| 30036 | case IrInstGenIdElemPtr: |
| 30037 | case IrInstGenIdVarPtr: |
| 30038 | case IrInstGenIdReturnPtr: |
| 30039 | case IrInstGenIdStructFieldPtr: |
| 30040 | case IrInstGenIdTestNonNull: |
| 30041 | case IrInstGenIdClz: |
| 30042 | case IrInstGenIdCtz: |
| 30043 | case IrInstGenIdPopCount: |
| 30044 | case IrInstGenIdBswap: |
| 30045 | case IrInstGenIdBitReverse: |
| 30046 | case IrInstGenIdUnionTag: |
| 30047 | case IrInstGenIdTruncate: |
| 30048 | case IrInstGenIdShuffleVector: |
| 30049 | case IrInstGenIdSplat: |
| 30050 | case IrInstGenIdBoolNot: |
| 30051 | case IrInstGenIdReturnAddress: |
| 30052 | case IrInstGenIdFrameAddress: |
| 30053 | case IrInstGenIdFrameHandle: |
| 30054 | case IrInstGenIdFrameSize: |
| 30055 | case IrInstGenIdTestErr: |
| 30056 | case IrInstGenIdPtrCast: |
| 30057 | case IrInstGenIdBitCast: |
| 30058 | case IrInstGenIdWidenOrShorten: |
| 30059 | case IrInstGenIdPtrToInt: |
| 30060 | case IrInstGenIdIntToPtr: |
| 30061 | case IrInstGenIdIntToEnum: |
| 30062 | case IrInstGenIdIntToErr: |
| 30063 | case IrInstGenIdErrToInt: |
| 30064 | case IrInstGenIdErrName: |
| 30065 | case IrInstGenIdTagName: |
| 30066 | case IrInstGenIdFieldParentPtr: |
| 30067 | case IrInstGenIdAlignCast: |
| 30068 | case IrInstGenIdErrorReturnTrace: |
| 30069 | case IrInstGenIdFloatOp: |
| 30070 | case IrInstGenIdMulAdd: |
| 30071 | case IrInstGenIdAtomicLoad: |
| 30072 | case IrInstGenIdArrayToVector: |
| 30073 | case IrInstGenIdAlloca: |
| 30074 | case IrInstGenIdSpillEnd: |
| 30075 | case IrInstGenIdVectorExtractElem: |
| 30076 | case IrInstGenIdBinaryNot: |
| 30077 | case IrInstGenIdNegation: |
| 30078 | case IrInstGenIdNegationWrapping: |
| 29261 | 30079 | return false; |
| 29262 | 30080 | |
| 29263 | | case IrInstructionIdAsmSrc: |
| 30081 | case IrInstGenIdAsm: |
| 29264 | 30082 | { |
| 29265 | | IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction; |
| 30083 | IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction; |
| 29266 | 30084 | return asm_instruction->has_side_effects; |
| 29267 | 30085 | } |
| 30086 | case IrInstGenIdUnwrapErrPayload: |
| 30087 | { |
| 30088 | IrInstGenUnwrapErrPayload *unwrap_err_payload_instruction = |
| 30089 | (IrInstGenUnwrapErrPayload *)instruction; |
| 30090 | return unwrap_err_payload_instruction->safety_check_on || |
| 30091 | unwrap_err_payload_instruction->initializing; |
| 30092 | } |
| 30093 | case IrInstGenIdUnwrapErrCode: |
| 30094 | return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing; |
| 30095 | case IrInstGenIdUnionFieldPtr: |
| 30096 | return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing; |
| 30097 | case IrInstGenIdOptionalUnwrapPtr: |
| 30098 | return reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(instruction)->initializing; |
| 30099 | case IrInstGenIdErrWrapPayload: |
| 30100 | return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 30101 | case IrInstGenIdErrWrapCode: |
| 30102 | return reinterpret_cast<IrInstGenErrWrapCode *>(instruction)->result_loc != nullptr; |
| 30103 | case IrInstGenIdLoadPtr: |
| 30104 | return reinterpret_cast<IrInstGenLoadPtr *>(instruction)->result_loc != nullptr; |
| 30105 | case IrInstGenIdRef: |
| 30106 | return reinterpret_cast<IrInstGenRef *>(instruction)->result_loc != nullptr; |
| 30107 | } |
| 30108 | zig_unreachable(); |
| 30109 | } |
| 30110 | |
| 30111 | bool ir_inst_src_has_side_effects(IrInstSrc *instruction) { |
| 30112 | switch (instruction->id) { |
| 30113 | case IrInstSrcIdInvalid: |
| 30114 | zig_unreachable(); |
| 30115 | case IrInstSrcIdBr: |
| 30116 | case IrInstSrcIdCondBr: |
| 30117 | case IrInstSrcIdSwitchBr: |
| 30118 | case IrInstSrcIdDeclVar: |
| 30119 | case IrInstSrcIdStorePtr: |
| 30120 | case IrInstSrcIdCallExtra: |
| 30121 | case IrInstSrcIdCall: |
| 30122 | case IrInstSrcIdCallArgs: |
| 30123 | case IrInstSrcIdReturn: |
| 30124 | case IrInstSrcIdUnreachable: |
| 30125 | case IrInstSrcIdSetCold: |
| 30126 | case IrInstSrcIdSetRuntimeSafety: |
| 30127 | case IrInstSrcIdSetFloatMode: |
| 30128 | case IrInstSrcIdImport: |
| 30129 | case IrInstSrcIdCompileErr: |
| 30130 | case IrInstSrcIdCompileLog: |
| 30131 | case IrInstSrcIdCImport: |
| 30132 | case IrInstSrcIdCInclude: |
| 30133 | case IrInstSrcIdCDefine: |
| 30134 | case IrInstSrcIdCUndef: |
| 30135 | case IrInstSrcIdFence: |
| 30136 | case IrInstSrcIdMemset: |
| 30137 | case IrInstSrcIdMemcpy: |
| 30138 | case IrInstSrcIdBreakpoint: |
| 30139 | case IrInstSrcIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 30140 | case IrInstSrcIdCheckSwitchProngs: |
| 30141 | case IrInstSrcIdCheckStatementIsVoid: |
| 30142 | case IrInstSrcIdCheckRuntimeScope: |
| 30143 | case IrInstSrcIdPanic: |
| 30144 | case IrInstSrcIdSetEvalBranchQuota: |
| 30145 | case IrInstSrcIdPtrType: |
| 30146 | case IrInstSrcIdSetAlignStack: |
| 30147 | case IrInstSrcIdExport: |
| 30148 | case IrInstSrcIdSaveErrRetAddr: |
| 30149 | case IrInstSrcIdAddImplicitReturnType: |
| 30150 | case IrInstSrcIdAtomicRmw: |
| 30151 | case IrInstSrcIdAtomicStore: |
| 30152 | case IrInstSrcIdCmpxchg: |
| 30153 | case IrInstSrcIdUndeclaredIdent: |
| 30154 | case IrInstSrcIdEndExpr: |
| 30155 | case IrInstSrcIdResetResult: |
| 30156 | case IrInstSrcIdSuspendBegin: |
| 30157 | case IrInstSrcIdSuspendFinish: |
| 30158 | case IrInstSrcIdResume: |
| 30159 | case IrInstSrcIdAwait: |
| 30160 | case IrInstSrcIdSpillBegin: |
| 30161 | return true; |
| 30162 | |
| 30163 | case IrInstSrcIdPhi: |
| 30164 | case IrInstSrcIdUnOp: |
| 30165 | case IrInstSrcIdBinOp: |
| 30166 | case IrInstSrcIdMergeErrSets: |
| 30167 | case IrInstSrcIdLoadPtr: |
| 30168 | case IrInstSrcIdConst: |
| 30169 | case IrInstSrcIdContainerInitList: |
| 30170 | case IrInstSrcIdContainerInitFields: |
| 30171 | case IrInstSrcIdUnionInitNamedField: |
| 30172 | case IrInstSrcIdFieldPtr: |
| 30173 | case IrInstSrcIdElemPtr: |
| 30174 | case IrInstSrcIdVarPtr: |
| 30175 | case IrInstSrcIdTypeOf: |
| 30176 | case IrInstSrcIdArrayType: |
| 30177 | case IrInstSrcIdSliceType: |
| 30178 | case IrInstSrcIdAnyFrameType: |
| 30179 | case IrInstSrcIdSizeOf: |
| 30180 | case IrInstSrcIdTestNonNull: |
| 30181 | case IrInstSrcIdOptionalUnwrapPtr: |
| 30182 | case IrInstSrcIdClz: |
| 30183 | case IrInstSrcIdCtz: |
| 30184 | case IrInstSrcIdPopCount: |
| 30185 | case IrInstSrcIdBswap: |
| 30186 | case IrInstSrcIdBitReverse: |
| 30187 | case IrInstSrcIdSwitchVar: |
| 30188 | case IrInstSrcIdSwitchElseVar: |
| 30189 | case IrInstSrcIdSwitchTarget: |
| 30190 | case IrInstSrcIdRef: |
| 30191 | case IrInstSrcIdEmbedFile: |
| 30192 | case IrInstSrcIdTruncate: |
| 30193 | case IrInstSrcIdIntType: |
| 30194 | case IrInstSrcIdVectorType: |
| 30195 | case IrInstSrcIdShuffleVector: |
| 30196 | case IrInstSrcIdSplat: |
| 30197 | case IrInstSrcIdBoolNot: |
| 30198 | case IrInstSrcIdSlice: |
| 30199 | case IrInstSrcIdMemberCount: |
| 30200 | case IrInstSrcIdMemberType: |
| 30201 | case IrInstSrcIdMemberName: |
| 30202 | case IrInstSrcIdAlignOf: |
| 30203 | case IrInstSrcIdReturnAddress: |
| 30204 | case IrInstSrcIdFrameAddress: |
| 30205 | case IrInstSrcIdFrameHandle: |
| 30206 | case IrInstSrcIdFrameType: |
| 30207 | case IrInstSrcIdFrameSize: |
| 30208 | case IrInstSrcIdTestErr: |
| 30209 | case IrInstSrcIdFnProto: |
| 30210 | case IrInstSrcIdTestComptime: |
| 30211 | case IrInstSrcIdPtrCast: |
| 30212 | case IrInstSrcIdBitCast: |
| 30213 | case IrInstSrcIdPtrToInt: |
| 30214 | case IrInstSrcIdIntToPtr: |
| 30215 | case IrInstSrcIdIntToEnum: |
| 30216 | case IrInstSrcIdIntToErr: |
| 30217 | case IrInstSrcIdErrToInt: |
| 30218 | case IrInstSrcIdDeclRef: |
| 30219 | case IrInstSrcIdErrName: |
| 30220 | case IrInstSrcIdTypeName: |
| 30221 | case IrInstSrcIdTagName: |
| 30222 | case IrInstSrcIdFieldParentPtr: |
| 30223 | case IrInstSrcIdByteOffsetOf: |
| 30224 | case IrInstSrcIdBitOffsetOf: |
| 30225 | case IrInstSrcIdTypeInfo: |
| 30226 | case IrInstSrcIdType: |
| 30227 | case IrInstSrcIdHasField: |
| 30228 | case IrInstSrcIdTypeId: |
| 30229 | case IrInstSrcIdAlignCast: |
| 30230 | case IrInstSrcIdImplicitCast: |
| 30231 | case IrInstSrcIdResolveResult: |
| 30232 | case IrInstSrcIdOpaqueType: |
| 30233 | case IrInstSrcIdArgType: |
| 30234 | case IrInstSrcIdTagType: |
| 30235 | case IrInstSrcIdErrorReturnTrace: |
| 30236 | case IrInstSrcIdErrorUnion: |
| 30237 | case IrInstSrcIdFloatOp: |
| 30238 | case IrInstSrcIdMulAdd: |
| 30239 | case IrInstSrcIdAtomicLoad: |
| 30240 | case IrInstSrcIdIntCast: |
| 30241 | case IrInstSrcIdFloatCast: |
| 30242 | case IrInstSrcIdErrSetCast: |
| 30243 | case IrInstSrcIdIntToFloat: |
| 30244 | case IrInstSrcIdFloatToInt: |
| 30245 | case IrInstSrcIdBoolToInt: |
| 30246 | case IrInstSrcIdFromBytes: |
| 30247 | case IrInstSrcIdToBytes: |
| 30248 | case IrInstSrcIdEnumToInt: |
| 30249 | case IrInstSrcIdHasDecl: |
| 30250 | case IrInstSrcIdAlloca: |
| 30251 | case IrInstSrcIdSpillEnd: |
| 30252 | return false; |
| 29268 | 30253 | |
| 29269 | | case IrInstructionIdAsmGen: |
| 30254 | case IrInstSrcIdAsm: |
| 29270 | 30255 | { |
| 29271 | | IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction; |
| 30256 | IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction; |
| 29272 | 30257 | return asm_instruction->has_side_effects; |
| 29273 | 30258 | } |
| 29274 | | case IrInstructionIdUnwrapErrPayload: |
| 30259 | |
| 30260 | case IrInstSrcIdUnwrapErrPayload: |
| 29275 | 30261 | { |
| 29276 | | IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction = |
| 29277 | | (IrInstructionUnwrapErrPayload *)instruction; |
| 30262 | IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction = |
| 30263 | (IrInstSrcUnwrapErrPayload *)instruction; |
| 29278 | 30264 | return unwrap_err_payload_instruction->safety_check_on || |
| 29279 | 30265 | unwrap_err_payload_instruction->initializing; |
| 29280 | 30266 | } |
| 29281 | | case IrInstructionIdUnwrapErrCode: |
| 29282 | | return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing; |
| 29283 | | case IrInstructionIdUnionFieldPtr: |
| 29284 | | return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing; |
| 29285 | | case IrInstructionIdErrWrapPayload: |
| 29286 | | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 29287 | | case IrInstructionIdErrWrapCode: |
| 29288 | | return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr; |
| 29289 | | case IrInstructionIdLoadPtrGen: |
| 29290 | | return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr; |
| 29291 | | case IrInstructionIdRefGen: |
| 29292 | | return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr; |
| 30267 | case IrInstSrcIdUnwrapErrCode: |
| 30268 | return reinterpret_cast<IrInstSrcUnwrapErrCode *>(instruction)->initializing; |
| 29293 | 30269 | } |
| 29294 | 30270 | zig_unreachable(); |
| 29295 | 30271 | } |
| ... | ... | @@ -29323,14 +30299,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29323 | 30299 | param_info->type = nullptr; |
| 29324 | 30300 | return get_generic_fn_type(ira->codegen, &fn_type_id); |
| 29325 | 30301 | } else { |
| 29326 | | IrInstruction *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index]; |
| 30302 | IrInstGen *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index]; |
| 29327 | 30303 | ZigType *param_type = ir_resolve_type(ira, param_type_inst); |
| 29328 | 30304 | if (type_is_invalid(param_type)) |
| 29329 | 30305 | return nullptr; |
| 29330 | 30306 | switch (type_requires_comptime(ira->codegen, param_type)) { |
| 29331 | 30307 | case ReqCompTimeYes: |
| 29332 | 30308 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 29333 | | ir_add_error(ira, param_type_inst, |
| 30309 | ir_add_error(ira, &param_type_inst->base, |
| 29334 | 30310 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 29335 | 30311 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 29336 | 30312 | return nullptr; |
| ... | ... | @@ -29348,7 +30324,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29348 | 30324 | if ((err = type_has_bits2(ira->codegen, param_type, &has_bits))) |
| 29349 | 30325 | return nullptr; |
| 29350 | 30326 | if (!has_bits) { |
| 29351 | | ir_add_error(ira, param_type_inst, |
| 30327 | ir_add_error(ira, &param_type_inst->base, |
| 29352 | 30328 | buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", |
| 29353 | 30329 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 29354 | 30330 | return nullptr; |
| ... | ... | @@ -29367,7 +30343,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29367 | 30343 | if (type_is_invalid(fn_type_id.return_type)) |
| 29368 | 30344 | return nullptr; |
| 29369 | 30345 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 29370 | | ir_add_error(ira, lazy_fn_type->return_type, buf_create_from_str("return type cannot be opaque")); |
| 30346 | ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque")); |
| 29371 | 30347 | return nullptr; |
| 29372 | 30348 | } |
| 29373 | 30349 | |
| ... | ... | @@ -29399,7 +30375,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29399 | 30375 | case ZigTypeIdBoundFn: |
| 29400 | 30376 | case ZigTypeIdVoid: |
| 29401 | 30377 | case ZigTypeIdOpaque: |
| 29402 | | ir_add_error(ira, lazy_align_of->target_type, |
| 30378 | ir_add_error(ira, &lazy_align_of->target_type->base, |
| 29403 | 30379 | buf_sprintf("no align available for type '%s'", |
| 29404 | 30380 | buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); |
| 29405 | 30381 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29449,7 +30425,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29449 | 30425 | case ZigTypeIdNull: |
| 29450 | 30426 | case ZigTypeIdBoundFn: |
| 29451 | 30427 | case ZigTypeIdOpaque: |
| 29452 | | ir_add_error(ira, lazy_size_of->target_type, |
| 30428 | ir_add_error(ira, &lazy_size_of->target_type->base, |
| 29453 | 30429 | buf_sprintf("no size available for type '%s'", |
| 29454 | 30430 | buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); |
| 29455 | 30431 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29507,7 +30483,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29507 | 30483 | if (lazy_slice_type->sentinel != nullptr) { |
| 29508 | 30484 | if (type_is_invalid(lazy_slice_type->sentinel->value->type)) |
| 29509 | 30485 | return ErrorSemanticAnalyzeFail; |
| 29510 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 30486 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 29511 | 30487 | if (type_is_invalid(sentinel->value->type)) |
| 29512 | 30488 | return ErrorSemanticAnalyzeFail; |
| 29513 | 30489 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29530,7 +30506,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29530 | 30506 | case ZigTypeIdUndefined: |
| 29531 | 30507 | case ZigTypeIdNull: |
| 29532 | 30508 | case ZigTypeIdOpaque: |
| 29533 | | ir_add_error(ira, lazy_slice_type->elem_type, |
| 30509 | ir_add_error(ira, &lazy_slice_type->elem_type->base, |
| 29534 | 30510 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name))); |
| 29535 | 30511 | return ErrorSemanticAnalyzeFail; |
| 29536 | 30512 | case ZigTypeIdMetaType: |
| ... | ... | @@ -29586,7 +30562,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29586 | 30562 | if (lazy_ptr_type->sentinel != nullptr) { |
| 29587 | 30563 | if (type_is_invalid(lazy_ptr_type->sentinel->value->type)) |
| 29588 | 30564 | return ErrorSemanticAnalyzeFail; |
| 29589 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 30565 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 29590 | 30566 | if (type_is_invalid(sentinel->value->type)) |
| 29591 | 30567 | return ErrorSemanticAnalyzeFail; |
| 29592 | 30568 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29603,11 +30579,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29603 | 30579 | } |
| 29604 | 30580 | |
| 29605 | 30581 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 29606 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30582 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29607 | 30583 | buf_create_from_str("pointer to noreturn not allowed")); |
| 29608 | 30584 | return ErrorSemanticAnalyzeFail; |
| 29609 | 30585 | } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) { |
| 29610 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30586 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29611 | 30587 | buf_create_from_str("unknown-length pointer to opaque")); |
| 29612 | 30588 | return ErrorSemanticAnalyzeFail; |
| 29613 | 30589 | } else if (lazy_ptr_type->ptr_len == PtrLenC) { |
| ... | ... | @@ -29615,16 +30591,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29615 | 30591 | if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type))) |
| 29616 | 30592 | return err; |
| 29617 | 30593 | if (!ok_type) { |
| 29618 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30594 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29619 | 30595 | buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'", |
| 29620 | 30596 | buf_ptr(&elem_type->name))); |
| 29621 | 30597 | return ErrorSemanticAnalyzeFail; |
| 29622 | 30598 | } else if (elem_type->id == ZigTypeIdOpaque) { |
| 29623 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30599 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29624 | 30600 | buf_sprintf("C pointers cannot point opaque types")); |
| 29625 | 30601 | return ErrorSemanticAnalyzeFail; |
| 29626 | 30602 | } else if (lazy_ptr_type->is_allowzero) { |
| 29627 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30603 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29628 | 30604 | buf_sprintf("C pointers always allow address zero")); |
| 29629 | 30605 | return ErrorSemanticAnalyzeFail; |
| 29630 | 30606 | } |
| ... | ... | @@ -29662,7 +30638,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29662 | 30638 | case ZigTypeIdUndefined: |
| 29663 | 30639 | case ZigTypeIdNull: |
| 29664 | 30640 | case ZigTypeIdOpaque: |
| 29665 | | ir_add_error(ira, lazy_array_type->elem_type, |
| 30641 | ir_add_error(ira, &lazy_array_type->elem_type->base, |
| 29666 | 30642 | buf_sprintf("array of type '%s' not allowed", |
| 29667 | 30643 | buf_ptr(&elem_type->name))); |
| 29668 | 30644 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29697,7 +30673,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29697 | 30673 | if (lazy_array_type->sentinel != nullptr) { |
| 29698 | 30674 | if (type_is_invalid(lazy_array_type->sentinel->value->type)) |
| 29699 | 30675 | return ErrorSemanticAnalyzeFail; |
| 29700 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type); |
| 30676 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type); |
| 29701 | 30677 | if (type_is_invalid(sentinel->value->type)) |
| 29702 | 30678 | return ErrorSemanticAnalyzeFail; |
| 29703 | 30679 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29721,7 +30697,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29721 | 30697 | return ErrorSemanticAnalyzeFail; |
| 29722 | 30698 | |
| 29723 | 30699 | if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) { |
| 29724 | | ir_add_error(ira, lazy_opt_type->payload_type, |
| 30700 | ir_add_error(ira, &lazy_opt_type->payload_type->base, |
| 29725 | 30701 | buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name))); |
| 29726 | 30702 | return ErrorSemanticAnalyzeFail; |
| 29727 | 30703 | } |
| ... | ... | @@ -29763,7 +30739,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29763 | 30739 | return ErrorSemanticAnalyzeFail; |
| 29764 | 30740 | |
| 29765 | 30741 | if (err_set_type->id != ZigTypeIdErrorSet) { |
| 29766 | | ir_add_error(ira, lazy_err_union_type->err_set_type, |
| 30742 | ir_add_error(ira, &lazy_err_union_type->err_set_type->base, |
| 29767 | 30743 | buf_sprintf("expected error set type, found type '%s'", |
| 29768 | 30744 | buf_ptr(&err_set_type->name))); |
| 29769 | 30745 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29799,8 +30775,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { |
| 29799 | 30775 | return ErrorNone; |
| 29800 | 30776 | } |
| 29801 | 30777 | |
| 29802 | | void IrInstruction::src() { |
| 29803 | | IrInstruction *inst = this; |
| 30778 | void IrInst::src() { |
| 30779 | IrInst *inst = this; |
| 29804 | 30780 | if (inst->source_node != nullptr) { |
| 29805 | 30781 | inst->source_node->src(); |
| 29806 | 30782 | } else { |
| ... | ... | @@ -29808,26 +30784,45 @@ void IrInstruction::src() { |
| 29808 | 30784 | } |
| 29809 | 30785 | } |
| 29810 | 30786 | |
| 29811 | | void IrInstruction::dump() { |
| 29812 | | IrInstruction *inst = this; |
| 30787 | void IrInst::dump() { |
| 30788 | this->src(); |
| 30789 | fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id); |
| 30790 | } |
| 30791 | |
| 30792 | void IrInstSrc::src() { |
| 30793 | this->base.src(); |
| 30794 | } |
| 30795 | |
| 30796 | void IrInstGen::src() { |
| 30797 | this->base.src(); |
| 30798 | } |
| 30799 | |
| 30800 | void IrInstSrc::dump() { |
| 30801 | IrInstSrc *inst = this; |
| 29813 | 30802 | inst->src(); |
| 29814 | | IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc; |
| 29815 | | if (inst->scope == nullptr) { |
| 30803 | if (inst->base.scope == nullptr) { |
| 29816 | 30804 | fprintf(stderr, "(null scope)\n"); |
| 29817 | 30805 | } else { |
| 29818 | | ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass); |
| 29819 | | if (pass == IrPassSrc) { |
| 29820 | | fprintf(stderr, "-> "); |
| 29821 | | ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen); |
| 29822 | | } |
| 30806 | ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0); |
| 30807 | fprintf(stderr, "-> "); |
| 30808 | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0); |
| 30809 | } |
| 30810 | } |
| 30811 | void IrInstGen::dump() { |
| 30812 | IrInstGen *inst = this; |
| 30813 | inst->src(); |
| 30814 | if (inst->base.scope == nullptr) { |
| 30815 | fprintf(stderr, "(null scope)\n"); |
| 30816 | } else { |
| 30817 | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0); |
| 29823 | 30818 | } |
| 29824 | 30819 | } |
| 29825 | 30820 | |
| 29826 | 30821 | void IrAnalyze::dump() { |
| 29827 | | ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen); |
| 30822 | ir_print_gen(this->codegen, stderr, this->new_irb.exec, 0); |
| 29828 | 30823 | if (this->new_irb.current_basic_block != nullptr) { |
| 29829 | 30824 | fprintf(stderr, "Current basic block:\n"); |
| 29830 | | ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen); |
| 30825 | ir_print_basic_block_gen(this->codegen, stderr, this->new_irb.current_basic_block, 1); |
| 29831 | 30826 | } |
| 29832 | 30827 | } |
| 29833 | 30828 | |