aboutsummaryrefslogtreecommitdiff
path: root/src/astgen.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2021-02-08 11:07:44 +0200
committerVeikka Tuominen <git@vexu.eu>2021-02-16 16:40:02 +0200
commitbb867b071a9e2fa69f39a45532dffa0f51ffdbfd (patch)
tree493ab077cfcf1501a2fa17692b83178f74eb6489 /src/astgen.zig
parentf36849fed24b54476ecadacb52d9a1b55ae14274 (diff)
downloadzig-bb867b071a9e2fa69f39a45532dffa0f51ffdbfd.tar.gz
zig-bb867b071a9e2fa69f39a45532dffa0f51ffdbfd.zip
translate-c: convert vardecl and typedef
Diffstat (limited to 'src/astgen.zig')
-rw-r--r--src/astgen.zig70
1 files changed, 32 insertions, 38 deletions
diff --git a/src/astgen.zig b/src/astgen.zig
index 56d1497f63..dd600e2840 100644
--- a/src/astgen.zig
+++ b/src/astgen.zig
@@ -2664,8 +2664,11 @@ fn identifier(
return mod.failNode(scope, ident, "TODO implement '_' identifier", .{});
}
- if (getSimplePrimitiveValue(ident_name)) |typed_value| {
- const result = try addZIRInstConst(mod, scope, src, typed_value);
+ if (simple_types.get(ident_name)) |val_tag| {
+ const result = try addZIRInstConst(mod, scope, src, TypedValue{
+ .ty = Type.initTag(.type),
+ .val = Value.initTag(val_tag),
+ });
return rvalue(mod, scope, rl, result);
}
@@ -3325,42 +3328,33 @@ fn callExpr(
return rvalue(mod, scope, rl, result);
}
-fn getSimplePrimitiveValue(name: []const u8) ?TypedValue {
- const simple_types = std.ComptimeStringMap(Value.Tag, .{
- .{ "u8", .u8_type },
- .{ "i8", .i8_type },
- .{ "isize", .isize_type },
- .{ "usize", .usize_type },
- .{ "c_short", .c_short_type },
- .{ "c_ushort", .c_ushort_type },
- .{ "c_int", .c_int_type },
- .{ "c_uint", .c_uint_type },
- .{ "c_long", .c_long_type },
- .{ "c_ulong", .c_ulong_type },
- .{ "c_longlong", .c_longlong_type },
- .{ "c_ulonglong", .c_ulonglong_type },
- .{ "c_longdouble", .c_longdouble_type },
- .{ "f16", .f16_type },
- .{ "f32", .f32_type },
- .{ "f64", .f64_type },
- .{ "f128", .f128_type },
- .{ "c_void", .c_void_type },
- .{ "bool", .bool_type },
- .{ "void", .void_type },
- .{ "type", .type_type },
- .{ "anyerror", .anyerror_type },
- .{ "comptime_int", .comptime_int_type },
- .{ "comptime_float", .comptime_float_type },
- .{ "noreturn", .noreturn_type },
- });
- if (simple_types.get(name)) |tag| {
- return TypedValue{
- .ty = Type.initTag(.type),
- .val = Value.initTag(tag),
- };
- }
- return null;
-}
+pub const simple_types = std.ComptimeStringMap(Value.Tag, .{
+ .{ "u8", .u8_type },
+ .{ "i8", .i8_type },
+ .{ "isize", .isize_type },
+ .{ "usize", .usize_type },
+ .{ "c_short", .c_short_type },
+ .{ "c_ushort", .c_ushort_type },
+ .{ "c_int", .c_int_type },
+ .{ "c_uint", .c_uint_type },
+ .{ "c_long", .c_long_type },
+ .{ "c_ulong", .c_ulong_type },
+ .{ "c_longlong", .c_longlong_type },
+ .{ "c_ulonglong", .c_ulonglong_type },
+ .{ "c_longdouble", .c_longdouble_type },
+ .{ "f16", .f16_type },
+ .{ "f32", .f32_type },
+ .{ "f64", .f64_type },
+ .{ "f128", .f128_type },
+ .{ "c_void", .c_void_type },
+ .{ "bool", .bool_type },
+ .{ "void", .void_type },
+ .{ "type", .type_type },
+ .{ "anyerror", .anyerror_type },
+ .{ "comptime_int", .comptime_int_type },
+ .{ "comptime_float", .comptime_float_type },
+ .{ "noreturn", .noreturn_type },
+});
fn nodeMayNeedMemoryLocation(start_node: *ast.Node, scope: *Scope) bool {
var node = start_node;