| ... | ... | @@ -6743,6 +6743,25 @@ static Error parse_asm_template(IrBuilder *irb, AstNode *source_node, Buf *asm_t |
| 6743 | 6743 | return ErrorNone; |
| 6744 | 6744 | } |
| 6745 | 6745 | |
| 6746 | static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_template) { |
| 6747 | const char *ptr = buf_ptr(src_template) + tok->start + 2; |
| 6748 | size_t len = tok->end - tok->start - 2; |
| 6749 | size_t result = 0; |
| 6750 | for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) { |
| 6751 | AsmOutput *asm_output = node->data.asm_expr.output_list.at(i); |
| 6752 | if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) { |
| 6753 | return result; |
| 6754 | } |
| 6755 | } |
| 6756 | for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) { |
| 6757 | AsmInput *asm_input = node->data.asm_expr.input_list.at(i); |
| 6758 | if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) { |
| 6759 | return result; |
| 6760 | } |
| 6761 | } |
| 6762 | return SIZE_MAX; |
| 6763 | } |
| 6764 | |
| 6746 | 6765 | static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 6747 | 6766 | Error err; |
| 6748 | 6767 | assert(node->type == NodeTypeAsmExpr); |
| ... | ... | @@ -6830,6 +6849,22 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod |
| 6830 | 6849 | input_list[i] = input_value; |
| 6831 | 6850 | } |
| 6832 | 6851 | |
| 6852 | for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) { |
| 6853 | AsmToken asm_token = tok_list.at(token_i); |
| 6854 | if (asm_token.id == AsmTokenIdVar) { |
| 6855 | size_t index = find_asm_index(irb->codegen, node, &asm_token, template_buf); |
| 6856 | if (index == SIZE_MAX) { |
| 6857 | const char *ptr = buf_ptr(template_buf) + asm_token.start + 2; |
| 6858 | uint32_t len = asm_token.end - asm_token.start - 2; |
| 6859 | |
| 6860 | add_node_error(irb->codegen, node, |
| 6861 | buf_sprintf("could not find '%.*s' in the inputs or outputs.", |
| 6862 | len, ptr)); |
| 6863 | return irb->codegen->invalid_instruction; |
| 6864 | } |
| 6865 | } |
| 6866 | } |
| 6867 | |
| 6833 | 6868 | return ir_build_asm(irb, scope, node, template_buf, tok_list.items, tok_list.length, |
| 6834 | 6869 | input_list, output_types, output_vars, return_count, is_volatile); |
| 6835 | 6870 | } |