diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-08-20 14:42:02 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-08-20 14:42:02 -0400 |
| commit | f0a141f79978d6d04b7cac1986b9bda770d3d6f9 (patch) | |
| tree | 43b99a9c9095517a21869dac8ab0e7e0de7ab7e7 /src/ir.cpp | |
| parent | 2aa18b909765a48878d3f30f638e79d6eee1b584 (diff) | |
| parent | 276eb4402b3c54adef10033d1ec54bf2053cc563 (diff) | |
| download | zig-f0a141f79978d6d04b7cac1986b9bda770d3d6f9.tar.gz zig-f0a141f79978d6d04b7cac1986b9bda770d3d6f9.zip | |
Merge branch 'FireFox317-fix-issue-3030'
closes #3084
closes #3030
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 8f27c9ea2c..cdddce1b18 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6743,6 +6743,25 @@ static Error parse_asm_template(IrBuilder *irb, AstNode *source_node, Buf *asm_t return ErrorNone; } +static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_template) { + const char *ptr = buf_ptr(src_template) + tok->start + 2; + size_t len = tok->end - tok->start - 2; + size_t result = 0; + for (size_t i = 0; i < node->data.asm_expr.output_list.length; i += 1, result += 1) { + AsmOutput *asm_output = node->data.asm_expr.output_list.at(i); + if (buf_eql_mem(asm_output->asm_symbolic_name, ptr, len)) { + return result; + } + } + for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1, result += 1) { + AsmInput *asm_input = node->data.asm_expr.input_list.at(i); + if (buf_eql_mem(asm_input->asm_symbolic_name, ptr, len)) { + return result; + } + } + return SIZE_MAX; +} + static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) { Error err; assert(node->type == NodeTypeAsmExpr); @@ -6830,6 +6849,22 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod input_list[i] = input_value; } + for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) { + AsmToken asm_token = tok_list.at(token_i); + if (asm_token.id == AsmTokenIdVar) { + size_t index = find_asm_index(irb->codegen, node, &asm_token, template_buf); + if (index == SIZE_MAX) { + const char *ptr = buf_ptr(template_buf) + asm_token.start + 2; + uint32_t len = asm_token.end - asm_token.start - 2; + + add_node_error(irb->codegen, node, + buf_sprintf("could not find '%.*s' in the inputs or outputs.", + len, ptr)); + return irb->codegen->invalid_instruction; + } + } + } + return ir_build_asm(irb, scope, node, template_buf, tok_list.items, tok_list.length, input_list, output_types, output_vars, return_count, is_volatile); } |
