| ... | @@ -1,3 +1,10 @@ | ... | @@ -1,3 +1,10 @@ |
| | 1 | /* |
| | 2 | * Copyright (c) 2016 Andrew Kelley |
| | 3 | * |
| | 4 | * This file is part of zig, which is MIT licensed. |
| | 5 | * See http://opensource.org/licenses/MIT |
| | 6 | */ |
| | 7 | |
| 1 | #include "analyze.hpp" | 8 | #include "analyze.hpp" |
| 2 | #include "error.hpp" | 9 | #include "error.hpp" |
| 3 | #include "eval.hpp" | 10 | #include "eval.hpp" |
| ... | @@ -71,6 +78,10 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { | ... | @@ -71,6 +78,10 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { |
| 71 | return result; | 78 | return result; |
| 72 | } | 79 | } |
| 73 | | 80 | |
| | 81 | static FnTableEntry *exec_fn_entry(IrExecutable *exec) { |
| | 82 | return exec->fn_entry; |
| | 83 | } |
| | 84 | |
| 74 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { | 85 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { |
| 75 | new_instruction->other = old_instruction; | 86 | new_instruction->other = old_instruction; |
| 76 | old_instruction->other = new_instruction; | 87 | old_instruction->other = new_instruction; |
| ... | @@ -289,26 +300,27 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionStructInit *) { | ... | @@ -289,26 +300,27 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionStructInit *) { |
| 289 | } | 300 | } |
| 290 | | 301 | |
| 291 | template<typename T> | 302 | template<typename T> |
| 292 | static T *ir_create_instruction(IrExecutable *exec, AstNode *source_node) { | 303 | static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) { |
| 293 | T *special_instruction = allocate<T>(1); | 304 | T *special_instruction = allocate<T>(1); |
| 294 | special_instruction->base.id = ir_instruction_id(special_instruction); | 305 | special_instruction->base.id = ir_instruction_id(special_instruction); |
| | 306 | special_instruction->base.scope = scope; |
| 295 | special_instruction->base.source_node = source_node; | 307 | special_instruction->base.source_node = source_node; |
| 296 | special_instruction->base.debug_id = exec_next_debug_id(exec); | 308 | special_instruction->base.debug_id = exec_next_debug_id(exec); |
| 297 | return special_instruction; | 309 | return special_instruction; |
| 298 | } | 310 | } |
| 299 | | 311 | |
| 300 | template<typename T> | 312 | template<typename T> |
| 301 | static T *ir_build_instruction(IrBuilder *irb, AstNode *source_node) { | 313 | static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 302 | assert(source_node); | 314 | assert(source_node); |
| 303 | T *special_instruction = ir_create_instruction<T>(irb->exec, source_node); | 315 | T *special_instruction = ir_create_instruction<T>(irb->exec, scope, source_node); |
| 304 | ir_instruction_append(irb->current_basic_block, &special_instruction->base); | 316 | ir_instruction_append(irb->current_basic_block, &special_instruction->base); |
| 305 | return special_instruction; | 317 | return special_instruction; |
| 306 | } | 318 | } |
| 307 | | 319 | |
| 308 | static IrInstruction *ir_build_cast(IrBuilder *irb, AstNode *source_node, TypeTableEntry *dest_type, | 320 | static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, TypeTableEntry *dest_type, |
| 309 | IrInstruction *value, CastOp cast_op) | 321 | IrInstruction *value, CastOp cast_op) |
| 310 | { | 322 | { |
| 311 | IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, source_node); | 323 | IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node); |
| 312 | cast_instruction->dest_type = dest_type; | 324 | cast_instruction->dest_type = dest_type; |
| 313 | cast_instruction->value = value; | 325 | cast_instruction->value = value; |
| 314 | cast_instruction->cast_op = cast_op; | 326 | cast_instruction->cast_op = cast_op; |
| ... | @@ -318,10 +330,10 @@ static IrInstruction *ir_build_cast(IrBuilder *irb, AstNode *source_node, TypeTa | ... | @@ -318,10 +330,10 @@ static IrInstruction *ir_build_cast(IrBuilder *irb, AstNode *source_node, TypeTa |
| 318 | return &cast_instruction->base; | 330 | return &cast_instruction->base; |
| 319 | } | 331 | } |
| 320 | | 332 | |
| 321 | static IrInstruction *ir_build_cond_br(IrBuilder *irb, AstNode *source_node, IrInstruction *condition, | 333 | static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition, |
| 322 | IrBasicBlock *then_block, IrBasicBlock *else_block, bool is_inline) | 334 | IrBasicBlock *then_block, IrBasicBlock *else_block, bool is_inline) |
| 323 | { | 335 | { |
| 324 | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, source_node); | 336 | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); |
| 325 | cond_br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; | 337 | cond_br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 326 | cond_br_instruction->base.static_value.special = ConstValSpecialStatic; | 338 | cond_br_instruction->base.static_value.special = ConstValSpecialStatic; |
| 327 | cond_br_instruction->condition = condition; | 339 | cond_br_instruction->condition = condition; |
| ... | @@ -339,14 +351,14 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, AstNode *source_node, IrI | ... | @@ -339,14 +351,14 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, AstNode *source_node, IrI |
| 339 | static IrInstruction *ir_build_cond_br_from(IrBuilder *irb, IrInstruction *old_instruction, | 351 | static IrInstruction *ir_build_cond_br_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 340 | IrInstruction *condition, IrBasicBlock *then_block, IrBasicBlock *else_block, bool is_inline) | 352 | IrInstruction *condition, IrBasicBlock *then_block, IrBasicBlock *else_block, bool is_inline) |
| 341 | { | 353 | { |
| 342 | IrInstruction *new_instruction = ir_build_cond_br(irb, old_instruction->source_node, | 354 | IrInstruction *new_instruction = ir_build_cond_br(irb, old_instruction->scope, old_instruction->source_node, |
| 343 | condition, then_block, else_block, is_inline); | 355 | condition, then_block, else_block, is_inline); |
| 344 | ir_link_new_instruction(new_instruction, old_instruction); | 356 | ir_link_new_instruction(new_instruction, old_instruction); |
| 345 | return new_instruction; | 357 | return new_instruction; |
| 346 | } | 358 | } |
| 347 | | 359 | |
| 348 | static IrInstruction *ir_build_return(IrBuilder *irb, AstNode *source_node, IrInstruction *return_value) { | 360 | static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *return_value) { |
| 349 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, source_node); | 361 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 350 | return_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; | 362 | return_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 351 | return_instruction->base.static_value.special = ConstValSpecialStatic; | 363 | return_instruction->base.static_value.special = ConstValSpecialStatic; |
| 352 | return_instruction->value = return_value; | 364 | return_instruction->value = return_value; |
| ... | @@ -359,38 +371,38 @@ static IrInstruction *ir_build_return(IrBuilder *irb, AstNode *source_node, IrIn | ... | @@ -359,38 +371,38 @@ static IrInstruction *ir_build_return(IrBuilder *irb, AstNode *source_node, IrIn |
| 359 | static IrInstruction *ir_build_return_from(IrBuilder *irb, IrInstruction *old_instruction, | 371 | static IrInstruction *ir_build_return_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 360 | IrInstruction *return_value) | 372 | IrInstruction *return_value) |
| 361 | { | 373 | { |
| 362 | IrInstruction *new_instruction = ir_build_return(irb, old_instruction->source_node, return_value); | 374 | IrInstruction *new_instruction = ir_build_return(irb, old_instruction->scope, old_instruction->source_node, return_value); |
| 363 | ir_link_new_instruction(new_instruction, old_instruction); | 375 | ir_link_new_instruction(new_instruction, old_instruction); |
| 364 | return new_instruction; | 376 | return new_instruction; |
| 365 | } | 377 | } |
| 366 | | 378 | |
| 367 | static IrInstruction *ir_create_const(IrBuilder *irb, AstNode *source_node, | 379 | static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 368 | TypeTableEntry *type_entry, bool depends_on_compile_var) | 380 | TypeTableEntry *type_entry, bool depends_on_compile_var) |
| 369 | { | 381 | { |
| 370 | assert(type_entry); | 382 | assert(type_entry); |
| 371 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, source_node); | 383 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| 372 | const_instruction->base.type_entry = type_entry; | 384 | const_instruction->base.type_entry = type_entry; |
| 373 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 385 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 374 | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; | 386 | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; |
| 375 | return &const_instruction->base; | 387 | return &const_instruction->base; |
| 376 | } | 388 | } |
| 377 | | 389 | |
| 378 | static IrInstruction *ir_build_const_void(IrBuilder *irb, AstNode *source_node) { | 390 | static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 379 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 391 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 380 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; | 392 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 381 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 393 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 382 | return &const_instruction->base; | 394 | return &const_instruction->base; |
| 383 | } | 395 | } |
| 384 | | 396 | |
| 385 | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, AstNode *source_node) { | 397 | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 386 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 398 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 387 | const_instruction->base.static_value.special = ConstValSpecialUndef; | 399 | const_instruction->base.static_value.special = ConstValSpecialUndef; |
| 388 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_undef; | 400 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_undef; |
| 389 | return &const_instruction->base; | 401 | return &const_instruction->base; |
| 390 | } | 402 | } |
| 391 | | 403 | |
| 392 | static IrInstruction *ir_build_const_bignum(IrBuilder *irb, AstNode *source_node, BigNum *bignum) { | 404 | static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) { |
| 393 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 405 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 394 | const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ? | 406 | const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ? |
| 395 | irb->codegen->builtin_types.entry_num_lit_int : irb->codegen->builtin_types.entry_num_lit_float; | 407 | irb->codegen->builtin_types.entry_num_lit_int : irb->codegen->builtin_types.entry_num_lit_float; |
| 396 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 408 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| ... | @@ -398,79 +410,77 @@ static IrInstruction *ir_build_const_bignum(IrBuilder *irb, AstNode *source_node | ... | @@ -398,79 +410,77 @@ static IrInstruction *ir_build_const_bignum(IrBuilder *irb, AstNode *source_node |
| 398 | return &const_instruction->base; | 410 | return &const_instruction->base; |
| 399 | } | 411 | } |
| 400 | | 412 | |
| 401 | static IrInstruction *ir_build_const_null(IrBuilder *irb, AstNode *source_node) { | 413 | static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 402 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 414 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 403 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_null; | 415 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_null; |
| 404 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 416 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 405 | return &const_instruction->base; | 417 | return &const_instruction->base; |
| 406 | } | 418 | } |
| 407 | | 419 | |
| 408 | static IrInstruction *ir_build_const_usize(IrBuilder *irb, AstNode *source_node, uint64_t value) { | 420 | static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 409 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 421 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 410 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_usize; | 422 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_usize; |
| 411 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 423 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 412 | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value); | 424 | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value); |
| 413 | return &const_instruction->base; | 425 | return &const_instruction->base; |
| 414 | } | 426 | } |
| 415 | | 427 | |
| 416 | static IrInstruction *ir_create_const_type(IrBuilder *irb, AstNode *source_node, TypeTableEntry *type_entry) { | 428 | static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 417 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, source_node); | 429 | TypeTableEntry *type_entry) |
| | 430 | { |
| | 431 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb->exec, scope, source_node); |
| 418 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_type; | 432 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_type; |
| 419 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 433 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 420 | const_instruction->base.static_value.data.x_type = type_entry; | 434 | const_instruction->base.static_value.data.x_type = type_entry; |
| 421 | return &const_instruction->base; | 435 | return &const_instruction->base; |
| 422 | } | 436 | } |
| 423 | | 437 | |
| 424 | static IrInstruction *ir_build_const_type(IrBuilder *irb, AstNode *source_node, TypeTableEntry *type_entry) { | 438 | static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 425 | IrInstruction *instruction = ir_create_const_type(irb, source_node, type_entry); | 439 | TypeTableEntry *type_entry) |
| | 440 | { |
| | 441 | IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); |
| 426 | ir_instruction_append(irb->current_basic_block, instruction); | 442 | ir_instruction_append(irb->current_basic_block, instruction); |
| 427 | return instruction; | 443 | return instruction; |
| 428 | } | 444 | } |
| 429 | | 445 | |
| 430 | static IrInstruction *ir_build_const_fn(IrBuilder *irb, AstNode *source_node, FnTableEntry *fn_entry) { | 446 | static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { |
| 431 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 447 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 432 | const_instruction->base.type_entry = fn_entry->type_entry; | 448 | const_instruction->base.type_entry = fn_entry->type_entry; |
| 433 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 449 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 434 | const_instruction->base.static_value.data.x_fn = fn_entry; | 450 | const_instruction->base.static_value.data.x_fn = fn_entry; |
| 435 | return &const_instruction->base; | 451 | return &const_instruction->base; |
| 436 | } | 452 | } |
| 437 | | 453 | |
| 438 | static IrInstruction *ir_build_const_generic_fn(IrBuilder *irb, AstNode *source_node, TypeTableEntry *fn_type) { | 454 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) { |
| 439 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 455 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 440 | const_instruction->base.type_entry = fn_type; | | |
| 441 | const_instruction->base.static_value.special = ConstValSpecialStatic; | | |
| 442 | const_instruction->base.static_value.data.x_type = fn_type; | | |
| 443 | return &const_instruction->base; | | |
| 444 | } | | |
| 445 | | | |
| 446 | static IrInstruction *ir_build_const_import(IrBuilder *irb, AstNode *source_node, ImportTableEntry *import) { | | |
| 447 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | | |
| 448 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_namespace; | 456 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_namespace; |
| 449 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 457 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 450 | const_instruction->base.static_value.data.x_import = import; | 458 | const_instruction->base.static_value.data.x_import = import; |
| 451 | return &const_instruction->base; | 459 | return &const_instruction->base; |
| 452 | } | 460 | } |
| 453 | | 461 | |
| 454 | static IrInstruction *ir_build_const_scope(IrBuilder *irb, AstNode *source_node, Scope *scope) { | 462 | static IrInstruction *ir_build_const_scope(IrBuilder *irb, Scope *parent_scope, AstNode *source_node, |
| 455 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 463 | Scope *target_scope) |
| | 464 | { |
| | 465 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, parent_scope, source_node); |
| 456 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block; | 466 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_block; |
| 457 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 467 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 458 | const_instruction->base.static_value.data.x_block = scope; | 468 | const_instruction->base.static_value.data.x_block = target_scope; |
| 459 | return &const_instruction->base; | 469 | return &const_instruction->base; |
| 460 | } | 470 | } |
| 461 | | 471 | |
| 462 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, AstNode *source_node, bool value) { | 472 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { |
| 463 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 473 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 464 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_bool; | 474 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_bool; |
| 465 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 475 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 466 | const_instruction->base.static_value.data.x_bool = value; | 476 | const_instruction->base.static_value.data.x_bool = value; |
| 467 | return &const_instruction->base; | 477 | return &const_instruction->base; |
| 468 | } | 478 | } |
| 469 | | 479 | |
| 470 | static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, AstNode *source_node, | 480 | static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 471 | FnTableEntry *fn_entry, IrInstruction *first_arg, bool depends_on_compile_var) | 481 | FnTableEntry *fn_entry, IrInstruction *first_arg, bool depends_on_compile_var) |
| 472 | { | 482 | { |
| 473 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 483 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 474 | const_instruction->base.type_entry = get_bound_fn_type(irb->codegen, fn_entry); | 484 | const_instruction->base.type_entry = get_bound_fn_type(irb->codegen, fn_entry); |
| 475 | const_instruction->base.static_value.special = ConstValSpecialStatic; | 485 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| 476 | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; | 486 | const_instruction->base.static_value.depends_on_compile_var = depends_on_compile_var; |
| ... | @@ -479,8 +489,8 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, AstNode *source_no | ... | @@ -479,8 +489,8 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, AstNode *source_no |
| 479 | return &const_instruction->base; | 489 | return &const_instruction->base; |
| 480 | } | 490 | } |
| 481 | | 491 | |
| 482 | static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, AstNode *source_node, Buf *str) { | 492 | static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 483 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 493 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 484 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; | 494 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; |
| 485 | TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str)); | 495 | TypeTableEntry *type_entry = get_array_type(irb->codegen, u8_type, buf_len(str)); |
| 486 | const_instruction->base.type_entry = type_entry; | 496 | const_instruction->base.type_entry = type_entry; |
| ... | @@ -498,7 +508,7 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, AstNode *source_nod | ... | @@ -498,7 +508,7 @@ static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, AstNode *source_nod |
| 498 | return &const_instruction->base; | 508 | return &const_instruction->base; |
| 499 | } | 509 | } |
| 500 | | 510 | |
| 501 | static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, AstNode *source_node, Buf *str) { | 511 | static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 502 | // first we build the underlying array | 512 | // first we build the underlying array |
| 503 | size_t len_with_null = buf_len(str) + 1; | 513 | size_t len_with_null = buf_len(str) + 1; |
| 504 | ConstExprValue *array_val = allocate<ConstExprValue>(1); | 514 | ConstExprValue *array_val = allocate<ConstExprValue>(1); |
| ... | @@ -515,7 +525,7 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, AstNode *source_n | ... | @@ -515,7 +525,7 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, AstNode *source_n |
| 515 | bignum_init_unsigned(&null_char->data.x_bignum, 0); | 525 | bignum_init_unsigned(&null_char->data.x_bignum, 0); |
| 516 | | 526 | |
| 517 | // then make the pointer point to it | 527 | // then make the pointer point to it |
| 518 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, source_node); | 528 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 519 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; | 529 | TypeTableEntry *u8_type = irb->codegen->builtin_types.entry_u8; |
| 520 | TypeTableEntry *type_entry = get_pointer_to_type(irb->codegen, u8_type, true); | 530 | TypeTableEntry *type_entry = get_pointer_to_type(irb->codegen, u8_type, true); |
| 521 | const_instruction->base.type_entry = type_entry; | 531 | const_instruction->base.type_entry = type_entry; |
| ... | @@ -528,10 +538,10 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, AstNode *source_n | ... | @@ -528,10 +538,10 @@ static IrInstruction *ir_build_const_c_str_lit(IrBuilder *irb, AstNode *source_n |
| 528 | return &const_instruction->base; | 538 | return &const_instruction->base; |
| 529 | } | 539 | } |
| 530 | | 540 | |
| 531 | static IrInstruction *ir_build_bin_op(IrBuilder *irb, AstNode *source_node, IrBinOp op_id, | 541 | static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 532 | IrInstruction *op1, IrInstruction *op2) | 542 | IrInstruction *op1, IrInstruction *op2) |
| 533 | { | 543 | { |
| 534 | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, source_node); | 544 | IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node); |
| 535 | bin_op_instruction->op_id = op_id; | 545 | bin_op_instruction->op_id = op_id; |
| 536 | bin_op_instruction->op1 = op1; | 546 | bin_op_instruction->op1 = op1; |
| 537 | bin_op_instruction->op2 = op2; | 547 | bin_op_instruction->op2 = op2; |
| ... | @@ -545,13 +555,14 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, AstNode *source_node, IrBi | ... | @@ -545,13 +555,14 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, AstNode *source_node, IrBi |
| 545 | static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_instruction, IrBinOp op_id, | 555 | static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_instruction, IrBinOp op_id, |
| 546 | IrInstruction *op1, IrInstruction *op2) | 556 | IrInstruction *op1, IrInstruction *op2) |
| 547 | { | 557 | { |
| 548 | IrInstruction *new_instruction = ir_build_bin_op(irb, old_instruction->source_node, op_id, op1, op2); | 558 | IrInstruction *new_instruction = ir_build_bin_op(irb, old_instruction->scope, |
| | 559 | old_instruction->source_node, op_id, op1, op2); |
| 549 | ir_link_new_instruction(new_instruction, old_instruction); | 560 | ir_link_new_instruction(new_instruction, old_instruction); |
| 550 | return new_instruction; | 561 | return new_instruction; |
| 551 | } | 562 | } |
| 552 | | 563 | |
| 553 | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, AstNode *source_node, VariableTableEntry *var) { | 564 | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) { |
| 554 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, source_node); | 565 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 555 | instruction->var = var; | 566 | instruction->var = var; |
| 556 | | 567 | |
| 557 | ir_ref_var(var); | 568 | ir_ref_var(var); |
| ... | @@ -560,16 +571,16 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, AstNode *source_node, Var | ... | @@ -560,16 +571,16 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, AstNode *source_node, Var |
| 560 | } | 571 | } |
| 561 | | 572 | |
| 562 | static IrInstruction *ir_build_var_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, VariableTableEntry *var) { | 573 | static IrInstruction *ir_build_var_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, VariableTableEntry *var) { |
| 563 | IrInstruction *new_instruction = ir_build_var_ptr(irb, old_instruction->source_node, var); | 574 | IrInstruction *new_instruction = ir_build_var_ptr(irb, old_instruction->scope, old_instruction->source_node, var); |
| 564 | ir_link_new_instruction(new_instruction, old_instruction); | 575 | ir_link_new_instruction(new_instruction, old_instruction); |
| 565 | return new_instruction; | 576 | return new_instruction; |
| 566 | | 577 | |
| 567 | } | 578 | } |
| 568 | | 579 | |
| 569 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, AstNode *source_node, IrInstruction *array_ptr, | 580 | static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr, |
| 570 | IrInstruction *elem_index, bool safety_check_on) | 581 | IrInstruction *elem_index, bool safety_check_on) |
| 571 | { | 582 | { |
| 572 | IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, source_node); | 583 | IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node); |
| 573 | instruction->array_ptr = array_ptr; | 584 | instruction->array_ptr = array_ptr; |
| 574 | instruction->elem_index = elem_index; | 585 | instruction->elem_index = elem_index; |
| 575 | instruction->safety_check_on = safety_check_on; | 586 | instruction->safety_check_on = safety_check_on; |
| ... | @@ -583,16 +594,16 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, AstNode *source_node, Ir | ... | @@ -583,16 +594,16 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, AstNode *source_node, Ir |
| 583 | static IrInstruction *ir_build_elem_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, | 594 | static IrInstruction *ir_build_elem_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 584 | IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on) | 595 | IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on) |
| 585 | { | 596 | { |
| 586 | IrInstruction *new_instruction = ir_build_elem_ptr(irb, old_instruction->source_node, array_ptr, elem_index, | 597 | IrInstruction *new_instruction = ir_build_elem_ptr(irb, old_instruction->scope, |
| 587 | safety_check_on); | 598 | old_instruction->source_node, array_ptr, elem_index, safety_check_on); |
| 588 | ir_link_new_instruction(new_instruction, old_instruction); | 599 | ir_link_new_instruction(new_instruction, old_instruction); |
| 589 | return new_instruction; | 600 | return new_instruction; |
| 590 | } | 601 | } |
| 591 | | 602 | |
| 592 | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, AstNode *source_node, | 603 | static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 593 | IrInstruction *container_ptr, Buf *field_name) | 604 | IrInstruction *container_ptr, Buf *field_name) |
| 594 | { | 605 | { |
| 595 | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, source_node); | 606 | IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node); |
| 596 | instruction->container_ptr = container_ptr; | 607 | instruction->container_ptr = container_ptr; |
| 597 | instruction->field_name = field_name; | 608 | instruction->field_name = field_name; |
| 598 | | 609 | |
| ... | @@ -601,10 +612,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, AstNode *source_node, | ... | @@ -601,10 +612,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, AstNode *source_node, |
| 601 | return &instruction->base; | 612 | return &instruction->base; |
| 602 | } | 613 | } |
| 603 | | 614 | |
| 604 | static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, AstNode *source_node, | 615 | static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 605 | IrInstruction *struct_ptr, TypeStructField *field) | 616 | IrInstruction *struct_ptr, TypeStructField *field) |
| 606 | { | 617 | { |
| 607 | IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, source_node); | 618 | IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node); |
| 608 | instruction->struct_ptr = struct_ptr; | 619 | instruction->struct_ptr = struct_ptr; |
| 609 | instruction->field = field; | 620 | instruction->field = field; |
| 610 | | 621 | |
| ... | @@ -616,16 +627,16 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, AstNode *source_ | ... | @@ -616,16 +627,16 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, AstNode *source_ |
| 616 | static IrInstruction *ir_build_struct_field_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, | 627 | static IrInstruction *ir_build_struct_field_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 617 | IrInstruction *struct_ptr, TypeStructField *type_struct_field) | 628 | IrInstruction *struct_ptr, TypeStructField *type_struct_field) |
| 618 | { | 629 | { |
| 619 | IrInstruction *new_instruction = ir_build_struct_field_ptr(irb, old_instruction->source_node, | 630 | IrInstruction *new_instruction = ir_build_struct_field_ptr(irb, old_instruction->scope, |
| 620 | struct_ptr, type_struct_field); | 631 | old_instruction->source_node, struct_ptr, type_struct_field); |
| 621 | ir_link_new_instruction(new_instruction, old_instruction); | 632 | ir_link_new_instruction(new_instruction, old_instruction); |
| 622 | return new_instruction; | 633 | return new_instruction; |
| 623 | } | 634 | } |
| 624 | | 635 | |
| 625 | static IrInstruction *ir_build_enum_field_ptr(IrBuilder *irb, AstNode *source_node, | 636 | static IrInstruction *ir_build_enum_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 626 | IrInstruction *enum_ptr, TypeEnumField *field) | 637 | IrInstruction *enum_ptr, TypeEnumField *field) |
| 627 | { | 638 | { |
| 628 | IrInstructionEnumFieldPtr *instruction = ir_build_instruction<IrInstructionEnumFieldPtr>(irb, source_node); | 639 | IrInstructionEnumFieldPtr *instruction = ir_build_instruction<IrInstructionEnumFieldPtr>(irb, scope, source_node); |
| 629 | instruction->enum_ptr = enum_ptr; | 640 | instruction->enum_ptr = enum_ptr; |
| 630 | instruction->field = field; | 641 | instruction->field = field; |
| 631 | | 642 | |
| ... | @@ -637,16 +648,16 @@ static IrInstruction *ir_build_enum_field_ptr(IrBuilder *irb, AstNode *source_no | ... | @@ -637,16 +648,16 @@ static IrInstruction *ir_build_enum_field_ptr(IrBuilder *irb, AstNode *source_no |
| 637 | static IrInstruction *ir_build_enum_field_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, | 648 | static IrInstruction *ir_build_enum_field_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 638 | IrInstruction *enum_ptr, TypeEnumField *type_enum_field) | 649 | IrInstruction *enum_ptr, TypeEnumField *type_enum_field) |
| 639 | { | 650 | { |
| 640 | IrInstruction *new_instruction = ir_build_enum_field_ptr(irb, old_instruction->source_node, | 651 | IrInstruction *new_instruction = ir_build_enum_field_ptr(irb, old_instruction->scope, |
| 641 | enum_ptr, type_enum_field); | 652 | old_instruction->source_node, enum_ptr, type_enum_field); |
| 642 | ir_link_new_instruction(new_instruction, old_instruction); | 653 | ir_link_new_instruction(new_instruction, old_instruction); |
| 643 | return new_instruction; | 654 | return new_instruction; |
| 644 | } | 655 | } |
| 645 | | 656 | |
| 646 | static IrInstruction *ir_build_call(IrBuilder *irb, AstNode *source_node, | 657 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 647 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args) | 658 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args) |
| 648 | { | 659 | { |
| 649 | IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, source_node); | 660 | IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, scope, source_node); |
| 650 | call_instruction->fn_entry = fn_entry; | 661 | call_instruction->fn_entry = fn_entry; |
| 651 | call_instruction->fn_ref = fn_ref; | 662 | call_instruction->fn_ref = fn_ref; |
| 652 | call_instruction->arg_count = arg_count; | 663 | call_instruction->arg_count = arg_count; |
| ... | @@ -663,18 +674,19 @@ static IrInstruction *ir_build_call(IrBuilder *irb, AstNode *source_node, | ... | @@ -663,18 +674,19 @@ static IrInstruction *ir_build_call(IrBuilder *irb, AstNode *source_node, |
| 663 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, | 674 | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 664 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args) | 675 | FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args) |
| 665 | { | 676 | { |
| 666 | IrInstruction *new_instruction = ir_build_call(irb, old_instruction->source_node, fn_entry, fn_ref, arg_count, args); | 677 | IrInstruction *new_instruction = ir_build_call(irb, old_instruction->scope, |
| | 678 | old_instruction->source_node, fn_entry, fn_ref, arg_count, args); |
| 667 | ir_link_new_instruction(new_instruction, old_instruction); | 679 | ir_link_new_instruction(new_instruction, old_instruction); |
| 668 | return new_instruction; | 680 | return new_instruction; |
| 669 | } | 681 | } |
| 670 | | 682 | |
| 671 | static IrInstruction *ir_build_phi(IrBuilder *irb, AstNode *source_node, | 683 | static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 672 | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) | 684 | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) |
| 673 | { | 685 | { |
| 674 | assert(incoming_count != 0); | 686 | assert(incoming_count != 0); |
| 675 | assert(incoming_count != SIZE_MAX); | 687 | assert(incoming_count != SIZE_MAX); |
| 676 | | 688 | |
| 677 | IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, source_node); | 689 | IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node); |
| 678 | phi_instruction->incoming_count = incoming_count; | 690 | phi_instruction->incoming_count = incoming_count; |
| 679 | phi_instruction->incoming_blocks = incoming_blocks; | 691 | phi_instruction->incoming_blocks = incoming_blocks; |
| 680 | phi_instruction->incoming_values = incoming_values; | 692 | phi_instruction->incoming_values = incoming_values; |
| ... | @@ -690,14 +702,16 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, AstNode *source_node, | ... | @@ -690,14 +702,16 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, AstNode *source_node, |
| 690 | static IrInstruction *ir_build_phi_from(IrBuilder *irb, IrInstruction *old_instruction, | 702 | static IrInstruction *ir_build_phi_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 691 | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) | 703 | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) |
| 692 | { | 704 | { |
| 693 | IrInstruction *new_instruction = ir_build_phi(irb, old_instruction->source_node, | 705 | IrInstruction *new_instruction = ir_build_phi(irb, old_instruction->scope, old_instruction->source_node, |
| 694 | incoming_count, incoming_blocks, incoming_values); | 706 | incoming_count, incoming_blocks, incoming_values); |
| 695 | ir_link_new_instruction(new_instruction, old_instruction); | 707 | ir_link_new_instruction(new_instruction, old_instruction); |
| 696 | return new_instruction; | 708 | return new_instruction; |
| 697 | } | 709 | } |
| 698 | | 710 | |
| 699 | static IrInstruction *ir_create_br(IrBuilder *irb, AstNode *source_node, IrBasicBlock *dest_block, bool is_inline) { | 711 | static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 700 | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb->exec, source_node); | 712 | IrBasicBlock *dest_block, bool is_inline) |
| | 713 | { |
| | 714 | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb->exec, scope, source_node); |
| 701 | br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; | 715 | br_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 702 | br_instruction->base.static_value.special = ConstValSpecialStatic; | 716 | br_instruction->base.static_value.special = ConstValSpecialStatic; |
| 703 | br_instruction->dest_block = dest_block; | 717 | br_instruction->dest_block = dest_block; |
| ... | @@ -708,20 +722,23 @@ static IrInstruction *ir_create_br(IrBuilder *irb, AstNode *source_node, IrBasic | ... | @@ -708,20 +722,23 @@ static IrInstruction *ir_create_br(IrBuilder *irb, AstNode *source_node, IrBasic |
| 708 | return &br_instruction->base; | 722 | return &br_instruction->base; |
| 709 | } | 723 | } |
| 710 | | 724 | |
| 711 | static IrInstruction *ir_build_br(IrBuilder *irb, AstNode *source_node, IrBasicBlock *dest_block, bool is_inline) { | 725 | static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 712 | IrInstruction *instruction = ir_create_br(irb, source_node, dest_block, is_inline); | 726 | IrBasicBlock *dest_block, bool is_inline) |
| | 727 | { |
| | 728 | IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_inline); |
| 713 | ir_instruction_append(irb->current_basic_block, instruction); | 729 | ir_instruction_append(irb->current_basic_block, instruction); |
| 714 | return instruction; | 730 | return instruction; |
| 715 | } | 731 | } |
| 716 | | 732 | |
| 717 | static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instruction, IrBasicBlock *dest_block) { | 733 | static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instruction, IrBasicBlock *dest_block) { |
| 718 | IrInstruction *new_instruction = ir_build_br(irb, old_instruction->source_node, dest_block, false); | 734 | IrInstruction *new_instruction = ir_build_br(irb, old_instruction->scope, |
| | 735 | old_instruction->source_node, dest_block, false); |
| 719 | ir_link_new_instruction(new_instruction, old_instruction); | 736 | ir_link_new_instruction(new_instruction, old_instruction); |
| 720 | return new_instruction; | 737 | return new_instruction; |
| 721 | } | 738 | } |
| 722 | | 739 | |
| 723 | static IrInstruction *ir_build_un_op(IrBuilder *irb, AstNode *source_node, IrUnOp op_id, IrInstruction *value) { | 740 | static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id, IrInstruction *value) { |
| 724 | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, source_node); | 741 | IrInstructionUnOp *br_instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node); |
| 725 | br_instruction->op_id = op_id; | 742 | br_instruction->op_id = op_id; |
| 726 | br_instruction->value = value; | 743 | br_instruction->value = value; |
| 727 | | 744 | |
| ... | @@ -733,16 +750,17 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, AstNode *source_node, IrUnO | ... | @@ -733,16 +750,17 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, AstNode *source_node, IrUnO |
| 733 | static IrInstruction *ir_build_un_op_from(IrBuilder *irb, IrInstruction *old_instruction, | 750 | static IrInstruction *ir_build_un_op_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 734 | IrUnOp op_id, IrInstruction *value) | 751 | IrUnOp op_id, IrInstruction *value) |
| 735 | { | 752 | { |
| 736 | IrInstruction *new_instruction = ir_build_un_op(irb, old_instruction->source_node, op_id, value); | 753 | IrInstruction *new_instruction = ir_build_un_op(irb, old_instruction->scope, |
| | 754 | old_instruction->source_node, op_id, value); |
| 737 | ir_link_new_instruction(new_instruction, old_instruction); | 755 | ir_link_new_instruction(new_instruction, old_instruction); |
| 738 | return new_instruction; | 756 | return new_instruction; |
| 739 | } | 757 | } |
| 740 | | 758 | |
| 741 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, AstNode *source_node, | 759 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 742 | IrInstruction *container_type, size_t item_count, IrInstruction **items) | 760 | IrInstruction *container_type, size_t item_count, IrInstruction **items) |
| 743 | { | 761 | { |
| 744 | IrInstructionContainerInitList *container_init_list_instruction = | 762 | IrInstructionContainerInitList *container_init_list_instruction = |
| 745 | ir_build_instruction<IrInstructionContainerInitList>(irb, source_node); | 763 | ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node); |
| 746 | container_init_list_instruction->container_type = container_type; | 764 | container_init_list_instruction->container_type = container_type; |
| 747 | container_init_list_instruction->item_count = item_count; | 765 | container_init_list_instruction->item_count = item_count; |
| 748 | container_init_list_instruction->items = items; | 766 | container_init_list_instruction->items = items; |
| ... | @@ -758,17 +776,17 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, AstNode *sour | ... | @@ -758,17 +776,17 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, AstNode *sour |
| 758 | static IrInstruction *ir_build_container_init_list_from(IrBuilder *irb, IrInstruction *old_instruction, | 776 | static IrInstruction *ir_build_container_init_list_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 759 | IrInstruction *container_type, size_t item_count, IrInstruction **items) | 777 | IrInstruction *container_type, size_t item_count, IrInstruction **items) |
| 760 | { | 778 | { |
| 761 | IrInstruction *new_instruction = ir_build_container_init_list(irb, old_instruction->source_node, | 779 | IrInstruction *new_instruction = ir_build_container_init_list(irb, old_instruction->scope, |
| 762 | container_type, item_count, items); | 780 | old_instruction->source_node, container_type, item_count, items); |
| 763 | ir_link_new_instruction(new_instruction, old_instruction); | 781 | ir_link_new_instruction(new_instruction, old_instruction); |
| 764 | return new_instruction; | 782 | return new_instruction; |
| 765 | } | 783 | } |
| 766 | | 784 | |
| 767 | static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, AstNode *source_node, | 785 | static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 768 | IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields) | 786 | IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields) |
| 769 | { | 787 | { |
| 770 | IrInstructionContainerInitFields *container_init_fields_instruction = | 788 | IrInstructionContainerInitFields *container_init_fields_instruction = |
| 771 | ir_build_instruction<IrInstructionContainerInitFields>(irb, source_node); | 789 | ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node); |
| 772 | container_init_fields_instruction->container_type = container_type; | 790 | container_init_fields_instruction->container_type = container_type; |
| 773 | container_init_fields_instruction->field_count = field_count; | 791 | container_init_fields_instruction->field_count = field_count; |
| 774 | container_init_fields_instruction->fields = fields; | 792 | container_init_fields_instruction->fields = fields; |
| ... | @@ -781,10 +799,10 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, AstNode *so | ... | @@ -781,10 +799,10 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, AstNode *so |
| 781 | return &container_init_fields_instruction->base; | 799 | return &container_init_fields_instruction->base; |
| 782 | } | 800 | } |
| 783 | | 801 | |
| 784 | static IrInstruction *ir_build_struct_init(IrBuilder *irb, AstNode *source_node, | 802 | static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 785 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) | 803 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) |
| 786 | { | 804 | { |
| 787 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, source_node); | 805 | IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node); |
| 788 | struct_init_instruction->struct_type = struct_type; | 806 | struct_init_instruction->struct_type = struct_type; |
| 789 | struct_init_instruction->field_count = field_count; | 807 | struct_init_instruction->field_count = field_count; |
| 790 | struct_init_instruction->fields = fields; | 808 | struct_init_instruction->fields = fields; |
| ... | @@ -798,30 +816,30 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, AstNode *source_node, | ... | @@ -798,30 +816,30 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, AstNode *source_node, |
| 798 | static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, | 816 | static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 799 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) | 817 | TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) |
| 800 | { | 818 | { |
| 801 | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->source_node, | 819 | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, |
| 802 | struct_type, field_count, fields); | 820 | old_instruction->source_node, struct_type, field_count, fields); |
| 803 | ir_link_new_instruction(new_instruction, old_instruction); | 821 | ir_link_new_instruction(new_instruction, old_instruction); |
| 804 | return new_instruction; | 822 | return new_instruction; |
| 805 | } | 823 | } |
| 806 | | 824 | |
| 807 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, AstNode *source_node) { | 825 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 808 | IrInstructionUnreachable *unreachable_instruction = | 826 | IrInstructionUnreachable *unreachable_instruction = |
| 809 | ir_build_instruction<IrInstructionUnreachable>(irb, source_node); | 827 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| 810 | unreachable_instruction->base.static_value.special = ConstValSpecialStatic; | 828 | unreachable_instruction->base.static_value.special = ConstValSpecialStatic; |
| 811 | unreachable_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; | 829 | unreachable_instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 812 | return &unreachable_instruction->base; | 830 | return &unreachable_instruction->base; |
| 813 | } | 831 | } |
| 814 | | 832 | |
| 815 | static IrInstruction *ir_build_unreachable_from(IrBuilder *irb, IrInstruction *old_instruction) { | 833 | static IrInstruction *ir_build_unreachable_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 816 | IrInstruction *new_instruction = ir_build_unreachable(irb, old_instruction->source_node); | 834 | IrInstruction *new_instruction = ir_build_unreachable(irb, old_instruction->scope, old_instruction->source_node); |
| 817 | ir_link_new_instruction(new_instruction, old_instruction); | 835 | ir_link_new_instruction(new_instruction, old_instruction); |
| 818 | return new_instruction; | 836 | return new_instruction; |
| 819 | } | 837 | } |
| 820 | | 838 | |
| 821 | static IrInstruction *ir_build_store_ptr(IrBuilder *irb, AstNode *source_node, | 839 | static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 822 | IrInstruction *ptr, IrInstruction *value) | 840 | IrInstruction *ptr, IrInstruction *value) |
| 823 | { | 841 | { |
| 824 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, source_node); | 842 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| 825 | instruction->base.static_value.special = ConstValSpecialStatic; | 843 | instruction->base.static_value.special = ConstValSpecialStatic; |
| 826 | instruction->base.type_entry = irb->codegen->builtin_types.entry_void; | 844 | instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 827 | instruction->ptr = ptr; | 845 | instruction->ptr = ptr; |
| ... | @@ -836,15 +854,16 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, AstNode *source_node, | ... | @@ -836,15 +854,16 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, AstNode *source_node, |
| 836 | static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, | 854 | static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 837 | IrInstruction *ptr, IrInstruction *value) | 855 | IrInstruction *ptr, IrInstruction *value) |
| 838 | { | 856 | { |
| 839 | IrInstruction *new_instruction = ir_build_store_ptr(irb, old_instruction->source_node, ptr, value); | 857 | IrInstruction *new_instruction = ir_build_store_ptr(irb, old_instruction->scope, |
| | 858 | old_instruction->source_node, ptr, value); |
| 840 | ir_link_new_instruction(new_instruction, old_instruction); | 859 | ir_link_new_instruction(new_instruction, old_instruction); |
| 841 | return new_instruction; | 860 | return new_instruction; |
| 842 | } | 861 | } |
| 843 | | 862 | |
| 844 | static IrInstruction *ir_build_var_decl(IrBuilder *irb, AstNode *source_node, | 863 | static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 845 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value) | 864 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value) |
| 846 | { | 865 | { |
| 847 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, source_node); | 866 | IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node); |
| 848 | decl_var_instruction->base.static_value.special = ConstValSpecialStatic; | 867 | decl_var_instruction->base.static_value.special = ConstValSpecialStatic; |
| 849 | decl_var_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; | 868 | decl_var_instruction->base.type_entry = irb->codegen->builtin_types.entry_void; |
| 850 | decl_var_instruction->var = var; | 869 | decl_var_instruction->var = var; |
| ... | @@ -860,13 +879,14 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, AstNode *source_node, | ... | @@ -860,13 +879,14 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, AstNode *source_node, |
| 860 | static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, | 879 | static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 861 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value) | 880 | VariableTableEntry *var, IrInstruction *var_type, IrInstruction *init_value) |
| 862 | { | 881 | { |
| 863 | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->source_node, var, var_type, init_value); | 882 | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, |
| | 883 | old_instruction->source_node, var, var_type, init_value); |
| 864 | ir_link_new_instruction(new_instruction, old_instruction); | 884 | ir_link_new_instruction(new_instruction, old_instruction); |
| 865 | return new_instruction; | 885 | return new_instruction; |
| 866 | } | 886 | } |
| 867 | | 887 | |
| 868 | static IrInstruction *ir_build_load_ptr(IrBuilder *irb, AstNode *source_node, IrInstruction *ptr) { | 888 | static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) { |
| 869 | IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, source_node); | 889 | IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node); |
| 870 | instruction->ptr = ptr; | 890 | instruction->ptr = ptr; |
| 871 | | 891 | |
| 872 | ir_ref_instruction(ptr); | 892 | ir_ref_instruction(ptr); |
| ... | @@ -875,13 +895,14 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, AstNode *source_node, Ir | ... | @@ -875,13 +895,14 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, AstNode *source_node, Ir |
| 875 | } | 895 | } |
| 876 | | 896 | |
| 877 | static IrInstruction *ir_build_load_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *ptr) { | 897 | static IrInstruction *ir_build_load_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *ptr) { |
| 878 | IrInstruction *new_instruction = ir_build_load_ptr(irb, old_instruction->source_node, ptr); | 898 | IrInstruction *new_instruction = ir_build_load_ptr(irb, old_instruction->scope, |
| | 899 | old_instruction->source_node, ptr); |
| 879 | ir_link_new_instruction(new_instruction, old_instruction); | 900 | ir_link_new_instruction(new_instruction, old_instruction); |
| 880 | return new_instruction; | 901 | return new_instruction; |
| 881 | } | 902 | } |
| 882 | | 903 | |
| 883 | static IrInstruction *ir_build_typeof(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 904 | static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 884 | IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, source_node); | 905 | IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node); |
| 885 | instruction->value = value; | 906 | instruction->value = value; |
| 886 | | 907 | |
| 887 | ir_ref_instruction(value); | 908 | ir_ref_instruction(value); |
| ... | @@ -889,8 +910,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, AstNode *source_node, IrIn | ... | @@ -889,8 +910,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, AstNode *source_node, IrIn |
| 889 | return &instruction->base; | 910 | return &instruction->base; |
| 890 | } | 911 | } |
| 891 | | 912 | |
| 892 | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 913 | static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 893 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, source_node); | 914 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); |
| 894 | instruction->value = value; | 915 | instruction->value = value; |
| 895 | | 916 | |
| 896 | ir_ref_instruction(value); | 917 | ir_ref_instruction(value); |
| ... | @@ -898,8 +919,8 @@ static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, AstNode *source_node, | ... | @@ -898,8 +919,8 @@ static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, AstNode *source_node, |
| 898 | return &instruction->base; | 919 | return &instruction->base; |
| 899 | } | 920 | } |
| 900 | | 921 | |
| 901 | static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 922 | static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 902 | IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>(irb, source_node); | 923 | IrInstructionPtrTypeChild *instruction = ir_build_instruction<IrInstructionPtrTypeChild>(irb, scope, source_node); |
| 903 | instruction->value = value; | 924 | instruction->value = value; |
| 904 | | 925 | |
| 905 | ir_ref_instruction(value); | 926 | ir_ref_instruction(value); |
| ... | @@ -907,10 +928,10 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, AstNode *source_no | ... | @@ -907,10 +928,10 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, AstNode *source_no |
| 907 | return &instruction->base; | 928 | return &instruction->base; |
| 908 | } | 929 | } |
| 909 | | 930 | |
| 910 | static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, AstNode *source_node, IrInstruction *fn_value, | 931 | static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn_value, |
| 911 | IrInstruction *is_test) | 932 | IrInstruction *is_test) |
| 912 | { | 933 | { |
| 913 | IrInstructionSetFnTest *instruction = ir_build_instruction<IrInstructionSetFnTest>(irb, source_node); | 934 | IrInstructionSetFnTest *instruction = ir_build_instruction<IrInstructionSetFnTest>(irb, scope, source_node); |
| 914 | instruction->fn_value = fn_value; | 935 | instruction->fn_value = fn_value; |
| 915 | instruction->is_test = is_test; | 936 | instruction->is_test = is_test; |
| 916 | | 937 | |
| ... | @@ -920,10 +941,10 @@ static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, AstNode *source_node, | ... | @@ -920,10 +941,10 @@ static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, AstNode *source_node, |
| 920 | return &instruction->base; | 941 | return &instruction->base; |
| 921 | } | 942 | } |
| 922 | | 943 | |
| 923 | static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, AstNode *source_node, IrInstruction *fn_value, | 944 | static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn_value, |
| 924 | IrInstruction *is_visible) | 945 | IrInstruction *is_visible) |
| 925 | { | 946 | { |
| 926 | IrInstructionSetFnVisible *instruction = ir_build_instruction<IrInstructionSetFnVisible>(irb, source_node); | 947 | IrInstructionSetFnVisible *instruction = ir_build_instruction<IrInstructionSetFnVisible>(irb, scope, source_node); |
| 927 | instruction->fn_value = fn_value; | 948 | instruction->fn_value = fn_value; |
| 928 | instruction->is_visible = is_visible; | 949 | instruction->is_visible = is_visible; |
| 929 | | 950 | |
| ... | @@ -933,10 +954,10 @@ static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, AstNode *source_no | ... | @@ -933,10 +954,10 @@ static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, AstNode *source_no |
| 933 | return &instruction->base; | 954 | return &instruction->base; |
| 934 | } | 955 | } |
| 935 | | 956 | |
| 936 | static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, AstNode *source_node, | 957 | static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 937 | IrInstruction *scope_value, IrInstruction *debug_safety_on) | 958 | IrInstruction *scope_value, IrInstruction *debug_safety_on) |
| 938 | { | 959 | { |
| 939 | IrInstructionSetDebugSafety *instruction = ir_build_instruction<IrInstructionSetDebugSafety>(irb, source_node); | 960 | IrInstructionSetDebugSafety *instruction = ir_build_instruction<IrInstructionSetDebugSafety>(irb, scope, source_node); |
| 940 | instruction->scope_value = scope_value; | 961 | instruction->scope_value = scope_value; |
| 941 | instruction->debug_safety_on = debug_safety_on; | 962 | instruction->debug_safety_on = debug_safety_on; |
| 942 | | 963 | |
| ... | @@ -946,10 +967,10 @@ static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, AstNode *source_ | ... | @@ -946,10 +967,10 @@ static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, AstNode *source_ |
| 946 | return &instruction->base; | 967 | return &instruction->base; |
| 947 | } | 968 | } |
| 948 | | 969 | |
| 949 | static IrInstruction *ir_build_array_type(IrBuilder *irb, AstNode *source_node, IrInstruction *size, | 970 | static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size, |
| 950 | IrInstruction *child_type) | 971 | IrInstruction *child_type) |
| 951 | { | 972 | { |
| 952 | IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, source_node); | 973 | IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node); |
| 953 | instruction->size = size; | 974 | instruction->size = size; |
| 954 | instruction->child_type = child_type; | 975 | instruction->child_type = child_type; |
| 955 | | 976 | |
| ... | @@ -959,10 +980,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, AstNode *source_node, | ... | @@ -959,10 +980,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, AstNode *source_node, |
| 959 | return &instruction->base; | 980 | return &instruction->base; |
| 960 | } | 981 | } |
| 961 | | 982 | |
| 962 | static IrInstruction *ir_build_slice_type(IrBuilder *irb, AstNode *source_node, bool is_const, | 983 | static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node, bool is_const, |
| 963 | IrInstruction *child_type) | 984 | IrInstruction *child_type) |
| 964 | { | 985 | { |
| 965 | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, source_node); | 986 | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node); |
| 966 | instruction->is_const = is_const; | 987 | instruction->is_const = is_const; |
| 967 | instruction->child_type = child_type; | 988 | instruction->child_type = child_type; |
| 968 | | 989 | |
| ... | @@ -971,12 +992,13 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, AstNode *source_node, | ... | @@ -971,12 +992,13 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, AstNode *source_node, |
| 971 | return &instruction->base; | 992 | return &instruction->base; |
| 972 | } | 993 | } |
| 973 | | 994 | |
| 974 | static IrInstruction *ir_build_asm(IrBuilder *irb, AstNode *source_node, IrInstruction **input_list, | 995 | static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list, |
| 975 | IrInstruction **output_types, size_t return_count, bool has_side_effects) | 996 | IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) |
| 976 | { | 997 | { |
| 977 | IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, source_node); | 998 | IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node); |
| 978 | instruction->input_list = input_list; | 999 | instruction->input_list = input_list; |
| 979 | instruction->output_types = output_types; | 1000 | instruction->output_types = output_types; |
| | 1001 | instruction->output_vars = output_vars; |
| 980 | instruction->return_count = return_count; | 1002 | instruction->return_count = return_count; |
| 981 | instruction->has_side_effects = has_side_effects; | 1003 | instruction->has_side_effects = has_side_effects; |
| 982 | | 1004 | |
| ... | @@ -995,16 +1017,16 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, AstNode *source_node, IrInstr | ... | @@ -995,16 +1017,16 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, AstNode *source_node, IrInstr |
| 995 | } | 1017 | } |
| 996 | | 1018 | |
| 997 | static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, | 1019 | static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, |
| 998 | IrInstruction **output_types, size_t return_count, bool has_side_effects) | 1020 | IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) |
| 999 | { | 1021 | { |
| 1000 | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->source_node, input_list, output_types, | 1022 | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, |
| 1001 | return_count, has_side_effects); | 1023 | old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects); |
| 1002 | ir_link_new_instruction(new_instruction, old_instruction); | 1024 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1003 | return new_instruction; | 1025 | return new_instruction; |
| 1004 | } | 1026 | } |
| 1005 | | 1027 | |
| 1006 | static IrInstruction *ir_build_compile_var(IrBuilder *irb, AstNode *source_node, IrInstruction *name) { | 1028 | static IrInstruction *ir_build_compile_var(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 1007 | IrInstructionCompileVar *instruction = ir_build_instruction<IrInstructionCompileVar>(irb, source_node); | 1029 | IrInstructionCompileVar *instruction = ir_build_instruction<IrInstructionCompileVar>(irb, scope, source_node); |
| 1008 | instruction->name = name; | 1030 | instruction->name = name; |
| 1009 | | 1031 | |
| 1010 | ir_ref_instruction(name); | 1032 | ir_ref_instruction(name); |
| ... | @@ -1012,8 +1034,8 @@ static IrInstruction *ir_build_compile_var(IrBuilder *irb, AstNode *source_node, | ... | @@ -1012,8 +1034,8 @@ static IrInstruction *ir_build_compile_var(IrBuilder *irb, AstNode *source_node, |
| 1012 | return &instruction->base; | 1034 | return &instruction->base; |
| 1013 | } | 1035 | } |
| 1014 | | 1036 | |
| 1015 | static IrInstruction *ir_build_size_of(IrBuilder *irb, AstNode *source_node, IrInstruction *type_value) { | 1037 | static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) { |
| 1016 | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, source_node); | 1038 | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node); |
| 1017 | instruction->type_value = type_value; | 1039 | instruction->type_value = type_value; |
| 1018 | | 1040 | |
| 1019 | ir_ref_instruction(type_value); | 1041 | ir_ref_instruction(type_value); |
| ... | @@ -1021,8 +1043,8 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, AstNode *source_node, IrI | ... | @@ -1021,8 +1043,8 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, AstNode *source_node, IrI |
| 1021 | return &instruction->base; | 1043 | return &instruction->base; |
| 1022 | } | 1044 | } |
| 1023 | | 1045 | |
| 1024 | static IrInstruction *ir_build_test_null(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1046 | static IrInstruction *ir_build_test_null(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1025 | IrInstructionTestNull *instruction = ir_build_instruction<IrInstructionTestNull>(irb, source_node); | 1047 | IrInstructionTestNull *instruction = ir_build_instruction<IrInstructionTestNull>(irb, scope, source_node); |
| 1026 | instruction->value = value; | 1048 | instruction->value = value; |
| 1027 | | 1049 | |
| 1028 | ir_ref_instruction(value); | 1050 | ir_ref_instruction(value); |
| ... | @@ -1033,15 +1055,16 @@ static IrInstruction *ir_build_test_null(IrBuilder *irb, AstNode *source_node, I | ... | @@ -1033,15 +1055,16 @@ static IrInstruction *ir_build_test_null(IrBuilder *irb, AstNode *source_node, I |
| 1033 | static IrInstruction *ir_build_test_null_from(IrBuilder *irb, IrInstruction *old_instruction, | 1055 | static IrInstruction *ir_build_test_null_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1034 | IrInstruction *value) | 1056 | IrInstruction *value) |
| 1035 | { | 1057 | { |
| 1036 | IrInstruction *new_instruction = ir_build_test_null(irb, old_instruction->source_node, value); | 1058 | IrInstruction *new_instruction = ir_build_test_null(irb, old_instruction->scope, |
| | 1059 | old_instruction->source_node, value); |
| 1037 | ir_link_new_instruction(new_instruction, old_instruction); | 1060 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1038 | return new_instruction; | 1061 | return new_instruction; |
| 1039 | } | 1062 | } |
| 1040 | | 1063 | |
| 1041 | static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, AstNode *source_node, IrInstruction *value, | 1064 | static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, |
| 1042 | bool safety_check_on) | 1065 | bool safety_check_on) |
| 1043 | { | 1066 | { |
| 1044 | IrInstructionUnwrapMaybe *instruction = ir_build_instruction<IrInstructionUnwrapMaybe>(irb, source_node); | 1067 | IrInstructionUnwrapMaybe *instruction = ir_build_instruction<IrInstructionUnwrapMaybe>(irb, scope, source_node); |
| 1045 | instruction->value = value; | 1068 | instruction->value = value; |
| 1046 | instruction->safety_check_on = safety_check_on; | 1069 | instruction->safety_check_on = safety_check_on; |
| 1047 | | 1070 | |
| ... | @@ -1053,14 +1076,14 @@ static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, AstNode *source_node | ... | @@ -1053,14 +1076,14 @@ static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, AstNode *source_node |
| 1053 | static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *old_instruction, | 1076 | static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1054 | IrInstruction *value, bool safety_check_on) | 1077 | IrInstruction *value, bool safety_check_on) |
| 1055 | { | 1078 | { |
| 1056 | IrInstruction *new_instruction = ir_build_unwrap_maybe(irb, old_instruction->source_node, | 1079 | IrInstruction *new_instruction = ir_build_unwrap_maybe(irb, old_instruction->scope, old_instruction->source_node, |
| 1057 | value, safety_check_on); | 1080 | value, safety_check_on); |
| 1058 | ir_link_new_instruction(new_instruction, old_instruction); | 1081 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1059 | return new_instruction; | 1082 | return new_instruction; |
| 1060 | } | 1083 | } |
| 1061 | | 1084 | |
| 1062 | static IrInstruction *ir_build_clz(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1085 | static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1063 | IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, source_node); | 1086 | IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node); |
| 1064 | instruction->value = value; | 1087 | instruction->value = value; |
| 1065 | | 1088 | |
| 1066 | ir_ref_instruction(value); | 1089 | ir_ref_instruction(value); |
| ... | @@ -1069,13 +1092,13 @@ static IrInstruction *ir_build_clz(IrBuilder *irb, AstNode *source_node, IrInstr | ... | @@ -1069,13 +1092,13 @@ static IrInstruction *ir_build_clz(IrBuilder *irb, AstNode *source_node, IrInstr |
| 1069 | } | 1092 | } |
| 1070 | | 1093 | |
| 1071 | static IrInstruction *ir_build_clz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { | 1094 | static IrInstruction *ir_build_clz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1072 | IrInstruction *new_instruction = ir_build_clz(irb, old_instruction->source_node, value); | 1095 | IrInstruction *new_instruction = ir_build_clz(irb, old_instruction->scope, old_instruction->source_node, value); |
| 1073 | ir_link_new_instruction(new_instruction, old_instruction); | 1096 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1074 | return new_instruction; | 1097 | return new_instruction; |
| 1075 | } | 1098 | } |
| 1076 | | 1099 | |
| 1077 | static IrInstruction *ir_build_ctz(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1100 | static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1078 | IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, source_node); | 1101 | IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node); |
| 1079 | instruction->value = value; | 1102 | instruction->value = value; |
| 1080 | | 1103 | |
| 1081 | ir_ref_instruction(value); | 1104 | ir_ref_instruction(value); |
| ... | @@ -1084,15 +1107,15 @@ static IrInstruction *ir_build_ctz(IrBuilder *irb, AstNode *source_node, IrInstr | ... | @@ -1084,15 +1107,15 @@ static IrInstruction *ir_build_ctz(IrBuilder *irb, AstNode *source_node, IrInstr |
| 1084 | } | 1107 | } |
| 1085 | | 1108 | |
| 1086 | static IrInstruction *ir_build_ctz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { | 1109 | static IrInstruction *ir_build_ctz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1087 | IrInstruction *new_instruction = ir_build_ctz(irb, old_instruction->source_node, value); | 1110 | IrInstruction *new_instruction = ir_build_ctz(irb, old_instruction->scope, old_instruction->source_node, value); |
| 1088 | ir_link_new_instruction(new_instruction, old_instruction); | 1111 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1089 | return new_instruction; | 1112 | return new_instruction; |
| 1090 | } | 1113 | } |
| 1091 | | 1114 | |
| 1092 | static IrInstruction *ir_build_switch_br(IrBuilder *irb, AstNode *source_node, IrInstruction *target_value, | 1115 | static IrInstruction *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value, |
| 1093 | IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, bool is_inline) | 1116 | IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, bool is_inline) |
| 1094 | { | 1117 | { |
| 1095 | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, source_node); | 1118 | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); |
| 1096 | instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; | 1119 | instruction->base.type_entry = irb->codegen->builtin_types.entry_unreachable; |
| 1097 | instruction->base.static_value.special = ConstValSpecialStatic; | 1120 | instruction->base.static_value.special = ConstValSpecialStatic; |
| 1098 | instruction->target_value = target_value; | 1121 | instruction->target_value = target_value; |
| ... | @@ -1116,16 +1139,16 @@ static IrInstruction *ir_build_switch_br_from(IrBuilder *irb, IrInstruction *old | ... | @@ -1116,16 +1139,16 @@ static IrInstruction *ir_build_switch_br_from(IrBuilder *irb, IrInstruction *old |
| 1116 | IrInstruction *target_value, IrBasicBlock *else_block, size_t case_count, | 1139 | IrInstruction *target_value, IrBasicBlock *else_block, size_t case_count, |
| 1117 | IrInstructionSwitchBrCase *cases, bool is_inline) | 1140 | IrInstructionSwitchBrCase *cases, bool is_inline) |
| 1118 | { | 1141 | { |
| 1119 | IrInstruction *new_instruction = ir_build_switch_br(irb, old_instruction->source_node, | 1142 | IrInstruction *new_instruction = ir_build_switch_br(irb, old_instruction->scope, old_instruction->source_node, |
| 1120 | target_value, else_block, case_count, cases, is_inline); | 1143 | target_value, else_block, case_count, cases, is_inline); |
| 1121 | ir_link_new_instruction(new_instruction, old_instruction); | 1144 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1122 | return new_instruction; | 1145 | return new_instruction; |
| 1123 | } | 1146 | } |
| 1124 | | 1147 | |
| 1125 | static IrInstruction *ir_build_switch_target(IrBuilder *irb, AstNode *source_node, | 1148 | static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1126 | IrInstruction *target_value_ptr) | 1149 | IrInstruction *target_value_ptr) |
| 1127 | { | 1150 | { |
| 1128 | IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, source_node); | 1151 | IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node); |
| 1129 | instruction->target_value_ptr = target_value_ptr; | 1152 | instruction->target_value_ptr = target_value_ptr; |
| 1130 | | 1153 | |
| 1131 | ir_ref_instruction(target_value_ptr); | 1154 | ir_ref_instruction(target_value_ptr); |
| ... | @@ -1133,10 +1156,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, AstNode *source_nod | ... | @@ -1133,10 +1156,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, AstNode *source_nod |
| 1133 | return &instruction->base; | 1156 | return &instruction->base; |
| 1134 | } | 1157 | } |
| 1135 | | 1158 | |
| 1136 | static IrInstruction *ir_build_switch_var(IrBuilder *irb, AstNode *source_node, | 1159 | static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1137 | IrInstruction *target_value_ptr, IrInstruction *prong_value) | 1160 | IrInstruction *target_value_ptr, IrInstruction *prong_value) |
| 1138 | { | 1161 | { |
| 1139 | IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, source_node); | 1162 | IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node); |
| 1140 | instruction->target_value_ptr = target_value_ptr; | 1163 | instruction->target_value_ptr = target_value_ptr; |
| 1141 | instruction->prong_value = prong_value; | 1164 | instruction->prong_value = prong_value; |
| 1142 | | 1165 | |
| ... | @@ -1146,8 +1169,8 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, AstNode *source_node, | ... | @@ -1146,8 +1169,8 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, AstNode *source_node, |
| 1146 | return &instruction->base; | 1169 | return &instruction->base; |
| 1147 | } | 1170 | } |
| 1148 | | 1171 | |
| 1149 | static IrInstruction *ir_build_enum_tag(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1172 | static IrInstruction *ir_build_enum_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1150 | IrInstructionEnumTag *instruction = ir_build_instruction<IrInstructionEnumTag>(irb, source_node); | 1173 | IrInstructionEnumTag *instruction = ir_build_instruction<IrInstructionEnumTag>(irb, scope, source_node); |
| 1151 | instruction->value = value; | 1174 | instruction->value = value; |
| 1152 | | 1175 | |
| 1153 | ir_ref_instruction(value); | 1176 | ir_ref_instruction(value); |
| ... | @@ -1156,13 +1179,14 @@ static IrInstruction *ir_build_enum_tag(IrBuilder *irb, AstNode *source_node, Ir | ... | @@ -1156,13 +1179,14 @@ static IrInstruction *ir_build_enum_tag(IrBuilder *irb, AstNode *source_node, Ir |
| 1156 | } | 1179 | } |
| 1157 | | 1180 | |
| 1158 | static IrInstruction *ir_build_enum_tag_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { | 1181 | static IrInstruction *ir_build_enum_tag_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1159 | IrInstruction *new_instruction = ir_build_enum_tag(irb, old_instruction->source_node, value); | 1182 | IrInstruction *new_instruction = ir_build_enum_tag(irb, old_instruction->scope, |
| | 1183 | old_instruction->source_node, value); |
| 1160 | ir_link_new_instruction(new_instruction, old_instruction); | 1184 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1161 | return new_instruction; | 1185 | return new_instruction; |
| 1162 | } | 1186 | } |
| 1163 | | 1187 | |
| 1164 | static IrInstruction *ir_build_static_eval(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1188 | static IrInstruction *ir_build_static_eval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1165 | IrInstructionStaticEval *instruction = ir_build_instruction<IrInstructionStaticEval>(irb, source_node); | 1189 | IrInstructionStaticEval *instruction = ir_build_instruction<IrInstructionStaticEval>(irb, scope, source_node); |
| 1166 | instruction->value = value; | 1190 | instruction->value = value; |
| 1167 | | 1191 | |
| 1168 | ir_ref_instruction(value); | 1192 | ir_ref_instruction(value); |
| ... | @@ -1170,8 +1194,8 @@ static IrInstruction *ir_build_static_eval(IrBuilder *irb, AstNode *source_node, | ... | @@ -1170,8 +1194,8 @@ static IrInstruction *ir_build_static_eval(IrBuilder *irb, AstNode *source_node, |
| 1170 | return &instruction->base; | 1194 | return &instruction->base; |
| 1171 | } | 1195 | } |
| 1172 | | 1196 | |
| 1173 | static IrInstruction *ir_build_import(IrBuilder *irb, AstNode *source_node, IrInstruction *name) { | 1197 | static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) { |
| 1174 | IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, source_node); | 1198 | IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node); |
| 1175 | instruction->name = name; | 1199 | instruction->name = name; |
| 1176 | | 1200 | |
| 1177 | ir_ref_instruction(name); | 1201 | ir_ref_instruction(name); |
| ... | @@ -1179,8 +1203,8 @@ static IrInstruction *ir_build_import(IrBuilder *irb, AstNode *source_node, IrIn | ... | @@ -1179,8 +1203,8 @@ static IrInstruction *ir_build_import(IrBuilder *irb, AstNode *source_node, IrIn |
| 1179 | return &instruction->base; | 1203 | return &instruction->base; |
| 1180 | } | 1204 | } |
| 1181 | | 1205 | |
| 1182 | static IrInstruction *ir_build_array_len(IrBuilder *irb, AstNode *source_node, IrInstruction *array_value) { | 1206 | static IrInstruction *ir_build_array_len(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_value) { |
| 1183 | IrInstructionArrayLen *instruction = ir_build_instruction<IrInstructionArrayLen>(irb, source_node); | 1207 | IrInstructionArrayLen *instruction = ir_build_instruction<IrInstructionArrayLen>(irb, scope, source_node); |
| 1184 | instruction->array_value = array_value; | 1208 | instruction->array_value = array_value; |
| 1185 | | 1209 | |
| 1186 | ir_ref_instruction(array_value); | 1210 | ir_ref_instruction(array_value); |
| ... | @@ -1191,13 +1215,14 @@ static IrInstruction *ir_build_array_len(IrBuilder *irb, AstNode *source_node, I | ... | @@ -1191,13 +1215,14 @@ static IrInstruction *ir_build_array_len(IrBuilder *irb, AstNode *source_node, I |
| 1191 | static IrInstruction *ir_build_array_len_from(IrBuilder *irb, IrInstruction *old_instruction, | 1215 | static IrInstruction *ir_build_array_len_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1192 | IrInstruction *array_value) | 1216 | IrInstruction *array_value) |
| 1193 | { | 1217 | { |
| 1194 | IrInstruction *new_instruction = ir_build_array_len(irb, old_instruction->source_node, array_value); | 1218 | IrInstruction *new_instruction = ir_build_array_len(irb, old_instruction->scope, |
| | 1219 | old_instruction->source_node, array_value); |
| 1195 | ir_link_new_instruction(new_instruction, old_instruction); | 1220 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1196 | return new_instruction; | 1221 | return new_instruction; |
| 1197 | } | 1222 | } |
| 1198 | | 1223 | |
| 1199 | static IrInstruction *ir_build_ref(IrBuilder *irb, AstNode *source_node, IrInstruction *value) { | 1224 | static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1200 | IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, source_node); | 1225 | IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node); |
| 1201 | instruction->value = value; | 1226 | instruction->value = value; |
| 1202 | | 1227 | |
| 1203 | ir_ref_instruction(value); | 1228 | ir_ref_instruction(value); |
| ... | @@ -1206,12 +1231,12 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, AstNode *source_node, IrInstr | ... | @@ -1206,12 +1231,12 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, AstNode *source_node, IrInstr |
| 1206 | } | 1231 | } |
| 1207 | | 1232 | |
| 1208 | static IrInstruction *ir_build_ref_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { | 1233 | static IrInstruction *ir_build_ref_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1209 | IrInstruction *new_instruction = ir_build_ref(irb, old_instruction->source_node, value); | 1234 | IrInstruction *new_instruction = ir_build_ref(irb, old_instruction->scope, old_instruction->source_node, value); |
| 1210 | ir_link_new_instruction(new_instruction, old_instruction); | 1235 | ir_link_new_instruction(new_instruction, old_instruction); |
| 1211 | return new_instruction; | 1236 | return new_instruction; |
| 1212 | } | 1237 | } |
| 1213 | | 1238 | |
| 1214 | static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, | 1239 | static void ir_gen_defers_for_block(IrBuilder *irb, Scope *parent_scope, Scope *inner_scope, Scope *outer_scope, |
| 1215 | bool gen_error_defers, bool gen_maybe_defers) | 1240 | bool gen_error_defers, bool gen_maybe_defers) |
| 1216 | { | 1241 | { |
| 1217 | while (inner_scope != outer_scope) { | 1242 | while (inner_scope != outer_scope) { |
| ... | @@ -1221,29 +1246,16 @@ static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o | ... | @@ -1221,29 +1246,16 @@ static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 1221 | (gen_maybe_defers && inner_scope->node->data.defer.kind == ReturnKindMaybe))) | 1246 | (gen_maybe_defers && inner_scope->node->data.defer.kind == ReturnKindMaybe))) |
| 1222 | { | 1247 | { |
| 1223 | AstNode *defer_expr_node = inner_scope->node->data.defer.expr; | 1248 | AstNode *defer_expr_node = inner_scope->node->data.defer.expr; |
| 1224 | ir_gen_node(irb, defer_expr_node, defer_expr_node->scope); | 1249 | ir_gen_node(irb, defer_expr_node, parent_scope); |
| 1225 | } | 1250 | } |
| 1226 | inner_scope = inner_scope->parent; | 1251 | inner_scope = inner_scope->parent; |
| 1227 | } | 1252 | } |
| 1228 | } | 1253 | } |
| 1229 | | 1254 | |
| 1230 | static FnTableEntry *scope_fn_entry(Scope *scope) { | 1255 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1231 | while (scope) { | | |
| 1232 | if (scope->node->type == NodeTypeFnDef) { | | |
| 1233 | ScopeFnBody *fn_scope = (ScopeFnBody *)scope; | | |
| 1234 | return fn_scope->fn_entry; | | |
| 1235 | } | | |
| 1236 | scope = scope->parent; | | |
| 1237 | } | | |
| 1238 | return nullptr; | | |
| 1239 | } | | |
| 1240 | | | |
| 1241 | static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) { | | |
| 1242 | assert(node->type == NodeTypeReturnExpr); | 1256 | assert(node->type == NodeTypeReturnExpr); |
| 1243 | | 1257 | |
| 1244 | Scope *scope = node->scope; | 1258 | if (!exec_fn_entry(irb->exec)) { |
| 1245 | | | |
| 1246 | if (!scope_fn_entry(scope)) { | | |
| 1247 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); | 1259 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); |
| 1248 | return irb->codegen->invalid_instruction; | 1260 | return irb->codegen->invalid_instruction; |
| 1249 | } | 1261 | } |
| ... | @@ -1254,12 +1266,12 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) { | ... | @@ -1254,12 +1266,12 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, AstNode *node) { |
| 1254 | { | 1266 | { |
| 1255 | IrInstruction *return_value; | 1267 | IrInstruction *return_value; |
| 1256 | if (expr_node) { | 1268 | if (expr_node) { |
| 1257 | return_value = ir_gen_node(irb, expr_node, node->scope); | 1269 | return_value = ir_gen_node(irb, expr_node, scope); |
| 1258 | } else { | 1270 | } else { |
| 1259 | return_value = ir_build_const_void(irb, node); | 1271 | return_value = ir_build_const_void(irb, scope, node); |
| 1260 | } | 1272 | } |
| 1261 | | 1273 | |
| 1262 | return ir_build_return(irb, node, return_value); | 1274 | return ir_build_return(irb, scope, node, return_value); |
| 1263 | } | 1275 | } |
| 1264 | case ReturnKindError: | 1276 | case ReturnKindError: |
| 1265 | zig_panic("TODO gen IR for %%return"); | 1277 | zig_panic("TODO gen IR for %%return"); |
| ... | @@ -1275,15 +1287,15 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { | ... | @@ -1275,15 +1287,15 @@ static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) { |
| 1275 | irb->current_basic_block = basic_block; | 1287 | irb->current_basic_block = basic_block; |
| 1276 | } | 1288 | } |
| 1277 | | 1289 | |
| 1278 | static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, | 1290 | static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, |
| 1279 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline) | 1291 | Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline) |
| 1280 | { | 1292 | { |
| 1281 | VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1); | 1293 | VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1); |
| 1282 | variable_entry->parent_scope = parent_scope; | 1294 | variable_entry->parent_scope = parent_scope; |
| 1283 | variable_entry->import = node->owner; | | |
| 1284 | variable_entry->shadowable = is_shadowable; | 1295 | variable_entry->shadowable = is_shadowable; |
| 1285 | variable_entry->mem_slot_index = SIZE_MAX; | 1296 | variable_entry->mem_slot_index = SIZE_MAX; |
| 1286 | variable_entry->is_inline = is_inline; | 1297 | variable_entry->is_inline = is_inline; |
| | 1298 | variable_entry->src_arg_index = SIZE_MAX; |
| 1287 | | 1299 | |
| 1288 | if (name) { | 1300 | if (name) { |
| 1289 | buf_init_from_buf(&variable_entry->name, name); | 1301 | buf_init_from_buf(&variable_entry->name, name); |
| ... | @@ -1302,11 +1314,11 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope | ... | @@ -1302,11 +1314,11 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope |
| 1302 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); | 1314 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); |
| 1303 | variable_entry->type = codegen->builtin_types.entry_invalid; | 1315 | variable_entry->type = codegen->builtin_types.entry_invalid; |
| 1304 | } else { | 1316 | } else { |
| 1305 | AstNode *decl_node = find_decl(parent_scope, name); | 1317 | Tld *tld = find_decl(parent_scope, name); |
| 1306 | if (decl_node && decl_node->type != NodeTypeVariableDeclaration) { | 1318 | if (tld && tld->id != TldIdVar) { |
| 1307 | ErrorMsg *msg = add_node_error(codegen, node, | 1319 | ErrorMsg *msg = add_node_error(codegen, node, |
| 1308 | buf_sprintf("redefinition of '%s'", buf_ptr(name))); | 1320 | buf_sprintf("redefinition of '%s'", buf_ptr(name))); |
| 1309 | add_error_note(codegen, msg, decl_node, buf_sprintf("previous definition is here")); | 1321 | add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here")); |
| 1310 | variable_entry->type = codegen->builtin_types.entry_invalid; | 1322 | variable_entry->type = codegen->builtin_types.entry_invalid; |
| 1311 | } | 1323 | } |
| 1312 | } | 1324 | } |
| ... | @@ -1333,7 +1345,7 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope | ... | @@ -1333,7 +1345,7 @@ static VariableTableEntry *add_local_var(CodeGen *codegen, AstNode *node, Scope |
| 1333 | static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, | 1345 | static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, |
| 1334 | bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline) | 1346 | bool src_is_const, bool gen_is_const, bool is_shadowable, bool is_inline) |
| 1335 | { | 1347 | { |
| 1336 | VariableTableEntry *var = add_local_var(irb->codegen, node, scope, name, | 1348 | VariableTableEntry *var = create_local_var(irb->codegen, node, scope, name, |
| 1337 | src_is_const, gen_is_const, is_shadowable, is_inline); | 1349 | src_is_const, gen_is_const, is_shadowable, is_inline); |
| 1338 | if (is_inline || gen_is_const) | 1350 | if (is_inline || gen_is_const) |
| 1339 | var->mem_slot_index = exec_next_mem_slot(irb->exec); | 1351 | var->mem_slot_index = exec_next_mem_slot(irb->exec); |
| ... | @@ -1341,10 +1353,9 @@ static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *s | ... | @@ -1341,10 +1353,9 @@ static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *s |
| 1341 | return var; | 1353 | return var; |
| 1342 | } | 1354 | } |
| 1343 | | 1355 | |
| 1344 | static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) { | 1356 | static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) { |
| 1345 | assert(block_node->type == NodeTypeBlock); | 1357 | assert(block_node->type == NodeTypeBlock); |
| 1346 | | 1358 | |
| 1347 | Scope *parent_scope = block_node->scope; | | |
| 1348 | Scope *outer_block_scope = create_block_scope(block_node, parent_scope); | 1359 | Scope *outer_block_scope = create_block_scope(block_node, parent_scope); |
| 1349 | Scope *child_scope = outer_block_scope; | 1360 | Scope *child_scope = outer_block_scope; |
| 1350 | | 1361 | |
| ... | @@ -1353,56 +1364,57 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) { | ... | @@ -1353,56 +1364,57 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, AstNode *block_node) { |
| 1353 | AstNode *statement_node = block_node->data.block.statements.at(i); | 1364 | AstNode *statement_node = block_node->data.block.statements.at(i); |
| 1354 | return_value = ir_gen_node(irb, statement_node, child_scope); | 1365 | return_value = ir_gen_node(irb, statement_node, child_scope); |
| 1355 | if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) { | 1366 | if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) { |
| 1356 | // defer starts a new block context | 1367 | // defer starts a new scope |
| 1357 | child_scope = statement_node->data.defer.child_block; | 1368 | child_scope = statement_node->data.defer.child_scope; |
| 1358 | assert(child_scope); | 1369 | assert(child_scope); |
| 1359 | } else if (return_value->id == IrInstructionIdDeclVar) { | 1370 | } else if (return_value->id == IrInstructionIdDeclVar) { |
| | 1371 | // variable declarations start a new scope |
| 1360 | IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)return_value; | 1372 | IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)return_value; |
| 1361 | child_scope = decl_var_instruction->var->child_scope; | 1373 | child_scope = decl_var_instruction->var->child_scope; |
| 1362 | } | 1374 | } |
| 1363 | } | 1375 | } |
| 1364 | | 1376 | |
| 1365 | if (!return_value) | 1377 | if (!return_value) |
| 1366 | return_value = ir_build_const_void(irb, block_node); | 1378 | return_value = ir_build_const_void(irb, child_scope, block_node); |
| 1367 | | 1379 | |
| 1368 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false, false); | 1380 | ir_gen_defers_for_block(irb, parent_scope, child_scope, outer_block_scope, false, false); |
| 1369 | | 1381 | |
| 1370 | return return_value; | 1382 | return return_value; |
| 1371 | } | 1383 | } |
| 1372 | | 1384 | |
| 1373 | static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, AstNode *node, IrBinOp op_id) { | 1385 | static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 1374 | IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, node->scope); | 1386 | IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope); |
| 1375 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope); | 1387 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 1376 | return ir_build_bin_op(irb, node, op_id, op1, op2); | 1388 | return ir_build_bin_op(irb, scope, node, op_id, op1, op2); |
| 1377 | } | 1389 | } |
| 1378 | | 1390 | |
| 1379 | static IrInstruction *ir_gen_assign(IrBuilder *irb, AstNode *node) { | 1391 | static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1380 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->scope, LValPurposeAssign); | 1392 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPurposeAssign); |
| 1381 | if (lvalue == irb->codegen->invalid_instruction) | 1393 | if (lvalue == irb->codegen->invalid_instruction) |
| 1382 | return lvalue; | 1394 | return lvalue; |
| 1383 | | 1395 | |
| 1384 | IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope); | 1396 | IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 1385 | if (rvalue == irb->codegen->invalid_instruction) | 1397 | if (rvalue == irb->codegen->invalid_instruction) |
| 1386 | return rvalue; | 1398 | return rvalue; |
| 1387 | | 1399 | |
| 1388 | ir_build_store_ptr(irb, node, lvalue, rvalue); | 1400 | ir_build_store_ptr(irb, scope, node, lvalue, rvalue); |
| 1389 | return ir_build_const_void(irb, node); | 1401 | return ir_build_const_void(irb, scope, node); |
| 1390 | } | 1402 | } |
| 1391 | | 1403 | |
| 1392 | static IrInstruction *ir_gen_assign_op(IrBuilder *irb, AstNode *node, IrBinOp op_id) { | 1404 | static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) { |
| 1393 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, node->scope, LValPurposeAssign); | 1405 | IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPurposeAssign); |
| 1394 | if (lvalue == irb->codegen->invalid_instruction) | 1406 | if (lvalue == irb->codegen->invalid_instruction) |
| 1395 | return lvalue; | 1407 | return lvalue; |
| 1396 | IrInstruction *op1 = ir_build_load_ptr(irb, node->data.bin_op_expr.op1, lvalue); | 1408 | IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue); |
| 1397 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, node->scope); | 1409 | IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); |
| 1398 | if (op2 == irb->codegen->invalid_instruction) | 1410 | if (op2 == irb->codegen->invalid_instruction) |
| 1399 | return op2; | 1411 | return op2; |
| 1400 | IrInstruction *result = ir_build_bin_op(irb, node, op_id, op1, op2); | 1412 | IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2); |
| 1401 | ir_build_store_ptr(irb, node, lvalue, result); | 1413 | ir_build_store_ptr(irb, scope, node, lvalue, result); |
| 1402 | return ir_build_const_void(irb, node); | 1414 | return ir_build_const_void(irb, scope, node); |
| 1403 | } | 1415 | } |
| 1404 | | 1416 | |
| 1405 | static IrInstruction *ir_gen_bin_op(IrBuilder *irb, AstNode *node) { | 1417 | static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1406 | assert(node->type == NodeTypeBinOpExpr); | 1418 | assert(node->type == NodeTypeBinOpExpr); |
| 1407 | | 1419 | |
| 1408 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; | 1420 | BinOpType bin_op_type = node->data.bin_op_expr.bin_op; |
| ... | @@ -1410,95 +1422,95 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, AstNode *node) { | ... | @@ -1410,95 +1422,95 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, AstNode *node) { |
| 1410 | case BinOpTypeInvalid: | 1422 | case BinOpTypeInvalid: |
| 1411 | zig_unreachable(); | 1423 | zig_unreachable(); |
| 1412 | case BinOpTypeAssign: | 1424 | case BinOpTypeAssign: |
| 1413 | return ir_gen_assign(irb, node); | 1425 | return ir_gen_assign(irb, scope, node); |
| 1414 | case BinOpTypeAssignTimes: | 1426 | case BinOpTypeAssignTimes: |
| 1415 | return ir_gen_assign_op(irb, node, IrBinOpMult); | 1427 | return ir_gen_assign_op(irb, scope, node, IrBinOpMult); |
| 1416 | case BinOpTypeAssignTimesWrap: | 1428 | case BinOpTypeAssignTimesWrap: |
| 1417 | return ir_gen_assign_op(irb, node, IrBinOpMultWrap); | 1429 | return ir_gen_assign_op(irb, scope, node, IrBinOpMultWrap); |
| 1418 | case BinOpTypeAssignDiv: | 1430 | case BinOpTypeAssignDiv: |
| 1419 | return ir_gen_assign_op(irb, node, IrBinOpDiv); | 1431 | return ir_gen_assign_op(irb, scope, node, IrBinOpDiv); |
| 1420 | case BinOpTypeAssignMod: | 1432 | case BinOpTypeAssignMod: |
| 1421 | return ir_gen_assign_op(irb, node, IrBinOpMod); | 1433 | return ir_gen_assign_op(irb, scope, node, IrBinOpMod); |
| 1422 | case BinOpTypeAssignPlus: | 1434 | case BinOpTypeAssignPlus: |
| 1423 | return ir_gen_assign_op(irb, node, IrBinOpAdd); | 1435 | return ir_gen_assign_op(irb, scope, node, IrBinOpAdd); |
| 1424 | case BinOpTypeAssignPlusWrap: | 1436 | case BinOpTypeAssignPlusWrap: |
| 1425 | return ir_gen_assign_op(irb, node, IrBinOpAddWrap); | 1437 | return ir_gen_assign_op(irb, scope, node, IrBinOpAddWrap); |
| 1426 | case BinOpTypeAssignMinus: | 1438 | case BinOpTypeAssignMinus: |
| 1427 | return ir_gen_assign_op(irb, node, IrBinOpSub); | 1439 | return ir_gen_assign_op(irb, scope, node, IrBinOpSub); |
| 1428 | case BinOpTypeAssignMinusWrap: | 1440 | case BinOpTypeAssignMinusWrap: |
| 1429 | return ir_gen_assign_op(irb, node, IrBinOpSubWrap); | 1441 | return ir_gen_assign_op(irb, scope, node, IrBinOpSubWrap); |
| 1430 | case BinOpTypeAssignBitShiftLeft: | 1442 | case BinOpTypeAssignBitShiftLeft: |
| 1431 | return ir_gen_assign_op(irb, node, IrBinOpBitShiftLeft); | 1443 | return ir_gen_assign_op(irb, scope, node, IrBinOpBitShiftLeft); |
| 1432 | case BinOpTypeAssignBitShiftLeftWrap: | 1444 | case BinOpTypeAssignBitShiftLeftWrap: |
| 1433 | return ir_gen_assign_op(irb, node, IrBinOpBitShiftLeftWrap); | 1445 | return ir_gen_assign_op(irb, scope, node, IrBinOpBitShiftLeftWrap); |
| 1434 | case BinOpTypeAssignBitShiftRight: | 1446 | case BinOpTypeAssignBitShiftRight: |
| 1435 | return ir_gen_assign_op(irb, node, IrBinOpBitShiftRight); | 1447 | return ir_gen_assign_op(irb, scope, node, IrBinOpBitShiftRight); |
| 1436 | case BinOpTypeAssignBitAnd: | 1448 | case BinOpTypeAssignBitAnd: |
| 1437 | return ir_gen_assign_op(irb, node, IrBinOpBinAnd); | 1449 | return ir_gen_assign_op(irb, scope, node, IrBinOpBinAnd); |
| 1438 | case BinOpTypeAssignBitXor: | 1450 | case BinOpTypeAssignBitXor: |
| 1439 | return ir_gen_assign_op(irb, node, IrBinOpBinXor); | 1451 | return ir_gen_assign_op(irb, scope, node, IrBinOpBinXor); |
| 1440 | case BinOpTypeAssignBitOr: | 1452 | case BinOpTypeAssignBitOr: |
| 1441 | return ir_gen_assign_op(irb, node, IrBinOpBinOr); | 1453 | return ir_gen_assign_op(irb, scope, node, IrBinOpBinOr); |
| 1442 | case BinOpTypeAssignBoolAnd: | 1454 | case BinOpTypeAssignBoolAnd: |
| 1443 | return ir_gen_assign_op(irb, node, IrBinOpBoolAnd); | 1455 | return ir_gen_assign_op(irb, scope, node, IrBinOpBoolAnd); |
| 1444 | case BinOpTypeAssignBoolOr: | 1456 | case BinOpTypeAssignBoolOr: |
| 1445 | return ir_gen_assign_op(irb, node, IrBinOpBoolOr); | 1457 | return ir_gen_assign_op(irb, scope, node, IrBinOpBoolOr); |
| 1446 | case BinOpTypeBoolOr: | 1458 | case BinOpTypeBoolOr: |
| 1447 | case BinOpTypeBoolAnd: | 1459 | case BinOpTypeBoolAnd: |
| 1448 | // note: this is not a direct mapping to IrBinOpBoolOr/And | 1460 | // note: this is not a direct mapping to IrBinOpBoolOr/And |
| 1449 | // because of the control flow | 1461 | // because of the control flow |
| 1450 | zig_panic("TODO gen IR for bool or/and"); | 1462 | zig_panic("TODO gen IR for bool or/and"); |
| 1451 | case BinOpTypeCmpEq: | 1463 | case BinOpTypeCmpEq: |
| 1452 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpEq); | 1464 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpEq); |
| 1453 | case BinOpTypeCmpNotEq: | 1465 | case BinOpTypeCmpNotEq: |
| 1454 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpNotEq); | 1466 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpNotEq); |
| 1455 | case BinOpTypeCmpLessThan: | 1467 | case BinOpTypeCmpLessThan: |
| 1456 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpLessThan); | 1468 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpLessThan); |
| 1457 | case BinOpTypeCmpGreaterThan: | 1469 | case BinOpTypeCmpGreaterThan: |
| 1458 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpGreaterThan); | 1470 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpGreaterThan); |
| 1459 | case BinOpTypeCmpLessOrEq: | 1471 | case BinOpTypeCmpLessOrEq: |
| 1460 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpLessOrEq); | 1472 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpLessOrEq); |
| 1461 | case BinOpTypeCmpGreaterOrEq: | 1473 | case BinOpTypeCmpGreaterOrEq: |
| 1462 | return ir_gen_bin_op_id(irb, node, IrBinOpCmpGreaterOrEq); | 1474 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpCmpGreaterOrEq); |
| 1463 | case BinOpTypeBinOr: | 1475 | case BinOpTypeBinOr: |
| 1464 | return ir_gen_bin_op_id(irb, node, IrBinOpBinOr); | 1476 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBinOr); |
| 1465 | case BinOpTypeBinXor: | 1477 | case BinOpTypeBinXor: |
| 1466 | return ir_gen_bin_op_id(irb, node, IrBinOpBinXor); | 1478 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBinXor); |
| 1467 | case BinOpTypeBinAnd: | 1479 | case BinOpTypeBinAnd: |
| 1468 | return ir_gen_bin_op_id(irb, node, IrBinOpBinAnd); | 1480 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBinAnd); |
| 1469 | case BinOpTypeBitShiftLeft: | 1481 | case BinOpTypeBitShiftLeft: |
| 1470 | return ir_gen_bin_op_id(irb, node, IrBinOpBitShiftLeft); | 1482 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBitShiftLeft); |
| 1471 | case BinOpTypeBitShiftLeftWrap: | 1483 | case BinOpTypeBitShiftLeftWrap: |
| 1472 | return ir_gen_bin_op_id(irb, node, IrBinOpBitShiftLeftWrap); | 1484 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBitShiftLeftWrap); |
| 1473 | case BinOpTypeBitShiftRight: | 1485 | case BinOpTypeBitShiftRight: |
| 1474 | return ir_gen_bin_op_id(irb, node, IrBinOpBitShiftRight); | 1486 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpBitShiftRight); |
| 1475 | case BinOpTypeAdd: | 1487 | case BinOpTypeAdd: |
| 1476 | return ir_gen_bin_op_id(irb, node, IrBinOpAdd); | 1488 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpAdd); |
| 1477 | case BinOpTypeAddWrap: | 1489 | case BinOpTypeAddWrap: |
| 1478 | return ir_gen_bin_op_id(irb, node, IrBinOpAddWrap); | 1490 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpAddWrap); |
| 1479 | case BinOpTypeSub: | 1491 | case BinOpTypeSub: |
| 1480 | return ir_gen_bin_op_id(irb, node, IrBinOpSub); | 1492 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpSub); |
| 1481 | case BinOpTypeSubWrap: | 1493 | case BinOpTypeSubWrap: |
| 1482 | return ir_gen_bin_op_id(irb, node, IrBinOpSubWrap); | 1494 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpSubWrap); |
| 1483 | case BinOpTypeMult: | 1495 | case BinOpTypeMult: |
| 1484 | return ir_gen_bin_op_id(irb, node, IrBinOpMult); | 1496 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpMult); |
| 1485 | case BinOpTypeMultWrap: | 1497 | case BinOpTypeMultWrap: |
| 1486 | return ir_gen_bin_op_id(irb, node, IrBinOpMultWrap); | 1498 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpMultWrap); |
| 1487 | case BinOpTypeDiv: | 1499 | case BinOpTypeDiv: |
| 1488 | return ir_gen_bin_op_id(irb, node, IrBinOpDiv); | 1500 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpDiv); |
| 1489 | case BinOpTypeMod: | 1501 | case BinOpTypeMod: |
| 1490 | return ir_gen_bin_op_id(irb, node, IrBinOpMod); | 1502 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpMod); |
| 1491 | case BinOpTypeArrayCat: | 1503 | case BinOpTypeArrayCat: |
| 1492 | return ir_gen_bin_op_id(irb, node, IrBinOpArrayCat); | 1504 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayCat); |
| 1493 | case BinOpTypeArrayMult: | 1505 | case BinOpTypeArrayMult: |
| 1494 | return ir_gen_bin_op_id(irb, node, IrBinOpArrayMult); | 1506 | return ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult); |
| 1495 | case BinOpTypeUnwrapMaybe: | 1507 | case BinOpTypeUnwrapMaybe: |
| 1496 | zig_panic("TODO gen IR for unwrap maybe binary operation"); | 1508 | zig_panic("TODO gen IR for unwrap maybe binary operation"); |
| 1497 | } | 1509 | } |
| 1498 | zig_unreachable(); | 1510 | zig_unreachable(); |
| 1499 | } | 1511 | } |
| 1500 | | 1512 | |
| 1501 | static IrInstruction *ir_gen_num_lit(IrBuilder *irb, AstNode *node) { | 1513 | static IrInstruction *ir_gen_num_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1502 | assert(node->type == NodeTypeNumberLiteral); | 1514 | assert(node->type == NodeTypeNumberLiteral); |
| 1503 | | 1515 | |
| 1504 | if (node->data.number_literal.overflow) { | 1516 | if (node->data.number_literal.overflow) { |
| ... | @@ -1506,95 +1518,95 @@ static IrInstruction *ir_gen_num_lit(IrBuilder *irb, AstNode *node) { | ... | @@ -1506,95 +1518,95 @@ static IrInstruction *ir_gen_num_lit(IrBuilder *irb, AstNode *node) { |
| 1506 | return irb->codegen->invalid_instruction; | 1518 | return irb->codegen->invalid_instruction; |
| 1507 | } | 1519 | } |
| 1508 | | 1520 | |
| 1509 | return ir_build_const_bignum(irb, node, node->data.number_literal.bignum); | 1521 | return ir_build_const_bignum(irb, scope, node, node->data.number_literal.bignum); |
| 1510 | } | 1522 | } |
| 1511 | | 1523 | |
| 1512 | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, AstNode *node) { | 1524 | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1513 | assert(node->type == NodeTypeNullLiteral); | 1525 | assert(node->type == NodeTypeNullLiteral); |
| 1514 | | 1526 | |
| 1515 | return ir_build_const_null(irb, node); | 1527 | return ir_build_const_null(irb, scope, node); |
| 1516 | } | 1528 | } |
| 1517 | | 1529 | |
| 1518 | static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstNode *decl_node, | 1530 | static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, Tld *tld, |
| 1519 | LValPurpose lval, Scope *scope) | 1531 | LValPurpose lval, Scope *scope) |
| 1520 | { | 1532 | { |
| 1521 | resolve_top_level_decl(irb->codegen, decl_node, lval != LValPurposeNone); | 1533 | resolve_top_level_decl(irb->codegen, tld, lval != LValPurposeNone); |
| 1522 | TopLevelDecl *tld = get_as_top_level_decl(decl_node); | | |
| 1523 | if (tld->resolution == TldResolutionInvalid) | 1534 | if (tld->resolution == TldResolutionInvalid) |
| 1524 | return irb->codegen->invalid_instruction; | 1535 | return irb->codegen->invalid_instruction; |
| 1525 | | 1536 | |
| 1526 | if (decl_node->type == NodeTypeVariableDeclaration) { | 1537 | switch (tld->id) { |
| 1527 | VariableTableEntry *var = decl_node->data.variable_declaration.variable; | 1538 | case TldIdVar: |
| 1528 | IrInstruction *var_ptr = ir_build_var_ptr(irb, source_node, var); | 1539 | { |
| 1529 | if (lval != LValPurposeNone) | 1540 | TldVar *tld_var = (TldVar *)tld; |
| 1530 | return var_ptr; | 1541 | VariableTableEntry *var = tld_var->var; |
| 1531 | else | 1542 | IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, source_node, var); |
| 1532 | return ir_build_load_ptr(irb, source_node, var_ptr); | 1543 | if (lval != LValPurposeNone) |
| 1533 | } else if (decl_node->type == NodeTypeFnProto) { | 1544 | return var_ptr; |
| 1534 | FnTableEntry *fn_entry = decl_node->data.fn_proto.fn_table_entry; | 1545 | else |
| 1535 | assert(fn_entry->type_entry); | 1546 | return ir_build_load_ptr(irb, scope, source_node, var_ptr); |
| 1536 | IrInstruction *ref_instruction; | | |
| 1537 | if (fn_entry->type_entry->id == TypeTableEntryIdGenericFn) { | | |
| 1538 | ref_instruction = ir_build_const_generic_fn(irb, source_node, fn_entry->type_entry); | | |
| 1539 | } else { | | |
| 1540 | ref_instruction = ir_build_const_fn(irb, source_node, fn_entry); | | |
| 1541 | } | 1547 | } |
| 1542 | if (lval != LValPurposeNone) | 1548 | case TldIdFn: |
| 1543 | return ir_build_ref(irb, source_node, ref_instruction); | 1549 | { |
| 1544 | else | 1550 | TldFn *tld_fn = (TldFn *)tld; |
| 1545 | return ref_instruction; | 1551 | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 1546 | } else if (decl_node->type == NodeTypeContainerDecl) { | 1552 | assert(fn_entry->type_entry); |
| 1547 | IrInstruction *ref_instruction; | 1553 | IrInstruction *ref_instruction = ir_build_const_fn(irb, scope, source_node, fn_entry); |
| 1548 | if (decl_node->data.struct_decl.generic_params.length > 0) { | 1554 | if (lval != LValPurposeNone) |
| 1549 | TypeTableEntry *type_entry = decl_node->data.struct_decl.generic_fn_type; | 1555 | return ir_build_ref(irb, scope, source_node, ref_instruction); |
| 1550 | assert(type_entry); | 1556 | else |
| 1551 | ref_instruction = ir_build_const_generic_fn(irb, source_node, type_entry); | 1557 | return ref_instruction; |
| 1552 | } else { | 1558 | } |
| 1553 | ref_instruction = ir_build_const_type(irb, source_node, decl_node->data.struct_decl.type_entry); | 1559 | case TldIdContainer: |
| | 1560 | { |
| | 1561 | TldContainer *tld_container = (TldContainer *)tld; |
| | 1562 | |
| | 1563 | IrInstruction *ref_instruction = ir_build_const_type(irb, scope, source_node, tld_container->type_entry); |
| | 1564 | if (lval != LValPurposeNone) |
| | 1565 | return ir_build_ref(irb, scope, source_node, ref_instruction); |
| | 1566 | else |
| | 1567 | return ref_instruction; |
| | 1568 | } |
| | 1569 | case TldIdTypeDef: |
| | 1570 | { |
| | 1571 | TldTypeDef *tld_typedef = (TldTypeDef *)tld; |
| | 1572 | TypeTableEntry *typedef_type = tld_typedef->type_entry; |
| | 1573 | IrInstruction *ref_instruction = ir_build_const_type(irb, scope, source_node, typedef_type); |
| | 1574 | if (lval != LValPurposeNone) |
| | 1575 | return ir_build_ref(irb, scope, source_node, ref_instruction); |
| | 1576 | else |
| | 1577 | return ref_instruction; |
| 1554 | } | 1578 | } |
| 1555 | if (lval != LValPurposeNone) | | |
| 1556 | return ir_build_ref(irb, source_node, ref_instruction); | | |
| 1557 | else | | |
| 1558 | return ref_instruction; | | |
| 1559 | } else if (decl_node->type == NodeTypeTypeDecl) { | | |
| 1560 | TypeTableEntry *child_type = decl_node->data.type_decl.child_type_entry; | | |
| 1561 | IrInstruction *ref_instruction = ir_build_const_type(irb, source_node, child_type); | | |
| 1562 | if (lval != LValPurposeNone) | | |
| 1563 | return ir_build_ref(irb, source_node, ref_instruction); | | |
| 1564 | else | | |
| 1565 | return ref_instruction; | | |
| 1566 | } else { | | |
| 1567 | zig_unreachable(); | | |
| 1568 | } | 1579 | } |
| | 1580 | zig_unreachable(); |
| 1569 | } | 1581 | } |
| 1570 | | 1582 | |
| 1571 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose lval) { | 1583 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LValPurpose lval) { |
| 1572 | assert(node->type == NodeTypeSymbol); | 1584 | assert(node->type == NodeTypeSymbol); |
| 1573 | | 1585 | |
| 1574 | Buf *variable_name = node->data.symbol_expr.symbol; | 1586 | Buf *variable_name = node->data.symbol_expr.symbol; |
| 1575 | | 1587 | |
| 1576 | auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name); | 1588 | auto primitive_table_entry = irb->codegen->primitive_type_table.maybe_get(variable_name); |
| 1577 | if (primitive_table_entry) { | 1589 | if (primitive_table_entry) { |
| 1578 | IrInstruction *value = ir_build_const_type(irb, node, primitive_table_entry->value); | 1590 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_table_entry->value); |
| 1579 | if (lval == LValPurposeAddressOf) { | 1591 | if (lval == LValPurposeAddressOf) { |
| 1580 | return ir_build_un_op(irb, node, IrUnOpAddressOf, value); | 1592 | return ir_build_un_op(irb, scope, node, IrUnOpAddressOf, value); |
| 1581 | } else { | 1593 | } else { |
| 1582 | return value; | 1594 | return value; |
| 1583 | } | 1595 | } |
| 1584 | } | 1596 | } |
| 1585 | | 1597 | |
| 1586 | VariableTableEntry *var = find_variable(irb->codegen, node->scope, variable_name); | 1598 | VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); |
| 1587 | if (var) { | 1599 | if (var) { |
| 1588 | IrInstruction *var_ptr = ir_build_var_ptr(irb, node, var); | 1600 | IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var); |
| 1589 | if (lval != LValPurposeNone) | 1601 | if (lval != LValPurposeNone) |
| 1590 | return var_ptr; | 1602 | return var_ptr; |
| 1591 | else | 1603 | else |
| 1592 | return ir_build_load_ptr(irb, node, var_ptr); | 1604 | return ir_build_load_ptr(irb, scope, node, var_ptr); |
| 1593 | } | 1605 | } |
| 1594 | | 1606 | |
| 1595 | AstNode *decl_node = find_decl(node->scope, variable_name); | 1607 | Tld *tld = find_decl(scope, variable_name); |
| 1596 | if (decl_node) | 1608 | if (tld) |
| 1597 | return ir_gen_decl_ref(irb, node, decl_node, lval, node->scope); | 1609 | return ir_gen_decl_ref(irb, node, tld, lval, scope); |
| 1598 | | 1610 | |
| 1599 | if (node->owner->any_imports_failed) { | 1611 | if (node->owner->any_imports_failed) { |
| 1600 | // skip the error message since we had a failing import in this file | 1612 | // skip the error message since we had a failing import in this file |
| ... | @@ -1606,47 +1618,47 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l | ... | @@ -1606,47 +1618,47 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l |
| 1606 | return irb->codegen->invalid_instruction; | 1618 | return irb->codegen->invalid_instruction; |
| 1607 | } | 1619 | } |
| 1608 | | 1620 | |
| 1609 | static IrInstruction *ir_gen_array_access(IrBuilder *irb, AstNode *node, LValPurpose lval) { | 1621 | static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LValPurpose lval) { |
| 1610 | assert(node->type == NodeTypeArrayAccessExpr); | 1622 | assert(node->type == NodeTypeArrayAccessExpr); |
| 1611 | | 1623 | |
| 1612 | AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; | 1624 | AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr; |
| 1613 | IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, node->scope, | 1625 | IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, |
| 1614 | LValPurposeAddressOf); | 1626 | LValPurposeAddressOf); |
| 1615 | if (array_ref_instruction == irb->codegen->invalid_instruction) | 1627 | if (array_ref_instruction == irb->codegen->invalid_instruction) |
| 1616 | return array_ref_instruction; | 1628 | return array_ref_instruction; |
| 1617 | | 1629 | |
| 1618 | AstNode *subscript_node = node->data.array_access_expr.subscript; | 1630 | AstNode *subscript_node = node->data.array_access_expr.subscript; |
| 1619 | IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, node->scope); | 1631 | IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope); |
| 1620 | if (subscript_instruction == irb->codegen->invalid_instruction) | 1632 | if (subscript_instruction == irb->codegen->invalid_instruction) |
| 1621 | return subscript_instruction; | 1633 | return subscript_instruction; |
| 1622 | | 1634 | |
| 1623 | IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, node, array_ref_instruction, | 1635 | IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction, |
| 1624 | subscript_instruction, true); | 1636 | subscript_instruction, true); |
| 1625 | if (lval != LValPurposeNone) | 1637 | if (lval != LValPurposeNone) |
| 1626 | return ptr_instruction; | 1638 | return ptr_instruction; |
| 1627 | | 1639 | |
| 1628 | return ir_build_load_ptr(irb, node, ptr_instruction); | 1640 | return ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 1629 | } | 1641 | } |
| 1630 | | 1642 | |
| 1631 | static IrInstruction *ir_gen_field_access(IrBuilder *irb, AstNode *node, LValPurpose lval) { | 1643 | static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node, LValPurpose lval) { |
| 1632 | assert(node->type == NodeTypeFieldAccessExpr); | 1644 | assert(node->type == NodeTypeFieldAccessExpr); |
| 1633 | | 1645 | |
| 1634 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; | 1646 | AstNode *container_ref_node = node->data.field_access_expr.struct_expr; |
| 1635 | Buf *field_name = node->data.field_access_expr.field_name; | 1647 | Buf *field_name = node->data.field_access_expr.field_name; |
| 1636 | | 1648 | |
| 1637 | IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, node->scope, | 1649 | IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, |
| 1638 | LValPurposeAddressOf); | 1650 | LValPurposeAddressOf); |
| 1639 | if (container_ref_instruction == irb->codegen->invalid_instruction) | 1651 | if (container_ref_instruction == irb->codegen->invalid_instruction) |
| 1640 | return container_ref_instruction; | 1652 | return container_ref_instruction; |
| 1641 | | 1653 | |
| 1642 | IrInstruction *ptr_instruction = ir_build_field_ptr(irb, node, container_ref_instruction, field_name); | 1654 | IrInstruction *ptr_instruction = ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name); |
| 1643 | if (lval != LValPurposeNone) | 1655 | if (lval != LValPurposeNone) |
| 1644 | return ptr_instruction; | 1656 | return ptr_instruction; |
| 1645 | | 1657 | |
| 1646 | return ir_build_load_ptr(irb, node, ptr_instruction); | 1658 | return ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 1647 | } | 1659 | } |
| 1648 | | 1660 | |
| 1649 | static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) { | 1661 | static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1650 | assert(node->type == NodeTypeFnCallExpr); | 1662 | assert(node->type == NodeTypeFnCallExpr); |
| 1651 | | 1663 | |
| 1652 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; | 1664 | AstNode *fn_ref_expr = node->data.fn_call_expr.fn_ref_expr; |
| ... | @@ -1675,115 +1687,115 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) { | ... | @@ -1675,115 +1687,115 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) { |
| 1675 | case BuiltinFnIdInvalid: | 1687 | case BuiltinFnIdInvalid: |
| 1676 | zig_unreachable(); | 1688 | zig_unreachable(); |
| 1677 | case BuiltinFnIdUnreachable: | 1689 | case BuiltinFnIdUnreachable: |
| 1678 | return ir_build_unreachable(irb, node); | 1690 | return ir_build_unreachable(irb, scope, node); |
| 1679 | case BuiltinFnIdTypeof: | 1691 | case BuiltinFnIdTypeof: |
| 1680 | { | 1692 | { |
| 1681 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); | 1693 | AstNode *arg_node = node->data.fn_call_expr.params.at(0); |
| 1682 | IrInstruction *arg = ir_gen_node(irb, arg_node, node->scope); | 1694 | IrInstruction *arg = ir_gen_node(irb, arg_node, scope); |
| 1683 | if (arg == irb->codegen->invalid_instruction) | 1695 | if (arg == irb->codegen->invalid_instruction) |
| 1684 | return arg; | 1696 | return arg; |
| 1685 | return ir_build_typeof(irb, node, arg); | 1697 | return ir_build_typeof(irb, scope, node, arg); |
| 1686 | } | 1698 | } |
| 1687 | case BuiltinFnIdSetFnTest: | 1699 | case BuiltinFnIdSetFnTest: |
| 1688 | { | 1700 | { |
| 1689 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1701 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1690 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1702 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1691 | if (arg0_value == irb->codegen->invalid_instruction) | 1703 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1692 | return arg0_value; | 1704 | return arg0_value; |
| 1693 | | 1705 | |
| 1694 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 1706 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 1695 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope); | 1707 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 1696 | if (arg1_value == irb->codegen->invalid_instruction) | 1708 | if (arg1_value == irb->codegen->invalid_instruction) |
| 1697 | return arg1_value; | 1709 | return arg1_value; |
| 1698 | | 1710 | |
| 1699 | return ir_build_set_fn_test(irb, node, arg0_value, arg1_value); | 1711 | return ir_build_set_fn_test(irb, scope, node, arg0_value, arg1_value); |
| 1700 | } | 1712 | } |
| 1701 | case BuiltinFnIdSetFnVisible: | 1713 | case BuiltinFnIdSetFnVisible: |
| 1702 | { | 1714 | { |
| 1703 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1715 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1704 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1716 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1705 | if (arg0_value == irb->codegen->invalid_instruction) | 1717 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1706 | return arg0_value; | 1718 | return arg0_value; |
| 1707 | | 1719 | |
| 1708 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 1720 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 1709 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope); | 1721 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 1710 | if (arg1_value == irb->codegen->invalid_instruction) | 1722 | if (arg1_value == irb->codegen->invalid_instruction) |
| 1711 | return arg1_value; | 1723 | return arg1_value; |
| 1712 | | 1724 | |
| 1713 | return ir_build_set_fn_visible(irb, node, arg0_value, arg1_value); | 1725 | return ir_build_set_fn_visible(irb, scope, node, arg0_value, arg1_value); |
| 1714 | } | 1726 | } |
| 1715 | case BuiltinFnIdSetDebugSafety: | 1727 | case BuiltinFnIdSetDebugSafety: |
| 1716 | { | 1728 | { |
| 1717 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1729 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1718 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1730 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1719 | if (arg0_value == irb->codegen->invalid_instruction) | 1731 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1720 | return arg0_value; | 1732 | return arg0_value; |
| 1721 | | 1733 | |
| 1722 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 1734 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); |
| 1723 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, node->scope); | 1735 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); |
| 1724 | if (arg1_value == irb->codegen->invalid_instruction) | 1736 | if (arg1_value == irb->codegen->invalid_instruction) |
| 1725 | return arg1_value; | 1737 | return arg1_value; |
| 1726 | | 1738 | |
| 1727 | return ir_build_set_debug_safety(irb, node, arg0_value, arg1_value); | 1739 | return ir_build_set_debug_safety(irb, scope, node, arg0_value, arg1_value); |
| 1728 | } | 1740 | } |
| 1729 | case BuiltinFnIdCompileVar: | 1741 | case BuiltinFnIdCompileVar: |
| 1730 | { | 1742 | { |
| 1731 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1743 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1732 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1744 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1733 | if (arg0_value == irb->codegen->invalid_instruction) | 1745 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1734 | return arg0_value; | 1746 | return arg0_value; |
| 1735 | | 1747 | |
| 1736 | return ir_build_compile_var(irb, node, arg0_value); | 1748 | return ir_build_compile_var(irb, scope, node, arg0_value); |
| 1737 | } | 1749 | } |
| 1738 | case BuiltinFnIdSizeof: | 1750 | case BuiltinFnIdSizeof: |
| 1739 | { | 1751 | { |
| 1740 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1752 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1741 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1753 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1742 | if (arg0_value == irb->codegen->invalid_instruction) | 1754 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1743 | return arg0_value; | 1755 | return arg0_value; |
| 1744 | | 1756 | |
| 1745 | return ir_build_size_of(irb, node, arg0_value); | 1757 | return ir_build_size_of(irb, scope, node, arg0_value); |
| 1746 | } | 1758 | } |
| 1747 | case BuiltinFnIdCtz: | 1759 | case BuiltinFnIdCtz: |
| 1748 | { | 1760 | { |
| 1749 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1761 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1750 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1762 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1751 | if (arg0_value == irb->codegen->invalid_instruction) | 1763 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1752 | return arg0_value; | 1764 | return arg0_value; |
| 1753 | | 1765 | |
| 1754 | return ir_build_ctz(irb, node, arg0_value); | 1766 | return ir_build_ctz(irb, scope, node, arg0_value); |
| 1755 | } | 1767 | } |
| 1756 | case BuiltinFnIdClz: | 1768 | case BuiltinFnIdClz: |
| 1757 | { | 1769 | { |
| 1758 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1770 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1759 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1771 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1760 | if (arg0_value == irb->codegen->invalid_instruction) | 1772 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1761 | return arg0_value; | 1773 | return arg0_value; |
| 1762 | | 1774 | |
| 1763 | return ir_build_clz(irb, node, arg0_value); | 1775 | return ir_build_clz(irb, scope, node, arg0_value); |
| 1764 | } | 1776 | } |
| 1765 | case BuiltinFnIdStaticEval: | 1777 | case BuiltinFnIdStaticEval: |
| 1766 | { | 1778 | { |
| 1767 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1779 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1768 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1780 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1769 | if (arg0_value == irb->codegen->invalid_instruction) | 1781 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1770 | return arg0_value; | 1782 | return arg0_value; |
| 1771 | | 1783 | |
| 1772 | return ir_build_static_eval(irb, node, arg0_value); | 1784 | return ir_build_static_eval(irb, scope, node, arg0_value); |
| 1773 | } | 1785 | } |
| 1774 | case BuiltinFnIdImport: | 1786 | case BuiltinFnIdImport: |
| 1775 | { | 1787 | { |
| 1776 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); | 1788 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1777 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, node->scope); | 1789 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1778 | if (arg0_value == irb->codegen->invalid_instruction) | 1790 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1779 | return arg0_value; | 1791 | return arg0_value; |
| 1780 | | 1792 | |
| 1781 | if (scope_fn_entry(node->scope)) { | 1793 | if (exec_fn_entry(irb->exec)) { |
| 1782 | add_node_error(irb->codegen, node, buf_sprintf("import valid only at top level scope")); | 1794 | add_node_error(irb->codegen, node, buf_sprintf("import valid only at top level scope")); |
| 1783 | return irb->codegen->invalid_instruction; | 1795 | return irb->codegen->invalid_instruction; |
| 1784 | } | 1796 | } |
| 1785 | | 1797 | |
| 1786 | return ir_build_import(irb, node, arg0_value); | 1798 | return ir_build_import(irb, scope, node, arg0_value); |
| 1787 | } | 1799 | } |
| 1788 | case BuiltinFnIdMemcpy: | 1800 | case BuiltinFnIdMemcpy: |
| 1789 | case BuiltinFnIdMemset: | 1801 | case BuiltinFnIdMemset: |
| ... | @@ -1816,14 +1828,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) { | ... | @@ -1816,14 +1828,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, AstNode *node) { |
| 1816 | zig_unreachable(); | 1828 | zig_unreachable(); |
| 1817 | } | 1829 | } |
| 1818 | | 1830 | |
| 1819 | static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) { | 1831 | static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1820 | assert(node->type == NodeTypeFnCallExpr); | 1832 | assert(node->type == NodeTypeFnCallExpr); |
| 1821 | | 1833 | |
| 1822 | if (node->data.fn_call_expr.is_builtin) | 1834 | if (node->data.fn_call_expr.is_builtin) |
| 1823 | return ir_gen_builtin_fn_call(irb, node); | 1835 | return ir_gen_builtin_fn_call(irb, scope, node); |
| 1824 | | 1836 | |
| 1825 | AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr; | 1837 | AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr; |
| 1826 | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, node->scope); | 1838 | IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope); |
| 1827 | if (fn_ref == irb->codegen->invalid_instruction) | 1839 | if (fn_ref == irb->codegen->invalid_instruction) |
| 1828 | return fn_ref; | 1840 | return fn_ref; |
| 1829 | | 1841 | |
| ... | @@ -1831,16 +1843,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) { | ... | @@ -1831,16 +1843,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, AstNode *node) { |
| 1831 | IrInstruction **args = allocate<IrInstruction*>(arg_count); | 1843 | IrInstruction **args = allocate<IrInstruction*>(arg_count); |
| 1832 | for (size_t i = 0; i < arg_count; i += 1) { | 1844 | for (size_t i = 0; i < arg_count; i += 1) { |
| 1833 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); | 1845 | AstNode *arg_node = node->data.fn_call_expr.params.at(i); |
| 1834 | args[i] = ir_gen_node(irb, arg_node, node->scope); | 1846 | args[i] = ir_gen_node(irb, arg_node, scope); |
| 1835 | } | 1847 | } |
| 1836 | | 1848 | |
| 1837 | return ir_build_call(irb, node, nullptr, fn_ref, arg_count, args); | 1849 | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args); |
| 1838 | } | 1850 | } |
| 1839 | | 1851 | |
| 1840 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) { | 1852 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1841 | assert(node->type == NodeTypeIfBoolExpr); | 1853 | assert(node->type == NodeTypeIfBoolExpr); |
| 1842 | | 1854 | |
| 1843 | IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, node->scope); | 1855 | IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope); |
| 1844 | if (condition == irb->codegen->invalid_instruction) | 1856 | if (condition == irb->codegen->invalid_instruction) |
| 1845 | return condition; | 1857 | return condition; |
| 1846 | | 1858 | |
| ... | @@ -1852,26 +1864,26 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -1852,26 +1864,26 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) { |
| 1852 | IrBasicBlock *endif_block = ir_build_basic_block(irb, "EndIf"); | 1864 | IrBasicBlock *endif_block = ir_build_basic_block(irb, "EndIf"); |
| 1853 | | 1865 | |
| 1854 | bool is_inline = ir_should_inline(irb) || node->data.if_bool_expr.is_inline; | 1866 | bool is_inline = ir_should_inline(irb) || node->data.if_bool_expr.is_inline; |
| 1855 | ir_build_cond_br(irb, condition->source_node, condition, then_block, else_block, is_inline); | 1867 | ir_build_cond_br(irb, scope, condition->source_node, condition, then_block, else_block, is_inline); |
| 1856 | | 1868 | |
| 1857 | ir_set_cursor_at_end(irb, then_block); | 1869 | ir_set_cursor_at_end(irb, then_block); |
| 1858 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, node->scope); | 1870 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope); |
| 1859 | if (then_expr_result == irb->codegen->invalid_instruction) | 1871 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 1860 | return then_expr_result; | 1872 | return then_expr_result; |
| 1861 | IrBasicBlock *after_then_block = irb->current_basic_block; | 1873 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 1862 | ir_build_br(irb, node, endif_block, is_inline); | 1874 | ir_build_br(irb, scope, node, endif_block, is_inline); |
| 1863 | | 1875 | |
| 1864 | ir_set_cursor_at_end(irb, else_block); | 1876 | ir_set_cursor_at_end(irb, else_block); |
| 1865 | IrInstruction *else_expr_result; | 1877 | IrInstruction *else_expr_result; |
| 1866 | if (else_node) { | 1878 | if (else_node) { |
| 1867 | else_expr_result = ir_gen_node(irb, else_node, node->scope); | 1879 | else_expr_result = ir_gen_node(irb, else_node, scope); |
| 1868 | if (else_expr_result == irb->codegen->invalid_instruction) | 1880 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 1869 | return else_expr_result; | 1881 | return else_expr_result; |
| 1870 | } else { | 1882 | } else { |
| 1871 | else_expr_result = ir_build_const_void(irb, node); | 1883 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 1872 | } | 1884 | } |
| 1873 | IrBasicBlock *after_else_block = irb->current_basic_block; | 1885 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 1874 | ir_build_br(irb, node, endif_block, is_inline); | 1886 | ir_build_br(irb, scope, node, endif_block, is_inline); |
| 1875 | | 1887 | |
| 1876 | ir_set_cursor_at_end(irb, endif_block); | 1888 | ir_set_cursor_at_end(irb, endif_block); |
| 1877 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 1889 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| ... | @@ -1881,14 +1893,14 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -1881,14 +1893,14 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, AstNode *node) { |
| 1881 | incoming_blocks[0] = after_then_block; | 1893 | incoming_blocks[0] = after_then_block; |
| 1882 | incoming_blocks[1] = after_else_block; | 1894 | incoming_blocks[1] = after_else_block; |
| 1883 | | 1895 | |
| 1884 | return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values); | 1896 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); |
| 1885 | } | 1897 | } |
| 1886 | | 1898 | |
| 1887 | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, IrUnOp op_id, LValPurpose lval) { | 1899 | static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LValPurpose lval) { |
| 1888 | assert(node->type == NodeTypePrefixOpExpr); | 1900 | assert(node->type == NodeTypePrefixOpExpr); |
| 1889 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | 1901 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 1890 | | 1902 | |
| 1891 | IrInstruction *value = ir_gen_node_extra(irb, expr_node, node->scope, lval); | 1903 | IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval); |
| 1892 | if (value == irb->codegen->invalid_instruction) | 1904 | if (value == irb->codegen->invalid_instruction) |
| 1893 | return value; | 1905 | return value; |
| 1894 | | 1906 | |
| ... | @@ -1896,27 +1908,27 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, Ir | ... | @@ -1896,27 +1908,27 @@ static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, AstNode *node, Ir |
| 1896 | return value; | 1908 | return value; |
| 1897 | } | 1909 | } |
| 1898 | | 1910 | |
| 1899 | return ir_build_un_op(irb, node, op_id, value); | 1911 | return ir_build_un_op(irb, scope, node, op_id, value); |
| 1900 | } | 1912 | } |
| 1901 | | 1913 | |
| 1902 | static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, AstNode *node, IrUnOp op_id) { | 1914 | static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) { |
| 1903 | return ir_gen_prefix_op_id_lval(irb, node, op_id, LValPurposeNone); | 1915 | return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValPurposeNone); |
| 1904 | } | 1916 | } |
| 1905 | | 1917 | |
| 1906 | static IrInstruction *ir_gen_prefix_op_unwrap_maybe(IrBuilder *irb, AstNode *node, LValPurpose lval) { | 1918 | static IrInstruction *ir_gen_prefix_op_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *node, LValPurpose lval) { |
| 1907 | AstNode *expr = node->data.prefix_op_expr.primary_expr; | 1919 | AstNode *expr = node->data.prefix_op_expr.primary_expr; |
| 1908 | IrInstruction *value = ir_gen_node_extra(irb, expr, node->scope, LValPurposeAddressOf); | 1920 | IrInstruction *value = ir_gen_node_extra(irb, expr, scope, LValPurposeAddressOf); |
| 1909 | if (value == irb->codegen->invalid_instruction) | 1921 | if (value == irb->codegen->invalid_instruction) |
| 1910 | return value; | 1922 | return value; |
| 1911 | | 1923 | |
| 1912 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, node, value, true); | 1924 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, value, true); |
| 1913 | if (lval == LValPurposeNone) | 1925 | if (lval == LValPurposeNone) |
| 1914 | return ir_build_load_ptr(irb, node, unwrapped_ptr); | 1926 | return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); |
| 1915 | else | 1927 | else |
| 1916 | return unwrapped_ptr; | 1928 | return unwrapped_ptr; |
| 1917 | } | 1929 | } |
| 1918 | | 1930 | |
| 1919 | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, AstNode *node, LValPurpose lval) { | 1931 | static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LValPurpose lval) { |
| 1920 | assert(node->type == NodeTypePrefixOpExpr); | 1932 | assert(node->type == NodeTypePrefixOpExpr); |
| 1921 | | 1933 | |
| 1922 | PrefixOp prefix_op = node->data.prefix_op_expr.prefix_op; | 1934 | PrefixOp prefix_op = node->data.prefix_op_expr.prefix_op; |
| ... | @@ -1925,38 +1937,38 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, AstNode *node, LValP | ... | @@ -1925,38 +1937,38 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, AstNode *node, LValP |
| 1925 | case PrefixOpInvalid: | 1937 | case PrefixOpInvalid: |
| 1926 | zig_unreachable(); | 1938 | zig_unreachable(); |
| 1927 | case PrefixOpBoolNot: | 1939 | case PrefixOpBoolNot: |
| 1928 | return ir_gen_prefix_op_id(irb, node, IrUnOpBoolNot); | 1940 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpBoolNot); |
| 1929 | case PrefixOpBinNot: | 1941 | case PrefixOpBinNot: |
| 1930 | return ir_gen_prefix_op_id(irb, node, IrUnOpBinNot); | 1942 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpBinNot); |
| 1931 | case PrefixOpNegation: | 1943 | case PrefixOpNegation: |
| 1932 | return ir_gen_prefix_op_id(irb, node, IrUnOpNegation); | 1944 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation); |
| 1933 | case PrefixOpNegationWrap: | 1945 | case PrefixOpNegationWrap: |
| 1934 | return ir_gen_prefix_op_id(irb, node, IrUnOpNegationWrap); | 1946 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap); |
| 1935 | case PrefixOpAddressOf: | 1947 | case PrefixOpAddressOf: |
| 1936 | return ir_gen_prefix_op_id_lval(irb, node, IrUnOpAddressOf, LValPurposeAddressOf); | 1948 | return ir_gen_prefix_op_id_lval(irb, scope, node, IrUnOpAddressOf, LValPurposeAddressOf); |
| 1937 | case PrefixOpConstAddressOf: | 1949 | case PrefixOpConstAddressOf: |
| 1938 | return ir_gen_prefix_op_id_lval(irb, node, IrUnOpConstAddressOf, LValPurposeAddressOf); | 1950 | return ir_gen_prefix_op_id_lval(irb, scope, node, IrUnOpConstAddressOf, LValPurposeAddressOf); |
| 1939 | case PrefixOpDereference: | 1951 | case PrefixOpDereference: |
| 1940 | return ir_gen_prefix_op_id_lval(irb, node, IrUnOpDereference, lval); | 1952 | return ir_gen_prefix_op_id_lval(irb, scope, node, IrUnOpDereference, lval); |
| 1941 | case PrefixOpMaybe: | 1953 | case PrefixOpMaybe: |
| 1942 | return ir_gen_prefix_op_id(irb, node, IrUnOpMaybe); | 1954 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe); |
| 1943 | case PrefixOpError: | 1955 | case PrefixOpError: |
| 1944 | return ir_gen_prefix_op_id(irb, node, IrUnOpError); | 1956 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpError); |
| 1945 | case PrefixOpUnwrapError: | 1957 | case PrefixOpUnwrapError: |
| 1946 | return ir_gen_prefix_op_id(irb, node, IrUnOpUnwrapError); | 1958 | return ir_gen_prefix_op_id(irb, scope, node, IrUnOpUnwrapError); |
| 1947 | case PrefixOpUnwrapMaybe: | 1959 | case PrefixOpUnwrapMaybe: |
| 1948 | return ir_gen_prefix_op_unwrap_maybe(irb, node, lval); | 1960 | return ir_gen_prefix_op_unwrap_maybe(irb, scope, node, lval); |
| 1949 | } | 1961 | } |
| 1950 | zig_unreachable(); | 1962 | zig_unreachable(); |
| 1951 | } | 1963 | } |
| 1952 | | 1964 | |
| 1953 | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node) { | 1965 | static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1954 | assert(node->type == NodeTypeContainerInitExpr); | 1966 | assert(node->type == NodeTypeContainerInitExpr); |
| 1955 | | 1967 | |
| 1956 | AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr; | 1968 | AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr; |
| 1957 | ContainerInitKind kind = container_init_expr->kind; | 1969 | ContainerInitKind kind = container_init_expr->kind; |
| 1958 | | 1970 | |
| 1959 | IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, node->scope); | 1971 | IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, scope); |
| 1960 | if (container_type == irb->codegen->invalid_instruction) | 1972 | if (container_type == irb->codegen->invalid_instruction) |
| 1961 | return container_type; | 1973 | return container_type; |
| 1962 | | 1974 | |
| ... | @@ -1969,7 +1981,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node) | ... | @@ -1969,7 +1981,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node) |
| 1969 | | 1981 | |
| 1970 | Buf *name = entry_node->data.struct_val_field.name; | 1982 | Buf *name = entry_node->data.struct_val_field.name; |
| 1971 | AstNode *expr_node = entry_node->data.struct_val_field.expr; | 1983 | AstNode *expr_node = entry_node->data.struct_val_field.expr; |
| 1972 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->scope); | 1984 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, scope); |
| 1973 | if (expr_value == irb->codegen->invalid_instruction) | 1985 | if (expr_value == irb->codegen->invalid_instruction) |
| 1974 | return expr_value; | 1986 | return expr_value; |
| 1975 | | 1987 | |
| ... | @@ -1977,39 +1989,39 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node) | ... | @@ -1977,39 +1989,39 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, AstNode *node) |
| 1977 | fields[i].value = expr_value; | 1989 | fields[i].value = expr_value; |
| 1978 | fields[i].source_node = entry_node; | 1990 | fields[i].source_node = entry_node; |
| 1979 | } | 1991 | } |
| 1980 | return ir_build_container_init_fields(irb, node, container_type, field_count, fields); | 1992 | return ir_build_container_init_fields(irb, scope, node, container_type, field_count, fields); |
| 1981 | } else if (kind == ContainerInitKindArray) { | 1993 | } else if (kind == ContainerInitKindArray) { |
| 1982 | size_t item_count = container_init_expr->entries.length; | 1994 | size_t item_count = container_init_expr->entries.length; |
| 1983 | IrInstruction **values = allocate<IrInstruction *>(item_count); | 1995 | IrInstruction **values = allocate<IrInstruction *>(item_count); |
| 1984 | for (size_t i = 0; i < item_count; i += 1) { | 1996 | for (size_t i = 0; i < item_count; i += 1) { |
| 1985 | AstNode *expr_node = container_init_expr->entries.at(i); | 1997 | AstNode *expr_node = container_init_expr->entries.at(i); |
| 1986 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, node->scope); | 1998 | IrInstruction *expr_value = ir_gen_node(irb, expr_node, scope); |
| 1987 | if (expr_value == irb->codegen->invalid_instruction) | 1999 | if (expr_value == irb->codegen->invalid_instruction) |
| 1988 | return expr_value; | 2000 | return expr_value; |
| 1989 | | 2001 | |
| 1990 | values[i] = expr_value; | 2002 | values[i] = expr_value; |
| 1991 | } | 2003 | } |
| 1992 | return ir_build_container_init_list(irb, node, container_type, item_count, values); | 2004 | return ir_build_container_init_list(irb, scope, node, container_type, item_count, values); |
| 1993 | } else { | 2005 | } else { |
| 1994 | zig_unreachable(); | 2006 | zig_unreachable(); |
| 1995 | } | 2007 | } |
| 1996 | } | 2008 | } |
| 1997 | | 2009 | |
| 1998 | static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) { | 2010 | static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1999 | assert(node->type == NodeTypeVariableDeclaration); | 2011 | assert(node->type == NodeTypeVariableDeclaration); |
| 2000 | | 2012 | |
| 2001 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; | 2013 | AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration; |
| 2002 | | 2014 | |
| 2003 | IrInstruction *type_instruction; | 2015 | IrInstruction *type_instruction; |
| 2004 | if (variable_declaration->type != nullptr) { | 2016 | if (variable_declaration->type != nullptr) { |
| 2005 | type_instruction = ir_gen_node(irb, variable_declaration->type, node->scope); | 2017 | type_instruction = ir_gen_node(irb, variable_declaration->type, scope); |
| 2006 | if (type_instruction == irb->codegen->invalid_instruction) | 2018 | if (type_instruction == irb->codegen->invalid_instruction) |
| 2007 | return type_instruction; | 2019 | return type_instruction; |
| 2008 | } else { | 2020 | } else { |
| 2009 | type_instruction = nullptr; | 2021 | type_instruction = nullptr; |
| 2010 | } | 2022 | } |
| 2011 | | 2023 | |
| 2012 | IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, node->scope); | 2024 | IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, scope); |
| 2013 | if (init_value == irb->codegen->invalid_instruction) | 2025 | if (init_value == irb->codegen->invalid_instruction) |
| 2014 | return init_value; | 2026 | return init_value; |
| 2015 | | 2027 | |
| ... | @@ -2017,7 +2029,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) { | ... | @@ -2017,7 +2029,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) { |
| 2017 | bool is_const = variable_declaration->is_const; | 2029 | bool is_const = variable_declaration->is_const; |
| 2018 | bool is_extern = variable_declaration->is_extern; | 2030 | bool is_extern = variable_declaration->is_extern; |
| 2019 | bool is_inline = ir_should_inline(irb) || variable_declaration->is_inline; | 2031 | bool is_inline = ir_should_inline(irb) || variable_declaration->is_inline; |
| 2020 | VariableTableEntry *var = ir_create_var(irb, node, node->scope, | 2032 | VariableTableEntry *var = ir_create_var(irb, node, scope, |
| 2021 | variable_declaration->symbol, is_const, is_const, is_shadowable, is_inline); | 2033 | variable_declaration->symbol, is_const, is_const, is_shadowable, is_inline); |
| 2022 | // we detect IrInstructionIdDeclVar in gen_block to make sure the next node | 2034 | // we detect IrInstructionIdDeclVar in gen_block to make sure the next node |
| 2023 | // is inside var->child_scope | 2035 | // is inside var->child_scope |
| ... | @@ -2028,10 +2040,10 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) { | ... | @@ -2028,10 +2040,10 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, AstNode *node) { |
| 2028 | return irb->codegen->invalid_instruction; | 2040 | return irb->codegen->invalid_instruction; |
| 2029 | } | 2041 | } |
| 2030 | | 2042 | |
| 2031 | return ir_build_var_decl(irb, node, var, type_instruction, init_value); | 2043 | return ir_build_var_decl(irb, scope, node, var, type_instruction, init_value); |
| 2032 | } | 2044 | } |
| 2033 | | 2045 | |
| 2034 | static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) { | 2046 | static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2035 | assert(node->type == NodeTypeWhileExpr); | 2047 | assert(node->type == NodeTypeWhileExpr); |
| 2036 | | 2048 | |
| 2037 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; | 2049 | AstNode *continue_expr_node = node->data.while_expr.continue_expr; |
| ... | @@ -2043,37 +2055,35 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2043,37 +2055,35 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, AstNode *node) { |
| 2043 | IrBasicBlock *end_block = ir_build_basic_block(irb, "WhileEnd"); | 2055 | IrBasicBlock *end_block = ir_build_basic_block(irb, "WhileEnd"); |
| 2044 | | 2056 | |
| 2045 | bool is_inline = ir_should_inline(irb) || node->data.while_expr.is_inline; | 2057 | bool is_inline = ir_should_inline(irb) || node->data.while_expr.is_inline; |
| 2046 | ir_build_br(irb, node, cond_block, is_inline); | 2058 | ir_build_br(irb, scope, node, cond_block, is_inline); |
| 2047 | | 2059 | |
| 2048 | if (continue_expr_node) { | 2060 | if (continue_expr_node) { |
| 2049 | ir_set_cursor_at_end(irb, continue_block); | 2061 | ir_set_cursor_at_end(irb, continue_block); |
| 2050 | ir_gen_node(irb, continue_expr_node, node->scope); | 2062 | ir_gen_node(irb, continue_expr_node, scope); |
| 2051 | ir_build_br(irb, node, cond_block, is_inline); | 2063 | ir_build_br(irb, scope, node, cond_block, is_inline); |
| 2052 | } | 2064 | } |
| 2053 | | 2065 | |
| 2054 | ir_set_cursor_at_end(irb, cond_block); | 2066 | ir_set_cursor_at_end(irb, cond_block); |
| 2055 | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, node->scope); | 2067 | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 2056 | ir_build_cond_br(irb, node->data.while_expr.condition, cond_val, body_block, end_block, is_inline); | 2068 | ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, body_block, end_block, is_inline); |
| 2057 | | 2069 | |
| 2058 | ir_set_cursor_at_end(irb, body_block); | 2070 | ir_set_cursor_at_end(irb, body_block); |
| 2059 | | 2071 | |
| 2060 | irb->break_block_stack.append(end_block); | 2072 | irb->break_block_stack.append(end_block); |
| 2061 | irb->continue_block_stack.append(continue_block); | 2073 | irb->continue_block_stack.append(continue_block); |
| 2062 | ir_gen_node(irb, node->data.while_expr.body, node->scope); | 2074 | ir_gen_node(irb, node->data.while_expr.body, scope); |
| 2063 | irb->break_block_stack.pop(); | 2075 | irb->break_block_stack.pop(); |
| 2064 | irb->continue_block_stack.pop(); | 2076 | irb->continue_block_stack.pop(); |
| 2065 | | 2077 | |
| 2066 | ir_build_br(irb, node, continue_block, is_inline); | 2078 | ir_build_br(irb, scope, node, continue_block, is_inline); |
| 2067 | ir_set_cursor_at_end(irb, end_block); | 2079 | ir_set_cursor_at_end(irb, end_block); |
| 2068 | | 2080 | |
| 2069 | return ir_build_const_void(irb, node); | 2081 | return ir_build_const_void(irb, scope, node); |
| 2070 | } | 2082 | } |
| 2071 | | 2083 | |
| 2072 | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { | 2084 | static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| 2073 | assert(node->type == NodeTypeForExpr); | 2085 | assert(node->type == NodeTypeForExpr); |
| 2074 | | 2086 | |
| 2075 | Scope *parent_scope = node->scope; | | |
| 2076 | | | |
| 2077 | AstNode *array_node = node->data.for_expr.array_expr; | 2087 | AstNode *array_node = node->data.for_expr.array_expr; |
| 2078 | AstNode *elem_node = node->data.for_expr.elem_node; | 2088 | AstNode *elem_node = node->data.for_expr.elem_node; |
| 2079 | AstNode *index_node = node->data.for_expr.index_node; | 2089 | AstNode *index_node = node->data.for_expr.index_node; |
| ... | @@ -2089,48 +2099,45 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2089,48 +2099,45 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { |
| 2089 | if (array_val == irb->codegen->invalid_instruction) | 2099 | if (array_val == irb->codegen->invalid_instruction) |
| 2090 | return array_val; | 2100 | return array_val; |
| 2091 | | 2101 | |
| 2092 | IrInstruction *array_type = ir_build_typeof(irb, array_node, array_val); | 2102 | IrInstruction *array_type = ir_build_typeof(irb, parent_scope, array_node, array_val); |
| 2093 | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, array_node, array_type); | 2103 | IrInstruction *pointer_type = ir_build_to_ptr_type(irb, parent_scope, array_node, array_type); |
| 2094 | IrInstruction *elem_var_type; | 2104 | IrInstruction *elem_var_type; |
| 2095 | if (node->data.for_expr.elem_is_ptr) { | 2105 | if (node->data.for_expr.elem_is_ptr) { |
| 2096 | elem_var_type = pointer_type; | 2106 | elem_var_type = pointer_type; |
| 2097 | } else { | 2107 | } else { |
| 2098 | elem_var_type = ir_build_ptr_type_child(irb, elem_node, pointer_type); | 2108 | elem_var_type = ir_build_ptr_type_child(irb, parent_scope, elem_node, pointer_type); |
| 2099 | } | 2109 | } |
| 2100 | bool is_inline = ir_should_inline(irb) || node->data.for_expr.is_inline; | 2110 | bool is_inline = ir_should_inline(irb) || node->data.for_expr.is_inline; |
| 2101 | | 2111 | |
| 2102 | Scope *child_scope = create_loop_scope(node, parent_scope); | 2112 | Scope *child_scope = create_loop_scope(node, parent_scope); |
| 2103 | elem_node->scope = child_scope; | | |
| 2104 | | 2113 | |
| 2105 | // TODO make it an error to write to element variable or i variable. | 2114 | // TODO make it an error to write to element variable or i variable. |
| 2106 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; | 2115 | Buf *elem_var_name = elem_node->data.symbol_expr.symbol; |
| 2107 | node->data.for_expr.elem_var = ir_create_var(irb, elem_node, child_scope, elem_var_name, | 2116 | VariableTableEntry *elem_var = ir_create_var(irb, elem_node, child_scope, elem_var_name, |
| 2108 | true, false, false, is_inline); | 2117 | true, false, false, is_inline); |
| 2109 | child_scope = node->data.for_expr.elem_var->child_scope; | 2118 | child_scope = elem_var->child_scope; |
| 2110 | | 2119 | |
| 2111 | IrInstruction *undefined_value = ir_build_const_undefined(irb, elem_node); | 2120 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); |
| 2112 | ir_build_var_decl(irb, elem_node, node->data.for_expr.elem_var, elem_var_type, undefined_value); | 2121 | ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, undefined_value); |
| 2113 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, node, node->data.for_expr.elem_var); | 2122 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 2114 | | 2123 | |
| 2115 | AstNode *index_var_source_node; | 2124 | AstNode *index_var_source_node; |
| | 2125 | VariableTableEntry *index_var; |
| 2116 | if (index_node) { | 2126 | if (index_node) { |
| 2117 | index_var_source_node = index_node; | 2127 | index_var_source_node = index_node; |
| 2118 | Buf *index_var_name = index_node->data.symbol_expr.symbol; | 2128 | Buf *index_var_name = index_node->data.symbol_expr.symbol; |
| 2119 | index_node->scope = child_scope; | 2129 | index_var = ir_create_var(irb, index_node, child_scope, index_var_name, true, false, false, is_inline); |
| 2120 | node->data.for_expr.index_var = ir_create_var(irb, index_node, child_scope, index_var_name, | | |
| 2121 | true, false, false, is_inline); | | |
| 2122 | } else { | 2130 | } else { |
| 2123 | index_var_source_node = node; | 2131 | index_var_source_node = node; |
| 2124 | node->data.for_expr.index_var = ir_create_var(irb, node, child_scope, nullptr, | 2132 | index_var = ir_create_var(irb, node, child_scope, nullptr, true, false, true, is_inline); |
| 2125 | true, false, true, is_inline); | | |
| 2126 | } | 2133 | } |
| 2127 | child_scope = node->data.for_expr.index_var->child_scope; | 2134 | child_scope = index_var->child_scope; |
| 2128 | | 2135 | |
| 2129 | IrInstruction *usize = ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_usize); | 2136 | IrInstruction *usize = ir_build_const_type(irb, child_scope, node, irb->codegen->builtin_types.entry_usize); |
| 2130 | IrInstruction *zero = ir_build_const_usize(irb, node, 0); | 2137 | IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0); |
| 2131 | IrInstruction *one = ir_build_const_usize(irb, node, 1); | 2138 | IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1); |
| 2132 | ir_build_var_decl(irb, index_var_source_node, node->data.for_expr.index_var, usize, zero); | 2139 | ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, zero); |
| 2133 | IrInstruction *index_ptr = ir_build_var_ptr(irb, node, node->data.for_expr.index_var); | 2140 | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var); |
| 2134 | | 2141 | |
| 2135 | | 2142 | |
| 2136 | IrBasicBlock *cond_block = ir_build_basic_block(irb, "ForCond"); | 2143 | IrBasicBlock *cond_block = ir_build_basic_block(irb, "ForCond"); |
| ... | @@ -2138,23 +2145,23 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2138,23 +2145,23 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { |
| 2138 | IrBasicBlock *end_block = ir_build_basic_block(irb, "ForEnd"); | 2145 | IrBasicBlock *end_block = ir_build_basic_block(irb, "ForEnd"); |
| 2139 | IrBasicBlock *continue_block = ir_build_basic_block(irb, "ForContinue"); | 2146 | IrBasicBlock *continue_block = ir_build_basic_block(irb, "ForContinue"); |
| 2140 | | 2147 | |
| 2141 | IrInstruction *len_val = ir_build_array_len(irb, node, array_val); | 2148 | IrInstruction *len_val = ir_build_array_len(irb, child_scope, node, array_val); |
| 2142 | ir_build_br(irb, node, cond_block, is_inline); | 2149 | ir_build_br(irb, child_scope, node, cond_block, is_inline); |
| 2143 | | 2150 | |
| 2144 | ir_set_cursor_at_end(irb, cond_block); | 2151 | ir_set_cursor_at_end(irb, cond_block); |
| 2145 | IrInstruction *index_val = ir_build_load_ptr(irb, node, index_ptr); | 2152 | IrInstruction *index_val = ir_build_load_ptr(irb, child_scope, node, index_ptr); |
| 2146 | IrInstruction *cond = ir_build_bin_op(irb, node, IrBinOpCmpLessThan, index_val, len_val); | 2153 | IrInstruction *cond = ir_build_bin_op(irb, child_scope, node, IrBinOpCmpLessThan, index_val, len_val); |
| 2147 | ir_build_cond_br(irb, node, cond, body_block, end_block, is_inline); | 2154 | ir_build_cond_br(irb, child_scope, node, cond, body_block, end_block, is_inline); |
| 2148 | | 2155 | |
| 2149 | ir_set_cursor_at_end(irb, body_block); | 2156 | ir_set_cursor_at_end(irb, body_block); |
| 2150 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, node, array_val, index_val, true); | 2157 | IrInstruction *elem_ptr = ir_build_elem_ptr(irb, child_scope, node, array_val, index_val, true); |
| 2151 | IrInstruction *elem_val; | 2158 | IrInstruction *elem_val; |
| 2152 | if (node->data.for_expr.elem_is_ptr) { | 2159 | if (node->data.for_expr.elem_is_ptr) { |
| 2153 | elem_val = elem_ptr; | 2160 | elem_val = elem_ptr; |
| 2154 | } else { | 2161 | } else { |
| 2155 | elem_val = ir_build_load_ptr(irb, node, elem_ptr); | 2162 | elem_val = ir_build_load_ptr(irb, child_scope, node, elem_ptr); |
| 2156 | } | 2163 | } |
| 2157 | ir_build_store_ptr(irb, node, elem_var_ptr, elem_val); | 2164 | ir_build_store_ptr(irb, child_scope, node, elem_var_ptr, elem_val); |
| 2158 | | 2165 | |
| 2159 | irb->break_block_stack.append(end_block); | 2166 | irb->break_block_stack.append(end_block); |
| 2160 | irb->continue_block_stack.append(continue_block); | 2167 | irb->continue_block_stack.append(continue_block); |
| ... | @@ -2162,61 +2169,60 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2162,61 +2169,60 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, AstNode *node) { |
| 2162 | irb->break_block_stack.pop(); | 2169 | irb->break_block_stack.pop(); |
| 2163 | irb->continue_block_stack.pop(); | 2170 | irb->continue_block_stack.pop(); |
| 2164 | | 2171 | |
| 2165 | ir_build_br(irb, node, continue_block, is_inline); | 2172 | ir_build_br(irb, child_scope, node, continue_block, is_inline); |
| 2166 | | 2173 | |
| 2167 | ir_set_cursor_at_end(irb, continue_block); | 2174 | ir_set_cursor_at_end(irb, continue_block); |
| 2168 | IrInstruction *new_index_val = ir_build_bin_op(irb, node, IrBinOpAdd, index_val, one); | 2175 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one); |
| 2169 | ir_build_store_ptr(irb, node, index_ptr, new_index_val); | 2176 | ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val); |
| 2170 | ir_build_br(irb, node, cond_block, is_inline); | 2177 | ir_build_br(irb, child_scope, node, cond_block, is_inline); |
| 2171 | | 2178 | |
| 2172 | ir_set_cursor_at_end(irb, end_block); | 2179 | ir_set_cursor_at_end(irb, end_block); |
| 2173 | return ir_build_const_void(irb, node); | 2180 | return ir_build_const_void(irb, child_scope, node); |
| 2174 | | 2181 | |
| 2175 | } | 2182 | } |
| 2176 | | 2183 | |
| 2177 | static IrInstruction *ir_gen_this_literal(IrBuilder *irb, AstNode *node) { | 2184 | static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2178 | assert(node->type == NodeTypeThisLiteral); | 2185 | assert(node->type == NodeTypeThisLiteral); |
| 2179 | | 2186 | |
| 2180 | Scope *scope = node->scope; | | |
| 2181 | | | |
| 2182 | if (!scope->parent) | 2187 | if (!scope->parent) |
| 2183 | return ir_build_const_import(irb, node, node->owner); | 2188 | return ir_build_const_import(irb, scope, node, node->owner); |
| 2184 | | 2189 | |
| 2185 | FnTableEntry *fn_entry = scope_fn_entry(scope); | 2190 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); |
| 2186 | if (fn_entry && scope->parent && scope->parent->parent && | 2191 | if (fn_entry && scope->parent && scope->parent->parent && |
| 2187 | !scope_fn_entry(scope->parent->parent)) | 2192 | !scope_fn_entry(scope->parent->parent)) |
| 2188 | { | 2193 | { |
| 2189 | return ir_build_const_fn(irb, node, fn_entry); | 2194 | return ir_build_const_fn(irb, scope, node, fn_entry); |
| 2190 | } | 2195 | } |
| 2191 | | 2196 | |
| 2192 | if (scope->node->type == NodeTypeContainerDecl) { | 2197 | if (scope->node->type == NodeTypeContainerDecl) { |
| 2193 | TypeTableEntry *container_type = scope->node->data.struct_decl.type_entry; | 2198 | ScopeDecls *decls_scope = (ScopeDecls *)scope; |
| | 2199 | TypeTableEntry *container_type = decls_scope->container_type; |
| 2194 | assert(container_type); | 2200 | assert(container_type); |
| 2195 | return ir_build_const_type(irb, node, container_type); | 2201 | return ir_build_const_type(irb, scope, node, container_type); |
| 2196 | } | 2202 | } |
| 2197 | | 2203 | |
| 2198 | if (scope->node->type == NodeTypeBlock) | 2204 | if (scope->node->type == NodeTypeBlock) |
| 2199 | return ir_build_const_scope(irb, node, scope); | 2205 | return ir_build_const_scope(irb, scope, node, scope); |
| 2200 | | 2206 | |
| 2201 | zig_unreachable(); | 2207 | zig_unreachable(); |
| 2202 | } | 2208 | } |
| 2203 | | 2209 | |
| 2204 | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, AstNode *node) { | 2210 | static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2205 | assert(node->type == NodeTypeBoolLiteral); | 2211 | assert(node->type == NodeTypeBoolLiteral); |
| 2206 | return ir_build_const_bool(irb, node, node->data.bool_literal.value); | 2212 | return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value); |
| 2207 | } | 2213 | } |
| 2208 | | 2214 | |
| 2209 | static IrInstruction *ir_gen_string_literal(IrBuilder *irb, AstNode *node) { | 2215 | static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2210 | assert(node->type == NodeTypeStringLiteral); | 2216 | assert(node->type == NodeTypeStringLiteral); |
| 2211 | | 2217 | |
| 2212 | if (node->data.string_literal.c) { | 2218 | if (node->data.string_literal.c) { |
| 2213 | return ir_build_const_c_str_lit(irb, node, node->data.string_literal.buf); | 2219 | return ir_build_const_c_str_lit(irb, scope, node, node->data.string_literal.buf); |
| 2214 | } else { | 2220 | } else { |
| 2215 | return ir_build_const_str_lit(irb, node, node->data.string_literal.buf); | 2221 | return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf); |
| 2216 | } | 2222 | } |
| 2217 | } | 2223 | } |
| 2218 | | 2224 | |
| 2219 | static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) { | 2225 | static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2220 | assert(node->type == NodeTypeArrayType); | 2226 | assert(node->type == NodeTypeArrayType); |
| 2221 | | 2227 | |
| 2222 | AstNode *size_node = node->data.array_type.size; | 2228 | AstNode *size_node = node->data.array_type.size; |
| ... | @@ -2229,35 +2235,36 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) { | ... | @@ -2229,35 +2235,36 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, AstNode *node) { |
| 2229 | return irb->codegen->invalid_instruction; | 2235 | return irb->codegen->invalid_instruction; |
| 2230 | } | 2236 | } |
| 2231 | | 2237 | |
| 2232 | IrInstruction *size_value = ir_gen_node(irb, size_node, node->scope); | 2238 | IrInstruction *size_value = ir_gen_node(irb, size_node, scope); |
| 2233 | if (size_value == irb->codegen->invalid_instruction) | 2239 | if (size_value == irb->codegen->invalid_instruction) |
| 2234 | return size_value; | 2240 | return size_value; |
| 2235 | | 2241 | |
| 2236 | IrInstruction *child_type = ir_gen_node(irb, child_type_node, node->scope); | 2242 | IrInstruction *child_type = ir_gen_node(irb, child_type_node, scope); |
| 2237 | if (child_type == irb->codegen->invalid_instruction) | 2243 | if (child_type == irb->codegen->invalid_instruction) |
| 2238 | return child_type; | 2244 | return child_type; |
| 2239 | | 2245 | |
| 2240 | return ir_build_array_type(irb, node, size_value, child_type); | 2246 | return ir_build_array_type(irb, scope, node, size_value, child_type); |
| 2241 | } else { | 2247 | } else { |
| 2242 | IrInstruction *child_type = ir_gen_node_extra(irb, child_type_node, | 2248 | IrInstruction *child_type = ir_gen_node_extra(irb, child_type_node, |
| 2243 | node->scope, LValPurposeAddressOf); | 2249 | scope, LValPurposeAddressOf); |
| 2244 | if (child_type == irb->codegen->invalid_instruction) | 2250 | if (child_type == irb->codegen->invalid_instruction) |
| 2245 | return child_type; | 2251 | return child_type; |
| 2246 | | 2252 | |
| 2247 | return ir_build_slice_type(irb, node, is_const, child_type); | 2253 | return ir_build_slice_type(irb, scope, node, is_const, child_type); |
| 2248 | } | 2254 | } |
| 2249 | } | 2255 | } |
| 2250 | | 2256 | |
| 2251 | static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, AstNode *node) { | 2257 | static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2252 | assert(node->type == NodeTypeUndefinedLiteral); | 2258 | assert(node->type == NodeTypeUndefinedLiteral); |
| 2253 | return ir_build_const_undefined(irb, node); | 2259 | return ir_build_const_undefined(irb, scope, node); |
| 2254 | } | 2260 | } |
| 2255 | | 2261 | |
| 2256 | static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { | 2262 | static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2257 | assert(node->type == NodeTypeAsmExpr); | 2263 | assert(node->type == NodeTypeAsmExpr); |
| 2258 | | 2264 | |
| 2259 | IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length); | 2265 | IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length); |
| 2260 | IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length); | 2266 | IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length); |
| | 2267 | VariableTableEntry **output_vars = allocate<VariableTableEntry *>(node->data.asm_expr.output_list.length); |
| 2261 | size_t return_count = 0; | 2268 | size_t return_count = 0; |
| 2262 | bool is_volatile = node->data.asm_expr.is_volatile; | 2269 | bool is_volatile = node->data.asm_expr.is_volatile; |
| 2263 | if (!is_volatile && node->data.asm_expr.output_list.length == 0) { | 2270 | if (!is_volatile && node->data.asm_expr.output_list.length == 0) { |
| ... | @@ -2270,7 +2277,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2270,7 +2277,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { |
| 2270 | if (asm_output->return_type) { | 2277 | if (asm_output->return_type) { |
| 2271 | return_count += 1; | 2278 | return_count += 1; |
| 2272 | | 2279 | |
| 2273 | IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, node->scope); | 2280 | IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope); |
| 2274 | if (return_type == irb->codegen->invalid_instruction) | 2281 | if (return_type == irb->codegen->invalid_instruction) |
| 2275 | return irb->codegen->invalid_instruction; | 2282 | return irb->codegen->invalid_instruction; |
| 2276 | if (return_count > 1) { | 2283 | if (return_count > 1) { |
| ... | @@ -2281,9 +2288,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2281,9 +2288,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { |
| 2281 | output_types[i] = return_type; | 2288 | output_types[i] = return_type; |
| 2282 | } else { | 2289 | } else { |
| 2283 | Buf *variable_name = asm_output->variable_name; | 2290 | Buf *variable_name = asm_output->variable_name; |
| 2284 | VariableTableEntry *var = find_variable(irb->codegen, node->scope, variable_name); | 2291 | VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); |
| 2285 | if (var) { | 2292 | if (var) { |
| 2286 | asm_output->variable = var; | 2293 | output_vars[i] = var; |
| 2287 | } else { | 2294 | } else { |
| 2288 | add_node_error(irb->codegen, node, | 2295 | add_node_error(irb->codegen, node, |
| 2289 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); | 2296 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); |
| ... | @@ -2293,17 +2300,17 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2293,17 +2300,17 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, AstNode *node) { |
| 2293 | } | 2300 | } |
| 2294 | for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) { | 2301 | for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) { |
| 2295 | AsmInput *asm_input = node->data.asm_expr.input_list.at(i); | 2302 | AsmInput *asm_input = node->data.asm_expr.input_list.at(i); |
| 2296 | IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, node->scope); | 2303 | IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope); |
| 2297 | if (input_value == irb->codegen->invalid_instruction) | 2304 | if (input_value == irb->codegen->invalid_instruction) |
| 2298 | return irb->codegen->invalid_instruction; | 2305 | return irb->codegen->invalid_instruction; |
| 2299 | | 2306 | |
| 2300 | input_list[i] = input_value; | 2307 | input_list[i] = input_value; |
| 2301 | } | 2308 | } |
| 2302 | | 2309 | |
| 2303 | return ir_build_asm(irb, node, input_list, output_types, return_count, is_volatile); | 2310 | return ir_build_asm(irb, scope, node, input_list, output_types, output_vars, return_count, is_volatile); |
| 2304 | } | 2311 | } |
| 2305 | | 2312 | |
| 2306 | static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) { | 2313 | static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2307 | assert(node->type == NodeTypeIfVarExpr); | 2314 | assert(node->type == NodeTypeIfVarExpr); |
| 2308 | | 2315 | |
| 2309 | AstNodeVariableDeclaration *var_decl = &node->data.if_var_expr.var_decl; | 2316 | AstNodeVariableDeclaration *var_decl = &node->data.if_var_expr.var_decl; |
| ... | @@ -2312,51 +2319,51 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2312,51 +2319,51 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) { |
| 2312 | AstNode *else_node = node->data.if_var_expr.else_node; | 2319 | AstNode *else_node = node->data.if_var_expr.else_node; |
| 2313 | bool var_is_ptr = node->data.if_var_expr.var_is_ptr; | 2320 | bool var_is_ptr = node->data.if_var_expr.var_is_ptr; |
| 2314 | | 2321 | |
| 2315 | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, node->scope, LValPurposeAddressOf); | 2322 | IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValPurposeAddressOf); |
| 2316 | if (expr_value == irb->codegen->invalid_instruction) | 2323 | if (expr_value == irb->codegen->invalid_instruction) |
| 2317 | return expr_value; | 2324 | return expr_value; |
| 2318 | | 2325 | |
| 2319 | IrInstruction *is_nonnull_value = ir_build_test_null(irb, node, expr_value); | 2326 | IrInstruction *is_nonnull_value = ir_build_test_null(irb, scope, node, expr_value); |
| 2320 | | 2327 | |
| 2321 | IrBasicBlock *then_block = ir_build_basic_block(irb, "MaybeThen"); | 2328 | IrBasicBlock *then_block = ir_build_basic_block(irb, "MaybeThen"); |
| 2322 | IrBasicBlock *else_block = ir_build_basic_block(irb, "MaybeElse"); | 2329 | IrBasicBlock *else_block = ir_build_basic_block(irb, "MaybeElse"); |
| 2323 | IrBasicBlock *endif_block = ir_build_basic_block(irb, "MaybeEndIf"); | 2330 | IrBasicBlock *endif_block = ir_build_basic_block(irb, "MaybeEndIf"); |
| 2324 | | 2331 | |
| 2325 | bool is_inline = ir_should_inline(irb) || node->data.if_var_expr.is_inline; | 2332 | bool is_inline = ir_should_inline(irb) || node->data.if_var_expr.is_inline; |
| 2326 | ir_build_cond_br(irb, node, is_nonnull_value, then_block, else_block, is_inline); | 2333 | ir_build_cond_br(irb, scope, node, is_nonnull_value, then_block, else_block, is_inline); |
| 2327 | | 2334 | |
| 2328 | ir_set_cursor_at_end(irb, then_block); | 2335 | ir_set_cursor_at_end(irb, then_block); |
| 2329 | IrInstruction *var_type = nullptr; | 2336 | IrInstruction *var_type = nullptr; |
| 2330 | if (var_decl->type) { | 2337 | if (var_decl->type) { |
| 2331 | var_type = ir_gen_node(irb, var_decl->type, node->scope); | 2338 | var_type = ir_gen_node(irb, var_decl->type, scope); |
| 2332 | if (var_type == irb->codegen->invalid_instruction) | 2339 | if (var_type == irb->codegen->invalid_instruction) |
| 2333 | return irb->codegen->invalid_instruction; | 2340 | return irb->codegen->invalid_instruction; |
| 2334 | } | 2341 | } |
| 2335 | bool is_shadowable = false; | 2342 | bool is_shadowable = false; |
| 2336 | bool is_const = var_decl->is_const; | 2343 | bool is_const = var_decl->is_const; |
| 2337 | VariableTableEntry *var = ir_create_var(irb, node, node->scope, | 2344 | VariableTableEntry *var = ir_create_var(irb, node, scope, |
| 2338 | var_decl->symbol, is_const, is_const, is_shadowable, is_inline); | 2345 | var_decl->symbol, is_const, is_const, is_shadowable, is_inline); |
| 2339 | | 2346 | |
| 2340 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, node, expr_value, false); | 2347 | IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, scope, node, expr_value, false); |
| 2341 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, node, var_ptr_value); | 2348 | IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value); |
| 2342 | ir_build_var_decl(irb, node, var, var_type, var_value); | 2349 | ir_build_var_decl(irb, scope, node, var, var_type, var_value); |
| 2343 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var->child_scope); | 2350 | IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var->child_scope); |
| 2344 | if (then_expr_result == irb->codegen->invalid_instruction) | 2351 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 2345 | return then_expr_result; | 2352 | return then_expr_result; |
| 2346 | IrBasicBlock *after_then_block = irb->current_basic_block; | 2353 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 2347 | ir_build_br(irb, node, endif_block, is_inline); | 2354 | ir_build_br(irb, scope, node, endif_block, is_inline); |
| 2348 | | 2355 | |
| 2349 | ir_set_cursor_at_end(irb, else_block); | 2356 | ir_set_cursor_at_end(irb, else_block); |
| 2350 | IrInstruction *else_expr_result; | 2357 | IrInstruction *else_expr_result; |
| 2351 | if (else_node) { | 2358 | if (else_node) { |
| 2352 | else_expr_result = ir_gen_node(irb, else_node, node->scope); | 2359 | else_expr_result = ir_gen_node(irb, else_node, scope); |
| 2353 | if (else_expr_result == irb->codegen->invalid_instruction) | 2360 | if (else_expr_result == irb->codegen->invalid_instruction) |
| 2354 | return else_expr_result; | 2361 | return else_expr_result; |
| 2355 | } else { | 2362 | } else { |
| 2356 | else_expr_result = ir_build_const_void(irb, node); | 2363 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 2357 | } | 2364 | } |
| 2358 | IrBasicBlock *after_else_block = irb->current_basic_block; | 2365 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 2359 | ir_build_br(irb, node, endif_block, is_inline); | 2366 | ir_build_br(irb, scope, node, endif_block, is_inline); |
| 2360 | | 2367 | |
| 2361 | ir_set_cursor_at_end(irb, endif_block); | 2368 | ir_set_cursor_at_end(irb, endif_block); |
| 2362 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); | 2369 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| ... | @@ -2366,10 +2373,10 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2366,10 +2373,10 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) { |
| 2366 | incoming_blocks[0] = after_then_block; | 2373 | incoming_blocks[0] = after_then_block; |
| 2367 | incoming_blocks[1] = after_else_block; | 2374 | incoming_blocks[1] = after_else_block; |
| 2368 | | 2375 | |
| 2369 | return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values); | 2376 | return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values); |
| 2370 | } | 2377 | } |
| 2371 | | 2378 | |
| 2372 | static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNode *prong_node, | 2379 | static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node, |
| 2373 | IrBasicBlock *end_block, bool is_inline, IrInstruction *target_value_ptr, IrInstruction *prong_value, | 2380 | IrBasicBlock *end_block, bool is_inline, IrInstruction *target_value_ptr, IrInstruction *prong_value, |
| 2374 | ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values) | 2381 | ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values) |
| 2375 | { | 2382 | { |
| ... | @@ -2386,39 +2393,39 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo | ... | @@ -2386,39 +2393,39 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, AstNode *switch_node, AstNo |
| 2386 | | 2393 | |
| 2387 | bool is_shadowable = false; | 2394 | bool is_shadowable = false; |
| 2388 | bool is_const = true; | 2395 | bool is_const = true; |
| 2389 | VariableTableEntry *var = ir_create_var(irb, var_symbol_node, switch_node->scope, | 2396 | VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope, |
| 2390 | var_name, is_const, is_const, is_shadowable, is_inline); | 2397 | var_name, is_const, is_const, is_shadowable, is_inline); |
| 2391 | child_scope = var->child_scope; | 2398 | child_scope = var->child_scope; |
| 2392 | IrInstruction *var_value; | 2399 | IrInstruction *var_value; |
| 2393 | if (prong_value) { | 2400 | if (prong_value) { |
| 2394 | IrInstruction *var_ptr_value = ir_build_switch_var(irb, var_symbol_node, target_value_ptr, prong_value); | 2401 | IrInstruction *var_ptr_value = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, prong_value); |
| 2395 | var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, var_symbol_node, var_ptr_value); | 2402 | var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, var_symbol_node, var_ptr_value); |
| 2396 | } else { | 2403 | } else { |
| 2397 | var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, var_symbol_node, target_value_ptr); | 2404 | var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, target_value_ptr); |
| 2398 | } | 2405 | } |
| 2399 | IrInstruction *var_type = nullptr; // infer the type | 2406 | IrInstruction *var_type = nullptr; // infer the type |
| 2400 | ir_build_var_decl(irb, var_symbol_node, var, var_type, var_value); | 2407 | ir_build_var_decl(irb, scope, var_symbol_node, var, var_type, var_value); |
| 2401 | } else { | 2408 | } else { |
| 2402 | child_scope = switch_node->scope; | 2409 | child_scope = scope; |
| 2403 | } | 2410 | } |
| 2404 | | 2411 | |
| 2405 | IrInstruction *expr_result = ir_gen_node(irb, expr_node, child_scope); | 2412 | IrInstruction *expr_result = ir_gen_node(irb, expr_node, child_scope); |
| 2406 | if (expr_result == irb->codegen->invalid_instruction) | 2413 | if (expr_result == irb->codegen->invalid_instruction) |
| 2407 | return false; | 2414 | return false; |
| 2408 | ir_build_br(irb, switch_node, end_block, is_inline); | 2415 | ir_build_br(irb, scope, switch_node, end_block, is_inline); |
| 2409 | incoming_blocks->append(irb->current_basic_block); | 2416 | incoming_blocks->append(irb->current_basic_block); |
| 2410 | incoming_values->append(expr_result); | 2417 | incoming_values->append(expr_result); |
| 2411 | return true; | 2418 | return true; |
| 2412 | } | 2419 | } |
| 2413 | | 2420 | |
| 2414 | static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | 2421 | static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2415 | assert(node->type == NodeTypeSwitchExpr); | 2422 | assert(node->type == NodeTypeSwitchExpr); |
| 2416 | | 2423 | |
| 2417 | AstNode *target_node = node->data.switch_expr.expr; | 2424 | AstNode *target_node = node->data.switch_expr.expr; |
| 2418 | IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, node->scope, LValPurposeAddressOf); | 2425 | IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPurposeAddressOf); |
| 2419 | if (target_value_ptr == irb->codegen->invalid_instruction) | 2426 | if (target_value_ptr == irb->codegen->invalid_instruction) |
| 2420 | return target_value_ptr; | 2427 | return target_value_ptr; |
| 2421 | IrInstruction *target_value = ir_build_switch_target(irb, node, target_value_ptr); | 2428 | IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr); |
| 2422 | | 2429 | |
| 2423 | IrBasicBlock *else_block = ir_build_basic_block(irb, "SwitchElse"); | 2430 | IrBasicBlock *else_block = ir_build_basic_block(irb, "SwitchElse"); |
| 2424 | IrBasicBlock *end_block = ir_build_basic_block(irb, "SwitchEnd"); | 2431 | IrBasicBlock *end_block = ir_build_basic_block(irb, "SwitchEnd"); |
| ... | @@ -2446,7 +2453,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2446,7 +2453,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2446 | | 2453 | |
| 2447 | IrBasicBlock *prev_block = irb->current_basic_block; | 2454 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 2448 | ir_set_cursor_at_end(irb, else_block); | 2455 | ir_set_cursor_at_end(irb, else_block); |
| 2449 | if (!ir_gen_switch_prong_expr(irb, node, prong_node, end_block, | 2456 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| 2450 | is_inline, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | 2457 | is_inline, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 2451 | { | 2458 | { |
| 2452 | return irb->codegen->invalid_instruction; | 2459 | return irb->codegen->invalid_instruction; |
| ... | @@ -2460,41 +2467,40 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2460,41 +2467,40 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2460 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); | 2467 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 2461 | last_item_node = item_node; | 2468 | last_item_node = item_node; |
| 2462 | if (item_node->type == NodeTypeSwitchRange) { | 2469 | if (item_node->type == NodeTypeSwitchRange) { |
| 2463 | item_node->scope = node->scope; | | |
| 2464 | AstNode *start_node = item_node->data.switch_range.start; | 2470 | AstNode *start_node = item_node->data.switch_range.start; |
| 2465 | AstNode *end_node = item_node->data.switch_range.end; | 2471 | AstNode *end_node = item_node->data.switch_range.end; |
| 2466 | | 2472 | |
| 2467 | IrInstruction *start_value = ir_gen_node(irb, start_node, node->scope); | 2473 | IrInstruction *start_value = ir_gen_node(irb, start_node, scope); |
| 2468 | if (start_value == irb->codegen->invalid_instruction) | 2474 | if (start_value == irb->codegen->invalid_instruction) |
| 2469 | return irb->codegen->invalid_instruction; | 2475 | return irb->codegen->invalid_instruction; |
| 2470 | | 2476 | |
| 2471 | IrInstruction *end_value = ir_gen_node(irb, end_node, node->scope); | 2477 | IrInstruction *end_value = ir_gen_node(irb, end_node, scope); |
| 2472 | if (end_value == irb->codegen->invalid_instruction) | 2478 | if (end_value == irb->codegen->invalid_instruction) |
| 2473 | return irb->codegen->invalid_instruction; | 2479 | return irb->codegen->invalid_instruction; |
| 2474 | | 2480 | |
| 2475 | IrInstruction *start_value_const = ir_build_static_eval(irb, start_node, start_value); | 2481 | IrInstruction *start_value_const = ir_build_static_eval(irb, scope, start_node, start_value); |
| 2476 | IrInstruction *end_value_const = ir_build_static_eval(irb, start_node, end_value); | 2482 | IrInstruction *end_value_const = ir_build_static_eval(irb, scope, start_node, end_value); |
| 2477 | | 2483 | |
| 2478 | IrInstruction *lower_range_ok = ir_build_bin_op(irb, item_node, IrBinOpCmpGreaterOrEq, | 2484 | IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq, |
| 2479 | target_value, start_value_const); | 2485 | target_value, start_value_const); |
| 2480 | IrInstruction *upper_range_ok = ir_build_bin_op(irb, item_node, IrBinOpCmpLessOrEq, | 2486 | IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq, |
| 2481 | target_value, end_value_const); | 2487 | target_value, end_value_const); |
| 2482 | IrInstruction *both_ok = ir_build_bin_op(irb, item_node, IrBinOpBoolAnd, | 2488 | IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd, |
| 2483 | lower_range_ok, upper_range_ok); | 2489 | lower_range_ok, upper_range_ok); |
| 2484 | if (ok_bit) { | 2490 | if (ok_bit) { |
| 2485 | ok_bit = ir_build_bin_op(irb, item_node, IrBinOpBoolOr, both_ok, ok_bit); | 2491 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit); |
| 2486 | } else { | 2492 | } else { |
| 2487 | ok_bit = both_ok; | 2493 | ok_bit = both_ok; |
| 2488 | } | 2494 | } |
| 2489 | } else { | 2495 | } else { |
| 2490 | IrInstruction *item_value = ir_gen_node(irb, item_node, node->scope); | 2496 | IrInstruction *item_value = ir_gen_node(irb, item_node, scope); |
| 2491 | if (item_value == irb->codegen->invalid_instruction) | 2497 | if (item_value == irb->codegen->invalid_instruction) |
| 2492 | return irb->codegen->invalid_instruction; | 2498 | return irb->codegen->invalid_instruction; |
| 2493 | | 2499 | |
| 2494 | IrInstruction *cmp_ok = ir_build_bin_op(irb, item_node, IrBinOpCmpEq, | 2500 | IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq, |
| 2495 | item_value, target_value); | 2501 | item_value, target_value); |
| 2496 | if (ok_bit) { | 2502 | if (ok_bit) { |
| 2497 | ok_bit = ir_build_bin_op(irb, item_node, IrBinOpBoolOr, cmp_ok, ok_bit); | 2503 | ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit); |
| 2498 | } else { | 2504 | } else { |
| 2499 | ok_bit = cmp_ok; | 2505 | ok_bit = cmp_ok; |
| 2500 | } | 2506 | } |
| ... | @@ -2506,10 +2512,10 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2506,10 +2512,10 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2506 | | 2512 | |
| 2507 | assert(ok_bit); | 2513 | assert(ok_bit); |
| 2508 | assert(last_item_node); | 2514 | assert(last_item_node); |
| 2509 | ir_build_cond_br(irb, last_item_node, ok_bit, range_block_yes, range_block_no, is_inline); | 2515 | ir_build_cond_br(irb, scope, last_item_node, ok_bit, range_block_yes, range_block_no, is_inline); |
| 2510 | | 2516 | |
| 2511 | ir_set_cursor_at_end(irb, range_block_yes); | 2517 | ir_set_cursor_at_end(irb, range_block_yes); |
| 2512 | if (!ir_gen_switch_prong_expr(irb, node, prong_node, end_block, | 2518 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| 2513 | is_inline, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) | 2519 | is_inline, target_value_ptr, nullptr, &incoming_blocks, &incoming_values)) |
| 2514 | { | 2520 | { |
| 2515 | return irb->codegen->invalid_instruction; | 2521 | return irb->codegen->invalid_instruction; |
| ... | @@ -2524,7 +2530,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2524,7 +2530,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2524 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); | 2530 | AstNode *item_node = prong_node->data.switch_prong.items.at(item_i); |
| 2525 | assert(item_node->type != NodeTypeSwitchRange); | 2531 | assert(item_node->type != NodeTypeSwitchRange); |
| 2526 | | 2532 | |
| 2527 | IrInstruction *item_value = ir_gen_node(irb, item_node, node->scope); | 2533 | IrInstruction *item_value = ir_gen_node(irb, item_node, scope); |
| 2528 | if (item_value == irb->codegen->invalid_instruction) | 2534 | if (item_value == irb->codegen->invalid_instruction) |
| 2529 | return irb->codegen->invalid_instruction; | 2535 | return irb->codegen->invalid_instruction; |
| 2530 | | 2536 | |
| ... | @@ -2538,7 +2544,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2538,7 +2544,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2538 | | 2544 | |
| 2539 | IrBasicBlock *prev_block = irb->current_basic_block; | 2545 | IrBasicBlock *prev_block = irb->current_basic_block; |
| 2540 | ir_set_cursor_at_end(irb, prong_block); | 2546 | ir_set_cursor_at_end(irb, prong_block); |
| 2541 | if (!ir_gen_switch_prong_expr(irb, node, prong_node, end_block, | 2547 | if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block, |
| 2542 | is_inline, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) | 2548 | is_inline, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values)) |
| 2543 | { | 2549 | { |
| 2544 | return irb->codegen->invalid_instruction; | 2550 | return irb->codegen->invalid_instruction; |
| ... | @@ -2551,19 +2557,19 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { | ... | @@ -2551,19 +2557,19 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, AstNode *node) { |
| 2551 | } | 2557 | } |
| 2552 | | 2558 | |
| 2553 | if (cases.length == 0) { | 2559 | if (cases.length == 0) { |
| 2554 | ir_build_br(irb, node, else_block, is_inline); | 2560 | ir_build_br(irb, scope, node, else_block, is_inline); |
| 2555 | } else { | 2561 | } else { |
| 2556 | ir_build_switch_br(irb, node, target_value, else_block, cases.length, cases.items, is_inline); | 2562 | ir_build_switch_br(irb, scope, node, target_value, else_block, cases.length, cases.items, is_inline); |
| 2557 | } | 2563 | } |
| 2558 | | 2564 | |
| 2559 | if (!else_prong) { | 2565 | if (!else_prong) { |
| 2560 | ir_set_cursor_at_end(irb, else_block); | 2566 | ir_set_cursor_at_end(irb, else_block); |
| 2561 | ir_build_unreachable(irb, node); | 2567 | ir_build_unreachable(irb, scope, node); |
| 2562 | } | 2568 | } |
| 2563 | | 2569 | |
| 2564 | ir_set_cursor_at_end(irb, end_block); | 2570 | ir_set_cursor_at_end(irb, end_block); |
| 2565 | assert(incoming_blocks.length == incoming_values.length); | 2571 | assert(incoming_blocks.length == incoming_values.length); |
| 2566 | return ir_build_phi(irb, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); | 2572 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 2567 | } | 2573 | } |
| 2568 | | 2574 | |
| 2569 | static LabelTableEntry *find_label(IrExecutable *exec, Scope *scope, Buf *name) { | 2575 | static LabelTableEntry *find_label(IrExecutable *exec, Scope *scope, Buf *name) { |
| ... | @@ -2589,7 +2595,7 @@ static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) { | ... | @@ -2589,7 +2595,7 @@ static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) { |
| 2589 | return nullptr; | 2595 | return nullptr; |
| 2590 | } | 2596 | } |
| 2591 | | 2597 | |
| 2592 | static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) { | 2598 | static IrInstruction *ir_gen_label(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2593 | assert(node->type == NodeTypeLabel); | 2599 | assert(node->type == NodeTypeLabel); |
| 2594 | | 2600 | |
| 2595 | Buf *label_name = node->data.label.name; | 2601 | Buf *label_name = node->data.label.name; |
| ... | @@ -2599,35 +2605,38 @@ static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) { | ... | @@ -2599,35 +2605,38 @@ static IrInstruction *ir_gen_label(IrBuilder *irb, AstNode *node) { |
| 2599 | label->bb = label_block; | 2605 | label->bb = label_block; |
| 2600 | irb->exec->all_labels.append(label); | 2606 | irb->exec->all_labels.append(label); |
| 2601 | | 2607 | |
| 2602 | LabelTableEntry *existing_label = find_label(irb->exec, node->scope, label_name); | 2608 | LabelTableEntry *existing_label = find_label(irb->exec, scope, label_name); |
| 2603 | if (existing_label) { | 2609 | if (existing_label) { |
| 2604 | ErrorMsg *msg = add_node_error(irb->codegen, node, | 2610 | ErrorMsg *msg = add_node_error(irb->codegen, node, |
| 2605 | buf_sprintf("duplicate label name '%s'", buf_ptr(label_name))); | 2611 | buf_sprintf("duplicate label name '%s'", buf_ptr(label_name))); |
| 2606 | add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here")); | 2612 | add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here")); |
| 2607 | return irb->codegen->invalid_instruction; | 2613 | return irb->codegen->invalid_instruction; |
| 2608 | } else { | 2614 | } else { |
| 2609 | ScopeBlock *scope_block = find_block_scope(irb->exec, node->scope); | 2615 | ScopeBlock *scope_block = find_block_scope(irb->exec, scope); |
| 2610 | scope_block->label_table.put(label_name, label); | 2616 | scope_block->label_table.put(label_name, label); |
| 2611 | } | 2617 | } |
| 2612 | | 2618 | |
| 2613 | bool is_inline = ir_should_inline(irb); | 2619 | bool is_inline = ir_should_inline(irb); |
| 2614 | ir_build_br(irb, node, label_block, is_inline); | 2620 | ir_build_br(irb, scope, node, label_block, is_inline); |
| 2615 | ir_set_cursor_at_end(irb, label_block); | 2621 | ir_set_cursor_at_end(irb, label_block); |
| 2616 | return ir_build_const_void(irb, node); | 2622 | return ir_build_const_void(irb, scope, node); |
| 2617 | } | 2623 | } |
| 2618 | | 2624 | |
| 2619 | static IrInstruction *ir_gen_goto(IrBuilder *irb, AstNode *node) { | 2625 | static IrInstruction *ir_gen_goto(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2620 | assert(node->type == NodeTypeGoto); | 2626 | assert(node->type == NodeTypeGoto); |
| 2621 | | 2627 | |
| 2622 | // make a placeholder unreachable statement and a note to come back and | 2628 | // make a placeholder unreachable statement and a note to come back and |
| 2623 | // replace the instruction with a branch instruction | 2629 | // replace the instruction with a branch instruction |
| 2624 | node->data.goto_expr.bb = irb->current_basic_block; | 2630 | IrGotoItem *goto_item = irb->exec->goto_list.add_one(); |
| 2625 | node->data.goto_expr.instruction_index = irb->current_basic_block->instruction_list.length; | 2631 | goto_item->bb = irb->current_basic_block; |
| 2626 | irb->exec->goto_list.append(node); | 2632 | goto_item->instruction_index = irb->current_basic_block->instruction_list.length; |
| 2627 | return ir_build_unreachable(irb, node); | 2633 | goto_item->source_node = node; |
| | 2634 | goto_item->scope = scope; |
| | 2635 | |
| | 2636 | return ir_build_unreachable(irb, scope, node); |
| 2628 | } | 2637 | } |
| 2629 | | 2638 | |
| 2630 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPurpose lval) { | 2639 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LValPurpose lval) { |
| 2631 | if (lval == LValPurposeNone) | 2640 | if (lval == LValPurposeNone) |
| 2632 | return value; | 2641 | return value; |
| 2633 | if (value == irb->codegen->invalid_instruction) | 2642 | if (value == irb->codegen->invalid_instruction) |
| ... | @@ -2635,75 +2644,73 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPur | ... | @@ -2635,75 +2644,73 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, IrInstruction *value, LValPur |
| 2635 | | 2644 | |
| 2636 | // We needed a pointer to a value, but we got a value. So we create | 2645 | // We needed a pointer to a value, but we got a value. So we create |
| 2637 | // an instruction which just makes a const pointer of it. | 2646 | // an instruction which just makes a const pointer of it. |
| 2638 | return ir_build_ref(irb, value->source_node, value); | 2647 | return ir_build_ref(irb, scope, value->source_node, value); |
| 2639 | } | 2648 | } |
| 2640 | | 2649 | |
| 2641 | static IrInstruction *ir_gen_type_literal(IrBuilder *irb, AstNode *node) { | 2650 | static IrInstruction *ir_gen_type_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 2642 | assert(node->type == NodeTypeTypeLiteral); | 2651 | assert(node->type == NodeTypeTypeLiteral); |
| 2643 | return ir_build_const_type(irb, node, irb->codegen->builtin_types.entry_type); | 2652 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_type); |
| 2644 | } | 2653 | } |
| 2645 | | 2654 | |
| 2646 | static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope, | 2655 | static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope, |
| 2647 | LValPurpose lval) | 2656 | LValPurpose lval) |
| 2648 | { | 2657 | { |
| 2649 | assert(scope); | 2658 | assert(scope); |
| 2650 | node->scope = scope; | | |
| 2651 | | | |
| 2652 | switch (node->type) { | 2659 | switch (node->type) { |
| 2653 | case NodeTypeStructValueField: | 2660 | case NodeTypeStructValueField: |
| 2654 | zig_unreachable(); | 2661 | zig_unreachable(); |
| 2655 | case NodeTypeBlock: | 2662 | case NodeTypeBlock: |
| 2656 | return ir_lval_wrap(irb, ir_gen_block(irb, node), lval); | 2663 | return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval); |
| 2657 | case NodeTypeBinOpExpr: | 2664 | case NodeTypeBinOpExpr: |
| 2658 | return ir_lval_wrap(irb, ir_gen_bin_op(irb, node), lval); | 2665 | return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval); |
| 2659 | case NodeTypeNumberLiteral: | 2666 | case NodeTypeNumberLiteral: |
| 2660 | return ir_lval_wrap(irb, ir_gen_num_lit(irb, node), lval); | 2667 | return ir_lval_wrap(irb, scope, ir_gen_num_lit(irb, scope, node), lval); |
| 2661 | case NodeTypeSymbol: | 2668 | case NodeTypeSymbol: |
| 2662 | return ir_gen_symbol(irb, node, lval); | 2669 | return ir_gen_symbol(irb, scope, node, lval); |
| 2663 | case NodeTypeFnCallExpr: | 2670 | case NodeTypeFnCallExpr: |
| 2664 | return ir_lval_wrap(irb, ir_gen_fn_call(irb, node), lval); | 2671 | return ir_lval_wrap(irb, scope, ir_gen_fn_call(irb, scope, node), lval); |
| 2665 | case NodeTypeIfBoolExpr: | 2672 | case NodeTypeIfBoolExpr: |
| 2666 | return ir_lval_wrap(irb, ir_gen_if_bool_expr(irb, node), lval); | 2673 | return ir_lval_wrap(irb, scope, ir_gen_if_bool_expr(irb, scope, node), lval); |
| 2667 | case NodeTypePrefixOpExpr: | 2674 | case NodeTypePrefixOpExpr: |
| 2668 | return ir_gen_prefix_op_expr(irb, node, lval); | 2675 | return ir_gen_prefix_op_expr(irb, scope, node, lval); |
| 2669 | case NodeTypeContainerInitExpr: | 2676 | case NodeTypeContainerInitExpr: |
| 2670 | return ir_lval_wrap(irb, ir_gen_container_init_expr(irb, node), lval); | 2677 | return ir_lval_wrap(irb, scope, ir_gen_container_init_expr(irb, scope, node), lval); |
| 2671 | case NodeTypeVariableDeclaration: | 2678 | case NodeTypeVariableDeclaration: |
| 2672 | return ir_lval_wrap(irb, ir_gen_var_decl(irb, node), lval); | 2679 | return ir_lval_wrap(irb, scope, ir_gen_var_decl(irb, scope, node), lval); |
| 2673 | case NodeTypeWhileExpr: | 2680 | case NodeTypeWhileExpr: |
| 2674 | return ir_lval_wrap(irb, ir_gen_while_expr(irb, node), lval); | 2681 | return ir_lval_wrap(irb, scope, ir_gen_while_expr(irb, scope, node), lval); |
| 2675 | case NodeTypeForExpr: | 2682 | case NodeTypeForExpr: |
| 2676 | return ir_lval_wrap(irb, ir_gen_for_expr(irb, node), lval); | 2683 | return ir_lval_wrap(irb, scope, ir_gen_for_expr(irb, scope, node), lval); |
| 2677 | case NodeTypeArrayAccessExpr: | 2684 | case NodeTypeArrayAccessExpr: |
| 2678 | return ir_gen_array_access(irb, node, lval); | 2685 | return ir_gen_array_access(irb, scope, node, lval); |
| 2679 | case NodeTypeReturnExpr: | 2686 | case NodeTypeReturnExpr: |
| 2680 | return ir_lval_wrap(irb, ir_gen_return(irb, node), lval); | 2687 | return ir_lval_wrap(irb, scope, ir_gen_return(irb, scope, node), lval); |
| 2681 | case NodeTypeFieldAccessExpr: | 2688 | case NodeTypeFieldAccessExpr: |
| 2682 | return ir_gen_field_access(irb, node, lval); | 2689 | return ir_gen_field_access(irb, scope, node, lval); |
| 2683 | case NodeTypeThisLiteral: | 2690 | case NodeTypeThisLiteral: |
| 2684 | return ir_lval_wrap(irb, ir_gen_this_literal(irb, node), lval); | 2691 | return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval); |
| 2685 | case NodeTypeBoolLiteral: | 2692 | case NodeTypeBoolLiteral: |
| 2686 | return ir_lval_wrap(irb, ir_gen_bool_literal(irb, node), lval); | 2693 | return ir_lval_wrap(irb, scope, ir_gen_bool_literal(irb, scope, node), lval); |
| 2687 | case NodeTypeArrayType: | 2694 | case NodeTypeArrayType: |
| 2688 | return ir_lval_wrap(irb, ir_gen_array_type(irb, node), lval); | 2695 | return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval); |
| 2689 | case NodeTypeStringLiteral: | 2696 | case NodeTypeStringLiteral: |
| 2690 | return ir_lval_wrap(irb, ir_gen_string_literal(irb, node), lval); | 2697 | return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval); |
| 2691 | case NodeTypeUndefinedLiteral: | 2698 | case NodeTypeUndefinedLiteral: |
| 2692 | return ir_lval_wrap(irb, ir_gen_undefined_literal(irb, node), lval); | 2699 | return ir_lval_wrap(irb, scope, ir_gen_undefined_literal(irb, scope, node), lval); |
| 2693 | case NodeTypeAsmExpr: | 2700 | case NodeTypeAsmExpr: |
| 2694 | return ir_lval_wrap(irb, ir_gen_asm_expr(irb, node), lval); | 2701 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval); |
| 2695 | case NodeTypeNullLiteral: | 2702 | case NodeTypeNullLiteral: |
| 2696 | return ir_lval_wrap(irb, ir_gen_null_literal(irb, node), lval); | 2703 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); |
| 2697 | case NodeTypeIfVarExpr: | 2704 | case NodeTypeIfVarExpr: |
| 2698 | return ir_lval_wrap(irb, ir_gen_if_var_expr(irb, node), lval); | 2705 | return ir_lval_wrap(irb, scope, ir_gen_if_var_expr(irb, scope, node), lval); |
| 2699 | case NodeTypeSwitchExpr: | 2706 | case NodeTypeSwitchExpr: |
| 2700 | return ir_lval_wrap(irb, ir_gen_switch_expr(irb, node), lval); | 2707 | return ir_lval_wrap(irb, scope, ir_gen_switch_expr(irb, scope, node), lval); |
| 2701 | case NodeTypeLabel: | 2708 | case NodeTypeLabel: |
| 2702 | return ir_lval_wrap(irb, ir_gen_label(irb, node), lval); | 2709 | return ir_lval_wrap(irb, scope, ir_gen_label(irb, scope, node), lval); |
| 2703 | case NodeTypeGoto: | 2710 | case NodeTypeGoto: |
| 2704 | return ir_lval_wrap(irb, ir_gen_goto(irb, node), lval); | 2711 | return ir_lval_wrap(irb, scope, ir_gen_goto(irb, scope, node), lval); |
| 2705 | case NodeTypeTypeLiteral: | 2712 | case NodeTypeTypeLiteral: |
| 2706 | return ir_lval_wrap(irb, ir_gen_type_literal(irb, node), lval); | 2713 | return ir_lval_wrap(irb, scope, ir_gen_type_literal(irb, scope, node), lval); |
| 2707 | case NodeTypeUnwrapErrorExpr: | 2714 | case NodeTypeUnwrapErrorExpr: |
| 2708 | case NodeTypeDefer: | 2715 | case NodeTypeDefer: |
| 2709 | case NodeTypeSliceExpr: | 2716 | case NodeTypeSliceExpr: |
| ... | @@ -2744,22 +2751,23 @@ static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) { | ... | @@ -2744,22 +2751,23 @@ static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) { |
| 2744 | | 2751 | |
| 2745 | static bool ir_goto_pass2(IrBuilder *irb) { | 2752 | static bool ir_goto_pass2(IrBuilder *irb) { |
| 2746 | for (size_t i = 0; i < irb->exec->goto_list.length; i += 1) { | 2753 | for (size_t i = 0; i < irb->exec->goto_list.length; i += 1) { |
| 2747 | AstNode *goto_node = irb->exec->goto_list.at(i); | 2754 | IrGotoItem *goto_item = &irb->exec->goto_list.at(i); |
| 2748 | size_t instruction_index = goto_node->data.goto_expr.instruction_index; | 2755 | AstNode *source_node = goto_item->source_node; |
| 2749 | IrInstruction **slot = &goto_node->data.goto_expr.bb->instruction_list.at(instruction_index); | 2756 | size_t instruction_index = goto_item->instruction_index; |
| | 2757 | IrInstruction **slot = &goto_item->bb->instruction_list.at(instruction_index); |
| 2750 | IrInstruction *old_instruction = *slot; | 2758 | IrInstruction *old_instruction = *slot; |
| 2751 | | 2759 | |
| 2752 | Buf *label_name = goto_node->data.goto_expr.name; | 2760 | Buf *label_name = source_node->data.goto_expr.name; |
| 2753 | LabelTableEntry *label = find_label(irb->exec, goto_node->scope, label_name); | 2761 | LabelTableEntry *label = find_label(irb->exec, goto_item->scope, label_name); |
| 2754 | if (!label) { | 2762 | if (!label) { |
| 2755 | add_node_error(irb->codegen, goto_node, | 2763 | add_node_error(irb->codegen, source_node, |
| 2756 | buf_sprintf("no label in scope named '%s'", buf_ptr(label_name))); | 2764 | buf_sprintf("no label in scope named '%s'", buf_ptr(label_name))); |
| 2757 | return false; | 2765 | return false; |
| 2758 | } | 2766 | } |
| 2759 | label->used = true; | 2767 | label->used = true; |
| 2760 | | 2768 | |
| 2761 | bool is_inline = ir_should_inline(irb) || goto_node->data.goto_expr.is_inline; | 2769 | bool is_inline = ir_should_inline(irb) || source_node->data.goto_expr.is_inline; |
| 2762 | IrInstruction *new_instruction = ir_create_br(irb, goto_node, label->bb, is_inline); | 2770 | IrInstruction *new_instruction = ir_create_br(irb, goto_item->scope, source_node, label->bb, is_inline); |
| 2763 | new_instruction->ref_count = old_instruction->ref_count; | 2771 | new_instruction->ref_count = old_instruction->ref_count; |
| 2764 | *slot = new_instruction; | 2772 | *slot = new_instruction; |
| 2765 | } | 2773 | } |
| ... | @@ -2795,7 +2803,7 @@ IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutabl | ... | @@ -2795,7 +2803,7 @@ IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutabl |
| 2795 | if (irb->exec->invalid) | 2803 | if (irb->exec->invalid) |
| 2796 | return codegen->invalid_instruction; | 2804 | return codegen->invalid_instruction; |
| 2797 | | 2805 | |
| 2798 | IrInstruction *return_instruction = ir_build_return(irb, result->source_node, result); | 2806 | IrInstruction *return_instruction = ir_build_return(irb, scope, result->source_node, result); |
| 2799 | assert(return_instruction); | 2807 | assert(return_instruction); |
| 2800 | | 2808 | |
| 2801 | if (!ir_goto_pass2(irb)) { | 2809 | if (!ir_goto_pass2(irb)) { |
| ... | @@ -2814,21 +2822,27 @@ IrInstruction *ir_gen_fn(CodeGen *codegn, FnTableEntry *fn_entry) { | ... | @@ -2814,21 +2822,27 @@ IrInstruction *ir_gen_fn(CodeGen *codegn, FnTableEntry *fn_entry) { |
| 2814 | assert(fn_def_node->type == NodeTypeFnDef); | 2822 | assert(fn_def_node->type == NodeTypeFnDef); |
| 2815 | | 2823 | |
| 2816 | AstNode *body_node = fn_def_node->data.fn_def.body; | 2824 | AstNode *body_node = fn_def_node->data.fn_def.body; |
| 2817 | Scope *child_scope = fn_def_node->data.fn_def.child_scope; | 2825 | |
| | 2826 | assert(fn_entry->child_scope); |
| | 2827 | Scope *child_scope = fn_entry->child_scope; |
| 2818 | | 2828 | |
| 2819 | return ir_gen(codegn, body_node, child_scope, ir_executable); | 2829 | return ir_gen(codegn, body_node, child_scope, ir_executable); |
| 2820 | } | 2830 | } |
| 2821 | | 2831 | |
| | 2832 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) { |
| | 2833 | return add_node_error(ira->codegen, source_instruction->source_node, msg); |
| | 2834 | } |
| | 2835 | |
| 2822 | static IrInstruction *ir_eval_fn(IrAnalyze *ira, IrInstruction *source_instruction, | 2836 | static IrInstruction *ir_eval_fn(IrAnalyze *ira, IrInstruction *source_instruction, |
| 2823 | size_t arg_count, IrInstruction **args) | 2837 | size_t arg_count, IrInstruction **args) |
| 2824 | { | 2838 | { |
| | 2839 | // TODO count this as part of the backward branch quota |
| 2825 | zig_panic("TODO ir_eval_fn"); | 2840 | zig_panic("TODO ir_eval_fn"); |
| 2826 | } | 2841 | } |
| 2827 | | 2842 | |
| 2828 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { | 2843 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 2829 | if (ir_should_inline(&ira->new_irb)) { | 2844 | if (ir_should_inline(&ira->new_irb)) { |
| 2830 | add_node_error(ira->codegen, source_instruction->source_node, | 2845 | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); |
| 2831 | buf_sprintf("unable to evaluate constant expression")); | | |
| 2832 | return false; | 2846 | return false; |
| 2833 | } | 2847 | } |
| 2834 | return true; | 2848 | return true; |
| ... | @@ -2863,7 +2877,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -2863,7 +2877,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 2863 | | 2877 | |
| 2864 | const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer"; | 2878 | const char *num_lit_str = (const_val->data.x_bignum.kind == BigNumKindFloat) ? "float" : "integer"; |
| 2865 | | 2879 | |
| 2866 | add_node_error(ira->codegen, instruction->source_node, | 2880 | ir_add_error(ira, instruction, |
| 2867 | buf_sprintf("%s value %s cannot be implicitly casted to type '%s'", | 2881 | buf_sprintf("%s value %s cannot be implicitly casted to type '%s'", |
| 2868 | num_lit_str, | 2882 | num_lit_str, |
| 2869 | buf_ptr(bignum_to_buf(&const_val->data.x_bignum)), | 2883 | buf_ptr(bignum_to_buf(&const_val->data.x_bignum)), |
| ... | @@ -3052,15 +3066,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -3052,15 +3066,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 3052 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) | 3066 | TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) |
| 3053 | { | 3067 | { |
| 3054 | if (value->static_value.special != ConstValSpecialRuntime) { | 3068 | if (value->static_value.special != ConstValSpecialRuntime) { |
| 3055 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->source_node, wanted_type, false); | 3069 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, false); |
| 3056 | eval_const_expr_implicit_cast(cast_op, &value->static_value, value->type_entry, | 3070 | eval_const_expr_implicit_cast(cast_op, &value->static_value, value->type_entry, |
| 3057 | &result->static_value, wanted_type); | 3071 | &result->static_value, wanted_type); |
| 3058 | return result; | 3072 | return result; |
| 3059 | } else { | 3073 | } else { |
| 3060 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->source_node, wanted_type, value, cast_op); | 3074 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); |
| 3061 | result->type_entry = wanted_type; | 3075 | result->type_entry = wanted_type; |
| 3062 | if (need_alloca) { | 3076 | if (need_alloca) { |
| 3063 | FnTableEntry *fn_entry = scope_fn_entry(source_instr->source_node->scope); | 3077 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 3064 | if (fn_entry) | 3078 | if (fn_entry) |
| 3065 | fn_entry->alloca_list.append(result); | 3079 | fn_entry->alloca_list.append(result); |
| 3066 | } | 3080 | } |
| ... | @@ -3153,20 +3167,20 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in | ... | @@ -3153,20 +3167,20 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in |
| 3153 | if (old_instruction->id == IrInstructionIdVarPtr) { | 3167 | if (old_instruction->id == IrInstructionIdVarPtr) { |
| 3154 | IrInstructionVarPtr *old_var_ptr_instruction = (IrInstructionVarPtr *)old_instruction; | 3168 | IrInstructionVarPtr *old_var_ptr_instruction = (IrInstructionVarPtr *)old_instruction; |
| 3155 | IrInstructionVarPtr *var_ptr_instruction = ir_create_instruction<IrInstructionVarPtr>(ira->new_irb.exec, | 3169 | IrInstructionVarPtr *var_ptr_instruction = ir_create_instruction<IrInstructionVarPtr>(ira->new_irb.exec, |
| 3156 | old_instruction->source_node); | 3170 | old_instruction->scope, old_instruction->source_node); |
| 3157 | var_ptr_instruction->var = old_var_ptr_instruction->var; | 3171 | var_ptr_instruction->var = old_var_ptr_instruction->var; |
| 3158 | new_instruction = &var_ptr_instruction->base; | 3172 | new_instruction = &var_ptr_instruction->base; |
| 3159 | } else if (old_instruction->id == IrInstructionIdFieldPtr) { | 3173 | } else if (old_instruction->id == IrInstructionIdFieldPtr) { |
| 3160 | IrInstructionFieldPtr *field_ptr_instruction = ir_create_instruction<IrInstructionFieldPtr>(ira->new_irb.exec, | 3174 | IrInstructionFieldPtr *field_ptr_instruction = ir_create_instruction<IrInstructionFieldPtr>(ira->new_irb.exec, |
| 3161 | old_instruction->source_node); | 3175 | old_instruction->scope, old_instruction->source_node); |
| 3162 | new_instruction = &field_ptr_instruction->base; | 3176 | new_instruction = &field_ptr_instruction->base; |
| 3163 | } else if (old_instruction->id == IrInstructionIdElemPtr) { | 3177 | } else if (old_instruction->id == IrInstructionIdElemPtr) { |
| 3164 | IrInstructionElemPtr *elem_ptr_instruction = ir_create_instruction<IrInstructionElemPtr>(ira->new_irb.exec, | 3178 | IrInstructionElemPtr *elem_ptr_instruction = ir_create_instruction<IrInstructionElemPtr>(ira->new_irb.exec, |
| 3165 | old_instruction->source_node); | 3179 | old_instruction->scope, old_instruction->source_node); |
| 3166 | new_instruction = &elem_ptr_instruction->base; | 3180 | new_instruction = &elem_ptr_instruction->base; |
| 3167 | } else { | 3181 | } else { |
| 3168 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, | 3182 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, |
| 3169 | old_instruction->source_node); | 3183 | old_instruction->scope, old_instruction->source_node); |
| 3170 | new_instruction = &const_instruction->base; | 3184 | new_instruction = &const_instruction->base; |
| 3171 | } | 3185 | } |
| 3172 | ir_link_new_instruction(new_instruction, old_instruction); | 3186 | ir_link_new_instruction(new_instruction, old_instruction); |
| ... | @@ -3553,13 +3567,13 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc | ... | @@ -3553,13 +3567,13 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 3553 | if (ptr->static_value.special != ConstValSpecialRuntime) { | 3567 | if (ptr->static_value.special != ConstValSpecialRuntime) { |
| 3554 | ConstExprValue *pointee = const_ptr_pointee(&ptr->static_value); | 3568 | ConstExprValue *pointee = const_ptr_pointee(&ptr->static_value); |
| 3555 | if (pointee->special != ConstValSpecialRuntime) { | 3569 | if (pointee->special != ConstValSpecialRuntime) { |
| 3556 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->source_node, | 3570 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, |
| 3557 | child_type, pointee->depends_on_compile_var); | 3571 | source_instruction->source_node, child_type, pointee->depends_on_compile_var); |
| 3558 | result->static_value = *pointee; | 3572 | result->static_value = *pointee; |
| 3559 | return result; | 3573 | return result; |
| 3560 | } | 3574 | } |
| 3561 | } | 3575 | } |
| 3562 | IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->source_node, ptr); | 3576 | IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr); |
| 3563 | load_ptr_instruction->type_entry = child_type; | 3577 | load_ptr_instruction->type_entry = child_type; |
| 3564 | return load_ptr_instruction; | 3578 | return load_ptr_instruction; |
| 3565 | } else { | 3579 | } else { |
| ... | @@ -3588,7 +3602,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -3588,7 +3602,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst |
| 3588 | ir_link_new_instruction(value, source_instruction); | 3602 | ir_link_new_instruction(value, source_instruction); |
| 3589 | return ptr_type; | 3603 | return ptr_type; |
| 3590 | } else { | 3604 | } else { |
| 3591 | FnTableEntry *fn_entry = scope_fn_entry(source_instruction->source_node->scope); | 3605 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 3592 | assert(fn_entry); | 3606 | assert(fn_entry); |
| 3593 | IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value); | 3607 | IrInstruction *new_instruction = ir_build_ref_from(&ira->new_irb, source_instruction, value); |
| 3594 | fn_entry->alloca_list.append(new_instruction); | 3608 | fn_entry->alloca_list.append(new_instruction); |
| ... | @@ -3754,7 +3768,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp | ... | @@ -3754,7 +3768,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 3754 | case TypeTableEntryIdTypeDecl: | 3768 | case TypeTableEntryIdTypeDecl: |
| 3755 | case TypeTableEntryIdNamespace: | 3769 | case TypeTableEntryIdNamespace: |
| 3756 | case TypeTableEntryIdBlock: | 3770 | case TypeTableEntryIdBlock: |
| 3757 | case TypeTableEntryIdGenericFn: | | |
| 3758 | case TypeTableEntryIdBoundFn: | 3771 | case TypeTableEntryIdBoundFn: |
| 3759 | if (!is_equality_cmp) { | 3772 | if (!is_equality_cmp) { |
| 3760 | add_node_error(ira->codegen, source_node, | 3773 | add_node_error(ira->codegen, source_node, |
| ... | @@ -4057,7 +4070,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -4057,7 +4070,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 4057 | } | 4070 | } |
| 4058 | | 4071 | |
| 4059 | AstNodeVariableDeclaration *variable_declaration = &var->decl_node->data.variable_declaration; | 4072 | AstNodeVariableDeclaration *variable_declaration = &var->decl_node->data.variable_declaration; |
| 4060 | bool is_export = (variable_declaration->top_level_decl.visib_mod == VisibModExport); | 4073 | bool is_export = (variable_declaration->visib_mod == VisibModExport); |
| 4061 | bool is_extern = variable_declaration->is_extern; | 4074 | bool is_extern = variable_declaration->is_extern; |
| 4062 | | 4075 | |
| 4063 | var->ref_count = 0; | 4076 | var->ref_count = 0; |
| ... | @@ -4119,7 +4132,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -4119,7 +4132,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 4119 | case TypeTableEntryIdEnum: | 4132 | case TypeTableEntryIdEnum: |
| 4120 | case TypeTableEntryIdUnion: | 4133 | case TypeTableEntryIdUnion: |
| 4121 | case TypeTableEntryIdFn: | 4134 | case TypeTableEntryIdFn: |
| 4122 | case TypeTableEntryIdGenericFn: | | |
| 4123 | case TypeTableEntryIdBoundFn: | 4135 | case TypeTableEntryIdBoundFn: |
| 4124 | // OK | 4136 | // OK |
| 4125 | break; | 4137 | break; |
| ... | @@ -4136,8 +4148,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc | ... | @@ -4136,8 +4148,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 4136 | | 4148 | |
| 4137 | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, casted_init_value); | 4149 | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, casted_init_value); |
| 4138 | | 4150 | |
| 4139 | Scope *scope = decl_var_instruction->base.source_node->scope; | 4151 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 4140 | FnTableEntry *fn_entry = scope_fn_entry(scope); | | |
| 4141 | if (fn_entry) | 4152 | if (fn_entry) |
| 4142 | fn_entry->variable_list.append(var); | 4153 | fn_entry->variable_list.append(var); |
| 4143 | | 4154 | |
| ... | @@ -4241,7 +4252,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal | ... | @@ -4241,7 +4252,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 4241 | fn_entry, fn_ref, call_param_count, casted_args); | 4252 | fn_entry, fn_ref, call_param_count, casted_args); |
| 4242 | | 4253 | |
| 4243 | if (type_has_bits(return_type) && handle_is_ptr(return_type)) { | 4254 | if (type_has_bits(return_type) && handle_is_ptr(return_type)) { |
| 4244 | FnTableEntry *fn_entry = scope_fn_entry(call_instruction->base.source_node->scope); | 4255 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 4245 | assert(fn_entry); | 4256 | assert(fn_entry); |
| 4246 | fn_entry->alloca_list.append(new_call_instruction); | 4257 | fn_entry->alloca_list.append(new_call_instruction); |
| 4247 | } | 4258 | } |
| ... | @@ -4288,8 +4299,6 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction | ... | @@ -4288,8 +4299,6 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction |
| 4288 | IrInstruction *first_arg_ptr = fn_ref->static_value.data.x_bound_fn.first_arg; | 4299 | IrInstruction *first_arg_ptr = fn_ref->static_value.data.x_bound_fn.first_arg; |
| 4289 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, | 4300 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 4290 | nullptr, first_arg_ptr, is_inline); | 4301 | nullptr, first_arg_ptr, is_inline); |
| 4291 | } else if (fn_ref->type_entry->id == TypeTableEntryIdGenericFn) { | | |
| 4292 | zig_panic("TODO generic fn call"); | | |
| 4293 | } else { | 4302 | } else { |
| 4294 | add_node_error(ira->codegen, fn_ref->source_node, | 4303 | add_node_error(ira->codegen, fn_ref->source_node, |
| 4295 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name))); | 4304 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->type_entry->name))); |
| ... | @@ -4360,7 +4369,6 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct | ... | @@ -4360,7 +4369,6 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct |
| 4360 | case TypeTableEntryIdEnum: | 4369 | case TypeTableEntryIdEnum: |
| 4361 | case TypeTableEntryIdUnion: | 4370 | case TypeTableEntryIdUnion: |
| 4362 | case TypeTableEntryIdFn: | 4371 | case TypeTableEntryIdFn: |
| 4363 | case TypeTableEntryIdGenericFn: | | |
| 4364 | case TypeTableEntryIdBoundFn: | 4372 | case TypeTableEntryIdBoundFn: |
| 4365 | { | 4373 | { |
| 4366 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, | 4374 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, |
| ... | @@ -4409,7 +4417,6 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction | ... | @@ -4409,7 +4417,6 @@ static TypeTableEntry *ir_analyze_unary_address_of(IrAnalyze *ira, IrInstruction |
| 4409 | case TypeTableEntryIdBlock: | 4417 | case TypeTableEntryIdBlock: |
| 4410 | case TypeTableEntryIdUnreachable: | 4418 | case TypeTableEntryIdUnreachable: |
| 4411 | case TypeTableEntryIdVar: | 4419 | case TypeTableEntryIdVar: |
| 4412 | case TypeTableEntryIdGenericFn: | | |
| 4413 | case TypeTableEntryIdBoundFn: | 4420 | case TypeTableEntryIdBoundFn: |
| 4414 | add_node_error(ira->codegen, un_op_instruction->base.source_node, | 4421 | add_node_error(ira->codegen, un_op_instruction->base.source_node, |
| 4415 | buf_sprintf("unable to get address of type '%s'", buf_ptr(&target_type->name))); | 4422 | buf_sprintf("unable to get address of type '%s'", buf_ptr(&target_type->name))); |
| ... | @@ -4508,7 +4515,6 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op | ... | @@ -4508,7 +4515,6 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 4508 | case TypeTableEntryIdFn: | 4515 | case TypeTableEntryIdFn: |
| 4509 | case TypeTableEntryIdNamespace: | 4516 | case TypeTableEntryIdNamespace: |
| 4510 | case TypeTableEntryIdBlock: | 4517 | case TypeTableEntryIdBlock: |
| 4511 | case TypeTableEntryIdGenericFn: | | |
| 4512 | case TypeTableEntryIdBoundFn: | 4518 | case TypeTableEntryIdBoundFn: |
| 4513 | { | 4519 | { |
| 4514 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, | 4520 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, |
| ... | @@ -4781,9 +4787,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc | ... | @@ -4781,9 +4787,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc |
| 4781 | if (var->mem_slot_index != SIZE_MAX) | 4787 | if (var->mem_slot_index != SIZE_MAX) |
| 4782 | mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; | 4788 | mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 4783 | } else if (var->src_is_const) { | 4789 | } else if (var->src_is_const) { |
| 4784 | AstNode *var_decl_node = var->decl_node; | 4790 | mem_slot = var->value; |
| 4785 | assert(var_decl_node->type == NodeTypeVariableDeclaration); | | |
| 4786 | mem_slot = &var_decl_node->data.variable_declaration.top_level_decl.value->static_value; | | |
| 4787 | assert(mem_slot->special != ConstValSpecialRuntime); | 4791 | assert(mem_slot->special != ConstValSpecialRuntime); |
| 4788 | } | 4792 | } |
| 4789 | | 4793 | |
| ... | @@ -4925,15 +4929,15 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -4925,15 +4929,15 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 4925 | if (!is_slice(bare_struct_type)) { | 4929 | if (!is_slice(bare_struct_type)) { |
| 4926 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); | 4930 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| 4927 | auto entry = container_scope->decl_table.maybe_get(field_name); | 4931 | auto entry = container_scope->decl_table.maybe_get(field_name); |
| 4928 | AstNode *fn_decl_node = entry ? entry->value : nullptr; | 4932 | Tld *tld = entry ? entry->value : nullptr; |
| 4929 | if (fn_decl_node && fn_decl_node->type == NodeTypeFnProto) { | 4933 | if (tld && tld->id == TldIdFn) { |
| 4930 | resolve_top_level_decl(ira->codegen, fn_decl_node, false); | 4934 | resolve_top_level_decl(ira->codegen, tld, false); |
| 4931 | TopLevelDecl *tld = get_as_top_level_decl(fn_decl_node); | | |
| 4932 | if (tld->resolution == TldResolutionInvalid) | 4935 | if (tld->resolution == TldResolutionInvalid) |
| 4933 | return ira->codegen->builtin_types.entry_invalid; | 4936 | return ira->codegen->builtin_types.entry_invalid; |
| 4934 | FnTableEntry *fn_entry = fn_decl_node->data.fn_proto.fn_table_entry; | 4937 | TldFn *tld_fn = (TldFn *)tld; |
| | 4938 | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 4935 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; | 4939 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; |
| 4936 | IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, | 4940 | IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope, |
| 4937 | field_ptr_instruction->base.source_node, fn_entry, container_ptr, depends_on_compile_var); | 4941 | field_ptr_instruction->base.source_node, fn_entry, container_ptr, depends_on_compile_var); |
| 4938 | return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value); | 4942 | return ir_analyze_ref(ira, &field_ptr_instruction->base, bound_fn_value); |
| 4939 | } | 4943 | } |
| ... | @@ -4976,53 +4980,63 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field | ... | @@ -4976,53 +4980,63 @@ static TypeTableEntry *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field |
| 4976 | } | 4980 | } |
| 4977 | } | 4981 | } |
| 4978 | | 4982 | |
| 4979 | static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, AstNode *decl_node, | 4983 | static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld, |
| 4980 | bool depends_on_compile_var) | 4984 | bool depends_on_compile_var) |
| 4981 | { | 4985 | { |
| 4982 | bool pointer_only = false; | 4986 | bool pointer_only = false; |
| 4983 | resolve_top_level_decl(ira->codegen, decl_node, pointer_only); | 4987 | resolve_top_level_decl(ira->codegen, tld, pointer_only); |
| 4984 | TopLevelDecl *tld = get_as_top_level_decl(decl_node); | | |
| 4985 | if (tld->resolution == TldResolutionInvalid) | 4988 | if (tld->resolution == TldResolutionInvalid) |
| 4986 | return ira->codegen->builtin_types.entry_invalid; | 4989 | return ira->codegen->builtin_types.entry_invalid; |
| 4987 | | 4990 | |
| 4988 | if (decl_node->type == NodeTypeVariableDeclaration) { | 4991 | switch (tld->id) { |
| 4989 | VariableTableEntry *var = decl_node->data.variable_declaration.variable; | 4992 | case TldIdVar: |
| 4990 | return ir_analyze_var_ptr(ira, source_instruction, var); | 4993 | { |
| 4991 | } else if (decl_node->type == NodeTypeFnProto) { | 4994 | TldVar *tld_var = (TldVar *)tld; |
| 4992 | FnTableEntry *fn_entry = decl_node->data.fn_proto.fn_table_entry; | 4995 | VariableTableEntry *var = tld_var->var; |
| 4993 | assert(fn_entry->type_entry); | 4996 | return ir_analyze_var_ptr(ira, source_instruction, var); |
| 4994 | | 4997 | } |
| 4995 | // TODO instead of allocating this every time, put it in the tld value and we can reference | 4998 | case TldIdFn: |
| 4996 | // the same one every time | 4999 | { |
| 4997 | ConstExprValue *const_val = allocate<ConstExprValue>(1); | 5000 | TldFn *tld_fn = (TldFn *)tld; |
| 4998 | const_val->special = ConstValSpecialStatic; | 5001 | FnTableEntry *fn_entry = tld_fn->fn_entry; |
| 4999 | if (fn_entry->type_entry->id == TypeTableEntryIdGenericFn) { | 5002 | assert(fn_entry->type_entry); |
| 5000 | const_val->data.x_type = fn_entry->type_entry; | 5003 | |
| 5001 | } else { | 5004 | // TODO instead of allocating this every time, put it in the tld value and we can reference |
| | 5005 | // the same one every time |
| | 5006 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| | 5007 | const_val->special = ConstValSpecialStatic; |
| 5002 | const_val->data.x_fn = fn_entry; | 5008 | const_val->data.x_fn = fn_entry; |
| | 5009 | |
| | 5010 | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, depends_on_compile_var); |
| 5003 | } | 5011 | } |
| | 5012 | case TldIdContainer: |
| | 5013 | { |
| | 5014 | TldContainer *tld_container = (TldContainer *)tld; |
| | 5015 | assert(tld_container->type_entry); |
| 5004 | | 5016 | |
| 5005 | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, depends_on_compile_var); | 5017 | // TODO instead of allocating this every time, put it in the tld value and we can reference |
| 5006 | } else if (decl_node->type == NodeTypeContainerDecl) { | 5018 | // the same one every time |
| 5007 | zig_panic("TODO"); | 5019 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| 5008 | //ConstExprValue *out_val = ir_build_const_from(ira, source_instruction, depends_on_compile_var); | 5020 | const_val->special = ConstValSpecialStatic; |
| 5009 | //if (decl_node->data.struct_decl.generic_params.length > 0) { | 5021 | const_val->data.x_type = tld_container->type_entry; |
| 5010 | // TypeTableEntry *type_entry = decl_node->data.struct_decl.generic_fn_type; | 5022 | |
| 5011 | // assert(type_entry); | 5023 | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_container->type_entry, depends_on_compile_var); |
| 5012 | // out_val->data.x_type = type_entry; | 5024 | } |
| 5013 | // return type_entry; | 5025 | case TldIdTypeDef: |
| 5014 | //} else { | 5026 | { |
| 5015 | // out_val->data.x_type = decl_node->data.struct_decl.type_entry; | 5027 | TldTypeDef *tld_typedef = (TldTypeDef *)tld; |
| 5016 | // return ira->codegen->builtin_types.entry_type; | 5028 | assert(tld_typedef->type_entry); |
| 5017 | //} | 5029 | |
| 5018 | } else if (decl_node->type == NodeTypeTypeDecl) { | 5030 | // TODO instead of allocating this every time, put it in the tld value and we can reference |
| 5019 | zig_panic("TODO"); | 5031 | // the same one every time |
| 5020 | //ConstExprValue *out_val = ir_build_const_from(ira, source_instruction, depends_on_compile_var); | 5032 | ConstExprValue *const_val = allocate<ConstExprValue>(1); |
| 5021 | //out_val->data.x_type = decl_node->data.type_decl.child_type_entry; | 5033 | const_val->special = ConstValSpecialStatic; |
| 5022 | //return ira->codegen->builtin_types.entry_type; | 5034 | const_val->data.x_type = tld_typedef->type_entry; |
| 5023 | } else { | 5035 | |
| 5024 | zig_unreachable(); | 5036 | return ir_analyze_const_ptr(ira, source_instruction, const_val, tld_typedef->type_entry, depends_on_compile_var); |
| | 5037 | } |
| 5025 | } | 5038 | } |
| | 5039 | zig_unreachable(); |
| 5026 | } | 5040 | } |
| 5027 | | 5041 | |
| 5028 | static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { | 5042 | static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| ... | @@ -5068,10 +5082,10 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -5068,10 +5082,10 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 5068 | } else if (child_type->id == TypeTableEntryIdStruct) { | 5082 | } else if (child_type->id == TypeTableEntryIdStruct) { |
| 5069 | ScopeDecls *container_scope = get_container_scope(child_type); | 5083 | ScopeDecls *container_scope = get_container_scope(child_type); |
| 5070 | auto entry = container_scope->decl_table.maybe_get(field_name); | 5084 | auto entry = container_scope->decl_table.maybe_get(field_name); |
| 5071 | AstNode *decl_node = entry ? entry->value : nullptr; | 5085 | Tld *tld = entry ? entry->value : nullptr; |
| 5072 | if (decl_node) { | 5086 | if (tld) { |
| 5073 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; | 5087 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; |
| 5074 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, decl_node, depends_on_compile_var); | 5088 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var); |
| 5075 | } else { | 5089 | } else { |
| 5076 | add_node_error(ira->codegen, source_node, | 5090 | add_node_error(ira->codegen, source_node, |
| 5077 | buf_sprintf("container '%s' has no member called '%s'", | 5091 | buf_sprintf("container '%s' has no member called '%s'", |
| ... | @@ -5098,30 +5112,29 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru | ... | @@ -5098,30 +5112,29 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 5098 | ImportTableEntry *namespace_import = namespace_val->data.x_import; | 5112 | ImportTableEntry *namespace_import = namespace_val->data.x_import; |
| 5099 | | 5113 | |
| 5100 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; | 5114 | bool depends_on_compile_var = container_ptr->static_value.depends_on_compile_var; |
| 5101 | AstNode *decl_node = find_decl(&namespace_import->decls_scope->base, field_name); | 5115 | Tld *tld = find_decl(&namespace_import->decls_scope->base, field_name); |
| 5102 | if (!decl_node) { | 5116 | if (!tld) { |
| 5103 | // we must now resolve all the use decls | 5117 | // we must now resolve all the use decls |
| | 5118 | // TODO move this check to find_decl? |
| 5104 | for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) { | 5119 | for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) { |
| 5105 | AstNode *use_decl_node = namespace_import->use_decls.at(i); | 5120 | AstNode *use_decl_node = namespace_import->use_decls.at(i); |
| 5106 | TopLevelDecl *tld = get_as_top_level_decl(use_decl_node); | 5121 | if (use_decl_node->data.use.resolution == TldResolutionUnresolved) { |
| 5107 | if (tld->resolution == TldResolutionUnresolved) { | | |
| 5108 | preview_use_decl(ira->codegen, use_decl_node); | 5122 | preview_use_decl(ira->codegen, use_decl_node); |
| 5109 | } | 5123 | } |
| 5110 | resolve_use_decl(ira->codegen, use_decl_node); | 5124 | resolve_use_decl(ira->codegen, use_decl_node); |
| 5111 | } | 5125 | } |
| 5112 | decl_node = find_decl(&namespace_import->decls_scope->base, field_name); | 5126 | tld = find_decl(&namespace_import->decls_scope->base, field_name); |
| 5113 | } | 5127 | } |
| 5114 | if (decl_node) { | 5128 | if (tld) { |
| 5115 | TopLevelDecl *tld = get_as_top_level_decl(decl_node); | | |
| 5116 | if (tld->visib_mod == VisibModPrivate && | 5129 | if (tld->visib_mod == VisibModPrivate && |
| 5117 | decl_node->owner != source_node->owner) | 5130 | tld->import != source_node->owner) |
| 5118 | { | 5131 | { |
| 5119 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, | 5132 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, |
| 5120 | buf_sprintf("'%s' is private", buf_ptr(field_name))); | 5133 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 5121 | add_error_note(ira->codegen, msg, decl_node, buf_sprintf("declared here")); | 5134 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 5122 | return ira->codegen->builtin_types.entry_invalid; | 5135 | return ira->codegen->builtin_types.entry_invalid; |
| 5123 | } | 5136 | } |
| 5124 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, decl_node, depends_on_compile_var); | 5137 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld, depends_on_compile_var); |
| 5125 | } else { | 5138 | } else { |
| 5126 | const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)"; | 5139 | const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)"; |
| 5127 | add_node_error(ira->codegen, source_node, | 5140 | add_node_error(ira->codegen, source_node, |
| ... | @@ -5176,7 +5189,8 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -5176,7 +5189,8 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 5176 | if (ptr->id == IrInstructionIdVarPtr) { | 5189 | if (ptr->id == IrInstructionIdVarPtr) { |
| 5177 | IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr; | 5190 | IrInstructionVarPtr *var_ptr_inst = (IrInstructionVarPtr *)ptr; |
| 5178 | VariableTableEntry *var = var_ptr_inst->var; | 5191 | VariableTableEntry *var = var_ptr_inst->var; |
| 5179 | new_ptr_inst = ir_build_var_ptr(&ira->new_irb, store_ptr_instruction->base.source_node, var); | 5192 | new_ptr_inst = ir_build_var_ptr(&ira->new_irb, store_ptr_instruction->base.scope, |
| | 5193 | store_ptr_instruction->base.source_node, var); |
| 5180 | assert(var->mem_slot_index != SIZE_MAX); | 5194 | assert(var->mem_slot_index != SIZE_MAX); |
| 5181 | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; | 5195 | ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
| 5182 | mem_slot->special = ConstValSpecialRuntime; | 5196 | mem_slot->special = ConstValSpecialRuntime; |
| ... | @@ -5188,7 +5202,8 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru | ... | @@ -5188,7 +5202,8 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 5188 | zig_unreachable(); | 5202 | zig_unreachable(); |
| 5189 | } | 5203 | } |
| 5190 | new_ptr_inst->type_entry = ptr->type_entry; | 5204 | new_ptr_inst->type_entry = ptr->type_entry; |
| 5191 | ir_build_store_ptr(&ira->new_irb, store_ptr_instruction->base.source_node, new_ptr_inst, casted_value); | 5205 | ir_build_store_ptr(&ira->new_irb, store_ptr_instruction->base.scope, |
| | 5206 | store_ptr_instruction->base.source_node, new_ptr_inst, casted_value); |
| 5192 | return ir_analyze_void(ira, &store_ptr_instruction->base); | 5207 | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 5193 | } | 5208 | } |
| 5194 | | 5209 | |
| ... | @@ -5212,7 +5227,6 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi | ... | @@ -5212,7 +5227,6 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 5212 | case TypeTableEntryIdNullLit: | 5227 | case TypeTableEntryIdNullLit: |
| 5213 | case TypeTableEntryIdNamespace: | 5228 | case TypeTableEntryIdNamespace: |
| 5214 | case TypeTableEntryIdBlock: | 5229 | case TypeTableEntryIdBlock: |
| 5215 | case TypeTableEntryIdGenericFn: | | |
| 5216 | case TypeTableEntryIdBoundFn: | 5230 | case TypeTableEntryIdBoundFn: |
| 5217 | case TypeTableEntryIdMetaType: | 5231 | case TypeTableEntryIdMetaType: |
| 5218 | case TypeTableEntryIdVoid: | 5232 | case TypeTableEntryIdVoid: |
| ... | @@ -5342,14 +5356,13 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira, | ... | @@ -5342,14 +5356,13 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_visible(IrAnalyze *ira, |
| 5342 | fn_entry->fn_export_set_node = source_node; | 5356 | fn_entry->fn_export_set_node = source_node; |
| 5343 | | 5357 | |
| 5344 | AstNodeFnProto *fn_proto = &fn_entry->proto_node->data.fn_proto; | 5358 | AstNodeFnProto *fn_proto = &fn_entry->proto_node->data.fn_proto; |
| 5345 | if (fn_proto->top_level_decl.visib_mod != VisibModExport) { | 5359 | if (fn_proto->visib_mod != VisibModExport) { |
| 5346 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, | 5360 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, |
| 5347 | buf_sprintf("function must be marked export to set function visibility")); | 5361 | buf_sprintf("function must be marked export to set function visibility")); |
| 5348 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("function declared here")); | 5362 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("function declared here")); |
| 5349 | return ira->codegen->builtin_types.entry_invalid; | 5363 | return ira->codegen->builtin_types.entry_invalid; |
| 5350 | } | 5364 | } |
| 5351 | if (!want_export) | 5365 | fn_entry->internal_linkage = !want_export; |
| 5352 | LLVMSetLinkage(fn_entry->fn_value, LLVMInternalLinkage); | | |
| 5353 | | 5366 | |
| 5354 | ir_build_const_from(ira, &set_fn_visible_instruction->base, false); | 5367 | ir_build_const_from(ira, &set_fn_visible_instruction->base, false); |
| 5355 | return ira->codegen->builtin_types.entry_void; | 5368 | return ira->codegen->builtin_types.entry_void; |
| ... | @@ -5366,24 +5379,33 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira, | ... | @@ -5366,24 +5379,33 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira, |
| 5366 | if (!target_val) | 5379 | if (!target_val) |
| 5367 | return ira->codegen->builtin_types.entry_invalid; | 5380 | return ira->codegen->builtin_types.entry_invalid; |
| 5368 | | 5381 | |
| 5369 | Scope *target_context; | 5382 | bool *safety_off_ptr; |
| | 5383 | AstNode **safety_set_node_ptr; |
| 5370 | if (target_type->id == TypeTableEntryIdBlock) { | 5384 | if (target_type->id == TypeTableEntryIdBlock) { |
| 5371 | target_context = target_val->data.x_block; | 5385 | ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; |
| | 5386 | safety_off_ptr = &block_scope->safety_off; |
| | 5387 | safety_set_node_ptr = &block_scope->safety_set_node; |
| 5372 | } else if (target_type->id == TypeTableEntryIdFn) { | 5388 | } else if (target_type->id == TypeTableEntryIdFn) { |
| 5373 | target_context = target_val->data.x_fn->fn_def_node->data.fn_def.child_scope; | 5389 | FnTableEntry *target_fn = target_val->data.x_fn; |
| | 5390 | assert(target_fn->def_scope); |
| | 5391 | safety_off_ptr = &target_fn->def_scope->safety_off; |
| | 5392 | safety_set_node_ptr = &target_fn->def_scope->safety_set_node; |
| 5374 | } else if (target_type->id == TypeTableEntryIdMetaType) { | 5393 | } else if (target_type->id == TypeTableEntryIdMetaType) { |
| | 5394 | ScopeDecls *decls_scope; |
| 5375 | TypeTableEntry *type_arg = target_val->data.x_type; | 5395 | TypeTableEntry *type_arg = target_val->data.x_type; |
| 5376 | if (type_arg->id == TypeTableEntryIdStruct) { | 5396 | if (type_arg->id == TypeTableEntryIdStruct) { |
| 5377 | target_context = &type_arg->data.structure.decls_scope->base; | 5397 | decls_scope = type_arg->data.structure.decls_scope; |
| 5378 | } else if (type_arg->id == TypeTableEntryIdEnum) { | 5398 | } else if (type_arg->id == TypeTableEntryIdEnum) { |
| 5379 | target_context = &type_arg->data.enumeration.decls_scope->base; | 5399 | decls_scope = type_arg->data.enumeration.decls_scope; |
| 5380 | } else if (type_arg->id == TypeTableEntryIdUnion) { | 5400 | } else if (type_arg->id == TypeTableEntryIdUnion) { |
| 5381 | target_context = &type_arg->data.unionation.decls_scope->base; | 5401 | decls_scope = type_arg->data.unionation.decls_scope; |
| 5382 | } else { | 5402 | } else { |
| 5383 | add_node_error(ira->codegen, target_instruction->source_node, | 5403 | add_node_error(ira->codegen, target_instruction->source_node, |
| 5384 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name))); | 5404 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name))); |
| 5385 | return ira->codegen->builtin_types.entry_invalid; | 5405 | return ira->codegen->builtin_types.entry_invalid; |
| 5386 | } | 5406 | } |
| | 5407 | safety_off_ptr = &decls_scope->safety_off; |
| | 5408 | safety_set_node_ptr = &decls_scope->safety_set_node; |
| 5387 | } else { | 5409 | } else { |
| 5388 | add_node_error(ira->codegen, target_instruction->source_node, | 5410 | add_node_error(ira->codegen, target_instruction->source_node, |
| 5389 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name))); | 5411 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name))); |
| ... | @@ -5396,14 +5418,14 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira, | ... | @@ -5396,14 +5418,14 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira, |
| 5396 | return ira->codegen->builtin_types.entry_invalid; | 5418 | return ira->codegen->builtin_types.entry_invalid; |
| 5397 | | 5419 | |
| 5398 | AstNode *source_node = set_debug_safety_instruction->base.source_node; | 5420 | AstNode *source_node = set_debug_safety_instruction->base.source_node; |
| 5399 | if (target_context->safety_set_node) { | 5421 | if (*safety_set_node_ptr) { |
| 5400 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, | 5422 | ErrorMsg *msg = add_node_error(ira->codegen, source_node, |
| 5401 | buf_sprintf("function test attribute set twice")); | 5423 | buf_sprintf("function test attribute set twice")); |
| 5402 | add_error_note(ira->codegen, msg, target_context->safety_set_node, buf_sprintf("first set here")); | 5424 | add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here")); |
| 5403 | return ira->codegen->builtin_types.entry_invalid; | 5425 | return ira->codegen->builtin_types.entry_invalid; |
| 5404 | } | 5426 | } |
| 5405 | target_context->safety_set_node = source_node; | 5427 | *safety_set_node_ptr = source_node; |
| 5406 | target_context->safety_off = !want_debug_safety; | 5428 | *safety_off_ptr = !want_debug_safety; |
| 5407 | | 5429 | |
| 5408 | ir_build_const_from(ira, &set_debug_safety_instruction->base, false); | 5430 | ir_build_const_from(ira, &set_debug_safety_instruction->base, false); |
| 5409 | return ira->codegen->builtin_types.entry_void; | 5431 | return ira->codegen->builtin_types.entry_void; |
| ... | @@ -5450,7 +5472,6 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -5450,7 +5472,6 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 5450 | case TypeTableEntryIdUnion: | 5472 | case TypeTableEntryIdUnion: |
| 5451 | case TypeTableEntryIdFn: | 5473 | case TypeTableEntryIdFn: |
| 5452 | case TypeTableEntryIdNamespace: | 5474 | case TypeTableEntryIdNamespace: |
| 5453 | case TypeTableEntryIdGenericFn: | | |
| 5454 | case TypeTableEntryIdBoundFn: | 5475 | case TypeTableEntryIdBoundFn: |
| 5455 | { | 5476 | { |
| 5456 | TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const); | 5477 | TypeTableEntry *result_type = get_slice_type(ira->codegen, resolved_child_type, is_const); |
| ... | @@ -5494,7 +5515,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA | ... | @@ -5494,7 +5515,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA |
| 5494 | } | 5515 | } |
| 5495 | | 5516 | |
| 5496 | ir_build_asm_from(&ira->new_irb, &asm_instruction->base, input_list, output_types, | 5517 | ir_build_asm_from(&ira->new_irb, &asm_instruction->base, input_list, output_types, |
| 5497 | asm_instruction->return_count, asm_instruction->has_side_effects); | 5518 | asm_instruction->output_vars, asm_instruction->return_count, asm_instruction->has_side_effects); |
| 5498 | return return_type; | 5519 | return return_type; |
| 5499 | } | 5520 | } |
| 5500 | | 5521 | |
| ... | @@ -5540,7 +5561,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, | ... | @@ -5540,7 +5561,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 5540 | case TypeTableEntryIdUnion: | 5561 | case TypeTableEntryIdUnion: |
| 5541 | case TypeTableEntryIdFn: | 5562 | case TypeTableEntryIdFn: |
| 5542 | case TypeTableEntryIdNamespace: | 5563 | case TypeTableEntryIdNamespace: |
| 5543 | case TypeTableEntryIdGenericFn: | | |
| 5544 | case TypeTableEntryIdBoundFn: | 5564 | case TypeTableEntryIdBoundFn: |
| 5545 | { | 5565 | { |
| 5546 | TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size); | 5566 | TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size); |
| ... | @@ -5611,7 +5631,6 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, | ... | @@ -5611,7 +5631,6 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 5611 | case TypeTableEntryIdBlock: | 5631 | case TypeTableEntryIdBlock: |
| 5612 | case TypeTableEntryIdNumLitFloat: | 5632 | case TypeTableEntryIdNumLitFloat: |
| 5613 | case TypeTableEntryIdNumLitInt: | 5633 | case TypeTableEntryIdNumLitInt: |
| 5614 | case TypeTableEntryIdGenericFn: | | |
| 5615 | case TypeTableEntryIdBoundFn: | 5634 | case TypeTableEntryIdBoundFn: |
| 5616 | case TypeTableEntryIdMetaType: | 5635 | case TypeTableEntryIdMetaType: |
| 5617 | case TypeTableEntryIdFn: | 5636 | case TypeTableEntryIdFn: |
| ... | @@ -5905,7 +5924,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -5905,7 +5924,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 5905 | case TypeTableEntryIdMaybe: | 5924 | case TypeTableEntryIdMaybe: |
| 5906 | case TypeTableEntryIdUnion: | 5925 | case TypeTableEntryIdUnion: |
| 5907 | case TypeTableEntryIdBlock: | 5926 | case TypeTableEntryIdBlock: |
| 5908 | case TypeTableEntryIdGenericFn: | | |
| 5909 | case TypeTableEntryIdBoundFn: | 5927 | case TypeTableEntryIdBoundFn: |
| 5910 | add_node_error(ira->codegen, switch_target_instruction->base.source_node, | 5928 | add_node_error(ira->codegen, switch_target_instruction->base.source_node, |
| 5911 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); | 5929 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| ... | @@ -6009,7 +6027,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi | ... | @@ -6009,7 +6027,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 6009 | ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, | 6027 | ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, |
| 6010 | abs_full_path, search_dir, import_target_path, import_code); | 6028 | abs_full_path, search_dir, import_target_path, import_code); |
| 6011 | | 6029 | |
| 6012 | scan_decls(ira->codegen, target_import, target_import->decls_scope, target_import->root); | 6030 | scan_decls(ira->codegen, target_import, target_import->decls_scope, target_import->root, nullptr); |
| 6013 | | 6031 | |
| 6014 | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var); | 6032 | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base, depends_on_compile_var); |
| 6015 | out_val->data.x_import = target_import; | 6033 | out_val->data.x_import = target_import; |
| ... | @@ -6064,7 +6082,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru | ... | @@ -6064,7 +6082,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru |
| 6064 | | 6082 | |
| 6065 | IrInstructionStructInitField *new_fields = allocate<IrInstructionStructInitField>(actual_field_count); | 6083 | IrInstructionStructInitField *new_fields = allocate<IrInstructionStructInitField>(actual_field_count); |
| 6066 | | 6084 | |
| 6067 | FnTableEntry *fn_entry = scope_fn_entry(instruction->source_node->scope); | 6085 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 6068 | bool outside_fn = (fn_entry == nullptr); | 6086 | bool outside_fn = (fn_entry == nullptr); |
| 6069 | | 6087 | |
| 6070 | ConstExprValue const_val = {}; | 6088 | ConstExprValue const_val = {}; |
| ... | @@ -6167,7 +6185,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira | ... | @@ -6167,7 +6185,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira |
| 6167 | const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count); | 6185 | const_val.data.x_array.elements = allocate<ConstExprValue>(elem_count); |
| 6168 | const_val.data.x_array.size = elem_count; | 6186 | const_val.data.x_array.size = elem_count; |
| 6169 | | 6187 | |
| 6170 | FnTableEntry *fn_entry = scope_fn_entry(instruction->base.source_node->scope); | 6188 | FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 6171 | bool outside_fn = (fn_entry == nullptr); | 6189 | bool outside_fn = (fn_entry == nullptr); |
| 6172 | | 6190 | |
| 6173 | IrInstruction **new_items = allocate<IrInstruction *>(elem_count); | 6191 | IrInstruction **new_items = allocate<IrInstruction *>(elem_count); |