| ... | @@ -1577,13 +1577,11 @@ static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, | ... | @@ -1577,13 +1577,11 @@ static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, |
| 1577 | } | 1577 | } |
| 1578 | | 1578 | |
| 1579 | static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1579 | static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1580 | IrInstruction *scope_value, IrInstruction *mode_value) | 1580 | IrInstruction *mode_value) |
| 1581 | { | 1581 | { |
| 1582 | IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node); | 1582 | IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node); |
| 1583 | instruction->scope_value = scope_value; | | |
| 1584 | instruction->mode_value = mode_value; | 1583 | instruction->mode_value = mode_value; |
| 1585 | | 1584 | |
| 1586 | ir_ref_instruction(scope_value, irb->current_basic_block); | | |
| 1587 | ir_ref_instruction(mode_value, irb->current_basic_block); | 1585 | ir_ref_instruction(mode_value, irb->current_basic_block); |
| 1588 | | 1586 | |
| 1589 | return &instruction->base; | 1587 | return &instruction->base; |
| ... | @@ -3959,12 +3957,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -3959,12 +3957,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 3959 | if (arg0_value == irb->codegen->invalid_instruction) | 3957 | if (arg0_value == irb->codegen->invalid_instruction) |
| 3960 | return arg0_value; | 3958 | return arg0_value; |
| 3961 | | 3959 | |
| 3962 | AstNode *arg1_node = node->data.fn_call_expr.params.at(1); | 3960 | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value); |
| 3963 | IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); | | |
| 3964 | if (arg1_value == irb->codegen->invalid_instruction) | | |
| 3965 | return arg1_value; | | |
| 3966 | | | |
| 3967 | IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value, arg1_value); | | |
| 3968 | return ir_lval_wrap(irb, scope, set_float_mode, lval); | 3961 | return ir_lval_wrap(irb, scope, set_float_mode, lval); |
| 3969 | } | 3962 | } |
| 3970 | case BuiltinFnIdSizeof: | 3963 | case BuiltinFnIdSizeof: |
| ... | @@ -15379,6 +15372,7 @@ static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSet | ... | @@ -15379,6 +15372,7 @@ static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSet |
| 15379 | ir_build_const_from(ira, &instruction->base); | 15372 | ir_build_const_from(ira, &instruction->base); |
| 15380 | return ira->codegen->builtin_types.entry_void; | 15373 | return ira->codegen->builtin_types.entry_void; |
| 15381 | } | 15374 | } |
| | 15375 | |
| 15382 | static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, | 15376 | static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15383 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) | 15377 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 15384 | { | 15378 | { |
| ... | @@ -15439,14 +15433,6 @@ static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, | ... | @@ -15439,14 +15433,6 @@ static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15439 | static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, | 15433 | static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15440 | IrInstructionSetFloatMode *instruction) | 15434 | IrInstructionSetFloatMode *instruction) |
| 15441 | { | 15435 | { |
| 15442 | IrInstruction *target_instruction = instruction->scope_value->other; | | |
| 15443 | ZigType *target_type = target_instruction->value.type; | | |
| 15444 | if (type_is_invalid(target_type)) | | |
| 15445 | return ira->codegen->builtin_types.entry_invalid; | | |
| 15446 | ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad); | | |
| 15447 | if (!target_val) | | |
| 15448 | return ira->codegen->builtin_types.entry_invalid; | | |
| 15449 | | | |
| 15450 | if (ira->new_irb.exec->is_inline) { | 15436 | if (ira->new_irb.exec->is_inline) { |
| 15451 | // ignore setFloatMode when running functions at compile time | 15437 | // ignore setFloatMode when running functions at compile time |
| 15452 | ir_build_const_from(ira, &instruction->base); | 15438 | ir_build_const_from(ira, &instruction->base); |
| ... | @@ -15455,40 +15441,34 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, | ... | @@ -15455,40 +15441,34 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15455 | | 15441 | |
| 15456 | bool *fast_math_on_ptr; | 15442 | bool *fast_math_on_ptr; |
| 15457 | AstNode **fast_math_set_node_ptr; | 15443 | AstNode **fast_math_set_node_ptr; |
| 15458 | if (target_type->id == ZigTypeIdBlock) { | 15444 | |
| 15459 | ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; | 15445 | Scope *scope = instruction->base.scope; |
| 15460 | fast_math_on_ptr = &block_scope->fast_math_on; | 15446 | while (scope != nullptr) { |
| 15461 | fast_math_set_node_ptr = &block_scope->fast_math_set_node; | 15447 | if (scope->id == ScopeIdBlock) { |
| 15462 | } else if (target_type->id == ZigTypeIdFn) { | 15448 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| 15463 | assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction); | 15449 | fast_math_on_ptr = &block_scope->fast_math_on; |
| 15464 | ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry; | 15450 | fast_math_set_node_ptr = &block_scope->fast_math_set_node; |
| 15465 | assert(target_fn->def_scope); | 15451 | break; |
| 15466 | fast_math_on_ptr = &target_fn->def_scope->fast_math_on; | 15452 | } else if (scope->id == ScopeIdFnDef) { |
| 15467 | fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; | 15453 | ScopeFnDef *def_scope = (ScopeFnDef *)scope; |
| 15468 | } else if (target_type->id == ZigTypeIdMetaType) { | 15454 | ZigFn *target_fn = def_scope->fn_entry; |
| 15469 | ScopeDecls *decls_scope; | 15455 | assert(target_fn->def_scope != nullptr); |
| 15470 | ZigType *type_arg = target_val->data.x_type; | 15456 | fast_math_on_ptr = &target_fn->def_scope->fast_math_on; |
| 15471 | if (type_arg->id == ZigTypeIdStruct) { | 15457 | fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; |
| 15472 | decls_scope = type_arg->data.structure.decls_scope; | 15458 | break; |
| 15473 | } else if (type_arg->id == ZigTypeIdEnum) { | 15459 | } else if (scope->id == ScopeIdDecls) { |
| 15474 | decls_scope = type_arg->data.enumeration.decls_scope; | 15460 | ScopeDecls *decls_scope = (ScopeDecls *)scope; |
| 15475 | } else if (type_arg->id == ZigTypeIdUnion) { | 15461 | fast_math_on_ptr = &decls_scope->fast_math_on; |
| 15476 | decls_scope = type_arg->data.unionation.decls_scope; | 15462 | fast_math_set_node_ptr = &decls_scope->fast_math_set_node; |
| | 15463 | break; |
| 15477 | } else { | 15464 | } else { |
| 15478 | ir_add_error_node(ira, target_instruction->source_node, | 15465 | scope = scope->parent; |
| 15479 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name))); | 15466 | continue; |
| 15480 | return ira->codegen->builtin_types.entry_invalid; | | |
| 15481 | } | 15467 | } |
| 15482 | fast_math_on_ptr = &decls_scope->fast_math_on; | | |
| 15483 | fast_math_set_node_ptr = &decls_scope->fast_math_set_node; | | |
| 15484 | } else { | | |
| 15485 | ir_add_error_node(ira, target_instruction->source_node, | | |
| 15486 | buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name))); | | |
| 15487 | return ira->codegen->builtin_types.entry_invalid; | | |
| 15488 | } | 15468 | } |
| | 15469 | assert(scope != nullptr); |
| 15489 | | 15470 | |
| 15490 | IrInstruction *float_mode_value = instruction->mode_value->other; | 15471 | IrInstruction *float_mode_value = instruction->mode_value->other; |
| 15491 | | | |
| 15492 | FloatMode float_mode_scalar; | 15472 | FloatMode float_mode_scalar; |
| 15493 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) | 15473 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) |
| 15494 | return ira->codegen->builtin_types.entry_invalid; | 15474 | return ira->codegen->builtin_types.entry_invalid; |