| ... | @@ -6290,11 +6290,12 @@ pub const FuncGen = struct { | ... | @@ -6290,11 +6290,12 @@ pub const FuncGen = struct { |
| 6290 | var rendered_template = std.ArrayList(u8).init(self.gpa); | 6290 | var rendered_template = std.ArrayList(u8).init(self.gpa); |
| 6291 | defer rendered_template.deinit(); | 6291 | defer rendered_template.deinit(); |
| 6292 | | 6292 | |
| 6293 | const State = enum { start, percent, input }; | 6293 | const State = enum { start, percent, input, modifier }; |
| 6294 | | 6294 | |
| 6295 | var state: State = .start; | 6295 | var state: State = .start; |
| 6296 | | 6296 | |
| 6297 | var name_start: usize = undefined; | 6297 | var name_start: usize = undefined; |
| | 6298 | var modifier_start: usize = undefined; |
| 6298 | for (asm_source) |byte, i| { | 6299 | for (asm_source) |byte, i| { |
| 6299 | switch (state) { | 6300 | switch (state) { |
| 6300 | .start => switch (byte) { | 6301 | .start => switch (byte) { |
| ... | @@ -6309,6 +6310,7 @@ pub const FuncGen = struct { | ... | @@ -6309,6 +6310,7 @@ pub const FuncGen = struct { |
| 6309 | }, | 6310 | }, |
| 6310 | '[' => { | 6311 | '[' => { |
| 6311 | try rendered_template.append('$'); | 6312 | try rendered_template.append('$'); |
| | 6313 | try rendered_template.append('{'); |
| 6312 | name_start = i + 1; | 6314 | name_start = i + 1; |
| 6313 | state = .input; | 6315 | state = .input; |
| 6314 | }, | 6316 | }, |
| ... | @@ -6319,15 +6321,30 @@ pub const FuncGen = struct { | ... | @@ -6319,15 +6321,30 @@ pub const FuncGen = struct { |
| 6319 | }, | 6321 | }, |
| 6320 | }, | 6322 | }, |
| 6321 | .input => switch (byte) { | 6323 | .input => switch (byte) { |
| 6322 | ']' => { | 6324 | ']', ':' => { |
| 6323 | const name = asm_source[name_start..i]; | 6325 | const name = asm_source[name_start..i]; |
| 6324 | state = .start; | | |
| 6325 | | 6326 | |
| 6326 | const index = name_map.get(name) orelse { | 6327 | const index = name_map.get(name) orelse { |
| 6327 | // we should validate the assembly in Sema; by now it is too late | 6328 | // we should validate the assembly in Sema; by now it is too late |
| 6328 | return self.todo("unknown input or output name: '{s}'", .{name}); | 6329 | return self.todo("unknown input or output name: '{s}'", .{name}); |
| 6329 | }; | 6330 | }; |
| 6330 | try rendered_template.writer().print("{d}", .{index}); | 6331 | try rendered_template.writer().print("{d}", .{index}); |
| | 6332 | if (byte == ':') { |
| | 6333 | try rendered_template.append(':'); |
| | 6334 | modifier_start = i + 1; |
| | 6335 | state = .modifier; |
| | 6336 | } else { |
| | 6337 | try rendered_template.append('}'); |
| | 6338 | state = .start; |
| | 6339 | } |
| | 6340 | }, |
| | 6341 | else => {}, |
| | 6342 | }, |
| | 6343 | .modifier => switch (byte) { |
| | 6344 | ']' => { |
| | 6345 | try rendered_template.appendSlice(asm_source[modifier_start..i]); |
| | 6346 | try rendered_template.append('}'); |
| | 6347 | state = .start; |
| 6331 | }, | 6348 | }, |
| 6332 | else => {}, | 6349 | else => {}, |
| 6333 | }, | 6350 | }, |