| ... | ... | @@ -383,8 +383,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 383 | 383 | |
| 384 | 384 | .identifier => return identifier(mod, scope, rl, node), |
| 385 | 385 | |
| 386 | | .asm_simple => return asmExpr(mod, scope, rl, tree.asmSimple(node)), |
| 387 | | .@"asm" => return asmExpr(mod, scope, rl, tree.asmFull(node)), |
| 386 | .asm_simple => return asmExpr(mod, scope, rl, node, tree.asmSimple(node)), |
| 387 | .@"asm" => return asmExpr(mod, scope, rl, node, tree.asmFull(node)), |
| 388 | 388 | |
| 389 | 389 | .string_literal => return stringLiteral(mod, scope, rl, node), |
| 390 | 390 | .multiline_string_literal => return multilineStringLiteral(mod, scope, rl, node), |
| ... | ... | @@ -497,15 +497,13 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 497 | 497 | return blockExpr(mod, scope, rl, node, statements); |
| 498 | 498 | }, |
| 499 | 499 | .enum_literal => { |
| 500 | | if (true) @panic("TODO update for zir-memory-layout"); |
| 501 | 500 | const ident_token = main_tokens[node]; |
| 502 | | const gen_zir = scope.getGenZir(); |
| 503 | | const string_bytes = &gen_zir.zir_exec.string_bytes; |
| 504 | | const str_index = string_bytes.items.len; |
| 501 | const string_bytes = &gz.zir_code.string_bytes; |
| 502 | const str_index = @intCast(u32, string_bytes.items.len); |
| 505 | 503 | try mod.appendIdentStr(scope, ident_token, string_bytes); |
| 506 | | const str_len = string_bytes.items.len - str_index; |
| 507 | | const result = try gen_zir.addStr(.enum_literal, str_index, str_len); |
| 508 | | return rvalue(mod, scope, rl, result); |
| 504 | try string_bytes.append(mod.gpa, 0); |
| 505 | const result = try gz.addStrTok(.enum_literal, str_index, ident_token); |
| 506 | return rvalue(mod, scope, rl, result, node); |
| 509 | 507 | }, |
| 510 | 508 | .error_value => { |
| 511 | 509 | if (true) @panic("TODO update for zir-memory-layout"); |
| ... | ... | @@ -2994,48 +2992,58 @@ fn floatLiteral( |
| 2994 | 2992 | return rvalue(mod, scope, rl, result); |
| 2995 | 2993 | } |
| 2996 | 2994 | |
| 2997 | | fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) InnerError!zir.Inst.Ref { |
| 2998 | | if (true) @panic("TODO update for zir-memory-layout"); |
| 2995 | fn asmExpr( |
| 2996 | mod: *Module, |
| 2997 | scope: *Scope, |
| 2998 | rl: ResultLoc, |
| 2999 | node: ast.Node.Index, |
| 3000 | full: ast.full.Asm, |
| 3001 | ) InnerError!zir.Inst.Ref { |
| 2999 | 3002 | const arena = scope.arena(); |
| 3000 | 3003 | const tree = scope.tree(); |
| 3001 | 3004 | const main_tokens = tree.nodes.items(.main_token); |
| 3002 | 3005 | const token_starts = tree.tokens.items(.start); |
| 3003 | 3006 | const node_datas = tree.nodes.items(.data); |
| 3007 | const gz = scope.getGenZir(); |
| 3008 | |
| 3009 | const str_type = @enumToInt(zir.Const.const_slice_u8_type); |
| 3010 | const str_type_rl: ResultLoc = .{ .ty = str_type }; |
| 3011 | const asm_source = try expr(mod, scope, str_type_rl, full.ast.template); |
| 3004 | 3012 | |
| 3005 | 3013 | if (full.outputs.len != 0) { |
| 3006 | 3014 | return mod.failTok(scope, full.ast.asm_token, "TODO implement asm with an output", .{}); |
| 3007 | 3015 | } |
| 3016 | const return_type = @enumToInt(zir.Const.void_type); |
| 3008 | 3017 | |
| 3009 | | const inputs = try arena.alloc([]const u8, full.inputs.len); |
| 3018 | const constraints = try arena.alloc(u32, full.inputs.len); |
| 3010 | 3019 | const args = try arena.alloc(zir.Inst.Ref, full.inputs.len); |
| 3011 | 3020 | |
| 3012 | | const str_type = try addZIRInstConst(mod, scope, src, .{ |
| 3013 | | .ty = Type.initTag(.type), |
| 3014 | | .val = Value.initTag(.const_slice_u8_type), |
| 3015 | | }); |
| 3016 | | const str_type_rl: ResultLoc = .{ .ty = str_type }; |
| 3017 | | |
| 3018 | 3021 | for (full.inputs) |input, i| { |
| 3019 | | // TODO semantically analyze constraints |
| 3020 | 3022 | const constraint_token = main_tokens[input] + 2; |
| 3021 | | inputs[i] = try parseStringLiteral(mod, scope, constraint_token); |
| 3022 | | args[i] = try expr(mod, scope, .none, node_datas[input].lhs); |
| 3023 | const string_bytes = &gz.zir_code.string_bytes; |
| 3024 | constraints[i] = @intCast(u32, string_bytes.items.len); |
| 3025 | try mod.appendIdentStr(scope, constraint_token, string_bytes); |
| 3026 | try string_bytes.append(mod.gpa, 0); |
| 3027 | |
| 3028 | const usize_rl: ResultLoc = .{ .ty = @enumToInt(zir.Const.usize_type) }; |
| 3029 | args[i] = try expr(mod, scope, usize_rl, node_datas[input].lhs); |
| 3023 | 3030 | } |
| 3024 | 3031 | |
| 3025 | | const return_type = try addZIRInstConst(mod, scope, src, .{ |
| 3026 | | .ty = Type.initTag(.type), |
| 3027 | | .val = Value.initTag(.void_type), |
| 3028 | | }); |
| 3029 | | const asm_inst = try addZIRInst(mod, scope, src, zir.Inst.Asm, .{ |
| 3030 | | .asm_source = try expr(mod, scope, str_type_rl, full.ast.template), |
| 3032 | const tag: zir.Inst.Tag = if (full.volatile_token != null) .asm_volatile else .@"asm"; |
| 3033 | const result = try gz.addPlNode(.@"asm", node, zir.Inst.Asm{ |
| 3034 | .asm_source = asm_source, |
| 3031 | 3035 | .return_type = return_type, |
| 3032 | | }, .{ |
| 3033 | | .@"volatile" = full.volatile_token != null, |
| 3034 | | //.clobbers = TODO handle clobbers |
| 3035 | | .inputs = inputs, |
| 3036 | | .args = args, |
| 3036 | .output = 0, |
| 3037 | .args_len = @intCast(u32, full.inputs.len), |
| 3038 | .clobbers_len = 0, // TODO implement asm clobbers |
| 3037 | 3039 | }); |
| 3038 | | return rvalue(mod, scope, rl, asm_inst); |
| 3040 | |
| 3041 | try gz.zir_code.extra.ensureCapacity(mod.gpa, gz.zir_code.extra.items.len + |
| 3042 | args.len + constraints.len); |
| 3043 | gz.zir_code.extra.appendSliceAssumeCapacity(args); |
| 3044 | gz.zir_code.extra.appendSliceAssumeCapacity(constraints); |
| 3045 | |
| 3046 | return rvalue(mod, scope, rl, result, node); |
| 3039 | 3047 | } |
| 3040 | 3048 | |
| 3041 | 3049 | fn as( |