| ... | ... | @@ -21,25 +21,31 @@ struct IrExecContext { |
| 21 | 21 | ZigList<ZigValue *> mem_slot_list; |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | | struct IrBuilder { |
| 24 | struct IrBuilderSrc { |
| 25 | 25 | CodeGen *codegen; |
| 26 | | IrExecutable *exec; |
| 27 | | IrBasicBlock *current_basic_block; |
| 26 | IrExecutableSrc *exec; |
| 27 | IrBasicBlockSrc *current_basic_block; |
| 28 | 28 | AstNode *main_block_node; |
| 29 | 29 | }; |
| 30 | 30 | |
| 31 | struct IrBuilderGen { |
| 32 | CodeGen *codegen; |
| 33 | IrExecutableGen *exec; |
| 34 | IrBasicBlockGen *current_basic_block; |
| 35 | }; |
| 36 | |
| 31 | 37 | struct IrAnalyze { |
| 32 | 38 | CodeGen *codegen; |
| 33 | | IrBuilder old_irb; |
| 34 | | IrBuilder new_irb; |
| 39 | IrBuilderSrc old_irb; |
| 40 | IrBuilderGen new_irb; |
| 35 | 41 | IrExecContext exec_context; |
| 36 | 42 | size_t old_bb_index; |
| 37 | 43 | size_t instruction_index; |
| 38 | 44 | ZigType *explicit_return_type; |
| 39 | 45 | AstNode *explicit_return_type_source_node; |
| 40 | | ZigList<IrInstruction *> src_implicit_return_type_list; |
| 46 | ZigList<IrInstGen *> src_implicit_return_type_list; |
| 41 | 47 | ZigList<IrSuspendPosition> resume_stack; |
| 42 | | IrBasicBlock *const_predecessor_bb; |
| 48 | IrBasicBlockSrc *const_predecessor_bb; |
| 43 | 49 | size_t ref_count; |
| 44 | 50 | size_t break_debug_id; // for debugging purposes |
| 45 | 51 | |
| ... | ... | @@ -206,412 +212,538 @@ struct DbgIrBreakPoint { |
| 206 | 212 | DbgIrBreakPoint dbg_ir_breakpoints_buf[20]; |
| 207 | 213 | size_t dbg_ir_breakpoints_count = 0; |
| 208 | 214 | |
| 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, |
| 215 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope); |
| 216 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, |
| 211 | 217 | 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, |
| 218 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type); |
| 219 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 220 | IrInstGen *value, ZigType *expected_type); |
| 221 | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, |
| 216 | 222 | 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); |
| 223 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg); |
| 224 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 225 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing); |
| 226 | static void ir_assert(bool ok, IrInst* source_instruction); |
| 227 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); |
| 228 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| 229 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 230 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); |
| 231 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); |
| 225 | 232 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 226 | 233 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| 227 | 234 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val); |
| 228 | 235 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); |
| 229 | 236 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 230 | 237 | 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); |
| 238 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 239 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on); |
| 240 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); |
| 234 | 241 | 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, |
| 242 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 236 | 243 | ZigType *ptr_type); |
| 237 | | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 244 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 238 | 245 | 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, |
| 246 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 247 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 241 | 248 | 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, |
| 249 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 250 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 244 | 251 | 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, |
| 252 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 253 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 254 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 255 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 256 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 257 | IrInstGen *base_ptr, bool initializing); |
| 258 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 259 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const); |
| 260 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 261 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 255 | 262 | LVal lval, ResultLoc *parent_result_loc); |
| 256 | 263 | static void ir_reset_result(ResultLoc *result_loc); |
| 257 | | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 264 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name, |
| 258 | 265 | Scope *scope, AstNode *source_node, Buf *out_bare_name); |
| 259 | | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, |
| 266 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, |
| 260 | 267 | 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); |
| 268 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 269 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing); |
| 270 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 271 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type); |
| 265 | 272 | static ResultLoc *no_result_loc(void); |
| 266 | | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value); |
| 273 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value); |
| 274 | |
| 275 | static void destroy_instruction_src(IrInstSrc *inst) { |
| 276 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 277 | const char *name = ir_inst_src_type_str(inst->id); |
| 278 | #else |
| 279 | const char *name = nullptr; |
| 280 | #endif |
| 281 | switch (inst->id) { |
| 282 | case IrInstSrcIdInvalid: |
| 283 | zig_unreachable(); |
| 284 | case IrInstSrcIdReturn: |
| 285 | return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name); |
| 286 | case IrInstSrcIdConst: |
| 287 | return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name); |
| 288 | case IrInstSrcIdBinOp: |
| 289 | return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name); |
| 290 | case IrInstSrcIdMergeErrSets: |
| 291 | return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name); |
| 292 | case IrInstSrcIdDeclVar: |
| 293 | return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name); |
| 294 | case IrInstSrcIdCall: |
| 295 | return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name); |
| 296 | case IrInstSrcIdCallExtra: |
| 297 | return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name); |
| 298 | case IrInstSrcIdUnOp: |
| 299 | return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name); |
| 300 | case IrInstSrcIdCondBr: |
| 301 | return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name); |
| 302 | case IrInstSrcIdBr: |
| 303 | return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name); |
| 304 | case IrInstSrcIdPhi: |
| 305 | return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name); |
| 306 | case IrInstSrcIdContainerInitList: |
| 307 | return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name); |
| 308 | case IrInstSrcIdContainerInitFields: |
| 309 | return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name); |
| 310 | case IrInstSrcIdUnreachable: |
| 311 | return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name); |
| 312 | case IrInstSrcIdElemPtr: |
| 313 | return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name); |
| 314 | case IrInstSrcIdVarPtr: |
| 315 | return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name); |
| 316 | case IrInstSrcIdLoadPtr: |
| 317 | return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name); |
| 318 | case IrInstSrcIdStorePtr: |
| 319 | return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name); |
| 320 | case IrInstSrcIdTypeOf: |
| 321 | return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name); |
| 322 | case IrInstSrcIdFieldPtr: |
| 323 | return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name); |
| 324 | case IrInstSrcIdSetCold: |
| 325 | return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name); |
| 326 | case IrInstSrcIdSetRuntimeSafety: |
| 327 | return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name); |
| 328 | case IrInstSrcIdSetFloatMode: |
| 329 | return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name); |
| 330 | case IrInstSrcIdArrayType: |
| 331 | return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name); |
| 332 | case IrInstSrcIdSliceType: |
| 333 | return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name); |
| 334 | case IrInstSrcIdAnyFrameType: |
| 335 | return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name); |
| 336 | case IrInstSrcIdAsm: |
| 337 | return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name); |
| 338 | case IrInstSrcIdSizeOf: |
| 339 | return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name); |
| 340 | case IrInstSrcIdTestNonNull: |
| 341 | return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name); |
| 342 | case IrInstSrcIdOptionalUnwrapPtr: |
| 343 | return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name); |
| 344 | case IrInstSrcIdPopCount: |
| 345 | return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name); |
| 346 | case IrInstSrcIdClz: |
| 347 | return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name); |
| 348 | case IrInstSrcIdCtz: |
| 349 | return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name); |
| 350 | case IrInstSrcIdBswap: |
| 351 | return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name); |
| 352 | case IrInstSrcIdBitReverse: |
| 353 | return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name); |
| 354 | case IrInstSrcIdSwitchBr: |
| 355 | return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name); |
| 356 | case IrInstSrcIdSwitchVar: |
| 357 | return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name); |
| 358 | case IrInstSrcIdSwitchElseVar: |
| 359 | return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name); |
| 360 | case IrInstSrcIdSwitchTarget: |
| 361 | return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name); |
| 362 | case IrInstSrcIdImport: |
| 363 | return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name); |
| 364 | case IrInstSrcIdRef: |
| 365 | return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name); |
| 366 | case IrInstSrcIdCompileErr: |
| 367 | return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name); |
| 368 | case IrInstSrcIdCompileLog: |
| 369 | return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name); |
| 370 | case IrInstSrcIdErrName: |
| 371 | return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name); |
| 372 | case IrInstSrcIdCImport: |
| 373 | return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name); |
| 374 | case IrInstSrcIdCInclude: |
| 375 | return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name); |
| 376 | case IrInstSrcIdCDefine: |
| 377 | return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name); |
| 378 | case IrInstSrcIdCUndef: |
| 379 | return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name); |
| 380 | case IrInstSrcIdEmbedFile: |
| 381 | return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name); |
| 382 | case IrInstSrcIdCmpxchg: |
| 383 | return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name); |
| 384 | case IrInstSrcIdFence: |
| 385 | return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name); |
| 386 | case IrInstSrcIdTruncate: |
| 387 | return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name); |
| 388 | case IrInstSrcIdIntCast: |
| 389 | return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name); |
| 390 | case IrInstSrcIdFloatCast: |
| 391 | return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name); |
| 392 | case IrInstSrcIdErrSetCast: |
| 393 | return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name); |
| 394 | case IrInstSrcIdFromBytes: |
| 395 | return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name); |
| 396 | case IrInstSrcIdToBytes: |
| 397 | return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name); |
| 398 | case IrInstSrcIdIntToFloat: |
| 399 | return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name); |
| 400 | case IrInstSrcIdFloatToInt: |
| 401 | return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name); |
| 402 | case IrInstSrcIdBoolToInt: |
| 403 | return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name); |
| 404 | case IrInstSrcIdIntType: |
| 405 | return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name); |
| 406 | case IrInstSrcIdVectorType: |
| 407 | return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name); |
| 408 | case IrInstSrcIdShuffleVector: |
| 409 | return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name); |
| 410 | case IrInstSrcIdSplat: |
| 411 | return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name); |
| 412 | case IrInstSrcIdBoolNot: |
| 413 | return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name); |
| 414 | case IrInstSrcIdMemset: |
| 415 | return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name); |
| 416 | case IrInstSrcIdMemcpy: |
| 417 | return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name); |
| 418 | case IrInstSrcIdSlice: |
| 419 | return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name); |
| 420 | case IrInstSrcIdMemberCount: |
| 421 | return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name); |
| 422 | case IrInstSrcIdMemberType: |
| 423 | return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name); |
| 424 | case IrInstSrcIdMemberName: |
| 425 | return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name); |
| 426 | case IrInstSrcIdBreakpoint: |
| 427 | return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name); |
| 428 | case IrInstSrcIdReturnAddress: |
| 429 | return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name); |
| 430 | case IrInstSrcIdFrameAddress: |
| 431 | return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name); |
| 432 | case IrInstSrcIdFrameHandle: |
| 433 | return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name); |
| 434 | case IrInstSrcIdFrameType: |
| 435 | return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name); |
| 436 | case IrInstSrcIdFrameSize: |
| 437 | return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name); |
| 438 | case IrInstSrcIdAlignOf: |
| 439 | return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name); |
| 440 | case IrInstSrcIdOverflowOp: |
| 441 | return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name); |
| 442 | case IrInstSrcIdTestErr: |
| 443 | return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name); |
| 444 | case IrInstSrcIdUnwrapErrCode: |
| 445 | return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name); |
| 446 | case IrInstSrcIdUnwrapErrPayload: |
| 447 | return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name); |
| 448 | case IrInstSrcIdFnProto: |
| 449 | return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name); |
| 450 | case IrInstSrcIdTestComptime: |
| 451 | return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name); |
| 452 | case IrInstSrcIdPtrCast: |
| 453 | return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name); |
| 454 | case IrInstSrcIdBitCast: |
| 455 | return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name); |
| 456 | case IrInstSrcIdPtrToInt: |
| 457 | return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name); |
| 458 | case IrInstSrcIdIntToPtr: |
| 459 | return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name); |
| 460 | case IrInstSrcIdIntToEnum: |
| 461 | return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name); |
| 462 | case IrInstSrcIdIntToErr: |
| 463 | return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name); |
| 464 | case IrInstSrcIdErrToInt: |
| 465 | return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name); |
| 466 | case IrInstSrcIdCheckSwitchProngs: |
| 467 | return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name); |
| 468 | case IrInstSrcIdCheckStatementIsVoid: |
| 469 | return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name); |
| 470 | case IrInstSrcIdTypeName: |
| 471 | return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name); |
| 472 | case IrInstSrcIdTagName: |
| 473 | return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name); |
| 474 | case IrInstSrcIdPtrType: |
| 475 | return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name); |
| 476 | case IrInstSrcIdDeclRef: |
| 477 | return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name); |
| 478 | case IrInstSrcIdPanic: |
| 479 | return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name); |
| 480 | case IrInstSrcIdFieldParentPtr: |
| 481 | return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name); |
| 482 | case IrInstSrcIdByteOffsetOf: |
| 483 | return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name); |
| 484 | case IrInstSrcIdBitOffsetOf: |
| 485 | return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name); |
| 486 | case IrInstSrcIdTypeInfo: |
| 487 | return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name); |
| 488 | case IrInstSrcIdType: |
| 489 | return destroy(reinterpret_cast<IrInstSrcType *>(inst), name); |
| 490 | case IrInstSrcIdHasField: |
| 491 | return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name); |
| 492 | case IrInstSrcIdTypeId: |
| 493 | return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name); |
| 494 | case IrInstSrcIdSetEvalBranchQuota: |
| 495 | return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name); |
| 496 | case IrInstSrcIdAlignCast: |
| 497 | return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name); |
| 498 | case IrInstSrcIdImplicitCast: |
| 499 | return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name); |
| 500 | case IrInstSrcIdResolveResult: |
| 501 | return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name); |
| 502 | case IrInstSrcIdResetResult: |
| 503 | return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name); |
| 504 | case IrInstSrcIdOpaqueType: |
| 505 | return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name); |
| 506 | case IrInstSrcIdSetAlignStack: |
| 507 | return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name); |
| 508 | case IrInstSrcIdArgType: |
| 509 | return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name); |
| 510 | case IrInstSrcIdTagType: |
| 511 | return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name); |
| 512 | case IrInstSrcIdExport: |
| 513 | return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name); |
| 514 | case IrInstSrcIdErrorReturnTrace: |
| 515 | return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name); |
| 516 | case IrInstSrcIdErrorUnion: |
| 517 | return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name); |
| 518 | case IrInstSrcIdAtomicRmw: |
| 519 | return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name); |
| 520 | case IrInstSrcIdSaveErrRetAddr: |
| 521 | return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name); |
| 522 | case IrInstSrcIdAddImplicitReturnType: |
| 523 | return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name); |
| 524 | case IrInstSrcIdFloatOp: |
| 525 | return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name); |
| 526 | case IrInstSrcIdMulAdd: |
| 527 | return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name); |
| 528 | case IrInstSrcIdAtomicLoad: |
| 529 | return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name); |
| 530 | case IrInstSrcIdAtomicStore: |
| 531 | return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name); |
| 532 | case IrInstSrcIdEnumToInt: |
| 533 | return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name); |
| 534 | case IrInstSrcIdCheckRuntimeScope: |
| 535 | return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name); |
| 536 | case IrInstSrcIdHasDecl: |
| 537 | return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name); |
| 538 | case IrInstSrcIdUndeclaredIdent: |
| 539 | return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name); |
| 540 | case IrInstSrcIdAlloca: |
| 541 | return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name); |
| 542 | case IrInstSrcIdEndExpr: |
| 543 | return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name); |
| 544 | case IrInstSrcIdUnionInitNamedField: |
| 545 | return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name); |
| 546 | case IrInstSrcIdSuspendBegin: |
| 547 | return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name); |
| 548 | case IrInstSrcIdSuspendFinish: |
| 549 | return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name); |
| 550 | case IrInstSrcIdResume: |
| 551 | return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name); |
| 552 | case IrInstSrcIdAwait: |
| 553 | return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name); |
| 554 | case IrInstSrcIdSpillBegin: |
| 555 | return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name); |
| 556 | case IrInstSrcIdSpillEnd: |
| 557 | return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name); |
| 558 | case IrInstSrcIdCallArgs: |
| 559 | return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name); |
| 560 | } |
| 561 | zig_unreachable(); |
| 562 | } |
| 267 | 563 | |
| 268 | | static void destroy_instruction(IrInstruction *inst) { |
| 564 | void destroy_instruction_gen(IrInstGen *inst) { |
| 269 | 565 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 270 | | const char *name = ir_instruction_type_str(inst->id); |
| 566 | const char *name = ir_inst_gen_type_str(inst->id); |
| 271 | 567 | #else |
| 272 | 568 | const char *name = nullptr; |
| 273 | 569 | #endif |
| 274 | 570 | switch (inst->id) { |
| 275 | | case IrInstructionIdInvalid: |
| 571 | case IrInstGenIdInvalid: |
| 276 | 572 | 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); |
| 573 | case IrInstGenIdReturn: |
| 574 | return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name); |
| 575 | case IrInstGenIdConst: |
| 576 | return destroy(reinterpret_cast<IrInstGenConst *>(inst), name); |
| 577 | case IrInstGenIdBinOp: |
| 578 | return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name); |
| 579 | case IrInstGenIdCast: |
| 580 | return destroy(reinterpret_cast<IrInstGenCast *>(inst), name); |
| 581 | case IrInstGenIdCall: |
| 582 | return destroy(reinterpret_cast<IrInstGenCall *>(inst), name); |
| 583 | case IrInstGenIdCondBr: |
| 584 | return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name); |
| 585 | case IrInstGenIdBr: |
| 586 | return destroy(reinterpret_cast<IrInstGenBr *>(inst), name); |
| 587 | case IrInstGenIdPhi: |
| 588 | return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name); |
| 589 | case IrInstGenIdUnreachable: |
| 590 | return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name); |
| 591 | case IrInstGenIdElemPtr: |
| 592 | return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name); |
| 593 | case IrInstGenIdVarPtr: |
| 594 | return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name); |
| 595 | case IrInstGenIdReturnPtr: |
| 596 | return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name); |
| 597 | case IrInstGenIdLoadPtr: |
| 598 | return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name); |
| 599 | case IrInstGenIdStorePtr: |
| 600 | return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name); |
| 601 | case IrInstGenIdVectorStoreElem: |
| 602 | return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name); |
| 603 | case IrInstGenIdStructFieldPtr: |
| 604 | return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name); |
| 605 | case IrInstGenIdUnionFieldPtr: |
| 606 | return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name); |
| 607 | case IrInstGenIdAsm: |
| 608 | return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name); |
| 609 | case IrInstGenIdTestNonNull: |
| 610 | return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name); |
| 611 | case IrInstGenIdOptionalUnwrapPtr: |
| 612 | return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name); |
| 613 | case IrInstGenIdPopCount: |
| 614 | return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name); |
| 615 | case IrInstGenIdClz: |
| 616 | return destroy(reinterpret_cast<IrInstGenClz *>(inst), name); |
| 617 | case IrInstGenIdCtz: |
| 618 | return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name); |
| 619 | case IrInstGenIdBswap: |
| 620 | return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name); |
| 621 | case IrInstGenIdBitReverse: |
| 622 | return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name); |
| 623 | case IrInstGenIdSwitchBr: |
| 624 | return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name); |
| 625 | case IrInstGenIdUnionTag: |
| 626 | return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name); |
| 627 | case IrInstGenIdRef: |
| 628 | return destroy(reinterpret_cast<IrInstGenRef *>(inst), name); |
| 629 | case IrInstGenIdErrName: |
| 630 | return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name); |
| 631 | case IrInstGenIdCmpxchg: |
| 632 | return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name); |
| 633 | case IrInstGenIdFence: |
| 634 | return destroy(reinterpret_cast<IrInstGenFence *>(inst), name); |
| 635 | case IrInstGenIdTruncate: |
| 636 | return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name); |
| 637 | case IrInstGenIdShuffleVector: |
| 638 | return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name); |
| 639 | case IrInstGenIdSplat: |
| 640 | return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name); |
| 641 | case IrInstGenIdBoolNot: |
| 642 | return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name); |
| 643 | case IrInstGenIdMemset: |
| 644 | return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name); |
| 645 | case IrInstGenIdMemcpy: |
| 646 | return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name); |
| 647 | case IrInstGenIdSlice: |
| 648 | return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name); |
| 649 | case IrInstGenIdBreakpoint: |
| 650 | return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name); |
| 651 | case IrInstGenIdReturnAddress: |
| 652 | return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name); |
| 653 | case IrInstGenIdFrameAddress: |
| 654 | return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name); |
| 655 | case IrInstGenIdFrameHandle: |
| 656 | return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name); |
| 657 | case IrInstGenIdFrameSize: |
| 658 | return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name); |
| 659 | case IrInstGenIdOverflowOp: |
| 660 | return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name); |
| 661 | case IrInstGenIdTestErr: |
| 662 | return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name); |
| 663 | case IrInstGenIdUnwrapErrCode: |
| 664 | return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name); |
| 665 | case IrInstGenIdUnwrapErrPayload: |
| 666 | return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name); |
| 667 | case IrInstGenIdOptionalWrap: |
| 668 | return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name); |
| 669 | case IrInstGenIdErrWrapCode: |
| 670 | return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name); |
| 671 | case IrInstGenIdErrWrapPayload: |
| 672 | return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name); |
| 673 | case IrInstGenIdPtrCast: |
| 674 | return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name); |
| 675 | case IrInstGenIdBitCast: |
| 676 | return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name); |
| 677 | case IrInstGenIdWidenOrShorten: |
| 678 | return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name); |
| 679 | case IrInstGenIdPtrToInt: |
| 680 | return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name); |
| 681 | case IrInstGenIdIntToPtr: |
| 682 | return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name); |
| 683 | case IrInstGenIdIntToEnum: |
| 684 | return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name); |
| 685 | case IrInstGenIdIntToErr: |
| 686 | return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name); |
| 687 | case IrInstGenIdErrToInt: |
| 688 | return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name); |
| 689 | case IrInstGenIdTagName: |
| 690 | return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name); |
| 691 | case IrInstGenIdPanic: |
| 692 | return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name); |
| 693 | case IrInstGenIdFieldParentPtr: |
| 694 | return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name); |
| 695 | case IrInstGenIdAlignCast: |
| 696 | return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name); |
| 697 | case IrInstGenIdErrorReturnTrace: |
| 698 | return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name); |
| 699 | case IrInstGenIdAtomicRmw: |
| 700 | return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name); |
| 701 | case IrInstGenIdSaveErrRetAddr: |
| 702 | return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name); |
| 703 | case IrInstGenIdFloatOp: |
| 704 | return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name); |
| 705 | case IrInstGenIdMulAdd: |
| 706 | return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name); |
| 707 | case IrInstGenIdAtomicLoad: |
| 708 | return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name); |
| 709 | case IrInstGenIdAtomicStore: |
| 710 | return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name); |
| 711 | case IrInstGenIdDeclVar: |
| 712 | return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name); |
| 713 | case IrInstGenIdArrayToVector: |
| 714 | return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name); |
| 715 | case IrInstGenIdVectorToArray: |
| 716 | return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name); |
| 717 | case IrInstGenIdPtrOfArrayToSlice: |
| 718 | return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name); |
| 719 | case IrInstGenIdAssertZero: |
| 720 | return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name); |
| 721 | case IrInstGenIdAssertNonNull: |
| 722 | return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name); |
| 723 | case IrInstGenIdResizeSlice: |
| 724 | return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name); |
| 725 | case IrInstGenIdAlloca: |
| 726 | return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name); |
| 727 | case IrInstGenIdSuspendBegin: |
| 728 | return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name); |
| 729 | case IrInstGenIdSuspendFinish: |
| 730 | return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name); |
| 731 | case IrInstGenIdResume: |
| 732 | return destroy(reinterpret_cast<IrInstGenResume *>(inst), name); |
| 733 | case IrInstGenIdAwait: |
| 734 | return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name); |
| 735 | case IrInstGenIdSpillBegin: |
| 736 | return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name); |
| 737 | case IrInstGenIdSpillEnd: |
| 738 | return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name); |
| 739 | case IrInstGenIdVectorExtractElem: |
| 740 | return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name); |
| 741 | case IrInstGenIdBinaryNot: |
| 742 | return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name); |
| 743 | case IrInstGenIdNegation: |
| 744 | return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name); |
| 745 | case IrInstGenIdNegationWrapping: |
| 746 | return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name); |
| 615 | 747 | } |
| 616 | 748 | zig_unreachable(); |
| 617 | 749 | } |
| ... | ... | @@ -627,17 +759,17 @@ static void ira_deref(IrAnalyze *ira) { |
| 627 | 759 | assert(ira->ref_count != 0); |
| 628 | 760 | |
| 629 | 761 | 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]; |
| 762 | IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i]; |
| 631 | 763 | 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); |
| 764 | IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i]; |
| 765 | destroy_instruction_src(pass1_inst); |
| 634 | 766 | } |
| 635 | | destroy(pass1_bb, "IrBasicBlock"); |
| 767 | destroy(pass1_bb, "IrBasicBlockSrc"); |
| 636 | 768 | } |
| 637 | 769 | ira->old_irb.exec->basic_block_list.deinit(); |
| 638 | 770 | ira->old_irb.exec->tld_list.deinit(); |
| 639 | 771 | // cannot destroy here because of var->owner_exec |
| 640 | | //destroy(ira->old_irb.exec, "IrExecutablePass1"); |
| 772 | //destroy(ira->old_irb.exec, "IrExecutableSrc"); |
| 641 | 773 | ira->src_implicit_return_type_list.deinit(); |
| 642 | 774 | ira->resume_stack.deinit(); |
| 643 | 775 | ira->exec_context.mem_slot_list.deinit(); |
| ... | ... | @@ -785,7 +917,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte |
| 785 | 917 | zig_unreachable(); |
| 786 | 918 | } |
| 787 | 919 | |
| 788 | | static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 920 | static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) { |
| 789 | 921 | if (exec->is_inline) |
| 790 | 922 | return true; |
| 791 | 923 | |
| ... | ... | @@ -801,29 +933,41 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) { |
| 801 | 933 | return false; |
| 802 | 934 | } |
| 803 | 935 | |
| 804 | | static void ir_instruction_append(IrBasicBlock *basic_block, IrInstruction *instruction) { |
| 936 | static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instruction) { |
| 937 | assert(basic_block); |
| 938 | assert(instruction); |
| 939 | basic_block->instruction_list.append(instruction); |
| 940 | } |
| 941 | |
| 942 | static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruction) { |
| 805 | 943 | assert(basic_block); |
| 806 | 944 | assert(instruction); |
| 807 | 945 | basic_block->instruction_list.append(instruction); |
| 808 | 946 | } |
| 809 | 947 | |
| 810 | | static size_t exec_next_debug_id(IrExecutable *exec) { |
| 948 | static size_t exec_next_debug_id(IrExecutableSrc *exec) { |
| 949 | size_t result = exec->next_debug_id; |
| 950 | exec->next_debug_id += 1; |
| 951 | return result; |
| 952 | } |
| 953 | |
| 954 | static size_t exec_next_debug_id_gen(IrExecutableGen *exec) { |
| 811 | 955 | size_t result = exec->next_debug_id; |
| 812 | 956 | exec->next_debug_id += 1; |
| 813 | 957 | return result; |
| 814 | 958 | } |
| 815 | 959 | |
| 816 | | static size_t exec_next_mem_slot(IrExecutable *exec) { |
| 960 | static size_t exec_next_mem_slot(IrExecutableSrc *exec) { |
| 817 | 961 | size_t result = exec->mem_slot_count; |
| 818 | 962 | exec->mem_slot_count += 1; |
| 819 | 963 | return result; |
| 820 | 964 | } |
| 821 | 965 | |
| 822 | | static ZigFn *exec_fn_entry(IrExecutable *exec) { |
| 966 | static ZigFn *exec_fn_entry(IrExecutableSrc *exec) { |
| 823 | 967 | return exec->fn_entry; |
| 824 | 968 | } |
| 825 | 969 | |
| 826 | | static Buf *exec_c_import_buf(IrExecutable *exec) { |
| 970 | static Buf *exec_c_import_buf(IrExecutableSrc *exec) { |
| 827 | 971 | return exec->c_import_buf; |
| 828 | 972 | } |
| 829 | 973 | |
| ... | ... | @@ -831,28 +975,42 @@ static bool value_is_comptime(ZigValue *const_val) { |
| 831 | 975 | return const_val->special != ConstValSpecialRuntime; |
| 832 | 976 | } |
| 833 | 977 | |
| 834 | | static bool instr_is_comptime(IrInstruction *instruction) { |
| 978 | static bool instr_is_comptime(IrInstGen *instruction) { |
| 835 | 979 | return value_is_comptime(instruction->value); |
| 836 | 980 | } |
| 837 | 981 | |
| 838 | | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 839 | | return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable; |
| 982 | static bool instr_is_unreachable(IrInstSrc *instruction) { |
| 983 | return instruction->is_noreturn; |
| 840 | 984 | } |
| 841 | 985 | |
| 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; |
| 986 | static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) { |
| 987 | new_bb->parent = old_bb; |
| 988 | old_bb->child = new_bb; |
| 845 | 989 | } |
| 846 | 990 | |
| 847 | | static void ir_ref_bb(IrBasicBlock *bb) { |
| 991 | static void ir_ref_bb(IrBasicBlockSrc *bb) { |
| 848 | 992 | bb->ref_count += 1; |
| 849 | 993 | } |
| 850 | 994 | |
| 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)) |
| 995 | static void ir_ref_bb_gen(IrBasicBlockGen *bb) { |
| 996 | bb->ref_count += 1; |
| 997 | } |
| 998 | |
| 999 | static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) { |
| 1000 | assert(instruction->id != IrInstSrcIdInvalid); |
| 1001 | instruction->base.ref_count += 1; |
| 1002 | if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction) |
| 1003 | && instruction->id != IrInstSrcIdConst) |
| 1004 | { |
| 855 | 1005 | ir_ref_bb(instruction->owner_bb); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | static void ir_ref_inst_gen(IrInstGen *instruction, IrBasicBlockGen *cur_bb) { |
| 1010 | assert(instruction->id != IrInstGenIdInvalid); |
| 1011 | instruction->base.ref_count += 1; |
| 1012 | if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction)) |
| 1013 | ir_ref_bb_gen(instruction->owner_bb); |
| 856 | 1014 | } |
| 857 | 1015 | |
| 858 | 1016 | static void ir_ref_var(ZigVar *var) { |
| ... | ... | @@ -871,962 +1029,1259 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { |
| 871 | 1029 | return result->data.x_type; |
| 872 | 1030 | } |
| 873 | 1031 | |
| 874 | | static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) { |
| 875 | | IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock"); |
| 1032 | static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) { |
| 1033 | IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc"); |
| 876 | 1034 | result->scope = scope; |
| 877 | 1035 | result->name_hint = name_hint; |
| 878 | 1036 | result->debug_id = exec_next_debug_id(irb->exec); |
| 879 | | result->index = SIZE_MAX; // set later |
| 1037 | result->index = UINT32_MAX; // set later |
| 880 | 1038 | return result; |
| 881 | 1039 | } |
| 882 | 1040 | |
| 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); |
| 1041 | static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) { |
| 1042 | IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen"); |
| 1043 | result->scope = scope; |
| 1044 | result->name_hint = name_hint; |
| 1045 | result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec); |
| 1046 | result->index = UINT32_MAX; // set later |
| 1047 | return result; |
| 1048 | } |
| 1049 | |
| 1050 | static IrBasicBlockGen *ir_build_bb_from(IrAnalyze *ira, IrBasicBlockSrc *other_bb) { |
| 1051 | IrBasicBlockGen *new_bb = ir_create_basic_block_gen(ira, other_bb->scope, other_bb->name_hint); |
| 885 | 1052 | ir_link_new_bb(new_bb, other_bb); |
| 886 | 1053 | return new_bb; |
| 887 | 1054 | } |
| 888 | 1055 | |
| 889 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) { |
| 890 | | return IrInstructionIdDeclVarSrc; |
| 1056 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) { |
| 1057 | return IrInstSrcIdDeclVar; |
| 1058 | } |
| 1059 | |
| 1060 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBr *) { |
| 1061 | return IrInstSrcIdBr; |
| 1062 | } |
| 1063 | |
| 1064 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCondBr *) { |
| 1065 | return IrInstSrcIdCondBr; |
| 1066 | } |
| 1067 | |
| 1068 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchBr *) { |
| 1069 | return IrInstSrcIdSwitchBr; |
| 1070 | } |
| 1071 | |
| 1072 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchVar *) { |
| 1073 | return IrInstSrcIdSwitchVar; |
| 1074 | } |
| 1075 | |
| 1076 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchElseVar *) { |
| 1077 | return IrInstSrcIdSwitchElseVar; |
| 1078 | } |
| 1079 | |
| 1080 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchTarget *) { |
| 1081 | return IrInstSrcIdSwitchTarget; |
| 1082 | } |
| 1083 | |
| 1084 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPhi *) { |
| 1085 | return IrInstSrcIdPhi; |
| 1086 | } |
| 1087 | |
| 1088 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnOp *) { |
| 1089 | return IrInstSrcIdUnOp; |
| 1090 | } |
| 1091 | |
| 1092 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBinOp *) { |
| 1093 | return IrInstSrcIdBinOp; |
| 1094 | } |
| 1095 | |
| 1096 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMergeErrSets *) { |
| 1097 | return IrInstSrcIdMergeErrSets; |
| 1098 | } |
| 1099 | |
| 1100 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcLoadPtr *) { |
| 1101 | return IrInstSrcIdLoadPtr; |
| 1102 | } |
| 1103 | |
| 1104 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcStorePtr *) { |
| 1105 | return IrInstSrcIdStorePtr; |
| 1106 | } |
| 1107 | |
| 1108 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldPtr *) { |
| 1109 | return IrInstSrcIdFieldPtr; |
| 1110 | } |
| 1111 | |
| 1112 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcElemPtr *) { |
| 1113 | return IrInstSrcIdElemPtr; |
| 1114 | } |
| 1115 | |
| 1116 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcVarPtr *) { |
| 1117 | return IrInstSrcIdVarPtr; |
| 1118 | } |
| 1119 | |
| 1120 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCall *) { |
| 1121 | return IrInstSrcIdCall; |
| 1122 | } |
| 1123 | |
| 1124 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallArgs *) { |
| 1125 | return IrInstSrcIdCallArgs; |
| 1126 | } |
| 1127 | |
| 1128 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallExtra *) { |
| 1129 | return IrInstSrcIdCallExtra; |
| 1130 | } |
| 1131 | |
| 1132 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcConst *) { |
| 1133 | return IrInstSrcIdConst; |
| 1134 | } |
| 1135 | |
| 1136 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturn *) { |
| 1137 | return IrInstSrcIdReturn; |
| 1138 | } |
| 1139 | |
| 1140 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitList *) { |
| 1141 | return IrInstSrcIdContainerInitList; |
| 1142 | } |
| 1143 | |
| 1144 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitFields *) { |
| 1145 | return IrInstSrcIdContainerInitFields; |
| 1146 | } |
| 1147 | |
| 1148 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnreachable *) { |
| 1149 | return IrInstSrcIdUnreachable; |
| 1150 | } |
| 1151 | |
| 1152 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeOf *) { |
| 1153 | return IrInstSrcIdTypeOf; |
| 1154 | } |
| 1155 | |
| 1156 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetCold *) { |
| 1157 | return IrInstSrcIdSetCold; |
| 1158 | } |
| 1159 | |
| 1160 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetRuntimeSafety *) { |
| 1161 | return IrInstSrcIdSetRuntimeSafety; |
| 1162 | } |
| 1163 | |
| 1164 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetFloatMode *) { |
| 1165 | return IrInstSrcIdSetFloatMode; |
| 1166 | } |
| 1167 | |
| 1168 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcArrayType *) { |
| 1169 | return IrInstSrcIdArrayType; |
| 1170 | } |
| 1171 | |
| 1172 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAnyFrameType *) { |
| 1173 | return IrInstSrcIdAnyFrameType; |
| 1174 | } |
| 1175 | |
| 1176 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSliceType *) { |
| 1177 | return IrInstSrcIdSliceType; |
| 1178 | } |
| 1179 | |
| 1180 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAsm *) { |
| 1181 | return IrInstSrcIdAsm; |
| 1182 | } |
| 1183 | |
| 1184 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSizeOf *) { |
| 1185 | return IrInstSrcIdSizeOf; |
| 1186 | } |
| 1187 | |
| 1188 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestNonNull *) { |
| 1189 | return IrInstSrcIdTestNonNull; |
| 1190 | } |
| 1191 | |
| 1192 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOptionalUnwrapPtr *) { |
| 1193 | return IrInstSrcIdOptionalUnwrapPtr; |
| 1194 | } |
| 1195 | |
| 1196 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcClz *) { |
| 1197 | return IrInstSrcIdClz; |
| 1198 | } |
| 1199 | |
| 1200 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCtz *) { |
| 1201 | return IrInstSrcIdCtz; |
| 1202 | } |
| 1203 | |
| 1204 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPopCount *) { |
| 1205 | return IrInstSrcIdPopCount; |
| 1206 | } |
| 1207 | |
| 1208 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBswap *) { |
| 1209 | return IrInstSrcIdBswap; |
| 1210 | } |
| 1211 | |
| 1212 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitReverse *) { |
| 1213 | return IrInstSrcIdBitReverse; |
| 1214 | } |
| 1215 | |
| 1216 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcImport *) { |
| 1217 | return IrInstSrcIdImport; |
| 1218 | } |
| 1219 | |
| 1220 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCImport *) { |
| 1221 | return IrInstSrcIdCImport; |
| 1222 | } |
| 1223 | |
| 1224 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCInclude *) { |
| 1225 | return IrInstSrcIdCInclude; |
| 1226 | } |
| 1227 | |
| 1228 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCDefine *) { |
| 1229 | return IrInstSrcIdCDefine; |
| 1230 | } |
| 1231 | |
| 1232 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCUndef *) { |
| 1233 | return IrInstSrcIdCUndef; |
| 1234 | } |
| 1235 | |
| 1236 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcRef *) { |
| 1237 | return IrInstSrcIdRef; |
| 1238 | } |
| 1239 | |
| 1240 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileErr *) { |
| 1241 | return IrInstSrcIdCompileErr; |
| 1242 | } |
| 1243 | |
| 1244 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileLog *) { |
| 1245 | return IrInstSrcIdCompileLog; |
| 1246 | } |
| 1247 | |
| 1248 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrName *) { |
| 1249 | return IrInstSrcIdErrName; |
| 1250 | } |
| 1251 | |
| 1252 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEmbedFile *) { |
| 1253 | return IrInstSrcIdEmbedFile; |
| 1254 | } |
| 1255 | |
| 1256 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCmpxchg *) { |
| 1257 | return IrInstSrcIdCmpxchg; |
| 1258 | } |
| 1259 | |
| 1260 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFence *) { |
| 1261 | return IrInstSrcIdFence; |
| 1262 | } |
| 1263 | |
| 1264 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTruncate *) { |
| 1265 | return IrInstSrcIdTruncate; |
| 1266 | } |
| 1267 | |
| 1268 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntCast *) { |
| 1269 | return IrInstSrcIdIntCast; |
| 1270 | } |
| 1271 | |
| 1272 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatCast *) { |
| 1273 | return IrInstSrcIdFloatCast; |
| 1274 | } |
| 1275 | |
| 1276 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToFloat *) { |
| 1277 | return IrInstSrcIdIntToFloat; |
| 1278 | } |
| 1279 | |
| 1280 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatToInt *) { |
| 1281 | return IrInstSrcIdFloatToInt; |
| 1282 | } |
| 1283 | |
| 1284 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) { |
| 1285 | return IrInstSrcIdBoolToInt; |
| 891 | 1286 | } |
| 892 | 1287 | |
| 893 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) { |
| 894 | | return IrInstructionIdDeclVarGen; |
| 1288 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) { |
| 1289 | return IrInstSrcIdIntType; |
| 895 | 1290 | } |
| 896 | 1291 | |
| 897 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) { |
| 898 | | return IrInstructionIdCondBr; |
| 1292 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) { |
| 1293 | return IrInstSrcIdVectorType; |
| 899 | 1294 | } |
| 900 | 1295 | |
| 901 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) { |
| 902 | | return IrInstructionIdBr; |
| 1296 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) { |
| 1297 | return IrInstSrcIdShuffleVector; |
| 903 | 1298 | } |
| 904 | 1299 | |
| 905 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) { |
| 906 | | return IrInstructionIdSwitchBr; |
| 1300 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) { |
| 1301 | return IrInstSrcIdSplat; |
| 907 | 1302 | } |
| 908 | 1303 | |
| 909 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) { |
| 910 | | return IrInstructionIdSwitchVar; |
| 1304 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) { |
| 1305 | return IrInstSrcIdBoolNot; |
| 911 | 1306 | } |
| 912 | 1307 | |
| 913 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) { |
| 914 | | return IrInstructionIdSwitchElseVar; |
| 1308 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) { |
| 1309 | return IrInstSrcIdMemset; |
| 915 | 1310 | } |
| 916 | 1311 | |
| 917 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) { |
| 918 | | return IrInstructionIdSwitchTarget; |
| 1312 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) { |
| 1313 | return IrInstSrcIdMemcpy; |
| 919 | 1314 | } |
| 920 | 1315 | |
| 921 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) { |
| 922 | | return IrInstructionIdPhi; |
| 1316 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) { |
| 1317 | return IrInstSrcIdSlice; |
| 923 | 1318 | } |
| 924 | 1319 | |
| 925 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) { |
| 926 | | return IrInstructionIdUnOp; |
| 1320 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) { |
| 1321 | return IrInstSrcIdMemberCount; |
| 927 | 1322 | } |
| 928 | 1323 | |
| 929 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) { |
| 930 | | return IrInstructionIdBinOp; |
| 1324 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) { |
| 1325 | return IrInstSrcIdMemberType; |
| 931 | 1326 | } |
| 932 | 1327 | |
| 933 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) { |
| 934 | | return IrInstructionIdMergeErrSets; |
| 1328 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) { |
| 1329 | return IrInstSrcIdMemberName; |
| 935 | 1330 | } |
| 936 | 1331 | |
| 937 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) { |
| 938 | | return IrInstructionIdExport; |
| 1332 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) { |
| 1333 | return IrInstSrcIdBreakpoint; |
| 939 | 1334 | } |
| 940 | 1335 | |
| 941 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) { |
| 942 | | return IrInstructionIdLoadPtr; |
| 1336 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) { |
| 1337 | return IrInstSrcIdReturnAddress; |
| 943 | 1338 | } |
| 944 | 1339 | |
| 945 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) { |
| 946 | | return IrInstructionIdLoadPtrGen; |
| 1340 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) { |
| 1341 | return IrInstSrcIdFrameAddress; |
| 947 | 1342 | } |
| 948 | 1343 | |
| 949 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) { |
| 950 | | return IrInstructionIdStorePtr; |
| 1344 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) { |
| 1345 | return IrInstSrcIdFrameHandle; |
| 951 | 1346 | } |
| 952 | 1347 | |
| 953 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) { |
| 954 | | return IrInstructionIdVectorStoreElem; |
| 1348 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) { |
| 1349 | return IrInstSrcIdFrameType; |
| 955 | 1350 | } |
| 956 | 1351 | |
| 957 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) { |
| 958 | | return IrInstructionIdFieldPtr; |
| 1352 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) { |
| 1353 | return IrInstSrcIdFrameSize; |
| 959 | 1354 | } |
| 960 | 1355 | |
| 961 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) { |
| 962 | | return IrInstructionIdStructFieldPtr; |
| 1356 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) { |
| 1357 | return IrInstSrcIdAlignOf; |
| 963 | 1358 | } |
| 964 | 1359 | |
| 965 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) { |
| 966 | | return IrInstructionIdUnionFieldPtr; |
| 1360 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) { |
| 1361 | return IrInstSrcIdOverflowOp; |
| 967 | 1362 | } |
| 968 | 1363 | |
| 969 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) { |
| 970 | | return IrInstructionIdElemPtr; |
| 1364 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) { |
| 1365 | return IrInstSrcIdTestErr; |
| 971 | 1366 | } |
| 972 | 1367 | |
| 973 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) { |
| 974 | | return IrInstructionIdVarPtr; |
| 1368 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) { |
| 1369 | return IrInstSrcIdMulAdd; |
| 975 | 1370 | } |
| 976 | 1371 | |
| 977 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) { |
| 978 | | return IrInstructionIdReturnPtr; |
| 1372 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) { |
| 1373 | return IrInstSrcIdFloatOp; |
| 979 | 1374 | } |
| 980 | 1375 | |
| 981 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) { |
| 982 | | return IrInstructionIdCallSrc; |
| 1376 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) { |
| 1377 | return IrInstSrcIdUnwrapErrCode; |
| 983 | 1378 | } |
| 984 | 1379 | |
| 985 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) { |
| 986 | | return IrInstructionIdCallSrcArgs; |
| 1380 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) { |
| 1381 | return IrInstSrcIdUnwrapErrPayload; |
| 987 | 1382 | } |
| 988 | 1383 | |
| 989 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) { |
| 990 | | return IrInstructionIdCallExtra; |
| 1384 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) { |
| 1385 | return IrInstSrcIdFnProto; |
| 991 | 1386 | } |
| 992 | 1387 | |
| 993 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) { |
| 994 | | return IrInstructionIdCallGen; |
| 1388 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) { |
| 1389 | return IrInstSrcIdTestComptime; |
| 995 | 1390 | } |
| 996 | 1391 | |
| 997 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) { |
| 998 | | return IrInstructionIdConst; |
| 1392 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) { |
| 1393 | return IrInstSrcIdPtrCast; |
| 999 | 1394 | } |
| 1000 | 1395 | |
| 1001 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) { |
| 1002 | | return IrInstructionIdReturn; |
| 1396 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) { |
| 1397 | return IrInstSrcIdBitCast; |
| 1003 | 1398 | } |
| 1004 | 1399 | |
| 1005 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) { |
| 1006 | | return IrInstructionIdCast; |
| 1400 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) { |
| 1401 | return IrInstSrcIdIntToPtr; |
| 1007 | 1402 | } |
| 1008 | 1403 | |
| 1009 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) { |
| 1010 | | return IrInstructionIdResizeSlice; |
| 1404 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) { |
| 1405 | return IrInstSrcIdPtrToInt; |
| 1011 | 1406 | } |
| 1012 | 1407 | |
| 1013 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) { |
| 1014 | | return IrInstructionIdContainerInitList; |
| 1408 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) { |
| 1409 | return IrInstSrcIdIntToEnum; |
| 1015 | 1410 | } |
| 1016 | 1411 | |
| 1017 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) { |
| 1018 | | return IrInstructionIdContainerInitFields; |
| 1412 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) { |
| 1413 | return IrInstSrcIdEnumToInt; |
| 1019 | 1414 | } |
| 1020 | 1415 | |
| 1021 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) { |
| 1022 | | return IrInstructionIdUnreachable; |
| 1416 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) { |
| 1417 | return IrInstSrcIdIntToErr; |
| 1023 | 1418 | } |
| 1024 | 1419 | |
| 1025 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) { |
| 1026 | | return IrInstructionIdTypeOf; |
| 1420 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) { |
| 1421 | return IrInstSrcIdErrToInt; |
| 1027 | 1422 | } |
| 1028 | 1423 | |
| 1029 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) { |
| 1030 | | return IrInstructionIdSetCold; |
| 1424 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) { |
| 1425 | return IrInstSrcIdCheckSwitchProngs; |
| 1031 | 1426 | } |
| 1032 | 1427 | |
| 1033 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) { |
| 1034 | | return IrInstructionIdSetRuntimeSafety; |
| 1428 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) { |
| 1429 | return IrInstSrcIdCheckStatementIsVoid; |
| 1035 | 1430 | } |
| 1036 | 1431 | |
| 1037 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) { |
| 1038 | | return IrInstructionIdSetFloatMode; |
| 1432 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) { |
| 1433 | return IrInstSrcIdTypeName; |
| 1039 | 1434 | } |
| 1040 | 1435 | |
| 1041 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) { |
| 1042 | | return IrInstructionIdArrayType; |
| 1436 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) { |
| 1437 | return IrInstSrcIdDeclRef; |
| 1043 | 1438 | } |
| 1044 | 1439 | |
| 1045 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) { |
| 1046 | | return IrInstructionIdAnyFrameType; |
| 1440 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) { |
| 1441 | return IrInstSrcIdPanic; |
| 1047 | 1442 | } |
| 1048 | 1443 | |
| 1049 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) { |
| 1050 | | return IrInstructionIdSliceType; |
| 1444 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) { |
| 1445 | return IrInstSrcIdTagName; |
| 1051 | 1446 | } |
| 1052 | 1447 | |
| 1053 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) { |
| 1054 | | return IrInstructionIdAsmSrc; |
| 1448 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) { |
| 1449 | return IrInstSrcIdTagType; |
| 1055 | 1450 | } |
| 1056 | 1451 | |
| 1057 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) { |
| 1058 | | return IrInstructionIdAsmGen; |
| 1452 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) { |
| 1453 | return IrInstSrcIdFieldParentPtr; |
| 1059 | 1454 | } |
| 1060 | 1455 | |
| 1061 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) { |
| 1062 | | return IrInstructionIdSizeOf; |
| 1456 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) { |
| 1457 | return IrInstSrcIdByteOffsetOf; |
| 1063 | 1458 | } |
| 1064 | 1459 | |
| 1065 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) { |
| 1066 | | return IrInstructionIdTestNonNull; |
| 1460 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) { |
| 1461 | return IrInstSrcIdBitOffsetOf; |
| 1067 | 1462 | } |
| 1068 | 1463 | |
| 1069 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) { |
| 1070 | | return IrInstructionIdOptionalUnwrapPtr; |
| 1464 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) { |
| 1465 | return IrInstSrcIdTypeInfo; |
| 1071 | 1466 | } |
| 1072 | 1467 | |
| 1073 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) { |
| 1074 | | return IrInstructionIdClz; |
| 1468 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) { |
| 1469 | return IrInstSrcIdType; |
| 1075 | 1470 | } |
| 1076 | 1471 | |
| 1077 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) { |
| 1078 | | return IrInstructionIdCtz; |
| 1472 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) { |
| 1473 | return IrInstSrcIdHasField; |
| 1079 | 1474 | } |
| 1080 | 1475 | |
| 1081 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) { |
| 1082 | | return IrInstructionIdPopCount; |
| 1476 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) { |
| 1477 | return IrInstSrcIdTypeId; |
| 1083 | 1478 | } |
| 1084 | 1479 | |
| 1085 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) { |
| 1086 | | return IrInstructionIdBswap; |
| 1480 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) { |
| 1481 | return IrInstSrcIdSetEvalBranchQuota; |
| 1087 | 1482 | } |
| 1088 | 1483 | |
| 1089 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) { |
| 1090 | | return IrInstructionIdBitReverse; |
| 1484 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) { |
| 1485 | return IrInstSrcIdPtrType; |
| 1091 | 1486 | } |
| 1092 | 1487 | |
| 1093 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) { |
| 1094 | | return IrInstructionIdUnionTag; |
| 1488 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) { |
| 1489 | return IrInstSrcIdAlignCast; |
| 1095 | 1490 | } |
| 1096 | 1491 | |
| 1097 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) { |
| 1098 | | return IrInstructionIdImport; |
| 1492 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) { |
| 1493 | return IrInstSrcIdImplicitCast; |
| 1099 | 1494 | } |
| 1100 | 1495 | |
| 1101 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) { |
| 1102 | | return IrInstructionIdCImport; |
| 1496 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) { |
| 1497 | return IrInstSrcIdResolveResult; |
| 1103 | 1498 | } |
| 1104 | 1499 | |
| 1105 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) { |
| 1106 | | return IrInstructionIdCInclude; |
| 1500 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) { |
| 1501 | return IrInstSrcIdResetResult; |
| 1107 | 1502 | } |
| 1108 | 1503 | |
| 1109 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) { |
| 1110 | | return IrInstructionIdCDefine; |
| 1504 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) { |
| 1505 | return IrInstSrcIdOpaqueType; |
| 1111 | 1506 | } |
| 1112 | 1507 | |
| 1113 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) { |
| 1114 | | return IrInstructionIdCUndef; |
| 1508 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) { |
| 1509 | return IrInstSrcIdSetAlignStack; |
| 1115 | 1510 | } |
| 1116 | 1511 | |
| 1117 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) { |
| 1118 | | return IrInstructionIdRef; |
| 1512 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) { |
| 1513 | return IrInstSrcIdArgType; |
| 1119 | 1514 | } |
| 1120 | 1515 | |
| 1121 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) { |
| 1122 | | return IrInstructionIdRefGen; |
| 1516 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) { |
| 1517 | return IrInstSrcIdExport; |
| 1123 | 1518 | } |
| 1124 | 1519 | |
| 1125 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 1126 | | return IrInstructionIdCompileErr; |
| 1520 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) { |
| 1521 | return IrInstSrcIdErrorReturnTrace; |
| 1127 | 1522 | } |
| 1128 | 1523 | |
| 1129 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) { |
| 1130 | | return IrInstructionIdCompileLog; |
| 1524 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) { |
| 1525 | return IrInstSrcIdErrorUnion; |
| 1131 | 1526 | } |
| 1132 | 1527 | |
| 1133 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) { |
| 1134 | | return IrInstructionIdErrName; |
| 1528 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) { |
| 1529 | return IrInstSrcIdAtomicRmw; |
| 1135 | 1530 | } |
| 1136 | 1531 | |
| 1137 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) { |
| 1138 | | return IrInstructionIdEmbedFile; |
| 1532 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) { |
| 1533 | return IrInstSrcIdAtomicLoad; |
| 1139 | 1534 | } |
| 1140 | 1535 | |
| 1141 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) { |
| 1142 | | return IrInstructionIdCmpxchgSrc; |
| 1536 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) { |
| 1537 | return IrInstSrcIdAtomicStore; |
| 1143 | 1538 | } |
| 1144 | 1539 | |
| 1145 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) { |
| 1146 | | return IrInstructionIdCmpxchgGen; |
| 1540 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) { |
| 1541 | return IrInstSrcIdSaveErrRetAddr; |
| 1147 | 1542 | } |
| 1148 | 1543 | |
| 1149 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) { |
| 1150 | | return IrInstructionIdFence; |
| 1544 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) { |
| 1545 | return IrInstSrcIdAddImplicitReturnType; |
| 1151 | 1546 | } |
| 1152 | 1547 | |
| 1153 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) { |
| 1154 | | return IrInstructionIdTruncate; |
| 1548 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) { |
| 1549 | return IrInstSrcIdErrSetCast; |
| 1155 | 1550 | } |
| 1156 | 1551 | |
| 1157 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) { |
| 1158 | | return IrInstructionIdIntCast; |
| 1552 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) { |
| 1553 | return IrInstSrcIdToBytes; |
| 1159 | 1554 | } |
| 1160 | 1555 | |
| 1161 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) { |
| 1162 | | return IrInstructionIdFloatCast; |
| 1556 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) { |
| 1557 | return IrInstSrcIdFromBytes; |
| 1163 | 1558 | } |
| 1164 | 1559 | |
| 1165 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) { |
| 1166 | | return IrInstructionIdErrSetCast; |
| 1560 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) { |
| 1561 | return IrInstSrcIdCheckRuntimeScope; |
| 1167 | 1562 | } |
| 1168 | 1563 | |
| 1169 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) { |
| 1170 | | return IrInstructionIdToBytes; |
| 1564 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) { |
| 1565 | return IrInstSrcIdHasDecl; |
| 1171 | 1566 | } |
| 1172 | 1567 | |
| 1173 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) { |
| 1174 | | return IrInstructionIdFromBytes; |
| 1568 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) { |
| 1569 | return IrInstSrcIdUndeclaredIdent; |
| 1175 | 1570 | } |
| 1176 | 1571 | |
| 1177 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) { |
| 1178 | | return IrInstructionIdIntToFloat; |
| 1572 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) { |
| 1573 | return IrInstSrcIdAlloca; |
| 1179 | 1574 | } |
| 1180 | 1575 | |
| 1181 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) { |
| 1182 | | return IrInstructionIdFloatToInt; |
| 1576 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) { |
| 1577 | return IrInstSrcIdEndExpr; |
| 1183 | 1578 | } |
| 1184 | 1579 | |
| 1185 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) { |
| 1186 | | return IrInstructionIdBoolToInt; |
| 1580 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) { |
| 1581 | return IrInstSrcIdUnionInitNamedField; |
| 1187 | 1582 | } |
| 1188 | 1583 | |
| 1189 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) { |
| 1190 | | return IrInstructionIdIntType; |
| 1584 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) { |
| 1585 | return IrInstSrcIdSuspendBegin; |
| 1191 | 1586 | } |
| 1192 | 1587 | |
| 1193 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) { |
| 1194 | | return IrInstructionIdVectorType; |
| 1588 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) { |
| 1589 | return IrInstSrcIdSuspendFinish; |
| 1195 | 1590 | } |
| 1196 | 1591 | |
| 1197 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) { |
| 1198 | | return IrInstructionIdShuffleVector; |
| 1592 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) { |
| 1593 | return IrInstSrcIdAwait; |
| 1199 | 1594 | } |
| 1200 | 1595 | |
| 1201 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) { |
| 1202 | | return IrInstructionIdSplatSrc; |
| 1596 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) { |
| 1597 | return IrInstSrcIdResume; |
| 1203 | 1598 | } |
| 1204 | 1599 | |
| 1205 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) { |
| 1206 | | return IrInstructionIdSplatGen; |
| 1600 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) { |
| 1601 | return IrInstSrcIdSpillBegin; |
| 1207 | 1602 | } |
| 1208 | 1603 | |
| 1209 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) { |
| 1210 | | return IrInstructionIdBoolNot; |
| 1604 | static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) { |
| 1605 | return IrInstSrcIdSpillEnd; |
| 1211 | 1606 | } |
| 1212 | 1607 | |
| 1213 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) { |
| 1214 | | return IrInstructionIdMemset; |
| 1608 | |
| 1609 | static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) { |
| 1610 | return IrInstGenIdDeclVar; |
| 1215 | 1611 | } |
| 1216 | 1612 | |
| 1217 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) { |
| 1218 | | return IrInstructionIdMemcpy; |
| 1613 | static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) { |
| 1614 | return IrInstGenIdBr; |
| 1219 | 1615 | } |
| 1220 | 1616 | |
| 1221 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) { |
| 1222 | | return IrInstructionIdSliceSrc; |
| 1617 | static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) { |
| 1618 | return IrInstGenIdCondBr; |
| 1223 | 1619 | } |
| 1224 | 1620 | |
| 1225 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) { |
| 1226 | | return IrInstructionIdSliceGen; |
| 1621 | static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) { |
| 1622 | return IrInstGenIdSwitchBr; |
| 1227 | 1623 | } |
| 1228 | 1624 | |
| 1229 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) { |
| 1230 | | return IrInstructionIdMemberCount; |
| 1625 | static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) { |
| 1626 | return IrInstGenIdPhi; |
| 1231 | 1627 | } |
| 1232 | 1628 | |
| 1233 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) { |
| 1234 | | return IrInstructionIdMemberType; |
| 1629 | static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) { |
| 1630 | return IrInstGenIdBinaryNot; |
| 1235 | 1631 | } |
| 1236 | 1632 | |
| 1237 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) { |
| 1238 | | return IrInstructionIdMemberName; |
| 1633 | static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) { |
| 1634 | return IrInstGenIdNegation; |
| 1239 | 1635 | } |
| 1240 | 1636 | |
| 1241 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) { |
| 1242 | | return IrInstructionIdBreakpoint; |
| 1637 | static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) { |
| 1638 | return IrInstGenIdNegationWrapping; |
| 1243 | 1639 | } |
| 1244 | 1640 | |
| 1245 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) { |
| 1246 | | return IrInstructionIdReturnAddress; |
| 1641 | static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) { |
| 1642 | return IrInstGenIdBinOp; |
| 1247 | 1643 | } |
| 1248 | 1644 | |
| 1249 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) { |
| 1250 | | return IrInstructionIdFrameAddress; |
| 1645 | static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) { |
| 1646 | return IrInstGenIdLoadPtr; |
| 1251 | 1647 | } |
| 1252 | 1648 | |
| 1253 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) { |
| 1254 | | return IrInstructionIdFrameHandle; |
| 1649 | static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) { |
| 1650 | return IrInstGenIdStorePtr; |
| 1255 | 1651 | } |
| 1256 | 1652 | |
| 1257 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) { |
| 1258 | | return IrInstructionIdFrameType; |
| 1653 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) { |
| 1654 | return IrInstGenIdVectorStoreElem; |
| 1259 | 1655 | } |
| 1260 | 1656 | |
| 1261 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) { |
| 1262 | | return IrInstructionIdFrameSizeSrc; |
| 1657 | static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) { |
| 1658 | return IrInstGenIdStructFieldPtr; |
| 1263 | 1659 | } |
| 1264 | 1660 | |
| 1265 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) { |
| 1266 | | return IrInstructionIdFrameSizeGen; |
| 1661 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) { |
| 1662 | return IrInstGenIdUnionFieldPtr; |
| 1267 | 1663 | } |
| 1268 | 1664 | |
| 1269 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) { |
| 1270 | | return IrInstructionIdAlignOf; |
| 1665 | static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) { |
| 1666 | return IrInstGenIdElemPtr; |
| 1271 | 1667 | } |
| 1272 | 1668 | |
| 1273 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) { |
| 1274 | | return IrInstructionIdOverflowOp; |
| 1669 | static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) { |
| 1670 | return IrInstGenIdVarPtr; |
| 1275 | 1671 | } |
| 1276 | 1672 | |
| 1277 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) { |
| 1278 | | return IrInstructionIdTestErrSrc; |
| 1673 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) { |
| 1674 | return IrInstGenIdReturnPtr; |
| 1279 | 1675 | } |
| 1280 | 1676 | |
| 1281 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) { |
| 1282 | | return IrInstructionIdTestErrGen; |
| 1677 | static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) { |
| 1678 | return IrInstGenIdCall; |
| 1283 | 1679 | } |
| 1284 | 1680 | |
| 1285 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) { |
| 1286 | | return IrInstructionIdMulAdd; |
| 1681 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) { |
| 1682 | return IrInstGenIdReturn; |
| 1287 | 1683 | } |
| 1288 | 1684 | |
| 1289 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) { |
| 1290 | | return IrInstructionIdUnwrapErrCode; |
| 1685 | static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) { |
| 1686 | return IrInstGenIdCast; |
| 1291 | 1687 | } |
| 1292 | 1688 | |
| 1293 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) { |
| 1294 | | return IrInstructionIdUnwrapErrPayload; |
| 1689 | static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) { |
| 1690 | return IrInstGenIdResizeSlice; |
| 1295 | 1691 | } |
| 1296 | 1692 | |
| 1297 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) { |
| 1298 | | return IrInstructionIdOptionalWrap; |
| 1693 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) { |
| 1694 | return IrInstGenIdUnreachable; |
| 1299 | 1695 | } |
| 1300 | 1696 | |
| 1301 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) { |
| 1302 | | return IrInstructionIdErrWrapPayload; |
| 1697 | static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) { |
| 1698 | return IrInstGenIdAsm; |
| 1303 | 1699 | } |
| 1304 | 1700 | |
| 1305 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) { |
| 1306 | | return IrInstructionIdErrWrapCode; |
| 1701 | static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) { |
| 1702 | return IrInstGenIdTestNonNull; |
| 1307 | 1703 | } |
| 1308 | 1704 | |
| 1309 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) { |
| 1310 | | return IrInstructionIdFnProto; |
| 1705 | static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) { |
| 1706 | return IrInstGenIdOptionalUnwrapPtr; |
| 1311 | 1707 | } |
| 1312 | 1708 | |
| 1313 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) { |
| 1314 | | return IrInstructionIdTestComptime; |
| 1709 | static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) { |
| 1710 | return IrInstGenIdOptionalWrap; |
| 1315 | 1711 | } |
| 1316 | 1712 | |
| 1317 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) { |
| 1318 | | return IrInstructionIdPtrCastSrc; |
| 1713 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) { |
| 1714 | return IrInstGenIdUnionTag; |
| 1319 | 1715 | } |
| 1320 | 1716 | |
| 1321 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) { |
| 1322 | | return IrInstructionIdPtrCastGen; |
| 1717 | static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) { |
| 1718 | return IrInstGenIdClz; |
| 1323 | 1719 | } |
| 1324 | 1720 | |
| 1325 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) { |
| 1326 | | return IrInstructionIdBitCastSrc; |
| 1721 | static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) { |
| 1722 | return IrInstGenIdCtz; |
| 1327 | 1723 | } |
| 1328 | 1724 | |
| 1329 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) { |
| 1330 | | return IrInstructionIdBitCastGen; |
| 1725 | static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) { |
| 1726 | return IrInstGenIdPopCount; |
| 1331 | 1727 | } |
| 1332 | 1728 | |
| 1333 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) { |
| 1334 | | return IrInstructionIdWidenOrShorten; |
| 1729 | static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) { |
| 1730 | return IrInstGenIdBswap; |
| 1335 | 1731 | } |
| 1336 | 1732 | |
| 1337 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) { |
| 1338 | | return IrInstructionIdPtrToInt; |
| 1733 | static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) { |
| 1734 | return IrInstGenIdBitReverse; |
| 1339 | 1735 | } |
| 1340 | 1736 | |
| 1341 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) { |
| 1342 | | return IrInstructionIdIntToPtr; |
| 1737 | static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) { |
| 1738 | return IrInstGenIdRef; |
| 1343 | 1739 | } |
| 1344 | 1740 | |
| 1345 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) { |
| 1346 | | return IrInstructionIdIntToEnum; |
| 1741 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) { |
| 1742 | return IrInstGenIdErrName; |
| 1347 | 1743 | } |
| 1348 | 1744 | |
| 1349 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) { |
| 1350 | | return IrInstructionIdEnumToInt; |
| 1745 | static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) { |
| 1746 | return IrInstGenIdCmpxchg; |
| 1351 | 1747 | } |
| 1352 | 1748 | |
| 1353 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) { |
| 1354 | | return IrInstructionIdIntToErr; |
| 1749 | static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) { |
| 1750 | return IrInstGenIdFence; |
| 1355 | 1751 | } |
| 1356 | 1752 | |
| 1357 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) { |
| 1358 | | return IrInstructionIdErrToInt; |
| 1753 | static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) { |
| 1754 | return IrInstGenIdTruncate; |
| 1359 | 1755 | } |
| 1360 | 1756 | |
| 1361 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) { |
| 1362 | | return IrInstructionIdCheckSwitchProngs; |
| 1757 | static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) { |
| 1758 | return IrInstGenIdShuffleVector; |
| 1363 | 1759 | } |
| 1364 | 1760 | |
| 1365 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) { |
| 1366 | | return IrInstructionIdCheckStatementIsVoid; |
| 1761 | static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) { |
| 1762 | return IrInstGenIdSplat; |
| 1367 | 1763 | } |
| 1368 | 1764 | |
| 1369 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) { |
| 1370 | | return IrInstructionIdTypeName; |
| 1765 | static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) { |
| 1766 | return IrInstGenIdBoolNot; |
| 1371 | 1767 | } |
| 1372 | 1768 | |
| 1373 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) { |
| 1374 | | return IrInstructionIdDeclRef; |
| 1769 | static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) { |
| 1770 | return IrInstGenIdMemset; |
| 1375 | 1771 | } |
| 1376 | 1772 | |
| 1377 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) { |
| 1378 | | return IrInstructionIdPanic; |
| 1773 | static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) { |
| 1774 | return IrInstGenIdMemcpy; |
| 1379 | 1775 | } |
| 1380 | 1776 | |
| 1381 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) { |
| 1382 | | return IrInstructionIdTagName; |
| 1777 | static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) { |
| 1778 | return IrInstGenIdSlice; |
| 1383 | 1779 | } |
| 1384 | 1780 | |
| 1385 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) { |
| 1386 | | return IrInstructionIdTagType; |
| 1781 | static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) { |
| 1782 | return IrInstGenIdBreakpoint; |
| 1387 | 1783 | } |
| 1388 | 1784 | |
| 1389 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) { |
| 1390 | | return IrInstructionIdFieldParentPtr; |
| 1785 | static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) { |
| 1786 | return IrInstGenIdReturnAddress; |
| 1391 | 1787 | } |
| 1392 | 1788 | |
| 1393 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) { |
| 1394 | | return IrInstructionIdByteOffsetOf; |
| 1789 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) { |
| 1790 | return IrInstGenIdFrameAddress; |
| 1395 | 1791 | } |
| 1396 | 1792 | |
| 1397 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) { |
| 1398 | | return IrInstructionIdBitOffsetOf; |
| 1793 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) { |
| 1794 | return IrInstGenIdFrameHandle; |
| 1399 | 1795 | } |
| 1400 | 1796 | |
| 1401 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) { |
| 1402 | | return IrInstructionIdTypeInfo; |
| 1797 | static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) { |
| 1798 | return IrInstGenIdFrameSize; |
| 1403 | 1799 | } |
| 1404 | 1800 | |
| 1405 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) { |
| 1406 | | return IrInstructionIdType; |
| 1801 | static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) { |
| 1802 | return IrInstGenIdOverflowOp; |
| 1407 | 1803 | } |
| 1408 | 1804 | |
| 1409 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) { |
| 1410 | | return IrInstructionIdHasField; |
| 1805 | static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) { |
| 1806 | return IrInstGenIdTestErr; |
| 1411 | 1807 | } |
| 1412 | 1808 | |
| 1413 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) { |
| 1414 | | return IrInstructionIdTypeId; |
| 1809 | static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) { |
| 1810 | return IrInstGenIdMulAdd; |
| 1415 | 1811 | } |
| 1416 | 1812 | |
| 1417 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) { |
| 1418 | | return IrInstructionIdSetEvalBranchQuota; |
| 1813 | static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) { |
| 1814 | return IrInstGenIdFloatOp; |
| 1419 | 1815 | } |
| 1420 | 1816 | |
| 1421 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) { |
| 1422 | | return IrInstructionIdPtrType; |
| 1817 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) { |
| 1818 | return IrInstGenIdUnwrapErrCode; |
| 1423 | 1819 | } |
| 1424 | 1820 | |
| 1425 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) { |
| 1426 | | return IrInstructionIdAlignCast; |
| 1821 | static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) { |
| 1822 | return IrInstGenIdUnwrapErrPayload; |
| 1427 | 1823 | } |
| 1428 | 1824 | |
| 1429 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) { |
| 1430 | | return IrInstructionIdImplicitCast; |
| 1825 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) { |
| 1826 | return IrInstGenIdErrWrapCode; |
| 1431 | 1827 | } |
| 1432 | 1828 | |
| 1433 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) { |
| 1434 | | return IrInstructionIdResolveResult; |
| 1829 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) { |
| 1830 | return IrInstGenIdErrWrapPayload; |
| 1435 | 1831 | } |
| 1436 | 1832 | |
| 1437 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) { |
| 1438 | | return IrInstructionIdResetResult; |
| 1833 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) { |
| 1834 | return IrInstGenIdPtrCast; |
| 1439 | 1835 | } |
| 1440 | 1836 | |
| 1441 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) { |
| 1442 | | return IrInstructionIdPtrOfArrayToSlice; |
| 1837 | static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) { |
| 1838 | return IrInstGenIdBitCast; |
| 1443 | 1839 | } |
| 1444 | 1840 | |
| 1445 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { |
| 1446 | | return IrInstructionIdOpaqueType; |
| 1841 | static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) { |
| 1842 | return IrInstGenIdWidenOrShorten; |
| 1447 | 1843 | } |
| 1448 | 1844 | |
| 1449 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) { |
| 1450 | | return IrInstructionIdSetAlignStack; |
| 1845 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) { |
| 1846 | return IrInstGenIdIntToPtr; |
| 1451 | 1847 | } |
| 1452 | 1848 | |
| 1453 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) { |
| 1454 | | return IrInstructionIdArgType; |
| 1849 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) { |
| 1850 | return IrInstGenIdPtrToInt; |
| 1455 | 1851 | } |
| 1456 | 1852 | |
| 1457 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) { |
| 1458 | | return IrInstructionIdErrorReturnTrace; |
| 1853 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) { |
| 1854 | return IrInstGenIdIntToEnum; |
| 1459 | 1855 | } |
| 1460 | 1856 | |
| 1461 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) { |
| 1462 | | return IrInstructionIdErrorUnion; |
| 1857 | static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) { |
| 1858 | return IrInstGenIdIntToErr; |
| 1463 | 1859 | } |
| 1464 | 1860 | |
| 1465 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) { |
| 1466 | | return IrInstructionIdAtomicRmw; |
| 1861 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) { |
| 1862 | return IrInstGenIdErrToInt; |
| 1467 | 1863 | } |
| 1468 | 1864 | |
| 1469 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) { |
| 1470 | | return IrInstructionIdAtomicLoad; |
| 1865 | static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) { |
| 1866 | return IrInstGenIdPanic; |
| 1471 | 1867 | } |
| 1472 | 1868 | |
| 1473 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) { |
| 1474 | | return IrInstructionIdAtomicStore; |
| 1869 | static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) { |
| 1870 | return IrInstGenIdTagName; |
| 1475 | 1871 | } |
| 1476 | 1872 | |
| 1477 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) { |
| 1478 | | return IrInstructionIdSaveErrRetAddr; |
| 1873 | static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) { |
| 1874 | return IrInstGenIdFieldParentPtr; |
| 1479 | 1875 | } |
| 1480 | 1876 | |
| 1481 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) { |
| 1482 | | return IrInstructionIdAddImplicitReturnType; |
| 1877 | static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) { |
| 1878 | return IrInstGenIdAlignCast; |
| 1483 | 1879 | } |
| 1484 | 1880 | |
| 1485 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) { |
| 1486 | | return IrInstructionIdFloatOp; |
| 1881 | static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) { |
| 1882 | return IrInstGenIdErrorReturnTrace; |
| 1487 | 1883 | } |
| 1488 | 1884 | |
| 1489 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) { |
| 1490 | | return IrInstructionIdCheckRuntimeScope; |
| 1885 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) { |
| 1886 | return IrInstGenIdAtomicRmw; |
| 1491 | 1887 | } |
| 1492 | 1888 | |
| 1493 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) { |
| 1494 | | return IrInstructionIdVectorToArray; |
| 1889 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) { |
| 1890 | return IrInstGenIdAtomicLoad; |
| 1495 | 1891 | } |
| 1496 | 1892 | |
| 1497 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) { |
| 1498 | | return IrInstructionIdArrayToVector; |
| 1893 | static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) { |
| 1894 | return IrInstGenIdAtomicStore; |
| 1499 | 1895 | } |
| 1500 | 1896 | |
| 1501 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) { |
| 1502 | | return IrInstructionIdAssertZero; |
| 1897 | static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) { |
| 1898 | return IrInstGenIdSaveErrRetAddr; |
| 1503 | 1899 | } |
| 1504 | 1900 | |
| 1505 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) { |
| 1506 | | return IrInstructionIdAssertNonNull; |
| 1901 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) { |
| 1902 | return IrInstGenIdVectorToArray; |
| 1507 | 1903 | } |
| 1508 | 1904 | |
| 1509 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { |
| 1510 | | return IrInstructionIdHasDecl; |
| 1905 | static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) { |
| 1906 | return IrInstGenIdArrayToVector; |
| 1511 | 1907 | } |
| 1512 | 1908 | |
| 1513 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) { |
| 1514 | | return IrInstructionIdUndeclaredIdent; |
| 1909 | static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) { |
| 1910 | return IrInstGenIdAssertZero; |
| 1515 | 1911 | } |
| 1516 | 1912 | |
| 1517 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) { |
| 1518 | | return IrInstructionIdAllocaSrc; |
| 1913 | static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) { |
| 1914 | return IrInstGenIdAssertNonNull; |
| 1519 | 1915 | } |
| 1520 | 1916 | |
| 1521 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) { |
| 1522 | | return IrInstructionIdAllocaGen; |
| 1917 | static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) { |
| 1918 | return IrInstGenIdPtrOfArrayToSlice; |
| 1523 | 1919 | } |
| 1524 | 1920 | |
| 1525 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) { |
| 1526 | | return IrInstructionIdEndExpr; |
| 1921 | static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) { |
| 1922 | return IrInstGenIdSuspendBegin; |
| 1527 | 1923 | } |
| 1528 | 1924 | |
| 1529 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) { |
| 1530 | | return IrInstructionIdUnionInitNamedField; |
| 1925 | static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) { |
| 1926 | return IrInstGenIdSuspendFinish; |
| 1531 | 1927 | } |
| 1532 | 1928 | |
| 1533 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) { |
| 1534 | | return IrInstructionIdSuspendBegin; |
| 1929 | static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) { |
| 1930 | return IrInstGenIdAwait; |
| 1535 | 1931 | } |
| 1536 | 1932 | |
| 1537 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) { |
| 1538 | | return IrInstructionIdSuspendFinish; |
| 1933 | static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) { |
| 1934 | return IrInstGenIdResume; |
| 1539 | 1935 | } |
| 1540 | 1936 | |
| 1541 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) { |
| 1542 | | return IrInstructionIdAwaitSrc; |
| 1937 | static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) { |
| 1938 | return IrInstGenIdSpillBegin; |
| 1543 | 1939 | } |
| 1544 | 1940 | |
| 1545 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) { |
| 1546 | | return IrInstructionIdAwaitGen; |
| 1941 | static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) { |
| 1942 | return IrInstGenIdSpillEnd; |
| 1547 | 1943 | } |
| 1548 | 1944 | |
| 1549 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) { |
| 1550 | | return IrInstructionIdResume; |
| 1945 | static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) { |
| 1946 | return IrInstGenIdVectorExtractElem; |
| 1551 | 1947 | } |
| 1552 | 1948 | |
| 1553 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) { |
| 1554 | | return IrInstructionIdSpillBegin; |
| 1949 | static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) { |
| 1950 | return IrInstGenIdAlloca; |
| 1555 | 1951 | } |
| 1556 | 1952 | |
| 1557 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) { |
| 1558 | | return IrInstructionIdSpillEnd; |
| 1953 | static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) { |
| 1954 | return IrInstGenIdConst; |
| 1559 | 1955 | } |
| 1560 | 1956 | |
| 1561 | | static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) { |
| 1562 | | return IrInstructionIdVectorExtractElem; |
| 1957 | template<typename T> |
| 1958 | static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 1959 | const char *name = nullptr; |
| 1960 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1961 | T *dummy = nullptr; |
| 1962 | name = ir_inst_src_type_str(ir_inst_id(dummy)); |
| 1963 | #endif |
| 1964 | T *special_instruction = allocate<T>(1, name); |
| 1965 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1966 | special_instruction->base.base.scope = scope; |
| 1967 | special_instruction->base.base.source_node = source_node; |
| 1968 | special_instruction->base.base.debug_id = exec_next_debug_id(irb->exec); |
| 1969 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1970 | return special_instruction; |
| 1563 | 1971 | } |
| 1564 | 1972 | |
| 1565 | 1973 | template<typename T> |
| 1566 | | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1974 | static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1567 | 1975 | const char *name = nullptr; |
| 1568 | 1976 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1569 | 1977 | T *dummy = nullptr; |
| 1570 | | name = ir_instruction_type_str(ir_instruction_id(dummy)); |
| 1978 | name = ir_inst_gen_type_str(ir_inst_id(dummy)); |
| 1571 | 1979 | #endif |
| 1572 | 1980 | 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); |
| 1981 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1982 | special_instruction->base.base.scope = scope; |
| 1983 | special_instruction->base.base.source_node = source_node; |
| 1984 | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1577 | 1985 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1578 | 1986 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 1579 | 1987 | return special_instruction; |
| 1580 | 1988 | } |
| 1581 | 1989 | |
| 1582 | 1990 | template<typename T> |
| 1583 | | static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1991 | static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1584 | 1992 | const char *name = nullptr; |
| 1585 | 1993 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1586 | 1994 | T *dummy = nullptr; |
| 1587 | | name = ir_instruction_type_str(ir_instruction_id(dummy)); |
| 1995 | name = ir_inst_gen_type_str(ir_inst_id(dummy)); |
| 1588 | 1996 | #endif |
| 1589 | 1997 | 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); |
| 1998 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1999 | special_instruction->base.base.scope = scope; |
| 2000 | special_instruction->base.base.source_node = source_node; |
| 2001 | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1594 | 2002 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1595 | 2003 | return special_instruction; |
| 1596 | 2004 | } |
| 1597 | 2005 | |
| 1598 | 2006 | template<typename T> |
| 1599 | | static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2007 | static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 1600 | 2008 | T *special_instruction = ir_create_instruction<T>(irb, scope, source_node); |
| 1601 | 2009 | ir_instruction_append(irb->current_basic_block, &special_instruction->base); |
| 1602 | 2010 | return special_instruction; |
| 1603 | 2011 | } |
| 1604 | 2012 | |
| 1605 | | static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type, |
| 1606 | | IrInstruction *value, CastOp cast_op) |
| 2013 | template<typename T> |
| 2014 | static T *ir_build_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2015 | T *special_instruction = ir_create_inst_gen<T>(irb, scope, source_node); |
| 2016 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2017 | return special_instruction; |
| 2018 | } |
| 2019 | |
| 2020 | template<typename T> |
| 2021 | static T *ir_build_inst_noreturn(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2022 | T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node); |
| 2023 | special_instruction->base.value = irb->codegen->intern.for_unreachable(); |
| 2024 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2025 | return special_instruction; |
| 2026 | } |
| 2027 | |
| 2028 | template<typename T> |
| 2029 | static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 2030 | T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node); |
| 2031 | special_instruction->base.value = irb->codegen->intern.for_void(); |
| 2032 | ir_inst_gen_append(irb->current_basic_block, &special_instruction->base); |
| 2033 | return special_instruction; |
| 2034 | } |
| 2035 | |
| 2036 | IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn, |
| 2037 | ZigType *var_type, const char *name_hint) |
| 1607 | 2038 | { |
| 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; |
| 2039 | IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1); |
| 2040 | alloca_gen->base.id = IrInstGenIdAlloca; |
| 2041 | alloca_gen->base.base.source_node = source_node; |
| 2042 | alloca_gen->base.base.scope = scope; |
| 2043 | alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 2044 | alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false); |
| 2045 | alloca_gen->base.base.ref_count = 1; |
| 2046 | alloca_gen->name_hint = name_hint; |
| 2047 | fn->alloca_gen_list.append(alloca_gen); |
| 2048 | return &alloca_gen->base; |
| 2049 | } |
| 1612 | 2050 | |
| 1613 | | ir_ref_instruction(value, irb->current_basic_block); |
| 2051 | static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type, |
| 2052 | IrInstGen *value, CastOp cast_op) |
| 2053 | { |
| 2054 | IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2055 | inst->base.value->type = dest_type; |
| 2056 | inst->value = value; |
| 2057 | inst->cast_op = cast_op; |
| 1614 | 2058 | |
| 1615 | | return &cast_instruction->base; |
| 2059 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2060 | |
| 2061 | return &inst->base; |
| 1616 | 2062 | } |
| 1617 | 2063 | |
| 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) |
| 2064 | static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition, |
| 2065 | IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime) |
| 1620 | 2066 | { |
| 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; |
| 2067 | IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node); |
| 2068 | inst->base.is_noreturn = true; |
| 2069 | inst->condition = condition; |
| 2070 | inst->then_block = then_block; |
| 2071 | inst->else_block = else_block; |
| 2072 | inst->is_comptime = is_comptime; |
| 1628 | 2073 | |
| 1629 | 2074 | ir_ref_instruction(condition, irb->current_basic_block); |
| 1630 | 2075 | ir_ref_bb(then_block); |
| 1631 | 2076 | ir_ref_bb(else_block); |
| 1632 | 2077 | if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 1633 | 2078 | |
| 1634 | | return &cond_br_instruction->base; |
| 2079 | return &inst->base; |
| 1635 | 2080 | } |
| 1636 | 2081 | |
| 1637 | | static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1638 | | IrInstruction *operand) |
| 2082 | static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition, |
| 2083 | IrBasicBlockGen *then_block, IrBasicBlockGen *else_block) |
| 1639 | 2084 | { |
| 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; |
| 2085 | IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2086 | inst->condition = condition; |
| 2087 | inst->then_block = then_block; |
| 2088 | inst->else_block = else_block; |
| 2089 | |
| 2090 | ir_ref_inst_gen(condition, ira->new_irb.current_basic_block); |
| 2091 | ir_ref_bb_gen(then_block); |
| 2092 | ir_ref_bb_gen(else_block); |
| 2093 | |
| 2094 | return &inst->base; |
| 2095 | } |
| 2096 | |
| 2097 | static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) { |
| 2098 | IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node); |
| 2099 | inst->base.is_noreturn = true; |
| 2100 | inst->operand = operand; |
| 1644 | 2101 | |
| 1645 | 2102 | if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); |
| 1646 | 2103 | |
| 1647 | | return &return_instruction->base; |
| 2104 | return &inst->base; |
| 2105 | } |
| 2106 | |
| 2107 | static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) { |
| 2108 | IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, |
| 2109 | source_inst->scope, source_inst->source_node); |
| 2110 | inst->operand = operand; |
| 2111 | |
| 2112 | if (operand != nullptr) ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2113 | |
| 2114 | return &inst->base; |
| 1648 | 2115 | } |
| 1649 | 2116 | |
| 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); |
| 2117 | static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2118 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1652 | 2119 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1653 | | const_instruction->base.value = irb->codegen->intern.for_void(); |
| 2120 | const_instruction->value = irb->codegen->intern.for_void(); |
| 1654 | 2121 | return &const_instruction->base; |
| 1655 | 2122 | } |
| 1656 | 2123 | |
| 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); |
| 2124 | static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2125 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1659 | 2126 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1660 | | const_instruction->base.value = irb->codegen->intern.for_undefined(); |
| 2127 | const_instruction->value = irb->codegen->intern.for_undefined(); |
| 1661 | 2128 | return &const_instruction->base; |
| 1662 | 2129 | } |
| 1663 | 2130 | |
| 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); |
| 2131 | static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 2132 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2133 | const_instruction->value = create_const_vals(1); |
| 2134 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 2135 | const_instruction->value->special = ConstValSpecialStatic; |
| 2136 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1669 | 2137 | return &const_instruction->base; |
| 1670 | 2138 | } |
| 1671 | 2139 | |
| 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); |
| 2140 | static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { |
| 2141 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2142 | const_instruction->value = create_const_vals(1); |
| 2143 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 2144 | const_instruction->value->special = ConstValSpecialStatic; |
| 2145 | bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint); |
| 1677 | 2146 | return &const_instruction->base; |
| 1678 | 2147 | } |
| 1679 | 2148 | |
| 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); |
| 2149 | static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { |
| 2150 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2151 | const_instruction->value = create_const_vals(1); |
| 2152 | const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float; |
| 2153 | const_instruction->value->special = ConstValSpecialStatic; |
| 2154 | bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat); |
| 1685 | 2155 | return &const_instruction->base; |
| 1686 | 2156 | } |
| 1687 | 2157 | |
| 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); |
| 2158 | static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2159 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 1690 | 2160 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1691 | | const_instruction->base.value = irb->codegen->intern.for_null(); |
| 2161 | const_instruction->value = irb->codegen->intern.for_null(); |
| 1692 | 2162 | return &const_instruction->base; |
| 1693 | 2163 | } |
| 1694 | 2164 | |
| 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); |
| 2165 | static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 2166 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2167 | const_instruction->value = create_const_vals(1); |
| 2168 | const_instruction->value->type = irb->codegen->builtin_types.entry_usize; |
| 2169 | const_instruction->value->special = ConstValSpecialStatic; |
| 2170 | bigint_init_unsigned(&const_instruction->value->data.x_bigint, value); |
| 1700 | 2171 | return &const_instruction->base; |
| 1701 | 2172 | } |
| 1702 | 2173 | |
| 1703 | | static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2174 | static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 1704 | 2175 | ZigType *type_entry) |
| 1705 | 2176 | { |
| 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; |
| 2177 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2178 | const_instruction->value = create_const_vals(1); |
| 2179 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; |
| 2180 | const_instruction->value->special = ConstValSpecialStatic; |
| 2181 | const_instruction->value->data.x_type = type_entry; |
| 1710 | 2182 | return &const_instruction->base; |
| 1711 | 2183 | } |
| 1712 | 2184 | |
| 1713 | | static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2185 | static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 1714 | 2186 | ZigType *type_entry) |
| 1715 | 2187 | { |
| 1716 | | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 2188 | IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 1717 | 2189 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1718 | 2190 | return instruction; |
| 1719 | 2191 | } |
| 1720 | 2192 | |
| 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; |
| 2193 | static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) { |
| 2194 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2195 | const_instruction->value = create_const_vals(1); |
| 2196 | const_instruction->value->type = irb->codegen->builtin_types.entry_type; |
| 2197 | const_instruction->value->special = ConstValSpecialStatic; |
| 2198 | const_instruction->value->data.x_type = import; |
| 1744 | 2199 | return &const_instruction->base; |
| 1745 | 2200 | } |
| 1746 | 2201 | |
| 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; |
| 2202 | static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) { |
| 2203 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2204 | const_instruction->value = create_const_vals(1); |
| 2205 | const_instruction->value->type = irb->codegen->builtin_types.entry_bool; |
| 2206 | const_instruction->value->special = ConstValSpecialStatic; |
| 2207 | const_instruction->value->data.x_bool = value; |
| 1752 | 2208 | return &const_instruction->base; |
| 1753 | 2209 | } |
| 1754 | 2210 | |
| 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; |
| 2211 | static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 2212 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2213 | const_instruction->value = create_const_vals(1); |
| 2214 | const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal; |
| 2215 | const_instruction->value->special = ConstValSpecialStatic; |
| 2216 | const_instruction->value->data.x_enum_literal = name; |
| 1763 | 2217 | return &const_instruction->base; |
| 1764 | 2218 | } |
| 1765 | 2219 | |
| 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); |
| 2220 | static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 2221 | IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node); |
| 2222 | const_instruction->value = create_const_vals(1); |
| 2223 | init_const_str_lit(irb->codegen, const_instruction->value, str); |
| 1769 | 2224 | |
| 1770 | 2225 | return &const_instruction->base; |
| 1771 | 2226 | } |
| 1772 | 2227 | |
| 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); |
| 2228 | static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 2229 | IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str); |
| 1775 | 2230 | ir_instruction_append(irb->current_basic_block, instruction); |
| 1776 | 2231 | return instruction; |
| 1777 | 2232 | } |
| 1778 | 2233 | |
| 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) |
| 2234 | static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 2235 | IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on) |
| 1781 | 2236 | { |
| 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; |
| 2237 | IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node); |
| 2238 | inst->op_id = op_id; |
| 2239 | inst->op1 = op1; |
| 2240 | inst->op2 = op2; |
| 2241 | inst->safety_check_on = safety_check_on; |
| 1787 | 2242 | |
| 1788 | 2243 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1789 | 2244 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1790 | 2245 | |
| 1791 | | return &bin_op_instruction->base; |
| 2246 | return &inst->base; |
| 1792 | 2247 | } |
| 1793 | 2248 | |
| 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) |
| 2249 | static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type, |
| 2250 | IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on) |
| 1796 | 2251 | { |
| 1797 | | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb, |
| 2252 | IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb, |
| 1798 | 2253 | 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; |
| 2254 | inst->base.value->type = res_type; |
| 2255 | inst->op_id = op_id; |
| 2256 | inst->op1 = op1; |
| 2257 | inst->op2 = op2; |
| 2258 | inst->safety_check_on = safety_check_on; |
| 1804 | 2259 | |
| 1805 | | ir_ref_instruction(op1, ira->new_irb.current_basic_block); |
| 1806 | | ir_ref_instruction(op2, ira->new_irb.current_basic_block); |
| 2260 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 2261 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 1807 | 2262 | |
| 1808 | | return &bin_op_instruction->base; |
| 2263 | return &inst->base; |
| 1809 | 2264 | } |
| 1810 | 2265 | |
| 1811 | 2266 | |
| 1812 | | static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1813 | | IrInstruction *op1, IrInstruction *op2, Buf *type_name) |
| 2267 | static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2268 | IrInstSrc *op1, IrInstSrc *op2, Buf *type_name) |
| 1814 | 2269 | { |
| 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; |
| 2270 | IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node); |
| 2271 | inst->op1 = op1; |
| 2272 | inst->op2 = op2; |
| 2273 | inst->type_name = type_name; |
| 1819 | 2274 | |
| 1820 | 2275 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1821 | 2276 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1822 | 2277 | |
| 1823 | | return &merge_err_sets_instruction->base; |
| 2278 | return &inst->base; |
| 1824 | 2279 | } |
| 1825 | 2280 | |
| 1826 | | static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 2281 | static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 1827 | 2282 | ScopeFnDef *crossed_fndef_scope) |
| 1828 | 2283 | { |
| 1829 | | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 2284 | IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node); |
| 1830 | 2285 | instruction->var = var; |
| 1831 | 2286 | instruction->crossed_fndef_scope = crossed_fndef_scope; |
| 1832 | 2287 | |
| ... | ... | @@ -1835,22 +2290,31 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode * |
| 1835 | 2290 | return &instruction->base; |
| 1836 | 2291 | } |
| 1837 | 2292 | |
| 1838 | | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 2293 | static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 1839 | 2294 | return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr); |
| 1840 | 2295 | } |
| 1841 | 2296 | |
| 1842 | | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 1843 | | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, |
| 2297 | static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 2298 | IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2299 | instruction->var = var; |
| 2300 | |
| 2301 | ir_ref_var(var); |
| 2302 | |
| 2303 | return &instruction->base; |
| 2304 | } |
| 2305 | |
| 2306 | static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 2307 | IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb, |
| 1844 | 2308 | source_instruction->scope, source_instruction->source_node); |
| 1845 | 2309 | instruction->base.value->type = ty; |
| 1846 | 2310 | return &instruction->base; |
| 1847 | 2311 | } |
| 1848 | 2312 | |
| 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, |
| 2313 | static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2314 | IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len, |
| 1851 | 2315 | AstNode *init_array_type_source_node) |
| 1852 | 2316 | { |
| 1853 | | IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node); |
| 2317 | IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node); |
| 1854 | 2318 | instruction->array_ptr = array_ptr; |
| 1855 | 2319 | instruction->elem_index = elem_index; |
| 1856 | 2320 | instruction->safety_check_on = safety_check_on; |
| ... | ... | @@ -1863,10 +2327,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 1863 | 2327 | return &instruction->base; |
| 1864 | 2328 | } |
| 1865 | 2329 | |
| 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) |
| 2330 | static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2331 | IrInstGen *array_ptr, IrInstGen *elem_index, bool safety_check_on, ZigType *return_type) |
| 2332 | { |
| 2333 | IrInstGenElemPtr *instruction = ir_build_inst_gen<IrInstGenElemPtr>(&ira->new_irb, scope, source_node); |
| 2334 | instruction->base.value->type = return_type; |
| 2335 | instruction->array_ptr = array_ptr; |
| 2336 | instruction->elem_index = elem_index; |
| 2337 | instruction->safety_check_on = safety_check_on; |
| 2338 | |
| 2339 | ir_ref_inst_gen(array_ptr, ira->new_irb.current_basic_block); |
| 2340 | ir_ref_inst_gen(elem_index, ira->new_irb.current_basic_block); |
| 2341 | |
| 2342 | return &instruction->base; |
| 2343 | } |
| 2344 | |
| 2345 | static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2346 | IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing) |
| 1868 | 2347 | { |
| 1869 | | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 2348 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); |
| 1870 | 2349 | instruction->container_ptr = container_ptr; |
| 1871 | 2350 | instruction->field_name_buffer = nullptr; |
| 1872 | 2351 | instruction->field_name_expr = field_name_expr; |
| ... | ... | @@ -1878,10 +2357,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop |
| 1878 | 2357 | return &instruction->base; |
| 1879 | 2358 | } |
| 1880 | 2359 | |
| 1881 | | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1882 | | IrInstruction *container_ptr, Buf *field_name, bool initializing) |
| 2360 | static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2361 | IrInstSrc *container_ptr, Buf *field_name, bool initializing) |
| 1883 | 2362 | { |
| 1884 | | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 2363 | IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node); |
| 1885 | 2364 | instruction->container_ptr = container_ptr; |
| 1886 | 2365 | instruction->field_name_buffer = field_name; |
| 1887 | 2366 | instruction->field_name_expr = nullptr; |
| ... | ... | @@ -1892,10 +2371,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1892 | 2371 | return &instruction->base; |
| 1893 | 2372 | } |
| 1894 | 2373 | |
| 1895 | | static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1896 | | IrInstruction *container_type, IrInstruction *field_name) |
| 2374 | static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2375 | IrInstSrc *container_type, IrInstSrc *field_name) |
| 1897 | 2376 | { |
| 1898 | | IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node); |
| 2377 | IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node); |
| 1899 | 2378 | instruction->container_type = container_type; |
| 1900 | 2379 | instruction->field_name = field_name; |
| 1901 | 2380 | |
| ... | ... | @@ -1905,36 +2384,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode * |
| 1905 | 2384 | return &instruction->base; |
| 1906 | 2385 | } |
| 1907 | 2386 | |
| 1908 | | static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1909 | | IrInstruction *struct_ptr, TypeStructField *field) |
| 2387 | static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 2388 | IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type) |
| 1910 | 2389 | { |
| 1911 | | IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node); |
| 1912 | | instruction->struct_ptr = struct_ptr; |
| 1913 | | instruction->field = field; |
| 2390 | IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2391 | inst->base.value->type = ptr_type; |
| 2392 | inst->struct_ptr = struct_ptr; |
| 2393 | inst->field = field; |
| 1914 | 2394 | |
| 1915 | | ir_ref_instruction(struct_ptr, irb->current_basic_block); |
| 2395 | ir_ref_inst_gen(struct_ptr, ira->new_irb.current_basic_block); |
| 1916 | 2396 | |
| 1917 | | return &instruction->base; |
| 2397 | return &inst->base; |
| 1918 | 2398 | } |
| 1919 | 2399 | |
| 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) |
| 2400 | static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 2401 | IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type) |
| 1922 | 2402 | { |
| 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; |
| 2403 | IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb, |
| 2404 | source_instr->scope, source_instr->source_node); |
| 2405 | inst->base.value->type = ptr_type; |
| 2406 | inst->initializing = initializing; |
| 2407 | inst->safety_check_on = safety_check_on; |
| 2408 | inst->union_ptr = union_ptr; |
| 2409 | inst->field = field; |
| 1928 | 2410 | |
| 1929 | | ir_ref_instruction(union_ptr, irb->current_basic_block); |
| 2411 | ir_ref_inst_gen(union_ptr, ira->new_irb.current_basic_block); |
| 1930 | 2412 | |
| 1931 | | return &instruction->base; |
| 2413 | return &inst->base; |
| 1932 | 2414 | } |
| 1933 | 2415 | |
| 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) |
| 2416 | static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2417 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc) |
| 1936 | 2418 | { |
| 1937 | | IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node); |
| 2419 | IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node); |
| 1938 | 2420 | call_instruction->options = options; |
| 1939 | 2421 | call_instruction->fn_ref = fn_ref; |
| 1940 | 2422 | call_instruction->args = args; |
| ... | ... | @@ -1947,11 +2429,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode |
| 1947 | 2429 | return &call_instruction->base; |
| 1948 | 2430 | } |
| 1949 | 2431 | |
| 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, |
| 2432 | static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2433 | IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len, |
| 1952 | 2434 | ResultLoc *result_loc) |
| 1953 | 2435 | { |
| 1954 | | IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node); |
| 2436 | IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node); |
| 1955 | 2437 | call_instruction->options = options; |
| 1956 | 2438 | call_instruction->fn_ref = fn_ref; |
| 1957 | 2439 | call_instruction->args_ptr = args_ptr; |
| ... | ... | @@ -1966,12 +2448,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo |
| 1966 | 2448 | return &call_instruction->base; |
| 1967 | 2449 | } |
| 1968 | 2450 | |
| 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) |
| 2451 | static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2452 | ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args, |
| 2453 | IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin, |
| 2454 | IrInstSrc *new_stack, ResultLoc *result_loc) |
| 1973 | 2455 | { |
| 1974 | | IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node); |
| 2456 | IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node); |
| 1975 | 2457 | call_instruction->fn_entry = fn_entry; |
| 1976 | 2458 | call_instruction->fn_ref = fn_ref; |
| 1977 | 2459 | call_instruction->args = args; |
| ... | ... | @@ -1991,12 +2473,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s |
| 1991 | 2473 | return &call_instruction->base; |
| 1992 | 2474 | } |
| 1993 | 2475 | |
| 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) |
| 2476 | static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2477 | ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args, |
| 2478 | CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin, |
| 2479 | IrInstGen *result_loc, ZigType *return_type) |
| 1998 | 2480 | { |
| 1999 | | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, |
| 2481 | IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb, |
| 2000 | 2482 | source_instruction->scope, source_instruction->source_node); |
| 2001 | 2483 | call_instruction->base.value->type = return_type; |
| 2002 | 2484 | call_instruction->fn_entry = fn_entry; |
| ... | ... | @@ -2008,23 +2490,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so |
| 2008 | 2490 | call_instruction->new_stack = new_stack; |
| 2009 | 2491 | call_instruction->result_loc = result_loc; |
| 2010 | 2492 | |
| 2011 | | if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block); |
| 2493 | if (fn_ref != nullptr) ir_ref_inst_gen(fn_ref, ira->new_irb.current_basic_block); |
| 2012 | 2494 | 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); |
| 2495 | ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block); |
| 2496 | if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block); |
| 2497 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2016 | 2498 | |
| 2017 | 2499 | return call_instruction; |
| 2018 | 2500 | } |
| 2019 | 2501 | |
| 2020 | | static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2021 | | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values, |
| 2502 | static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2503 | size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values, |
| 2022 | 2504 | ResultLocPeerParent *peer_parent) |
| 2023 | 2505 | { |
| 2024 | 2506 | assert(incoming_count != 0); |
| 2025 | 2507 | assert(incoming_count != SIZE_MAX); |
| 2026 | 2508 | |
| 2027 | | IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node); |
| 2509 | IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node); |
| 2028 | 2510 | phi_instruction->incoming_count = incoming_count; |
| 2029 | 2511 | phi_instruction->incoming_blocks = incoming_blocks; |
| 2030 | 2512 | phi_instruction->incoming_values = incoming_values; |
| ... | ... | @@ -2038,56 +2520,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source |
| 2038 | 2520 | return &phi_instruction->base; |
| 2039 | 2521 | } |
| 2040 | 2522 | |
| 2041 | | static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2042 | | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 2523 | static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count, |
| 2524 | IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type) |
| 2525 | { |
| 2526 | assert(incoming_count != 0); |
| 2527 | assert(incoming_count != SIZE_MAX); |
| 2528 | |
| 2529 | IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb, |
| 2530 | source_instr->scope, source_instr->source_node); |
| 2531 | phi_instruction->base.value->type = result_type; |
| 2532 | phi_instruction->incoming_count = incoming_count; |
| 2533 | phi_instruction->incoming_blocks = incoming_blocks; |
| 2534 | phi_instruction->incoming_values = incoming_values; |
| 2535 | |
| 2536 | for (size_t i = 0; i < incoming_count; i += 1) { |
| 2537 | ir_ref_bb_gen(incoming_blocks[i]); |
| 2538 | ir_ref_inst_gen(incoming_values[i], ira->new_irb.current_basic_block); |
| 2539 | } |
| 2540 | |
| 2541 | return &phi_instruction->base; |
| 2542 | } |
| 2543 | |
| 2544 | static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2545 | IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime) |
| 2043 | 2546 | { |
| 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; |
| 2547 | IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node); |
| 2548 | inst->base.is_noreturn = true; |
| 2549 | inst->dest_block = dest_block; |
| 2550 | inst->is_comptime = is_comptime; |
| 2049 | 2551 | |
| 2050 | 2552 | ir_ref_bb(dest_block); |
| 2051 | 2553 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 2052 | 2554 | |
| 2053 | | return &br_instruction->base; |
| 2555 | return &inst->base; |
| 2054 | 2556 | } |
| 2055 | 2557 | |
| 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; |
| 2558 | static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) { |
| 2559 | IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2560 | inst->dest_block = dest_block; |
| 2561 | |
| 2562 | ir_ref_bb_gen(dest_block); |
| 2563 | |
| 2564 | return &inst->base; |
| 2062 | 2565 | } |
| 2063 | 2566 | |
| 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, |
| 2567 | static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2568 | IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 2569 | IrInstSrc *sentinel, IrInstSrc *align_value, |
| 2067 | 2570 | uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) |
| 2068 | 2571 | { |
| 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; |
| 2572 | IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node); |
| 2573 | inst->sentinel = sentinel; |
| 2574 | inst->align_value = align_value; |
| 2575 | inst->child_type = child_type; |
| 2576 | inst->is_const = is_const; |
| 2577 | inst->is_volatile = is_volatile; |
| 2578 | inst->ptr_len = ptr_len; |
| 2579 | inst->bit_offset_start = bit_offset_start; |
| 2580 | inst->host_int_bytes = host_int_bytes; |
| 2581 | inst->is_allow_zero = is_allow_zero; |
| 2079 | 2582 | |
| 2080 | 2583 | if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block); |
| 2081 | 2584 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2082 | 2585 | ir_ref_instruction(child_type, irb->current_basic_block); |
| 2083 | 2586 | |
| 2084 | | return &ptr_type_of_instruction->base; |
| 2587 | return &inst->base; |
| 2085 | 2588 | } |
| 2086 | 2589 | |
| 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) |
| 2590 | static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2591 | IrInstSrc *value, LVal lval, ResultLoc *result_loc) |
| 2089 | 2592 | { |
| 2090 | | IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 2593 | IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node); |
| 2091 | 2594 | instruction->op_id = op_id; |
| 2092 | 2595 | instruction->value = value; |
| 2093 | 2596 | instruction->lval = lval; |
| ... | ... | @@ -2098,36 +2601,73 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode |
| 2098 | 2601 | return &instruction->base; |
| 2099 | 2602 | } |
| 2100 | 2603 | |
| 2101 | | static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2102 | | IrInstruction *value) |
| 2604 | static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, |
| 2605 | IrInstSrc *value) |
| 2103 | 2606 | { |
| 2104 | 2607 | return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr); |
| 2105 | 2608 | } |
| 2106 | 2609 | |
| 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, |
| 2109 | | AstNode *init_array_type_source_node) |
| 2110 | | { |
| 2111 | | IrInstructionContainerInitList *container_init_list_instruction = |
| 2112 | | ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node); |
| 2113 | | container_init_list_instruction->item_count = item_count; |
| 2114 | | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; |
| 2115 | | container_init_list_instruction->result_loc = result_loc; |
| 2116 | | container_init_list_instruction->init_array_type_source_node = init_array_type_source_node; |
| 2610 | static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) { |
| 2611 | IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb, |
| 2612 | source_instr->scope, source_instr->source_node); |
| 2613 | instruction->base.value->type = expr_type; |
| 2614 | instruction->operand = operand; |
| 2117 | 2615 | |
| 2118 | | for (size_t i = 0; i < item_count; i += 1) { |
| 2119 | | ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block); |
| 2616 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2617 | |
| 2618 | return &instruction->base; |
| 2619 | } |
| 2620 | |
| 2621 | static IrInstGen *ir_build_negation_wrapping(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 2622 | ZigType *expr_type) |
| 2623 | { |
| 2624 | IrInstGenNegationWrapping *instruction = ir_build_inst_gen<IrInstGenNegationWrapping>(&ira->new_irb, |
| 2625 | source_instr->scope, source_instr->source_node); |
| 2626 | instruction->base.value->type = expr_type; |
| 2627 | instruction->operand = operand; |
| 2628 | |
| 2629 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2630 | |
| 2631 | return &instruction->base; |
| 2632 | } |
| 2633 | |
| 2634 | static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 2635 | ZigType *expr_type) |
| 2636 | { |
| 2637 | IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb, |
| 2638 | source_instr->scope, source_instr->source_node); |
| 2639 | instruction->base.value->type = expr_type; |
| 2640 | instruction->operand = operand; |
| 2641 | |
| 2642 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2643 | |
| 2644 | return &instruction->base; |
| 2645 | } |
| 2646 | |
| 2647 | static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2648 | size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc, |
| 2649 | AstNode *init_array_type_source_node) |
| 2650 | { |
| 2651 | IrInstSrcContainerInitList *container_init_list_instruction = |
| 2652 | ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node); |
| 2653 | container_init_list_instruction->item_count = item_count; |
| 2654 | container_init_list_instruction->elem_result_loc_list = elem_result_loc_list; |
| 2655 | container_init_list_instruction->result_loc = result_loc; |
| 2656 | container_init_list_instruction->init_array_type_source_node = init_array_type_source_node; |
| 2657 | |
| 2658 | for (size_t i = 0; i < item_count; i += 1) { |
| 2659 | ir_ref_instruction(elem_result_loc_list[i], irb->current_basic_block); |
| 2120 | 2660 | } |
| 2121 | 2661 | if (result_loc != nullptr) ir_ref_instruction(result_loc, irb->current_basic_block); |
| 2122 | 2662 | |
| 2123 | 2663 | return &container_init_list_instruction->base; |
| 2124 | 2664 | } |
| 2125 | 2665 | |
| 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) |
| 2666 | static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2667 | size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc) |
| 2128 | 2668 | { |
| 2129 | | IrInstructionContainerInitFields *container_init_fields_instruction = |
| 2130 | | ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node); |
| 2669 | IrInstSrcContainerInitFields *container_init_fields_instruction = |
| 2670 | ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node); |
| 2131 | 2671 | container_init_fields_instruction->field_count = field_count; |
| 2132 | 2672 | container_init_fields_instruction->fields = fields; |
| 2133 | 2673 | container_init_fields_instruction->result_loc = result_loc; |
| ... | ... | @@ -2140,20 +2680,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 2140 | 2680 | return &container_init_fields_instruction->base; |
| 2141 | 2681 | } |
| 2142 | 2682 | |
| 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; |
| 2683 | static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 2684 | IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node); |
| 2685 | inst->base.is_noreturn = true; |
| 2686 | return &inst->base; |
| 2687 | } |
| 2688 | |
| 2689 | static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 2690 | IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2691 | return &inst->base; |
| 2149 | 2692 | } |
| 2150 | 2693 | |
| 2151 | | static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2152 | | IrInstruction *ptr, IrInstruction *value) |
| 2694 | static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2695 | IrInstSrc *ptr, IrInstSrc *value) |
| 2153 | 2696 | { |
| 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; |
| 2697 | IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node); |
| 2157 | 2698 | instruction->ptr = ptr; |
| 2158 | 2699 | instruction->value = value; |
| 2159 | 2700 | |
| ... | ... | @@ -2163,76 +2704,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A |
| 2163 | 2704 | return instruction; |
| 2164 | 2705 | } |
| 2165 | 2706 | |
| 2166 | | static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2167 | | IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *value) |
| 2707 | static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) { |
| 2708 | IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb, |
| 2709 | source_instr->scope, source_instr->source_node); |
| 2710 | instruction->ptr = ptr; |
| 2711 | instruction->value = value; |
| 2712 | |
| 2713 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 2714 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2715 | |
| 2716 | return &instruction->base; |
| 2717 | } |
| 2718 | |
| 2719 | static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst, |
| 2720 | IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value) |
| 2168 | 2721 | { |
| 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; |
| 2722 | IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>( |
| 2723 | &ira->new_irb, src_inst->scope, src_inst->source_node); |
| 2172 | 2724 | inst->vector_ptr = vector_ptr; |
| 2173 | 2725 | inst->index = index; |
| 2174 | 2726 | inst->value = value; |
| 2175 | 2727 | |
| 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); |
| 2728 | ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block); |
| 2729 | ir_ref_inst_gen(index, ira->new_irb.current_basic_block); |
| 2730 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2179 | 2731 | |
| 2180 | 2732 | return &inst->base; |
| 2181 | 2733 | } |
| 2182 | 2734 | |
| 2183 | | static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2184 | | ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) |
| 2735 | static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2736 | ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr) |
| 2185 | 2737 | { |
| 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; |
| 2738 | IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node); |
| 2739 | inst->var = var; |
| 2740 | inst->align_value = align_value; |
| 2741 | inst->ptr = ptr; |
| 2192 | 2742 | |
| 2193 | 2743 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2194 | 2744 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 2195 | 2745 | |
| 2196 | | return &decl_var_instruction->base; |
| 2746 | return &inst->base; |
| 2197 | 2747 | } |
| 2198 | 2748 | |
| 2199 | | static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2200 | | ZigVar *var, IrInstruction *var_ptr) |
| 2749 | static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2750 | ZigVar *var, IrInstGen *var_ptr) |
| 2201 | 2751 | { |
| 2202 | | IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb, |
| 2752 | IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb, |
| 2203 | 2753 | 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; |
| 2754 | inst->base.value->special = ConstValSpecialStatic; |
| 2755 | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2756 | inst->var = var; |
| 2757 | inst->var_ptr = var_ptr; |
| 2208 | 2758 | |
| 2209 | | ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block); |
| 2759 | ir_ref_inst_gen(var_ptr, ira->new_irb.current_basic_block); |
| 2210 | 2760 | |
| 2211 | | return &decl_var_instruction->base; |
| 2761 | return &inst->base; |
| 2212 | 2762 | } |
| 2213 | 2763 | |
| 2214 | | static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2215 | | IrInstruction *operand, ZigType *ty, IrInstruction *result_loc) |
| 2764 | static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction, |
| 2765 | IrInstGen *operand, ZigType *ty, IrInstGen *result_loc) |
| 2216 | 2766 | { |
| 2217 | | IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, |
| 2767 | IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb, |
| 2218 | 2768 | source_instruction->scope, source_instruction->source_node); |
| 2219 | 2769 | instruction->base.value->type = ty; |
| 2220 | 2770 | instruction->operand = operand; |
| 2221 | 2771 | instruction->result_loc = result_loc; |
| 2222 | 2772 | |
| 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); |
| 2773 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 2774 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2225 | 2775 | |
| 2226 | 2776 | return &instruction->base; |
| 2227 | 2777 | } |
| 2228 | 2778 | |
| 2229 | | static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2230 | | IrInstruction *target, IrInstruction *options) |
| 2779 | static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2780 | IrInstSrc *target, IrInstSrc *options) |
| 2231 | 2781 | { |
| 2232 | | IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( |
| 2782 | IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>( |
| 2233 | 2783 | irb, scope, source_node); |
| 2234 | | export_instruction->base.value->special = ConstValSpecialStatic; |
| 2235 | | export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 2236 | 2784 | export_instruction->target = target; |
| 2237 | 2785 | export_instruction->options = options; |
| 2238 | 2786 | |
| ... | ... | @@ -2242,8 +2790,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2242 | 2790 | return &export_instruction->base; |
| 2243 | 2791 | } |
| 2244 | 2792 | |
| 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); |
| 2793 | static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) { |
| 2794 | IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node); |
| 2247 | 2795 | instruction->ptr = ptr; |
| 2248 | 2796 | |
| 2249 | 2797 | ir_ref_instruction(ptr, irb->current_basic_block); |
| ... | ... | @@ -2251,8 +2799,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 2251 | 2799 | return &instruction->base; |
| 2252 | 2800 | } |
| 2253 | 2801 | |
| 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); |
| 2802 | static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2803 | IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc) |
| 2804 | { |
| 2805 | IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>( |
| 2806 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2807 | instruction->base.value->type = ty; |
| 2808 | instruction->ptr = ptr; |
| 2809 | instruction->result_loc = result_loc; |
| 2810 | |
| 2811 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 2812 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2813 | |
| 2814 | return &instruction->base; |
| 2815 | } |
| 2816 | |
| 2817 | static IrInstSrc *ir_build_typeof(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 2818 | IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node); |
| 2256 | 2819 | instruction->value = value; |
| 2257 | 2820 | |
| 2258 | 2821 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2260,8 +2823,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2260 | 2823 | return &instruction->base; |
| 2261 | 2824 | } |
| 2262 | 2825 | |
| 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); |
| 2826 | static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) { |
| 2827 | IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node); |
| 2265 | 2828 | instruction->is_cold = is_cold; |
| 2266 | 2829 | |
| 2267 | 2830 | ir_ref_instruction(is_cold, irb->current_basic_block); |
| ... | ... | @@ -2269,21 +2832,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s |
| 2269 | 2832 | return &instruction->base; |
| 2270 | 2833 | } |
| 2271 | 2834 | |
| 2272 | | static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2273 | | IrInstruction *safety_on) |
| 2835 | static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2836 | IrInstSrc *safety_on) |
| 2274 | 2837 | { |
| 2275 | | IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node); |
| 2276 | | instruction->safety_on = safety_on; |
| 2838 | IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node); |
| 2839 | inst->safety_on = safety_on; |
| 2277 | 2840 | |
| 2278 | 2841 | ir_ref_instruction(safety_on, irb->current_basic_block); |
| 2279 | 2842 | |
| 2280 | | return &instruction->base; |
| 2843 | return &inst->base; |
| 2281 | 2844 | } |
| 2282 | 2845 | |
| 2283 | | static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2284 | | IrInstruction *mode_value) |
| 2846 | static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2847 | IrInstSrc *mode_value) |
| 2285 | 2848 | { |
| 2286 | | IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node); |
| 2849 | IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node); |
| 2287 | 2850 | instruction->mode_value = mode_value; |
| 2288 | 2851 | |
| 2289 | 2852 | ir_ref_instruction(mode_value, irb->current_basic_block); |
| ... | ... | @@ -2291,10 +2854,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN |
| 2291 | 2854 | return &instruction->base; |
| 2292 | 2855 | } |
| 2293 | 2856 | |
| 2294 | | static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size, |
| 2295 | | IrInstruction *sentinel, IrInstruction *child_type) |
| 2857 | static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size, |
| 2858 | IrInstSrc *sentinel, IrInstSrc *child_type) |
| 2296 | 2859 | { |
| 2297 | | IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node); |
| 2860 | IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node); |
| 2298 | 2861 | instruction->size = size; |
| 2299 | 2862 | instruction->sentinel = sentinel; |
| 2300 | 2863 | instruction->child_type = child_type; |
| ... | ... | @@ -2306,10 +2869,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode |
| 2306 | 2869 | return &instruction->base; |
| 2307 | 2870 | } |
| 2308 | 2871 | |
| 2309 | | static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2310 | | IrInstruction *payload_type) |
| 2872 | static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2873 | IrInstSrc *payload_type) |
| 2311 | 2874 | { |
| 2312 | | IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node); |
| 2875 | IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node); |
| 2313 | 2876 | instruction->payload_type = payload_type; |
| 2314 | 2877 | |
| 2315 | 2878 | if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block); |
| ... | ... | @@ -2317,11 +2880,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo |
| 2317 | 2880 | return &instruction->base; |
| 2318 | 2881 | } |
| 2319 | 2882 | |
| 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) |
| 2883 | static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2884 | IrInstSrc *child_type, bool is_const, bool is_volatile, |
| 2885 | IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero) |
| 2323 | 2886 | { |
| 2324 | | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node); |
| 2887 | IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node); |
| 2325 | 2888 | instruction->is_const = is_const; |
| 2326 | 2889 | instruction->is_volatile = is_volatile; |
| 2327 | 2890 | instruction->child_type = child_type; |
| ... | ... | @@ -2336,11 +2899,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode |
| 2336 | 2899 | return &instruction->base; |
| 2337 | 2900 | } |
| 2338 | 2901 | |
| 2339 | | static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2340 | | IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types, |
| 2902 | static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2903 | IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types, |
| 2341 | 2904 | ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global) |
| 2342 | 2905 | { |
| 2343 | | IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node); |
| 2906 | IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node); |
| 2344 | 2907 | instruction->asm_template = asm_template; |
| 2345 | 2908 | instruction->input_list = input_list; |
| 2346 | 2909 | instruction->output_types = output_types; |
| ... | ... | @@ -2351,24 +2914,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so |
| 2351 | 2914 | |
| 2352 | 2915 | assert(source_node->type == NodeTypeAsmExpr); |
| 2353 | 2916 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 2354 | | IrInstruction *output_type = output_types[i]; |
| 2917 | IrInstSrc *output_type = output_types[i]; |
| 2355 | 2918 | if (output_type) ir_ref_instruction(output_type, irb->current_basic_block); |
| 2356 | 2919 | } |
| 2357 | 2920 | |
| 2358 | 2921 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 2359 | | IrInstruction *input_value = input_list[i]; |
| 2922 | IrInstSrc *input_value = input_list[i]; |
| 2360 | 2923 | ir_ref_instruction(input_value, irb->current_basic_block); |
| 2361 | 2924 | } |
| 2362 | 2925 | |
| 2363 | 2926 | return &instruction->base; |
| 2364 | 2927 | } |
| 2365 | 2928 | |
| 2366 | | static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2929 | static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2367 | 2930 | 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) |
| 2931 | IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count, |
| 2932 | bool has_side_effects, ZigType *return_type) |
| 2370 | 2933 | { |
| 2371 | | IrInstructionAsmGen *instruction = ir_build_instruction<IrInstructionAsmGen>(&ira->new_irb, scope, source_node); |
| 2934 | IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2935 | instruction->base.value->type = return_type; |
| 2372 | 2936 | instruction->asm_template = asm_template; |
| 2373 | 2937 | instruction->token_list = token_list; |
| 2374 | 2938 | instruction->token_list_len = token_list_len; |
| ... | ... | @@ -2378,22 +2942,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so |
| 2378 | 2942 | instruction->return_count = return_count; |
| 2379 | 2943 | instruction->has_side_effects = has_side_effects; |
| 2380 | 2944 | |
| 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); |
| 2945 | assert(source_instr->source_node->type == NodeTypeAsmExpr); |
| 2946 | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) { |
| 2947 | IrInstGen *output_type = output_types[i]; |
| 2948 | if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block); |
| 2385 | 2949 | } |
| 2386 | 2950 | |
| 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); |
| 2951 | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) { |
| 2952 | IrInstGen *input_value = input_list[i]; |
| 2953 | ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block); |
| 2390 | 2954 | } |
| 2391 | 2955 | |
| 2392 | 2956 | return &instruction->base; |
| 2393 | 2957 | } |
| 2394 | 2958 | |
| 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); |
| 2959 | static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value, |
| 2960 | bool bit_size) |
| 2961 | { |
| 2962 | IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node); |
| 2397 | 2963 | instruction->type_value = type_value; |
| 2398 | 2964 | instruction->bit_size = bit_size; |
| 2399 | 2965 | |
| ... | ... | @@ -2402,8 +2968,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so |
| 2402 | 2968 | return &instruction->base; |
| 2403 | 2969 | } |
| 2404 | 2970 | |
| 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); |
| 2971 | static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2972 | IrInstSrc *value) |
| 2973 | { |
| 2974 | IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node); |
| 2407 | 2975 | instruction->value = value; |
| 2408 | 2976 | |
| 2409 | 2977 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2411,10 +2979,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod |
| 2411 | 2979 | return &instruction->base; |
| 2412 | 2980 | } |
| 2413 | 2981 | |
| 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) |
| 2982 | static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 2983 | IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb, |
| 2984 | source_instr->scope, source_instr->source_node); |
| 2985 | inst->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 2986 | inst->value = value; |
| 2987 | |
| 2988 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2989 | |
| 2990 | return &inst->base; |
| 2991 | } |
| 2992 | |
| 2993 | static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 2994 | IrInstSrc *base_ptr, bool safety_check_on, bool initializing) |
| 2416 | 2995 | { |
| 2417 | | IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node); |
| 2996 | IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node); |
| 2418 | 2997 | instruction->base_ptr = base_ptr; |
| 2419 | 2998 | instruction->safety_check_on = safety_check_on; |
| 2420 | 2999 | instruction->initializing = initializing; |
| ... | ... | @@ -2424,113 +3003,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, |
| 2424 | 3003 | return &instruction->base; |
| 2425 | 3004 | } |
| 2426 | 3005 | |
| 2427 | | static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty, |
| 2428 | | IrInstruction *operand, IrInstruction *result_loc) |
| 3006 | static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3007 | IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type) |
| 2429 | 3008 | { |
| 2430 | | IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>( |
| 3009 | IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb, |
| 3010 | source_instr->scope, source_instr->source_node); |
| 3011 | inst->base.value->type = result_type; |
| 3012 | inst->base_ptr = base_ptr; |
| 3013 | inst->safety_check_on = safety_check_on; |
| 3014 | inst->initializing = initializing; |
| 3015 | |
| 3016 | ir_ref_inst_gen(base_ptr, ira->new_irb.current_basic_block); |
| 3017 | |
| 3018 | return &inst->base; |
| 3019 | } |
| 3020 | |
| 3021 | static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty, |
| 3022 | IrInstGen *operand, IrInstGen *result_loc) |
| 3023 | { |
| 3024 | IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>( |
| 2431 | 3025 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2432 | 3026 | instruction->base.value->type = result_ty; |
| 2433 | 3027 | instruction->operand = operand; |
| 2434 | 3028 | instruction->result_loc = result_loc; |
| 2435 | 3029 | |
| 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); |
| 3030 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3031 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2438 | 3032 | |
| 2439 | 3033 | return &instruction->base; |
| 2440 | 3034 | } |
| 2441 | 3035 | |
| 2442 | | static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2443 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 3036 | static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction, |
| 3037 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 2444 | 3038 | { |
| 2445 | | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( |
| 3039 | IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>( |
| 2446 | 3040 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2447 | 3041 | instruction->base.value->type = result_type; |
| 2448 | 3042 | instruction->operand = operand; |
| 2449 | 3043 | instruction->result_loc = result_loc; |
| 2450 | 3044 | |
| 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); |
| 3045 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3046 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2453 | 3047 | |
| 2454 | 3048 | return &instruction->base; |
| 2455 | 3049 | } |
| 2456 | 3050 | |
| 2457 | | static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2458 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 3051 | static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction, |
| 3052 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 2459 | 3053 | { |
| 2460 | | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( |
| 3054 | IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>( |
| 2461 | 3055 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2462 | 3056 | instruction->base.value->type = result_type; |
| 2463 | 3057 | instruction->operand = operand; |
| 2464 | 3058 | instruction->result_loc = result_loc; |
| 2465 | 3059 | |
| 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); |
| 3060 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3061 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2468 | 3062 | |
| 2469 | 3063 | return &instruction->base; |
| 2470 | 3064 | } |
| 2471 | 3065 | |
| 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); |
| 3066 | static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3067 | IrInstSrc *op) |
| 3068 | { |
| 3069 | IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node); |
| 2474 | 3070 | instruction->type = type; |
| 2475 | 3071 | instruction->op = op; |
| 2476 | 3072 | |
| 2477 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3073 | ir_ref_instruction(type, irb->current_basic_block); |
| 2478 | 3074 | ir_ref_instruction(op, irb->current_basic_block); |
| 2479 | 3075 | |
| 2480 | 3076 | return &instruction->base; |
| 2481 | 3077 | } |
| 2482 | 3078 | |
| 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); |
| 3079 | static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 3080 | IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb, |
| 3081 | source_instr->scope, source_instr->source_node); |
| 3082 | instruction->base.value->type = result_type; |
| 3083 | instruction->op = op; |
| 3084 | |
| 3085 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3086 | |
| 3087 | return &instruction->base; |
| 3088 | } |
| 3089 | |
| 3090 | static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3091 | IrInstSrc *op) |
| 3092 | { |
| 3093 | IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node); |
| 2485 | 3094 | instruction->type = type; |
| 2486 | 3095 | instruction->op = op; |
| 2487 | 3096 | |
| 2488 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3097 | ir_ref_instruction(type, irb->current_basic_block); |
| 2489 | 3098 | ir_ref_instruction(op, irb->current_basic_block); |
| 2490 | 3099 | |
| 2491 | 3100 | return &instruction->base; |
| 2492 | 3101 | } |
| 2493 | 3102 | |
| 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); |
| 3103 | static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 3104 | IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb, |
| 3105 | source_instr->scope, source_instr->source_node); |
| 3106 | instruction->base.value->type = result_type; |
| 3107 | instruction->op = op; |
| 3108 | |
| 3109 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3110 | |
| 3111 | return &instruction->base; |
| 3112 | } |
| 3113 | |
| 3114 | static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3115 | IrInstSrc *op) |
| 3116 | { |
| 3117 | IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node); |
| 2496 | 3118 | instruction->type = type; |
| 2497 | 3119 | instruction->op = op; |
| 2498 | 3120 | |
| 2499 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3121 | ir_ref_instruction(type, irb->current_basic_block); |
| 2500 | 3122 | ir_ref_instruction(op, irb->current_basic_block); |
| 2501 | 3123 | |
| 2502 | 3124 | return &instruction->base; |
| 2503 | 3125 | } |
| 2504 | 3126 | |
| 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); |
| 3127 | static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, |
| 3128 | IrInstGen *op) |
| 3129 | { |
| 3130 | IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb, |
| 3131 | source_instr->scope, source_instr->source_node); |
| 3132 | instruction->base.value->type = result_type; |
| 3133 | instruction->op = op; |
| 3134 | |
| 3135 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3136 | |
| 3137 | return &instruction->base; |
| 3138 | } |
| 3139 | |
| 3140 | static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3141 | IrInstSrc *op) |
| 3142 | { |
| 3143 | IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node); |
| 2507 | 3144 | instruction->type = type; |
| 2508 | 3145 | instruction->op = op; |
| 2509 | 3146 | |
| 2510 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3147 | ir_ref_instruction(type, irb->current_basic_block); |
| 2511 | 3148 | ir_ref_instruction(op, irb->current_basic_block); |
| 2512 | 3149 | |
| 2513 | 3150 | return &instruction->base; |
| 2514 | 3151 | } |
| 2515 | 3152 | |
| 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); |
| 3153 | static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type, |
| 3154 | IrInstGen *op) |
| 3155 | { |
| 3156 | IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb, |
| 3157 | source_instr->scope, source_instr->source_node); |
| 3158 | instruction->base.value->type = op_type; |
| 3159 | instruction->op = op; |
| 3160 | |
| 3161 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3162 | |
| 3163 | return &instruction->base; |
| 3164 | } |
| 3165 | |
| 3166 | static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type, |
| 3167 | IrInstSrc *op) |
| 3168 | { |
| 3169 | IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node); |
| 2518 | 3170 | instruction->type = type; |
| 2519 | 3171 | instruction->op = op; |
| 2520 | 3172 | |
| 2521 | | if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block); |
| 3173 | ir_ref_instruction(type, irb->current_basic_block); |
| 2522 | 3174 | ir_ref_instruction(op, irb->current_basic_block); |
| 2523 | 3175 | |
| 2524 | 3176 | return &instruction->base; |
| 2525 | 3177 | } |
| 2526 | 3178 | |
| 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) |
| 3179 | static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type, |
| 3180 | IrInstGen *op) |
| 2530 | 3181 | { |
| 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; |
| 3182 | IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb, |
| 3183 | source_instr->scope, source_instr->source_node); |
| 3184 | instruction->base.value->type = int_type; |
| 3185 | instruction->op = op; |
| 3186 | |
| 3187 | ir_ref_inst_gen(op, ira->new_irb.current_basic_block); |
| 3188 | |
| 3189 | return &instruction->base; |
| 3190 | } |
| 3191 | |
| 3192 | static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3193 | IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases, |
| 3194 | IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void) |
| 3195 | { |
| 3196 | IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node); |
| 3197 | instruction->base.is_noreturn = true; |
| 2534 | 3198 | instruction->target_value = target_value; |
| 2535 | 3199 | instruction->else_block = else_block; |
| 2536 | 3200 | instruction->case_count = case_count; |
| ... | ... | @@ -2539,9 +3203,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2539 | 3203 | instruction->switch_prongs_void = switch_prongs_void; |
| 2540 | 3204 | |
| 2541 | 3205 | ir_ref_instruction(target_value, irb->current_basic_block); |
| 2542 | | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 3206 | ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 2543 | 3207 | ir_ref_bb(else_block); |
| 2544 | | if (switch_prongs_void) ir_ref_instruction(switch_prongs_void, irb->current_basic_block); |
| 3208 | ir_ref_instruction(switch_prongs_void, irb->current_basic_block); |
| 2545 | 3209 | |
| 2546 | 3210 | for (size_t i = 0; i < case_count; i += 1) { |
| 2547 | 3211 | ir_ref_instruction(cases[i].value, irb->current_basic_block); |
| ... | ... | @@ -2551,10 +3215,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2551 | 3215 | return instruction; |
| 2552 | 3216 | } |
| 2553 | 3217 | |
| 2554 | | static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2555 | | IrInstruction *target_value_ptr) |
| 3218 | static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3219 | IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases) |
| 2556 | 3220 | { |
| 2557 | | IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node); |
| 3221 | IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb, |
| 3222 | source_instr->scope, source_instr->source_node); |
| 3223 | instruction->target_value = target_value; |
| 3224 | instruction->else_block = else_block; |
| 3225 | instruction->case_count = case_count; |
| 3226 | instruction->cases = cases; |
| 3227 | |
| 3228 | ir_ref_inst_gen(target_value, ira->new_irb.current_basic_block); |
| 3229 | ir_ref_bb_gen(else_block); |
| 3230 | |
| 3231 | for (size_t i = 0; i < case_count; i += 1) { |
| 3232 | ir_ref_inst_gen(cases[i].value, ira->new_irb.current_basic_block); |
| 3233 | ir_ref_bb_gen(cases[i].block); |
| 3234 | } |
| 3235 | |
| 3236 | return instruction; |
| 3237 | } |
| 3238 | |
| 3239 | static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3240 | IrInstSrc *target_value_ptr) |
| 3241 | { |
| 3242 | IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node); |
| 2558 | 3243 | instruction->target_value_ptr = target_value_ptr; |
| 2559 | 3244 | |
| 2560 | 3245 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| ... | ... | @@ -2562,10 +3247,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo |
| 2562 | 3247 | return &instruction->base; |
| 2563 | 3248 | } |
| 2564 | 3249 | |
| 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) |
| 3250 | static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3251 | IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len) |
| 2567 | 3252 | { |
| 2568 | | IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node); |
| 3253 | IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node); |
| 2569 | 3254 | instruction->target_value_ptr = target_value_ptr; |
| 2570 | 3255 | instruction->prongs_ptr = prongs_ptr; |
| 2571 | 3256 | instruction->prongs_len = prongs_len; |
| ... | ... | @@ -2579,10 +3264,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode |
| 2579 | 3264 | } |
| 2580 | 3265 | |
| 2581 | 3266 | // 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) |
| 3267 | static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3268 | IrInstSrc *target_value_ptr) |
| 2584 | 3269 | { |
| 2585 | | IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node); |
| 3270 | IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node); |
| 2586 | 3271 | instruction->target_value_ptr = target_value_ptr; |
| 2587 | 3272 | |
| 2588 | 3273 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| ... | ... | @@ -2590,17 +3275,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop |
| 2590 | 3275 | return instruction; |
| 2591 | 3276 | } |
| 2592 | 3277 | |
| 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); |
| 3278 | static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 3279 | ZigType *tag_type) |
| 3280 | { |
| 3281 | IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb, |
| 3282 | source_instr->scope, source_instr->source_node); |
| 2595 | 3283 | instruction->value = value; |
| 3284 | instruction->base.value->type = tag_type; |
| 2596 | 3285 | |
| 2597 | | ir_ref_instruction(value, irb->current_basic_block); |
| 3286 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 2598 | 3287 | |
| 2599 | 3288 | return &instruction->base; |
| 2600 | 3289 | } |
| 2601 | 3290 | |
| 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); |
| 3291 | static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3292 | IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node); |
| 2604 | 3293 | instruction->name = name; |
| 2605 | 3294 | |
| 2606 | 3295 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2608,10 +3297,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2608 | 3297 | return &instruction->base; |
| 2609 | 3298 | } |
| 2610 | 3299 | |
| 2611 | | static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, |
| 3300 | static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value, |
| 2612 | 3301 | bool is_const, bool is_volatile) |
| 2613 | 3302 | { |
| 2614 | | IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node); |
| 3303 | IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node); |
| 2615 | 3304 | instruction->value = value; |
| 2616 | 3305 | instruction->is_const = is_const; |
| 2617 | 3306 | instruction->is_volatile = is_volatile; |
| ... | ... | @@ -2621,23 +3310,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source |
| 2621 | 3310 | return &instruction->base; |
| 2622 | 3311 | } |
| 2623 | 3312 | |
| 2624 | | static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type, |
| 2625 | | IrInstruction *operand, IrInstruction *result_loc) |
| 3313 | static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3314 | IrInstGen *operand, IrInstGen *result_loc) |
| 2626 | 3315 | { |
| 2627 | | IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, |
| 3316 | IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb, |
| 2628 | 3317 | source_instruction->scope, source_instruction->source_node); |
| 2629 | 3318 | instruction->base.value->type = result_type; |
| 2630 | 3319 | instruction->operand = operand; |
| 2631 | 3320 | instruction->result_loc = result_loc; |
| 2632 | 3321 | |
| 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); |
| 3322 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3323 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2635 | 3324 | |
| 2636 | 3325 | return &instruction->base; |
| 2637 | 3326 | } |
| 2638 | 3327 | |
| 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); |
| 3328 | static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 3329 | IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node); |
| 2641 | 3330 | instruction->msg = msg; |
| 2642 | 3331 | |
| 2643 | 3332 | ir_ref_instruction(msg, irb->current_basic_block); |
| ... | ... | @@ -2645,10 +3334,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode |
| 2645 | 3334 | return &instruction->base; |
| 2646 | 3335 | } |
| 2647 | 3336 | |
| 2648 | | static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2649 | | size_t msg_count, IrInstruction **msg_list) |
| 3337 | static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3338 | size_t msg_count, IrInstSrc **msg_list) |
| 2650 | 3339 | { |
| 2651 | | IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node); |
| 3340 | IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node); |
| 2652 | 3341 | instruction->msg_count = msg_count; |
| 2653 | 3342 | instruction->msg_list = msg_list; |
| 2654 | 3343 | |
| ... | ... | @@ -2659,8 +3348,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode |
| 2659 | 3348 | return &instruction->base; |
| 2660 | 3349 | } |
| 2661 | 3350 | |
| 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); |
| 3351 | static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 3352 | IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node); |
| 2664 | 3353 | instruction->value = value; |
| 2665 | 3354 | |
| 2666 | 3355 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2668,13 +3357,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s |
| 2668 | 3357 | return &instruction->base; |
| 2669 | 3358 | } |
| 2670 | 3359 | |
| 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); |
| 3360 | static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 3361 | ZigType *str_type) |
| 3362 | { |
| 3363 | IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb, |
| 3364 | source_instr->scope, source_instr->source_node); |
| 3365 | instruction->base.value->type = str_type; |
| 3366 | instruction->value = value; |
| 3367 | |
| 3368 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 3369 | |
| 3370 | return &instruction->base; |
| 3371 | } |
| 3372 | |
| 3373 | static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3374 | IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node); |
| 2673 | 3375 | return &instruction->base; |
| 2674 | 3376 | } |
| 2675 | 3377 | |
| 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); |
| 3378 | static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3379 | IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node); |
| 2678 | 3380 | instruction->name = name; |
| 2679 | 3381 | |
| 2680 | 3382 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2682,8 +3384,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode * |
| 2682 | 3384 | return &instruction->base; |
| 2683 | 3385 | } |
| 2684 | 3386 | |
| 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); |
| 3387 | static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) { |
| 3388 | IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node); |
| 2687 | 3389 | instruction->name = name; |
| 2688 | 3390 | instruction->value = value; |
| 2689 | 3391 | |
| ... | ... | @@ -2693,8 +3395,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s |
| 2693 | 3395 | return &instruction->base; |
| 2694 | 3396 | } |
| 2695 | 3397 | |
| 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); |
| 3398 | static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3399 | IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node); |
| 2698 | 3400 | instruction->name = name; |
| 2699 | 3401 | |
| 2700 | 3402 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2702,8 +3404,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so |
| 2702 | 3404 | return &instruction->base; |
| 2703 | 3405 | } |
| 2704 | 3406 | |
| 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); |
| 3407 | static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) { |
| 3408 | IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node); |
| 2707 | 3409 | instruction->name = name; |
| 2708 | 3410 | |
| 2709 | 3411 | ir_ref_instruction(name, irb->current_basic_block); |
| ... | ... | @@ -2711,11 +3413,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode |
| 2711 | 3413 | return &instruction->base; |
| 2712 | 3414 | } |
| 2713 | 3415 | |
| 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) |
| 3416 | static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3417 | IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value, |
| 3418 | IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc) |
| 2717 | 3419 | { |
| 2718 | | IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node); |
| 3420 | IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node); |
| 2719 | 3421 | instruction->type_value = type_value; |
| 2720 | 3422 | instruction->ptr = ptr; |
| 2721 | 3423 | instruction->cmp_value = cmp_value; |
| ... | ... | @@ -2735,11 +3437,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode |
| 2735 | 3437 | return &instruction->base; |
| 2736 | 3438 | } |
| 2737 | 3439 | |
| 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) |
| 3440 | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3441 | IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value, |
| 3442 | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc) |
| 2741 | 3443 | { |
| 2742 | | IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb, |
| 3444 | IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb, |
| 2743 | 3445 | source_instruction->scope, source_instruction->source_node); |
| 2744 | 3446 | instruction->base.value->type = result_type; |
| 2745 | 3447 | instruction->ptr = ptr; |
| ... | ... | @@ -2750,26 +3452,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source |
| 2750 | 3452 | instruction->is_weak = is_weak; |
| 2751 | 3453 | instruction->result_loc = result_loc; |
| 2752 | 3454 | |
| 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); |
| 3455 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3456 | ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block); |
| 3457 | ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block); |
| 3458 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 2757 | 3459 | |
| 2758 | 3460 | return &instruction->base; |
| 2759 | 3461 | } |
| 2760 | 3462 | |
| 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; |
| 3463 | static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) { |
| 3464 | IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node); |
| 2764 | 3465 | instruction->order = order; |
| 2765 | 3466 | |
| 2766 | | ir_ref_instruction(order_value, irb->current_basic_block); |
| 3467 | ir_ref_instruction(order, irb->current_basic_block); |
| 3468 | |
| 3469 | return &instruction->base; |
| 3470 | } |
| 3471 | |
| 3472 | static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) { |
| 3473 | IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb, |
| 3474 | source_instr->scope, source_instr->source_node); |
| 3475 | instruction->order = order; |
| 2767 | 3476 | |
| 2768 | 3477 | return &instruction->base; |
| 2769 | 3478 | } |
| 2770 | 3479 | |
| 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); |
| 3480 | static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3481 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3482 | { |
| 3483 | IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node); |
| 2773 | 3484 | instruction->dest_type = dest_type; |
| 2774 | 3485 | instruction->target = target; |
| 2775 | 3486 | |
| ... | ... | @@ -2779,8 +3490,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s |
| 2779 | 3490 | return &instruction->base; |
| 2780 | 3491 | } |
| 2781 | 3492 | |
| 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); |
| 3493 | static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type, |
| 3494 | IrInstGen *target) |
| 3495 | { |
| 3496 | IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb, |
| 3497 | source_instr->scope, source_instr->source_node); |
| 3498 | instruction->base.value->type = dest_type; |
| 3499 | instruction->target = target; |
| 3500 | |
| 3501 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3502 | |
| 3503 | return &instruction->base; |
| 3504 | } |
| 3505 | |
| 3506 | static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 3507 | IrInstSrc *target) |
| 3508 | { |
| 3509 | IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node); |
| 2784 | 3510 | instruction->dest_type = dest_type; |
| 2785 | 3511 | instruction->target = target; |
| 2786 | 3512 | |
| ... | ... | @@ -2790,8 +3516,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s |
| 2790 | 3516 | return &instruction->base; |
| 2791 | 3517 | } |
| 2792 | 3518 | |
| 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); |
| 3519 | static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type, |
| 3520 | IrInstSrc *target) |
| 3521 | { |
| 3522 | IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node); |
| 2795 | 3523 | instruction->dest_type = dest_type; |
| 2796 | 3524 | instruction->target = target; |
| 2797 | 3525 | |
| ... | ... | @@ -2801,8 +3529,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode |
| 2801 | 3529 | return &instruction->base; |
| 2802 | 3530 | } |
| 2803 | 3531 | |
| 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); |
| 3532 | static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3533 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3534 | { |
| 3535 | IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node); |
| 2806 | 3536 | instruction->dest_type = dest_type; |
| 2807 | 3537 | instruction->target = target; |
| 2808 | 3538 | |
| ... | ... | @@ -2812,10 +3542,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod |
| 2812 | 3542 | return &instruction->base; |
| 2813 | 3543 | } |
| 2814 | 3544 | |
| 2815 | | static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target, |
| 3545 | static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target, |
| 2816 | 3546 | ResultLoc *result_loc) |
| 2817 | 3547 | { |
| 2818 | | IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node); |
| 3548 | IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node); |
| 2819 | 3549 | instruction->target = target; |
| 2820 | 3550 | instruction->result_loc = result_loc; |
| 2821 | 3551 | |
| ... | ... | @@ -2824,10 +3554,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s |
| 2824 | 3554 | return &instruction->base; |
| 2825 | 3555 | } |
| 2826 | 3556 | |
| 2827 | | static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2828 | | IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc) |
| 3557 | static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3558 | IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc) |
| 2829 | 3559 | { |
| 2830 | | IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node); |
| 3560 | IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node); |
| 2831 | 3561 | instruction->dest_child_type = dest_child_type; |
| 2832 | 3562 | instruction->target = target; |
| 2833 | 3563 | instruction->result_loc = result_loc; |
| ... | ... | @@ -2838,8 +3568,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode |
| 2838 | 3568 | return &instruction->base; |
| 2839 | 3569 | } |
| 2840 | 3570 | |
| 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); |
| 3571 | static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3572 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3573 | { |
| 3574 | IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node); |
| 2843 | 3575 | instruction->dest_type = dest_type; |
| 2844 | 3576 | instruction->target = target; |
| 2845 | 3577 | |
| ... | ... | @@ -2849,8 +3581,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod |
| 2849 | 3581 | return &instruction->base; |
| 2850 | 3582 | } |
| 2851 | 3583 | |
| 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); |
| 3584 | static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3585 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3586 | { |
| 3587 | IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node); |
| 2854 | 3588 | instruction->dest_type = dest_type; |
| 2855 | 3589 | instruction->target = target; |
| 2856 | 3590 | |
| ... | ... | @@ -2860,8 +3594,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod |
| 2860 | 3594 | return &instruction->base; |
| 2861 | 3595 | } |
| 2862 | 3596 | |
| 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); |
| 3597 | static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 3598 | IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node); |
| 2865 | 3599 | instruction->target = target; |
| 2866 | 3600 | |
| 2867 | 3601 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -2869,8 +3603,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 2869 | 3603 | return &instruction->base; |
| 2870 | 3604 | } |
| 2871 | 3605 | |
| 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); |
| 3606 | static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed, |
| 3607 | IrInstSrc *bit_count) |
| 3608 | { |
| 3609 | IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node); |
| 2874 | 3610 | instruction->is_signed = is_signed; |
| 2875 | 3611 | instruction->bit_count = bit_count; |
| 2876 | 3612 | |
| ... | ... | @@ -2880,10 +3616,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 2880 | 3616 | return &instruction->base; |
| 2881 | 3617 | } |
| 2882 | 3618 | |
| 2883 | | static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len, |
| 2884 | | IrInstruction *elem_type) |
| 3619 | static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len, |
| 3620 | IrInstSrc *elem_type) |
| 2885 | 3621 | { |
| 2886 | | IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node); |
| 3622 | IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node); |
| 2887 | 3623 | instruction->len = len; |
| 2888 | 3624 | instruction->elem_type = elem_type; |
| 2889 | 3625 | |
| ... | ... | @@ -2893,18 +3629,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode |
| 2893 | 3629 | return &instruction->base; |
| 2894 | 3630 | } |
| 2895 | 3631 | |
| 2896 | | static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2897 | | IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask) |
| 3632 | static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3633 | IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask) |
| 2898 | 3634 | { |
| 2899 | | IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node); |
| 3635 | IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node); |
| 2900 | 3636 | instruction->scalar_type = scalar_type; |
| 2901 | 3637 | instruction->a = a; |
| 2902 | 3638 | instruction->b = b; |
| 2903 | 3639 | instruction->mask = mask; |
| 2904 | 3640 | |
| 2905 | | if (scalar_type != nullptr) { |
| 2906 | | ir_ref_instruction(scalar_type, irb->current_basic_block); |
| 2907 | | } |
| 3641 | if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block); |
| 2908 | 3642 | ir_ref_instruction(a, irb->current_basic_block); |
| 2909 | 3643 | ir_ref_instruction(b, irb->current_basic_block); |
| 2910 | 3644 | ir_ref_instruction(mask, irb->current_basic_block); |
| ... | ... | @@ -2912,10 +3646,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN |
| 2912 | 3646 | return &instruction->base; |
| 2913 | 3647 | } |
| 2914 | 3648 | |
| 2915 | | static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2916 | | IrInstruction *len, IrInstruction *scalar) |
| 3649 | static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 3650 | ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask) |
| 2917 | 3651 | { |
| 2918 | | IrInstructionSplatSrc *instruction = ir_build_instruction<IrInstructionSplatSrc>(irb, scope, source_node); |
| 3652 | IrInstGenShuffleVector *inst = ir_build_inst_gen<IrInstGenShuffleVector>(&ira->new_irb, scope, source_node); |
| 3653 | inst->base.value->type = result_type; |
| 3654 | inst->a = a; |
| 3655 | inst->b = b; |
| 3656 | inst->mask = mask; |
| 3657 | |
| 3658 | ir_ref_inst_gen(a, ira->new_irb.current_basic_block); |
| 3659 | ir_ref_inst_gen(b, ira->new_irb.current_basic_block); |
| 3660 | ir_ref_inst_gen(mask, ira->new_irb.current_basic_block); |
| 3661 | |
| 3662 | return &inst->base; |
| 3663 | } |
| 3664 | |
| 3665 | static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3666 | IrInstSrc *len, IrInstSrc *scalar) |
| 3667 | { |
| 3668 | IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node); |
| 2919 | 3669 | instruction->len = len; |
| 2920 | 3670 | instruction->scalar = scalar; |
| 2921 | 3671 | |
| ... | ... | @@ -2925,8 +3675,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode * |
| 2925 | 3675 | return &instruction->base; |
| 2926 | 3676 | } |
| 2927 | 3677 | |
| 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); |
| 3678 | static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3679 | IrInstGen *scalar) |
| 3680 | { |
| 3681 | IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>( |
| 3682 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3683 | instruction->base.value->type = result_type; |
| 3684 | instruction->scalar = scalar; |
| 3685 | |
| 3686 | ir_ref_inst_gen(scalar, ira->new_irb.current_basic_block); |
| 3687 | |
| 3688 | return &instruction->base; |
| 3689 | } |
| 3690 | |
| 3691 | static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 3692 | IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node); |
| 2930 | 3693 | instruction->value = value; |
| 2931 | 3694 | |
| 2932 | 3695 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -2934,10 +3697,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s |
| 2934 | 3697 | return &instruction->base; |
| 2935 | 3698 | } |
| 2936 | 3699 | |
| 2937 | | static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2938 | | IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count) |
| 3700 | static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 3701 | IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb, |
| 3702 | source_instr->scope, source_instr->source_node); |
| 3703 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3704 | instruction->value = value; |
| 3705 | |
| 3706 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 3707 | |
| 3708 | return &instruction->base; |
| 3709 | } |
| 3710 | |
| 3711 | static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3712 | IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count) |
| 2939 | 3713 | { |
| 2940 | | IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node); |
| 3714 | IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node); |
| 2941 | 3715 | instruction->dest_ptr = dest_ptr; |
| 2942 | 3716 | instruction->byte = byte; |
| 2943 | 3717 | instruction->count = count; |
| ... | ... | @@ -2949,10 +3723,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2949 | 3723 | return &instruction->base; |
| 2950 | 3724 | } |
| 2951 | 3725 | |
| 2952 | | static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2953 | | IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count) |
| 3726 | static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3727 | IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count) |
| 3728 | { |
| 3729 | IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb, |
| 3730 | source_instr->scope, source_instr->source_node); |
| 3731 | instruction->dest_ptr = dest_ptr; |
| 3732 | instruction->byte = byte; |
| 3733 | instruction->count = count; |
| 3734 | |
| 3735 | ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block); |
| 3736 | ir_ref_inst_gen(byte, ira->new_irb.current_basic_block); |
| 3737 | ir_ref_inst_gen(count, ira->new_irb.current_basic_block); |
| 3738 | |
| 3739 | return &instruction->base; |
| 3740 | } |
| 3741 | |
| 3742 | static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3743 | IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count) |
| 2954 | 3744 | { |
| 2955 | | IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node); |
| 3745 | IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node); |
| 2956 | 3746 | instruction->dest_ptr = dest_ptr; |
| 2957 | 3747 | instruction->src_ptr = src_ptr; |
| 2958 | 3748 | instruction->count = count; |
| ... | ... | @@ -2964,11 +3754,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2964 | 3754 | return &instruction->base; |
| 2965 | 3755 | } |
| 2966 | 3756 | |
| 2967 | | static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2968 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel, |
| 3757 | static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3758 | IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count) |
| 3759 | { |
| 3760 | IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb, |
| 3761 | source_instr->scope, source_instr->source_node); |
| 3762 | instruction->dest_ptr = dest_ptr; |
| 3763 | instruction->src_ptr = src_ptr; |
| 3764 | instruction->count = count; |
| 3765 | |
| 3766 | ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block); |
| 3767 | ir_ref_inst_gen(src_ptr, ira->new_irb.current_basic_block); |
| 3768 | ir_ref_inst_gen(count, ira->new_irb.current_basic_block); |
| 3769 | |
| 3770 | return &instruction->base; |
| 3771 | } |
| 3772 | |
| 3773 | static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3774 | IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel, |
| 2969 | 3775 | bool safety_check_on, ResultLoc *result_loc) |
| 2970 | 3776 | { |
| 2971 | | IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node); |
| 3777 | IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node); |
| 2972 | 3778 | instruction->ptr = ptr; |
| 2973 | 3779 | instruction->start = start; |
| 2974 | 3780 | instruction->end = end; |
| ... | ... | @@ -2984,23 +3790,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode * |
| 2984 | 3790 | return &instruction->base; |
| 2985 | 3791 | } |
| 2986 | 3792 | |
| 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) |
| 3793 | static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type, |
| 3794 | IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc) |
| 3002 | 3795 | { |
| 3003 | | IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>( |
| 3796 | IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>( |
| 3004 | 3797 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3005 | 3798 | instruction->base.value->type = slice_type; |
| 3006 | 3799 | instruction->ptr = ptr; |
| ... | ... | @@ -3009,16 +3802,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i |
| 3009 | 3802 | instruction->safety_check_on = safety_check_on; |
| 3010 | 3803 | instruction->result_loc = result_loc; |
| 3011 | 3804 | |
| 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); |
| 3805 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3806 | ir_ref_inst_gen(start, ira->new_irb.current_basic_block); |
| 3807 | if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block); |
| 3808 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3016 | 3809 | |
| 3017 | 3810 | return &instruction->base; |
| 3018 | 3811 | } |
| 3019 | 3812 | |
| 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); |
| 3813 | static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) { |
| 3814 | IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node); |
| 3022 | 3815 | instruction->container = container; |
| 3023 | 3816 | |
| 3024 | 3817 | ir_ref_instruction(container, irb->current_basic_block); |
| ... | ... | @@ -3026,10 +3819,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod |
| 3026 | 3819 | return &instruction->base; |
| 3027 | 3820 | } |
| 3028 | 3821 | |
| 3029 | | static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3030 | | IrInstruction *container_type, IrInstruction *member_index) |
| 3822 | static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3823 | IrInstSrc *container_type, IrInstSrc *member_index) |
| 3031 | 3824 | { |
| 3032 | | IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node); |
| 3825 | IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node); |
| 3033 | 3826 | instruction->container_type = container_type; |
| 3034 | 3827 | instruction->member_index = member_index; |
| 3035 | 3828 | |
| ... | ... | @@ -3039,10 +3832,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode |
| 3039 | 3832 | return &instruction->base; |
| 3040 | 3833 | } |
| 3041 | 3834 | |
| 3042 | | static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3043 | | IrInstruction *container_type, IrInstruction *member_index) |
| 3835 | static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3836 | IrInstSrc *container_type, IrInstSrc *member_index) |
| 3044 | 3837 | { |
| 3045 | | IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node); |
| 3838 | IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node); |
| 3046 | 3839 | instruction->container_type = container_type; |
| 3047 | 3840 | instruction->member_index = member_index; |
| 3048 | 3841 | |
| ... | ... | @@ -3052,65 +3845,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode |
| 3052 | 3845 | return &instruction->base; |
| 3053 | 3846 | } |
| 3054 | 3847 | |
| 3055 | | static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3056 | | IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node); |
| 3848 | static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3849 | IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node); |
| 3057 | 3850 | return &instruction->base; |
| 3058 | 3851 | } |
| 3059 | 3852 | |
| 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); |
| 3853 | static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3854 | IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb, |
| 3855 | source_instr->scope, source_instr->source_node); |
| 3062 | 3856 | return &instruction->base; |
| 3063 | 3857 | } |
| 3064 | 3858 | |
| 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); |
| 3859 | static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3860 | IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node); |
| 3067 | 3861 | return &instruction->base; |
| 3068 | 3862 | } |
| 3069 | 3863 | |
| 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; |
| 3864 | static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3865 | IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3866 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3867 | return &inst->base; |
| 3868 | } |
| 3869 | |
| 3870 | static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3871 | IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node); |
| 3872 | return &inst->base; |
| 3873 | } |
| 3874 | |
| 3875 | static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 3876 | IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3877 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3878 | return &inst->base; |
| 3879 | } |
| 3880 | |
| 3881 | static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 3882 | IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node); |
| 3883 | return &inst->base; |
| 3884 | } |
| 3885 | |
| 3886 | static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) { |
| 3887 | IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3888 | inst->base.value->type = ty; |
| 3889 | return &inst->base; |
| 3073 | 3890 | } |
| 3074 | 3891 | |
| 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; |
| 3892 | static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 3893 | IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node); |
| 3894 | inst->fn = fn; |
| 3078 | 3895 | |
| 3079 | 3896 | ir_ref_instruction(fn, irb->current_basic_block); |
| 3080 | 3897 | |
| 3081 | | return &instruction->base; |
| 3898 | return &inst->base; |
| 3082 | 3899 | } |
| 3083 | 3900 | |
| 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; |
| 3901 | static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) { |
| 3902 | IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node); |
| 3903 | inst->fn = fn; |
| 3087 | 3904 | |
| 3088 | 3905 | ir_ref_instruction(fn, irb->current_basic_block); |
| 3089 | 3906 | |
| 3090 | | return &instruction->base; |
| 3907 | return &inst->base; |
| 3091 | 3908 | } |
| 3092 | 3909 | |
| 3093 | | static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) |
| 3910 | static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn) |
| 3094 | 3911 | { |
| 3095 | | IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node); |
| 3096 | | instruction->fn = fn; |
| 3912 | IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 3913 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 3914 | inst->fn = fn; |
| 3097 | 3915 | |
| 3098 | | ir_ref_instruction(fn, irb->current_basic_block); |
| 3916 | ir_ref_inst_gen(fn, ira->new_irb.current_basic_block); |
| 3099 | 3917 | |
| 3100 | | return &instruction->base; |
| 3918 | return &inst->base; |
| 3101 | 3919 | } |
| 3102 | 3920 | |
| 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) |
| 3921 | static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3922 | IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr) |
| 3106 | 3923 | { |
| 3107 | | IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node); |
| 3924 | IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node); |
| 3108 | 3925 | instruction->op = op; |
| 3109 | 3926 | instruction->type_value = type_value; |
| 3110 | 3927 | instruction->op1 = op1; |
| 3111 | 3928 | instruction->op2 = op2; |
| 3112 | 3929 | instruction->result_ptr = result_ptr; |
| 3113 | | instruction->result_ptr_type = result_ptr_type; |
| 3114 | 3930 | |
| 3115 | 3931 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 3116 | 3932 | ir_ref_instruction(op1, irb->current_basic_block); |
| ... | ... | @@ -3120,49 +3936,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 3120 | 3936 | return &instruction->base; |
| 3121 | 3937 | } |
| 3122 | 3938 | |
| 3939 | static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr, |
| 3940 | IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr, |
| 3941 | ZigType *result_ptr_type) |
| 3942 | { |
| 3943 | IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb, |
| 3944 | source_instr->scope, source_instr->source_node); |
| 3945 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3946 | instruction->op = op; |
| 3947 | instruction->op1 = op1; |
| 3948 | instruction->op2 = op2; |
| 3949 | instruction->result_ptr = result_ptr; |
| 3950 | instruction->result_ptr_type = result_ptr_type; |
| 3123 | 3951 | |
| 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 | | } |
| 3952 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 3953 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 3954 | ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block); |
| 3955 | |
| 3956 | return &instruction->base; |
| 3160 | 3957 | } |
| 3161 | 3958 | |
| 3162 | | static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *operand, |
| 3959 | static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand, |
| 3163 | 3960 | BuiltinFnId fn_id) |
| 3164 | 3961 | { |
| 3165 | | IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node); |
| 3962 | IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node); |
| 3166 | 3963 | instruction->operand = operand; |
| 3167 | 3964 | instruction->fn_id = fn_id; |
| 3168 | 3965 | |
| ... | ... | @@ -3171,9 +3968,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s |
| 3171 | 3968 | return &instruction->base; |
| 3172 | 3969 | } |
| 3173 | 3970 | |
| 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); |
| 3971 | static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 3972 | BuiltinFnId fn_id, ZigType *operand_type) |
| 3973 | { |
| 3974 | IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb, |
| 3975 | source_instr->scope, source_instr->source_node); |
| 3976 | instruction->base.value->type = operand_type; |
| 3977 | instruction->operand = operand; |
| 3978 | instruction->fn_id = fn_id; |
| 3979 | |
| 3980 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3981 | |
| 3982 | return &instruction->base; |
| 3983 | } |
| 3984 | |
| 3985 | static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3986 | IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3) |
| 3987 | { |
| 3988 | IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node); |
| 3177 | 3989 | instruction->type_value = type_value; |
| 3178 | 3990 | instruction->op1 = op1; |
| 3179 | 3991 | instruction->op2 = op2; |
| ... | ... | @@ -3187,8 +3999,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so |
| 3187 | 3999 | return &instruction->base; |
| 3188 | 4000 | } |
| 3189 | 4001 | |
| 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); |
| 4002 | static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2, |
| 4003 | IrInstGen *op3, ZigType *expr_type) |
| 4004 | { |
| 4005 | IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb, |
| 4006 | source_instr->scope, source_instr->source_node); |
| 4007 | instruction->base.value->type = expr_type; |
| 4008 | instruction->op1 = op1; |
| 4009 | instruction->op2 = op2; |
| 4010 | instruction->op3 = op3; |
| 4011 | |
| 4012 | ir_ref_inst_gen(op1, ira->new_irb.current_basic_block); |
| 4013 | ir_ref_inst_gen(op2, ira->new_irb.current_basic_block); |
| 4014 | ir_ref_inst_gen(op3, ira->new_irb.current_basic_block); |
| 4015 | |
| 4016 | return &instruction->base; |
| 4017 | } |
| 4018 | |
| 4019 | static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4020 | IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node); |
| 3192 | 4021 | instruction->type_value = type_value; |
| 3193 | 4022 | |
| 3194 | 4023 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3196,10 +4025,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s |
| 3196 | 4025 | return &instruction->base; |
| 3197 | 4026 | } |
| 3198 | 4027 | |
| 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) |
| 4028 | static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4029 | IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload) |
| 3201 | 4030 | { |
| 3202 | | IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node); |
| 4031 | IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node); |
| 3203 | 4032 | instruction->base_ptr = base_ptr; |
| 3204 | 4033 | instruction->resolve_err_set = resolve_err_set; |
| 3205 | 4034 | instruction->base_ptr_is_payload = base_ptr_is_payload; |
| ... | ... | @@ -3209,48 +4038,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod |
| 3209 | 4038 | return &instruction->base; |
| 3210 | 4039 | } |
| 3211 | 4040 | |
| 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>( |
| 4041 | static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) { |
| 4042 | IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>( |
| 3216 | 4043 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3217 | 4044 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 3218 | 4045 | instruction->err_union = err_union; |
| 3219 | 4046 | |
| 3220 | | ir_ref_instruction(err_union, ira->new_irb.current_basic_block); |
| 4047 | ir_ref_inst_gen(err_union, ira->new_irb.current_basic_block); |
| 3221 | 4048 | |
| 3222 | 4049 | return &instruction->base; |
| 3223 | 4050 | } |
| 3224 | 4051 | |
| 3225 | | static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3226 | | IrInstruction *err_union_ptr) |
| 4052 | static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4053 | IrInstSrc *err_union_ptr) |
| 3227 | 4054 | { |
| 3228 | | IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node); |
| 3229 | | instruction->err_union_ptr = err_union_ptr; |
| 4055 | IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node); |
| 4056 | inst->err_union_ptr = err_union_ptr; |
| 3230 | 4057 | |
| 3231 | 4058 | ir_ref_instruction(err_union_ptr, irb->current_basic_block); |
| 3232 | 4059 | |
| 3233 | | return &instruction->base; |
| 4060 | return &inst->base; |
| 3234 | 4061 | } |
| 3235 | 4062 | |
| 3236 | | static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3237 | | IrInstruction *value, bool safety_check_on, bool initializing) |
| 4063 | static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4064 | IrInstGen *err_union_ptr, ZigType *result_type) |
| 3238 | 4065 | { |
| 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; |
| 4066 | IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node); |
| 4067 | inst->base.value->type = result_type; |
| 4068 | inst->err_union_ptr = err_union_ptr; |
| 4069 | |
| 4070 | ir_ref_inst_gen(err_union_ptr, ira->new_irb.current_basic_block); |
| 4071 | |
| 4072 | return &inst->base; |
| 4073 | } |
| 4074 | |
| 4075 | static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4076 | IrInstSrc *value, bool safety_check_on, bool initializing) |
| 4077 | { |
| 4078 | IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node); |
| 4079 | inst->value = value; |
| 4080 | inst->safety_check_on = safety_check_on; |
| 4081 | inst->initializing = initializing; |
| 3243 | 4082 | |
| 3244 | 4083 | ir_ref_instruction(value, irb->current_basic_block); |
| 3245 | 4084 | |
| 3246 | | return &instruction->base; |
| 4085 | return &inst->base; |
| 4086 | } |
| 4087 | |
| 4088 | static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4089 | IrInstGen *value, bool safety_check_on, bool initializing, ZigType *result_type) |
| 4090 | { |
| 4091 | IrInstGenUnwrapErrPayload *inst = ir_build_inst_gen<IrInstGenUnwrapErrPayload>(&ira->new_irb, scope, source_node); |
| 4092 | inst->base.value->type = result_type; |
| 4093 | inst->value = value; |
| 4094 | inst->safety_check_on = safety_check_on; |
| 4095 | inst->initializing = initializing; |
| 4096 | |
| 4097 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 4098 | |
| 4099 | return &inst->base; |
| 3247 | 4100 | } |
| 3248 | 4101 | |
| 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) |
| 4102 | static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4103 | IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value, |
| 4104 | IrInstSrc *return_type, bool is_var_args) |
| 3252 | 4105 | { |
| 3253 | | IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node); |
| 4106 | IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node); |
| 3254 | 4107 | instruction->param_types = param_types; |
| 3255 | 4108 | instruction->align_value = align_value; |
| 3256 | 4109 | instruction->callconv_value = callconv_value; |
| ... | ... | @@ -3270,8 +4123,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s |
| 3270 | 4123 | return &instruction->base; |
| 3271 | 4124 | } |
| 3272 | 4125 | |
| 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); |
| 4126 | static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) { |
| 4127 | IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node); |
| 3275 | 4128 | instruction->value = value; |
| 3276 | 4129 | |
| 3277 | 4130 | ir_ref_instruction(value, irb->current_basic_block); |
| ... | ... | @@ -3279,10 +4132,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo |
| 3279 | 4132 | return &instruction->base; |
| 3280 | 4133 | } |
| 3281 | 4134 | |
| 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) |
| 4135 | static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4136 | IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on) |
| 3284 | 4137 | { |
| 3285 | | IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>( |
| 4138 | IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>( |
| 3286 | 4139 | irb, scope, source_node); |
| 3287 | 4140 | instruction->dest_type = dest_type; |
| 3288 | 4141 | instruction->ptr = ptr; |
| ... | ... | @@ -3294,39 +4147,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod |
| 3294 | 4147 | return &instruction->base; |
| 3295 | 4148 | } |
| 3296 | 4149 | |
| 3297 | | static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3298 | | ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on) |
| 4150 | static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4151 | ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on) |
| 3299 | 4152 | { |
| 3300 | | IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>( |
| 4153 | IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>( |
| 3301 | 4154 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3302 | 4155 | instruction->base.value->type = ptr_type; |
| 3303 | 4156 | instruction->ptr = ptr; |
| 3304 | 4157 | instruction->safety_check_on = safety_check_on; |
| 3305 | 4158 | |
| 3306 | | ir_ref_instruction(ptr, ira->new_irb.current_basic_block); |
| 4159 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3307 | 4160 | |
| 3308 | 4161 | return &instruction->base; |
| 3309 | 4162 | } |
| 3310 | 4163 | |
| 3311 | | static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3312 | | IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc) |
| 4164 | static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4165 | IrInstSrc *operand, ResultLocCast *result_loc_cast) |
| 3313 | 4166 | { |
| 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); |
| 3322 | | |
| 3323 | | return &instruction->base; |
| 3324 | | } |
| 3325 | | |
| 3326 | | static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3327 | | IrInstruction *operand, ResultLocCast *result_loc_cast) |
| 3328 | | { |
| 3329 | | IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node); |
| 4167 | IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node); |
| 3330 | 4168 | instruction->operand = operand; |
| 3331 | 4169 | instruction->result_loc_cast = result_loc_cast; |
| 3332 | 4170 | |
| ... | ... | @@ -3335,10 +4173,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo |
| 3335 | 4173 | return &instruction->base; |
| 3336 | 4174 | } |
| 3337 | 4175 | |
| 3338 | | static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3339 | | IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast) |
| 4176 | static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4177 | IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast) |
| 3340 | 4178 | { |
| 3341 | | IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node); |
| 4179 | IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node); |
| 3342 | 4180 | instruction->operand = operand; |
| 3343 | 4181 | instruction->result_loc_bit_cast = result_loc_bit_cast; |
| 3344 | 4182 | |
| ... | ... | @@ -3347,62 +4185,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod |
| 3347 | 4185 | return &instruction->base; |
| 3348 | 4186 | } |
| 3349 | 4187 | |
| 3350 | | static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3351 | | IrInstruction *operand, ZigType *ty) |
| 4188 | static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4189 | IrInstGen *operand, ZigType *ty) |
| 3352 | 4190 | { |
| 3353 | | IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>( |
| 4191 | IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>( |
| 3354 | 4192 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3355 | 4193 | instruction->base.value->type = ty; |
| 3356 | 4194 | instruction->operand = operand; |
| 3357 | 4195 | |
| 3358 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 4196 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3359 | 4197 | |
| 3360 | 4198 | return &instruction->base; |
| 3361 | 4199 | } |
| 3362 | 4200 | |
| 3363 | | static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3364 | | IrInstruction *target) |
| 4201 | static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4202 | ZigType *result_type) |
| 3365 | 4203 | { |
| 3366 | | IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>( |
| 3367 | | irb, scope, source_node); |
| 3368 | | instruction->target = target; |
| 4204 | IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node); |
| 4205 | inst->base.value->type = result_type; |
| 4206 | inst->target = target; |
| 3369 | 4207 | |
| 3370 | | ir_ref_instruction(target, irb->current_basic_block); |
| 4208 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3371 | 4209 | |
| 3372 | | return &instruction->base; |
| 4210 | return &inst->base; |
| 3373 | 4211 | } |
| 3374 | 4212 | |
| 3375 | | static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3376 | | IrInstruction *dest_type, IrInstruction *target) |
| 4213 | static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4214 | IrInstSrc *dest_type, IrInstSrc *target) |
| 3377 | 4215 | { |
| 3378 | | IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>( |
| 3379 | | irb, scope, source_node); |
| 4216 | IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node); |
| 3380 | 4217 | instruction->dest_type = dest_type; |
| 3381 | 4218 | instruction->target = target; |
| 3382 | 4219 | |
| 3383 | | if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block); |
| 4220 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 3384 | 4221 | ir_ref_instruction(target, irb->current_basic_block); |
| 3385 | 4222 | |
| 3386 | 4223 | return &instruction->base; |
| 3387 | 4224 | } |
| 3388 | 4225 | |
| 3389 | | static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3390 | | IrInstruction *target) |
| 4226 | static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4227 | IrInstGen *target, ZigType *ptr_type) |
| 3391 | 4228 | { |
| 3392 | | IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>( |
| 3393 | | irb, scope, source_node); |
| 4229 | IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node); |
| 4230 | instruction->base.value->type = ptr_type; |
| 3394 | 4231 | instruction->target = target; |
| 3395 | 4232 | |
| 3396 | | ir_ref_instruction(target, irb->current_basic_block); |
| 4233 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3397 | 4234 | |
| 3398 | 4235 | return &instruction->base; |
| 3399 | 4236 | } |
| 3400 | 4237 | |
| 3401 | | static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3402 | | IrInstruction *dest_type, IrInstruction *target) |
| 4238 | static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4239 | IrInstSrc *target) |
| 3403 | 4240 | { |
| 3404 | | IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>( |
| 3405 | | irb, scope, source_node); |
| 4241 | IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node); |
| 4242 | inst->target = target; |
| 4243 | |
| 4244 | ir_ref_instruction(target, irb->current_basic_block); |
| 4245 | |
| 4246 | return &inst->base; |
| 4247 | } |
| 4248 | |
| 4249 | static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 4250 | IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4251 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 4252 | inst->target = target; |
| 4253 | |
| 4254 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4255 | |
| 4256 | return &inst->base; |
| 4257 | } |
| 4258 | |
| 4259 | static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4260 | IrInstSrc *dest_type, IrInstSrc *target) |
| 4261 | { |
| 4262 | IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node); |
| 3406 | 4263 | instruction->dest_type = dest_type; |
| 3407 | 4264 | instruction->target = target; |
| 3408 | 4265 | |
| ... | ... | @@ -3412,12 +4269,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode |
| 3412 | 4269 | return &instruction->base; |
| 3413 | 4270 | } |
| 3414 | 4271 | |
| 4272 | static IrInstGen *ir_build_int_to_enum_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4273 | ZigType *dest_type, IrInstGen *target) |
| 4274 | { |
| 4275 | IrInstGenIntToEnum *instruction = ir_build_inst_gen<IrInstGenIntToEnum>(&ira->new_irb, scope, source_node); |
| 4276 | instruction->base.value->type = dest_type; |
| 4277 | instruction->target = target; |
| 4278 | |
| 4279 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3415 | 4280 | |
| 4281 | return &instruction->base; |
| 4282 | } |
| 3416 | 4283 | |
| 3417 | | static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3418 | | IrInstruction *target) |
| 4284 | static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4285 | IrInstSrc *target) |
| 3419 | 4286 | { |
| 3420 | | IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>( |
| 4287 | IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>( |
| 3421 | 4288 | irb, scope, source_node); |
| 3422 | 4289 | instruction->target = target; |
| 3423 | 4290 | |
| ... | ... | @@ -3426,11 +4293,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 3426 | 4293 | return &instruction->base; |
| 3427 | 4294 | } |
| 3428 | 4295 | |
| 3429 | | static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3430 | | IrInstruction *target) |
| 4296 | static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4297 | IrInstSrc *target) |
| 3431 | 4298 | { |
| 3432 | | IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>( |
| 3433 | | irb, scope, source_node); |
| 4299 | IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node); |
| 3434 | 4300 | instruction->target = target; |
| 3435 | 4301 | |
| 3436 | 4302 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -3438,10 +4304,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode |
| 3438 | 4304 | return &instruction->base; |
| 3439 | 4305 | } |
| 3440 | 4306 | |
| 3441 | | static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3442 | | IrInstruction *target) |
| 4307 | static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4308 | ZigType *wanted_type) |
| 4309 | { |
| 4310 | IrInstGenIntToErr *instruction = ir_build_inst_gen<IrInstGenIntToErr>(&ira->new_irb, scope, source_node); |
| 4311 | instruction->base.value->type = wanted_type; |
| 4312 | instruction->target = target; |
| 4313 | |
| 4314 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4315 | |
| 4316 | return &instruction->base; |
| 4317 | } |
| 4318 | |
| 4319 | static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4320 | IrInstSrc *target) |
| 3443 | 4321 | { |
| 3444 | | IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>( |
| 4322 | IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>( |
| 3445 | 4323 | irb, scope, source_node); |
| 3446 | 4324 | instruction->target = target; |
| 3447 | 4325 | |
| ... | ... | @@ -3450,11 +4328,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 3450 | 4328 | return &instruction->base; |
| 3451 | 4329 | } |
| 3452 | 4330 | |
| 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, |
| 4331 | static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4332 | ZigType *wanted_type) |
| 4333 | { |
| 4334 | IrInstGenErrToInt *instruction = ir_build_inst_gen<IrInstGenErrToInt>(&ira->new_irb, scope, source_node); |
| 4335 | instruction->base.value->type = wanted_type; |
| 4336 | instruction->target = target; |
| 4337 | |
| 4338 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4339 | |
| 4340 | return &instruction->base; |
| 4341 | } |
| 4342 | |
| 4343 | static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4344 | IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count, |
| 3455 | 4345 | bool have_else_prong, bool have_underscore_prong) |
| 3456 | 4346 | { |
| 3457 | | IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>( |
| 4347 | IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>( |
| 3458 | 4348 | irb, scope, source_node); |
| 3459 | 4349 | instruction->target_value = target_value; |
| 3460 | 4350 | instruction->ranges = ranges; |
| ... | ... | @@ -3471,10 +4361,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, |
| 3471 | 4361 | return &instruction->base; |
| 3472 | 4362 | } |
| 3473 | 4363 | |
| 3474 | | static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3475 | | IrInstruction* statement_value) |
| 4364 | static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4365 | IrInstSrc* statement_value) |
| 3476 | 4366 | { |
| 3477 | | IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>( |
| 4367 | IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>( |
| 3478 | 4368 | irb, scope, source_node); |
| 3479 | 4369 | instruction->statement_value = statement_value; |
| 3480 | 4370 | |
| ... | ... | @@ -3483,11 +4373,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc |
| 3483 | 4373 | return &instruction->base; |
| 3484 | 4374 | } |
| 3485 | 4375 | |
| 3486 | | static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3487 | | IrInstruction *type_value) |
| 4376 | static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4377 | IrInstSrc *type_value) |
| 3488 | 4378 | { |
| 3489 | | IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>( |
| 3490 | | irb, scope, source_node); |
| 4379 | IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node); |
| 3491 | 4380 | instruction->type_value = type_value; |
| 3492 | 4381 | |
| 3493 | 4382 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3495,40 +4384,60 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode * |
| 3495 | 4384 | return &instruction->base; |
| 3496 | 4385 | } |
| 3497 | 4386 | |
| 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); |
| 3500 | | instruction->tld = tld; |
| 3501 | | instruction->lval = lval; |
| 4387 | static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) { |
| 4388 | IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node); |
| 4389 | instruction->tld = tld; |
| 4390 | instruction->lval = lval; |
| 4391 | |
| 4392 | return &instruction->base; |
| 4393 | } |
| 4394 | |
| 4395 | static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) { |
| 4396 | IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node); |
| 4397 | instruction->base.is_noreturn = true; |
| 4398 | instruction->msg = msg; |
| 4399 | |
| 4400 | ir_ref_instruction(msg, irb->current_basic_block); |
| 4401 | |
| 4402 | return &instruction->base; |
| 4403 | } |
| 4404 | |
| 4405 | static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) { |
| 4406 | IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb, |
| 4407 | source_instr->scope, source_instr->source_node); |
| 4408 | instruction->msg = msg; |
| 4409 | |
| 4410 | ir_ref_inst_gen(msg, ira->new_irb.current_basic_block); |
| 3502 | 4411 | |
| 3503 | 4412 | return &instruction->base; |
| 3504 | 4413 | } |
| 3505 | 4414 | |
| 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; |
| 3510 | | instruction->msg = msg; |
| 4415 | static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) { |
| 4416 | IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node); |
| 4417 | instruction->target = target; |
| 3511 | 4418 | |
| 3512 | | ir_ref_instruction(msg, irb->current_basic_block); |
| 4419 | ir_ref_instruction(target, irb->current_basic_block); |
| 3513 | 4420 | |
| 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) |
| 4424 | static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target, |
| 4425 | ZigType *result_type) |
| 3519 | 4426 | { |
| 3520 | | IrInstructionTagName *instruction = ir_build_instruction<IrInstructionTagName>(irb, scope, source_node); |
| 4427 | IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb, |
| 4428 | source_instr->scope, source_instr->source_node); |
| 4429 | instruction->base.value->type = result_type; |
| 3521 | 4430 | instruction->target = target; |
| 3522 | 4431 | |
| 3523 | | ir_ref_instruction(target, irb->current_basic_block); |
| 4432 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3524 | 4433 | |
| 3525 | 4434 | return &instruction->base; |
| 3526 | 4435 | } |
| 3527 | 4436 | |
| 3528 | | static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3529 | | IrInstruction *target) |
| 4437 | static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4438 | IrInstSrc *target) |
| 3530 | 4439 | { |
| 3531 | | IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node); |
| 4440 | IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node); |
| 3532 | 4441 | instruction->target = target; |
| 3533 | 4442 | |
| 3534 | 4443 | ir_ref_instruction(target, irb->current_basic_block); |
| ... | ... | @@ -3536,27 +4445,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 3536 | 4445 | return &instruction->base; |
| 3537 | 4446 | } |
| 3538 | 4447 | |
| 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) |
| 4448 | static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4449 | IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr) |
| 3541 | 4450 | { |
| 3542 | | IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>( |
| 4451 | IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>( |
| 3543 | 4452 | 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; |
| 4453 | inst->type_value = type_value; |
| 4454 | inst->field_name = field_name; |
| 4455 | inst->field_ptr = field_ptr; |
| 3548 | 4456 | |
| 3549 | 4457 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 3550 | 4458 | ir_ref_instruction(field_name, irb->current_basic_block); |
| 3551 | 4459 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 3552 | 4460 | |
| 3553 | | return &instruction->base; |
| 4461 | return &inst->base; |
| 4462 | } |
| 4463 | |
| 4464 | static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4465 | IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type) |
| 4466 | { |
| 4467 | IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb, |
| 4468 | source_instr->scope, source_instr->source_node); |
| 4469 | inst->base.value->type = result_type; |
| 4470 | inst->field_ptr = field_ptr; |
| 4471 | inst->field = field; |
| 4472 | |
| 4473 | ir_ref_inst_gen(field_ptr, ira->new_irb.current_basic_block); |
| 4474 | |
| 4475 | return &inst->base; |
| 3554 | 4476 | } |
| 3555 | 4477 | |
| 3556 | | static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3557 | | IrInstruction *type_value, IrInstruction *field_name) |
| 4478 | static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4479 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 3558 | 4480 | { |
| 3559 | | IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node); |
| 4481 | IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node); |
| 3560 | 4482 | instruction->type_value = type_value; |
| 3561 | 4483 | instruction->field_name = field_name; |
| 3562 | 4484 | |
| ... | ... | @@ -3566,10 +4488,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN |
| 3566 | 4488 | return &instruction->base; |
| 3567 | 4489 | } |
| 3568 | 4490 | |
| 3569 | | static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3570 | | IrInstruction *type_value, IrInstruction *field_name) |
| 4491 | static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4492 | IrInstSrc *type_value, IrInstSrc *field_name) |
| 3571 | 4493 | { |
| 3572 | | IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node); |
| 4494 | IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node); |
| 3573 | 4495 | instruction->type_value = type_value; |
| 3574 | 4496 | instruction->field_name = field_name; |
| 3575 | 4497 | |
| ... | ... | @@ -3579,9 +4501,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo |
| 3579 | 4501 | return &instruction->base; |
| 3580 | 4502 | } |
| 3581 | 4503 | |
| 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); |
| 4504 | static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4505 | IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node); |
| 3585 | 4506 | instruction->type_value = type_value; |
| 3586 | 4507 | |
| 3587 | 4508 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3589,8 +4510,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode * |
| 3589 | 4510 | return &instruction->base; |
| 3590 | 4511 | } |
| 3591 | 4512 | |
| 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); |
| 4513 | static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) { |
| 4514 | IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node); |
| 3594 | 4515 | instruction->type_info = type_info; |
| 3595 | 4516 | |
| 3596 | 4517 | ir_ref_instruction(type_info, irb->current_basic_block); |
| ... | ... | @@ -3598,10 +4519,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 3598 | 4519 | return &instruction->base; |
| 3599 | 4520 | } |
| 3600 | 4521 | |
| 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); |
| 4522 | static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) { |
| 4523 | IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node); |
| 3605 | 4524 | instruction->type_value = type_value; |
| 3606 | 4525 | |
| 3607 | 4526 | ir_ref_instruction(type_value, irb->current_basic_block); |
| ... | ... | @@ -3609,10 +4528,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so |
| 3609 | 4528 | return &instruction->base; |
| 3610 | 4529 | } |
| 3611 | 4530 | |
| 3612 | | static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3613 | | IrInstruction *new_quota) |
| 4531 | static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4532 | IrInstSrc *new_quota) |
| 3614 | 4533 | { |
| 3615 | | IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node); |
| 4534 | IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node); |
| 3616 | 4535 | instruction->new_quota = new_quota; |
| 3617 | 4536 | |
| 3618 | 4537 | ir_ref_instruction(new_quota, irb->current_basic_block); |
| ... | ... | @@ -3620,23 +4539,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop |
| 3620 | 4539 | return &instruction->base; |
| 3621 | 4540 | } |
| 3622 | 4541 | |
| 3623 | | static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3624 | | IrInstruction *align_bytes, IrInstruction *target) |
| 4542 | static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4543 | IrInstSrc *align_bytes, IrInstSrc *target) |
| 3625 | 4544 | { |
| 3626 | | IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node); |
| 4545 | IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node); |
| 3627 | 4546 | instruction->align_bytes = align_bytes; |
| 3628 | 4547 | instruction->target = target; |
| 3629 | 4548 | |
| 3630 | | if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 4549 | ir_ref_instruction(align_bytes, irb->current_basic_block); |
| 3631 | 4550 | ir_ref_instruction(target, irb->current_basic_block); |
| 3632 | 4551 | |
| 3633 | 4552 | return &instruction->base; |
| 3634 | 4553 | } |
| 3635 | 4554 | |
| 3636 | | static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3637 | | ResultLoc *result_loc, IrInstruction *ty) |
| 4555 | static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 4556 | ZigType *result_type) |
| 4557 | { |
| 4558 | IrInstGenAlignCast *instruction = ir_build_inst_gen<IrInstGenAlignCast>(&ira->new_irb, scope, source_node); |
| 4559 | instruction->base.value->type = result_type; |
| 4560 | instruction->target = target; |
| 4561 | |
| 4562 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 4563 | |
| 4564 | return &instruction->base; |
| 4565 | } |
| 4566 | |
| 4567 | static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4568 | ResultLoc *result_loc, IrInstSrc *ty) |
| 3638 | 4569 | { |
| 3639 | | IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node); |
| 4570 | IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node); |
| 3640 | 4571 | instruction->result_loc = result_loc; |
| 3641 | 4572 | instruction->ty = ty; |
| 3642 | 4573 | |
| ... | ... | @@ -3645,25 +4576,25 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN |
| 3645 | 4576 | return &instruction->base; |
| 3646 | 4577 | } |
| 3647 | 4578 | |
| 3648 | | static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 4579 | static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 3649 | 4580 | ResultLoc *result_loc) |
| 3650 | 4581 | { |
| 3651 | | IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node); |
| 4582 | IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node); |
| 3652 | 4583 | instruction->result_loc = result_loc; |
| 3653 | 4584 | |
| 3654 | 4585 | return &instruction->base; |
| 3655 | 4586 | } |
| 3656 | 4587 | |
| 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); |
| 4588 | static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4589 | IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node); |
| 3659 | 4590 | |
| 3660 | 4591 | return &instruction->base; |
| 3661 | 4592 | } |
| 3662 | 4593 | |
| 3663 | | static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3664 | | IrInstruction *align_bytes) |
| 4594 | static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4595 | IrInstSrc *align_bytes) |
| 3665 | 4596 | { |
| 3666 | | IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node); |
| 4597 | IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node); |
| 3667 | 4598 | instruction->align_bytes = align_bytes; |
| 3668 | 4599 | |
| 3669 | 4600 | ir_ref_instruction(align_bytes, irb->current_basic_block); |
| ... | ... | @@ -3671,10 +4602,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast |
| 3671 | 4602 | return &instruction->base; |
| 3672 | 4603 | } |
| 3673 | 4604 | |
| 3674 | | static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3675 | | IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var) |
| 4605 | static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4606 | IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var) |
| 3676 | 4607 | { |
| 3677 | | IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node); |
| 4608 | IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node); |
| 3678 | 4609 | instruction->fn_type = fn_type; |
| 3679 | 4610 | instruction->arg_index = arg_index; |
| 3680 | 4611 | instruction->allow_var = allow_var; |
| ... | ... | @@ -3685,17 +4616,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 3685 | 4616 | return &instruction->base; |
| 3686 | 4617 | } |
| 3687 | 4618 | |
| 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; |
| 4619 | static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4620 | IrInstErrorReturnTraceOptional optional) |
| 4621 | { |
| 4622 | IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node); |
| 4623 | inst->optional = optional; |
| 3691 | 4624 | |
| 3692 | | return &instruction->base; |
| 4625 | return &inst->base; |
| 4626 | } |
| 4627 | |
| 4628 | static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4629 | IrInstErrorReturnTraceOptional optional, ZigType *result_type) |
| 4630 | { |
| 4631 | IrInstGenErrorReturnTrace *inst = ir_build_inst_gen<IrInstGenErrorReturnTrace>(&ira->new_irb, scope, source_node); |
| 4632 | inst->base.value->type = result_type; |
| 4633 | inst->optional = optional; |
| 4634 | |
| 4635 | return &inst->base; |
| 3693 | 4636 | } |
| 3694 | 4637 | |
| 3695 | | static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3696 | | IrInstruction *err_set, IrInstruction *payload) |
| 4638 | static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4639 | IrInstSrc *err_set, IrInstSrc *payload) |
| 3697 | 4640 | { |
| 3698 | | IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node); |
| 4641 | IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node); |
| 3699 | 4642 | instruction->err_set = err_set; |
| 3700 | 4643 | instruction->payload = payload; |
| 3701 | 4644 | |
| ... | ... | @@ -3705,85 +4648,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode |
| 3705 | 4648 | return &instruction->base; |
| 3706 | 4649 | } |
| 3707 | 4650 | |
| 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) |
| 4651 | static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4652 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand, |
| 4653 | IrInstSrc *ordering) |
| 3711 | 4654 | { |
| 3712 | | IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node); |
| 4655 | IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node); |
| 3713 | 4656 | instruction->operand_type = operand_type; |
| 3714 | 4657 | instruction->ptr = ptr; |
| 3715 | 4658 | instruction->op = op; |
| 3716 | 4659 | instruction->operand = operand; |
| 3717 | 4660 | instruction->ordering = ordering; |
| 3718 | | instruction->resolved_op = resolved_op; |
| 3719 | | instruction->resolved_ordering = resolved_ordering; |
| 3720 | 4661 | |
| 3721 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4662 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3722 | 4663 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3723 | | if (op != nullptr) ir_ref_instruction(op, irb->current_basic_block); |
| 4664 | ir_ref_instruction(op, irb->current_basic_block); |
| 3724 | 4665 | ir_ref_instruction(operand, irb->current_basic_block); |
| 3725 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4666 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 4667 | |
| 4668 | return &instruction->base; |
| 4669 | } |
| 4670 | |
| 4671 | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4672 | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type) |
| 4673 | { |
| 4674 | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4675 | instruction->base.value->type = operand_type; |
| 4676 | instruction->ptr = ptr; |
| 4677 | instruction->op = op; |
| 4678 | instruction->operand = operand; |
| 4679 | instruction->ordering = ordering; |
| 4680 | |
| 4681 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4682 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 3726 | 4683 | |
| 3727 | 4684 | return &instruction->base; |
| 3728 | 4685 | } |
| 3729 | 4686 | |
| 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) |
| 4687 | static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4688 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering) |
| 3733 | 4689 | { |
| 3734 | | IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node); |
| 4690 | IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node); |
| 3735 | 4691 | instruction->operand_type = operand_type; |
| 3736 | 4692 | instruction->ptr = ptr; |
| 3737 | 4693 | instruction->ordering = ordering; |
| 3738 | | instruction->resolved_ordering = resolved_ordering; |
| 3739 | 4694 | |
| 3740 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4695 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3741 | 4696 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3742 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4697 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 4698 | |
| 4699 | return &instruction->base; |
| 4700 | } |
| 4701 | |
| 4702 | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4703 | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type) |
| 4704 | { |
| 4705 | IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb, |
| 4706 | source_instr->scope, source_instr->source_node); |
| 4707 | instruction->base.value->type = operand_type; |
| 4708 | instruction->ptr = ptr; |
| 4709 | instruction->ordering = ordering; |
| 4710 | |
| 4711 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3743 | 4712 | |
| 3744 | 4713 | return &instruction->base; |
| 3745 | 4714 | } |
| 3746 | 4715 | |
| 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) |
| 4716 | static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4717 | IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering) |
| 3750 | 4718 | { |
| 3751 | | IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node); |
| 4719 | IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node); |
| 3752 | 4720 | instruction->operand_type = operand_type; |
| 3753 | 4721 | instruction->ptr = ptr; |
| 3754 | 4722 | instruction->value = value; |
| 3755 | 4723 | instruction->ordering = ordering; |
| 3756 | | instruction->resolved_ordering = resolved_ordering; |
| 3757 | 4724 | |
| 3758 | | if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block); |
| 4725 | ir_ref_instruction(operand_type, irb->current_basic_block); |
| 3759 | 4726 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 3760 | 4727 | ir_ref_instruction(value, irb->current_basic_block); |
| 3761 | | if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block); |
| 4728 | ir_ref_instruction(ordering, irb->current_basic_block); |
| 3762 | 4729 | |
| 3763 | 4730 | return &instruction->base; |
| 3764 | 4731 | } |
| 3765 | 4732 | |
| 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); |
| 4733 | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4734 | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering) |
| 4735 | { |
| 4736 | IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb, |
| 4737 | source_instr->scope, source_instr->source_node); |
| 4738 | instruction->ptr = ptr; |
| 4739 | instruction->value = value; |
| 4740 | instruction->ordering = ordering; |
| 4741 | |
| 4742 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4743 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| 4744 | |
| 3768 | 4745 | return &instruction->base; |
| 3769 | 4746 | } |
| 3770 | 4747 | |
| 3771 | | static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3772 | | IrInstruction *value, ResultLocReturn *result_loc_ret) |
| 4748 | static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4749 | IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node); |
| 4750 | return &inst->base; |
| 4751 | } |
| 4752 | |
| 4753 | static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 4754 | IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb, |
| 4755 | source_instr->scope, source_instr->source_node); |
| 4756 | return &inst->base; |
| 4757 | } |
| 4758 | |
| 4759 | static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4760 | IrInstSrc *value, ResultLocReturn *result_loc_ret) |
| 3773 | 4761 | { |
| 3774 | | IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node); |
| 3775 | | instruction->value = value; |
| 3776 | | instruction->result_loc_ret = result_loc_ret; |
| 4762 | IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node); |
| 4763 | inst->value = value; |
| 4764 | inst->result_loc_ret = result_loc_ret; |
| 3777 | 4765 | |
| 3778 | 4766 | ir_ref_instruction(value, irb->current_basic_block); |
| 3779 | 4767 | |
| 3780 | | return &instruction->base; |
| 4768 | return &inst->base; |
| 3781 | 4769 | } |
| 3782 | 4770 | |
| 3783 | | static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3784 | | IrInstruction *container, IrInstruction *name) |
| 4771 | static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4772 | IrInstSrc *container, IrInstSrc *name) |
| 3785 | 4773 | { |
| 3786 | | IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node); |
| 4774 | IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node); |
| 3787 | 4775 | instruction->container = container; |
| 3788 | 4776 | instruction->name = name; |
| 3789 | 4777 | |
| ... | ... | @@ -3793,17 +4781,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 3793 | 4781 | return &instruction->base; |
| 3794 | 4782 | } |
| 3795 | 4783 | |
| 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); |
| 4784 | static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 4785 | IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node); |
| 3800 | 4786 | instruction->name = name; |
| 3801 | 4787 | |
| 3802 | 4788 | return &instruction->base; |
| 3803 | 4789 | } |
| 3804 | 4790 | |
| 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); |
| 4791 | static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) { |
| 4792 | IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node); |
| 3807 | 4793 | instruction->scope_is_comptime = scope_is_comptime; |
| 3808 | 4794 | instruction->is_comptime = is_comptime; |
| 3809 | 4795 | |
| ... | ... | @@ -3813,10 +4799,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, |
| 3813 | 4799 | return &instruction->base; |
| 3814 | 4800 | } |
| 3815 | 4801 | |
| 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) |
| 4802 | static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4803 | IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc) |
| 3818 | 4804 | { |
| 3819 | | IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node); |
| 4805 | IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node); |
| 3820 | 4806 | instruction->union_type = union_type; |
| 3821 | 4807 | instruction->field_name = field_name; |
| 3822 | 4808 | instruction->field_result_loc = field_result_loc; |
| ... | ... | @@ -3831,79 +4817,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco |
| 3831 | 4817 | } |
| 3832 | 4818 | |
| 3833 | 4819 | |
| 3834 | | static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3835 | | ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc) |
| 4820 | static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction, |
| 4821 | ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc) |
| 3836 | 4822 | { |
| 3837 | | IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, |
| 4823 | IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb, |
| 3838 | 4824 | source_instruction->scope, source_instruction->source_node); |
| 3839 | 4825 | instruction->base.value->type = result_type; |
| 3840 | 4826 | instruction->vector = vector; |
| 3841 | 4827 | instruction->result_loc = result_loc; |
| 3842 | 4828 | |
| 3843 | | ir_ref_instruction(vector, ira->new_irb.current_basic_block); |
| 3844 | | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 4829 | ir_ref_inst_gen(vector, ira->new_irb.current_basic_block); |
| 4830 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3845 | 4831 | |
| 3846 | 4832 | return &instruction->base; |
| 3847 | 4833 | } |
| 3848 | 4834 | |
| 3849 | | static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3850 | | ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc) |
| 4835 | static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction, |
| 4836 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 3851 | 4837 | { |
| 3852 | | IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb, |
| 4838 | IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb, |
| 3853 | 4839 | source_instruction->scope, source_instruction->source_node); |
| 3854 | 4840 | instruction->base.value->type = result_type; |
| 3855 | 4841 | instruction->operand = operand; |
| 3856 | 4842 | instruction->result_loc = result_loc; |
| 3857 | 4843 | |
| 3858 | | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| 3859 | | ir_ref_instruction(result_loc, ira->new_irb.current_basic_block); |
| 4844 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 4845 | ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3860 | 4846 | |
| 3861 | 4847 | return &instruction->base; |
| 3862 | 4848 | } |
| 3863 | 4849 | |
| 3864 | | static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3865 | | IrInstruction *array, ZigType *result_type) |
| 4850 | static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction, |
| 4851 | IrInstGen *array, ZigType *result_type) |
| 3866 | 4852 | { |
| 3867 | | IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb, |
| 4853 | IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb, |
| 3868 | 4854 | source_instruction->scope, source_instruction->source_node); |
| 3869 | 4855 | instruction->base.value->type = result_type; |
| 3870 | 4856 | instruction->array = array; |
| 3871 | 4857 | |
| 3872 | | ir_ref_instruction(array, ira->new_irb.current_basic_block); |
| 4858 | ir_ref_inst_gen(array, ira->new_irb.current_basic_block); |
| 3873 | 4859 | |
| 3874 | 4860 | return &instruction->base; |
| 3875 | 4861 | } |
| 3876 | 4862 | |
| 3877 | | static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3878 | | IrInstruction *target) |
| 4863 | static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction, |
| 4864 | IrInstGen *target) |
| 3879 | 4865 | { |
| 3880 | | IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb, |
| 4866 | IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb, |
| 3881 | 4867 | source_instruction->scope, source_instruction->source_node); |
| 3882 | 4868 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3883 | 4869 | instruction->target = target; |
| 3884 | 4870 | |
| 3885 | | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| 4871 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3886 | 4872 | |
| 3887 | 4873 | return &instruction->base; |
| 3888 | 4874 | } |
| 3889 | 4875 | |
| 3890 | | static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3891 | | IrInstruction *target) |
| 4876 | static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction, |
| 4877 | IrInstGen *target) |
| 3892 | 4878 | { |
| 3893 | | IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb, |
| 4879 | IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb, |
| 3894 | 4880 | source_instruction->scope, source_instruction->source_node); |
| 3895 | 4881 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3896 | 4882 | instruction->target = target; |
| 3897 | 4883 | |
| 3898 | | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| 4884 | ir_ref_inst_gen(target, ira->new_irb.current_basic_block); |
| 3899 | 4885 | |
| 3900 | 4886 | return &instruction->base; |
| 3901 | 4887 | } |
| 3902 | 4888 | |
| 3903 | | static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3904 | | IrInstruction *align, const char *name_hint, IrInstruction *is_comptime) |
| 4889 | static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4890 | IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime) |
| 3905 | 4891 | { |
| 3906 | | IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node); |
| 4892 | IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node); |
| 3907 | 4893 | instruction->base.is_gen = true; |
| 3908 | 4894 | instruction->align = align; |
| 3909 | 4895 | instruction->name_hint = name_hint; |
| ... | ... | @@ -3915,10 +4901,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode |
| 3915 | 4901 | return &instruction->base; |
| 3916 | 4902 | } |
| 3917 | 4903 | |
| 3918 | | static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 4904 | static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 3919 | 4905 | uint32_t align, const char *name_hint) |
| 3920 | 4906 | { |
| 3921 | | IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb, |
| 4907 | IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb, |
| 3922 | 4908 | source_instruction->scope, source_instruction->source_node); |
| 3923 | 4909 | instruction->align = align; |
| 3924 | 4910 | instruction->name_hint = name_hint; |
| ... | ... | @@ -3926,10 +4912,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction |
| 3926 | 4912 | return instruction; |
| 3927 | 4913 | } |
| 3928 | 4914 | |
| 3929 | | static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3930 | | IrInstruction *value, ResultLoc *result_loc) |
| 4915 | static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4916 | IrInstSrc *value, ResultLoc *result_loc) |
| 3931 | 4917 | { |
| 3932 | | IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node); |
| 4918 | IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node); |
| 3933 | 4919 | instruction->base.is_gen = true; |
| 3934 | 4920 | instruction->value = value; |
| 3935 | 4921 | instruction->result_loc = result_loc; |
| ... | ... | @@ -3939,29 +4925,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s |
| 3939 | 4925 | return &instruction->base; |
| 3940 | 4926 | } |
| 3941 | 4927 | |
| 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; |
| 4928 | static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) { |
| 4929 | return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node); |
| 4930 | } |
| 3945 | 4931 | |
| 3946 | | return instruction; |
| 4932 | static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 4933 | IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb, |
| 4934 | source_instr->scope, source_instr->source_node); |
| 4935 | return &inst->base; |
| 3947 | 4936 | } |
| 3948 | 4937 | |
| 3949 | | static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3950 | | IrInstructionSuspendBegin *begin) |
| 4938 | static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4939 | IrInstSrcSuspendBegin *begin) |
| 3951 | 4940 | { |
| 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; |
| 4941 | IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node); |
| 4942 | inst->begin = begin; |
| 3955 | 4943 | |
| 3956 | 4944 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| 3957 | 4945 | |
| 3958 | | return &instruction->base; |
| 4946 | return &inst->base; |
| 4947 | } |
| 4948 | |
| 4949 | static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) { |
| 4950 | IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb, |
| 4951 | source_instr->scope, source_instr->source_node); |
| 4952 | inst->begin = begin; |
| 4953 | |
| 4954 | ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block); |
| 4955 | |
| 4956 | return &inst->base; |
| 3959 | 4957 | } |
| 3960 | 4958 | |
| 3961 | | static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3962 | | IrInstruction *frame, ResultLoc *result_loc) |
| 4959 | static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 4960 | IrInstSrc *frame, ResultLoc *result_loc) |
| 3963 | 4961 | { |
| 3964 | | IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node); |
| 4962 | IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node); |
| 3965 | 4963 | instruction->frame = frame; |
| 3966 | 4964 | instruction->result_loc = result_loc; |
| 3967 | 4965 | |
| ... | ... | @@ -3970,24 +4968,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode * |
| 3970 | 4968 | return &instruction->base; |
| 3971 | 4969 | } |
| 3972 | 4970 | |
| 3973 | | static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction, |
| 3974 | | IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc) |
| 4971 | static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 4972 | IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc) |
| 3975 | 4973 | { |
| 3976 | | IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb, |
| 4974 | IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb, |
| 3977 | 4975 | source_instruction->scope, source_instruction->source_node); |
| 3978 | 4976 | instruction->base.value->type = result_type; |
| 3979 | 4977 | instruction->frame = frame; |
| 3980 | 4978 | instruction->result_loc = result_loc; |
| 3981 | 4979 | |
| 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); |
| 4980 | ir_ref_inst_gen(frame, ira->new_irb.current_basic_block); |
| 4981 | if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block); |
| 3984 | 4982 | |
| 3985 | 4983 | return instruction; |
| 3986 | 4984 | } |
| 3987 | 4985 | |
| 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; |
| 4986 | static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) { |
| 4987 | IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node); |
| 3991 | 4988 | instruction->frame = frame; |
| 3992 | 4989 | |
| 3993 | 4990 | ir_ref_instruction(frame, irb->current_basic_block); |
| ... | ... | @@ -3995,12 +4992,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou |
| 3995 | 4992 | return &instruction->base; |
| 3996 | 4993 | } |
| 3997 | 4994 | |
| 3998 | | static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 3999 | | IrInstruction *operand, SpillId spill_id) |
| 4995 | static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) { |
| 4996 | IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb, |
| 4997 | source_instr->scope, source_instr->source_node); |
| 4998 | instruction->frame = frame; |
| 4999 | |
| 5000 | ir_ref_inst_gen(frame, ira->new_irb.current_basic_block); |
| 5001 | |
| 5002 | return &instruction->base; |
| 5003 | } |
| 5004 | |
| 5005 | static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 5006 | IrInstSrc *operand, SpillId spill_id) |
| 4000 | 5007 | { |
| 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; |
| 5008 | IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node); |
| 4004 | 5009 | instruction->operand = operand; |
| 4005 | 5010 | instruction->spill_id = spill_id; |
| 4006 | 5011 | |
| ... | ... | @@ -4009,10 +5014,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop |
| 4009 | 5014 | return instruction; |
| 4010 | 5015 | } |
| 4011 | 5016 | |
| 4012 | | static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 4013 | | IrInstructionSpillBegin *begin) |
| 5017 | static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 5018 | SpillId spill_id) |
| 5019 | { |
| 5020 | IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb, |
| 5021 | source_instr->scope, source_instr->source_node); |
| 5022 | instruction->operand = operand; |
| 5023 | instruction->spill_id = spill_id; |
| 5024 | |
| 5025 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| 5026 | |
| 5027 | return &instruction->base; |
| 5028 | } |
| 5029 | |
| 5030 | static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 5031 | IrInstSrcSpillBegin *begin) |
| 4014 | 5032 | { |
| 4015 | | IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node); |
| 5033 | IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node); |
| 4016 | 5034 | instruction->begin = begin; |
| 4017 | 5035 | |
| 4018 | 5036 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| ... | ... | @@ -4020,22 +5038,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode * |
| 4020 | 5038 | return &instruction->base; |
| 4021 | 5039 | } |
| 4022 | 5040 | |
| 4023 | | static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction, |
| 4024 | | IrInstruction *vector, IrInstruction *index) |
| 5041 | static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin, |
| 5042 | ZigType *result_type) |
| 5043 | { |
| 5044 | IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb, |
| 5045 | source_instr->scope, source_instr->source_node); |
| 5046 | instruction->base.value->type = result_type; |
| 5047 | instruction->begin = begin; |
| 5048 | |
| 5049 | ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block); |
| 5050 | |
| 5051 | return &instruction->base; |
| 5052 | } |
| 5053 | |
| 5054 | static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction, |
| 5055 | IrInstGen *vector, IrInstGen *index) |
| 4025 | 5056 | { |
| 4026 | | IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>( |
| 5057 | IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>( |
| 4027 | 5058 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 4028 | 5059 | instruction->base.value->type = vector->value->type->data.vector.elem_type; |
| 4029 | 5060 | instruction->vector = vector; |
| 4030 | 5061 | instruction->index = index; |
| 4031 | 5062 | |
| 4032 | | ir_ref_instruction(vector, ira->new_irb.current_basic_block); |
| 4033 | | ir_ref_instruction(index, ira->new_irb.current_basic_block); |
| 5063 | ir_ref_inst_gen(vector, ira->new_irb.current_basic_block); |
| 5064 | ir_ref_inst_gen(index, ira->new_irb.current_basic_block); |
| 4034 | 5065 | |
| 4035 | 5066 | return &instruction->base; |
| 4036 | 5067 | } |
| 4037 | 5068 | |
| 4038 | | static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 5069 | static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) { |
| 4039 | 5070 | results[ReturnKindUnconditional] = 0; |
| 4040 | 5071 | results[ReturnKindError] = 0; |
| 4041 | 5072 | |
| ... | ... | @@ -4072,12 +5103,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 4072 | 5103 | } |
| 4073 | 5104 | } |
| 4074 | 5105 | |
| 4075 | | static IrInstruction *ir_mark_gen(IrInstruction *instruction) { |
| 5106 | static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) { |
| 4076 | 5107 | instruction->is_gen = true; |
| 4077 | 5108 | return instruction; |
| 4078 | 5109 | } |
| 4079 | 5110 | |
| 4080 | | static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) { |
| 5111 | static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) { |
| 4081 | 5112 | Scope *scope = inner_scope; |
| 4082 | 5113 | bool is_noreturn = false; |
| 4083 | 5114 | while (scope != outer_scope) { |
| ... | ... | @@ -4094,11 +5125,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 4094 | 5125 | { |
| 4095 | 5126 | AstNode *defer_expr_node = defer_node->data.defer.expr; |
| 4096 | 5127 | 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 | | { |
| 5128 | IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 5129 | if (defer_expr_value != irb->codegen->invalid_inst_src) { |
| 5130 | if (defer_expr_value->is_noreturn) { |
| 4102 | 5131 | is_noreturn = true; |
| 4103 | 5132 | } else { |
| 4104 | 5133 | ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, |
| ... | ... | @@ -4130,13 +5159,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 4130 | 5159 | return is_noreturn; |
| 4131 | 5160 | } |
| 4132 | 5161 | |
| 4133 | | static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 5162 | static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) { |
| 4134 | 5163 | assert(basic_block); |
| 5164 | irb->current_basic_block = basic_block; |
| 5165 | } |
| 4135 | 5166 | |
| 5167 | static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { |
| 5168 | assert(basic_block); |
| 4136 | 5169 | irb->current_basic_block = basic_block; |
| 4137 | 5170 | } |
| 4138 | 5171 | |
| 4139 | | static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 5172 | static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) { |
| 4140 | 5173 | basic_block->index = irb->exec->basic_block_list.length; |
| 4141 | 5174 | irb->exec->basic_block_list.append(basic_block); |
| 4142 | 5175 | ir_set_cursor_at_end(irb, basic_block); |
| ... | ... | @@ -4166,13 +5199,13 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 4166 | 5199 | return nullptr; |
| 4167 | 5200 | } |
| 4168 | 5201 | |
| 4169 | | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5202 | static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4170 | 5203 | assert(node->type == NodeTypeReturnExpr); |
| 4171 | 5204 | |
| 4172 | 5205 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 4173 | 5206 | if (!fn_entry) { |
| 4174 | 5207 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); |
| 4175 | | return irb->codegen->invalid_instruction; |
| 5208 | return irb->codegen->invalid_inst_src; |
| 4176 | 5209 | } |
| 4177 | 5210 | |
| 4178 | 5211 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); |
| ... | ... | @@ -4181,7 +5214,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4181 | 5214 | add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression")); |
| 4182 | 5215 | scope_defer_expr->reported_err = true; |
| 4183 | 5216 | } |
| 4184 | | return irb->codegen->invalid_instruction; |
| 5217 | return irb->codegen->invalid_inst_src; |
| 4185 | 5218 | } |
| 4186 | 5219 | |
| 4187 | 5220 | Scope *outer_scope = irb->exec->begin_scope; |
| ... | ... | @@ -4194,15 +5227,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4194 | 5227 | result_loc_ret->base.id = ResultLocIdReturn; |
| 4195 | 5228 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); |
| 4196 | 5229 | |
| 4197 | | IrInstruction *return_value; |
| 5230 | IrInstSrc *return_value; |
| 4198 | 5231 | if (expr_node) { |
| 4199 | 5232 | // Temporarily set this so that if we return a type it gets the name of the function |
| 4200 | 5233 | ZigFn *prev_name_fn = irb->exec->name_fn; |
| 4201 | 5234 | irb->exec->name_fn = exec_fn_entry(irb->exec); |
| 4202 | 5235 | return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base); |
| 4203 | 5236 | irb->exec->name_fn = prev_name_fn; |
| 4204 | | if (return_value == irb->codegen->invalid_instruction) |
| 4205 | | return irb->codegen->invalid_instruction; |
| 5237 | if (return_value == irb->codegen->invalid_inst_src) |
| 5238 | return irb->codegen->invalid_inst_src; |
| 4206 | 5239 | } else { |
| 4207 | 5240 | return_value = ir_build_const_void(irb, scope, node); |
| 4208 | 5241 | } |
| ... | ... | @@ -4215,22 +5248,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4215 | 5248 | if (!have_err_defers && !irb->codegen->have_err_ret_tracing) { |
| 4216 | 5249 | // only generate unconditional defers |
| 4217 | 5250 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 4218 | | IrInstruction *result = ir_build_return(irb, scope, node, return_value); |
| 5251 | IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value); |
| 4219 | 5252 | result_loc_ret->base.source_instruction = result; |
| 4220 | 5253 | return result; |
| 4221 | 5254 | } |
| 4222 | 5255 | bool should_inline = ir_should_inline(irb->exec, scope); |
| 4223 | 5256 | |
| 4224 | | IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); |
| 4225 | | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); |
| 5257 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr"); |
| 5258 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk"); |
| 4226 | 5259 | |
| 4227 | 5260 | if (!have_err_defers) { |
| 4228 | 5261 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 4229 | 5262 | } |
| 4230 | 5263 | |
| 4231 | | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true); |
| 5264 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true); |
| 4232 | 5265 | |
| 4233 | | IrInstruction *is_comptime; |
| 5266 | IrInstSrc *is_comptime; |
| 4234 | 5267 | if (should_inline) { |
| 4235 | 5268 | is_comptime = ir_build_const_bool(irb, scope, node, should_inline); |
| 4236 | 5269 | } else { |
| ... | ... | @@ -4238,14 +5271,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4238 | 5271 | } |
| 4239 | 5272 | |
| 4240 | 5273 | 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"); |
| 5274 | IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt"); |
| 4242 | 5275 | |
| 4243 | 5276 | ir_set_cursor_at_end_and_append_block(irb, err_block); |
| 4244 | 5277 | if (have_err_defers) { |
| 4245 | 5278 | ir_gen_defers_for_block(irb, scope, outer_scope, true); |
| 4246 | 5279 | } |
| 4247 | 5280 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 4248 | | ir_build_save_err_ret_addr(irb, scope, node); |
| 5281 | ir_build_save_err_ret_addr_src(irb, scope, node); |
| 4249 | 5282 | } |
| 4250 | 5283 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); |
| 4251 | 5284 | |
| ... | ... | @@ -4256,21 +5289,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4256 | 5289 | ir_build_br(irb, scope, node, ret_stmt_block, is_comptime); |
| 4257 | 5290 | |
| 4258 | 5291 | ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block); |
| 4259 | | IrInstruction *result = ir_build_return(irb, scope, node, return_value); |
| 5292 | IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value); |
| 4260 | 5293 | result_loc_ret->base.source_instruction = result; |
| 4261 | 5294 | return result; |
| 4262 | 5295 | } |
| 4263 | 5296 | case ReturnKindError: |
| 4264 | 5297 | { |
| 4265 | 5298 | 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; |
| 5299 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 5300 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 5301 | return irb->codegen->invalid_inst_src; |
| 5302 | IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false); |
| 5303 | |
| 5304 | IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); |
| 5305 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); |
| 5306 | IrInstSrc *is_comptime; |
| 4274 | 5307 | bool should_inline = ir_should_inline(irb->exec, scope); |
| 4275 | 5308 | if (should_inline) { |
| 4276 | 5309 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| ... | ... | @@ -4280,10 +5313,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4280 | 5313 | ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime)); |
| 4281 | 5314 | |
| 4282 | 5315 | 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); |
| 5316 | IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr); |
| 5317 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 4285 | 5318 | 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, |
| 5319 | IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val, |
| 4287 | 5320 | SpillIdRetErrCode); |
| 4288 | 5321 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn"); |
| 4289 | 5322 | result_loc_ret->base.id = ResultLocIdReturn; |
| ... | ... | @@ -4291,15 +5324,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4291 | 5324 | ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base); |
| 4292 | 5325 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { |
| 4293 | 5326 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 4294 | | ir_build_save_err_ret_addr(irb, scope, node); |
| 5327 | ir_build_save_err_ret_addr_src(irb, scope, node); |
| 4295 | 5328 | } |
| 4296 | | err_val = ir_build_spill_end(irb, scope, node, spill_begin); |
| 4297 | | IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val); |
| 5329 | err_val = ir_build_spill_end_src(irb, scope, node, spill_begin); |
| 5330 | IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val); |
| 4298 | 5331 | result_loc_ret->base.source_instruction = ret_inst; |
| 4299 | 5332 | } |
| 4300 | 5333 | |
| 4301 | 5334 | 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); |
| 5335 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false); |
| 4303 | 5336 | if (lval == LValPtr) |
| 4304 | 5337 | return unwrapped_ptr; |
| 4305 | 5338 | else |
| ... | ... | @@ -4310,7 +5343,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4310 | 5343 | } |
| 4311 | 5344 | |
| 4312 | 5345 | 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, |
| 5346 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime, |
| 4314 | 5347 | bool skip_name_check) |
| 4315 | 5348 | { |
| 4316 | 5349 | ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar"); |
| ... | ... | @@ -4322,7 +5355,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 4322 | 5355 | variable_entry->const_value = create_const_vals(1); |
| 4323 | 5356 | |
| 4324 | 5357 | if (is_comptime != nullptr) { |
| 4325 | | is_comptime->ref_count += 1; |
| 5358 | is_comptime->base.ref_count += 1; |
| 4326 | 5359 | } |
| 4327 | 5360 | |
| 4328 | 5361 | if (name) { |
| ... | ... | @@ -4372,8 +5405,8 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 4372 | 5405 | |
| 4373 | 5406 | // Set name to nullptr to make the variable anonymous (not visible to programmer). |
| 4374 | 5407 | // 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) |
| 5408 | static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name, |
| 5409 | bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime) |
| 4377 | 5410 | { |
| 4378 | 5411 | bool is_underscored = name ? buf_eql_str(name, "_") : false; |
| 4379 | 5412 | ZigVar *var = create_local_var(irb->codegen, node, scope, |
| ... | ... | @@ -4396,13 +5429,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) { |
| 4396 | 5429 | return result; |
| 4397 | 5430 | } |
| 4398 | 5431 | |
| 4399 | | static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node, LVal lval, |
| 5432 | static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval, |
| 4400 | 5433 | ResultLoc *result_loc) |
| 4401 | 5434 | { |
| 4402 | 5435 | assert(block_node->type == NodeTypeBlock); |
| 4403 | 5436 | |
| 4404 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 4405 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 5437 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 5438 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 4406 | 5439 | |
| 4407 | 5440 | ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope); |
| 4408 | 5441 | |
| ... | ... | @@ -4438,11 +5471,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4438 | 5471 | } |
| 4439 | 5472 | |
| 4440 | 5473 | bool is_continuation_unreachable = false; |
| 4441 | | IrInstruction *noreturn_return_value = nullptr; |
| 5474 | IrInstSrc *noreturn_return_value = nullptr; |
| 4442 | 5475 | for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { |
| 4443 | 5476 | AstNode *statement_node = block_node->data.block.statements.at(i); |
| 4444 | 5477 | |
| 4445 | | IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope); |
| 5478 | IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope); |
| 4446 | 5479 | is_continuation_unreachable = instr_is_unreachable(statement_value); |
| 4447 | 5480 | if (is_continuation_unreachable) { |
| 4448 | 5481 | // keep the last noreturn statement value around in case we need to return it |
| ... | ... | @@ -4450,15 +5483,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4450 | 5483 | } |
| 4451 | 5484 | // This logic must be kept in sync with |
| 4452 | 5485 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 4453 | | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) { |
| 5486 | if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) { |
| 4454 | 5487 | // defer starts a new scope |
| 4455 | 5488 | child_scope = statement_node->data.defer.child_scope; |
| 4456 | 5489 | assert(child_scope); |
| 4457 | | } else if (statement_value->id == IrInstructionIdDeclVarSrc) { |
| 5490 | } else if (statement_value->id == IrInstSrcIdDeclVar) { |
| 4458 | 5491 | // variable declarations start a new scope |
| 4459 | | IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value; |
| 5492 | IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value; |
| 4460 | 5493 | child_scope = decl_var_instruction->var->child_scope; |
| 4461 | | } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) { |
| 5494 | } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) { |
| 4462 | 5495 | // this statement's value must be void |
| 4463 | 5496 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value)); |
| 4464 | 5497 | } |
| ... | ... | @@ -4474,12 +5507,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4474 | 5507 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; |
| 4475 | 5508 | } |
| 4476 | 5509 | 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, |
| 5510 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 4478 | 5511 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 4479 | 5512 | return ir_expr_wrap(irb, parent_scope, phi, result_loc); |
| 4480 | 5513 | } else { |
| 4481 | 5514 | incoming_blocks.append(irb->current_basic_block); |
| 4482 | | IrInstruction *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)); |
| 5515 | IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)); |
| 4483 | 5516 | |
| 4484 | 5517 | if (scope_block->peer_parent != nullptr) { |
| 4485 | 5518 | ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent); |
| ... | ... | @@ -4499,15 +5532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4499 | 5532 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false); |
| 4500 | 5533 | } |
| 4501 | 5534 | |
| 4502 | | IrInstruction *result; |
| 5535 | IrInstSrc *result; |
| 4503 | 5536 | if (block_node->data.block.name != nullptr) { |
| 4504 | 5537 | ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime)); |
| 4505 | 5538 | 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, |
| 5539 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, |
| 4507 | 5540 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 4508 | 5541 | result = ir_expr_wrap(irb, parent_scope, phi, result_loc); |
| 4509 | 5542 | } else { |
| 4510 | | IrInstruction *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); |
| 5543 | IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); |
| 4511 | 5544 | result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc); |
| 4512 | 5545 | } |
| 4513 | 5546 | if (!is_return_from_fn) |
| ... | ... | @@ -4518,30 +5551,30 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4518 | 5551 | |
| 4519 | 5552 | ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr)); |
| 4520 | 5553 | 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)); |
| 5554 | return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result)); |
| 4522 | 5555 | } |
| 4523 | 5556 | |
| 4524 | | static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 5557 | static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 4525 | 5558 | Scope *inner_scope = scope; |
| 4526 | 5559 | if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) { |
| 4527 | 5560 | inner_scope = create_comptime_scope(irb->codegen, node, scope); |
| 4528 | 5561 | } |
| 4529 | 5562 | |
| 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); |
| 5563 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope); |
| 5564 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope); |
| 4532 | 5565 | |
| 4533 | | if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction) |
| 4534 | | return irb->codegen->invalid_instruction; |
| 5566 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) |
| 5567 | return irb->codegen->invalid_inst_src; |
| 4535 | 5568 | |
| 4536 | 5569 | return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 4537 | 5570 | } |
| 4538 | 5571 | |
| 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); |
| 5572 | static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5573 | IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5574 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 4542 | 5575 | |
| 4543 | | if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction) |
| 4544 | | return irb->codegen->invalid_instruction; |
| 5576 | if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src) |
| 5577 | return irb->codegen->invalid_inst_src; |
| 4545 | 5578 | |
| 4546 | 5579 | // TODO only pass type_name when the || operator is the top level AST node in the var decl expr |
| 4547 | 5580 | Buf bare_name = BUF_INIT; |
| ... | ... | @@ -4550,10 +5583,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod |
| 4550 | 5583 | return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name); |
| 4551 | 5584 | } |
| 4552 | 5585 | |
| 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; |
| 5586 | static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5587 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5588 | if (lvalue == irb->codegen->invalid_inst_src) |
| 5589 | return irb->codegen->invalid_inst_src; |
| 4557 | 5590 | |
| 4558 | 5591 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction"); |
| 4559 | 5592 | result_loc_inst->base.id = ResultLocIdInstruction; |
| ... | ... | @@ -4561,49 +5594,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) |
| 4561 | 5594 | ir_ref_instruction(lvalue, irb->current_basic_block); |
| 4562 | 5595 | ir_build_reset_result(irb, scope, node, &result_loc_inst->base); |
| 4563 | 5596 | |
| 4564 | | IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, |
| 5597 | IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone, |
| 4565 | 5598 | &result_loc_inst->base); |
| 4566 | | if (rvalue == irb->codegen->invalid_instruction) |
| 4567 | | return irb->codegen->invalid_instruction; |
| 5599 | if (rvalue == irb->codegen->invalid_inst_src) |
| 5600 | return irb->codegen->invalid_inst_src; |
| 4568 | 5601 | |
| 4569 | 5602 | return ir_build_const_void(irb, scope, node); |
| 4570 | 5603 | } |
| 4571 | 5604 | |
| 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) |
| 5605 | static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5606 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5607 | if (lvalue == irb->codegen->invalid_inst_src) |
| 4575 | 5608 | 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) |
| 5609 | IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 5610 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5611 | if (op2 == irb->codegen->invalid_inst_src) |
| 4579 | 5612 | return op2; |
| 4580 | | IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr); |
| 5613 | IrInstSrc *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr); |
| 4581 | 5614 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 4582 | 5615 | return ir_build_const_void(irb, scope, node); |
| 4583 | 5616 | } |
| 4584 | 5617 | |
| 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) |
| 5618 | static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 5619 | IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr); |
| 5620 | if (lvalue == irb->codegen->invalid_inst_src) |
| 4588 | 5621 | 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) |
| 5622 | IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 5623 | IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5624 | if (op2 == irb->codegen->invalid_inst_src) |
| 4592 | 5625 | return op2; |
| 4593 | | IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 5626 | IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true); |
| 4594 | 5627 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 4595 | 5628 | return ir_build_const_void(irb, scope, node); |
| 4596 | 5629 | } |
| 4597 | 5630 | |
| 4598 | | static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5631 | static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4599 | 5632 | assert(node->type == NodeTypeBinOpExpr); |
| 4600 | 5633 | |
| 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; |
| 5634 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5635 | if (val1 == irb->codegen->invalid_inst_src) |
| 5636 | return irb->codegen->invalid_inst_src; |
| 5637 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; |
| 4605 | 5638 | |
| 4606 | | IrInstruction *is_comptime; |
| 5639 | IrInstSrc *is_comptime; |
| 4607 | 5640 | if (ir_should_inline(irb->exec, scope)) { |
| 4608 | 5641 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 4609 | 5642 | } else { |
| ... | ... | @@ -4611,41 +5644,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node |
| 4611 | 5644 | } |
| 4612 | 5645 | |
| 4613 | 5646 | // block for when val1 == false |
| 4614 | | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); |
| 5647 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse"); |
| 4615 | 5648 | // block for when val1 == true (don't even evaluate the second part) |
| 4616 | | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); |
| 5649 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue"); |
| 4617 | 5650 | |
| 4618 | 5651 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 4619 | 5652 | |
| 4620 | 5653 | 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; |
| 5654 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5655 | if (val2 == irb->codegen->invalid_inst_src) |
| 5656 | return irb->codegen->invalid_inst_src; |
| 5657 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; |
| 4625 | 5658 | |
| 4626 | 5659 | ir_build_br(irb, scope, node, true_block, is_comptime); |
| 4627 | 5660 | |
| 4628 | 5661 | ir_set_cursor_at_end_and_append_block(irb, true_block); |
| 4629 | 5662 | |
| 4630 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2, "IrInstruction *"); |
| 5663 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *"); |
| 4631 | 5664 | incoming_values[0] = val1; |
| 4632 | 5665 | incoming_values[1] = val2; |
| 4633 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5666 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4634 | 5667 | incoming_blocks[0] = post_val1_block; |
| 4635 | 5668 | incoming_blocks[1] = post_val2_block; |
| 4636 | 5669 | |
| 4637 | 5670 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 4638 | 5671 | } |
| 4639 | 5672 | |
| 4640 | | static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5673 | static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4641 | 5674 | assert(node->type == NodeTypeBinOpExpr); |
| 4642 | 5675 | |
| 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; |
| 5676 | IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 5677 | if (val1 == irb->codegen->invalid_inst_src) |
| 5678 | return irb->codegen->invalid_inst_src; |
| 5679 | IrBasicBlockSrc *post_val1_block = irb->current_basic_block; |
| 4647 | 5680 | |
| 4648 | | IrInstruction *is_comptime; |
| 5681 | IrInstSrc *is_comptime; |
| 4649 | 5682 | if (ir_should_inline(irb->exec, scope)) { |
| 4650 | 5683 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 4651 | 5684 | } else { |
| ... | ... | @@ -4653,34 +5686,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod |
| 4653 | 5686 | } |
| 4654 | 5687 | |
| 4655 | 5688 | // block for when val1 == true |
| 4656 | | IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); |
| 5689 | IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue"); |
| 4657 | 5690 | // block for when val1 == false (don't even evaluate the second part) |
| 4658 | | IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); |
| 5691 | IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse"); |
| 4659 | 5692 | |
| 4660 | 5693 | ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime); |
| 4661 | 5694 | |
| 4662 | 5695 | 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; |
| 5696 | IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 5697 | if (val2 == irb->codegen->invalid_inst_src) |
| 5698 | return irb->codegen->invalid_inst_src; |
| 5699 | IrBasicBlockSrc *post_val2_block = irb->current_basic_block; |
| 4667 | 5700 | |
| 4668 | 5701 | ir_build_br(irb, scope, node, false_block, is_comptime); |
| 4669 | 5702 | |
| 4670 | 5703 | ir_set_cursor_at_end_and_append_block(irb, false_block); |
| 4671 | 5704 | |
| 4672 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5705 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 4673 | 5706 | incoming_values[0] = val1; |
| 4674 | 5707 | incoming_values[1] = val2; |
| 4675 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5708 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4676 | 5709 | incoming_blocks[0] = post_val1_block; |
| 4677 | 5710 | incoming_blocks[1] = post_val2_block; |
| 4678 | 5711 | |
| 4679 | 5712 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 4680 | 5713 | } |
| 4681 | 5714 | |
| 4682 | | static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst, |
| 4683 | | IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime) |
| 5715 | static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, |
| 5716 | IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 4684 | 5717 | { |
| 4685 | 5718 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 4686 | 5719 | peer_parent->base.id = ResultLocIdPeerParent; |
| ... | ... | @@ -4690,17 +5723,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction |
| 4690 | 5723 | peer_parent->is_comptime = is_comptime; |
| 4691 | 5724 | peer_parent->parent = parent; |
| 4692 | 5725 | |
| 4693 | | IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop(); |
| 4694 | | ir_assert(popped_inst == cond_br_inst, cond_br_inst); |
| 5726 | IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop(); |
| 5727 | ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base); |
| 4695 | 5728 | |
| 4696 | | ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base); |
| 5729 | ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base); |
| 4697 | 5730 | irb->current_basic_block->instruction_list.append(popped_inst); |
| 4698 | 5731 | |
| 4699 | 5732 | return peer_parent; |
| 4700 | 5733 | } |
| 4701 | 5734 | |
| 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) |
| 5735 | static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst, |
| 5736 | IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime) |
| 4704 | 5737 | { |
| 4705 | 5738 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime); |
| 4706 | 5739 | |
| ... | ... | @@ -4713,7 +5746,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr |
| 4713 | 5746 | return peer_parent; |
| 4714 | 5747 | } |
| 4715 | 5748 | |
| 4716 | | static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 5749 | static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 4717 | 5750 | ResultLoc *result_loc) |
| 4718 | 5751 | { |
| 4719 | 5752 | assert(node->type == NodeTypeBinOpExpr); |
| ... | ... | @@ -4721,73 +5754,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode |
| 4721 | 5754 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 4722 | 5755 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 4723 | 5756 | |
| 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; |
| 5757 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 5758 | if (maybe_ptr == irb->codegen->invalid_inst_src) |
| 5759 | return irb->codegen->invalid_inst_src; |
| 4727 | 5760 | |
| 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); |
| 5761 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr); |
| 5762 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val); |
| 4730 | 5763 | |
| 4731 | | IrInstruction *is_comptime; |
| 5764 | IrInstSrc *is_comptime; |
| 4732 | 5765 | if (ir_should_inline(irb->exec, parent_scope)) { |
| 4733 | 5766 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); |
| 4734 | 5767 | } else { |
| 4735 | 5768 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null); |
| 4736 | 5769 | } |
| 4737 | 5770 | |
| 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); |
| 5771 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull"); |
| 5772 | IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull"); |
| 5773 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd"); |
| 5774 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime); |
| 4742 | 5775 | |
| 4743 | 5776 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, |
| 4744 | 5777 | result_loc, is_comptime); |
| 4745 | 5778 | |
| 4746 | 5779 | 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, |
| 5780 | IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone, |
| 4748 | 5781 | &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; |
| 5782 | if (null_result == irb->codegen->invalid_inst_src) |
| 5783 | return irb->codegen->invalid_inst_src; |
| 5784 | IrBasicBlockSrc *after_null_block = irb->current_basic_block; |
| 4752 | 5785 | if (!instr_is_unreachable(null_result)) |
| 4753 | 5786 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 4754 | 5787 | |
| 4755 | 5788 | 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); |
| 5789 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false); |
| 5790 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 4758 | 5791 | 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; |
| 5792 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; |
| 4760 | 5793 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 4761 | 5794 | |
| 4762 | 5795 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 4763 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 5796 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 4764 | 5797 | incoming_values[0] = null_result; |
| 4765 | 5798 | incoming_values[1] = unwrapped_payload; |
| 4766 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 5799 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 4767 | 5800 | incoming_blocks[0] = after_null_block; |
| 4768 | 5801 | incoming_blocks[1] = after_ok_block; |
| 4769 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 5802 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 4770 | 5803 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 4771 | 5804 | } |
| 4772 | 5805 | |
| 4773 | | static IrInstruction *ir_gen_error_union(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 5806 | static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 4774 | 5807 | assert(node->type == NodeTypeBinOpExpr); |
| 4775 | 5808 | |
| 4776 | 5809 | AstNode *op1_node = node->data.bin_op_expr.op1; |
| 4777 | 5810 | AstNode *op2_node = node->data.bin_op_expr.op2; |
| 4778 | 5811 | |
| 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; |
| 5812 | IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope); |
| 5813 | if (err_set == irb->codegen->invalid_inst_src) |
| 5814 | return irb->codegen->invalid_inst_src; |
| 4782 | 5815 | |
| 4783 | | IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope); |
| 4784 | | if (payload == irb->codegen->invalid_instruction) |
| 4785 | | return irb->codegen->invalid_instruction; |
| 5816 | IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope); |
| 5817 | if (payload == irb->codegen->invalid_inst_src) |
| 5818 | return irb->codegen->invalid_inst_src; |
| 4786 | 5819 | |
| 4787 | 5820 | return ir_build_error_union(irb, parent_scope, node, err_set, payload); |
| 4788 | 5821 | } |
| 4789 | 5822 | |
| 4790 | | static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5823 | static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4791 | 5824 | assert(node->type == NodeTypeBinOpExpr); |
| 4792 | 5825 | |
| 4793 | 5826 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; |
| ... | ... | @@ -4880,30 +5913,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4880 | 5913 | zig_unreachable(); |
| 4881 | 5914 | } |
| 4882 | 5915 | |
| 4883 | | static IrInstruction *ir_gen_int_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5916 | static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4884 | 5917 | assert(node->type == NodeTypeIntLiteral); |
| 4885 | 5918 | |
| 4886 | 5919 | return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint); |
| 4887 | 5920 | } |
| 4888 | 5921 | |
| 4889 | | static IrInstruction *ir_gen_float_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5922 | static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4890 | 5923 | assert(node->type == NodeTypeFloatLiteral); |
| 4891 | 5924 | |
| 4892 | 5925 | if (node->data.float_literal.overflow) { |
| 4893 | 5926 | add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type")); |
| 4894 | | return irb->codegen->invalid_instruction; |
| 5927 | return irb->codegen->invalid_inst_src; |
| 4895 | 5928 | } |
| 4896 | 5929 | |
| 4897 | 5930 | return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat); |
| 4898 | 5931 | } |
| 4899 | 5932 | |
| 4900 | | static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5933 | static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4901 | 5934 | assert(node->type == NodeTypeCharLiteral); |
| 4902 | 5935 | |
| 4903 | 5936 | return ir_build_const_uint(irb, scope, node, node->data.char_literal.value); |
| 4904 | 5937 | } |
| 4905 | 5938 | |
| 4906 | | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 5939 | static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 4907 | 5940 | assert(node->type == NodeTypeNullLiteral); |
| 4908 | 5941 | |
| 4909 | 5942 | return ir_build_const_null(irb, scope, node); |
| ... | ... | @@ -4921,11 +5954,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 4921 | 5954 | init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); |
| 4922 | 5955 | tld_var->base.resolution = TldResolutionInvalid; |
| 4923 | 5956 | 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); |
| 5957 | g->invalid_inst_gen->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4925 | 5958 | scope_decls->decl_table.put(var_name, &tld_var->base); |
| 4926 | 5959 | } |
| 4927 | 5960 | |
| 4928 | | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 5961 | static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4929 | 5962 | Error err; |
| 4930 | 5963 | assert(node->type == NodeTypeSymbol); |
| 4931 | 5964 | |
| ... | ... | @@ -4933,15 +5966,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4933 | 5966 | |
| 4934 | 5967 | if (buf_eql_str(variable_name, "_")) { |
| 4935 | 5968 | 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, |
| 5969 | IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node); |
| 5970 | const_instruction->value = create_const_vals(1); |
| 5971 | const_instruction->value->type = get_pointer_to_type(irb->codegen, |
| 4938 | 5972 | irb->codegen->builtin_types.entry_void, false); |
| 4939 | | const_instruction->base.value->special = ConstValSpecialStatic; |
| 4940 | | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 5973 | const_instruction->value->special = ConstValSpecialStatic; |
| 5974 | const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4941 | 5975 | return &const_instruction->base; |
| 4942 | 5976 | } else { |
| 4943 | 5977 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| 4944 | | return irb->codegen->invalid_instruction; |
| 5978 | return irb->codegen->invalid_inst_src; |
| 4945 | 5979 | } |
| 4946 | 5980 | } |
| 4947 | 5981 | |
| ... | ... | @@ -4951,13 +5985,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4951 | 5985 | add_node_error(irb->codegen, node, |
| 4952 | 5986 | buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535", |
| 4953 | 5987 | buf_ptr(variable_name))); |
| 4954 | | return irb->codegen->invalid_instruction; |
| 5988 | return irb->codegen->invalid_inst_src; |
| 4955 | 5989 | } |
| 4956 | 5990 | assert(err == ErrorPrimitiveTypeNotFound); |
| 4957 | 5991 | } else { |
| 4958 | | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 5992 | IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 4959 | 5993 | if (lval == LValPtr) { |
| 4960 | | return ir_build_ref(irb, scope, node, value, false, false); |
| 5994 | return ir_build_ref_src(irb, scope, node, value, false, false); |
| 4961 | 5995 | } else { |
| 4962 | 5996 | return ir_expr_wrap(irb, scope, value, result_loc); |
| 4963 | 5997 | } |
| ... | ... | @@ -4966,7 +6000,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4966 | 6000 | ScopeFnDef *crossed_fndef_scope; |
| 4967 | 6001 | ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope); |
| 4968 | 6002 | if (var) { |
| 4969 | | IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); |
| 6003 | IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope); |
| 4970 | 6004 | if (lval == LValPtr) { |
| 4971 | 6005 | return var_ptr; |
| 4972 | 6006 | } else { |
| ... | ... | @@ -4976,7 +6010,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4976 | 6010 | |
| 4977 | 6011 | Tld *tld = find_decl(irb->codegen, scope, variable_name); |
| 4978 | 6012 | if (tld) { |
| 4979 | | IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval); |
| 6013 | IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval); |
| 4980 | 6014 | if (lval == LValPtr) { |
| 4981 | 6015 | return decl_ref; |
| 4982 | 6016 | } else { |
| ... | ... | @@ -4987,50 +6021,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4987 | 6021 | if (get_container_scope(node->owner)->any_imports_failed) { |
| 4988 | 6022 | // skip the error message since we had a failing import in this file |
| 4989 | 6023 | // if an import breaks we don't need redundant undeclared identifier errors |
| 4990 | | return irb->codegen->invalid_instruction; |
| 6024 | return irb->codegen->invalid_inst_src; |
| 4991 | 6025 | } |
| 4992 | 6026 | |
| 4993 | 6027 | return ir_build_undeclared_identifier(irb, scope, node, variable_name); |
| 4994 | 6028 | } |
| 4995 | 6029 | |
| 4996 | | static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 6030 | static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 4997 | 6031 | ResultLoc *result_loc) |
| 4998 | 6032 | { |
| 4999 | 6033 | assert(node->type == NodeTypeArrayAccessExpr); |
| 5000 | 6034 | |
| 5001 | 6035 | 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) |
| 6036 | IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr); |
| 6037 | if (array_ref_instruction == irb->codegen->invalid_inst_src) |
| 5004 | 6038 | return array_ref_instruction; |
| 5005 | 6039 | |
| 5006 | 6040 | 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) |
| 6041 | IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope); |
| 6042 | if (subscript_instruction == irb->codegen->invalid_inst_src) |
| 5009 | 6043 | return subscript_instruction; |
| 5010 | 6044 | |
| 5011 | | IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, |
| 6045 | IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, |
| 5012 | 6046 | subscript_instruction, true, PtrLenSingle, nullptr); |
| 5013 | 6047 | if (lval == LValPtr) |
| 5014 | 6048 | return ptr_instruction; |
| 5015 | 6049 | |
| 5016 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 6050 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 5017 | 6051 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 5018 | 6052 | } |
| 5019 | 6053 | |
| 5020 | | static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 6054 | static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5021 | 6055 | assert(node->type == NodeTypeFieldAccessExpr); |
| 5022 | 6056 | |
| 5023 | 6057 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; |
| 5024 | 6058 | Buf *field_name = node->data.field_access_expr.field_name; |
| 5025 | 6059 | |
| 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) |
| 6060 | IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr); |
| 6061 | if (container_ref_instruction == irb->codegen->invalid_inst_src) |
| 5028 | 6062 | return container_ref_instruction; |
| 5029 | 6063 | |
| 5030 | 6064 | return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false); |
| 5031 | 6065 | } |
| 5032 | 6066 | |
| 5033 | | static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) { |
| 6067 | static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) { |
| 5034 | 6068 | assert(node->type == NodeTypeFnCallExpr); |
| 5035 | 6069 | |
| 5036 | 6070 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -5039,26 +6073,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode * |
| 5039 | 6073 | AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3); |
| 5040 | 6074 | |
| 5041 | 6075 | |
| 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; |
| 6076 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); |
| 6077 | if (type_value == irb->codegen->invalid_inst_src) |
| 6078 | return irb->codegen->invalid_inst_src; |
| 5045 | 6079 | |
| 5046 | | IrInstruction *op1 = ir_gen_node(irb, op1_node, scope); |
| 5047 | | if (op1 == irb->codegen->invalid_instruction) |
| 5048 | | return irb->codegen->invalid_instruction; |
| 6080 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); |
| 6081 | if (op1 == irb->codegen->invalid_inst_src) |
| 6082 | return irb->codegen->invalid_inst_src; |
| 5049 | 6083 | |
| 5050 | | IrInstruction *op2 = ir_gen_node(irb, op2_node, scope); |
| 5051 | | if (op2 == irb->codegen->invalid_instruction) |
| 5052 | | return irb->codegen->invalid_instruction; |
| 6084 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); |
| 6085 | if (op2 == irb->codegen->invalid_inst_src) |
| 6086 | return irb->codegen->invalid_inst_src; |
| 5053 | 6087 | |
| 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; |
| 6088 | IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope); |
| 6089 | if (result_ptr == irb->codegen->invalid_inst_src) |
| 6090 | return irb->codegen->invalid_inst_src; |
| 5057 | 6091 | |
| 5058 | | return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr); |
| 6092 | return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr); |
| 5059 | 6093 | } |
| 5060 | 6094 | |
| 5061 | | static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 6095 | static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 5062 | 6096 | assert(node->type == NodeTypeFnCallExpr); |
| 5063 | 6097 | |
| 5064 | 6098 | AstNode *type_node = node->data.fn_call_expr.params.at(0); |
| ... | ... | @@ -5066,26 +6100,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node |
| 5066 | 6100 | AstNode *op2_node = node->data.fn_call_expr.params.at(2); |
| 5067 | 6101 | AstNode *op3_node = node->data.fn_call_expr.params.at(3); |
| 5068 | 6102 | |
| 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; |
| 6103 | IrInstSrc *type_value = ir_gen_node(irb, type_node, scope); |
| 6104 | if (type_value == irb->codegen->invalid_inst_src) |
| 6105 | return irb->codegen->invalid_inst_src; |
| 5072 | 6106 | |
| 5073 | | IrInstruction *op1 = ir_gen_node(irb, op1_node, scope); |
| 5074 | | if (op1 == irb->codegen->invalid_instruction) |
| 5075 | | return irb->codegen->invalid_instruction; |
| 6107 | IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope); |
| 6108 | if (op1 == irb->codegen->invalid_inst_src) |
| 6109 | return irb->codegen->invalid_inst_src; |
| 5076 | 6110 | |
| 5077 | | IrInstruction *op2 = ir_gen_node(irb, op2_node, scope); |
| 5078 | | if (op2 == irb->codegen->invalid_instruction) |
| 5079 | | return irb->codegen->invalid_instruction; |
| 6111 | IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope); |
| 6112 | if (op2 == irb->codegen->invalid_inst_src) |
| 6113 | return irb->codegen->invalid_inst_src; |
| 5080 | 6114 | |
| 5081 | | IrInstruction *op3 = ir_gen_node(irb, op3_node, scope); |
| 5082 | | if (op3 == irb->codegen->invalid_instruction) |
| 5083 | | return irb->codegen->invalid_instruction; |
| 6115 | IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope); |
| 6116 | if (op3 == irb->codegen->invalid_inst_src) |
| 6117 | return irb->codegen->invalid_inst_src; |
| 5084 | 6118 | |
| 5085 | | return ir_build_mul_add(irb, scope, node, type_value, op1, op2, op3); |
| 6119 | return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3); |
| 5086 | 6120 | } |
| 5087 | 6121 | |
| 5088 | | static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) { |
| 6122 | static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) { |
| 5089 | 6123 | for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) { |
| 5090 | 6124 | if (it_scope->id == ScopeIdDecls) { |
| 5091 | 6125 | ScopeDecls *decls_scope = (ScopeDecls *)it_scope; |
| ... | ... | @@ -5100,7 +6134,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no |
| 5100 | 6134 | zig_unreachable(); |
| 5101 | 6135 | } |
| 5102 | 6136 | |
| 5103 | | static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *await_node, AstNode *call_node, |
| 6137 | static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node, |
| 5104 | 6138 | LVal lval, ResultLoc *result_loc) |
| 5105 | 6139 | { |
| 5106 | 6140 | size_t arg_offset = 3; |
| ... | ... | @@ -5108,71 +6142,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a |
| 5108 | 6142 | add_node_error(irb->codegen, call_node, |
| 5109 | 6143 | buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, |
| 5110 | 6144 | arg_offset, call_node->data.fn_call_expr.params.length)); |
| 5111 | | return irb->codegen->invalid_instruction; |
| 6145 | return irb->codegen->invalid_inst_src; |
| 5112 | 6146 | } |
| 5113 | 6147 | |
| 5114 | 6148 | 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) |
| 6149 | IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope); |
| 6150 | if (bytes == irb->codegen->invalid_inst_src) |
| 5117 | 6151 | return bytes; |
| 5118 | 6152 | |
| 5119 | 6153 | 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) |
| 6154 | IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope); |
| 6155 | if (ret_ptr == irb->codegen->invalid_inst_src) |
| 5122 | 6156 | return ret_ptr; |
| 5123 | 6157 | |
| 5124 | 6158 | 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) |
| 6159 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6160 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 5127 | 6161 | return fn_ref; |
| 5128 | 6162 | |
| 5129 | 6163 | size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset; |
| 5130 | | IrInstruction **args = allocate<IrInstruction*>(arg_count); |
| 6164 | IrInstSrc **args = allocate<IrInstSrc*>(arg_count); |
| 5131 | 6165 | for (size_t i = 0; i < arg_count; i += 1) { |
| 5132 | 6166 | 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) |
| 6167 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); |
| 6168 | if (arg == irb->codegen->invalid_inst_src) |
| 5135 | 6169 | return arg; |
| 5136 | 6170 | args[i] = arg; |
| 5137 | 6171 | } |
| 5138 | 6172 | |
| 5139 | 6173 | CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone; |
| 5140 | 6174 | bool is_async_call_builtin = true; |
| 5141 | | IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, |
| 6175 | IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, |
| 5142 | 6176 | ret_ptr, modifier, is_async_call_builtin, bytes, result_loc); |
| 5143 | 6177 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 5144 | 6178 | } |
| 5145 | 6179 | |
| 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, |
| 6180 | static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 6181 | AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options, |
| 5148 | 6182 | AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc) |
| 5149 | 6183 | { |
| 5150 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 5151 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 6184 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6185 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 5152 | 6186 | return fn_ref; |
| 5153 | 6187 | |
| 5154 | | IrInstruction *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref); |
| 6188 | IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref); |
| 5155 | 6189 | |
| 5156 | | IrInstruction **args = allocate<IrInstruction*>(args_len); |
| 6190 | IrInstSrc **args = allocate<IrInstSrc*>(args_len); |
| 5157 | 6191 | for (size_t i = 0; i < args_len; i += 1) { |
| 5158 | 6192 | AstNode *arg_node = args_ptr[i]; |
| 5159 | 6193 | |
| 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); |
| 6194 | IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i); |
| 6195 | IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true); |
| 5162 | 6196 | ResultLoc *no_result = no_result_loc(); |
| 5163 | 6197 | ir_build_reset_result(irb, scope, source_node, no_result); |
| 5164 | 6198 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result); |
| 5165 | 6199 | |
| 5166 | | IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base); |
| 5167 | | if (arg == irb->codegen->invalid_instruction) |
| 6200 | IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base); |
| 6201 | if (arg == irb->codegen->invalid_inst_src) |
| 5168 | 6202 | return arg; |
| 5169 | 6203 | |
| 5170 | 6204 | args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast); |
| 5171 | 6205 | } |
| 5172 | 6206 | |
| 5173 | | IrInstruction *fn_call; |
| 6207 | IrInstSrc *fn_call; |
| 5174 | 6208 | if (options != nullptr) { |
| 5175 | | fn_call = ir_build_call_src_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc); |
| 6209 | fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc); |
| 5176 | 6210 | } else { |
| 5177 | 6211 | fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr, |
| 5178 | 6212 | modifier, false, nullptr, result_loc); |
| ... | ... | @@ -5180,7 +6214,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast |
| 5180 | 6214 | return ir_lval_wrap(irb, scope, fn_call, lval, result_loc); |
| 5181 | 6215 | } |
| 5182 | 6216 | |
| 5183 | | static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 6217 | static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 5184 | 6218 | ResultLoc *result_loc) |
| 5185 | 6219 | { |
| 5186 | 6220 | assert(node->type == NodeTypeFnCallExpr); |
| ... | ... | @@ -5192,7 +6226,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5192 | 6226 | if (!entry) { |
| 5193 | 6227 | add_node_error(irb->codegen, node, |
| 5194 | 6228 | buf_sprintf("invalid builtin function: '%s'", buf_ptr(name))); |
| 5195 | | return irb->codegen->invalid_instruction; |
| 6229 | return irb->codegen->invalid_inst_src; |
| 5196 | 6230 | } |
| 5197 | 6231 | |
| 5198 | 6232 | BuiltinFnEntry *builtin_fn = entry->value; |
| ... | ... | @@ -5202,7 +6236,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5202 | 6236 | add_node_error(irb->codegen, node, |
| 5203 | 6237 | buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize, |
| 5204 | 6238 | builtin_fn->param_count, actual_param_count)); |
| 5205 | | return irb->codegen->invalid_instruction; |
| 6239 | return irb->codegen->invalid_inst_src; |
| 5206 | 6240 | } |
| 5207 | 6241 | |
| 5208 | 6242 | switch (builtin_fn->id) { |
| ... | ... | @@ -5213,197 +6247,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5213 | 6247 | Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope); |
| 5214 | 6248 | |
| 5215 | 6249 | 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) |
| 6250 | IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope); |
| 6251 | if (arg == irb->codegen->invalid_inst_src) |
| 5218 | 6252 | return arg; |
| 5219 | 6253 | |
| 5220 | | IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg); |
| 6254 | IrInstSrc *type_of = ir_build_typeof(irb, scope, node, arg); |
| 5221 | 6255 | return ir_lval_wrap(irb, scope, type_of, lval, result_loc); |
| 5222 | 6256 | } |
| 5223 | 6257 | case BuiltinFnIdSetCold: |
| 5224 | 6258 | { |
| 5225 | 6259 | 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) |
| 6260 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6261 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5228 | 6262 | return arg0_value; |
| 5229 | 6263 | |
| 5230 | | IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); |
| 6264 | IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value); |
| 5231 | 6265 | return ir_lval_wrap(irb, scope, set_cold, lval, result_loc); |
| 5232 | 6266 | } |
| 5233 | 6267 | case BuiltinFnIdSetRuntimeSafety: |
| 5234 | 6268 | { |
| 5235 | 6269 | 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) |
| 6270 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6271 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5238 | 6272 | return arg0_value; |
| 5239 | 6273 | |
| 5240 | | IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); |
| 6274 | IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value); |
| 5241 | 6275 | return ir_lval_wrap(irb, scope, set_safety, lval, result_loc); |
| 5242 | 6276 | } |
| 5243 | 6277 | case BuiltinFnIdSetFloatMode: |
| 5244 | 6278 | { |
| 5245 | 6279 | 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) |
| 6280 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6281 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5248 | 6282 | return arg0_value; |
| 5249 | 6283 | |
| 5250 | | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 6284 | IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 5251 | 6285 | return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc); |
| 5252 | 6286 | } |
| 5253 | 6287 | case BuiltinFnIdSizeof: |
| 5254 | 6288 | case BuiltinFnIdBitSizeof: |
| 5255 | 6289 | { |
| 5256 | 6290 | 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) |
| 6291 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6292 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5259 | 6293 | return arg0_value; |
| 5260 | 6294 | |
| 5261 | | IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); |
| 6295 | IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof); |
| 5262 | 6296 | return ir_lval_wrap(irb, scope, size_of, lval, result_loc); |
| 5263 | 6297 | } |
| 5264 | 6298 | case BuiltinFnIdImport: |
| 5265 | 6299 | { |
| 5266 | 6300 | 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) |
| 6301 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6302 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5269 | 6303 | return arg0_value; |
| 5270 | 6304 | |
| 5271 | | IrInstruction *import = ir_build_import(irb, scope, node, arg0_value); |
| 6305 | IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value); |
| 5272 | 6306 | return ir_lval_wrap(irb, scope, import, lval, result_loc); |
| 5273 | 6307 | } |
| 5274 | 6308 | case BuiltinFnIdCImport: |
| 5275 | 6309 | { |
| 5276 | | IrInstruction *c_import = ir_build_c_import(irb, scope, node); |
| 6310 | IrInstSrc *c_import = ir_build_c_import(irb, scope, node); |
| 5277 | 6311 | return ir_lval_wrap(irb, scope, c_import, lval, result_loc); |
| 5278 | 6312 | } |
| 5279 | 6313 | case BuiltinFnIdCInclude: |
| 5280 | 6314 | { |
| 5281 | 6315 | 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) |
| 6316 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6317 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5284 | 6318 | return arg0_value; |
| 5285 | 6319 | |
| 5286 | 6320 | if (!exec_c_import_buf(irb->exec)) { |
| 5287 | 6321 | add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block")); |
| 5288 | | return irb->codegen->invalid_instruction; |
| 6322 | return irb->codegen->invalid_inst_src; |
| 5289 | 6323 | } |
| 5290 | 6324 | |
| 5291 | | IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value); |
| 6325 | IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value); |
| 5292 | 6326 | return ir_lval_wrap(irb, scope, c_include, lval, result_loc); |
| 5293 | 6327 | } |
| 5294 | 6328 | case BuiltinFnIdCDefine: |
| 5295 | 6329 | { |
| 5296 | 6330 | 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) |
| 6331 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6332 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5299 | 6333 | return arg0_value; |
| 5300 | 6334 | |
| 5301 | 6335 | 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) |
| 6336 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6337 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5304 | 6338 | return arg1_value; |
| 5305 | 6339 | |
| 5306 | 6340 | if (!exec_c_import_buf(irb->exec)) { |
| 5307 | 6341 | add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block")); |
| 5308 | | return irb->codegen->invalid_instruction; |
| 6342 | return irb->codegen->invalid_inst_src; |
| 5309 | 6343 | } |
| 5310 | 6344 | |
| 5311 | | IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); |
| 6345 | IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value); |
| 5312 | 6346 | return ir_lval_wrap(irb, scope, c_define, lval, result_loc); |
| 5313 | 6347 | } |
| 5314 | 6348 | case BuiltinFnIdCUndef: |
| 5315 | 6349 | { |
| 5316 | 6350 | 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) |
| 6351 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6352 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5319 | 6353 | return arg0_value; |
| 5320 | 6354 | |
| 5321 | 6355 | if (!exec_c_import_buf(irb->exec)) { |
| 5322 | 6356 | add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block")); |
| 5323 | | return irb->codegen->invalid_instruction; |
| 6357 | return irb->codegen->invalid_inst_src; |
| 5324 | 6358 | } |
| 5325 | 6359 | |
| 5326 | | IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 6360 | IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value); |
| 5327 | 6361 | return ir_lval_wrap(irb, scope, c_undef, lval, result_loc); |
| 5328 | 6362 | } |
| 5329 | 6363 | case BuiltinFnIdCompileErr: |
| 5330 | 6364 | { |
| 5331 | 6365 | 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) |
| 6366 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6367 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5334 | 6368 | return arg0_value; |
| 5335 | 6369 | |
| 5336 | | IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); |
| 6370 | IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value); |
| 5337 | 6371 | return ir_lval_wrap(irb, scope, compile_err, lval, result_loc); |
| 5338 | 6372 | } |
| 5339 | 6373 | case BuiltinFnIdCompileLog: |
| 5340 | 6374 | { |
| 5341 | | IrInstruction **args = allocate<IrInstruction*>(actual_param_count); |
| 6375 | IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count); |
| 5342 | 6376 | |
| 5343 | 6377 | for (size_t i = 0; i < actual_param_count; i += 1) { |
| 5344 | 6378 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); |
| 5345 | 6379 | args[i] = ir_gen_node(irb, arg_node, scope); |
| 5346 | | if (args[i] == irb->codegen->invalid_instruction) |
| 5347 | | return irb->codegen->invalid_instruction; |
| 6380 | if (args[i] == irb->codegen->invalid_inst_src) |
| 6381 | return irb->codegen->invalid_inst_src; |
| 5348 | 6382 | } |
| 5349 | 6383 | |
| 5350 | | IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); |
| 6384 | IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args); |
| 5351 | 6385 | return ir_lval_wrap(irb, scope, compile_log, lval, result_loc); |
| 5352 | 6386 | } |
| 5353 | 6387 | case BuiltinFnIdErrName: |
| 5354 | 6388 | { |
| 5355 | 6389 | 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) |
| 6390 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6391 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5358 | 6392 | return arg0_value; |
| 5359 | 6393 | |
| 5360 | | IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value); |
| 6394 | IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value); |
| 5361 | 6395 | return ir_lval_wrap(irb, scope, err_name, lval, result_loc); |
| 5362 | 6396 | } |
| 5363 | 6397 | case BuiltinFnIdEmbedFile: |
| 5364 | 6398 | { |
| 5365 | 6399 | 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) |
| 6400 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6401 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5368 | 6402 | return arg0_value; |
| 5369 | 6403 | |
| 5370 | | IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); |
| 6404 | IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value); |
| 5371 | 6405 | return ir_lval_wrap(irb, scope, embed_file, lval, result_loc); |
| 5372 | 6406 | } |
| 5373 | 6407 | case BuiltinFnIdCmpxchgWeak: |
| 5374 | 6408 | case BuiltinFnIdCmpxchgStrong: |
| 5375 | 6409 | { |
| 5376 | 6410 | 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) |
| 6411 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6412 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5379 | 6413 | return arg0_value; |
| 5380 | 6414 | |
| 5381 | 6415 | 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) |
| 6416 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6417 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5384 | 6418 | return arg1_value; |
| 5385 | 6419 | |
| 5386 | 6420 | 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) |
| 6421 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6422 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5389 | 6423 | return arg2_value; |
| 5390 | 6424 | |
| 5391 | 6425 | 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) |
| 6426 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6427 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 5394 | 6428 | return arg3_value; |
| 5395 | 6429 | |
| 5396 | 6430 | 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) |
| 6431 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 6432 | if (arg4_value == irb->codegen->invalid_inst_src) |
| 5399 | 6433 | return arg4_value; |
| 5400 | 6434 | |
| 5401 | 6435 | 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) |
| 6436 | IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope); |
| 6437 | if (arg5_value == irb->codegen->invalid_inst_src) |
| 5404 | 6438 | return arg5_value; |
| 5405 | 6439 | |
| 5406 | | IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, |
| 6440 | IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value, |
| 5407 | 6441 | arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak), |
| 5408 | 6442 | result_loc); |
| 5409 | 6443 | return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc); |
| ... | ... | @@ -5411,86 +6445,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5411 | 6445 | case BuiltinFnIdFence: |
| 5412 | 6446 | { |
| 5413 | 6447 | 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) |
| 6448 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6449 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5416 | 6450 | return arg0_value; |
| 5417 | 6451 | |
| 5418 | | IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered); |
| 6452 | IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value); |
| 5419 | 6453 | return ir_lval_wrap(irb, scope, fence, lval, result_loc); |
| 5420 | 6454 | } |
| 5421 | 6455 | case BuiltinFnIdDivExact: |
| 5422 | 6456 | { |
| 5423 | 6457 | 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) |
| 6458 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6459 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5426 | 6460 | return arg0_value; |
| 5427 | 6461 | |
| 5428 | 6462 | 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) |
| 6463 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6464 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5431 | 6465 | return arg1_value; |
| 5432 | 6466 | |
| 5433 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 6467 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true); |
| 5434 | 6468 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5435 | 6469 | } |
| 5436 | 6470 | case BuiltinFnIdDivTrunc: |
| 5437 | 6471 | { |
| 5438 | 6472 | 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) |
| 6473 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6474 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5441 | 6475 | return arg0_value; |
| 5442 | 6476 | |
| 5443 | 6477 | 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) |
| 6478 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6479 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5446 | 6480 | return arg1_value; |
| 5447 | 6481 | |
| 5448 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 6482 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true); |
| 5449 | 6483 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5450 | 6484 | } |
| 5451 | 6485 | case BuiltinFnIdDivFloor: |
| 5452 | 6486 | { |
| 5453 | 6487 | 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) |
| 6488 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6489 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5456 | 6490 | return arg0_value; |
| 5457 | 6491 | |
| 5458 | 6492 | 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) |
| 6493 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6494 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5461 | 6495 | return arg1_value; |
| 5462 | 6496 | |
| 5463 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 6497 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true); |
| 5464 | 6498 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5465 | 6499 | } |
| 5466 | 6500 | case BuiltinFnIdRem: |
| 5467 | 6501 | { |
| 5468 | 6502 | 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) |
| 6503 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6504 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5471 | 6505 | return arg0_value; |
| 5472 | 6506 | |
| 5473 | 6507 | 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) |
| 6508 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6509 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5476 | 6510 | return arg1_value; |
| 5477 | 6511 | |
| 5478 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 6512 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true); |
| 5479 | 6513 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5480 | 6514 | } |
| 5481 | 6515 | case BuiltinFnIdMod: |
| 5482 | 6516 | { |
| 5483 | 6517 | 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) |
| 6518 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6519 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5486 | 6520 | return arg0_value; |
| 5487 | 6521 | |
| 5488 | 6522 | 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) |
| 6523 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6524 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5491 | 6525 | return arg1_value; |
| 5492 | 6526 | |
| 5493 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 6527 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true); |
| 5494 | 6528 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 5495 | 6529 | } |
| 5496 | 6530 | case BuiltinFnIdSqrt: |
| ... | ... | @@ -5509,406 +6543,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5509 | 6543 | case BuiltinFnIdRound: |
| 5510 | 6544 | { |
| 5511 | 6545 | 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) |
| 6546 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6547 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5514 | 6548 | return arg0_value; |
| 5515 | 6549 | |
| 5516 | | IrInstruction *inst = ir_build_float_op(irb, scope, node, arg0_value, builtin_fn->id); |
| 6550 | IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id); |
| 5517 | 6551 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 5518 | 6552 | } |
| 5519 | 6553 | case BuiltinFnIdTruncate: |
| 5520 | 6554 | { |
| 5521 | 6555 | 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) |
| 6556 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6557 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5524 | 6558 | return arg0_value; |
| 5525 | 6559 | |
| 5526 | 6560 | 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) |
| 6561 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6562 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5529 | 6563 | return arg1_value; |
| 5530 | 6564 | |
| 5531 | | IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); |
| 6565 | IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value); |
| 5532 | 6566 | return ir_lval_wrap(irb, scope, truncate, lval, result_loc); |
| 5533 | 6567 | } |
| 5534 | 6568 | case BuiltinFnIdIntCast: |
| 5535 | 6569 | { |
| 5536 | 6570 | 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) |
| 6571 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6572 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5539 | 6573 | return arg0_value; |
| 5540 | 6574 | |
| 5541 | 6575 | 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) |
| 6576 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6577 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5544 | 6578 | return arg1_value; |
| 5545 | 6579 | |
| 5546 | | IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); |
| 6580 | IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value); |
| 5547 | 6581 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5548 | 6582 | } |
| 5549 | 6583 | case BuiltinFnIdFloatCast: |
| 5550 | 6584 | { |
| 5551 | 6585 | 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) |
| 6586 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6587 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5554 | 6588 | return arg0_value; |
| 5555 | 6589 | |
| 5556 | 6590 | 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) |
| 6591 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6592 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5559 | 6593 | return arg1_value; |
| 5560 | 6594 | |
| 5561 | | IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); |
| 6595 | IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value); |
| 5562 | 6596 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5563 | 6597 | } |
| 5564 | 6598 | case BuiltinFnIdErrSetCast: |
| 5565 | 6599 | { |
| 5566 | 6600 | 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) |
| 6601 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6602 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5569 | 6603 | return arg0_value; |
| 5570 | 6604 | |
| 5571 | 6605 | 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) |
| 6606 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6607 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5574 | 6608 | return arg1_value; |
| 5575 | 6609 | |
| 5576 | | IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); |
| 6610 | IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value); |
| 5577 | 6611 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5578 | 6612 | } |
| 5579 | 6613 | case BuiltinFnIdFromBytes: |
| 5580 | 6614 | { |
| 5581 | 6615 | 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) |
| 6616 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6617 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5584 | 6618 | return arg0_value; |
| 5585 | 6619 | |
| 5586 | 6620 | 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) |
| 6621 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6622 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5589 | 6623 | return arg1_value; |
| 5590 | 6624 | |
| 5591 | | IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc); |
| 6625 | IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc); |
| 5592 | 6626 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5593 | 6627 | } |
| 5594 | 6628 | case BuiltinFnIdToBytes: |
| 5595 | 6629 | { |
| 5596 | 6630 | 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) |
| 6631 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6632 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5599 | 6633 | return arg0_value; |
| 5600 | 6634 | |
| 5601 | | IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc); |
| 6635 | IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc); |
| 5602 | 6636 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5603 | 6637 | } |
| 5604 | 6638 | case BuiltinFnIdIntToFloat: |
| 5605 | 6639 | { |
| 5606 | 6640 | 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) |
| 6641 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6642 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5609 | 6643 | return arg0_value; |
| 5610 | 6644 | |
| 5611 | 6645 | 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) |
| 6646 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6647 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5614 | 6648 | return arg1_value; |
| 5615 | 6649 | |
| 5616 | | IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); |
| 6650 | IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value); |
| 5617 | 6651 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5618 | 6652 | } |
| 5619 | 6653 | case BuiltinFnIdFloatToInt: |
| 5620 | 6654 | { |
| 5621 | 6655 | 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) |
| 6656 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6657 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5624 | 6658 | return arg0_value; |
| 5625 | 6659 | |
| 5626 | 6660 | 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) |
| 6661 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6662 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5629 | 6663 | return arg1_value; |
| 5630 | 6664 | |
| 5631 | | IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); |
| 6665 | IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value); |
| 5632 | 6666 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5633 | 6667 | } |
| 5634 | 6668 | case BuiltinFnIdErrToInt: |
| 5635 | 6669 | { |
| 5636 | 6670 | 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) |
| 6671 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6672 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5639 | 6673 | return arg0_value; |
| 5640 | 6674 | |
| 5641 | | IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value); |
| 6675 | IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value); |
| 5642 | 6676 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5643 | 6677 | } |
| 5644 | 6678 | case BuiltinFnIdIntToErr: |
| 5645 | 6679 | { |
| 5646 | 6680 | 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) |
| 6681 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6682 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5649 | 6683 | return arg0_value; |
| 5650 | 6684 | |
| 5651 | | IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value); |
| 6685 | IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value); |
| 5652 | 6686 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5653 | 6687 | } |
| 5654 | 6688 | case BuiltinFnIdBoolToInt: |
| 5655 | 6689 | { |
| 5656 | 6690 | 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) |
| 6691 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6692 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5659 | 6693 | return arg0_value; |
| 5660 | 6694 | |
| 5661 | | IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value); |
| 6695 | IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value); |
| 5662 | 6696 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 5663 | 6697 | } |
| 5664 | 6698 | case BuiltinFnIdIntType: |
| 5665 | 6699 | { |
| 5666 | 6700 | 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) |
| 6701 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6702 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5669 | 6703 | return arg0_value; |
| 5670 | 6704 | |
| 5671 | 6705 | 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) |
| 6706 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6707 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5674 | 6708 | return arg1_value; |
| 5675 | 6709 | |
| 5676 | | IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); |
| 6710 | IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value); |
| 5677 | 6711 | return ir_lval_wrap(irb, scope, int_type, lval, result_loc); |
| 5678 | 6712 | } |
| 5679 | 6713 | case BuiltinFnIdVectorType: |
| 5680 | 6714 | { |
| 5681 | 6715 | 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) |
| 6716 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6717 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5684 | 6718 | return arg0_value; |
| 5685 | 6719 | |
| 5686 | 6720 | 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) |
| 6721 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6722 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5689 | 6723 | return arg1_value; |
| 5690 | 6724 | |
| 5691 | | IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); |
| 6725 | IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value); |
| 5692 | 6726 | return ir_lval_wrap(irb, scope, vector_type, lval, result_loc); |
| 5693 | 6727 | } |
| 5694 | 6728 | case BuiltinFnIdShuffle: |
| 5695 | 6729 | { |
| 5696 | 6730 | 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) |
| 6731 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6732 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5699 | 6733 | return arg0_value; |
| 5700 | 6734 | |
| 5701 | 6735 | 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) |
| 6736 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6737 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5704 | 6738 | return arg1_value; |
| 5705 | 6739 | |
| 5706 | 6740 | 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) |
| 6741 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6742 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5709 | 6743 | return arg2_value; |
| 5710 | 6744 | |
| 5711 | 6745 | 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) |
| 6746 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 6747 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 5714 | 6748 | return arg3_value; |
| 5715 | 6749 | |
| 5716 | | IrInstruction *shuffle_vector = ir_build_shuffle_vector(irb, scope, node, |
| 6750 | IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node, |
| 5717 | 6751 | arg0_value, arg1_value, arg2_value, arg3_value); |
| 5718 | 6752 | return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc); |
| 5719 | 6753 | } |
| 5720 | 6754 | case BuiltinFnIdSplat: |
| 5721 | 6755 | { |
| 5722 | 6756 | 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) |
| 6757 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6758 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5725 | 6759 | return arg0_value; |
| 5726 | 6760 | |
| 5727 | 6761 | 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) |
| 6762 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6763 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5730 | 6764 | return arg1_value; |
| 5731 | 6765 | |
| 5732 | | IrInstruction *splat = ir_build_splat_src(irb, scope, node, |
| 6766 | IrInstSrc *splat = ir_build_splat_src(irb, scope, node, |
| 5733 | 6767 | arg0_value, arg1_value); |
| 5734 | 6768 | return ir_lval_wrap(irb, scope, splat, lval, result_loc); |
| 5735 | 6769 | } |
| 5736 | 6770 | case BuiltinFnIdMemcpy: |
| 5737 | 6771 | { |
| 5738 | 6772 | 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) |
| 6773 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6774 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5741 | 6775 | return arg0_value; |
| 5742 | 6776 | |
| 5743 | 6777 | 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) |
| 6778 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6779 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5746 | 6780 | return arg1_value; |
| 5747 | 6781 | |
| 5748 | 6782 | 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) |
| 6783 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6784 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5751 | 6785 | return arg2_value; |
| 5752 | 6786 | |
| 5753 | | IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6787 | IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5754 | 6788 | return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc); |
| 5755 | 6789 | } |
| 5756 | 6790 | case BuiltinFnIdMemset: |
| 5757 | 6791 | { |
| 5758 | 6792 | 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) |
| 6793 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6794 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5761 | 6795 | return arg0_value; |
| 5762 | 6796 | |
| 5763 | 6797 | 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) |
| 6798 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6799 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5766 | 6800 | return arg1_value; |
| 5767 | 6801 | |
| 5768 | 6802 | 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) |
| 6803 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 6804 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 5771 | 6805 | return arg2_value; |
| 5772 | 6806 | |
| 5773 | | IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6807 | IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 5774 | 6808 | return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc); |
| 5775 | 6809 | } |
| 5776 | 6810 | case BuiltinFnIdMemberCount: |
| 5777 | 6811 | { |
| 5778 | 6812 | 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) |
| 6813 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6814 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5781 | 6815 | return arg0_value; |
| 5782 | 6816 | |
| 5783 | | IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value); |
| 6817 | IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value); |
| 5784 | 6818 | return ir_lval_wrap(irb, scope, member_count, lval, result_loc); |
| 5785 | 6819 | } |
| 5786 | 6820 | case BuiltinFnIdMemberType: |
| 5787 | 6821 | { |
| 5788 | 6822 | 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) |
| 6823 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6824 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5791 | 6825 | return arg0_value; |
| 5792 | 6826 | |
| 5793 | 6827 | 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) |
| 6828 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6829 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5796 | 6830 | return arg1_value; |
| 5797 | 6831 | |
| 5798 | 6832 | |
| 5799 | | IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); |
| 6833 | IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value); |
| 5800 | 6834 | return ir_lval_wrap(irb, scope, member_type, lval, result_loc); |
| 5801 | 6835 | } |
| 5802 | 6836 | case BuiltinFnIdMemberName: |
| 5803 | 6837 | { |
| 5804 | 6838 | 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) |
| 6839 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6840 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5807 | 6841 | return arg0_value; |
| 5808 | 6842 | |
| 5809 | 6843 | 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) |
| 6844 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6845 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5812 | 6846 | return arg1_value; |
| 5813 | 6847 | |
| 5814 | 6848 | |
| 5815 | | IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); |
| 6849 | IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value); |
| 5816 | 6850 | return ir_lval_wrap(irb, scope, member_name, lval, result_loc); |
| 5817 | 6851 | } |
| 5818 | 6852 | case BuiltinFnIdField: |
| 5819 | 6853 | { |
| 5820 | 6854 | 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) |
| 6855 | IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr); |
| 6856 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5823 | 6857 | return arg0_value; |
| 5824 | 6858 | |
| 5825 | 6859 | 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) |
| 6860 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6861 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5828 | 6862 | return arg1_value; |
| 5829 | 6863 | |
| 5830 | | IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, |
| 6864 | IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node, |
| 5831 | 6865 | arg0_value, arg1_value, false); |
| 5832 | 6866 | |
| 5833 | 6867 | if (lval == LValPtr) |
| 5834 | 6868 | return ptr_instruction; |
| 5835 | 6869 | |
| 5836 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 6870 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 5837 | 6871 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 5838 | 6872 | } |
| 5839 | 6873 | case BuiltinFnIdHasField: |
| 5840 | 6874 | { |
| 5841 | 6875 | 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) |
| 6876 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6877 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5844 | 6878 | return arg0_value; |
| 5845 | 6879 | |
| 5846 | 6880 | 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) |
| 6881 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6882 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5849 | 6883 | return arg1_value; |
| 5850 | 6884 | |
| 5851 | | IrInstruction *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value); |
| 6885 | IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value); |
| 5852 | 6886 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); |
| 5853 | 6887 | } |
| 5854 | 6888 | case BuiltinFnIdTypeInfo: |
| 5855 | 6889 | { |
| 5856 | 6890 | 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) |
| 6891 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6892 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5859 | 6893 | return arg0_value; |
| 5860 | 6894 | |
| 5861 | | IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value); |
| 6895 | IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value); |
| 5862 | 6896 | return ir_lval_wrap(irb, scope, type_info, lval, result_loc); |
| 5863 | 6897 | } |
| 5864 | 6898 | case BuiltinFnIdType: |
| 5865 | 6899 | { |
| 5866 | 6900 | 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) |
| 6901 | IrInstSrc *arg = ir_gen_node(irb, arg_node, scope); |
| 6902 | if (arg == irb->codegen->invalid_inst_src) |
| 5869 | 6903 | return arg; |
| 5870 | 6904 | |
| 5871 | | IrInstruction *type = ir_build_type(irb, scope, node, arg); |
| 6905 | IrInstSrc *type = ir_build_type(irb, scope, node, arg); |
| 5872 | 6906 | return ir_lval_wrap(irb, scope, type, lval, result_loc); |
| 5873 | 6907 | } |
| 5874 | 6908 | case BuiltinFnIdBreakpoint: |
| 5875 | 6909 | return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc); |
| 5876 | 6910 | case BuiltinFnIdReturnAddress: |
| 5877 | | return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc); |
| 6911 | return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc); |
| 5878 | 6912 | case BuiltinFnIdFrameAddress: |
| 5879 | | return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc); |
| 6913 | return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc); |
| 5880 | 6914 | case BuiltinFnIdFrameHandle: |
| 5881 | 6915 | if (!irb->exec->fn_entry) { |
| 5882 | 6916 | add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition")); |
| 5883 | | return irb->codegen->invalid_instruction; |
| 6917 | return irb->codegen->invalid_inst_src; |
| 5884 | 6918 | } |
| 5885 | | return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc); |
| 6919 | return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc); |
| 5886 | 6920 | case BuiltinFnIdFrameType: { |
| 5887 | 6921 | 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) |
| 6922 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6923 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5890 | 6924 | return arg0_value; |
| 5891 | 6925 | |
| 5892 | | IrInstruction *frame_type = ir_build_frame_type(irb, scope, node, arg0_value); |
| 6926 | IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value); |
| 5893 | 6927 | return ir_lval_wrap(irb, scope, frame_type, lval, result_loc); |
| 5894 | 6928 | } |
| 5895 | 6929 | case BuiltinFnIdFrameSize: { |
| 5896 | 6930 | 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) |
| 6931 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6932 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5899 | 6933 | return arg0_value; |
| 5900 | 6934 | |
| 5901 | | IrInstruction *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value); |
| 6935 | IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value); |
| 5902 | 6936 | return ir_lval_wrap(irb, scope, frame_size, lval, result_loc); |
| 5903 | 6937 | } |
| 5904 | 6938 | case BuiltinFnIdAlignOf: |
| 5905 | 6939 | { |
| 5906 | 6940 | 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) |
| 6941 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6942 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5909 | 6943 | return arg0_value; |
| 5910 | 6944 | |
| 5911 | | IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value); |
| 6945 | IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value); |
| 5912 | 6946 | return ir_lval_wrap(irb, scope, align_of, lval, result_loc); |
| 5913 | 6947 | } |
| 5914 | 6948 | case BuiltinFnIdAddWithOverflow: |
| ... | ... | @@ -5924,43 +6958,43 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5924 | 6958 | case BuiltinFnIdTypeName: |
| 5925 | 6959 | { |
| 5926 | 6960 | 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) |
| 6961 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6962 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5929 | 6963 | return arg0_value; |
| 5930 | 6964 | |
| 5931 | | IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value); |
| 6965 | IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value); |
| 5932 | 6966 | return ir_lval_wrap(irb, scope, type_name, lval, result_loc); |
| 5933 | 6967 | } |
| 5934 | 6968 | case BuiltinFnIdPanic: |
| 5935 | 6969 | { |
| 5936 | 6970 | 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) |
| 6971 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6972 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5939 | 6973 | return arg0_value; |
| 5940 | 6974 | |
| 5941 | | IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value); |
| 6975 | IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value); |
| 5942 | 6976 | return ir_lval_wrap(irb, scope, panic, lval, result_loc); |
| 5943 | 6977 | } |
| 5944 | 6978 | case BuiltinFnIdPtrCast: |
| 5945 | 6979 | { |
| 5946 | 6980 | 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) |
| 6981 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 6982 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 5949 | 6983 | return arg0_value; |
| 5950 | 6984 | |
| 5951 | 6985 | 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) |
| 6986 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 6987 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5954 | 6988 | return arg1_value; |
| 5955 | 6989 | |
| 5956 | | IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); |
| 6990 | IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true); |
| 5957 | 6991 | return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc); |
| 5958 | 6992 | } |
| 5959 | 6993 | case BuiltinFnIdBitCast: |
| 5960 | 6994 | { |
| 5961 | 6995 | 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) |
| 6996 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 6997 | if (dest_type == irb->codegen->invalid_inst_src) |
| 5964 | 6998 | return dest_type; |
| 5965 | 6999 | |
| 5966 | 7000 | ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1); |
| ... | ... | @@ -5972,125 +7006,126 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 5972 | 7006 | ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base); |
| 5973 | 7007 | |
| 5974 | 7008 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5975 | | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 7009 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 5976 | 7010 | &result_loc_bit_cast->base); |
| 5977 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7011 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5978 | 7012 | return arg1_value; |
| 5979 | 7013 | |
| 5980 | | IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 7014 | IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast); |
| 5981 | 7015 | return ir_lval_wrap(irb, scope, bitcast, lval, result_loc); |
| 5982 | 7016 | } |
| 5983 | 7017 | case BuiltinFnIdAs: |
| 5984 | 7018 | { |
| 5985 | 7019 | 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) |
| 7020 | IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope); |
| 7021 | if (dest_type == irb->codegen->invalid_inst_src) |
| 5988 | 7022 | return dest_type; |
| 5989 | 7023 | |
| 5990 | 7024 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc); |
| 5991 | 7025 | |
| 5992 | 7026 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 5993 | | IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 7027 | IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone, |
| 5994 | 7028 | &result_loc_cast->base); |
| 5995 | | if (arg1_value == irb->codegen->invalid_instruction) |
| 7029 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 5996 | 7030 | return arg1_value; |
| 5997 | 7031 | |
| 5998 | | IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); |
| 7032 | IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast); |
| 5999 | 7033 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6000 | 7034 | } |
| 6001 | 7035 | case BuiltinFnIdIntToPtr: |
| 6002 | 7036 | { |
| 6003 | 7037 | 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) |
| 7038 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7039 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6006 | 7040 | return arg0_value; |
| 6007 | 7041 | |
| 6008 | 7042 | 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) |
| 7043 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7044 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6011 | 7045 | return arg1_value; |
| 6012 | 7046 | |
| 6013 | | IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value); |
| 7047 | IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value); |
| 6014 | 7048 | return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc); |
| 6015 | 7049 | } |
| 6016 | 7050 | case BuiltinFnIdPtrToInt: |
| 6017 | 7051 | { |
| 6018 | 7052 | 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) |
| 7053 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7054 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6021 | 7055 | return arg0_value; |
| 6022 | 7056 | |
| 6023 | | IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value); |
| 7057 | IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value); |
| 6024 | 7058 | return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc); |
| 6025 | 7059 | } |
| 6026 | 7060 | case BuiltinFnIdTagName: |
| 6027 | 7061 | { |
| 6028 | 7062 | 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) |
| 7063 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7064 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6031 | 7065 | return arg0_value; |
| 6032 | 7066 | |
| 6033 | | IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, arg0_value); |
| 7067 | IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value); |
| 6034 | 7068 | return ir_lval_wrap(irb, scope, tag_name, lval, result_loc); |
| 6035 | 7069 | } |
| 6036 | 7070 | case BuiltinFnIdTagType: |
| 6037 | 7071 | { |
| 6038 | 7072 | 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) |
| 7073 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7074 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6041 | 7075 | return arg0_value; |
| 6042 | 7076 | |
| 6043 | | IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); |
| 7077 | IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value); |
| 6044 | 7078 | return ir_lval_wrap(irb, scope, tag_type, lval, result_loc); |
| 6045 | 7079 | } |
| 6046 | 7080 | case BuiltinFnIdFieldParentPtr: |
| 6047 | 7081 | { |
| 6048 | 7082 | 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) |
| 7083 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7084 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6051 | 7085 | return arg0_value; |
| 6052 | 7086 | |
| 6053 | 7087 | 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) |
| 7088 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7089 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6056 | 7090 | return arg1_value; |
| 6057 | 7091 | |
| 6058 | 7092 | 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) |
| 7093 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7094 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6061 | 7095 | return arg2_value; |
| 6062 | 7096 | |
| 6063 | | IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr); |
| 7097 | IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node, |
| 7098 | arg0_value, arg1_value, arg2_value); |
| 6064 | 7099 | return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc); |
| 6065 | 7100 | } |
| 6066 | 7101 | case BuiltinFnIdByteOffsetOf: |
| 6067 | 7102 | { |
| 6068 | 7103 | 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) |
| 7104 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7105 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6071 | 7106 | return arg0_value; |
| 6072 | 7107 | |
| 6073 | 7108 | 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) |
| 7109 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7110 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6076 | 7111 | return arg1_value; |
| 6077 | 7112 | |
| 6078 | | IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 7113 | IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 6079 | 7114 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 6080 | 7115 | } |
| 6081 | 7116 | case BuiltinFnIdBitOffsetOf: |
| 6082 | 7117 | { |
| 6083 | 7118 | 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) |
| 7119 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7120 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6086 | 7121 | return arg0_value; |
| 6087 | 7122 | |
| 6088 | 7123 | 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) |
| 7124 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7125 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6091 | 7126 | return arg1_value; |
| 6092 | 7127 | |
| 6093 | | IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 7128 | IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value); |
| 6094 | 7129 | return ir_lval_wrap(irb, scope, offset_of, lval, result_loc); |
| 6095 | 7130 | } |
| 6096 | 7131 | case BuiltinFnIdNewStackCall: |
| ... | ... | @@ -6099,45 +7134,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6099 | 7134 | add_node_error(irb->codegen, node, |
| 6100 | 7135 | buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize, |
| 6101 | 7136 | node->data.fn_call_expr.params.length)); |
| 6102 | | return irb->codegen->invalid_instruction; |
| 7137 | return irb->codegen->invalid_inst_src; |
| 6103 | 7138 | } |
| 6104 | 7139 | |
| 6105 | 7140 | 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) |
| 7141 | IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope); |
| 7142 | if (new_stack == irb->codegen->invalid_inst_src) |
| 6108 | 7143 | return new_stack; |
| 6109 | 7144 | |
| 6110 | 7145 | 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) |
| 7146 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 7147 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 6113 | 7148 | return fn_ref; |
| 6114 | 7149 | |
| 6115 | 7150 | size_t arg_count = node->data.fn_call_expr.params.length - 2; |
| 6116 | 7151 | |
| 6117 | | IrInstruction **args = allocate<IrInstruction*>(arg_count); |
| 7152 | IrInstSrc **args = allocate<IrInstSrc*>(arg_count); |
| 6118 | 7153 | for (size_t i = 0; i < arg_count; i += 1) { |
| 6119 | 7154 | AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2); |
| 6120 | 7155 | args[i] = ir_gen_node(irb, arg_node, scope); |
| 6121 | | if (args[i] == irb->codegen->invalid_instruction) |
| 7156 | if (args[i] == irb->codegen->invalid_inst_src) |
| 6122 | 7157 | return args[i]; |
| 6123 | 7158 | } |
| 6124 | 7159 | |
| 6125 | | IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, |
| 7160 | IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, |
| 6126 | 7161 | nullptr, CallModifierNone, false, new_stack, result_loc); |
| 6127 | 7162 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 6128 | 7163 | } |
| 6129 | 7164 | case BuiltinFnIdCall: { |
| 6130 | 7165 | // Cast the options parameter to the options type |
| 6131 | 7166 | ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions"); |
| 6132 | | IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 7167 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 6133 | 7168 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); |
| 6134 | 7169 | |
| 6135 | 7170 | AstNode *options_node = node->data.fn_call_expr.params.at(0); |
| 6136 | | IrInstruction *options_inner = ir_gen_node_extra(irb, options_node, scope, |
| 7171 | IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope, |
| 6137 | 7172 | LValNone, &result_loc_cast->base); |
| 6138 | | if (options_inner == irb->codegen->invalid_instruction) |
| 7173 | if (options_inner == irb->codegen->invalid_inst_src) |
| 6139 | 7174 | return options_inner; |
| 6140 | | IrInstruction *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast); |
| 7175 | IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast); |
| 6141 | 7176 | |
| 6142 | 7177 | AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1); |
| 6143 | 7178 | AstNode *args_node = node->data.fn_call_expr.params.at(2); |
| ... | ... | @@ -6153,18 +7188,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6153 | 7188 | } else { |
| 6154 | 7189 | exec_add_error_node(irb->codegen, irb->exec, args_node, |
| 6155 | 7190 | buf_sprintf("TODO: @call with anon struct literal")); |
| 6156 | | return irb->codegen->invalid_instruction; |
| 7191 | return irb->codegen->invalid_inst_src; |
| 6157 | 7192 | } |
| 6158 | 7193 | } else { |
| 6159 | | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 6160 | | if (fn_ref == irb->codegen->invalid_instruction) |
| 7194 | IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 7195 | if (fn_ref == irb->codegen->invalid_inst_src) |
| 6161 | 7196 | return fn_ref; |
| 6162 | 7197 | |
| 6163 | | IrInstruction *args = ir_gen_node(irb, args_node, scope); |
| 6164 | | if (args == irb->codegen->invalid_instruction) |
| 7198 | IrInstSrc *args = ir_gen_node(irb, args_node, scope); |
| 7199 | if (args == irb->codegen->invalid_inst_src) |
| 6165 | 7200 | return args; |
| 6166 | 7201 | |
| 6167 | | IrInstruction *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc); |
| 7202 | IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc); |
| 6168 | 7203 | return ir_lval_wrap(irb, scope, call, lval, result_loc); |
| 6169 | 7204 | } |
| 6170 | 7205 | } |
| ... | ... | @@ -6173,237 +7208,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6173 | 7208 | case BuiltinFnIdTypeId: |
| 6174 | 7209 | { |
| 6175 | 7210 | 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) |
| 7211 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7212 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6178 | 7213 | return arg0_value; |
| 6179 | 7214 | |
| 6180 | | IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value); |
| 7215 | IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value); |
| 6181 | 7216 | return ir_lval_wrap(irb, scope, type_id, lval, result_loc); |
| 6182 | 7217 | } |
| 6183 | 7218 | case BuiltinFnIdShlExact: |
| 6184 | 7219 | { |
| 6185 | 7220 | 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) |
| 7221 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7222 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6188 | 7223 | return arg0_value; |
| 6189 | 7224 | |
| 6190 | 7225 | 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) |
| 7226 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7227 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6193 | 7228 | return arg1_value; |
| 6194 | 7229 | |
| 6195 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 7230 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true); |
| 6196 | 7231 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 6197 | 7232 | } |
| 6198 | 7233 | case BuiltinFnIdShrExact: |
| 6199 | 7234 | { |
| 6200 | 7235 | 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) |
| 7236 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7237 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6203 | 7238 | return arg0_value; |
| 6204 | 7239 | |
| 6205 | 7240 | 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) |
| 7241 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7242 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6208 | 7243 | return arg1_value; |
| 6209 | 7244 | |
| 6210 | | IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 7245 | IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true); |
| 6211 | 7246 | return ir_lval_wrap(irb, scope, bin_op, lval, result_loc); |
| 6212 | 7247 | } |
| 6213 | 7248 | case BuiltinFnIdSetEvalBranchQuota: |
| 6214 | 7249 | { |
| 6215 | 7250 | 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) |
| 7251 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7252 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6218 | 7253 | return arg0_value; |
| 6219 | 7254 | |
| 6220 | | IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 7255 | IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value); |
| 6221 | 7256 | return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc); |
| 6222 | 7257 | } |
| 6223 | 7258 | case BuiltinFnIdAlignCast: |
| 6224 | 7259 | { |
| 6225 | 7260 | 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) |
| 7261 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7262 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6228 | 7263 | return arg0_value; |
| 6229 | 7264 | |
| 6230 | 7265 | 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) |
| 7266 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7267 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6233 | 7268 | return arg1_value; |
| 6234 | 7269 | |
| 6235 | | IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); |
| 7270 | IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value); |
| 6236 | 7271 | return ir_lval_wrap(irb, scope, align_cast, lval, result_loc); |
| 6237 | 7272 | } |
| 6238 | 7273 | case BuiltinFnIdOpaqueType: |
| 6239 | 7274 | { |
| 6240 | | IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node); |
| 7275 | IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node); |
| 6241 | 7276 | return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc); |
| 6242 | 7277 | } |
| 6243 | 7278 | case BuiltinFnIdThis: |
| 6244 | 7279 | { |
| 6245 | | IrInstruction *this_inst = ir_gen_this(irb, scope, node); |
| 7280 | IrInstSrc *this_inst = ir_gen_this(irb, scope, node); |
| 6246 | 7281 | return ir_lval_wrap(irb, scope, this_inst, lval, result_loc); |
| 6247 | 7282 | } |
| 6248 | 7283 | case BuiltinFnIdSetAlignStack: |
| 6249 | 7284 | { |
| 6250 | 7285 | 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) |
| 7286 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7287 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6253 | 7288 | return arg0_value; |
| 6254 | 7289 | |
| 6255 | | IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); |
| 7290 | IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value); |
| 6256 | 7291 | return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc); |
| 6257 | 7292 | } |
| 6258 | 7293 | case BuiltinFnIdArgType: |
| 6259 | 7294 | { |
| 6260 | 7295 | 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) |
| 7296 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7297 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6263 | 7298 | return arg0_value; |
| 6264 | 7299 | |
| 6265 | 7300 | 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) |
| 7301 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7302 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6268 | 7303 | return arg1_value; |
| 6269 | 7304 | |
| 6270 | | IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false); |
| 7305 | IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false); |
| 6271 | 7306 | return ir_lval_wrap(irb, scope, arg_type, lval, result_loc); |
| 6272 | 7307 | } |
| 6273 | 7308 | case BuiltinFnIdExport: |
| 6274 | 7309 | { |
| 6275 | 7310 | // Cast the options parameter to the options type |
| 6276 | 7311 | ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions"); |
| 6277 | | IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 7312 | IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type); |
| 6278 | 7313 | ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc()); |
| 6279 | 7314 | |
| 6280 | 7315 | 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) |
| 7316 | IrInstSrc *target_value = ir_gen_node(irb, target_node, scope); |
| 7317 | if (target_value == irb->codegen->invalid_inst_src) |
| 6283 | 7318 | return target_value; |
| 6284 | 7319 | |
| 6285 | 7320 | AstNode *options_node = node->data.fn_call_expr.params.at(1); |
| 6286 | | IrInstruction *options_value = ir_gen_node_extra(irb, options_node, |
| 7321 | IrInstSrc *options_value = ir_gen_node_extra(irb, options_node, |
| 6287 | 7322 | scope, LValNone, &result_loc_cast->base); |
| 6288 | | if (options_value == irb->codegen->invalid_instruction) |
| 7323 | if (options_value == irb->codegen->invalid_inst_src) |
| 6289 | 7324 | return options_value; |
| 6290 | 7325 | |
| 6291 | | IrInstruction *casted_options_value = ir_build_implicit_cast( |
| 7326 | IrInstSrc *casted_options_value = ir_build_implicit_cast( |
| 6292 | 7327 | irb, scope, options_node, options_value, result_loc_cast); |
| 6293 | 7328 | |
| 6294 | | IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value); |
| 7329 | IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value); |
| 6295 | 7330 | return ir_lval_wrap(irb, scope, ir_export, lval, result_loc); |
| 6296 | 7331 | } |
| 6297 | 7332 | case BuiltinFnIdErrorReturnTrace: |
| 6298 | 7333 | { |
| 6299 | | IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null); |
| 7334 | IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node, |
| 7335 | IrInstErrorReturnTraceNull); |
| 6300 | 7336 | return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc); |
| 6301 | 7337 | } |
| 6302 | 7338 | case BuiltinFnIdAtomicRmw: |
| 6303 | 7339 | { |
| 6304 | 7340 | 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) |
| 7341 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7342 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6307 | 7343 | return arg0_value; |
| 6308 | 7344 | |
| 6309 | 7345 | 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) |
| 7346 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7347 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6312 | 7348 | return arg1_value; |
| 6313 | 7349 | |
| 6314 | 7350 | 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) |
| 7351 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7352 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6317 | 7353 | return arg2_value; |
| 6318 | 7354 | |
| 6319 | 7355 | 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) |
| 7356 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 7357 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 6322 | 7358 | return arg3_value; |
| 6323 | 7359 | |
| 6324 | 7360 | 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) |
| 7361 | IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope); |
| 7362 | if (arg4_value == irb->codegen->invalid_inst_src) |
| 6327 | 7363 | return arg4_value; |
| 6328 | 7364 | |
| 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); |
| 7365 | IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node, |
| 7366 | arg0_value, arg1_value, arg2_value, arg3_value, arg4_value); |
| 6333 | 7367 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6334 | 7368 | } |
| 6335 | 7369 | case BuiltinFnIdAtomicLoad: |
| 6336 | 7370 | { |
| 6337 | 7371 | 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) |
| 7372 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7373 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6340 | 7374 | return arg0_value; |
| 6341 | 7375 | |
| 6342 | 7376 | 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) |
| 7377 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7378 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6345 | 7379 | return arg1_value; |
| 6346 | 7380 | |
| 6347 | 7381 | 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) |
| 7382 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7383 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6350 | 7384 | return arg2_value; |
| 6351 | 7385 | |
| 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); |
| 7386 | IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value); |
| 6355 | 7387 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6356 | 7388 | } |
| 6357 | 7389 | case BuiltinFnIdAtomicStore: |
| 6358 | 7390 | { |
| 6359 | 7391 | 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) |
| 7392 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7393 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6362 | 7394 | return arg0_value; |
| 6363 | 7395 | |
| 6364 | 7396 | 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) |
| 7397 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7398 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6367 | 7399 | return arg1_value; |
| 6368 | 7400 | |
| 6369 | 7401 | 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) |
| 7402 | IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope); |
| 7403 | if (arg2_value == irb->codegen->invalid_inst_src) |
| 6372 | 7404 | return arg2_value; |
| 6373 | 7405 | |
| 6374 | 7406 | 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) |
| 7407 | IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope); |
| 7408 | if (arg3_value == irb->codegen->invalid_inst_src) |
| 6377 | 7409 | return arg3_value; |
| 6378 | 7410 | |
| 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); |
| 7411 | IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value, |
| 7412 | arg2_value, arg3_value); |
| 6382 | 7413 | return ir_lval_wrap(irb, scope, inst, lval, result_loc); |
| 6383 | 7414 | } |
| 6384 | 7415 | case BuiltinFnIdIntToEnum: |
| 6385 | 7416 | { |
| 6386 | 7417 | 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) |
| 7418 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7419 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6389 | 7420 | return arg0_value; |
| 6390 | 7421 | |
| 6391 | 7422 | 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) |
| 7423 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7424 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6394 | 7425 | return arg1_value; |
| 6395 | 7426 | |
| 6396 | | IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value); |
| 7427 | IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value); |
| 6397 | 7428 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6398 | 7429 | } |
| 6399 | 7430 | case BuiltinFnIdEnumToInt: |
| 6400 | 7431 | { |
| 6401 | 7432 | 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) |
| 7433 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7434 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6404 | 7435 | return arg0_value; |
| 6405 | 7436 | |
| 6406 | | IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value); |
| 7437 | IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value); |
| 6407 | 7438 | return ir_lval_wrap(irb, scope, result, lval, result_loc); |
| 6408 | 7439 | } |
| 6409 | 7440 | case BuiltinFnIdCtz: |
| ... | ... | @@ -6413,16 +7444,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6413 | 7444 | case BuiltinFnIdBitReverse: |
| 6414 | 7445 | { |
| 6415 | 7446 | 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) |
| 7447 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7448 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6418 | 7449 | return arg0_value; |
| 6419 | 7450 | |
| 6420 | 7451 | 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) |
| 7452 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7453 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6423 | 7454 | return arg1_value; |
| 6424 | 7455 | |
| 6425 | | IrInstruction *result; |
| 7456 | IrInstSrc *result; |
| 6426 | 7457 | switch (builtin_fn->id) { |
| 6427 | 7458 | case BuiltinFnIdCtz: |
| 6428 | 7459 | result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value); |
| ... | ... | @@ -6447,28 +7478,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6447 | 7478 | case BuiltinFnIdHasDecl: |
| 6448 | 7479 | { |
| 6449 | 7480 | 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) |
| 7481 | IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 7482 | if (arg0_value == irb->codegen->invalid_inst_src) |
| 6452 | 7483 | return arg0_value; |
| 6453 | 7484 | |
| 6454 | 7485 | 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) |
| 7486 | IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 7487 | if (arg1_value == irb->codegen->invalid_inst_src) |
| 6457 | 7488 | return arg1_value; |
| 6458 | 7489 | |
| 6459 | | IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 7490 | IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value); |
| 6460 | 7491 | return ir_lval_wrap(irb, scope, has_decl, lval, result_loc); |
| 6461 | 7492 | } |
| 6462 | 7493 | case BuiltinFnIdUnionInit: |
| 6463 | 7494 | { |
| 6464 | 7495 | 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) |
| 7496 | IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope); |
| 7497 | if (union_type_inst == irb->codegen->invalid_inst_src) |
| 6467 | 7498 | return union_type_inst; |
| 6468 | 7499 | |
| 6469 | 7500 | 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) |
| 7501 | IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope); |
| 7502 | if (name_inst == irb->codegen->invalid_inst_src) |
| 6472 | 7503 | return name_inst; |
| 6473 | 7504 | |
| 6474 | 7505 | AstNode *init_node = node->data.fn_call_expr.params.at(2); |
| ... | ... | @@ -6480,7 +7511,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 6480 | 7511 | zig_unreachable(); |
| 6481 | 7512 | } |
| 6482 | 7513 | |
| 6483 | | static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7514 | static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6484 | 7515 | ResultLoc *result_loc) |
| 6485 | 7516 | { |
| 6486 | 7517 | assert(node->type == NodeTypeFnCallExpr); |
| ... | ... | @@ -6493,16 +7524,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node |
| 6493 | 7524 | nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc); |
| 6494 | 7525 | } |
| 6495 | 7526 | |
| 6496 | | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7527 | static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6497 | 7528 | ResultLoc *result_loc) |
| 6498 | 7529 | { |
| 6499 | 7530 | assert(node->type == NodeTypeIfBoolExpr); |
| 6500 | 7531 | |
| 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; |
| 7532 | IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); |
| 7533 | if (condition == irb->codegen->invalid_inst_src) |
| 7534 | return irb->codegen->invalid_inst_src; |
| 6504 | 7535 | |
| 6505 | | IrInstruction *is_comptime; |
| 7536 | IrInstSrc *is_comptime; |
| 6506 | 7537 | if (ir_should_inline(irb->exec, scope)) { |
| 6507 | 7538 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 6508 | 7539 | } else { |
| ... | ... | @@ -6512,11 +7543,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 6512 | 7543 | AstNode *then_node = node->data.if_bool_expr.then_block; |
| 6513 | 7544 | AstNode *else_node = node->data.if_bool_expr.else_node; |
| 6514 | 7545 | |
| 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"); |
| 7546 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then"); |
| 7547 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else"); |
| 7548 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf"); |
| 6518 | 7549 | |
| 6519 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition, |
| 7550 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition, |
| 6520 | 7551 | then_block, else_block, is_comptime); |
| 6521 | 7552 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 6522 | 7553 | result_loc, is_comptime); |
| ... | ... | @@ -6524,70 +7555,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 6524 | 7555 | ir_set_cursor_at_end_and_append_block(irb, then_block); |
| 6525 | 7556 | |
| 6526 | 7557 | 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, |
| 7558 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval, |
| 6528 | 7559 | &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; |
| 7560 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7561 | return irb->codegen->invalid_inst_src; |
| 7562 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 6532 | 7563 | if (!instr_is_unreachable(then_expr_result)) |
| 6533 | 7564 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 6534 | 7565 | |
| 6535 | 7566 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 6536 | | IrInstruction *else_expr_result; |
| 7567 | IrInstSrc *else_expr_result; |
| 6537 | 7568 | if (else_node) { |
| 6538 | 7569 | 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; |
| 7570 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7571 | return irb->codegen->invalid_inst_src; |
| 6541 | 7572 | } else { |
| 6542 | 7573 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 6543 | 7574 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 6544 | 7575 | } |
| 6545 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 7576 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 6546 | 7577 | if (!instr_is_unreachable(else_expr_result)) |
| 6547 | 7578 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 6548 | 7579 | |
| 6549 | 7580 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 6550 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 7581 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 6551 | 7582 | incoming_values[0] = then_expr_result; |
| 6552 | 7583 | incoming_values[1] = else_expr_result; |
| 6553 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 7584 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 6554 | 7585 | incoming_blocks[0] = after_then_block; |
| 6555 | 7586 | incoming_blocks[1] = after_else_block; |
| 6556 | 7587 | |
| 6557 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7588 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 6558 | 7589 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 6559 | 7590 | } |
| 6560 | 7591 | |
| 6561 | | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| 7592 | static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) { |
| 6562 | 7593 | assert(node->type == NodeTypePrefixOpExpr); |
| 6563 | 7594 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 6564 | 7595 | |
| 6565 | | IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 6566 | | if (value == irb->codegen->invalid_instruction) |
| 7596 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 7597 | if (value == irb->codegen->invalid_inst_src) |
| 6567 | 7598 | return value; |
| 6568 | 7599 | |
| 6569 | 7600 | return ir_build_un_op(irb, scope, node, op_id, value); |
| 6570 | 7601 | } |
| 6571 | 7602 | |
| 6572 | | static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 7603 | static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 6573 | 7604 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone); |
| 6574 | 7605 | } |
| 6575 | 7606 | |
| 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); |
| 7607 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) { |
| 7608 | if (inst == irb->codegen->invalid_inst_src) return inst; |
| 7609 | ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc); |
| 6579 | 7610 | return inst; |
| 6580 | 7611 | } |
| 6581 | 7612 | |
| 6582 | | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, |
| 7613 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, |
| 6583 | 7614 | ResultLoc *result_loc) |
| 6584 | 7615 | { |
| 6585 | 7616 | // This logic must be kept in sync with |
| 6586 | 7617 | // [STMT_EXPR_TEST_THING] <--- (search this token) |
| 6587 | | if (value == irb->codegen->invalid_instruction || |
| 7618 | if (value == irb->codegen->invalid_inst_src || |
| 6588 | 7619 | instr_is_unreachable(value) || |
| 6589 | | value->source_node->type == NodeTypeDefer || |
| 6590 | | value->id == IrInstructionIdDeclVarSrc) |
| 7620 | value->base.source_node->type == NodeTypeDefer || |
| 7621 | value->id == IrInstSrcIdDeclVar) |
| 6591 | 7622 | { |
| 6592 | 7623 | return value; |
| 6593 | 7624 | } |
| ... | ... | @@ -6595,7 +7626,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction * |
| 6595 | 7626 | if (lval == LValPtr) { |
| 6596 | 7627 | // We needed a pointer to a value, but we got a value. So we create |
| 6597 | 7628 | // an instruction which just makes a pointer of it. |
| 6598 | | return ir_build_ref(irb, scope, value->source_node, value, false, false); |
| 7629 | return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false); |
| 6599 | 7630 | } else if (result_loc != nullptr) { |
| 6600 | 7631 | return ir_expr_wrap(irb, scope, value, result_loc); |
| 6601 | 7632 | } else { |
| ... | ... | @@ -6618,7 +7649,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) { |
| 6618 | 7649 | } |
| 6619 | 7650 | } |
| 6620 | 7651 | |
| 6621 | | static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7652 | static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6622 | 7653 | assert(node->type == NodeTypePointerType); |
| 6623 | 7654 | |
| 6624 | 7655 | PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id); |
| ... | ... | @@ -6630,26 +7661,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6630 | 7661 | AstNode *expr_node = node->data.pointer_type.op_expr; |
| 6631 | 7662 | AstNode *align_expr = node->data.pointer_type.align_expr; |
| 6632 | 7663 | |
| 6633 | | IrInstruction *sentinel; |
| 7664 | IrInstSrc *sentinel; |
| 6634 | 7665 | if (sentinel_expr != nullptr) { |
| 6635 | 7666 | sentinel = ir_gen_node(irb, sentinel_expr, scope); |
| 6636 | | if (sentinel == irb->codegen->invalid_instruction) |
| 7667 | if (sentinel == irb->codegen->invalid_inst_src) |
| 6637 | 7668 | return sentinel; |
| 6638 | 7669 | } else { |
| 6639 | 7670 | sentinel = nullptr; |
| 6640 | 7671 | } |
| 6641 | 7672 | |
| 6642 | | IrInstruction *align_value; |
| 7673 | IrInstSrc *align_value; |
| 6643 | 7674 | if (align_expr != nullptr) { |
| 6644 | 7675 | align_value = ir_gen_node(irb, align_expr, scope); |
| 6645 | | if (align_value == irb->codegen->invalid_instruction) |
| 7676 | if (align_value == irb->codegen->invalid_inst_src) |
| 6646 | 7677 | return align_value; |
| 6647 | 7678 | } else { |
| 6648 | 7679 | align_value = nullptr; |
| 6649 | 7680 | } |
| 6650 | 7681 | |
| 6651 | | IrInstruction *child_type = ir_gen_node(irb, expr_node, scope); |
| 6652 | | if (child_type == irb->codegen->invalid_instruction) |
| 7682 | IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope); |
| 7683 | if (child_type == irb->codegen->invalid_inst_src) |
| 6653 | 7684 | return child_type; |
| 6654 | 7685 | |
| 6655 | 7686 | uint32_t bit_offset_start = 0; |
| ... | ... | @@ -6659,7 +7690,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6659 | 7690 | bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10); |
| 6660 | 7691 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6661 | 7692 | buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf))); |
| 6662 | | return irb->codegen->invalid_instruction; |
| 7693 | return irb->codegen->invalid_inst_src; |
| 6663 | 7694 | } |
| 6664 | 7695 | bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start); |
| 6665 | 7696 | } |
| ... | ... | @@ -6671,7 +7702,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6671 | 7702 | bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10); |
| 6672 | 7703 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6673 | 7704 | buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf))); |
| 6674 | | return irb->codegen->invalid_instruction; |
| 7705 | return irb->codegen->invalid_inst_src; |
| 6675 | 7706 | } |
| 6676 | 7707 | host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes); |
| 6677 | 7708 | } |
| ... | ... | @@ -6679,43 +7710,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 6679 | 7710 | if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) { |
| 6680 | 7711 | exec_add_error_node(irb->codegen, irb->exec, node, |
| 6681 | 7712 | buf_sprintf("bit offset starts after end of host integer")); |
| 6682 | | return irb->codegen->invalid_instruction; |
| 7713 | return irb->codegen->invalid_inst_src; |
| 6683 | 7714 | } |
| 6684 | 7715 | |
| 6685 | 7716 | return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile, |
| 6686 | 7717 | ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero); |
| 6687 | 7718 | } |
| 6688 | 7719 | |
| 6689 | | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 7720 | static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 6690 | 7721 | AstNode *expr_node, LVal lval, ResultLoc *result_loc) |
| 6691 | 7722 | { |
| 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; |
| 7723 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 7724 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 7725 | return irb->codegen->invalid_inst_src; |
| 6695 | 7726 | |
| 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; |
| 7727 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false); |
| 7728 | if (payload_ptr == irb->codegen->invalid_inst_src) |
| 7729 | return irb->codegen->invalid_inst_src; |
| 6699 | 7730 | |
| 6700 | 7731 | if (lval == LValPtr) |
| 6701 | 7732 | return payload_ptr; |
| 6702 | 7733 | |
| 6703 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 7734 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 6704 | 7735 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 6705 | 7736 | } |
| 6706 | 7737 | |
| 6707 | | static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7738 | static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6708 | 7739 | assert(node->type == NodeTypePrefixOpExpr); |
| 6709 | 7740 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 6710 | 7741 | |
| 6711 | | IrInstruction *value = ir_gen_node(irb, expr_node, scope); |
| 6712 | | if (value == irb->codegen->invalid_instruction) |
| 6713 | | return irb->codegen->invalid_instruction; |
| 7742 | IrInstSrc *value = ir_gen_node(irb, expr_node, scope); |
| 7743 | if (value == irb->codegen->invalid_inst_src) |
| 7744 | return irb->codegen->invalid_inst_src; |
| 6714 | 7745 | |
| 6715 | 7746 | return ir_build_bool_not(irb, scope, node, value); |
| 6716 | 7747 | } |
| 6717 | 7748 | |
| 6718 | | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7749 | static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6719 | 7750 | ResultLoc *result_loc) |
| 6720 | 7751 | { |
| 6721 | 7752 | assert(node->type == NodeTypePrefixOpExpr); |
| ... | ... | @@ -6743,12 +7774,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 6743 | 7774 | zig_unreachable(); |
| 6744 | 7775 | } |
| 6745 | 7776 | |
| 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, |
| 7777 | static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, |
| 7778 | IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node, |
| 6748 | 7779 | LVal lval, ResultLoc *parent_result_loc) |
| 6749 | 7780 | { |
| 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, |
| 7781 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type); |
| 7782 | IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr, |
| 6752 | 7783 | field_name, true); |
| 6753 | 7784 | |
| 6754 | 7785 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| ... | ... | @@ -6757,18 +7788,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo |
| 6757 | 7788 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 6758 | 7789 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6759 | 7790 | |
| 6760 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7791 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6761 | 7792 | &result_loc_inst->base); |
| 6762 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7793 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6763 | 7794 | return expr_value; |
| 6764 | 7795 | |
| 6765 | | IrInstruction *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type, |
| 7796 | IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type, |
| 6766 | 7797 | field_name, field_ptr, container_ptr); |
| 6767 | 7798 | |
| 6768 | 7799 | return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc); |
| 6769 | 7800 | } |
| 6770 | 7801 | |
| 6771 | | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 7802 | static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 6772 | 7803 | ResultLoc *parent_result_loc) |
| 6773 | 7804 | { |
| 6774 | 7805 | assert(node->type == NodeTypeContainerInitExpr); |
| ... | ... | @@ -6780,42 +7811,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6780 | 7811 | ResultLoc *child_result_loc; |
| 6781 | 7812 | AstNode *init_array_type_source_node; |
| 6782 | 7813 | if (container_init_expr->type != nullptr) { |
| 6783 | | IrInstruction *container_type; |
| 7814 | IrInstSrc *container_type; |
| 6784 | 7815 | if (container_init_expr->type->type == NodeTypeInferredArrayType) { |
| 6785 | 7816 | if (kind == ContainerInitKindStruct) { |
| 6786 | 7817 | add_node_error(irb->codegen, container_init_expr->type, |
| 6787 | 7818 | buf_sprintf("initializing array with struct syntax")); |
| 6788 | | return irb->codegen->invalid_instruction; |
| 7819 | return irb->codegen->invalid_inst_src; |
| 6789 | 7820 | } |
| 6790 | | IrInstruction *sentinel; |
| 7821 | IrInstSrc *sentinel; |
| 6791 | 7822 | if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) { |
| 6792 | 7823 | sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope); |
| 6793 | | if (sentinel == irb->codegen->invalid_instruction) |
| 7824 | if (sentinel == irb->codegen->invalid_inst_src) |
| 6794 | 7825 | return sentinel; |
| 6795 | 7826 | } else { |
| 6796 | 7827 | sentinel = nullptr; |
| 6797 | 7828 | } |
| 6798 | 7829 | |
| 6799 | | IrInstruction *elem_type = ir_gen_node(irb, |
| 7830 | IrInstSrc *elem_type = ir_gen_node(irb, |
| 6800 | 7831 | container_init_expr->type->data.inferred_array_type.child_type, scope); |
| 6801 | | if (elem_type == irb->codegen->invalid_instruction) |
| 7832 | if (elem_type == irb->codegen->invalid_inst_src) |
| 6802 | 7833 | return elem_type; |
| 6803 | 7834 | size_t item_count = container_init_expr->entries.length; |
| 6804 | | IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 7835 | IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count); |
| 6805 | 7836 | container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type); |
| 6806 | 7837 | } else { |
| 6807 | 7838 | container_type = ir_gen_node(irb, container_init_expr->type, scope); |
| 6808 | | if (container_type == irb->codegen->invalid_instruction) |
| 7839 | if (container_type == irb->codegen->invalid_inst_src) |
| 6809 | 7840 | return container_type; |
| 6810 | 7841 | } |
| 6811 | 7842 | |
| 6812 | 7843 | result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc); |
| 6813 | 7844 | child_result_loc = &result_loc_cast->base; |
| 6814 | | init_array_type_source_node = container_type->source_node; |
| 7845 | init_array_type_source_node = container_type->base.source_node; |
| 6815 | 7846 | } else { |
| 6816 | 7847 | child_result_loc = parent_result_loc; |
| 6817 | 7848 | if (parent_result_loc->source_instruction != nullptr) { |
| 6818 | | init_array_type_source_node = parent_result_loc->source_instruction->source_node; |
| 7849 | init_array_type_source_node = parent_result_loc->source_instruction->base.source_node; |
| 6819 | 7850 | } else { |
| 6820 | 7851 | init_array_type_source_node = node; |
| 6821 | 7852 | } |
| ... | ... | @@ -6823,11 +7854,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6823 | 7854 | |
| 6824 | 7855 | switch (kind) { |
| 6825 | 7856 | case ContainerInitKindStruct: { |
| 6826 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 7857 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6827 | 7858 | nullptr); |
| 6828 | 7859 | |
| 6829 | 7860 | size_t field_count = container_init_expr->entries.length; |
| 6830 | | IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count); |
| 7861 | IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count); |
| 6831 | 7862 | for (size_t i = 0; i < field_count; i += 1) { |
| 6832 | 7863 | AstNode *entry_node = container_init_expr->entries.at(i); |
| 6833 | 7864 | assert(entry_node->type == NodeTypeStructValueField); |
| ... | ... | @@ -6835,7 +7866,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6835 | 7866 | Buf *name = entry_node->data.struct_val_field.name; |
| 6836 | 7867 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 6837 | 7868 | |
| 6838 | | IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true); |
| 7869 | IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true); |
| 6839 | 7870 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6840 | 7871 | result_loc_inst->base.id = ResultLocIdInstruction; |
| 6841 | 7872 | result_loc_inst->base.source_instruction = field_ptr; |
| ... | ... | @@ -6843,16 +7874,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6843 | 7874 | ir_ref_instruction(field_ptr, irb->current_basic_block); |
| 6844 | 7875 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6845 | 7876 | |
| 6846 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7877 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6847 | 7878 | &result_loc_inst->base); |
| 6848 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7879 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6849 | 7880 | return expr_value; |
| 6850 | 7881 | |
| 6851 | 7882 | fields[i].name = name; |
| 6852 | 7883 | fields[i].source_node = entry_node; |
| 6853 | 7884 | fields[i].result_loc = field_ptr; |
| 6854 | 7885 | } |
| 6855 | | IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count, |
| 7886 | IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count, |
| 6856 | 7887 | fields, container_ptr); |
| 6857 | 7888 | |
| 6858 | 7889 | if (result_loc_cast != nullptr) { |
| ... | ... | @@ -6863,15 +7894,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6863 | 7894 | case ContainerInitKindArray: { |
| 6864 | 7895 | size_t item_count = container_init_expr->entries.length; |
| 6865 | 7896 | |
| 6866 | | IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 7897 | IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc, |
| 6867 | 7898 | nullptr); |
| 6868 | 7899 | |
| 6869 | | IrInstruction **result_locs = allocate<IrInstruction *>(item_count); |
| 7900 | IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count); |
| 6870 | 7901 | for (size_t i = 0; i < item_count; i += 1) { |
| 6871 | 7902 | AstNode *expr_node = container_init_expr->entries.at(i); |
| 6872 | 7903 | |
| 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, |
| 7904 | IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i); |
| 7905 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, |
| 6875 | 7906 | elem_index, false, PtrLenSingle, init_array_type_source_node); |
| 6876 | 7907 | ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1); |
| 6877 | 7908 | result_loc_inst->base.id = ResultLocIdInstruction; |
| ... | ... | @@ -6880,14 +7911,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6880 | 7911 | ir_ref_instruction(elem_ptr, irb->current_basic_block); |
| 6881 | 7912 | ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base); |
| 6882 | 7913 | |
| 6883 | | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 7914 | IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, |
| 6884 | 7915 | &result_loc_inst->base); |
| 6885 | | if (expr_value == irb->codegen->invalid_instruction) |
| 7916 | if (expr_value == irb->codegen->invalid_inst_src) |
| 6886 | 7917 | return expr_value; |
| 6887 | 7918 | |
| 6888 | 7919 | result_locs[i] = elem_ptr; |
| 6889 | 7920 | } |
| 6890 | | IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count, |
| 7921 | IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count, |
| 6891 | 7922 | result_locs, container_ptr, init_array_type_source_node); |
| 6892 | 7923 | if (result_loc_cast != nullptr) { |
| 6893 | 7924 | result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast); |
| ... | ... | @@ -6898,19 +7929,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A |
| 6898 | 7929 | zig_unreachable(); |
| 6899 | 7930 | } |
| 6900 | 7931 | |
| 6901 | | static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) { |
| 7932 | static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) { |
| 6902 | 7933 | ResultLocVar *result_loc_var = allocate<ResultLocVar>(1); |
| 6903 | 7934 | result_loc_var->base.id = ResultLocIdVar; |
| 6904 | 7935 | result_loc_var->base.source_instruction = alloca; |
| 6905 | 7936 | result_loc_var->base.allow_write_through_const = true; |
| 6906 | 7937 | result_loc_var->var = var; |
| 6907 | 7938 | |
| 6908 | | ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base); |
| 7939 | ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base); |
| 6909 | 7940 | |
| 6910 | 7941 | return result_loc_var; |
| 6911 | 7942 | } |
| 6912 | 7943 | |
| 6913 | | static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type, |
| 7944 | static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type, |
| 6914 | 7945 | ResultLoc *parent_result_loc) |
| 6915 | 7946 | { |
| 6916 | 7947 | ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1); |
| ... | ... | @@ -6920,37 +7951,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de |
| 6920 | 7951 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 6921 | 7952 | result_loc_cast->parent = parent_result_loc; |
| 6922 | 7953 | |
| 6923 | | ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base); |
| 7954 | ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base); |
| 6924 | 7955 | |
| 6925 | 7956 | return result_loc_cast; |
| 6926 | 7957 | } |
| 6927 | 7958 | |
| 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) |
| 7959 | static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 7960 | IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime) |
| 6930 | 7961 | { |
| 6931 | | IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); |
| 7962 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime); |
| 6932 | 7963 | ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var); |
| 6933 | 7964 | ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base); |
| 6934 | 7965 | ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca); |
| 6935 | 7966 | } |
| 6936 | 7967 | |
| 6937 | | static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 7968 | static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 6938 | 7969 | assert(node->type == NodeTypeVariableDeclaration); |
| 6939 | 7970 | |
| 6940 | 7971 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; |
| 6941 | 7972 | |
| 6942 | 7973 | if (buf_eql_str(variable_declaration->symbol, "_")) { |
| 6943 | 7974 | add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol")); |
| 6944 | | return irb->codegen->invalid_instruction; |
| 7975 | return irb->codegen->invalid_inst_src; |
| 6945 | 7976 | } |
| 6946 | 7977 | |
| 6947 | 7978 | // Used for the type expr and the align expr |
| 6948 | 7979 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| 6949 | 7980 | |
| 6950 | | IrInstruction *type_instruction; |
| 7981 | IrInstSrc *type_instruction; |
| 6951 | 7982 | if (variable_declaration->type != nullptr) { |
| 6952 | 7983 | type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope); |
| 6953 | | if (type_instruction == irb->codegen->invalid_instruction) |
| 7984 | if (type_instruction == irb->codegen->invalid_inst_src) |
| 6954 | 7985 | return type_instruction; |
| 6955 | 7986 | } else { |
| 6956 | 7987 | type_instruction = nullptr; |
| ... | ... | @@ -6961,22 +7992,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6961 | 7992 | bool is_extern = variable_declaration->is_extern; |
| 6962 | 7993 | |
| 6963 | 7994 | 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); |
| 7995 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar); |
| 6965 | 7996 | ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol, |
| 6966 | 7997 | is_const, is_const, is_shadowable, is_comptime); |
| 6967 | | // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node |
| 7998 | // we detect IrInstSrcDeclVar in gen_block to make sure the next node |
| 6968 | 7999 | // is inside var->child_scope |
| 6969 | 8000 | |
| 6970 | 8001 | if (!is_extern && !variable_declaration->expr) { |
| 6971 | 8002 | var->var_type = irb->codegen->builtin_types.entry_invalid; |
| 6972 | 8003 | add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized")); |
| 6973 | | return irb->codegen->invalid_instruction; |
| 8004 | return irb->codegen->invalid_inst_src; |
| 6974 | 8005 | } |
| 6975 | 8006 | |
| 6976 | | IrInstruction *align_value = nullptr; |
| 8007 | IrInstSrc *align_value = nullptr; |
| 6977 | 8008 | if (variable_declaration->align_expr != nullptr) { |
| 6978 | 8009 | align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope); |
| 6979 | | if (align_value == irb->codegen->invalid_instruction) |
| 8010 | if (align_value == irb->codegen->invalid_inst_src) |
| 6980 | 8011 | return align_value; |
| 6981 | 8012 | } |
| 6982 | 8013 | |
| ... | ... | @@ -6988,7 +8019,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6988 | 8019 | // Parser should ensure that this never happens |
| 6989 | 8020 | assert(variable_declaration->threadlocal_tok == nullptr); |
| 6990 | 8021 | |
| 6991 | | IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value, |
| 8022 | IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value, |
| 6992 | 8023 | buf_ptr(variable_declaration->symbol), is_comptime); |
| 6993 | 8024 | |
| 6994 | 8025 | // Create a result location for the initialization expression. |
| ... | ... | @@ -7006,19 +8037,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7006 | 8037 | Scope *init_scope = is_comptime_scalar ? |
| 7007 | 8038 | create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope; |
| 7008 | 8039 | |
| 7009 | | // Temporarily set the name of the IrExecutable to the VariableDeclaration |
| 8040 | // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration |
| 7010 | 8041 | // so that the struct or enum from the init expression inherits the name. |
| 7011 | 8042 | Buf *old_exec_name = irb->exec->name; |
| 7012 | 8043 | irb->exec->name = variable_declaration->symbol; |
| 7013 | | IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope, |
| 8044 | IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope, |
| 7014 | 8045 | LValNone, init_result_loc); |
| 7015 | 8046 | irb->exec->name = old_exec_name; |
| 7016 | 8047 | |
| 7017 | | if (init_value == irb->codegen->invalid_instruction) |
| 7018 | | return irb->codegen->invalid_instruction; |
| 8048 | if (init_value == irb->codegen->invalid_inst_src) |
| 8049 | return irb->codegen->invalid_inst_src; |
| 7019 | 8050 | |
| 7020 | 8051 | if (result_loc_cast != nullptr) { |
| 7021 | | IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node, |
| 8052 | IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node, |
| 7022 | 8053 | init_value, result_loc_cast); |
| 7023 | 8054 | ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base); |
| 7024 | 8055 | } |
| ... | ... | @@ -7026,7 +8057,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7026 | 8057 | return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca); |
| 7027 | 8058 | } |
| 7028 | 8059 | |
| 7029 | | static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8060 | static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7030 | 8061 | ResultLoc *result_loc) |
| 7031 | 8062 | { |
| 7032 | 8063 | assert(node->type == NodeTypeWhileExpr); |
| ... | ... | @@ -7034,15 +8065,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7034 | 8065 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; |
| 7035 | 8066 | AstNode *else_node = node->data.while_expr.else_node; |
| 7036 | 8067 | |
| 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 ? |
| 8068 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond"); |
| 8069 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody"); |
| 8070 | IrBasicBlockSrc *continue_block = continue_expr_node ? |
| 7040 | 8071 | 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 ? |
| 8072 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd"); |
| 8073 | IrBasicBlockSrc *else_block = else_node ? |
| 7043 | 8074 | ir_create_basic_block(irb, scope, "WhileElse") : end_block; |
| 7044 | 8075 | |
| 7045 | | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 8076 | IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, |
| 7046 | 8077 | ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline); |
| 7047 | 8078 | ir_build_br(irb, scope, node, cond_block, is_comptime); |
| 7048 | 8079 | |
| ... | ... | @@ -7063,15 +8094,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7063 | 8094 | } else { |
| 7064 | 8095 | payload_scope = subexpr_scope; |
| 7065 | 8096 | } |
| 7066 | | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 8097 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 7067 | 8098 | LValPtr, nullptr); |
| 7068 | | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 8099 | if (err_val_ptr == irb->codegen->invalid_inst_src) |
| 7069 | 8100 | return err_val_ptr; |
| 7070 | | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, |
| 8101 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, |
| 7071 | 8102 | 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; |
| 8103 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8104 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8105 | IrInstSrc *cond_br_inst; |
| 7075 | 8106 | if (!instr_is_unreachable(is_err)) { |
| 7076 | 8107 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err, |
| 7077 | 8108 | else_block, body_block, is_comptime); |
| ... | ... | @@ -7086,15 +8117,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7086 | 8117 | |
| 7087 | 8118 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7088 | 8119 | if (var_symbol) { |
| 7089 | | IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node, |
| 8120 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, payload_scope, symbol_node, |
| 7090 | 8121 | 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; |
| 8122 | IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ? |
| 8123 | ir_build_ref_src(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 7093 | 8124 | ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 7094 | 8125 | } |
| 7095 | 8126 | |
| 7096 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7097 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8127 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8128 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7098 | 8129 | |
| 7099 | 8130 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope); |
| 7100 | 8131 | loop_scope->break_block = end_block; |
| ... | ... | @@ -7108,8 +8139,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7108 | 8139 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7109 | 8140 | // it's actually in break statements, handled similarly to return statements. |
| 7110 | 8141 | // 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) |
| 8142 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8143 | if (body_result == irb->codegen->invalid_inst_src) |
| 7113 | 8144 | return body_result; |
| 7114 | 8145 | |
| 7115 | 8146 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7119,8 +8150,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7119 | 8150 | |
| 7120 | 8151 | if (continue_expr_node) { |
| 7121 | 8152 | 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) |
| 8153 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope); |
| 8154 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7124 | 8155 | return expr_result; |
| 7125 | 8156 | if (!instr_is_unreachable(expr_result)) { |
| 7126 | 8157 | ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7136,7 +8167,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7136 | 8167 | ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, |
| 7137 | 8168 | true, false, false, is_comptime); |
| 7138 | 8169 | 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); |
| 8170 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr); |
| 7140 | 8171 | ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr); |
| 7141 | 8172 | |
| 7142 | 8173 | if (peer_parent->peers.length != 0) { |
| ... | ... | @@ -7144,12 +8175,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7144 | 8175 | } |
| 7145 | 8176 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7146 | 8177 | 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) |
| 8178 | IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base); |
| 8179 | if (else_result == irb->codegen->invalid_inst_src) |
| 7149 | 8180 | return else_result; |
| 7150 | 8181 | if (!instr_is_unreachable(else_result)) |
| 7151 | 8182 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7152 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8183 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7153 | 8184 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7154 | 8185 | if (else_result) { |
| 7155 | 8186 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7162,7 +8193,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7162 | 8193 | peer_parent->peers.last()->next_bb = end_block; |
| 7163 | 8194 | } |
| 7164 | 8195 | |
| 7165 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8196 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7166 | 8197 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7167 | 8198 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7168 | 8199 | } else if (var_symbol != nullptr) { |
| ... | ... | @@ -7174,15 +8205,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7174 | 8205 | ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, |
| 7175 | 8206 | true, false, false, is_comptime); |
| 7176 | 8207 | Scope *child_scope = payload_var->child_scope; |
| 7177 | | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 8208 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, |
| 7178 | 8209 | LValPtr, nullptr); |
| 7179 | | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 8210 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) |
| 7180 | 8211 | 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; |
| 8212 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr); |
| 8213 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val); |
| 8214 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8215 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8216 | IrInstSrc *cond_br_inst; |
| 7186 | 8217 | if (!instr_is_unreachable(is_non_null)) { |
| 7187 | 8218 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null, |
| 7188 | 8219 | body_block, else_block, is_comptime); |
| ... | ... | @@ -7196,13 +8227,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7196 | 8227 | is_comptime); |
| 7197 | 8228 | |
| 7198 | 8229 | 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; |
| 8230 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false); |
| 8231 | IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ? |
| 8232 | ir_build_ref_src(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr; |
| 7202 | 8233 | ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr); |
| 7203 | 8234 | |
| 7204 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7205 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8235 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8236 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7206 | 8237 | |
| 7207 | 8238 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); |
| 7208 | 8239 | loop_scope->break_block = end_block; |
| ... | ... | @@ -7216,8 +8247,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7216 | 8247 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7217 | 8248 | // it's actually in break statements, handled similarly to return statements. |
| 7218 | 8249 | // 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) |
| 8250 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8251 | if (body_result == irb->codegen->invalid_inst_src) |
| 7221 | 8252 | return body_result; |
| 7222 | 8253 | |
| 7223 | 8254 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7227,8 +8258,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7227 | 8258 | |
| 7228 | 8259 | if (continue_expr_node) { |
| 7229 | 8260 | 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) |
| 8261 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope); |
| 8262 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7232 | 8263 | return expr_result; |
| 7233 | 8264 | if (!instr_is_unreachable(expr_result)) { |
| 7234 | 8265 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7236,7 +8267,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7236 | 8267 | } |
| 7237 | 8268 | } |
| 7238 | 8269 | |
| 7239 | | IrInstruction *else_result = nullptr; |
| 8270 | IrInstSrc *else_result = nullptr; |
| 7240 | 8271 | if (else_node) { |
| 7241 | 8272 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7242 | 8273 | |
| ... | ... | @@ -7246,12 +8277,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7246 | 8277 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7247 | 8278 | peer_parent->peers.append(peer_result); |
| 7248 | 8279 | else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base); |
| 7249 | | if (else_result == irb->codegen->invalid_instruction) |
| 8280 | if (else_result == irb->codegen->invalid_inst_src) |
| 7250 | 8281 | return else_result; |
| 7251 | 8282 | if (!instr_is_unreachable(else_result)) |
| 7252 | 8283 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7253 | 8284 | } |
| 7254 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8285 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7255 | 8286 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7256 | 8287 | if (else_result) { |
| 7257 | 8288 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7264,17 +8295,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7264 | 8295 | peer_parent->peers.last()->next_bb = end_block; |
| 7265 | 8296 | } |
| 7266 | 8297 | |
| 7267 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8298 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7268 | 8299 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7269 | 8300 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7270 | 8301 | } else { |
| 7271 | 8302 | 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) |
| 8303 | IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 8304 | if (cond_val == irb->codegen->invalid_inst_src) |
| 7274 | 8305 | 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; |
| 8306 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8307 | IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 8308 | IrInstSrc *cond_br_inst; |
| 7278 | 8309 | if (!instr_is_unreachable(cond_val)) { |
| 7279 | 8310 | cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, |
| 7280 | 8311 | body_block, else_block, is_comptime); |
| ... | ... | @@ -7288,8 +8319,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7288 | 8319 | is_comptime); |
| 7289 | 8320 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7290 | 8321 | |
| 7291 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7292 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8322 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8323 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7293 | 8324 | |
| 7294 | 8325 | Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime); |
| 7295 | 8326 | |
| ... | ... | @@ -7305,8 +8336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7305 | 8336 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7306 | 8337 | // it's actually in break statements, handled similarly to return statements. |
| 7307 | 8338 | // 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) |
| 8339 | IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base); |
| 8340 | if (body_result == irb->codegen->invalid_inst_src) |
| 7310 | 8341 | return body_result; |
| 7311 | 8342 | |
| 7312 | 8343 | if (!instr_is_unreachable(body_result)) { |
| ... | ... | @@ -7316,8 +8347,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7316 | 8347 | |
| 7317 | 8348 | if (continue_expr_node) { |
| 7318 | 8349 | 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) |
| 8350 | IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope); |
| 8351 | if (expr_result == irb->codegen->invalid_inst_src) |
| 7321 | 8352 | return expr_result; |
| 7322 | 8353 | if (!instr_is_unreachable(expr_result)) { |
| 7323 | 8354 | ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result)); |
| ... | ... | @@ -7325,7 +8356,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7325 | 8356 | } |
| 7326 | 8357 | } |
| 7327 | 8358 | |
| 7328 | | IrInstruction *else_result = nullptr; |
| 8359 | IrInstSrc *else_result = nullptr; |
| 7329 | 8360 | if (else_node) { |
| 7330 | 8361 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7331 | 8362 | |
| ... | ... | @@ -7336,12 +8367,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7336 | 8367 | peer_parent->peers.append(peer_result); |
| 7337 | 8368 | |
| 7338 | 8369 | else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base); |
| 7339 | | if (else_result == irb->codegen->invalid_instruction) |
| 8370 | if (else_result == irb->codegen->invalid_inst_src) |
| 7340 | 8371 | return else_result; |
| 7341 | 8372 | if (!instr_is_unreachable(else_result)) |
| 7342 | 8373 | ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime)); |
| 7343 | 8374 | } |
| 7344 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8375 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7345 | 8376 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7346 | 8377 | if (else_result) { |
| 7347 | 8378 | incoming_blocks.append(after_else_block); |
| ... | ... | @@ -7354,13 +8385,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 7354 | 8385 | peer_parent->peers.last()->next_bb = end_block; |
| 7355 | 8386 | } |
| 7356 | 8387 | |
| 7357 | | IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 8388 | IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length, |
| 7358 | 8389 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7359 | 8390 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7360 | 8391 | } |
| 7361 | 8392 | } |
| 7362 | 8393 | |
| 7363 | | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 8394 | static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 7364 | 8395 | ResultLoc *result_loc) |
| 7365 | 8396 | { |
| 7366 | 8397 | assert(node->type == NodeTypeForExpr); |
| ... | ... | @@ -7373,17 +8404,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7373 | 8404 | |
| 7374 | 8405 | if (!elem_node) { |
| 7375 | 8406 | add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter")); |
| 7376 | | return irb->codegen->invalid_instruction; |
| 8407 | return irb->codegen->invalid_inst_src; |
| 7377 | 8408 | } |
| 7378 | 8409 | assert(elem_node->type == NodeTypeSymbol); |
| 7379 | 8410 | |
| 7380 | 8411 | ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope); |
| 7381 | 8412 | |
| 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) |
| 8413 | IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr); |
| 8414 | if (array_val_ptr == irb->codegen->invalid_inst_src) |
| 7384 | 8415 | return array_val_ptr; |
| 7385 | 8416 | |
| 7386 | | IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 8417 | IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node, |
| 7387 | 8418 | ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline); |
| 7388 | 8419 | |
| 7389 | 8420 | AstNode *index_var_source_node; |
| ... | ... | @@ -7400,50 +8431,50 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7400 | 8431 | index_var_name = "i"; |
| 7401 | 8432 | } |
| 7402 | 8433 | |
| 7403 | | IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0); |
| 8434 | IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0); |
| 7404 | 8435 | build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime); |
| 7405 | 8436 | parent_scope = index_var->child_scope; |
| 7406 | 8437 | |
| 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); |
| 8438 | IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1); |
| 8439 | IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var); |
| 7409 | 8440 | |
| 7410 | 8441 | |
| 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"); |
| 8442 | IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond"); |
| 8443 | IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody"); |
| 8444 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd"); |
| 8445 | IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block; |
| 8446 | IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue"); |
| 7416 | 8447 | |
| 7417 | 8448 | 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); |
| 8449 | IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false); |
| 8450 | IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref); |
| 7420 | 8451 | ir_build_br(irb, parent_scope, node, cond_block, is_comptime); |
| 7421 | 8452 | |
| 7422 | 8453 | 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, |
| 8454 | IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr); |
| 8455 | IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false); |
| 8456 | IrBasicBlockSrc *after_cond_block = irb->current_basic_block; |
| 8457 | IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node)); |
| 8458 | IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond, |
| 7428 | 8459 | body_block, else_block, is_comptime)); |
| 7429 | 8460 | |
| 7430 | 8461 | ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime); |
| 7431 | 8462 | |
| 7432 | 8463 | ir_set_cursor_at_end_and_append_block(irb, body_block); |
| 7433 | 8464 | 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, |
| 8465 | IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false, |
| 7435 | 8466 | PtrLenSingle, nullptr); |
| 7436 | 8467 | // TODO make it an error to write to element variable or i variable. |
| 7437 | 8468 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; |
| 7438 | 8469 | ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); |
| 7439 | 8470 | Scope *child_scope = elem_var->child_scope; |
| 7440 | 8471 | |
| 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; |
| 8472 | IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ? |
| 8473 | ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr; |
| 7443 | 8474 | ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr); |
| 7444 | 8475 | |
| 7445 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 7446 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8476 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 8477 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 7447 | 8478 | ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope); |
| 7448 | 8479 | loop_scope->break_block = end_block; |
| 7449 | 8480 | loop_scope->continue_block = continue_block; |
| ... | ... | @@ -7457,9 +8488,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7457 | 8488 | // Note the body block of the loop is not the place that lval and result_loc are used - |
| 7458 | 8489 | // it's actually in break statements, handled similarly to return statements. |
| 7459 | 8490 | // 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; |
| 8491 | IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 8492 | if (body_result == irb->codegen->invalid_inst_src) |
| 8493 | return irb->codegen->invalid_inst_src; |
| 7463 | 8494 | |
| 7464 | 8495 | if (!instr_is_unreachable(body_result)) { |
| 7465 | 8496 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result)); |
| ... | ... | @@ -7467,11 +8498,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7467 | 8498 | } |
| 7468 | 8499 | |
| 7469 | 8500 | 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); |
| 8501 | IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| 7471 | 8502 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true; |
| 7472 | 8503 | ir_build_br(irb, child_scope, node, cond_block, is_comptime); |
| 7473 | 8504 | |
| 7474 | | IrInstruction *else_result = nullptr; |
| 8505 | IrInstSrc *else_result = nullptr; |
| 7475 | 8506 | if (else_node) { |
| 7476 | 8507 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7477 | 8508 | |
| ... | ... | @@ -7481,12 +8512,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7481 | 8512 | ResultLocPeer *peer_result = create_peer_result(peer_parent); |
| 7482 | 8513 | peer_parent->peers.append(peer_result); |
| 7483 | 8514 | else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base); |
| 7484 | | if (else_result == irb->codegen->invalid_instruction) |
| 8515 | if (else_result == irb->codegen->invalid_inst_src) |
| 7485 | 8516 | return else_result; |
| 7486 | 8517 | if (!instr_is_unreachable(else_result)) |
| 7487 | 8518 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 7488 | 8519 | } |
| 7489 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8520 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7490 | 8521 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 7491 | 8522 | |
| 7492 | 8523 | if (else_result) { |
| ... | ... | @@ -7500,29 +8531,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7500 | 8531 | peer_parent->peers.last()->next_bb = end_block; |
| 7501 | 8532 | } |
| 7502 | 8533 | |
| 7503 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, |
| 8534 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length, |
| 7504 | 8535 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7505 | 8536 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 7506 | 8537 | } |
| 7507 | 8538 | |
| 7508 | | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8539 | static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7509 | 8540 | assert(node->type == NodeTypeBoolLiteral); |
| 7510 | 8541 | return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value); |
| 7511 | 8542 | } |
| 7512 | 8543 | |
| 7513 | | static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8544 | static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7514 | 8545 | assert(node->type == NodeTypeEnumLiteral); |
| 7515 | 8546 | Buf *name = &node->data.enum_literal.identifier->data.str_lit.str; |
| 7516 | 8547 | return ir_build_const_enum_literal(irb, scope, node, name); |
| 7517 | 8548 | } |
| 7518 | 8549 | |
| 7519 | | static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8550 | static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7520 | 8551 | assert(node->type == NodeTypeStringLiteral); |
| 7521 | 8552 | |
| 7522 | 8553 | return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf); |
| 7523 | 8554 | } |
| 7524 | 8555 | |
| 7525 | | static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8556 | static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7526 | 8557 | assert(node->type == NodeTypeArrayType); |
| 7527 | 8558 | |
| 7528 | 8559 | AstNode *size_node = node->data.array_type.size; |
| ... | ... | @@ -7535,10 +8566,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7535 | 8566 | |
| 7536 | 8567 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| 7537 | 8568 | |
| 7538 | | IrInstruction *sentinel; |
| 8569 | IrInstSrc *sentinel; |
| 7539 | 8570 | if (sentinel_expr != nullptr) { |
| 7540 | 8571 | sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope); |
| 7541 | | if (sentinel == irb->codegen->invalid_instruction) |
| 8572 | if (sentinel == irb->codegen->invalid_inst_src) |
| 7542 | 8573 | return sentinel; |
| 7543 | 8574 | } else { |
| 7544 | 8575 | sentinel = nullptr; |
| ... | ... | @@ -7547,42 +8578,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7547 | 8578 | if (size_node) { |
| 7548 | 8579 | if (is_const) { |
| 7549 | 8580 | add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type")); |
| 7550 | | return irb->codegen->invalid_instruction; |
| 8581 | return irb->codegen->invalid_inst_src; |
| 7551 | 8582 | } |
| 7552 | 8583 | if (is_volatile) { |
| 7553 | 8584 | add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); |
| 7554 | | return irb->codegen->invalid_instruction; |
| 8585 | return irb->codegen->invalid_inst_src; |
| 7555 | 8586 | } |
| 7556 | 8587 | if (is_allow_zero) { |
| 7557 | 8588 | add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type")); |
| 7558 | | return irb->codegen->invalid_instruction; |
| 8589 | return irb->codegen->invalid_inst_src; |
| 7559 | 8590 | } |
| 7560 | 8591 | if (align_expr != nullptr) { |
| 7561 | 8592 | add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type")); |
| 7562 | | return irb->codegen->invalid_instruction; |
| 8593 | return irb->codegen->invalid_inst_src; |
| 7563 | 8594 | } |
| 7564 | 8595 | |
| 7565 | | IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope); |
| 7566 | | if (size_value == irb->codegen->invalid_instruction) |
| 8596 | IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope); |
| 8597 | if (size_value == irb->codegen->invalid_inst_src) |
| 7567 | 8598 | return size_value; |
| 7568 | 8599 | |
| 7569 | | IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 7570 | | if (child_type == irb->codegen->invalid_instruction) |
| 8600 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 8601 | if (child_type == irb->codegen->invalid_inst_src) |
| 7571 | 8602 | return child_type; |
| 7572 | 8603 | |
| 7573 | 8604 | return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type); |
| 7574 | 8605 | } else { |
| 7575 | | IrInstruction *align_value; |
| 8606 | IrInstSrc *align_value; |
| 7576 | 8607 | if (align_expr != nullptr) { |
| 7577 | 8608 | align_value = ir_gen_node(irb, align_expr, comptime_scope); |
| 7578 | | if (align_value == irb->codegen->invalid_instruction) |
| 8609 | if (align_value == irb->codegen->invalid_inst_src) |
| 7579 | 8610 | return align_value; |
| 7580 | 8611 | } else { |
| 7581 | 8612 | align_value = nullptr; |
| 7582 | 8613 | } |
| 7583 | 8614 | |
| 7584 | | IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 7585 | | if (child_type == irb->codegen->invalid_instruction) |
| 8615 | IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope); |
| 8616 | if (child_type == irb->codegen->invalid_inst_src) |
| 7586 | 8617 | return child_type; |
| 7587 | 8618 | |
| 7588 | 8619 | return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel, |
| ... | ... | @@ -7590,15 +8621,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 7590 | 8621 | } |
| 7591 | 8622 | } |
| 7592 | 8623 | |
| 7593 | | static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8624 | static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7594 | 8625 | assert(node->type == NodeTypeAnyFrameType); |
| 7595 | 8626 | |
| 7596 | 8627 | AstNode *payload_type_node = node->data.anyframe_type.payload_type; |
| 7597 | | IrInstruction *payload_type_value = nullptr; |
| 8628 | IrInstSrc *payload_type_value = nullptr; |
| 7598 | 8629 | |
| 7599 | 8630 | if (payload_type_node != nullptr) { |
| 7600 | 8631 | payload_type_value = ir_gen_node(irb, payload_type_node, scope); |
| 7601 | | if (payload_type_value == irb->codegen->invalid_instruction) |
| 8632 | if (payload_type_value == irb->codegen->invalid_inst_src) |
| 7602 | 8633 | return payload_type_value; |
| 7603 | 8634 | |
| 7604 | 8635 | } |
| ... | ... | @@ -7606,7 +8637,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode |
| 7606 | 8637 | return ir_build_anyframe_type(irb, scope, node, payload_type_value); |
| 7607 | 8638 | } |
| 7608 | 8639 | |
| 7609 | | static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8640 | static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7610 | 8641 | assert(node->type == NodeTypeUndefinedLiteral); |
| 7611 | 8642 | return ir_build_const_undefined(irb, scope, node); |
| 7612 | 8643 | } |
| ... | ... | @@ -7723,13 +8754,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_ |
| 7723 | 8754 | return SIZE_MAX; |
| 7724 | 8755 | } |
| 7725 | 8756 | |
| 7726 | | static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 8757 | static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 7727 | 8758 | assert(node->type == NodeTypeAsmExpr); |
| 7728 | 8759 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; |
| 7729 | 8760 | |
| 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; |
| 8761 | IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope); |
| 8762 | if (asm_template == irb->codegen->invalid_inst_src) |
| 8763 | return irb->codegen->invalid_inst_src; |
| 7733 | 8764 | |
| 7734 | 8765 | bool is_volatile = asm_expr->volatile_token != nullptr; |
| 7735 | 8766 | bool in_fn_scope = (scope_fn_entry(scope) != nullptr); |
| ... | ... | @@ -7738,7 +8769,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7738 | 8769 | if (is_volatile) { |
| 7739 | 8770 | add_token_error(irb->codegen, node->owner, asm_expr->volatile_token, |
| 7740 | 8771 | buf_sprintf("volatile is meaningless on global assembly")); |
| 7741 | | return irb->codegen->invalid_instruction; |
| 8772 | return irb->codegen->invalid_inst_src; |
| 7742 | 8773 | } |
| 7743 | 8774 | |
| 7744 | 8775 | if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 || |
| ... | ... | @@ -7746,34 +8777,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7746 | 8777 | { |
| 7747 | 8778 | add_node_error(irb->codegen, node, |
| 7748 | 8779 | buf_sprintf("global assembly cannot have inputs, outputs, or clobbers")); |
| 7749 | | return irb->codegen->invalid_instruction; |
| 8780 | return irb->codegen->invalid_inst_src; |
| 7750 | 8781 | } |
| 7751 | 8782 | |
| 7752 | 8783 | return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr, |
| 7753 | 8784 | nullptr, 0, is_volatile, true); |
| 7754 | 8785 | } |
| 7755 | 8786 | |
| 7756 | | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 7757 | | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); |
| 8787 | IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length); |
| 8788 | IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length); |
| 7758 | 8789 | ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length); |
| 7759 | 8790 | size_t return_count = 0; |
| 7760 | 8791 | if (!is_volatile && asm_expr->output_list.length == 0) { |
| 7761 | 8792 | add_node_error(irb->codegen, node, |
| 7762 | 8793 | buf_sprintf("assembly expression with no output must be marked volatile")); |
| 7763 | | return irb->codegen->invalid_instruction; |
| 8794 | return irb->codegen->invalid_inst_src; |
| 7764 | 8795 | } |
| 7765 | 8796 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 7766 | 8797 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 7767 | 8798 | if (asm_output->return_type) { |
| 7768 | 8799 | return_count += 1; |
| 7769 | 8800 | |
| 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; |
| 8801 | IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope); |
| 8802 | if (return_type == irb->codegen->invalid_inst_src) |
| 8803 | return irb->codegen->invalid_inst_src; |
| 7773 | 8804 | if (return_count > 1) { |
| 7774 | 8805 | add_node_error(irb->codegen, node, |
| 7775 | 8806 | buf_sprintf("inline assembly allows up to one output value")); |
| 7776 | | return irb->codegen->invalid_instruction; |
| 8807 | return irb->codegen->invalid_inst_src; |
| 7777 | 8808 | } |
| 7778 | 8809 | output_types[i] = return_type; |
| 7779 | 8810 | } else { |
| ... | ... | @@ -7786,7 +8817,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7786 | 8817 | } else { |
| 7787 | 8818 | add_node_error(irb->codegen, node, |
| 7788 | 8819 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); |
| 7789 | | return irb->codegen->invalid_instruction; |
| 8820 | return irb->codegen->invalid_inst_src; |
| 7790 | 8821 | } |
| 7791 | 8822 | } |
| 7792 | 8823 | |
| ... | ... | @@ -7796,14 +8827,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7796 | 8827 | buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported." |
| 7797 | 8828 | " Compiler TODO: see https://github.com/ziglang/zig/issues/215", |
| 7798 | 8829 | buf_ptr(asm_output->asm_symbolic_name), modifier)); |
| 7799 | | return irb->codegen->invalid_instruction; |
| 8830 | return irb->codegen->invalid_inst_src; |
| 7800 | 8831 | } |
| 7801 | 8832 | } |
| 7802 | 8833 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 7803 | 8834 | 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; |
| 8835 | IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope); |
| 8836 | if (input_value == irb->codegen->invalid_inst_src) |
| 8837 | return irb->codegen->invalid_inst_src; |
| 7807 | 8838 | |
| 7808 | 8839 | input_list[i] = input_value; |
| 7809 | 8840 | } |
| ... | ... | @@ -7812,7 +8843,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 7812 | 8843 | output_vars, return_count, is_volatile, false); |
| 7813 | 8844 | } |
| 7814 | 8845 | |
| 7815 | | static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8846 | static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7816 | 8847 | ResultLoc *result_loc) |
| 7817 | 8848 | { |
| 7818 | 8849 | assert(node->type == NodeTypeIfOptional); |
| ... | ... | @@ -7823,24 +8854,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 7823 | 8854 | AstNode *else_node = node->data.test_expr.else_node; |
| 7824 | 8855 | bool var_is_ptr = node->data.test_expr.var_is_ptr; |
| 7825 | 8856 | |
| 7826 | | IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 7827 | | if (maybe_val_ptr == irb->codegen->invalid_instruction) |
| 8857 | IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 8858 | if (maybe_val_ptr == irb->codegen->invalid_inst_src) |
| 7828 | 8859 | return maybe_val_ptr; |
| 7829 | 8860 | |
| 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); |
| 8861 | IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr); |
| 8862 | IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val); |
| 7832 | 8863 | |
| 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"); |
| 8864 | IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen"); |
| 8865 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse"); |
| 8866 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf"); |
| 7836 | 8867 | |
| 7837 | | IrInstruction *is_comptime; |
| 8868 | IrInstSrc *is_comptime; |
| 7838 | 8869 | if (ir_should_inline(irb->exec, scope)) { |
| 7839 | 8870 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 7840 | 8871 | } else { |
| 7841 | 8872 | is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null); |
| 7842 | 8873 | } |
| 7843 | | IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 8874 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null, |
| 7844 | 8875 | then_block, else_block, is_comptime); |
| 7845 | 8876 | |
| 7846 | 8877 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| ... | ... | @@ -7856,48 +8887,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN |
| 7856 | 8887 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7857 | 8888 | var_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 7858 | 8889 | |
| 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; |
| 8890 | IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false); |
| 8891 | IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 7861 | 8892 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr); |
| 7862 | 8893 | var_scope = var->child_scope; |
| 7863 | 8894 | } else { |
| 7864 | 8895 | var_scope = subexpr_scope; |
| 7865 | 8896 | } |
| 7866 | | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 8897 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 7867 | 8898 | &peer_parent->peers.at(0)->base); |
| 7868 | | if (then_expr_result == irb->codegen->invalid_instruction) |
| 8899 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7869 | 8900 | return then_expr_result; |
| 7870 | | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 8901 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 7871 | 8902 | if (!instr_is_unreachable(then_expr_result)) |
| 7872 | 8903 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7873 | 8904 | |
| 7874 | 8905 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7875 | | IrInstruction *else_expr_result; |
| 8906 | IrInstSrc *else_expr_result; |
| 7876 | 8907 | if (else_node) { |
| 7877 | 8908 | 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) |
| 8909 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7879 | 8910 | return else_expr_result; |
| 7880 | 8911 | } else { |
| 7881 | 8912 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 7882 | 8913 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 7883 | 8914 | } |
| 7884 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 8915 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7885 | 8916 | if (!instr_is_unreachable(else_expr_result)) |
| 7886 | 8917 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7887 | 8918 | |
| 7888 | 8919 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 7889 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 8920 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 7890 | 8921 | incoming_values[0] = then_expr_result; |
| 7891 | 8922 | incoming_values[1] = else_expr_result; |
| 7892 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 8923 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 7893 | 8924 | incoming_blocks[0] = after_then_block; |
| 7894 | 8925 | incoming_blocks[1] = after_else_block; |
| 7895 | 8926 | |
| 7896 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 8927 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7897 | 8928 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7898 | 8929 | } |
| 7899 | 8930 | |
| 7900 | | static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 8931 | static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 7901 | 8932 | ResultLoc *result_loc) |
| 7902 | 8933 | { |
| 7903 | 8934 | assert(node->type == NodeTypeIfErrorExpr); |
| ... | ... | @@ -7910,20 +8941,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7910 | 8941 | Buf *var_symbol = node->data.if_err_expr.var_symbol; |
| 7911 | 8942 | Buf *err_symbol = node->data.if_err_expr.err_symbol; |
| 7912 | 8943 | |
| 7913 | | IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 7914 | | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 8944 | IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 8945 | if (err_val_ptr == irb->codegen->invalid_inst_src) |
| 7915 | 8946 | return err_val_ptr; |
| 7916 | 8947 | |
| 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); |
| 8948 | IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 8949 | IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false); |
| 7919 | 8950 | |
| 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"); |
| 8951 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk"); |
| 8952 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse"); |
| 8953 | IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd"); |
| 7923 | 8954 | |
| 7924 | 8955 | 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); |
| 8956 | IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err); |
| 8957 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime); |
| 7927 | 8958 | |
| 7928 | 8959 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block, |
| 7929 | 8960 | result_loc, is_comptime); |
| ... | ... | @@ -7934,29 +8965,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7934 | 8965 | Scope *var_scope; |
| 7935 | 8966 | if (var_symbol) { |
| 7936 | 8967 | 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); |
| 8968 | 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 | 8969 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7939 | 8970 | var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); |
| 7940 | 8971 | |
| 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; |
| 8972 | IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false); |
| 8973 | IrInstSrc *var_ptr = var_is_ptr ? |
| 8974 | ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr; |
| 7944 | 8975 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr); |
| 7945 | 8976 | var_scope = var->child_scope; |
| 7946 | 8977 | } else { |
| 7947 | 8978 | var_scope = subexpr_scope; |
| 7948 | 8979 | } |
| 7949 | | IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 8980 | IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval, |
| 7950 | 8981 | &peer_parent->peers.at(0)->base); |
| 7951 | | if (then_expr_result == irb->codegen->invalid_instruction) |
| 8982 | if (then_expr_result == irb->codegen->invalid_inst_src) |
| 7952 | 8983 | return then_expr_result; |
| 7953 | | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 8984 | IrBasicBlockSrc *after_then_block = irb->current_basic_block; |
| 7954 | 8985 | if (!instr_is_unreachable(then_expr_result)) |
| 7955 | 8986 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7956 | 8987 | |
| 7957 | 8988 | ir_set_cursor_at_end_and_append_block(irb, else_block); |
| 7958 | 8989 | |
| 7959 | | IrInstruction *else_expr_result; |
| 8990 | IrInstSrc *else_expr_result; |
| 7960 | 8991 | if (else_node) { |
| 7961 | 8992 | Scope *err_var_scope; |
| 7962 | 8993 | if (err_symbol) { |
| ... | ... | @@ -7965,40 +8996,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 7965 | 8996 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, |
| 7966 | 8997 | err_symbol, is_const, is_const, is_shadowable, is_comptime); |
| 7967 | 8998 | |
| 7968 | | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); |
| 8999 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr); |
| 7969 | 9000 | ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr); |
| 7970 | 9001 | err_var_scope = var->child_scope; |
| 7971 | 9002 | } else { |
| 7972 | 9003 | err_var_scope = subexpr_scope; |
| 7973 | 9004 | } |
| 7974 | 9005 | 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) |
| 9006 | if (else_expr_result == irb->codegen->invalid_inst_src) |
| 7976 | 9007 | return else_expr_result; |
| 7977 | 9008 | } else { |
| 7978 | 9009 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 7979 | 9010 | ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base); |
| 7980 | 9011 | } |
| 7981 | | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 9012 | IrBasicBlockSrc *after_else_block = irb->current_basic_block; |
| 7982 | 9013 | if (!instr_is_unreachable(else_expr_result)) |
| 7983 | 9014 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 7984 | 9015 | |
| 7985 | 9016 | ir_set_cursor_at_end_and_append_block(irb, endif_block); |
| 7986 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 9017 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 7987 | 9018 | incoming_values[0] = then_expr_result; |
| 7988 | 9019 | incoming_values[1] = else_expr_result; |
| 7989 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 9020 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 7990 | 9021 | incoming_blocks[0] = after_then_block; |
| 7991 | 9022 | incoming_blocks[1] = after_else_block; |
| 7992 | 9023 | |
| 7993 | | IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 9024 | IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7994 | 9025 | return ir_expr_wrap(irb, scope, phi, result_loc); |
| 7995 | 9026 | } |
| 7996 | 9027 | |
| 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) |
| 9028 | static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node, |
| 9029 | IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime, |
| 9030 | IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len, |
| 9031 | ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values, |
| 9032 | IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc) |
| 8002 | 9033 | { |
| 8003 | 9034 | assert(switch_node->type == NodeTypeSwitchExpr); |
| 8004 | 9035 | assert(prong_node->type == NodeTypeSwitchProng); |
| ... | ... | @@ -8016,28 +9047,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 8016 | 9047 | ZigVar *var = ir_create_var(irb, var_symbol_node, scope, |
| 8017 | 9048 | var_name, is_const, is_const, is_shadowable, var_is_comptime); |
| 8018 | 9049 | child_scope = var->child_scope; |
| 8019 | | IrInstruction *var_ptr; |
| 9050 | IrInstSrc *var_ptr; |
| 8020 | 9051 | if (out_switch_else_var != nullptr) { |
| 8021 | | IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node, |
| 9052 | IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node, |
| 8022 | 9053 | target_value_ptr); |
| 8023 | 9054 | *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; |
| 9055 | IrInstSrc *payload_ptr = &switch_else_var->base; |
| 9056 | var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8026 | 9057 | } else if (prong_values != nullptr) { |
| 8027 | | IrInstruction *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, |
| 9058 | IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, |
| 8028 | 9059 | 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; |
| 9060 | var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr; |
| 8030 | 9061 | } else { |
| 8031 | 9062 | var_ptr = var_is_ptr ? |
| 8032 | | ir_build_ref(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr; |
| 9063 | ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr; |
| 8033 | 9064 | } |
| 8034 | 9065 | ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr); |
| 8035 | 9066 | } else { |
| 8036 | 9067 | child_scope = scope; |
| 8037 | 9068 | } |
| 8038 | 9069 | |
| 8039 | | IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc); |
| 8040 | | if (expr_result == irb->codegen->invalid_instruction) |
| 9070 | IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc); |
| 9071 | if (expr_result == irb->codegen->invalid_inst_src) |
| 8041 | 9072 | return false; |
| 8042 | 9073 | if (!instr_is_unreachable(expr_result)) |
| 8043 | 9074 | ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime)); |
| ... | ... | @@ -8046,25 +9077,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 8046 | 9077 | return true; |
| 8047 | 9078 | } |
| 8048 | 9079 | |
| 8049 | | static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 9080 | static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 8050 | 9081 | ResultLoc *result_loc) |
| 8051 | 9082 | { |
| 8052 | 9083 | assert(node->type == NodeTypeSwitchExpr); |
| 8053 | 9084 | |
| 8054 | 9085 | 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) |
| 9086 | IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr); |
| 9087 | if (target_value_ptr == irb->codegen->invalid_inst_src) |
| 8057 | 9088 | return target_value_ptr; |
| 8058 | | IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 9089 | IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 8059 | 9090 | |
| 8060 | | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); |
| 8061 | | IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); |
| 9091 | IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse"); |
| 9092 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd"); |
| 8062 | 9093 | |
| 8063 | 9094 | size_t prong_count = node->data.switch_expr.prongs.length; |
| 8064 | | ZigList<IrInstructionSwitchBrCase> cases = {0}; |
| 9095 | ZigList<IrInstSrcSwitchBrCase> cases = {0}; |
| 8065 | 9096 | |
| 8066 | | IrInstruction *is_comptime; |
| 8067 | | IrInstruction *var_is_comptime; |
| 9097 | IrInstSrc *is_comptime; |
| 9098 | IrInstSrc *var_is_comptime; |
| 8068 | 9099 | if (ir_should_inline(irb->exec, scope)) { |
| 8069 | 9100 | is_comptime = ir_build_const_bool(irb, scope, node, true); |
| 8070 | 9101 | var_is_comptime = is_comptime; |
| ... | ... | @@ -8073,11 +9104,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8073 | 9104 | var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr); |
| 8074 | 9105 | } |
| 8075 | 9106 | |
| 8076 | | ZigList<IrInstruction *> incoming_values = {0}; |
| 8077 | | ZigList<IrBasicBlock *> incoming_blocks = {0}; |
| 8078 | | ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0}; |
| 9107 | ZigList<IrInstSrc *> incoming_values = {0}; |
| 9108 | ZigList<IrBasicBlockSrc *> incoming_blocks = {0}; |
| 9109 | ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0}; |
| 8079 | 9110 | |
| 8080 | | IrInstructionSwitchElseVar *switch_else_var = nullptr; |
| 9111 | IrInstSrcSwitchElseVar *switch_else_var = nullptr; |
| 8081 | 9112 | |
| 8082 | 9113 | ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1); |
| 8083 | 9114 | peer_parent->base.id = ResultLocIdPeerParent; |
| ... | ... | @@ -8099,7 +9130,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8099 | 9130 | if (prong_node->data.switch_prong.any_items_are_range) { |
| 8100 | 9131 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8101 | 9132 | |
| 8102 | | IrInstruction *ok_bit = nullptr; |
| 9133 | IrInstSrc *ok_bit = nullptr; |
| 8103 | 9134 | AstNode *last_item_node = nullptr; |
| 8104 | 9135 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 8105 | 9136 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| ... | ... | @@ -8108,23 +9139,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8108 | 9139 | AstNode *start_node = item_node->data.switch_range.start; |
| 8109 | 9140 | AstNode *end_node = item_node->data.switch_range.end; |
| 8110 | 9141 | |
| 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; |
| 9142 | IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope); |
| 9143 | if (start_value == irb->codegen->invalid_inst_src) |
| 9144 | return irb->codegen->invalid_inst_src; |
| 8114 | 9145 | |
| 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; |
| 9146 | IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope); |
| 9147 | if (end_value == irb->codegen->invalid_inst_src) |
| 9148 | return irb->codegen->invalid_inst_src; |
| 8118 | 9149 | |
| 8119 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9150 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8120 | 9151 | check_range->start = start_value; |
| 8121 | 9152 | check_range->end = end_value; |
| 8122 | 9153 | |
| 8123 | | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 9154 | IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 8124 | 9155 | target_value, start_value, false); |
| 8125 | | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 9156 | IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 8126 | 9157 | target_value, end_value, false); |
| 8127 | | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 9158 | IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 8128 | 9159 | lower_range_ok, upper_range_ok, false); |
| 8129 | 9160 | if (ok_bit) { |
| 8130 | 9161 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false); |
| ... | ... | @@ -8132,15 +9163,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8132 | 9163 | ok_bit = both_ok; |
| 8133 | 9164 | } |
| 8134 | 9165 | } 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; |
| 9166 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 9167 | if (item_value == irb->codegen->invalid_inst_src) |
| 9168 | return irb->codegen->invalid_inst_src; |
| 8138 | 9169 | |
| 8139 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9170 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8140 | 9171 | check_range->start = item_value; |
| 8141 | 9172 | check_range->end = item_value; |
| 8142 | 9173 | |
| 8143 | | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 9174 | IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 8144 | 9175 | item_value, target_value, false); |
| 8145 | 9176 | if (ok_bit) { |
| 8146 | 9177 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false); |
| ... | ... | @@ -8150,12 +9181,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8150 | 9181 | } |
| 8151 | 9182 | } |
| 8152 | 9183 | |
| 8153 | | IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); |
| 8154 | | IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); |
| 9184 | IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes"); |
| 9185 | IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo"); |
| 8155 | 9186 | |
| 8156 | 9187 | assert(ok_bit); |
| 8157 | 9188 | assert(last_item_node); |
| 8158 | | IrInstruction *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, |
| 9189 | IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit, |
| 8159 | 9190 | range_block_yes, range_block_no, is_comptime)); |
| 8160 | 9191 | if (peer_parent->base.source_instruction == nullptr) { |
| 8161 | 9192 | peer_parent->base.source_instruction = br_inst; |
| ... | ... | @@ -8170,7 +9201,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8170 | 9201 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, |
| 8171 | 9202 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 8172 | 9203 | { |
| 8173 | | return irb->codegen->invalid_instruction; |
| 9204 | return irb->codegen->invalid_inst_src; |
| 8174 | 9205 | } |
| 8175 | 9206 | |
| 8176 | 9207 | ir_set_cursor_at_end_and_append_block(irb, range_block_no); |
| ... | ... | @@ -8181,7 +9212,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8181 | 9212 | buf_sprintf("multiple else prongs in switch expression")); |
| 8182 | 9213 | add_error_note(irb->codegen, msg, else_prong, |
| 8183 | 9214 | buf_sprintf("previous else prong is here")); |
| 8184 | | return irb->codegen->invalid_instruction; |
| 9215 | return irb->codegen->invalid_inst_src; |
| 8185 | 9216 | } |
| 8186 | 9217 | else_prong = prong_node; |
| 8187 | 9218 | } else if (prong_item_count == 1 && |
| ... | ... | @@ -8192,7 +9223,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8192 | 9223 | buf_sprintf("multiple '_' prongs in switch expression")); |
| 8193 | 9224 | add_error_note(irb->codegen, msg, underscore_prong, |
| 8194 | 9225 | buf_sprintf("previous '_' prong is here")); |
| 8195 | | return irb->codegen->invalid_instruction; |
| 9226 | return irb->codegen->invalid_inst_src; |
| 8196 | 9227 | } |
| 8197 | 9228 | underscore_prong = prong_node; |
| 8198 | 9229 | } else { |
| ... | ... | @@ -8207,11 +9238,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8207 | 9238 | else |
| 8208 | 9239 | add_error_note(irb->codegen, msg, underscore_prong, |
| 8209 | 9240 | buf_sprintf("'_' prong is here")); |
| 8210 | | return irb->codegen->invalid_instruction; |
| 9241 | return irb->codegen->invalid_inst_src; |
| 8211 | 9242 | } |
| 8212 | 9243 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8213 | 9244 | |
| 8214 | | IrBasicBlock *prev_block = irb->current_basic_block; |
| 9245 | IrBasicBlockSrc *prev_block = irb->current_basic_block; |
| 8215 | 9246 | if (peer_parent->peers.length > 0) { |
| 8216 | 9247 | peer_parent->peers.last()->next_bb = else_block; |
| 8217 | 9248 | } |
| ... | ... | @@ -8221,7 +9252,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8221 | 9252 | is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values, |
| 8222 | 9253 | &switch_else_var, LValNone, &this_peer_result_loc->base)) |
| 8223 | 9254 | { |
| 8224 | | return irb->codegen->invalid_instruction; |
| 9255 | return irb->codegen->invalid_inst_src; |
| 8225 | 9256 | } |
| 8226 | 9257 | ir_set_cursor_at_end(irb, prev_block); |
| 8227 | 9258 | } |
| ... | ... | @@ -8240,29 +9271,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8240 | 9271 | |
| 8241 | 9272 | ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent); |
| 8242 | 9273 | |
| 8243 | | IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); |
| 8244 | | IrInstruction **items = allocate<IrInstruction *>(prong_item_count); |
| 9274 | IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng"); |
| 9275 | IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count); |
| 8245 | 9276 | |
| 8246 | 9277 | for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) { |
| 8247 | 9278 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 8248 | 9279 | assert(item_node->type != NodeTypeSwitchRange); |
| 8249 | 9280 | |
| 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; |
| 9281 | IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope); |
| 9282 | if (item_value == irb->codegen->invalid_inst_src) |
| 9283 | return irb->codegen->invalid_inst_src; |
| 8253 | 9284 | |
| 8254 | | IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 9285 | IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one(); |
| 8255 | 9286 | check_range->start = item_value; |
| 8256 | 9287 | check_range->end = item_value; |
| 8257 | 9288 | |
| 8258 | | IrInstructionSwitchBrCase *this_case = cases.add_one(); |
| 9289 | IrInstSrcSwitchBrCase *this_case = cases.add_one(); |
| 8259 | 9290 | this_case->value = item_value; |
| 8260 | 9291 | this_case->block = prong_block; |
| 8261 | 9292 | |
| 8262 | 9293 | items[item_i] = item_value; |
| 8263 | 9294 | } |
| 8264 | 9295 | |
| 8265 | | IrBasicBlock *prev_block = irb->current_basic_block; |
| 9296 | IrBasicBlockSrc *prev_block = irb->current_basic_block; |
| 8266 | 9297 | if (peer_parent->peers.length > 0) { |
| 8267 | 9298 | peer_parent->peers.last()->next_bb = prong_block; |
| 8268 | 9299 | } |
| ... | ... | @@ -8272,21 +9303,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8272 | 9303 | is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count, |
| 8273 | 9304 | &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base)) |
| 8274 | 9305 | { |
| 8275 | | return irb->codegen->invalid_instruction; |
| 9306 | return irb->codegen->invalid_inst_src; |
| 8276 | 9307 | } |
| 8277 | 9308 | |
| 8278 | 9309 | ir_set_cursor_at_end(irb, prev_block); |
| 8279 | 9310 | |
| 8280 | 9311 | } |
| 8281 | 9312 | |
| 8282 | | IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, |
| 9313 | IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value, |
| 8283 | 9314 | check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr); |
| 8284 | 9315 | |
| 8285 | | IrInstruction *br_instruction; |
| 9316 | IrInstSrc *br_instruction; |
| 8286 | 9317 | if (cases.length == 0) { |
| 8287 | 9318 | br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime); |
| 8288 | 9319 | } else { |
| 8289 | | IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, scope, node, target_value, else_block, |
| 9320 | IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block, |
| 8290 | 9321 | cases.length, cases.items, is_comptime, switch_prongs_void); |
| 8291 | 9322 | if (switch_else_var != nullptr) { |
| 8292 | 9323 | switch_else_var->switch_br = switch_br; |
| ... | ... | @@ -8314,7 +9345,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8314 | 9345 | |
| 8315 | 9346 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 8316 | 9347 | assert(incoming_blocks.length == incoming_values.length); |
| 8317 | | IrInstruction *result_instruction; |
| 9348 | IrInstSrc *result_instruction; |
| 8318 | 9349 | if (incoming_blocks.length == 0) { |
| 8319 | 9350 | result_instruction = ir_build_const_void(irb, scope, node); |
| 8320 | 9351 | } else { |
| ... | ... | @@ -8324,7 +9355,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 8324 | 9355 | return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc); |
| 8325 | 9356 | } |
| 8326 | 9357 | |
| 8327 | | static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) { |
| 9358 | static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) { |
| 8328 | 9359 | assert(node->type == NodeTypeCompTime); |
| 8329 | 9360 | |
| 8330 | 9361 | Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope); |
| ... | ... | @@ -8332,28 +9363,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo |
| 8332 | 9363 | return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr); |
| 8333 | 9364 | } |
| 8334 | 9365 | |
| 8335 | | static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { |
| 8336 | | IrInstruction *is_comptime; |
| 9366 | static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) { |
| 9367 | IrInstSrc *is_comptime; |
| 8337 | 9368 | if (ir_should_inline(irb->exec, break_scope)) { |
| 8338 | 9369 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); |
| 8339 | 9370 | } else { |
| 8340 | 9371 | is_comptime = block_scope->is_comptime; |
| 8341 | 9372 | } |
| 8342 | 9373 | |
| 8343 | | IrInstruction *result_value; |
| 9374 | IrInstSrc *result_value; |
| 8344 | 9375 | if (node->data.break_expr.expr) { |
| 8345 | 9376 | ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent); |
| 8346 | 9377 | block_scope->peer_parent->peers.append(peer_result); |
| 8347 | 9378 | |
| 8348 | 9379 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval, |
| 8349 | 9380 | &peer_result->base); |
| 8350 | | if (result_value == irb->codegen->invalid_instruction) |
| 8351 | | return irb->codegen->invalid_instruction; |
| 9381 | if (result_value == irb->codegen->invalid_inst_src) |
| 9382 | return irb->codegen->invalid_inst_src; |
| 8352 | 9383 | } else { |
| 8353 | 9384 | result_value = ir_build_const_void(irb, break_scope, node); |
| 8354 | 9385 | } |
| 8355 | 9386 | |
| 8356 | | IrBasicBlock *dest_block = block_scope->end_block; |
| 9387 | IrBasicBlockSrc *dest_block = block_scope->end_block; |
| 8357 | 9388 | ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false); |
| 8358 | 9389 | |
| 8359 | 9390 | block_scope->incoming_blocks->append(irb->current_basic_block); |
| ... | ... | @@ -8361,7 +9392,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop |
| 8361 | 9392 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); |
| 8362 | 9393 | } |
| 8363 | 9394 | |
| 8364 | | static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) { |
| 9395 | static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) { |
| 8365 | 9396 | assert(node->type == NodeTypeBreak); |
| 8366 | 9397 | |
| 8367 | 9398 | // Search up the scope. We'll find one of these things first: |
| ... | ... | @@ -8376,14 +9407,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8376 | 9407 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 8377 | 9408 | if (node->data.break_expr.name != nullptr) { |
| 8378 | 9409 | 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; |
| 9410 | return irb->codegen->invalid_inst_src; |
| 8380 | 9411 | } else { |
| 8381 | 9412 | add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop")); |
| 8382 | | return irb->codegen->invalid_instruction; |
| 9413 | return irb->codegen->invalid_inst_src; |
| 8383 | 9414 | } |
| 8384 | 9415 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 8385 | 9416 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression")); |
| 8386 | | return irb->codegen->invalid_instruction; |
| 9417 | return irb->codegen->invalid_inst_src; |
| 8387 | 9418 | } else if (search_scope->id == ScopeIdLoop) { |
| 8388 | 9419 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 8389 | 9420 | if (node->data.break_expr.name == nullptr || |
| ... | ... | @@ -8402,32 +9433,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8402 | 9433 | } |
| 8403 | 9434 | } else if (search_scope->id == ScopeIdSuspend) { |
| 8404 | 9435 | add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block")); |
| 8405 | | return irb->codegen->invalid_instruction; |
| 9436 | return irb->codegen->invalid_inst_src; |
| 8406 | 9437 | } |
| 8407 | 9438 | search_scope = search_scope->parent; |
| 8408 | 9439 | } |
| 8409 | 9440 | |
| 8410 | | IrInstruction *is_comptime; |
| 9441 | IrInstSrc *is_comptime; |
| 8411 | 9442 | if (ir_should_inline(irb->exec, break_scope)) { |
| 8412 | 9443 | is_comptime = ir_build_const_bool(irb, break_scope, node, true); |
| 8413 | 9444 | } else { |
| 8414 | 9445 | is_comptime = loop_scope->is_comptime; |
| 8415 | 9446 | } |
| 8416 | 9447 | |
| 8417 | | IrInstruction *result_value; |
| 9448 | IrInstSrc *result_value; |
| 8418 | 9449 | if (node->data.break_expr.expr) { |
| 8419 | 9450 | ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent); |
| 8420 | 9451 | loop_scope->peer_parent->peers.append(peer_result); |
| 8421 | 9452 | |
| 8422 | 9453 | result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, |
| 8423 | 9454 | loop_scope->lval, &peer_result->base); |
| 8424 | | if (result_value == irb->codegen->invalid_instruction) |
| 8425 | | return irb->codegen->invalid_instruction; |
| 9455 | if (result_value == irb->codegen->invalid_inst_src) |
| 9456 | return irb->codegen->invalid_inst_src; |
| 8426 | 9457 | } else { |
| 8427 | 9458 | result_value = ir_build_const_void(irb, break_scope, node); |
| 8428 | 9459 | } |
| 8429 | 9460 | |
| 8430 | | IrBasicBlock *dest_block = loop_scope->break_block; |
| 9461 | IrBasicBlockSrc *dest_block = loop_scope->break_block; |
| 8431 | 9462 | ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false); |
| 8432 | 9463 | |
| 8433 | 9464 | loop_scope->incoming_blocks->append(irb->current_basic_block); |
| ... | ... | @@ -8435,7 +9466,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode * |
| 8435 | 9466 | return ir_build_br(irb, break_scope, node, dest_block, is_comptime); |
| 8436 | 9467 | } |
| 8437 | 9468 | |
| 8438 | | static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, AstNode *node) { |
| 9469 | static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) { |
| 8439 | 9470 | assert(node->type == NodeTypeContinue); |
| 8440 | 9471 | |
| 8441 | 9472 | // Search up the scope. We'll find one of these things first: |
| ... | ... | @@ -8451,14 +9482,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8451 | 9482 | if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) { |
| 8452 | 9483 | if (node->data.continue_expr.name != nullptr) { |
| 8453 | 9484 | 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; |
| 9485 | return irb->codegen->invalid_inst_src; |
| 8455 | 9486 | } else { |
| 8456 | 9487 | add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop")); |
| 8457 | | return irb->codegen->invalid_instruction; |
| 9488 | return irb->codegen->invalid_inst_src; |
| 8458 | 9489 | } |
| 8459 | 9490 | } else if (search_scope->id == ScopeIdDeferExpr) { |
| 8460 | 9491 | add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression")); |
| 8461 | | return irb->codegen->invalid_instruction; |
| 9492 | return irb->codegen->invalid_inst_src; |
| 8462 | 9493 | } else if (search_scope->id == ScopeIdLoop) { |
| 8463 | 9494 | ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope; |
| 8464 | 9495 | if (node->data.continue_expr.name == nullptr || |
| ... | ... | @@ -8474,7 +9505,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8474 | 9505 | search_scope = search_scope->parent; |
| 8475 | 9506 | } |
| 8476 | 9507 | |
| 8477 | | IrInstruction *is_comptime; |
| 9508 | IrInstSrc *is_comptime; |
| 8478 | 9509 | if (ir_should_inline(irb->exec, continue_scope)) { |
| 8479 | 9510 | is_comptime = ir_build_const_bool(irb, continue_scope, node, true); |
| 8480 | 9511 | } else { |
| ... | ... | @@ -8486,17 +9517,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast |
| 8486 | 9517 | ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime)); |
| 8487 | 9518 | } |
| 8488 | 9519 | |
| 8489 | | IrBasicBlock *dest_block = loop_scope->continue_block; |
| 9520 | IrBasicBlockSrc *dest_block = loop_scope->continue_block; |
| 8490 | 9521 | ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false); |
| 8491 | 9522 | return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime)); |
| 8492 | 9523 | } |
| 8493 | 9524 | |
| 8494 | | static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 9525 | static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 8495 | 9526 | assert(node->type == NodeTypeErrorType); |
| 8496 | 9527 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set); |
| 8497 | 9528 | } |
| 8498 | 9529 | |
| 8499 | | static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9530 | static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8500 | 9531 | assert(node->type == NodeTypeDefer); |
| 8501 | 9532 | |
| 8502 | 9533 | ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope); |
| ... | ... | @@ -8508,7 +9539,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8508 | 9539 | return ir_build_const_void(irb, parent_scope, node); |
| 8509 | 9540 | } |
| 8510 | 9541 | |
| 8511 | | static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 9542 | static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 8512 | 9543 | assert(node->type == NodeTypeSliceExpr); |
| 8513 | 9544 | |
| 8514 | 9545 | AstNodeSliceExpr *slice_expr = &node->data.slice_expr; |
| ... | ... | @@ -8517,38 +9548,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, |
| 8517 | 9548 | AstNode *end_node = slice_expr->end; |
| 8518 | 9549 | AstNode *sentinel_node = slice_expr->sentinel; |
| 8519 | 9550 | |
| 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; |
| 9551 | IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr); |
| 9552 | if (ptr_value == irb->codegen->invalid_inst_src) |
| 9553 | return irb->codegen->invalid_inst_src; |
| 8523 | 9554 | |
| 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; |
| 9555 | IrInstSrc *start_value = ir_gen_node(irb, start_node, scope); |
| 9556 | if (start_value == irb->codegen->invalid_inst_src) |
| 9557 | return irb->codegen->invalid_inst_src; |
| 8527 | 9558 | |
| 8528 | | IrInstruction *end_value; |
| 9559 | IrInstSrc *end_value; |
| 8529 | 9560 | if (end_node) { |
| 8530 | 9561 | end_value = ir_gen_node(irb, end_node, scope); |
| 8531 | | if (end_value == irb->codegen->invalid_instruction) |
| 8532 | | return irb->codegen->invalid_instruction; |
| 9562 | if (end_value == irb->codegen->invalid_inst_src) |
| 9563 | return irb->codegen->invalid_inst_src; |
| 8533 | 9564 | } else { |
| 8534 | 9565 | end_value = nullptr; |
| 8535 | 9566 | } |
| 8536 | 9567 | |
| 8537 | | IrInstruction *sentinel_value; |
| 9568 | IrInstSrc *sentinel_value; |
| 8538 | 9569 | if (sentinel_node) { |
| 8539 | 9570 | sentinel_value = ir_gen_node(irb, sentinel_node, scope); |
| 8540 | | if (sentinel_value == irb->codegen->invalid_instruction) |
| 8541 | | return irb->codegen->invalid_instruction; |
| 9571 | if (sentinel_value == irb->codegen->invalid_inst_src) |
| 9572 | return irb->codegen->invalid_inst_src; |
| 8542 | 9573 | } else { |
| 8543 | 9574 | sentinel_value = nullptr; |
| 8544 | 9575 | } |
| 8545 | 9576 | |
| 8546 | | IrInstruction *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value, |
| 9577 | IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value, |
| 8547 | 9578 | sentinel_value, true, result_loc); |
| 8548 | 9579 | return ir_lval_wrap(irb, scope, slice, lval, result_loc); |
| 8549 | 9580 | } |
| 8550 | 9581 | |
| 8551 | | static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 9582 | static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval, |
| 8552 | 9583 | ResultLoc *result_loc) |
| 8553 | 9584 | { |
| 8554 | 9585 | assert(node->type == NodeTypeCatchExpr); |
| ... | ... | @@ -8562,29 +9593,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8562 | 9593 | assert(var_node->type == NodeTypeSymbol); |
| 8563 | 9594 | Buf *var_name = var_node->data.symbol_expr.symbol; |
| 8564 | 9595 | add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name))); |
| 8565 | | return irb->codegen->invalid_instruction; |
| 9596 | return irb->codegen->invalid_inst_src; |
| 8566 | 9597 | } |
| 8567 | 9598 | return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc); |
| 8568 | 9599 | } |
| 8569 | 9600 | |
| 8570 | 9601 | |
| 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; |
| 9602 | IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr); |
| 9603 | if (err_union_ptr == irb->codegen->invalid_inst_src) |
| 9604 | return irb->codegen->invalid_inst_src; |
| 8574 | 9605 | |
| 8575 | | IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false); |
| 9606 | IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false); |
| 8576 | 9607 | |
| 8577 | | IrInstruction *is_comptime; |
| 9608 | IrInstSrc *is_comptime; |
| 8578 | 9609 | if (ir_should_inline(irb->exec, parent_scope)) { |
| 8579 | 9610 | is_comptime = ir_build_const_bool(irb, parent_scope, node, true); |
| 8580 | 9611 | } else { |
| 8581 | 9612 | is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err); |
| 8582 | 9613 | } |
| 8583 | 9614 | |
| 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); |
| 9615 | IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk"); |
| 9616 | IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError"); |
| 9617 | IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd"); |
| 9618 | IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime); |
| 8588 | 9619 | |
| 8589 | 9620 | ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc, |
| 8590 | 9621 | is_comptime); |
| ... | ... | @@ -8600,33 +9631,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 8600 | 9631 | ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name, |
| 8601 | 9632 | is_const, is_const, is_shadowable, is_comptime); |
| 8602 | 9633 | err_scope = var->child_scope; |
| 8603 | | IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); |
| 9634 | IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr); |
| 8604 | 9635 | ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr); |
| 8605 | 9636 | } else { |
| 8606 | 9637 | err_scope = subexpr_scope; |
| 8607 | 9638 | } |
| 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; |
| 9639 | IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base); |
| 9640 | if (err_result == irb->codegen->invalid_inst_src) |
| 9641 | return irb->codegen->invalid_inst_src; |
| 9642 | IrBasicBlockSrc *after_err_block = irb->current_basic_block; |
| 8612 | 9643 | if (!instr_is_unreachable(err_result)) |
| 8613 | 9644 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 8614 | 9645 | |
| 8615 | 9646 | 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); |
| 9647 | IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false); |
| 9648 | IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr); |
| 8618 | 9649 | 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; |
| 9650 | IrBasicBlockSrc *after_ok_block = irb->current_basic_block; |
| 8620 | 9651 | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 8621 | 9652 | |
| 8622 | 9653 | ir_set_cursor_at_end_and_append_block(irb, end_block); |
| 8623 | | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| 9654 | IrInstSrc **incoming_values = allocate<IrInstSrc *>(2); |
| 8624 | 9655 | incoming_values[0] = err_result; |
| 8625 | 9656 | incoming_values[1] = unwrapped_payload; |
| 8626 | | IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *"); |
| 9657 | IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *"); |
| 8627 | 9658 | incoming_blocks[0] = after_err_block; |
| 8628 | 9659 | incoming_blocks[1] = after_ok_block; |
| 8629 | | IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 9660 | IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 8630 | 9661 | return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc); |
| 8631 | 9662 | } |
| 8632 | 9663 | |
| ... | ... | @@ -8644,7 +9675,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o |
| 8644 | 9675 | return true; |
| 8645 | 9676 | } |
| 8646 | 9677 | |
| 8647 | | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, |
| 9678 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name, |
| 8648 | 9679 | Scope *scope, AstNode *source_node, Buf *out_bare_name) |
| 8649 | 9680 | { |
| 8650 | 9681 | if (exec != nullptr && exec->name) { |
| ... | ... | @@ -8673,7 +9704,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char |
| 8673 | 9704 | } |
| 8674 | 9705 | } |
| 8675 | 9706 | |
| 8676 | | static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9707 | static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8677 | 9708 | assert(node->type == NodeTypeContainerDecl); |
| 8678 | 9709 | |
| 8679 | 9710 | ContainerKind kind = node->data.container_decl.kind; |
| ... | ... | @@ -8798,7 +9829,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) { |
| 8798 | 9829 | } |
| 8799 | 9830 | } |
| 8800 | 9831 | |
| 8801 | | static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9832 | static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8802 | 9833 | assert(node->type == NodeTypeErrorSetDecl); |
| 8803 | 9834 | |
| 8804 | 9835 | uint32_t err_count = node->data.err_set_decl.decls.length; |
| ... | ... | @@ -8841,7 +9872,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 8841 | 9872 | buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name))); |
| 8842 | 9873 | add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node), |
| 8843 | 9874 | buf_sprintf("other error here")); |
| 8844 | | return irb->codegen->invalid_instruction; |
| 9875 | return irb->codegen->invalid_inst_src; |
| 8845 | 9876 | } |
| 8846 | 9877 | errors[err->value] = err; |
| 8847 | 9878 | } |
| ... | ... | @@ -8849,11 +9880,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 8849 | 9880 | return ir_build_const_type(irb, parent_scope, node, err_set_type); |
| 8850 | 9881 | } |
| 8851 | 9882 | |
| 8852 | | static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9883 | static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8853 | 9884 | assert(node->type == NodeTypeFnProto); |
| 8854 | 9885 | |
| 8855 | 9886 | size_t param_count = node->data.fn_proto.params.length; |
| 8856 | | IrInstruction **param_types = allocate<IrInstruction*>(param_count); |
| 9887 | IrInstSrc **param_types = allocate<IrInstSrc*>(param_count); |
| 8857 | 9888 | |
| 8858 | 9889 | bool is_var_args = false; |
| 8859 | 9890 | for (size_t i = 0; i < param_count; i += 1) { |
| ... | ... | @@ -8864,59 +9895,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 8864 | 9895 | } |
| 8865 | 9896 | if (param_node->data.param_decl.var_token == nullptr) { |
| 8866 | 9897 | 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; |
| 9898 | IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope); |
| 9899 | if (type_value == irb->codegen->invalid_inst_src) |
| 9900 | return irb->codegen->invalid_inst_src; |
| 8870 | 9901 | param_types[i] = type_value; |
| 8871 | 9902 | } else { |
| 8872 | 9903 | param_types[i] = nullptr; |
| 8873 | 9904 | } |
| 8874 | 9905 | } |
| 8875 | 9906 | |
| 8876 | | IrInstruction *align_value = nullptr; |
| 9907 | IrInstSrc *align_value = nullptr; |
| 8877 | 9908 | if (node->data.fn_proto.align_expr != nullptr) { |
| 8878 | 9909 | 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; |
| 9910 | if (align_value == irb->codegen->invalid_inst_src) |
| 9911 | return irb->codegen->invalid_inst_src; |
| 8881 | 9912 | } |
| 8882 | 9913 | |
| 8883 | | IrInstruction *callconv_value = nullptr; |
| 9914 | IrInstSrc *callconv_value = nullptr; |
| 8884 | 9915 | if (node->data.fn_proto.callconv_expr != nullptr) { |
| 8885 | 9916 | 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; |
| 9917 | if (callconv_value == irb->codegen->invalid_inst_src) |
| 9918 | return irb->codegen->invalid_inst_src; |
| 8888 | 9919 | } |
| 8889 | 9920 | |
| 8890 | | IrInstruction *return_type; |
| 9921 | IrInstSrc *return_type; |
| 8891 | 9922 | if (node->data.fn_proto.return_var_token == nullptr) { |
| 8892 | 9923 | if (node->data.fn_proto.return_type == nullptr) { |
| 8893 | 9924 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); |
| 8894 | 9925 | } else { |
| 8895 | 9926 | 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; |
| 9927 | if (return_type == irb->codegen->invalid_inst_src) |
| 9928 | return irb->codegen->invalid_inst_src; |
| 8898 | 9929 | } |
| 8899 | 9930 | } else { |
| 8900 | 9931 | add_node_error(irb->codegen, node, |
| 8901 | 9932 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); |
| 8902 | | return irb->codegen->invalid_instruction; |
| 9933 | return irb->codegen->invalid_inst_src; |
| 8903 | 9934 | //return_type = nullptr; |
| 8904 | 9935 | } |
| 8905 | 9936 | |
| 8906 | 9937 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args); |
| 8907 | 9938 | } |
| 8908 | 9939 | |
| 8909 | | static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 9940 | static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) { |
| 8910 | 9941 | assert(node->type == NodeTypeResume); |
| 8911 | 9942 | |
| 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; |
| 9943 | IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr); |
| 9944 | if (target_inst == irb->codegen->invalid_inst_src) |
| 9945 | return irb->codegen->invalid_inst_src; |
| 8915 | 9946 | |
| 8916 | | return ir_build_resume(irb, scope, node, target_inst); |
| 9947 | return ir_build_resume_src(irb, scope, node, target_inst); |
| 8917 | 9948 | } |
| 8918 | 9949 | |
| 8919 | | static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, |
| 9950 | static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, |
| 8920 | 9951 | ResultLoc *result_loc) |
| 8921 | 9952 | { |
| 8922 | 9953 | assert(node->type == NodeTypeAwaitExpr); |
| ... | ... | @@ -8937,7 +9968,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 8937 | 9968 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 8938 | 9969 | if (!fn_entry) { |
| 8939 | 9970 | add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); |
| 8940 | | return irb->codegen->invalid_instruction; |
| 9971 | return irb->codegen->invalid_inst_src; |
| 8941 | 9972 | } |
| 8942 | 9973 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope); |
| 8943 | 9974 | if (existing_suspend_scope) { |
| ... | ... | @@ -8946,24 +9977,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 8946 | 9977 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here")); |
| 8947 | 9978 | existing_suspend_scope->reported_err = true; |
| 8948 | 9979 | } |
| 8949 | | return irb->codegen->invalid_instruction; |
| 9980 | return irb->codegen->invalid_inst_src; |
| 8950 | 9981 | } |
| 8951 | 9982 | |
| 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; |
| 9983 | IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 9984 | if (target_inst == irb->codegen->invalid_inst_src) |
| 9985 | return irb->codegen->invalid_inst_src; |
| 8955 | 9986 | |
| 8956 | | IrInstruction *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc); |
| 9987 | IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc); |
| 8957 | 9988 | return ir_lval_wrap(irb, scope, await_inst, lval, result_loc); |
| 8958 | 9989 | } |
| 8959 | 9990 | |
| 8960 | | static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 9991 | static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) { |
| 8961 | 9992 | assert(node->type == NodeTypeSuspend); |
| 8962 | 9993 | |
| 8963 | 9994 | ZigFn *fn_entry = exec_fn_entry(irb->exec); |
| 8964 | 9995 | if (!fn_entry) { |
| 8965 | 9996 | add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); |
| 8966 | | return irb->codegen->invalid_instruction; |
| 9997 | return irb->codegen->invalid_inst_src; |
| 8967 | 9998 | } |
| 8968 | 9999 | ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope); |
| 8969 | 10000 | if (existing_suspend_scope) { |
| ... | ... | @@ -8972,21 +10003,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod |
| 8972 | 10003 | add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here")); |
| 8973 | 10004 | existing_suspend_scope->reported_err = true; |
| 8974 | 10005 | } |
| 8975 | | return irb->codegen->invalid_instruction; |
| 10006 | return irb->codegen->invalid_inst_src; |
| 8976 | 10007 | } |
| 8977 | 10008 | |
| 8978 | | IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node); |
| 10009 | IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node); |
| 8979 | 10010 | if (node->data.suspend.block != nullptr) { |
| 8980 | 10011 | ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope); |
| 8981 | 10012 | Scope *child_scope = &suspend_scope->base; |
| 8982 | | IrInstruction *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope); |
| 10013 | IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope); |
| 8983 | 10014 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res)); |
| 8984 | 10015 | } |
| 8985 | 10016 | |
| 8986 | | return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin)); |
| 10017 | return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin)); |
| 8987 | 10018 | } |
| 8988 | 10019 | |
| 8989 | | static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope, |
| 10020 | static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope, |
| 8990 | 10021 | LVal lval, ResultLoc *result_loc) |
| 8991 | 10022 | { |
| 8992 | 10023 | assert(scope); |
| ... | ... | @@ -9035,39 +10066,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 9035 | 10066 | return ir_gen_return(irb, scope, node, lval, result_loc); |
| 9036 | 10067 | case NodeTypeFieldAccessExpr: |
| 9037 | 10068 | { |
| 9038 | | IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node); |
| 9039 | | if (ptr_instruction == irb->codegen->invalid_instruction) |
| 10069 | IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node); |
| 10070 | if (ptr_instruction == irb->codegen->invalid_inst_src) |
| 9040 | 10071 | return ptr_instruction; |
| 9041 | 10072 | if (lval == LValPtr) |
| 9042 | 10073 | return ptr_instruction; |
| 9043 | 10074 | |
| 9044 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 10075 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 9045 | 10076 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 9046 | 10077 | } |
| 9047 | 10078 | case NodeTypePtrDeref: { |
| 9048 | 10079 | 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) |
| 10080 | IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr); |
| 10081 | if (value == irb->codegen->invalid_inst_src) |
| 9051 | 10082 | return value; |
| 9052 | 10083 | |
| 9053 | 10084 | // We essentially just converted any lvalue from &(x.*) to (&x).*; |
| 9054 | 10085 | // this inhibits checking that x is a pointer later, so we directly |
| 9055 | 10086 | // record whether the pointer check is needed |
| 9056 | | IrInstruction *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc); |
| 10087 | IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc); |
| 9057 | 10088 | return ir_expr_wrap(irb, scope, un_op, result_loc); |
| 9058 | 10089 | } |
| 9059 | 10090 | case NodeTypeUnwrapOptional: { |
| 9060 | 10091 | AstNode *expr_node = node->data.unwrap_optional.expr; |
| 9061 | 10092 | |
| 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; |
| 10093 | IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 10094 | if (maybe_ptr == irb->codegen->invalid_inst_src) |
| 10095 | return irb->codegen->invalid_inst_src; |
| 9065 | 10096 | |
| 9066 | | IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false); |
| 10097 | IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false); |
| 9067 | 10098 | if (lval == LValPtr) |
| 9068 | 10099 | return unwrapped_ptr; |
| 9069 | 10100 | |
| 9070 | | IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 10101 | IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 9071 | 10102 | return ir_expr_wrap(irb, scope, load_ptr, result_loc); |
| 9072 | 10103 | } |
| 9073 | 10104 | case NodeTypeBoolLiteral: |
| ... | ... | @@ -9125,7 +10156,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 9125 | 10156 | case NodeTypeInferredArrayType: |
| 9126 | 10157 | add_node_error(irb->codegen, node, |
| 9127 | 10158 | buf_sprintf("inferred array size invalid here")); |
| 9128 | | return irb->codegen->invalid_instruction; |
| 10159 | return irb->codegen->invalid_inst_src; |
| 9129 | 10160 | case NodeTypeVarFieldType: |
| 9130 | 10161 | return ir_lval_wrap(irb, scope, |
| 9131 | 10162 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc); |
| ... | ... | @@ -9139,7 +10170,7 @@ static ResultLoc *no_result_loc(void) { |
| 9139 | 10170 | return &result_loc_none->base; |
| 9140 | 10171 | } |
| 9141 | 10172 | |
| 9142 | | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval, |
| 10173 | static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval, |
| 9143 | 10174 | ResultLoc *result_loc) |
| 9144 | 10175 | { |
| 9145 | 10176 | if (result_loc == nullptr) { |
| ... | ... | @@ -9156,8 +10187,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc |
| 9156 | 10187 | } else { |
| 9157 | 10188 | child_scope = &create_expr_scope(irb->codegen, node, scope)->base; |
| 9158 | 10189 | } |
| 9159 | | IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc); |
| 9160 | | if (result == irb->codegen->invalid_instruction) { |
| 10190 | IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc); |
| 10191 | if (result == irb->codegen->invalid_inst_src) { |
| 9161 | 10192 | if (irb->exec->first_err_trace_msg == nullptr) { |
| 9162 | 10193 | irb->exec->first_err_trace_msg = irb->codegen->trace_err; |
| 9163 | 10194 | } |
| ... | ... | @@ -9165,11 +10196,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc |
| 9165 | 10196 | return result; |
| 9166 | 10197 | } |
| 9167 | 10198 | |
| 9168 | | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) { |
| 10199 | static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) { |
| 9169 | 10200 | return ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 9170 | 10201 | } |
| 9171 | 10202 | |
| 9172 | | static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) { |
| 10203 | static void invalidate_exec(IrExecutableSrc *exec, ErrorMsg *msg) { |
| 10204 | if (exec->first_err_trace_msg != nullptr) |
| 10205 | return; |
| 10206 | |
| 10207 | exec->first_err_trace_msg = msg; |
| 10208 | |
| 10209 | for (size_t i = 0; i < exec->tld_list.length; i += 1) { |
| 10210 | exec->tld_list.items[i]->resolution = TldResolutionInvalid; |
| 10211 | } |
| 10212 | } |
| 10213 | |
| 10214 | static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) { |
| 9173 | 10215 | if (exec->first_err_trace_msg != nullptr) |
| 9174 | 10216 | return; |
| 9175 | 10217 | |
| ... | ... | @@ -9183,24 +10225,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) { |
| 9183 | 10225 | invalidate_exec(exec->source_exec, msg); |
| 9184 | 10226 | } |
| 9185 | 10227 | |
| 9186 | | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) { |
| 10228 | |
| 10229 | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable) { |
| 9187 | 10230 | assert(node->owner); |
| 9188 | 10231 | |
| 9189 | | IrBuilder ir_builder = {0}; |
| 9190 | | IrBuilder *irb = &ir_builder; |
| 10232 | IrBuilderSrc ir_builder = {0}; |
| 10233 | IrBuilderSrc *irb = &ir_builder; |
| 9191 | 10234 | |
| 9192 | 10235 | irb->codegen = codegen; |
| 9193 | 10236 | irb->exec = ir_executable; |
| 9194 | 10237 | irb->main_block_node = node; |
| 9195 | 10238 | |
| 9196 | | IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry"); |
| 10239 | IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry"); |
| 9197 | 10240 | ir_set_cursor_at_end_and_append_block(irb, entry_block); |
| 9198 | 10241 | // Entry block gets a reference because we enter it to begin. |
| 9199 | 10242 | ir_ref_bb(irb->current_basic_block); |
| 9200 | 10243 | |
| 9201 | | IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 10244 | IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr); |
| 9202 | 10245 | |
| 9203 | | if (result == irb->codegen->invalid_instruction) |
| 10246 | if (result == irb->codegen->invalid_inst_src) |
| 9204 | 10247 | return false; |
| 9205 | 10248 | |
| 9206 | 10249 | if (irb->exec->first_err_trace_msg != nullptr) { |
| ... | ... | @@ -9209,9 +10252,9 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 9209 | 10252 | } |
| 9210 | 10253 | |
| 9211 | 10254 | if (!instr_is_unreachable(result)) { |
| 9212 | | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr)); |
| 10255 | ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr)); |
| 9213 | 10256 | // 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)); |
| 10257 | ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result)); |
| 9215 | 10258 | } |
| 9216 | 10259 | |
| 9217 | 10260 | return true; |
| ... | ... | @@ -9220,7 +10263,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 9220 | 10263 | bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { |
| 9221 | 10264 | assert(fn_entry); |
| 9222 | 10265 | |
| 9223 | | IrExecutable *ir_executable = fn_entry->ir_executable; |
| 10266 | IrExecutableSrc *ir_executable = fn_entry->ir_executable; |
| 9224 | 10267 | AstNode *body_node = fn_entry->body_node; |
| 9225 | 10268 | |
| 9226 | 10269 | assert(fn_entry->child_scope); |
| ... | ... | @@ -9228,14 +10271,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { |
| 9228 | 10271 | return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable); |
| 9229 | 10272 | } |
| 9230 | 10273 | |
| 9231 | | static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) { |
| 10274 | static void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) { |
| 10275 | if (!exec || !exec->source_node || limit < 0) return; |
| 10276 | add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here")); |
| 10277 | |
| 10278 | ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1); |
| 10279 | } |
| 10280 | |
| 10281 | static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutableSrc *exec, ErrorMsg *err_msg, int limit) { |
| 9232 | 10282 | if (!exec || !exec->source_node || limit < 0) return; |
| 9233 | 10283 | add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here")); |
| 9234 | 10284 | |
| 9235 | | ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1); |
| 10285 | ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1); |
| 9236 | 10286 | } |
| 9237 | 10287 | |
| 9238 | | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) { |
| 10288 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg) { |
| 9239 | 10289 | ErrorMsg *err_msg = add_node_error(codegen, source_node, msg); |
| 9240 | 10290 | invalidate_exec(exec, err_msg); |
| 9241 | 10291 | if (exec->parent_exec) { |
| ... | ... | @@ -9244,26 +10294,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo |
| 9244 | 10294 | return err_msg; |
| 9245 | 10295 | } |
| 9246 | 10296 | |
| 10297 | static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) { |
| 10298 | ErrorMsg *err_msg = add_node_error(codegen, source_node, msg); |
| 10299 | invalidate_exec_gen(exec, err_msg); |
| 10300 | if (exec->parent_exec) { |
| 10301 | ir_add_call_stack_errors_gen(codegen, exec, err_msg, 10); |
| 10302 | } |
| 10303 | return err_msg; |
| 10304 | } |
| 10305 | |
| 9247 | 10306 | 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); |
| 10307 | return exec_add_error_node_gen(ira->codegen, ira->new_irb.exec, source_node, msg); |
| 9249 | 10308 | } |
| 9250 | 10309 | |
| 9251 | 10310 | static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) { |
| 9252 | 10311 | if (ira != nullptr) |
| 9253 | | return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg); |
| 10312 | return exec_add_error_node_gen(codegen, ira->new_irb.exec, source_node, msg); |
| 9254 | 10313 | else |
| 9255 | 10314 | return add_node_error(codegen, source_node, msg); |
| 9256 | 10315 | } |
| 9257 | 10316 | |
| 9258 | | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { |
| 10317 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) { |
| 9259 | 10318 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 9260 | 10319 | } |
| 9261 | 10320 | |
| 9262 | | static void ir_assert(bool ok, IrInstruction *source_instruction) { |
| 10321 | static void ir_assert(bool ok, IrInst *source_instruction) { |
| 9263 | 10322 | if (ok) return; |
| 9264 | 10323 | src_assert(ok, source_instruction->source_node); |
| 9265 | 10324 | } |
| 9266 | 10325 | |
| 10326 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction) { |
| 10327 | if (ok) return; |
| 10328 | src_assert(ok, source_instruction->base.source_node); |
| 10329 | } |
| 10330 | |
| 9267 | 10331 | // This function takes a comptime ptr and makes the child const value conform to the type |
| 9268 | 10332 | // described by the pointer. |
| 9269 | 10333 | static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| ... | ... | @@ -9309,43 +10373,43 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va |
| 9309 | 10373 | return val; |
| 9310 | 10374 | } |
| 9311 | 10375 | |
| 9312 | | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 9313 | | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 10376 | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutableGen *exec) { |
| 10377 | IrBasicBlockGen *bb = exec->basic_block_list.at(0); |
| 9314 | 10378 | 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; |
| 10379 | IrInstGen *instruction = bb->instruction_list.at(i); |
| 10380 | if (instruction->id == IrInstGenIdReturn) { |
| 10381 | IrInstGenReturn *ret_inst = (IrInstGenReturn *)instruction; |
| 10382 | IrInstGen *operand = ret_inst->operand; |
| 9319 | 10383 | if (operand->value->special == ConstValSpecialRuntime) { |
| 9320 | | exec_add_error_node(codegen, exec, operand->source_node, |
| 10384 | exec_add_error_node_gen(codegen, exec, operand->base.source_node, |
| 9321 | 10385 | buf_sprintf("unable to evaluate constant expression")); |
| 9322 | | return codegen->invalid_instruction->value; |
| 10386 | return codegen->invalid_inst_gen->value; |
| 9323 | 10387 | } |
| 9324 | 10388 | return operand->value; |
| 9325 | | } else if (ir_has_side_effects(instruction)) { |
| 10389 | } else if (ir_inst_gen_has_side_effects(instruction)) { |
| 9326 | 10390 | if (instr_is_comptime(instruction)) { |
| 9327 | 10391 | switch (instruction->id) { |
| 9328 | | case IrInstructionIdUnwrapErrPayload: |
| 9329 | | case IrInstructionIdUnionFieldPtr: |
| 10392 | case IrInstGenIdUnwrapErrPayload: |
| 10393 | case IrInstGenIdUnionFieldPtr: |
| 9330 | 10394 | continue; |
| 9331 | 10395 | default: |
| 9332 | 10396 | break; |
| 9333 | 10397 | } |
| 9334 | 10398 | } |
| 9335 | | if (get_scope_typeof(instruction->scope) != nullptr) { |
| 10399 | if (get_scope_typeof(instruction->base.scope) != nullptr) { |
| 9336 | 10400 | // doesn't count, it's inside a @TypeOf() |
| 9337 | 10401 | continue; |
| 9338 | 10402 | } |
| 9339 | | exec_add_error_node(codegen, exec, instruction->source_node, |
| 10403 | exec_add_error_node_gen(codegen, exec, instruction->base.source_node, |
| 9340 | 10404 | buf_sprintf("unable to evaluate constant expression")); |
| 9341 | | return codegen->invalid_instruction->value; |
| 10405 | return codegen->invalid_inst_gen->value; |
| 9342 | 10406 | } |
| 9343 | 10407 | } |
| 9344 | 10408 | zig_unreachable(); |
| 9345 | 10409 | } |
| 9346 | 10410 | |
| 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)) { |
| 10411 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) { |
| 10412 | if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) { |
| 9349 | 10413 | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); |
| 9350 | 10414 | return false; |
| 9351 | 10415 | } |
| ... | ... | @@ -10079,7 +11143,7 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) { |
| 10079 | 11143 | } |
| 10080 | 11144 | } |
| 10081 | 11145 | |
| 10082 | | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type, |
| 11146 | static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type, |
| 10083 | 11147 | bool explicit_cast) |
| 10084 | 11148 | { |
| 10085 | 11149 | if (type_is_invalid(other_type)) { |
| ... | ... | @@ -10173,7 +11237,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10173 | 11237 | } |
| 10174 | 11238 | Buf *val_buf = buf_alloc(); |
| 10175 | 11239 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10176 | | ir_add_error(ira, instruction, |
| 11240 | ir_add_error_node(ira, instruction->base.source_node, |
| 10177 | 11241 | buf_sprintf("integer value %s has no representation in type '%s'", |
| 10178 | 11242 | buf_ptr(val_buf), |
| 10179 | 11243 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10268,7 +11332,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10268 | 11332 | } |
| 10269 | 11333 | Buf *val_buf = buf_alloc(); |
| 10270 | 11334 | float_append_buf(val_buf, const_val); |
| 10271 | | ir_add_error(ira, instruction, |
| 11335 | ir_add_error_node(ira, instruction->base.source_node, |
| 10272 | 11336 | buf_sprintf("cast of value %s to type '%s' loses information", |
| 10273 | 11337 | buf_ptr(val_buf), |
| 10274 | 11338 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10277,7 +11341,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10277 | 11341 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 10278 | 11342 | Buf *val_buf = buf_alloc(); |
| 10279 | 11343 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10280 | | ir_add_error(ira, instruction, |
| 11344 | ir_add_error_node(ira, instruction->base.source_node, |
| 10281 | 11345 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 10282 | 11346 | buf_ptr(val_buf), |
| 10283 | 11347 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10298,7 +11362,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10298 | 11362 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 10299 | 11363 | Buf *val_buf = buf_alloc(); |
| 10300 | 11364 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10301 | | ir_add_error(ira, instruction, |
| 11365 | ir_add_error_node(ira, instruction->base.source_node, |
| 10302 | 11366 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 10303 | 11367 | buf_ptr(val_buf), |
| 10304 | 11368 | buf_ptr(&child_type->name))); |
| ... | ... | @@ -10321,7 +11385,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10321 | 11385 | Buf *val_buf = buf_alloc(); |
| 10322 | 11386 | float_append_buf(val_buf, const_val); |
| 10323 | 11387 | |
| 10324 | | ir_add_error(ira, instruction, |
| 11388 | ir_add_error_node(ira, instruction->base.source_node, |
| 10325 | 11389 | buf_sprintf("fractional component prevents float value %s from being casted to type '%s'", |
| 10326 | 11390 | buf_ptr(val_buf), |
| 10327 | 11391 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -10351,7 +11415,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 10351 | 11415 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 10352 | 11416 | } |
| 10353 | 11417 | |
| 10354 | | ir_add_error(ira, instruction, |
| 11418 | ir_add_error_node(ira, instruction->base.source_node, |
| 10355 | 11419 | buf_sprintf("%s value %s cannot be coerced to type '%s'", |
| 10356 | 11420 | num_lit_str, |
| 10357 | 11421 | buf_ptr(val_buf), |
| ... | ... | @@ -10805,11 +11869,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * |
| 10805 | 11869 | } |
| 10806 | 11870 | |
| 10807 | 11871 | static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, |
| 10808 | | IrInstruction **instructions, size_t instruction_count) |
| 11872 | IrInstGen **instructions, size_t instruction_count) |
| 10809 | 11873 | { |
| 10810 | 11874 | Error err; |
| 10811 | 11875 | assert(instruction_count >= 1); |
| 10812 | | IrInstruction *prev_inst; |
| 11876 | IrInstGen *prev_inst; |
| 10813 | 11877 | size_t i = 0; |
| 10814 | 11878 | for (;;) { |
| 10815 | 11879 | prev_inst = instructions[i]; |
| ... | ... | @@ -10829,7 +11893,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10829 | 11893 | size_t errors_count = 0; |
| 10830 | 11894 | ZigType *err_set_type = nullptr; |
| 10831 | 11895 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10832 | | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { |
| 11896 | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) { |
| 10833 | 11897 | return ira->codegen->builtin_types.entry_invalid; |
| 10834 | 11898 | } |
| 10835 | 11899 | if (type_is_global_error_set(prev_inst->value->type)) { |
| ... | ... | @@ -10849,7 +11913,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10849 | 11913 | bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); |
| 10850 | 11914 | bool convert_to_const_slice = false; |
| 10851 | 11915 | for (; i < instruction_count; i += 1) { |
| 10852 | | IrInstruction *cur_inst = instructions[i]; |
| 11916 | IrInstGen *cur_inst = instructions[i]; |
| 10853 | 11917 | ZigType *cur_type = cur_inst->value->type; |
| 10854 | 11918 | ZigType *prev_type = prev_inst->value->type; |
| 10855 | 11919 | |
| ... | ... | @@ -10871,14 +11935,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10871 | 11935 | } |
| 10872 | 11936 | |
| 10873 | 11937 | if (prev_type->id == ZigTypeIdErrorSet) { |
| 10874 | | ir_assert(err_set_type != nullptr, prev_inst); |
| 11938 | ir_assert_gen(err_set_type != nullptr, prev_inst); |
| 10875 | 11939 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 10876 | 11940 | if (type_is_global_error_set(err_set_type)) { |
| 10877 | 11941 | continue; |
| 10878 | 11942 | } |
| 10879 | 11943 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 10880 | 11944 | 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)) { |
| 11945 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 10882 | 11946 | return ira->codegen->builtin_types.entry_invalid; |
| 10883 | 11947 | } |
| 10884 | 11948 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -10946,7 +12010,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10946 | 12010 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 10947 | 12011 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 10948 | 12012 | 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)) { |
| 12013 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 10950 | 12014 | return ira->codegen->builtin_types.entry_invalid; |
| 10951 | 12015 | } |
| 10952 | 12016 | if (!allow_infer && type_is_global_error_set(cur_err_set_type)) { |
| ... | ... | @@ -11001,7 +12065,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11001 | 12065 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 11002 | 12066 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 11003 | 12067 | 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)) { |
| 12068 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 11005 | 12069 | return ira->codegen->builtin_types.entry_invalid; |
| 11006 | 12070 | } |
| 11007 | 12071 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -11024,7 +12088,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11024 | 12088 | err_set_type = cur_type; |
| 11025 | 12089 | } |
| 11026 | 12090 | |
| 11027 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) { |
| 12091 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) { |
| 11028 | 12092 | return ira->codegen->builtin_types.entry_invalid; |
| 11029 | 12093 | } |
| 11030 | 12094 | |
| ... | ... | @@ -11087,11 +12151,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11087 | 12151 | bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 11088 | 12152 | cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry; |
| 11089 | 12153 | |
| 11090 | | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 12154 | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) { |
| 11091 | 12155 | return ira->codegen->builtin_types.entry_invalid; |
| 11092 | 12156 | } |
| 11093 | 12157 | |
| 11094 | | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 12158 | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 11095 | 12159 | return ira->codegen->builtin_types.entry_invalid; |
| 11096 | 12160 | } |
| 11097 | 12161 | |
| ... | ... | @@ -11268,7 +12332,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11268 | 12332 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 11269 | 12333 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 11270 | 12334 | 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)) { |
| 12335 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 11272 | 12336 | return ira->codegen->builtin_types.entry_invalid; |
| 11273 | 12337 | } |
| 11274 | 12338 | if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) || |
| ... | ... | @@ -11463,9 +12527,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11463 | 12527 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 11464 | 12528 | buf_sprintf("incompatible types: '%s' and '%s'", |
| 11465 | 12529 | buf_ptr(&prev_type->name), buf_ptr(&cur_type->name))); |
| 11466 | | add_error_note(ira->codegen, msg, prev_inst->source_node, |
| 12530 | add_error_note(ira->codegen, msg, prev_inst->base.source_node, |
| 11467 | 12531 | buf_sprintf("type '%s' here", buf_ptr(&prev_type->name))); |
| 11468 | | add_error_note(ira->codegen, msg, cur_inst->source_node, |
| 12532 | add_error_note(ira->codegen, msg, cur_inst->base.source_node, |
| 11469 | 12533 | buf_sprintf("type '%s' here", buf_ptr(&cur_type->name))); |
| 11470 | 12534 | |
| 11471 | 12535 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11535,7 +12599,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11535 | 12599 | } |
| 11536 | 12600 | } |
| 11537 | 12601 | |
| 11538 | | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 12602 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr, |
| 11539 | 12603 | CastOp cast_op, |
| 11540 | 12604 | ZigValue *other_val, ZigType *other_type, |
| 11541 | 12605 | ZigValue *const_val, ZigType *new_type) |
| ... | ... | @@ -11635,58 +12699,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 11635 | 12699 | return true; |
| 11636 | 12700 | } |
| 11637 | 12701 | |
| 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; |
| 12702 | static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) { |
| 12703 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12704 | inst->scope, inst->source_node); |
| 12705 | IrInstGen *new_instruction = &const_instruction->base; |
| 11642 | 12706 | new_instruction->value->type = ty; |
| 11643 | 12707 | new_instruction->value->special = ConstValSpecialStatic; |
| 11644 | 12708 | return new_instruction; |
| 11645 | 12709 | } |
| 11646 | 12710 | |
| 11647 | | static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 11648 | | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb, |
| 12711 | static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) { |
| 12712 | IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, |
| 11649 | 12713 | old_instruction->scope, old_instruction->source_node); |
| 11650 | 12714 | return &const_instruction->base; |
| 11651 | 12715 | } |
| 11652 | 12716 | |
| 11653 | | // This function initializes the new IrInstruction with the provided ZigValue, |
| 12717 | // This function initializes the new IrInstGen with the provided ZigValue, |
| 11654 | 12718 | // 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); |
| 12719 | static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) { |
| 12720 | IrInstGen *result = ir_const_noval(ira, old_instruction); |
| 11657 | 12721 | result->value = val; |
| 11658 | 12722 | return result; |
| 11659 | 12723 | } |
| 11660 | 12724 | |
| 11661 | | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 12725 | static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 11662 | 12726 | ZigType *wanted_type, CastOp cast_op) |
| 11663 | 12727 | { |
| 11664 | 12728 | if (instr_is_comptime(value) || !type_has_bits(wanted_type)) { |
| 11665 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12729 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11666 | 12730 | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type, |
| 11667 | 12731 | result->value, wanted_type)) |
| 11668 | 12732 | { |
| 11669 | | return ira->codegen->invalid_instruction; |
| 12733 | return ira->codegen->invalid_inst_gen; |
| 11670 | 12734 | } |
| 11671 | 12735 | return result; |
| 11672 | 12736 | } 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; |
| 12737 | return ir_build_cast(ira, source_instr, wanted_type, value, cast_op); |
| 11676 | 12738 | } |
| 11677 | 12739 | } |
| 11678 | 12740 | |
| 11679 | | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 11680 | | IrInstruction *value, ZigType *wanted_type) |
| 12741 | static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12742 | IrInstGen *value, ZigType *wanted_type) |
| 11681 | 12743 | { |
| 11682 | | assert(value->value->type->id == ZigTypeIdPointer); |
| 12744 | ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr); |
| 11683 | 12745 | |
| 11684 | 12746 | Error err; |
| 11685 | 12747 | |
| 11686 | 12748 | if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type, |
| 11687 | 12749 | ResolveStatusAlignmentKnown))) |
| 11688 | 12750 | { |
| 11689 | | return ira->codegen->invalid_instruction; |
| 12751 | return ira->codegen->invalid_inst_gen; |
| 11690 | 12752 | } |
| 11691 | 12753 | |
| 11692 | 12754 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type)); |
| ... | ... | @@ -11694,9 +12756,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 11694 | 12756 | if (instr_is_comptime(value)) { |
| 11695 | 12757 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node); |
| 11696 | 12758 | if (pointee == nullptr) |
| 11697 | | return ira->codegen->invalid_instruction; |
| 12759 | return ira->codegen->invalid_inst_gen; |
| 11698 | 12760 | if (pointee->special != ConstValSpecialRuntime) { |
| 11699 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12761 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11700 | 12762 | result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11701 | 12763 | result->value->data.x_ptr.mut = value->value->data.x_ptr.mut; |
| 11702 | 12764 | result->value->data.x_ptr.data.base_array.array_val = pointee; |
| ... | ... | @@ -11705,21 +12767,18 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 11705 | 12767 | } |
| 11706 | 12768 | } |
| 11707 | 12769 | |
| 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; |
| 12770 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 11712 | 12771 | } |
| 11713 | 12772 | |
| 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) |
| 12773 | static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr, |
| 12774 | IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc) |
| 11716 | 12775 | { |
| 11717 | 12776 | Error err; |
| 11718 | 12777 | |
| 11719 | 12778 | if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type, |
| 11720 | 12779 | ResolveStatusAlignmentKnown))) |
| 11721 | 12780 | { |
| 11722 | | return ira->codegen->invalid_instruction; |
| 12781 | return ira->codegen->invalid_inst_gen; |
| 11723 | 12782 | } |
| 11724 | 12783 | |
| 11725 | 12784 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| ... | ... | @@ -11727,14 +12786,14 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11727 | 12786 | if (instr_is_comptime(array_ptr)) { |
| 11728 | 12787 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); |
| 11729 | 12788 | if (pointee == nullptr) |
| 11730 | | return ira->codegen->invalid_instruction; |
| 12789 | return ira->codegen->invalid_inst_gen; |
| 11731 | 12790 | if (pointee->special != ConstValSpecialRuntime) { |
| 11732 | 12791 | assert(array_ptr->value->type->id == ZigTypeIdPointer); |
| 11733 | 12792 | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; |
| 11734 | 12793 | assert(is_slice(wanted_type)); |
| 11735 | 12794 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 11736 | 12795 | |
| 11737 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12796 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 11738 | 12797 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11739 | 12798 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; |
| 11740 | 12799 | result->value->type = wanted_type; |
| ... | ... | @@ -11743,32 +12802,34 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11743 | 12802 | } |
| 11744 | 12803 | |
| 11745 | 12804 | 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, |
| 12805 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, |
| 11747 | 12806 | false, true); |
| 11748 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12807 | if (type_is_invalid(result_loc_inst->value->type) || |
| 12808 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 12809 | { |
| 11749 | 12810 | return result_loc_inst; |
| 11750 | 12811 | } |
| 11751 | 12812 | return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); |
| 11752 | 12813 | } |
| 11753 | 12814 | |
| 11754 | | static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| 12815 | static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) { |
| 11755 | 12816 | assert(old_bb); |
| 11756 | 12817 | |
| 11757 | | if (old_bb->other) { |
| 11758 | | if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) { |
| 11759 | | return old_bb->other; |
| 12818 | if (old_bb->child) { |
| 12819 | if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) { |
| 12820 | return old_bb->child; |
| 11760 | 12821 | } |
| 11761 | 12822 | } |
| 11762 | 12823 | |
| 11763 | | IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb); |
| 12824 | IrBasicBlockGen *new_bb = ir_build_bb_from(ira, old_bb); |
| 11764 | 12825 | new_bb->ref_instruction = ref_old_instruction; |
| 11765 | 12826 | |
| 11766 | 12827 | return new_bb; |
| 11767 | 12828 | } |
| 11768 | 12829 | |
| 11769 | | static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { |
| 12830 | static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) { |
| 11770 | 12831 | assert(ref_old_instruction != nullptr); |
| 11771 | | IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 12832 | IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 11772 | 12833 | if (new_bb->must_be_comptime_source_instr) { |
| 11773 | 12834 | ErrorMsg *msg = ir_add_error(ira, ref_old_instruction, |
| 11774 | 12835 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| ... | ... | @@ -11779,24 +12840,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, |
| 11779 | 12840 | return new_bb; |
| 11780 | 12841 | } |
| 11781 | 12842 | |
| 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); |
| 12843 | static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) { |
| 12844 | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr); |
| 11784 | 12845 | ira->instruction_index = 0; |
| 11785 | 12846 | ira->old_irb.current_basic_block = old_bb; |
| 11786 | 12847 | ira->const_predecessor_bb = const_predecessor_bb; |
| 11787 | 12848 | ira->old_bb_index = old_bb->index; |
| 11788 | 12849 | } |
| 11789 | 12850 | |
| 11790 | | static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb, |
| 12851 | static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBlockSrc *next_bb, |
| 11791 | 12852 | IrSuspendPosition *suspend_pos) |
| 11792 | 12853 | { |
| 11793 | 12854 | if (ira->codegen->verbose_ir) { |
| 11794 | | fprintf(stderr, "suspend %s_%zu %s_%zu #%" PRIu32 " (%zu,%zu)\n", |
| 12855 | fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n", |
| 11795 | 12856 | ira->old_irb.current_basic_block->name_hint, |
| 11796 | 12857 | ira->old_irb.current_basic_block->debug_id, |
| 11797 | 12858 | ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint, |
| 11798 | 12859 | 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, |
| 12860 | ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id, |
| 11800 | 12861 | ira->old_bb_index, ira->instruction_index); |
| 11801 | 12862 | } |
| 11802 | 12863 | suspend_pos->basic_block_index = ira->old_bb_index; |
| ... | ... | @@ -11811,13 +12872,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction |
| 11811 | 12872 | assert(ira->old_irb.current_basic_block == next_bb); |
| 11812 | 12873 | ira->instruction_index = 0; |
| 11813 | 12874 | 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; |
| 12875 | next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction); |
| 12876 | ira->new_irb.current_basic_block = next_bb->child; |
| 11816 | 12877 | } |
| 11817 | 12878 | return ira->codegen->unreach_instruction; |
| 11818 | 12879 | } |
| 11819 | 12880 | |
| 11820 | | static IrInstruction *ira_resume(IrAnalyze *ira) { |
| 12881 | static IrInstGen *ira_resume(IrAnalyze *ira) { |
| 11821 | 12882 | IrSuspendPosition pos = ira->resume_stack.pop(); |
| 11822 | 12883 | if (ira->codegen->verbose_ir) { |
| 11823 | 12884 | fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index); |
| ... | ... | @@ -11830,12 +12891,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) { |
| 11830 | 12891 | ira->instruction_index = pos.instruction_index; |
| 11831 | 12892 | assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length); |
| 11832 | 12893 | if (ira->codegen->verbose_ir) { |
| 11833 | | fprintf(stderr, "%s_%zu #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint, |
| 12894 | fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint, |
| 11834 | 12895 | ira->old_irb.current_basic_block->debug_id, |
| 11835 | | ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id); |
| 12896 | ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id); |
| 11836 | 12897 | } |
| 11837 | 12898 | ira->const_predecessor_bb = nullptr; |
| 11838 | | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other; |
| 12899 | ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child; |
| 11839 | 12900 | assert(ira->new_irb.current_basic_block != nullptr); |
| 11840 | 12901 | return ira->codegen->unreach_instruction; |
| 11841 | 12902 | } |
| ... | ... | @@ -11846,8 +12907,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11846 | 12907 | bool need_repeat = true; |
| 11847 | 12908 | for (;;) { |
| 11848 | 12909 | 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) { |
| 12910 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index); |
| 12911 | if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) { |
| 11851 | 12912 | ira->old_bb_index += 1; |
| 11852 | 12913 | continue; |
| 11853 | 12914 | } |
| ... | ... | @@ -11855,8 +12916,8 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11855 | 12916 | // if it's a suspended block, |
| 11856 | 12917 | // then skip it |
| 11857 | 12918 | 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)) |
| 12919 | (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) || |
| 12920 | (old_bb->child != nullptr && old_bb->child->already_appended)) |
| 11860 | 12921 | { |
| 11861 | 12922 | ira->old_bb_index += 1; |
| 11862 | 12923 | continue; |
| ... | ... | @@ -11870,10 +12931,10 @@ static void ir_start_next_bb(IrAnalyze *ira) { |
| 11870 | 12931 | return; |
| 11871 | 12932 | } |
| 11872 | 12933 | |
| 11873 | | if (old_bb->other == nullptr) { |
| 11874 | | old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref); |
| 12934 | if (old_bb->child == nullptr) { |
| 12935 | old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref); |
| 11875 | 12936 | } |
| 11876 | | ira->new_irb.current_basic_block = old_bb->other; |
| 12937 | ira->new_irb.current_basic_block = old_bb->child; |
| 11877 | 12938 | ir_start_bb(ira, old_bb, nullptr); |
| 11878 | 12939 | return; |
| 11879 | 12940 | } |
| ... | ... | @@ -11893,16 +12954,16 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 11893 | 12954 | if (!ira->new_irb.current_basic_block->already_appended) { |
| 11894 | 12955 | ira->new_irb.current_basic_block->already_appended = true; |
| 11895 | 12956 | if (ira->codegen->verbose_ir) { |
| 11896 | | fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint, |
| 12957 | fprintf(stderr, "append new bb %s_%" PRIu32 "\n", ira->new_irb.current_basic_block->name_hint, |
| 11897 | 12958 | ira->new_irb.current_basic_block->debug_id); |
| 11898 | 12959 | } |
| 11899 | 12960 | ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block); |
| 11900 | 12961 | } |
| 11901 | 12962 | ira->instruction_index += 1; |
| 11902 | 12963 | 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); |
| 12964 | IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 11904 | 12965 | if (!next_instruction->is_gen) { |
| 11905 | | ir_add_error(ira, next_instruction, buf_sprintf("unreachable code")); |
| 12966 | ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code")); |
| 11906 | 12967 | break; |
| 11907 | 12968 | } |
| 11908 | 12969 | ira->instruction_index += 1; |
| ... | ... | @@ -11911,7 +12972,7 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 11911 | 12972 | ir_start_next_bb(ira); |
| 11912 | 12973 | } |
| 11913 | 12974 | |
| 11914 | | static IrInstruction *ir_unreach_error(IrAnalyze *ira) { |
| 12975 | static IrInstGen *ir_unreach_error(IrAnalyze *ira) { |
| 11915 | 12976 | ira->old_bb_index = SIZE_MAX; |
| 11916 | 12977 | if (ira->new_irb.exec->first_err_trace_msg == nullptr) { |
| 11917 | 12978 | ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err; |
| ... | ... | @@ -11919,7 +12980,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) { |
| 11919 | 12980 | return ira->codegen->unreach_instruction; |
| 11920 | 12981 | } |
| 11921 | 12982 | |
| 11922 | | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 12983 | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) { |
| 11923 | 12984 | size_t *bbc = ira->new_irb.exec->backward_branch_count; |
| 11924 | 12985 | size_t *quota = ira->new_irb.exec->backward_branch_quota; |
| 11925 | 12986 | |
| ... | ... | @@ -11938,66 +12999,82 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 11938 | 12999 | return true; |
| 11939 | 13000 | } |
| 11940 | 13001 | |
| 11941 | | static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { |
| 13002 | static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) { |
| 11942 | 13003 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { |
| 11943 | 13004 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 11944 | 13005 | return ir_unreach_error(ira); |
| 11945 | 13006 | } |
| 11946 | 13007 | |
| 11947 | | old_bb->other = ira->old_irb.current_basic_block->other; |
| 13008 | old_bb->child = ira->old_irb.current_basic_block->child; |
| 11948 | 13009 | ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block); |
| 11949 | 13010 | return ira->codegen->unreach_instruction; |
| 11950 | 13011 | } |
| 11951 | 13012 | |
| 11952 | | static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { |
| 13013 | static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) { |
| 11953 | 13014 | if (instruction->value->type->id == ZigTypeIdUnreachable) |
| 11954 | 13015 | ir_finish_bb(ira); |
| 11955 | 13016 | return instruction; |
| 11956 | 13017 | } |
| 11957 | 13018 | |
| 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); |
| 13019 | static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) { |
| 13020 | IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry); |
| 13021 | result->value->special = ConstValSpecialStatic; |
| 13022 | result->value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 13023 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 13024 | result->value->data.x_ptr.special = ConstPtrSpecialFunction; |
| 13025 | return result; |
| 13026 | } |
| 13027 | |
| 13028 | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg) { |
| 13029 | IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry)); |
| 13030 | result->value->data.x_bound_fn.fn = fn_entry; |
| 13031 | result->value->data.x_bound_fn.first_arg = first_arg; |
| 13032 | return result; |
| 13033 | } |
| 13034 | |
| 13035 | static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 13036 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 11960 | 13037 | result->value->data.x_type = ty; |
| 11961 | 13038 | return result; |
| 11962 | 13039 | } |
| 11963 | 13040 | |
| 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); |
| 13041 | static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) { |
| 13042 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 11966 | 13043 | result->value->data.x_bool = value; |
| 11967 | 13044 | return result; |
| 11968 | 13045 | } |
| 11969 | 13046 | |
| 11970 | | static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11971 | | IrInstruction *result = ir_const(ira, source_instruction, ty); |
| 13047 | static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 13048 | IrInstGen *result = ir_const(ira, source_instruction, ty); |
| 11972 | 13049 | result->value->special = ConstValSpecialUndef; |
| 11973 | 13050 | return result; |
| 11974 | 13051 | } |
| 11975 | 13052 | |
| 11976 | | static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11977 | | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 13053 | static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) { |
| 13054 | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 11978 | 13055 | result->value = ira->codegen->intern.for_unreachable(); |
| 11979 | 13056 | return result; |
| 11980 | 13057 | } |
| 11981 | 13058 | |
| 11982 | | static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11983 | | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 13059 | static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) { |
| 13060 | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 11984 | 13061 | result->value = ira->codegen->intern.for_void(); |
| 11985 | 13062 | return result; |
| 11986 | 13063 | } |
| 11987 | 13064 | |
| 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); |
| 13065 | static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) { |
| 13066 | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 11990 | 13067 | bigint_init_unsigned(&result->value->data.x_bigint, value); |
| 11991 | 13068 | return result; |
| 11992 | 13069 | } |
| 11993 | 13070 | |
| 11994 | | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13071 | static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction, |
| 11995 | 13072 | ZigValue *pointee, ZigType *pointee_type, |
| 11996 | 13073 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 11997 | 13074 | { |
| 11998 | 13075 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 11999 | 13076 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 12000 | | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 13077 | IrInstGen *const_instr = ir_const(ira, instruction, ptr_type); |
| 12001 | 13078 | ZigValue *const_val = const_instr->value; |
| 12002 | 13079 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 12003 | 13080 | const_val->data.x_ptr.mut = ptr_mut; |
| ... | ... | @@ -12005,7 +13082,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 12005 | 13082 | return const_instr; |
| 12006 | 13083 | } |
| 12007 | 13084 | |
| 12008 | | static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 13085 | static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 12009 | 13086 | ZigValue *val, UndefAllowed undef_allowed) |
| 12010 | 13087 | { |
| 12011 | 13088 | Error err; |
| ... | ... | @@ -12017,14 +13094,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 12017 | 13094 | if (!type_has_bits(val->type)) |
| 12018 | 13095 | return ErrorNone; |
| 12019 | 13096 | |
| 12020 | | exec_add_error_node(codegen, exec, source_node, |
| 13097 | exec_add_error_node_gen(codegen, exec, source_node, |
| 12021 | 13098 | buf_sprintf("unable to evaluate constant expression")); |
| 12022 | 13099 | return ErrorSemanticAnalyzeFail; |
| 12023 | 13100 | case ConstValSpecialUndef: |
| 12024 | 13101 | if (undef_allowed == UndefOk || undef_allowed == LazyOk) |
| 12025 | 13102 | return ErrorNone; |
| 12026 | 13103 | |
| 12027 | | exec_add_error_node(codegen, exec, source_node, |
| 13104 | exec_add_error_node_gen(codegen, exec, source_node, |
| 12028 | 13105 | buf_sprintf("use of undefined value here causes undefined behavior")); |
| 12029 | 13106 | return ErrorSemanticAnalyzeFail; |
| 12030 | 13107 | case ConstValSpecialLazy: |
| ... | ... | @@ -12039,9 +13116,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 12039 | 13116 | } |
| 12040 | 13117 | } |
| 12041 | 13118 | |
| 12042 | | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 13119 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) { |
| 12043 | 13120 | Error err; |
| 12044 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, |
| 13121 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 12045 | 13122 | value->value, undef_allowed))) |
| 12046 | 13123 | { |
| 12047 | 13124 | return nullptr; |
| ... | ... | @@ -12052,14 +13129,14 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll |
| 12052 | 13129 | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12053 | 13130 | ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 12054 | 13131 | 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) |
| 13132 | IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| 12056 | 13133 | { |
| 12057 | 13134 | Error err; |
| 12058 | 13135 | |
| 12059 | 13136 | if (expected_type != nullptr && type_is_invalid(expected_type)) |
| 12060 | | return codegen->invalid_instruction->value; |
| 13137 | return codegen->invalid_inst_gen->value; |
| 12061 | 13138 | |
| 12062 | | IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1"); |
| 13139 | IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc"); |
| 12063 | 13140 | ir_executable->source_node = source_node; |
| 12064 | 13141 | ir_executable->parent_exec = parent_exec; |
| 12065 | 13142 | ir_executable->name = exec_name; |
| ... | ... | @@ -12069,21 +13146,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12069 | 13146 | ir_executable->begin_scope = scope; |
| 12070 | 13147 | |
| 12071 | 13148 | if (!ir_gen(codegen, node, scope, ir_executable)) |
| 12072 | | return codegen->invalid_instruction->value; |
| 13149 | return codegen->invalid_inst_gen->value; |
| 12073 | 13150 | |
| 12074 | 13151 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 12075 | 13152 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 12076 | | return codegen->invalid_instruction->value; |
| 13153 | return codegen->invalid_inst_gen->value; |
| 12077 | 13154 | } |
| 12078 | 13155 | |
| 12079 | 13156 | if (codegen->verbose_ir) { |
| 12080 | 13157 | fprintf(stderr, "\nSource: "); |
| 12081 | 13158 | ast_render(stderr, node, 4); |
| 12082 | 13159 | fprintf(stderr, "\n{ // (IR)\n"); |
| 12083 | | ir_print(codegen, stderr, ir_executable, 2, IrPassSrc); |
| 13160 | ir_print_src(codegen, stderr, ir_executable, 2); |
| 12084 | 13161 | fprintf(stderr, "}\n"); |
| 12085 | 13162 | } |
| 12086 | | IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2"); |
| 13163 | IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen"); |
| 12087 | 13164 | analyzed_executable->source_node = source_node; |
| 12088 | 13165 | analyzed_executable->parent_exec = parent_exec; |
| 12089 | 13166 | analyzed_executable->source_exec = ir_executable; |
| ... | ... | @@ -12096,31 +13173,31 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 12096 | 13173 | analyzed_executable->begin_scope = scope; |
| 12097 | 13174 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); |
| 12098 | 13175 | if (type_is_invalid(result_type)) { |
| 12099 | | return codegen->invalid_instruction->value; |
| 13176 | return codegen->invalid_inst_gen->value; |
| 12100 | 13177 | } |
| 12101 | 13178 | |
| 12102 | 13179 | if (codegen->verbose_ir) { |
| 12103 | 13180 | fprintf(stderr, "{ // (analyzed)\n"); |
| 12104 | | ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen); |
| 13181 | ir_print_gen(codegen, stderr, analyzed_executable, 2); |
| 12105 | 13182 | fprintf(stderr, "}\n"); |
| 12106 | 13183 | } |
| 12107 | 13184 | |
| 12108 | 13185 | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 12109 | 13186 | if (type_is_invalid(result->type)) |
| 12110 | | return codegen->invalid_instruction->value; |
| 13187 | return codegen->invalid_inst_gen->value; |
| 12111 | 13188 | |
| 12112 | 13189 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 12113 | | return codegen->invalid_instruction->value; |
| 13190 | return codegen->invalid_inst_gen->value; |
| 12114 | 13191 | |
| 12115 | 13192 | return result; |
| 12116 | 13193 | } |
| 12117 | 13194 | |
| 12118 | | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { |
| 13195 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) { |
| 12119 | 13196 | if (type_is_invalid(err_value->value->type)) |
| 12120 | 13197 | return nullptr; |
| 12121 | 13198 | |
| 12122 | 13199 | if (err_value->value->type->id != ZigTypeIdErrorSet) { |
| 12123 | | ir_add_error(ira, err_value, |
| 13200 | ir_add_error_node(ira, err_value->base.source_node, |
| 12124 | 13201 | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); |
| 12125 | 13202 | return nullptr; |
| 12126 | 13203 | } |
| ... | ... | @@ -12133,7 +13210,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu |
| 12133 | 13210 | return const_val->data.x_err_set; |
| 12134 | 13211 | } |
| 12135 | 13212 | |
| 12136 | | static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 13213 | static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 12137 | 13214 | ZigValue *val) |
| 12138 | 13215 | { |
| 12139 | 13216 | Error err; |
| ... | ... | @@ -12144,18 +13221,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN |
| 12144 | 13221 | return val->data.x_type; |
| 12145 | 13222 | } |
| 12146 | 13223 | |
| 12147 | | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { |
| 13224 | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) { |
| 12148 | 13225 | if (type_is_invalid(type_value->value->type)) |
| 12149 | 13226 | return nullptr; |
| 12150 | 13227 | |
| 12151 | 13228 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 12152 | | ir_add_error(ira, type_value, |
| 13229 | ir_add_error_node(ira, type_value->base.source_node, |
| 12153 | 13230 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); |
| 12154 | 13231 | return nullptr; |
| 12155 | 13232 | } |
| 12156 | 13233 | |
| 12157 | 13234 | Error err; |
| 12158 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, |
| 13235 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node, |
| 12159 | 13236 | type_value->value, LazyOk))) |
| 12160 | 13237 | { |
| 12161 | 13238 | return nullptr; |
| ... | ... | @@ -12164,17 +13241,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) |
| 12164 | 13241 | return type_value->value; |
| 12165 | 13242 | } |
| 12166 | 13243 | |
| 12167 | | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 13244 | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 12168 | 13245 | ZigValue *val = ir_resolve_type_lazy(ira, type_value); |
| 12169 | 13246 | if (val == nullptr) |
| 12170 | 13247 | return ira->codegen->builtin_types.entry_invalid; |
| 12171 | 13248 | |
| 12172 | | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val); |
| 13249 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val); |
| 12173 | 13250 | } |
| 12174 | 13251 | |
| 12175 | | static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *elem_type) { |
| 13252 | static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) { |
| 12176 | 13253 | if (!is_valid_vector_elem_type(elem_type)) { |
| 12177 | | ir_add_error(ira, source_instr, |
| 13254 | ir_add_error_node(ira, source_node, |
| 12178 | 13255 | buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid", |
| 12179 | 13256 | buf_ptr(&elem_type->name))); |
| 12180 | 13257 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -12182,28 +13259,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_ |
| 12182 | 13259 | return ErrorNone; |
| 12183 | 13260 | } |
| 12184 | 13261 | |
| 12185 | | static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstruction *elem_type_value) { |
| 13262 | static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type_value) { |
| 12186 | 13263 | Error err; |
| 12187 | 13264 | ZigType *elem_type = ir_resolve_type(ira, elem_type_value); |
| 12188 | 13265 | if (type_is_invalid(elem_type)) |
| 12189 | 13266 | return ira->codegen->builtin_types.entry_invalid; |
| 12190 | | if ((err = ir_validate_vector_elem_type(ira, elem_type_value, elem_type))) |
| 13267 | if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type))) |
| 12191 | 13268 | return ira->codegen->builtin_types.entry_invalid; |
| 12192 | 13269 | return elem_type; |
| 12193 | 13270 | } |
| 12194 | 13271 | |
| 12195 | | static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 13272 | static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 12196 | 13273 | ZigType *ty = ir_resolve_type(ira, type_value); |
| 12197 | 13274 | if (type_is_invalid(ty)) |
| 12198 | 13275 | return ira->codegen->builtin_types.entry_invalid; |
| 12199 | 13276 | |
| 12200 | 13277 | if (ty->id != ZigTypeIdInt) { |
| 12201 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13278 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12202 | 13279 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name))); |
| 12203 | 13280 | if (ty->id == ZigTypeIdVector && |
| 12204 | 13281 | ty->data.vector.elem_type->id == ZigTypeIdInt) |
| 12205 | 13282 | { |
| 12206 | | add_error_note(ira->codegen, msg, type_value->source_node, |
| 13283 | add_error_note(ira->codegen, msg, type_value->base.source_node, |
| 12207 | 13284 | buf_sprintf("represent vectors with their element types, i.e. '%s'", |
| 12208 | 13285 | buf_ptr(&ty->data.vector.elem_type->name))); |
| 12209 | 13286 | } |
| ... | ... | @@ -12213,12 +13290,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 12213 | 13290 | return ty; |
| 12214 | 13291 | } |
| 12215 | 13292 | |
| 12216 | | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) { |
| 13293 | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) { |
| 12217 | 13294 | if (type_is_invalid(type_value->value->type)) |
| 12218 | 13295 | return ira->codegen->builtin_types.entry_invalid; |
| 12219 | 13296 | |
| 12220 | 13297 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 12221 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13298 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12222 | 13299 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); |
| 12223 | 13300 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 12224 | 13301 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| ... | ... | @@ -12232,7 +13309,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour |
| 12232 | 13309 | assert(const_val->data.x_type != nullptr); |
| 12233 | 13310 | ZigType *result_type = const_val->data.x_type; |
| 12234 | 13311 | if (result_type->id != ZigTypeIdErrorSet) { |
| 12235 | | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 13312 | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 12236 | 13313 | buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name))); |
| 12237 | 13314 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 12238 | 13315 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| ... | ... | @@ -12241,15 +13318,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour |
| 12241 | 13318 | return result_type; |
| 12242 | 13319 | } |
| 12243 | 13320 | |
| 12244 | | static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 12245 | | if (fn_value == ira->codegen->invalid_instruction) |
| 12246 | | return nullptr; |
| 12247 | | |
| 13321 | static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) { |
| 12248 | 13322 | if (type_is_invalid(fn_value->value->type)) |
| 12249 | 13323 | return nullptr; |
| 12250 | 13324 | |
| 12251 | 13325 | if (fn_value->value->type->id != ZigTypeIdFn) { |
| 12252 | | ir_add_error_node(ira, fn_value->source_node, |
| 13326 | ir_add_error_node(ira, fn_value->base.source_node, |
| 12253 | 13327 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); |
| 12254 | 13328 | return nullptr; |
| 12255 | 13329 | } |
| ... | ... | @@ -12265,22 +13339,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 12265 | 13339 | return const_val->data.x_ptr.data.fn.fn_entry; |
| 12266 | 13340 | } |
| 12267 | 13341 | |
| 12268 | | static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 12269 | | ZigType *wanted_type, ResultLoc *result_loc) |
| 13342 | static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 13343 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 12270 | 13344 | { |
| 12271 | 13345 | assert(wanted_type->id == ZigTypeIdOptional); |
| 12272 | 13346 | |
| 12273 | 13347 | if (instr_is_comptime(value)) { |
| 12274 | 13348 | ZigType *payload_type = wanted_type->data.maybe.child_type; |
| 12275 | | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 13349 | IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 12276 | 13350 | if (type_is_invalid(casted_payload->value->type)) |
| 12277 | | return ira->codegen->invalid_instruction; |
| 13351 | return ira->codegen->invalid_inst_gen; |
| 12278 | 13352 | |
| 12279 | 13353 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 12280 | 13354 | if (!val) |
| 12281 | | return ira->codegen->invalid_instruction; |
| 13355 | return ira->codegen->invalid_inst_gen; |
| 12282 | 13356 | |
| 12283 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13357 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12284 | 13358 | source_instr->scope, source_instr->source_node); |
| 12285 | 13359 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 12286 | 13360 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| ... | ... | @@ -12295,40 +13369,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 12295 | 13369 | if (result_loc == nullptr && handle_is_ptr(wanted_type)) { |
| 12296 | 13370 | result_loc = no_result_loc(); |
| 12297 | 13371 | } |
| 12298 | | IrInstruction *result_loc_inst = nullptr; |
| 13372 | IrInstGen *result_loc_inst = nullptr; |
| 12299 | 13373 | if (result_loc != nullptr) { |
| 12300 | 13374 | 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)) { |
| 13375 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13376 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13377 | { |
| 12302 | 13378 | return result_loc_inst; |
| 12303 | 13379 | } |
| 12304 | 13380 | } |
| 12305 | | IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13381 | IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12306 | 13382 | result->value->data.rh_maybe = RuntimeHintOptionalNonNull; |
| 12307 | 13383 | return result; |
| 12308 | 13384 | } |
| 12309 | 13385 | |
| 12310 | | static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 12311 | | IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 13386 | static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr, |
| 13387 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 12312 | 13388 | { |
| 12313 | 13389 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 12314 | 13390 | |
| 12315 | 13391 | ZigType *payload_type = wanted_type->data.error_union.payload_type; |
| 12316 | 13392 | ZigType *err_set_type = wanted_type->data.error_union.err_set_type; |
| 12317 | 13393 | if (instr_is_comptime(value)) { |
| 12318 | | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 13394 | IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 12319 | 13395 | if (type_is_invalid(casted_payload->value->type)) |
| 12320 | | return ira->codegen->invalid_instruction; |
| 13396 | return ira->codegen->invalid_inst_gen; |
| 12321 | 13397 | |
| 12322 | 13398 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 12323 | 13399 | if (!val) |
| 12324 | | return ira->codegen->invalid_instruction; |
| 13400 | return ira->codegen->invalid_inst_gen; |
| 12325 | 13401 | |
| 12326 | 13402 | ZigValue *err_set_val = create_const_vals(1); |
| 12327 | 13403 | err_set_val->type = err_set_type; |
| 12328 | 13404 | err_set_val->special = ConstValSpecialStatic; |
| 12329 | 13405 | err_set_val->data.x_err_set = nullptr; |
| 12330 | 13406 | |
| 12331 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13407 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12332 | 13408 | source_instr->scope, source_instr->source_node); |
| 12333 | 13409 | const_instruction->base.value->type = wanted_type; |
| 12334 | 13410 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12337,23 +13413,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 12337 | 13413 | return &const_instruction->base; |
| 12338 | 13414 | } |
| 12339 | 13415 | |
| 12340 | | IrInstruction *result_loc_inst; |
| 13416 | IrInstGen *result_loc_inst; |
| 12341 | 13417 | if (handle_is_ptr(wanted_type)) { |
| 12342 | 13418 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12343 | 13419 | 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)) { |
| 13420 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13421 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 12345 | 13422 | return result_loc_inst; |
| 12346 | 13423 | } |
| 12347 | 13424 | } else { |
| 12348 | 13425 | result_loc_inst = nullptr; |
| 12349 | 13426 | } |
| 12350 | 13427 | |
| 12351 | | IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13428 | IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12352 | 13429 | result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 12353 | 13430 | return result; |
| 12354 | 13431 | } |
| 12355 | 13432 | |
| 12356 | | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 13433 | static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 12357 | 13434 | ZigType *wanted_type) |
| 12358 | 13435 | { |
| 12359 | 13436 | assert(value->value->type->id == ZigTypeIdErrorSet); |
| ... | ... | @@ -12362,10 +13439,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12362 | 13439 | if (instr_is_comptime(value)) { |
| 12363 | 13440 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12364 | 13441 | if (!val) |
| 12365 | | return ira->codegen->invalid_instruction; |
| 13442 | return ira->codegen->invalid_inst_gen; |
| 12366 | 13443 | |
| 12367 | 13444 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 12368 | | return ira->codegen->invalid_instruction; |
| 13445 | return ira->codegen->invalid_inst_gen; |
| 12369 | 13446 | } |
| 12370 | 13447 | if (!type_is_global_error_set(wanted_type)) { |
| 12371 | 13448 | bool subset = false; |
| ... | ... | @@ -12379,11 +13456,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12379 | 13456 | ir_add_error(ira, source_instr, |
| 12380 | 13457 | buf_sprintf("error.%s not a member of error set '%s'", |
| 12381 | 13458 | buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name))); |
| 12382 | | return ira->codegen->invalid_instruction; |
| 13459 | return ira->codegen->invalid_inst_gen; |
| 12383 | 13460 | } |
| 12384 | 13461 | } |
| 12385 | 13462 | |
| 12386 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13463 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12387 | 13464 | source_instr->scope, source_instr->source_node); |
| 12388 | 13465 | const_instruction->base.value->type = wanted_type; |
| 12389 | 13466 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12391,18 +13468,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 12391 | 13468 | return &const_instruction->base; |
| 12392 | 13469 | } |
| 12393 | 13470 | |
| 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; |
| 13471 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet); |
| 12397 | 13472 | } |
| 12398 | 13473 | |
| 12399 | | static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr, |
| 12400 | | IrInstruction *frame_ptr, ZigType *wanted_type) |
| 13474 | static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 13475 | IrInstGen *frame_ptr, ZigType *wanted_type) |
| 12401 | 13476 | { |
| 12402 | 13477 | if (instr_is_comptime(frame_ptr)) { |
| 12403 | 13478 | ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); |
| 12404 | 13479 | if (ptr_val == nullptr) |
| 12405 | | return ira->codegen->invalid_instruction; |
| 13480 | return ira->codegen->invalid_inst_gen; |
| 12406 | 13481 | |
| 12407 | 13482 | ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr); |
| 12408 | 13483 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| ... | ... | @@ -12410,44 +13485,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc |
| 12410 | 13485 | } |
| 12411 | 13486 | } |
| 12412 | 13487 | |
| 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; |
| 13488 | return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast); |
| 12417 | 13489 | } |
| 12418 | 13490 | |
| 12419 | | static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr, |
| 12420 | | IrInstruction *value, ZigType *wanted_type) |
| 13491 | static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 13492 | IrInstGen *value, ZigType *wanted_type) |
| 12421 | 13493 | { |
| 12422 | 13494 | if (instr_is_comptime(value)) { |
| 12423 | 13495 | zig_panic("TODO comptime anyframe->T to anyframe"); |
| 12424 | 13496 | } |
| 12425 | 13497 | |
| 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; |
| 13498 | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 12430 | 13499 | } |
| 12431 | 13500 | |
| 12432 | 13501 | |
| 12433 | | static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 13502 | static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 12434 | 13503 | ZigType *wanted_type, ResultLoc *result_loc) |
| 12435 | 13504 | { |
| 12436 | 13505 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| 12437 | 13506 | |
| 12438 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 13507 | IrInstGen *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 12439 | 13508 | |
| 12440 | 13509 | if (instr_is_comptime(casted_value)) { |
| 12441 | 13510 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 12442 | 13511 | if (!val) |
| 12443 | | return ira->codegen->invalid_instruction; |
| 13512 | return ira->codegen->invalid_inst_gen; |
| 12444 | 13513 | |
| 12445 | 13514 | ZigValue *err_set_val = create_const_vals(1); |
| 12446 | 13515 | err_set_val->special = ConstValSpecialStatic; |
| 12447 | 13516 | err_set_val->type = wanted_type->data.error_union.err_set_type; |
| 12448 | 13517 | err_set_val->data.x_err_set = val->data.x_err_set; |
| 12449 | 13518 | |
| 12450 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 13519 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 12451 | 13520 | source_instr->scope, source_instr->source_node); |
| 12452 | 13521 | const_instruction->base.value->type = wanted_type; |
| 12453 | 13522 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -12456,11 +13525,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 12456 | 13525 | return &const_instruction->base; |
| 12457 | 13526 | } |
| 12458 | 13527 | |
| 12459 | | IrInstruction *result_loc_inst; |
| 13528 | IrInstGen *result_loc_inst; |
| 12460 | 13529 | if (handle_is_ptr(wanted_type)) { |
| 12461 | 13530 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12462 | 13531 | 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)) { |
| 13532 | if (type_is_invalid(result_loc_inst->value->type) || |
| 13533 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 13534 | { |
| 12464 | 13535 | return result_loc_inst; |
| 12465 | 13536 | } |
| 12466 | 13537 | } else { |
| ... | ... | @@ -12468,19 +13539,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 12468 | 13539 | } |
| 12469 | 13540 | |
| 12470 | 13541 | |
| 12471 | | IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 13542 | IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 12472 | 13543 | result->value->data.rh_error_union = RuntimeHintErrorUnionError; |
| 12473 | 13544 | return result; |
| 12474 | 13545 | } |
| 12475 | 13546 | |
| 12476 | | static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { |
| 13547 | static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) { |
| 12477 | 13548 | assert(wanted_type->id == ZigTypeIdOptional); |
| 12478 | 13549 | assert(instr_is_comptime(value)); |
| 12479 | 13550 | |
| 12480 | 13551 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12481 | 13552 | assert(val != nullptr); |
| 12482 | 13553 | |
| 12483 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13554 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12484 | 13555 | result->value->special = ConstValSpecialStatic; |
| 12485 | 13556 | if (get_codegen_ptr_type(wanted_type) != nullptr) { |
| 12486 | 13557 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| ... | ... | @@ -12492,8 +13563,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 12492 | 13563 | return result; |
| 12493 | 13564 | } |
| 12494 | 13565 | |
| 12495 | | static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr, |
| 12496 | | IrInstruction *value, ZigType *wanted_type) |
| 13566 | static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr, |
| 13567 | IrInstGen *value, ZigType *wanted_type) |
| 12497 | 13568 | { |
| 12498 | 13569 | assert(wanted_type->id == ZigTypeIdPointer); |
| 12499 | 13570 | assert(wanted_type->data.pointer.ptr_len == PtrLenC); |
| ... | ... | @@ -12502,24 +13573,24 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction |
| 12502 | 13573 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 12503 | 13574 | assert(val != nullptr); |
| 12504 | 13575 | |
| 12505 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13576 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12506 | 13577 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 12507 | 13578 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 12508 | 13579 | return result; |
| 12509 | 13580 | } |
| 12510 | 13581 | |
| 12511 | | static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 13582 | static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 12512 | 13583 | bool is_const, bool is_volatile) |
| 12513 | 13584 | { |
| 12514 | 13585 | Error err; |
| 12515 | 13586 | |
| 12516 | 13587 | if (type_is_invalid(value->value->type)) |
| 12517 | | return ira->codegen->invalid_instruction; |
| 13588 | return ira->codegen->invalid_inst_gen; |
| 12518 | 13589 | |
| 12519 | 13590 | if (instr_is_comptime(value)) { |
| 12520 | 13591 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 12521 | 13592 | if (!val) |
| 12522 | | return ira->codegen->invalid_instruction; |
| 13593 | return ira->codegen->invalid_inst_gen; |
| 12523 | 13594 | return ir_get_const_ptr(ira, source_instruction, val, value->value->type, |
| 12524 | 13595 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 12525 | 13596 | } |
| ... | ... | @@ -12528,9 +13599,9 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 12528 | 13599 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 12529 | 13600 | |
| 12530 | 13601 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) |
| 12531 | | return ira->codegen->invalid_instruction; |
| 13602 | return ira->codegen->invalid_inst_gen; |
| 12532 | 13603 | |
| 12533 | | IrInstruction *result_loc; |
| 13604 | IrInstGen *result_loc; |
| 12534 | 13605 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { |
| 12535 | 13606 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, |
| 12536 | 13607 | false, true); |
| ... | ... | @@ -12538,12 +13609,12 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 12538 | 13609 | result_loc = nullptr; |
| 12539 | 13610 | } |
| 12540 | 13611 | |
| 12541 | | IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 13612 | IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 12542 | 13613 | new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; |
| 12543 | 13614 | return new_instruction; |
| 12544 | 13615 | } |
| 12545 | 13616 | |
| 12546 | | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) { |
| 13617 | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) { |
| 12547 | 13618 | assert(union_type->id == ZigTypeIdUnion); |
| 12548 | 13619 | |
| 12549 | 13620 | Error err; |
| ... | ... | @@ -12555,36 +13626,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_ |
| 12555 | 13626 | assert(union_type->data.unionation.tag_type != nullptr); |
| 12556 | 13627 | return union_type->data.unionation.tag_type; |
| 12557 | 13628 | } else { |
| 12558 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union '%s' has no tag", |
| 13629 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union '%s' has no tag", |
| 12559 | 13630 | buf_ptr(&union_type->name))); |
| 12560 | 13631 | add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here")); |
| 12561 | 13632 | return ira->codegen->builtin_types.entry_invalid; |
| 12562 | 13633 | } |
| 12563 | 13634 | } |
| 12564 | 13635 | |
| 12565 | | static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target) { |
| 13636 | static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 12566 | 13637 | Error err; |
| 12567 | 13638 | |
| 12568 | | IrInstruction *enum_target; |
| 13639 | IrInstGen *enum_target; |
| 12569 | 13640 | ZigType *enum_type; |
| 12570 | 13641 | if (target->value->type->id == ZigTypeIdUnion) { |
| 12571 | | enum_type = ir_resolve_union_tag_type(ira, target, target->value->type); |
| 13642 | enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type); |
| 12572 | 13643 | if (type_is_invalid(enum_type)) |
| 12573 | | return ira->codegen->invalid_instruction; |
| 13644 | return ira->codegen->invalid_inst_gen; |
| 12574 | 13645 | enum_target = ir_implicit_cast(ira, target, enum_type); |
| 12575 | 13646 | if (type_is_invalid(enum_target->value->type)) |
| 12576 | | return ira->codegen->invalid_instruction; |
| 13647 | return ira->codegen->invalid_inst_gen; |
| 12577 | 13648 | } else if (target->value->type->id == ZigTypeIdEnum) { |
| 12578 | 13649 | enum_target = target; |
| 12579 | 13650 | enum_type = target->value->type; |
| 12580 | 13651 | } else { |
| 12581 | | ir_add_error(ira, target, |
| 13652 | ir_add_error_node(ira, target->base.source_node, |
| 12582 | 13653 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); |
| 12583 | | return ira->codegen->invalid_instruction; |
| 13654 | return ira->codegen->invalid_inst_gen; |
| 12584 | 13655 | } |
| 12585 | 13656 | |
| 12586 | 13657 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown))) |
| 12587 | | return ira->codegen->invalid_instruction; |
| 13658 | return ira->codegen->invalid_inst_gen; |
| 12588 | 13659 | |
| 12589 | 13660 | ZigType *tag_type = enum_type->data.enumeration.tag_int_type; |
| 12590 | 13661 | assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt); |
| ... | ... | @@ -12593,7 +13664,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12593 | 13664 | if (enum_type->data.enumeration.layout == ContainerLayoutAuto && |
| 12594 | 13665 | enum_type->data.enumeration.src_field_count == 1) |
| 12595 | 13666 | { |
| 12596 | | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 13667 | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 12597 | 13668 | init_const_bigint(result->value, tag_type, |
| 12598 | 13669 | &enum_type->data.enumeration.fields[0].value); |
| 12599 | 13670 | return result; |
| ... | ... | @@ -12602,20 +13673,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12602 | 13673 | if (instr_is_comptime(enum_target)) { |
| 12603 | 13674 | ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 12604 | 13675 | if (!val) |
| 12605 | | return ira->codegen->invalid_instruction; |
| 12606 | | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 13676 | return ira->codegen->invalid_inst_gen; |
| 13677 | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 12607 | 13678 | init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); |
| 12608 | 13679 | return result; |
| 12609 | 13680 | } |
| 12610 | 13681 | |
| 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; |
| 13682 | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type); |
| 12615 | 13683 | } |
| 12616 | 13684 | |
| 12617 | | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, |
| 12618 | | IrInstruction *target, ZigType *wanted_type) |
| 13685 | static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 13686 | IrInstGen *target, ZigType *wanted_type) |
| 12619 | 13687 | { |
| 12620 | 13688 | assert(target->value->type->id == ZigTypeIdUnion); |
| 12621 | 13689 | assert(wanted_type->id == ZigTypeIdEnum); |
| ... | ... | @@ -12624,8 +13692,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12624 | 13692 | if (instr_is_comptime(target)) { |
| 12625 | 13693 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12626 | 13694 | if (!val) |
| 12627 | | return ira->codegen->invalid_instruction; |
| 12628 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13695 | return ira->codegen->invalid_inst_gen; |
| 13696 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12629 | 13697 | result->value->special = ConstValSpecialStatic; |
| 12630 | 13698 | result->value->type = wanted_type; |
| 12631 | 13699 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); |
| ... | ... | @@ -12636,7 +13704,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12636 | 13704 | if (wanted_type->data.enumeration.layout == ContainerLayoutAuto && |
| 12637 | 13705 | wanted_type->data.enumeration.src_field_count == 1) |
| 12638 | 13706 | { |
| 12639 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13707 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12640 | 13708 | result->value->special = ConstValSpecialStatic; |
| 12641 | 13709 | result->value->type = wanted_type; |
| 12642 | 13710 | TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; |
| ... | ... | @@ -12644,48 +13712,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12644 | 13712 | return result; |
| 12645 | 13713 | } |
| 12646 | 13714 | |
| 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; |
| 13715 | return ir_build_union_tag(ira, source_instr, target, wanted_type); |
| 12651 | 13716 | } |
| 12652 | 13717 | |
| 12653 | | static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr, |
| 12654 | | IrInstruction *target, ZigType *wanted_type) |
| 13718 | static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr, |
| 13719 | IrInstGen *target, ZigType *wanted_type) |
| 12655 | 13720 | { |
| 12656 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13721 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12657 | 13722 | result->value->special = ConstValSpecialUndef; |
| 12658 | 13723 | return result; |
| 12659 | 13724 | } |
| 12660 | 13725 | |
| 12661 | | static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr, |
| 12662 | | IrInstruction *uncasted_target, ZigType *wanted_type) |
| 13726 | static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 13727 | IrInstGen *uncasted_target, ZigType *wanted_type) |
| 12663 | 13728 | { |
| 12664 | 13729 | Error err; |
| 12665 | 13730 | assert(wanted_type->id == ZigTypeIdUnion); |
| 12666 | 13731 | |
| 12667 | 13732 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown))) |
| 12668 | | return ira->codegen->invalid_instruction; |
| 13733 | return ira->codegen->invalid_inst_gen; |
| 12669 | 13734 | |
| 12670 | | IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 13735 | IrInstGen *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 12671 | 13736 | if (type_is_invalid(target->value->type)) |
| 12672 | | return ira->codegen->invalid_instruction; |
| 13737 | return ira->codegen->invalid_inst_gen; |
| 12673 | 13738 | |
| 12674 | 13739 | if (instr_is_comptime(target)) { |
| 12675 | 13740 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12676 | 13741 | if (!val) |
| 12677 | | return ira->codegen->invalid_instruction; |
| 13742 | return ira->codegen->invalid_inst_gen; |
| 12678 | 13743 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 12679 | 13744 | assert(union_field != nullptr); |
| 12680 | 13745 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); |
| 12681 | 13746 | if (field_type == nullptr) |
| 12682 | | return ira->codegen->invalid_instruction; |
| 13747 | return ira->codegen->invalid_inst_gen; |
| 12683 | 13748 | if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown))) |
| 12684 | | return ira->codegen->invalid_instruction; |
| 13749 | return ira->codegen->invalid_inst_gen; |
| 12685 | 13750 | |
| 12686 | 13751 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 12687 | 13752 | case OnePossibleValueInvalid: |
| 12688 | | return ira->codegen->invalid_instruction; |
| 13753 | return ira->codegen->invalid_inst_gen; |
| 12689 | 13754 | case OnePossibleValueNo: { |
| 12690 | 13755 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 12691 | 13756 | union_field->enum_field->decl_index); |
| ... | ... | @@ -12696,13 +13761,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12696 | 13761 | buf_ptr(union_field->name))); |
| 12697 | 13762 | add_error_note(ira->codegen, msg, field_node, |
| 12698 | 13763 | buf_sprintf("field '%s' declared here", buf_ptr(union_field->name))); |
| 12699 | | return ira->codegen->invalid_instruction; |
| 13764 | return ira->codegen->invalid_inst_gen; |
| 12700 | 13765 | } |
| 12701 | 13766 | case OnePossibleValueYes: |
| 12702 | 13767 | break; |
| 12703 | 13768 | } |
| 12704 | 13769 | |
| 12705 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13770 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12706 | 13771 | result->value->special = ConstValSpecialStatic; |
| 12707 | 13772 | result->value->type = wanted_type; |
| 12708 | 13773 | bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); |
| ... | ... | @@ -12715,9 +13780,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12715 | 13780 | // if the union has all fields 0 bits, we can do it |
| 12716 | 13781 | // and in fact it's a noop cast because the union value is just the enum value |
| 12717 | 13782 | 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; |
| 13783 | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop); |
| 12721 | 13784 | } |
| 12722 | 13785 | |
| 12723 | 13786 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| ... | ... | @@ -12727,10 +13790,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12727 | 13790 | TypeUnionField *union_field = &wanted_type->data.unionation.fields[i]; |
| 12728 | 13791 | ZigType *field_type = resolve_union_field_type(ira->codegen, union_field); |
| 12729 | 13792 | if (field_type == nullptr) |
| 12730 | | return ira->codegen->invalid_instruction; |
| 13793 | return ira->codegen->invalid_inst_gen; |
| 12731 | 13794 | bool has_bits; |
| 12732 | 13795 | if ((err = type_has_bits2(ira->codegen, field_type, &has_bits))) |
| 12733 | | return ira->codegen->invalid_instruction; |
| 13796 | return ira->codegen->invalid_inst_gen; |
| 12734 | 13797 | if (has_bits) { |
| 12735 | 13798 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i); |
| 12736 | 13799 | add_error_note(ira->codegen, msg, field_node, |
| ... | ... | @@ -12739,23 +13802,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12739 | 13802 | buf_ptr(&field_type->name))); |
| 12740 | 13803 | } |
| 12741 | 13804 | } |
| 12742 | | return ira->codegen->invalid_instruction; |
| 13805 | return ira->codegen->invalid_inst_gen; |
| 12743 | 13806 | } |
| 12744 | 13807 | |
| 12745 | | static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, |
| 12746 | | IrInstruction *target, ZigType *wanted_type) |
| 13808 | static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr, |
| 13809 | IrInstGen *target, ZigType *wanted_type) |
| 12747 | 13810 | { |
| 12748 | 13811 | assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); |
| 12749 | 13812 | |
| 12750 | 13813 | if (instr_is_comptime(target)) { |
| 12751 | 13814 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12752 | 13815 | if (!val) |
| 12753 | | return ira->codegen->invalid_instruction; |
| 13816 | return ira->codegen->invalid_inst_gen; |
| 12754 | 13817 | if (wanted_type->id == ZigTypeIdInt) { |
| 12755 | 13818 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { |
| 12756 | 13819 | ir_add_error(ira, source_instr, |
| 12757 | 13820 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| 12758 | | return ira->codegen->invalid_instruction; |
| 13821 | return ira->codegen->invalid_inst_gen; |
| 12759 | 13822 | } |
| 12760 | 13823 | if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count, |
| 12761 | 13824 | wanted_type->data.integral.is_signed)) |
| ... | ... | @@ -12763,10 +13826,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12763 | 13826 | ir_add_error(ira, source_instr, |
| 12764 | 13827 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| 12765 | 13828 | buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name))); |
| 12766 | | return ira->codegen->invalid_instruction; |
| 13829 | return ira->codegen->invalid_inst_gen; |
| 12767 | 13830 | } |
| 12768 | 13831 | } |
| 12769 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13832 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12770 | 13833 | result->value->type = wanted_type; |
| 12771 | 13834 | if (wanted_type->id == ZigTypeIdInt) { |
| 12772 | 13835 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| ... | ... | @@ -12783,19 +13846,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12783 | 13846 | assert(wanted_type->id == ZigTypeIdInt); |
| 12784 | 13847 | assert(type_has_bits(target->value->type)); |
| 12785 | 13848 | ir_build_assert_zero(ira, source_instr, target); |
| 12786 | | IrInstruction *result = ir_const_unsigned(ira, source_instr, 0); |
| 13849 | IrInstGen *result = ir_const_unsigned(ira, source_instr, 0); |
| 12787 | 13850 | result->value->type = wanted_type; |
| 12788 | 13851 | return result; |
| 12789 | 13852 | } |
| 12790 | 13853 | |
| 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; |
| 13854 | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 12795 | 13855 | } |
| 12796 | 13856 | |
| 12797 | | static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, |
| 12798 | | IrInstruction *target, ZigType *wanted_type) |
| 13857 | static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 13858 | IrInstGen *target, ZigType *wanted_type) |
| 12799 | 13859 | { |
| 12800 | 13860 | Error err; |
| 12801 | 13861 | assert(wanted_type->id == ZigTypeIdEnum); |
| ... | ... | @@ -12803,14 +13863,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12803 | 13863 | ZigType *actual_type = target->value->type; |
| 12804 | 13864 | |
| 12805 | 13865 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) |
| 12806 | | return ira->codegen->invalid_instruction; |
| 13866 | return ira->codegen->invalid_inst_gen; |
| 12807 | 13867 | |
| 12808 | 13868 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { |
| 12809 | 13869 | ir_add_error(ira, source_instr, |
| 12810 | 13870 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", |
| 12811 | 13871 | buf_ptr(&actual_type->name), |
| 12812 | 13872 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); |
| 12813 | | return ira->codegen->invalid_instruction; |
| 13873 | return ira->codegen->invalid_inst_gen; |
| 12814 | 13874 | } |
| 12815 | 13875 | |
| 12816 | 13876 | assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt); |
| ... | ... | @@ -12818,7 +13878,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12818 | 13878 | if (instr_is_comptime(target)) { |
| 12819 | 13879 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12820 | 13880 | if (!val) |
| 12821 | | return ira->codegen->invalid_instruction; |
| 13881 | return ira->codegen->invalid_inst_gen; |
| 12822 | 13882 | |
| 12823 | 13883 | TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint); |
| 12824 | 13884 | if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) { |
| ... | ... | @@ -12829,28 +13889,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12829 | 13889 | buf_ptr(&wanted_type->name), buf_ptr(val_buf))); |
| 12830 | 13890 | add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node, |
| 12831 | 13891 | buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name))); |
| 12832 | | return ira->codegen->invalid_instruction; |
| 13892 | return ira->codegen->invalid_inst_gen; |
| 12833 | 13893 | } |
| 12834 | 13894 | |
| 12835 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13895 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12836 | 13896 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); |
| 12837 | 13897 | return result; |
| 12838 | 13898 | } |
| 12839 | 13899 | |
| 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; |
| 13900 | return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target); |
| 12844 | 13901 | } |
| 12845 | 13902 | |
| 12846 | | static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, |
| 12847 | | IrInstruction *target, ZigType *wanted_type) |
| 13903 | static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr, |
| 13904 | IrInstGen *target, ZigType *wanted_type) |
| 12848 | 13905 | { |
| 12849 | 13906 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12850 | 13907 | if (!val) |
| 12851 | | return ira->codegen->invalid_instruction; |
| 13908 | return ira->codegen->invalid_inst_gen; |
| 12852 | 13909 | |
| 12853 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13910 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12854 | 13911 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 12855 | 13912 | float_init_float(result->value, val); |
| 12856 | 13913 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -12861,7 +13918,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 12861 | 13918 | return result; |
| 12862 | 13919 | } |
| 12863 | 13920 | |
| 12864 | | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 13921 | static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 12865 | 13922 | ZigType *wanted_type) |
| 12866 | 13923 | { |
| 12867 | 13924 | assert(target->value->type->id == ZigTypeIdInt); |
| ... | ... | @@ -12871,12 +13928,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12871 | 13928 | if (instr_is_comptime(target)) { |
| 12872 | 13929 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12873 | 13930 | if (!val) |
| 12874 | | return ira->codegen->invalid_instruction; |
| 13931 | return ira->codegen->invalid_inst_gen; |
| 12875 | 13932 | |
| 12876 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13933 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12877 | 13934 | |
| 12878 | 13935 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 12879 | | return ira->codegen->invalid_instruction; |
| 13936 | return ira->codegen->invalid_inst_gen; |
| 12880 | 13937 | } |
| 12881 | 13938 | |
| 12882 | 13939 | if (type_is_global_error_set(wanted_type)) { |
| ... | ... | @@ -12888,7 +13945,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12888 | 13945 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 12889 | 13946 | ir_add_error(ira, source_instr, |
| 12890 | 13947 | buf_sprintf("integer value %s represents no error", buf_ptr(val_buf))); |
| 12891 | | return ira->codegen->invalid_instruction; |
| 13948 | return ira->codegen->invalid_inst_gen; |
| 12892 | 13949 | } |
| 12893 | 13950 | |
| 12894 | 13951 | size_t index = bigint_as_usize(&val->data.x_bigint); |
| ... | ... | @@ -12912,7 +13969,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12912 | 13969 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 12913 | 13970 | ir_add_error(ira, source_instr, |
| 12914 | 13971 | 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; |
| 13972 | return ira->codegen->invalid_inst_gen; |
| 12916 | 13973 | } |
| 12917 | 13974 | |
| 12918 | 13975 | result->value->data.x_err_set = err; |
| ... | ... | @@ -12920,12 +13977,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12920 | 13977 | } |
| 12921 | 13978 | } |
| 12922 | 13979 | |
| 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; |
| 13980 | return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 12926 | 13981 | } |
| 12927 | 13982 | |
| 12928 | | static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 13983 | static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 12929 | 13984 | ZigType *wanted_type) |
| 12930 | 13985 | { |
| 12931 | 13986 | assert(wanted_type->id == ZigTypeIdInt); |
| ... | ... | @@ -12935,9 +13990,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12935 | 13990 | if (instr_is_comptime(target)) { |
| 12936 | 13991 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12937 | 13992 | if (!val) |
| 12938 | | return ira->codegen->invalid_instruction; |
| 13993 | return ira->codegen->invalid_inst_gen; |
| 12939 | 13994 | |
| 12940 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13995 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12941 | 13996 | |
| 12942 | 13997 | ErrorTableEntry *err; |
| 12943 | 13998 | if (err_type->id == ZigTypeIdErrorUnion) { |
| ... | ... | @@ -12957,7 +14012,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12957 | 14012 | ir_add_error_node(ira, source_instr->source_node, |
| 12958 | 14013 | buf_sprintf("error code '%s' does not fit in '%s'", |
| 12959 | 14014 | buf_ptr(&err->name), buf_ptr(&wanted_type->name))); |
| 12960 | | return ira->codegen->invalid_instruction; |
| 14015 | return ira->codegen->invalid_inst_gen; |
| 12961 | 14016 | } |
| 12962 | 14017 | |
| 12963 | 14018 | return result; |
| ... | ... | @@ -12973,14 +14028,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12973 | 14028 | } |
| 12974 | 14029 | if (!type_is_global_error_set(err_set_type)) { |
| 12975 | 14030 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) { |
| 12976 | | return ira->codegen->invalid_instruction; |
| 14031 | return ira->codegen->invalid_inst_gen; |
| 12977 | 14032 | } |
| 12978 | 14033 | if (err_set_type->data.error_set.err_count == 0) { |
| 12979 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14034 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12980 | 14035 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 12981 | 14036 | return result; |
| 12982 | 14037 | } else if (err_set_type->data.error_set.err_count == 1) { |
| 12983 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14038 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 12984 | 14039 | ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; |
| 12985 | 14040 | bigint_init_unsigned(&result->value->data.x_bigint, err->value); |
| 12986 | 14041 | return result; |
| ... | ... | @@ -12992,21 +14047,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12992 | 14047 | if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) { |
| 12993 | 14048 | ir_add_error_node(ira, source_instr->source_node, |
| 12994 | 14049 | buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name))); |
| 12995 | | return ira->codegen->invalid_instruction; |
| 14050 | return ira->codegen->invalid_inst_gen; |
| 12996 | 14051 | } |
| 12997 | 14052 | |
| 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; |
| 14053 | return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 13001 | 14054 | } |
| 13002 | 14055 | |
| 13003 | | static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 14056 | static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 13004 | 14057 | ZigType *wanted_type) |
| 13005 | 14058 | { |
| 13006 | 14059 | assert(wanted_type->id == ZigTypeIdPointer); |
| 13007 | 14060 | Error err; |
| 13008 | 14061 | if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13009 | | return ira->codegen->invalid_instruction; |
| 14062 | return ira->codegen->invalid_inst_gen; |
| 13010 | 14063 | assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const); |
| 13011 | 14064 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type)); |
| 13012 | 14065 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| ... | ... | @@ -13016,12 +14069,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13016 | 14069 | if (instr_is_comptime(target)) { |
| 13017 | 14070 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 13018 | 14071 | if (!val) |
| 13019 | | return ira->codegen->invalid_instruction; |
| 14072 | return ira->codegen->invalid_inst_gen; |
| 13020 | 14073 | |
| 13021 | 14074 | assert(val->type->id == ZigTypeIdPointer); |
| 13022 | 14075 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 13023 | 14076 | if (pointee == nullptr) |
| 13024 | | return ira->codegen->invalid_instruction; |
| 14077 | return ira->codegen->invalid_inst_gen; |
| 13025 | 14078 | if (pointee->special != ConstValSpecialRuntime) { |
| 13026 | 14079 | ZigValue *array_val = create_const_vals(1); |
| 13027 | 14080 | array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -13031,7 +14084,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13031 | 14084 | array_val->parent.id = ConstParentIdScalar; |
| 13032 | 14085 | array_val->parent.data.p_scalar.scalar_val = pointee; |
| 13033 | 14086 | |
| 13034 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 14087 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 13035 | 14088 | source_instr->scope, source_instr->source_node); |
| 13036 | 14089 | const_instruction->base.value->type = wanted_type; |
| 13037 | 14090 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -13043,10 +14096,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 13043 | 14096 | } |
| 13044 | 14097 | |
| 13045 | 14098 | // 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; |
| 14099 | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast); |
| 13050 | 14100 | } |
| 13051 | 14101 | |
| 13052 | 14102 | static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result, |
| ... | ... | @@ -13234,12 +14284,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 13234 | 14284 | } |
| 13235 | 14285 | } |
| 13236 | 14286 | |
| 13237 | | static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr, |
| 13238 | | IrInstruction *array, ZigType *vector_type) |
| 14287 | static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr, |
| 14288 | IrInstGen *array, ZigType *vector_type) |
| 13239 | 14289 | { |
| 13240 | 14290 | if (instr_is_comptime(array)) { |
| 13241 | 14291 | // arrays and vectors have the same ZigValue representation |
| 13242 | | IrInstruction *result = ir_const(ira, source_instr, vector_type); |
| 14292 | IrInstGen *result = ir_const(ira, source_instr, vector_type); |
| 13243 | 14293 | copy_const_val(result->value, array->value); |
| 13244 | 14294 | result->value->type = vector_type; |
| 13245 | 14295 | return result; |
| ... | ... | @@ -13247,12 +14297,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 13247 | 14297 | return ir_build_array_to_vector(ira, source_instr, array, vector_type); |
| 13248 | 14298 | } |
| 13249 | 14299 | |
| 13250 | | static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr, |
| 13251 | | IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc) |
| 14300 | static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 14301 | IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc) |
| 13252 | 14302 | { |
| 13253 | 14303 | if (instr_is_comptime(vector)) { |
| 13254 | 14304 | // arrays and vectors have the same ZigValue representation |
| 13255 | | IrInstruction *result = ir_const(ira, source_instr, array_type); |
| 14305 | IrInstGen *result = ir_const(ira, source_instr, array_type); |
| 13256 | 14306 | copy_const_val(result->value, vector->value); |
| 13257 | 14307 | result->value->type = array_type; |
| 13258 | 14308 | return result; |
| ... | ... | @@ -13260,18 +14310,18 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 13260 | 14310 | if (result_loc == nullptr) { |
| 13261 | 14311 | result_loc = no_result_loc(); |
| 13262 | 14312 | } |
| 13263 | | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 14313 | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 13264 | 14314 | true, false, true); |
| 13265 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 14315 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 13266 | 14316 | return result_loc_inst; |
| 13267 | 14317 | } |
| 13268 | 14318 | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); |
| 13269 | 14319 | } |
| 13270 | 14320 | |
| 13271 | | static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 13272 | | IrInstruction *integer, ZigType *dest_type) |
| 14321 | static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 14322 | IrInstGen *integer, ZigType *dest_type) |
| 13273 | 14323 | { |
| 13274 | | IrInstruction *unsigned_integer; |
| 14324 | IrInstGen *unsigned_integer; |
| 13275 | 14325 | if (instr_is_comptime(integer)) { |
| 13276 | 14326 | unsigned_integer = integer; |
| 13277 | 14327 | } else { |
| ... | ... | @@ -13284,7 +14334,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 13284 | 14334 | buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", |
| 13285 | 14335 | buf_ptr(&integer->value->type->name), |
| 13286 | 14336 | buf_ptr(&dest_type->name))); |
| 13287 | | return ira->codegen->invalid_instruction; |
| 14337 | return ira->codegen->invalid_inst_gen; |
| 13288 | 14338 | } |
| 13289 | 14339 | |
| 13290 | 14340 | if (integer->value->type->data.integral.is_signed) { |
| ... | ... | @@ -13292,7 +14342,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 13292 | 14342 | integer->value->type->data.integral.bit_count); |
| 13293 | 14343 | unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); |
| 13294 | 14344 | if (type_is_invalid(unsigned_integer->value->type)) |
| 13295 | | return ira->codegen->invalid_instruction; |
| 14345 | return ira->codegen->invalid_inst_gen; |
| 13296 | 14346 | } else { |
| 13297 | 14347 | unsigned_integer = integer; |
| 13298 | 14348 | } |
| ... | ... | @@ -13312,14 +14362,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) { |
| 13312 | 14362 | return false; |
| 13313 | 14363 | } |
| 13314 | 14364 | |
| 13315 | | static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 14365 | static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 13316 | 14366 | ZigType *enum_type) |
| 13317 | 14367 | { |
| 13318 | 14368 | assert(enum_type->id == ZigTypeIdEnum); |
| 13319 | 14369 | |
| 13320 | 14370 | Error err; |
| 13321 | 14371 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown))) |
| 13322 | | return ira->codegen->invalid_instruction; |
| 14372 | return ira->codegen->invalid_inst_gen; |
| 13323 | 14373 | |
| 13324 | 14374 | TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); |
| 13325 | 14375 | if (field == nullptr) { |
| ... | ... | @@ -13327,40 +14377,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou |
| 13327 | 14377 | buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); |
| 13328 | 14378 | add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, |
| 13329 | 14379 | buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); |
| 13330 | | return ira->codegen->invalid_instruction; |
| 14380 | return ira->codegen->invalid_inst_gen; |
| 13331 | 14381 | } |
| 13332 | | IrInstruction *result = ir_const(ira, source_instr, enum_type); |
| 14382 | IrInstGen *result = ir_const(ira, source_instr, enum_type); |
| 13333 | 14383 | bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); |
| 13334 | 14384 | |
| 13335 | 14385 | return result; |
| 13336 | 14386 | } |
| 13337 | 14387 | |
| 13338 | | static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr, |
| 13339 | | IrInstruction *value, ZigType *wanted_type) |
| 14388 | static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 14389 | IrInstGen *value, ZigType *wanted_type) |
| 13340 | 14390 | { |
| 13341 | 14391 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array")); |
| 13342 | | return ira->codegen->invalid_instruction; |
| 14392 | return ira->codegen->invalid_inst_gen; |
| 13343 | 14393 | } |
| 13344 | 14394 | |
| 13345 | | static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr, |
| 13346 | | IrInstruction *value, ZigType *wanted_type) |
| 14395 | static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr, |
| 14396 | IrInstGen *value, ZigType *wanted_type) |
| 13347 | 14397 | { |
| 13348 | 14398 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct")); |
| 13349 | | return ira->codegen->invalid_instruction; |
| 14399 | return ira->codegen->invalid_inst_gen; |
| 13350 | 14400 | } |
| 13351 | 14401 | |
| 13352 | | static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr, |
| 13353 | | IrInstruction *value, ZigType *wanted_type) |
| 14402 | static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 14403 | IrInstGen *value, ZigType *wanted_type) |
| 13354 | 14404 | { |
| 13355 | 14405 | ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union")); |
| 13356 | | return ira->codegen->invalid_instruction; |
| 14406 | return ira->codegen->invalid_inst_gen; |
| 13357 | 14407 | } |
| 13358 | 14408 | |
| 13359 | 14409 | // Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work, |
| 13360 | 14410 | // otherwise return ErrorNone. Does not emit any instructions. |
| 13361 | 14411 | // Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the |
| 13362 | 14412 | // 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, |
| 14413 | static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type, |
| 13364 | 14414 | ZigType *src_ptr_type, AstNode *src_source_node) |
| 13365 | 14415 | { |
| 13366 | 14416 | Error err; |
| ... | ... | @@ -13394,37 +14444,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT |
| 13394 | 14444 | return ErrorNone; |
| 13395 | 14445 | } |
| 13396 | 14446 | |
| 13397 | | static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr, |
| 13398 | | IrInstruction *struct_operand, TypeStructField *field) |
| 14447 | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr, |
| 14448 | IrInstGen *struct_operand, TypeStructField *field) |
| 13399 | 14449 | { |
| 13400 | | IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 14450 | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 13401 | 14451 | 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, |
| 14452 | return ira->codegen->invalid_inst_gen; |
| 14453 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 13404 | 14454 | struct_operand->value->type, false); |
| 13405 | 14455 | if (type_is_invalid(field_ptr->value->type)) |
| 13406 | | return ira->codegen->invalid_instruction; |
| 14456 | return ira->codegen->invalid_inst_gen; |
| 13407 | 14457 | return ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 13408 | 14458 | } |
| 13409 | 14459 | |
| 13410 | | static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr, |
| 13411 | | IrInstruction *optional_operand, bool safety_check_on) |
| 14460 | static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr, |
| 14461 | IrInstGen *optional_operand, bool safety_check_on) |
| 13412 | 14462 | { |
| 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, |
| 14463 | IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false); |
| 14464 | IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr, |
| 13415 | 14465 | safety_check_on, false); |
| 13416 | 14466 | return ir_get_deref(ira, source_instr, payload_ptr, nullptr); |
| 13417 | 14467 | } |
| 13418 | 14468 | |
| 13419 | | static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 13420 | | ZigType *wanted_type, IrInstruction *value) |
| 14469 | static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 14470 | ZigType *wanted_type, IrInstGen *value) |
| 13421 | 14471 | { |
| 13422 | 14472 | Error err; |
| 13423 | 14473 | ZigType *actual_type = value->value->type; |
| 13424 | 14474 | AstNode *source_node = source_instr->source_node; |
| 13425 | 14475 | |
| 13426 | 14476 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| 13427 | | return ira->codegen->invalid_instruction; |
| 14477 | return ira->codegen->invalid_inst_gen; |
| 13428 | 14478 | } |
| 13429 | 14479 | |
| 13430 | 14480 | // This means the wanted type is anything. |
| ... | ... | @@ -13436,7 +14486,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13436 | 14486 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type, |
| 13437 | 14487 | source_node, false); |
| 13438 | 14488 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 13439 | | return ira->codegen->invalid_instruction; |
| 14489 | return ira->codegen->invalid_inst_gen; |
| 13440 | 14490 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 13441 | 14491 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop); |
| 13442 | 14492 | } |
| ... | ... | @@ -13470,7 +14520,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13470 | 14520 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { |
| 13471 | 14521 | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 13472 | 14522 | } else { |
| 13473 | | return ira->codegen->invalid_instruction; |
| 14523 | return ira->codegen->invalid_inst_gen; |
| 13474 | 14524 | } |
| 13475 | 14525 | } else if ( |
| 13476 | 14526 | wanted_child_type->id == ZigTypeIdPointer && |
| ... | ... | @@ -13480,18 +14530,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13480 | 14530 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13481 | 14531 | { |
| 13482 | 14532 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13483 | | return ira->codegen->invalid_instruction; |
| 14533 | return ira->codegen->invalid_inst_gen; |
| 13484 | 14534 | if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13485 | | return ira->codegen->invalid_instruction; |
| 14535 | return ira->codegen->invalid_inst_gen; |
| 13486 | 14536 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) && |
| 13487 | 14537 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 13488 | 14538 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 13489 | 14539 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 13490 | 14540 | { |
| 13491 | | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 14541 | IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 13492 | 14542 | wanted_child_type); |
| 13493 | 14543 | if (type_is_invalid(cast1->value->type)) |
| 13494 | | return ira->codegen->invalid_instruction; |
| 14544 | return ira->codegen->invalid_inst_gen; |
| 13495 | 14545 | return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); |
| 13496 | 14546 | } |
| 13497 | 14547 | } |
| ... | ... | @@ -13509,7 +14559,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13509 | 14559 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 13510 | 14560 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 13511 | 14561 | } else { |
| 13512 | | return ira->codegen->invalid_instruction; |
| 14562 | return ira->codegen->invalid_inst_gen; |
| 13513 | 14563 | } |
| 13514 | 14564 | } |
| 13515 | 14565 | } |
| ... | ... | @@ -13525,13 +14575,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13525 | 14575 | actual_type->id == ZigTypeIdComptimeInt || |
| 13526 | 14576 | actual_type->id == ZigTypeIdComptimeFloat) |
| 13527 | 14577 | { |
| 13528 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 14578 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13529 | 14579 | if (type_is_invalid(cast1->value->type)) |
| 13530 | | return ira->codegen->invalid_instruction; |
| 14580 | return ira->codegen->invalid_inst_gen; |
| 13531 | 14581 | |
| 13532 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14582 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13533 | 14583 | if (type_is_invalid(cast2->value->type)) |
| 13534 | | return ira->codegen->invalid_instruction; |
| 14584 | return ira->codegen->invalid_inst_gen; |
| 13535 | 14585 | |
| 13536 | 14586 | return cast2; |
| 13537 | 14587 | } |
| ... | ... | @@ -13546,13 +14596,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13546 | 14596 | wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) |
| 13547 | 14597 | { |
| 13548 | 14598 | if (value->value->special == ConstValSpecialUndef) { |
| 13549 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14599 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13550 | 14600 | result->value->special = ConstValSpecialUndef; |
| 13551 | 14601 | return result; |
| 13552 | 14602 | } |
| 13553 | 14603 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 13554 | 14604 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 13555 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14605 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13556 | 14606 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13557 | 14607 | copy_const_val(result->value, value->value); |
| 13558 | 14608 | result->value->type = wanted_type; |
| ... | ... | @@ -13561,7 +14611,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13561 | 14611 | } |
| 13562 | 14612 | return result; |
| 13563 | 14613 | } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { |
| 13564 | | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 14614 | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 13565 | 14615 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13566 | 14616 | BigFloat bf; |
| 13567 | 14617 | bigfloat_init_bigint(&bf, &value->value->data.x_bigint); |
| ... | ... | @@ -13573,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13573 | 14623 | } |
| 13574 | 14624 | zig_unreachable(); |
| 13575 | 14625 | } else { |
| 13576 | | return ira->codegen->invalid_instruction; |
| 14626 | return ira->codegen->invalid_inst_gen; |
| 13577 | 14627 | } |
| 13578 | 14628 | } |
| 13579 | 14629 | |
| ... | ... | @@ -13609,13 +14659,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13609 | 14659 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 13610 | 14660 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13611 | 14661 | { |
| 13612 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 14662 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13613 | 14663 | if (type_is_invalid(cast1->value->type)) |
| 13614 | | return ira->codegen->invalid_instruction; |
| 14664 | return ira->codegen->invalid_inst_gen; |
| 13615 | 14665 | |
| 13616 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14666 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13617 | 14667 | if (type_is_invalid(cast2->value->type)) |
| 13618 | | return ira->codegen->invalid_instruction; |
| 14668 | return ira->codegen->invalid_inst_gen; |
| 13619 | 14669 | |
| 13620 | 14670 | return cast2; |
| 13621 | 14671 | } |
| ... | ... | @@ -13636,9 +14686,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13636 | 14686 | actual_array_type->data.array.sentinel))) |
| 13637 | 14687 | { |
| 13638 | 14688 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13639 | | return ira->codegen->invalid_instruction; |
| 14689 | return ira->codegen->invalid_inst_gen; |
| 13640 | 14690 | if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 13641 | | return ira->codegen->invalid_instruction; |
| 14691 | return ira->codegen->invalid_inst_gen; |
| 13642 | 14692 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) && |
| 13643 | 14693 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 13644 | 14694 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| ... | ... | @@ -13679,24 +14729,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13679 | 14729 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, |
| 13680 | 14730 | ResolveStatusAlignmentKnown))) |
| 13681 | 14731 | { |
| 13682 | | return ira->codegen->invalid_instruction; |
| 14732 | return ira->codegen->invalid_inst_gen; |
| 13683 | 14733 | } |
| 13684 | 14734 | if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type, |
| 13685 | 14735 | ResolveStatusAlignmentKnown))) |
| 13686 | 14736 | { |
| 13687 | | return ira->codegen->invalid_instruction; |
| 14737 | return ira->codegen->invalid_inst_gen; |
| 13688 | 14738 | } |
| 13689 | 14739 | ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type); |
| 13690 | 14740 | } |
| 13691 | 14741 | if (ok_align) { |
| 13692 | 14742 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 13693 | | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 14743 | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 13694 | 14744 | if (type_is_invalid(cast1->value->type)) |
| 13695 | | return ira->codegen->invalid_instruction; |
| 14745 | return ira->codegen->invalid_inst_gen; |
| 13696 | 14746 | |
| 13697 | | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 14747 | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13698 | 14748 | if (type_is_invalid(cast2->value->type)) |
| 13699 | | return ira->codegen->invalid_instruction; |
| 14749 | return ira->codegen->invalid_inst_gen; |
| 13700 | 14750 | |
| 13701 | 14751 | return cast2; |
| 13702 | 14752 | } else { |
| ... | ... | @@ -13731,12 +14781,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13731 | 14781 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, |
| 13732 | 14782 | ResolveStatusAlignmentKnown))) |
| 13733 | 14783 | { |
| 13734 | | return ira->codegen->invalid_instruction; |
| 14784 | return ira->codegen->invalid_inst_gen; |
| 13735 | 14785 | } |
| 13736 | 14786 | if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type, |
| 13737 | 14787 | ResolveStatusAlignmentKnown))) |
| 13738 | 14788 | { |
| 13739 | | return ira->codegen->invalid_instruction; |
| 14789 | return ira->codegen->invalid_inst_gen; |
| 13740 | 14790 | } |
| 13741 | 14791 | ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type); |
| 13742 | 14792 | } |
| ... | ... | @@ -13777,7 +14827,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13777 | 14827 | } |
| 13778 | 14828 | } |
| 13779 | 14829 | if (ok) { |
| 13780 | | IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); |
| 14830 | IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); |
| 13781 | 14831 | if (anyframe_type == wanted_type) |
| 13782 | 14832 | return cast1; |
| 13783 | 14833 | return ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| ... | ... | @@ -13832,28 +14882,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13832 | 14882 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 13833 | 14883 | (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum)) |
| 13834 | 14884 | { |
| 13835 | | IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 13836 | | if (result == ira->codegen->invalid_instruction) |
| 14885 | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 14886 | if (type_is_invalid(result->value->type)) |
| 13837 | 14887 | return result; |
| 13838 | 14888 | |
| 13839 | | return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr); |
| 14889 | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 13840 | 14890 | } |
| 13841 | 14891 | |
| 13842 | 14892 | // cast from enum literal to error union when payload is an enum |
| 13843 | 14893 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 13844 | 14894 | (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum)) |
| 13845 | 14895 | { |
| 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) |
| 14896 | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 14897 | if (type_is_invalid(result->value->type)) |
| 13848 | 14898 | return result; |
| 13849 | 14899 | |
| 13850 | | return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr); |
| 14900 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 13851 | 14901 | } |
| 13852 | 14902 | |
| 13853 | 14903 | // cast from union to the enum type of the union |
| 13854 | 14904 | if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { |
| 13855 | 14905 | if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown))) |
| 13856 | | return ira->codegen->invalid_instruction; |
| 14906 | return ira->codegen->invalid_inst_gen; |
| 13857 | 14907 | |
| 13858 | 14908 | if (actual_type->data.unionation.tag_type == wanted_type) { |
| 13859 | 14909 | return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type); |
| ... | ... | @@ -13881,8 +14931,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13881 | 14931 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 13882 | 14932 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| 13883 | 14933 | { |
| 13884 | | if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node))) |
| 13885 | | return ira->codegen->invalid_instruction; |
| 14934 | if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node))) |
| 14935 | return ira->codegen->invalid_inst_gen; |
| 13886 | 14936 | |
| 13887 | 14937 | return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type); |
| 13888 | 14938 | } |
| ... | ... | @@ -13905,7 +14955,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13905 | 14955 | slice_ptr_type->data.pointer.sentinel)))) |
| 13906 | 14956 | { |
| 13907 | 14957 | 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); |
| 14958 | IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field); |
| 13909 | 14959 | return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type); |
| 13910 | 14960 | } |
| 13911 | 14961 | } |
| ... | ... | @@ -13936,7 +14986,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13936 | 14986 | { |
| 13937 | 14987 | bool has_bits; |
| 13938 | 14988 | if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits))) |
| 13939 | | return ira->codegen->invalid_instruction; |
| 14989 | return ira->codegen->invalid_inst_gen; |
| 13940 | 14990 | if (!has_bits) { |
| 13941 | 14991 | return ir_get_ref(ira, source_instr, value, false, false); |
| 13942 | 14992 | } |
| ... | ... | @@ -14003,9 +15053,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14003 | 15053 | |
| 14004 | 15054 | // T to ?U, where T implicitly casts to U |
| 14005 | 15055 | 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); |
| 15056 | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 14007 | 15057 | if (type_is_invalid(cast1->value->type)) |
| 14008 | | return ira->codegen->invalid_instruction; |
| 15058 | return ira->codegen->invalid_inst_gen; |
| 14009 | 15059 | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 14010 | 15060 | } |
| 14011 | 15061 | |
| ... | ... | @@ -14013,9 +15063,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14013 | 15063 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion && |
| 14014 | 15064 | actual_type->id != ZigTypeIdErrorSet) |
| 14015 | 15065 | { |
| 14016 | | IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 15066 | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 14017 | 15067 | if (type_is_invalid(cast1->value->type)) |
| 14018 | | return ira->codegen->invalid_instruction; |
| 15068 | return ira->codegen->invalid_inst_gen; |
| 14019 | 15069 | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 14020 | 15070 | } |
| 14021 | 15071 | |
| ... | ... | @@ -14024,14 +15074,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 14024 | 15074 | buf_ptr(&wanted_type->name), |
| 14025 | 15075 | buf_ptr(&actual_type->name))); |
| 14026 | 15076 | report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg); |
| 14027 | | return ira->codegen->invalid_instruction; |
| 15077 | return ira->codegen->invalid_inst_gen; |
| 14028 | 15078 | } |
| 14029 | 15079 | |
| 14030 | | static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr, |
| 14031 | | IrInstruction *value, ZigType *expected_type) |
| 15080 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 15081 | IrInstGen *value, ZigType *expected_type) |
| 14032 | 15082 | { |
| 14033 | 15083 | assert(value); |
| 14034 | | assert(value != ira->codegen->invalid_instruction); |
| 14035 | 15084 | assert(!expected_type || !type_is_invalid(expected_type)); |
| 14036 | 15085 | assert(value->value->type); |
| 14037 | 15086 | assert(!type_is_invalid(value->value->type)); |
| ... | ... | @@ -14045,17 +15094,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou |
| 14045 | 15094 | return ir_analyze_cast(ira, value_source_instr, expected_type, value); |
| 14046 | 15095 | } |
| 14047 | 15096 | |
| 14048 | | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { |
| 14049 | | return ir_implicit_cast2(ira, value, value, expected_type); |
| 15097 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) { |
| 15098 | return ir_implicit_cast2(ira, &value->base, value, expected_type); |
| 14050 | 15099 | } |
| 14051 | 15100 | |
| 14052 | | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 14053 | | ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 15101 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) { |
| 15102 | ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 14054 | 15103 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 14055 | 15104 | if (elem_type != g->builtin_types.entry_var) |
| 14056 | 15105 | return elem_type; |
| 14057 | 15106 | |
| 14058 | | if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) |
| 15107 | if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value)) |
| 14059 | 15108 | return g->builtin_types.entry_invalid; |
| 14060 | 15109 | |
| 14061 | 15110 | assert(value_is_comptime(ptr->value)); |
| ... | ... | @@ -14063,28 +15112,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 14063 | 15112 | return pointee->type; |
| 14064 | 15113 | } |
| 14065 | 15114 | |
| 14066 | | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr, |
| 15115 | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr, |
| 14067 | 15116 | ResultLoc *result_loc) |
| 14068 | 15117 | { |
| 14069 | 15118 | Error err; |
| 14070 | 15119 | ZigType *ptr_type = ptr->value->type; |
| 14071 | 15120 | if (type_is_invalid(ptr_type)) |
| 14072 | | return ira->codegen->invalid_instruction; |
| 15121 | return ira->codegen->invalid_inst_gen; |
| 14073 | 15122 | |
| 14074 | 15123 | if (ptr_type->id != ZigTypeIdPointer) { |
| 14075 | 15124 | ir_add_error_node(ira, source_instruction->source_node, |
| 14076 | 15125 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 14077 | 15126 | buf_ptr(&ptr_type->name))); |
| 14078 | | return ira->codegen->invalid_instruction; |
| 15127 | return ira->codegen->invalid_inst_gen; |
| 14079 | 15128 | } |
| 14080 | 15129 | |
| 14081 | 15130 | ZigType *child_type = ptr_type->data.pointer.child_type; |
| 14082 | 15131 | if (type_is_invalid(child_type)) |
| 14083 | | return ira->codegen->invalid_instruction; |
| 15132 | return ira->codegen->invalid_inst_gen; |
| 14084 | 15133 | // if the child type has one possible value, the deref is comptime |
| 14085 | 15134 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 14086 | 15135 | case OnePossibleValueInvalid: |
| 14087 | | return ira->codegen->invalid_instruction; |
| 15136 | return ira->codegen->invalid_inst_gen; |
| 14088 | 15137 | case OnePossibleValueYes: |
| 14089 | 15138 | return ir_const_move(ira, source_instruction, |
| 14090 | 15139 | get_the_one_possible_value(ira->codegen, child_type)); |
| ... | ... | @@ -14093,8 +15142,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14093 | 15142 | } |
| 14094 | 15143 | if (instr_is_comptime(ptr)) { |
| 14095 | 15144 | if (ptr->value->special == ConstValSpecialUndef) { |
| 14096 | | ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); |
| 14097 | | return ira->codegen->invalid_instruction; |
| 15145 | ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value")); |
| 15146 | return ira->codegen->invalid_inst_gen; |
| 14098 | 15147 | } |
| 14099 | 15148 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 14100 | 15149 | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| ... | ... | @@ -14102,12 +15151,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14102 | 15151 | child_type = pointee->type; |
| 14103 | 15152 | } |
| 14104 | 15153 | if (pointee->special != ConstValSpecialRuntime) { |
| 14105 | | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 15154 | IrInstGen *result = ir_const(ira, source_instruction, child_type); |
| 14106 | 15155 | |
| 14107 | 15156 | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, |
| 14108 | 15157 | ptr->value))) |
| 14109 | 15158 | { |
| 14110 | | return ira->codegen->invalid_instruction; |
| 15159 | return ira->codegen->invalid_inst_gen; |
| 14111 | 15160 | } |
| 14112 | 15161 | result->value->type = child_type; |
| 14113 | 15162 | return result; |
| ... | ... | @@ -14116,38 +15165,38 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14116 | 15165 | } |
| 14117 | 15166 | |
| 14118 | 15167 | // 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; |
| 15168 | if (ptr->id == IrInstGenIdRef) { |
| 15169 | IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr); |
| 15170 | return ref_inst->operand; |
| 14122 | 15171 | } |
| 14123 | 15172 | |
| 14124 | 15173 | // If the instruction is a element pointer instruction to a vector, we emit |
| 14125 | 15174 | // vector element extract instruction rather than load pointer. If the |
| 14126 | 15175 | // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been |
| 14127 | | // possible to implement this in the codegen for IrInstructionLoadPtrGen. |
| 15176 | // possible to implement this in the codegen for IrInstGenLoadPtr. |
| 14128 | 15177 | // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error |
| 14129 | 15178 | // if the vector index cannot be determined right here, right now, because |
| 14130 | 15179 | // the type information does not contain enough information to actually |
| 14131 | 15180 | // perform a dereference. |
| 14132 | 15181 | 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, |
| 15182 | if (ptr->id == IrInstGenIdElemPtr) { |
| 15183 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 15184 | IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base, |
| 14136 | 15185 | elem_ptr->array_ptr, nullptr); |
| 14137 | | IrInstruction *elem_index = elem_ptr->elem_index; |
| 15186 | IrInstGen *elem_index = elem_ptr->elem_index; |
| 14138 | 15187 | return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index); |
| 14139 | 15188 | } |
| 14140 | | ir_add_error(ira, ptr, |
| 15189 | ir_add_error(ira, &ptr->base, |
| 14141 | 15190 | buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name))); |
| 14142 | | return ira->codegen->invalid_instruction; |
| 15191 | return ira->codegen->invalid_inst_gen; |
| 14143 | 15192 | } |
| 14144 | 15193 | |
| 14145 | | IrInstruction *result_loc_inst; |
| 15194 | IrInstGen *result_loc_inst; |
| 14146 | 15195 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) { |
| 14147 | 15196 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 14148 | 15197 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| 14149 | 15198 | true, false, true); |
| 14150 | | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 15199 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 14151 | 15200 | return result_loc_inst; |
| 14152 | 15201 | } |
| 14153 | 15202 | } else { |
| ... | ... | @@ -14157,7 +15206,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 14157 | 15206 | return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst); |
| 14158 | 15207 | } |
| 14159 | 15208 | |
| 14160 | | static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 15209 | static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, |
| 14161 | 15210 | ZigValue *const_val, uint32_t *out) |
| 14162 | 15211 | { |
| 14163 | 15212 | Error err; |
| ... | ... | @@ -14166,12 +15215,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 14166 | 15215 | |
| 14167 | 15216 | uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint); |
| 14168 | 15217 | if (align_bytes == 0) { |
| 14169 | | exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1")); |
| 15218 | exec_add_error_node_gen(codegen, exec, source_node, buf_sprintf("alignment must be >= 1")); |
| 14170 | 15219 | return false; |
| 14171 | 15220 | } |
| 14172 | 15221 | |
| 14173 | 15222 | if (!is_power_of_2(align_bytes)) { |
| 14174 | | exec_add_error_node(codegen, exec, source_node, |
| 15223 | exec_add_error_node_gen(codegen, exec, source_node, |
| 14175 | 15224 | buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes)); |
| 14176 | 15225 | return false; |
| 14177 | 15226 | } |
| ... | ... | @@ -14180,7 +15229,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 14180 | 15229 | return true; |
| 14181 | 15230 | } |
| 14182 | 15231 | |
| 14183 | | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { |
| 15232 | static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_type, uint32_t *out) { |
| 14184 | 15233 | if (type_is_invalid(value->value->type)) |
| 14185 | 15234 | return false; |
| 14186 | 15235 | |
| ... | ... | @@ -14201,19 +15250,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem |
| 14201 | 15250 | } |
| 14202 | 15251 | } |
| 14203 | 15252 | |
| 14204 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 15253 | IrInstGen *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 14205 | 15254 | if (type_is_invalid(casted_value->value->type)) |
| 14206 | 15255 | return false; |
| 14207 | 15256 | |
| 14208 | | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, |
| 15257 | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 14209 | 15258 | casted_value->value, out); |
| 14210 | 15259 | } |
| 14211 | 15260 | |
| 14212 | | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { |
| 15261 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstGen *value, ZigType *int_type, uint64_t *out) { |
| 14213 | 15262 | if (type_is_invalid(value->value->type)) |
| 14214 | 15263 | return false; |
| 14215 | 15264 | |
| 14216 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type); |
| 15265 | IrInstGen *casted_value = ir_implicit_cast(ira, value, int_type); |
| 14217 | 15266 | if (type_is_invalid(casted_value->value->type)) |
| 14218 | 15267 | return false; |
| 14219 | 15268 | |
| ... | ... | @@ -14225,15 +15274,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i |
| 14225 | 15274 | return true; |
| 14226 | 15275 | } |
| 14227 | 15276 | |
| 14228 | | static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) { |
| 15277 | static bool ir_resolve_usize(IrAnalyze *ira, IrInstGen *value, uint64_t *out) { |
| 14229 | 15278 | return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out); |
| 14230 | 15279 | } |
| 14231 | 15280 | |
| 14232 | | static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 15281 | static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) { |
| 14233 | 15282 | if (type_is_invalid(value->value->type)) |
| 14234 | 15283 | return false; |
| 14235 | 15284 | |
| 14236 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 15285 | IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 14237 | 15286 | if (type_is_invalid(casted_value->value->type)) |
| 14238 | 15287 | return false; |
| 14239 | 15288 | |
| ... | ... | @@ -14245,7 +15294,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 14245 | 15294 | return true; |
| 14246 | 15295 | } |
| 14247 | 15296 | |
| 14248 | | static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 15297 | static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) { |
| 14249 | 15298 | if (!value) { |
| 14250 | 15299 | *out = false; |
| 14251 | 15300 | return true; |
| ... | ... | @@ -14253,13 +15302,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) |
| 14253 | 15302 | return ir_resolve_bool(ira, value, out); |
| 14254 | 15303 | } |
| 14255 | 15304 | |
| 14256 | | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { |
| 15305 | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstGen *value, AtomicOrder *out) { |
| 14257 | 15306 | if (type_is_invalid(value->value->type)) |
| 14258 | 15307 | return false; |
| 14259 | 15308 | |
| 14260 | 15309 | ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder"); |
| 14261 | 15310 | |
| 14262 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 15311 | IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 14263 | 15312 | if (type_is_invalid(casted_value->value->type)) |
| 14264 | 15313 | return false; |
| 14265 | 15314 | |
| ... | ... | @@ -14271,13 +15320,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 14271 | 15320 | return true; |
| 14272 | 15321 | } |
| 14273 | 15322 | |
| 14274 | | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) { |
| 15323 | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstGen *value, AtomicRmwOp *out) { |
| 14275 | 15324 | if (type_is_invalid(value->value->type)) |
| 14276 | 15325 | return false; |
| 14277 | 15326 | |
| 14278 | 15327 | ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp"); |
| 14279 | 15328 | |
| 14280 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 15329 | IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 14281 | 15330 | if (type_is_invalid(casted_value->value->type)) |
| 14282 | 15331 | return false; |
| 14283 | 15332 | |
| ... | ... | @@ -14289,13 +15338,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 14289 | 15338 | return true; |
| 14290 | 15339 | } |
| 14291 | 15340 | |
| 14292 | | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) { |
| 15341 | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstGen *value, GlobalLinkageId *out) { |
| 14293 | 15342 | if (type_is_invalid(value->value->type)) |
| 14294 | 15343 | return false; |
| 14295 | 15344 | |
| 14296 | 15345 | ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage"); |
| 14297 | 15346 | |
| 14298 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 15347 | IrInstGen *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 14299 | 15348 | if (type_is_invalid(casted_value->value->type)) |
| 14300 | 15349 | return false; |
| 14301 | 15350 | |
| ... | ... | @@ -14307,13 +15356,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 14307 | 15356 | return true; |
| 14308 | 15357 | } |
| 14309 | 15358 | |
| 14310 | | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) { |
| 15359 | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstGen *value, FloatMode *out) { |
| 14311 | 15360 | if (type_is_invalid(value->value->type)) |
| 14312 | 15361 | return false; |
| 14313 | 15362 | |
| 14314 | 15363 | ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode"); |
| 14315 | 15364 | |
| 14316 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 15365 | IrInstGen *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 14317 | 15366 | if (type_is_invalid(casted_value->value->type)) |
| 14318 | 15367 | return false; |
| 14319 | 15368 | |
| ... | ... | @@ -14325,14 +15374,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 14325 | 15374 | return true; |
| 14326 | 15375 | } |
| 14327 | 15376 | |
| 14328 | | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 15377 | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) { |
| 14329 | 15378 | if (type_is_invalid(value->value->type)) |
| 14330 | 15379 | return nullptr; |
| 14331 | 15380 | |
| 14332 | 15381 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 14333 | 15382 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 14334 | 15383 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 14335 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 15384 | IrInstGen *casted_value = ir_implicit_cast(ira, value, str_type); |
| 14336 | 15385 | if (type_is_invalid(casted_value->value->type)) |
| 14337 | 15386 | return nullptr; |
| 14338 | 15387 | |
| ... | ... | @@ -14356,7 +15405,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 14356 | 15405 | size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; |
| 14357 | 15406 | ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; |
| 14358 | 15407 | if (char_val->special == ConstValSpecialUndef) { |
| 14359 | | ir_add_error(ira, casted_value, buf_sprintf("use of undefined value")); |
| 15408 | ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value")); |
| 14360 | 15409 | return nullptr; |
| 14361 | 15410 | } |
| 14362 | 15411 | uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint); |
| ... | ... | @@ -14367,10 +15416,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 14367 | 15416 | return result; |
| 14368 | 15417 | } |
| 14369 | 15418 | |
| 14370 | | static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 14371 | | IrInstructionAddImplicitReturnType *instruction) |
| 15419 | static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 15420 | IrInstSrcAddImplicitReturnType *instruction) |
| 14372 | 15421 | { |
| 14373 | | IrInstruction *value = instruction->value->child; |
| 15422 | IrInstGen *value = instruction->value->child; |
| 14374 | 15423 | if (type_is_invalid(value->value->type)) |
| 14375 | 15424 | return ir_unreach_error(ira); |
| 14376 | 15425 | |
| ... | ... | @@ -14378,15 +15427,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 14378 | 15427 | ira->src_implicit_return_type_list.append(value); |
| 14379 | 15428 | } |
| 14380 | 15429 | |
| 14381 | | return ir_const_void(ira, &instruction->base); |
| 15430 | return ir_const_void(ira, &instruction->base.base); |
| 14382 | 15431 | } |
| 14383 | 15432 | |
| 14384 | | static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { |
| 14385 | | IrInstruction *operand = instruction->operand->child; |
| 15433 | static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) { |
| 15434 | IrInstGen *operand = instruction->operand->child; |
| 14386 | 15435 | if (type_is_invalid(operand->value->type)) |
| 14387 | 15436 | return ir_unreach_error(ira); |
| 14388 | 15437 | |
| 14389 | | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 15438 | IrInstGen *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 14390 | 15439 | if (type_is_invalid(casted_operand->value->type)) { |
| 14391 | 15440 | AstNode *source_node = ira->explicit_return_type_source_node; |
| 14392 | 15441 | if (source_node != nullptr) { |
| ... | ... | @@ -14401,9 +15450,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 14401 | 15450 | handle_is_ptr(ira->explicit_return_type)) |
| 14402 | 15451 | { |
| 14403 | 15452 | // 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; |
| 15453 | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr); |
| 14407 | 15454 | return ir_finish_anal(ira, result); |
| 14408 | 15455 | } |
| 14409 | 15456 | |
| ... | ... | @@ -14411,47 +15458,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 14411 | 15458 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 14412 | 15459 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 14413 | 15460 | { |
| 14414 | | ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable")); |
| 15461 | ir_add_error(ira, &casted_operand->base, buf_sprintf("function returns address of local variable")); |
| 14415 | 15462 | return ir_unreach_error(ira); |
| 14416 | 15463 | } |
| 14417 | 15464 | |
| 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; |
| 15465 | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand); |
| 14421 | 15466 | return ir_finish_anal(ira, result); |
| 14422 | 15467 | } |
| 14423 | 15468 | |
| 14424 | | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 14425 | | return ir_const_move(ira, &instruction->base, instruction->base.value); |
| 15469 | static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) { |
| 15470 | return ir_const_move(ira, &instruction->base.base, instruction->value); |
| 14426 | 15471 | } |
| 14427 | 15472 | |
| 14428 | | static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 14429 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 15473 | static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 15474 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 14430 | 15475 | if (type_is_invalid(op1->value->type)) |
| 14431 | | return ira->codegen->invalid_instruction; |
| 15476 | return ira->codegen->invalid_inst_gen; |
| 14432 | 15477 | |
| 14433 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 15478 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 14434 | 15479 | if (type_is_invalid(op2->value->type)) |
| 14435 | | return ira->codegen->invalid_instruction; |
| 15480 | return ira->codegen->invalid_inst_gen; |
| 14436 | 15481 | |
| 14437 | 15482 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 14438 | 15483 | |
| 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; |
| 15484 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 15485 | if (type_is_invalid(casted_op1->value->type)) |
| 15486 | return ira->codegen->invalid_inst_gen; |
| 14442 | 15487 | |
| 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; |
| 15488 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type); |
| 15489 | if (type_is_invalid(casted_op2->value->type)) |
| 15490 | return ira->codegen->invalid_inst_gen; |
| 14446 | 15491 | |
| 14447 | 15492 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 14448 | 15493 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 14449 | 15494 | if (op1_val == nullptr) |
| 14450 | | return ira->codegen->invalid_instruction; |
| 15495 | return ira->codegen->invalid_inst_gen; |
| 14451 | 15496 | |
| 14452 | 15497 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 14453 | 15498 | if (op2_val == nullptr) |
| 14454 | | return ira->codegen->invalid_instruction; |
| 15499 | return ira->codegen->invalid_inst_gen; |
| 14455 | 15500 | |
| 14456 | 15501 | assert(casted_op1->value->type->id == ZigTypeIdBool); |
| 14457 | 15502 | assert(casted_op2->value->type->id == ZigTypeIdBool); |
| ... | ... | @@ -14463,14 +15508,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 14463 | 15508 | } else { |
| 14464 | 15509 | zig_unreachable(); |
| 14465 | 15510 | } |
| 14466 | | return ir_const_bool(ira, &bin_op_instruction->base, result_bool); |
| 15511 | return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool); |
| 14467 | 15512 | } |
| 14468 | 15513 | |
| 14469 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14470 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 15514 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type, |
| 14471 | 15515 | 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 | 15516 | } |
| 14475 | 15517 | |
| 14476 | 15518 | static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { |
| ... | ... | @@ -14535,12 +15577,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) { |
| 14535 | 15577 | } |
| 14536 | 15578 | } |
| 14537 | 15579 | |
| 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) { |
| 15580 | static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 15581 | ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id, |
| 15582 | bool one_possible_value) |
| 15583 | { |
| 14541 | 15584 | if (op1_val->special == ConstValSpecialUndef || |
| 14542 | 15585 | op2_val->special == ConstValSpecialUndef) |
| 14543 | | return ir_const_undef(ira, &bin_op_instruction->base, resolved_type); |
| 15586 | return ir_const_undef(ira, &bin_op_instruction->base.base, resolved_type); |
| 14544 | 15587 | if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) { |
| 14545 | 15588 | if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14546 | 15589 | op1_val->data.x_ptr.special == ConstPtrSpecialNull) && |
| ... | ... | @@ -14560,7 +15603,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t |
| 14560 | 15603 | cmp_result = CmpEQ; |
| 14561 | 15604 | } |
| 14562 | 15605 | bool answer = resolve_cmp_op_id(op_id, cmp_result); |
| 14563 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 15606 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 14564 | 15607 | } |
| 14565 | 15608 | } else { |
| 14566 | 15609 | bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val); |
| ... | ... | @@ -14572,7 +15615,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t |
| 14572 | 15615 | } else { |
| 14573 | 15616 | zig_unreachable(); |
| 14574 | 15617 | } |
| 14575 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 15618 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 14576 | 15619 | } |
| 14577 | 15620 | zig_unreachable(); |
| 14578 | 15621 | } |
| ... | ... | @@ -14626,7 +15669,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { |
| 14626 | 15669 | zig_unreachable(); |
| 14627 | 15670 | } |
| 14628 | 15671 | |
| 14629 | | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source_instr, |
| 15672 | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 14630 | 15673 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 14631 | 15674 | { |
| 14632 | 15675 | Error err; |
| ... | ... | @@ -14704,14 +15747,14 @@ never_mind_just_calculate_it_normally: |
| 14704 | 15747 | return nullptr; |
| 14705 | 15748 | } |
| 14706 | 15749 | if (op1_val->type->id == ZigTypeIdComptimeFloat) { |
| 14707 | | IrInstruction *tmp = ir_const_noval(ira, source_instr); |
| 15750 | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 14708 | 15751 | tmp->value = op1_val; |
| 14709 | | IrInstruction *casted = ir_implicit_cast(ira, tmp, op2_val->type); |
| 15752 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type); |
| 14710 | 15753 | op1_val = casted->value; |
| 14711 | 15754 | } else if (op2_val->type->id == ZigTypeIdComptimeFloat) { |
| 14712 | | IrInstruction *tmp = ir_const_noval(ira, source_instr); |
| 15755 | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 14713 | 15756 | tmp->value = op2_val; |
| 14714 | | IrInstruction *casted = ir_implicit_cast(ira, tmp, op1_val->type); |
| 15757 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type); |
| 14715 | 15758 | op2_val = casted->value; |
| 14716 | 15759 | } |
| 14717 | 15760 | Cmp cmp_result = float_cmp(op1_val, op2_val); |
| ... | ... | @@ -14753,8 +15796,8 @@ never_mind_just_calculate_it_normally: |
| 14753 | 15796 | return nullptr; |
| 14754 | 15797 | } |
| 14755 | 15798 | |
| 14756 | | static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr, |
| 14757 | | IrInstruction *op1, IrInstruction *op2, IrBinOp op_id) |
| 15799 | static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr, |
| 15800 | IrInstGen *op1, IrInstGen *op2, IrBinOp op_id) |
| 14758 | 15801 | { |
| 14759 | 15802 | Error err; |
| 14760 | 15803 | |
| ... | ... | @@ -14767,7 +15810,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14767 | 15810 | ir_add_error(ira, source_instr, |
| 14768 | 15811 | buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32, |
| 14769 | 15812 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); |
| 14770 | | return ira->codegen->invalid_instruction; |
| 15813 | return ira->codegen->invalid_inst_gen; |
| 14771 | 15814 | } |
| 14772 | 15815 | result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type); |
| 14773 | 15816 | op1_scalar_type = op1->value->type->data.vector.elem_type; |
| ... | ... | @@ -14776,13 +15819,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14776 | 15819 | ir_add_error(ira, source_instr, |
| 14777 | 15820 | buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'", |
| 14778 | 15821 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 14779 | | return ira->codegen->invalid_instruction; |
| 15822 | return ira->codegen->invalid_inst_gen; |
| 14780 | 15823 | } |
| 14781 | 15824 | |
| 14782 | 15825 | bool opv_op1; |
| 14783 | 15826 | switch (type_has_one_possible_value(ira->codegen, op1->value->type)) { |
| 14784 | 15827 | case OnePossibleValueInvalid: |
| 14785 | | return ira->codegen->invalid_instruction; |
| 15828 | return ira->codegen->invalid_inst_gen; |
| 14786 | 15829 | case OnePossibleValueYes: |
| 14787 | 15830 | opv_op1 = true; |
| 14788 | 15831 | break; |
| ... | ... | @@ -14793,7 +15836,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14793 | 15836 | bool opv_op2; |
| 14794 | 15837 | switch (type_has_one_possible_value(ira->codegen, op2->value->type)) { |
| 14795 | 15838 | case OnePossibleValueInvalid: |
| 14796 | | return ira->codegen->invalid_instruction; |
| 15839 | return ira->codegen->invalid_inst_gen; |
| 14797 | 15840 | case OnePossibleValueYes: |
| 14798 | 15841 | opv_op2 = true; |
| 14799 | 15842 | break; |
| ... | ... | @@ -14804,21 +15847,21 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14804 | 15847 | Cmp op1_cmp_zero; |
| 14805 | 15848 | bool have_op1_cmp_zero = false; |
| 14806 | 15849 | if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) { |
| 14807 | | if (err != ErrorNotLazy) return ira->codegen->invalid_instruction; |
| 15850 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 14808 | 15851 | } else { |
| 14809 | 15852 | have_op1_cmp_zero = true; |
| 14810 | 15853 | } |
| 14811 | 15854 | Cmp op2_cmp_zero; |
| 14812 | 15855 | bool have_op2_cmp_zero = false; |
| 14813 | 15856 | if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) { |
| 14814 | | if (err != ErrorNotLazy) return ira->codegen->invalid_instruction; |
| 15857 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 14815 | 15858 | } else { |
| 14816 | 15859 | have_op2_cmp_zero = true; |
| 14817 | 15860 | } |
| 14818 | 15861 | if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) || |
| 14819 | 15862 | (have_op1_cmp_zero && have_op2_cmp_zero)) |
| 14820 | 15863 | { |
| 14821 | | IrInstruction *result_instruction = ir_const(ira, source_instr, result_type); |
| 15864 | IrInstGen *result_instruction = ir_const(ira, source_instr, result_type); |
| 14822 | 15865 | ZigValue *out_val = result_instruction->value; |
| 14823 | 15866 | if (result_type->id == ZigTypeIdVector) { |
| 14824 | 15867 | size_t len = result_type->data.vector.len; |
| ... | ... | @@ -14836,7 +15879,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14836 | 15879 | if (msg != nullptr) { |
| 14837 | 15880 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 14838 | 15881 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 14839 | | return ira->codegen->invalid_instruction; |
| 15882 | return ira->codegen->invalid_inst_gen; |
| 14840 | 15883 | } |
| 14841 | 15884 | } |
| 14842 | 15885 | out_val->type = result_type; |
| ... | ... | @@ -14845,7 +15888,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14845 | 15888 | if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id, |
| 14846 | 15889 | op2->value, out_val) != nullptr) |
| 14847 | 15890 | { |
| 14848 | | return ira->codegen->invalid_instruction; |
| 15891 | return ira->codegen->invalid_inst_gen; |
| 14849 | 15892 | } |
| 14850 | 15893 | } |
| 14851 | 15894 | return result_instruction; |
| ... | ... | @@ -14939,10 +15982,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14939 | 15982 | } |
| 14940 | 15983 | ZigType *dest_type = (result_type->id == ZigTypeIdVector) ? |
| 14941 | 15984 | 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); |
| 15985 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 15986 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 14944 | 15987 | if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type)) |
| 14945 | | return ira->codegen->invalid_instruction; |
| 15988 | return ira->codegen->invalid_inst_gen; |
| 14946 | 15989 | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 14947 | 15990 | } |
| 14948 | 15991 | |
| ... | ... | @@ -14972,12 +16015,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 14972 | 16015 | if (instr_is_comptime(op1)) { |
| 14973 | 16016 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk); |
| 14974 | 16017 | if (op1_val == nullptr) |
| 14975 | | return ira->codegen->invalid_instruction; |
| 16018 | return ira->codegen->invalid_inst_gen; |
| 14976 | 16019 | if (op1_val->special == ConstValSpecialUndef) |
| 14977 | 16020 | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 14978 | 16021 | 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; |
| 16022 | ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 16023 | return ira->codegen->invalid_inst_gen; |
| 14981 | 16024 | } |
| 14982 | 16025 | bool is_unsigned; |
| 14983 | 16026 | if (op1_is_float) { |
| ... | ... | @@ -15016,12 +16059,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 15016 | 16059 | if (instr_is_comptime(op2)) { |
| 15017 | 16060 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk); |
| 15018 | 16061 | if (op2_val == nullptr) |
| 15019 | | return ira->codegen->invalid_instruction; |
| 16062 | return ira->codegen->invalid_inst_gen; |
| 15020 | 16063 | if (op2_val->special == ConstValSpecialUndef) |
| 15021 | 16064 | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 15022 | 16065 | 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; |
| 16066 | ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here")); |
| 16067 | return ira->codegen->invalid_inst_gen; |
| 15025 | 16068 | } |
| 15026 | 16069 | bool is_unsigned; |
| 15027 | 16070 | if (op2_is_float) { |
| ... | ... | @@ -15062,35 +16105,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio |
| 15062 | 16105 | ZigType *dest_type = (result_type->id == ZigTypeIdVector) ? |
| 15063 | 16106 | get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type; |
| 15064 | 16107 | |
| 15065 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 16108 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 15066 | 16109 | 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); |
| 16110 | return ira->codegen->invalid_inst_gen; |
| 16111 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 15069 | 16112 | if (type_is_invalid(casted_op2->value->type)) |
| 15070 | | return ira->codegen->invalid_instruction; |
| 16113 | return ira->codegen->invalid_inst_gen; |
| 15071 | 16114 | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 15072 | 16115 | } |
| 15073 | 16116 | |
| 15074 | | static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 15075 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 16117 | static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16118 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 15076 | 16119 | if (type_is_invalid(op1->value->type)) |
| 15077 | | return ira->codegen->invalid_instruction; |
| 16120 | return ira->codegen->invalid_inst_gen; |
| 15078 | 16121 | |
| 15079 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 16122 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 15080 | 16123 | if (type_is_invalid(op2->value->type)) |
| 15081 | | return ira->codegen->invalid_instruction; |
| 16124 | return ira->codegen->invalid_inst_gen; |
| 15082 | 16125 | |
| 15083 | | AstNode *source_node = bin_op_instruction->base.source_node; |
| 16126 | AstNode *source_node = bin_op_instruction->base.base.source_node; |
| 15084 | 16127 | |
| 15085 | 16128 | IrBinOp op_id = bin_op_instruction->op_id; |
| 15086 | 16129 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 15087 | 16130 | 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)); |
| 16131 | return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq)); |
| 15089 | 16132 | } else if (is_equality_cmp && |
| 15090 | 16133 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || |
| 15091 | 16134 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) |
| 15092 | 16135 | { |
| 15093 | | IrInstruction *maybe_op; |
| 16136 | IrInstGen *maybe_op; |
| 15094 | 16137 | if (op1->value->type->id == ZigTypeIdNull) { |
| 15095 | 16138 | maybe_op = op2; |
| 15096 | 16139 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| ... | ... | @@ -15101,21 +16144,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15101 | 16144 | if (instr_is_comptime(maybe_op)) { |
| 15102 | 16145 | ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); |
| 15103 | 16146 | if (!maybe_val) |
| 15104 | | return ira->codegen->invalid_instruction; |
| 16147 | return ira->codegen->invalid_inst_gen; |
| 15105 | 16148 | bool is_null = optional_value_is_null(maybe_val); |
| 15106 | 16149 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 15107 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16150 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15108 | 16151 | } |
| 15109 | 16152 | |
| 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; |
| 16153 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op); |
| 15113 | 16154 | |
| 15114 | 16155 | 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; |
| 16156 | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 15119 | 16157 | } else { |
| 15120 | 16158 | return is_non_null; |
| 15121 | 16159 | } |
| ... | ... | @@ -15125,7 +16163,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15125 | 16163 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer && |
| 15126 | 16164 | op1->value->type->data.pointer.ptr_len == PtrLenC))) |
| 15127 | 16165 | { |
| 15128 | | IrInstruction *c_ptr_op; |
| 16166 | IrInstGen *c_ptr_op; |
| 15129 | 16167 | if (op1->value->type->id == ZigTypeIdNull) { |
| 15130 | 16168 | c_ptr_op = op2; |
| 15131 | 16169 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| ... | ... | @@ -15136,24 +16174,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15136 | 16174 | if (instr_is_comptime(c_ptr_op)) { |
| 15137 | 16175 | ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); |
| 15138 | 16176 | if (!c_ptr_val) |
| 15139 | | return ira->codegen->invalid_instruction; |
| 16177 | return ira->codegen->invalid_inst_gen; |
| 15140 | 16178 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 15141 | | return ir_const_undef(ira, &bin_op_instruction->base, ira->codegen->builtin_types.entry_bool); |
| 16179 | return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool); |
| 15142 | 16180 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 15143 | 16181 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 15144 | 16182 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 15145 | 16183 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 15146 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16184 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15147 | 16185 | } |
| 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; |
| 16186 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op); |
| 15151 | 16187 | |
| 15152 | 16188 | 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; |
| 16189 | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 15157 | 16190 | } else { |
| 15158 | 16191 | return is_non_null; |
| 15159 | 16192 | } |
| ... | ... | @@ -15161,61 +16194,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15161 | 16194 | ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; |
| 15162 | 16195 | ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", |
| 15163 | 16196 | buf_ptr(&non_null_type->name))); |
| 15164 | | return ira->codegen->invalid_instruction; |
| 16197 | return ira->codegen->invalid_inst_gen; |
| 15165 | 16198 | } else if (is_equality_cmp && ( |
| 15166 | 16199 | (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) || |
| 15167 | 16200 | (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion))) |
| 15168 | 16201 | { |
| 15169 | 16202 | // 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; |
| 16203 | IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; |
| 16204 | IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; |
| 15172 | 16205 | |
| 15173 | 16206 | ZigType *tag_type = union_val->value->type->data.unionation.tag_type; |
| 15174 | 16207 | assert(tag_type != nullptr); |
| 15175 | 16208 | |
| 15176 | | IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 16209 | IrInstGen *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 15177 | 16210 | if (type_is_invalid(casted_union->value->type)) |
| 15178 | | return ira->codegen->invalid_instruction; |
| 16211 | return ira->codegen->invalid_inst_gen; |
| 15179 | 16212 | |
| 15180 | | IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 16213 | IrInstGen *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 15181 | 16214 | if (type_is_invalid(casted_val->value->type)) |
| 15182 | | return ira->codegen->invalid_instruction; |
| 16215 | return ira->codegen->invalid_inst_gen; |
| 15183 | 16216 | |
| 15184 | 16217 | if (instr_is_comptime(casted_union)) { |
| 15185 | 16218 | ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); |
| 15186 | 16219 | if (!const_union_val) |
| 15187 | | return ira->codegen->invalid_instruction; |
| 16220 | return ira->codegen->invalid_inst_gen; |
| 15188 | 16221 | |
| 15189 | 16222 | ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); |
| 15190 | 16223 | if (!const_enum_val) |
| 15191 | | return ira->codegen->invalid_instruction; |
| 16224 | return ira->codegen->invalid_inst_gen; |
| 15192 | 16225 | |
| 15193 | 16226 | Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag); |
| 15194 | 16227 | bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ; |
| 15195 | 16228 | |
| 15196 | | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 16229 | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 15197 | 16230 | } |
| 15198 | 16231 | |
| 15199 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15200 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16232 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 15201 | 16233 | 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 | 16234 | } |
| 15206 | 16235 | |
| 15207 | 16236 | if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) { |
| 15208 | 16237 | if (!is_equality_cmp) { |
| 15209 | 16238 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 15210 | | return ira->codegen->invalid_instruction; |
| 16239 | return ira->codegen->invalid_inst_gen; |
| 15211 | 16240 | } |
| 15212 | 16241 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node); |
| 15213 | 16242 | if (type_is_invalid(intersect_type)) { |
| 15214 | | return ira->codegen->invalid_instruction; |
| 16243 | return ira->codegen->invalid_inst_gen; |
| 15215 | 16244 | } |
| 15216 | 16245 | |
| 15217 | 16246 | if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) { |
| 15218 | | return ira->codegen->invalid_instruction; |
| 16247 | return ira->codegen->invalid_inst_gen; |
| 15219 | 16248 | } |
| 15220 | 16249 | |
| 15221 | 16250 | // exception if one of the operators has the type of the empty error set, we allow the comparison |
| ... | ... | @@ -15232,7 +16261,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15232 | 16261 | } else { |
| 15233 | 16262 | zig_unreachable(); |
| 15234 | 16263 | } |
| 15235 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16264 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15236 | 16265 | } |
| 15237 | 16266 | |
| 15238 | 16267 | if (!type_is_global_error_set(intersect_type)) { |
| ... | ... | @@ -15240,7 +16269,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15240 | 16269 | ir_add_error_node(ira, source_node, |
| 15241 | 16270 | buf_sprintf("error sets '%s' and '%s' have no common errors", |
| 15242 | 16271 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 15243 | | return ira->codegen->invalid_instruction; |
| 16272 | return ira->codegen->invalid_inst_gen; |
| 15244 | 16273 | } |
| 15245 | 16274 | if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) { |
| 15246 | 16275 | bool are_equal = true; |
| ... | ... | @@ -15252,17 +16281,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15252 | 16281 | } else { |
| 15253 | 16282 | zig_unreachable(); |
| 15254 | 16283 | } |
| 15255 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16284 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15256 | 16285 | } |
| 15257 | 16286 | } |
| 15258 | 16287 | |
| 15259 | 16288 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15260 | 16289 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15261 | 16290 | if (op1_val == nullptr) |
| 15262 | | return ira->codegen->invalid_instruction; |
| 16291 | return ira->codegen->invalid_inst_gen; |
| 15263 | 16292 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15264 | 16293 | if (op2_val == nullptr) |
| 15265 | | return ira->codegen->invalid_instruction; |
| 16294 | return ira->codegen->invalid_inst_gen; |
| 15266 | 16295 | |
| 15267 | 16296 | bool answer; |
| 15268 | 16297 | bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value; |
| ... | ... | @@ -15274,27 +16303,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15274 | 16303 | zig_unreachable(); |
| 15275 | 16304 | } |
| 15276 | 16305 | |
| 15277 | | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 16306 | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 15278 | 16307 | } |
| 15279 | 16308 | |
| 15280 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15281 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16309 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 15282 | 16310 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 15283 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 15284 | | return result; |
| 15285 | 16311 | } |
| 15286 | 16312 | |
| 15287 | 16313 | if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) { |
| 15288 | 16314 | // This operation allows any combination of integer and float types, regardless of the |
| 15289 | 16315 | // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for |
| 15290 | 16316 | // numeric types. |
| 15291 | | return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base, op1, op2, op_id); |
| 16317 | return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id); |
| 15292 | 16318 | } |
| 15293 | 16319 | |
| 15294 | | IrInstruction *instructions[] = {op1, op2}; |
| 16320 | IrInstGen *instructions[] = {op1, op2}; |
| 15295 | 16321 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 15296 | 16322 | if (type_is_invalid(resolved_type)) |
| 15297 | | return ira->codegen->invalid_instruction; |
| 16323 | return ira->codegen->invalid_inst_gen; |
| 15298 | 16324 | |
| 15299 | 16325 | bool operator_allowed; |
| 15300 | 16326 | switch (resolved_type->id) { |
| ... | ... | @@ -15342,21 +16368,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15342 | 16368 | if (!operator_allowed) { |
| 15343 | 16369 | ir_add_error_node(ira, source_node, |
| 15344 | 16370 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); |
| 15345 | | return ira->codegen->invalid_instruction; |
| 16371 | return ira->codegen->invalid_inst_gen; |
| 15346 | 16372 | } |
| 15347 | 16373 | |
| 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; |
| 16374 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 16375 | if (type_is_invalid(casted_op1->value->type)) |
| 16376 | return ira->codegen->invalid_inst_gen; |
| 15351 | 16377 | |
| 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; |
| 16378 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 16379 | if (type_is_invalid(casted_op2->value->type)) |
| 16380 | return ira->codegen->invalid_inst_gen; |
| 15355 | 16381 | |
| 15356 | 16382 | bool one_possible_value; |
| 15357 | 16383 | switch (type_has_one_possible_value(ira->codegen, resolved_type)) { |
| 15358 | 16384 | case OnePossibleValueInvalid: |
| 15359 | | return ira->codegen->invalid_instruction; |
| 16385 | return ira->codegen->invalid_inst_gen; |
| 15360 | 16386 | case OnePossibleValueYes: |
| 15361 | 16387 | one_possible_value = true; |
| 15362 | 16388 | break; |
| ... | ... | @@ -15368,20 +16394,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15368 | 16394 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 15369 | 16395 | ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 15370 | 16396 | if (op1_val == nullptr) |
| 15371 | | return ira->codegen->invalid_instruction; |
| 16397 | return ira->codegen->invalid_inst_gen; |
| 15372 | 16398 | ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 15373 | 16399 | if (op2_val == nullptr) |
| 15374 | | return ira->codegen->invalid_instruction; |
| 16400 | return ira->codegen->invalid_inst_gen; |
| 15375 | 16401 | if (resolved_type->id != ZigTypeIdVector) |
| 15376 | 16402 | 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, |
| 16403 | IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base, |
| 15378 | 16404 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); |
| 15379 | 16405 | result->value->data.x_array.data.s_none.elements = |
| 15380 | 16406 | create_const_vals(resolved_type->data.vector.len); |
| 15381 | 16407 | |
| 15382 | 16408 | expand_undef_array(ira->codegen, result->value); |
| 15383 | 16409 | 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, |
| 16410 | IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 15385 | 16411 | &op1_val->data.x_array.data.s_none.elements[i], |
| 15386 | 16412 | &op2_val->data.x_array.data.s_none.elements[i], |
| 15387 | 16413 | bin_op_instruction, op_id, one_possible_value); |
| ... | ... | @@ -15390,19 +16416,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 15390 | 16416 | return result; |
| 15391 | 16417 | } |
| 15392 | 16418 | |
| 15393 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 15394 | | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 16419 | ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ? |
| 16420 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) : |
| 16421 | ira->codegen->builtin_types.entry_bool; |
| 16422 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type, |
| 15395 | 16423 | 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 | 16424 | } |
| 15404 | 16425 | |
| 15405 | | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 16426 | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 15406 | 16427 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 15407 | 16428 | { |
| 15408 | 16429 | bool is_int; |
| ... | ... | @@ -15582,10 +16603,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in |
| 15582 | 16603 | } |
| 15583 | 16604 | |
| 15584 | 16605 | // 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, |
| 16606 | static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr, |
| 15586 | 16607 | ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) |
| 15587 | 16608 | { |
| 15588 | | IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry); |
| 16609 | IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry); |
| 15589 | 16610 | ZigValue *out_val = result_instruction->value; |
| 15590 | 16611 | if (type_entry->id == ZigTypeIdVector) { |
| 15591 | 16612 | expand_undef_array(ira->codegen, op1_val); |
| ... | ... | @@ -15606,43 +16627,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 15606 | 16627 | if (msg != nullptr) { |
| 15607 | 16628 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 15608 | 16629 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 15609 | | return ira->codegen->invalid_instruction; |
| 16630 | return ira->codegen->invalid_inst_gen; |
| 15610 | 16631 | } |
| 15611 | 16632 | } |
| 15612 | 16633 | out_val->type = type_entry; |
| 15613 | 16634 | out_val->special = ConstValSpecialStatic; |
| 15614 | 16635 | } else { |
| 15615 | 16636 | 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; |
| 16637 | return ira->codegen->invalid_inst_gen; |
| 15617 | 16638 | } |
| 15618 | 16639 | } |
| 15619 | 16640 | return ir_implicit_cast(ira, result_instruction, type_entry); |
| 15620 | 16641 | } |
| 15621 | 16642 | |
| 15622 | | static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 15623 | | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 16643 | static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16644 | IrInstGen *op1 = bin_op_instruction->op1->child; |
| 15624 | 16645 | if (type_is_invalid(op1->value->type)) |
| 15625 | | return ira->codegen->invalid_instruction; |
| 16646 | return ira->codegen->invalid_inst_gen; |
| 15626 | 16647 | |
| 15627 | 16648 | if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) { |
| 15628 | | ir_add_error(ira, bin_op_instruction->op1, |
| 16649 | ir_add_error(ira, &bin_op_instruction->op1->base, |
| 15629 | 16650 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 15630 | 16651 | buf_ptr(&op1->value->type->name))); |
| 15631 | | return ira->codegen->invalid_instruction; |
| 16652 | return ira->codegen->invalid_inst_gen; |
| 15632 | 16653 | } |
| 15633 | 16654 | |
| 15634 | | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 16655 | IrInstGen *op2 = bin_op_instruction->op2->child; |
| 15635 | 16656 | if (type_is_invalid(op2->value->type)) |
| 15636 | | return ira->codegen->invalid_instruction; |
| 16657 | return ira->codegen->invalid_inst_gen; |
| 15637 | 16658 | |
| 15638 | 16659 | if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) { |
| 15639 | | ir_add_error(ira, bin_op_instruction->op2, |
| 16660 | ir_add_error(ira, &bin_op_instruction->op2->base, |
| 15640 | 16661 | buf_sprintf("shift amount has to be an integer type, but found '%s'", |
| 15641 | 16662 | buf_ptr(&op2->value->type->name))); |
| 15642 | | return ira->codegen->invalid_instruction; |
| 16663 | return ira->codegen->invalid_inst_gen; |
| 15643 | 16664 | } |
| 15644 | 16665 | |
| 15645 | | IrInstruction *casted_op2; |
| 16666 | IrInstGen *casted_op2; |
| 15646 | 16667 | IrBinOp op_id = bin_op_instruction->op_id; |
| 15647 | 16668 | if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 15648 | 16669 | casted_op2 = op2; |
| ... | ... | @@ -15654,8 +16675,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 15654 | 16675 | if (casted_op2->value->data.x_bigint.is_negative) { |
| 15655 | 16676 | Buf *val_buf = buf_alloc(); |
| 15656 | 16677 | 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; |
| 16678 | ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 16679 | return ira->codegen->invalid_inst_gen; |
| 15659 | 16680 | } |
| 15660 | 16681 | } else { |
| 15661 | 16682 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| ... | ... | @@ -15665,57 +16686,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 15665 | 16686 | |
| 15666 | 16687 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15667 | 16688 | if (op2_val == nullptr) |
| 15668 | | return ira->codegen->invalid_instruction; |
| 16689 | return ira->codegen->invalid_inst_gen; |
| 15669 | 16690 | if (!bigint_fits_in_bits(&op2_val->data.x_bigint, |
| 15670 | 16691 | shift_amt_type->data.integral.bit_count, |
| 15671 | 16692 | op2_val->data.x_bigint.is_negative)) { |
| 15672 | 16693 | Buf *val_buf = buf_alloc(); |
| 15673 | 16694 | bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10); |
| 15674 | 16695 | ErrorMsg* msg = ir_add_error(ira, |
| 15675 | | &bin_op_instruction->base, |
| 16696 | &bin_op_instruction->base.base, |
| 15676 | 16697 | buf_sprintf("RHS of shift is too large for LHS type")); |
| 15677 | 16698 | add_error_note( |
| 15678 | 16699 | ira->codegen, |
| 15679 | 16700 | msg, |
| 15680 | | op2->source_node, |
| 16701 | op2->base.source_node, |
| 15681 | 16702 | buf_sprintf("value %s cannot fit into type %s", |
| 15682 | 16703 | buf_ptr(val_buf), |
| 15683 | 16704 | buf_ptr(&shift_amt_type->name))); |
| 15684 | | return ira->codegen->invalid_instruction; |
| 16705 | return ira->codegen->invalid_inst_gen; |
| 15685 | 16706 | } |
| 15686 | 16707 | } |
| 15687 | 16708 | |
| 15688 | 16709 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); |
| 15689 | | if (casted_op2 == ira->codegen->invalid_instruction) |
| 15690 | | return ira->codegen->invalid_instruction; |
| 16710 | if (type_is_invalid(casted_op2->value->type)) |
| 16711 | return ira->codegen->invalid_inst_gen; |
| 15691 | 16712 | } |
| 15692 | 16713 | |
| 15693 | 16714 | if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { |
| 15694 | 16715 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15695 | 16716 | if (op1_val == nullptr) |
| 15696 | | return ira->codegen->invalid_instruction; |
| 16717 | return ira->codegen->invalid_inst_gen; |
| 15697 | 16718 | |
| 15698 | 16719 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15699 | 16720 | if (op2_val == nullptr) |
| 15700 | | return ira->codegen->invalid_instruction; |
| 16721 | return ira->codegen->invalid_inst_gen; |
| 15701 | 16722 | |
| 15702 | | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val); |
| 16723 | return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1->value->type, op1_val, op_id, op2_val); |
| 15703 | 16724 | } else if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 15704 | | ir_add_error(ira, &bin_op_instruction->base, |
| 16725 | ir_add_error(ira, &bin_op_instruction->base.base, |
| 15705 | 16726 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 15706 | | return ira->codegen->invalid_instruction; |
| 16727 | return ira->codegen->invalid_inst_gen; |
| 15707 | 16728 | } 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; |
| 16729 | return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop); |
| 15712 | 16730 | } |
| 15713 | 16731 | |
| 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; |
| 16732 | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type, |
| 16733 | op_id, op1, casted_op2, bin_op_instruction->safety_check_on); |
| 15719 | 16734 | } |
| 15720 | 16735 | |
| 15721 | 16736 | static bool ok_float_op(IrBinOp op) { |
| ... | ... | @@ -15779,24 +16794,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) { |
| 15779 | 16794 | zig_unreachable(); |
| 15780 | 16795 | } |
| 15781 | 16796 | |
| 15782 | | static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16797 | static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 15783 | 16798 | Error err; |
| 15784 | 16799 | |
| 15785 | | IrInstruction *op1 = instruction->op1->child; |
| 16800 | IrInstGen *op1 = instruction->op1->child; |
| 15786 | 16801 | if (type_is_invalid(op1->value->type)) |
| 15787 | | return ira->codegen->invalid_instruction; |
| 16802 | return ira->codegen->invalid_inst_gen; |
| 15788 | 16803 | |
| 15789 | | IrInstruction *op2 = instruction->op2->child; |
| 16804 | IrInstGen *op2 = instruction->op2->child; |
| 15790 | 16805 | if (type_is_invalid(op2->value->type)) |
| 15791 | | return ira->codegen->invalid_instruction; |
| 16806 | return ira->codegen->invalid_inst_gen; |
| 15792 | 16807 | |
| 15793 | 16808 | IrBinOp op_id = instruction->op_id; |
| 15794 | 16809 | |
| 15795 | 16810 | // look for pointer math |
| 15796 | 16811 | 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); |
| 16812 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 15798 | 16813 | if (type_is_invalid(casted_op2->value->type)) |
| 15799 | | return ira->codegen->invalid_instruction; |
| 16814 | return ira->codegen->invalid_inst_gen; |
| 15800 | 16815 | |
| 15801 | 16816 | // If either operand is undef, result is undef. |
| 15802 | 16817 | ZigValue *op1_val = nullptr; |
| ... | ... | @@ -15804,28 +16819,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15804 | 16819 | if (instr_is_comptime(op1)) { |
| 15805 | 16820 | op1_val = ir_resolve_const(ira, op1, UndefOk); |
| 15806 | 16821 | if (op1_val == nullptr) |
| 15807 | | return ira->codegen->invalid_instruction; |
| 16822 | return ira->codegen->invalid_inst_gen; |
| 15808 | 16823 | if (op1_val->special == ConstValSpecialUndef) |
| 15809 | | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 16824 | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 15810 | 16825 | } |
| 15811 | 16826 | if (instr_is_comptime(casted_op2)) { |
| 15812 | 16827 | op2_val = ir_resolve_const(ira, casted_op2, UndefOk); |
| 15813 | 16828 | if (op2_val == nullptr) |
| 15814 | | return ira->codegen->invalid_instruction; |
| 16829 | return ira->codegen->invalid_inst_gen; |
| 15815 | 16830 | if (op2_val->special == ConstValSpecialUndef) |
| 15816 | | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 16831 | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 15817 | 16832 | } |
| 15818 | 16833 | |
| 15819 | 16834 | ZigType *elem_type = op1->value->type->data.pointer.child_type; |
| 15820 | 16835 | if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) |
| 15821 | | return ira->codegen->invalid_instruction; |
| 16836 | return ira->codegen->invalid_inst_gen; |
| 15822 | 16837 | |
| 15823 | 16838 | // NOTE: this variable is meaningful iff op2_val is not null! |
| 15824 | 16839 | uint64_t byte_offset; |
| 15825 | 16840 | if (op2_val != nullptr) { |
| 15826 | 16841 | uint64_t elem_offset; |
| 15827 | 16842 | if (!ir_resolve_usize(ira, casted_op2, &elem_offset)) |
| 15828 | | return ira->codegen->invalid_instruction; |
| 16843 | return ira->codegen->invalid_inst_gen; |
| 15829 | 16844 | |
| 15830 | 16845 | byte_offset = type_size(ira->codegen, elem_type) * elem_offset; |
| 15831 | 16846 | } |
| ... | ... | @@ -15840,7 +16855,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15840 | 16855 | { |
| 15841 | 16856 | uint32_t align_bytes; |
| 15842 | 16857 | if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes))) |
| 15843 | | return ira->codegen->invalid_instruction; |
| 16858 | return ira->codegen->invalid_inst_gen; |
| 15844 | 16859 | |
| 15845 | 16860 | // If the addend is not a comptime-known value we can still count on |
| 15846 | 16861 | // it being a multiple of the type size |
| ... | ... | @@ -15869,23 +16884,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15869 | 16884 | } else { |
| 15870 | 16885 | zig_unreachable(); |
| 15871 | 16886 | } |
| 15872 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 16887 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 15873 | 16888 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 15874 | 16889 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 15875 | 16890 | result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 15876 | 16891 | return result; |
| 15877 | 16892 | } |
| 15878 | 16893 | |
| 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; |
| 16894 | return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true); |
| 15883 | 16895 | } |
| 15884 | 16896 | |
| 15885 | | IrInstruction *instructions[] = {op1, op2}; |
| 15886 | | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2); |
| 16897 | IrInstGen *instructions[] = {op1, op2}; |
| 16898 | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2); |
| 15887 | 16899 | if (type_is_invalid(resolved_type)) |
| 15888 | | return ira->codegen->invalid_instruction; |
| 16900 | return ira->codegen->invalid_inst_gen; |
| 15889 | 16901 | |
| 15890 | 16902 | bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; |
| 15891 | 16903 | bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; |
| ... | ... | @@ -15905,11 +16917,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15905 | 16917 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15906 | 16918 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15907 | 16919 | if (op1_val == nullptr) |
| 15908 | | return ira->codegen->invalid_instruction; |
| 16920 | return ira->codegen->invalid_inst_gen; |
| 15909 | 16921 | |
| 15910 | 16922 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15911 | 16923 | if (op2_val == nullptr) |
| 15912 | | return ira->codegen->invalid_instruction; |
| 16924 | return ira->codegen->invalid_inst_gen; |
| 15913 | 16925 | |
| 15914 | 16926 | if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) { |
| 15915 | 16927 | // the division by zero error will be caught later, but we don't have a |
| ... | ... | @@ -15928,11 +16940,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15928 | 16940 | } |
| 15929 | 16941 | } |
| 15930 | 16942 | if (!ok) { |
| 15931 | | ir_add_error(ira, &instruction->base, |
| 16943 | ir_add_error(ira, &instruction->base.base, |
| 15932 | 16944 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 15933 | 16945 | buf_ptr(&op1->value->type->name), |
| 15934 | 16946 | buf_ptr(&op2->value->type->name))); |
| 15935 | | return ira->codegen->invalid_instruction; |
| 16947 | return ira->codegen->invalid_inst_gen; |
| 15936 | 16948 | } |
| 15937 | 16949 | } else { |
| 15938 | 16950 | op_id = IrBinOpDivTrunc; |
| ... | ... | @@ -15943,12 +16955,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15943 | 16955 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15944 | 16956 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15945 | 16957 | if (op1_val == nullptr) |
| 15946 | | return ira->codegen->invalid_instruction; |
| 16958 | return ira->codegen->invalid_inst_gen; |
| 15947 | 16959 | |
| 15948 | 16960 | if (is_int) { |
| 15949 | 16961 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15950 | 16962 | if (op2_val == nullptr) |
| 15951 | | return ira->codegen->invalid_instruction; |
| 16963 | return ira->codegen->invalid_inst_gen; |
| 15952 | 16964 | |
| 15953 | 16965 | if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) { |
| 15954 | 16966 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -15962,13 +16974,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15962 | 16974 | ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ; |
| 15963 | 16975 | } |
| 15964 | 16976 | } 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; |
| 16977 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 16978 | if (type_is_invalid(casted_op2->value->type)) |
| 16979 | return ira->codegen->invalid_inst_gen; |
| 15968 | 16980 | |
| 15969 | 16981 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15970 | 16982 | if (op2_val == nullptr) |
| 15971 | | return ira->codegen->invalid_instruction; |
| 16983 | return ira->codegen->invalid_inst_gen; |
| 15972 | 16984 | |
| 15973 | 16985 | if (float_cmp_zero(casted_op2->value) == CmpEQ) { |
| 15974 | 16986 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -15984,11 +16996,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15984 | 16996 | } |
| 15985 | 16997 | } |
| 15986 | 16998 | if (!ok) { |
| 15987 | | ir_add_error(ira, &instruction->base, |
| 16999 | ir_add_error(ira, &instruction->base.base, |
| 15988 | 17000 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 15989 | 17001 | buf_ptr(&op1->value->type->name), |
| 15990 | 17002 | buf_ptr(&op2->value->type->name))); |
| 15991 | | return ira->codegen->invalid_instruction; |
| 17003 | return ira->codegen->invalid_inst_gen; |
| 15992 | 17004 | } |
| 15993 | 17005 | } |
| 15994 | 17006 | op_id = IrBinOpRemRem; |
| ... | ... | @@ -16008,12 +17020,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 16008 | 17020 | } |
| 16009 | 17021 | } |
| 16010 | 17022 | if (!ok) { |
| 16011 | | AstNode *source_node = instruction->base.source_node; |
| 17023 | AstNode *source_node = instruction->base.base.source_node; |
| 16012 | 17024 | ir_add_error_node(ira, source_node, |
| 16013 | 17025 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 16014 | 17026 | buf_ptr(&op1->value->type->name), |
| 16015 | 17027 | buf_ptr(&op2->value->type->name))); |
| 16016 | | return ira->codegen->invalid_instruction; |
| 17028 | return ira->codegen->invalid_inst_gen; |
| 16017 | 17029 | } |
| 16018 | 17030 | |
| 16019 | 17031 | if (resolved_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -16026,33 +17038,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 16026 | 17038 | } |
| 16027 | 17039 | } |
| 16028 | 17040 | |
| 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; |
| 17041 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 17042 | if (type_is_invalid(casted_op1->value->type)) |
| 17043 | return ira->codegen->invalid_inst_gen; |
| 16032 | 17044 | |
| 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; |
| 17045 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 17046 | if (type_is_invalid(casted_op2->value->type)) |
| 17047 | return ira->codegen->invalid_inst_gen; |
| 16036 | 17048 | |
| 16037 | 17049 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 16038 | 17050 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 16039 | 17051 | if (op1_val == nullptr) |
| 16040 | | return ira->codegen->invalid_instruction; |
| 17052 | return ira->codegen->invalid_inst_gen; |
| 16041 | 17053 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 16042 | 17054 | if (op2_val == nullptr) |
| 16043 | | return ira->codegen->invalid_instruction; |
| 17055 | return ira->codegen->invalid_inst_gen; |
| 16044 | 17056 | |
| 16045 | | return ir_analyze_math_op(ira, &instruction->base, resolved_type, op1_val, op_id, op2_val); |
| 17057 | return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val); |
| 16046 | 17058 | } |
| 16047 | 17059 | |
| 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; |
| 17060 | return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type, |
| 17061 | op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 16052 | 17062 | } |
| 16053 | 17063 | |
| 16054 | | static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr, |
| 16055 | | IrInstruction *op1, IrInstruction *op2) |
| 17064 | static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 17065 | IrInstGen *op1, IrInstGen *op2) |
| 16056 | 17066 | { |
| 16057 | 17067 | Error err; |
| 16058 | 17068 | ZigType *op1_type = op1->value->type; |
| ... | ... | @@ -16069,9 +17079,9 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16069 | 17079 | new_type->data.structure.special = StructSpecialInferredTuple; |
| 16070 | 17080 | new_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| 16071 | 17081 | |
| 16072 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope); |
| 17082 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope); |
| 16073 | 17083 | |
| 16074 | | IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 17084 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 16075 | 17085 | new_type, nullptr, false, false, true); |
| 16076 | 17086 | uint32_t new_field_count = op1_field_count + op2_field_count; |
| 16077 | 17087 | |
| ... | ... | @@ -16095,13 +17105,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16095 | 17105 | new_field->is_comptime = src_field->is_comptime; |
| 16096 | 17106 | } |
| 16097 | 17107 | if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown))) |
| 16098 | | return ira->codegen->invalid_instruction; |
| 17108 | return ira->codegen->invalid_inst_gen; |
| 16099 | 17109 | |
| 16100 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 16101 | | IrInstruction *first_non_const_instruction = nullptr; |
| 17110 | ZigList<IrInstGen *> const_ptrs = {}; |
| 17111 | IrInstGen *first_non_const_instruction = nullptr; |
| 16102 | 17112 | for (uint32_t i = 0; i < new_field_count; i += 1) { |
| 16103 | 17113 | TypeStructField *dst_field = new_type->data.structure.fields[i]; |
| 16104 | | IrInstruction *src_struct_op; |
| 17114 | IrInstGen *src_struct_op; |
| 16105 | 17115 | TypeStructField *src_field; |
| 16106 | 17116 | if (i < op1_field_count) { |
| 16107 | 17117 | src_field = op1_type->data.structure.fields[i]; |
| ... | ... | @@ -16110,73 +17120,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source |
| 16110 | 17120 | src_field = op2_type->data.structure.fields[i - op1_field_count]; |
| 16111 | 17121 | src_struct_op = op2; |
| 16112 | 17122 | } |
| 16113 | | IrInstruction *field_value = ir_analyze_struct_value_field_value(ira, source_instr, |
| 17123 | IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr, |
| 16114 | 17124 | src_struct_op, src_field); |
| 16115 | 17125 | 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, |
| 17126 | return ira->codegen->invalid_inst_gen; |
| 17127 | IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field, |
| 16118 | 17128 | new_struct_ptr, new_type, true); |
| 16119 | 17129 | if (type_is_invalid(dest_ptr->value->type)) |
| 16120 | | return ira->codegen->invalid_instruction; |
| 17130 | return ira->codegen->invalid_inst_gen; |
| 16121 | 17131 | if (instr_is_comptime(field_value)) { |
| 16122 | 17132 | const_ptrs.append(dest_ptr); |
| 16123 | 17133 | } else { |
| 16124 | 17134 | first_non_const_instruction = field_value; |
| 16125 | 17135 | } |
| 16126 | | IrInstruction *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value, |
| 17136 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value, |
| 16127 | 17137 | true); |
| 16128 | 17138 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 16129 | | return ira->codegen->invalid_instruction; |
| 17139 | return ira->codegen->invalid_inst_gen; |
| 16130 | 17140 | } |
| 16131 | 17141 | if (const_ptrs.length != new_field_count) { |
| 16132 | 17142 | new_struct_ptr->value->special = ConstValSpecialRuntime; |
| 16133 | 17143 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 16134 | | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 17144 | IrInstGen *elem_result_loc = const_ptrs.at(i); |
| 16135 | 17145 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 16136 | 17146 | if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) { |
| 16137 | 17147 | // This field will be generated comptime; no need to do this. |
| 16138 | 17148 | continue; |
| 16139 | 17149 | } |
| 16140 | | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 17150 | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 16141 | 17151 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 16142 | | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 17152 | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false); |
| 16143 | 17153 | } |
| 16144 | 17154 | } |
| 16145 | | IrInstruction *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 17155 | IrInstGen *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 16146 | 17156 | if (instr_is_comptime(result)) |
| 16147 | 17157 | return result; |
| 16148 | 17158 | |
| 16149 | 17159 | if (is_comptime) { |
| 16150 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 17160 | ir_add_error(ira, &first_non_const_instruction->base, |
| 16151 | 17161 | buf_sprintf("unable to evaluate constant expression")); |
| 16152 | | return ira->codegen->invalid_instruction; |
| 17162 | return ira->codegen->invalid_inst_gen; |
| 16153 | 17163 | } |
| 16154 | 17164 | |
| 16155 | 17165 | return result; |
| 16156 | 17166 | } |
| 16157 | 17167 | |
| 16158 | | static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16159 | | IrInstruction *op1 = instruction->op1->child; |
| 17168 | static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 17169 | IrInstGen *op1 = instruction->op1->child; |
| 16160 | 17170 | ZigType *op1_type = op1->value->type; |
| 16161 | 17171 | if (type_is_invalid(op1_type)) |
| 16162 | | return ira->codegen->invalid_instruction; |
| 17172 | return ira->codegen->invalid_inst_gen; |
| 16163 | 17173 | |
| 16164 | | IrInstruction *op2 = instruction->op2->child; |
| 17174 | IrInstGen *op2 = instruction->op2->child; |
| 16165 | 17175 | ZigType *op2_type = op2->value->type; |
| 16166 | 17176 | if (type_is_invalid(op2_type)) |
| 16167 | | return ira->codegen->invalid_instruction; |
| 17177 | return ira->codegen->invalid_inst_gen; |
| 16168 | 17178 | |
| 16169 | 17179 | if (is_tuple(op1_type) && is_tuple(op2_type)) { |
| 16170 | | return ir_analyze_tuple_cat(ira, &instruction->base, op1, op2); |
| 17180 | return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2); |
| 16171 | 17181 | } |
| 16172 | 17182 | |
| 16173 | 17183 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 16174 | 17184 | if (!op1_val) |
| 16175 | | return ira->codegen->invalid_instruction; |
| 17185 | return ira->codegen->invalid_inst_gen; |
| 16176 | 17186 | |
| 16177 | 17187 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 16178 | 17188 | if (!op2_val) |
| 16179 | | return ira->codegen->invalid_instruction; |
| 17189 | return ira->codegen->invalid_inst_gen; |
| 16180 | 17190 | |
| 16181 | 17191 | ZigValue *sentinel1 = nullptr; |
| 16182 | 17192 | ZigValue *op1_array_val; |
| ... | ... | @@ -16214,15 +17224,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16214 | 17224 | { |
| 16215 | 17225 | ZigType *array_type = op1_type->data.pointer.child_type; |
| 16216 | 17226 | child_type = array_type->data.array.child_type; |
| 16217 | | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node); |
| 17227 | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node); |
| 16218 | 17228 | if (op1_array_val == nullptr) |
| 16219 | | return ira->codegen->invalid_instruction; |
| 17229 | return ira->codegen->invalid_inst_gen; |
| 16220 | 17230 | op1_array_index = 0; |
| 16221 | 17231 | op1_array_end = array_type->data.array.len; |
| 16222 | 17232 | sentinel1 = array_type->data.array.sentinel; |
| 16223 | 17233 | } 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; |
| 17234 | ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 17235 | return ira->codegen->invalid_inst_gen; |
| 16226 | 17236 | } |
| 16227 | 17237 | |
| 16228 | 17238 | ZigValue *sentinel2 = nullptr; |
| ... | ... | @@ -16262,23 +17272,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16262 | 17272 | { |
| 16263 | 17273 | ZigType *array_type = op2_type->data.pointer.child_type; |
| 16264 | 17274 | 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); |
| 17275 | op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node); |
| 16266 | 17276 | if (op2_array_val == nullptr) |
| 16267 | | return ira->codegen->invalid_instruction; |
| 17277 | return ira->codegen->invalid_inst_gen; |
| 16268 | 17278 | op2_array_index = 0; |
| 16269 | 17279 | op2_array_end = array_type->data.array.len; |
| 16270 | 17280 | |
| 16271 | 17281 | sentinel2 = array_type->data.array.sentinel; |
| 16272 | 17282 | } else { |
| 16273 | | ir_add_error(ira, op2, |
| 17283 | ir_add_error(ira, &op2->base, |
| 16274 | 17284 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); |
| 16275 | | return ira->codegen->invalid_instruction; |
| 17285 | return ira->codegen->invalid_inst_gen; |
| 16276 | 17286 | } |
| 16277 | 17287 | if (!op2_type_valid) { |
| 16278 | | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 17288 | ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'", |
| 16279 | 17289 | buf_ptr(&child_type->name), |
| 16280 | 17290 | buf_ptr(&op2->value->type->name))); |
| 16281 | | return ira->codegen->invalid_instruction; |
| 17291 | return ira->codegen->invalid_inst_gen; |
| 16282 | 17292 | } |
| 16283 | 17293 | |
| 16284 | 17294 | ZigValue *sentinel; |
| ... | ... | @@ -16295,7 +17305,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16295 | 17305 | } |
| 16296 | 17306 | |
| 16297 | 17307 | // The type of result is populated in the following if blocks |
| 16298 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 17308 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16299 | 17309 | ZigValue *out_val = result->value; |
| 16300 | 17310 | |
| 16301 | 17311 | ZigValue *out_array_val; |
| ... | ... | @@ -16383,14 +17393,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 16383 | 17393 | return result; |
| 16384 | 17394 | } |
| 16385 | 17395 | |
| 16386 | | static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 16387 | | IrInstruction *op1 = instruction->op1->child; |
| 17396 | static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| 17397 | IrInstGen *op1 = instruction->op1->child; |
| 16388 | 17398 | if (type_is_invalid(op1->value->type)) |
| 16389 | | return ira->codegen->invalid_instruction; |
| 17399 | return ira->codegen->invalid_inst_gen; |
| 16390 | 17400 | |
| 16391 | | IrInstruction *op2 = instruction->op2->child; |
| 17401 | IrInstGen *op2 = instruction->op2->child; |
| 16392 | 17402 | if (type_is_invalid(op2->value->type)) |
| 16393 | | return ira->codegen->invalid_instruction; |
| 17403 | return ira->codegen->invalid_inst_gen; |
| 16394 | 17404 | |
| 16395 | 17405 | bool want_ptr_to_array = false; |
| 16396 | 17406 | ZigType *array_type; |
| ... | ... | @@ -16399,49 +17409,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 16399 | 17409 | array_type = op1->value->type; |
| 16400 | 17410 | array_val = ir_resolve_const(ira, op1, UndefOk); |
| 16401 | 17411 | if (array_val == nullptr) |
| 16402 | | return ira->codegen->invalid_instruction; |
| 17412 | return ira->codegen->invalid_inst_gen; |
| 16403 | 17413 | } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 16404 | 17414 | op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) |
| 16405 | 17415 | { |
| 16406 | 17416 | array_type = op1->value->type->data.pointer.child_type; |
| 16407 | | IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr); |
| 17417 | IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr); |
| 16408 | 17418 | if (type_is_invalid(array_inst->value->type)) |
| 16409 | | return ira->codegen->invalid_instruction; |
| 17419 | return ira->codegen->invalid_inst_gen; |
| 16410 | 17420 | array_val = ir_resolve_const(ira, array_inst, UndefOk); |
| 16411 | 17421 | if (array_val == nullptr) |
| 16412 | | return ira->codegen->invalid_instruction; |
| 17422 | return ira->codegen->invalid_inst_gen; |
| 16413 | 17423 | want_ptr_to_array = true; |
| 16414 | 17424 | } 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; |
| 17425 | ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 17426 | return ira->codegen->invalid_inst_gen; |
| 16417 | 17427 | } |
| 16418 | 17428 | |
| 16419 | 17429 | uint64_t mult_amt; |
| 16420 | 17430 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 16421 | | return ira->codegen->invalid_instruction; |
| 17431 | return ira->codegen->invalid_inst_gen; |
| 16422 | 17432 | |
| 16423 | 17433 | uint64_t old_array_len = array_type->data.array.len; |
| 16424 | 17434 | uint64_t new_array_len; |
| 16425 | 17435 | |
| 16426 | 17436 | 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; |
| 17437 | ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow")); |
| 17438 | return ira->codegen->invalid_inst_gen; |
| 16429 | 17439 | } |
| 16430 | 17440 | |
| 16431 | 17441 | ZigType *child_type = array_type->data.array.child_type; |
| 16432 | 17442 | ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len, |
| 16433 | 17443 | array_type->data.array.sentinel); |
| 16434 | 17444 | |
| 16435 | | IrInstruction *array_result; |
| 17445 | IrInstGen *array_result; |
| 16436 | 17446 | if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 16437 | | array_result = ir_const_undef(ira, &instruction->base, result_array_type); |
| 17447 | array_result = ir_const_undef(ira, &instruction->base.base, result_array_type); |
| 16438 | 17448 | } else { |
| 16439 | | array_result = ir_const(ira, &instruction->base, result_array_type); |
| 17449 | array_result = ir_const(ira, &instruction->base.base, result_array_type); |
| 16440 | 17450 | ZigValue *out_val = array_result->value; |
| 16441 | 17451 | |
| 16442 | 17452 | switch (type_has_one_possible_value(ira->codegen, result_array_type)) { |
| 16443 | 17453 | case OnePossibleValueInvalid: |
| 16444 | | return ira->codegen->invalid_instruction; |
| 17454 | return ira->codegen->invalid_inst_gen; |
| 16445 | 17455 | case OnePossibleValueYes: |
| 16446 | 17456 | goto skip_computation; |
| 16447 | 17457 | case OnePossibleValueNo: |
| ... | ... | @@ -16477,35 +17487,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 16477 | 17487 | } |
| 16478 | 17488 | skip_computation: |
| 16479 | 17489 | if (want_ptr_to_array) { |
| 16480 | | return ir_get_ref(ira, &instruction->base, array_result, true, false); |
| 17490 | return ir_get_ref(ira, &instruction->base.base, array_result, true, false); |
| 16481 | 17491 | } else { |
| 16482 | 17492 | return array_result; |
| 16483 | 17493 | } |
| 16484 | 17494 | } |
| 16485 | 17495 | |
| 16486 | | static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 16487 | | IrInstructionMergeErrSets *instruction) |
| 17496 | static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 17497 | IrInstSrcMergeErrSets *instruction) |
| 16488 | 17498 | { |
| 16489 | | ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child); |
| 17499 | ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child); |
| 16490 | 17500 | if (type_is_invalid(op1_type)) |
| 16491 | | return ira->codegen->invalid_instruction; |
| 17501 | return ira->codegen->invalid_inst_gen; |
| 16492 | 17502 | |
| 16493 | | ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op2->child); |
| 17503 | ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child); |
| 16494 | 17504 | if (type_is_invalid(op2_type)) |
| 16495 | | return ira->codegen->invalid_instruction; |
| 17505 | return ira->codegen->invalid_inst_gen; |
| 16496 | 17506 | |
| 16497 | 17507 | if (type_is_global_error_set(op1_type) || |
| 16498 | 17508 | type_is_global_error_set(op2_type)) |
| 16499 | 17509 | { |
| 16500 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set); |
| 17510 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set); |
| 16501 | 17511 | } |
| 16502 | 17512 | |
| 16503 | | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) { |
| 16504 | | return ira->codegen->invalid_instruction; |
| 17513 | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) { |
| 17514 | return ira->codegen->invalid_inst_gen; |
| 16505 | 17515 | } |
| 16506 | 17516 | |
| 16507 | | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) { |
| 16508 | | return ira->codegen->invalid_instruction; |
| 17517 | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) { |
| 17518 | return ira->codegen->invalid_inst_gen; |
| 16509 | 17519 | } |
| 16510 | 17520 | |
| 16511 | 17521 | size_t errors_count = ira->codegen->errors_by_index.length; |
| ... | ... | @@ -16518,11 +17528,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 16518 | 17528 | ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name); |
| 16519 | 17529 | deallocate(errors, errors_count, "ErrorTableEntry *"); |
| 16520 | 17530 | |
| 16521 | | return ir_const_type(ira, &instruction->base, result_type); |
| 17531 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 16522 | 17532 | } |
| 16523 | 17533 | |
| 16524 | 17534 | |
| 16525 | | static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 17535 | static IrInstGen *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| 16526 | 17536 | IrBinOp op_id = bin_op_instruction->op_id; |
| 16527 | 17537 | switch (op_id) { |
| 16528 | 17538 | case IrBinOpInvalid: |
| ... | ... | @@ -16567,41 +17577,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio |
| 16567 | 17577 | zig_unreachable(); |
| 16568 | 17578 | } |
| 16569 | 17579 | |
| 16570 | | static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16571 | | IrInstructionDeclVarSrc *decl_var_instruction) |
| 16572 | | { |
| 17580 | static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) { |
| 16573 | 17581 | Error err; |
| 16574 | 17582 | ZigVar *var = decl_var_instruction->var; |
| 16575 | 17583 | |
| 16576 | 17584 | ZigType *explicit_type = nullptr; |
| 16577 | | IrInstruction *var_type = nullptr; |
| 17585 | IrInstGen *var_type = nullptr; |
| 16578 | 17586 | if (decl_var_instruction->var_type != nullptr) { |
| 16579 | 17587 | var_type = decl_var_instruction->var_type->child; |
| 16580 | 17588 | ZigType *proposed_type = ir_resolve_type(ira, var_type); |
| 16581 | | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 17589 | explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type); |
| 16582 | 17590 | if (type_is_invalid(explicit_type)) { |
| 16583 | 17591 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16584 | | return ira->codegen->invalid_instruction; |
| 17592 | return ira->codegen->invalid_inst_gen; |
| 16585 | 17593 | } |
| 16586 | 17594 | } |
| 16587 | 17595 | |
| 16588 | | AstNode *source_node = decl_var_instruction->base.source_node; |
| 17596 | AstNode *source_node = decl_var_instruction->base.base.source_node; |
| 16589 | 17597 | |
| 16590 | 17598 | bool is_comptime_var = ir_get_var_is_comptime(var); |
| 16591 | 17599 | |
| 16592 | 17600 | bool var_class_requires_const = false; |
| 16593 | 17601 | |
| 16594 | | IrInstruction *var_ptr = decl_var_instruction->ptr->child; |
| 17602 | IrInstGen *var_ptr = decl_var_instruction->ptr->child; |
| 16595 | 17603 | // if this is null, a compiler error happened and did not initialize the variable. |
| 16596 | 17604 | // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. |
| 16597 | 17605 | 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); |
| 17606 | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base); |
| 16599 | 17607 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16600 | | return ira->codegen->invalid_instruction; |
| 17608 | return ira->codegen->invalid_inst_gen; |
| 16601 | 17609 | } |
| 16602 | 17610 | |
| 16603 | 17611 | // 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); |
| 17612 | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base); |
| 16605 | 17613 | |
| 16606 | 17614 | ZigType *result_type = var_ptr->value->type->data.pointer.child_type; |
| 16607 | 17615 | if (type_is_invalid(result_type)) { |
| ... | ... | @@ -16612,7 +17620,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16612 | 17620 | |
| 16613 | 17621 | ZigValue *init_val = nullptr; |
| 16614 | 17622 | 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); |
| 17623 | init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.base.source_node); |
| 16616 | 17624 | if (is_comptime_var) { |
| 16617 | 17625 | if (var->gen_is_const) { |
| 16618 | 17626 | var->const_value = init_val; |
| ... | ... | @@ -16639,7 +17647,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16639 | 17647 | case ReqCompTimeNo: |
| 16640 | 17648 | if (init_val != nullptr && value_is_comptime(init_val)) { |
| 16641 | 17649 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 16642 | | decl_var_instruction->base.source_node, init_val, UndefOk))) |
| 17650 | decl_var_instruction->base.base.source_node, init_val, UndefOk))) |
| 16643 | 17651 | { |
| 16644 | 17652 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 16645 | 17653 | } else if (init_val->type->id == ZigTypeIdFn && |
| ... | ... | @@ -16687,13 +17695,13 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16687 | 17695 | assert(var->var_type); |
| 16688 | 17696 | |
| 16689 | 17697 | if (type_is_invalid(result_type)) { |
| 16690 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 17698 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16691 | 17699 | } |
| 16692 | 17700 | |
| 16693 | 17701 | if (decl_var_instruction->align_value == nullptr) { |
| 16694 | 17702 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) { |
| 16695 | 17703 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16696 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 17704 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16697 | 17705 | } |
| 16698 | 17706 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 16699 | 17707 | } else { |
| ... | ... | @@ -16712,17 +17720,17 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16712 | 17720 | // we need a runtime ptr but we have a comptime val. |
| 16713 | 17721 | // since it's a comptime val there are no instructions for it. |
| 16714 | 17722 | // we memcpy the init value here |
| 16715 | | IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); |
| 17723 | IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr); |
| 16716 | 17724 | if (type_is_invalid(deref->value->type)) { |
| 16717 | 17725 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16718 | | return ira->codegen->invalid_instruction; |
| 17726 | return ira->codegen->invalid_inst_gen; |
| 16719 | 17727 | } |
| 16720 | 17728 | // If this assertion trips, something is wrong with the IR instructions, because |
| 16721 | 17729 | // we expected the above deref to return a constant value, but it created a runtime |
| 16722 | 17730 | // instruction. |
| 16723 | 17731 | assert(deref->value->special != ConstValSpecialRuntime); |
| 16724 | 17732 | var_ptr->value->special = ConstValSpecialRuntime; |
| 16725 | | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 17733 | ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false); |
| 16726 | 17734 | } |
| 16727 | 17735 | |
| 16728 | 17736 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { |
| ... | ... | @@ -16732,84 +17740,84 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 16732 | 17740 | ira_ref(var->owner_exec->analysis); |
| 16733 | 17741 | |
| 16734 | 17742 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| 16735 | | return ir_const_void(ira, &decl_var_instruction->base); |
| 17743 | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 16736 | 17744 | } |
| 16737 | 17745 | } |
| 16738 | 17746 | } else if (is_comptime_var) { |
| 16739 | | ir_add_error(ira, &decl_var_instruction->base, |
| 17747 | ir_add_error(ira, &decl_var_instruction->base.base, |
| 16740 | 17748 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 16741 | 17749 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 16742 | | return ira->codegen->invalid_instruction; |
| 17750 | return ira->codegen->invalid_inst_gen; |
| 16743 | 17751 | } |
| 16744 | 17752 | |
| 16745 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 17753 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 16746 | 17754 | if (fn_entry) |
| 16747 | 17755 | fn_entry->variable_list.append(var); |
| 16748 | 17756 | |
| 16749 | | return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr); |
| 17757 | return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr); |
| 16750 | 17758 | } |
| 16751 | 17759 | |
| 16752 | | static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { |
| 16753 | | IrInstruction *target = instruction->target->child; |
| 17760 | static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) { |
| 17761 | IrInstGen *target = instruction->target->child; |
| 16754 | 17762 | if (type_is_invalid(target->value->type)) |
| 16755 | | return ira->codegen->invalid_instruction; |
| 17763 | return ira->codegen->invalid_inst_gen; |
| 16756 | 17764 | |
| 16757 | | IrInstruction *options = instruction->options->child; |
| 17765 | IrInstGen *options = instruction->options->child; |
| 16758 | 17766 | if (type_is_invalid(options->value->type)) |
| 16759 | | return ira->codegen->invalid_instruction; |
| 17767 | return ira->codegen->invalid_inst_gen; |
| 16760 | 17768 | |
| 16761 | 17769 | ZigType *options_type = options->value->type; |
| 16762 | 17770 | assert(options_type->id == ZigTypeIdStruct); |
| 16763 | 17771 | |
| 16764 | 17772 | 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); |
| 17773 | ir_assert(name_field != nullptr, &instruction->base.base); |
| 17774 | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field); |
| 16767 | 17775 | if (type_is_invalid(name_inst->value->type)) |
| 16768 | | return ira->codegen->invalid_instruction; |
| 17776 | return ira->codegen->invalid_inst_gen; |
| 16769 | 17777 | |
| 16770 | 17778 | 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); |
| 17779 | ir_assert(linkage_field != nullptr, &instruction->base.base); |
| 17780 | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field); |
| 16773 | 17781 | if (type_is_invalid(linkage_inst->value->type)) |
| 16774 | | return ira->codegen->invalid_instruction; |
| 17782 | return ira->codegen->invalid_inst_gen; |
| 16775 | 17783 | |
| 16776 | 17784 | 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); |
| 17785 | ir_assert(section_field != nullptr, &instruction->base.base); |
| 17786 | IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field); |
| 16779 | 17787 | if (type_is_invalid(section_inst->value->type)) |
| 16780 | | return ira->codegen->invalid_instruction; |
| 17788 | return ira->codegen->invalid_inst_gen; |
| 16781 | 17789 | |
| 16782 | 17790 | // 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); |
| 17791 | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst); |
| 16784 | 17792 | bool is_non_null; |
| 16785 | 17793 | if (!ir_resolve_bool(ira, non_null_check, &is_non_null)) |
| 16786 | | return ira->codegen->invalid_instruction; |
| 17794 | return ira->codegen->invalid_inst_gen; |
| 16787 | 17795 | |
| 16788 | | IrInstruction *section_str_inst = nullptr; |
| 17796 | IrInstGen *section_str_inst = nullptr; |
| 16789 | 17797 | if (is_non_null) { |
| 16790 | | section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false); |
| 17798 | section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false); |
| 16791 | 17799 | if (type_is_invalid(section_str_inst->value->type)) |
| 16792 | | return ira->codegen->invalid_instruction; |
| 17800 | return ira->codegen->invalid_inst_gen; |
| 16793 | 17801 | } |
| 16794 | 17802 | |
| 16795 | 17803 | // Resolve all the comptime values |
| 16796 | 17804 | Buf *symbol_name = ir_resolve_str(ira, name_inst); |
| 16797 | 17805 | if (!symbol_name) |
| 16798 | | return ira->codegen->invalid_instruction; |
| 17806 | return ira->codegen->invalid_inst_gen; |
| 16799 | 17807 | |
| 16800 | 17808 | if (buf_len(symbol_name) < 1) { |
| 16801 | | ir_add_error(ira, name_inst, |
| 17809 | ir_add_error(ira, &name_inst->base, |
| 16802 | 17810 | buf_sprintf("exported symbol name cannot be empty")); |
| 16803 | | return ira->codegen->invalid_instruction; |
| 17811 | return ira->codegen->invalid_inst_gen; |
| 16804 | 17812 | } |
| 16805 | 17813 | |
| 16806 | 17814 | GlobalLinkageId global_linkage_id; |
| 16807 | 17815 | if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id)) |
| 16808 | | return ira->codegen->invalid_instruction; |
| 17816 | return ira->codegen->invalid_inst_gen; |
| 16809 | 17817 | |
| 16810 | 17818 | Buf *section_name = nullptr; |
| 16811 | 17819 | if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst))) |
| 16812 | | return ira->codegen->invalid_instruction; |
| 17820 | return ira->codegen->invalid_inst_gen; |
| 16813 | 17821 | |
| 16814 | 17822 | // TODO: This function needs to be audited. |
| 16815 | 17823 | // It's not clear how all the different types are supposed to be handled. |
| ... | ... | @@ -16817,15 +17825,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16817 | 17825 | // in another file. |
| 16818 | 17826 | TldFn *tld_fn = allocate<TldFn>(1); |
| 16819 | 17827 | tld_fn->base.id = TldIdFn; |
| 16820 | | tld_fn->base.source_node = instruction->base.source_node; |
| 17828 | tld_fn->base.source_node = instruction->base.base.source_node; |
| 16821 | 17829 | |
| 16822 | 17830 | auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base); |
| 16823 | 17831 | if (entry) { |
| 16824 | 17832 | AstNode *other_export_node = entry->value->source_node; |
| 16825 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 17833 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 16826 | 17834 | buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name))); |
| 16827 | 17835 | add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here")); |
| 16828 | | return ira->codegen->invalid_instruction; |
| 17836 | return ira->codegen->invalid_inst_gen; |
| 16829 | 17837 | } |
| 16830 | 17838 | |
| 16831 | 17839 | Error err; |
| ... | ... | @@ -16841,12 +17849,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16841 | 17849 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 16842 | 17850 | switch (cc) { |
| 16843 | 17851 | case CallingConventionUnspecified: { |
| 16844 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17852 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16845 | 17853 | buf_sprintf("exported function must specify calling convention")); |
| 16846 | 17854 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 16847 | 17855 | } break; |
| 16848 | 17856 | case CallingConventionAsync: { |
| 16849 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17857 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16850 | 17858 | buf_sprintf("exported function cannot be async")); |
| 16851 | 17859 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 16852 | 17860 | } break; |
| ... | ... | @@ -16869,10 +17877,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16869 | 17877 | } break; |
| 16870 | 17878 | case ZigTypeIdStruct: |
| 16871 | 17879 | if (is_slice(target->value->type)) { |
| 16872 | | ir_add_error(ira, target, |
| 17880 | ir_add_error(ira, &target->base, |
| 16873 | 17881 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); |
| 16874 | 17882 | } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { |
| 16875 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17883 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16876 | 17884 | buf_sprintf("exported struct value must be declared extern")); |
| 16877 | 17885 | add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); |
| 16878 | 17886 | } else { |
| ... | ... | @@ -16881,7 +17889,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16881 | 17889 | break; |
| 16882 | 17890 | case ZigTypeIdUnion: |
| 16883 | 17891 | if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { |
| 16884 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17892 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16885 | 17893 | buf_sprintf("exported union value must be declared extern")); |
| 16886 | 17894 | add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 16887 | 17895 | } else { |
| ... | ... | @@ -16890,7 +17898,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16890 | 17898 | break; |
| 16891 | 17899 | case ZigTypeIdEnum: |
| 16892 | 17900 | if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { |
| 16893 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17901 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16894 | 17902 | buf_sprintf("exported enum value must be declared extern")); |
| 16895 | 17903 | add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 16896 | 17904 | } else { |
| ... | ... | @@ -16900,10 +17908,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16900 | 17908 | case ZigTypeIdArray: { |
| 16901 | 17909 | bool ok_type; |
| 16902 | 17910 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) |
| 16903 | | return ira->codegen->invalid_instruction; |
| 17911 | return ira->codegen->invalid_inst_gen; |
| 16904 | 17912 | |
| 16905 | 17913 | if (!ok_type) { |
| 16906 | | ir_add_error(ira, target, |
| 17914 | ir_add_error(ira, &target->base, |
| 16907 | 17915 | buf_sprintf("array element type '%s' not extern-compatible", |
| 16908 | 17916 | buf_ptr(&target->value->type->data.array.child_type->name))); |
| 16909 | 17917 | } else { |
| ... | ... | @@ -16918,31 +17926,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16918 | 17926 | zig_unreachable(); |
| 16919 | 17927 | case ZigTypeIdStruct: |
| 16920 | 17928 | if (is_slice(type_value)) { |
| 16921 | | ir_add_error(ira, target, |
| 17929 | ir_add_error(ira, &target->base, |
| 16922 | 17930 | buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); |
| 16923 | 17931 | } else if (type_value->data.structure.layout != ContainerLayoutExtern) { |
| 16924 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17932 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16925 | 17933 | buf_sprintf("exported struct must be declared extern")); |
| 16926 | 17934 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); |
| 16927 | 17935 | } |
| 16928 | 17936 | break; |
| 16929 | 17937 | case ZigTypeIdUnion: |
| 16930 | 17938 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { |
| 16931 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17939 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16932 | 17940 | buf_sprintf("exported union must be declared extern")); |
| 16933 | 17941 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); |
| 16934 | 17942 | } |
| 16935 | 17943 | break; |
| 16936 | 17944 | case ZigTypeIdEnum: |
| 16937 | 17945 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { |
| 16938 | | ErrorMsg *msg = ir_add_error(ira, target, |
| 17946 | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 16939 | 17947 | buf_sprintf("exported enum must be declared extern")); |
| 16940 | 17948 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 16941 | 17949 | } |
| 16942 | 17950 | break; |
| 16943 | 17951 | case ZigTypeIdFn: { |
| 16944 | 17952 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 16945 | | ir_add_error(ira, target, |
| 17953 | ir_add_error(ira, &target->base, |
| 16946 | 17954 | buf_sprintf("exported function type must specify calling convention")); |
| 16947 | 17955 | } |
| 16948 | 17956 | } break; |
| ... | ... | @@ -16968,7 +17976,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16968 | 17976 | case ZigTypeIdOpaque: |
| 16969 | 17977 | case ZigTypeIdFnFrame: |
| 16970 | 17978 | case ZigTypeIdAnyFrame: |
| 16971 | | ir_add_error(ira, target, |
| 17979 | ir_add_error(ira, &target->base, |
| 16972 | 17980 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); |
| 16973 | 17981 | break; |
| 16974 | 17982 | } |
| ... | ... | @@ -16993,61 +18001,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 16993 | 18001 | case ZigTypeIdEnumLiteral: |
| 16994 | 18002 | case ZigTypeIdFnFrame: |
| 16995 | 18003 | case ZigTypeIdAnyFrame: |
| 16996 | | ir_add_error(ira, target, |
| 18004 | ir_add_error(ira, &target->base, |
| 16997 | 18005 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); |
| 16998 | 18006 | break; |
| 16999 | 18007 | } |
| 17000 | 18008 | |
| 17001 | 18009 | // 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); |
| 18010 | if (want_var_export && target->id == IrInstGenIdLoadPtr) { |
| 18011 | IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target); |
| 18012 | if (load_ptr->ptr->id == IrInstGenIdVarPtr) { |
| 18013 | IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr); |
| 17006 | 18014 | ZigVar *var = var_ptr->var; |
| 17007 | 18015 | add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id); |
| 17008 | 18016 | var->section_name = section_name; |
| 17009 | 18017 | } |
| 17010 | 18018 | } |
| 17011 | 18019 | |
| 17012 | | return ir_const_void(ira, &instruction->base); |
| 18020 | return ir_const_void(ira, &instruction->base.base); |
| 17013 | 18021 | } |
| 17014 | 18022 | |
| 17015 | | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { |
| 18023 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) { |
| 17016 | 18024 | ZigFn *fn_entry = exec_fn_entry(exec); |
| 17017 | 18025 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 17018 | 18026 | } |
| 17019 | 18027 | |
| 17020 | | static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 17021 | | IrInstructionErrorReturnTrace *instruction) |
| 18028 | static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 18029 | IrInstSrcErrorReturnTrace *instruction) |
| 17022 | 18030 | { |
| 17023 | 18031 | 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) { |
| 18032 | if (instruction->optional == IrInstErrorReturnTraceNull) { |
| 17025 | 18033 | 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); |
| 18034 | if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) { |
| 18035 | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); |
| 17028 | 18036 | ZigValue *out_val = result->value; |
| 17029 | 18037 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| 17030 | 18038 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 17031 | 18039 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| 17032 | 18040 | return result; |
| 17033 | 18041 | } |
| 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; |
| 18042 | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 18043 | instruction->base.base.source_node, instruction->optional, optional_type); |
| 17038 | 18044 | } else { |
| 17039 | 18045 | 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; |
| 18046 | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 18047 | instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type); |
| 17044 | 18048 | } |
| 17045 | 18049 | } |
| 17046 | 18050 | |
| 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); |
| 18051 | static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) { |
| 18052 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 17051 | 18053 | result->value->special = ConstValSpecialLazy; |
| 17052 | 18054 | |
| 17053 | 18055 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType"); |
| ... | ... | @@ -17057,16 +18059,16 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 17057 | 18059 | |
| 17058 | 18060 | lazy_err_union_type->err_set_type = instruction->err_set->child; |
| 17059 | 18061 | if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr) |
| 17060 | | return ira->codegen->invalid_instruction; |
| 18062 | return ira->codegen->invalid_inst_gen; |
| 17061 | 18063 | |
| 17062 | 18064 | lazy_err_union_type->payload_type = instruction->payload->child; |
| 17063 | 18065 | if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr) |
| 17064 | | return ira->codegen->invalid_instruction; |
| 18066 | return ira->codegen->invalid_inst_gen; |
| 17065 | 18067 | |
| 17066 | 18068 | return result; |
| 17067 | 18069 | } |
| 17068 | 18070 | |
| 17069 | | static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type, |
| 18071 | static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type, |
| 17070 | 18072 | uint32_t align, const char *name_hint, bool force_comptime) |
| 17071 | 18073 | { |
| 17072 | 18074 | Error err; |
| ... | ... | @@ -17074,7 +18076,7 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17074 | 18076 | ZigValue *pointee = create_const_vals(1); |
| 17075 | 18077 | pointee->special = ConstValSpecialUndef; |
| 17076 | 18078 | |
| 17077 | | IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 18079 | IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 17078 | 18080 | result->base.value->special = ConstValSpecialStatic; |
| 17079 | 18081 | result->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 17080 | 18082 | result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| ... | ... | @@ -17082,15 +18084,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17082 | 18084 | |
| 17083 | 18085 | bool var_type_has_bits; |
| 17084 | 18086 | if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits))) |
| 17085 | | return ira->codegen->invalid_instruction; |
| 18087 | return ira->codegen->invalid_inst_gen; |
| 17086 | 18088 | if (align != 0) { |
| 17087 | 18089 | if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown))) |
| 17088 | | return ira->codegen->invalid_instruction; |
| 18090 | return ira->codegen->invalid_inst_gen; |
| 17089 | 18091 | if (!var_type_has_bits) { |
| 17090 | 18092 | ir_add_error(ira, source_inst, |
| 17091 | 18093 | buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned", |
| 17092 | 18094 | name_hint, buf_ptr(&var_type->name))); |
| 17093 | | return ira->codegen->invalid_instruction; |
| 18095 | return ira->codegen->invalid_inst_gen; |
| 17094 | 18096 | } |
| 17095 | 18097 | } |
| 17096 | 18098 | assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid); |
| ... | ... | @@ -17099,15 +18101,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17099 | 18101 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 17100 | 18102 | PtrLenSingle, align, 0, 0, false); |
| 17101 | 18103 | |
| 17102 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 18104 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 17103 | 18105 | if (fn_entry != nullptr) { |
| 17104 | 18106 | fn_entry->alloca_gen_list.append(result); |
| 17105 | 18107 | } |
| 17106 | | result->base.is_gen = true; |
| 17107 | 18108 | return &result->base; |
| 17108 | 18109 | } |
| 17109 | 18110 | |
| 17110 | | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 18111 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 17111 | 18112 | ResultLoc *result_loc) |
| 17112 | 18113 | { |
| 17113 | 18114 | switch (result_loc->id) { |
| ... | ... | @@ -17150,7 +18151,7 @@ static bool type_can_bit_cast(ZigType *t) { |
| 17150 | 18151 | } |
| 17151 | 18152 | } |
| 17152 | 18153 | |
| 17153 | | static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { |
| 18154 | static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) { |
| 17154 | 18155 | ZigValue *undef_child = create_const_vals(1); |
| 17155 | 18156 | undef_child->type = ptr->value->type->data.pointer.child_type; |
| 17156 | 18157 | undef_child->special = ConstValSpecialUndef; |
| ... | ... | @@ -17189,16 +18190,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 17189 | 18190 | zig_unreachable(); |
| 17190 | 18191 | } |
| 17191 | 18192 | |
| 17192 | | static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr, |
| 18193 | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 17193 | 18194 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) |
| 17194 | 18195 | { |
| 17195 | 18196 | 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, ""); |
| 18197 | return ira->codegen->invalid_inst_gen; |
| 18198 | IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 17198 | 18199 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 17199 | 18200 | PtrLenSingle, 0, 0, 0, false); |
| 17200 | 18201 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); |
| 17201 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 18202 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 17202 | 18203 | if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) { |
| 17203 | 18204 | fn_entry->alloca_gen_list.append(alloca_gen); |
| 17204 | 18205 | } |
| ... | ... | @@ -17208,8 +18209,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su |
| 17208 | 18209 | } |
| 17209 | 18210 | |
| 17210 | 18211 | // 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, |
| 18212 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18213 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 17213 | 18214 | bool non_null_comptime, bool allow_discard) |
| 17214 | 18215 | { |
| 17215 | 18216 | Error err; |
| ... | ... | @@ -17235,35 +18236,34 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17235 | 18236 | } |
| 17236 | 18237 | case ResultLocIdVar: { |
| 17237 | 18238 | ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc); |
| 17238 | | assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc); |
| 18239 | assert(result_loc->source_instruction->id == IrInstSrcIdAlloca); |
| 17239 | 18240 | |
| 17240 | 18241 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { |
| 17241 | | ir_add_error(ira, result_loc->source_instruction, |
| 18242 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17242 | 18243 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); |
| 17243 | | return ira->codegen->invalid_instruction; |
| 18244 | return ira->codegen->invalid_inst_gen; |
| 17244 | 18245 | } |
| 17245 | 18246 | |
| 17246 | | IrInstructionAllocaSrc *alloca_src = |
| 17247 | | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| 18247 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); |
| 17248 | 18248 | bool force_comptime; |
| 17249 | 18249 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 17250 | | return ira->codegen->invalid_instruction; |
| 18250 | return ira->codegen->invalid_inst_gen; |
| 17251 | 18251 | bool is_comptime = force_comptime || (!force_runtime && value != nullptr && |
| 17252 | 18252 | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 17253 | 18253 | |
| 17254 | 18254 | if (alloca_src->base.child == nullptr || is_comptime) { |
| 17255 | 18255 | uint32_t align = 0; |
| 17256 | 18256 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 17257 | | return ira->codegen->invalid_instruction; |
| 18257 | return ira->codegen->invalid_inst_gen; |
| 17258 | 18258 | } |
| 17259 | | IrInstruction *alloca_gen; |
| 18259 | IrInstGen *alloca_gen; |
| 17260 | 18260 | if (is_comptime && value != nullptr) { |
| 17261 | 18261 | if (align > value->value->llvm_align) { |
| 17262 | 18262 | value->value->llvm_align = align; |
| 17263 | 18263 | } |
| 17264 | | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 18264 | alloca_gen = ir_get_ref(ira, &result_loc->source_instruction->base, value, true, false); |
| 17265 | 18265 | } else { |
| 17266 | | alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align, |
| 18266 | alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, align, |
| 17267 | 18267 | alloca_src->name_hint, force_comptime); |
| 17268 | 18268 | if (force_runtime) { |
| 17269 | 18269 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| ... | ... | @@ -17271,7 +18271,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17271 | 18271 | } |
| 17272 | 18272 | } |
| 17273 | 18273 | if (alloca_src->base.child != nullptr && !result_loc->written) { |
| 17274 | | alloca_src->base.child->ref_count = 0; |
| 18274 | alloca_src->base.child->base.ref_count = 0; |
| 17275 | 18275 | } |
| 17276 | 18276 | alloca_src->base.child = alloca_gen; |
| 17277 | 18277 | } |
| ... | ... | @@ -17296,9 +18296,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17296 | 18296 | } |
| 17297 | 18297 | bool has_bits; |
| 17298 | 18298 | if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits))) |
| 17299 | | return ira->codegen->invalid_instruction; |
| 18299 | return ira->codegen->invalid_inst_gen; |
| 17300 | 18300 | if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) { |
| 17301 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 18301 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 17302 | 18302 | if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) { |
| 17303 | 18303 | return nullptr; |
| 17304 | 18304 | } |
| ... | ... | @@ -17306,8 +18306,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17306 | 18306 | |
| 17307 | 18307 | ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false); |
| 17308 | 18308 | 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)) { |
| 18309 | result_loc->resolved_loc = ir_build_return_ptr(ira, &result_loc->source_instruction->base, ptr_return_type); |
| 18310 | if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->base.scope)) { |
| 17311 | 18311 | set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc); |
| 17312 | 18312 | } |
| 17313 | 18313 | return result_loc->resolved_loc; |
| ... | ... | @@ -17317,7 +18317,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17317 | 18317 | ResultLocPeerParent *peer_parent = result_peer->parent; |
| 17318 | 18318 | |
| 17319 | 18319 | if (peer_parent->peers.length == 1) { |
| 17320 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18320 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17321 | 18321 | value_type, value, force_runtime, non_null_comptime, true); |
| 17322 | 18322 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 17323 | 18323 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| ... | ... | @@ -17333,7 +18333,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17333 | 18333 | |
| 17334 | 18334 | bool is_condition_comptime; |
| 17335 | 18335 | if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime)) |
| 17336 | | return ira->codegen->invalid_instruction; |
| 18336 | return ira->codegen->invalid_inst_gen; |
| 17337 | 18337 | if (is_condition_comptime) { |
| 17338 | 18338 | peer_parent->skipped = true; |
| 17339 | 18339 | if (non_null_comptime) { |
| ... | ... | @@ -17344,10 +18344,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17344 | 18344 | } |
| 17345 | 18345 | bool peer_parent_has_type; |
| 17346 | 18346 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| 17347 | | return ira->codegen->invalid_instruction; |
| 18347 | return ira->codegen->invalid_inst_gen; |
| 17348 | 18348 | if (peer_parent_has_type) { |
| 17349 | 18349 | peer_parent->skipped = true; |
| 17350 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18350 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17351 | 18351 | value_type, value, force_runtime || !is_condition_comptime, true, true); |
| 17352 | 18352 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17353 | 18353 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| ... | ... | @@ -17364,7 +18364,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17364 | 18364 | if (peer_parent->end_bb->suspend_instruction_ref == nullptr) { |
| 17365 | 18365 | peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr; |
| 17366 | 18366 | } |
| 17367 | | IrInstruction *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb, |
| 18367 | IrInstGen *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb, |
| 17368 | 18368 | &result_peer->suspend_pos); |
| 17369 | 18369 | if (result_peer->next_bb == nullptr) { |
| 17370 | 18370 | ir_start_next_bb(ira); |
| ... | ... | @@ -17372,7 +18372,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17372 | 18372 | return unreach_inst; |
| 17373 | 18373 | } |
| 17374 | 18374 | |
| 17375 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 18375 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 17376 | 18376 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); |
| 17377 | 18377 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17378 | 18378 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| ... | ... | @@ -17391,24 +18391,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17391 | 18391 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 17392 | 18392 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| 17393 | 18393 | if (type_is_invalid(dest_type)) |
| 17394 | | return ira->codegen->invalid_instruction; |
| 18394 | return ira->codegen->invalid_inst_gen; |
| 17395 | 18395 | |
| 17396 | 18396 | if (dest_type == ira->codegen->builtin_types.entry_var) { |
| 17397 | 18397 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type, |
| 17398 | 18398 | force_runtime, non_null_comptime); |
| 17399 | 18399 | } |
| 17400 | 18400 | |
| 17401 | | IrInstruction *casted_value; |
| 18401 | IrInstGen *casted_value; |
| 17402 | 18402 | if (value != nullptr) { |
| 17403 | 18403 | casted_value = ir_implicit_cast(ira, value, dest_type); |
| 17404 | 18404 | if (type_is_invalid(casted_value->value->type)) |
| 17405 | | return ira->codegen->invalid_instruction; |
| 18405 | return ira->codegen->invalid_inst_gen; |
| 17406 | 18406 | dest_type = casted_value->value->type; |
| 17407 | 18407 | } else { |
| 17408 | 18408 | casted_value = nullptr; |
| 17409 | 18409 | } |
| 17410 | 18410 | |
| 17411 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 18411 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 17412 | 18412 | dest_type, casted_value, force_runtime, non_null_comptime, true); |
| 17413 | 18413 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17414 | 18414 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| ... | ... | @@ -17422,11 +18422,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17422 | 18422 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 17423 | 18423 | ResolveStatusAlignmentKnown))) |
| 17424 | 18424 | { |
| 17425 | | return ira->codegen->invalid_instruction; |
| 18425 | return ira->codegen->invalid_inst_gen; |
| 17426 | 18426 | } |
| 17427 | 18427 | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 17428 | 18428 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { |
| 17429 | | return ira->codegen->invalid_instruction; |
| 18429 | return ira->codegen->invalid_inst_gen; |
| 17430 | 18430 | } |
| 17431 | 18431 | if (!type_has_bits(value_type)) { |
| 17432 | 18432 | parent_ptr_align = 0; |
| ... | ... | @@ -17449,9 +18449,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17449 | 18449 | |
| 17450 | 18450 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 17451 | 18451 | parent_result_loc->value->type, ptr_type, |
| 17452 | | result_cast->base.source_instruction->source_node, false); |
| 18452 | result_cast->base.source_instruction->base.source_node, false); |
| 17453 | 18453 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 17454 | | return ira->codegen->invalid_instruction; |
| 18454 | return ira->codegen->invalid_inst_gen; |
| 17455 | 18455 | if (const_cast_result.id != ConstCastResultIdOk) { |
| 17456 | 18456 | if (allow_discard) { |
| 17457 | 18457 | return parent_result_loc; |
| ... | ... | @@ -17465,42 +18465,42 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17465 | 18465 | |
| 17466 | 18466 | result_loc->written = true; |
| 17467 | 18467 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 17468 | | ptr_type, result_cast->base.source_instruction, false); |
| 18468 | ptr_type, &result_cast->base.source_instruction->base, false); |
| 17469 | 18469 | return result_loc->resolved_loc; |
| 17470 | 18470 | } |
| 17471 | 18471 | case ResultLocIdBitCast: { |
| 17472 | 18472 | ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc); |
| 17473 | 18473 | ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child); |
| 17474 | 18474 | if (type_is_invalid(dest_type)) |
| 17475 | | return ira->codegen->invalid_instruction; |
| 18475 | return ira->codegen->invalid_inst_gen; |
| 17476 | 18476 | |
| 17477 | 18477 | if (get_codegen_ptr_type(dest_type) != nullptr) { |
| 17478 | | ir_add_error(ira, result_loc->source_instruction, |
| 18478 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17479 | 18479 | buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name))); |
| 17480 | | return ira->codegen->invalid_instruction; |
| 18480 | return ira->codegen->invalid_inst_gen; |
| 17481 | 18481 | } |
| 17482 | 18482 | |
| 17483 | 18483 | if (!type_can_bit_cast(dest_type)) { |
| 17484 | | ir_add_error(ira, result_loc->source_instruction, |
| 18484 | ir_add_error(ira, &result_loc->source_instruction->base, |
| 17485 | 18485 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 17486 | | return ira->codegen->invalid_instruction; |
| 18486 | return ira->codegen->invalid_inst_gen; |
| 17487 | 18487 | } |
| 17488 | 18488 | |
| 17489 | 18489 | if (get_codegen_ptr_type(value_type) != nullptr) { |
| 17490 | 18490 | ir_add_error(ira, suspend_source_instr, |
| 17491 | 18491 | buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name))); |
| 17492 | | return ira->codegen->invalid_instruction; |
| 18492 | return ira->codegen->invalid_inst_gen; |
| 17493 | 18493 | } |
| 17494 | 18494 | |
| 17495 | 18495 | if (!type_can_bit_cast(value_type)) { |
| 17496 | 18496 | ir_add_error(ira, suspend_source_instr, |
| 17497 | 18497 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name))); |
| 17498 | | return ira->codegen->invalid_instruction; |
| 18498 | return ira->codegen->invalid_inst_gen; |
| 17499 | 18499 | } |
| 17500 | 18500 | |
| 17501 | | IrInstruction *bitcasted_value; |
| 18501 | IrInstGen *bitcasted_value; |
| 17502 | 18502 | if (value != nullptr) { |
| 17503 | | bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type); |
| 18503 | bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type); |
| 17504 | 18504 | dest_type = bitcasted_value->value->type; |
| 17505 | 18505 | } else { |
| 17506 | 18506 | bitcasted_value = nullptr; |
| ... | ... | @@ -17510,7 +18510,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17510 | 18510 | return bitcasted_value; |
| 17511 | 18511 | } |
| 17512 | 18512 | |
| 17513 | | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 18513 | IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 17514 | 18514 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 17515 | 18515 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 17516 | 18516 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| ... | ... | @@ -17523,7 +18523,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17523 | 18523 | |
| 17524 | 18524 | bool has_bits; |
| 17525 | 18525 | if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) { |
| 17526 | | return ira->codegen->invalid_instruction; |
| 18526 | return ira->codegen->invalid_inst_gen; |
| 17527 | 18527 | } |
| 17528 | 18528 | |
| 17529 | 18529 | // This happens when the bitCast result is assigned to _ |
| ... | ... | @@ -17533,12 +18533,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17533 | 18533 | } |
| 17534 | 18534 | |
| 17535 | 18535 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) { |
| 17536 | | return ira->codegen->invalid_instruction; |
| 18536 | return ira->codegen->invalid_inst_gen; |
| 17537 | 18537 | } |
| 17538 | 18538 | |
| 17539 | 18539 | uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type); |
| 17540 | 18540 | if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) { |
| 17541 | | return ira->codegen->invalid_instruction; |
| 18541 | return ira->codegen->invalid_inst_gen; |
| 17542 | 18542 | } |
| 17543 | 18543 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type, |
| 17544 | 18544 | parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, |
| ... | ... | @@ -17546,29 +18546,33 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 17546 | 18546 | |
| 17547 | 18547 | result_loc->written = true; |
| 17548 | 18548 | 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); |
| 18549 | ptr_type, &result_bit_cast->base.source_instruction->base, false); |
| 17550 | 18550 | return result_loc->resolved_loc; |
| 17551 | 18551 | } |
| 17552 | 18552 | } |
| 17553 | 18553 | zig_unreachable(); |
| 17554 | 18554 | } |
| 17555 | 18555 | |
| 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, |
| 18556 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 18557 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 17558 | 18558 | bool non_null_comptime, bool allow_discard) |
| 17559 | 18559 | { |
| 17560 | 18560 | Error err; |
| 17561 | 18561 | 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) |
| 18562 | result_loc_pass1->source_instruction->id == IrInstSrcIdConst) |
| 17565 | 18563 | { |
| 17566 | | result_loc_pass1 = no_result_loc(); |
| 18564 | IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction); |
| 18565 | if (value_is_comptime(const_inst->value) && |
| 18566 | const_inst->value->type->id == ZigTypeIdPointer && |
| 18567 | const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| 18568 | { |
| 18569 | result_loc_pass1 = no_result_loc(); |
| 18570 | } |
| 17567 | 18571 | } |
| 17568 | 18572 | 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, |
| 18573 | IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 17570 | 18574 | 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))) |
| 18575 | if (result_loc == nullptr || (result_loc->value->type->id == ZigTypeIdUnreachable || type_is_invalid(result_loc->value->type))) |
| 17572 | 18576 | return result_loc; |
| 17573 | 18577 | |
| 17574 | 18578 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && |
| ... | ... | @@ -17591,11 +18595,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17591 | 18595 | field->type_entry = value_type; |
| 17592 | 18596 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 17593 | 18597 | field->src_index = old_field_count; |
| 17594 | | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; |
| 18598 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| 17595 | 18599 | if (value && instr_is_comptime(value)) { |
| 17596 | 18600 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 17597 | 18601 | if (!val) |
| 17598 | | return ira->codegen->invalid_instruction; |
| 18602 | return ira->codegen->invalid_inst_gen; |
| 17599 | 18603 | field->is_comptime = true; |
| 17600 | 18604 | field->init_val = create_const_vals(1); |
| 17601 | 18605 | copy_const_val(field->init_val, val); |
| ... | ... | @@ -17603,7 +18607,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17603 | 18607 | } |
| 17604 | 18608 | |
| 17605 | 18609 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 17606 | | IrInstruction *casted_ptr; |
| 18610 | IrInstGen *casted_ptr; |
| 17607 | 18611 | if (instr_is_comptime(result_loc)) { |
| 17608 | 18612 | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| 17609 | 18613 | copy_const_val(casted_ptr->value, result_loc->value); |
| ... | ... | @@ -17614,7 +18618,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17614 | 18618 | if (instr_is_comptime(casted_ptr)) { |
| 17615 | 18619 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 17616 | 18620 | if (!ptr_val) |
| 17617 | | return ira->codegen->invalid_instruction; |
| 18621 | return ira->codegen->invalid_inst_gen; |
| 17618 | 18622 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 17619 | 18623 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| 17620 | 18624 | suspend_source_instr->source_node); |
| ... | ... | @@ -17644,7 +18648,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17644 | 18648 | { |
| 17645 | 18649 | bool has_bits; |
| 17646 | 18650 | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) |
| 17647 | | return ira->codegen->invalid_instruction; |
| 18651 | return ira->codegen->invalid_inst_gen; |
| 17648 | 18652 | if (has_bits) { |
| 17649 | 18653 | result_loc_pass1->written = false; |
| 17650 | 18654 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); |
| ... | ... | @@ -17652,12 +18656,12 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17652 | 18656 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) { |
| 17653 | 18657 | bool has_bits; |
| 17654 | 18658 | if ((err = type_has_bits2(ira->codegen, value_type, &has_bits))) |
| 17655 | | return ira->codegen->invalid_instruction; |
| 18659 | return ira->codegen->invalid_inst_gen; |
| 17656 | 18660 | if (has_bits) { |
| 17657 | 18661 | if (value_type->id == ZigTypeIdErrorSet) { |
| 17658 | 18662 | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); |
| 17659 | 18663 | } else { |
| 17660 | | IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| 18664 | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| 17661 | 18665 | result_loc, false, true); |
| 17662 | 18666 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| 17663 | 18667 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| ... | ... | @@ -17672,37 +18676,35 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17672 | 18676 | return result_loc; |
| 17673 | 18677 | } |
| 17674 | 18678 | |
| 17675 | | static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17676 | | IrInstructionResolveResult *instruction) |
| 17677 | | { |
| 18679 | static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) { |
| 17678 | 18680 | ZigType *implicit_elem_type; |
| 17679 | 18681 | if (instruction->ty == nullptr) { |
| 17680 | 18682 | if (instruction->result_loc->id == ResultLocIdCast) { |
| 17681 | 18683 | implicit_elem_type = ir_resolve_type(ira, |
| 17682 | 18684 | instruction->result_loc->source_instruction->child); |
| 17683 | 18685 | if (type_is_invalid(implicit_elem_type)) |
| 17684 | | return ira->codegen->invalid_instruction; |
| 18686 | return ira->codegen->invalid_inst_gen; |
| 17685 | 18687 | } else if (instruction->result_loc->id == ResultLocIdReturn) { |
| 17686 | 18688 | implicit_elem_type = ira->explicit_return_type; |
| 17687 | 18689 | if (type_is_invalid(implicit_elem_type)) |
| 17688 | | return ira->codegen->invalid_instruction; |
| 18690 | return ira->codegen->invalid_inst_gen; |
| 17689 | 18691 | } else { |
| 17690 | 18692 | implicit_elem_type = ira->codegen->builtin_types.entry_var; |
| 17691 | 18693 | } |
| 17692 | 18694 | if (implicit_elem_type == ira->codegen->builtin_types.entry_var) { |
| 17693 | 18695 | Buf *bare_name = buf_alloc(); |
| 17694 | 18696 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 17695 | | instruction->base.scope, instruction->base.source_node, bare_name); |
| 18697 | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| 17696 | 18698 | |
| 17697 | 18699 | StructSpecial struct_special = StructSpecialInferredStruct; |
| 17698 | | if (instruction->base.source_node->type == NodeTypeContainerInitExpr && |
| 17699 | | instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 18700 | if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr && |
| 18701 | instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 17700 | 18702 | { |
| 17701 | 18703 | struct_special = StructSpecialInferredTuple; |
| 17702 | 18704 | } |
| 17703 | 18705 | |
| 17704 | 18706 | ZigType *inferred_struct_type = get_partial_container_type(ira->codegen, |
| 17705 | | instruction->base.scope, ContainerKindStruct, instruction->base.source_node, |
| 18707 | instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node, |
| 17706 | 18708 | buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 17707 | 18709 | inferred_struct_type->data.structure.special = struct_special; |
| 17708 | 18710 | inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| ... | ... | @@ -17711,21 +18713,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17711 | 18713 | } else { |
| 17712 | 18714 | implicit_elem_type = ir_resolve_type(ira, instruction->ty->child); |
| 17713 | 18715 | if (type_is_invalid(implicit_elem_type)) |
| 17714 | | return ira->codegen->invalid_instruction; |
| 18716 | return ira->codegen->invalid_inst_gen; |
| 17715 | 18717 | } |
| 17716 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 18718 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 17717 | 18719 | implicit_elem_type, nullptr, false, true, true); |
| 17718 | 18720 | if (result_loc != nullptr) |
| 17719 | 18721 | return result_loc; |
| 17720 | 18722 | |
| 17721 | | ZigFn *fn = exec_fn_entry(ira->new_irb.exec); |
| 18723 | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 17722 | 18724 | if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 17723 | 18725 | instruction->result_loc->id == ResultLocIdReturn) |
| 17724 | 18726 | { |
| 17725 | | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 18727 | result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(), |
| 17726 | 18728 | implicit_elem_type, nullptr, false, true, true); |
| 17727 | 18729 | if (result_loc != nullptr && |
| 17728 | | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 18730 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 17729 | 18731 | { |
| 17730 | 18732 | return result_loc; |
| 17731 | 18733 | } |
| ... | ... | @@ -17733,9 +18735,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 17733 | 18735 | return result_loc; |
| 17734 | 18736 | } |
| 17735 | 18737 | |
| 17736 | | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); |
| 18738 | IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type); |
| 17737 | 18739 | result->value->special = ConstValSpecialUndef; |
| 17738 | | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); |
| 18740 | IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false); |
| 17739 | 18741 | ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 17740 | 18742 | return ptr; |
| 17741 | 18743 | } |
| ... | ... | @@ -17759,8 +18761,7 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 17759 | 18761 | break; |
| 17760 | 18762 | } |
| 17761 | 18763 | case ResultLocIdVar: { |
| 17762 | | IrInstructionAllocaSrc *alloca_src = |
| 17763 | | reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction); |
| 18764 | IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction); |
| 17764 | 18765 | alloca_src->base.child = nullptr; |
| 17765 | 18766 | break; |
| 17766 | 18767 | } |
| ... | ... | @@ -17776,18 +18777,18 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 17776 | 18777 | } |
| 17777 | 18778 | } |
| 17778 | 18779 | |
| 17779 | | static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) { |
| 18780 | static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) { |
| 17780 | 18781 | ir_reset_result(instruction->result_loc); |
| 17781 | | return ir_const_void(ira, &instruction->base); |
| 18782 | return ir_const_void(ira, &instruction->base.base); |
| 17782 | 18783 | } |
| 17783 | 18784 | |
| 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) |
| 18785 | static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr, |
| 18786 | ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len, |
| 18787 | IrInstGen *ret_ptr_uncasted) |
| 17787 | 18788 | { |
| 17788 | 18789 | ir_assert(is_async_call_builtin, source_instr); |
| 17789 | 18790 | if (type_is_invalid(ret_ptr_uncasted->value->type)) |
| 17790 | | return ira->codegen->invalid_instruction; |
| 18791 | return ira->codegen->invalid_inst_gen; |
| 17791 | 18792 | if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { |
| 17792 | 18793 | // Result location will be inside the async frame. |
| 17793 | 18794 | return nullptr; |
| ... | ... | @@ -17795,57 +18796,57 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s |
| 17795 | 18796 | return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false)); |
| 17796 | 18797 | } |
| 17797 | 18798 | |
| 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, |
| 18799 | static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry, |
| 18800 | ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count, |
| 18801 | IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted, |
| 17801 | 18802 | ResultLoc *call_result_loc) |
| 17802 | 18803 | { |
| 17803 | 18804 | if (fn_entry == nullptr) { |
| 17804 | 18805 | if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) { |
| 17805 | | ir_add_error(ira, fn_ref, |
| 18806 | ir_add_error(ira, &fn_ref->base, |
| 17806 | 18807 | buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name))); |
| 17807 | | return ira->codegen->invalid_instruction; |
| 18808 | return ira->codegen->invalid_inst_gen; |
| 17808 | 18809 | } |
| 17809 | 18810 | 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; |
| 18811 | ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required")); |
| 18812 | return ira->codegen->invalid_inst_gen; |
| 17812 | 18813 | } |
| 17813 | 18814 | } |
| 17814 | 18815 | if (casted_new_stack != nullptr) { |
| 17815 | 18816 | 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, |
| 18817 | IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin, |
| 17817 | 18818 | casted_args, arg_count, ret_ptr_uncasted); |
| 17818 | 18819 | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) |
| 17819 | | return ira->codegen->invalid_instruction; |
| 18820 | return ira->codegen->invalid_inst_gen; |
| 17820 | 18821 | |
| 17821 | 18822 | ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); |
| 17822 | 18823 | |
| 17823 | | IrInstructionCallGen *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 18824 | IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 17824 | 18825 | arg_count, casted_args, CallModifierAsync, casted_new_stack, |
| 17825 | 18826 | is_async_call_builtin, ret_ptr, anyframe_type); |
| 17826 | 18827 | return &call_gen->base; |
| 17827 | 18828 | } else { |
| 17828 | 18829 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 17829 | | IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18830 | IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 17830 | 18831 | frame_type, nullptr, true, true, false); |
| 17831 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 18832 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 17832 | 18833 | return result_loc; |
| 17833 | 18834 | } |
| 17834 | 18835 | result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); |
| 17835 | 18836 | if (type_is_invalid(result_loc->value->type)) |
| 17836 | | return ira->codegen->invalid_instruction; |
| 18837 | return ira->codegen->invalid_inst_gen; |
| 17837 | 18838 | return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count, |
| 17838 | 18839 | casted_args, CallModifierAsync, casted_new_stack, |
| 17839 | 18840 | is_async_call_builtin, result_loc, frame_type)->base; |
| 17840 | 18841 | } |
| 17841 | 18842 | } |
| 17842 | 18843 | 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) |
| 18844 | IrInstGen *arg, Scope **exec_scope, size_t *next_proto_i) |
| 17844 | 18845 | { |
| 17845 | 18846 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 17846 | 18847 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 17847 | 18848 | |
| 17848 | | IrInstruction *casted_arg; |
| 18849 | IrInstGen *casted_arg; |
| 17849 | 18850 | if (param_decl_node->data.param_decl.var_token == nullptr) { |
| 17850 | 18851 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 17851 | 18852 | ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node); |
| ... | ... | @@ -17873,15 +18874,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 17873 | 18874 | } |
| 17874 | 18875 | |
| 17875 | 18876 | 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, |
| 18877 | IrInstGen *arg, Scope **child_scope, size_t *next_proto_i, |
| 18878 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args, |
| 17878 | 18879 | ZigFn *impl_fn) |
| 17879 | 18880 | { |
| 17880 | 18881 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 17881 | 18882 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 17882 | 18883 | bool is_var_args = param_decl_node->data.param_decl.is_var_args; |
| 17883 | 18884 | bool arg_part_of_generic_id = false; |
| 17884 | | IrInstruction *casted_arg; |
| 18885 | IrInstGen *casted_arg; |
| 17885 | 18886 | if (is_var_args) { |
| 17886 | 18887 | arg_part_of_generic_id = true; |
| 17887 | 18888 | casted_arg = arg; |
| ... | ... | @@ -17941,7 +18942,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 17941 | 18942 | } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || |
| 17942 | 18943 | casted_arg->value->type->id == ZigTypeIdComptimeFloat) |
| 17943 | 18944 | { |
| 17944 | | ir_add_error(ira, casted_arg, |
| 18945 | ir_add_error(ira, &casted_arg->base, |
| 17945 | 18946 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| 17946 | 18947 | return false; |
| 17947 | 18948 | } |
| ... | ... | @@ -17958,17 +18959,17 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 17958 | 18959 | return true; |
| 17959 | 18960 | } |
| 17960 | 18961 | |
| 17961 | | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { |
| 18962 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 17962 | 18963 | while (var->next_var != nullptr) { |
| 17963 | 18964 | var = var->next_var; |
| 17964 | 18965 | } |
| 17965 | 18966 | |
| 17966 | 18967 | if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) { |
| 17967 | 18968 | assert(ira->codegen->errors.length != 0); |
| 17968 | | return ira->codegen->invalid_instruction; |
| 18969 | return ira->codegen->invalid_inst_gen; |
| 17969 | 18970 | } |
| 17970 | 18971 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) |
| 17971 | | return ira->codegen->invalid_instruction; |
| 18972 | return ira->codegen->invalid_inst_gen; |
| 17972 | 18973 | |
| 17973 | 18974 | ZigValue *mem_slot = nullptr; |
| 17974 | 18975 | |
| ... | ... | @@ -17976,8 +18977,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 17976 | 18977 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 17977 | 18978 | bool is_volatile = false; |
| 17978 | 18979 | |
| 17979 | | IrInstruction *result = ir_build_var_ptr(&ira->new_irb, |
| 17980 | | instruction->scope, instruction->source_node, var); |
| 18980 | IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var); |
| 17981 | 18981 | result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 17982 | 18982 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 17983 | 18983 | |
| ... | ... | @@ -18030,7 +19030,7 @@ no_mem_slot: |
| 18030 | 19030 | } |
| 18031 | 19031 | |
| 18032 | 19032 | // 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) { |
| 19033 | static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) { |
| 18034 | 19034 | ir_assert(value_is_comptime(val), source_instr); |
| 18035 | 19035 | if (val->special == ConstValSpecialUndef) |
| 18036 | 19036 | return; |
| ... | ... | @@ -18043,8 +19043,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins |
| 18043 | 19043 | } |
| 18044 | 19044 | } |
| 18045 | 19045 | |
| 18046 | | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 18047 | | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 19046 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 19047 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const) |
| 18048 | 19048 | { |
| 18049 | 19049 | assert(ptr->value->type->id == ZigTypeIdPointer); |
| 18050 | 19050 | |
| ... | ... | @@ -18053,24 +19053,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18053 | 19053 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 18054 | 19054 | { |
| 18055 | 19055 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); |
| 18056 | | return ira->codegen->invalid_instruction; |
| 19056 | return ira->codegen->invalid_inst_gen; |
| 18057 | 19057 | } |
| 18058 | 19058 | return ir_const_void(ira, source_instr); |
| 18059 | 19059 | } |
| 18060 | 19060 | |
| 18061 | 19061 | if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { |
| 18062 | 19062 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 18063 | | return ira->codegen->invalid_instruction; |
| 19063 | return ira->codegen->invalid_inst_gen; |
| 18064 | 19064 | } |
| 18065 | 19065 | |
| 18066 | 19066 | 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; |
| 19067 | IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type); |
| 19068 | if (type_is_invalid(value->value->type)) |
| 19069 | return ira->codegen->invalid_inst_gen; |
| 18070 | 19070 | |
| 18071 | 19071 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 18072 | 19072 | case OnePossibleValueInvalid: |
| 18073 | | return ira->codegen->invalid_instruction; |
| 19073 | return ira->codegen->invalid_inst_gen; |
| 18074 | 19074 | case OnePossibleValueYes: |
| 18075 | 19075 | return ir_const_void(ira, source_instr); |
| 18076 | 19076 | case OnePossibleValueNo: |
| ... | ... | @@ -18080,7 +19080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18080 | 19080 | if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 18081 | 19081 | if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 18082 | 19082 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 18083 | | return ira->codegen->invalid_instruction; |
| 19083 | return ira->codegen->invalid_inst_gen; |
| 18084 | 19084 | } |
| 18085 | 19085 | if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) || |
| 18086 | 19086 | ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar || |
| ... | ... | @@ -18089,7 +19089,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18089 | 19089 | if (instr_is_comptime(value)) { |
| 18090 | 19090 | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); |
| 18091 | 19091 | if (dest_val == nullptr) |
| 18092 | | return ira->codegen->invalid_instruction; |
| 19092 | return ira->codegen->invalid_inst_gen; |
| 18093 | 19093 | if (dest_val->special != ConstValSpecialRuntime) { |
| 18094 | 19094 | copy_const_val(dest_val, value->value); |
| 18095 | 19095 | |
| ... | ... | @@ -18109,7 +19109,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18109 | 19109 | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 18110 | 19110 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 18111 | 19111 | |
| 18112 | | return ira->codegen->invalid_instruction; |
| 19112 | return ira->codegen->invalid_inst_gen; |
| 18113 | 19113 | } |
| 18114 | 19114 | } |
| 18115 | 19115 | } |
| ... | ... | @@ -18122,15 +19122,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18122 | 19122 | |
| 18123 | 19123 | switch (type_requires_comptime(ira->codegen, child_type)) { |
| 18124 | 19124 | case ReqCompTimeInvalid: |
| 18125 | | return ira->codegen->invalid_instruction; |
| 19125 | return ira->codegen->invalid_inst_gen; |
| 18126 | 19126 | case ReqCompTimeYes: |
| 18127 | 19127 | switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) { |
| 18128 | 19128 | case OnePossibleValueInvalid: |
| 18129 | | return ira->codegen->invalid_instruction; |
| 19129 | return ira->codegen->invalid_inst_gen; |
| 18130 | 19130 | case OnePossibleValueNo: |
| 18131 | 19131 | ir_add_error(ira, source_instr, |
| 18132 | 19132 | buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name))); |
| 18133 | | return ira->codegen->invalid_instruction; |
| 19133 | return ira->codegen->invalid_inst_gen; |
| 18134 | 19134 | case OnePossibleValueYes: |
| 18135 | 19135 | return ir_const_void(ira, source_instr); |
| 18136 | 19136 | } |
| ... | ... | @@ -18144,30 +19144,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 18144 | 19144 | } |
| 18145 | 19145 | |
| 18146 | 19146 | // 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 |
| 19147 | // we have to figure out the IrInstGen which represents the index and |
| 19148 | // emit a IrInstGenVectorStoreElem, or emit a compile error |
| 18149 | 19149 | // explaining why it is impossible for this store to work. Which is that |
| 18150 | 19150 | // the pointer address is of the vector; without the element index being known |
| 18151 | 19151 | // we cannot properly perform the insertion. |
| 18152 | 19152 | if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 18153 | | if (ptr->id == IrInstructionIdElemPtr) { |
| 18154 | | IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; |
| 19153 | if (ptr->id == IrInstGenIdElemPtr) { |
| 19154 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 18155 | 19155 | return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, |
| 18156 | 19156 | elem_ptr->elem_index, value); |
| 18157 | 19157 | } |
| 18158 | | ir_add_error(ira, ptr, |
| 19158 | ir_add_error(ira, &ptr->base, |
| 18159 | 19159 | buf_sprintf("unable to determine vector element index of type '%s'", |
| 18160 | 19160 | buf_ptr(&ptr->value->type->name))); |
| 18161 | | return ira->codegen->invalid_instruction; |
| 19161 | return ira->codegen->invalid_inst_gen; |
| 18162 | 19162 | } |
| 18163 | 19163 | |
| 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; |
| 19164 | return ir_build_store_ptr_gen(ira, source_instr, ptr, value); |
| 18167 | 19165 | } |
| 18168 | 19166 | |
| 18169 | | static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr, |
| 18170 | | IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry) |
| 19167 | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 19168 | IrInstGen *new_stack, bool is_async_call_builtin, ZigFn *fn_entry) |
| 18171 | 19169 | { |
| 18172 | 19170 | if (new_stack == nullptr) |
| 18173 | 19171 | return nullptr; |
| ... | ... | @@ -18196,11 +19194,11 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so |
| 18196 | 19194 | } |
| 18197 | 19195 | } |
| 18198 | 19196 | |
| 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) |
| 19197 | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19198 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19199 | IrInstGen *first_arg_ptr, CallModifier modifier, |
| 19200 | IrInstGen *new_stack, bool is_async_call_builtin, |
| 19201 | IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc) |
| 18204 | 19202 | { |
| 18205 | 19203 | Error err; |
| 18206 | 19204 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| ... | ... | @@ -18221,11 +19219,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18221 | 19219 | AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;; |
| 18222 | 19220 | |
| 18223 | 19221 | 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")); |
| 19222 | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention")); |
| 18225 | 19223 | if (fn_proto_node) { |
| 18226 | 19224 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 18227 | 19225 | } |
| 18228 | | return ira->codegen->invalid_instruction; |
| 19226 | return ira->codegen->invalid_inst_gen; |
| 18229 | 19227 | } |
| 18230 | 19228 | |
| 18231 | 19229 | if (fn_type_id->is_var_args) { |
| ... | ... | @@ -18236,7 +19234,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18236 | 19234 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 18237 | 19235 | buf_sprintf("declared here")); |
| 18238 | 19236 | } |
| 18239 | | return ira->codegen->invalid_instruction; |
| 19237 | return ira->codegen->invalid_inst_gen; |
| 18240 | 19238 | } |
| 18241 | 19239 | } else if (src_param_count != call_param_count) { |
| 18242 | 19240 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| ... | ... | @@ -18245,18 +19243,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18245 | 19243 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 18246 | 19244 | buf_sprintf("declared here")); |
| 18247 | 19245 | } |
| 18248 | | return ira->codegen->invalid_instruction; |
| 19246 | return ira->codegen->invalid_inst_gen; |
| 18249 | 19247 | } |
| 18250 | 19248 | |
| 18251 | 19249 | if (modifier == CallModifierCompileTime) { |
| 18252 | 19250 | // No special handling is needed for compile time evaluation of generic functions. |
| 18253 | 19251 | 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; |
| 19252 | ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression")); |
| 19253 | return ira->codegen->invalid_inst_gen; |
| 18256 | 19254 | } |
| 18257 | 19255 | |
| 18258 | 19256 | if (!ir_emit_backward_branch(ira, source_instr)) |
| 18259 | | return ira->codegen->invalid_instruction; |
| 19257 | return ira->codegen->invalid_inst_gen; |
| 18260 | 19258 | |
| 18261 | 19259 | // Fork a scope of the function with known values for the parameters. |
| 18262 | 19260 | Scope *exec_scope = &fn_entry->fndef_scope->base; |
| ... | ... | @@ -18269,47 +19267,47 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18269 | 19267 | if (fn_type_id->next_param_index >= 1) { |
| 18270 | 19268 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 18271 | 19269 | if (type_is_invalid(param_type)) |
| 18272 | | return ira->codegen->invalid_instruction; |
| 19270 | return ira->codegen->invalid_inst_gen; |
| 18273 | 19271 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 18274 | 19272 | } |
| 18275 | 19273 | |
| 18276 | | IrInstruction *first_arg; |
| 19274 | IrInstGen *first_arg; |
| 18277 | 19275 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 18278 | 19276 | first_arg = first_arg_ptr; |
| 18279 | 19277 | } else { |
| 18280 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19278 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18281 | 19279 | if (type_is_invalid(first_arg->value->type)) |
| 18282 | | return ira->codegen->invalid_instruction; |
| 19280 | return ira->codegen->invalid_inst_gen; |
| 18283 | 19281 | } |
| 18284 | 19282 | |
| 18285 | 19283 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i)) |
| 18286 | | return ira->codegen->invalid_instruction; |
| 19284 | return ira->codegen->invalid_inst_gen; |
| 18287 | 19285 | } |
| 18288 | 19286 | |
| 18289 | 19287 | if (fn_proto_node->data.fn_proto.is_var_args) { |
| 18290 | 19288 | ir_add_error(ira, source_instr, |
| 18291 | 19289 | 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; |
| 19290 | return ira->codegen->invalid_inst_gen; |
| 18293 | 19291 | } |
| 18294 | 19292 | |
| 18295 | 19293 | |
| 18296 | 19294 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18297 | | IrInstruction *old_arg = args_ptr[call_i]; |
| 19295 | IrInstGen *old_arg = args_ptr[call_i]; |
| 18298 | 19296 | |
| 18299 | 19297 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| 18300 | | return ira->codegen->invalid_instruction; |
| 19298 | return ira->codegen->invalid_inst_gen; |
| 18301 | 19299 | } |
| 18302 | 19300 | |
| 18303 | 19301 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 18304 | 19302 | ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node); |
| 18305 | 19303 | if (type_is_invalid(specified_return_type)) |
| 18306 | | return ira->codegen->invalid_instruction; |
| 19304 | return ira->codegen->invalid_inst_gen; |
| 18307 | 19305 | ZigType *return_type; |
| 18308 | 19306 | ZigType *inferred_err_set_type = nullptr; |
| 18309 | 19307 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 18310 | 19308 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); |
| 18311 | 19309 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 18312 | | return ira->codegen->invalid_instruction; |
| 19310 | return ira->codegen->invalid_inst_gen; |
| 18313 | 19311 | return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 18314 | 19312 | } else { |
| 18315 | 19313 | return_type = specified_return_type; |
| ... | ... | @@ -18354,24 +19352,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18354 | 19352 | } |
| 18355 | 19353 | |
| 18356 | 19354 | if (type_is_invalid(result->type)) { |
| 18357 | | return ira->codegen->invalid_instruction; |
| 19355 | return ira->codegen->invalid_inst_gen; |
| 18358 | 19356 | } |
| 18359 | 19357 | } |
| 18360 | 19358 | |
| 18361 | | IrInstruction *new_instruction = ir_const_move(ira, source_instr, result); |
| 19359 | IrInstGen *new_instruction = ir_const_move(ira, source_instr, result); |
| 18362 | 19360 | return ir_finish_anal(ira, new_instruction); |
| 18363 | 19361 | } |
| 18364 | 19362 | |
| 18365 | 19363 | if (fn_type->data.fn.is_generic) { |
| 18366 | 19364 | if (!fn_entry) { |
| 18367 | | ir_add_error(ira, fn_ref, |
| 19365 | ir_add_error(ira, &fn_ref->base, |
| 18368 | 19366 | buf_sprintf("calling a generic function requires compile-time known function value")); |
| 18369 | | return ira->codegen->invalid_instruction; |
| 19367 | return ira->codegen->invalid_inst_gen; |
| 18370 | 19368 | } |
| 18371 | 19369 | |
| 18372 | 19370 | size_t new_fn_arg_count = first_arg_1_or_0 + args_len; |
| 18373 | 19371 | |
| 18374 | | IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count); |
| 19372 | IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count); |
| 18375 | 19373 | |
| 18376 | 19374 | // Fork a scope of the function with known values for the parameters. |
| 18377 | 19375 | Scope *parent_scope = fn_entry->fndef_scope->base.parent; |
| ... | ... | @@ -18400,30 +19398,30 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18400 | 19398 | if (fn_type_id->next_param_index >= 1) { |
| 18401 | 19399 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 18402 | 19400 | if (type_is_invalid(param_type)) |
| 18403 | | return ira->codegen->invalid_instruction; |
| 19401 | return ira->codegen->invalid_inst_gen; |
| 18404 | 19402 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 18405 | 19403 | } |
| 18406 | 19404 | |
| 18407 | | IrInstruction *first_arg; |
| 19405 | IrInstGen *first_arg; |
| 18408 | 19406 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 18409 | 19407 | first_arg = first_arg_ptr; |
| 18410 | 19408 | } else { |
| 18411 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19409 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18412 | 19410 | if (type_is_invalid(first_arg->value->type)) |
| 18413 | | return ira->codegen->invalid_instruction; |
| 19411 | return ira->codegen->invalid_inst_gen; |
| 18414 | 19412 | } |
| 18415 | 19413 | |
| 18416 | 19414 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope, |
| 18417 | 19415 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 18418 | 19416 | { |
| 18419 | | return ira->codegen->invalid_instruction; |
| 19417 | return ira->codegen->invalid_inst_gen; |
| 18420 | 19418 | } |
| 18421 | 19419 | } |
| 18422 | 19420 | |
| 18423 | | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19421 | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 18424 | 19422 | assert(parent_fn_entry); |
| 18425 | 19423 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18426 | | IrInstruction *arg = args_ptr[call_i]; |
| 19424 | IrInstGen *arg = args_ptr[call_i]; |
| 18427 | 19425 | |
| 18428 | 19426 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); |
| 18429 | 19427 | assert(param_decl_node->type == NodeTypeParamDecl); |
| ... | ... | @@ -18431,7 +19429,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18431 | 19429 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, |
| 18432 | 19430 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 18433 | 19431 | { |
| 18434 | | return ira->codegen->invalid_instruction; |
| 19432 | return ira->codegen->invalid_inst_gen; |
| 18435 | 19433 | } |
| 18436 | 19434 | } |
| 18437 | 19435 | |
| ... | ... | @@ -18441,7 +19439,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18441 | 19439 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 18442 | 19440 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| 18443 | 19441 | nullptr, UndefBad); |
| 18444 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 19442 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 18445 | 19443 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 18446 | 19444 | copy_const_val(const_instruction->base.value, align_result); |
| 18447 | 19445 | |
| ... | ... | @@ -18455,11 +19453,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18455 | 19453 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 18456 | 19454 | ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); |
| 18457 | 19455 | if (type_is_invalid(specified_return_type)) |
| 18458 | | return ira->codegen->invalid_instruction; |
| 19456 | return ira->codegen->invalid_inst_gen; |
| 18459 | 19457 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 18460 | 19458 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| 18461 | 19459 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 18462 | | return ira->codegen->invalid_instruction; |
| 19460 | return ira->codegen->invalid_inst_gen; |
| 18463 | 19461 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 18464 | 19462 | } else { |
| 18465 | 19463 | inst_fn_type_id.return_type = specified_return_type; |
| ... | ... | @@ -18472,7 +19470,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18472 | 19470 | CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len, |
| 18473 | 19471 | ret_ptr, call_result_loc); |
| 18474 | 19472 | case ReqCompTimeInvalid: |
| 18475 | | return ira->codegen->invalid_instruction; |
| 19473 | return ira->codegen->invalid_inst_gen; |
| 18476 | 19474 | case ReqCompTimeNo: |
| 18477 | 19475 | break; |
| 18478 | 19476 | } |
| ... | ... | @@ -18486,7 +19484,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18486 | 19484 | // finish instantiating the function |
| 18487 | 19485 | impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id); |
| 18488 | 19486 | if (type_is_invalid(impl_fn->type_entry)) |
| 18489 | | return ira->codegen->invalid_instruction; |
| 19487 | return ira->codegen->invalid_inst_gen; |
| 18490 | 19488 | |
| 18491 | 19489 | impl_fn->ir_executable->source_node = source_instr->source_node; |
| 18492 | 19490 | impl_fn->ir_executable->parent_exec = ira->new_irb.exec; |
| ... | ... | @@ -18504,25 +19502,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18504 | 19502 | parent_fn_entry->calls_or_awaits_errorable_fn = true; |
| 18505 | 19503 | } |
| 18506 | 19504 | |
| 18507 | | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 19505 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 18508 | 19506 | is_async_call_builtin, impl_fn); |
| 18509 | 19507 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 18510 | | return ira->codegen->invalid_instruction; |
| 19508 | return ira->codegen->invalid_inst_gen; |
| 18511 | 19509 | |
| 18512 | 19510 | size_t impl_param_count = impl_fn_type_id->param_count; |
| 18513 | 19511 | if (modifier == CallModifierAsync) { |
| 18514 | | IrInstruction *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry, |
| 19512 | IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry, |
| 18515 | 19513 | nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, |
| 18516 | 19514 | call_result_loc); |
| 18517 | 19515 | return ir_finish_anal(ira, result); |
| 18518 | 19516 | } |
| 18519 | 19517 | |
| 18520 | | IrInstruction *result_loc; |
| 19518 | IrInstGen *result_loc; |
| 18521 | 19519 | if (handle_is_ptr(impl_fn_type_id->return_type)) { |
| 18522 | 19520 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18523 | 19521 | impl_fn_type_id->return_type, nullptr, true, true, false); |
| 18524 | 19522 | if (result_loc != nullptr) { |
| 18525 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 19523 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18526 | 19524 | return result_loc; |
| 18527 | 19525 | } |
| 18528 | 19526 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| ... | ... | @@ -18538,7 +19536,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18538 | 19536 | result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type, |
| 18539 | 19537 | is_async_call_builtin, args_ptr, args_len, ret_ptr); |
| 18540 | 19538 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 18541 | | return ira->codegen->invalid_instruction; |
| 19539 | return ira->codegen->invalid_inst_gen; |
| 18542 | 19540 | } else { |
| 18543 | 19541 | result_loc = nullptr; |
| 18544 | 19542 | } |
| ... | ... | @@ -18547,11 +19545,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18547 | 19545 | parent_fn_entry->inferred_async_node == nullptr && |
| 18548 | 19546 | modifier != CallModifierNoAsync) |
| 18549 | 19547 | { |
| 18550 | | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 19548 | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 18551 | 19549 | parent_fn_entry->inferred_async_fn = impl_fn; |
| 18552 | 19550 | } |
| 18553 | 19551 | |
| 18554 | | IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, |
| 19552 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, |
| 18555 | 19553 | impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack, |
| 18556 | 19554 | is_async_call_builtin, result_loc, impl_fn_type_id->return_type); |
| 18557 | 19555 | |
| ... | ... | @@ -18562,7 +19560,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18562 | 19560 | return ir_finish_anal(ira, &new_call_instruction->base); |
| 18563 | 19561 | } |
| 18564 | 19562 | |
| 18565 | | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19563 | ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry; |
| 18566 | 19564 | assert(fn_type_id->return_type != nullptr); |
| 18567 | 19565 | assert(parent_fn_entry != nullptr); |
| 18568 | 19566 | if (fn_type_can_fail(fn_type_id)) { |
| ... | ... | @@ -18570,46 +19568,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18570 | 19568 | } |
| 18571 | 19569 | |
| 18572 | 19570 | |
| 18573 | | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 19571 | IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count); |
| 18574 | 19572 | size_t next_arg_index = 0; |
| 18575 | 19573 | if (first_arg_ptr) { |
| 18576 | 19574 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 18577 | 19575 | |
| 18578 | 19576 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 18579 | 19577 | if (type_is_invalid(param_type)) |
| 18580 | | return ira->codegen->invalid_instruction; |
| 19578 | return ira->codegen->invalid_inst_gen; |
| 18581 | 19579 | |
| 18582 | | IrInstruction *first_arg; |
| 19580 | IrInstGen *first_arg; |
| 18583 | 19581 | if (param_type->id == ZigTypeIdPointer && |
| 18584 | 19582 | handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) |
| 18585 | 19583 | { |
| 18586 | 19584 | first_arg = first_arg_ptr; |
| 18587 | 19585 | } else { |
| 18588 | | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 19586 | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 18589 | 19587 | if (type_is_invalid(first_arg->value->type)) |
| 18590 | | return ira->codegen->invalid_instruction; |
| 19588 | return ira->codegen->invalid_inst_gen; |
| 18591 | 19589 | } |
| 18592 | 19590 | |
| 18593 | | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 19591 | IrInstGen *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 18594 | 19592 | if (type_is_invalid(casted_arg->value->type)) |
| 18595 | | return ira->codegen->invalid_instruction; |
| 19593 | return ira->codegen->invalid_inst_gen; |
| 18596 | 19594 | |
| 18597 | 19595 | casted_args[next_arg_index] = casted_arg; |
| 18598 | 19596 | next_arg_index += 1; |
| 18599 | 19597 | } |
| 18600 | 19598 | for (size_t call_i = 0; call_i < args_len; call_i += 1) { |
| 18601 | | IrInstruction *old_arg = args_ptr[call_i]; |
| 19599 | IrInstGen *old_arg = args_ptr[call_i]; |
| 18602 | 19600 | if (type_is_invalid(old_arg->value->type)) |
| 18603 | | return ira->codegen->invalid_instruction; |
| 19601 | return ira->codegen->invalid_inst_gen; |
| 18604 | 19602 | |
| 18605 | | IrInstruction *casted_arg; |
| 19603 | IrInstGen *casted_arg; |
| 18606 | 19604 | if (next_arg_index < src_param_count) { |
| 18607 | 19605 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 18608 | 19606 | if (type_is_invalid(param_type)) |
| 18609 | | return ira->codegen->invalid_instruction; |
| 19607 | return ira->codegen->invalid_inst_gen; |
| 18610 | 19608 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 18611 | 19609 | if (type_is_invalid(casted_arg->value->type)) |
| 18612 | | return ira->codegen->invalid_instruction; |
| 19610 | return ira->codegen->invalid_inst_gen; |
| 18613 | 19611 | } else { |
| 18614 | 19612 | casted_arg = old_arg; |
| 18615 | 19613 | } |
| ... | ... | @@ -18622,21 +19620,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18622 | 19620 | |
| 18623 | 19621 | ZigType *return_type = fn_type_id->return_type; |
| 18624 | 19622 | if (type_is_invalid(return_type)) |
| 18625 | | return ira->codegen->invalid_instruction; |
| 19623 | return ira->codegen->invalid_inst_gen; |
| 18626 | 19624 | |
| 18627 | 19625 | if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) { |
| 18628 | 19626 | ir_add_error(ira, source_instr, |
| 18629 | 19627 | buf_sprintf("no-inline call of inline function")); |
| 18630 | | return ira->codegen->invalid_instruction; |
| 19628 | return ira->codegen->invalid_inst_gen; |
| 18631 | 19629 | } |
| 18632 | 19630 | |
| 18633 | | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 19631 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 18634 | 19632 | is_async_call_builtin, fn_entry); |
| 18635 | 19633 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 18636 | | return ira->codegen->invalid_instruction; |
| 19634 | return ira->codegen->invalid_inst_gen; |
| 18637 | 19635 | |
| 18638 | 19636 | if (modifier == CallModifierAsync) { |
| 18639 | | IrInstruction *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref, |
| 19637 | IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref, |
| 18640 | 19638 | casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc); |
| 18641 | 19639 | return ir_finish_anal(ira, result); |
| 18642 | 19640 | } |
| ... | ... | @@ -18645,16 +19643,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18645 | 19643 | parent_fn_entry->inferred_async_node == nullptr && |
| 18646 | 19644 | modifier != CallModifierNoAsync) |
| 18647 | 19645 | { |
| 18648 | | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 19646 | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 18649 | 19647 | parent_fn_entry->inferred_async_fn = fn_entry; |
| 18650 | 19648 | } |
| 18651 | 19649 | |
| 18652 | | IrInstruction *result_loc; |
| 19650 | IrInstGen *result_loc; |
| 18653 | 19651 | if (handle_is_ptr(return_type)) { |
| 18654 | 19652 | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 18655 | 19653 | return_type, nullptr, true, true, false); |
| 18656 | 19654 | if (result_loc != nullptr) { |
| 18657 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 19655 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18658 | 19656 | return result_loc; |
| 18659 | 19657 | } |
| 18660 | 19658 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| ... | ... | @@ -18670,12 +19668,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18670 | 19668 | result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin, |
| 18671 | 19669 | args_ptr, args_len, ret_ptr); |
| 18672 | 19670 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 18673 | | return ira->codegen->invalid_instruction; |
| 19671 | return ira->codegen->invalid_inst_gen; |
| 18674 | 19672 | } else { |
| 18675 | 19673 | result_loc = nullptr; |
| 18676 | 19674 | } |
| 18677 | 19675 | |
| 18678 | | IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 19676 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 18679 | 19677 | call_param_count, casted_args, modifier, casted_new_stack, |
| 18680 | 19678 | is_async_call_builtin, result_loc, return_type); |
| 18681 | 19679 | if (get_scope_typeof(source_instr->scope) == nullptr) { |
| ... | ... | @@ -18684,62 +19682,62 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18684 | 19682 | return ir_finish_anal(ira, &new_call_instruction->base); |
| 18685 | 19683 | } |
| 18686 | 19684 | |
| 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) |
| 19685 | static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction, |
| 19686 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 19687 | IrInstGen *first_arg_ptr, CallModifier modifier) |
| 18690 | 19688 | { |
| 18691 | | IrInstruction *new_stack = nullptr; |
| 19689 | IrInstGen *new_stack = nullptr; |
| 18692 | 19690 | if (call_instruction->new_stack) { |
| 18693 | 19691 | new_stack = call_instruction->new_stack->child; |
| 18694 | 19692 | if (type_is_invalid(new_stack->value->type)) |
| 18695 | | return ira->codegen->invalid_instruction; |
| 19693 | return ira->codegen->invalid_inst_gen; |
| 18696 | 19694 | } |
| 18697 | | IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *"); |
| 19695 | IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *"); |
| 18698 | 19696 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 18699 | 19697 | args_ptr[i] = call_instruction->args[i]->child; |
| 18700 | 19698 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18701 | | return ira->codegen->invalid_instruction; |
| 19699 | return ira->codegen->invalid_inst_gen; |
| 18702 | 19700 | } |
| 18703 | | IrInstruction *ret_ptr = nullptr; |
| 19701 | IrInstGen *ret_ptr = nullptr; |
| 18704 | 19702 | if (call_instruction->ret_ptr != nullptr) { |
| 18705 | 19703 | ret_ptr = call_instruction->ret_ptr->child; |
| 18706 | 19704 | if (type_is_invalid(ret_ptr->value->type)) |
| 18707 | | return ira->codegen->invalid_instruction; |
| 19705 | return ira->codegen->invalid_inst_gen; |
| 18708 | 19706 | } |
| 18709 | | IrInstruction *result = ir_analyze_fn_call(ira, &call_instruction->base, fn_entry, fn_type, fn_ref, |
| 19707 | IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref, |
| 18710 | 19708 | first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin, |
| 18711 | 19709 | args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc); |
| 18712 | | deallocate(args_ptr, call_instruction->arg_count, "IrInstruction *"); |
| 19710 | deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *"); |
| 18713 | 19711 | return result; |
| 18714 | 19712 | } |
| 18715 | 19713 | |
| 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, |
| 19714 | static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19715 | IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len, |
| 18718 | 19716 | ResultLoc *result_loc) |
| 18719 | 19717 | { |
| 18720 | | IrInstruction *options = pass1_options->child; |
| 19718 | IrInstGen *options = pass1_options->child; |
| 18721 | 19719 | if (type_is_invalid(options->value->type)) |
| 18722 | | return ira->codegen->invalid_instruction; |
| 19720 | return ira->codegen->invalid_inst_gen; |
| 18723 | 19721 | |
| 18724 | | IrInstruction *fn_ref = pass1_fn_ref->child; |
| 19722 | IrInstGen *fn_ref = pass1_fn_ref->child; |
| 18725 | 19723 | if (type_is_invalid(fn_ref->value->type)) |
| 18726 | | return ira->codegen->invalid_instruction; |
| 19724 | return ira->codegen->invalid_inst_gen; |
| 18727 | 19725 | |
| 18728 | 19726 | TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier")); |
| 18729 | 19727 | ir_assert(modifier_field != nullptr, source_instr); |
| 18730 | | IrInstruction *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field); |
| 19728 | IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field); |
| 18731 | 19729 | ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad); |
| 18732 | 19730 | if (modifier_val == nullptr) |
| 18733 | | return ira->codegen->invalid_instruction; |
| 19731 | return ira->codegen->invalid_inst_gen; |
| 18734 | 19732 | CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag); |
| 18735 | 19733 | |
| 18736 | | if (ir_should_inline(ira->new_irb.exec, source_instr->scope)) { |
| 19734 | if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) { |
| 18737 | 19735 | switch (modifier) { |
| 18738 | 19736 | case CallModifierBuiltin: |
| 18739 | 19737 | zig_unreachable(); |
| 18740 | 19738 | case CallModifierAsync: |
| 18741 | 19739 | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier")); |
| 18742 | | return ira->codegen->invalid_instruction; |
| 19740 | return ira->codegen->invalid_inst_gen; |
| 18743 | 19741 | case CallModifierCompileTime: |
| 18744 | 19742 | case CallModifierNone: |
| 18745 | 19743 | case CallModifierAlwaysInline: |
| ... | ... | @@ -18750,15 +19748,15 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18750 | 19748 | case CallModifierNeverInline: |
| 18751 | 19749 | ir_add_error(ira, source_instr, |
| 18752 | 19750 | buf_sprintf("unable to perform 'never_inline' call at compile-time")); |
| 18753 | | return ira->codegen->invalid_instruction; |
| 19751 | return ira->codegen->invalid_inst_gen; |
| 18754 | 19752 | case CallModifierNeverTail: |
| 18755 | 19753 | ir_add_error(ira, source_instr, |
| 18756 | 19754 | buf_sprintf("unable to perform 'never_tail' call at compile-time")); |
| 18757 | | return ira->codegen->invalid_instruction; |
| 19755 | return ira->codegen->invalid_inst_gen; |
| 18758 | 19756 | } |
| 18759 | 19757 | } |
| 18760 | 19758 | |
| 18761 | | IrInstruction *first_arg_ptr = nullptr; |
| 19759 | IrInstGen *first_arg_ptr = nullptr; |
| 18762 | 19760 | ZigFn *fn = nullptr; |
| 18763 | 19761 | if (instr_is_comptime(fn_ref)) { |
| 18764 | 19762 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| ... | ... | @@ -18766,7 +19764,7 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18766 | 19764 | fn = fn_ref->value->data.x_bound_fn.fn; |
| 18767 | 19765 | first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 18768 | 19766 | if (type_is_invalid(first_arg_ptr->value->type)) |
| 18769 | | return ira->codegen->invalid_instruction; |
| 19767 | return ira->codegen->invalid_inst_gen; |
| 18770 | 19768 | } else { |
| 18771 | 19769 | fn = ir_resolve_fn(ira, fn_ref); |
| 18772 | 19770 | } |
| ... | ... | @@ -18778,9 +19776,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18778 | 19776 | case CallModifierAlwaysInline: |
| 18779 | 19777 | case CallModifierAsync: |
| 18780 | 19778 | if (fn == nullptr) { |
| 18781 | | ir_add_error(ira, modifier_inst, |
| 19779 | ir_add_error(ira, &modifier_inst->base, |
| 18782 | 19780 | buf_sprintf("the specified modifier requires a comptime-known function")); |
| 18783 | | return ira->codegen->invalid_instruction; |
| 19781 | return ira->codegen->invalid_inst_gen; |
| 18784 | 19782 | } |
| 18785 | 19783 | default: |
| 18786 | 19784 | break; |
| ... | ... | @@ -18790,93 +19788,93 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc |
| 18790 | 19788 | |
| 18791 | 19789 | TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack")); |
| 18792 | 19790 | ir_assert(stack_field != nullptr, source_instr); |
| 18793 | | IrInstruction *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field); |
| 19791 | IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field); |
| 18794 | 19792 | if (type_is_invalid(opt_stack->value->type)) |
| 18795 | | return ira->codegen->invalid_instruction; |
| 19793 | return ira->codegen->invalid_inst_gen; |
| 18796 | 19794 | |
| 18797 | | IrInstruction *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack); |
| 19795 | IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack); |
| 18798 | 19796 | bool stack_is_non_null; |
| 18799 | 19797 | if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null)) |
| 18800 | | return ira->codegen->invalid_instruction; |
| 19798 | return ira->codegen->invalid_inst_gen; |
| 18801 | 19799 | |
| 18802 | | IrInstruction *stack = nullptr; |
| 19800 | IrInstGen *stack = nullptr; |
| 18803 | 19801 | if (stack_is_non_null) { |
| 18804 | 19802 | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); |
| 18805 | 19803 | if (type_is_invalid(stack->value->type)) |
| 18806 | | return ira->codegen->invalid_instruction; |
| 19804 | return ira->codegen->invalid_inst_gen; |
| 18807 | 19805 | } |
| 18808 | 19806 | |
| 18809 | 19807 | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, |
| 18810 | 19808 | modifier, stack, false, args_ptr, args_len, nullptr, result_loc); |
| 18811 | 19809 | } |
| 18812 | 19810 | |
| 18813 | | static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) { |
| 18814 | | IrInstruction *args = instruction->args->child; |
| 19811 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { |
| 19812 | IrInstGen *args = instruction->args->child; |
| 18815 | 19813 | ZigType *args_type = args->value->type; |
| 18816 | 19814 | if (type_is_invalid(args_type)) |
| 18817 | | return ira->codegen->invalid_instruction; |
| 19815 | return ira->codegen->invalid_inst_gen; |
| 18818 | 19816 | |
| 18819 | 19817 | if (args_type->id != ZigTypeIdStruct) { |
| 18820 | | ir_add_error(ira, args, |
| 19818 | ir_add_error(ira, &args->base, |
| 18821 | 19819 | buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name))); |
| 18822 | | return ira->codegen->invalid_instruction; |
| 19820 | return ira->codegen->invalid_inst_gen; |
| 18823 | 19821 | } |
| 18824 | 19822 | |
| 18825 | | IrInstruction **args_ptr = nullptr; |
| 19823 | IrInstGen **args_ptr = nullptr; |
| 18826 | 19824 | size_t args_len = 0; |
| 18827 | 19825 | |
| 18828 | 19826 | if (is_tuple(args_type)) { |
| 18829 | 19827 | args_len = args_type->data.structure.src_field_count; |
| 18830 | | args_ptr = allocate<IrInstruction *>(args_len, "IrInstruction *"); |
| 19828 | args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *"); |
| 18831 | 19829 | for (size_t i = 0; i < args_len; i += 1) { |
| 18832 | 19830 | 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); |
| 19831 | args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field); |
| 18834 | 19832 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18835 | | return ira->codegen->invalid_instruction; |
| 19833 | return ira->codegen->invalid_inst_gen; |
| 18836 | 19834 | } |
| 18837 | 19835 | } else { |
| 18838 | | ir_add_error(ira, args, buf_sprintf("TODO: struct args")); |
| 18839 | | return ira->codegen->invalid_instruction; |
| 19836 | ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args")); |
| 19837 | return ira->codegen->invalid_inst_gen; |
| 18840 | 19838 | } |
| 18841 | | IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options, |
| 19839 | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 18842 | 19840 | instruction->fn_ref, args_ptr, args_len, instruction->result_loc); |
| 18843 | | deallocate(args_ptr, args_len, "IrInstruction *"); |
| 19841 | deallocate(args_ptr, args_len, "IrInstGen *"); |
| 18844 | 19842 | return result; |
| 18845 | 19843 | } |
| 18846 | 19844 | |
| 18847 | | static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) { |
| 18848 | | IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *"); |
| 19845 | static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) { |
| 19846 | IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *"); |
| 18849 | 19847 | for (size_t i = 0; i < instruction->args_len; i += 1) { |
| 18850 | 19848 | args_ptr[i] = instruction->args_ptr[i]->child; |
| 18851 | 19849 | if (type_is_invalid(args_ptr[i]->value->type)) |
| 18852 | | return ira->codegen->invalid_instruction; |
| 19850 | return ira->codegen->invalid_inst_gen; |
| 18853 | 19851 | } |
| 18854 | 19852 | |
| 18855 | | IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options, |
| 19853 | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 18856 | 19854 | instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc); |
| 18857 | | deallocate(args_ptr, instruction->args_len, "IrInstruction *"); |
| 19855 | deallocate(args_ptr, instruction->args_len, "IrInstGen *"); |
| 18858 | 19856 | return result; |
| 18859 | 19857 | } |
| 18860 | 19858 | |
| 18861 | | static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) { |
| 18862 | | IrInstruction *fn_ref = call_instruction->fn_ref->child; |
| 19859 | static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) { |
| 19860 | IrInstGen *fn_ref = call_instruction->fn_ref->child; |
| 18863 | 19861 | if (type_is_invalid(fn_ref->value->type)) |
| 18864 | | return ira->codegen->invalid_instruction; |
| 19862 | return ira->codegen->invalid_inst_gen; |
| 18865 | 19863 | |
| 18866 | 19864 | bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) || |
| 18867 | | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 19865 | ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope); |
| 18868 | 19866 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 18869 | 19867 | |
| 18870 | 19868 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 18871 | 19869 | if (fn_ref->value->type->id == ZigTypeIdMetaType) { |
| 18872 | 19870 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 18873 | 19871 | if (ty == nullptr) |
| 18874 | | return ira->codegen->invalid_instruction; |
| 18875 | | ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node, |
| 19872 | return ira->codegen->invalid_inst_gen; |
| 19873 | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, |
| 18876 | 19874 | buf_sprintf("type '%s' not a function", buf_ptr(&ty->name))); |
| 18877 | | add_error_note(ira->codegen, msg, call_instruction->base.source_node, |
| 19875 | add_error_note(ira->codegen, msg, call_instruction->base.base.source_node, |
| 18878 | 19876 | buf_sprintf("use @as builtin for type coercion")); |
| 18879 | | return ira->codegen->invalid_instruction; |
| 19877 | return ira->codegen->invalid_inst_gen; |
| 18880 | 19878 | } else if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 18881 | 19879 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 18882 | 19880 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type; |
| ... | ... | @@ -18886,14 +19884,14 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 18886 | 19884 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 18887 | 19885 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 18888 | 19886 | 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; |
| 19887 | IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 18890 | 19888 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 18891 | 19889 | return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 18892 | 19890 | fn_ref, first_arg_ptr, modifier); |
| 18893 | 19891 | } else { |
| 18894 | | ir_add_error_node(ira, fn_ref->source_node, |
| 19892 | ir_add_error(ira, &fn_ref->base, |
| 18895 | 19893 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 18896 | | return ira->codegen->invalid_instruction; |
| 19894 | return ira->codegen->invalid_inst_gen; |
| 18897 | 19895 | } |
| 18898 | 19896 | } |
| 18899 | 19897 | |
| ... | ... | @@ -18901,9 +19899,9 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 18901 | 19899 | return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type, |
| 18902 | 19900 | fn_ref, nullptr, modifier); |
| 18903 | 19901 | } else { |
| 18904 | | ir_add_error_node(ira, fn_ref->source_node, |
| 19902 | ir_add_error(ira, &fn_ref->base, |
| 18905 | 19903 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 18906 | | return ira->codegen->invalid_instruction; |
| 19904 | return ira->codegen->invalid_inst_gen; |
| 18907 | 19905 | } |
| 18908 | 19906 | } |
| 18909 | 19907 | |
| ... | ... | @@ -18992,8 +19990,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 18992 | 19990 | zig_unreachable(); |
| 18993 | 19991 | } |
| 18994 | 19992 | |
| 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); |
| 19993 | static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 19994 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 18997 | 19995 | result->value->special = ConstValSpecialLazy; |
| 18998 | 19996 | |
| 18999 | 19997 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType"); |
| ... | ... | @@ -19003,12 +20001,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp |
| 19003 | 20001 | |
| 19004 | 20002 | lazy_opt_type->payload_type = instruction->value->child; |
| 19005 | 20003 | if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr) |
| 19006 | | return ira->codegen->invalid_instruction; |
| 20004 | return ira->codegen->invalid_inst_gen; |
| 19007 | 20005 | |
| 19008 | 20006 | return result; |
| 19009 | 20007 | } |
| 19010 | 20008 | |
| 19011 | | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type, |
| 20009 | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type, |
| 19012 | 20010 | ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op) |
| 19013 | 20011 | { |
| 19014 | 20012 | bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat); |
| ... | ... | @@ -19043,19 +20041,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i |
| 19043 | 20041 | return nullptr; |
| 19044 | 20042 | } |
| 19045 | 20043 | |
| 19046 | | static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 19047 | | IrInstruction *value = instruction->value->child; |
| 20044 | static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 20045 | IrInstGen *value = instruction->value->child; |
| 19048 | 20046 | ZigType *expr_type = value->value->type; |
| 19049 | 20047 | if (type_is_invalid(expr_type)) |
| 19050 | | return ira->codegen->invalid_instruction; |
| 20048 | return ira->codegen->invalid_inst_gen; |
| 19051 | 20049 | |
| 19052 | 20050 | if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt || |
| 19053 | 20051 | expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat || |
| 19054 | 20052 | expr_type->id == ZigTypeIdVector)) |
| 19055 | 20053 | { |
| 19056 | | ir_add_error(ira, &instruction->base, |
| 20054 | ir_add_error(ira, &instruction->base.base, |
| 19057 | 20055 | buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name))); |
| 19058 | | return ira->codegen->invalid_instruction; |
| 20056 | return ira->codegen->invalid_inst_gen; |
| 19059 | 20057 | } |
| 19060 | 20058 | |
| 19061 | 20059 | bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap); |
| ... | ... | @@ -19065,9 +20063,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 19065 | 20063 | if (instr_is_comptime(value)) { |
| 19066 | 20064 | ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad); |
| 19067 | 20065 | if (!operand_val) |
| 19068 | | return ira->codegen->invalid_instruction; |
| 20066 | return ira->codegen->invalid_inst_gen; |
| 19069 | 20067 | |
| 19070 | | IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type); |
| 20068 | IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type); |
| 19071 | 20069 | ZigValue *out_val = result_instruction->value; |
| 19072 | 20070 | if (expr_type->id == ZigTypeIdVector) { |
| 19073 | 20071 | expand_undef_array(ira->codegen, operand_val); |
| ... | ... | @@ -19079,63 +20077,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 19079 | 20077 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 19080 | 20078 | assert(scalar_operand_val->type == scalar_type); |
| 19081 | 20079 | assert(scalar_out_val->type == scalar_type); |
| 19082 | | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type, |
| 20080 | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, |
| 19083 | 20081 | scalar_operand_val, scalar_out_val, is_wrap_op); |
| 19084 | 20082 | if (msg != nullptr) { |
| 19085 | | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 20083 | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 19086 | 20084 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 19087 | | return ira->codegen->invalid_instruction; |
| 20085 | return ira->codegen->invalid_inst_gen; |
| 19088 | 20086 | } |
| 19089 | 20087 | } |
| 19090 | 20088 | out_val->type = expr_type; |
| 19091 | 20089 | out_val->special = ConstValSpecialStatic; |
| 19092 | 20090 | } else { |
| 19093 | | if (ir_eval_negation_scalar(ira, &instruction->base, scalar_type, operand_val, out_val, |
| 20091 | if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val, |
| 19094 | 20092 | is_wrap_op) != nullptr) |
| 19095 | 20093 | { |
| 19096 | | return ira->codegen->invalid_instruction; |
| 20094 | return ira->codegen->invalid_inst_gen; |
| 19097 | 20095 | } |
| 19098 | 20096 | } |
| 19099 | 20097 | return result_instruction; |
| 19100 | 20098 | } |
| 19101 | 20099 | |
| 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; |
| 20100 | if (is_wrap_op) { |
| 20101 | return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type); |
| 20102 | } else { |
| 20103 | return ir_build_negation(ira, &instruction->base.base, value, expr_type); |
| 20104 | } |
| 19107 | 20105 | } |
| 19108 | 20106 | |
| 19109 | | static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 19110 | | IrInstruction *value = instruction->value->child; |
| 20107 | static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 20108 | IrInstGen *value = instruction->value->child; |
| 19111 | 20109 | ZigType *expr_type = value->value->type; |
| 19112 | 20110 | if (type_is_invalid(expr_type)) |
| 19113 | | return ira->codegen->invalid_instruction; |
| 20111 | return ira->codegen->invalid_inst_gen; |
| 19114 | 20112 | |
| 19115 | 20113 | if (expr_type->id == ZigTypeIdInt) { |
| 19116 | 20114 | if (instr_is_comptime(value)) { |
| 19117 | 20115 | ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 19118 | 20116 | if (target_const_val == nullptr) |
| 19119 | | return ira->codegen->invalid_instruction; |
| 20117 | return ira->codegen->invalid_inst_gen; |
| 19120 | 20118 | |
| 19121 | | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 20119 | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 19122 | 20120 | bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint, |
| 19123 | 20121 | expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); |
| 19124 | 20122 | return result; |
| 19125 | 20123 | } |
| 19126 | 20124 | |
| 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; |
| 20125 | return ir_build_binary_not(ira, &instruction->base.base, value, expr_type); |
| 19131 | 20126 | } |
| 19132 | 20127 | |
| 19133 | | ir_add_error(ira, &instruction->base, |
| 20128 | ir_add_error(ira, &instruction->base.base, |
| 19134 | 20129 | buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); |
| 19135 | | return ira->codegen->invalid_instruction; |
| 20130 | return ira->codegen->invalid_inst_gen; |
| 19136 | 20131 | } |
| 19137 | 20132 | |
| 19138 | | static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 20133 | static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 19139 | 20134 | IrUnOp op_id = instruction->op_id; |
| 19140 | 20135 | switch (op_id) { |
| 19141 | 20136 | case IrUnOpInvalid: |
| ... | ... | @@ -19146,26 +20141,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 19146 | 20141 | case IrUnOpNegationWrap: |
| 19147 | 20142 | return ir_analyze_negation(ira, instruction); |
| 19148 | 20143 | case IrUnOpDereference: { |
| 19149 | | IrInstruction *ptr = instruction->value->child; |
| 20144 | IrInstGen *ptr = instruction->value->child; |
| 19150 | 20145 | if (type_is_invalid(ptr->value->type)) |
| 19151 | | return ira->codegen->invalid_instruction; |
| 20146 | return ira->codegen->invalid_inst_gen; |
| 19152 | 20147 | ZigType *ptr_type = ptr->value->type; |
| 19153 | 20148 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 19154 | | ir_add_error_node(ira, instruction->base.source_node, |
| 20149 | ir_add_error_node(ira, instruction->base.base.source_node, |
| 19155 | 20150 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| 19156 | 20151 | buf_ptr(&ptr_type->name))); |
| 19157 | | return ira->codegen->invalid_instruction; |
| 20152 | return ira->codegen->invalid_inst_gen; |
| 19158 | 20153 | } |
| 19159 | 20154 | |
| 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; |
| 20155 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc); |
| 20156 | if (type_is_invalid(result->value->type)) |
| 20157 | return ira->codegen->invalid_inst_gen; |
| 19163 | 20158 | |
| 19164 | 20159 | // If the result needs to be an lvalue, type check it |
| 19165 | 20160 | if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) { |
| 19166 | | ir_add_error(ira, &instruction->base, |
| 20161 | ir_add_error(ira, &instruction->base.base, |
| 19167 | 20162 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); |
| 19168 | | return ira->codegen->invalid_instruction; |
| 20163 | return ira->codegen->invalid_inst_gen; |
| 19169 | 20164 | } |
| 19170 | 20165 | |
| 19171 | 20166 | return result; |
| ... | ... | @@ -19177,42 +20172,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 19177 | 20172 | } |
| 19178 | 20173 | |
| 19179 | 20174 | 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); |
| 20175 | IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index); |
| 19181 | 20176 | if (old_bb->in_resume_stack) return; |
| 19182 | 20177 | ira->resume_stack.append(pos); |
| 19183 | 20178 | old_bb->in_resume_stack = true; |
| 19184 | 20179 | } |
| 19185 | 20180 | |
| 19186 | | static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) { |
| 20181 | static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) { |
| 19187 | 20182 | if (ira->resume_stack.length != 0) { |
| 19188 | 20183 | ir_push_resume(ira, {old_bb->index, 0}); |
| 19189 | 20184 | } |
| 19190 | 20185 | } |
| 19191 | 20186 | |
| 19192 | | static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { |
| 19193 | | IrBasicBlock *old_dest_block = br_instruction->dest_block; |
| 20187 | static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) { |
| 20188 | IrBasicBlockSrc *old_dest_block = br_instruction->dest_block; |
| 19194 | 20189 | |
| 19195 | 20190 | bool is_comptime; |
| 19196 | 20191 | if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime)) |
| 19197 | 20192 | return ir_unreach_error(ira); |
| 19198 | 20193 | |
| 19199 | 20194 | 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); |
| 20195 | return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block); |
| 19201 | 20196 | |
| 19202 | | IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 20197 | IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base); |
| 19203 | 20198 | if (new_bb == nullptr) |
| 19204 | 20199 | return ir_unreach_error(ira); |
| 19205 | 20200 | |
| 19206 | 20201 | ir_push_resume_block(ira, old_dest_block); |
| 19207 | 20202 | |
| 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; |
| 20203 | IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb); |
| 19211 | 20204 | return ir_finish_anal(ira, result); |
| 19212 | 20205 | } |
| 19213 | 20206 | |
| 19214 | | static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 19215 | | IrInstruction *condition = cond_br_instruction->condition->child; |
| 20207 | static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) { |
| 20208 | IrInstGen *condition = cond_br_instruction->condition->child; |
| 19216 | 20209 | if (type_is_invalid(condition->value->type)) |
| 19217 | 20210 | return ir_unreach_error(ira); |
| 19218 | 20211 | |
| ... | ... | @@ -19221,7 +20214,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 19221 | 20214 | return ir_unreach_error(ira); |
| 19222 | 20215 | |
| 19223 | 20216 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 19224 | | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 20217 | IrInstGen *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 19225 | 20218 | if (type_is_invalid(casted_condition->value->type)) |
| 19226 | 20219 | return ir_unreach_error(ira); |
| 19227 | 20220 | |
| ... | ... | @@ -19230,67 +20223,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 19230 | 20223 | if (!ir_resolve_bool(ira, casted_condition, &cond_is_true)) |
| 19231 | 20224 | return ir_unreach_error(ira); |
| 19232 | 20225 | |
| 19233 | | IrBasicBlock *old_dest_block = cond_is_true ? |
| 20226 | IrBasicBlockSrc *old_dest_block = cond_is_true ? |
| 19234 | 20227 | cond_br_instruction->then_block : cond_br_instruction->else_block; |
| 19235 | 20228 | |
| 19236 | 20229 | 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); |
| 20230 | return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block); |
| 19238 | 20231 | |
| 19239 | | IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base); |
| 20232 | IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base); |
| 19240 | 20233 | if (new_dest_block == nullptr) |
| 19241 | 20234 | return ir_unreach_error(ira); |
| 19242 | 20235 | |
| 19243 | 20236 | ir_push_resume_block(ira, old_dest_block); |
| 19244 | 20237 | |
| 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; |
| 20238 | IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block); |
| 19248 | 20239 | return ir_finish_anal(ira, result); |
| 19249 | 20240 | } |
| 19250 | 20241 | |
| 19251 | 20242 | 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); |
| 20243 | IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base); |
| 19253 | 20244 | if (new_then_block == nullptr) |
| 19254 | 20245 | return ir_unreach_error(ira); |
| 19255 | 20246 | |
| 19256 | | IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| 20247 | IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base); |
| 19257 | 20248 | if (new_else_block == nullptr) |
| 19258 | 20249 | return ir_unreach_error(ira); |
| 19259 | 20250 | |
| 19260 | 20251 | ir_push_resume_block(ira, cond_br_instruction->else_block); |
| 19261 | 20252 | ir_push_resume_block(ira, cond_br_instruction->then_block); |
| 19262 | 20253 | |
| 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; |
| 20254 | IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base, |
| 20255 | casted_condition, new_then_block, new_else_block); |
| 19267 | 20256 | return ir_finish_anal(ira, result); |
| 19268 | 20257 | } |
| 19269 | 20258 | |
| 19270 | | static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 19271 | | IrInstructionUnreachable *unreachable_instruction) |
| 20259 | static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 20260 | IrInstSrcUnreachable *unreachable_instruction) |
| 19272 | 20261 | { |
| 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; |
| 20262 | IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base); |
| 19276 | 20263 | return ir_finish_anal(ira, result); |
| 19277 | 20264 | } |
| 19278 | 20265 | |
| 19279 | | static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { |
| 20266 | static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) { |
| 19280 | 20267 | Error err; |
| 19281 | 20268 | |
| 19282 | 20269 | if (ira->const_predecessor_bb) { |
| 19283 | 20270 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 19284 | | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| 20271 | IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i]; |
| 19285 | 20272 | if (predecessor != ira->const_predecessor_bb) |
| 19286 | 20273 | continue; |
| 19287 | | IrInstruction *value = phi_instruction->incoming_values[i]->child; |
| 20274 | IrInstGen *value = phi_instruction->incoming_values[i]->child; |
| 19288 | 20275 | assert(value->value->type); |
| 19289 | 20276 | if (type_is_invalid(value->value->type)) |
| 19290 | | return ira->codegen->invalid_instruction; |
| 20277 | return ira->codegen->invalid_inst_gen; |
| 19291 | 20278 | |
| 19292 | 20279 | if (value->value->special != ConstValSpecialRuntime) { |
| 19293 | | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 20280 | IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr); |
| 19294 | 20281 | copy_const_val(result->value, value->value); |
| 19295 | 20282 | return result; |
| 19296 | 20283 | } else { |
| ... | ... | @@ -19305,17 +20292,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19305 | 20292 | peer_parent->peers.length >= 2) |
| 19306 | 20293 | { |
| 19307 | 20294 | if (peer_parent->resolved_type == nullptr) { |
| 19308 | | IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length); |
| 20295 | IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length); |
| 19309 | 20296 | for (size_t i = 0; i < peer_parent->peers.length; i += 1) { |
| 19310 | 20297 | ResultLocPeer *this_peer = peer_parent->peers.at(i); |
| 19311 | 20298 | |
| 19312 | | IrInstruction *gen_instruction = this_peer->base.gen_instruction; |
| 20299 | IrInstGen *gen_instruction = this_peer->base.gen_instruction; |
| 19313 | 20300 | if (gen_instruction == nullptr) { |
| 19314 | 20301 | // unreachable instructions will cause implicit_elem_type to be null |
| 19315 | 20302 | if (this_peer->base.implicit_elem_type == nullptr) { |
| 19316 | | instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction); |
| 20303 | instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base); |
| 19317 | 20304 | } else { |
| 19318 | | instructions[i] = ir_const(ira, this_peer->base.source_instruction, |
| 20305 | instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base, |
| 19319 | 20306 | this_peer->base.implicit_elem_type); |
| 19320 | 20307 | instructions[i]->value->special = ConstValSpecialRuntime; |
| 19321 | 20308 | } |
| ... | ... | @@ -19324,34 +20311,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19324 | 20311 | } |
| 19325 | 20312 | |
| 19326 | 20313 | } |
| 19327 | | ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base, peer_parent->parent); |
| 20314 | ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent); |
| 19328 | 20315 | peer_parent->resolved_type = ir_resolve_peer_types(ira, |
| 19329 | | peer_parent->base.source_instruction->source_node, expected_type, instructions, |
| 20316 | peer_parent->base.source_instruction->base.source_node, expected_type, instructions, |
| 19330 | 20317 | peer_parent->peers.length); |
| 19331 | 20318 | if (type_is_invalid(peer_parent->resolved_type)) |
| 19332 | | return ira->codegen->invalid_instruction; |
| 20319 | return ira->codegen->invalid_inst_gen; |
| 19333 | 20320 | |
| 19334 | 20321 | // 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); |
| 20322 | ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base); |
| 19336 | 20323 | |
| 19337 | 20324 | // 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, |
| 20325 | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent, |
| 19339 | 20326 | peer_parent->resolved_type, nullptr, false, false, true); |
| 19340 | 20327 | if (parent_result_loc != nullptr && |
| 19341 | | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) |
| 20328 | (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 19342 | 20329 | { |
| 19343 | 20330 | return parent_result_loc; |
| 19344 | 20331 | } |
| 19345 | 20332 | // If the above code generated any instructions in the current basic block, we need |
| 19346 | 20333 | // to move them to the peer parent predecessor. |
| 19347 | | ZigList<IrInstruction *> instrs_to_move = {}; |
| 20334 | ZigList<IrInstGen *> instrs_to_move = {}; |
| 19348 | 20335 | while (ira->new_irb.current_basic_block->instruction_list.length != 0) { |
| 19349 | 20336 | instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop()); |
| 19350 | 20337 | } |
| 19351 | 20338 | 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); |
| 20339 | IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 20340 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 20341 | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base); |
| 19355 | 20342 | while (instrs_to_move.length != 0) { |
| 19356 | 20343 | predecessor->instruction_list.append(instrs_to_move.pop()); |
| 19357 | 20344 | } |
| ... | ... | @@ -19360,7 +20347,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19360 | 20347 | } |
| 19361 | 20348 | |
| 19362 | 20349 | IrSuspendPosition suspend_pos; |
| 19363 | | ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos); |
| 20350 | ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos); |
| 19364 | 20351 | ir_push_resume(ira, suspend_pos); |
| 19365 | 20352 | |
| 19366 | 20353 | for (size_t i = 0; i < peer_parent->peers.length; i += 1) { |
| ... | ... | @@ -19376,34 +20363,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19376 | 20363 | return ira_resume(ira); |
| 19377 | 20364 | } |
| 19378 | 20365 | |
| 19379 | | ZigList<IrBasicBlock*> new_incoming_blocks = {0}; |
| 19380 | | ZigList<IrInstruction*> new_incoming_values = {0}; |
| 20366 | ZigList<IrBasicBlockGen*> new_incoming_blocks = {0}; |
| 20367 | ZigList<IrInstGen*> new_incoming_values = {0}; |
| 19381 | 20368 | |
| 19382 | 20369 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 19383 | | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| 20370 | IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i]; |
| 19384 | 20371 | if (predecessor->ref_count == 0) |
| 19385 | 20372 | continue; |
| 19386 | 20373 | |
| 19387 | 20374 | |
| 19388 | | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 20375 | IrInstSrc *old_value = phi_instruction->incoming_values[i]; |
| 19389 | 20376 | assert(old_value); |
| 19390 | | IrInstruction *new_value = old_value->child; |
| 19391 | | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 20377 | IrInstGen *new_value = old_value->child; |
| 20378 | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr) |
| 19392 | 20379 | continue; |
| 19393 | 20380 | |
| 19394 | 20381 | if (type_is_invalid(new_value->value->type)) |
| 19395 | | return ira->codegen->invalid_instruction; |
| 20382 | return ira->codegen->invalid_inst_gen; |
| 19396 | 20383 | |
| 19397 | 20384 | |
| 19398 | | assert(predecessor->other); |
| 19399 | | new_incoming_blocks.append(predecessor->other); |
| 20385 | assert(predecessor->child); |
| 20386 | new_incoming_blocks.append(predecessor->child); |
| 19400 | 20387 | new_incoming_values.append(new_value); |
| 19401 | 20388 | } |
| 19402 | 20389 | |
| 19403 | 20390 | 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; |
| 20391 | IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base); |
| 19407 | 20392 | return ir_finish_anal(ira, result); |
| 19408 | 20393 | } |
| 19409 | 20394 | |
| ... | ... | @@ -19415,7 +20400,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19415 | 20400 | if (peer_parent != nullptr) { |
| 19416 | 20401 | bool peer_parent_has_type; |
| 19417 | 20402 | if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type))) |
| 19418 | | return ira->codegen->invalid_instruction; |
| 20403 | return ira->codegen->invalid_inst_gen; |
| 19419 | 20404 | if (peer_parent_has_type) { |
| 19420 | 20405 | if (peer_parent->parent->id == ResultLocIdReturn) { |
| 19421 | 20406 | resolved_type = ira->explicit_return_type; |
| ... | ... | @@ -19423,27 +20408,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19423 | 20408 | resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child); |
| 19424 | 20409 | } else if (peer_parent->parent->resolved_loc) { |
| 19425 | 20410 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; |
| 19426 | | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); |
| 20411 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base); |
| 19427 | 20412 | resolved_type = resolved_loc_ptr_type->data.pointer.child_type; |
| 19428 | 20413 | } |
| 19429 | 20414 | |
| 19430 | 20415 | if (resolved_type != nullptr && type_is_invalid(resolved_type)) |
| 19431 | | return ira->codegen->invalid_instruction; |
| 20416 | return ira->codegen->invalid_inst_gen; |
| 19432 | 20417 | } |
| 19433 | 20418 | } |
| 19434 | 20419 | |
| 19435 | 20420 | if (resolved_type == nullptr) { |
| 19436 | | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 20421 | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr, |
| 19437 | 20422 | new_incoming_values.items, new_incoming_values.length); |
| 19438 | 20423 | if (type_is_invalid(resolved_type)) |
| 19439 | | return ira->codegen->invalid_instruction; |
| 20424 | return ira->codegen->invalid_inst_gen; |
| 19440 | 20425 | } |
| 19441 | 20426 | |
| 19442 | 20427 | switch (type_has_one_possible_value(ira->codegen, resolved_type)) { |
| 19443 | 20428 | case OnePossibleValueInvalid: |
| 19444 | | return ira->codegen->invalid_instruction; |
| 20429 | return ira->codegen->invalid_inst_gen; |
| 19445 | 20430 | case OnePossibleValueYes: |
| 19446 | | return ir_const_move(ira, &phi_instruction->base, |
| 20431 | return ir_const_move(ira, &phi_instruction->base.base, |
| 19447 | 20432 | get_the_one_possible_value(ira->codegen, resolved_type)); |
| 19448 | 20433 | case OnePossibleValueNo: |
| 19449 | 20434 | break; |
| ... | ... | @@ -19451,11 +20436,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19451 | 20436 | |
| 19452 | 20437 | switch (type_requires_comptime(ira->codegen, resolved_type)) { |
| 19453 | 20438 | case ReqCompTimeInvalid: |
| 19454 | | return ira->codegen->invalid_instruction; |
| 20439 | return ira->codegen->invalid_inst_gen; |
| 19455 | 20440 | case ReqCompTimeYes: |
| 19456 | | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 20441 | ir_add_error(ira, &phi_instruction->base.base, |
| 19457 | 20442 | buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name))); |
| 19458 | | return ira->codegen->invalid_instruction; |
| 20443 | return ira->codegen->invalid_inst_gen; |
| 19459 | 20444 | case ReqCompTimeNo: |
| 19460 | 20445 | break; |
| 19461 | 20446 | } |
| ... | ... | @@ -19465,16 +20450,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19465 | 20450 | // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. |
| 19466 | 20451 | // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and |
| 19467 | 20452 | // then make sure the branch instruction is preserved. |
| 19468 | | IrBasicBlock *cur_bb = ira->new_irb.current_basic_block; |
| 20453 | IrBasicBlockGen *cur_bb = ira->new_irb.current_basic_block; |
| 19469 | 20454 | 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); |
| 20455 | IrInstGen *new_value = new_incoming_values.at(i); |
| 20456 | IrBasicBlockGen *predecessor = new_incoming_blocks.at(i); |
| 20457 | ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base); |
| 20458 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 20459 | ir_set_cursor_at_end_gen(&ira->new_irb, predecessor); |
| 20460 | IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 19476 | 20461 | if (type_is_invalid(casted_value->value->type)) { |
| 19477 | | return ira->codegen->invalid_instruction; |
| 20462 | return ira->codegen->invalid_inst_gen; |
| 19478 | 20463 | } |
| 19479 | 20464 | new_incoming_values.items[i] = casted_value; |
| 19480 | 20465 | predecessor->instruction_list.append(branch_instruction); |
| ... | ... | @@ -19485,12 +20470,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19485 | 20470 | all_stack_ptrs = false; |
| 19486 | 20471 | } |
| 19487 | 20472 | } |
| 19488 | | ir_set_cursor_at_end(&ira->new_irb, cur_bb); |
| 20473 | ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb); |
| 19489 | 20474 | |
| 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; |
| 20475 | IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base, |
| 20476 | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type); |
| 19494 | 20477 | |
| 19495 | 20478 | if (all_stack_ptrs) { |
| 19496 | 20479 | assert(result->value->special == ConstValSpecialRuntime); |
| ... | ... | @@ -19500,17 +20483,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 19500 | 20483 | return result; |
| 19501 | 20484 | } |
| 19502 | 20485 | |
| 19503 | | static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 20486 | static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) { |
| 19504 | 20487 | ZigVar *var = instruction->var; |
| 19505 | | IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var); |
| 20488 | IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var); |
| 19506 | 20489 | if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) { |
| 19507 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 20490 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 19508 | 20491 | buf_sprintf("'%s' not accessible from inner function", var->name)); |
| 19509 | 20492 | add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node, |
| 19510 | 20493 | buf_sprintf("crossed function definition here")); |
| 19511 | 20494 | add_error_note(ira->codegen, msg, var->decl_node, |
| 19512 | 20495 | buf_sprintf("declared here")); |
| 19513 | | return ira->codegen->invalid_instruction; |
| 20496 | return ira->codegen->invalid_inst_gen; |
| 19514 | 20497 | } |
| 19515 | 20498 | return result; |
| 19516 | 20499 | } |
| ... | ... | @@ -19561,17 +20544,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 19561 | 20544 | ptr_type->data.pointer.allow_zero); |
| 19562 | 20545 | } |
| 19563 | 20546 | |
| 19564 | | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 20547 | static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemPtr *elem_ptr_instruction) { |
| 19565 | 20548 | Error err; |
| 19566 | | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 20549 | IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 19567 | 20550 | if (type_is_invalid(array_ptr->value->type)) |
| 19568 | | return ira->codegen->invalid_instruction; |
| 20551 | return ira->codegen->invalid_inst_gen; |
| 19569 | 20552 | |
| 19570 | 20553 | ZigValue *orig_array_ptr_val = array_ptr->value; |
| 19571 | 20554 | |
| 19572 | | IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; |
| 20555 | IrInstGen *elem_index = elem_ptr_instruction->elem_index->child; |
| 19573 | 20556 | if (type_is_invalid(elem_index->value->type)) |
| 19574 | | return ira->codegen->invalid_instruction; |
| 20557 | return ira->codegen->invalid_inst_gen; |
| 19575 | 20558 | |
| 19576 | 20559 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 19577 | 20560 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -19583,7 +20566,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19583 | 20566 | ZigType *return_type; |
| 19584 | 20567 | |
| 19585 | 20568 | if (type_is_invalid(array_type)) { |
| 19586 | | return ira->codegen->invalid_instruction; |
| 20569 | return ira->codegen->invalid_inst_gen; |
| 19587 | 20570 | } else if (array_type->id == ZigTypeIdArray || |
| 19588 | 20571 | (array_type->id == ZigTypeIdPointer && |
| 19589 | 20572 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| ... | ... | @@ -19594,15 +20577,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19594 | 20577 | ptr_type = ptr_type->data.pointer.child_type; |
| 19595 | 20578 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { |
| 19596 | 20579 | orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 19597 | | elem_ptr_instruction->base.source_node); |
| 20580 | elem_ptr_instruction->base.base.source_node); |
| 19598 | 20581 | if (orig_array_ptr_val == nullptr) |
| 19599 | | return ira->codegen->invalid_instruction; |
| 20582 | return ira->codegen->invalid_inst_gen; |
| 19600 | 20583 | } |
| 19601 | 20584 | } |
| 19602 | 20585 | if (array_type->data.array.len == 0) { |
| 19603 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20586 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19604 | 20587 | buf_sprintf("index 0 outside array of size 0")); |
| 19605 | | return ira->codegen->invalid_instruction; |
| 20588 | return ira->codegen->invalid_inst_gen; |
| 19606 | 20589 | } |
| 19607 | 20590 | ZigType *child_type = array_type->data.array.child_type; |
| 19608 | 20591 | if (ptr_type->data.pointer.host_int_bytes == 0) { |
| ... | ... | @@ -19613,7 +20596,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19613 | 20596 | } else { |
| 19614 | 20597 | uint64_t elem_val_scalar; |
| 19615 | 20598 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) |
| 19616 | | return ira->codegen->invalid_instruction; |
| 20599 | return ira->codegen->invalid_inst_gen; |
| 19617 | 20600 | |
| 19618 | 20601 | size_t bit_width = type_size_bits(ira->codegen, child_type); |
| 19619 | 20602 | size_t bit_offset = bit_width * elem_val_scalar; |
| ... | ... | @@ -19625,9 +20608,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19625 | 20608 | } |
| 19626 | 20609 | } else if (array_type->id == ZigTypeIdPointer) { |
| 19627 | 20610 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 19628 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20611 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19629 | 20612 | buf_sprintf("index of single-item pointer")); |
| 19630 | | return ira->codegen->invalid_instruction; |
| 20613 | return ira->codegen->invalid_inst_gen; |
| 19631 | 20614 | } |
| 19632 | 20615 | return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len); |
| 19633 | 20616 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -19641,38 +20624,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19641 | 20624 | array_type->data.structure.resolve_status == ResolveStatusBeingInferred) |
| 19642 | 20625 | { |
| 19643 | 20626 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 19644 | | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 20627 | IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 19645 | 20628 | 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); |
| 20629 | return ira->codegen->invalid_inst_gen; |
| 20630 | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base); |
| 19648 | 20631 | Buf *field_name = buf_alloc(); |
| 19649 | 20632 | 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, |
| 20633 | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base, |
| 19651 | 20634 | array_ptr, array_type); |
| 19652 | 20635 | } else if (is_tuple(array_type)) { |
| 19653 | 20636 | uint64_t elem_index_scalar; |
| 19654 | 20637 | if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar)) |
| 19655 | | return ira->codegen->invalid_instruction; |
| 20638 | return ira->codegen->invalid_inst_gen; |
| 19656 | 20639 | if (elem_index_scalar >= array_type->data.structure.src_field_count) { |
| 19657 | | ir_add_error(ira, &elem_ptr_instruction->base, buf_sprintf( |
| 20640 | ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf( |
| 19658 | 20641 | "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields", |
| 19659 | 20642 | elem_index_scalar, buf_ptr(&array_type->name), |
| 19660 | 20643 | array_type->data.structure.src_field_count)); |
| 19661 | | return ira->codegen->invalid_instruction; |
| 20644 | return ira->codegen->invalid_inst_gen; |
| 19662 | 20645 | } |
| 19663 | 20646 | 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, |
| 20647 | return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr, |
| 19665 | 20648 | array_type, false); |
| 19666 | 20649 | } else { |
| 19667 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20650 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19668 | 20651 | buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name))); |
| 19669 | | return ira->codegen->invalid_instruction; |
| 20652 | return ira->codegen->invalid_inst_gen; |
| 19670 | 20653 | } |
| 19671 | 20654 | |
| 19672 | 20655 | 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; |
| 20656 | IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 20657 | if (type_is_invalid(casted_elem_index->value->type)) |
| 20658 | return ira->codegen->invalid_inst_gen; |
| 19676 | 20659 | |
| 19677 | 20660 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 19678 | 20661 | if (instr_is_comptime(casted_elem_index)) { |
| ... | ... | @@ -19681,15 +20664,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19681 | 20664 | uint64_t array_len = array_type->data.array.len; |
| 19682 | 20665 | if (index == array_len && array_type->data.array.sentinel != nullptr) { |
| 19683 | 20666 | ZigType *elem_type = array_type->data.array.child_type; |
| 19684 | | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); |
| 20667 | IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type); |
| 19685 | 20668 | 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); |
| 20669 | return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false); |
| 19687 | 20670 | } |
| 19688 | 20671 | if (index >= array_len) { |
| 19689 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20672 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19690 | 20673 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, |
| 19691 | 20674 | index, array_len)); |
| 19692 | | return ira->codegen->invalid_instruction; |
| 20675 | return ira->codegen->invalid_inst_gen; |
| 19693 | 20676 | } |
| 19694 | 20677 | safety_check_on = false; |
| 19695 | 20678 | } |
| ... | ... | @@ -19705,7 +20688,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19705 | 20688 | // figure out the largest alignment possible |
| 19706 | 20689 | |
| 19707 | 20690 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 19708 | | return ira->codegen->invalid_instruction; |
| 20691 | return ira->codegen->invalid_inst_gen; |
| 19709 | 20692 | |
| 19710 | 20693 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 19711 | 20694 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| ... | ... | @@ -19735,9 +20718,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19735 | 20718 | array_type->id == ZigTypeIdArray)) |
| 19736 | 20719 | { |
| 19737 | 20720 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 19738 | | elem_ptr_instruction->base.source_node); |
| 20721 | elem_ptr_instruction->base.base.source_node); |
| 19739 | 20722 | if (array_ptr_val == nullptr) |
| 19740 | | return ira->codegen->invalid_instruction; |
| 20723 | return ira->codegen->invalid_inst_gen; |
| 19741 | 20724 | |
| 19742 | 20725 | if (array_ptr_val->special == ConstValSpecialUndef && |
| 19743 | 20726 | elem_ptr_instruction->init_array_type_source_node != nullptr) |
| ... | ... | @@ -19755,16 +20738,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19755 | 20738 | elem_val->parent.data.p_array.elem_index = i; |
| 19756 | 20739 | } |
| 19757 | 20740 | } else if (is_slice(array_type)) { |
| 19758 | | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 20741 | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base); |
| 19759 | 20742 | ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; |
| 19760 | 20743 | |
| 19761 | 20744 | if (type_is_invalid(actual_array_type)) |
| 19762 | | return ira->codegen->invalid_instruction; |
| 20745 | return ira->codegen->invalid_inst_gen; |
| 19763 | 20746 | if (actual_array_type->id != ZigTypeIdArray) { |
| 19764 | 20747 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 19765 | 20748 | buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'", |
| 19766 | 20749 | buf_ptr(&actual_array_type->name))); |
| 19767 | | return ira->codegen->invalid_instruction; |
| 20750 | return ira->codegen->invalid_inst_gen; |
| 19768 | 20751 | } |
| 19769 | 20752 | |
| 19770 | 20753 | ZigValue *array_init_val = create_const_vals(1); |
| ... | ... | @@ -19789,7 +20772,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19789 | 20772 | ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node, |
| 19790 | 20773 | buf_sprintf("expected array type or [_], found '%s'", |
| 19791 | 20774 | buf_ptr(&array_type->name))); |
| 19792 | | return ira->codegen->invalid_instruction; |
| 20775 | return ira->codegen->invalid_inst_gen; |
| 19793 | 20776 | } |
| 19794 | 20777 | } |
| 19795 | 20778 | |
| ... | ... | @@ -19798,7 +20781,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19798 | 20781 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 19799 | 20782 | { |
| 19800 | 20783 | if (array_type->id == ZigTypeIdPointer) { |
| 19801 | | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 20784 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19802 | 20785 | ZigValue *out_val = result->value; |
| 19803 | 20786 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 19804 | 20787 | size_t new_index; |
| ... | ... | @@ -19867,33 +20850,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19867 | 20850 | zig_panic("TODO elem ptr on a null pointer"); |
| 19868 | 20851 | } |
| 19869 | 20852 | if (new_index >= mem_size) { |
| 19870 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20853 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19871 | 20854 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| 19872 | | return ira->codegen->invalid_instruction; |
| 20855 | return ira->codegen->invalid_inst_gen; |
| 19873 | 20856 | } |
| 19874 | 20857 | return result; |
| 19875 | 20858 | } else if (is_slice(array_type)) { |
| 19876 | 20859 | ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 19877 | | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base); |
| 20860 | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base); |
| 19878 | 20861 | 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; |
| 20862 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 20863 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false, |
| 20864 | return_type); |
| 19884 | 20865 | } |
| 19885 | 20866 | 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); |
| 20867 | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19887 | 20868 | ZigValue *out_val = result->value; |
| 19888 | 20869 | ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 19889 | 20870 | uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); |
| 19890 | 20871 | uint64_t full_slice_len = slice_len + |
| 19891 | 20872 | ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0); |
| 19892 | 20873 | if (index >= full_slice_len) { |
| 19893 | | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 20874 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 19894 | 20875 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 19895 | 20876 | index, slice_len)); |
| 19896 | | return ira->codegen->invalid_instruction; |
| 20877 | return ira->codegen->invalid_inst_gen; |
| 19897 | 20878 | } |
| 19898 | 20879 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 19899 | 20880 | switch (ptr_field->data.x_ptr.special) { |
| ... | ... | @@ -19913,7 +20894,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19913 | 20894 | { |
| 19914 | 20895 | ir_assert(new_index < |
| 19915 | 20896 | ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len, |
| 19916 | | &elem_ptr_instruction->base); |
| 20897 | &elem_ptr_instruction->base.base); |
| 19917 | 20898 | } |
| 19918 | 20899 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 19919 | 20900 | out_val->data.x_ptr.data.base_array.array_val = |
| ... | ... | @@ -19938,15 +20919,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19938 | 20919 | } |
| 19939 | 20920 | return result; |
| 19940 | 20921 | } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) { |
| 19941 | | IrInstruction *result; |
| 20922 | IrInstGen *result; |
| 19942 | 20923 | 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; |
| 20924 | result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 20925 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, |
| 20926 | false, return_type); |
| 19947 | 20927 | result->value->special = ConstValSpecialStatic; |
| 19948 | 20928 | } else { |
| 19949 | | result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 20929 | result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 19950 | 20930 | } |
| 19951 | 20931 | ZigValue *out_val = result->value; |
| 19952 | 20932 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| ... | ... | @@ -19972,19 +20952,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19972 | 20952 | // runtime known element index |
| 19973 | 20953 | switch (type_requires_comptime(ira->codegen, return_type)) { |
| 19974 | 20954 | case ReqCompTimeYes: |
| 19975 | | ir_add_error(ira, elem_index, |
| 20955 | ir_add_error(ira, &elem_index->base, |
| 19976 | 20956 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", |
| 19977 | 20957 | buf_ptr(&return_type->data.pointer.child_type->name))); |
| 19978 | | return ira->codegen->invalid_instruction; |
| 20958 | return ira->codegen->invalid_inst_gen; |
| 19979 | 20959 | case ReqCompTimeInvalid: |
| 19980 | | return ira->codegen->invalid_instruction; |
| 20960 | return ira->codegen->invalid_inst_gen; |
| 19981 | 20961 | case ReqCompTimeNo: |
| 19982 | 20962 | break; |
| 19983 | 20963 | } |
| 19984 | 20964 | |
| 19985 | 20965 | if (return_type->data.pointer.explicit_alignment != 0) { |
| 19986 | 20966 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 19987 | | return ira->codegen->invalid_instruction; |
| 20967 | return ira->codegen->invalid_inst_gen; |
| 19988 | 20968 | |
| 19989 | 20969 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 19990 | 20970 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| ... | ... | @@ -20002,16 +20982,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 20002 | 20982 | } |
| 20003 | 20983 | } |
| 20004 | 20984 | |
| 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; |
| 20985 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 20986 | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type); |
| 20010 | 20987 | } |
| 20011 | 20988 | |
| 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) |
| 20989 | static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20990 | ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr, |
| 20991 | IrInstGen *container_ptr, ZigType *container_type) |
| 20015 | 20992 | { |
| 20016 | 20993 | if (!is_slice(bare_struct_type)) { |
| 20017 | 20994 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| ... | ... | @@ -20021,29 +20998,27 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20021 | 20998 | if (tld->id == TldIdFn) { |
| 20022 | 20999 | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 20023 | 21000 | if (tld->resolution == TldResolutionInvalid) |
| 20024 | | return ira->codegen->invalid_instruction; |
| 21001 | return ira->codegen->invalid_inst_gen; |
| 20025 | 21002 | TldFn *tld_fn = (TldFn *)tld; |
| 20026 | 21003 | ZigFn *fn_entry = tld_fn->fn_entry; |
| 20027 | 21004 | if (type_is_invalid(fn_entry->type_entry)) |
| 20028 | | return ira->codegen->invalid_instruction; |
| 21005 | return ira->codegen->invalid_inst_gen; |
| 20029 | 21006 | |
| 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); |
| 21007 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr); |
| 20032 | 21008 | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 20033 | 21009 | } else if (tld->id == TldIdVar) { |
| 20034 | 21010 | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 20035 | 21011 | if (tld->resolution == TldResolutionInvalid) |
| 20036 | | return ira->codegen->invalid_instruction; |
| 21012 | return ira->codegen->invalid_inst_gen; |
| 20037 | 21013 | TldVar *tld_var = (TldVar *)tld; |
| 20038 | 21014 | ZigVar *var = tld_var->var; |
| 20039 | 21015 | if (type_is_invalid(var->var_type)) |
| 20040 | | return ira->codegen->invalid_instruction; |
| 21016 | return ira->codegen->invalid_inst_gen; |
| 20041 | 21017 | |
| 20042 | 21018 | if (var->const_value->type->id == ZigTypeIdFn) { |
| 20043 | 21019 | ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 20044 | 21020 | 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); |
| 21021 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr); |
| 20047 | 21022 | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 20048 | 21023 | } |
| 20049 | 21024 | } |
| ... | ... | @@ -20063,7 +21038,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 20063 | 21038 | } |
| 20064 | 21039 | ir_add_error_node(ira, source_instr->source_node, |
| 20065 | 21040 | 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; |
| 21041 | return ira->codegen->invalid_inst_gen; |
| 20067 | 21042 | } |
| 20068 | 21043 | |
| 20069 | 21044 | static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) { |
| ... | ... | @@ -20078,24 +21053,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty |
| 20078 | 21053 | field->type_entry, nullptr, UndefOk); |
| 20079 | 21054 | } |
| 20080 | 21055 | |
| 20081 | | static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 20082 | | TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing) |
| 21056 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 21057 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing) |
| 20083 | 21058 | { |
| 20084 | 21059 | Error err; |
| 20085 | 21060 | ZigType *field_type = resolve_struct_field_type(ira->codegen, field); |
| 20086 | 21061 | if (field_type == nullptr) |
| 20087 | | return ira->codegen->invalid_instruction; |
| 21062 | return ira->codegen->invalid_inst_gen; |
| 20088 | 21063 | if (field->is_comptime) { |
| 20089 | | IrInstruction *elem = ir_const(ira, source_instr, field_type); |
| 21064 | IrInstGen *elem = ir_const(ira, source_instr, field_type); |
| 20090 | 21065 | memoize_field_init_val(ira->codegen, struct_type, field); |
| 20091 | 21066 | copy_const_val(elem->value, field->init_val); |
| 20092 | 21067 | return ir_get_ref(ira, source_instr, elem, true, false); |
| 20093 | 21068 | } |
| 20094 | 21069 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 20095 | 21070 | case OnePossibleValueInvalid: |
| 20096 | | return ira->codegen->invalid_instruction; |
| 21071 | return ira->codegen->invalid_inst_gen; |
| 20097 | 21072 | case OnePossibleValueYes: { |
| 20098 | | IrInstruction *elem = ir_const_move(ira, source_instr, |
| 21073 | IrInstGen *elem = ir_const_move(ira, source_instr, |
| 20099 | 21074 | get_the_one_possible_value(ira->codegen, field_type)); |
| 20100 | 21075 | return ir_get_ref(ira, source_instr, elem, false, false); |
| 20101 | 21076 | } |
| ... | ... | @@ -20113,7 +21088,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20113 | 21088 | (struct_type->data.structure.layout == ContainerLayoutAuto) ? |
| 20114 | 21089 | ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown; |
| 20115 | 21090 | if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status))) |
| 20116 | | return ira->codegen->invalid_instruction; |
| 21091 | return ira->codegen->invalid_inst_gen; |
| 20117 | 21092 | assert(struct_ptr->value->type->id == ZigTypeIdPointer); |
| 20118 | 21093 | uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host; |
| 20119 | 21094 | uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes; |
| ... | ... | @@ -20127,14 +21102,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20127 | 21102 | if (instr_is_comptime(struct_ptr)) { |
| 20128 | 21103 | ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); |
| 20129 | 21104 | if (!ptr_val) |
| 20130 | | return ira->codegen->invalid_instruction; |
| 21105 | return ira->codegen->invalid_inst_gen; |
| 20131 | 21106 | |
| 20132 | 21107 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 20133 | 21108 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20134 | 21109 | if (struct_val == nullptr) |
| 20135 | | return ira->codegen->invalid_instruction; |
| 21110 | return ira->codegen->invalid_inst_gen; |
| 20136 | 21111 | if (type_is_invalid(struct_val->type)) |
| 20137 | | return ira->codegen->invalid_instruction; |
| 21112 | return ira->codegen->invalid_inst_gen; |
| 20138 | 21113 | if (initializing && struct_val->special == ConstValSpecialUndef) { |
| 20139 | 21114 | struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count); |
| 20140 | 21115 | struct_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -20148,11 +21123,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20148 | 21123 | field_val->parent.data.p_struct.field_index = i; |
| 20149 | 21124 | } |
| 20150 | 21125 | } |
| 20151 | | IrInstruction *result; |
| 21126 | IrInstGen *result; |
| 20152 | 21127 | 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; |
| 21128 | result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 20156 | 21129 | result->value->special = ConstValSpecialStatic; |
| 20157 | 21130 | } else { |
| 20158 | 21131 | result = ir_const(ira, source_instr, ptr_type); |
| ... | ... | @@ -20165,14 +21138,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 20165 | 21138 | return result; |
| 20166 | 21139 | } |
| 20167 | 21140 | } |
| 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; |
| 21141 | return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 20172 | 21142 | } |
| 20173 | 21143 | |
| 20174 | | static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 20175 | | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type) |
| 21144 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21145 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type) |
| 20176 | 21146 | { |
| 20177 | 21147 | // The type of the field is not available until a store using this pointer happens. |
| 20178 | 21148 | // So, here we create a special pointer type which has the inferred struct type and |
| ... | ... | @@ -20195,12 +21165,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 20195 | 21165 | if (instr_is_comptime(container_ptr)) { |
| 20196 | 21166 | ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20197 | 21167 | if (ptr_val == nullptr) |
| 20198 | | return ira->codegen->invalid_instruction; |
| 21168 | return ira->codegen->invalid_inst_gen; |
| 20199 | 21169 | |
| 20200 | | IrInstruction *result; |
| 21170 | IrInstGen *result; |
| 20201 | 21171 | 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); |
| 21172 | result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop); |
| 20204 | 21173 | } else { |
| 20205 | 21174 | result = ir_const(ira, source_instr, field_ptr_type); |
| 20206 | 21175 | } |
| ... | ... | @@ -20209,14 +21178,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 20209 | 21178 | return result; |
| 20210 | 21179 | } |
| 20211 | 21180 | |
| 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; |
| 21181 | return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop); |
| 20216 | 21182 | } |
| 20217 | 21183 | |
| 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) |
| 21184 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 21185 | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type, bool initializing) |
| 20220 | 21186 | { |
| 20221 | 21187 | Error err; |
| 20222 | 21188 | |
| ... | ... | @@ -20229,7 +21195,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20229 | 21195 | } |
| 20230 | 21196 | |
| 20231 | 21197 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 20232 | | return ira->codegen->invalid_instruction; |
| 21198 | return ira->codegen->invalid_inst_gen; |
| 20233 | 21199 | |
| 20234 | 21200 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20235 | 21201 | if (bare_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -20259,22 +21225,22 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20259 | 21225 | |
| 20260 | 21226 | ZigType *field_type = resolve_union_field_type(ira->codegen, field); |
| 20261 | 21227 | if (field_type == nullptr) |
| 20262 | | return ira->codegen->invalid_instruction; |
| 21228 | return ira->codegen->invalid_inst_gen; |
| 20263 | 21229 | |
| 20264 | 21230 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 20265 | 21231 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 20266 | 21232 | if (instr_is_comptime(container_ptr)) { |
| 20267 | 21233 | ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20268 | 21234 | if (!ptr_val) |
| 20269 | | return ira->codegen->invalid_instruction; |
| 21235 | return ira->codegen->invalid_inst_gen; |
| 20270 | 21236 | |
| 20271 | 21237 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 20272 | 21238 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 20273 | 21239 | ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20274 | 21240 | if (union_val == nullptr) |
| 20275 | | return ira->codegen->invalid_instruction; |
| 21241 | return ira->codegen->invalid_inst_gen; |
| 20276 | 21242 | if (type_is_invalid(union_val->type)) |
| 20277 | | return ira->codegen->invalid_instruction; |
| 21243 | return ira->codegen->invalid_inst_gen; |
| 20278 | 21244 | |
| 20279 | 21245 | if (initializing) { |
| 20280 | 21246 | ZigValue *payload_val = create_const_vals(1); |
| ... | ... | @@ -20295,17 +21261,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20295 | 21261 | ir_add_error_node(ira, source_instr->source_node, |
| 20296 | 21262 | buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name), |
| 20297 | 21263 | buf_ptr(actual_field->name))); |
| 20298 | | return ira->codegen->invalid_instruction; |
| 21264 | return ira->codegen->invalid_inst_gen; |
| 20299 | 21265 | } |
| 20300 | 21266 | } |
| 20301 | 21267 | |
| 20302 | 21268 | ZigValue *payload_val = union_val->data.x_union.payload; |
| 20303 | 21269 | |
| 20304 | | IrInstruction *result; |
| 21270 | IrInstGen *result; |
| 20305 | 21271 | 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; |
| 21272 | result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, |
| 21273 | initializing, ptr_type); |
| 20309 | 21274 | result->value->special = ConstValSpecialStatic; |
| 20310 | 21275 | } else { |
| 20311 | 21276 | result = ir_const(ira, source_instr, ptr_type); |
| ... | ... | @@ -20318,10 +21283,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 20318 | 21283 | } |
| 20319 | 21284 | } |
| 20320 | 21285 | |
| 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; |
| 21286 | return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type); |
| 20325 | 21287 | } |
| 20326 | 21288 | |
| 20327 | 21289 | zig_unreachable(); |
| ... | ... | @@ -20362,15 +21324,15 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 20362 | 21324 | link_lib->symbols.append(symbol_name); |
| 20363 | 21325 | } |
| 20364 | 21326 | |
| 20365 | | static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) { |
| 21327 | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) { |
| 20366 | 21328 | ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected")); |
| 20367 | | return ira->codegen->invalid_instruction; |
| 21329 | return ira->codegen->invalid_inst_gen; |
| 20368 | 21330 | } |
| 20369 | 21331 | |
| 20370 | | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 21332 | static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) { |
| 20371 | 21333 | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true); |
| 20372 | 21334 | if (tld->resolution == TldResolutionInvalid) { |
| 20373 | | return ira->codegen->invalid_instruction; |
| 21335 | return ira->codegen->invalid_inst_gen; |
| 20374 | 21336 | } |
| 20375 | 21337 | |
| 20376 | 21338 | switch (tld->id) { |
| ... | ... | @@ -20397,14 +21359,13 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_ |
| 20397 | 21359 | assert(fn_entry->type_entry); |
| 20398 | 21360 | |
| 20399 | 21361 | if (type_is_invalid(fn_entry->type_entry)) |
| 20400 | | return ira->codegen->invalid_instruction; |
| 21362 | return ira->codegen->invalid_inst_gen; |
| 20401 | 21363 | |
| 20402 | 21364 | if (tld_fn->extern_lib_name != nullptr) { |
| 20403 | 21365 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); |
| 20404 | 21366 | } |
| 20405 | 21367 | |
| 20406 | | IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope, |
| 20407 | | source_instruction->source_node, fn_entry); |
| 21368 | IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry); |
| 20408 | 21369 | return ir_get_ref(ira, source_instruction, fn_inst, true, false); |
| 20409 | 21370 | } |
| 20410 | 21371 | } |
| ... | ... | @@ -20422,40 +21383,40 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n |
| 20422 | 21383 | return nullptr; |
| 20423 | 21384 | } |
| 20424 | 21385 | |
| 20425 | | static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 21386 | static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFieldPtr *field_ptr_instruction) { |
| 20426 | 21387 | Error err; |
| 20427 | | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; |
| 21388 | IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child; |
| 20428 | 21389 | if (type_is_invalid(container_ptr->value->type)) |
| 20429 | | return ira->codegen->invalid_instruction; |
| 21390 | return ira->codegen->invalid_inst_gen; |
| 20430 | 21391 | |
| 20431 | 21392 | ZigType *container_type = container_ptr->value->type->data.pointer.child_type; |
| 20432 | 21393 | |
| 20433 | 21394 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 20434 | 21395 | if (!field_name) { |
| 20435 | | IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child; |
| 21396 | IrInstGen *field_name_expr = field_ptr_instruction->field_name_expr->child; |
| 20436 | 21397 | field_name = ir_resolve_str(ira, field_name_expr); |
| 20437 | 21398 | if (!field_name) |
| 20438 | | return ira->codegen->invalid_instruction; |
| 21399 | return ira->codegen->invalid_inst_gen; |
| 20439 | 21400 | } |
| 20440 | 21401 | |
| 20441 | 21402 | |
| 20442 | | AstNode *source_node = field_ptr_instruction->base.source_node; |
| 21403 | AstNode *source_node = field_ptr_instruction->base.base.source_node; |
| 20443 | 21404 | |
| 20444 | 21405 | if (type_is_invalid(container_type)) { |
| 20445 | | return ira->codegen->invalid_instruction; |
| 21406 | return ira->codegen->invalid_inst_gen; |
| 20446 | 21407 | } 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, |
| 21408 | IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base, |
| 20448 | 21409 | container_type->data.structure.src_field_count); |
| 20449 | | return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false); |
| 21410 | return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false); |
| 20450 | 21411 | } else if (is_slice(container_type) || is_container_ref(container_type)) { |
| 20451 | 21412 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20452 | 21413 | if (container_type->id == ZigTypeIdPointer) { |
| 20453 | 21414 | 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); |
| 21415 | IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr); |
| 21416 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_child, bare_type, field_ptr_instruction->initializing); |
| 20456 | 21417 | return result; |
| 20457 | 21418 | } else { |
| 20458 | | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing); |
| 21419 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, container_ptr, container_type, field_ptr_instruction->initializing); |
| 20459 | 21420 | return result; |
| 20460 | 21421 | } |
| 20461 | 21422 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { |
| ... | ... | @@ -20470,42 +21431,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20470 | 21431 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 20471 | 21432 | bool ptr_is_const = true; |
| 20472 | 21433 | bool ptr_is_volatile = false; |
| 20473 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 21434 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val, |
| 20474 | 21435 | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20475 | 21436 | } else { |
| 20476 | 21437 | ir_add_error_node(ira, source_node, |
| 20477 | 21438 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), |
| 20478 | 21439 | buf_ptr(&container_type->name))); |
| 20479 | | return ira->codegen->invalid_instruction; |
| 21440 | return ira->codegen->invalid_inst_gen; |
| 20480 | 21441 | } |
| 20481 | 21442 | } else if (container_type->id == ZigTypeIdMetaType) { |
| 20482 | 21443 | ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 20483 | 21444 | if (!container_ptr_val) |
| 20484 | | return ira->codegen->invalid_instruction; |
| 21445 | return ira->codegen->invalid_inst_gen; |
| 20485 | 21446 | |
| 20486 | 21447 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 20487 | 21448 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 20488 | 21449 | if (child_val == nullptr) |
| 20489 | | return ira->codegen->invalid_instruction; |
| 21450 | return ira->codegen->invalid_inst_gen; |
| 20490 | 21451 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 20491 | | field_ptr_instruction->base.source_node, child_val, UndefBad))) |
| 21452 | field_ptr_instruction->base.base.source_node, child_val, UndefBad))) |
| 20492 | 21453 | { |
| 20493 | | return ira->codegen->invalid_instruction; |
| 21454 | return ira->codegen->invalid_inst_gen; |
| 20494 | 21455 | } |
| 20495 | 21456 | ZigType *child_type = child_val->data.x_type; |
| 20496 | 21457 | |
| 20497 | 21458 | if (type_is_invalid(child_type)) { |
| 20498 | | return ira->codegen->invalid_instruction; |
| 21459 | return ira->codegen->invalid_inst_gen; |
| 20499 | 21460 | } else if (is_container(child_type)) { |
| 20500 | 21461 | if (child_type->id == ZigTypeIdEnum) { |
| 20501 | 21462 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) |
| 20502 | | return ira->codegen->invalid_instruction; |
| 21463 | return ira->codegen->invalid_inst_gen; |
| 20503 | 21464 | |
| 20504 | 21465 | TypeEnumField *field = find_enum_type_field(child_type, field_name); |
| 20505 | 21466 | if (field) { |
| 20506 | 21467 | bool ptr_is_const = true; |
| 20507 | 21468 | bool ptr_is_volatile = false; |
| 20508 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21469 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20509 | 21470 | create_const_enum(child_type, &field->value), child_type, |
| 20510 | 21471 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20511 | 21472 | } |
| ... | ... | @@ -20514,37 +21475,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20514 | 21475 | Tld *tld = find_container_decl(ira->codegen, container_scope, field_name); |
| 20515 | 21476 | if (tld) { |
| 20516 | 21477 | if (tld->visib_mod == VisibModPrivate && |
| 20517 | | tld->import != get_scope_import(field_ptr_instruction->base.scope)) |
| 21478 | tld->import != get_scope_import(field_ptr_instruction->base.base.scope)) |
| 20518 | 21479 | { |
| 20519 | | ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base, |
| 21480 | ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20520 | 21481 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 20521 | 21482 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 20522 | | return ira->codegen->invalid_instruction; |
| 21483 | return ira->codegen->invalid_inst_gen; |
| 20523 | 21484 | } |
| 20524 | | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); |
| 21485 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld); |
| 20525 | 21486 | } |
| 20526 | 21487 | if (child_type->id == ZigTypeIdUnion && |
| 20527 | 21488 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || |
| 20528 | 21489 | child_type->data.unionation.decl_node->data.container_decl.auto_enum)) |
| 20529 | 21490 | { |
| 20530 | 21491 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) |
| 20531 | | return ira->codegen->invalid_instruction; |
| 21492 | return ira->codegen->invalid_inst_gen; |
| 20532 | 21493 | TypeUnionField *field = find_union_type_field(child_type, field_name); |
| 20533 | 21494 | if (field) { |
| 20534 | 21495 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 20535 | 21496 | bool ptr_is_const = true; |
| 20536 | 21497 | bool ptr_is_volatile = false; |
| 20537 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21498 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20538 | 21499 | create_const_enum(enum_type, &field->enum_field->value), enum_type, |
| 20539 | 21500 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20540 | 21501 | } |
| 20541 | 21502 | } |
| 20542 | 21503 | const char *container_name = (child_type == ira->codegen->root_import) ? |
| 20543 | 21504 | "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name))); |
| 20544 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21505 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20545 | 21506 | buf_sprintf("%s has no member called '%s'", |
| 20546 | 21507 | container_name, buf_ptr(field_name))); |
| 20547 | | return ira->codegen->invalid_instruction; |
| 21508 | return ira->codegen->invalid_inst_gen; |
| 20548 | 21509 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 20549 | 21510 | ErrorTableEntry *err_entry; |
| 20550 | 21511 | ZigType *err_set_type; |
| ... | ... | @@ -20554,7 +21515,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20554 | 21515 | err_entry = existing_entry->value; |
| 20555 | 21516 | } else { |
| 20556 | 21517 | err_entry = allocate<ErrorTableEntry>(1); |
| 20557 | | err_entry->decl_node = field_ptr_instruction->base.source_node; |
| 21518 | err_entry->decl_node = field_ptr_instruction->base.base.source_node; |
| 20558 | 21519 | buf_init_from_buf(&err_entry->name, field_name); |
| 20559 | 21520 | size_t error_value_count = ira->codegen->errors_by_index.length; |
| 20560 | 21521 | assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count)); |
| ... | ... | @@ -20564,19 +21525,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20564 | 21525 | } |
| 20565 | 21526 | if (err_entry->set_with_only_this_in_it == nullptr) { |
| 20566 | 21527 | 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, |
| 21528 | field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node, |
| 20568 | 21529 | err_entry); |
| 20569 | 21530 | } |
| 20570 | 21531 | err_set_type = err_entry->set_with_only_this_in_it; |
| 20571 | 21532 | } else { |
| 20572 | | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { |
| 20573 | | return ira->codegen->invalid_instruction; |
| 21533 | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) { |
| 21534 | return ira->codegen->invalid_inst_gen; |
| 20574 | 21535 | } |
| 20575 | 21536 | err_entry = find_err_table_entry(child_type, field_name); |
| 20576 | 21537 | if (err_entry == nullptr) { |
| 20577 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21538 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20578 | 21539 | buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); |
| 20579 | | return ira->codegen->invalid_instruction; |
| 21540 | return ira->codegen->invalid_inst_gen; |
| 20580 | 21541 | } |
| 20581 | 21542 | err_set_type = child_type; |
| 20582 | 21543 | } |
| ... | ... | @@ -20587,13 +21548,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20587 | 21548 | |
| 20588 | 21549 | bool ptr_is_const = true; |
| 20589 | 21550 | bool ptr_is_volatile = false; |
| 20590 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 21551 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val, |
| 20591 | 21552 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20592 | 21553 | } else if (child_type->id == ZigTypeIdInt) { |
| 20593 | 21554 | if (buf_eql_str(field_name, "bit_count")) { |
| 20594 | 21555 | bool ptr_is_const = true; |
| 20595 | 21556 | bool ptr_is_volatile = false; |
| 20596 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21557 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20597 | 21558 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20598 | 21559 | child_type->data.integral.bit_count, false), |
| 20599 | 21560 | ira->codegen->builtin_types.entry_num_lit_int, |
| ... | ... | @@ -20601,36 +21562,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20601 | 21562 | } else if (buf_eql_str(field_name, "is_signed")) { |
| 20602 | 21563 | bool ptr_is_const = true; |
| 20603 | 21564 | bool ptr_is_volatile = false; |
| 20604 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21565 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20605 | 21566 | create_const_bool(ira->codegen, child_type->data.integral.is_signed), |
| 20606 | 21567 | ira->codegen->builtin_types.entry_bool, |
| 20607 | 21568 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20608 | 21569 | } else { |
| 20609 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21570 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20610 | 21571 | buf_sprintf("type '%s' has no member called '%s'", |
| 20611 | 21572 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20612 | | return ira->codegen->invalid_instruction; |
| 21573 | return ira->codegen->invalid_inst_gen; |
| 20613 | 21574 | } |
| 20614 | 21575 | } else if (child_type->id == ZigTypeIdFloat) { |
| 20615 | 21576 | if (buf_eql_str(field_name, "bit_count")) { |
| 20616 | 21577 | bool ptr_is_const = true; |
| 20617 | 21578 | bool ptr_is_volatile = false; |
| 20618 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21579 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20619 | 21580 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20620 | 21581 | child_type->data.floating.bit_count, false), |
| 20621 | 21582 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20622 | 21583 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20623 | 21584 | } else { |
| 20624 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21585 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20625 | 21586 | buf_sprintf("type '%s' has no member called '%s'", |
| 20626 | 21587 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20627 | | return ira->codegen->invalid_instruction; |
| 21588 | return ira->codegen->invalid_inst_gen; |
| 20628 | 21589 | } |
| 20629 | 21590 | } else if (child_type->id == ZigTypeIdPointer) { |
| 20630 | 21591 | if (buf_eql_str(field_name, "Child")) { |
| 20631 | 21592 | bool ptr_is_const = true; |
| 20632 | 21593 | bool ptr_is_volatile = false; |
| 20633 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21594 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20634 | 21595 | create_const_type(ira->codegen, child_type->data.pointer.child_type), |
| 20635 | 21596 | ira->codegen->builtin_types.entry_type, |
| 20636 | 21597 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| ... | ... | @@ -20640,75 +21601,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20640 | 21601 | if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type, |
| 20641 | 21602 | ResolveStatusAlignmentKnown))) |
| 20642 | 21603 | { |
| 20643 | | return ira->codegen->invalid_instruction; |
| 21604 | return ira->codegen->invalid_inst_gen; |
| 20644 | 21605 | } |
| 20645 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21606 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20646 | 21607 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20647 | 21608 | get_ptr_align(ira->codegen, child_type), false), |
| 20648 | 21609 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20649 | 21610 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20650 | 21611 | } else { |
| 20651 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21612 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20652 | 21613 | buf_sprintf("type '%s' has no member called '%s'", |
| 20653 | 21614 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20654 | | return ira->codegen->invalid_instruction; |
| 21615 | return ira->codegen->invalid_inst_gen; |
| 20655 | 21616 | } |
| 20656 | 21617 | } else if (child_type->id == ZigTypeIdArray) { |
| 20657 | 21618 | if (buf_eql_str(field_name, "Child")) { |
| 20658 | 21619 | bool ptr_is_const = true; |
| 20659 | 21620 | bool ptr_is_volatile = false; |
| 20660 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21621 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20661 | 21622 | create_const_type(ira->codegen, child_type->data.array.child_type), |
| 20662 | 21623 | ira->codegen->builtin_types.entry_type, |
| 20663 | 21624 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20664 | 21625 | } else if (buf_eql_str(field_name, "len")) { |
| 20665 | 21626 | bool ptr_is_const = true; |
| 20666 | 21627 | bool ptr_is_volatile = false; |
| 20667 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21628 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20668 | 21629 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 20669 | 21630 | child_type->data.array.len, false), |
| 20670 | 21631 | ira->codegen->builtin_types.entry_num_lit_int, |
| 20671 | 21632 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20672 | 21633 | } else { |
| 20673 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21634 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20674 | 21635 | buf_sprintf("type '%s' has no member called '%s'", |
| 20675 | 21636 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20676 | | return ira->codegen->invalid_instruction; |
| 21637 | return ira->codegen->invalid_inst_gen; |
| 20677 | 21638 | } |
| 20678 | 21639 | } else if (child_type->id == ZigTypeIdErrorUnion) { |
| 20679 | 21640 | if (buf_eql_str(field_name, "Payload")) { |
| 20680 | 21641 | bool ptr_is_const = true; |
| 20681 | 21642 | bool ptr_is_volatile = false; |
| 20682 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21643 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20683 | 21644 | create_const_type(ira->codegen, child_type->data.error_union.payload_type), |
| 20684 | 21645 | ira->codegen->builtin_types.entry_type, |
| 20685 | 21646 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20686 | 21647 | } else if (buf_eql_str(field_name, "ErrorSet")) { |
| 20687 | 21648 | bool ptr_is_const = true; |
| 20688 | 21649 | bool ptr_is_volatile = false; |
| 20689 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21650 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20690 | 21651 | create_const_type(ira->codegen, child_type->data.error_union.err_set_type), |
| 20691 | 21652 | ira->codegen->builtin_types.entry_type, |
| 20692 | 21653 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20693 | 21654 | } else { |
| 20694 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21655 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20695 | 21656 | buf_sprintf("type '%s' has no member called '%s'", |
| 20696 | 21657 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20697 | | return ira->codegen->invalid_instruction; |
| 21658 | return ira->codegen->invalid_inst_gen; |
| 20698 | 21659 | } |
| 20699 | 21660 | } else if (child_type->id == ZigTypeIdOptional) { |
| 20700 | 21661 | if (buf_eql_str(field_name, "Child")) { |
| 20701 | 21662 | bool ptr_is_const = true; |
| 20702 | 21663 | bool ptr_is_volatile = false; |
| 20703 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21664 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20704 | 21665 | create_const_type(ira->codegen, child_type->data.maybe.child_type), |
| 20705 | 21666 | ira->codegen->builtin_types.entry_type, |
| 20706 | 21667 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20707 | 21668 | } else { |
| 20708 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21669 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20709 | 21670 | buf_sprintf("type '%s' has no member called '%s'", |
| 20710 | 21671 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20711 | | return ira->codegen->invalid_instruction; |
| 21672 | return ira->codegen->invalid_inst_gen; |
| 20712 | 21673 | } |
| 20713 | 21674 | } else if (child_type->id == ZigTypeIdFn) { |
| 20714 | 21675 | if (buf_eql_str(field_name, "ReturnType")) { |
| ... | ... | @@ -20716,121 +21677,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 20716 | 21677 | // Return type can only ever be null, if the function is generic |
| 20717 | 21678 | assert(child_type->data.fn.is_generic); |
| 20718 | 21679 | |
| 20719 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21680 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20720 | 21681 | buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name))); |
| 20721 | | return ira->codegen->invalid_instruction; |
| 21682 | return ira->codegen->invalid_inst_gen; |
| 20722 | 21683 | } |
| 20723 | 21684 | |
| 20724 | 21685 | bool ptr_is_const = true; |
| 20725 | 21686 | bool ptr_is_volatile = false; |
| 20726 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21687 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20727 | 21688 | create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type), |
| 20728 | 21689 | ira->codegen->builtin_types.entry_type, |
| 20729 | 21690 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20730 | 21691 | } else if (buf_eql_str(field_name, "is_var_args")) { |
| 20731 | 21692 | bool ptr_is_const = true; |
| 20732 | 21693 | bool ptr_is_volatile = false; |
| 20733 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21694 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20734 | 21695 | create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args), |
| 20735 | 21696 | ira->codegen->builtin_types.entry_bool, |
| 20736 | 21697 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20737 | 21698 | } else if (buf_eql_str(field_name, "arg_count")) { |
| 20738 | 21699 | bool ptr_is_const = true; |
| 20739 | 21700 | bool ptr_is_volatile = false; |
| 20740 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 21701 | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 20741 | 21702 | create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count), |
| 20742 | 21703 | ira->codegen->builtin_types.entry_usize, |
| 20743 | 21704 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 20744 | 21705 | } else { |
| 20745 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21706 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20746 | 21707 | buf_sprintf("type '%s' has no member called '%s'", |
| 20747 | 21708 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 20748 | | return ira->codegen->invalid_instruction; |
| 21709 | return ira->codegen->invalid_inst_gen; |
| 20749 | 21710 | } |
| 20750 | 21711 | } else { |
| 20751 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21712 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20752 | 21713 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 20753 | | return ira->codegen->invalid_instruction; |
| 21714 | return ira->codegen->invalid_inst_gen; |
| 20754 | 21715 | } |
| 20755 | 21716 | } else if (field_ptr_instruction->initializing) { |
| 20756 | | ir_add_error(ira, &field_ptr_instruction->base, |
| 21717 | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 20757 | 21718 | buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name))); |
| 20758 | | return ira->codegen->invalid_instruction; |
| 21719 | return ira->codegen->invalid_inst_gen; |
| 20759 | 21720 | } else { |
| 20760 | | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 21721 | ir_add_error_node(ira, field_ptr_instruction->base.base.source_node, |
| 20761 | 21722 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 20762 | | return ira->codegen->invalid_instruction; |
| 21723 | return ira->codegen->invalid_inst_gen; |
| 20763 | 21724 | } |
| 20764 | 21725 | } |
| 20765 | 21726 | |
| 20766 | | static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) { |
| 20767 | | IrInstruction *ptr = instruction->ptr->child; |
| 21727 | static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) { |
| 21728 | IrInstGen *ptr = instruction->ptr->child; |
| 20768 | 21729 | if (type_is_invalid(ptr->value->type)) |
| 20769 | | return ira->codegen->invalid_instruction; |
| 21730 | return ira->codegen->invalid_inst_gen; |
| 20770 | 21731 | |
| 20771 | | IrInstruction *value = instruction->value->child; |
| 21732 | IrInstGen *value = instruction->value->child; |
| 20772 | 21733 | if (type_is_invalid(value->value->type)) |
| 20773 | | return ira->codegen->invalid_instruction; |
| 21734 | return ira->codegen->invalid_inst_gen; |
| 20774 | 21735 | |
| 20775 | | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| 21736 | return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const); |
| 20776 | 21737 | } |
| 20777 | 21738 | |
| 20778 | | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| 20779 | | IrInstruction *ptr = instruction->ptr->child; |
| 21739 | static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) { |
| 21740 | IrInstGen *ptr = instruction->ptr->child; |
| 20780 | 21741 | if (type_is_invalid(ptr->value->type)) |
| 20781 | | return ira->codegen->invalid_instruction; |
| 20782 | | return ir_get_deref(ira, &instruction->base, ptr, nullptr); |
| 21742 | return ira->codegen->invalid_inst_gen; |
| 21743 | return ir_get_deref(ira, &instruction->base.base, ptr, nullptr); |
| 20783 | 21744 | } |
| 20784 | 21745 | |
| 20785 | | static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 20786 | | IrInstruction *expr_value = typeof_instruction->value->child; |
| 21746 | static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) { |
| 21747 | IrInstGen *expr_value = typeof_instruction->value->child; |
| 20787 | 21748 | ZigType *type_entry = expr_value->value->type; |
| 20788 | 21749 | if (type_is_invalid(type_entry)) |
| 20789 | | return ira->codegen->invalid_instruction; |
| 20790 | | return ir_const_type(ira, &typeof_instruction->base, type_entry); |
| 21750 | return ira->codegen->invalid_inst_gen; |
| 21751 | return ir_const_type(ira, &typeof_instruction->base.base, type_entry); |
| 20791 | 21752 | } |
| 20792 | 21753 | |
| 20793 | | static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { |
| 21754 | static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) { |
| 20794 | 21755 | if (ira->new_irb.exec->is_inline) { |
| 20795 | 21756 | // ignore setCold when running functions at compile time |
| 20796 | | return ir_const_void(ira, &instruction->base); |
| 21757 | return ir_const_void(ira, &instruction->base.base); |
| 20797 | 21758 | } |
| 20798 | 21759 | |
| 20799 | | IrInstruction *is_cold_value = instruction->is_cold->child; |
| 21760 | IrInstGen *is_cold_value = instruction->is_cold->child; |
| 20800 | 21761 | bool want_cold; |
| 20801 | 21762 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 20802 | | return ira->codegen->invalid_instruction; |
| 21763 | return ira->codegen->invalid_inst_gen; |
| 20803 | 21764 | |
| 20804 | | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 21765 | ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope); |
| 20805 | 21766 | if (fn_entry == nullptr) { |
| 20806 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); |
| 20807 | | return ira->codegen->invalid_instruction; |
| 21767 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function")); |
| 21768 | return ira->codegen->invalid_inst_gen; |
| 20808 | 21769 | } |
| 20809 | 21770 | |
| 20810 | 21771 | if (fn_entry->set_cold_node != nullptr) { |
| 20811 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function")); |
| 21772 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function")); |
| 20812 | 21773 | add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here")); |
| 20813 | | return ira->codegen->invalid_instruction; |
| 21774 | return ira->codegen->invalid_inst_gen; |
| 20814 | 21775 | } |
| 20815 | 21776 | |
| 20816 | | fn_entry->set_cold_node = instruction->base.source_node; |
| 21777 | fn_entry->set_cold_node = instruction->base.base.source_node; |
| 20817 | 21778 | fn_entry->is_cold = want_cold; |
| 20818 | 21779 | |
| 20819 | | return ir_const_void(ira, &instruction->base); |
| 21780 | return ir_const_void(ira, &instruction->base.base); |
| 20820 | 21781 | } |
| 20821 | 21782 | |
| 20822 | | static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 20823 | | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 21783 | static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 21784 | IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction) |
| 20824 | 21785 | { |
| 20825 | 21786 | if (ira->new_irb.exec->is_inline) { |
| 20826 | 21787 | // ignore setRuntimeSafety when running functions at compile time |
| 20827 | | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 21788 | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 20828 | 21789 | } |
| 20829 | 21790 | |
| 20830 | 21791 | bool *safety_off_ptr; |
| 20831 | 21792 | AstNode **safety_set_node_ptr; |
| 20832 | 21793 | |
| 20833 | | Scope *scope = set_runtime_safety_instruction->base.scope; |
| 21794 | Scope *scope = set_runtime_safety_instruction->base.base.scope; |
| 20834 | 21795 | while (scope != nullptr) { |
| 20835 | 21796 | if (scope->id == ScopeIdBlock) { |
| 20836 | 21797 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -20856,36 +21817,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 20856 | 21817 | } |
| 20857 | 21818 | assert(scope != nullptr); |
| 20858 | 21819 | |
| 20859 | | IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child; |
| 21820 | IrInstGen *safety_on_value = set_runtime_safety_instruction->safety_on->child; |
| 20860 | 21821 | bool want_runtime_safety; |
| 20861 | 21822 | if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety)) |
| 20862 | | return ira->codegen->invalid_instruction; |
| 21823 | return ira->codegen->invalid_inst_gen; |
| 20863 | 21824 | |
| 20864 | | AstNode *source_node = set_runtime_safety_instruction->base.source_node; |
| 21825 | AstNode *source_node = set_runtime_safety_instruction->base.base.source_node; |
| 20865 | 21826 | if (*safety_set_node_ptr) { |
| 20866 | 21827 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 20867 | 21828 | buf_sprintf("runtime safety set twice for same scope")); |
| 20868 | 21829 | add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here")); |
| 20869 | | return ira->codegen->invalid_instruction; |
| 21830 | return ira->codegen->invalid_inst_gen; |
| 20870 | 21831 | } |
| 20871 | 21832 | *safety_set_node_ptr = source_node; |
| 20872 | 21833 | *safety_off_ptr = !want_runtime_safety; |
| 20873 | 21834 | |
| 20874 | | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 21835 | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 20875 | 21836 | } |
| 20876 | 21837 | |
| 20877 | | static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 20878 | | IrInstructionSetFloatMode *instruction) |
| 21838 | static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 21839 | IrInstSrcSetFloatMode *instruction) |
| 20879 | 21840 | { |
| 20880 | 21841 | if (ira->new_irb.exec->is_inline) { |
| 20881 | 21842 | // ignore setFloatMode when running functions at compile time |
| 20882 | | return ir_const_void(ira, &instruction->base); |
| 21843 | return ir_const_void(ira, &instruction->base.base); |
| 20883 | 21844 | } |
| 20884 | 21845 | |
| 20885 | 21846 | bool *fast_math_on_ptr; |
| 20886 | 21847 | AstNode **fast_math_set_node_ptr; |
| 20887 | 21848 | |
| 20888 | | Scope *scope = instruction->base.scope; |
| 21849 | Scope *scope = instruction->base.base.scope; |
| 20889 | 21850 | while (scope != nullptr) { |
| 20890 | 21851 | if (scope->id == ScopeIdBlock) { |
| 20891 | 21852 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -20911,42 +21872,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 20911 | 21872 | } |
| 20912 | 21873 | assert(scope != nullptr); |
| 20913 | 21874 | |
| 20914 | | IrInstruction *float_mode_value = instruction->mode_value->child; |
| 21875 | IrInstGen *float_mode_value = instruction->mode_value->child; |
| 20915 | 21876 | FloatMode float_mode_scalar; |
| 20916 | 21877 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) |
| 20917 | | return ira->codegen->invalid_instruction; |
| 21878 | return ira->codegen->invalid_inst_gen; |
| 20918 | 21879 | |
| 20919 | | AstNode *source_node = instruction->base.source_node; |
| 21880 | AstNode *source_node = instruction->base.base.source_node; |
| 20920 | 21881 | if (*fast_math_set_node_ptr) { |
| 20921 | 21882 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 20922 | 21883 | buf_sprintf("float mode set twice for same scope")); |
| 20923 | 21884 | add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here")); |
| 20924 | | return ira->codegen->invalid_instruction; |
| 21885 | return ira->codegen->invalid_inst_gen; |
| 20925 | 21886 | } |
| 20926 | 21887 | *fast_math_set_node_ptr = source_node; |
| 20927 | 21888 | *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized); |
| 20928 | 21889 | |
| 20929 | | return ir_const_void(ira, &instruction->base); |
| 21890 | return ir_const_void(ira, &instruction->base.base); |
| 20930 | 21891 | } |
| 20931 | 21892 | |
| 20932 | | static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, |
| 20933 | | IrInstructionAnyFrameType *instruction) |
| 20934 | | { |
| 21893 | static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) { |
| 20935 | 21894 | ZigType *payload_type = nullptr; |
| 20936 | 21895 | if (instruction->payload_type != nullptr) { |
| 20937 | 21896 | payload_type = ir_resolve_type(ira, instruction->payload_type->child); |
| 20938 | 21897 | if (type_is_invalid(payload_type)) |
| 20939 | | return ira->codegen->invalid_instruction; |
| 21898 | return ira->codegen->invalid_inst_gen; |
| 20940 | 21899 | } |
| 20941 | 21900 | |
| 20942 | 21901 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type); |
| 20943 | | return ir_const_type(ira, &instruction->base, any_frame_type); |
| 21902 | return ir_const_type(ira, &instruction->base.base, any_frame_type); |
| 20944 | 21903 | } |
| 20945 | 21904 | |
| 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); |
| 21905 | static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) { |
| 21906 | IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 20950 | 21907 | result->value->special = ConstValSpecialLazy; |
| 20951 | 21908 | |
| 20952 | 21909 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType"); |
| ... | ... | @@ -20957,18 +21914,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 20957 | 21914 | if (slice_type_instruction->align_value != nullptr) { |
| 20958 | 21915 | lazy_slice_type->align_inst = slice_type_instruction->align_value->child; |
| 20959 | 21916 | if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr) |
| 20960 | | return ira->codegen->invalid_instruction; |
| 21917 | return ira->codegen->invalid_inst_gen; |
| 20961 | 21918 | } |
| 20962 | 21919 | |
| 20963 | 21920 | if (slice_type_instruction->sentinel != nullptr) { |
| 20964 | 21921 | lazy_slice_type->sentinel = slice_type_instruction->sentinel->child; |
| 20965 | 21922 | if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr) |
| 20966 | | return ira->codegen->invalid_instruction; |
| 21923 | return ira->codegen->invalid_inst_gen; |
| 20967 | 21924 | } |
| 20968 | 21925 | |
| 20969 | 21926 | lazy_slice_type->elem_type = slice_type_instruction->child_type->child; |
| 20970 | 21927 | if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr) |
| 20971 | | return ira->codegen->invalid_instruction; |
| 21928 | return ira->codegen->invalid_inst_gen; |
| 20972 | 21929 | |
| 20973 | 21930 | lazy_slice_type->is_const = slice_type_instruction->is_const; |
| 20974 | 21931 | lazy_slice_type->is_volatile = slice_type_instruction->is_volatile; |
| ... | ... | @@ -20977,31 +21934,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 20977 | 21934 | return result; |
| 20978 | 21935 | } |
| 20979 | 21936 | |
| 20980 | | static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) { |
| 21937 | static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) { |
| 20981 | 21938 | Error err; |
| 20982 | 21939 | |
| 20983 | | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 21940 | assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr); |
| 20984 | 21941 | |
| 20985 | | AstNode *node = asm_instruction->base.source_node; |
| 20986 | | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; |
| 21942 | AstNode *node = asm_instruction->base.base.source_node; |
| 21943 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr; |
| 20987 | 21944 | |
| 20988 | 21945 | Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child); |
| 20989 | 21946 | if (template_buf == nullptr) |
| 20990 | | return ira->codegen->invalid_instruction; |
| 21947 | return ira->codegen->invalid_inst_gen; |
| 20991 | 21948 | |
| 20992 | 21949 | if (asm_instruction->is_global) { |
| 20993 | 21950 | buf_append_char(&ira->codegen->global_asm, '\n'); |
| 20994 | 21951 | buf_append_buf(&ira->codegen->global_asm, template_buf); |
| 20995 | 21952 | |
| 20996 | | return ir_const_void(ira, &asm_instruction->base); |
| 21953 | return ir_const_void(ira, &asm_instruction->base.base); |
| 20997 | 21954 | } |
| 20998 | 21955 | |
| 20999 | | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base)) |
| 21000 | | return ira->codegen->invalid_instruction; |
| 21956 | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base)) |
| 21957 | return ira->codegen->invalid_inst_gen; |
| 21001 | 21958 | |
| 21002 | 21959 | ZigList<AsmToken> tok_list = {}; |
| 21003 | 21960 | if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) { |
| 21004 | | return ira->codegen->invalid_instruction; |
| 21961 | return ira->codegen->invalid_inst_gen; |
| 21005 | 21962 | } |
| 21006 | 21963 | |
| 21007 | 21964 | for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) { |
| ... | ... | @@ -21015,15 +21972,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 21015 | 21972 | add_node_error(ira->codegen, node, |
| 21016 | 21973 | buf_sprintf("could not find '%.*s' in the inputs or outputs", |
| 21017 | 21974 | len, ptr)); |
| 21018 | | return ira->codegen->invalid_instruction; |
| 21975 | return ira->codegen->invalid_inst_gen; |
| 21019 | 21976 | } |
| 21020 | 21977 | } |
| 21021 | 21978 | } |
| 21022 | 21979 | |
| 21023 | 21980 | // TODO validate the output types and variable types |
| 21024 | 21981 | |
| 21025 | | IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length); |
| 21026 | | IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length); |
| 21982 | IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length); |
| 21983 | IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length); |
| 21027 | 21984 | |
| 21028 | 21985 | ZigType *return_type = ira->codegen->builtin_types.entry_void; |
| 21029 | 21986 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| ... | ... | @@ -21032,39 +21989,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 21032 | 21989 | output_types[i] = asm_instruction->output_types[i]->child; |
| 21033 | 21990 | return_type = ir_resolve_type(ira, output_types[i]); |
| 21034 | 21991 | if (type_is_invalid(return_type)) |
| 21035 | | return ira->codegen->invalid_instruction; |
| 21992 | return ira->codegen->invalid_inst_gen; |
| 21036 | 21993 | } |
| 21037 | 21994 | } |
| 21038 | 21995 | |
| 21039 | 21996 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 21040 | | IrInstruction *const input_value = asm_instruction->input_list[i]->child; |
| 21997 | IrInstGen *const input_value = asm_instruction->input_list[i]->child; |
| 21041 | 21998 | if (type_is_invalid(input_value->value->type)) |
| 21042 | | return ira->codegen->invalid_instruction; |
| 21999 | return ira->codegen->invalid_inst_gen; |
| 21043 | 22000 | |
| 21044 | 22001 | if (instr_is_comptime(input_value) && |
| 21045 | 22002 | (input_value->value->type->id == ZigTypeIdComptimeInt || |
| 21046 | 22003 | input_value->value->type->id == ZigTypeIdComptimeFloat)) { |
| 21047 | | ir_add_error_node(ira, input_value->source_node, |
| 22004 | ir_add_error(ira, &input_value->base, |
| 21048 | 22005 | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); |
| 21049 | | return ira->codegen->invalid_instruction; |
| 22006 | return ira->codegen->invalid_inst_gen; |
| 21050 | 22007 | } |
| 21051 | 22008 | |
| 21052 | 22009 | input_list[i] = input_value; |
| 21053 | 22010 | } |
| 21054 | 22011 | |
| 21055 | | IrInstruction *result = ir_build_asm_gen(ira, |
| 21056 | | asm_instruction->base.scope, asm_instruction->base.source_node, |
| 22012 | return ir_build_asm_gen(ira, &asm_instruction->base.base, |
| 21057 | 22013 | template_buf, tok_list.items, tok_list.length, |
| 21058 | 22014 | 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; |
| 22015 | asm_instruction->has_side_effects, return_type); |
| 21062 | 22016 | } |
| 21063 | 22017 | |
| 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); |
| 22018 | static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) { |
| 22019 | IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 21068 | 22020 | result->value->special = ConstValSpecialLazy; |
| 21069 | 22021 | |
| 21070 | 22022 | LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType"); |
| ... | ... | @@ -21074,22 +22026,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 21074 | 22026 | |
| 21075 | 22027 | lazy_array_type->elem_type = array_type_instruction->child_type->child; |
| 21076 | 22028 | if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr) |
| 21077 | | return ira->codegen->invalid_instruction; |
| 22029 | return ira->codegen->invalid_inst_gen; |
| 21078 | 22030 | |
| 21079 | 22031 | if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length)) |
| 21080 | | return ira->codegen->invalid_instruction; |
| 22032 | return ira->codegen->invalid_inst_gen; |
| 21081 | 22033 | |
| 21082 | 22034 | if (array_type_instruction->sentinel != nullptr) { |
| 21083 | 22035 | lazy_array_type->sentinel = array_type_instruction->sentinel->child; |
| 21084 | 22036 | if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr) |
| 21085 | | return ira->codegen->invalid_instruction; |
| 22037 | return ira->codegen->invalid_inst_gen; |
| 21086 | 22038 | } |
| 21087 | 22039 | |
| 21088 | 22040 | return result; |
| 21089 | 22041 | } |
| 21090 | 22042 | |
| 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); |
| 22043 | static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) { |
| 22044 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21093 | 22045 | result->value->special = ConstValSpecialLazy; |
| 21094 | 22046 | |
| 21095 | 22047 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf"); |
| ... | ... | @@ -21100,19 +22052,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi |
| 21100 | 22052 | |
| 21101 | 22053 | lazy_size_of->target_type = instruction->type_value->child; |
| 21102 | 22054 | if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr) |
| 21103 | | return ira->codegen->invalid_instruction; |
| 22055 | return ira->codegen->invalid_inst_gen; |
| 21104 | 22056 | |
| 21105 | 22057 | return result; |
| 21106 | 22058 | } |
| 21107 | 22059 | |
| 21108 | | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) { |
| 22060 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) { |
| 21109 | 22061 | ZigType *type_entry = value->value->type; |
| 21110 | 22062 | |
| 21111 | 22063 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { |
| 21112 | 22064 | if (instr_is_comptime(value)) { |
| 21113 | 22065 | ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); |
| 21114 | 22066 | if (c_ptr_val == nullptr) |
| 21115 | | return ira->codegen->invalid_instruction; |
| 22067 | return ira->codegen->invalid_inst_gen; |
| 21116 | 22068 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 21117 | 22069 | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 21118 | 22070 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| ... | ... | @@ -21121,25 +22073,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 21121 | 22073 | return ir_const_bool(ira, source_inst, !is_null); |
| 21122 | 22074 | } |
| 21123 | 22075 | |
| 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; |
| 22076 | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 21128 | 22077 | } else if (type_entry->id == ZigTypeIdOptional) { |
| 21129 | 22078 | if (instr_is_comptime(value)) { |
| 21130 | 22079 | ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk); |
| 21131 | 22080 | if (maybe_val == nullptr) |
| 21132 | | return ira->codegen->invalid_instruction; |
| 22081 | return ira->codegen->invalid_inst_gen; |
| 21133 | 22082 | if (maybe_val->special == ConstValSpecialUndef) |
| 21134 | 22083 | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 21135 | 22084 | |
| 21136 | 22085 | return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val)); |
| 21137 | 22086 | } |
| 21138 | 22087 | |
| 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; |
| 22088 | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 21143 | 22089 | } else if (type_entry->id == ZigTypeIdNull) { |
| 21144 | 22090 | return ir_const_bool(ira, source_inst, false); |
| 21145 | 22091 | } else { |
| ... | ... | @@ -21147,51 +22093,51 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 21147 | 22093 | } |
| 21148 | 22094 | } |
| 21149 | 22095 | |
| 21150 | | static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 21151 | | IrInstruction *value = instruction->value->child; |
| 22096 | static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) { |
| 22097 | IrInstGen *value = instruction->value->child; |
| 21152 | 22098 | if (type_is_invalid(value->value->type)) |
| 21153 | | return ira->codegen->invalid_instruction; |
| 22099 | return ira->codegen->invalid_inst_gen; |
| 21154 | 22100 | |
| 21155 | | return ir_analyze_test_non_null(ira, &instruction->base, value); |
| 22101 | return ir_analyze_test_non_null(ira, &instruction->base.base, value); |
| 21156 | 22102 | } |
| 21157 | 22103 | |
| 21158 | | static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 21159 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 22104 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 22105 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 21160 | 22106 | { |
| 21161 | 22107 | ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr); |
| 21162 | 22108 | if (type_is_invalid(type_entry)) |
| 21163 | | return ira->codegen->invalid_instruction; |
| 22109 | return ira->codegen->invalid_inst_gen; |
| 21164 | 22110 | |
| 21165 | 22111 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) { |
| 21166 | 22112 | if (instr_is_comptime(base_ptr)) { |
| 21167 | 22113 | ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 21168 | 22114 | if (!val) |
| 21169 | | return ira->codegen->invalid_instruction; |
| 22115 | return ira->codegen->invalid_inst_gen; |
| 21170 | 22116 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21171 | 22117 | ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 21172 | 22118 | if (c_ptr_val == nullptr) |
| 21173 | | return ira->codegen->invalid_instruction; |
| 22119 | return ira->codegen->invalid_inst_gen; |
| 21174 | 22120 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 21175 | 22121 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 21176 | 22122 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 21177 | 22123 | if (is_null) { |
| 21178 | 22124 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 21179 | | return ira->codegen->invalid_instruction; |
| 22125 | return ira->codegen->invalid_inst_gen; |
| 21180 | 22126 | } |
| 21181 | 22127 | return base_ptr; |
| 21182 | 22128 | } |
| 21183 | 22129 | } |
| 21184 | 22130 | if (!safety_check_on) |
| 21185 | 22131 | return base_ptr; |
| 21186 | | IrInstruction *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr); |
| 22132 | IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr); |
| 21187 | 22133 | ir_build_assert_non_null(ira, source_instr, c_ptr_val); |
| 21188 | 22134 | return base_ptr; |
| 21189 | 22135 | } |
| 21190 | 22136 | |
| 21191 | 22137 | if (type_entry->id != ZigTypeIdOptional) { |
| 21192 | | ir_add_error_node(ira, base_ptr->source_node, |
| 22138 | ir_add_error(ira, &base_ptr->base, |
| 21193 | 22139 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 21194 | | return ira->codegen->invalid_instruction; |
| 22140 | return ira->codegen->invalid_inst_gen; |
| 21195 | 22141 | } |
| 21196 | 22142 | |
| 21197 | 22143 | ZigType *child_type = type_entry->data.maybe.child_type; |
| ... | ... | @@ -21204,16 +22150,16 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21204 | 22150 | if (instr_is_comptime(base_ptr)) { |
| 21205 | 22151 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 21206 | 22152 | if (!ptr_val) |
| 21207 | | return ira->codegen->invalid_instruction; |
| 22153 | return ira->codegen->invalid_inst_gen; |
| 21208 | 22154 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21209 | 22155 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 21210 | 22156 | if (optional_val == nullptr) |
| 21211 | | return ira->codegen->invalid_instruction; |
| 22157 | return ira->codegen->invalid_inst_gen; |
| 21212 | 22158 | |
| 21213 | 22159 | if (initializing) { |
| 21214 | 22160 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 21215 | 22161 | case OnePossibleValueInvalid: |
| 21216 | | return ira->codegen->invalid_instruction; |
| 22162 | return ira->codegen->invalid_inst_gen; |
| 21217 | 22163 | case OnePossibleValueNo: |
| 21218 | 22164 | if (!same_comptime_repr) { |
| 21219 | 22165 | ZigValue *payload_val = create_const_vals(1); |
| ... | ... | @@ -21240,14 +22186,13 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21240 | 22186 | } |
| 21241 | 22187 | } else if (optional_value_is_null(optional_val)) { |
| 21242 | 22188 | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 21243 | | return ira->codegen->invalid_instruction; |
| 22189 | return ira->codegen->invalid_inst_gen; |
| 21244 | 22190 | } |
| 21245 | 22191 | |
| 21246 | | IrInstruction *result; |
| 22192 | IrInstGen *result; |
| 21247 | 22193 | 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; |
| 22194 | result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false, |
| 22195 | initializing, result_type); |
| 21251 | 22196 | result->value->special = ConstValSpecialStatic; |
| 21252 | 22197 | } else { |
| 21253 | 22198 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -21257,7 +22202,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21257 | 22202 | result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 21258 | 22203 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 21259 | 22204 | case OnePossibleValueInvalid: |
| 21260 | | return ira->codegen->invalid_instruction; |
| 22205 | return ira->codegen->invalid_inst_gen; |
| 21261 | 22206 | case OnePossibleValueNo: |
| 21262 | 22207 | if (same_comptime_repr) { |
| 21263 | 22208 | result_val->data.x_ptr.data.ref.pointee = optional_val; |
| ... | ... | @@ -21275,131 +22220,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21275 | 22220 | } |
| 21276 | 22221 | } |
| 21277 | 22222 | |
| 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; |
| 22223 | return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on, |
| 22224 | initializing, result_type); |
| 21282 | 22225 | } |
| 21283 | 22226 | |
| 21284 | | static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 21285 | | IrInstructionOptionalUnwrapPtr *instruction) |
| 22227 | static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 22228 | IrInstSrcOptionalUnwrapPtr *instruction) |
| 21286 | 22229 | { |
| 21287 | | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 22230 | IrInstGen *base_ptr = instruction->base_ptr->child; |
| 21288 | 22231 | if (type_is_invalid(base_ptr->value->type)) |
| 21289 | | return ira->codegen->invalid_instruction; |
| 22232 | return ira->codegen->invalid_inst_gen; |
| 21290 | 22233 | |
| 21291 | | return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr, |
| 22234 | return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr, |
| 21292 | 22235 | instruction->safety_check_on, false); |
| 21293 | 22236 | } |
| 21294 | 22237 | |
| 21295 | | static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) { |
| 22238 | static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) { |
| 21296 | 22239 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21297 | 22240 | if (type_is_invalid(int_type)) |
| 21298 | | return ira->codegen->invalid_instruction; |
| 22241 | return ira->codegen->invalid_inst_gen; |
| 21299 | 22242 | |
| 21300 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22243 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21301 | 22244 | if (type_is_invalid(op->value->type)) |
| 21302 | | return ira->codegen->invalid_instruction; |
| 22245 | return ira->codegen->invalid_inst_gen; |
| 21303 | 22246 | |
| 21304 | 22247 | if (int_type->data.integral.bit_count == 0) |
| 21305 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22248 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21306 | 22249 | |
| 21307 | 22250 | if (instr_is_comptime(op)) { |
| 21308 | 22251 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21309 | 22252 | if (val == nullptr) |
| 21310 | | return ira->codegen->invalid_instruction; |
| 22253 | return ira->codegen->invalid_inst_gen; |
| 21311 | 22254 | if (val->special == ConstValSpecialUndef) |
| 21312 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22255 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21313 | 22256 | 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); |
| 22257 | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 21315 | 22258 | } |
| 21316 | 22259 | |
| 21317 | 22260 | 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; |
| 22261 | return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op); |
| 21322 | 22262 | } |
| 21323 | 22263 | |
| 21324 | | static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) { |
| 22264 | static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) { |
| 21325 | 22265 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21326 | 22266 | if (type_is_invalid(int_type)) |
| 21327 | | return ira->codegen->invalid_instruction; |
| 22267 | return ira->codegen->invalid_inst_gen; |
| 21328 | 22268 | |
| 21329 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22269 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21330 | 22270 | if (type_is_invalid(op->value->type)) |
| 21331 | | return ira->codegen->invalid_instruction; |
| 22271 | return ira->codegen->invalid_inst_gen; |
| 21332 | 22272 | |
| 21333 | 22273 | if (int_type->data.integral.bit_count == 0) |
| 21334 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22274 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21335 | 22275 | |
| 21336 | 22276 | if (instr_is_comptime(op)) { |
| 21337 | 22277 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21338 | 22278 | if (val == nullptr) |
| 21339 | | return ira->codegen->invalid_instruction; |
| 22279 | return ira->codegen->invalid_inst_gen; |
| 21340 | 22280 | if (val->special == ConstValSpecialUndef) |
| 21341 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22281 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21342 | 22282 | 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); |
| 22283 | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 21344 | 22284 | } |
| 21345 | 22285 | |
| 21346 | 22286 | 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; |
| 22287 | return ir_build_clz_gen(ira, &instruction->base.base, return_type, op); |
| 21351 | 22288 | } |
| 21352 | 22289 | |
| 21353 | | static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { |
| 22290 | static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) { |
| 21354 | 22291 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 21355 | 22292 | if (type_is_invalid(int_type)) |
| 21356 | | return ira->codegen->invalid_instruction; |
| 22293 | return ira->codegen->invalid_inst_gen; |
| 21357 | 22294 | |
| 21358 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 22295 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 21359 | 22296 | if (type_is_invalid(op->value->type)) |
| 21360 | | return ira->codegen->invalid_instruction; |
| 22297 | return ira->codegen->invalid_inst_gen; |
| 21361 | 22298 | |
| 21362 | 22299 | if (int_type->data.integral.bit_count == 0) |
| 21363 | | return ir_const_unsigned(ira, &instruction->base, 0); |
| 22300 | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 21364 | 22301 | |
| 21365 | 22302 | if (instr_is_comptime(op)) { |
| 21366 | 22303 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 21367 | 22304 | if (val == nullptr) |
| 21368 | | return ira->codegen->invalid_instruction; |
| 22305 | return ira->codegen->invalid_inst_gen; |
| 21369 | 22306 | if (val->special == ConstValSpecialUndef) |
| 21370 | | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 22307 | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21371 | 22308 | |
| 21372 | 22309 | if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) { |
| 21373 | 22310 | size_t result = bigint_popcount_unsigned(&val->data.x_bigint); |
| 21374 | | return ir_const_unsigned(ira, &instruction->base, result); |
| 22311 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 21375 | 22312 | } |
| 21376 | 22313 | 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); |
| 22314 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 21378 | 22315 | } |
| 21379 | 22316 | |
| 21380 | 22317 | 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; |
| 22318 | return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op); |
| 21385 | 22319 | } |
| 21386 | 22320 | |
| 21387 | | static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| 22321 | static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) { |
| 21388 | 22322 | if (type_is_invalid(value->value->type)) |
| 21389 | | return ira->codegen->invalid_instruction; |
| 22323 | return ira->codegen->invalid_inst_gen; |
| 21390 | 22324 | |
| 21391 | 22325 | if (value->value->type->id != ZigTypeIdUnion) { |
| 21392 | | ir_add_error(ira, value, |
| 22326 | ir_add_error(ira, &value->base, |
| 21393 | 22327 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); |
| 21394 | | return ira->codegen->invalid_instruction; |
| 22328 | return ira->codegen->invalid_inst_gen; |
| 21395 | 22329 | } |
| 21396 | | if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 22330 | if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) { |
| 21397 | 22331 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); |
| 21398 | 22332 | if (value->value->type->data.unionation.decl_node != nullptr) { |
| 21399 | 22333 | add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, |
| 21400 | 22334 | buf_sprintf("declared here")); |
| 21401 | 22335 | } |
| 21402 | | return ira->codegen->invalid_instruction; |
| 22336 | return ira->codegen->invalid_inst_gen; |
| 21403 | 22337 | } |
| 21404 | 22338 | |
| 21405 | 22339 | ZigType *tag_type = value->value->type->data.unionation.tag_type; |
| ... | ... | @@ -21408,9 +22342,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 21408 | 22342 | if (instr_is_comptime(value)) { |
| 21409 | 22343 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 21410 | 22344 | if (!val) |
| 21411 | | return ira->codegen->invalid_instruction; |
| 22345 | return ira->codegen->invalid_inst_gen; |
| 21412 | 22346 | |
| 21413 | | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 22347 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 21414 | 22348 | source_instr->scope, source_instr->source_node); |
| 21415 | 22349 | const_instruction->base.value->type = tag_type; |
| 21416 | 22350 | const_instruction->base.value->special = ConstValSpecialStatic; |
| ... | ... | @@ -21418,15 +22352,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 21418 | 22352 | return &const_instruction->base; |
| 21419 | 22353 | } |
| 21420 | 22354 | |
| 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; |
| 22355 | return ir_build_union_tag(ira, source_instr, value, tag_type); |
| 21424 | 22356 | } |
| 21425 | 22357 | |
| 21426 | | static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21427 | | IrInstructionSwitchBr *switch_br_instruction) |
| 22358 | static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 22359 | IrInstSrcSwitchBr *switch_br_instruction) |
| 21428 | 22360 | { |
| 21429 | | IrInstruction *target_value = switch_br_instruction->target_value->child; |
| 22361 | IrInstGen *target_value = switch_br_instruction->target_value->child; |
| 21430 | 22362 | if (type_is_invalid(target_value->value->type)) |
| 21431 | 22363 | return ir_unreach_error(ira); |
| 21432 | 22364 | |
| ... | ... | @@ -21441,21 +22373,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21441 | 22373 | |
| 21442 | 22374 | bool is_comptime; |
| 21443 | 22375 | if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime)) |
| 21444 | | return ira->codegen->invalid_instruction; |
| 22376 | return ira->codegen->invalid_inst_gen; |
| 21445 | 22377 | |
| 21446 | 22378 | if (is_comptime || instr_is_comptime(target_value)) { |
| 21447 | 22379 | ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad); |
| 21448 | 22380 | if (!target_val) |
| 21449 | 22381 | return ir_unreach_error(ira); |
| 21450 | 22382 | |
| 21451 | | IrBasicBlock *old_dest_block = switch_br_instruction->else_block; |
| 22383 | IrBasicBlockSrc *old_dest_block = switch_br_instruction->else_block; |
| 21452 | 22384 | 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; |
| 22385 | IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 22386 | IrInstGen *case_value = old_case->value->child; |
| 21455 | 22387 | if (type_is_invalid(case_value->value->type)) |
| 21456 | 22388 | return ir_unreach_error(ira); |
| 21457 | 22389 | |
| 21458 | | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 22390 | IrInstGen *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 21459 | 22391 | if (type_is_invalid(casted_case_value->value->type)) |
| 21460 | 22392 | return ir_unreach_error(ira); |
| 21461 | 22393 | |
| ... | ... | @@ -21470,23 +22402,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21470 | 22402 | } |
| 21471 | 22403 | |
| 21472 | 22404 | if (is_comptime || old_dest_block->ref_count == 1) { |
| 21473 | | return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block); |
| 22405 | return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block); |
| 21474 | 22406 | } 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; |
| 22407 | IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base); |
| 22408 | IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block); |
| 21480 | 22409 | return ir_finish_anal(ira, result); |
| 21481 | 22410 | } |
| 21482 | 22411 | } |
| 21483 | 22412 | |
| 21484 | | IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count); |
| 22413 | IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count); |
| 21485 | 22414 | 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; |
| 22415 | IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 22416 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 22417 | new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base); |
| 22418 | new_case->value = ira->codegen->invalid_inst_gen; |
| 21490 | 22419 | |
| 21491 | 22420 | // Calling ir_get_new_bb set the ref_instruction on the new basic block. |
| 21492 | 22421 | // However a switch br may branch to the same basic block which would trigger an |
| ... | ... | @@ -21494,12 +22423,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21494 | 22423 | // it back after the loop. |
| 21495 | 22424 | new_case->block->ref_instruction = nullptr; |
| 21496 | 22425 | |
| 21497 | | IrInstruction *old_value = old_case->value; |
| 21498 | | IrInstruction *new_value = old_value->child; |
| 22426 | IrInstSrc *old_value = old_case->value; |
| 22427 | IrInstGen *new_value = old_value->child; |
| 21499 | 22428 | if (type_is_invalid(new_value->value->type)) |
| 21500 | 22429 | continue; |
| 21501 | 22430 | |
| 21502 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 22431 | IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 21503 | 22432 | if (type_is_invalid(casted_new_value->value->type)) |
| 21504 | 22433 | continue; |
| 21505 | 22434 | |
| ... | ... | @@ -21510,47 +22439,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 21510 | 22439 | } |
| 21511 | 22440 | |
| 21512 | 22441 | 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) |
| 22442 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 22443 | if (type_is_invalid(new_case->value->value->type)) |
| 21515 | 22444 | return ir_unreach_error(ira); |
| 21516 | | new_case->block->ref_instruction = &switch_br_instruction->base; |
| 22445 | new_case->block->ref_instruction = &switch_br_instruction->base.base; |
| 21517 | 22446 | } |
| 21518 | 22447 | |
| 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; |
| 22448 | IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base); |
| 22449 | IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base, |
| 22450 | target_value, new_else_block, case_count, cases); |
| 21524 | 22451 | return ir_finish_anal(ira, &switch_br->base); |
| 21525 | 22452 | } |
| 21526 | 22453 | |
| 21527 | | static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21528 | | IrInstructionSwitchTarget *switch_target_instruction) |
| 22454 | static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 22455 | IrInstSrcSwitchTarget *switch_target_instruction) |
| 21529 | 22456 | { |
| 21530 | 22457 | Error err; |
| 21531 | | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 22458 | IrInstGen *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 21532 | 22459 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21533 | | return ira->codegen->invalid_instruction; |
| 22460 | return ira->codegen->invalid_inst_gen; |
| 21534 | 22461 | |
| 21535 | 22462 | if (target_value_ptr->value->type->id == ZigTypeIdMetaType) { |
| 21536 | 22463 | assert(instr_is_comptime(target_value_ptr)); |
| 21537 | 22464 | ZigType *ptr_type = target_value_ptr->value->data.x_type; |
| 21538 | 22465 | assert(ptr_type->id == ZigTypeIdPointer); |
| 21539 | | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 22466 | return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type); |
| 21540 | 22467 | } |
| 21541 | 22468 | |
| 21542 | 22469 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 21543 | 22470 | ZigValue *pointee_val = nullptr; |
| 21544 | 22471 | 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); |
| 22472 | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node); |
| 21546 | 22473 | if (pointee_val == nullptr) |
| 21547 | | return ira->codegen->invalid_instruction; |
| 22474 | return ira->codegen->invalid_inst_gen; |
| 21548 | 22475 | |
| 21549 | 22476 | if (pointee_val->special == ConstValSpecialRuntime) |
| 21550 | 22477 | pointee_val = nullptr; |
| 21551 | 22478 | } |
| 21552 | 22479 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown))) |
| 21553 | | return ira->codegen->invalid_instruction; |
| 22480 | return ira->codegen->invalid_inst_gen; |
| 21554 | 22481 | |
| 21555 | 22482 | switch (target_type->id) { |
| 21556 | 22483 | case ZigTypeIdInvalid: |
| ... | ... | @@ -21567,13 +22494,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21567 | 22494 | case ZigTypeIdFn: |
| 21568 | 22495 | case ZigTypeIdErrorSet: { |
| 21569 | 22496 | if (pointee_val) { |
| 21570 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 22497 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr); |
| 21571 | 22498 | copy_const_val(result->value, pointee_val); |
| 21572 | 22499 | result->value->type = target_type; |
| 21573 | 22500 | return result; |
| 21574 | 22501 | } |
| 21575 | 22502 | |
| 21576 | | IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22503 | IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21577 | 22504 | result->value->type = target_type; |
| 21578 | 22505 | return result; |
| 21579 | 22506 | } |
| ... | ... | @@ -21582,52 +22509,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21582 | 22509 | if (!decl_node->data.container_decl.auto_enum && |
| 21583 | 22510 | decl_node->data.container_decl.init_arg_expr == nullptr) |
| 21584 | 22511 | { |
| 21585 | | ErrorMsg *msg = ir_add_error(ira, target_value_ptr, |
| 22512 | ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base, |
| 21586 | 22513 | buf_sprintf("switch on union which has no attached enum")); |
| 21587 | 22514 | add_error_note(ira->codegen, msg, decl_node, |
| 21588 | 22515 | buf_sprintf("consider 'union(enum)' here")); |
| 21589 | | return ira->codegen->invalid_instruction; |
| 22516 | return ira->codegen->invalid_inst_gen; |
| 21590 | 22517 | } |
| 21591 | 22518 | ZigType *tag_type = target_type->data.unionation.tag_type; |
| 21592 | 22519 | assert(tag_type != nullptr); |
| 21593 | 22520 | assert(tag_type->id == ZigTypeIdEnum); |
| 21594 | 22521 | if (pointee_val) { |
| 21595 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 22522 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 21596 | 22523 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 21597 | 22524 | return result; |
| 21598 | 22525 | } |
| 21599 | 22526 | if (tag_type->data.enumeration.src_field_count == 1) { |
| 21600 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 22527 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 21601 | 22528 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 21602 | 22529 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 21603 | 22530 | return result; |
| 21604 | 22531 | } |
| 21605 | 22532 | |
| 21606 | | IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22533 | IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21607 | 22534 | union_value->value->type = target_type; |
| 21608 | 22535 | |
| 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; |
| 22536 | return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type); |
| 21613 | 22537 | } |
| 21614 | 22538 | case ZigTypeIdEnum: { |
| 21615 | 22539 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| 21616 | | return ira->codegen->invalid_instruction; |
| 22540 | return ira->codegen->invalid_inst_gen; |
| 21617 | 22541 | if (target_type->data.enumeration.src_field_count == 1) { |
| 21618 | 22542 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 21619 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 22543 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 21620 | 22544 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 21621 | 22545 | return result; |
| 21622 | 22546 | } |
| 21623 | 22547 | |
| 21624 | 22548 | if (pointee_val) { |
| 21625 | | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 22549 | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 21626 | 22550 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 21627 | 22551 | return result; |
| 21628 | 22552 | } |
| 21629 | 22553 | |
| 21630 | | IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 22554 | IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 21631 | 22555 | enum_value->value->type = target_type; |
| 21632 | 22556 | return enum_value; |
| 21633 | 22557 | } |
| ... | ... | @@ -21643,17 +22567,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 21643 | 22567 | case ZigTypeIdVector: |
| 21644 | 22568 | case ZigTypeIdFnFrame: |
| 21645 | 22569 | case ZigTypeIdAnyFrame: |
| 21646 | | ir_add_error(ira, &switch_target_instruction->base, |
| 22570 | ir_add_error(ira, &switch_target_instruction->base.base, |
| 21647 | 22571 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 21648 | | return ira->codegen->invalid_instruction; |
| 22572 | return ira->codegen->invalid_inst_gen; |
| 21649 | 22573 | } |
| 21650 | 22574 | zig_unreachable(); |
| 21651 | 22575 | } |
| 21652 | 22576 | |
| 21653 | | static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 21654 | | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 22577 | static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) { |
| 22578 | IrInstGen *target_value_ptr = instruction->target_value_ptr->child; |
| 21655 | 22579 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21656 | | return ira->codegen->invalid_instruction; |
| 22580 | return ira->codegen->invalid_inst_gen; |
| 21657 | 22581 | |
| 21658 | 22582 | ZigType *ref_type = target_value_ptr->value->type; |
| 21659 | 22583 | assert(ref_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -21664,62 +22588,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21664 | 22588 | assert(enum_type->id == ZigTypeIdEnum); |
| 21665 | 22589 | assert(instruction->prongs_len > 0); |
| 21666 | 22590 | |
| 21667 | | IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; |
| 22591 | IrInstGen *first_prong_value = instruction->prongs_ptr[0]->child; |
| 21668 | 22592 | if (type_is_invalid(first_prong_value->value->type)) |
| 21669 | | return ira->codegen->invalid_instruction; |
| 22593 | return ira->codegen->invalid_inst_gen; |
| 21670 | 22594 | |
| 21671 | | IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 22595 | IrInstGen *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 21672 | 22596 | if (type_is_invalid(first_casted_prong_value->value->type)) |
| 21673 | | return ira->codegen->invalid_instruction; |
| 22597 | return ira->codegen->invalid_inst_gen; |
| 21674 | 22598 | |
| 21675 | 22599 | ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| 21676 | 22600 | if (first_prong_val == nullptr) |
| 21677 | | return ira->codegen->invalid_instruction; |
| 22601 | return ira->codegen->invalid_inst_gen; |
| 21678 | 22602 | |
| 21679 | 22603 | TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag); |
| 21680 | 22604 | |
| 21681 | 22605 | ErrorMsg *invalid_payload_msg = nullptr; |
| 21682 | 22606 | 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; |
| 22607 | IrInstGen *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 21684 | 22608 | if (type_is_invalid(this_prong_inst->value->type)) |
| 21685 | | return ira->codegen->invalid_instruction; |
| 22609 | return ira->codegen->invalid_inst_gen; |
| 21686 | 22610 | |
| 21687 | | IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 22611 | IrInstGen *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 21688 | 22612 | if (type_is_invalid(this_casted_prong_value->value->type)) |
| 21689 | | return ira->codegen->invalid_instruction; |
| 22613 | return ira->codegen->invalid_inst_gen; |
| 21690 | 22614 | |
| 21691 | 22615 | ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| 21692 | 22616 | if (this_prong == nullptr) |
| 21693 | | return ira->codegen->invalid_instruction; |
| 22617 | return ira->codegen->invalid_inst_gen; |
| 21694 | 22618 | |
| 21695 | 22619 | TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag); |
| 21696 | 22620 | ZigType *payload_type = payload_field->type_entry; |
| 21697 | 22621 | if (first_field->type_entry != payload_type) { |
| 21698 | 22622 | if (invalid_payload_msg == nullptr) { |
| 21699 | | invalid_payload_msg = ir_add_error(ira, &instruction->base, |
| 22623 | invalid_payload_msg = ir_add_error(ira, &instruction->base.base, |
| 21700 | 22624 | buf_sprintf("capture group with incompatible types")); |
| 21701 | | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node, |
| 22625 | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node, |
| 21702 | 22626 | buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name))); |
| 21703 | 22627 | } |
| 21704 | | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node, |
| 22628 | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node, |
| 21705 | 22629 | buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name))); |
| 21706 | 22630 | } |
| 21707 | 22631 | } |
| 21708 | 22632 | |
| 21709 | 22633 | if (invalid_payload_msg != nullptr) { |
| 21710 | | return ira->codegen->invalid_instruction; |
| 22634 | return ira->codegen->invalid_inst_gen; |
| 21711 | 22635 | } |
| 21712 | 22636 | |
| 21713 | 22637 | if (instr_is_comptime(target_value_ptr)) { |
| 21714 | 22638 | ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 21715 | 22639 | if (!target_value_ptr) |
| 21716 | | return ira->codegen->invalid_instruction; |
| 22640 | return ira->codegen->invalid_inst_gen; |
| 21717 | 22641 | |
| 21718 | | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); |
| 22642 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node); |
| 21719 | 22643 | if (pointee_val == nullptr) |
| 21720 | | return ira->codegen->invalid_instruction; |
| 22644 | return ira->codegen->invalid_inst_gen; |
| 21721 | 22645 | |
| 21722 | | IrInstruction *result = ir_const(ira, &instruction->base, |
| 22646 | IrInstGen *result = ir_const(ira, &instruction->base.base, |
| 21723 | 22647 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 21724 | 22648 | target_val_ptr->type->data.pointer.is_const)); |
| 21725 | 22649 | ZigValue *out_val = result->value; |
| ... | ... | @@ -21729,11 +22653,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21729 | 22653 | return result; |
| 21730 | 22654 | } |
| 21731 | 22655 | |
| 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, |
| 22656 | ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 21735 | 22657 | target_value_ptr->value->type->data.pointer.is_const); |
| 21736 | | return result; |
| 22658 | return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field, |
| 22659 | false, false, result_type); |
| 21737 | 22660 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| 21738 | 22661 | // construct an error set from the prong values |
| 21739 | 22662 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| ... | ... | @@ -21746,7 +22669,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21746 | 22669 | for (size_t i = 0; i < instruction->prongs_len; i += 1) { |
| 21747 | 22670 | ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child); |
| 21748 | 22671 | if (err == nullptr) |
| 21749 | | return ira->codegen->invalid_instruction; |
| 22672 | return ira->codegen->invalid_inst_gen; |
| 21750 | 22673 | error_list.append(err); |
| 21751 | 22674 | buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name)); |
| 21752 | 22675 | } |
| ... | ... | @@ -21762,29 +22685,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 21762 | 22685 | ref_type->data.pointer.explicit_alignment, |
| 21763 | 22686 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 21764 | 22687 | 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); |
| 22688 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, |
| 22689 | &instruction->base.base, false); |
| 21767 | 22690 | } else { |
| 21768 | | ir_add_error(ira, &instruction->base, |
| 22691 | ir_add_error(ira, &instruction->base.base, |
| 21769 | 22692 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| 21770 | | return ira->codegen->invalid_instruction; |
| 22693 | return ira->codegen->invalid_inst_gen; |
| 21771 | 22694 | } |
| 21772 | 22695 | } |
| 21773 | 22696 | |
| 21774 | | static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21775 | | IrInstructionSwitchElseVar *instruction) |
| 22697 | static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 22698 | IrInstSrcSwitchElseVar *instruction) |
| 21776 | 22699 | { |
| 21777 | | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 22700 | IrInstGen *target_value_ptr = instruction->target_value_ptr->child; |
| 21778 | 22701 | if (type_is_invalid(target_value_ptr->value->type)) |
| 21779 | | return ira->codegen->invalid_instruction; |
| 22702 | return ira->codegen->invalid_inst_gen; |
| 21780 | 22703 | |
| 21781 | 22704 | ZigType *ref_type = target_value_ptr->value->type; |
| 21782 | 22705 | assert(ref_type->id == ZigTypeIdPointer); |
| 21783 | 22706 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 21784 | 22707 | if (target_type->id == ZigTypeIdErrorSet) { |
| 21785 | 22708 | // 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; |
| 22709 | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) { |
| 22710 | return ira->codegen->invalid_inst_gen; |
| 21788 | 22711 | } |
| 21789 | 22712 | if (type_is_global_error_set(target_type)) { |
| 21790 | 22713 | // the type of the else capture variable still has to be the global error set. |
| ... | ... | @@ -21794,17 +22717,17 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21794 | 22717 | // Make note of the errors handled by other cases |
| 21795 | 22718 | ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| 21796 | 22719 | 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; |
| 22720 | IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; |
| 22721 | IrInstGen *case_expr = br_case->value->child; |
| 21799 | 22722 | if (case_expr->value->type->id == ZigTypeIdErrorSet) { |
| 21800 | 22723 | ErrorTableEntry *err = ir_resolve_error(ira, case_expr); |
| 21801 | 22724 | if (err == nullptr) |
| 21802 | | return ira->codegen->invalid_instruction; |
| 22725 | return ira->codegen->invalid_inst_gen; |
| 21803 | 22726 | errors[err->value] = err; |
| 21804 | 22727 | } else if (case_expr->value->type->id == ZigTypeIdMetaType) { |
| 21805 | 22728 | ZigType *err_set_type = ir_resolve_type(ira, case_expr); |
| 21806 | 22729 | if (type_is_invalid(err_set_type)) |
| 21807 | | return ira->codegen->invalid_instruction; |
| 22730 | return ira->codegen->invalid_inst_gen; |
| 21808 | 22731 | populate_error_set_table(errors, err_set_type); |
| 21809 | 22732 | } else { |
| 21810 | 22733 | zig_unreachable(); |
| ... | ... | @@ -21843,27 +22766,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 21843 | 22766 | ref_type->data.pointer.explicit_alignment, |
| 21844 | 22767 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 21845 | 22768 | 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); |
| 22769 | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, new_target_value_ptr_type, |
| 22770 | &instruction->base.base, false); |
| 21848 | 22771 | } |
| 21849 | 22772 | |
| 21850 | 22773 | return target_value_ptr; |
| 21851 | 22774 | } |
| 21852 | 22775 | |
| 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) { |
| 22776 | static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_instruction) { |
| 21859 | 22777 | Error err; |
| 21860 | 22778 | |
| 21861 | | IrInstruction *name_value = import_instruction->name->child; |
| 22779 | IrInstGen *name_value = import_instruction->name->child; |
| 21862 | 22780 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 21863 | 22781 | if (!import_target_str) |
| 21864 | | return ira->codegen->invalid_instruction; |
| 22782 | return ira->codegen->invalid_inst_gen; |
| 21865 | 22783 | |
| 21866 | | AstNode *source_node = import_instruction->base.source_node; |
| 22784 | AstNode *source_node = import_instruction->base.base.source_node; |
| 21867 | 22785 | ZigType *import = source_node->owner; |
| 21868 | 22786 | |
| 21869 | 22787 | ZigType *target_import; |
| ... | ... | @@ -21876,48 +22794,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 21876 | 22794 | ir_add_error_node(ira, source_node, |
| 21877 | 22795 | buf_sprintf("import of file outside package path: '%s'", |
| 21878 | 22796 | buf_ptr(import_target_path))); |
| 21879 | | return ira->codegen->invalid_instruction; |
| 22797 | return ira->codegen->invalid_inst_gen; |
| 21880 | 22798 | } else if (err == ErrorFileNotFound) { |
| 21881 | 22799 | ir_add_error_node(ira, source_node, |
| 21882 | 22800 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); |
| 21883 | | return ira->codegen->invalid_instruction; |
| 22801 | return ira->codegen->invalid_inst_gen; |
| 21884 | 22802 | } else { |
| 21885 | 22803 | ir_add_error_node(ira, source_node, |
| 21886 | 22804 | buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); |
| 21887 | | return ira->codegen->invalid_instruction; |
| 22805 | return ira->codegen->invalid_inst_gen; |
| 21888 | 22806 | } |
| 21889 | 22807 | } |
| 21890 | 22808 | |
| 21891 | | return ir_const_type(ira, &import_instruction->base, target_import); |
| 22809 | return ir_const_type(ira, &import_instruction->base.base, target_import); |
| 21892 | 22810 | } |
| 21893 | 22811 | |
| 21894 | | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 21895 | | IrInstruction *value = ref_instruction->value->child; |
| 22812 | static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) { |
| 22813 | IrInstGen *value = ref_instruction->value->child; |
| 21896 | 22814 | 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); |
| 22815 | return ira->codegen->invalid_inst_gen; |
| 22816 | return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 21899 | 22817 | } |
| 21900 | 22818 | |
| 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) |
| 22819 | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction, |
| 22820 | AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc, |
| 22821 | IrInstGen *result_loc) |
| 21904 | 22822 | { |
| 21905 | 22823 | Error err; |
| 21906 | 22824 | assert(union_type->id == ZigTypeIdUnion); |
| 21907 | 22825 | |
| 21908 | 22826 | if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown))) |
| 21909 | | return ira->codegen->invalid_instruction; |
| 22827 | return ira->codegen->invalid_inst_gen; |
| 21910 | 22828 | |
| 21911 | 22829 | TypeUnionField *type_field = find_union_type_field(union_type, field_name); |
| 21912 | 22830 | if (type_field == nullptr) { |
| 21913 | 22831 | ir_add_error_node(ira, field_source_node, |
| 21914 | 22832 | buf_sprintf("no member named '%s' in union '%s'", |
| 21915 | 22833 | buf_ptr(field_name), buf_ptr(&union_type->name))); |
| 21916 | | return ira->codegen->invalid_instruction; |
| 22834 | return ira->codegen->invalid_inst_gen; |
| 21917 | 22835 | } |
| 21918 | 22836 | |
| 21919 | 22837 | if (type_is_invalid(type_field->type_entry)) |
| 21920 | | return ira->codegen->invalid_instruction; |
| 22838 | return ira->codegen->invalid_inst_gen; |
| 21921 | 22839 | |
| 21922 | 22840 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21923 | 22841 | if (instr_is_comptime(field_result_loc) && |
| ... | ... | @@ -21929,42 +22847,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc |
| 21929 | 22847 | } |
| 21930 | 22848 | } |
| 21931 | 22849 | |
| 21932 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope) |
| 22850 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope) |
| 21933 | 22851 | || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes; |
| 21934 | 22852 | |
| 21935 | | IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| 22853 | IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| 21936 | 22854 | if (is_comptime && !instr_is_comptime(result)) { |
| 21937 | | ir_add_error(ira, field_result_loc, |
| 22855 | ir_add_error(ira, &field_result_loc->base, |
| 21938 | 22856 | buf_sprintf("unable to evaluate constant expression")); |
| 21939 | | return ira->codegen->invalid_instruction; |
| 22857 | return ira->codegen->invalid_inst_gen; |
| 21940 | 22858 | } |
| 21941 | 22859 | return result; |
| 21942 | 22860 | } |
| 21943 | 22861 | |
| 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) |
| 22862 | static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr, |
| 22863 | ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields, |
| 22864 | IrInstGen *result_loc) |
| 21947 | 22865 | { |
| 21948 | 22866 | Error err; |
| 21949 | 22867 | if (container_type->id == ZigTypeIdUnion) { |
| 21950 | 22868 | if (instr_field_count != 1) { |
| 21951 | | ir_add_error(ira, instruction, |
| 22869 | ir_add_error(ira, source_instr, |
| 21952 | 22870 | buf_sprintf("union initialization expects exactly one field")); |
| 21953 | | return ira->codegen->invalid_instruction; |
| 22871 | return ira->codegen->invalid_inst_gen; |
| 21954 | 22872 | } |
| 21955 | | IrInstructionContainerInitFieldsField *field = &fields[0]; |
| 21956 | | IrInstruction *field_result_loc = field->result_loc->child; |
| 22873 | IrInstSrcContainerInitFieldsField *field = &fields[0]; |
| 22874 | IrInstGen *field_result_loc = field->result_loc->child; |
| 21957 | 22875 | if (type_is_invalid(field_result_loc->value->type)) |
| 21958 | | return ira->codegen->invalid_instruction; |
| 22876 | return ira->codegen->invalid_inst_gen; |
| 21959 | 22877 | |
| 21960 | | return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name, |
| 22878 | return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name, |
| 21961 | 22879 | field_result_loc, result_loc); |
| 21962 | 22880 | } |
| 21963 | 22881 | if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) { |
| 21964 | | ir_add_error(ira, instruction, |
| 22882 | ir_add_error(ira, source_instr, |
| 21965 | 22883 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 21966 | 22884 | buf_ptr(&container_type->name))); |
| 21967 | | return ira->codegen->invalid_instruction; |
| 22885 | return ira->codegen->invalid_inst_gen; |
| 21968 | 22886 | } |
| 21969 | 22887 | |
| 21970 | 22888 | if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) { |
| ... | ... | @@ -21973,16 +22891,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 21973 | 22891 | } |
| 21974 | 22892 | |
| 21975 | 22893 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 21976 | | return ira->codegen->invalid_instruction; |
| 22894 | return ira->codegen->invalid_inst_gen; |
| 21977 | 22895 | |
| 21978 | 22896 | size_t actual_field_count = container_type->data.structure.src_field_count; |
| 21979 | 22897 | |
| 21980 | | IrInstruction *first_non_const_instruction = nullptr; |
| 22898 | IrInstGen *first_non_const_instruction = nullptr; |
| 21981 | 22899 | |
| 21982 | 22900 | AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count); |
| 21983 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 22901 | ZigList<IrInstGen *> const_ptrs = {}; |
| 21984 | 22902 | |
| 21985 | | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope) |
| 22903 | bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope) |
| 21986 | 22904 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; |
| 21987 | 22905 | |
| 21988 | 22906 | |
| ... | ... | @@ -21998,29 +22916,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 21998 | 22916 | // comptime-known values. |
| 21999 | 22917 | |
| 22000 | 22918 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 22001 | | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 22919 | IrInstSrcContainerInitFieldsField *field = &fields[i]; |
| 22002 | 22920 | |
| 22003 | | IrInstruction *field_result_loc = field->result_loc->child; |
| 22921 | IrInstGen *field_result_loc = field->result_loc->child; |
| 22004 | 22922 | if (type_is_invalid(field_result_loc->value->type)) |
| 22005 | | return ira->codegen->invalid_instruction; |
| 22923 | return ira->codegen->invalid_inst_gen; |
| 22006 | 22924 | |
| 22007 | 22925 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| 22008 | 22926 | if (!type_field) { |
| 22009 | 22927 | ir_add_error_node(ira, field->source_node, |
| 22010 | 22928 | buf_sprintf("no member named '%s' in struct '%s'", |
| 22011 | 22929 | buf_ptr(field->name), buf_ptr(&container_type->name))); |
| 22012 | | return ira->codegen->invalid_instruction; |
| 22930 | return ira->codegen->invalid_inst_gen; |
| 22013 | 22931 | } |
| 22014 | 22932 | |
| 22015 | 22933 | if (type_is_invalid(type_field->type_entry)) |
| 22016 | | return ira->codegen->invalid_instruction; |
| 22934 | return ira->codegen->invalid_inst_gen; |
| 22017 | 22935 | |
| 22018 | 22936 | size_t field_index = type_field->src_index; |
| 22019 | 22937 | AstNode *existing_assign_node = field_assign_nodes[field_index]; |
| 22020 | 22938 | if (existing_assign_node) { |
| 22021 | 22939 | ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field")); |
| 22022 | 22940 | add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here")); |
| 22023 | | return ira->codegen->invalid_instruction; |
| 22941 | return ira->codegen->invalid_inst_gen; |
| 22024 | 22942 | } |
| 22025 | 22943 | field_assign_nodes[field_index] = field->source_node; |
| 22026 | 22944 | |
| ... | ... | @@ -22041,20 +22959,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 22041 | 22959 | TypeStructField *field = container_type->data.structure.fields[i]; |
| 22042 | 22960 | memoize_field_init_val(ira->codegen, container_type, field); |
| 22043 | 22961 | if (field->init_val == nullptr) { |
| 22044 | | ir_add_error_node(ira, instruction->source_node, |
| 22962 | ir_add_error(ira, source_instr, |
| 22045 | 22963 | buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name))); |
| 22046 | 22964 | any_missing = true; |
| 22047 | 22965 | continue; |
| 22048 | 22966 | } |
| 22049 | 22967 | if (type_is_invalid(field->init_val->type)) |
| 22050 | | return ira->codegen->invalid_instruction; |
| 22968 | return ira->codegen->invalid_inst_gen; |
| 22051 | 22969 | |
| 22052 | | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 22970 | IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type); |
| 22053 | 22971 | copy_const_val(runtime_inst->value, field->init_val); |
| 22054 | 22972 | |
| 22055 | | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 22973 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc, |
| 22056 | 22974 | container_type, true); |
| 22057 | | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 22975 | ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false); |
| 22058 | 22976 | if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 22059 | 22977 | const_ptrs.append(field_ptr); |
| 22060 | 22978 | } else { |
| ... | ... | @@ -22062,39 +22980,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 22062 | 22980 | } |
| 22063 | 22981 | } |
| 22064 | 22982 | if (any_missing) |
| 22065 | | return ira->codegen->invalid_instruction; |
| 22983 | return ira->codegen->invalid_inst_gen; |
| 22066 | 22984 | |
| 22067 | 22985 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 22068 | 22986 | if (const_ptrs.length != actual_field_count) { |
| 22069 | 22987 | result_loc->value->special = ConstValSpecialRuntime; |
| 22070 | 22988 | 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); |
| 22989 | IrInstGen *field_result_loc = const_ptrs.at(i); |
| 22990 | IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr); |
| 22073 | 22991 | field_result_loc->value->special = ConstValSpecialRuntime; |
| 22074 | | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 22992 | ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false); |
| 22075 | 22993 | } |
| 22076 | 22994 | } |
| 22077 | 22995 | } |
| 22078 | 22996 | |
| 22079 | | IrInstruction *result = ir_get_deref(ira, instruction, result_loc, nullptr); |
| 22997 | IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr); |
| 22080 | 22998 | |
| 22081 | 22999 | if (is_comptime && !instr_is_comptime(result)) { |
| 22082 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 23000 | ir_add_error_node(ira, first_non_const_instruction->base.source_node, |
| 22083 | 23001 | buf_sprintf("unable to evaluate constant expression")); |
| 22084 | | return ira->codegen->invalid_instruction; |
| 23002 | return ira->codegen->invalid_inst_gen; |
| 22085 | 23003 | } |
| 22086 | 23004 | |
| 22087 | 23005 | return result; |
| 22088 | 23006 | } |
| 22089 | 23007 | |
| 22090 | | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22091 | | IrInstructionContainerInitList *instruction) |
| 23008 | static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 23009 | IrInstSrcContainerInitList *instruction) |
| 22092 | 23010 | { |
| 22093 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 22094 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 23011 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23012 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22095 | 23013 | if (type_is_invalid(result_loc->value->type)) |
| 22096 | 23014 | return result_loc; |
| 22097 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 23015 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 22098 | 23016 | |
| 22099 | 23017 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 22100 | 23018 | |
| ... | ... | @@ -22104,24 +23022,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22104 | 23022 | ir_add_error_node(ira, instruction->init_array_type_source_node, |
| 22105 | 23023 | buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'", |
| 22106 | 23024 | buf_ptr(&container_type->name))); |
| 22107 | | return ira->codegen->invalid_instruction; |
| 23025 | return ira->codegen->invalid_inst_gen; |
| 22108 | 23026 | } |
| 22109 | 23027 | |
| 22110 | 23028 | if (container_type->id == ZigTypeIdVoid) { |
| 22111 | 23029 | if (elem_count != 0) { |
| 22112 | | ir_add_error_node(ira, instruction->base.source_node, |
| 23030 | ir_add_error_node(ira, instruction->base.base.source_node, |
| 22113 | 23031 | buf_sprintf("void expression expects no arguments")); |
| 22114 | | return ira->codegen->invalid_instruction; |
| 23032 | return ira->codegen->invalid_inst_gen; |
| 22115 | 23033 | } |
| 22116 | | return ir_const_void(ira, &instruction->base); |
| 23034 | return ir_const_void(ira, &instruction->base.base); |
| 22117 | 23035 | } |
| 22118 | 23036 | |
| 22119 | 23037 | 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; |
| 23038 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23039 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22122 | 23040 | if (type_is_invalid(result_loc->value->type)) |
| 22123 | 23041 | return result_loc; |
| 22124 | | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc); |
| 23042 | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc); |
| 22125 | 23043 | } |
| 22126 | 23044 | |
| 22127 | 23045 | if (container_type->id == ZigTypeIdArray) { |
| ... | ... | @@ -22129,10 +23047,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22129 | 23047 | if (container_type->data.array.len != elem_count) { |
| 22130 | 23048 | ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr); |
| 22131 | 23049 | |
| 22132 | | ir_add_error(ira, &instruction->base, |
| 23050 | ir_add_error(ira, &instruction->base.base, |
| 22133 | 23051 | buf_sprintf("expected %s literal, found %s literal", |
| 22134 | 23052 | buf_ptr(&container_type->name), buf_ptr(&literal_type->name))); |
| 22135 | | return ira->codegen->invalid_instruction; |
| 23053 | return ira->codegen->invalid_inst_gen; |
| 22136 | 23054 | } |
| 22137 | 23055 | } else if (container_type->id == ZigTypeIdStruct && |
| 22138 | 23056 | container_type->data.structure.resolve_status == ResolveStatusBeingInferred) |
| ... | ... | @@ -22142,17 +23060,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22142 | 23060 | } else if (container_type->id == ZigTypeIdVector) { |
| 22143 | 23061 | // OK |
| 22144 | 23062 | } else { |
| 22145 | | ir_add_error_node(ira, instruction->base.source_node, |
| 23063 | ir_add_error(ira, &instruction->base.base, |
| 22146 | 23064 | buf_sprintf("type '%s' does not support array initialization", |
| 22147 | 23065 | buf_ptr(&container_type->name))); |
| 22148 | | return ira->codegen->invalid_instruction; |
| 23066 | return ira->codegen->invalid_inst_gen; |
| 22149 | 23067 | } |
| 22150 | 23068 | |
| 22151 | 23069 | switch (type_has_one_possible_value(ira->codegen, container_type)) { |
| 22152 | 23070 | case OnePossibleValueInvalid: |
| 22153 | | return ira->codegen->invalid_instruction; |
| 23071 | return ira->codegen->invalid_inst_gen; |
| 22154 | 23072 | case OnePossibleValueYes: |
| 22155 | | return ir_const_move(ira, &instruction->base, |
| 23073 | return ir_const_move(ira, &instruction->base.base, |
| 22156 | 23074 | get_the_one_possible_value(ira->codegen, container_type)); |
| 22157 | 23075 | case OnePossibleValueNo: |
| 22158 | 23076 | break; |
| ... | ... | @@ -22161,16 +23079,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22161 | 23079 | bool is_comptime; |
| 22162 | 23080 | switch (type_requires_comptime(ira->codegen, container_type)) { |
| 22163 | 23081 | case ReqCompTimeInvalid: |
| 22164 | | return ira->codegen->invalid_instruction; |
| 23082 | return ira->codegen->invalid_inst_gen; |
| 22165 | 23083 | case ReqCompTimeNo: |
| 22166 | | is_comptime = ir_should_inline(ira->new_irb.exec, instruction->base.scope); |
| 23084 | is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope); |
| 22167 | 23085 | break; |
| 22168 | 23086 | case ReqCompTimeYes: |
| 22169 | 23087 | is_comptime = true; |
| 22170 | 23088 | break; |
| 22171 | 23089 | } |
| 22172 | 23090 | |
| 22173 | | IrInstruction *first_non_const_instruction = nullptr; |
| 23091 | IrInstGen *first_non_const_instruction = nullptr; |
| 22174 | 23092 | |
| 22175 | 23093 | // The Result Location Mechanism has already emitted runtime instructions to |
| 22176 | 23094 | // initialize runtime elements and has omitted instructions for the comptime |
| ... | ... | @@ -22179,12 +23097,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22179 | 23097 | // array initialization can be a comptime value, overwrite ConstPtrMutInfer with |
| 22180 | 23098 | // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the |
| 22181 | 23099 | // elements that have comptime-known values. |
| 22182 | | ZigList<IrInstruction *> const_ptrs = {}; |
| 23100 | ZigList<IrInstGen *> const_ptrs = {}; |
| 22183 | 23101 | |
| 22184 | 23102 | for (size_t i = 0; i < elem_count; i += 1) { |
| 22185 | | IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 23103 | IrInstGen *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 22186 | 23104 | if (type_is_invalid(elem_result_loc->value->type)) |
| 22187 | | return ira->codegen->invalid_instruction; |
| 23105 | return ira->codegen->invalid_inst_gen; |
| 22188 | 23106 | |
| 22189 | 23107 | assert(elem_result_loc->value->type->id == ZigTypeIdPointer); |
| 22190 | 23108 | |
| ... | ... | @@ -22201,81 +23119,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 22201 | 23119 | if (const_ptrs.length != elem_count) { |
| 22202 | 23120 | result_loc->value->special = ConstValSpecialRuntime; |
| 22203 | 23121 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 22204 | | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 23122 | IrInstGen *elem_result_loc = const_ptrs.at(i); |
| 22205 | 23123 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 22206 | 23124 | if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) { |
| 22207 | 23125 | // This field will be generated comptime; no need to do this. |
| 22208 | 23126 | continue; |
| 22209 | 23127 | } |
| 22210 | | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 23128 | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 22211 | 23129 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 22212 | | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 23130 | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false); |
| 22213 | 23131 | } |
| 22214 | 23132 | } |
| 22215 | 23133 | } |
| 22216 | 23134 | |
| 22217 | | IrInstruction *result = ir_get_deref(ira, &instruction->base, result_loc, nullptr); |
| 23135 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr); |
| 22218 | 23136 | if (instr_is_comptime(result)) |
| 22219 | 23137 | return result; |
| 22220 | 23138 | |
| 22221 | 23139 | if (is_comptime) { |
| 22222 | | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 23140 | ir_add_error(ira, &first_non_const_instruction->base, |
| 22223 | 23141 | buf_sprintf("unable to evaluate constant expression")); |
| 22224 | | return ira->codegen->invalid_instruction; |
| 23142 | return ira->codegen->invalid_inst_gen; |
| 22225 | 23143 | } |
| 22226 | 23144 | |
| 22227 | 23145 | ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; |
| 22228 | 23146 | if (is_slice(result_elem_type)) { |
| 22229 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 23147 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 22230 | 23148 | buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", |
| 22231 | 23149 | buf_ptr(&result_elem_type->name))); |
| 22232 | | add_error_note(ira->codegen, msg, first_non_const_instruction->source_node, |
| 23150 | add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node, |
| 22233 | 23151 | buf_sprintf("this value is not comptime-known")); |
| 22234 | | return ira->codegen->invalid_instruction; |
| 23152 | return ira->codegen->invalid_inst_gen; |
| 22235 | 23153 | } |
| 22236 | 23154 | return result; |
| 22237 | 23155 | } |
| 22238 | 23156 | |
| 22239 | | static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 22240 | | IrInstructionContainerInitFields *instruction) |
| 23157 | static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 23158 | IrInstSrcContainerInitFields *instruction) |
| 22241 | 23159 | { |
| 22242 | | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 22243 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 23160 | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 23161 | IrInstGen *result_loc = instruction->result_loc->child; |
| 22244 | 23162 | if (type_is_invalid(result_loc->value->type)) |
| 22245 | 23163 | return result_loc; |
| 22246 | 23164 | |
| 22247 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 23165 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 22248 | 23166 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 22249 | 23167 | |
| 22250 | | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 23168 | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, |
| 22251 | 23169 | instruction->field_count, instruction->fields, result_loc); |
| 22252 | 23170 | } |
| 22253 | 23171 | |
| 22254 | | static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 22255 | | IrInstructionCompileErr *instruction) |
| 22256 | | { |
| 22257 | | IrInstruction *msg_value = instruction->msg->child; |
| 23172 | static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) { |
| 23173 | IrInstGen *msg_value = instruction->msg->child; |
| 22258 | 23174 | Buf *msg_buf = ir_resolve_str(ira, msg_value); |
| 22259 | 23175 | if (!msg_buf) |
| 22260 | | return ira->codegen->invalid_instruction; |
| 23176 | return ira->codegen->invalid_inst_gen; |
| 22261 | 23177 | |
| 22262 | | ir_add_error(ira, &instruction->base, msg_buf); |
| 23178 | ir_add_error(ira, &instruction->base.base, msg_buf); |
| 22263 | 23179 | |
| 22264 | | return ira->codegen->invalid_instruction; |
| 23180 | return ira->codegen->invalid_inst_gen; |
| 22265 | 23181 | } |
| 22266 | 23182 | |
| 22267 | | static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { |
| 23183 | static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) { |
| 22268 | 23184 | Buf buf = BUF_INIT; |
| 22269 | 23185 | fprintf(stderr, "| "); |
| 22270 | 23186 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| 22271 | | IrInstruction *msg = instruction->msg_list[i]->child; |
| 23187 | IrInstGen *msg = instruction->msg_list[i]->child; |
| 22272 | 23188 | if (type_is_invalid(msg->value->type)) |
| 22273 | | return ira->codegen->invalid_instruction; |
| 23189 | return ira->codegen->invalid_inst_gen; |
| 22274 | 23190 | buf_resize(&buf, 0); |
| 22275 | 23191 | if (msg->value->special == ConstValSpecialLazy) { |
| 22276 | 23192 | // 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; |
| 23193 | if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value)) |
| 23194 | return ira->codegen->invalid_inst_gen; |
| 22279 | 23195 | } |
| 22280 | 23196 | render_const_value(ira->codegen, &buf, msg->value); |
| 22281 | 23197 | const char *comma_str = (i != 0) ? ", " : ""; |
| ... | ... | @@ -22283,25 +23199,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 22283 | 23199 | } |
| 22284 | 23200 | fprintf(stderr, "\n"); |
| 22285 | 23201 | |
| 22286 | | auto *expr = &instruction->base.source_node->data.fn_call_expr; |
| 23202 | auto *expr = &instruction->base.base.source_node->data.fn_call_expr; |
| 22287 | 23203 | if (!expr->seen) { |
| 22288 | 23204 | // Here we bypass higher level functions such as ir_add_error because we do not want |
| 22289 | 23205 | // invalidate_exec to be called. |
| 22290 | | add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement")); |
| 23206 | add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement")); |
| 22291 | 23207 | } |
| 22292 | 23208 | expr->seen = true; |
| 22293 | 23209 | |
| 22294 | | return ir_const_void(ira, &instruction->base); |
| 23210 | return ir_const_void(ira, &instruction->base.base); |
| 22295 | 23211 | } |
| 22296 | 23212 | |
| 22297 | | static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 22298 | | IrInstruction *value = instruction->value->child; |
| 23213 | static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) { |
| 23214 | IrInstGen *value = instruction->value->child; |
| 22299 | 23215 | if (type_is_invalid(value->value->type)) |
| 22300 | | return ira->codegen->invalid_instruction; |
| 23216 | return ira->codegen->invalid_inst_gen; |
| 22301 | 23217 | |
| 22302 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 23218 | IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 22303 | 23219 | if (type_is_invalid(casted_value->value->type)) |
| 22304 | | return ira->codegen->invalid_instruction; |
| 23220 | return ira->codegen->invalid_inst_gen; |
| 22305 | 23221 | |
| 22306 | 23222 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 22307 | 23223 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| ... | ... | @@ -22309,13 +23225,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 22309 | 23225 | if (instr_is_comptime(casted_value)) { |
| 22310 | 23226 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 22311 | 23227 | if (val == nullptr) |
| 22312 | | return ira->codegen->invalid_instruction; |
| 23228 | return ira->codegen->invalid_inst_gen; |
| 22313 | 23229 | ErrorTableEntry *err = casted_value->value->data.x_err_set; |
| 22314 | 23230 | if (!err->cached_error_name_val) { |
| 22315 | 23231 | ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; |
| 22316 | 23232 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 22317 | 23233 | } |
| 22318 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23234 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22319 | 23235 | copy_const_val(result->value, err->cached_error_name_val); |
| 22320 | 23236 | result->value->type = str_type; |
| 22321 | 23237 | return result; |
| ... | ... | @@ -22323,20 +23239,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 22323 | 23239 | |
| 22324 | 23240 | ira->codegen->generate_error_name_table = true; |
| 22325 | 23241 | |
| 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; |
| 23242 | return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type); |
| 22330 | 23243 | } |
| 22331 | 23244 | |
| 22332 | | static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 23245 | static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) { |
| 22333 | 23246 | Error err; |
| 22334 | | IrInstruction *target = instruction->target->child; |
| 23247 | IrInstGen *target = instruction->target->child; |
| 22335 | 23248 | if (type_is_invalid(target->value->type)) |
| 22336 | | return ira->codegen->invalid_instruction; |
| 23249 | return ira->codegen->invalid_inst_gen; |
| 22337 | 23250 | |
| 22338 | 23251 | if (target->value->type->id == ZigTypeIdEnumLiteral) { |
| 22339 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23252 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22340 | 23253 | Buf *field_name = target->value->data.x_enum_literal; |
| 22341 | 23254 | ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee; |
| 22342 | 23255 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true); |
| ... | ... | @@ -22344,9 +23257,9 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 22344 | 23257 | } |
| 22345 | 23258 | |
| 22346 | 23259 | if (target->value->type->id == ZigTypeIdUnion) { |
| 22347 | | target = ir_analyze_union_tag(ira, &instruction->base, target); |
| 23260 | target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen); |
| 22348 | 23261 | if (type_is_invalid(target->value->type)) |
| 22349 | | return ira->codegen->invalid_instruction; |
| 23262 | return ira->codegen->invalid_inst_gen; |
| 22350 | 23263 | } |
| 22351 | 23264 | |
| 22352 | 23265 | if (target->value->type->id != ZigTypeIdEnum) { |
| ... | ... | @@ -22359,75 +23272,73 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 22359 | 23272 | !target->value->type->data.enumeration.non_exhaustive) { |
| 22360 | 23273 | TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0]; |
| 22361 | 23274 | ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee; |
| 22362 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23275 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22363 | 23276 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true); |
| 22364 | 23277 | return result; |
| 22365 | 23278 | } |
| 22366 | 23279 | |
| 22367 | 23280 | if (instr_is_comptime(target)) { |
| 22368 | 23281 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 22369 | | return ira->codegen->invalid_instruction; |
| 23282 | return ira->codegen->invalid_inst_gen; |
| 22370 | 23283 | if (target->value->type->data.enumeration.non_exhaustive) { |
| 22371 | | add_node_error(ira->codegen, instruction->base.source_node, |
| 23284 | ir_add_error(ira, &instruction->base.base, |
| 22372 | 23285 | buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991")); |
| 22373 | | return ira->codegen->invalid_instruction; |
| 23286 | return ira->codegen->invalid_inst_gen; |
| 22374 | 23287 | } |
| 22375 | 23288 | TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); |
| 22376 | 23289 | ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 22377 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 23290 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 22378 | 23291 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true); |
| 22379 | 23292 | return result; |
| 22380 | 23293 | } |
| 22381 | 23294 | |
| 22382 | | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, |
| 22383 | | instruction->base.source_node, target); |
| 22384 | 23295 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 22385 | 23296 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 22386 | 23297 | true, false, PtrLenUnknown, |
| 22387 | 23298 | 0, 0, 0, false); |
| 22388 | | result->value->type = get_slice_type(ira->codegen, u8_ptr_type); |
| 22389 | | return result; |
| 23299 | ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 23300 | return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type); |
| 22390 | 23301 | } |
| 22391 | 23302 | |
| 22392 | | static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22393 | | IrInstructionFieldParentPtr *instruction) |
| 23303 | static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 23304 | IrInstSrcFieldParentPtr *instruction) |
| 22394 | 23305 | { |
| 22395 | 23306 | Error err; |
| 22396 | | IrInstruction *type_value = instruction->type_value->child; |
| 23307 | IrInstGen *type_value = instruction->type_value->child; |
| 22397 | 23308 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| 22398 | 23309 | if (type_is_invalid(container_type)) |
| 22399 | | return ira->codegen->invalid_instruction; |
| 23310 | return ira->codegen->invalid_inst_gen; |
| 22400 | 23311 | |
| 22401 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23312 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22402 | 23313 | Buf *field_name = ir_resolve_str(ira, field_name_value); |
| 22403 | 23314 | if (!field_name) |
| 22404 | | return ira->codegen->invalid_instruction; |
| 23315 | return ira->codegen->invalid_inst_gen; |
| 22405 | 23316 | |
| 22406 | | IrInstruction *field_ptr = instruction->field_ptr->child; |
| 23317 | IrInstGen *field_ptr = instruction->field_ptr->child; |
| 22407 | 23318 | if (type_is_invalid(field_ptr->value->type)) |
| 22408 | | return ira->codegen->invalid_instruction; |
| 23319 | return ira->codegen->invalid_inst_gen; |
| 22409 | 23320 | |
| 22410 | 23321 | if (container_type->id != ZigTypeIdStruct) { |
| 22411 | | ir_add_error(ira, type_value, |
| 23322 | ir_add_error(ira, &type_value->base, |
| 22412 | 23323 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 22413 | | return ira->codegen->invalid_instruction; |
| 23324 | return ira->codegen->invalid_inst_gen; |
| 22414 | 23325 | } |
| 22415 | 23326 | |
| 22416 | 23327 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 22417 | | return ira->codegen->invalid_instruction; |
| 23328 | return ira->codegen->invalid_inst_gen; |
| 22418 | 23329 | |
| 22419 | 23330 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 22420 | 23331 | if (field == nullptr) { |
| 22421 | | ir_add_error(ira, field_name_value, |
| 23332 | ir_add_error(ira, &field_name_value->base, |
| 22422 | 23333 | buf_sprintf("struct '%s' has no field '%s'", |
| 22423 | 23334 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 22424 | | return ira->codegen->invalid_instruction; |
| 23335 | return ira->codegen->invalid_inst_gen; |
| 22425 | 23336 | } |
| 22426 | 23337 | |
| 22427 | 23338 | if (field_ptr->value->type->id != ZigTypeIdPointer) { |
| 22428 | | ir_add_error(ira, field_ptr, |
| 23339 | ir_add_error(ira, &field_ptr->base, |
| 22429 | 23340 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); |
| 22430 | | return ira->codegen->invalid_instruction; |
| 23341 | return ira->codegen->invalid_inst_gen; |
| 22431 | 23342 | } |
| 22432 | 23343 | |
| 22433 | 23344 | bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked); |
| ... | ... | @@ -22439,9 +23350,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22439 | 23350 | field_ptr->value->type->data.pointer.is_volatile, |
| 22440 | 23351 | PtrLenSingle, |
| 22441 | 23352 | field_ptr_align, 0, 0, false); |
| 22442 | | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 23353 | IrInstGen *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 22443 | 23354 | if (type_is_invalid(casted_field_ptr->value->type)) |
| 22444 | | return ira->codegen->invalid_instruction; |
| 23355 | return ira->codegen->invalid_inst_gen; |
| 22445 | 23356 | |
| 22446 | 23357 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 22447 | 23358 | casted_field_ptr->value->type->data.pointer.is_const, |
| ... | ... | @@ -22452,23 +23363,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22452 | 23363 | if (instr_is_comptime(casted_field_ptr)) { |
| 22453 | 23364 | ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| 22454 | 23365 | if (!field_ptr_val) |
| 22455 | | return ira->codegen->invalid_instruction; |
| 23366 | return ira->codegen->invalid_inst_gen; |
| 22456 | 23367 | |
| 22457 | 23368 | if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) { |
| 22458 | | ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct")); |
| 22459 | | return ira->codegen->invalid_instruction; |
| 23369 | ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct")); |
| 23370 | return ira->codegen->invalid_inst_gen; |
| 22460 | 23371 | } |
| 22461 | 23372 | |
| 22462 | 23373 | size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; |
| 22463 | 23374 | if (ptr_field_index != field->src_index) { |
| 22464 | | ir_add_error(ira, &instruction->base, |
| 23375 | ir_add_error(ira, &instruction->base.base, |
| 22465 | 23376 | buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", |
| 22466 | 23377 | buf_ptr(field->name), field->src_index, |
| 22467 | 23378 | ptr_field_index, buf_ptr(&container_type->name))); |
| 22468 | | return ira->codegen->invalid_instruction; |
| 23379 | return ira->codegen->invalid_inst_gen; |
| 22469 | 23380 | } |
| 22470 | 23381 | |
| 22471 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 23382 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 22472 | 23383 | ZigValue *out_val = result->value; |
| 22473 | 23384 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 22474 | 23385 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| ... | ... | @@ -22476,15 +23387,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 22476 | 23387 | return result; |
| 22477 | 23388 | } |
| 22478 | 23389 | |
| 22479 | | IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, |
| 22480 | | instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); |
| 22481 | | result->value->type = result_type; |
| 22482 | | return result; |
| 23390 | return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type); |
| 22483 | 23391 | } |
| 22484 | 23392 | |
| 22485 | 23393 | static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22486 | | IrInstruction *type_value, |
| 22487 | | IrInstruction *field_name_value, |
| 23394 | IrInstGen *type_value, |
| 23395 | IrInstGen *field_name_value, |
| 22488 | 23396 | size_t *byte_offset) |
| 22489 | 23397 | { |
| 22490 | 23398 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -22500,21 +23408,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22500 | 23408 | return nullptr; |
| 22501 | 23409 | |
| 22502 | 23410 | if (container_type->id != ZigTypeIdStruct) { |
| 22503 | | ir_add_error(ira, type_value, |
| 23411 | ir_add_error(ira, &type_value->base, |
| 22504 | 23412 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 22505 | 23413 | return nullptr; |
| 22506 | 23414 | } |
| 22507 | 23415 | |
| 22508 | 23416 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 22509 | 23417 | if (field == nullptr) { |
| 22510 | | ir_add_error(ira, field_name_value, |
| 23418 | ir_add_error(ira, &field_name_value->base, |
| 22511 | 23419 | buf_sprintf("struct '%s' has no field '%s'", |
| 22512 | 23420 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 22513 | 23421 | return nullptr; |
| 22514 | 23422 | } |
| 22515 | 23423 | |
| 22516 | 23424 | if (!type_has_bits(field->type_entry)) { |
| 22517 | | ir_add_error(ira, field_name_value, |
| 23425 | ir_add_error(ira, &field_name_value->base, |
| 22518 | 23426 | buf_sprintf("zero-bit field '%s' in struct '%s' has no offset", |
| 22519 | 23427 | buf_ptr(field_name), buf_ptr(&container_type->name))); |
| 22520 | 23428 | return nullptr; |
| ... | ... | @@ -22524,36 +23432,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 22524 | 23432 | return field; |
| 22525 | 23433 | } |
| 22526 | 23434 | |
| 22527 | | static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 22528 | | IrInstructionByteOffsetOf *instruction) |
| 22529 | | { |
| 22530 | | IrInstruction *type_value = instruction->type_value->child; |
| 23435 | static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) { |
| 23436 | IrInstGen *type_value = instruction->type_value->child; |
| 22531 | 23437 | if (type_is_invalid(type_value->value->type)) |
| 22532 | | return ira->codegen->invalid_instruction; |
| 23438 | return ira->codegen->invalid_inst_gen; |
| 22533 | 23439 | |
| 22534 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23440 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22535 | 23441 | size_t byte_offset = 0; |
| 22536 | 23442 | if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset)) |
| 22537 | | return ira->codegen->invalid_instruction; |
| 23443 | return ira->codegen->invalid_inst_gen; |
| 22538 | 23444 | |
| 22539 | 23445 | |
| 22540 | | return ir_const_unsigned(ira, &instruction->base, byte_offset); |
| 23446 | return ir_const_unsigned(ira, &instruction->base.base, byte_offset); |
| 22541 | 23447 | } |
| 22542 | 23448 | |
| 22543 | | static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 22544 | | IrInstructionBitOffsetOf *instruction) |
| 22545 | | { |
| 22546 | | IrInstruction *type_value = instruction->type_value->child; |
| 23449 | static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) { |
| 23450 | IrInstGen *type_value = instruction->type_value->child; |
| 22547 | 23451 | if (type_is_invalid(type_value->value->type)) |
| 22548 | | return ira->codegen->invalid_instruction; |
| 22549 | | IrInstruction *field_name_value = instruction->field_name->child; |
| 23452 | return ira->codegen->invalid_inst_gen; |
| 23453 | IrInstGen *field_name_value = instruction->field_name->child; |
| 22550 | 23454 | size_t byte_offset = 0; |
| 22551 | 23455 | TypeStructField *field = nullptr; |
| 22552 | 23456 | if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset))) |
| 22553 | | return ira->codegen->invalid_instruction; |
| 23457 | return ira->codegen->invalid_inst_gen; |
| 22554 | 23458 | |
| 22555 | 23459 | size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host; |
| 22556 | | return ir_const_unsigned(ira, &instruction->base, bit_offset); |
| 23460 | return ir_const_unsigned(ira, &instruction->base.base, bit_offset); |
| 22557 | 23461 | } |
| 22558 | 23462 | |
| 22559 | 23463 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { |
| ... | ... | @@ -22601,7 +23505,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig |
| 22601 | 23505 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); |
| 22602 | 23506 | } |
| 22603 | 23507 | |
| 22604 | | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val, |
| 23508 | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val, |
| 22605 | 23509 | ScopeDecls *decls_scope) |
| 22606 | 23510 | { |
| 22607 | 23511 | Error err; |
| ... | ... | @@ -22959,7 +23863,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn |
| 22959 | 23863 | enum_field_val->data.x_struct.fields = inner_fields; |
| 22960 | 23864 | } |
| 22961 | 23865 | |
| 22962 | | static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 23866 | static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 22963 | 23867 | ZigValue **out) |
| 22964 | 23868 | { |
| 22965 | 23869 | Error err; |
| ... | ... | @@ -23547,22 +24451,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 23547 | 24451 | return ErrorNone; |
| 23548 | 24452 | } |
| 23549 | 24453 | |
| 23550 | | static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 23551 | | IrInstructionTypeInfo *instruction) |
| 23552 | | { |
| 24454 | static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) { |
| 23553 | 24455 | Error err; |
| 23554 | | IrInstruction *type_value = instruction->type_value->child; |
| 24456 | IrInstGen *type_value = instruction->type_value->child; |
| 23555 | 24457 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23556 | 24458 | if (type_is_invalid(type_entry)) |
| 23557 | | return ira->codegen->invalid_instruction; |
| 24459 | return ira->codegen->invalid_inst_gen; |
| 23558 | 24460 | |
| 23559 | 24461 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 23560 | 24462 | |
| 23561 | 24463 | ZigValue *payload; |
| 23562 | | if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload))) |
| 23563 | | return ira->codegen->invalid_instruction; |
| 24464 | if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload))) |
| 24465 | return ira->codegen->invalid_inst_gen; |
| 23564 | 24466 | |
| 23565 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 24467 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 23566 | 24468 | ZigValue *out_val = result->value; |
| 23567 | 24469 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 23568 | 24470 | out_val->data.x_union.payload = payload; |
| ... | ... | @@ -23586,15 +24488,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue |
| 23586 | 24488 | return val; |
| 23587 | 24489 | } |
| 23588 | 24490 | |
| 23589 | | static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value, |
| 24491 | static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value, |
| 23590 | 24492 | const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) |
| 23591 | 24493 | { |
| 23592 | 24494 | ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index); |
| 23593 | 24495 | if (field_val == nullptr) |
| 23594 | 24496 | return ErrorSemanticAnalyzeFail; |
| 23595 | 24497 | |
| 23596 | | IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val); |
| 23597 | | IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 24498 | IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val); |
| 24499 | IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 23598 | 24500 | get_optional_type(ira->codegen, elem_type)); |
| 23599 | 24501 | if (type_is_invalid(casted_field_inst->value->type)) |
| 23600 | 24502 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -23633,12 +24535,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, |
| 23633 | 24535 | { |
| 23634 | 24536 | ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index); |
| 23635 | 24537 | if (value == nullptr) |
| 23636 | | return ira->codegen->invalid_instruction->value->type; |
| 24538 | return ira->codegen->invalid_inst_gen->value->type; |
| 23637 | 24539 | assert(value->type == ira->codegen->builtin_types.entry_type); |
| 23638 | 24540 | return value->data.x_type; |
| 23639 | 24541 | } |
| 23640 | 24542 | |
| 23641 | | static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) { |
| 24543 | static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) { |
| 23642 | 24544 | Error err; |
| 23643 | 24545 | switch (tagTypeId) { |
| 23644 | 24546 | case ZigTypeIdInvalid: |
| ... | ... | @@ -23654,21 +24556,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23654 | 24556 | case ZigTypeIdInt: { |
| 23655 | 24557 | assert(payload->special == ConstValSpecialStatic); |
| 23656 | 24558 | assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr)); |
| 23657 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1); |
| 24559 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1); |
| 23658 | 24560 | if (bi == nullptr) |
| 23659 | | return ira->codegen->invalid_instruction->value->type; |
| 24561 | return ira->codegen->invalid_inst_gen->value->type; |
| 23660 | 24562 | bool is_signed; |
| 23661 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed))) |
| 23662 | | return ira->codegen->invalid_instruction->value->type; |
| 24563 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed))) |
| 24564 | return ira->codegen->invalid_inst_gen->value->type; |
| 23663 | 24565 | return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi)); |
| 23664 | 24566 | } |
| 23665 | 24567 | case ZigTypeIdFloat: |
| 23666 | 24568 | { |
| 23667 | 24569 | assert(payload->special == ConstValSpecialStatic); |
| 23668 | 24570 | assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr)); |
| 23669 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0); |
| 24571 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0); |
| 23670 | 24572 | if (bi == nullptr) |
| 23671 | | return ira->codegen->invalid_instruction->value->type; |
| 24573 | return ira->codegen->invalid_inst_gen->value->type; |
| 23672 | 24574 | uint32_t bits = bigint_as_u32(bi); |
| 23673 | 24575 | switch (bits) { |
| 23674 | 24576 | case 16: return ira->codegen->builtin_types.entry_f16; |
| ... | ... | @@ -23676,48 +24578,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23676 | 24578 | case 64: return ira->codegen->builtin_types.entry_f64; |
| 23677 | 24579 | case 128: return ira->codegen->builtin_types.entry_f128; |
| 23678 | 24580 | } |
| 23679 | | ir_add_error(ira, instruction, |
| 23680 | | buf_sprintf("%d-bit float unsupported", bits)); |
| 23681 | | return ira->codegen->invalid_instruction->value->type; |
| 24581 | ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits)); |
| 24582 | return ira->codegen->invalid_inst_gen->value->type; |
| 23682 | 24583 | } |
| 23683 | 24584 | case ZigTypeIdPointer: |
| 23684 | 24585 | { |
| 23685 | 24586 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 23686 | 24587 | assert(payload->special == ConstValSpecialStatic); |
| 23687 | 24588 | assert(payload->type == type_info_pointer_type); |
| 23688 | | ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0); |
| 24589 | ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0); |
| 23689 | 24590 | assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); |
| 23690 | 24591 | BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); |
| 23691 | 24592 | PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); |
| 23692 | | ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4); |
| 24593 | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4); |
| 23693 | 24594 | if (type_is_invalid(elem_type)) |
| 23694 | | return ira->codegen->invalid_instruction->value->type; |
| 24595 | return ira->codegen->invalid_inst_gen->value->type; |
| 23695 | 24596 | ZigValue *sentinel; |
| 23696 | | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, |
| 24597 | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6, |
| 23697 | 24598 | elem_type, &sentinel))) |
| 23698 | 24599 | { |
| 23699 | | return ira->codegen->invalid_instruction->value->type; |
| 24600 | return ira->codegen->invalid_inst_gen->value->type; |
| 23700 | 24601 | } |
| 23701 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3); |
| 24602 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3); |
| 23702 | 24603 | if (bi == nullptr) |
| 23703 | | return ira->codegen->invalid_instruction->value->type; |
| 24604 | return ira->codegen->invalid_inst_gen->value->type; |
| 23704 | 24605 | |
| 23705 | 24606 | bool is_const; |
| 23706 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const))) |
| 23707 | | return ira->codegen->invalid_instruction->value->type; |
| 24607 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const))) |
| 24608 | return ira->codegen->invalid_inst_gen->value->type; |
| 23708 | 24609 | |
| 23709 | 24610 | bool is_volatile; |
| 23710 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2, |
| 24611 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2, |
| 23711 | 24612 | &is_volatile))) |
| 23712 | 24613 | { |
| 23713 | | return ira->codegen->invalid_instruction->value->type; |
| 24614 | return ira->codegen->invalid_inst_gen->value->type; |
| 23714 | 24615 | } |
| 23715 | 24616 | |
| 23716 | 24617 | bool is_allowzero; |
| 23717 | | if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5, |
| 24618 | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5, |
| 23718 | 24619 | &is_allowzero))) |
| 23719 | 24620 | { |
| 23720 | | return ira->codegen->invalid_instruction->value->type; |
| 24621 | return ira->codegen->invalid_inst_gen->value->type; |
| 23721 | 24622 | } |
| 23722 | 24623 | |
| 23723 | 24624 | |
| ... | ... | @@ -23738,18 +24639,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23738 | 24639 | case ZigTypeIdArray: { |
| 23739 | 24640 | assert(payload->special == ConstValSpecialStatic); |
| 23740 | 24641 | assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); |
| 23741 | | ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1); |
| 24642 | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1); |
| 23742 | 24643 | if (type_is_invalid(elem_type)) |
| 23743 | | return ira->codegen->invalid_instruction->value->type; |
| 24644 | return ira->codegen->invalid_inst_gen->value->type; |
| 23744 | 24645 | ZigValue *sentinel; |
| 23745 | | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, |
| 24646 | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2, |
| 23746 | 24647 | elem_type, &sentinel))) |
| 23747 | 24648 | { |
| 23748 | | return ira->codegen->invalid_instruction->value->type; |
| 24649 | return ira->codegen->invalid_inst_gen->value->type; |
| 23749 | 24650 | } |
| 23750 | | BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0); |
| 24651 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0); |
| 23751 | 24652 | if (bi == nullptr) |
| 23752 | | return ira->codegen->invalid_instruction->value->type; |
| 24653 | return ira->codegen->invalid_inst_gen->value->type; |
| 23753 | 24654 | return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel); |
| 23754 | 24655 | } |
| 23755 | 24656 | case ZigTypeIdComptimeFloat: |
| ... | ... | @@ -23769,78 +24670,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 23769 | 24670 | case ZigTypeIdAnyFrame: |
| 23770 | 24671 | case ZigTypeIdVector: |
| 23771 | 24672 | case ZigTypeIdEnumLiteral: |
| 23772 | | ir_add_error(ira, instruction, buf_sprintf( |
| 24673 | ir_add_error(ira, source_instr, buf_sprintf( |
| 23773 | 24674 | "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId))); |
| 23774 | | return ira->codegen->invalid_instruction->value->type; |
| 24675 | return ira->codegen->invalid_inst_gen->value->type; |
| 23775 | 24676 | case ZigTypeIdUnion: |
| 23776 | 24677 | case ZigTypeIdFn: |
| 23777 | 24678 | case ZigTypeIdBoundFn: |
| 23778 | 24679 | case ZigTypeIdStruct: |
| 23779 | | ir_add_error(ira, instruction, buf_sprintf( |
| 24680 | ir_add_error(ira, source_instr, buf_sprintf( |
| 23780 | 24681 | "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId))); |
| 23781 | | return ira->codegen->invalid_instruction->value->type; |
| 24682 | return ira->codegen->invalid_inst_gen->value->type; |
| 23782 | 24683 | } |
| 23783 | 24684 | zig_unreachable(); |
| 23784 | 24685 | } |
| 23785 | 24686 | |
| 23786 | | static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) { |
| 23787 | | IrInstruction *type_info_ir = instruction->type_info->child; |
| 23788 | | if (type_is_invalid(type_info_ir->value->type)) |
| 23789 | | return ira->codegen->invalid_instruction; |
| 24687 | static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) { |
| 24688 | IrInstGen *uncasted_type_info = instruction->type_info->child; |
| 24689 | if (type_is_invalid(uncasted_type_info->value->type)) |
| 24690 | return ira->codegen->invalid_inst_gen; |
| 23790 | 24691 | |
| 23791 | | IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 23792 | | if (type_is_invalid(casted_ir->value->type)) |
| 23793 | | return ira->codegen->invalid_instruction; |
| 24692 | IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 24693 | if (type_is_invalid(type_info->value->type)) |
| 24694 | return ira->codegen->invalid_inst_gen; |
| 23794 | 24695 | |
| 23795 | | ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); |
| 23796 | | if (!type_info_value) |
| 23797 | | return ira->codegen->invalid_instruction; |
| 23798 | | ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag)); |
| 23799 | | ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload); |
| 24696 | ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad); |
| 24697 | if (type_info_val == nullptr) |
| 24698 | return ira->codegen->invalid_inst_gen; |
| 24699 | ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag)); |
| 24700 | ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag, |
| 24701 | type_info_val->data.x_union.payload); |
| 23800 | 24702 | if (type_is_invalid(type)) |
| 23801 | | return ira->codegen->invalid_instruction; |
| 23802 | | return ir_const_type(ira, &instruction->base, type); |
| 24703 | return ira->codegen->invalid_inst_gen; |
| 24704 | return ir_const_type(ira, &instruction->base.base, type); |
| 23803 | 24705 | } |
| 23804 | 24706 | |
| 23805 | | static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 23806 | | IrInstructionTypeId *instruction) |
| 23807 | | { |
| 23808 | | IrInstruction *type_value = instruction->type_value->child; |
| 24707 | static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) { |
| 24708 | IrInstGen *type_value = instruction->type_value->child; |
| 23809 | 24709 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23810 | 24710 | if (type_is_invalid(type_entry)) |
| 23811 | | return ira->codegen->invalid_instruction; |
| 24711 | return ira->codegen->invalid_inst_gen; |
| 23812 | 24712 | |
| 23813 | 24713 | ZigType *result_type = get_builtin_type(ira->codegen, "TypeId"); |
| 23814 | 24714 | |
| 23815 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 24715 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 23816 | 24716 | bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry)); |
| 23817 | 24717 | return result; |
| 23818 | 24718 | } |
| 23819 | 24719 | |
| 23820 | | static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 23821 | | IrInstructionSetEvalBranchQuota *instruction) |
| 24720 | static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 24721 | IrInstSrcSetEvalBranchQuota *instruction) |
| 23822 | 24722 | { |
| 23823 | 24723 | uint64_t new_quota; |
| 23824 | 24724 | if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota)) |
| 23825 | | return ira->codegen->invalid_instruction; |
| 24725 | return ira->codegen->invalid_inst_gen; |
| 23826 | 24726 | |
| 23827 | 24727 | if (new_quota > *ira->new_irb.exec->backward_branch_quota) { |
| 23828 | 24728 | *ira->new_irb.exec->backward_branch_quota = new_quota; |
| 23829 | 24729 | } |
| 23830 | 24730 | |
| 23831 | | return ir_const_void(ira, &instruction->base); |
| 24731 | return ir_const_void(ira, &instruction->base.base); |
| 23832 | 24732 | } |
| 23833 | 24733 | |
| 23834 | | static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 23835 | | IrInstruction *type_value = instruction->type_value->child; |
| 24734 | static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) { |
| 24735 | IrInstGen *type_value = instruction->type_value->child; |
| 23836 | 24736 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 23837 | 24737 | if (type_is_invalid(type_entry)) |
| 23838 | | return ira->codegen->invalid_instruction; |
| 24738 | return ira->codegen->invalid_inst_gen; |
| 23839 | 24739 | |
| 23840 | 24740 | if (!type_entry->cached_const_name_val) { |
| 23841 | 24741 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 23842 | 24742 | } |
| 23843 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24743 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 23844 | 24744 | copy_const_val(result->value, type_entry->cached_const_name_val); |
| 23845 | 24745 | return result; |
| 23846 | 24746 | } |
| ... | ... | @@ -23852,13 +24752,13 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf * |
| 23852 | 24752 | buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest)); |
| 23853 | 24753 | buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir)); |
| 23854 | 24754 | } |
| 23855 | | static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { |
| 24755 | static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) { |
| 23856 | 24756 | Error err; |
| 23857 | | AstNode *node = instruction->base.source_node; |
| 24757 | AstNode *node = instruction->base.base.source_node; |
| 23858 | 24758 | assert(node->type == NodeTypeFnCallExpr); |
| 23859 | 24759 | AstNode *block_node = node->data.fn_call_expr.params.at(0); |
| 23860 | 24760 | |
| 23861 | | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope); |
| 24761 | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope); |
| 23862 | 24762 | |
| 23863 | 24763 | // Execute the C import block like an inline function |
| 23864 | 24764 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| ... | ... | @@ -23866,9 +24766,9 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23866 | 24766 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 23867 | 24767 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); |
| 23868 | 24768 | if (type_is_invalid(cimport_result->type)) |
| 23869 | | return ira->codegen->invalid_instruction; |
| 24769 | return ira->codegen->invalid_inst_gen; |
| 23870 | 24770 | |
| 23871 | | ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope); |
| 24771 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope); |
| 23872 | 24772 | Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize, |
| 23873 | 24773 | buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1); |
| 23874 | 24774 | |
| ... | ... | @@ -23880,7 +24780,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23880 | 24780 | CacheHash *cache_hash; |
| 23881 | 24781 | if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) { |
| 23882 | 24782 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err))); |
| 23883 | | return ira->codegen->invalid_instruction; |
| 24783 | return ira->codegen->invalid_inst_gen; |
| 23884 | 24784 | } |
| 23885 | 24785 | cache_buf(cache_hash, &cimport_scope->buf); |
| 23886 | 24786 | |
| ... | ... | @@ -23892,7 +24792,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23892 | 24792 | if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) { |
| 23893 | 24793 | if (err != ErrorInvalidFormat) { |
| 23894 | 24794 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err))); |
| 23895 | | return ira->codegen->invalid_instruction; |
| 24795 | return ira->codegen->invalid_inst_gen; |
| 23896 | 24796 | } |
| 23897 | 24797 | } |
| 23898 | 24798 | ira->codegen->caches_to_release.append(cache_hash); |
| ... | ... | @@ -23911,12 +24811,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23911 | 24811 | |
| 23912 | 24812 | if ((err = os_make_path(tmp_c_file_dir))) { |
| 23913 | 24813 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err))); |
| 23914 | | return ira->codegen->invalid_instruction; |
| 24814 | return ira->codegen->invalid_inst_gen; |
| 23915 | 24815 | } |
| 23916 | 24816 | |
| 23917 | 24817 | if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) { |
| 23918 | 24818 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err))); |
| 23919 | | return ira->codegen->invalid_instruction; |
| 24819 | return ira->codegen->invalid_inst_gen; |
| 23920 | 24820 | } |
| 23921 | 24821 | if (ira->codegen->verbose_cimport) { |
| 23922 | 24822 | fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path)); |
| ... | ... | @@ -23951,7 +24851,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23951 | 24851 | { |
| 23952 | 24852 | if (err != ErrorCCompileErrors) { |
| 23953 | 24853 | ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err))); |
| 23954 | | return ira->codegen->invalid_instruction; |
| 24854 | return ira->codegen->invalid_inst_gen; |
| 23955 | 24855 | } |
| 23956 | 24856 | |
| 23957 | 24857 | ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed")); |
| ... | ... | @@ -23972,7 +24872,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23972 | 24872 | } |
| 23973 | 24873 | } |
| 23974 | 24874 | |
| 23975 | | return ira->codegen->invalid_instruction; |
| 24875 | return ira->codegen->invalid_inst_gen; |
| 23976 | 24876 | } |
| 23977 | 24877 | if (ira->codegen->verbose_cimport) { |
| 23978 | 24878 | fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file)); |
| ... | ... | @@ -23980,29 +24880,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 23980 | 24880 | |
| 23981 | 24881 | if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) { |
| 23982 | 24882 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err))); |
| 23983 | | return ira->codegen->invalid_instruction; |
| 24883 | return ira->codegen->invalid_inst_gen; |
| 23984 | 24884 | } |
| 23985 | 24885 | if ((err = cache_final(cache_hash, &tmp_c_file_digest))) { |
| 23986 | 24886 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err))); |
| 23987 | | return ira->codegen->invalid_instruction; |
| 24887 | return ira->codegen->invalid_inst_gen; |
| 23988 | 24888 | } |
| 23989 | 24889 | |
| 23990 | 24890 | ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path); |
| 23991 | 24891 | if ((err = os_make_path(out_zig_dir))) { |
| 23992 | 24892 | ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err))); |
| 23993 | | return ira->codegen->invalid_instruction; |
| 24893 | return ira->codegen->invalid_inst_gen; |
| 23994 | 24894 | } |
| 23995 | 24895 | FILE *out_file = fopen(buf_ptr(out_zig_path), "wb"); |
| 23996 | 24896 | if (out_file == nullptr) { |
| 23997 | 24897 | ir_add_error_node(ira, node, |
| 23998 | 24898 | buf_sprintf("C import failed: unable to open output file: %s", strerror(errno))); |
| 23999 | | return ira->codegen->invalid_instruction; |
| 24899 | return ira->codegen->invalid_inst_gen; |
| 24000 | 24900 | } |
| 24001 | 24901 | stage2_render_ast(ast, out_file); |
| 24002 | 24902 | if (fclose(out_file) != 0) { |
| 24003 | 24903 | ir_add_error_node(ira, node, |
| 24004 | 24904 | buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno))); |
| 24005 | | return ira->codegen->invalid_instruction; |
| 24905 | return ira->codegen->invalid_inst_gen; |
| 24006 | 24906 | } |
| 24007 | 24907 | |
| 24008 | 24908 | if (ira->codegen->verbose_cimport) { |
| ... | ... | @@ -24021,90 +24921,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 24021 | 24921 | if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) { |
| 24022 | 24922 | ir_add_error_node(ira, node, |
| 24023 | 24923 | buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err))); |
| 24024 | | return ira->codegen->invalid_instruction; |
| 24924 | return ira->codegen->invalid_inst_gen; |
| 24025 | 24925 | } |
| 24026 | 24926 | ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path, |
| 24027 | 24927 | import_code, SourceKindCImport); |
| 24028 | | return ir_const_type(ira, &instruction->base, child_import); |
| 24928 | return ir_const_type(ira, &instruction->base.base, child_import); |
| 24029 | 24929 | } |
| 24030 | 24930 | |
| 24031 | | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 24032 | | IrInstruction *name_value = instruction->name->child; |
| 24931 | static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) { |
| 24932 | IrInstGen *name_value = instruction->name->child; |
| 24033 | 24933 | if (type_is_invalid(name_value->value->type)) |
| 24034 | | return ira->codegen->invalid_instruction; |
| 24934 | return ira->codegen->invalid_inst_gen; |
| 24035 | 24935 | |
| 24036 | 24936 | Buf *include_name = ir_resolve_str(ira, name_value); |
| 24037 | 24937 | if (!include_name) |
| 24038 | | return ira->codegen->invalid_instruction; |
| 24938 | return ira->codegen->invalid_inst_gen; |
| 24039 | 24939 | |
| 24040 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 24940 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24041 | 24941 | // We check for this error in pass1 |
| 24042 | 24942 | assert(c_import_buf); |
| 24043 | 24943 | |
| 24044 | 24944 | buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name)); |
| 24045 | 24945 | |
| 24046 | | return ir_const_void(ira, &instruction->base); |
| 24946 | return ir_const_void(ira, &instruction->base.base); |
| 24047 | 24947 | } |
| 24048 | 24948 | |
| 24049 | | static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 24050 | | IrInstruction *name = instruction->name->child; |
| 24949 | static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) { |
| 24950 | IrInstGen *name = instruction->name->child; |
| 24051 | 24951 | if (type_is_invalid(name->value->type)) |
| 24052 | | return ira->codegen->invalid_instruction; |
| 24952 | return ira->codegen->invalid_inst_gen; |
| 24053 | 24953 | |
| 24054 | 24954 | Buf *define_name = ir_resolve_str(ira, name); |
| 24055 | 24955 | if (!define_name) |
| 24056 | | return ira->codegen->invalid_instruction; |
| 24956 | return ira->codegen->invalid_inst_gen; |
| 24057 | 24957 | |
| 24058 | | IrInstruction *value = instruction->value->child; |
| 24958 | IrInstGen *value = instruction->value->child; |
| 24059 | 24959 | if (type_is_invalid(value->value->type)) |
| 24060 | | return ira->codegen->invalid_instruction; |
| 24960 | return ira->codegen->invalid_inst_gen; |
| 24061 | 24961 | |
| 24062 | 24962 | Buf *define_value = nullptr; |
| 24063 | 24963 | // The second parameter is either a string or void (equivalent to "") |
| 24064 | 24964 | if (value->value->type->id != ZigTypeIdVoid) { |
| 24065 | 24965 | define_value = ir_resolve_str(ira, value); |
| 24066 | 24966 | if (!define_value) |
| 24067 | | return ira->codegen->invalid_instruction; |
| 24967 | return ira->codegen->invalid_inst_gen; |
| 24068 | 24968 | } |
| 24069 | 24969 | |
| 24070 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 24970 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24071 | 24971 | // We check for this error in pass1 |
| 24072 | 24972 | assert(c_import_buf); |
| 24073 | 24973 | |
| 24074 | 24974 | buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), |
| 24075 | 24975 | define_value ? buf_ptr(define_value) : ""); |
| 24076 | 24976 | |
| 24077 | | return ir_const_void(ira, &instruction->base); |
| 24977 | return ir_const_void(ira, &instruction->base.base); |
| 24078 | 24978 | } |
| 24079 | 24979 | |
| 24080 | | static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 24081 | | IrInstruction *name = instruction->name->child; |
| 24980 | static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) { |
| 24981 | IrInstGen *name = instruction->name->child; |
| 24082 | 24982 | if (type_is_invalid(name->value->type)) |
| 24083 | | return ira->codegen->invalid_instruction; |
| 24983 | return ira->codegen->invalid_inst_gen; |
| 24084 | 24984 | |
| 24085 | 24985 | Buf *undef_name = ir_resolve_str(ira, name); |
| 24086 | 24986 | if (!undef_name) |
| 24087 | | return ira->codegen->invalid_instruction; |
| 24987 | return ira->codegen->invalid_inst_gen; |
| 24088 | 24988 | |
| 24089 | | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 24989 | Buf *c_import_buf = ira->new_irb.exec->c_import_buf; |
| 24090 | 24990 | // We check for this error in pass1 |
| 24091 | 24991 | assert(c_import_buf); |
| 24092 | 24992 | |
| 24093 | 24993 | buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name)); |
| 24094 | 24994 | |
| 24095 | | return ir_const_void(ira, &instruction->base); |
| 24995 | return ir_const_void(ira, &instruction->base.base); |
| 24096 | 24996 | } |
| 24097 | 24997 | |
| 24098 | | static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 24099 | | IrInstruction *name = instruction->name->child; |
| 24998 | static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) { |
| 24999 | IrInstGen *name = instruction->name->child; |
| 24100 | 25000 | if (type_is_invalid(name->value->type)) |
| 24101 | | return ira->codegen->invalid_instruction; |
| 25001 | return ira->codegen->invalid_inst_gen; |
| 24102 | 25002 | |
| 24103 | 25003 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| 24104 | 25004 | if (!rel_file_path) |
| 24105 | | return ira->codegen->invalid_instruction; |
| 25005 | return ira->codegen->invalid_inst_gen; |
| 24106 | 25006 | |
| 24107 | | ZigType *import = get_scope_import(instruction->base.scope); |
| 25007 | ZigType *import = get_scope_import(instruction->base.base.scope); |
| 24108 | 25008 | // figure out absolute path to resource |
| 24109 | 25009 | Buf source_dir_path = BUF_INIT; |
| 24110 | 25010 | os_path_dirname(import->data.structure.root_struct->path, &source_dir_path); |
| ... | ... | @@ -24121,93 +25021,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 24121 | 25021 | Error err; |
| 24122 | 25022 | if ((err = file_fetch(ira->codegen, file_path, file_contents))) { |
| 24123 | 25023 | if (err == ErrorFileNotFound) { |
| 24124 | | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 24125 | | return ira->codegen->invalid_instruction; |
| 25024 | ir_add_error(ira, &instruction->name->base, |
| 25025 | buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 25026 | return ira->codegen->invalid_inst_gen; |
| 24126 | 25027 | } else { |
| 24127 | | ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 24128 | | return ira->codegen->invalid_instruction; |
| 25028 | ir_add_error(ira, &instruction->name->base, |
| 25029 | buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 25030 | return ira->codegen->invalid_inst_gen; |
| 24129 | 25031 | } |
| 24130 | 25032 | } |
| 24131 | 25033 | |
| 24132 | 25034 | ZigType *result_type = get_array_type(ira->codegen, |
| 24133 | 25035 | ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr); |
| 24134 | | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 25036 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 24135 | 25037 | init_const_str_lit(ira->codegen, result->value, file_contents); |
| 24136 | 25038 | return result; |
| 24137 | 25039 | } |
| 24138 | 25040 | |
| 24139 | | static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) { |
| 25041 | static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) { |
| 24140 | 25042 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child); |
| 24141 | 25043 | if (type_is_invalid(operand_type)) |
| 24142 | | return ira->codegen->invalid_instruction; |
| 25044 | return ira->codegen->invalid_inst_gen; |
| 24143 | 25045 | |
| 24144 | 25046 | if (operand_type->id == ZigTypeIdFloat) { |
| 24145 | | ir_add_error(ira, instruction->type_value->child, |
| 25047 | ir_add_error(ira, &instruction->type_value->child->base, |
| 24146 | 25048 | buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name))); |
| 24147 | | return ira->codegen->invalid_instruction; |
| 25049 | return ira->codegen->invalid_inst_gen; |
| 24148 | 25050 | } |
| 24149 | 25051 | |
| 24150 | | IrInstruction *ptr = instruction->ptr->child; |
| 25052 | IrInstGen *ptr = instruction->ptr->child; |
| 24151 | 25053 | if (type_is_invalid(ptr->value->type)) |
| 24152 | | return ira->codegen->invalid_instruction; |
| 25054 | return ira->codegen->invalid_inst_gen; |
| 24153 | 25055 | |
| 24154 | 25056 | // TODO let this be volatile |
| 24155 | 25057 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 24156 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 25058 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 24157 | 25059 | if (type_is_invalid(casted_ptr->value->type)) |
| 24158 | | return ira->codegen->invalid_instruction; |
| 25060 | return ira->codegen->invalid_inst_gen; |
| 24159 | 25061 | |
| 24160 | | IrInstruction *cmp_value = instruction->cmp_value->child; |
| 25062 | IrInstGen *cmp_value = instruction->cmp_value->child; |
| 24161 | 25063 | if (type_is_invalid(cmp_value->value->type)) |
| 24162 | | return ira->codegen->invalid_instruction; |
| 25064 | return ira->codegen->invalid_inst_gen; |
| 24163 | 25065 | |
| 24164 | | IrInstruction *new_value = instruction->new_value->child; |
| 25066 | IrInstGen *new_value = instruction->new_value->child; |
| 24165 | 25067 | if (type_is_invalid(new_value->value->type)) |
| 24166 | | return ira->codegen->invalid_instruction; |
| 25068 | return ira->codegen->invalid_inst_gen; |
| 24167 | 25069 | |
| 24168 | | IrInstruction *success_order_value = instruction->success_order_value->child; |
| 25070 | IrInstGen *success_order_value = instruction->success_order_value->child; |
| 24169 | 25071 | if (type_is_invalid(success_order_value->value->type)) |
| 24170 | | return ira->codegen->invalid_instruction; |
| 25072 | return ira->codegen->invalid_inst_gen; |
| 24171 | 25073 | |
| 24172 | 25074 | AtomicOrder success_order; |
| 24173 | 25075 | if (!ir_resolve_atomic_order(ira, success_order_value, &success_order)) |
| 24174 | | return ira->codegen->invalid_instruction; |
| 25076 | return ira->codegen->invalid_inst_gen; |
| 24175 | 25077 | |
| 24176 | | IrInstruction *failure_order_value = instruction->failure_order_value->child; |
| 25078 | IrInstGen *failure_order_value = instruction->failure_order_value->child; |
| 24177 | 25079 | if (type_is_invalid(failure_order_value->value->type)) |
| 24178 | | return ira->codegen->invalid_instruction; |
| 25080 | return ira->codegen->invalid_inst_gen; |
| 24179 | 25081 | |
| 24180 | 25082 | AtomicOrder failure_order; |
| 24181 | 25083 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 24182 | | return ira->codegen->invalid_instruction; |
| 25084 | return ira->codegen->invalid_inst_gen; |
| 24183 | 25085 | |
| 24184 | | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 25086 | IrInstGen *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 24185 | 25087 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 24186 | | return ira->codegen->invalid_instruction; |
| 25088 | return ira->codegen->invalid_inst_gen; |
| 24187 | 25089 | |
| 24188 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 25090 | IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 24189 | 25091 | if (type_is_invalid(casted_new_value->value->type)) |
| 24190 | | return ira->codegen->invalid_instruction; |
| 25092 | return ira->codegen->invalid_inst_gen; |
| 24191 | 25093 | |
| 24192 | 25094 | if (success_order < AtomicOrderMonotonic) { |
| 24193 | | ir_add_error(ira, success_order_value, |
| 25095 | ir_add_error(ira, &success_order_value->base, |
| 24194 | 25096 | buf_sprintf("success atomic ordering must be Monotonic or stricter")); |
| 24195 | | return ira->codegen->invalid_instruction; |
| 25097 | return ira->codegen->invalid_inst_gen; |
| 24196 | 25098 | } |
| 24197 | 25099 | if (failure_order < AtomicOrderMonotonic) { |
| 24198 | | ir_add_error(ira, failure_order_value, |
| 25100 | ir_add_error(ira, &failure_order_value->base, |
| 24199 | 25101 | buf_sprintf("failure atomic ordering must be Monotonic or stricter")); |
| 24200 | | return ira->codegen->invalid_instruction; |
| 25102 | return ira->codegen->invalid_inst_gen; |
| 24201 | 25103 | } |
| 24202 | 25104 | if (failure_order > success_order) { |
| 24203 | | ir_add_error(ira, failure_order_value, |
| 25105 | ir_add_error(ira, &failure_order_value->base, |
| 24204 | 25106 | buf_sprintf("failure atomic ordering must be no stricter than success")); |
| 24205 | | return ira->codegen->invalid_instruction; |
| 25107 | return ira->codegen->invalid_inst_gen; |
| 24206 | 25108 | } |
| 24207 | 25109 | if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) { |
| 24208 | | ir_add_error(ira, failure_order_value, |
| 25110 | ir_add_error(ira, &failure_order_value->base, |
| 24209 | 25111 | buf_sprintf("failure atomic ordering must not be Release or AcqRel")); |
| 24210 | | return ira->codegen->invalid_instruction; |
| 25112 | return ira->codegen->invalid_inst_gen; |
| 24211 | 25113 | } |
| 24212 | 25114 | |
| 24213 | 25115 | if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| ... | ... | @@ -24216,66 +25118,63 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 24216 | 25118 | } |
| 24217 | 25119 | |
| 24218 | 25120 | ZigType *result_type = get_optional_type(ira->codegen, operand_type); |
| 24219 | | IrInstruction *result_loc; |
| 25121 | IrInstGen *result_loc; |
| 24220 | 25122 | if (handle_is_ptr(result_type)) { |
| 24221 | | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 25123 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 24222 | 25124 | result_type, nullptr, true, false, true); |
| 24223 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 25125 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 24224 | 25126 | return result_loc; |
| 24225 | 25127 | } |
| 24226 | 25128 | } else { |
| 24227 | 25129 | result_loc = nullptr; |
| 24228 | 25130 | } |
| 24229 | 25131 | |
| 24230 | | return ir_build_cmpxchg_gen(ira, &instruction->base, result_type, |
| 25132 | return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type, |
| 24231 | 25133 | casted_ptr, casted_cmp_value, casted_new_value, |
| 24232 | 25134 | success_order, failure_order, instruction->is_weak, result_loc); |
| 24233 | 25135 | } |
| 24234 | 25136 | |
| 24235 | | static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 24236 | | IrInstruction *order_value = instruction->order_value->child; |
| 24237 | | if (type_is_invalid(order_value->value->type)) |
| 24238 | | return ira->codegen->invalid_instruction; |
| 25137 | static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) { |
| 25138 | IrInstGen *order_inst = instruction->order->child; |
| 25139 | if (type_is_invalid(order_inst->value->type)) |
| 25140 | return ira->codegen->invalid_inst_gen; |
| 24239 | 25141 | |
| 24240 | 25142 | AtomicOrder order; |
| 24241 | | if (!ir_resolve_atomic_order(ira, order_value, &order)) |
| 24242 | | return ira->codegen->invalid_instruction; |
| 25143 | if (!ir_resolve_atomic_order(ira, order_inst, &order)) |
| 25144 | return ira->codegen->invalid_inst_gen; |
| 24243 | 25145 | |
| 24244 | 25146 | if (order < AtomicOrderAcquire) { |
| 24245 | | ir_add_error(ira, order_value, |
| 25147 | ir_add_error(ira, &order_inst->base, |
| 24246 | 25148 | buf_sprintf("atomic ordering must be Acquire or stricter")); |
| 24247 | | return ira->codegen->invalid_instruction; |
| 25149 | return ira->codegen->invalid_inst_gen; |
| 24248 | 25150 | } |
| 24249 | 25151 | |
| 24250 | | IrInstruction *result = ir_build_fence(&ira->new_irb, |
| 24251 | | instruction->base.scope, instruction->base.source_node, order_value, order); |
| 24252 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24253 | | return result; |
| 25152 | return ir_build_fence_gen(ira, &instruction->base.base, order); |
| 24254 | 25153 | } |
| 24255 | 25154 | |
| 24256 | | static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 24257 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 25155 | static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) { |
| 25156 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 24258 | 25157 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 24259 | 25158 | if (type_is_invalid(dest_type)) |
| 24260 | | return ira->codegen->invalid_instruction; |
| 25159 | return ira->codegen->invalid_inst_gen; |
| 24261 | 25160 | |
| 24262 | 25161 | if (dest_type->id != ZigTypeIdInt && |
| 24263 | 25162 | dest_type->id != ZigTypeIdComptimeInt) |
| 24264 | 25163 | { |
| 24265 | | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 24266 | | return ira->codegen->invalid_instruction; |
| 25164 | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25165 | return ira->codegen->invalid_inst_gen; |
| 24267 | 25166 | } |
| 24268 | 25167 | |
| 24269 | | IrInstruction *target = instruction->target->child; |
| 25168 | IrInstGen *target = instruction->target->child; |
| 24270 | 25169 | ZigType *src_type = target->value->type; |
| 24271 | 25170 | if (type_is_invalid(src_type)) |
| 24272 | | return ira->codegen->invalid_instruction; |
| 25171 | return ira->codegen->invalid_inst_gen; |
| 24273 | 25172 | |
| 24274 | 25173 | if (src_type->id != ZigTypeIdInt && |
| 24275 | 25174 | src_type->id != ZigTypeIdComptimeInt) |
| 24276 | 25175 | { |
| 24277 | | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 24278 | | return ira->codegen->invalid_instruction; |
| 25176 | ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 25177 | return ira->codegen->invalid_inst_gen; |
| 24279 | 25178 | } |
| 24280 | 25179 | |
| 24281 | 25180 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -24285,54 +25184,51 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 24285 | 25184 | if (instr_is_comptime(target)) { |
| 24286 | 25185 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 24287 | 25186 | if (val == nullptr) |
| 24288 | | return ira->codegen->invalid_instruction; |
| 25187 | return ira->codegen->invalid_inst_gen; |
| 24289 | 25188 | |
| 24290 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 25189 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 24291 | 25190 | bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, |
| 24292 | 25191 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 24293 | 25192 | return result; |
| 24294 | 25193 | } |
| 24295 | 25194 | |
| 24296 | 25195 | if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { |
| 24297 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 25196 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 24298 | 25197 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 24299 | 25198 | return result; |
| 24300 | 25199 | } |
| 24301 | 25200 | |
| 24302 | 25201 | if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) { |
| 24303 | 25202 | const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned"; |
| 24304 | | ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 24305 | | return ira->codegen->invalid_instruction; |
| 25203 | ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 25204 | return ira->codegen->invalid_inst_gen; |
| 24306 | 25205 | } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) { |
| 24307 | | ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 25206 | ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 24308 | 25207 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 24309 | | return ira->codegen->invalid_instruction; |
| 25208 | return ira->codegen->invalid_inst_gen; |
| 24310 | 25209 | } |
| 24311 | 25210 | |
| 24312 | | IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, |
| 24313 | | instruction->base.source_node, dest_type_value, target); |
| 24314 | | new_instruction->value->type = dest_type; |
| 24315 | | return new_instruction; |
| 25211 | return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target); |
| 24316 | 25212 | } |
| 24317 | 25213 | |
| 24318 | | static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 25214 | static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) { |
| 24319 | 25215 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24320 | 25216 | if (type_is_invalid(dest_type)) |
| 24321 | | return ira->codegen->invalid_instruction; |
| 25217 | return ira->codegen->invalid_inst_gen; |
| 24322 | 25218 | |
| 24323 | 25219 | if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) { |
| 24324 | | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 24325 | | return ira->codegen->invalid_instruction; |
| 25220 | ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25221 | return ira->codegen->invalid_inst_gen; |
| 24326 | 25222 | } |
| 24327 | 25223 | |
| 24328 | | IrInstruction *target = instruction->target->child; |
| 25224 | IrInstGen *target = instruction->target->child; |
| 24329 | 25225 | if (type_is_invalid(target->value->type)) |
| 24330 | | return ira->codegen->invalid_instruction; |
| 25226 | return ira->codegen->invalid_inst_gen; |
| 24331 | 25227 | |
| 24332 | 25228 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 24333 | | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 25229 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'", |
| 24334 | 25230 | buf_ptr(&target->value->type->name))); |
| 24335 | | return ira->codegen->invalid_instruction; |
| 25231 | return ira->codegen->invalid_inst_gen; |
| 24336 | 25232 | } |
| 24337 | 25233 | |
| 24338 | 25234 | if (instr_is_comptime(target)) { |
| ... | ... | @@ -24340,28 +25236,28 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct |
| 24340 | 25236 | } |
| 24341 | 25237 | |
| 24342 | 25238 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| 24343 | | ir_add_error(ira, instruction->target, buf_sprintf("attempt to cast runtime value to '%s'", |
| 25239 | ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'", |
| 24344 | 25240 | buf_ptr(&dest_type->name))); |
| 24345 | | return ira->codegen->invalid_instruction; |
| 25241 | return ira->codegen->invalid_inst_gen; |
| 24346 | 25242 | } |
| 24347 | 25243 | |
| 24348 | | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 25244 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 24349 | 25245 | } |
| 24350 | 25246 | |
| 24351 | | static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 25247 | static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) { |
| 24352 | 25248 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24353 | 25249 | if (type_is_invalid(dest_type)) |
| 24354 | | return ira->codegen->invalid_instruction; |
| 25250 | return ira->codegen->invalid_inst_gen; |
| 24355 | 25251 | |
| 24356 | 25252 | if (dest_type->id != ZigTypeIdFloat) { |
| 24357 | | ir_add_error(ira, instruction->dest_type, |
| 25253 | ir_add_error(ira, &instruction->dest_type->base, |
| 24358 | 25254 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 24359 | | return ira->codegen->invalid_instruction; |
| 25255 | return ira->codegen->invalid_inst_gen; |
| 24360 | 25256 | } |
| 24361 | 25257 | |
| 24362 | | IrInstruction *target = instruction->target->child; |
| 25258 | IrInstGen *target = instruction->target->child; |
| 24363 | 25259 | if (type_is_invalid(target->value->type)) |
| 24364 | | return ira->codegen->invalid_instruction; |
| 25260 | return ira->codegen->invalid_inst_gen; |
| 24365 | 25261 | |
| 24366 | 25262 | if (target->value->type->id == ZigTypeIdComptimeInt || |
| 24367 | 25263 | target->value->type->id == ZigTypeIdComptimeFloat) |
| ... | ... | @@ -24373,55 +25269,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 24373 | 25269 | } else { |
| 24374 | 25270 | op = CastOpNumLitToConcrete; |
| 24375 | 25271 | } |
| 24376 | | return ir_resolve_cast(ira, &instruction->base, target, dest_type, op); |
| 25272 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op); |
| 24377 | 25273 | } else { |
| 24378 | | return ira->codegen->invalid_instruction; |
| 25274 | return ira->codegen->invalid_inst_gen; |
| 24379 | 25275 | } |
| 24380 | 25276 | } |
| 24381 | 25277 | |
| 24382 | 25278 | if (target->value->type->id != ZigTypeIdFloat) { |
| 24383 | | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 25279 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'", |
| 24384 | 25280 | buf_ptr(&target->value->type->name))); |
| 24385 | | return ira->codegen->invalid_instruction; |
| 25281 | return ira->codegen->invalid_inst_gen; |
| 24386 | 25282 | } |
| 24387 | 25283 | |
| 24388 | | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 25284 | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 24389 | 25285 | } |
| 24390 | 25286 | |
| 24391 | | static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 25287 | static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) { |
| 24392 | 25288 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24393 | 25289 | if (type_is_invalid(dest_type)) |
| 24394 | | return ira->codegen->invalid_instruction; |
| 25290 | return ira->codegen->invalid_inst_gen; |
| 24395 | 25291 | |
| 24396 | 25292 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 24397 | | ir_add_error(ira, instruction->dest_type, |
| 25293 | ir_add_error(ira, &instruction->dest_type->base, |
| 24398 | 25294 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 24399 | | return ira->codegen->invalid_instruction; |
| 25295 | return ira->codegen->invalid_inst_gen; |
| 24400 | 25296 | } |
| 24401 | 25297 | |
| 24402 | | IrInstruction *target = instruction->target->child; |
| 25298 | IrInstGen *target = instruction->target->child; |
| 24403 | 25299 | if (type_is_invalid(target->value->type)) |
| 24404 | | return ira->codegen->invalid_instruction; |
| 25300 | return ira->codegen->invalid_inst_gen; |
| 24405 | 25301 | |
| 24406 | 25302 | if (target->value->type->id != ZigTypeIdErrorSet) { |
| 24407 | | ir_add_error(ira, instruction->target, |
| 25303 | ir_add_error(ira, &instruction->target->base, |
| 24408 | 25304 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); |
| 24409 | | return ira->codegen->invalid_instruction; |
| 25305 | return ira->codegen->invalid_inst_gen; |
| 24410 | 25306 | } |
| 24411 | 25307 | |
| 24412 | | return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type); |
| 25308 | return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type); |
| 24413 | 25309 | } |
| 24414 | 25310 | |
| 24415 | | static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 25311 | static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) { |
| 24416 | 25312 | Error err; |
| 24417 | 25313 | |
| 24418 | 25314 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child); |
| 24419 | 25315 | if (type_is_invalid(dest_child_type)) |
| 24420 | | return ira->codegen->invalid_instruction; |
| 25316 | return ira->codegen->invalid_inst_gen; |
| 24421 | 25317 | |
| 24422 | | IrInstruction *target = instruction->target->child; |
| 25318 | IrInstGen *target = instruction->target->child; |
| 24423 | 25319 | if (type_is_invalid(target->value->type)) |
| 24424 | | return ira->codegen->invalid_instruction; |
| 25320 | return ira->codegen->invalid_inst_gen; |
| 24425 | 25321 | |
| 24426 | 25322 | bool src_ptr_const; |
| 24427 | 25323 | bool src_ptr_volatile; |
| ... | ... | @@ -24431,27 +25327,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24431 | 25327 | src_ptr_volatile = target->value->type->data.pointer.is_volatile; |
| 24432 | 25328 | |
| 24433 | 25329 | if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align))) |
| 24434 | | return ira->codegen->invalid_instruction; |
| 25330 | return ira->codegen->invalid_inst_gen; |
| 24435 | 25331 | } else if (is_slice(target->value->type)) { |
| 24436 | 25332 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 24437 | 25333 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 24438 | 25334 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 24439 | 25335 | |
| 24440 | 25336 | if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align))) |
| 24441 | | return ira->codegen->invalid_instruction; |
| 25337 | return ira->codegen->invalid_inst_gen; |
| 24442 | 25338 | } else { |
| 24443 | 25339 | src_ptr_const = true; |
| 24444 | 25340 | src_ptr_volatile = false; |
| 24445 | 25341 | |
| 24446 | 25342 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown))) |
| 24447 | | return ira->codegen->invalid_instruction; |
| 25343 | return ira->codegen->invalid_inst_gen; |
| 24448 | 25344 | |
| 24449 | 25345 | src_ptr_align = get_abi_alignment(ira->codegen, target->value->type); |
| 24450 | 25346 | } |
| 24451 | 25347 | |
| 24452 | 25348 | if (src_ptr_align != 0) { |
| 24453 | 25349 | if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown))) |
| 24454 | | return ira->codegen->invalid_instruction; |
| 25350 | return ira->codegen->invalid_inst_gen; |
| 24455 | 25351 | } |
| 24456 | 25352 | |
| 24457 | 25353 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, |
| ... | ... | @@ -24464,9 +25360,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24464 | 25360 | src_ptr_align, 0, 0, false); |
| 24465 | 25361 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 24466 | 25362 | |
| 24467 | | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 25363 | IrInstGen *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 24468 | 25364 | if (type_is_invalid(casted_value->value->type)) |
| 24469 | | return ira->codegen->invalid_instruction; |
| 25365 | return ira->codegen->invalid_inst_gen; |
| 24470 | 25366 | |
| 24471 | 25367 | bool have_known_len = false; |
| 24472 | 25368 | uint64_t known_len; |
| ... | ... | @@ -24474,7 +25370,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24474 | 25370 | if (instr_is_comptime(casted_value)) { |
| 24475 | 25371 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 24476 | 25372 | if (!val) |
| 24477 | | return ira->codegen->invalid_instruction; |
| 25373 | return ira->codegen->invalid_inst_gen; |
| 24478 | 25374 | |
| 24479 | 25375 | ZigValue *len_val = val->data.x_struct.fields[slice_len_index]; |
| 24480 | 25376 | if (value_is_comptime(len_val)) { |
| ... | ... | @@ -24483,9 +25379,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24483 | 25379 | } |
| 24484 | 25380 | } |
| 24485 | 25381 | |
| 24486 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 25382 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 24487 | 25383 | dest_slice_type, nullptr, true, false, true); |
| 24488 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { |
| 25384 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) { |
| 24489 | 25385 | return result_loc; |
| 24490 | 25386 | } |
| 24491 | 25387 | |
| ... | ... | @@ -24502,41 +25398,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 24502 | 25398 | |
| 24503 | 25399 | if (have_known_len) { |
| 24504 | 25400 | if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown))) |
| 24505 | | return ira->codegen->invalid_instruction; |
| 25401 | return ira->codegen->invalid_inst_gen; |
| 24506 | 25402 | uint64_t child_type_size = type_size(ira->codegen, dest_child_type); |
| 24507 | 25403 | uint64_t remainder = known_len % child_type_size; |
| 24508 | 25404 | if (remainder != 0) { |
| 24509 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 25405 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 24510 | 25406 | buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch", |
| 24511 | 25407 | known_len, buf_ptr(&dest_slice_type->name))); |
| 24512 | | add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node, |
| 25408 | add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node, |
| 24513 | 25409 | buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64, |
| 24514 | 25410 | buf_ptr(&dest_child_type->name), child_type_size, remainder)); |
| 24515 | | return ira->codegen->invalid_instruction; |
| 25411 | return ira->codegen->invalid_inst_gen; |
| 24516 | 25412 | } |
| 24517 | 25413 | } |
| 24518 | 25414 | |
| 24519 | | return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc); |
| 25415 | return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc); |
| 24520 | 25416 | } |
| 24521 | 25417 | |
| 24522 | | static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 25418 | static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) { |
| 24523 | 25419 | Error err; |
| 24524 | 25420 | |
| 24525 | | IrInstruction *target = instruction->target->child; |
| 25421 | IrInstGen *target = instruction->target->child; |
| 24526 | 25422 | if (type_is_invalid(target->value->type)) |
| 24527 | | return ira->codegen->invalid_instruction; |
| 25423 | return ira->codegen->invalid_inst_gen; |
| 24528 | 25424 | |
| 24529 | 25425 | if (!is_slice(target->value->type)) { |
| 24530 | | ir_add_error(ira, instruction->target, |
| 25426 | ir_add_error(ira, &instruction->target->base, |
| 24531 | 25427 | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name))); |
| 24532 | | return ira->codegen->invalid_instruction; |
| 25428 | return ira->codegen->invalid_inst_gen; |
| 24533 | 25429 | } |
| 24534 | 25430 | |
| 24535 | 25431 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 24536 | 25432 | |
| 24537 | 25433 | uint32_t alignment; |
| 24538 | 25434 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| 24539 | | return ira->codegen->invalid_instruction; |
| 25435 | return ira->codegen->invalid_inst_gen; |
| 24540 | 25436 | |
| 24541 | 25437 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 24542 | 25438 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| ... | ... | @@ -24546,9 +25442,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 24546 | 25442 | if (instr_is_comptime(target)) { |
| 24547 | 25443 | ZigValue *target_val = ir_resolve_const(ira, target, UndefBad); |
| 24548 | 25444 | if (target_val == nullptr) |
| 24549 | | return ira->codegen->invalid_instruction; |
| 25445 | return ira->codegen->invalid_inst_gen; |
| 24550 | 25446 | |
| 24551 | | IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type); |
| 25447 | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type); |
| 24552 | 25448 | result->value->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 24553 | 25449 | |
| 24554 | 25450 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; |
| ... | ... | @@ -24568,13 +25464,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 24568 | 25464 | return result; |
| 24569 | 25465 | } |
| 24570 | 25466 | |
| 24571 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 25467 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 24572 | 25468 | dest_slice_type, nullptr, true, false, true); |
| 24573 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 25469 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 24574 | 25470 | return result_loc; |
| 24575 | 25471 | } |
| 24576 | 25472 | |
| 24577 | | return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc); |
| 25473 | return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc); |
| 24578 | 25474 | } |
| 24579 | 25475 | |
| 24580 | 25476 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |
| ... | ... | @@ -24591,26 +25487,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali |
| 24591 | 25487 | return ErrorNone; |
| 24592 | 25488 | } |
| 24593 | 25489 | |
| 24594 | | static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 25490 | static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcIntToFloat *instruction) { |
| 24595 | 25491 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24596 | 25492 | if (type_is_invalid(dest_type)) |
| 24597 | | return ira->codegen->invalid_instruction; |
| 25493 | return ira->codegen->invalid_inst_gen; |
| 24598 | 25494 | |
| 24599 | | IrInstruction *target = instruction->target->child; |
| 25495 | IrInstGen *target = instruction->target->child; |
| 24600 | 25496 | if (type_is_invalid(target->value->type)) |
| 24601 | | return ira->codegen->invalid_instruction; |
| 25497 | return ira->codegen->invalid_inst_gen; |
| 24602 | 25498 | |
| 24603 | 25499 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 24604 | | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 25500 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'", |
| 24605 | 25501 | buf_ptr(&target->value->type->name))); |
| 24606 | | return ira->codegen->invalid_instruction; |
| 25502 | return ira->codegen->invalid_inst_gen; |
| 24607 | 25503 | } |
| 24608 | 25504 | |
| 24609 | | return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat); |
| 25505 | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat); |
| 24610 | 25506 | } |
| 24611 | 25507 | |
| 24612 | | static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr, |
| 24613 | | ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node) |
| 25508 | static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr, |
| 25509 | ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node) |
| 24614 | 25510 | { |
| 24615 | 25511 | if (operand->value->type->id == ZigTypeIdComptimeInt) { |
| 24616 | 25512 | return ir_implicit_cast(ira, operand, dest_type); |
| ... | ... | @@ -24619,106 +25515,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou |
| 24619 | 25515 | if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) { |
| 24620 | 25516 | ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'", |
| 24621 | 25517 | buf_ptr(&operand->value->type->name))); |
| 24622 | | return ira->codegen->invalid_instruction; |
| 25518 | return ira->codegen->invalid_inst_gen; |
| 24623 | 25519 | } |
| 24624 | 25520 | |
| 24625 | 25521 | return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt); |
| 24626 | 25522 | } |
| 24627 | 25523 | |
| 24628 | | static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 25524 | static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) { |
| 24629 | 25525 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 24630 | 25526 | if (type_is_invalid(dest_type)) |
| 24631 | | return ira->codegen->invalid_instruction; |
| 25527 | return ira->codegen->invalid_inst_gen; |
| 24632 | 25528 | |
| 24633 | | IrInstruction *operand = instruction->target->child; |
| 25529 | IrInstGen *operand = instruction->target->child; |
| 24634 | 25530 | if (type_is_invalid(operand->value->type)) |
| 24635 | | return ira->codegen->invalid_instruction; |
| 25531 | return ira->codegen->invalid_inst_gen; |
| 24636 | 25532 | |
| 24637 | | return ir_analyze_float_to_int(ira, &instruction->base, dest_type, operand, instruction->target->source_node); |
| 25533 | return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand, |
| 25534 | instruction->target->base.source_node); |
| 24638 | 25535 | } |
| 24639 | 25536 | |
| 24640 | | static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 24641 | | IrInstruction *target = instruction->target->child; |
| 25537 | static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) { |
| 25538 | IrInstGen *target = instruction->target->child; |
| 24642 | 25539 | if (type_is_invalid(target->value->type)) |
| 24643 | | return ira->codegen->invalid_instruction; |
| 25540 | return ira->codegen->invalid_inst_gen; |
| 24644 | 25541 | |
| 24645 | | IrInstruction *casted_target; |
| 25542 | IrInstGen *casted_target; |
| 24646 | 25543 | if (target->value->type->id == ZigTypeIdErrorSet) { |
| 24647 | 25544 | casted_target = target; |
| 24648 | 25545 | } else { |
| 24649 | 25546 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| 24650 | 25547 | if (type_is_invalid(casted_target->value->type)) |
| 24651 | | return ira->codegen->invalid_instruction; |
| 25548 | return ira->codegen->invalid_inst_gen; |
| 24652 | 25549 | } |
| 24653 | 25550 | |
| 24654 | | return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type); |
| 25551 | return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type); |
| 24655 | 25552 | } |
| 24656 | 25553 | |
| 24657 | | static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 24658 | | IrInstruction *target = instruction->target->child; |
| 25554 | static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) { |
| 25555 | IrInstGen *target = instruction->target->child; |
| 24659 | 25556 | if (type_is_invalid(target->value->type)) |
| 24660 | | return ira->codegen->invalid_instruction; |
| 25557 | return ira->codegen->invalid_inst_gen; |
| 24661 | 25558 | |
| 24662 | | IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 25559 | IrInstGen *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 24663 | 25560 | if (type_is_invalid(casted_target->value->type)) |
| 24664 | | return ira->codegen->invalid_instruction; |
| 25561 | return ira->codegen->invalid_inst_gen; |
| 24665 | 25562 | |
| 24666 | | return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 25563 | return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 24667 | 25564 | } |
| 24668 | 25565 | |
| 24669 | | static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 24670 | | IrInstruction *target = instruction->target->child; |
| 25566 | static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) { |
| 25567 | IrInstGen *target = instruction->target->child; |
| 24671 | 25568 | if (type_is_invalid(target->value->type)) |
| 24672 | | return ira->codegen->invalid_instruction; |
| 25569 | return ira->codegen->invalid_inst_gen; |
| 24673 | 25570 | |
| 24674 | 25571 | if (target->value->type->id != ZigTypeIdBool) { |
| 24675 | | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 25572 | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'", |
| 24676 | 25573 | buf_ptr(&target->value->type->name))); |
| 24677 | | return ira->codegen->invalid_instruction; |
| 25574 | return ira->codegen->invalid_inst_gen; |
| 24678 | 25575 | } |
| 24679 | 25576 | |
| 24680 | 25577 | if (instr_is_comptime(target)) { |
| 24681 | 25578 | bool is_true; |
| 24682 | 25579 | if (!ir_resolve_bool(ira, target, &is_true)) |
| 24683 | | return ira->codegen->invalid_instruction; |
| 25580 | return ira->codegen->invalid_inst_gen; |
| 24684 | 25581 | |
| 24685 | | return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0); |
| 25582 | return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0); |
| 24686 | 25583 | } |
| 24687 | 25584 | |
| 24688 | 25585 | ZigType *u1_type = get_int_type(ira->codegen, false, 1); |
| 24689 | | return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt); |
| 25586 | return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt); |
| 24690 | 25587 | } |
| 24691 | 25588 | |
| 24692 | | static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { |
| 24693 | | IrInstruction *is_signed_value = instruction->is_signed->child; |
| 25589 | static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) { |
| 25590 | IrInstGen *is_signed_value = instruction->is_signed->child; |
| 24694 | 25591 | bool is_signed; |
| 24695 | 25592 | if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) |
| 24696 | | return ira->codegen->invalid_instruction; |
| 25593 | return ira->codegen->invalid_inst_gen; |
| 24697 | 25594 | |
| 24698 | | IrInstruction *bit_count_value = instruction->bit_count->child; |
| 25595 | IrInstGen *bit_count_value = instruction->bit_count->child; |
| 24699 | 25596 | uint64_t bit_count; |
| 24700 | 25597 | if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count)) |
| 24701 | | return ira->codegen->invalid_instruction; |
| 25598 | return ira->codegen->invalid_inst_gen; |
| 24702 | 25599 | |
| 24703 | | return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
| 25600 | return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
| 24704 | 25601 | } |
| 24705 | 25602 | |
| 24706 | | static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) { |
| 25603 | static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) { |
| 24707 | 25604 | uint64_t len; |
| 24708 | 25605 | if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len)) |
| 24709 | | return ira->codegen->invalid_instruction; |
| 25606 | return ira->codegen->invalid_inst_gen; |
| 24710 | 25607 | |
| 24711 | 25608 | ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child); |
| 24712 | 25609 | if (type_is_invalid(elem_type)) |
| 24713 | | return ira->codegen->invalid_instruction; |
| 25610 | return ira->codegen->invalid_inst_gen; |
| 24714 | 25611 | |
| 24715 | 25612 | ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type); |
| 24716 | 25613 | |
| 24717 | | return ir_const_type(ira, &instruction->base, vector_type); |
| 25614 | return ir_const_type(ira, &instruction->base.base, vector_type); |
| 24718 | 25615 | } |
| 24719 | 25616 | |
| 24720 | | static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr, |
| 24721 | | ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask) |
| 25617 | static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr, |
| 25618 | ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask) |
| 24722 | 25619 | { |
| 24723 | 25620 | ir_assert(source_instr && scalar_type && a && b && mask, source_instr); |
| 24724 | 25621 | ir_assert(is_valid_vector_elem_type(scalar_type), source_instr); |
| ... | ... | @@ -24729,15 +25626,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24729 | 25626 | } else if (mask->value->type->id == ZigTypeIdArray) { |
| 24730 | 25627 | len_mask = mask->value->type->data.array.len; |
| 24731 | 25628 | } else { |
| 24732 | | ir_add_error(ira, mask, |
| 25629 | ir_add_error(ira, &mask->base, |
| 24733 | 25630 | buf_sprintf("expected vector or array, found '%s'", |
| 24734 | 25631 | buf_ptr(&mask->value->type->name))); |
| 24735 | | return ira->codegen->invalid_instruction; |
| 25632 | return ira->codegen->invalid_inst_gen; |
| 24736 | 25633 | } |
| 24737 | 25634 | mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask, |
| 24738 | 25635 | ira->codegen->builtin_types.entry_i32)); |
| 24739 | 25636 | if (type_is_invalid(mask->value->type)) |
| 24740 | | return ira->codegen->invalid_instruction; |
| 25637 | return ira->codegen->invalid_inst_gen; |
| 24741 | 25638 | |
| 24742 | 25639 | uint32_t len_a; |
| 24743 | 25640 | if (a->value->type->id == ZigTypeIdVector) { |
| ... | ... | @@ -24747,11 +25644,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24747 | 25644 | } else if (a->value->type->id == ZigTypeIdUndefined) { |
| 24748 | 25645 | len_a = UINT32_MAX; |
| 24749 | 25646 | } else { |
| 24750 | | ir_add_error(ira, a, |
| 25647 | ir_add_error(ira, &a->base, |
| 24751 | 25648 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 24752 | 25649 | buf_ptr(&scalar_type->name), |
| 24753 | 25650 | buf_ptr(&a->value->type->name))); |
| 24754 | | return ira->codegen->invalid_instruction; |
| 25651 | return ira->codegen->invalid_inst_gen; |
| 24755 | 25652 | } |
| 24756 | 25653 | |
| 24757 | 25654 | uint32_t len_b; |
| ... | ... | @@ -24762,38 +25659,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24762 | 25659 | } else if (b->value->type->id == ZigTypeIdUndefined) { |
| 24763 | 25660 | len_b = UINT32_MAX; |
| 24764 | 25661 | } else { |
| 24765 | | ir_add_error(ira, b, |
| 25662 | ir_add_error(ira, &b->base, |
| 24766 | 25663 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 24767 | 25664 | buf_ptr(&scalar_type->name), |
| 24768 | 25665 | buf_ptr(&b->value->type->name))); |
| 24769 | | return ira->codegen->invalid_instruction; |
| 25666 | return ira->codegen->invalid_inst_gen; |
| 24770 | 25667 | } |
| 24771 | 25668 | |
| 24772 | 25669 | if (len_a == UINT32_MAX && len_b == UINT32_MAX) { |
| 24773 | | return ir_const_undef(ira, a, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 25670 | return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 24774 | 25671 | } |
| 24775 | 25672 | |
| 24776 | 25673 | if (len_a == UINT32_MAX) { |
| 24777 | 25674 | len_a = len_b; |
| 24778 | | a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 25675 | a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 24779 | 25676 | } else { |
| 24780 | 25677 | a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 24781 | 25678 | if (type_is_invalid(a->value->type)) |
| 24782 | | return ira->codegen->invalid_instruction; |
| 25679 | return ira->codegen->invalid_inst_gen; |
| 24783 | 25680 | } |
| 24784 | 25681 | |
| 24785 | 25682 | if (len_b == UINT32_MAX) { |
| 24786 | 25683 | len_b = len_a; |
| 24787 | | b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 25684 | b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 24788 | 25685 | } else { |
| 24789 | 25686 | b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 24790 | 25687 | if (type_is_invalid(b->value->type)) |
| 24791 | | return ira->codegen->invalid_instruction; |
| 25688 | return ira->codegen->invalid_inst_gen; |
| 24792 | 25689 | } |
| 24793 | 25690 | |
| 24794 | 25691 | ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk); |
| 24795 | 25692 | if (mask_val == nullptr) |
| 24796 | | return ira->codegen->invalid_instruction; |
| 25693 | return ira->codegen->invalid_inst_gen; |
| 24797 | 25694 | |
| 24798 | 25695 | expand_undef_array(ira->codegen, mask_val); |
| 24799 | 25696 | |
| ... | ... | @@ -24803,7 +25700,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24803 | 25700 | continue; |
| 24804 | 25701 | int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint); |
| 24805 | 25702 | uint32_t v; |
| 24806 | | IrInstruction *chosen_operand; |
| 25703 | IrInstGen *chosen_operand; |
| 24807 | 25704 | if (v_i32 >= 0) { |
| 24808 | 25705 | v = (uint32_t)v_i32; |
| 24809 | 25706 | chosen_operand = a; |
| ... | ... | @@ -24812,16 +25709,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24812 | 25709 | chosen_operand = b; |
| 24813 | 25710 | } |
| 24814 | 25711 | if (v >= chosen_operand->value->type->data.vector.len) { |
| 24815 | | ErrorMsg *msg = ir_add_error(ira, mask, |
| 25712 | ErrorMsg *msg = ir_add_error(ira, &mask->base, |
| 24816 | 25713 | buf_sprintf("mask index '%u' has out-of-bounds selection", i)); |
| 24817 | | add_error_note(ira->codegen, msg, chosen_operand->source_node, |
| 25714 | add_error_note(ira->codegen, msg, chosen_operand->base.source_node, |
| 24818 | 25715 | buf_sprintf("selected index '%u' out of bounds of %s", v, |
| 24819 | 25716 | buf_ptr(&chosen_operand->value->type->name))); |
| 24820 | 25717 | if (chosen_operand == a && v < len_a + len_b) { |
| 24821 | | add_error_note(ira->codegen, msg, b->source_node, |
| 25718 | add_error_note(ira->codegen, msg, b->base.source_node, |
| 24822 | 25719 | buf_create_from_str("selections from the second vector are specified with negative numbers")); |
| 24823 | 25720 | } |
| 24824 | | return ira->codegen->invalid_instruction; |
| 25721 | return ira->codegen->invalid_inst_gen; |
| 24825 | 25722 | } |
| 24826 | 25723 | } |
| 24827 | 25724 | |
| ... | ... | @@ -24829,16 +25726,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24829 | 25726 | if (instr_is_comptime(a) && instr_is_comptime(b)) { |
| 24830 | 25727 | ZigValue *a_val = ir_resolve_const(ira, a, UndefOk); |
| 24831 | 25728 | if (a_val == nullptr) |
| 24832 | | return ira->codegen->invalid_instruction; |
| 25729 | return ira->codegen->invalid_inst_gen; |
| 24833 | 25730 | |
| 24834 | 25731 | ZigValue *b_val = ir_resolve_const(ira, b, UndefOk); |
| 24835 | 25732 | if (b_val == nullptr) |
| 24836 | | return ira->codegen->invalid_instruction; |
| 25733 | return ira->codegen->invalid_inst_gen; |
| 24837 | 25734 | |
| 24838 | 25735 | expand_undef_array(ira->codegen, a_val); |
| 24839 | 25736 | expand_undef_array(ira->codegen, b_val); |
| 24840 | 25737 | |
| 24841 | | IrInstruction *result = ir_const(ira, source_instr, result_type); |
| 25738 | IrInstGen *result = ir_const(ira, source_instr, result_type); |
| 24842 | 25739 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 24843 | 25740 | for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { |
| 24844 | 25741 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| ... | ... | @@ -24870,7 +25767,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24870 | 25767 | uint32_t len_min = min(len_a, len_b); |
| 24871 | 25768 | uint32_t len_max = max(len_a, len_b); |
| 24872 | 25769 | |
| 24873 | | IrInstruction *expand_mask = ir_const(ira, mask, |
| 25770 | IrInstGen *expand_mask = ir_const(ira, &mask->base, |
| 24874 | 25771 | get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); |
| 24875 | 25772 | expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 24876 | 25773 | uint32_t i = 0; |
| ... | ... | @@ -24879,7 +25776,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24879 | 25776 | for (; i < len_max; i += 1) |
| 24880 | 25777 | bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 24881 | 25778 | |
| 24882 | | IrInstruction *undef = ir_const_undef(ira, source_instr, |
| 25779 | IrInstGen *undef = ir_const_undef(ira, source_instr, |
| 24883 | 25780 | get_vector_type(ira->codegen, len_min, scalar_type)); |
| 24884 | 25781 | |
| 24885 | 25782 | if (len_b < len_a) { |
| ... | ... | @@ -24889,62 +25786,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 24889 | 25786 | } |
| 24890 | 25787 | } |
| 24891 | 25788 | |
| 24892 | | IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb, |
| 24893 | | source_instr->scope, source_instr->source_node, |
| 24894 | | nullptr, a, b, mask); |
| 24895 | | result->value->type = result_type; |
| 24896 | | return result; |
| 25789 | return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node, |
| 25790 | result_type, a, b, mask); |
| 24897 | 25791 | } |
| 24898 | 25792 | |
| 24899 | | static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) { |
| 24900 | | ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type); |
| 25793 | static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) { |
| 25794 | ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child); |
| 24901 | 25795 | if (type_is_invalid(scalar_type)) |
| 24902 | | return ira->codegen->invalid_instruction; |
| 25796 | return ira->codegen->invalid_inst_gen; |
| 24903 | 25797 | |
| 24904 | | IrInstruction *a = instruction->a->child; |
| 25798 | IrInstGen *a = instruction->a->child; |
| 24905 | 25799 | if (type_is_invalid(a->value->type)) |
| 24906 | | return ira->codegen->invalid_instruction; |
| 25800 | return ira->codegen->invalid_inst_gen; |
| 24907 | 25801 | |
| 24908 | | IrInstruction *b = instruction->b->child; |
| 25802 | IrInstGen *b = instruction->b->child; |
| 24909 | 25803 | if (type_is_invalid(b->value->type)) |
| 24910 | | return ira->codegen->invalid_instruction; |
| 25804 | return ira->codegen->invalid_inst_gen; |
| 24911 | 25805 | |
| 24912 | | IrInstruction *mask = instruction->mask->child; |
| 25806 | IrInstGen *mask = instruction->mask->child; |
| 24913 | 25807 | if (type_is_invalid(mask->value->type)) |
| 24914 | | return ira->codegen->invalid_instruction; |
| 25808 | return ira->codegen->invalid_inst_gen; |
| 24915 | 25809 | |
| 24916 | | return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask); |
| 25810 | return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask); |
| 24917 | 25811 | } |
| 24918 | 25812 | |
| 24919 | | static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) { |
| 25813 | static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) { |
| 24920 | 25814 | Error err; |
| 24921 | 25815 | |
| 24922 | | IrInstruction *len = instruction->len->child; |
| 25816 | IrInstGen *len = instruction->len->child; |
| 24923 | 25817 | if (type_is_invalid(len->value->type)) |
| 24924 | | return ira->codegen->invalid_instruction; |
| 25818 | return ira->codegen->invalid_inst_gen; |
| 24925 | 25819 | |
| 24926 | | IrInstruction *scalar = instruction->scalar->child; |
| 25820 | IrInstGen *scalar = instruction->scalar->child; |
| 24927 | 25821 | if (type_is_invalid(scalar->value->type)) |
| 24928 | | return ira->codegen->invalid_instruction; |
| 25822 | return ira->codegen->invalid_inst_gen; |
| 24929 | 25823 | |
| 24930 | 25824 | uint64_t len_u64; |
| 24931 | 25825 | if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64)) |
| 24932 | | return ira->codegen->invalid_instruction; |
| 25826 | return ira->codegen->invalid_inst_gen; |
| 24933 | 25827 | uint32_t len_int = len_u64; |
| 24934 | 25828 | |
| 24935 | | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type))) |
| 24936 | | return ira->codegen->invalid_instruction; |
| 25829 | if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type))) |
| 25830 | return ira->codegen->invalid_inst_gen; |
| 24937 | 25831 | |
| 24938 | 25832 | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); |
| 24939 | 25833 | |
| 24940 | 25834 | if (instr_is_comptime(scalar)) { |
| 24941 | 25835 | ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); |
| 24942 | 25836 | if (scalar_val == nullptr) |
| 24943 | | return ira->codegen->invalid_instruction; |
| 25837 | return ira->codegen->invalid_inst_gen; |
| 24944 | 25838 | if (scalar_val->special == ConstValSpecialUndef) |
| 24945 | | return ir_const_undef(ira, &instruction->base, return_type); |
| 25839 | return ir_const_undef(ira, &instruction->base.base, return_type); |
| 24946 | 25840 | |
| 24947 | | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 25841 | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 24948 | 25842 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 24949 | 25843 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 24950 | 25844 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val); |
| ... | ... | @@ -24952,48 +25846,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 24952 | 25846 | return result; |
| 24953 | 25847 | } |
| 24954 | 25848 | |
| 24955 | | return ir_build_splat_gen(ira, &instruction->base, return_type, scalar); |
| 25849 | return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar); |
| 24956 | 25850 | } |
| 24957 | 25851 | |
| 24958 | | static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 24959 | | IrInstruction *value = instruction->value->child; |
| 25852 | static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) { |
| 25853 | IrInstGen *value = instruction->value->child; |
| 24960 | 25854 | if (type_is_invalid(value->value->type)) |
| 24961 | | return ira->codegen->invalid_instruction; |
| 25855 | return ira->codegen->invalid_inst_gen; |
| 24962 | 25856 | |
| 24963 | 25857 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 24964 | 25858 | |
| 24965 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 25859 | IrInstGen *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 24966 | 25860 | if (type_is_invalid(casted_value->value->type)) |
| 24967 | | return ira->codegen->invalid_instruction; |
| 25861 | return ira->codegen->invalid_inst_gen; |
| 24968 | 25862 | |
| 24969 | 25863 | if (instr_is_comptime(casted_value)) { |
| 24970 | 25864 | ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad); |
| 24971 | 25865 | if (value == nullptr) |
| 24972 | | return ira->codegen->invalid_instruction; |
| 25866 | return ira->codegen->invalid_inst_gen; |
| 24973 | 25867 | |
| 24974 | | return ir_const_bool(ira, &instruction->base, !value->data.x_bool); |
| 25868 | return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool); |
| 24975 | 25869 | } |
| 24976 | 25870 | |
| 24977 | | IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, |
| 24978 | | instruction->base.source_node, casted_value); |
| 24979 | | result->value->type = bool_type; |
| 24980 | | return result; |
| 25871 | return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value); |
| 24981 | 25872 | } |
| 24982 | 25873 | |
| 24983 | | static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 25874 | static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) { |
| 24984 | 25875 | Error err; |
| 24985 | 25876 | |
| 24986 | | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 25877 | IrInstGen *dest_ptr = instruction->dest_ptr->child; |
| 24987 | 25878 | if (type_is_invalid(dest_ptr->value->type)) |
| 24988 | | return ira->codegen->invalid_instruction; |
| 25879 | return ira->codegen->invalid_inst_gen; |
| 24989 | 25880 | |
| 24990 | | IrInstruction *byte_value = instruction->byte->child; |
| 25881 | IrInstGen *byte_value = instruction->byte->child; |
| 24991 | 25882 | if (type_is_invalid(byte_value->value->type)) |
| 24992 | | return ira->codegen->invalid_instruction; |
| 25883 | return ira->codegen->invalid_inst_gen; |
| 24993 | 25884 | |
| 24994 | | IrInstruction *count_value = instruction->count->child; |
| 25885 | IrInstGen *count_value = instruction->count->child; |
| 24995 | 25886 | if (type_is_invalid(count_value->value->type)) |
| 24996 | | return ira->codegen->invalid_instruction; |
| 25887 | return ira->codegen->invalid_inst_gen; |
| 24997 | 25888 | |
| 24998 | 25889 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 24999 | 25890 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| ... | ... | @@ -25004,24 +25895,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25004 | 25895 | uint32_t dest_align; |
| 25005 | 25896 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 25006 | 25897 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 25007 | | return ira->codegen->invalid_instruction; |
| 25898 | return ira->codegen->invalid_inst_gen; |
| 25008 | 25899 | } else { |
| 25009 | 25900 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 25010 | 25901 | } |
| 25011 | 25902 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 25012 | 25903 | PtrLenUnknown, dest_align, 0, 0, false); |
| 25013 | 25904 | |
| 25014 | | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 25905 | IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 25015 | 25906 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 25016 | | return ira->codegen->invalid_instruction; |
| 25907 | return ira->codegen->invalid_inst_gen; |
| 25017 | 25908 | |
| 25018 | | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 25909 | IrInstGen *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 25019 | 25910 | if (type_is_invalid(casted_byte->value->type)) |
| 25020 | | return ira->codegen->invalid_instruction; |
| 25911 | return ira->codegen->invalid_inst_gen; |
| 25021 | 25912 | |
| 25022 | | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 25913 | IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 25023 | 25914 | if (type_is_invalid(casted_count->value->type)) |
| 25024 | | return ira->codegen->invalid_instruction; |
| 25915 | return ira->codegen->invalid_inst_gen; |
| 25025 | 25916 | |
| 25026 | 25917 | // TODO test this at comptime with u8 and non-u8 types |
| 25027 | 25918 | if (instr_is_comptime(casted_dest_ptr) && |
| ... | ... | @@ -25030,15 +25921,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25030 | 25921 | { |
| 25031 | 25922 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 25032 | 25923 | if (dest_ptr_val == nullptr) |
| 25033 | | return ira->codegen->invalid_instruction; |
| 25924 | return ira->codegen->invalid_inst_gen; |
| 25034 | 25925 | |
| 25035 | 25926 | ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); |
| 25036 | 25927 | if (byte_val == nullptr) |
| 25037 | | return ira->codegen->invalid_instruction; |
| 25928 | return ira->codegen->invalid_inst_gen; |
| 25038 | 25929 | |
| 25039 | 25930 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 25040 | 25931 | if (count_val == nullptr) |
| 25041 | | return ira->codegen->invalid_instruction; |
| 25932 | return ira->codegen->invalid_inst_gen; |
| 25042 | 25933 | |
| 25043 | 25934 | if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 25044 | 25935 | casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| ... | ... | @@ -25083,38 +25974,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 25083 | 25974 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| 25084 | 25975 | size_t end = start + count; |
| 25085 | 25976 | if (end > bound_end) { |
| 25086 | | ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access")); |
| 25087 | | return ira->codegen->invalid_instruction; |
| 25977 | ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access")); |
| 25978 | return ira->codegen->invalid_inst_gen; |
| 25088 | 25979 | } |
| 25089 | 25980 | |
| 25090 | 25981 | for (size_t i = start; i < end; i += 1) { |
| 25091 | 25982 | copy_const_val(&dest_elements[i], byte_val); |
| 25092 | 25983 | } |
| 25093 | 25984 | |
| 25094 | | return ir_const_void(ira, &instruction->base); |
| 25985 | return ir_const_void(ira, &instruction->base.base); |
| 25095 | 25986 | } |
| 25096 | 25987 | } |
| 25097 | 25988 | |
| 25098 | | IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 25099 | | casted_dest_ptr, casted_byte, casted_count); |
| 25100 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25101 | | return result; |
| 25989 | return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count); |
| 25102 | 25990 | } |
| 25103 | 25991 | |
| 25104 | | static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 25992 | static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) { |
| 25105 | 25993 | Error err; |
| 25106 | 25994 | |
| 25107 | | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 25995 | IrInstGen *dest_ptr = instruction->dest_ptr->child; |
| 25108 | 25996 | if (type_is_invalid(dest_ptr->value->type)) |
| 25109 | | return ira->codegen->invalid_instruction; |
| 25997 | return ira->codegen->invalid_inst_gen; |
| 25110 | 25998 | |
| 25111 | | IrInstruction *src_ptr = instruction->src_ptr->child; |
| 25999 | IrInstGen *src_ptr = instruction->src_ptr->child; |
| 25112 | 26000 | if (type_is_invalid(src_ptr->value->type)) |
| 25113 | | return ira->codegen->invalid_instruction; |
| 26001 | return ira->codegen->invalid_inst_gen; |
| 25114 | 26002 | |
| 25115 | | IrInstruction *count_value = instruction->count->child; |
| 26003 | IrInstGen *count_value = instruction->count->child; |
| 25116 | 26004 | if (type_is_invalid(count_value->value->type)) |
| 25117 | | return ira->codegen->invalid_instruction; |
| 26005 | return ira->codegen->invalid_inst_gen; |
| 25118 | 26006 | |
| 25119 | 26007 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 25120 | 26008 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| ... | ... | @@ -25127,7 +26015,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25127 | 26015 | uint32_t dest_align; |
| 25128 | 26016 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 25129 | 26017 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 25130 | | return ira->codegen->invalid_instruction; |
| 26018 | return ira->codegen->invalid_inst_gen; |
| 25131 | 26019 | } else { |
| 25132 | 26020 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 25133 | 26021 | } |
| ... | ... | @@ -25135,7 +26023,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25135 | 26023 | uint32_t src_align; |
| 25136 | 26024 | if (src_uncasted_type->id == ZigTypeIdPointer) { |
| 25137 | 26025 | if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align))) |
| 25138 | | return ira->codegen->invalid_instruction; |
| 26026 | return ira->codegen->invalid_inst_gen; |
| 25139 | 26027 | } else { |
| 25140 | 26028 | src_align = get_abi_alignment(ira->codegen, u8); |
| 25141 | 26029 | } |
| ... | ... | @@ -25146,17 +26034,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25146 | 26034 | ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, |
| 25147 | 26035 | PtrLenUnknown, src_align, 0, 0, false); |
| 25148 | 26036 | |
| 25149 | | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 26037 | IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 25150 | 26038 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 25151 | | return ira->codegen->invalid_instruction; |
| 26039 | return ira->codegen->invalid_inst_gen; |
| 25152 | 26040 | |
| 25153 | | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 26041 | IrInstGen *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 25154 | 26042 | if (type_is_invalid(casted_src_ptr->value->type)) |
| 25155 | | return ira->codegen->invalid_instruction; |
| 26043 | return ira->codegen->invalid_inst_gen; |
| 25156 | 26044 | |
| 25157 | | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 26045 | IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 25158 | 26046 | if (type_is_invalid(casted_count->value->type)) |
| 25159 | | return ira->codegen->invalid_instruction; |
| 26047 | return ira->codegen->invalid_inst_gen; |
| 25160 | 26048 | |
| 25161 | 26049 | // TODO test this at comptime with u8 and non-u8 types |
| 25162 | 26050 | // TODO test with dest ptr being a global runtime variable |
| ... | ... | @@ -25166,15 +26054,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25166 | 26054 | { |
| 25167 | 26055 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 25168 | 26056 | if (dest_ptr_val == nullptr) |
| 25169 | | return ira->codegen->invalid_instruction; |
| 26057 | return ira->codegen->invalid_inst_gen; |
| 25170 | 26058 | |
| 25171 | 26059 | ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); |
| 25172 | 26060 | if (src_ptr_val == nullptr) |
| 25173 | | return ira->codegen->invalid_instruction; |
| 26061 | return ira->codegen->invalid_inst_gen; |
| 25174 | 26062 | |
| 25175 | 26063 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 25176 | 26064 | if (count_val == nullptr) |
| 25177 | | return ira->codegen->invalid_instruction; |
| 26065 | return ira->codegen->invalid_inst_gen; |
| 25178 | 26066 | |
| 25179 | 26067 | if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 25180 | 26068 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| ... | ... | @@ -25217,8 +26105,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25217 | 26105 | } |
| 25218 | 26106 | |
| 25219 | 26107 | if (dest_start + count > dest_end) { |
| 25220 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 25221 | | return ira->codegen->invalid_instruction; |
| 26108 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 26109 | return ira->codegen->invalid_inst_gen; |
| 25222 | 26110 | } |
| 25223 | 26111 | |
| 25224 | 26112 | ZigValue *src_elements; |
| ... | ... | @@ -25260,8 +26148,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25260 | 26148 | } |
| 25261 | 26149 | |
| 25262 | 26150 | if (src_start + count > src_end) { |
| 25263 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 25264 | | return ira->codegen->invalid_instruction; |
| 26151 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 26152 | return ira->codegen->invalid_inst_gen; |
| 25265 | 26153 | } |
| 25266 | 26154 | |
| 25267 | 26155 | // TODO check for noalias violations - this should be generalized to work for any function |
| ... | ... | @@ -25270,42 +26158,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 25270 | 26158 | copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]); |
| 25271 | 26159 | } |
| 25272 | 26160 | |
| 25273 | | return ir_const_void(ira, &instruction->base); |
| 26161 | return ir_const_void(ira, &instruction->base.base); |
| 25274 | 26162 | } |
| 25275 | 26163 | } |
| 25276 | 26164 | |
| 25277 | | IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 25278 | | casted_dest_ptr, casted_src_ptr, casted_count); |
| 25279 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25280 | | return result; |
| 26165 | return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count); |
| 25281 | 26166 | } |
| 25282 | 26167 | |
| 25283 | | static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) { |
| 25284 | | IrInstruction *ptr_ptr = instruction->ptr->child; |
| 26168 | static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) { |
| 26169 | IrInstGen *ptr_ptr = instruction->ptr->child; |
| 25285 | 26170 | if (type_is_invalid(ptr_ptr->value->type)) |
| 25286 | | return ira->codegen->invalid_instruction; |
| 26171 | return ira->codegen->invalid_inst_gen; |
| 25287 | 26172 | |
| 25288 | 26173 | ZigType *ptr_ptr_type = ptr_ptr->value->type; |
| 25289 | 26174 | assert(ptr_ptr_type->id == ZigTypeIdPointer); |
| 25290 | 26175 | ZigType *array_type = ptr_ptr_type->data.pointer.child_type; |
| 25291 | 26176 | |
| 25292 | | IrInstruction *start = instruction->start->child; |
| 26177 | IrInstGen *start = instruction->start->child; |
| 25293 | 26178 | if (type_is_invalid(start->value->type)) |
| 25294 | | return ira->codegen->invalid_instruction; |
| 26179 | return ira->codegen->invalid_inst_gen; |
| 25295 | 26180 | |
| 25296 | 26181 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 25297 | | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 26182 | IrInstGen *casted_start = ir_implicit_cast(ira, start, usize); |
| 25298 | 26183 | if (type_is_invalid(casted_start->value->type)) |
| 25299 | | return ira->codegen->invalid_instruction; |
| 26184 | return ira->codegen->invalid_inst_gen; |
| 25300 | 26185 | |
| 25301 | | IrInstruction *end; |
| 26186 | IrInstGen *end; |
| 25302 | 26187 | if (instruction->end) { |
| 25303 | 26188 | end = instruction->end->child; |
| 25304 | 26189 | if (type_is_invalid(end->value->type)) |
| 25305 | | return ira->codegen->invalid_instruction; |
| 26190 | return ira->codegen->invalid_inst_gen; |
| 25306 | 26191 | end = ir_implicit_cast(ira, end, usize); |
| 25307 | 26192 | if (type_is_invalid(end->value->type)) |
| 25308 | | return ira->codegen->invalid_instruction; |
| 26193 | return ira->codegen->invalid_inst_gen; |
| 25309 | 26194 | } else { |
| 25310 | 26195 | end = nullptr; |
| 25311 | 26196 | } |
| ... | ... | @@ -25333,8 +26218,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25333 | 26218 | PtrLenUnknown, |
| 25334 | 26219 | array_type->data.pointer.explicit_alignment, 0, 0, false); |
| 25335 | 26220 | } else { |
| 25336 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); |
| 25337 | | return ira->codegen->invalid_instruction; |
| 26221 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer")); |
| 26222 | return ira->codegen->invalid_inst_gen; |
| 25338 | 26223 | } |
| 25339 | 26224 | } else { |
| 25340 | 26225 | elem_type = array_type->data.pointer.child_type; |
| ... | ... | @@ -25344,8 +26229,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25344 | 26229 | ZigType *maybe_sentineled_slice_ptr_type = array_type; |
| 25345 | 26230 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 25346 | 26231 | if (!end) { |
| 25347 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
| 25348 | | return ira->codegen->invalid_instruction; |
| 26232 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value")); |
| 26233 | return ira->codegen->invalid_inst_gen; |
| 25349 | 26234 | } |
| 25350 | 26235 | } |
| 25351 | 26236 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -25353,23 +26238,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25353 | 26238 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 25354 | 26239 | elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type; |
| 25355 | 26240 | } else { |
| 25356 | | ir_add_error(ira, &instruction->base, |
| 26241 | ir_add_error(ira, &instruction->base.base, |
| 25357 | 26242 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name))); |
| 25358 | | return ira->codegen->invalid_instruction; |
| 26243 | return ira->codegen->invalid_inst_gen; |
| 25359 | 26244 | } |
| 25360 | 26245 | |
| 25361 | 26246 | ZigType *return_type; |
| 25362 | 26247 | ZigValue *sentinel_val = nullptr; |
| 25363 | 26248 | if (instruction->sentinel) { |
| 25364 | | IrInstruction *uncasted_sentinel = instruction->sentinel->child; |
| 26249 | IrInstGen *uncasted_sentinel = instruction->sentinel->child; |
| 25365 | 26250 | if (type_is_invalid(uncasted_sentinel->value->type)) |
| 25366 | | return ira->codegen->invalid_instruction; |
| 25367 | | IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type); |
| 26251 | return ira->codegen->invalid_inst_gen; |
| 26252 | IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type); |
| 25368 | 26253 | if (type_is_invalid(sentinel->value->type)) |
| 25369 | | return ira->codegen->invalid_instruction; |
| 26254 | return ira->codegen->invalid_inst_gen; |
| 25370 | 26255 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 25371 | 26256 | if (sentinel_val == nullptr) |
| 25372 | | return ira->codegen->invalid_instruction; |
| 26257 | return ira->codegen->invalid_inst_gen; |
| 25373 | 26258 | ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val); |
| 25374 | 26259 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 25375 | 26260 | } else { |
| ... | ... | @@ -25391,9 +26276,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25391 | 26276 | if (array_type->id == ZigTypeIdPointer) { |
| 25392 | 26277 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 25393 | 26278 | assert(child_array_type->id == ZigTypeIdArray); |
| 25394 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26279 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25395 | 26280 | if (parent_ptr == nullptr) |
| 25396 | | return ira->codegen->invalid_instruction; |
| 26281 | return ira->codegen->invalid_inst_gen; |
| 25397 | 26282 | |
| 25398 | 26283 | |
| 25399 | 26284 | if (parent_ptr->special == ConstValSpecialUndef) { |
| ... | ... | @@ -25402,26 +26287,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25402 | 26287 | rel_end = SIZE_MAX; |
| 25403 | 26288 | ptr_is_undef = true; |
| 25404 | 26289 | } else { |
| 25405 | | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); |
| 26290 | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node); |
| 25406 | 26291 | if (array_val == nullptr) |
| 25407 | | return ira->codegen->invalid_instruction; |
| 26292 | return ira->codegen->invalid_inst_gen; |
| 25408 | 26293 | |
| 25409 | 26294 | rel_end = child_array_type->data.array.len; |
| 25410 | 26295 | abs_offset = 0; |
| 25411 | 26296 | } |
| 25412 | 26297 | } else { |
| 25413 | | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26298 | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25414 | 26299 | if (array_val == nullptr) |
| 25415 | | return ira->codegen->invalid_instruction; |
| 26300 | return ira->codegen->invalid_inst_gen; |
| 25416 | 26301 | rel_end = array_type->data.array.len; |
| 25417 | 26302 | parent_ptr = nullptr; |
| 25418 | 26303 | abs_offset = 0; |
| 25419 | 26304 | } |
| 25420 | 26305 | } else if (array_type->id == ZigTypeIdPointer) { |
| 25421 | 26306 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 25422 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26307 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25423 | 26308 | if (parent_ptr == nullptr) |
| 25424 | | return ira->codegen->invalid_instruction; |
| 26309 | return ira->codegen->invalid_inst_gen; |
| 25425 | 26310 | |
| 25426 | 26311 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 25427 | 26312 | array_val = nullptr; |
| ... | ... | @@ -25467,19 +26352,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25467 | 26352 | zig_panic("TODO slice of null ptr"); |
| 25468 | 26353 | } |
| 25469 | 26354 | } else if (is_slice(array_type)) { |
| 25470 | | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 26355 | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 25471 | 26356 | if (slice_ptr == nullptr) |
| 25472 | | return ira->codegen->invalid_instruction; |
| 26357 | return ira->codegen->invalid_inst_gen; |
| 25473 | 26358 | |
| 25474 | 26359 | if (slice_ptr->special == ConstValSpecialUndef) { |
| 25475 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| 25476 | | return ira->codegen->invalid_instruction; |
| 26360 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 26361 | return ira->codegen->invalid_inst_gen; |
| 25477 | 26362 | } |
| 25478 | 26363 | |
| 25479 | 26364 | parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 25480 | 26365 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 25481 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| 25482 | | return ira->codegen->invalid_instruction; |
| 26366 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 26367 | return ira->codegen->invalid_inst_gen; |
| 25483 | 26368 | } |
| 25484 | 26369 | |
| 25485 | 26370 | ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; |
| ... | ... | @@ -25522,37 +26407,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25522 | 26407 | |
| 25523 | 26408 | ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); |
| 25524 | 26409 | if (!start_val) |
| 25525 | | return ira->codegen->invalid_instruction; |
| 26410 | return ira->codegen->invalid_inst_gen; |
| 25526 | 26411 | |
| 25527 | 26412 | uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint); |
| 25528 | 26413 | if (!ptr_is_undef && start_scalar > rel_end) { |
| 25529 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 25530 | | return ira->codegen->invalid_instruction; |
| 26414 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 26415 | return ira->codegen->invalid_inst_gen; |
| 25531 | 26416 | } |
| 25532 | 26417 | |
| 25533 | 26418 | uint64_t end_scalar = rel_end; |
| 25534 | 26419 | if (end) { |
| 25535 | 26420 | ZigValue *end_val = ir_resolve_const(ira, end, UndefBad); |
| 25536 | 26421 | if (!end_val) |
| 25537 | | return ira->codegen->invalid_instruction; |
| 26422 | return ira->codegen->invalid_inst_gen; |
| 25538 | 26423 | end_scalar = bigint_as_u64(&end_val->data.x_bigint); |
| 25539 | 26424 | } |
| 25540 | 26425 | if (!ptr_is_undef) { |
| 25541 | 26426 | if (end_scalar > rel_end) { |
| 25542 | | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 25543 | | return ira->codegen->invalid_instruction; |
| 26427 | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 26428 | return ira->codegen->invalid_inst_gen; |
| 25544 | 26429 | } |
| 25545 | 26430 | if (start_scalar > end_scalar) { |
| 25546 | | ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end")); |
| 25547 | | return ira->codegen->invalid_instruction; |
| 26431 | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end")); |
| 26432 | return ira->codegen->invalid_inst_gen; |
| 25548 | 26433 | } |
| 25549 | 26434 | } |
| 25550 | 26435 | if (ptr_is_undef && start_scalar != end_scalar) { |
| 25551 | | ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 25552 | | return ira->codegen->invalid_instruction; |
| 26436 | ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 26437 | return ira->codegen->invalid_inst_gen; |
| 25553 | 26438 | } |
| 25554 | 26439 | |
| 25555 | | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 26440 | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 25556 | 26441 | ZigValue *out_val = result->value; |
| 25557 | 26442 | out_val->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 25558 | 26443 | |
| ... | ... | @@ -25609,28 +26494,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 25609 | 26494 | return result; |
| 25610 | 26495 | } |
| 25611 | 26496 | |
| 25612 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 26497 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 25613 | 26498 | return_type, nullptr, true, false, true); |
| 25614 | | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 26499 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 25615 | 26500 | return result_loc; |
| 25616 | 26501 | } |
| 25617 | | return ir_build_slice_gen(ira, &instruction->base, return_type, |
| 26502 | return ir_build_slice_gen(ira, &instruction->base.base, return_type, |
| 25618 | 26503 | ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc); |
| 25619 | 26504 | } |
| 25620 | 26505 | |
| 25621 | | static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 26506 | static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) { |
| 25622 | 26507 | Error err; |
| 25623 | | IrInstruction *container = instruction->container->child; |
| 26508 | IrInstGen *container = instruction->container->child; |
| 25624 | 26509 | if (type_is_invalid(container->value->type)) |
| 25625 | | return ira->codegen->invalid_instruction; |
| 26510 | return ira->codegen->invalid_inst_gen; |
| 25626 | 26511 | ZigType *container_type = ir_resolve_type(ira, container); |
| 25627 | 26512 | |
| 25628 | 26513 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25629 | | return ira->codegen->invalid_instruction; |
| 26514 | return ira->codegen->invalid_inst_gen; |
| 25630 | 26515 | |
| 25631 | 26516 | uint64_t result; |
| 25632 | 26517 | if (type_is_invalid(container_type)) { |
| 25633 | | return ira->codegen->invalid_instruction; |
| 26518 | return ira->codegen->invalid_inst_gen; |
| 25634 | 26519 | } else if (container_type->id == ZigTypeIdEnum) { |
| 25635 | 26520 | result = container_type->data.enumeration.src_field_count; |
| 25636 | 26521 | } else if (container_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -25638,135 +26523,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst |
| 25638 | 26523 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25639 | 26524 | result = container_type->data.unionation.src_field_count; |
| 25640 | 26525 | } else if (container_type->id == ZigTypeIdErrorSet) { |
| 25641 | | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 25642 | | return ira->codegen->invalid_instruction; |
| 26526 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) { |
| 26527 | return ira->codegen->invalid_inst_gen; |
| 25643 | 26528 | } |
| 25644 | 26529 | if (type_is_global_error_set(container_type)) { |
| 25645 | | ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime")); |
| 25646 | | return ira->codegen->invalid_instruction; |
| 26530 | ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime")); |
| 26531 | return ira->codegen->invalid_inst_gen; |
| 25647 | 26532 | } |
| 25648 | 26533 | result = container_type->data.error_set.err_count; |
| 25649 | 26534 | } else { |
| 25650 | | ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 25651 | | return ira->codegen->invalid_instruction; |
| 26535 | ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 26536 | return ira->codegen->invalid_inst_gen; |
| 25652 | 26537 | } |
| 25653 | 26538 | |
| 25654 | | return ir_const_unsigned(ira, &instruction->base, result); |
| 26539 | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 25655 | 26540 | } |
| 25656 | 26541 | |
| 25657 | | static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { |
| 26542 | static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) { |
| 25658 | 26543 | Error err; |
| 25659 | | IrInstruction *container_type_value = instruction->container_type->child; |
| 26544 | IrInstGen *container_type_value = instruction->container_type->child; |
| 25660 | 26545 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 25661 | 26546 | if (type_is_invalid(container_type)) |
| 25662 | | return ira->codegen->invalid_instruction; |
| 26547 | return ira->codegen->invalid_inst_gen; |
| 25663 | 26548 | |
| 25664 | 26549 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25665 | | return ira->codegen->invalid_instruction; |
| 26550 | return ira->codegen->invalid_inst_gen; |
| 25666 | 26551 | |
| 25667 | 26552 | |
| 25668 | 26553 | uint64_t member_index; |
| 25669 | | IrInstruction *index_value = instruction->member_index->child; |
| 26554 | IrInstGen *index_value = instruction->member_index->child; |
| 25670 | 26555 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 25671 | | return ira->codegen->invalid_instruction; |
| 26556 | return ira->codegen->invalid_inst_gen; |
| 25672 | 26557 | |
| 25673 | 26558 | if (container_type->id == ZigTypeIdStruct) { |
| 25674 | 26559 | if (member_index >= container_type->data.structure.src_field_count) { |
| 25675 | | ir_add_error(ira, index_value, |
| 26560 | ir_add_error(ira, &index_value->base, |
| 25676 | 26561 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25677 | 26562 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 25678 | | return ira->codegen->invalid_instruction; |
| 26563 | return ira->codegen->invalid_inst_gen; |
| 25679 | 26564 | } |
| 25680 | 26565 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 25681 | 26566 | |
| 25682 | | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 26567 | return ir_const_type(ira, &instruction->base.base, field->type_entry); |
| 25683 | 26568 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25684 | 26569 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 25685 | | ir_add_error(ira, index_value, |
| 26570 | ir_add_error(ira, &index_value->base, |
| 25686 | 26571 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25687 | 26572 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 25688 | | return ira->codegen->invalid_instruction; |
| 26573 | return ira->codegen->invalid_inst_gen; |
| 25689 | 26574 | } |
| 25690 | 26575 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 25691 | 26576 | |
| 25692 | | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 26577 | return ir_const_type(ira, &instruction->base.base, field->type_entry); |
| 25693 | 26578 | } else { |
| 25694 | | ir_add_error(ira, container_type_value, |
| 26579 | ir_add_error(ira, &container_type_value->base, |
| 25695 | 26580 | buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name))); |
| 25696 | | return ira->codegen->invalid_instruction; |
| 26581 | return ira->codegen->invalid_inst_gen; |
| 25697 | 26582 | } |
| 25698 | 26583 | } |
| 25699 | 26584 | |
| 25700 | | static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { |
| 26585 | static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) { |
| 25701 | 26586 | Error err; |
| 25702 | | IrInstruction *container_type_value = instruction->container_type->child; |
| 26587 | IrInstGen *container_type_value = instruction->container_type->child; |
| 25703 | 26588 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 25704 | 26589 | if (type_is_invalid(container_type)) |
| 25705 | | return ira->codegen->invalid_instruction; |
| 26590 | return ira->codegen->invalid_inst_gen; |
| 25706 | 26591 | |
| 25707 | 26592 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown))) |
| 25708 | | return ira->codegen->invalid_instruction; |
| 26593 | return ira->codegen->invalid_inst_gen; |
| 25709 | 26594 | |
| 25710 | 26595 | uint64_t member_index; |
| 25711 | | IrInstruction *index_value = instruction->member_index->child; |
| 26596 | IrInstGen *index_value = instruction->member_index->child; |
| 25712 | 26597 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 25713 | | return ira->codegen->invalid_instruction; |
| 26598 | return ira->codegen->invalid_inst_gen; |
| 25714 | 26599 | |
| 25715 | 26600 | if (container_type->id == ZigTypeIdStruct) { |
| 25716 | 26601 | if (member_index >= container_type->data.structure.src_field_count) { |
| 25717 | | ir_add_error(ira, index_value, |
| 26602 | ir_add_error(ira, &index_value->base, |
| 25718 | 26603 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25719 | 26604 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 25720 | | return ira->codegen->invalid_instruction; |
| 26605 | return ira->codegen->invalid_inst_gen; |
| 25721 | 26606 | } |
| 25722 | 26607 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 25723 | 26608 | |
| 25724 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26609 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25725 | 26610 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25726 | 26611 | return result; |
| 25727 | 26612 | } else if (container_type->id == ZigTypeIdEnum) { |
| 25728 | 26613 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| 25729 | | ir_add_error(ira, index_value, |
| 26614 | ir_add_error(ira, &index_value->base, |
| 25730 | 26615 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25731 | 26616 | member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count)); |
| 25732 | | return ira->codegen->invalid_instruction; |
| 26617 | return ira->codegen->invalid_inst_gen; |
| 25733 | 26618 | } |
| 25734 | 26619 | TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; |
| 25735 | 26620 | |
| 25736 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26621 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25737 | 26622 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25738 | 26623 | return result; |
| 25739 | 26624 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25740 | 26625 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 25741 | | ir_add_error(ira, index_value, |
| 26626 | ir_add_error(ira, &index_value->base, |
| 25742 | 26627 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 25743 | 26628 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 25744 | | return ira->codegen->invalid_instruction; |
| 26629 | return ira->codegen->invalid_inst_gen; |
| 25745 | 26630 | } |
| 25746 | 26631 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 25747 | 26632 | |
| 25748 | | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 26633 | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 25749 | 26634 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 25750 | 26635 | return result; |
| 25751 | 26636 | } else { |
| 25752 | | ir_add_error(ira, container_type_value, |
| 26637 | ir_add_error(ira, &container_type_value->base, |
| 25753 | 26638 | buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name))); |
| 25754 | | return ira->codegen->invalid_instruction; |
| 26639 | return ira->codegen->invalid_inst_gen; |
| 25755 | 26640 | } |
| 25756 | 26641 | } |
| 25757 | 26642 | |
| 25758 | | static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) { |
| 26643 | static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) { |
| 25759 | 26644 | Error err; |
| 25760 | 26645 | ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child); |
| 25761 | 26646 | if (type_is_invalid(container_type)) |
| 25762 | | return ira->codegen->invalid_instruction; |
| 26647 | return ira->codegen->invalid_inst_gen; |
| 25763 | 26648 | |
| 25764 | 26649 | if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown))) |
| 25765 | | return ira->codegen->invalid_instruction; |
| 26650 | return ira->codegen->invalid_inst_gen; |
| 25766 | 26651 | |
| 25767 | 26652 | Buf *field_name = ir_resolve_str(ira, instruction->field_name->child); |
| 25768 | 26653 | if (field_name == nullptr) |
| 25769 | | return ira->codegen->invalid_instruction; |
| 26654 | return ira->codegen->invalid_inst_gen; |
| 25770 | 26655 | |
| 25771 | 26656 | bool result; |
| 25772 | 26657 | if (container_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -25776,91 +26661,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc |
| 25776 | 26661 | } else if (container_type->id == ZigTypeIdUnion) { |
| 25777 | 26662 | result = find_union_type_field(container_type, field_name) != nullptr; |
| 25778 | 26663 | } else { |
| 25779 | | ir_add_error(ira, instruction->container_type, |
| 26664 | ir_add_error(ira, &instruction->container_type->base, |
| 25780 | 26665 | buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name))); |
| 25781 | | return ira->codegen->invalid_instruction; |
| 26666 | return ira->codegen->invalid_inst_gen; |
| 25782 | 26667 | } |
| 25783 | | return ir_const_bool(ira, &instruction->base, result); |
| 26668 | return ir_const_bool(ira, &instruction->base.base, result); |
| 25784 | 26669 | } |
| 25785 | 26670 | |
| 25786 | | static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 25787 | | IrInstruction *result = ir_build_breakpoint(&ira->new_irb, |
| 25788 | | instruction->base.scope, instruction->base.source_node); |
| 25789 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 25790 | | return result; |
| 26671 | static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) { |
| 26672 | return ir_build_breakpoint_gen(ira, &instruction->base.base); |
| 25791 | 26673 | } |
| 25792 | 26674 | |
| 25793 | | static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 25794 | | IrInstruction *result = ir_build_return_address(&ira->new_irb, |
| 25795 | | instruction->base.scope, instruction->base.source_node); |
| 25796 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25797 | | return result; |
| 26675 | static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) { |
| 26676 | return ir_build_return_address_gen(ira, &instruction->base.base); |
| 25798 | 26677 | } |
| 25799 | 26678 | |
| 25800 | | static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 25801 | | IrInstruction *result = ir_build_frame_address(&ira->new_irb, |
| 25802 | | instruction->base.scope, instruction->base.source_node); |
| 25803 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25804 | | return result; |
| 26679 | static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) { |
| 26680 | return ir_build_frame_address_gen(ira, &instruction->base.base); |
| 25805 | 26681 | } |
| 25806 | 26682 | |
| 25807 | | static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) { |
| 25808 | | ZigFn *fn = exec_fn_entry(ira->new_irb.exec); |
| 25809 | | ir_assert(fn != nullptr, &instruction->base); |
| 26683 | static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) { |
| 26684 | ZigFn *fn = ira->new_irb.exec->fn_entry; |
| 26685 | ir_assert(fn != nullptr, &instruction->base.base); |
| 25810 | 26686 | |
| 25811 | 26687 | if (fn->inferred_async_node == nullptr) { |
| 25812 | | fn->inferred_async_node = instruction->base.source_node; |
| 26688 | fn->inferred_async_node = instruction->base.base.source_node; |
| 25813 | 26689 | } |
| 25814 | 26690 | |
| 25815 | 26691 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn); |
| 25816 | 26692 | ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); |
| 25817 | 26693 | |
| 25818 | | IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 25819 | | result->value->type = ptr_frame_type; |
| 25820 | | return result; |
| 26694 | return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type); |
| 25821 | 26695 | } |
| 25822 | 26696 | |
| 25823 | | static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) { |
| 26697 | static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) { |
| 25824 | 26698 | ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child); |
| 25825 | 26699 | if (fn == nullptr) |
| 25826 | | return ira->codegen->invalid_instruction; |
| 26700 | return ira->codegen->invalid_inst_gen; |
| 25827 | 26701 | |
| 25828 | 26702 | if (fn->type_entry->data.fn.is_generic) { |
| 25829 | | ir_add_error(ira, &instruction->base, |
| 26703 | ir_add_error(ira, &instruction->base.base, |
| 25830 | 26704 | buf_sprintf("@Frame() of generic function")); |
| 25831 | | return ira->codegen->invalid_instruction; |
| 26705 | return ira->codegen->invalid_inst_gen; |
| 25832 | 26706 | } |
| 25833 | 26707 | |
| 25834 | 26708 | ZigType *ty = get_fn_frame_type(ira->codegen, fn); |
| 25835 | | return ir_const_type(ira, &instruction->base, ty); |
| 26709 | return ir_const_type(ira, &instruction->base.base, ty); |
| 25836 | 26710 | } |
| 25837 | 26711 | |
| 25838 | | static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) { |
| 25839 | | IrInstruction *fn = instruction->fn->child; |
| 26712 | static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) { |
| 26713 | IrInstGen *fn = instruction->fn->child; |
| 25840 | 26714 | if (type_is_invalid(fn->value->type)) |
| 25841 | | return ira->codegen->invalid_instruction; |
| 26715 | return ira->codegen->invalid_inst_gen; |
| 25842 | 26716 | |
| 25843 | 26717 | if (fn->value->type->id != ZigTypeIdFn) { |
| 25844 | | ir_add_error(ira, fn, |
| 26718 | ir_add_error(ira, &fn->base, |
| 25845 | 26719 | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); |
| 25846 | | return ira->codegen->invalid_instruction; |
| 26720 | return ira->codegen->invalid_inst_gen; |
| 25847 | 26721 | } |
| 25848 | 26722 | |
| 25849 | 26723 | ira->codegen->need_frame_size_prefix_data = true; |
| 25850 | 26724 | |
| 25851 | | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, |
| 25852 | | instruction->base.source_node, fn); |
| 25853 | | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 25854 | | return result; |
| 26725 | return ir_build_frame_size_gen(ira, &instruction->base.base, fn); |
| 25855 | 26726 | } |
| 25856 | 26727 | |
| 25857 | | static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 26728 | static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) { |
| 25858 | 26729 | // Here we create a lazy value in order to avoid resolving the alignment of the type |
| 25859 | 26730 | // immediately. This avoids false positive dependency loops such as: |
| 25860 | 26731 | // const Node = struct { |
| 25861 | 26732 | // field: []align(@alignOf(Node)) Node, |
| 25862 | 26733 | // }; |
| 25863 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 26734 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 25864 | 26735 | result->value->special = ConstValSpecialLazy; |
| 25865 | 26736 | |
| 25866 | 26737 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf"); |
| ... | ... | @@ -25870,41 +26741,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 25870 | 26741 | |
| 25871 | 26742 | lazy_align_of->target_type = instruction->type_value->child; |
| 25872 | 26743 | if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr) |
| 25873 | | return ira->codegen->invalid_instruction; |
| 26744 | return ira->codegen->invalid_inst_gen; |
| 25874 | 26745 | |
| 25875 | 26746 | return result; |
| 25876 | 26747 | } |
| 25877 | 26748 | |
| 25878 | | static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 26749 | static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) { |
| 25879 | 26750 | Error err; |
| 25880 | 26751 | |
| 25881 | | IrInstruction *type_value = instruction->type_value->child; |
| 26752 | IrInstGen *type_value = instruction->type_value->child; |
| 25882 | 26753 | if (type_is_invalid(type_value->value->type)) |
| 25883 | | return ira->codegen->invalid_instruction; |
| 26754 | return ira->codegen->invalid_inst_gen; |
| 25884 | 26755 | |
| 25885 | 26756 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| 25886 | 26757 | if (type_is_invalid(dest_type)) |
| 25887 | | return ira->codegen->invalid_instruction; |
| 26758 | return ira->codegen->invalid_inst_gen; |
| 25888 | 26759 | |
| 25889 | 26760 | if (dest_type->id != ZigTypeIdInt) { |
| 25890 | | ir_add_error(ira, type_value, |
| 26761 | ir_add_error(ira, &type_value->base, |
| 25891 | 26762 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 25892 | | return ira->codegen->invalid_instruction; |
| 26763 | return ira->codegen->invalid_inst_gen; |
| 25893 | 26764 | } |
| 25894 | 26765 | |
| 25895 | | IrInstruction *op1 = instruction->op1->child; |
| 26766 | IrInstGen *op1 = instruction->op1->child; |
| 25896 | 26767 | if (type_is_invalid(op1->value->type)) |
| 25897 | | return ira->codegen->invalid_instruction; |
| 26768 | return ira->codegen->invalid_inst_gen; |
| 25898 | 26769 | |
| 25899 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 26770 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 25900 | 26771 | if (type_is_invalid(casted_op1->value->type)) |
| 25901 | | return ira->codegen->invalid_instruction; |
| 26772 | return ira->codegen->invalid_inst_gen; |
| 25902 | 26773 | |
| 25903 | | IrInstruction *op2 = instruction->op2->child; |
| 26774 | IrInstGen *op2 = instruction->op2->child; |
| 25904 | 26775 | if (type_is_invalid(op2->value->type)) |
| 25905 | | return ira->codegen->invalid_instruction; |
| 26776 | return ira->codegen->invalid_inst_gen; |
| 25906 | 26777 | |
| 25907 | | IrInstruction *casted_op2; |
| 26778 | IrInstGen *casted_op2; |
| 25908 | 26779 | if (instruction->op == IrOverflowOpShl) { |
| 25909 | 26780 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 25910 | 26781 | dest_type->data.integral.bit_count - 1); |
| ... | ... | @@ -25913,17 +26784,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25913 | 26784 | casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 25914 | 26785 | } |
| 25915 | 26786 | if (type_is_invalid(casted_op2->value->type)) |
| 25916 | | return ira->codegen->invalid_instruction; |
| 26787 | return ira->codegen->invalid_inst_gen; |
| 25917 | 26788 | |
| 25918 | | IrInstruction *result_ptr = instruction->result_ptr->child; |
| 26789 | IrInstGen *result_ptr = instruction->result_ptr->child; |
| 25919 | 26790 | if (type_is_invalid(result_ptr->value->type)) |
| 25920 | | return ira->codegen->invalid_instruction; |
| 26791 | return ira->codegen->invalid_inst_gen; |
| 25921 | 26792 | |
| 25922 | 26793 | ZigType *expected_ptr_type; |
| 25923 | 26794 | if (result_ptr->value->type->id == ZigTypeIdPointer) { |
| 25924 | 26795 | uint32_t alignment; |
| 25925 | 26796 | if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment))) |
| 25926 | | return ira->codegen->invalid_instruction; |
| 26797 | return ira->codegen->invalid_inst_gen; |
| 25927 | 26798 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 25928 | 26799 | false, result_ptr->value->type->data.pointer.is_volatile, |
| 25929 | 26800 | PtrLenSingle, |
| ... | ... | @@ -25932,9 +26803,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25932 | 26803 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); |
| 25933 | 26804 | } |
| 25934 | 26805 | |
| 25935 | | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 26806 | IrInstGen *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 25936 | 26807 | if (type_is_invalid(casted_result_ptr->value->type)) |
| 25937 | | return ira->codegen->invalid_instruction; |
| 26808 | return ira->codegen->invalid_inst_gen; |
| 25938 | 26809 | |
| 25939 | 26810 | if (instr_is_comptime(casted_op1) && |
| 25940 | 26811 | instr_is_comptime(casted_op2) && |
| ... | ... | @@ -25942,22 +26813,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25942 | 26813 | { |
| 25943 | 26814 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 25944 | 26815 | if (op1_val == nullptr) |
| 25945 | | return ira->codegen->invalid_instruction; |
| 26816 | return ira->codegen->invalid_inst_gen; |
| 25946 | 26817 | |
| 25947 | 26818 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 25948 | 26819 | if (op2_val == nullptr) |
| 25949 | | return ira->codegen->invalid_instruction; |
| 26820 | return ira->codegen->invalid_inst_gen; |
| 25950 | 26821 | |
| 25951 | 26822 | ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); |
| 25952 | 26823 | if (result_val == nullptr) |
| 25953 | | return ira->codegen->invalid_instruction; |
| 26824 | return ira->codegen->invalid_inst_gen; |
| 25954 | 26825 | |
| 25955 | 26826 | BigInt *op1_bigint = &op1_val->data.x_bigint; |
| 25956 | 26827 | BigInt *op2_bigint = &op2_val->data.x_bigint; |
| 25957 | 26828 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, |
| 25958 | | casted_result_ptr->source_node); |
| 26829 | casted_result_ptr->base.source_node); |
| 25959 | 26830 | if (pointee_val == nullptr) |
| 25960 | | return ira->codegen->invalid_instruction; |
| 26831 | return ira->codegen->invalid_inst_gen; |
| 25961 | 26832 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 25962 | 26833 | switch (instruction->op) { |
| 25963 | 26834 | case IrOverflowOpAdd: |
| ... | ... | @@ -25984,17 +26855,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 25984 | 26855 | dest_type->data.integral.is_signed); |
| 25985 | 26856 | } |
| 25986 | 26857 | pointee_val->special = ConstValSpecialStatic; |
| 25987 | | return ir_const_bool(ira, &instruction->base, result_bool); |
| 26858 | return ir_const_bool(ira, &instruction->base.base, result_bool); |
| 25988 | 26859 | } |
| 25989 | 26860 | |
| 25990 | | IrInstruction *result = ir_build_overflow_op(&ira->new_irb, |
| 25991 | | instruction->base.scope, instruction->base.source_node, |
| 25992 | | instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 25993 | | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 25994 | | return result; |
| 26861 | return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op, |
| 26862 | casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 25995 | 26863 | } |
| 25996 | 26864 | |
| 25997 | | static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type, |
| 26865 | static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type, |
| 25998 | 26866 | ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) { |
| 25999 | 26867 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 26000 | 26868 | f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value, |
| ... | ... | @@ -26021,61 +26889,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z |
| 26021 | 26889 | } |
| 26022 | 26890 | } |
| 26023 | 26891 | |
| 26024 | | static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) { |
| 26025 | | IrInstruction *type_value = instruction->type_value->child; |
| 26892 | static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) { |
| 26893 | IrInstGen *type_value = instruction->type_value->child; |
| 26026 | 26894 | if (type_is_invalid(type_value->value->type)) |
| 26027 | | return ira->codegen->invalid_instruction; |
| 26895 | return ira->codegen->invalid_inst_gen; |
| 26028 | 26896 | |
| 26029 | 26897 | ZigType *expr_type = ir_resolve_type(ira, type_value); |
| 26030 | 26898 | if (type_is_invalid(expr_type)) |
| 26031 | | return ira->codegen->invalid_instruction; |
| 26899 | return ira->codegen->invalid_inst_gen; |
| 26032 | 26900 | |
| 26033 | 26901 | // Only allow float types, and vectors of floats. |
| 26034 | 26902 | ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
| 26035 | 26903 | if (float_type->id != ZigTypeIdFloat) { |
| 26036 | | ir_add_error(ira, type_value, |
| 26904 | ir_add_error(ira, &type_value->base, |
| 26037 | 26905 | buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name))); |
| 26038 | | return ira->codegen->invalid_instruction; |
| 26906 | return ira->codegen->invalid_inst_gen; |
| 26039 | 26907 | } |
| 26040 | 26908 | |
| 26041 | | IrInstruction *op1 = instruction->op1->child; |
| 26909 | IrInstGen *op1 = instruction->op1->child; |
| 26042 | 26910 | if (type_is_invalid(op1->value->type)) |
| 26043 | | return ira->codegen->invalid_instruction; |
| 26911 | return ira->codegen->invalid_inst_gen; |
| 26044 | 26912 | |
| 26045 | | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 26913 | IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 26046 | 26914 | if (type_is_invalid(casted_op1->value->type)) |
| 26047 | | return ira->codegen->invalid_instruction; |
| 26915 | return ira->codegen->invalid_inst_gen; |
| 26048 | 26916 | |
| 26049 | | IrInstruction *op2 = instruction->op2->child; |
| 26917 | IrInstGen *op2 = instruction->op2->child; |
| 26050 | 26918 | if (type_is_invalid(op2->value->type)) |
| 26051 | | return ira->codegen->invalid_instruction; |
| 26919 | return ira->codegen->invalid_inst_gen; |
| 26052 | 26920 | |
| 26053 | | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 26921 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 26054 | 26922 | if (type_is_invalid(casted_op2->value->type)) |
| 26055 | | return ira->codegen->invalid_instruction; |
| 26923 | return ira->codegen->invalid_inst_gen; |
| 26056 | 26924 | |
| 26057 | | IrInstruction *op3 = instruction->op3->child; |
| 26925 | IrInstGen *op3 = instruction->op3->child; |
| 26058 | 26926 | if (type_is_invalid(op3->value->type)) |
| 26059 | | return ira->codegen->invalid_instruction; |
| 26927 | return ira->codegen->invalid_inst_gen; |
| 26060 | 26928 | |
| 26061 | | IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 26929 | IrInstGen *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 26062 | 26930 | if (type_is_invalid(casted_op3->value->type)) |
| 26063 | | return ira->codegen->invalid_instruction; |
| 26931 | return ira->codegen->invalid_inst_gen; |
| 26064 | 26932 | |
| 26065 | 26933 | if (instr_is_comptime(casted_op1) && |
| 26066 | 26934 | instr_is_comptime(casted_op2) && |
| 26067 | 26935 | instr_is_comptime(casted_op3)) { |
| 26068 | 26936 | ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 26069 | 26937 | if (!op1_const) |
| 26070 | | return ira->codegen->invalid_instruction; |
| 26938 | return ira->codegen->invalid_inst_gen; |
| 26071 | 26939 | ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); |
| 26072 | 26940 | if (!op2_const) |
| 26073 | | return ira->codegen->invalid_instruction; |
| 26941 | return ira->codegen->invalid_inst_gen; |
| 26074 | 26942 | ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); |
| 26075 | 26943 | if (!op3_const) |
| 26076 | | return ira->codegen->invalid_instruction; |
| 26944 | return ira->codegen->invalid_inst_gen; |
| 26077 | 26945 | |
| 26078 | | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 26946 | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 26079 | 26947 | ZigValue *out_val = result->value; |
| 26080 | 26948 | |
| 26081 | 26949 | if (expr_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -26106,63 +26974,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 26106 | 26974 | return result; |
| 26107 | 26975 | } |
| 26108 | 26976 | |
| 26109 | | IrInstruction *result = ir_build_mul_add(&ira->new_irb, |
| 26110 | | instruction->base.scope, instruction->base.source_node, |
| 26111 | | type_value, casted_op1, casted_op2, casted_op3); |
| 26112 | | result->value->type = expr_type; |
| 26113 | | return result; |
| 26977 | return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type); |
| 26114 | 26978 | } |
| 26115 | 26979 | |
| 26116 | | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { |
| 26117 | | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 26980 | static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) { |
| 26981 | IrInstGen *base_ptr = instruction->base_ptr->child; |
| 26118 | 26982 | if (type_is_invalid(base_ptr->value->type)) |
| 26119 | | return ira->codegen->invalid_instruction; |
| 26983 | return ira->codegen->invalid_inst_gen; |
| 26120 | 26984 | |
| 26121 | | IrInstruction *value; |
| 26985 | IrInstGen *value; |
| 26122 | 26986 | if (instruction->base_ptr_is_payload) { |
| 26123 | 26987 | value = base_ptr; |
| 26124 | 26988 | } else { |
| 26125 | | value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); |
| 26989 | value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr); |
| 26126 | 26990 | } |
| 26127 | 26991 | |
| 26128 | 26992 | ZigType *type_entry = value->value->type; |
| 26129 | 26993 | if (type_is_invalid(type_entry)) |
| 26130 | | return ira->codegen->invalid_instruction; |
| 26994 | return ira->codegen->invalid_inst_gen; |
| 26131 | 26995 | if (type_entry->id == ZigTypeIdErrorUnion) { |
| 26132 | 26996 | if (instr_is_comptime(value)) { |
| 26133 | 26997 | ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 26134 | 26998 | if (!err_union_val) |
| 26135 | | return ira->codegen->invalid_instruction; |
| 26999 | return ira->codegen->invalid_inst_gen; |
| 26136 | 27000 | |
| 26137 | 27001 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 26138 | 27002 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; |
| 26139 | | return ir_const_bool(ira, &instruction->base, (err != nullptr)); |
| 27003 | return ir_const_bool(ira, &instruction->base.base, (err != nullptr)); |
| 26140 | 27004 | } |
| 26141 | 27005 | } |
| 26142 | 27006 | |
| 26143 | 27007 | if (instruction->resolve_err_set) { |
| 26144 | 27008 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| 26145 | | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 26146 | | return ira->codegen->invalid_instruction; |
| 27009 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) { |
| 27010 | return ira->codegen->invalid_inst_gen; |
| 26147 | 27011 | } |
| 26148 | 27012 | if (!type_is_global_error_set(err_set_type) && |
| 26149 | 27013 | err_set_type->data.error_set.err_count == 0) |
| 26150 | 27014 | { |
| 26151 | 27015 | assert(!err_set_type->data.error_set.incomplete); |
| 26152 | | return ir_const_bool(ira, &instruction->base, false); |
| 27016 | return ir_const_bool(ira, &instruction->base.base, false); |
| 26153 | 27017 | } |
| 26154 | 27018 | } |
| 26155 | 27019 | |
| 26156 | | return ir_build_test_err_gen(ira, &instruction->base, value); |
| 27020 | return ir_build_test_err_gen(ira, &instruction->base.base, value); |
| 26157 | 27021 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 26158 | | return ir_const_bool(ira, &instruction->base, true); |
| 27022 | return ir_const_bool(ira, &instruction->base.base, true); |
| 26159 | 27023 | } else { |
| 26160 | | return ir_const_bool(ira, &instruction->base, false); |
| 27024 | return ir_const_bool(ira, &instruction->base.base, false); |
| 26161 | 27025 | } |
| 26162 | 27026 | } |
| 26163 | 27027 | |
| 26164 | | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 26165 | | IrInstruction *base_ptr, bool initializing) |
| 27028 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 27029 | IrInstGen *base_ptr, bool initializing) |
| 26166 | 27030 | { |
| 26167 | 27031 | ZigType *ptr_type = base_ptr->value->type; |
| 26168 | 27032 | |
| ... | ... | @@ -26171,12 +27035,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26171 | 27035 | |
| 26172 | 27036 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 26173 | 27037 | if (type_is_invalid(type_entry)) |
| 26174 | | return ira->codegen->invalid_instruction; |
| 27038 | return ira->codegen->invalid_inst_gen; |
| 26175 | 27039 | |
| 26176 | 27040 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 26177 | | ir_add_error(ira, base_ptr, |
| 27041 | ir_add_error(ira, &base_ptr->base, |
| 26178 | 27042 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 26179 | | return ira->codegen->invalid_instruction; |
| 27043 | return ira->codegen->invalid_inst_gen; |
| 26180 | 27044 | } |
| 26181 | 27045 | |
| 26182 | 27046 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| ... | ... | @@ -26187,13 +27051,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26187 | 27051 | if (instr_is_comptime(base_ptr)) { |
| 26188 | 27052 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 26189 | 27053 | if (!ptr_val) |
| 26190 | | return ira->codegen->invalid_instruction; |
| 27054 | return ira->codegen->invalid_inst_gen; |
| 26191 | 27055 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 26192 | 27056 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) |
| 26193 | 27057 | { |
| 26194 | 27058 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 26195 | 27059 | if (err_union_val == nullptr) |
| 26196 | | return ira->codegen->invalid_instruction; |
| 27060 | return ira->codegen->invalid_inst_gen; |
| 26197 | 27061 | |
| 26198 | 27062 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 26199 | 27063 | ZigValue *vals = create_const_vals(2); |
| ... | ... | @@ -26216,11 +27080,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26216 | 27080 | } |
| 26217 | 27081 | ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr); |
| 26218 | 27082 | |
| 26219 | | IrInstruction *result; |
| 27083 | IrInstGen *result; |
| 26220 | 27084 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26221 | | result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, |
| 26222 | | source_instr->source_node, base_ptr); |
| 26223 | | result->value->type = result_type; |
| 27085 | result = ir_build_unwrap_err_code_gen(ira, source_instr->scope, |
| 27086 | source_instr->source_node, base_ptr, result_type); |
| 26224 | 27087 | result->value->special = ConstValSpecialStatic; |
| 26225 | 27088 | } else { |
| 26226 | 27089 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -26233,23 +27096,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 26233 | 27096 | } |
| 26234 | 27097 | } |
| 26235 | 27098 | |
| 26236 | | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 26237 | | source_instr->scope, source_instr->source_node, base_ptr); |
| 26238 | | result->value->type = result_type; |
| 26239 | | return result; |
| 27099 | return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type); |
| 26240 | 27100 | } |
| 26241 | 27101 | |
| 26242 | | static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 26243 | | IrInstructionUnwrapErrCode *instruction) |
| 26244 | | { |
| 26245 | | IrInstruction *base_ptr = instruction->err_union_ptr->child; |
| 27102 | static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) { |
| 27103 | IrInstGen *base_ptr = instruction->err_union_ptr->child; |
| 26246 | 27104 | if (type_is_invalid(base_ptr->value->type)) |
| 26247 | | return ira->codegen->invalid_instruction; |
| 26248 | | return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false); |
| 27105 | return ira->codegen->invalid_inst_gen; |
| 27106 | return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false); |
| 26249 | 27107 | } |
| 26250 | 27108 | |
| 26251 | | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 26252 | | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 27109 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 27110 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 26253 | 27111 | { |
| 26254 | 27112 | ZigType *ptr_type = base_ptr->value->type; |
| 26255 | 27113 | |
| ... | ... | @@ -26258,17 +27116,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26258 | 27116 | |
| 26259 | 27117 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 26260 | 27118 | if (type_is_invalid(type_entry)) |
| 26261 | | return ira->codegen->invalid_instruction; |
| 27119 | return ira->codegen->invalid_inst_gen; |
| 26262 | 27120 | |
| 26263 | 27121 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 26264 | | ir_add_error(ira, base_ptr, |
| 27122 | ir_add_error(ira, &base_ptr->base, |
| 26265 | 27123 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 26266 | | return ira->codegen->invalid_instruction; |
| 27124 | return ira->codegen->invalid_inst_gen; |
| 26267 | 27125 | } |
| 26268 | 27126 | |
| 26269 | 27127 | ZigType *payload_type = type_entry->data.error_union.payload_type; |
| 26270 | 27128 | if (type_is_invalid(payload_type)) |
| 26271 | | return ira->codegen->invalid_instruction; |
| 27129 | return ira->codegen->invalid_inst_gen; |
| 26272 | 27130 | |
| 26273 | 27131 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 26274 | 27132 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | ... | @@ -26277,11 +27135,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26277 | 27135 | if (instr_is_comptime(base_ptr)) { |
| 26278 | 27136 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 26279 | 27137 | if (!ptr_val) |
| 26280 | | return ira->codegen->invalid_instruction; |
| 27138 | return ira->codegen->invalid_inst_gen; |
| 26281 | 27139 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 26282 | 27140 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 26283 | 27141 | if (err_union_val == nullptr) |
| 26284 | | return ira->codegen->invalid_instruction; |
| 27142 | return ira->codegen->invalid_inst_gen; |
| 26285 | 27143 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 26286 | 27144 | ZigValue *vals = create_const_vals(2); |
| 26287 | 27145 | ZigValue *err_set_val = &vals[0]; |
| ... | ... | @@ -26304,14 +27162,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26304 | 27162 | if (err != nullptr) { |
| 26305 | 27163 | ir_add_error(ira, source_instr, |
| 26306 | 27164 | buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name))); |
| 26307 | | return ira->codegen->invalid_instruction; |
| 27165 | return ira->codegen->invalid_inst_gen; |
| 26308 | 27166 | } |
| 26309 | 27167 | |
| 26310 | | IrInstruction *result; |
| 27168 | IrInstGen *result; |
| 26311 | 27169 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26312 | | result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 26313 | | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 26314 | | result->value->type = result_type; |
| 27170 | result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope, |
| 27171 | source_instr->source_node, base_ptr, safety_check_on, initializing, result_type); |
| 26315 | 27172 | result->value->special = ConstValSpecialStatic; |
| 26316 | 27173 | } else { |
| 26317 | 27174 | result = ir_const(ira, source_instr, result_type); |
| ... | ... | @@ -26324,28 +27181,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 26324 | 27181 | } |
| 26325 | 27182 | } |
| 26326 | 27183 | |
| 26327 | | IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 26328 | | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 26329 | | result->value->type = result_type; |
| 26330 | | return result; |
| 27184 | return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node, |
| 27185 | base_ptr, safety_check_on, initializing, result_type); |
| 26331 | 27186 | } |
| 26332 | 27187 | |
| 26333 | | static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 26334 | | IrInstructionUnwrapErrPayload *instruction) |
| 27188 | static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 27189 | IrInstSrcUnwrapErrPayload *instruction) |
| 26335 | 27190 | { |
| 26336 | 27191 | assert(instruction->value->child); |
| 26337 | | IrInstruction *value = instruction->value->child; |
| 27192 | IrInstGen *value = instruction->value->child; |
| 26338 | 27193 | if (type_is_invalid(value->value->type)) |
| 26339 | | return ira->codegen->invalid_instruction; |
| 27194 | return ira->codegen->invalid_inst_gen; |
| 26340 | 27195 | |
| 26341 | | return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false); |
| 27196 | return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false); |
| 26342 | 27197 | } |
| 26343 | 27198 | |
| 26344 | | static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| 26345 | | AstNode *proto_node = instruction->base.source_node; |
| 27199 | static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) { |
| 27200 | AstNode *proto_node = instruction->base.base.source_node; |
| 26346 | 27201 | assert(proto_node->type == NodeTypeFnProto); |
| 26347 | 27202 | |
| 26348 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 27203 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 26349 | 27204 | result->value->special = ConstValSpecialLazy; |
| 26350 | 27205 | |
| 26351 | 27206 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType"); |
| ... | ... | @@ -26354,29 +27209,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 26354 | 27209 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 26355 | 27210 | |
| 26356 | 27211 | if (proto_node->data.fn_proto.auto_err_set) { |
| 26357 | | ir_add_error(ira, &instruction->base, |
| 27212 | ir_add_error(ira, &instruction->base.base, |
| 26358 | 27213 | buf_sprintf("inferring error set of return type valid only for function definitions")); |
| 26359 | | return ira->codegen->invalid_instruction; |
| 27214 | return ira->codegen->invalid_inst_gen; |
| 26360 | 27215 | } |
| 26361 | 27216 | |
| 26362 | 27217 | lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto); |
| 26363 | 27218 | if (instruction->callconv_value != nullptr) { |
| 26364 | 27219 | ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention"); |
| 26365 | 27220 | |
| 26366 | | IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type); |
| 27221 | IrInstGen *casted_value = ir_implicit_cast(ira, instruction->callconv_value->child, cc_enum_type); |
| 26367 | 27222 | if (type_is_invalid(casted_value->value->type)) |
| 26368 | | return ira->codegen->invalid_instruction; |
| 27223 | return ira->codegen->invalid_inst_gen; |
| 26369 | 27224 | |
| 26370 | 27225 | ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad); |
| 26371 | 27226 | if (const_value == nullptr) |
| 26372 | | return ira->codegen->invalid_instruction; |
| 27227 | return ira->codegen->invalid_inst_gen; |
| 26373 | 27228 | |
| 26374 | 27229 | lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag); |
| 26375 | 27230 | } |
| 26376 | 27231 | |
| 26377 | 27232 | size_t param_count = proto_node->data.fn_proto.params.length; |
| 26378 | 27233 | lazy_fn_type->proto_node = proto_node; |
| 26379 | | lazy_fn_type->param_types = allocate<IrInstruction *>(param_count); |
| 27234 | lazy_fn_type->param_types = allocate<IrInstGen *>(param_count); |
| 26380 | 27235 | |
| 26381 | 27236 | for (size_t param_index = 0; param_index < param_count; param_index += 1) { |
| 26382 | 27237 | AstNode *param_node = proto_node->data.fn_proto.params.at(param_index); |
| ... | ... | @@ -26401,63 +27256,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 26401 | 27256 | return result; |
| 26402 | 27257 | } |
| 26403 | 27258 | |
| 26404 | | IrInstruction *param_type_value = instruction->param_types[param_index]->child; |
| 27259 | IrInstGen *param_type_value = instruction->param_types[param_index]->child; |
| 26405 | 27260 | if (type_is_invalid(param_type_value->value->type)) |
| 26406 | | return ira->codegen->invalid_instruction; |
| 27261 | return ira->codegen->invalid_inst_gen; |
| 26407 | 27262 | if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr) |
| 26408 | | return ira->codegen->invalid_instruction; |
| 27263 | return ira->codegen->invalid_inst_gen; |
| 26409 | 27264 | lazy_fn_type->param_types[param_index] = param_type_value; |
| 26410 | 27265 | } |
| 26411 | 27266 | |
| 26412 | 27267 | if (instruction->align_value != nullptr) { |
| 26413 | 27268 | lazy_fn_type->align_inst = instruction->align_value->child; |
| 26414 | 27269 | if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr) |
| 26415 | | return ira->codegen->invalid_instruction; |
| 27270 | return ira->codegen->invalid_inst_gen; |
| 26416 | 27271 | } |
| 26417 | 27272 | |
| 26418 | 27273 | lazy_fn_type->return_type = instruction->return_type->child; |
| 26419 | 27274 | if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr) |
| 26420 | | return ira->codegen->invalid_instruction; |
| 27275 | return ira->codegen->invalid_inst_gen; |
| 26421 | 27276 | |
| 26422 | 27277 | return result; |
| 26423 | 27278 | } |
| 26424 | 27279 | |
| 26425 | | static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 26426 | | IrInstruction *value = instruction->value->child; |
| 27280 | static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) { |
| 27281 | IrInstGen *value = instruction->value->child; |
| 26427 | 27282 | if (type_is_invalid(value->value->type)) |
| 26428 | | return ira->codegen->invalid_instruction; |
| 27283 | return ira->codegen->invalid_inst_gen; |
| 26429 | 27284 | |
| 26430 | | return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); |
| 27285 | return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value)); |
| 26431 | 27286 | } |
| 26432 | 27287 | |
| 26433 | | static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26434 | | IrInstructionCheckSwitchProngs *instruction) |
| 27288 | static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 27289 | IrInstSrcCheckSwitchProngs *instruction) |
| 26435 | 27290 | { |
| 26436 | | IrInstruction *target_value = instruction->target_value->child; |
| 27291 | IrInstGen *target_value = instruction->target_value->child; |
| 26437 | 27292 | ZigType *switch_type = target_value->value->type; |
| 26438 | 27293 | if (type_is_invalid(switch_type)) |
| 26439 | | return ira->codegen->invalid_instruction; |
| 27294 | return ira->codegen->invalid_inst_gen; |
| 26440 | 27295 | |
| 26441 | 27296 | if (switch_type->id == ZigTypeIdEnum) { |
| 26442 | 27297 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; |
| 26443 | 27298 | field_prev_uses.init(switch_type->data.enumeration.src_field_count); |
| 26444 | 27299 | |
| 26445 | 27300 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26446 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27301 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26447 | 27302 | |
| 26448 | | IrInstruction *start_value_uncasted = range->start->child; |
| 27303 | IrInstGen *start_value_uncasted = range->start->child; |
| 26449 | 27304 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 26450 | | return ira->codegen->invalid_instruction; |
| 26451 | | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 27305 | return ira->codegen->invalid_inst_gen; |
| 27306 | IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 26452 | 27307 | if (type_is_invalid(start_value->value->type)) |
| 26453 | | return ira->codegen->invalid_instruction; |
| 27308 | return ira->codegen->invalid_inst_gen; |
| 26454 | 27309 | |
| 26455 | | IrInstruction *end_value_uncasted = range->end->child; |
| 27310 | IrInstGen *end_value_uncasted = range->end->child; |
| 26456 | 27311 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 26457 | | return ira->codegen->invalid_instruction; |
| 26458 | | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 27312 | return ira->codegen->invalid_inst_gen; |
| 27313 | IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 26459 | 27314 | if (type_is_invalid(end_value->value->type)) |
| 26460 | | return ira->codegen->invalid_instruction; |
| 27315 | return ira->codegen->invalid_inst_gen; |
| 26461 | 27316 | |
| 26462 | 27317 | assert(start_value->value->type->id == ZigTypeIdEnum); |
| 26463 | 27318 | BigInt start_index; |
| ... | ... | @@ -26468,7 +27323,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26468 | 27323 | bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); |
| 26469 | 27324 | |
| 26470 | 27325 | if (bigint_cmp(&start_index, &end_index) == CmpGT) { |
| 26471 | | ir_add_error(ira, start_value, |
| 27326 | ir_add_error(ira, &start_value->base, |
| 26472 | 27327 | buf_sprintf("range start value is greater than the end value")); |
| 26473 | 27328 | } |
| 26474 | 27329 | |
| ... | ... | @@ -26479,12 +27334,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26479 | 27334 | if (cmp == CmpGT) { |
| 26480 | 27335 | break; |
| 26481 | 27336 | } |
| 26482 | | auto entry = field_prev_uses.put_unique(field_index, start_value->source_node); |
| 27337 | auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node); |
| 26483 | 27338 | if (entry) { |
| 26484 | 27339 | AstNode *prev_node = entry->value; |
| 26485 | 27340 | TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index); |
| 26486 | 27341 | assert(enum_field != nullptr); |
| 26487 | | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 27342 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 26488 | 27343 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), |
| 26489 | 27344 | buf_ptr(enum_field->name))); |
| 26490 | 27345 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); |
| ... | ... | @@ -26494,7 +27349,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26494 | 27349 | } |
| 26495 | 27350 | if (instruction->have_underscore_prong) { |
| 26496 | 27351 | if (!switch_type->data.enumeration.non_exhaustive){ |
| 26497 | | ir_add_error(ira, &instruction->base, |
| 27352 | ir_add_error(ira, &instruction->base.base, |
| 26498 | 27353 | buf_sprintf("switch on non-exhaustive enum has `_` prong")); |
| 26499 | 27354 | } |
| 26500 | 27355 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -26504,14 +27359,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26504 | 27359 | |
| 26505 | 27360 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 26506 | 27361 | if (!entry) { |
| 26507 | | ir_add_error(ira, &instruction->base, |
| 27362 | ir_add_error(ira, &instruction->base.base, |
| 26508 | 27363 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 26509 | 27364 | buf_ptr(enum_field->name))); |
| 26510 | 27365 | } |
| 26511 | 27366 | } |
| 26512 | 27367 | } else if (!instruction->have_else_prong) { |
| 26513 | 27368 | if (switch_type->data.enumeration.non_exhaustive) { |
| 26514 | | ir_add_error(ira, &instruction->base, |
| 27369 | ir_add_error(ira, &instruction->base.base, |
| 26515 | 27370 | buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong")); |
| 26516 | 27371 | } |
| 26517 | 27372 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -26519,69 +27374,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26519 | 27374 | |
| 26520 | 27375 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 26521 | 27376 | if (!entry) { |
| 26522 | | ir_add_error(ira, &instruction->base, |
| 27377 | ir_add_error(ira, &instruction->base.base, |
| 26523 | 27378 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 26524 | 27379 | buf_ptr(enum_field->name))); |
| 26525 | 27380 | } |
| 26526 | 27381 | } |
| 26527 | 27382 | } |
| 26528 | 27383 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 26529 | | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 26530 | | return ira->codegen->invalid_instruction; |
| 27384 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) { |
| 27385 | return ira->codegen->invalid_inst_gen; |
| 26531 | 27386 | } |
| 26532 | 27387 | |
| 26533 | 27388 | size_t field_prev_uses_count = ira->codegen->errors_by_index.length; |
| 26534 | 27389 | AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *"); |
| 26535 | 27390 | |
| 26536 | 27391 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26537 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27392 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26538 | 27393 | |
| 26539 | | IrInstruction *start_value_uncasted = range->start->child; |
| 27394 | IrInstGen *start_value_uncasted = range->start->child; |
| 26540 | 27395 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 26541 | | return ira->codegen->invalid_instruction; |
| 26542 | | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 27396 | return ira->codegen->invalid_inst_gen; |
| 27397 | IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 26543 | 27398 | if (type_is_invalid(start_value->value->type)) |
| 26544 | | return ira->codegen->invalid_instruction; |
| 27399 | return ira->codegen->invalid_inst_gen; |
| 26545 | 27400 | |
| 26546 | | IrInstruction *end_value_uncasted = range->end->child; |
| 27401 | IrInstGen *end_value_uncasted = range->end->child; |
| 26547 | 27402 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 26548 | | return ira->codegen->invalid_instruction; |
| 26549 | | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 27403 | return ira->codegen->invalid_inst_gen; |
| 27404 | IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 26550 | 27405 | if (type_is_invalid(end_value->value->type)) |
| 26551 | | return ira->codegen->invalid_instruction; |
| 27406 | return ira->codegen->invalid_inst_gen; |
| 26552 | 27407 | |
| 26553 | | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 27408 | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 26554 | 27409 | uint32_t start_index = start_value->value->data.x_err_set->value; |
| 26555 | 27410 | |
| 26556 | | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 27411 | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 26557 | 27412 | uint32_t end_index = end_value->value->data.x_err_set->value; |
| 26558 | 27413 | |
| 26559 | 27414 | if (start_index != end_index) { |
| 26560 | | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| 26561 | | return ira->codegen->invalid_instruction; |
| 27415 | ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors")); |
| 27416 | return ira->codegen->invalid_inst_gen; |
| 26562 | 27417 | } |
| 26563 | 27418 | |
| 26564 | 27419 | AstNode *prev_node = field_prev_uses[start_index]; |
| 26565 | 27420 | if (prev_node != nullptr) { |
| 26566 | 27421 | Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name; |
| 26567 | | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 27422 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 26568 | 27423 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name))); |
| 26569 | 27424 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here")); |
| 26570 | 27425 | } |
| 26571 | | field_prev_uses[start_index] = start_value->source_node; |
| 27426 | field_prev_uses[start_index] = start_value->base.source_node; |
| 26572 | 27427 | } |
| 26573 | 27428 | if (!instruction->have_else_prong) { |
| 26574 | 27429 | if (type_is_global_error_set(switch_type)) { |
| 26575 | | ir_add_error(ira, &instruction->base, |
| 27430 | ir_add_error(ira, &instruction->base.base, |
| 26576 | 27431 | buf_sprintf("else prong required when switching on type 'anyerror'")); |
| 26577 | | return ira->codegen->invalid_instruction; |
| 27432 | return ira->codegen->invalid_inst_gen; |
| 26578 | 27433 | } else { |
| 26579 | 27434 | for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) { |
| 26580 | 27435 | ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i]; |
| 26581 | 27436 | |
| 26582 | 27437 | AstNode *prev_node = field_prev_uses[err_entry->value]; |
| 26583 | 27438 | if (prev_node == nullptr) { |
| 26584 | | ir_add_error(ira, &instruction->base, |
| 27439 | ir_add_error(ira, &instruction->base.base, |
| 26585 | 27440 | buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name))); |
| 26586 | 27441 | } |
| 26587 | 27442 | } |
| ... | ... | @@ -26592,44 +27447,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26592 | 27447 | } else if (switch_type->id == ZigTypeIdInt) { |
| 26593 | 27448 | RangeSet rs = {0}; |
| 26594 | 27449 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26595 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27450 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26596 | 27451 | |
| 26597 | | IrInstruction *start_value = range->start->child; |
| 27452 | IrInstGen *start_value = range->start->child; |
| 26598 | 27453 | if (type_is_invalid(start_value->value->type)) |
| 26599 | | return ira->codegen->invalid_instruction; |
| 26600 | | IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 27454 | return ira->codegen->invalid_inst_gen; |
| 27455 | IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 26601 | 27456 | if (type_is_invalid(casted_start_value->value->type)) |
| 26602 | | return ira->codegen->invalid_instruction; |
| 27457 | return ira->codegen->invalid_inst_gen; |
| 26603 | 27458 | |
| 26604 | | IrInstruction *end_value = range->end->child; |
| 27459 | IrInstGen *end_value = range->end->child; |
| 26605 | 27460 | if (type_is_invalid(end_value->value->type)) |
| 26606 | | return ira->codegen->invalid_instruction; |
| 26607 | | IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 27461 | return ira->codegen->invalid_inst_gen; |
| 27462 | IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 26608 | 27463 | if (type_is_invalid(casted_end_value->value->type)) |
| 26609 | | return ira->codegen->invalid_instruction; |
| 27464 | return ira->codegen->invalid_inst_gen; |
| 26610 | 27465 | |
| 26611 | 27466 | ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| 26612 | 27467 | if (!start_val) |
| 26613 | | return ira->codegen->invalid_instruction; |
| 27468 | return ira->codegen->invalid_inst_gen; |
| 26614 | 27469 | |
| 26615 | 27470 | ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); |
| 26616 | 27471 | if (!end_val) |
| 26617 | | return ira->codegen->invalid_instruction; |
| 27472 | return ira->codegen->invalid_inst_gen; |
| 26618 | 27473 | |
| 26619 | 27474 | assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); |
| 26620 | 27475 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| 26621 | 27476 | |
| 26622 | 27477 | if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) { |
| 26623 | | ir_add_error(ira, start_value, |
| 27478 | ir_add_error(ira, &start_value->base, |
| 26624 | 27479 | buf_sprintf("range start value is greater than the end value")); |
| 26625 | 27480 | } |
| 26626 | 27481 | |
| 26627 | 27482 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, |
| 26628 | | start_value->source_node); |
| 27483 | start_value->base.source_node); |
| 26629 | 27484 | if (prev_node != nullptr) { |
| 26630 | | ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value")); |
| 27485 | ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value")); |
| 26631 | 27486 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here")); |
| 26632 | | return ira->codegen->invalid_instruction; |
| 27487 | return ira->codegen->invalid_inst_gen; |
| 26633 | 27488 | } |
| 26634 | 27489 | } |
| 26635 | 27490 | if (!instruction->have_else_prong) { |
| ... | ... | @@ -26638,25 +27493,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26638 | 27493 | BigInt max_val; |
| 26639 | 27494 | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 26640 | 27495 | if (!rangeset_spans(&rs, &min_val, &max_val)) { |
| 26641 | | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 26642 | | return ira->codegen->invalid_instruction; |
| 27496 | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 27497 | return ira->codegen->invalid_inst_gen; |
| 26643 | 27498 | } |
| 26644 | 27499 | } |
| 26645 | 27500 | } else if (switch_type->id == ZigTypeIdBool) { |
| 26646 | 27501 | int seenTrue = 0; |
| 26647 | 27502 | int seenFalse = 0; |
| 26648 | 27503 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 26649 | | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 27504 | IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 26650 | 27505 | |
| 26651 | | IrInstruction *value = range->start->child; |
| 27506 | IrInstGen *value = range->start->child; |
| 26652 | 27507 | |
| 26653 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 27508 | IrInstGen *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 26654 | 27509 | if (type_is_invalid(casted_value->value->type)) |
| 26655 | | return ira->codegen->invalid_instruction; |
| 27510 | return ira->codegen->invalid_inst_gen; |
| 26656 | 27511 | |
| 26657 | 27512 | ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 26658 | 27513 | if (!const_expr_val) |
| 26659 | | return ira->codegen->invalid_instruction; |
| 27514 | return ira->codegen->invalid_inst_gen; |
| 26660 | 27515 | |
| 26661 | 27516 | assert(const_expr_val->type->id == ZigTypeIdBool); |
| 26662 | 27517 | |
| ... | ... | @@ -26667,60 +27522,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26667 | 27522 | } |
| 26668 | 27523 | |
| 26669 | 27524 | if ((seenTrue > 1) || (seenFalse > 1)) { |
| 26670 | | ir_add_error(ira, value, buf_sprintf("duplicate switch value")); |
| 26671 | | return ira->codegen->invalid_instruction; |
| 27525 | ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value")); |
| 27526 | return ira->codegen->invalid_inst_gen; |
| 26672 | 27527 | } |
| 26673 | 27528 | } |
| 26674 | 27529 | if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) { |
| 26675 | | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 26676 | | return ira->codegen->invalid_instruction; |
| 27530 | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 27531 | return ira->codegen->invalid_inst_gen; |
| 26677 | 27532 | } |
| 26678 | 27533 | } else if (!instruction->have_else_prong) { |
| 26679 | | ir_add_error(ira, &instruction->base, |
| 27534 | ir_add_error(ira, &instruction->base.base, |
| 26680 | 27535 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |
| 26681 | | return ira->codegen->invalid_instruction; |
| 27536 | return ira->codegen->invalid_inst_gen; |
| 26682 | 27537 | } |
| 26683 | | return ir_const_void(ira, &instruction->base); |
| 27538 | return ir_const_void(ira, &instruction->base.base); |
| 26684 | 27539 | } |
| 26685 | 27540 | |
| 26686 | | static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 26687 | | IrInstructionCheckStatementIsVoid *instruction) |
| 27541 | static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 27542 | IrInstSrcCheckStatementIsVoid *instruction) |
| 26688 | 27543 | { |
| 26689 | | IrInstruction *statement_value = instruction->statement_value->child; |
| 27544 | IrInstGen *statement_value = instruction->statement_value->child; |
| 26690 | 27545 | ZigType *statement_type = statement_value->value->type; |
| 26691 | 27546 | if (type_is_invalid(statement_type)) |
| 26692 | | return ira->codegen->invalid_instruction; |
| 27547 | return ira->codegen->invalid_inst_gen; |
| 26693 | 27548 | |
| 26694 | 27549 | if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { |
| 26695 | | ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); |
| 27550 | ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); |
| 26696 | 27551 | } |
| 26697 | 27552 | |
| 26698 | | return ir_const_void(ira, &instruction->base); |
| 27553 | return ir_const_void(ira, &instruction->base.base); |
| 26699 | 27554 | } |
| 26700 | 27555 | |
| 26701 | | static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 26702 | | IrInstruction *msg = instruction->msg->child; |
| 27556 | static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) { |
| 27557 | IrInstGen *msg = instruction->msg->child; |
| 26703 | 27558 | if (type_is_invalid(msg->value->type)) |
| 26704 | 27559 | return ir_unreach_error(ira); |
| 26705 | 27560 | |
| 26706 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) { |
| 26707 | | ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time")); |
| 27561 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) { |
| 27562 | ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time")); |
| 26708 | 27563 | return ir_unreach_error(ira); |
| 26709 | 27564 | } |
| 26710 | 27565 | |
| 26711 | 27566 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 26712 | 27567 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 26713 | 27568 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 26714 | | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 27569 | IrInstGen *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 26715 | 27570 | if (type_is_invalid(casted_msg->value->type)) |
| 26716 | 27571 | return ir_unreach_error(ira); |
| 26717 | 27572 | |
| 26718 | | IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, |
| 26719 | | instruction->base.source_node, casted_msg); |
| 27573 | IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg); |
| 26720 | 27574 | return ir_finish_anal(ira, new_instruction); |
| 26721 | 27575 | } |
| 26722 | 27576 | |
| 26723 | | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 27577 | static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t align_bytes, bool safety_check_on) { |
| 26724 | 27578 | Error err; |
| 26725 | 27579 | |
| 26726 | 27580 | ZigType *target_type = target->value->type; |
| ... | ... | @@ -26732,7 +27586,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26732 | 27586 | if (target_type->id == ZigTypeIdPointer) { |
| 26733 | 27587 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); |
| 26734 | 27588 | if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes))) |
| 26735 | | return ira->codegen->invalid_instruction; |
| 27589 | return ira->codegen->invalid_inst_gen; |
| 26736 | 27590 | } else if (target_type->id == ZigTypeIdFn) { |
| 26737 | 27591 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 26738 | 27592 | old_align_bytes = fn_type_id.alignment; |
| ... | ... | @@ -26743,7 +27597,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26743 | 27597 | { |
| 26744 | 27598 | ZigType *ptr_type = target_type->data.maybe.child_type; |
| 26745 | 27599 | if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes))) |
| 26746 | | return ira->codegen->invalid_instruction; |
| 27600 | return ira->codegen->invalid_inst_gen; |
| 26747 | 27601 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); |
| 26748 | 27602 | |
| 26749 | 27603 | result_type = get_optional_type(ira->codegen, better_ptr_type); |
| ... | ... | @@ -26758,47 +27612,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 26758 | 27612 | } else if (is_slice(target_type)) { |
| 26759 | 27613 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26760 | 27614 | if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes))) |
| 26761 | | return ira->codegen->invalid_instruction; |
| 27615 | return ira->codegen->invalid_inst_gen; |
| 26762 | 27616 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 26763 | 27617 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 26764 | 27618 | } else { |
| 26765 | | ir_add_error(ira, target, |
| 27619 | ir_add_error(ira, &target->base, |
| 26766 | 27620 | buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name))); |
| 26767 | | return ira->codegen->invalid_instruction; |
| 27621 | return ira->codegen->invalid_inst_gen; |
| 26768 | 27622 | } |
| 26769 | 27623 | |
| 26770 | 27624 | if (instr_is_comptime(target)) { |
| 26771 | 27625 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 26772 | 27626 | if (!val) |
| 26773 | | return ira->codegen->invalid_instruction; |
| 27627 | return ira->codegen->invalid_inst_gen; |
| 26774 | 27628 | |
| 26775 | 27629 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 26776 | 27630 | val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0) |
| 26777 | 27631 | { |
| 26778 | | ir_add_error(ira, target, |
| 27632 | ir_add_error(ira, &target->base, |
| 26779 | 27633 | buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes", |
| 26780 | 27634 | val->data.x_ptr.data.hard_coded_addr.addr, align_bytes)); |
| 26781 | | return ira->codegen->invalid_instruction; |
| 27635 | return ira->codegen->invalid_inst_gen; |
| 26782 | 27636 | } |
| 26783 | 27637 | |
| 26784 | | IrInstruction *result = ir_const(ira, target, result_type); |
| 27638 | IrInstGen *result = ir_const(ira, &target->base, result_type); |
| 26785 | 27639 | copy_const_val(result->value, val); |
| 26786 | 27640 | result->value->type = result_type; |
| 26787 | 27641 | return result; |
| 26788 | 27642 | } |
| 26789 | 27643 | |
| 26790 | | IrInstruction *result; |
| 26791 | 27644 | if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) { |
| 26792 | | result = ir_build_align_cast(&ira->new_irb, target->scope, target->source_node, nullptr, target); |
| 27645 | return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type); |
| 26793 | 27646 | } else { |
| 26794 | | result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop); |
| 27647 | return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop); |
| 26795 | 27648 | } |
| 26796 | | result->value->type = result_type; |
| 26797 | | return result; |
| 26798 | 27649 | } |
| 26799 | 27650 | |
| 26800 | | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 26801 | | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on) |
| 27651 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 27652 | ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on) |
| 26802 | 27653 | { |
| 26803 | 27654 | Error err; |
| 26804 | 27655 | |
| ... | ... | @@ -26814,44 +27665,44 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26814 | 27665 | |
| 26815 | 27666 | ZigType *src_ptr_type = get_src_ptr_type(src_type); |
| 26816 | 27667 | if (src_ptr_type == nullptr) { |
| 26817 | | ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 26818 | | return ira->codegen->invalid_instruction; |
| 27668 | ir_add_error(ira, &ptr->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 27669 | return ira->codegen->invalid_inst_gen; |
| 26819 | 27670 | } |
| 26820 | 27671 | |
| 26821 | 27672 | ZigType *dest_ptr_type = get_src_ptr_type(dest_type); |
| 26822 | 27673 | if (dest_ptr_type == nullptr) { |
| 26823 | 27674 | ir_add_error(ira, dest_type_src, |
| 26824 | 27675 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 26825 | | return ira->codegen->invalid_instruction; |
| 27676 | return ira->codegen->invalid_inst_gen; |
| 26826 | 27677 | } |
| 26827 | 27678 | |
| 26828 | 27679 | if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) { |
| 26829 | 27680 | ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier")); |
| 26830 | | return ira->codegen->invalid_instruction; |
| 27681 | return ira->codegen->invalid_inst_gen; |
| 26831 | 27682 | } |
| 26832 | 27683 | uint32_t src_align_bytes; |
| 26833 | 27684 | if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes))) |
| 26834 | | return ira->codegen->invalid_instruction; |
| 27685 | return ira->codegen->invalid_inst_gen; |
| 26835 | 27686 | |
| 26836 | 27687 | uint32_t dest_align_bytes; |
| 26837 | 27688 | if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes))) |
| 26838 | | return ira->codegen->invalid_instruction; |
| 27689 | return ira->codegen->invalid_inst_gen; |
| 26839 | 27690 | |
| 26840 | 27691 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 26841 | | return ira->codegen->invalid_instruction; |
| 27692 | return ira->codegen->invalid_inst_gen; |
| 26842 | 27693 | |
| 26843 | 27694 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown))) |
| 26844 | | return ira->codegen->invalid_instruction; |
| 27695 | return ira->codegen->invalid_inst_gen; |
| 26845 | 27696 | |
| 26846 | 27697 | if (type_has_bits(dest_type) && !type_has_bits(src_type)) { |
| 26847 | 27698 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 26848 | 27699 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", |
| 26849 | 27700 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 26850 | | add_error_note(ira->codegen, msg, ptr->source_node, |
| 27701 | add_error_note(ira->codegen, msg, ptr->base.source_node, |
| 26851 | 27702 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); |
| 26852 | 27703 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 26853 | 27704 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); |
| 26854 | | return ira->codegen->invalid_instruction; |
| 27705 | return ira->codegen->invalid_inst_gen; |
| 26855 | 27706 | } |
| 26856 | 27707 | |
| 26857 | 27708 | if (instr_is_comptime(ptr)) { |
| ... | ... | @@ -26859,7 +27710,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26859 | 27710 | UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; |
| 26860 | 27711 | ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); |
| 26861 | 27712 | if (!val) |
| 26862 | | return ira->codegen->invalid_instruction; |
| 27713 | return ira->codegen->invalid_inst_gen; |
| 26863 | 27714 | |
| 26864 | 27715 | if (value_is_comptime(val) && val->special != ConstValSpecialUndef) { |
| 26865 | 27716 | bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull || |
| ... | ... | @@ -26868,16 +27719,16 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26868 | 27719 | if (is_addr_zero && !dest_allows_addr_zero) { |
| 26869 | 27720 | ir_add_error(ira, source_instr, |
| 26870 | 27721 | buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name))); |
| 26871 | | return ira->codegen->invalid_instruction; |
| 27722 | return ira->codegen->invalid_inst_gen; |
| 26872 | 27723 | } |
| 26873 | 27724 | } |
| 26874 | 27725 | |
| 26875 | | IrInstruction *result; |
| 27726 | IrInstGen *result; |
| 26876 | 27727 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 26877 | 27728 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 26878 | 27729 | |
| 26879 | 27730 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 26880 | | return ira->codegen->invalid_instruction; |
| 27731 | return ira->codegen->invalid_inst_gen; |
| 26881 | 27732 | } else { |
| 26882 | 27733 | result = ir_const(ira, source_instr, dest_type); |
| 26883 | 27734 | } |
| ... | ... | @@ -26895,40 +27746,40 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 26895 | 27746 | |
| 26896 | 27747 | if (dest_align_bytes > src_align_bytes) { |
| 26897 | 27748 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 26898 | | add_error_note(ira->codegen, msg, ptr->source_node, |
| 27749 | add_error_note(ira->codegen, msg, ptr->base.source_node, |
| 26899 | 27750 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); |
| 26900 | 27751 | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 26901 | 27752 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); |
| 26902 | | return ira->codegen->invalid_instruction; |
| 27753 | return ira->codegen->invalid_inst_gen; |
| 26903 | 27754 | } |
| 26904 | 27755 | |
| 26905 | | IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 27756 | IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 26906 | 27757 | |
| 26907 | 27758 | // Keep the bigger alignment, it can only help- |
| 26908 | 27759 | // unless the target is zero bits. |
| 26909 | | IrInstruction *result; |
| 27760 | IrInstGen *result; |
| 26910 | 27761 | if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { |
| 26911 | 27762 | result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); |
| 26912 | 27763 | if (type_is_invalid(result->value->type)) |
| 26913 | | return ira->codegen->invalid_instruction; |
| 27764 | return ira->codegen->invalid_inst_gen; |
| 26914 | 27765 | } else { |
| 26915 | 27766 | result = casted_ptr; |
| 26916 | 27767 | } |
| 26917 | 27768 | return result; |
| 26918 | 27769 | } |
| 26919 | 27770 | |
| 26920 | | static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) { |
| 26921 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 27771 | static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) { |
| 27772 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 26922 | 27773 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 26923 | 27774 | if (type_is_invalid(dest_type)) |
| 26924 | | return ira->codegen->invalid_instruction; |
| 27775 | return ira->codegen->invalid_inst_gen; |
| 26925 | 27776 | |
| 26926 | | IrInstruction *ptr = instruction->ptr->child; |
| 27777 | IrInstGen *ptr = instruction->ptr->child; |
| 26927 | 27778 | ZigType *src_type = ptr->value->type; |
| 26928 | 27779 | if (type_is_invalid(src_type)) |
| 26929 | | return ira->codegen->invalid_instruction; |
| 27780 | return ira->codegen->invalid_inst_gen; |
| 26930 | 27781 | |
| 26931 | | return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value, |
| 27782 | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, dest_type, &dest_type_value->base, |
| 26932 | 27783 | instruction->safety_check_on); |
| 26933 | 27784 | } |
| 26934 | 27785 | |
| ... | ... | @@ -27259,7 +28110,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 27259 | 28110 | zig_unreachable(); |
| 27260 | 28111 | } |
| 27261 | 28112 | |
| 27262 | | static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 28113 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 27263 | 28114 | ZigType *dest_type) |
| 27264 | 28115 | { |
| 27265 | 28116 | Error err; |
| ... | ... | @@ -27275,14 +28126,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27275 | 28126 | buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name))); |
| 27276 | 28127 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 27277 | 28128 | buf_sprintf("use @intToEnum for type coercion")); |
| 27278 | | return ira->codegen->invalid_instruction; |
| 28129 | return ira->codegen->invalid_inst_gen; |
| 27279 | 28130 | } |
| 27280 | 28131 | |
| 27281 | 28132 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown))) |
| 27282 | | return ira->codegen->invalid_instruction; |
| 28133 | return ira->codegen->invalid_inst_gen; |
| 27283 | 28134 | |
| 27284 | 28135 | if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown))) |
| 27285 | | return ira->codegen->invalid_instruction; |
| 28136 | return ira->codegen->invalid_inst_gen; |
| 27286 | 28137 | |
| 27287 | 28138 | uint64_t dest_size_bytes = type_size(ira->codegen, dest_type); |
| 27288 | 28139 | uint64_t src_size_bytes = type_size(ira->codegen, src_type); |
| ... | ... | @@ -27291,7 +28142,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27291 | 28142 | buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64, |
| 27292 | 28143 | buf_ptr(&dest_type->name), dest_size_bytes, |
| 27293 | 28144 | buf_ptr(&src_type->name), src_size_bytes)); |
| 27294 | | return ira->codegen->invalid_instruction; |
| 28145 | return ira->codegen->invalid_inst_gen; |
| 27295 | 28146 | } |
| 27296 | 28147 | |
| 27297 | 28148 | uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type); |
| ... | ... | @@ -27301,26 +28152,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 27301 | 28152 | buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits", |
| 27302 | 28153 | buf_ptr(&dest_type->name), dest_size_bits, |
| 27303 | 28154 | buf_ptr(&src_type->name), src_size_bits)); |
| 27304 | | return ira->codegen->invalid_instruction; |
| 28155 | return ira->codegen->invalid_inst_gen; |
| 27305 | 28156 | } |
| 27306 | 28157 | |
| 27307 | 28158 | if (instr_is_comptime(value)) { |
| 27308 | 28159 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 27309 | 28160 | if (!val) |
| 27310 | | return ira->codegen->invalid_instruction; |
| 28161 | return ira->codegen->invalid_inst_gen; |
| 27311 | 28162 | |
| 27312 | | IrInstruction *result = ir_const(ira, source_instr, dest_type); |
| 28163 | IrInstGen *result = ir_const(ira, source_instr, dest_type); |
| 27313 | 28164 | uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); |
| 27314 | 28165 | buf_write_value_bytes(ira->codegen, buf, val); |
| 27315 | 28166 | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) |
| 27316 | | return ira->codegen->invalid_instruction; |
| 28167 | return ira->codegen->invalid_inst_gen; |
| 27317 | 28168 | return result; |
| 27318 | 28169 | } |
| 27319 | 28170 | |
| 27320 | 28171 | return ir_build_bit_cast_gen(ira, source_instr, value, dest_type); |
| 27321 | 28172 | } |
| 27322 | 28173 | |
| 27323 | | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 28174 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 27324 | 28175 | ZigType *ptr_type) |
| 27325 | 28176 | { |
| 27326 | 28177 | Error err; |
| ... | ... | @@ -27328,136 +28179,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 27328 | 28179 | ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr); |
| 27329 | 28180 | ir_assert(type_has_bits(ptr_type), source_instr); |
| 27330 | 28181 | |
| 27331 | | IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 28182 | IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 27332 | 28183 | if (type_is_invalid(casted_int->value->type)) |
| 27333 | | return ira->codegen->invalid_instruction; |
| 28184 | return ira->codegen->invalid_inst_gen; |
| 27334 | 28185 | |
| 27335 | 28186 | if (instr_is_comptime(casted_int)) { |
| 27336 | 28187 | ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad); |
| 27337 | 28188 | if (!val) |
| 27338 | | return ira->codegen->invalid_instruction; |
| 28189 | return ira->codegen->invalid_inst_gen; |
| 27339 | 28190 | |
| 27340 | 28191 | uint64_t addr = bigint_as_u64(&val->data.x_bigint); |
| 27341 | 28192 | if (!ptr_allows_addr_zero(ptr_type) && addr == 0) { |
| 27342 | 28193 | ir_add_error(ira, source_instr, |
| 27343 | 28194 | buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name))); |
| 27344 | | return ira->codegen->invalid_instruction; |
| 28195 | return ira->codegen->invalid_inst_gen; |
| 27345 | 28196 | } |
| 27346 | 28197 | |
| 27347 | 28198 | uint32_t align_bytes; |
| 27348 | 28199 | if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes))) |
| 27349 | | return ira->codegen->invalid_instruction; |
| 28200 | return ira->codegen->invalid_inst_gen; |
| 27350 | 28201 | |
| 27351 | 28202 | if (addr != 0 && addr % align_bytes != 0) { |
| 27352 | 28203 | ir_add_error(ira, source_instr, |
| 27353 | 28204 | buf_sprintf("pointer type '%s' requires aligned address", |
| 27354 | 28205 | buf_ptr(&ptr_type->name))); |
| 27355 | | return ira->codegen->invalid_instruction; |
| 28206 | return ira->codegen->invalid_inst_gen; |
| 27356 | 28207 | } |
| 27357 | 28208 | |
| 27358 | | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 28209 | IrInstGen *result = ir_const(ira, source_instr, ptr_type); |
| 27359 | 28210 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 27360 | 28211 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 27361 | 28212 | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 27362 | 28213 | return result; |
| 27363 | 28214 | } |
| 27364 | 28215 | |
| 27365 | | IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope, |
| 27366 | | source_instr->source_node, nullptr, casted_int); |
| 27367 | | result->value->type = ptr_type; |
| 27368 | | return result; |
| 28216 | return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type); |
| 27369 | 28217 | } |
| 27370 | 28218 | |
| 27371 | | static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { |
| 28219 | static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) { |
| 27372 | 28220 | Error err; |
| 27373 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 28221 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 27374 | 28222 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 27375 | 28223 | if (type_is_invalid(dest_type)) |
| 27376 | | return ira->codegen->invalid_instruction; |
| 28224 | return ira->codegen->invalid_inst_gen; |
| 27377 | 28225 | |
| 27378 | 28226 | // We explicitly check for the size, so we can use get_src_ptr_type |
| 27379 | 28227 | if (get_src_ptr_type(dest_type) == nullptr) { |
| 27380 | | ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 27381 | | return ira->codegen->invalid_instruction; |
| 28228 | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 28229 | return ira->codegen->invalid_inst_gen; |
| 27382 | 28230 | } |
| 27383 | 28231 | |
| 27384 | 28232 | bool has_bits; |
| 27385 | 28233 | if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits))) |
| 27386 | | return ira->codegen->invalid_instruction; |
| 28234 | return ira->codegen->invalid_inst_gen; |
| 27387 | 28235 | |
| 27388 | 28236 | if (!has_bits) { |
| 27389 | | ir_add_error(ira, dest_type_value, |
| 28237 | ir_add_error(ira, &dest_type_value->base, |
| 27390 | 28238 | buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name))); |
| 27391 | | return ira->codegen->invalid_instruction; |
| 28239 | return ira->codegen->invalid_inst_gen; |
| 27392 | 28240 | } |
| 27393 | 28241 | |
| 27394 | | IrInstruction *target = instruction->target->child; |
| 28242 | IrInstGen *target = instruction->target->child; |
| 27395 | 28243 | if (type_is_invalid(target->value->type)) |
| 27396 | | return ira->codegen->invalid_instruction; |
| 28244 | return ira->codegen->invalid_inst_gen; |
| 27397 | 28245 | |
| 27398 | | return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type); |
| 28246 | return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type); |
| 27399 | 28247 | } |
| 27400 | 28248 | |
| 27401 | | static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 27402 | | IrInstructionDeclRef *instruction) |
| 27403 | | { |
| 27404 | | IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); |
| 28249 | static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) { |
| 28250 | IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld); |
| 27405 | 28251 | if (type_is_invalid(ref_instruction->value->type)) { |
| 27406 | | return ira->codegen->invalid_instruction; |
| 28252 | return ira->codegen->invalid_inst_gen; |
| 27407 | 28253 | } |
| 27408 | 28254 | |
| 27409 | 28255 | if (instruction->lval == LValPtr) { |
| 27410 | 28256 | return ref_instruction; |
| 27411 | 28257 | } else { |
| 27412 | | return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr); |
| 28258 | return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr); |
| 27413 | 28259 | } |
| 27414 | 28260 | } |
| 27415 | 28261 | |
| 27416 | | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 28262 | static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtrToInt *instruction) { |
| 27417 | 28263 | Error err; |
| 27418 | | IrInstruction *target = instruction->target->child; |
| 28264 | IrInstGen *target = instruction->target->child; |
| 27419 | 28265 | if (type_is_invalid(target->value->type)) |
| 27420 | | return ira->codegen->invalid_instruction; |
| 28266 | return ira->codegen->invalid_inst_gen; |
| 27421 | 28267 | |
| 27422 | 28268 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 27423 | 28269 | |
| 27424 | 28270 | // We check size explicitly so we can use get_src_ptr_type here. |
| 27425 | 28271 | if (get_src_ptr_type(target->value->type) == nullptr) { |
| 27426 | | ir_add_error(ira, target, |
| 28272 | ir_add_error(ira, &target->base, |
| 27427 | 28273 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 27428 | | return ira->codegen->invalid_instruction; |
| 28274 | return ira->codegen->invalid_inst_gen; |
| 27429 | 28275 | } |
| 27430 | 28276 | |
| 27431 | 28277 | bool has_bits; |
| 27432 | 28278 | if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits))) |
| 27433 | | return ira->codegen->invalid_instruction; |
| 28279 | return ira->codegen->invalid_inst_gen; |
| 27434 | 28280 | |
| 27435 | 28281 | if (!has_bits) { |
| 27436 | | ir_add_error(ira, target, |
| 28282 | ir_add_error(ira, &target->base, |
| 27437 | 28283 | buf_sprintf("pointer to size 0 type has no address")); |
| 27438 | | return ira->codegen->invalid_instruction; |
| 28284 | return ira->codegen->invalid_inst_gen; |
| 27439 | 28285 | } |
| 27440 | 28286 | |
| 27441 | 28287 | if (instr_is_comptime(target)) { |
| 27442 | 28288 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 27443 | 28289 | if (!val) |
| 27444 | | return ira->codegen->invalid_instruction; |
| 28290 | return ira->codegen->invalid_inst_gen; |
| 27445 | 28291 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 27446 | | IrInstruction *result = ir_const(ira, &instruction->base, usize); |
| 28292 | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 27447 | 28293 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 27448 | 28294 | result->value->type = usize; |
| 27449 | 28295 | return result; |
| 27450 | 28296 | } |
| 27451 | 28297 | } |
| 27452 | 28298 | |
| 27453 | | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, |
| 27454 | | instruction->base.source_node, target); |
| 27455 | | result->value->type = usize; |
| 27456 | | return result; |
| 28299 | return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target); |
| 27457 | 28300 | } |
| 27458 | 28301 | |
| 27459 | | static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 27460 | | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 28302 | static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) { |
| 28303 | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 27461 | 28304 | result->value->special = ConstValSpecialLazy; |
| 27462 | 28305 | |
| 27463 | 28306 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType"); |
| ... | ... | @@ -27468,17 +28311,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 27468 | 28311 | if (instruction->sentinel != nullptr) { |
| 27469 | 28312 | lazy_ptr_type->sentinel = instruction->sentinel->child; |
| 27470 | 28313 | if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr) |
| 27471 | | return ira->codegen->invalid_instruction; |
| 28314 | return ira->codegen->invalid_inst_gen; |
| 27472 | 28315 | } |
| 27473 | 28316 | |
| 27474 | 28317 | lazy_ptr_type->elem_type = instruction->child_type->child; |
| 27475 | 28318 | if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr) |
| 27476 | | return ira->codegen->invalid_instruction; |
| 28319 | return ira->codegen->invalid_inst_gen; |
| 27477 | 28320 | |
| 27478 | 28321 | if (instruction->align_value != nullptr) { |
| 27479 | 28322 | lazy_ptr_type->align_inst = instruction->align_value->child; |
| 27480 | 28323 | if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr) |
| 27481 | | return ira->codegen->invalid_instruction; |
| 28324 | return ira->codegen->invalid_inst_gen; |
| 27482 | 28325 | } |
| 27483 | 28326 | |
| 27484 | 28327 | lazy_ptr_type->ptr_len = instruction->ptr_len; |
| ... | ... | @@ -27491,10 +28334,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 27491 | 28334 | return result; |
| 27492 | 28335 | } |
| 27493 | 28336 | |
| 27494 | | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 27495 | | IrInstruction *target = instruction->target->child; |
| 28337 | static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) { |
| 28338 | IrInstGen *target = instruction->target->child; |
| 27496 | 28339 | if (type_is_invalid(target->value->type)) |
| 27497 | | return ira->codegen->invalid_instruction; |
| 28340 | return ira->codegen->invalid_inst_gen; |
| 27498 | 28341 | |
| 27499 | 28342 | ZigType *elem_type = nullptr; |
| 27500 | 28343 | if (is_slice(target->value->type)) { |
| ... | ... | @@ -27505,192 +28348,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 27505 | 28348 | } |
| 27506 | 28349 | |
| 27507 | 28350 | uint32_t align_bytes; |
| 27508 | | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 28351 | IrInstGen *align_bytes_inst = instruction->align_bytes->child; |
| 27509 | 28352 | if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes)) |
| 27510 | | return ira->codegen->invalid_instruction; |
| 28353 | return ira->codegen->invalid_inst_gen; |
| 27511 | 28354 | |
| 27512 | | IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); |
| 28355 | IrInstGen *result = ir_align_cast(ira, target, align_bytes, true); |
| 27513 | 28356 | if (type_is_invalid(result->value->type)) |
| 27514 | | return ira->codegen->invalid_instruction; |
| 28357 | return ira->codegen->invalid_inst_gen; |
| 27515 | 28358 | |
| 27516 | 28359 | return result; |
| 27517 | 28360 | } |
| 27518 | 28361 | |
| 27519 | | static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 28362 | static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) { |
| 27520 | 28363 | Buf *bare_name = buf_alloc(); |
| 27521 | | Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", |
| 27522 | | instruction->base.scope, instruction->base.source_node, bare_name); |
| 27523 | | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 27524 | | buf_ptr(full_name), bare_name); |
| 27525 | | return ir_const_type(ira, &instruction->base, result_type); |
| 28364 | Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque", |
| 28365 | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| 28366 | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope, |
| 28367 | instruction->base.base.source_node, buf_ptr(full_name), bare_name); |
| 28368 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 27526 | 28369 | } |
| 27527 | 28370 | |
| 27528 | | static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 28371 | static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstSrcSetAlignStack *instruction) { |
| 27529 | 28372 | uint32_t align_bytes; |
| 27530 | | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 28373 | IrInstGen *align_bytes_inst = instruction->align_bytes->child; |
| 27531 | 28374 | if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes)) |
| 27532 | | return ira->codegen->invalid_instruction; |
| 28375 | return ira->codegen->invalid_inst_gen; |
| 27533 | 28376 | |
| 27534 | 28377 | if (align_bytes > 256) { |
| 27535 | | ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 27536 | | return ira->codegen->invalid_instruction; |
| 28378 | ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 28379 | return ira->codegen->invalid_inst_gen; |
| 27537 | 28380 | } |
| 27538 | 28381 | |
| 27539 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28382 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 27540 | 28383 | if (fn_entry == nullptr) { |
| 27541 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); |
| 27542 | | return ira->codegen->invalid_instruction; |
| 28384 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function")); |
| 28385 | return ira->codegen->invalid_inst_gen; |
| 27543 | 28386 | } |
| 27544 | 28387 | if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) { |
| 27545 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function")); |
| 27546 | | return ira->codegen->invalid_instruction; |
| 28388 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function")); |
| 28389 | return ira->codegen->invalid_inst_gen; |
| 27547 | 28390 | } |
| 27548 | 28391 | |
| 27549 | 28392 | if (fn_entry->fn_inline == FnInlineAlways) { |
| 27550 | | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function")); |
| 27551 | | return ira->codegen->invalid_instruction; |
| 28393 | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function")); |
| 28394 | return ira->codegen->invalid_inst_gen; |
| 27552 | 28395 | } |
| 27553 | 28396 | |
| 27554 | 28397 | if (fn_entry->set_alignstack_node != nullptr) { |
| 27555 | | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 28398 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 27556 | 28399 | buf_sprintf("alignstack set twice")); |
| 27557 | 28400 | add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here")); |
| 27558 | | return ira->codegen->invalid_instruction; |
| 28401 | return ira->codegen->invalid_inst_gen; |
| 27559 | 28402 | } |
| 27560 | 28403 | |
| 27561 | | fn_entry->set_alignstack_node = instruction->base.source_node; |
| 28404 | fn_entry->set_alignstack_node = instruction->base.base.source_node; |
| 27562 | 28405 | fn_entry->alignstack_value = align_bytes; |
| 27563 | 28406 | |
| 27564 | | return ir_const_void(ira, &instruction->base); |
| 28407 | return ir_const_void(ira, &instruction->base.base); |
| 27565 | 28408 | } |
| 27566 | 28409 | |
| 27567 | | static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { |
| 27568 | | IrInstruction *fn_type_inst = instruction->fn_type->child; |
| 28410 | static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) { |
| 28411 | IrInstGen *fn_type_inst = instruction->fn_type->child; |
| 27569 | 28412 | ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); |
| 27570 | 28413 | if (type_is_invalid(fn_type)) |
| 27571 | | return ira->codegen->invalid_instruction; |
| 28414 | return ira->codegen->invalid_inst_gen; |
| 27572 | 28415 | |
| 27573 | | IrInstruction *arg_index_inst = instruction->arg_index->child; |
| 28416 | IrInstGen *arg_index_inst = instruction->arg_index->child; |
| 27574 | 28417 | uint64_t arg_index; |
| 27575 | 28418 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) |
| 27576 | | return ira->codegen->invalid_instruction; |
| 28419 | return ira->codegen->invalid_inst_gen; |
| 27577 | 28420 | |
| 27578 | 28421 | if (fn_type->id == ZigTypeIdBoundFn) { |
| 27579 | 28422 | fn_type = fn_type->data.bound_fn.fn_type; |
| 27580 | 28423 | arg_index += 1; |
| 27581 | 28424 | } |
| 27582 | 28425 | if (fn_type->id != ZigTypeIdFn) { |
| 27583 | | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 27584 | | return ira->codegen->invalid_instruction; |
| 28426 | ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 28427 | return ira->codegen->invalid_inst_gen; |
| 27585 | 28428 | } |
| 27586 | 28429 | |
| 27587 | 28430 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| 27588 | 28431 | if (arg_index >= fn_type_id->param_count) { |
| 27589 | 28432 | if (instruction->allow_var) { |
| 27590 | 28433 | // TODO remove this with var args |
| 27591 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var); |
| 28434 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); |
| 27592 | 28435 | } |
| 27593 | | ir_add_error(ira, arg_index_inst, |
| 28436 | ir_add_error(ira, &arg_index_inst->base, |
| 27594 | 28437 | buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments", |
| 27595 | 28438 | arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count)); |
| 27596 | | return ira->codegen->invalid_instruction; |
| 28439 | return ira->codegen->invalid_inst_gen; |
| 27597 | 28440 | } |
| 27598 | 28441 | |
| 27599 | 28442 | ZigType *result_type = fn_type_id->param_info[arg_index].type; |
| 27600 | 28443 | if (result_type == nullptr) { |
| 27601 | 28444 | // Args are only unresolved if our function is generic. |
| 27602 | | ir_assert(fn_type->data.fn.is_generic, &instruction->base); |
| 28445 | ir_assert(fn_type->data.fn.is_generic, &instruction->base.base); |
| 27603 | 28446 | |
| 27604 | 28447 | if (instruction->allow_var) { |
| 27605 | | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var); |
| 28448 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); |
| 27606 | 28449 | } else { |
| 27607 | | ir_add_error(ira, arg_index_inst, |
| 28450 | ir_add_error(ira, &arg_index_inst->base, |
| 27608 | 28451 | buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic", |
| 27609 | 28452 | arg_index, buf_ptr(&fn_type->name))); |
| 27610 | | return ira->codegen->invalid_instruction; |
| 28453 | return ira->codegen->invalid_inst_gen; |
| 27611 | 28454 | } |
| 27612 | 28455 | } |
| 27613 | | return ir_const_type(ira, &instruction->base, result_type); |
| 28456 | return ir_const_type(ira, &instruction->base.base, result_type); |
| 27614 | 28457 | } |
| 27615 | 28458 | |
| 27616 | | static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { |
| 28459 | static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) { |
| 27617 | 28460 | Error err; |
| 27618 | | IrInstruction *target_inst = instruction->target->child; |
| 28461 | IrInstGen *target_inst = instruction->target->child; |
| 27619 | 28462 | ZigType *enum_type = ir_resolve_type(ira, target_inst); |
| 27620 | 28463 | if (type_is_invalid(enum_type)) |
| 27621 | | return ira->codegen->invalid_instruction; |
| 28464 | return ira->codegen->invalid_inst_gen; |
| 27622 | 28465 | |
| 27623 | 28466 | if (enum_type->id == ZigTypeIdEnum) { |
| 27624 | 28467 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown))) |
| 27625 | | return ira->codegen->invalid_instruction; |
| 28468 | return ira->codegen->invalid_inst_gen; |
| 27626 | 28469 | |
| 27627 | | return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type); |
| 28470 | return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type); |
| 27628 | 28471 | } else if (enum_type->id == ZigTypeIdUnion) { |
| 27629 | | ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target, enum_type); |
| 28472 | ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type); |
| 27630 | 28473 | if (type_is_invalid(tag_type)) |
| 27631 | | return ira->codegen->invalid_instruction; |
| 27632 | | return ir_const_type(ira, &instruction->base, tag_type); |
| 28474 | return ira->codegen->invalid_inst_gen; |
| 28475 | return ir_const_type(ira, &instruction->base.base, tag_type); |
| 27633 | 28476 | } else { |
| 27634 | | ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'", |
| 28477 | ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'", |
| 27635 | 28478 | buf_ptr(&enum_type->name))); |
| 27636 | | return ira->codegen->invalid_instruction; |
| 28479 | return ira->codegen->invalid_inst_gen; |
| 27637 | 28480 | } |
| 27638 | 28481 | } |
| 27639 | 28482 | |
| 27640 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| 28483 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 27641 | 28484 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 27642 | 28485 | if (type_is_invalid(operand_type)) |
| 27643 | 28486 | return ira->codegen->builtin_types.entry_invalid; |
| 27644 | 28487 | |
| 27645 | 28488 | if (operand_type->id == ZigTypeIdInt) { |
| 27646 | 28489 | if (operand_type->data.integral.bit_count < 8) { |
| 27647 | | ir_add_error(ira, op, |
| 28490 | ir_add_error(ira, &op->base, |
| 27648 | 28491 | buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", |
| 27649 | 28492 | operand_type->data.integral.bit_count)); |
| 27650 | 28493 | return ira->codegen->builtin_types.entry_invalid; |
| 27651 | 28494 | } |
| 27652 | 28495 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27653 | 28496 | if (operand_type->data.integral.bit_count > max_atomic_bits) { |
| 27654 | | ir_add_error(ira, op, |
| 28497 | ir_add_error(ira, &op->base, |
| 27655 | 28498 | buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type", |
| 27656 | 28499 | max_atomic_bits, operand_type->data.integral.bit_count)); |
| 27657 | 28500 | return ira->codegen->builtin_types.entry_invalid; |
| 27658 | 28501 | } |
| 27659 | 28502 | if (!is_power_of_2(operand_type->data.integral.bit_count)) { |
| 27660 | | ir_add_error(ira, op, |
| 28503 | ir_add_error(ira, &op->base, |
| 27661 | 28504 | buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count)); |
| 27662 | 28505 | return ira->codegen->builtin_types.entry_invalid; |
| 27663 | 28506 | } |
| 27664 | 28507 | } else if (operand_type->id == ZigTypeIdEnum) { |
| 27665 | 28508 | ZigType *int_type = operand_type->data.enumeration.tag_int_type; |
| 27666 | 28509 | if (int_type->data.integral.bit_count < 8) { |
| 27667 | | ir_add_error(ira, op, |
| 28510 | ir_add_error(ira, &op->base, |
| 27668 | 28511 | buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type", |
| 27669 | 28512 | int_type->data.integral.bit_count)); |
| 27670 | 28513 | return ira->codegen->builtin_types.entry_invalid; |
| 27671 | 28514 | } |
| 27672 | 28515 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27673 | 28516 | if (int_type->data.integral.bit_count > max_atomic_bits) { |
| 27674 | | ir_add_error(ira, op, |
| 28517 | ir_add_error(ira, &op->base, |
| 27675 | 28518 | buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type", |
| 27676 | 28519 | max_atomic_bits, int_type->data.integral.bit_count)); |
| 27677 | 28520 | return ira->codegen->builtin_types.entry_invalid; |
| 27678 | 28521 | } |
| 27679 | 28522 | if (!is_power_of_2(int_type->data.integral.bit_count)) { |
| 27680 | | ir_add_error(ira, op, |
| 28523 | ir_add_error(ira, &op->base, |
| 27681 | 28524 | buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count)); |
| 27682 | 28525 | return ira->codegen->builtin_types.entry_invalid; |
| 27683 | 28526 | } |
| 27684 | 28527 | } else if (operand_type->id == ZigTypeIdFloat) { |
| 27685 | 28528 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 27686 | 28529 | if (operand_type->data.floating.bit_count > max_atomic_bits) { |
| 27687 | | ir_add_error(ira, op, |
| 28530 | ir_add_error(ira, &op->base, |
| 27688 | 28531 | buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float", |
| 27689 | 28532 | max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count)); |
| 27690 | 28533 | return ira->codegen->builtin_types.entry_invalid; |
| 27691 | 28534 | } |
| 27692 | 28535 | } else if (get_codegen_ptr_type(operand_type) == nullptr) { |
| 27693 | | ir_add_error(ira, op, |
| 28536 | ir_add_error(ira, &op->base, |
| 27694 | 28537 | buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name))); |
| 27695 | 28538 | return ira->codegen->builtin_types.entry_invalid; |
| 27696 | 28539 | } |
| ... | ... | @@ -27698,172 +28541,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op |
| 27698 | 28541 | return operand_type; |
| 27699 | 28542 | } |
| 27700 | 28543 | |
| 27701 | | static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 28544 | static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) { |
| 27702 | 28545 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27703 | 28546 | if (type_is_invalid(operand_type)) |
| 27704 | | return ira->codegen->invalid_instruction; |
| 28547 | return ira->codegen->invalid_inst_gen; |
| 27705 | 28548 | |
| 27706 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28549 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27707 | 28550 | if (type_is_invalid(ptr_inst->value->type)) |
| 27708 | | return ira->codegen->invalid_instruction; |
| 28551 | return ira->codegen->invalid_inst_gen; |
| 27709 | 28552 | |
| 27710 | 28553 | // TODO let this be volatile |
| 27711 | 28554 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 27712 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28555 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27713 | 28556 | if (type_is_invalid(casted_ptr->value->type)) |
| 27714 | | return ira->codegen->invalid_instruction; |
| 28557 | return ira->codegen->invalid_inst_gen; |
| 27715 | 28558 | |
| 27716 | 28559 | AtomicRmwOp op; |
| 27717 | | if (instruction->op == nullptr) { |
| 27718 | | op = instruction->resolved_op; |
| 27719 | | } else { |
| 27720 | | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) { |
| 27721 | | return ira->codegen->invalid_instruction; |
| 27722 | | } |
| 28560 | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) { |
| 28561 | return ira->codegen->invalid_inst_gen; |
| 27723 | 28562 | } |
| 27724 | 28563 | |
| 27725 | 28564 | if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) { |
| 27726 | | ir_add_error(ira, instruction->op, |
| 28565 | ir_add_error(ira, &instruction->op->base, |
| 27727 | 28566 | buf_sprintf("@atomicRmw on enum only works with .Xchg")); |
| 27728 | | return ira->codegen->invalid_instruction; |
| 28567 | return ira->codegen->invalid_inst_gen; |
| 27729 | 28568 | } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) { |
| 27730 | | ir_add_error(ira, instruction->op, |
| 28569 | ir_add_error(ira, &instruction->op->base, |
| 27731 | 28570 | buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub")); |
| 27732 | | return ira->codegen->invalid_instruction; |
| 28571 | return ira->codegen->invalid_inst_gen; |
| 27733 | 28572 | } |
| 27734 | 28573 | |
| 27735 | | IrInstruction *operand = instruction->operand->child; |
| 28574 | IrInstGen *operand = instruction->operand->child; |
| 27736 | 28575 | if (type_is_invalid(operand->value->type)) |
| 27737 | | return ira->codegen->invalid_instruction; |
| 28576 | return ira->codegen->invalid_inst_gen; |
| 27738 | 28577 | |
| 27739 | | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 28578 | IrInstGen *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 27740 | 28579 | if (type_is_invalid(casted_operand->value->type)) |
| 27741 | | return ira->codegen->invalid_instruction; |
| 28580 | return ira->codegen->invalid_inst_gen; |
| 27742 | 28581 | |
| 27743 | 28582 | AtomicOrder ordering; |
| 27744 | | if (instruction->ordering == nullptr) { |
| 27745 | | ordering = instruction->resolved_ordering; |
| 27746 | | } else { |
| 27747 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27748 | | return ira->codegen->invalid_instruction; |
| 27749 | | if (ordering == AtomicOrderUnordered) { |
| 27750 | | ir_add_error(ira, instruction->ordering, |
| 27751 | | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 27752 | | return ira->codegen->invalid_instruction; |
| 27753 | | } |
| 28583 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28584 | return ira->codegen->invalid_inst_gen; |
| 28585 | if (ordering == AtomicOrderUnordered) { |
| 28586 | ir_add_error(ira, &instruction->ordering->base, |
| 28587 | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 28588 | return ira->codegen->invalid_inst_gen; |
| 27754 | 28589 | } |
| 27755 | 28590 | |
| 27756 | 28591 | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 27757 | 28592 | { |
| 27758 | | zig_panic("TODO compile-time execution of atomicRmw"); |
| 28593 | ir_add_error(ira, &instruction->base.base, |
| 28594 | buf_sprintf("compiler bug: TODO compile-time execution of @atomicRmw")); |
| 28595 | return ira->codegen->invalid_inst_gen; |
| 27759 | 28596 | } |
| 27760 | 28597 | |
| 27761 | | IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, |
| 27762 | | instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, |
| 27763 | | op, ordering); |
| 27764 | | result->value->type = operand_type; |
| 27765 | | return result; |
| 28598 | return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op, |
| 28599 | ordering, operand_type); |
| 27766 | 28600 | } |
| 27767 | 28601 | |
| 27768 | | static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 28602 | static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) { |
| 27769 | 28603 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27770 | 28604 | if (type_is_invalid(operand_type)) |
| 27771 | | return ira->codegen->invalid_instruction; |
| 28605 | return ira->codegen->invalid_inst_gen; |
| 27772 | 28606 | |
| 27773 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28607 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27774 | 28608 | if (type_is_invalid(ptr_inst->value->type)) |
| 27775 | | return ira->codegen->invalid_instruction; |
| 28609 | return ira->codegen->invalid_inst_gen; |
| 27776 | 28610 | |
| 27777 | 28611 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 27778 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28612 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27779 | 28613 | if (type_is_invalid(casted_ptr->value->type)) |
| 27780 | | return ira->codegen->invalid_instruction; |
| 28614 | return ira->codegen->invalid_inst_gen; |
| 27781 | 28615 | |
| 27782 | 28616 | AtomicOrder ordering; |
| 27783 | | if (instruction->ordering == nullptr) { |
| 27784 | | ordering = instruction->resolved_ordering; |
| 27785 | | } else { |
| 27786 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27787 | | return ira->codegen->invalid_instruction; |
| 27788 | | } |
| 28617 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28618 | return ira->codegen->invalid_inst_gen; |
| 27789 | 28619 | |
| 27790 | 28620 | if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) { |
| 27791 | | ir_assert(instruction->ordering != nullptr, &instruction->base); |
| 27792 | | ir_add_error(ira, instruction->ordering, |
| 28621 | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 28622 | ir_add_error(ira, &instruction->ordering->base, |
| 27793 | 28623 | buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel")); |
| 27794 | | return ira->codegen->invalid_instruction; |
| 28624 | return ira->codegen->invalid_inst_gen; |
| 27795 | 28625 | } |
| 27796 | 28626 | |
| 27797 | 28627 | if (instr_is_comptime(casted_ptr)) { |
| 27798 | | IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr); |
| 27799 | | ir_assert(result->value->type != nullptr, &instruction->base); |
| 28628 | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr); |
| 28629 | ir_assert(result->value->type != nullptr, &instruction->base.base); |
| 27800 | 28630 | return result; |
| 27801 | 28631 | } |
| 27802 | 28632 | |
| 27803 | | IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, |
| 27804 | | instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); |
| 27805 | | result->value->type = operand_type; |
| 27806 | | return result; |
| 28633 | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type); |
| 27807 | 28634 | } |
| 27808 | 28635 | |
| 27809 | | static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) { |
| 28636 | static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) { |
| 27810 | 28637 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 27811 | 28638 | if (type_is_invalid(operand_type)) |
| 27812 | | return ira->codegen->invalid_instruction; |
| 28639 | return ira->codegen->invalid_inst_gen; |
| 27813 | 28640 | |
| 27814 | | IrInstruction *ptr_inst = instruction->ptr->child; |
| 28641 | IrInstGen *ptr_inst = instruction->ptr->child; |
| 27815 | 28642 | if (type_is_invalid(ptr_inst->value->type)) |
| 27816 | | return ira->codegen->invalid_instruction; |
| 28643 | return ira->codegen->invalid_inst_gen; |
| 27817 | 28644 | |
| 27818 | 28645 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 27819 | | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 28646 | IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 27820 | 28647 | if (type_is_invalid(casted_ptr->value->type)) |
| 27821 | | return ira->codegen->invalid_instruction; |
| 28648 | return ira->codegen->invalid_inst_gen; |
| 27822 | 28649 | |
| 27823 | | IrInstruction *value = instruction->value->child; |
| 28650 | IrInstGen *value = instruction->value->child; |
| 27824 | 28651 | if (type_is_invalid(value->value->type)) |
| 27825 | | return ira->codegen->invalid_instruction; |
| 28652 | return ira->codegen->invalid_inst_gen; |
| 27826 | 28653 | |
| 27827 | | IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 28654 | IrInstGen *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 27828 | 28655 | if (type_is_invalid(casted_value->value->type)) |
| 27829 | | return ira->codegen->invalid_instruction; |
| 28656 | return ira->codegen->invalid_inst_gen; |
| 27830 | 28657 | |
| 27831 | 28658 | |
| 27832 | 28659 | AtomicOrder ordering; |
| 27833 | | if (instruction->ordering == nullptr) { |
| 27834 | | ordering = instruction->resolved_ordering; |
| 27835 | | } else { |
| 27836 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 27837 | | return ira->codegen->invalid_instruction; |
| 27838 | | } |
| 28660 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 28661 | return ira->codegen->invalid_inst_gen; |
| 27839 | 28662 | |
| 27840 | 28663 | if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) { |
| 27841 | | ir_assert(instruction->ordering != nullptr, &instruction->base); |
| 27842 | | ir_add_error(ira, instruction->ordering, |
| 28664 | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 28665 | ir_add_error(ira, &instruction->ordering->base, |
| 27843 | 28666 | buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel")); |
| 27844 | | return ira->codegen->invalid_instruction; |
| 28667 | return ira->codegen->invalid_inst_gen; |
| 27845 | 28668 | } |
| 27846 | 28669 | |
| 27847 | 28670 | if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { |
| 27848 | | IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false); |
| 28671 | IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false); |
| 27849 | 28672 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27850 | 28673 | return result; |
| 27851 | 28674 | } |
| 27852 | 28675 | |
| 27853 | | IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope, |
| 27854 | | instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering); |
| 27855 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27856 | | return result; |
| 28676 | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering); |
| 27857 | 28677 | } |
| 27858 | 28678 | |
| 27859 | | static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 27860 | | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 27861 | | instruction->base.source_node); |
| 27862 | | result->value->type = ira->codegen->builtin_types.entry_void; |
| 27863 | | return result; |
| 28679 | static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) { |
| 28680 | return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base); |
| 27864 | 28681 | } |
| 27865 | 28682 | |
| 27866 | | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, BuiltinFnId fop, ZigType *float_type, |
| 28683 | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type, |
| 27867 | 28684 | ZigValue *op, ZigValue *out_val) |
| 27868 | 28685 | { |
| 27869 | 28686 | assert(ira && source_instr && float_type && out_val && op); |
| ... | ... | @@ -28076,30 +28893,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B |
| 28076 | 28893 | return nullptr; |
| 28077 | 28894 | } |
| 28078 | 28895 | |
| 28079 | | static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) { |
| 28080 | | IrInstruction *operand = instruction->operand->child; |
| 28896 | static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) { |
| 28897 | IrInstGen *operand = instruction->operand->child; |
| 28081 | 28898 | ZigType *operand_type = operand->value->type; |
| 28082 | 28899 | if (type_is_invalid(operand_type)) |
| 28083 | | return ira->codegen->invalid_instruction; |
| 28900 | return ira->codegen->invalid_inst_gen; |
| 28084 | 28901 | |
| 28085 | 28902 | // This instruction accepts floats and vectors of floats. |
| 28086 | 28903 | ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? |
| 28087 | 28904 | operand_type->data.vector.elem_type : operand_type; |
| 28088 | 28905 | |
| 28089 | 28906 | if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) { |
| 28090 | | ir_add_error(ira, operand, |
| 28907 | ir_add_error(ira, &operand->base, |
| 28091 | 28908 | buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name))); |
| 28092 | | return ira->codegen->invalid_instruction; |
| 28909 | return ira->codegen->invalid_inst_gen; |
| 28093 | 28910 | } |
| 28094 | 28911 | |
| 28095 | 28912 | if (instr_is_comptime(operand)) { |
| 28096 | 28913 | ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk); |
| 28097 | 28914 | if (operand_val == nullptr) |
| 28098 | | return ira->codegen->invalid_instruction; |
| 28915 | return ira->codegen->invalid_inst_gen; |
| 28099 | 28916 | if (operand_val->special == ConstValSpecialUndef) |
| 28100 | | return ir_const_undef(ira, &instruction->base, operand_type); |
| 28917 | return ir_const_undef(ira, &instruction->base.base, operand_type); |
| 28101 | 28918 | |
| 28102 | | IrInstruction *result = ir_const(ira, &instruction->base, operand_type); |
| 28919 | IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type); |
| 28103 | 28920 | ZigValue *out_val = result->value; |
| 28104 | 28921 | |
| 28105 | 28922 | if (operand_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -28110,47 +28927,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 28110 | 28927 | for (size_t i = 0; i < len; i += 1) { |
| 28111 | 28928 | ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i]; |
| 28112 | 28929 | ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 28113 | | ir_assert(elem_operand->type == scalar_type, &instruction->base); |
| 28114 | | ir_assert(float_out_val->type == scalar_type, &instruction->base); |
| 28115 | | ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type, |
| 28930 | ir_assert(elem_operand->type == scalar_type, &instruction->base.base); |
| 28931 | ir_assert(float_out_val->type == scalar_type, &instruction->base.base); |
| 28932 | ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 28116 | 28933 | elem_operand, float_out_val); |
| 28117 | 28934 | if (msg != nullptr) { |
| 28118 | | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 28935 | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 28119 | 28936 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 28120 | | return ira->codegen->invalid_instruction; |
| 28937 | return ira->codegen->invalid_inst_gen; |
| 28121 | 28938 | } |
| 28122 | 28939 | float_out_val->type = scalar_type; |
| 28123 | 28940 | } |
| 28124 | 28941 | out_val->type = operand_type; |
| 28125 | 28942 | out_val->special = ConstValSpecialStatic; |
| 28126 | 28943 | } else { |
| 28127 | | if (ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type, |
| 28944 | if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 28128 | 28945 | operand_val, out_val) != nullptr) |
| 28129 | 28946 | { |
| 28130 | | return ira->codegen->invalid_instruction; |
| 28947 | return ira->codegen->invalid_inst_gen; |
| 28131 | 28948 | } |
| 28132 | 28949 | } |
| 28133 | 28950 | return result; |
| 28134 | 28951 | } |
| 28135 | 28952 | |
| 28136 | | ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base); |
| 28953 | ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base); |
| 28137 | 28954 | |
| 28138 | | IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope, |
| 28139 | | instruction->base.source_node, operand, instruction->fn_id); |
| 28140 | | result->value->type = operand_type; |
| 28141 | | return result; |
| 28955 | return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type); |
| 28142 | 28956 | } |
| 28143 | 28957 | |
| 28144 | | static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) { |
| 28958 | static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) { |
| 28145 | 28959 | Error err; |
| 28146 | 28960 | |
| 28147 | 28961 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 28148 | 28962 | if (type_is_invalid(int_type)) |
| 28149 | | return ira->codegen->invalid_instruction; |
| 28963 | return ira->codegen->invalid_inst_gen; |
| 28150 | 28964 | |
| 28151 | | IrInstruction *uncasted_op = instruction->op->child; |
| 28965 | IrInstGen *uncasted_op = instruction->op->child; |
| 28152 | 28966 | if (type_is_invalid(uncasted_op->value->type)) |
| 28153 | | return ira->codegen->invalid_instruction; |
| 28967 | return ira->codegen->invalid_inst_gen; |
| 28154 | 28968 | |
| 28155 | 28969 | uint32_t vector_len; // UINT32_MAX means not a vector |
| 28156 | 28970 | if (uncasted_op->value->type->id == ZigTypeIdArray && |
| ... | ... | @@ -28166,28 +28980,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28166 | 28980 | bool is_vector = (vector_len != UINT32_MAX); |
| 28167 | 28981 | ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type; |
| 28168 | 28982 | |
| 28169 | | IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 28983 | IrInstGen *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 28170 | 28984 | if (type_is_invalid(op->value->type)) |
| 28171 | | return ira->codegen->invalid_instruction; |
| 28985 | return ira->codegen->invalid_inst_gen; |
| 28172 | 28986 | |
| 28173 | 28987 | if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0) |
| 28174 | 28988 | return op; |
| 28175 | 28989 | |
| 28176 | 28990 | if (int_type->data.integral.bit_count % 8 != 0) { |
| 28177 | | ir_add_error(ira, instruction->op, |
| 28991 | ir_add_error(ira, &instruction->op->base, |
| 28178 | 28992 | buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8", |
| 28179 | 28993 | buf_ptr(&int_type->name), int_type->data.integral.bit_count)); |
| 28180 | | return ira->codegen->invalid_instruction; |
| 28994 | return ira->codegen->invalid_inst_gen; |
| 28181 | 28995 | } |
| 28182 | 28996 | |
| 28183 | 28997 | if (instr_is_comptime(op)) { |
| 28184 | 28998 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 28185 | 28999 | if (val == nullptr) |
| 28186 | | return ira->codegen->invalid_instruction; |
| 29000 | return ira->codegen->invalid_inst_gen; |
| 28187 | 29001 | if (val->special == ConstValSpecialUndef) |
| 28188 | | return ir_const_undef(ira, &instruction->base, op_type); |
| 29002 | return ir_const_undef(ira, &instruction->base.base, op_type); |
| 28189 | 29003 | |
| 28190 | | IrInstruction *result = ir_const(ira, &instruction->base, op_type); |
| 29004 | IrInstGen *result = ir_const(ira, &instruction->base.base, op_type); |
| 28191 | 29005 | size_t buf_size = int_type->data.integral.bit_count / 8; |
| 28192 | 29006 | uint8_t *buf = allocate_nonzero<uint8_t>(buf_size); |
| 28193 | 29007 | if (is_vector) { |
| ... | ... | @@ -28195,10 +29009,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28195 | 29009 | result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 28196 | 29010 | for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { |
| 28197 | 29011 | ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 28198 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, |
| 29012 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node, |
| 28199 | 29013 | op_elem_val, UndefOk))) |
| 28200 | 29014 | { |
| 28201 | | return ira->codegen->invalid_instruction; |
| 29015 | return ira->codegen->invalid_inst_gen; |
| 28202 | 29016 | } |
| 28203 | 29017 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 28204 | 29018 | result_elem_val->type = int_type; |
| ... | ... | @@ -28220,23 +29034,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 28220 | 29034 | return result; |
| 28221 | 29035 | } |
| 28222 | 29036 | |
| 28223 | | IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope, |
| 28224 | | instruction->base.source_node, nullptr, op); |
| 28225 | | result->value->type = op_type; |
| 28226 | | return result; |
| 29037 | return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op); |
| 28227 | 29038 | } |
| 28228 | 29039 | |
| 28229 | | static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) { |
| 29040 | static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) { |
| 28230 | 29041 | ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child); |
| 28231 | 29042 | if (type_is_invalid(int_type)) |
| 28232 | | return ira->codegen->invalid_instruction; |
| 29043 | return ira->codegen->invalid_inst_gen; |
| 28233 | 29044 | |
| 28234 | | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 29045 | IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 28235 | 29046 | if (type_is_invalid(op->value->type)) |
| 28236 | | return ira->codegen->invalid_instruction; |
| 29047 | return ira->codegen->invalid_inst_gen; |
| 28237 | 29048 | |
| 28238 | 29049 | if (int_type->data.integral.bit_count == 0) { |
| 28239 | | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 29050 | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 28240 | 29051 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 28241 | 29052 | return result; |
| 28242 | 29053 | } |
| ... | ... | @@ -28244,11 +29055,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 28244 | 29055 | if (instr_is_comptime(op)) { |
| 28245 | 29056 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 28246 | 29057 | if (val == nullptr) |
| 28247 | | return ira->codegen->invalid_instruction; |
| 29058 | return ira->codegen->invalid_inst_gen; |
| 28248 | 29059 | if (val->special == ConstValSpecialUndef) |
| 28249 | | return ir_const_undef(ira, &instruction->base, int_type); |
| 29060 | return ir_const_undef(ira, &instruction->base.base, int_type); |
| 28250 | 29061 | |
| 28251 | | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 29062 | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 28252 | 29063 | size_t num_bits = int_type->data.integral.bit_count; |
| 28253 | 29064 | size_t buf_size = (num_bits + 7) / 8; |
| 28254 | 29065 | uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size); |
| ... | ... | @@ -28275,128 +29086,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 28275 | 29086 | return result; |
| 28276 | 29087 | } |
| 28277 | 29088 | |
| 28278 | | IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope, |
| 28279 | | instruction->base.source_node, nullptr, op); |
| 28280 | | result->value->type = int_type; |
| 28281 | | return result; |
| 29089 | return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op); |
| 28282 | 29090 | } |
| 28283 | 29091 | |
| 28284 | 29092 | |
| 28285 | | static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 28286 | | IrInstruction *target = instruction->target->child; |
| 29093 | static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) { |
| 29094 | IrInstGen *target = instruction->target->child; |
| 28287 | 29095 | if (type_is_invalid(target->value->type)) |
| 28288 | | return ira->codegen->invalid_instruction; |
| 29096 | return ira->codegen->invalid_inst_gen; |
| 28289 | 29097 | |
| 28290 | | return ir_analyze_enum_to_int(ira, &instruction->base, target); |
| 29098 | return ir_analyze_enum_to_int(ira, &instruction->base.base, target); |
| 28291 | 29099 | } |
| 28292 | 29100 | |
| 28293 | | static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { |
| 29101 | static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) { |
| 28294 | 29102 | Error err; |
| 28295 | | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 29103 | IrInstGen *dest_type_value = instruction->dest_type->child; |
| 28296 | 29104 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 28297 | 29105 | if (type_is_invalid(dest_type)) |
| 28298 | | return ira->codegen->invalid_instruction; |
| 29106 | return ira->codegen->invalid_inst_gen; |
| 28299 | 29107 | |
| 28300 | 29108 | if (dest_type->id != ZigTypeIdEnum) { |
| 28301 | | ir_add_error(ira, instruction->dest_type, |
| 29109 | ir_add_error(ira, &instruction->dest_type->base, |
| 28302 | 29110 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 28303 | | return ira->codegen->invalid_instruction; |
| 29111 | return ira->codegen->invalid_inst_gen; |
| 28304 | 29112 | } |
| 28305 | 29113 | |
| 28306 | 29114 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 28307 | | return ira->codegen->invalid_instruction; |
| 29115 | return ira->codegen->invalid_inst_gen; |
| 28308 | 29116 | |
| 28309 | 29117 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 28310 | 29118 | |
| 28311 | | IrInstruction *target = instruction->target->child; |
| 29119 | IrInstGen *target = instruction->target->child; |
| 28312 | 29120 | if (type_is_invalid(target->value->type)) |
| 28313 | | return ira->codegen->invalid_instruction; |
| 29121 | return ira->codegen->invalid_inst_gen; |
| 28314 | 29122 | |
| 28315 | | IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 29123 | IrInstGen *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 28316 | 29124 | if (type_is_invalid(casted_target->value->type)) |
| 28317 | | return ira->codegen->invalid_instruction; |
| 29125 | return ira->codegen->invalid_inst_gen; |
| 28318 | 29126 | |
| 28319 | | return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| 29127 | return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type); |
| 28320 | 29128 | } |
| 28321 | 29129 | |
| 28322 | | static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { |
| 28323 | | IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child; |
| 29130 | static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) { |
| 29131 | IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child; |
| 28324 | 29132 | bool scope_is_comptime; |
| 28325 | 29133 | if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime)) |
| 28326 | | return ira->codegen->invalid_instruction; |
| 29134 | return ira->codegen->invalid_inst_gen; |
| 28327 | 29135 | |
| 28328 | | IrInstruction *is_comptime_inst = instruction->is_comptime->child; |
| 29136 | IrInstGen *is_comptime_inst = instruction->is_comptime->child; |
| 28329 | 29137 | bool is_comptime; |
| 28330 | 29138 | if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime)) |
| 28331 | | return ira->codegen->invalid_instruction; |
| 29139 | return ira->codegen->invalid_inst_gen; |
| 28332 | 29140 | |
| 28333 | 29141 | if (!scope_is_comptime && is_comptime) { |
| 28334 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 29142 | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 28335 | 29143 | buf_sprintf("comptime control flow inside runtime block")); |
| 28336 | | add_error_note(ira->codegen, msg, block_comptime_inst->source_node, |
| 29144 | add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node, |
| 28337 | 29145 | buf_sprintf("runtime block created here")); |
| 28338 | | return ira->codegen->invalid_instruction; |
| 29146 | return ira->codegen->invalid_inst_gen; |
| 28339 | 29147 | } |
| 28340 | 29148 | |
| 28341 | | return ir_const_void(ira, &instruction->base); |
| 29149 | return ir_const_void(ira, &instruction->base.base); |
| 28342 | 29150 | } |
| 28343 | 29151 | |
| 28344 | | static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) { |
| 29152 | static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) { |
| 28345 | 29153 | ZigType *container_type = ir_resolve_type(ira, instruction->container->child); |
| 28346 | 29154 | if (type_is_invalid(container_type)) |
| 28347 | | return ira->codegen->invalid_instruction; |
| 29155 | return ira->codegen->invalid_inst_gen; |
| 28348 | 29156 | |
| 28349 | 29157 | Buf *name = ir_resolve_str(ira, instruction->name->child); |
| 28350 | 29158 | if (name == nullptr) |
| 28351 | | return ira->codegen->invalid_instruction; |
| 29159 | return ira->codegen->invalid_inst_gen; |
| 28352 | 29160 | |
| 28353 | 29161 | if (!is_container(container_type)) { |
| 28354 | | ir_add_error(ira, instruction->container, |
| 29162 | ir_add_error(ira, &instruction->container->base, |
| 28355 | 29163 | buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name))); |
| 28356 | | return ira->codegen->invalid_instruction; |
| 29164 | return ira->codegen->invalid_inst_gen; |
| 28357 | 29165 | } |
| 28358 | 29166 | |
| 28359 | 29167 | ScopeDecls *container_scope = get_container_scope(container_type); |
| 28360 | 29168 | Tld *tld = find_container_decl(ira->codegen, container_scope, name); |
| 28361 | 29169 | if (tld == nullptr) |
| 28362 | | return ir_const_bool(ira, &instruction->base, false); |
| 29170 | return ir_const_bool(ira, &instruction->base.base, false); |
| 28363 | 29171 | |
| 28364 | | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) { |
| 28365 | | return ir_const_bool(ira, &instruction->base, false); |
| 29172 | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) { |
| 29173 | return ir_const_bool(ira, &instruction->base.base, false); |
| 28366 | 29174 | } |
| 28367 | 29175 | |
| 28368 | | return ir_const_bool(ira, &instruction->base, true); |
| 29176 | return ir_const_bool(ira, &instruction->base.base, true); |
| 28369 | 29177 | } |
| 28370 | 29178 | |
| 28371 | | static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) { |
| 29179 | static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) { |
| 28372 | 29180 | // put a variable of same name with invalid type in global scope |
| 28373 | 29181 | // so that future references to this same name will find a variable with an invalid type |
| 28374 | | populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 28375 | | instruction->name); |
| 28376 | | ir_add_error(ira, &instruction->base, |
| 29182 | populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope, |
| 29183 | instruction->base.base.source_node, instruction->name); |
| 29184 | ir_add_error(ira, &instruction->base.base, |
| 28377 | 29185 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name))); |
| 28378 | | return ira->codegen->invalid_instruction; |
| 29186 | return ira->codegen->invalid_inst_gen; |
| 28379 | 29187 | } |
| 28380 | 29188 | |
| 28381 | | static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { |
| 28382 | | IrInstruction *value = instruction->value->child; |
| 29189 | static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) { |
| 29190 | IrInstGen *value = instruction->value->child; |
| 28383 | 29191 | if (type_is_invalid(value->value->type)) |
| 28384 | | return ira->codegen->invalid_instruction; |
| 29192 | return ira->codegen->invalid_inst_gen; |
| 28385 | 29193 | |
| 28386 | 29194 | bool was_written = instruction->result_loc->written; |
| 28387 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 29195 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 28388 | 29196 | value->value->type, value, false, false, true); |
| 28389 | 29197 | if (result_loc != nullptr) { |
| 28390 | 29198 | if (type_is_invalid(result_loc->value->type)) |
| 28391 | | return ira->codegen->invalid_instruction; |
| 29199 | return ira->codegen->invalid_inst_gen; |
| 28392 | 29200 | if (result_loc->value->type->id == ZigTypeIdUnreachable) |
| 28393 | 29201 | return result_loc; |
| 28394 | 29202 | |
| 28395 | 29203 | if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { |
| 28396 | | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| 29204 | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value, |
| 28397 | 29205 | instruction->result_loc->allow_write_through_const); |
| 28398 | 29206 | if (type_is_invalid(store_ptr->value->type)) { |
| 28399 | | return ira->codegen->invalid_instruction; |
| 29207 | return ira->codegen->invalid_inst_gen; |
| 28400 | 29208 | } |
| 28401 | 29209 | } |
| 28402 | 29210 | |
| ... | ... | @@ -28411,33 +29219,33 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 28411 | 29219 | } |
| 28412 | 29220 | } |
| 28413 | 29221 | |
| 28414 | | return ir_const_void(ira, &instruction->base); |
| 29222 | return ir_const_void(ira, &instruction->base.base); |
| 28415 | 29223 | } |
| 28416 | 29224 | |
| 28417 | | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { |
| 28418 | | IrInstruction *operand = instruction->operand->child; |
| 29225 | static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) { |
| 29226 | IrInstGen *operand = instruction->operand->child; |
| 28419 | 29227 | if (type_is_invalid(operand->value->type)) |
| 28420 | 29228 | return operand; |
| 28421 | 29229 | |
| 28422 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 29230 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, |
| 28423 | 29231 | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); |
| 28424 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 29232 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 28425 | 29233 | return result_loc; |
| 28426 | 29234 | |
| 28427 | 29235 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); |
| 28428 | 29236 | if (type_is_invalid(dest_type)) |
| 28429 | | return ira->codegen->invalid_instruction; |
| 28430 | | return ir_implicit_cast2(ira, &instruction->base, operand, dest_type); |
| 29237 | return ira->codegen->invalid_inst_gen; |
| 29238 | return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type); |
| 28431 | 29239 | } |
| 28432 | 29240 | |
| 28433 | | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 28434 | | IrInstruction *operand = instruction->operand->child; |
| 29241 | static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) { |
| 29242 | IrInstGen *operand = instruction->operand->child; |
| 28435 | 29243 | if (type_is_invalid(operand->value->type)) |
| 28436 | 29244 | return operand; |
| 28437 | 29245 | |
| 28438 | | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 29246 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, |
| 28439 | 29247 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); |
| 28440 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 29248 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 28441 | 29249 | return result_loc; |
| 28442 | 29250 | |
| 28443 | 29251 | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { |
| ... | ... | @@ -28447,70 +29255,66 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst |
| 28447 | 29255 | return result_loc; |
| 28448 | 29256 | } |
| 28449 | 29257 | |
| 28450 | | static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 28451 | | IrInstructionUnionInitNamedField *instruction) |
| 29258 | static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 29259 | IrInstSrcUnionInitNamedField *instruction) |
| 28452 | 29260 | { |
| 28453 | 29261 | ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child); |
| 28454 | 29262 | if (type_is_invalid(union_type)) |
| 28455 | | return ira->codegen->invalid_instruction; |
| 29263 | return ira->codegen->invalid_inst_gen; |
| 28456 | 29264 | |
| 28457 | 29265 | if (union_type->id != ZigTypeIdUnion) { |
| 28458 | | ir_add_error(ira, instruction->union_type, |
| 29266 | ir_add_error(ira, &instruction->union_type->base, |
| 28459 | 29267 | buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name))); |
| 28460 | | return ira->codegen->invalid_instruction; |
| 29268 | return ira->codegen->invalid_inst_gen; |
| 28461 | 29269 | } |
| 28462 | 29270 | |
| 28463 | 29271 | Buf *field_name = ir_resolve_str(ira, instruction->field_name->child); |
| 28464 | 29272 | if (field_name == nullptr) |
| 28465 | | return ira->codegen->invalid_instruction; |
| 29273 | return ira->codegen->invalid_inst_gen; |
| 28466 | 29274 | |
| 28467 | | IrInstruction *field_result_loc = instruction->field_result_loc->child; |
| 29275 | IrInstGen *field_result_loc = instruction->field_result_loc->child; |
| 28468 | 29276 | if (type_is_invalid(field_result_loc->value->type)) |
| 28469 | | return ira->codegen->invalid_instruction; |
| 29277 | return ira->codegen->invalid_inst_gen; |
| 28470 | 29278 | |
| 28471 | | IrInstruction *result_loc = instruction->result_loc->child; |
| 29279 | IrInstGen *result_loc = instruction->result_loc->child; |
| 28472 | 29280 | if (type_is_invalid(result_loc->value->type)) |
| 28473 | | return ira->codegen->invalid_instruction; |
| 29281 | return ira->codegen->invalid_inst_gen; |
| 28474 | 29282 | |
| 28475 | | return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node, |
| 29283 | return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node, |
| 28476 | 29284 | union_type, field_name, field_result_loc, result_loc); |
| 28477 | 29285 | } |
| 28478 | 29286 | |
| 28479 | | static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) { |
| 28480 | | IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope, |
| 28481 | | instruction->base.source_node); |
| 28482 | | return &result->base; |
| 29287 | static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) { |
| 29288 | return ir_build_suspend_begin_gen(ira, &instruction->base.base); |
| 28483 | 29289 | } |
| 28484 | 29290 | |
| 28485 | | static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 28486 | | IrInstructionSuspendFinish *instruction) |
| 28487 | | { |
| 28488 | | IrInstruction *begin_base = instruction->begin->base.child; |
| 29291 | static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) { |
| 29292 | IrInstGen *begin_base = instruction->begin->base.child; |
| 28489 | 29293 | if (type_is_invalid(begin_base->value->type)) |
| 28490 | | return ira->codegen->invalid_instruction; |
| 28491 | | ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base); |
| 28492 | | IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base); |
| 29294 | return ira->codegen->invalid_inst_gen; |
| 29295 | ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base); |
| 29296 | IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base); |
| 28493 | 29297 | |
| 28494 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28495 | | ir_assert(fn_entry != nullptr, &instruction->base); |
| 29298 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 29299 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 28496 | 29300 | |
| 28497 | 29301 | if (fn_entry->inferred_async_node == nullptr) { |
| 28498 | | fn_entry->inferred_async_node = instruction->base.source_node; |
| 29302 | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 28499 | 29303 | } |
| 28500 | 29304 | |
| 28501 | | return ir_build_suspend_finish(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin); |
| 29305 | return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin); |
| 28502 | 29306 | } |
| 28503 | 29307 | |
| 28504 | | static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr, |
| 28505 | | IrInstruction *frame_ptr, ZigFn **target_fn) |
| 29308 | static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr, |
| 29309 | IrInstGen *frame_ptr, ZigFn **target_fn) |
| 28506 | 29310 | { |
| 28507 | 29311 | if (type_is_invalid(frame_ptr->value->type)) |
| 28508 | | return ira->codegen->invalid_instruction; |
| 29312 | return ira->codegen->invalid_inst_gen; |
| 28509 | 29313 | |
| 28510 | 29314 | *target_fn = nullptr; |
| 28511 | 29315 | |
| 28512 | 29316 | ZigType *result_type; |
| 28513 | | IrInstruction *frame; |
| 29317 | IrInstGen *frame; |
| 28514 | 29318 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 28515 | 29319 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 28516 | 29320 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| ... | ... | @@ -28533,38 +29337,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct |
| 28533 | 29337 | { |
| 28534 | 29338 | ir_add_error(ira, source_instr, |
| 28535 | 29339 | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); |
| 28536 | | return ira->codegen->invalid_instruction; |
| 29340 | return ira->codegen->invalid_inst_gen; |
| 28537 | 29341 | } else { |
| 28538 | 29342 | result_type = frame->value->type->data.any_frame.result_type; |
| 28539 | 29343 | } |
| 28540 | 29344 | } |
| 28541 | 29345 | |
| 28542 | 29346 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type); |
| 28543 | | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 29347 | IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 28544 | 29348 | if (type_is_invalid(casted_frame->value->type)) |
| 28545 | | return ira->codegen->invalid_instruction; |
| 29349 | return ira->codegen->invalid_inst_gen; |
| 28546 | 29350 | |
| 28547 | 29351 | return casted_frame; |
| 28548 | 29352 | } |
| 28549 | 29353 | |
| 28550 | | static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) { |
| 28551 | | IrInstruction *operand = instruction->frame->child; |
| 29354 | static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) { |
| 29355 | IrInstGen *operand = instruction->frame->child; |
| 28552 | 29356 | if (type_is_invalid(operand->value->type)) |
| 28553 | | return ira->codegen->invalid_instruction; |
| 29357 | return ira->codegen->invalid_inst_gen; |
| 28554 | 29358 | ZigFn *target_fn; |
| 28555 | | IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn); |
| 29359 | IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn); |
| 28556 | 29360 | if (type_is_invalid(frame->value->type)) |
| 28557 | | return ira->codegen->invalid_instruction; |
| 29361 | return ira->codegen->invalid_inst_gen; |
| 28558 | 29362 | |
| 28559 | 29363 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 28560 | 29364 | |
| 28561 | | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 28562 | | ir_assert(fn_entry != nullptr, &instruction->base); |
| 29365 | ZigFn *fn_entry = ira->new_irb.exec->fn_entry; |
| 29366 | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 28563 | 29367 | |
| 28564 | 29368 | // If it's not @Frame(func) then it's definitely a suspend point |
| 28565 | 29369 | if (target_fn == nullptr) { |
| 28566 | 29370 | if (fn_entry->inferred_async_node == nullptr) { |
| 28567 | | fn_entry->inferred_async_node = instruction->base.source_node; |
| 29371 | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 28568 | 29372 | } |
| 28569 | 29373 | } |
| 28570 | 29374 | |
| ... | ... | @@ -28572,401 +29376,364 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 28572 | 29376 | fn_entry->calls_or_awaits_errorable_fn = true; |
| 28573 | 29377 | } |
| 28574 | 29378 | |
| 28575 | | IrInstruction *result_loc; |
| 29379 | IrInstGen *result_loc; |
| 28576 | 29380 | if (type_has_bits(result_type)) { |
| 28577 | | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 29381 | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 28578 | 29382 | result_type, nullptr, true, true, true); |
| 28579 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 29383 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| 28580 | 29384 | return result_loc; |
| 28581 | 29385 | } else { |
| 28582 | 29386 | result_loc = nullptr; |
| 28583 | 29387 | } |
| 28584 | 29388 | |
| 28585 | | IrInstructionAwaitGen *result = ir_build_await_gen(ira, &instruction->base, frame, result_type, result_loc); |
| 29389 | IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc); |
| 28586 | 29390 | result->target_fn = target_fn; |
| 28587 | 29391 | fn_entry->await_list.append(result); |
| 28588 | 29392 | return ir_finish_anal(ira, &result->base); |
| 28589 | 29393 | } |
| 28590 | 29394 | |
| 28591 | | static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) { |
| 28592 | | IrInstruction *frame_ptr = instruction->frame->child; |
| 29395 | static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) { |
| 29396 | IrInstGen *frame_ptr = instruction->frame->child; |
| 28593 | 29397 | if (type_is_invalid(frame_ptr->value->type)) |
| 28594 | | return ira->codegen->invalid_instruction; |
| 29398 | return ira->codegen->invalid_inst_gen; |
| 28595 | 29399 | |
| 28596 | | IrInstruction *frame; |
| 29400 | IrInstGen *frame; |
| 28597 | 29401 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 28598 | 29402 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 28599 | 29403 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 28600 | 29404 | { |
| 28601 | 29405 | frame = frame_ptr; |
| 28602 | 29406 | } else { |
| 28603 | | frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr); |
| 29407 | frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr); |
| 28604 | 29408 | } |
| 28605 | 29409 | |
| 28606 | 29410 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 28607 | | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 29411 | IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 28608 | 29412 | if (type_is_invalid(casted_frame->value->type)) |
| 28609 | | return ira->codegen->invalid_instruction; |
| 29413 | return ira->codegen->invalid_inst_gen; |
| 28610 | 29414 | |
| 28611 | | return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame); |
| 29415 | return ir_build_resume_gen(ira, &instruction->base.base, casted_frame); |
| 28612 | 29416 | } |
| 28613 | 29417 | |
| 28614 | | static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) { |
| 28615 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) |
| 28616 | | return ir_const_void(ira, &instruction->base); |
| 29418 | static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) { |
| 29419 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) |
| 29420 | return ir_const_void(ira, &instruction->base.base); |
| 28617 | 29421 | |
| 28618 | | IrInstruction *operand = instruction->operand->child; |
| 29422 | IrInstGen *operand = instruction->operand->child; |
| 28619 | 29423 | if (type_is_invalid(operand->value->type)) |
| 28620 | | return ira->codegen->invalid_instruction; |
| 29424 | return ira->codegen->invalid_inst_gen; |
| 28621 | 29425 | |
| 28622 | 29426 | if (!type_has_bits(operand->value->type)) |
| 28623 | | return ir_const_void(ira, &instruction->base); |
| 29427 | return ir_const_void(ira, &instruction->base.base); |
| 28624 | 29428 | |
| 28625 | | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base); |
| 29429 | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base.base); |
| 28626 | 29430 | ira->new_irb.exec->need_err_code_spill = true; |
| 28627 | 29431 | |
| 28628 | | IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope, |
| 28629 | | instruction->base.source_node, operand, instruction->spill_id); |
| 28630 | | return &result->base; |
| 29432 | return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id); |
| 28631 | 29433 | } |
| 28632 | 29434 | |
| 28633 | | static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) { |
| 28634 | | IrInstruction *operand = instruction->begin->operand->child; |
| 29435 | static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) { |
| 29436 | IrInstGen *operand = instruction->begin->operand->child; |
| 28635 | 29437 | if (type_is_invalid(operand->value->type)) |
| 28636 | | return ira->codegen->invalid_instruction; |
| 29438 | return ira->codegen->invalid_inst_gen; |
| 28637 | 29439 | |
| 28638 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type)) |
| 29440 | if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || !type_has_bits(operand->value->type)) |
| 28639 | 29441 | return operand; |
| 28640 | 29442 | |
| 28641 | | ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base); |
| 28642 | | IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child); |
| 29443 | ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base); |
| 29444 | IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child); |
| 28643 | 29445 | |
| 28644 | | IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope, |
| 28645 | | instruction->base.source_node, begin); |
| 28646 | | result->value->type = operand->value->type; |
| 28647 | | return result; |
| 29446 | return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type); |
| 28648 | 29447 | } |
| 28649 | 29448 | |
| 28650 | | static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) { |
| 29449 | static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) { |
| 28651 | 29450 | switch (instruction->id) { |
| 28652 | | case IrInstructionIdInvalid: |
| 28653 | | case IrInstructionIdWidenOrShorten: |
| 28654 | | case IrInstructionIdStructFieldPtr: |
| 28655 | | case IrInstructionIdUnionFieldPtr: |
| 28656 | | case IrInstructionIdOptionalWrap: |
| 28657 | | case IrInstructionIdErrWrapCode: |
| 28658 | | case IrInstructionIdErrWrapPayload: |
| 28659 | | case IrInstructionIdCast: |
| 28660 | | case IrInstructionIdDeclVarGen: |
| 28661 | | case IrInstructionIdPtrCastGen: |
| 28662 | | case IrInstructionIdCmpxchgGen: |
| 28663 | | case IrInstructionIdArrayToVector: |
| 28664 | | case IrInstructionIdVectorToArray: |
| 28665 | | case IrInstructionIdPtrOfArrayToSlice: |
| 28666 | | case IrInstructionIdAssertZero: |
| 28667 | | case IrInstructionIdAssertNonNull: |
| 28668 | | case IrInstructionIdResizeSlice: |
| 28669 | | case IrInstructionIdLoadPtrGen: |
| 28670 | | case IrInstructionIdBitCastGen: |
| 28671 | | case IrInstructionIdCallGen: |
| 28672 | | case IrInstructionIdReturnPtr: |
| 28673 | | case IrInstructionIdAllocaGen: |
| 28674 | | case IrInstructionIdSliceGen: |
| 28675 | | case IrInstructionIdRefGen: |
| 28676 | | case IrInstructionIdTestErrGen: |
| 28677 | | case IrInstructionIdFrameSizeGen: |
| 28678 | | case IrInstructionIdAwaitGen: |
| 28679 | | case IrInstructionIdSplatGen: |
| 28680 | | case IrInstructionIdVectorExtractElem: |
| 28681 | | case IrInstructionIdVectorStoreElem: |
| 28682 | | case IrInstructionIdAsmGen: |
| 29451 | case IrInstSrcIdInvalid: |
| 28683 | 29452 | zig_unreachable(); |
| 28684 | 29453 | |
| 28685 | | case IrInstructionIdReturn: |
| 28686 | | return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction); |
| 28687 | | case IrInstructionIdConst: |
| 28688 | | return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction); |
| 28689 | | case IrInstructionIdUnOp: |
| 28690 | | return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction); |
| 28691 | | case IrInstructionIdBinOp: |
| 28692 | | return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction); |
| 28693 | | case IrInstructionIdMergeErrSets: |
| 28694 | | return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction); |
| 28695 | | case IrInstructionIdDeclVarSrc: |
| 28696 | | return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction); |
| 28697 | | case IrInstructionIdLoadPtr: |
| 28698 | | return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction); |
| 28699 | | case IrInstructionIdStorePtr: |
| 28700 | | return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction); |
| 28701 | | case IrInstructionIdElemPtr: |
| 28702 | | return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction); |
| 28703 | | case IrInstructionIdVarPtr: |
| 28704 | | return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction); |
| 28705 | | case IrInstructionIdFieldPtr: |
| 28706 | | return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction); |
| 28707 | | case IrInstructionIdCallSrc: |
| 28708 | | return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction); |
| 28709 | | case IrInstructionIdCallSrcArgs: |
| 28710 | | return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction); |
| 28711 | | case IrInstructionIdCallExtra: |
| 28712 | | return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction); |
| 28713 | | case IrInstructionIdBr: |
| 28714 | | return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction); |
| 28715 | | case IrInstructionIdCondBr: |
| 28716 | | return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction); |
| 28717 | | case IrInstructionIdUnreachable: |
| 28718 | | return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction); |
| 28719 | | case IrInstructionIdPhi: |
| 28720 | | return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction); |
| 28721 | | case IrInstructionIdTypeOf: |
| 28722 | | return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction); |
| 28723 | | case IrInstructionIdSetCold: |
| 28724 | | return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction); |
| 28725 | | case IrInstructionIdSetRuntimeSafety: |
| 28726 | | return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction); |
| 28727 | | case IrInstructionIdSetFloatMode: |
| 28728 | | return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction); |
| 28729 | | case IrInstructionIdAnyFrameType: |
| 28730 | | return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction); |
| 28731 | | case IrInstructionIdSliceType: |
| 28732 | | return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction); |
| 28733 | | case IrInstructionIdAsmSrc: |
| 28734 | | return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction); |
| 28735 | | case IrInstructionIdArrayType: |
| 28736 | | return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction); |
| 28737 | | case IrInstructionIdSizeOf: |
| 28738 | | return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction); |
| 28739 | | case IrInstructionIdTestNonNull: |
| 28740 | | return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction); |
| 28741 | | case IrInstructionIdOptionalUnwrapPtr: |
| 28742 | | return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction); |
| 28743 | | case IrInstructionIdClz: |
| 28744 | | return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction); |
| 28745 | | case IrInstructionIdCtz: |
| 28746 | | return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction); |
| 28747 | | case IrInstructionIdPopCount: |
| 28748 | | return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction); |
| 28749 | | case IrInstructionIdBswap: |
| 28750 | | return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction); |
| 28751 | | case IrInstructionIdBitReverse: |
| 28752 | | return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction); |
| 28753 | | case IrInstructionIdSwitchBr: |
| 28754 | | return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction); |
| 28755 | | case IrInstructionIdSwitchTarget: |
| 28756 | | return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction); |
| 28757 | | case IrInstructionIdSwitchVar: |
| 28758 | | return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction); |
| 28759 | | case IrInstructionIdSwitchElseVar: |
| 28760 | | return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction); |
| 28761 | | case IrInstructionIdUnionTag: |
| 28762 | | return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction); |
| 28763 | | case IrInstructionIdImport: |
| 28764 | | return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction); |
| 28765 | | case IrInstructionIdRef: |
| 28766 | | return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction); |
| 28767 | | case IrInstructionIdContainerInitList: |
| 28768 | | return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction); |
| 28769 | | case IrInstructionIdContainerInitFields: |
| 28770 | | return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction); |
| 28771 | | case IrInstructionIdCompileErr: |
| 28772 | | return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction); |
| 28773 | | case IrInstructionIdCompileLog: |
| 28774 | | return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction); |
| 28775 | | case IrInstructionIdErrName: |
| 28776 | | return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction); |
| 28777 | | case IrInstructionIdTypeName: |
| 28778 | | return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction); |
| 28779 | | case IrInstructionIdCImport: |
| 28780 | | return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction); |
| 28781 | | case IrInstructionIdCInclude: |
| 28782 | | return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction); |
| 28783 | | case IrInstructionIdCDefine: |
| 28784 | | return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction); |
| 28785 | | case IrInstructionIdCUndef: |
| 28786 | | return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction); |
| 28787 | | case IrInstructionIdEmbedFile: |
| 28788 | | return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction); |
| 28789 | | case IrInstructionIdCmpxchgSrc: |
| 28790 | | return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction); |
| 28791 | | case IrInstructionIdFence: |
| 28792 | | return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction); |
| 28793 | | case IrInstructionIdTruncate: |
| 28794 | | return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction); |
| 28795 | | case IrInstructionIdIntCast: |
| 28796 | | return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction); |
| 28797 | | case IrInstructionIdFloatCast: |
| 28798 | | return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction); |
| 28799 | | case IrInstructionIdErrSetCast: |
| 28800 | | return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction); |
| 28801 | | case IrInstructionIdFromBytes: |
| 28802 | | return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction); |
| 28803 | | case IrInstructionIdToBytes: |
| 28804 | | return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction); |
| 28805 | | case IrInstructionIdIntToFloat: |
| 28806 | | return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction); |
| 28807 | | case IrInstructionIdFloatToInt: |
| 28808 | | return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction); |
| 28809 | | case IrInstructionIdBoolToInt: |
| 28810 | | return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction); |
| 28811 | | case IrInstructionIdIntType: |
| 28812 | | return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction); |
| 28813 | | case IrInstructionIdVectorType: |
| 28814 | | return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction); |
| 28815 | | case IrInstructionIdShuffleVector: |
| 28816 | | return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction); |
| 28817 | | case IrInstructionIdSplatSrc: |
| 28818 | | return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction); |
| 28819 | | case IrInstructionIdBoolNot: |
| 28820 | | return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction); |
| 28821 | | case IrInstructionIdMemset: |
| 28822 | | return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction); |
| 28823 | | case IrInstructionIdMemcpy: |
| 28824 | | return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction); |
| 28825 | | case IrInstructionIdSliceSrc: |
| 28826 | | return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction); |
| 28827 | | case IrInstructionIdMemberCount: |
| 28828 | | return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction); |
| 28829 | | case IrInstructionIdMemberType: |
| 28830 | | return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction); |
| 28831 | | case IrInstructionIdMemberName: |
| 28832 | | return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction); |
| 28833 | | case IrInstructionIdBreakpoint: |
| 28834 | | return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction); |
| 28835 | | case IrInstructionIdReturnAddress: |
| 28836 | | return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction); |
| 28837 | | case IrInstructionIdFrameAddress: |
| 28838 | | return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction); |
| 28839 | | case IrInstructionIdFrameHandle: |
| 28840 | | return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction); |
| 28841 | | case IrInstructionIdFrameType: |
| 28842 | | return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction); |
| 28843 | | case IrInstructionIdFrameSizeSrc: |
| 28844 | | return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction); |
| 28845 | | case IrInstructionIdAlignOf: |
| 28846 | | return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction); |
| 28847 | | case IrInstructionIdOverflowOp: |
| 28848 | | return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction); |
| 28849 | | case IrInstructionIdTestErrSrc: |
| 28850 | | return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction); |
| 28851 | | case IrInstructionIdUnwrapErrCode: |
| 28852 | | return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction); |
| 28853 | | case IrInstructionIdUnwrapErrPayload: |
| 28854 | | return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction); |
| 28855 | | case IrInstructionIdFnProto: |
| 28856 | | return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction); |
| 28857 | | case IrInstructionIdTestComptime: |
| 28858 | | return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction); |
| 28859 | | case IrInstructionIdCheckSwitchProngs: |
| 28860 | | return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction); |
| 28861 | | case IrInstructionIdCheckStatementIsVoid: |
| 28862 | | return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction); |
| 28863 | | case IrInstructionIdDeclRef: |
| 28864 | | return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction); |
| 28865 | | case IrInstructionIdPanic: |
| 28866 | | return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction); |
| 28867 | | case IrInstructionIdPtrCastSrc: |
| 28868 | | return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction); |
| 28869 | | case IrInstructionIdIntToPtr: |
| 28870 | | return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction); |
| 28871 | | case IrInstructionIdPtrToInt: |
| 28872 | | return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction); |
| 28873 | | case IrInstructionIdTagName: |
| 28874 | | return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction); |
| 28875 | | case IrInstructionIdFieldParentPtr: |
| 28876 | | return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction); |
| 28877 | | case IrInstructionIdByteOffsetOf: |
| 28878 | | return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction); |
| 28879 | | case IrInstructionIdBitOffsetOf: |
| 28880 | | return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction); |
| 28881 | | case IrInstructionIdTypeInfo: |
| 28882 | | return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction); |
| 28883 | | case IrInstructionIdType: |
| 28884 | | return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction); |
| 28885 | | case IrInstructionIdHasField: |
| 28886 | | return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction); |
| 28887 | | case IrInstructionIdTypeId: |
| 28888 | | return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction); |
| 28889 | | case IrInstructionIdSetEvalBranchQuota: |
| 28890 | | return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction); |
| 28891 | | case IrInstructionIdPtrType: |
| 28892 | | return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction); |
| 28893 | | case IrInstructionIdAlignCast: |
| 28894 | | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); |
| 28895 | | case IrInstructionIdImplicitCast: |
| 28896 | | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| 28897 | | case IrInstructionIdResolveResult: |
| 28898 | | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); |
| 28899 | | case IrInstructionIdResetResult: |
| 28900 | | return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction); |
| 28901 | | case IrInstructionIdOpaqueType: |
| 28902 | | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 28903 | | case IrInstructionIdSetAlignStack: |
| 28904 | | return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction); |
| 28905 | | case IrInstructionIdArgType: |
| 28906 | | return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction); |
| 28907 | | case IrInstructionIdTagType: |
| 28908 | | return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction); |
| 28909 | | case IrInstructionIdExport: |
| 28910 | | return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction); |
| 28911 | | case IrInstructionIdErrorReturnTrace: |
| 28912 | | return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction); |
| 28913 | | case IrInstructionIdErrorUnion: |
| 28914 | | return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction); |
| 28915 | | case IrInstructionIdAtomicRmw: |
| 28916 | | return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction); |
| 28917 | | case IrInstructionIdAtomicLoad: |
| 28918 | | return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction); |
| 28919 | | case IrInstructionIdAtomicStore: |
| 28920 | | return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction); |
| 28921 | | case IrInstructionIdSaveErrRetAddr: |
| 28922 | | return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction); |
| 28923 | | case IrInstructionIdAddImplicitReturnType: |
| 28924 | | return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction); |
| 28925 | | case IrInstructionIdFloatOp: |
| 28926 | | return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction); |
| 28927 | | case IrInstructionIdMulAdd: |
| 28928 | | return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction); |
| 28929 | | case IrInstructionIdIntToErr: |
| 28930 | | return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction); |
| 28931 | | case IrInstructionIdErrToInt: |
| 28932 | | return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction); |
| 28933 | | case IrInstructionIdIntToEnum: |
| 28934 | | return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction); |
| 28935 | | case IrInstructionIdEnumToInt: |
| 28936 | | return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction); |
| 28937 | | case IrInstructionIdCheckRuntimeScope: |
| 28938 | | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); |
| 28939 | | case IrInstructionIdHasDecl: |
| 28940 | | return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction); |
| 28941 | | case IrInstructionIdUndeclaredIdent: |
| 28942 | | return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction); |
| 28943 | | case IrInstructionIdAllocaSrc: |
| 29454 | case IrInstSrcIdReturn: |
| 29455 | return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction); |
| 29456 | case IrInstSrcIdConst: |
| 29457 | return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction); |
| 29458 | case IrInstSrcIdUnOp: |
| 29459 | return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction); |
| 29460 | case IrInstSrcIdBinOp: |
| 29461 | return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction); |
| 29462 | case IrInstSrcIdMergeErrSets: |
| 29463 | return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction); |
| 29464 | case IrInstSrcIdDeclVar: |
| 29465 | return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction); |
| 29466 | case IrInstSrcIdLoadPtr: |
| 29467 | return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction); |
| 29468 | case IrInstSrcIdStorePtr: |
| 29469 | return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction); |
| 29470 | case IrInstSrcIdElemPtr: |
| 29471 | return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction); |
| 29472 | case IrInstSrcIdVarPtr: |
| 29473 | return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction); |
| 29474 | case IrInstSrcIdFieldPtr: |
| 29475 | return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction); |
| 29476 | case IrInstSrcIdCall: |
| 29477 | return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction); |
| 29478 | case IrInstSrcIdCallArgs: |
| 29479 | return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction); |
| 29480 | case IrInstSrcIdCallExtra: |
| 29481 | return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction); |
| 29482 | case IrInstSrcIdBr: |
| 29483 | return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction); |
| 29484 | case IrInstSrcIdCondBr: |
| 29485 | return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction); |
| 29486 | case IrInstSrcIdUnreachable: |
| 29487 | return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction); |
| 29488 | case IrInstSrcIdPhi: |
| 29489 | return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction); |
| 29490 | case IrInstSrcIdTypeOf: |
| 29491 | return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction); |
| 29492 | case IrInstSrcIdSetCold: |
| 29493 | return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction); |
| 29494 | case IrInstSrcIdSetRuntimeSafety: |
| 29495 | return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction); |
| 29496 | case IrInstSrcIdSetFloatMode: |
| 29497 | return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction); |
| 29498 | case IrInstSrcIdAnyFrameType: |
| 29499 | return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction); |
| 29500 | case IrInstSrcIdSliceType: |
| 29501 | return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction); |
| 29502 | case IrInstSrcIdAsm: |
| 29503 | return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction); |
| 29504 | case IrInstSrcIdArrayType: |
| 29505 | return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction); |
| 29506 | case IrInstSrcIdSizeOf: |
| 29507 | return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction); |
| 29508 | case IrInstSrcIdTestNonNull: |
| 29509 | return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction); |
| 29510 | case IrInstSrcIdOptionalUnwrapPtr: |
| 29511 | return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction); |
| 29512 | case IrInstSrcIdClz: |
| 29513 | return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction); |
| 29514 | case IrInstSrcIdCtz: |
| 29515 | return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction); |
| 29516 | case IrInstSrcIdPopCount: |
| 29517 | return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction); |
| 29518 | case IrInstSrcIdBswap: |
| 29519 | return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction); |
| 29520 | case IrInstSrcIdBitReverse: |
| 29521 | return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction); |
| 29522 | case IrInstSrcIdSwitchBr: |
| 29523 | return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction); |
| 29524 | case IrInstSrcIdSwitchTarget: |
| 29525 | return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction); |
| 29526 | case IrInstSrcIdSwitchVar: |
| 29527 | return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction); |
| 29528 | case IrInstSrcIdSwitchElseVar: |
| 29529 | return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction); |
| 29530 | case IrInstSrcIdImport: |
| 29531 | return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction); |
| 29532 | case IrInstSrcIdRef: |
| 29533 | return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction); |
| 29534 | case IrInstSrcIdContainerInitList: |
| 29535 | return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction); |
| 29536 | case IrInstSrcIdContainerInitFields: |
| 29537 | return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction); |
| 29538 | case IrInstSrcIdCompileErr: |
| 29539 | return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction); |
| 29540 | case IrInstSrcIdCompileLog: |
| 29541 | return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction); |
| 29542 | case IrInstSrcIdErrName: |
| 29543 | return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction); |
| 29544 | case IrInstSrcIdTypeName: |
| 29545 | return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction); |
| 29546 | case IrInstSrcIdCImport: |
| 29547 | return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction); |
| 29548 | case IrInstSrcIdCInclude: |
| 29549 | return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction); |
| 29550 | case IrInstSrcIdCDefine: |
| 29551 | return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction); |
| 29552 | case IrInstSrcIdCUndef: |
| 29553 | return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction); |
| 29554 | case IrInstSrcIdEmbedFile: |
| 29555 | return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction); |
| 29556 | case IrInstSrcIdCmpxchg: |
| 29557 | return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction); |
| 29558 | case IrInstSrcIdFence: |
| 29559 | return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction); |
| 29560 | case IrInstSrcIdTruncate: |
| 29561 | return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction); |
| 29562 | case IrInstSrcIdIntCast: |
| 29563 | return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction); |
| 29564 | case IrInstSrcIdFloatCast: |
| 29565 | return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction); |
| 29566 | case IrInstSrcIdErrSetCast: |
| 29567 | return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction); |
| 29568 | case IrInstSrcIdFromBytes: |
| 29569 | return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction); |
| 29570 | case IrInstSrcIdToBytes: |
| 29571 | return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction); |
| 29572 | case IrInstSrcIdIntToFloat: |
| 29573 | return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction); |
| 29574 | case IrInstSrcIdFloatToInt: |
| 29575 | return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction); |
| 29576 | case IrInstSrcIdBoolToInt: |
| 29577 | return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction); |
| 29578 | case IrInstSrcIdIntType: |
| 29579 | return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction); |
| 29580 | case IrInstSrcIdVectorType: |
| 29581 | return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction); |
| 29582 | case IrInstSrcIdShuffleVector: |
| 29583 | return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction); |
| 29584 | case IrInstSrcIdSplat: |
| 29585 | return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction); |
| 29586 | case IrInstSrcIdBoolNot: |
| 29587 | return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction); |
| 29588 | case IrInstSrcIdMemset: |
| 29589 | return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction); |
| 29590 | case IrInstSrcIdMemcpy: |
| 29591 | return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction); |
| 29592 | case IrInstSrcIdSlice: |
| 29593 | return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction); |
| 29594 | case IrInstSrcIdMemberCount: |
| 29595 | return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction); |
| 29596 | case IrInstSrcIdMemberType: |
| 29597 | return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction); |
| 29598 | case IrInstSrcIdMemberName: |
| 29599 | return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction); |
| 29600 | case IrInstSrcIdBreakpoint: |
| 29601 | return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction); |
| 29602 | case IrInstSrcIdReturnAddress: |
| 29603 | return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction); |
| 29604 | case IrInstSrcIdFrameAddress: |
| 29605 | return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction); |
| 29606 | case IrInstSrcIdFrameHandle: |
| 29607 | return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction); |
| 29608 | case IrInstSrcIdFrameType: |
| 29609 | return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction); |
| 29610 | case IrInstSrcIdFrameSize: |
| 29611 | return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction); |
| 29612 | case IrInstSrcIdAlignOf: |
| 29613 | return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction); |
| 29614 | case IrInstSrcIdOverflowOp: |
| 29615 | return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction); |
| 29616 | case IrInstSrcIdTestErr: |
| 29617 | return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction); |
| 29618 | case IrInstSrcIdUnwrapErrCode: |
| 29619 | return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction); |
| 29620 | case IrInstSrcIdUnwrapErrPayload: |
| 29621 | return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction); |
| 29622 | case IrInstSrcIdFnProto: |
| 29623 | return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction); |
| 29624 | case IrInstSrcIdTestComptime: |
| 29625 | return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction); |
| 29626 | case IrInstSrcIdCheckSwitchProngs: |
| 29627 | return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction); |
| 29628 | case IrInstSrcIdCheckStatementIsVoid: |
| 29629 | return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction); |
| 29630 | case IrInstSrcIdDeclRef: |
| 29631 | return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction); |
| 29632 | case IrInstSrcIdPanic: |
| 29633 | return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction); |
| 29634 | case IrInstSrcIdPtrCast: |
| 29635 | return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction); |
| 29636 | case IrInstSrcIdIntToPtr: |
| 29637 | return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction); |
| 29638 | case IrInstSrcIdPtrToInt: |
| 29639 | return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction); |
| 29640 | case IrInstSrcIdTagName: |
| 29641 | return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction); |
| 29642 | case IrInstSrcIdFieldParentPtr: |
| 29643 | return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction); |
| 29644 | case IrInstSrcIdByteOffsetOf: |
| 29645 | return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction); |
| 29646 | case IrInstSrcIdBitOffsetOf: |
| 29647 | return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction); |
| 29648 | case IrInstSrcIdTypeInfo: |
| 29649 | return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction); |
| 29650 | case IrInstSrcIdType: |
| 29651 | return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction); |
| 29652 | case IrInstSrcIdHasField: |
| 29653 | return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction); |
| 29654 | case IrInstSrcIdTypeId: |
| 29655 | return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction); |
| 29656 | case IrInstSrcIdSetEvalBranchQuota: |
| 29657 | return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction); |
| 29658 | case IrInstSrcIdPtrType: |
| 29659 | return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction); |
| 29660 | case IrInstSrcIdAlignCast: |
| 29661 | return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction); |
| 29662 | case IrInstSrcIdImplicitCast: |
| 29663 | return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction); |
| 29664 | case IrInstSrcIdResolveResult: |
| 29665 | return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction); |
| 29666 | case IrInstSrcIdResetResult: |
| 29667 | return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction); |
| 29668 | case IrInstSrcIdOpaqueType: |
| 29669 | return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction); |
| 29670 | case IrInstSrcIdSetAlignStack: |
| 29671 | return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction); |
| 29672 | case IrInstSrcIdArgType: |
| 29673 | return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction); |
| 29674 | case IrInstSrcIdTagType: |
| 29675 | return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction); |
| 29676 | case IrInstSrcIdExport: |
| 29677 | return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction); |
| 29678 | case IrInstSrcIdErrorReturnTrace: |
| 29679 | return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction); |
| 29680 | case IrInstSrcIdErrorUnion: |
| 29681 | return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction); |
| 29682 | case IrInstSrcIdAtomicRmw: |
| 29683 | return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction); |
| 29684 | case IrInstSrcIdAtomicLoad: |
| 29685 | return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction); |
| 29686 | case IrInstSrcIdAtomicStore: |
| 29687 | return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction); |
| 29688 | case IrInstSrcIdSaveErrRetAddr: |
| 29689 | return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction); |
| 29690 | case IrInstSrcIdAddImplicitReturnType: |
| 29691 | return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction); |
| 29692 | case IrInstSrcIdFloatOp: |
| 29693 | return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction); |
| 29694 | case IrInstSrcIdMulAdd: |
| 29695 | return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction); |
| 29696 | case IrInstSrcIdIntToErr: |
| 29697 | return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction); |
| 29698 | case IrInstSrcIdErrToInt: |
| 29699 | return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction); |
| 29700 | case IrInstSrcIdIntToEnum: |
| 29701 | return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction); |
| 29702 | case IrInstSrcIdEnumToInt: |
| 29703 | return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction); |
| 29704 | case IrInstSrcIdCheckRuntimeScope: |
| 29705 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction); |
| 29706 | case IrInstSrcIdHasDecl: |
| 29707 | return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction); |
| 29708 | case IrInstSrcIdUndeclaredIdent: |
| 29709 | return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction); |
| 29710 | case IrInstSrcIdAlloca: |
| 28944 | 29711 | return nullptr; |
| 28945 | | case IrInstructionIdEndExpr: |
| 28946 | | return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction); |
| 28947 | | case IrInstructionIdBitCastSrc: |
| 28948 | | return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction); |
| 28949 | | case IrInstructionIdUnionInitNamedField: |
| 28950 | | return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction); |
| 28951 | | case IrInstructionIdSuspendBegin: |
| 28952 | | return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction); |
| 28953 | | case IrInstructionIdSuspendFinish: |
| 28954 | | return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction); |
| 28955 | | case IrInstructionIdResume: |
| 28956 | | return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction); |
| 28957 | | case IrInstructionIdAwaitSrc: |
| 28958 | | return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction); |
| 28959 | | case IrInstructionIdSpillBegin: |
| 28960 | | return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction); |
| 28961 | | case IrInstructionIdSpillEnd: |
| 28962 | | return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction); |
| 29712 | case IrInstSrcIdEndExpr: |
| 29713 | return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction); |
| 29714 | case IrInstSrcIdBitCast: |
| 29715 | return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction); |
| 29716 | case IrInstSrcIdUnionInitNamedField: |
| 29717 | return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction); |
| 29718 | case IrInstSrcIdSuspendBegin: |
| 29719 | return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction); |
| 29720 | case IrInstSrcIdSuspendFinish: |
| 29721 | return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction); |
| 29722 | case IrInstSrcIdResume: |
| 29723 | return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction); |
| 29724 | case IrInstSrcIdAwait: |
| 29725 | return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction); |
| 29726 | case IrInstSrcIdSpillBegin: |
| 29727 | return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction); |
| 29728 | case IrInstSrcIdSpillEnd: |
| 29729 | return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction); |
| 28963 | 29730 | } |
| 28964 | 29731 | zig_unreachable(); |
| 28965 | 29732 | } |
| 28966 | 29733 | |
| 28967 | 29734 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| 28968 | | // It emits a new IrExecutable which is partially evaluated IR code. |
| 28969 | | ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, |
| 29735 | // It emits to a new IrExecutableGen which is partially evaluated IR code. |
| 29736 | ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec, |
| 28970 | 29737 | ZigType *expected_type, AstNode *expected_type_source_node) |
| 28971 | 29738 | { |
| 28972 | 29739 | assert(old_exec->first_err_trace_msg == nullptr); |
| ... | ... | @@ -28992,18 +29759,18 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 28992 | 29759 | ira->exec_context.mem_slot_list.items[i] = &vals[i]; |
| 28993 | 29760 | } |
| 28994 | 29761 | |
| 28995 | | IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 28996 | | IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 28997 | | ir_ref_bb(new_entry_bb); |
| 29762 | IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0); |
| 29763 | IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr); |
| 29764 | ir_ref_bb_gen(new_entry_bb); |
| 28998 | 29765 | ira->new_irb.current_basic_block = new_entry_bb; |
| 28999 | 29766 | ira->old_bb_index = 0; |
| 29000 | 29767 | |
| 29001 | 29768 | ir_start_bb(ira, old_entry_bb, nullptr); |
| 29002 | 29769 | |
| 29003 | 29770 | while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) { |
| 29004 | | IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 29771 | IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 29005 | 29772 | |
| 29006 | | if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) { |
| 29773 | if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { |
| 29007 | 29774 | ira->instruction_index += 1; |
| 29008 | 29775 | continue; |
| 29009 | 29776 | } |
| ... | ... | @@ -29012,14 +29779,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29012 | 29779 | fprintf(stderr, "~ "); |
| 29013 | 29780 | old_instruction->src(); |
| 29014 | 29781 | fprintf(stderr, "~ "); |
| 29015 | | ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc); |
| 29782 | ir_print_inst_src(codegen, stderr, old_instruction, 0); |
| 29016 | 29783 | bool want_break = false; |
| 29017 | | if (ira->break_debug_id == old_instruction->debug_id) { |
| 29784 | if (ira->break_debug_id == old_instruction->base.debug_id) { |
| 29018 | 29785 | want_break = true; |
| 29019 | | } else if (old_instruction->source_node != nullptr) { |
| 29786 | } else if (old_instruction->base.source_node != nullptr) { |
| 29020 | 29787 | for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) { |
| 29021 | | if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 && |
| 29022 | | buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path, |
| 29788 | if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 && |
| 29789 | buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path, |
| 29023 | 29790 | dbg_ir_breakpoints_buf[i].src_file)) |
| 29024 | 29791 | { |
| 29025 | 29792 | want_break = true; |
| ... | ... | @@ -29028,9 +29795,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29028 | 29795 | } |
| 29029 | 29796 | if (want_break) BREAKPOINT; |
| 29030 | 29797 | } |
| 29031 | | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 29798 | IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 29032 | 29799 | if (new_instruction != nullptr) { |
| 29033 | | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction); |
| 29800 | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base); |
| 29034 | 29801 | old_instruction->child = new_instruction; |
| 29035 | 29802 | |
| 29036 | 29803 | if (type_is_invalid(new_instruction->value->type)) { |
| ... | ... | @@ -29044,19 +29811,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29044 | 29811 | new_exec->first_err_trace_msg = ira->codegen->trace_err; |
| 29045 | 29812 | } |
| 29046 | 29813 | if (new_exec->first_err_trace_msg != nullptr && |
| 29047 | | !old_instruction->source_node->already_traced_this_node) |
| 29814 | !old_instruction->base.source_node->already_traced_this_node) |
| 29048 | 29815 | { |
| 29049 | | old_instruction->source_node->already_traced_this_node = true; |
| 29816 | old_instruction->base.source_node->already_traced_this_node = true; |
| 29050 | 29817 | new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg, |
| 29051 | | old_instruction->source_node, buf_create_from_str("referenced here")); |
| 29818 | old_instruction->base.source_node, buf_create_from_str("referenced here")); |
| 29052 | 29819 | } |
| 29053 | 29820 | return ira->codegen->builtin_types.entry_invalid; |
| 29054 | 29821 | } else if (ira->codegen->verbose_ir) { |
| 29055 | 29822 | fprintf(stderr, "-> "); |
| 29056 | | if (instr_is_unreachable(new_instruction)) { |
| 29823 | if (new_instruction->value->type->id == ZigTypeIdUnreachable) { |
| 29057 | 29824 | fprintf(stderr, "(noreturn)\n"); |
| 29058 | 29825 | } else { |
| 29059 | | ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen); |
| 29826 | ir_print_inst_gen(codegen, stderr, new_instruction, 0); |
| 29060 | 29827 | } |
| 29061 | 29828 | } |
| 29062 | 29829 | |
| ... | ... | @@ -29096,204 +29863,279 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 29096 | 29863 | return res_type; |
| 29097 | 29864 | } |
| 29098 | 29865 | |
| 29099 | | bool ir_has_side_effects(IrInstruction *instruction) { |
| 29866 | bool ir_inst_gen_has_side_effects(IrInstGen *instruction) { |
| 29100 | 29867 | switch (instruction->id) { |
| 29101 | | case IrInstructionIdInvalid: |
| 29868 | case IrInstGenIdInvalid: |
| 29102 | 29869 | zig_unreachable(); |
| 29103 | | case IrInstructionIdBr: |
| 29104 | | case IrInstructionIdCondBr: |
| 29105 | | case IrInstructionIdSwitchBr: |
| 29106 | | case IrInstructionIdDeclVarSrc: |
| 29107 | | case IrInstructionIdDeclVarGen: |
| 29108 | | case IrInstructionIdStorePtr: |
| 29109 | | case IrInstructionIdVectorStoreElem: |
| 29110 | | case IrInstructionIdCallExtra: |
| 29111 | | case IrInstructionIdCallSrc: |
| 29112 | | case IrInstructionIdCallSrcArgs: |
| 29113 | | case IrInstructionIdCallGen: |
| 29114 | | case IrInstructionIdReturn: |
| 29115 | | case IrInstructionIdUnreachable: |
| 29116 | | case IrInstructionIdSetCold: |
| 29117 | | case IrInstructionIdSetRuntimeSafety: |
| 29118 | | case IrInstructionIdSetFloatMode: |
| 29119 | | case IrInstructionIdImport: |
| 29120 | | case IrInstructionIdCompileErr: |
| 29121 | | case IrInstructionIdCompileLog: |
| 29122 | | case IrInstructionIdCImport: |
| 29123 | | case IrInstructionIdCInclude: |
| 29124 | | case IrInstructionIdCDefine: |
| 29125 | | case IrInstructionIdCUndef: |
| 29126 | | case IrInstructionIdFence: |
| 29127 | | case IrInstructionIdMemset: |
| 29128 | | case IrInstructionIdMemcpy: |
| 29129 | | case IrInstructionIdBreakpoint: |
| 29130 | | case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 29131 | | case IrInstructionIdCheckSwitchProngs: |
| 29132 | | case IrInstructionIdCheckStatementIsVoid: |
| 29133 | | case IrInstructionIdCheckRuntimeScope: |
| 29134 | | case IrInstructionIdPanic: |
| 29135 | | case IrInstructionIdSetEvalBranchQuota: |
| 29136 | | case IrInstructionIdPtrType: |
| 29137 | | case IrInstructionIdSetAlignStack: |
| 29138 | | case IrInstructionIdExport: |
| 29139 | | case IrInstructionIdSaveErrRetAddr: |
| 29140 | | case IrInstructionIdAddImplicitReturnType: |
| 29141 | | case IrInstructionIdAtomicRmw: |
| 29142 | | case IrInstructionIdAtomicStore: |
| 29143 | | case IrInstructionIdCmpxchgGen: |
| 29144 | | case IrInstructionIdCmpxchgSrc: |
| 29145 | | case IrInstructionIdAssertZero: |
| 29146 | | case IrInstructionIdAssertNonNull: |
| 29147 | | case IrInstructionIdResizeSlice: |
| 29148 | | case IrInstructionIdUndeclaredIdent: |
| 29149 | | case IrInstructionIdEndExpr: |
| 29150 | | case IrInstructionIdPtrOfArrayToSlice: |
| 29151 | | case IrInstructionIdSliceGen: |
| 29152 | | case IrInstructionIdOptionalWrap: |
| 29153 | | case IrInstructionIdVectorToArray: |
| 29154 | | case IrInstructionIdResetResult: |
| 29155 | | case IrInstructionIdSuspendBegin: |
| 29156 | | case IrInstructionIdSuspendFinish: |
| 29157 | | case IrInstructionIdResume: |
| 29158 | | case IrInstructionIdAwaitSrc: |
| 29159 | | case IrInstructionIdAwaitGen: |
| 29160 | | case IrInstructionIdSpillBegin: |
| 29870 | case IrInstGenIdBr: |
| 29871 | case IrInstGenIdCondBr: |
| 29872 | case IrInstGenIdSwitchBr: |
| 29873 | case IrInstGenIdDeclVar: |
| 29874 | case IrInstGenIdStorePtr: |
| 29875 | case IrInstGenIdVectorStoreElem: |
| 29876 | case IrInstGenIdCall: |
| 29877 | case IrInstGenIdReturn: |
| 29878 | case IrInstGenIdUnreachable: |
| 29879 | case IrInstGenIdFence: |
| 29880 | case IrInstGenIdMemset: |
| 29881 | case IrInstGenIdMemcpy: |
| 29882 | case IrInstGenIdBreakpoint: |
| 29883 | case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 29884 | case IrInstGenIdPanic: |
| 29885 | case IrInstGenIdSaveErrRetAddr: |
| 29886 | case IrInstGenIdAtomicRmw: |
| 29887 | case IrInstGenIdAtomicStore: |
| 29888 | case IrInstGenIdCmpxchg: |
| 29889 | case IrInstGenIdAssertZero: |
| 29890 | case IrInstGenIdAssertNonNull: |
| 29891 | case IrInstGenIdResizeSlice: |
| 29892 | case IrInstGenIdPtrOfArrayToSlice: |
| 29893 | case IrInstGenIdSlice: |
| 29894 | case IrInstGenIdOptionalWrap: |
| 29895 | case IrInstGenIdVectorToArray: |
| 29896 | case IrInstGenIdSuspendBegin: |
| 29897 | case IrInstGenIdSuspendFinish: |
| 29898 | case IrInstGenIdResume: |
| 29899 | case IrInstGenIdAwait: |
| 29900 | case IrInstGenIdSpillBegin: |
| 29161 | 29901 | return true; |
| 29162 | 29902 | |
| 29163 | | case IrInstructionIdPhi: |
| 29164 | | case IrInstructionIdUnOp: |
| 29165 | | case IrInstructionIdBinOp: |
| 29166 | | case IrInstructionIdMergeErrSets: |
| 29167 | | case IrInstructionIdLoadPtr: |
| 29168 | | case IrInstructionIdConst: |
| 29169 | | case IrInstructionIdCast: |
| 29170 | | case IrInstructionIdContainerInitList: |
| 29171 | | case IrInstructionIdContainerInitFields: |
| 29172 | | case IrInstructionIdUnionInitNamedField: |
| 29173 | | case IrInstructionIdFieldPtr: |
| 29174 | | case IrInstructionIdElemPtr: |
| 29175 | | case IrInstructionIdVarPtr: |
| 29176 | | case IrInstructionIdReturnPtr: |
| 29177 | | case IrInstructionIdTypeOf: |
| 29178 | | case IrInstructionIdStructFieldPtr: |
| 29179 | | case IrInstructionIdArrayType: |
| 29180 | | case IrInstructionIdSliceType: |
| 29181 | | case IrInstructionIdAnyFrameType: |
| 29182 | | case IrInstructionIdSizeOf: |
| 29183 | | case IrInstructionIdTestNonNull: |
| 29184 | | case IrInstructionIdOptionalUnwrapPtr: |
| 29185 | | case IrInstructionIdClz: |
| 29186 | | case IrInstructionIdCtz: |
| 29187 | | case IrInstructionIdPopCount: |
| 29188 | | case IrInstructionIdBswap: |
| 29189 | | case IrInstructionIdBitReverse: |
| 29190 | | case IrInstructionIdSwitchVar: |
| 29191 | | case IrInstructionIdSwitchElseVar: |
| 29192 | | case IrInstructionIdSwitchTarget: |
| 29193 | | case IrInstructionIdUnionTag: |
| 29194 | | case IrInstructionIdRef: |
| 29195 | | case IrInstructionIdEmbedFile: |
| 29196 | | case IrInstructionIdTruncate: |
| 29197 | | case IrInstructionIdIntType: |
| 29198 | | case IrInstructionIdVectorType: |
| 29199 | | case IrInstructionIdShuffleVector: |
| 29200 | | case IrInstructionIdSplatSrc: |
| 29201 | | case IrInstructionIdSplatGen: |
| 29202 | | case IrInstructionIdBoolNot: |
| 29203 | | case IrInstructionIdSliceSrc: |
| 29204 | | case IrInstructionIdMemberCount: |
| 29205 | | case IrInstructionIdMemberType: |
| 29206 | | case IrInstructionIdMemberName: |
| 29207 | | case IrInstructionIdAlignOf: |
| 29208 | | case IrInstructionIdReturnAddress: |
| 29209 | | case IrInstructionIdFrameAddress: |
| 29210 | | case IrInstructionIdFrameHandle: |
| 29211 | | case IrInstructionIdFrameType: |
| 29212 | | case IrInstructionIdFrameSizeSrc: |
| 29213 | | case IrInstructionIdFrameSizeGen: |
| 29214 | | case IrInstructionIdTestErrSrc: |
| 29215 | | case IrInstructionIdTestErrGen: |
| 29216 | | case IrInstructionIdFnProto: |
| 29217 | | case IrInstructionIdTestComptime: |
| 29218 | | case IrInstructionIdPtrCastSrc: |
| 29219 | | case IrInstructionIdPtrCastGen: |
| 29220 | | case IrInstructionIdBitCastSrc: |
| 29221 | | case IrInstructionIdBitCastGen: |
| 29222 | | case IrInstructionIdWidenOrShorten: |
| 29223 | | case IrInstructionIdPtrToInt: |
| 29224 | | case IrInstructionIdIntToPtr: |
| 29225 | | case IrInstructionIdIntToEnum: |
| 29226 | | case IrInstructionIdIntToErr: |
| 29227 | | case IrInstructionIdErrToInt: |
| 29228 | | case IrInstructionIdDeclRef: |
| 29229 | | case IrInstructionIdErrName: |
| 29230 | | case IrInstructionIdTypeName: |
| 29231 | | case IrInstructionIdTagName: |
| 29232 | | case IrInstructionIdFieldParentPtr: |
| 29233 | | case IrInstructionIdByteOffsetOf: |
| 29234 | | case IrInstructionIdBitOffsetOf: |
| 29235 | | case IrInstructionIdTypeInfo: |
| 29236 | | case IrInstructionIdType: |
| 29237 | | case IrInstructionIdHasField: |
| 29238 | | case IrInstructionIdTypeId: |
| 29239 | | case IrInstructionIdAlignCast: |
| 29240 | | case IrInstructionIdImplicitCast: |
| 29241 | | case IrInstructionIdResolveResult: |
| 29242 | | case IrInstructionIdOpaqueType: |
| 29243 | | case IrInstructionIdArgType: |
| 29244 | | case IrInstructionIdTagType: |
| 29245 | | case IrInstructionIdErrorReturnTrace: |
| 29246 | | case IrInstructionIdErrorUnion: |
| 29247 | | case IrInstructionIdFloatOp: |
| 29248 | | case IrInstructionIdMulAdd: |
| 29249 | | case IrInstructionIdAtomicLoad: |
| 29250 | | case IrInstructionIdIntCast: |
| 29251 | | case IrInstructionIdFloatCast: |
| 29252 | | case IrInstructionIdErrSetCast: |
| 29253 | | case IrInstructionIdIntToFloat: |
| 29254 | | case IrInstructionIdFloatToInt: |
| 29255 | | case IrInstructionIdBoolToInt: |
| 29256 | | case IrInstructionIdFromBytes: |
| 29257 | | case IrInstructionIdToBytes: |
| 29258 | | case IrInstructionIdEnumToInt: |
| 29259 | | case IrInstructionIdArrayToVector: |
| 29260 | | case IrInstructionIdHasDecl: |
| 29261 | | case IrInstructionIdAllocaSrc: |
| 29262 | | case IrInstructionIdAllocaGen: |
| 29263 | | case IrInstructionIdSpillEnd: |
| 29264 | | case IrInstructionIdVectorExtractElem: |
| 29903 | case IrInstGenIdPhi: |
| 29904 | case IrInstGenIdBinOp: |
| 29905 | case IrInstGenIdConst: |
| 29906 | case IrInstGenIdCast: |
| 29907 | case IrInstGenIdElemPtr: |
| 29908 | case IrInstGenIdVarPtr: |
| 29909 | case IrInstGenIdReturnPtr: |
| 29910 | case IrInstGenIdStructFieldPtr: |
| 29911 | case IrInstGenIdTestNonNull: |
| 29912 | case IrInstGenIdOptionalUnwrapPtr: |
| 29913 | case IrInstGenIdClz: |
| 29914 | case IrInstGenIdCtz: |
| 29915 | case IrInstGenIdPopCount: |
| 29916 | case IrInstGenIdBswap: |
| 29917 | case IrInstGenIdBitReverse: |
| 29918 | case IrInstGenIdUnionTag: |
| 29919 | case IrInstGenIdTruncate: |
| 29920 | case IrInstGenIdShuffleVector: |
| 29921 | case IrInstGenIdSplat: |
| 29922 | case IrInstGenIdBoolNot: |
| 29923 | case IrInstGenIdReturnAddress: |
| 29924 | case IrInstGenIdFrameAddress: |
| 29925 | case IrInstGenIdFrameHandle: |
| 29926 | case IrInstGenIdFrameSize: |
| 29927 | case IrInstGenIdTestErr: |
| 29928 | case IrInstGenIdPtrCast: |
| 29929 | case IrInstGenIdBitCast: |
| 29930 | case IrInstGenIdWidenOrShorten: |
| 29931 | case IrInstGenIdPtrToInt: |
| 29932 | case IrInstGenIdIntToPtr: |
| 29933 | case IrInstGenIdIntToEnum: |
| 29934 | case IrInstGenIdIntToErr: |
| 29935 | case IrInstGenIdErrToInt: |
| 29936 | case IrInstGenIdErrName: |
| 29937 | case IrInstGenIdTagName: |
| 29938 | case IrInstGenIdFieldParentPtr: |
| 29939 | case IrInstGenIdAlignCast: |
| 29940 | case IrInstGenIdErrorReturnTrace: |
| 29941 | case IrInstGenIdFloatOp: |
| 29942 | case IrInstGenIdMulAdd: |
| 29943 | case IrInstGenIdAtomicLoad: |
| 29944 | case IrInstGenIdArrayToVector: |
| 29945 | case IrInstGenIdAlloca: |
| 29946 | case IrInstGenIdSpillEnd: |
| 29947 | case IrInstGenIdVectorExtractElem: |
| 29948 | case IrInstGenIdBinaryNot: |
| 29949 | case IrInstGenIdNegation: |
| 29950 | case IrInstGenIdNegationWrapping: |
| 29265 | 29951 | return false; |
| 29266 | 29952 | |
| 29267 | | case IrInstructionIdAsmSrc: |
| 29953 | case IrInstGenIdAsm: |
| 29268 | 29954 | { |
| 29269 | | IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction; |
| 29955 | IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction; |
| 29270 | 29956 | return asm_instruction->has_side_effects; |
| 29271 | 29957 | } |
| 29958 | case IrInstGenIdUnwrapErrPayload: |
| 29959 | { |
| 29960 | IrInstGenUnwrapErrPayload *unwrap_err_payload_instruction = |
| 29961 | (IrInstGenUnwrapErrPayload *)instruction; |
| 29962 | return unwrap_err_payload_instruction->safety_check_on || |
| 29963 | unwrap_err_payload_instruction->initializing; |
| 29964 | } |
| 29965 | case IrInstGenIdUnwrapErrCode: |
| 29966 | return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing; |
| 29967 | case IrInstGenIdUnionFieldPtr: |
| 29968 | return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing; |
| 29969 | case IrInstGenIdErrWrapPayload: |
| 29970 | return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 29971 | case IrInstGenIdErrWrapCode: |
| 29972 | return reinterpret_cast<IrInstGenErrWrapCode *>(instruction)->result_loc != nullptr; |
| 29973 | case IrInstGenIdLoadPtr: |
| 29974 | return reinterpret_cast<IrInstGenLoadPtr *>(instruction)->result_loc != nullptr; |
| 29975 | case IrInstGenIdRef: |
| 29976 | return reinterpret_cast<IrInstGenRef *>(instruction)->result_loc != nullptr; |
| 29977 | } |
| 29978 | zig_unreachable(); |
| 29979 | } |
| 29980 | |
| 29981 | bool ir_inst_src_has_side_effects(IrInstSrc *instruction) { |
| 29982 | switch (instruction->id) { |
| 29983 | case IrInstSrcIdInvalid: |
| 29984 | zig_unreachable(); |
| 29985 | case IrInstSrcIdBr: |
| 29986 | case IrInstSrcIdCondBr: |
| 29987 | case IrInstSrcIdSwitchBr: |
| 29988 | case IrInstSrcIdDeclVar: |
| 29989 | case IrInstSrcIdStorePtr: |
| 29990 | case IrInstSrcIdCallExtra: |
| 29991 | case IrInstSrcIdCall: |
| 29992 | case IrInstSrcIdCallArgs: |
| 29993 | case IrInstSrcIdReturn: |
| 29994 | case IrInstSrcIdUnreachable: |
| 29995 | case IrInstSrcIdSetCold: |
| 29996 | case IrInstSrcIdSetRuntimeSafety: |
| 29997 | case IrInstSrcIdSetFloatMode: |
| 29998 | case IrInstSrcIdImport: |
| 29999 | case IrInstSrcIdCompileErr: |
| 30000 | case IrInstSrcIdCompileLog: |
| 30001 | case IrInstSrcIdCImport: |
| 30002 | case IrInstSrcIdCInclude: |
| 30003 | case IrInstSrcIdCDefine: |
| 30004 | case IrInstSrcIdCUndef: |
| 30005 | case IrInstSrcIdFence: |
| 30006 | case IrInstSrcIdMemset: |
| 30007 | case IrInstSrcIdMemcpy: |
| 30008 | case IrInstSrcIdBreakpoint: |
| 30009 | case IrInstSrcIdOverflowOp: // TODO when we support multiple returns this can be side effect free |
| 30010 | case IrInstSrcIdCheckSwitchProngs: |
| 30011 | case IrInstSrcIdCheckStatementIsVoid: |
| 30012 | case IrInstSrcIdCheckRuntimeScope: |
| 30013 | case IrInstSrcIdPanic: |
| 30014 | case IrInstSrcIdSetEvalBranchQuota: |
| 30015 | case IrInstSrcIdPtrType: |
| 30016 | case IrInstSrcIdSetAlignStack: |
| 30017 | case IrInstSrcIdExport: |
| 30018 | case IrInstSrcIdSaveErrRetAddr: |
| 30019 | case IrInstSrcIdAddImplicitReturnType: |
| 30020 | case IrInstSrcIdAtomicRmw: |
| 30021 | case IrInstSrcIdAtomicStore: |
| 30022 | case IrInstSrcIdCmpxchg: |
| 30023 | case IrInstSrcIdUndeclaredIdent: |
| 30024 | case IrInstSrcIdEndExpr: |
| 30025 | case IrInstSrcIdResetResult: |
| 30026 | case IrInstSrcIdSuspendBegin: |
| 30027 | case IrInstSrcIdSuspendFinish: |
| 30028 | case IrInstSrcIdResume: |
| 30029 | case IrInstSrcIdAwait: |
| 30030 | case IrInstSrcIdSpillBegin: |
| 30031 | return true; |
| 30032 | |
| 30033 | case IrInstSrcIdPhi: |
| 30034 | case IrInstSrcIdUnOp: |
| 30035 | case IrInstSrcIdBinOp: |
| 30036 | case IrInstSrcIdMergeErrSets: |
| 30037 | case IrInstSrcIdLoadPtr: |
| 30038 | case IrInstSrcIdConst: |
| 30039 | case IrInstSrcIdContainerInitList: |
| 30040 | case IrInstSrcIdContainerInitFields: |
| 30041 | case IrInstSrcIdUnionInitNamedField: |
| 30042 | case IrInstSrcIdFieldPtr: |
| 30043 | case IrInstSrcIdElemPtr: |
| 30044 | case IrInstSrcIdVarPtr: |
| 30045 | case IrInstSrcIdTypeOf: |
| 30046 | case IrInstSrcIdArrayType: |
| 30047 | case IrInstSrcIdSliceType: |
| 30048 | case IrInstSrcIdAnyFrameType: |
| 30049 | case IrInstSrcIdSizeOf: |
| 30050 | case IrInstSrcIdTestNonNull: |
| 30051 | case IrInstSrcIdOptionalUnwrapPtr: |
| 30052 | case IrInstSrcIdClz: |
| 30053 | case IrInstSrcIdCtz: |
| 30054 | case IrInstSrcIdPopCount: |
| 30055 | case IrInstSrcIdBswap: |
| 30056 | case IrInstSrcIdBitReverse: |
| 30057 | case IrInstSrcIdSwitchVar: |
| 30058 | case IrInstSrcIdSwitchElseVar: |
| 30059 | case IrInstSrcIdSwitchTarget: |
| 30060 | case IrInstSrcIdRef: |
| 30061 | case IrInstSrcIdEmbedFile: |
| 30062 | case IrInstSrcIdTruncate: |
| 30063 | case IrInstSrcIdIntType: |
| 30064 | case IrInstSrcIdVectorType: |
| 30065 | case IrInstSrcIdShuffleVector: |
| 30066 | case IrInstSrcIdSplat: |
| 30067 | case IrInstSrcIdBoolNot: |
| 30068 | case IrInstSrcIdSlice: |
| 30069 | case IrInstSrcIdMemberCount: |
| 30070 | case IrInstSrcIdMemberType: |
| 30071 | case IrInstSrcIdMemberName: |
| 30072 | case IrInstSrcIdAlignOf: |
| 30073 | case IrInstSrcIdReturnAddress: |
| 30074 | case IrInstSrcIdFrameAddress: |
| 30075 | case IrInstSrcIdFrameHandle: |
| 30076 | case IrInstSrcIdFrameType: |
| 30077 | case IrInstSrcIdFrameSize: |
| 30078 | case IrInstSrcIdTestErr: |
| 30079 | case IrInstSrcIdFnProto: |
| 30080 | case IrInstSrcIdTestComptime: |
| 30081 | case IrInstSrcIdPtrCast: |
| 30082 | case IrInstSrcIdBitCast: |
| 30083 | case IrInstSrcIdPtrToInt: |
| 30084 | case IrInstSrcIdIntToPtr: |
| 30085 | case IrInstSrcIdIntToEnum: |
| 30086 | case IrInstSrcIdIntToErr: |
| 30087 | case IrInstSrcIdErrToInt: |
| 30088 | case IrInstSrcIdDeclRef: |
| 30089 | case IrInstSrcIdErrName: |
| 30090 | case IrInstSrcIdTypeName: |
| 30091 | case IrInstSrcIdTagName: |
| 30092 | case IrInstSrcIdFieldParentPtr: |
| 30093 | case IrInstSrcIdByteOffsetOf: |
| 30094 | case IrInstSrcIdBitOffsetOf: |
| 30095 | case IrInstSrcIdTypeInfo: |
| 30096 | case IrInstSrcIdType: |
| 30097 | case IrInstSrcIdHasField: |
| 30098 | case IrInstSrcIdTypeId: |
| 30099 | case IrInstSrcIdAlignCast: |
| 30100 | case IrInstSrcIdImplicitCast: |
| 30101 | case IrInstSrcIdResolveResult: |
| 30102 | case IrInstSrcIdOpaqueType: |
| 30103 | case IrInstSrcIdArgType: |
| 30104 | case IrInstSrcIdTagType: |
| 30105 | case IrInstSrcIdErrorReturnTrace: |
| 30106 | case IrInstSrcIdErrorUnion: |
| 30107 | case IrInstSrcIdFloatOp: |
| 30108 | case IrInstSrcIdMulAdd: |
| 30109 | case IrInstSrcIdAtomicLoad: |
| 30110 | case IrInstSrcIdIntCast: |
| 30111 | case IrInstSrcIdFloatCast: |
| 30112 | case IrInstSrcIdErrSetCast: |
| 30113 | case IrInstSrcIdIntToFloat: |
| 30114 | case IrInstSrcIdFloatToInt: |
| 30115 | case IrInstSrcIdBoolToInt: |
| 30116 | case IrInstSrcIdFromBytes: |
| 30117 | case IrInstSrcIdToBytes: |
| 30118 | case IrInstSrcIdEnumToInt: |
| 30119 | case IrInstSrcIdHasDecl: |
| 30120 | case IrInstSrcIdAlloca: |
| 30121 | case IrInstSrcIdSpillEnd: |
| 30122 | return false; |
| 29272 | 30123 | |
| 29273 | | case IrInstructionIdAsmGen: |
| 30124 | case IrInstSrcIdAsm: |
| 29274 | 30125 | { |
| 29275 | | IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction; |
| 30126 | IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction; |
| 29276 | 30127 | return asm_instruction->has_side_effects; |
| 29277 | 30128 | } |
| 29278 | | case IrInstructionIdUnwrapErrPayload: |
| 30129 | |
| 30130 | case IrInstSrcIdUnwrapErrPayload: |
| 29279 | 30131 | { |
| 29280 | | IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction = |
| 29281 | | (IrInstructionUnwrapErrPayload *)instruction; |
| 30132 | IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction = |
| 30133 | (IrInstSrcUnwrapErrPayload *)instruction; |
| 29282 | 30134 | return unwrap_err_payload_instruction->safety_check_on || |
| 29283 | 30135 | unwrap_err_payload_instruction->initializing; |
| 29284 | 30136 | } |
| 29285 | | case IrInstructionIdUnwrapErrCode: |
| 29286 | | return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing; |
| 29287 | | case IrInstructionIdUnionFieldPtr: |
| 29288 | | return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing; |
| 29289 | | case IrInstructionIdErrWrapPayload: |
| 29290 | | return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr; |
| 29291 | | case IrInstructionIdErrWrapCode: |
| 29292 | | return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr; |
| 29293 | | case IrInstructionIdLoadPtrGen: |
| 29294 | | return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr; |
| 29295 | | case IrInstructionIdRefGen: |
| 29296 | | return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr; |
| 30137 | case IrInstSrcIdUnwrapErrCode: |
| 30138 | return reinterpret_cast<IrInstSrcUnwrapErrCode *>(instruction)->initializing; |
| 29297 | 30139 | } |
| 29298 | 30140 | zig_unreachable(); |
| 29299 | 30141 | } |
| ... | ... | @@ -29327,14 +30169,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29327 | 30169 | param_info->type = nullptr; |
| 29328 | 30170 | return get_generic_fn_type(ira->codegen, &fn_type_id); |
| 29329 | 30171 | } else { |
| 29330 | | IrInstruction *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index]; |
| 30172 | IrInstGen *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index]; |
| 29331 | 30173 | ZigType *param_type = ir_resolve_type(ira, param_type_inst); |
| 29332 | 30174 | if (type_is_invalid(param_type)) |
| 29333 | 30175 | return nullptr; |
| 29334 | 30176 | switch (type_requires_comptime(ira->codegen, param_type)) { |
| 29335 | 30177 | case ReqCompTimeYes: |
| 29336 | 30178 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 29337 | | ir_add_error(ira, param_type_inst, |
| 30179 | ir_add_error(ira, &param_type_inst->base, |
| 29338 | 30180 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 29339 | 30181 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 29340 | 30182 | return nullptr; |
| ... | ... | @@ -29352,7 +30194,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29352 | 30194 | if ((err = type_has_bits2(ira->codegen, param_type, &has_bits))) |
| 29353 | 30195 | return nullptr; |
| 29354 | 30196 | if (!has_bits) { |
| 29355 | | ir_add_error(ira, param_type_inst, |
| 30197 | ir_add_error(ira, &param_type_inst->base, |
| 29356 | 30198 | buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", |
| 29357 | 30199 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 29358 | 30200 | return nullptr; |
| ... | ... | @@ -29371,7 +30213,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 29371 | 30213 | if (type_is_invalid(fn_type_id.return_type)) |
| 29372 | 30214 | return nullptr; |
| 29373 | 30215 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 29374 | | ir_add_error(ira, lazy_fn_type->return_type, buf_create_from_str("return type cannot be opaque")); |
| 30216 | ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque")); |
| 29375 | 30217 | return nullptr; |
| 29376 | 30218 | } |
| 29377 | 30219 | |
| ... | ... | @@ -29403,7 +30245,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29403 | 30245 | case ZigTypeIdBoundFn: |
| 29404 | 30246 | case ZigTypeIdVoid: |
| 29405 | 30247 | case ZigTypeIdOpaque: |
| 29406 | | ir_add_error(ira, lazy_align_of->target_type, |
| 30248 | ir_add_error(ira, &lazy_align_of->target_type->base, |
| 29407 | 30249 | buf_sprintf("no align available for type '%s'", |
| 29408 | 30250 | buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); |
| 29409 | 30251 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29453,7 +30295,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29453 | 30295 | case ZigTypeIdNull: |
| 29454 | 30296 | case ZigTypeIdBoundFn: |
| 29455 | 30297 | case ZigTypeIdOpaque: |
| 29456 | | ir_add_error(ira, lazy_size_of->target_type, |
| 30298 | ir_add_error(ira, &lazy_size_of->target_type->base, |
| 29457 | 30299 | buf_sprintf("no size available for type '%s'", |
| 29458 | 30300 | buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); |
| 29459 | 30301 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29511,7 +30353,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29511 | 30353 | if (lazy_slice_type->sentinel != nullptr) { |
| 29512 | 30354 | if (type_is_invalid(lazy_slice_type->sentinel->value->type)) |
| 29513 | 30355 | return ErrorSemanticAnalyzeFail; |
| 29514 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 30356 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 29515 | 30357 | if (type_is_invalid(sentinel->value->type)) |
| 29516 | 30358 | return ErrorSemanticAnalyzeFail; |
| 29517 | 30359 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29534,7 +30376,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29534 | 30376 | case ZigTypeIdUndefined: |
| 29535 | 30377 | case ZigTypeIdNull: |
| 29536 | 30378 | case ZigTypeIdOpaque: |
| 29537 | | ir_add_error(ira, lazy_slice_type->elem_type, |
| 30379 | ir_add_error(ira, &lazy_slice_type->elem_type->base, |
| 29538 | 30380 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name))); |
| 29539 | 30381 | return ErrorSemanticAnalyzeFail; |
| 29540 | 30382 | case ZigTypeIdMetaType: |
| ... | ... | @@ -29590,7 +30432,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29590 | 30432 | if (lazy_ptr_type->sentinel != nullptr) { |
| 29591 | 30433 | if (type_is_invalid(lazy_ptr_type->sentinel->value->type)) |
| 29592 | 30434 | return ErrorSemanticAnalyzeFail; |
| 29593 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 30435 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 29594 | 30436 | if (type_is_invalid(sentinel->value->type)) |
| 29595 | 30437 | return ErrorSemanticAnalyzeFail; |
| 29596 | 30438 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29607,11 +30449,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29607 | 30449 | } |
| 29608 | 30450 | |
| 29609 | 30451 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 29610 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30452 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29611 | 30453 | buf_create_from_str("pointer to noreturn not allowed")); |
| 29612 | 30454 | return ErrorSemanticAnalyzeFail; |
| 29613 | 30455 | } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) { |
| 29614 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30456 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29615 | 30457 | buf_create_from_str("unknown-length pointer to opaque")); |
| 29616 | 30458 | return ErrorSemanticAnalyzeFail; |
| 29617 | 30459 | } else if (lazy_ptr_type->ptr_len == PtrLenC) { |
| ... | ... | @@ -29619,16 +30461,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29619 | 30461 | if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type))) |
| 29620 | 30462 | return err; |
| 29621 | 30463 | if (!ok_type) { |
| 29622 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30464 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29623 | 30465 | buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'", |
| 29624 | 30466 | buf_ptr(&elem_type->name))); |
| 29625 | 30467 | return ErrorSemanticAnalyzeFail; |
| 29626 | 30468 | } else if (elem_type->id == ZigTypeIdOpaque) { |
| 29627 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30469 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29628 | 30470 | buf_sprintf("C pointers cannot point opaque types")); |
| 29629 | 30471 | return ErrorSemanticAnalyzeFail; |
| 29630 | 30472 | } else if (lazy_ptr_type->is_allowzero) { |
| 29631 | | ir_add_error(ira, lazy_ptr_type->elem_type, |
| 30473 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 29632 | 30474 | buf_sprintf("C pointers always allow address zero")); |
| 29633 | 30475 | return ErrorSemanticAnalyzeFail; |
| 29634 | 30476 | } |
| ... | ... | @@ -29666,7 +30508,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29666 | 30508 | case ZigTypeIdUndefined: |
| 29667 | 30509 | case ZigTypeIdNull: |
| 29668 | 30510 | case ZigTypeIdOpaque: |
| 29669 | | ir_add_error(ira, lazy_array_type->elem_type, |
| 30511 | ir_add_error(ira, &lazy_array_type->elem_type->base, |
| 29670 | 30512 | buf_sprintf("array of type '%s' not allowed", |
| 29671 | 30513 | buf_ptr(&elem_type->name))); |
| 29672 | 30514 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29701,7 +30543,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29701 | 30543 | if (lazy_array_type->sentinel != nullptr) { |
| 29702 | 30544 | if (type_is_invalid(lazy_array_type->sentinel->value->type)) |
| 29703 | 30545 | return ErrorSemanticAnalyzeFail; |
| 29704 | | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type); |
| 30546 | IrInstGen *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type); |
| 29705 | 30547 | if (type_is_invalid(sentinel->value->type)) |
| 29706 | 30548 | return ErrorSemanticAnalyzeFail; |
| 29707 | 30549 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| ... | ... | @@ -29725,7 +30567,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29725 | 30567 | return ErrorSemanticAnalyzeFail; |
| 29726 | 30568 | |
| 29727 | 30569 | if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) { |
| 29728 | | ir_add_error(ira, lazy_opt_type->payload_type, |
| 30570 | ir_add_error(ira, &lazy_opt_type->payload_type->base, |
| 29729 | 30571 | buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name))); |
| 29730 | 30572 | return ErrorSemanticAnalyzeFail; |
| 29731 | 30573 | } |
| ... | ... | @@ -29767,7 +30609,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 29767 | 30609 | return ErrorSemanticAnalyzeFail; |
| 29768 | 30610 | |
| 29769 | 30611 | if (err_set_type->id != ZigTypeIdErrorSet) { |
| 29770 | | ir_add_error(ira, lazy_err_union_type->err_set_type, |
| 30612 | ir_add_error(ira, &lazy_err_union_type->err_set_type->base, |
| 29771 | 30613 | buf_sprintf("expected error set type, found type '%s'", |
| 29772 | 30614 | buf_ptr(&err_set_type->name))); |
| 29773 | 30615 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -29803,8 +30645,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { |
| 29803 | 30645 | return ErrorNone; |
| 29804 | 30646 | } |
| 29805 | 30647 | |
| 29806 | | void IrInstruction::src() { |
| 29807 | | IrInstruction *inst = this; |
| 30648 | void IrInst::src() { |
| 30649 | IrInst *inst = this; |
| 29808 | 30650 | if (inst->source_node != nullptr) { |
| 29809 | 30651 | inst->source_node->src(); |
| 29810 | 30652 | } else { |
| ... | ... | @@ -29812,26 +30654,45 @@ void IrInstruction::src() { |
| 29812 | 30654 | } |
| 29813 | 30655 | } |
| 29814 | 30656 | |
| 29815 | | void IrInstruction::dump() { |
| 29816 | | IrInstruction *inst = this; |
| 30657 | void IrInst::dump() { |
| 30658 | this->src(); |
| 30659 | fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id); |
| 30660 | } |
| 30661 | |
| 30662 | void IrInstSrc::src() { |
| 30663 | this->base.src(); |
| 30664 | } |
| 30665 | |
| 30666 | void IrInstGen::src() { |
| 30667 | this->base.src(); |
| 30668 | } |
| 30669 | |
| 30670 | void IrInstSrc::dump() { |
| 30671 | IrInstSrc *inst = this; |
| 29817 | 30672 | inst->src(); |
| 29818 | | IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc; |
| 29819 | | if (inst->scope == nullptr) { |
| 30673 | if (inst->base.scope == nullptr) { |
| 29820 | 30674 | fprintf(stderr, "(null scope)\n"); |
| 29821 | 30675 | } else { |
| 29822 | | ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass); |
| 29823 | | if (pass == IrPassSrc) { |
| 29824 | | fprintf(stderr, "-> "); |
| 29825 | | ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen); |
| 29826 | | } |
| 30676 | ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0); |
| 30677 | fprintf(stderr, "-> "); |
| 30678 | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0); |
| 30679 | } |
| 30680 | } |
| 30681 | void IrInstGen::dump() { |
| 30682 | IrInstGen *inst = this; |
| 30683 | inst->src(); |
| 30684 | if (inst->base.scope == nullptr) { |
| 30685 | fprintf(stderr, "(null scope)\n"); |
| 30686 | } else { |
| 30687 | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0); |
| 29827 | 30688 | } |
| 29828 | 30689 | } |
| 29829 | 30690 | |
| 29830 | 30691 | void IrAnalyze::dump() { |
| 29831 | | ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen); |
| 30692 | ir_print_gen(this->codegen, stderr, this->new_irb.exec, 0); |
| 29832 | 30693 | if (this->new_irb.current_basic_block != nullptr) { |
| 29833 | 30694 | fprintf(stderr, "Current basic block:\n"); |
| 29834 | | ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen); |
| 30695 | ir_print_basic_block_gen(this->codegen, stderr, this->new_irb.current_basic_block, 1); |
| 29835 | 30696 | } |
| 29836 | 30697 | } |
| 29837 | 30698 | |