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 {...@@ -17,6 +17,7 @@ pub const Inst = struct {
17 @"asm",17 @"asm",
18 @"unreachable",18 @"unreachable",
19 @"fn",19 @"fn",
20 @"export",
20 };21 };
2122
22 pub fn TagToType(tag: Tag) type {23 pub fn TagToType(tag: Tag) type {
...@@ -26,8 +27,9 @@ pub const Inst = struct {...@@ -26,8 +27,9 @@ pub const Inst = struct {
26 .fieldptr => FieldPtr,27 .fieldptr => FieldPtr,
27 .deref => Deref,28 .deref => Deref,
28 .@"asm" => Assembly,29 .@"asm" => Assembly,
29 .@"unreachable" => Unreach,30 .@"unreachable" => Unreachable,
30 .@"fn" => Fn,31 .@"fn" => Fn,
32 .@"export" => Export,
31 };33 };
32 }34 }
3335
...@@ -87,8 +89,8 @@ pub const Inst = struct {...@@ -87,8 +89,8 @@ pub const Inst = struct {
87 },89 },
88 };90 };
8991
90 pub const Unreach = struct {92 pub const Unreachable = struct {
91 base: Inst = Inst{ .tag = .unreach },93 base: Inst = Inst{ .tag = .@"unreachable" },
9294
93 positionals: struct {},95 positionals: struct {},
94 kw_args: struct {},96 kw_args: struct {},
...@@ -108,6 +110,16 @@ pub const Inst = struct {...@@ -108,6 +110,16 @@ pub const Inst = struct {
108 instructions: []*Inst,110 instructions: []*Inst,
109 };111 };
110 };112 };
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 };
111};123};
112124
113pub const ErrorMsg = struct {125pub const ErrorMsg = struct {
...@@ -319,7 +331,6 @@ fn parseParameterGeneric(ctx: *ParseContext, comptime T: type, body_ctx: ?*BodyC...@@ -319,7 +331,6 @@ fn parseParameterGeneric(ctx: *ParseContext, comptime T: type, body_ctx: ?*BodyC
319 while (ctx.i < ctx.source.len) : (ctx.i += 1) switch (ctx.source[ctx.i]) {331 while (ctx.i < ctx.source.len) : (ctx.i += 1) switch (ctx.source[ctx.i]) {
320 ' ', '\n', ',', ')' => {332 ' ', '\n', ',', ')' => {
321 const enum_name = ctx.source[start..ctx.i];333 const enum_name = ctx.source[start..ctx.i];
322 ctx.i += 1;
323 return std.meta.stringToEnum(T, enum_name) orelse {334 return std.meta.stringToEnum(T, enum_name) orelse {
324 return parseError(ctx, "tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) });335 return parseError(ctx, "tag '{}' not a member of enum '{}'", .{ enum_name, @typeName(T) });
325 };336 };
...@@ -427,6 +438,10 @@ fn parseBody(ctx: *ParseContext) !Inst.Fn.Body {...@@ -427,6 +438,10 @@ fn parseBody(ctx: *ParseContext) !Inst.Fn.Body {
427 continue;438 continue;
428 },439 },
429 ' ', '\n' => continue,440 ' ', '\n' => continue,
441 '}' => {
442 ctx.i += 1;
443 break;
444 },
430 else => |byte| return parseError(ctx, "unexpected byte: '{c}'", .{byte}),445 else => |byte| return parseError(ctx, "unexpected byte: '{c}'", .{byte}),
431 };446 };
432447