| ... | ... | @@ -6422,52 +6422,17 @@ fn asmExpr( |
| 6422 | 6422 | const asm_source = switch (node_tags[full.ast.template]) { |
| 6423 | 6423 | .string_literal => try astgen.strLitAsString(main_tokens[full.ast.template]), |
| 6424 | 6424 | .multiline_string_literal => try astgen.strLitNodeAsString(full.ast.template), |
| 6425 | | else => { |
| 6425 | else => blk: { |
| 6426 | 6426 | // stage1 allows this, and until we do another design iteration on inline assembly |
| 6427 | 6427 | // in stage2 to improve support for the various needed use cases, we allow inline |
| 6428 | 6428 | // assembly templates to be an expression. Once stage2 addresses the real world needs |
| 6429 | 6429 | // of people using inline assembly (primarily OS developers) then we can re-institute |
| 6430 | 6430 | // the rule into AstGen that assembly code must use string literal syntax. |
| 6431 | 6431 | //return astgen.failNode(full.ast.template, "assembly code must use string literal syntax", .{}), |
| 6432 | | |
| 6433 | | // This code emits ZIR for |
| 6434 | | // `@compileError("assembly code must use string literal syntax")` |
| 6435 | | // which allows it to make it to stage1 but gives the error for stage2. |
| 6436 | | const string_bytes = &astgen.string_bytes; |
| 6437 | | const str_index = @intCast(u32, string_bytes.items.len); |
| 6438 | | try string_bytes.appendSlice(astgen.gpa, "assembly code must use string literal syntax"); |
| 6439 | | const key = string_bytes.items[str_index..]; |
| 6440 | | const gop = try astgen.string_table.getOrPutContextAdapted(astgen.gpa, @as([]const u8, key), StringIndexAdapter{ |
| 6441 | | .bytes = string_bytes, |
| 6442 | | }, StringIndexContext{ |
| 6443 | | .bytes = string_bytes, |
| 6444 | | }); |
| 6445 | | const str = if (gop.found_existing) str: { |
| 6446 | | string_bytes.shrinkRetainingCapacity(str_index); |
| 6447 | | break :str IndexSlice{ |
| 6448 | | .index = gop.key_ptr.*, |
| 6449 | | .len = @intCast(u32, key.len), |
| 6450 | | }; |
| 6451 | | } else str: { |
| 6452 | | gop.key_ptr.* = str_index; |
| 6453 | | // Still need a null byte because we are using the same table |
| 6454 | | // to lookup null terminated strings, so if we get a match, it has to |
| 6455 | | // be null terminated for that to work. |
| 6456 | | try string_bytes.append(astgen.gpa, 0); |
| 6457 | | break :str IndexSlice{ |
| 6458 | | .index = str_index, |
| 6459 | | .len = @intCast(u32, key.len), |
| 6460 | | }; |
| 6461 | | }; |
| 6462 | | const msg = try gz.add(.{ |
| 6463 | | .tag = .str, |
| 6464 | | .data = .{ .str = .{ |
| 6465 | | .start = str.index, |
| 6466 | | .len = str.len, |
| 6467 | | } }, |
| 6468 | | }); |
| 6469 | | const result = try gz.addUnNode(.compile_error, msg, node); |
| 6470 | | return rvalue(gz, rl, result, node); |
| 6432 | // We still need to trigger all the expr() calls here to avoid errors for unused things. |
| 6433 | // So we pass 0 as the asm source and stage2 Sema will notice this and |
| 6434 | // report the error. |
| 6435 | break :blk IndexSlice{ .index = 0, .len = 0 }; |
| 6471 | 6436 | }, |
| 6472 | 6437 | }; |
| 6473 | 6438 | |