authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-19 03:19:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-19 19:31:50-04:00
log104ae419e4f8b327c354a9a6f02b52c9884aedf0
treec0e16b5c0994cb549041cf545edb75206f02193b
parentf020999ca3135220a1b34e05d22c76ed3628b0c2

ir: parse export instruction


1 files changed, 19 insertions(+), 4 deletions(-)

src-self-hosted/ir.zig+19-4
......@@ -17,6 +17,7 @@ pub const Inst = struct {
1717 @"asm",
1818 @"unreachable",
1919 @"fn",
20 @"export",
2021 };
2122
2223 pub fn TagToType(tag: Tag) type {
......@@ -26,8 +27,9 @@ pub const Inst = struct {
2627 .fieldptr => FieldPtr,
2728 .deref => Deref,
2829 .@"asm" => Assembly,
29 .@"unreachable" => Unreach,
30 .@"unreachable" => Unreachable,
3031 .@"fn" => Fn,
32 .@"export" => Export,
3133 };
3234 }
3335
......@@ -87,8 +89,8 @@ pub const Inst = struct {
8789 },
8890 };
8991
90 pub const Unreach = struct {
91 base: Inst = Inst{ .tag = .unreach },
92 pub const Unreachable = struct {
93 base: Inst = Inst{ .tag = .@"unreachable" },
9294
9395 positionals: struct {},
9496 kw_args: struct {},
......@@ -108,6 +110,16 @@ pub const Inst = struct {
108110 instructions: []*Inst,
109111 };
110112 };
113
114 pub const Export = struct {
115 base: Inst = Inst{ .tag = .@"export" },
116
117 positionals: struct {
118 symbol_name: *Inst,
119 value: *Inst,
120 },
121 kw_args: struct {},
122 };
111123};
112124
113125pub const ErrorMsg = struct {
......@@ -319,7 +331,6 @@ fn parseParameterGeneric(ctx: *ParseContext, comptime T: type, body_ctx: ?*BodyC
319331 while (ctx.i < ctx.source.len) : (ctx.i += 1) switch (ctx.source[ctx.i]) {
320332 ' ', '\n', ',', ')' => {
321333 const enum_name = ctx.source[start..ctx.i];
322 ctx.i += 1;
323334 return std.meta.stringToEnum(T, enum_name) orelse {
324335 return parseError(ctx, "tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) });
325336 };
......@@ -427,6 +438,10 @@ fn parseBody(ctx: *ParseContext) !Inst.Fn.Body {
427438 continue;
428439 },
429440 ' ', '\n' => continue,
441 '}' => {
442 ctx.i += 1;
443 break;
444 },
430445 else => |byte| return parseError(ctx, "unexpected byte: '{c}'", .{byte}),
431446 };
432447