authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-08-17 01:38:22+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-09-20 02:29:03+02:00
log7da9fa6fe2e982d10ebc9c3844d1249a4eb1d514
tree73599545ff9e5a93799c33ad5e7ac04f99718a2a
parentccc7f9987debd2112d1432f7aa58a81a0814e81d

Address spaces: AstGen

Adds AST generation for address spaces on pointers, function prototypes, function declarations and variable declarations. In the latter two cases, declaration properties were already stored more efficiently in a declaration structure. To accomodate these for address spaces, the bit indicating presence of a linksection attribute has been extended to include either linksection, address space, or both.

7 files changed, 137 insertions(+), 25 deletions(-)

lib/std/builtin.zig+6
......@@ -166,6 +166,12 @@ pub const CallingConvention = enum {
166166 SysV,
167167};
168168
169/// This data structure is used by the Zig language code generation and
170/// therefore must be kept in sync with the compiler implementation.
171pub const AddressSpace = enum {
172 generic,
173};
174
169175/// This data structure is used by the Zig language code generation and
170176/// therefore must be kept in sync with the compiler implementation.
171177pub const SourceLocation = struct {
src/AstGen.zig+43-7
......@@ -1116,6 +1116,11 @@ fn fnProtoExpr(
11161116 const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: {
11171117 break :inst try expr(gz, scope, align_rl, fn_proto.ast.align_expr);
11181118 };
1119
1120 const addrspace_inst: Zir.Inst.Ref = if (fn_proto.ast.addrspace_expr == 0) .none else inst: {
1121 break :inst try expr(gz, scope, .{ .ty = .address_space_type }, fn_proto.ast.addrspace_expr);
1122 };
1123
11191124 if (fn_proto.ast.section_expr != 0) {
11201125 return astgen.failNode(fn_proto.ast.section_expr, "linksection not allowed on function prototypes", .{});
11211126 }
......@@ -1148,6 +1153,7 @@ fn fnProtoExpr(
11481153 .body = &[0]Zir.Inst.Index{},
11491154 .cc = cc,
11501155 .align_inst = align_inst,
1156 .addrspace_inst = addrspace_inst,
11511157 .lib_name = 0,
11521158 .is_var_args = is_var_args,
11531159 .is_inferred_error = false,
......@@ -2714,6 +2720,7 @@ fn ptrType(
27142720 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
27152721
27162722 const simple = ptr_info.ast.align_node == 0 and
2723 ptr_info.ast.addrspace_node == 0 and
27172724 ptr_info.ast.sentinel == 0 and
27182725 ptr_info.ast.bit_range_start == 0;
27192726
......@@ -2732,6 +2739,7 @@ fn ptrType(
27322739
27332740 var sentinel_ref: Zir.Inst.Ref = .none;
27342741 var align_ref: Zir.Inst.Ref = .none;
2742 var addrspace_ref: Zir.Inst.Ref = .none;
27352743 var bit_start_ref: Zir.Inst.Ref = .none;
27362744 var bit_end_ref: Zir.Inst.Ref = .none;
27372745 var trailing_count: u32 = 0;
......@@ -2744,6 +2752,10 @@ fn ptrType(
27442752 align_ref = try expr(gz, scope, align_rl, ptr_info.ast.align_node);
27452753 trailing_count += 1;
27462754 }
2755 if (ptr_info.ast.addrspace_node != 0) {
2756 addrspace_ref = try expr(gz, scope, .{ .ty = .address_space_type }, ptr_info.ast.addrspace_node);
2757 trailing_count += 1;
2758 }
27472759 if (ptr_info.ast.bit_range_start != 0) {
27482760 assert(ptr_info.ast.bit_range_end != 0);
27492761 bit_start_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_start);
......@@ -2764,6 +2776,9 @@ fn ptrType(
27642776 if (align_ref != .none) {
27652777 gz.astgen.extra.appendAssumeCapacity(@enumToInt(align_ref));
27662778 }
2779 if (addrspace_ref != .none) {
2780 gz.astgen.extra.appendAssumeCapacity(@enumToInt(addrspace_ref));
2781 }
27672782 if (bit_start_ref != .none) {
27682783 gz.astgen.extra.appendAssumeCapacity(@enumToInt(bit_start_ref));
27692784 gz.astgen.extra.appendAssumeCapacity(@enumToInt(bit_end_ref));
......@@ -2779,6 +2794,7 @@ fn ptrType(
27792794 .is_volatile = ptr_info.volatile_token != null,
27802795 .has_sentinel = sentinel_ref != .none,
27812796 .has_align = align_ref != .none,
2797 .has_addrspace = addrspace_ref != .none,
27822798 .has_bit_range = bit_start_ref != .none,
27832799 },
27842800 .size = ptr_info.size,
......@@ -2847,7 +2863,7 @@ const WipDecls = struct {
28472863 is_pub: bool,
28482864 is_export: bool,
28492865 has_align: bool,
2850 has_section: bool,
2866 has_section_or_addrspace: bool,
28512867 ) Allocator.Error!void {
28522868 if (wip_decls.decl_index % fields_per_u32 == 0 and wip_decls.decl_index != 0) {
28532869 try wip_decls.bit_bag.append(gpa, wip_decls.cur_bit_bag);
......@@ -2857,7 +2873,7 @@ const WipDecls = struct {
28572873 (@as(u32, @boolToInt(is_pub)) << 28) |
28582874 (@as(u32, @boolToInt(is_export)) << 29) |
28592875 (@as(u32, @boolToInt(has_align)) << 30) |
2860 (@as(u32, @boolToInt(has_section)) << 31);
2876 (@as(u32, @boolToInt(has_section_or_addrspace)) << 31);
28612877 wip_decls.decl_index += 1;
28622878 }
28632879
......@@ -2922,7 +2938,8 @@ fn fnDecl(
29222938 const maybe_inline_token = fn_proto.extern_export_inline_token orelse break :blk false;
29232939 break :blk token_tags[maybe_inline_token] == .keyword_inline;
29242940 };
2925 try wip_decls.next(gpa, is_pub, is_export, fn_proto.ast.align_expr != 0, fn_proto.ast.section_expr != 0);
2941 const has_section_or_addrspace = fn_proto.ast.section_expr != 0 or fn_proto.ast.addrspace_expr != 0;
2942 try wip_decls.next(gpa, is_pub, is_export, fn_proto.ast.align_expr != 0, has_section_or_addrspace);
29262943
29272944 var params_scope = &fn_gz.base;
29282945 const is_var_args = is_var_args: {
......@@ -3011,6 +3028,9 @@ fn fnDecl(
30113028 const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: {
30123029 break :inst try expr(&decl_gz, params_scope, align_rl, fn_proto.ast.align_expr);
30133030 };
3031 const addrspace_inst: Zir.Inst.Ref = if (fn_proto.ast.addrspace_expr == 0) .none else inst: {
3032 break :inst try expr(&decl_gz, params_scope, .{ .ty = .address_space_type }, fn_proto.ast.addrspace_expr);
3033 };
30143034 const section_inst: Zir.Inst.Ref = if (fn_proto.ast.section_expr == 0) .none else inst: {
30153035 break :inst try comptimeExpr(&decl_gz, params_scope, .{ .ty = .const_slice_u8_type }, fn_proto.ast.section_expr);
30163036 };
......@@ -3060,6 +3080,7 @@ fn fnDecl(
30603080 .body = &[0]Zir.Inst.Index{},
30613081 .cc = cc,
30623082 .align_inst = .none, // passed in the per-decl data
3083 .addrspace_inst = .none, // passed in the per-decl data
30633084 .lib_name = lib_name,
30643085 .is_var_args = is_var_args,
30653086 .is_inferred_error = false,
......@@ -3099,6 +3120,7 @@ fn fnDecl(
30993120 .body = fn_gz.instructions.items,
31003121 .cc = cc,
31013122 .align_inst = .none, // passed in the per-decl data
3123 .addrspace_inst = .none, // passed in the per-decl data
31023124 .lib_name = lib_name,
31033125 .is_var_args = is_var_args,
31043126 .is_inferred_error = is_inferred_error,
......@@ -3127,8 +3149,10 @@ fn fnDecl(
31273149 if (align_inst != .none) {
31283150 wip_decls.payload.appendAssumeCapacity(@enumToInt(align_inst));
31293151 }
3130 if (section_inst != .none) {
3152
3153 if (has_section_or_addrspace) {
31313154 wip_decls.payload.appendAssumeCapacity(@enumToInt(section_inst));
3155 wip_decls.payload.appendAssumeCapacity(@enumToInt(addrspace_inst));
31323156 }
31333157}
31343158
......@@ -3175,10 +3199,14 @@ fn globalVarDecl(
31753199 const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node == 0) .none else inst: {
31763200 break :inst try expr(&block_scope, &block_scope.base, align_rl, var_decl.ast.align_node);
31773201 };
3202 const addrspace_inst: Zir.Inst.Ref = if (var_decl.ast.addrspace_node == 0) .none else inst: {
3203 break :inst try expr(&block_scope, &block_scope.base, .{ .ty = .address_space_type }, var_decl.ast.addrspace_node);
3204 };
31783205 const section_inst: Zir.Inst.Ref = if (var_decl.ast.section_node == 0) .none else inst: {
31793206 break :inst try comptimeExpr(&block_scope, &block_scope.base, .{ .ty = .const_slice_u8_type }, var_decl.ast.section_node);
31803207 };
3181 try wip_decls.next(gpa, is_pub, is_export, align_inst != .none, section_inst != .none);
3208 const has_section_or_addrspace = section_inst != .none or addrspace_inst != .none;
3209 try wip_decls.next(gpa, is_pub, is_export, align_inst != .none, has_section_or_addrspace);
31823210
31833211 const is_threadlocal = if (var_decl.threadlocal_token) |tok| blk: {
31843212 if (!is_mutable) {
......@@ -3271,8 +3299,9 @@ fn globalVarDecl(
32713299 if (align_inst != .none) {
32723300 wip_decls.payload.appendAssumeCapacity(@enumToInt(align_inst));
32733301 }
3274 if (section_inst != .none) {
3302 if (has_section_or_addrspace) {
32753303 wip_decls.payload.appendAssumeCapacity(@enumToInt(section_inst));
3304 wip_decls.payload.appendAssumeCapacity(@enumToInt(addrspace_inst));
32763305 }
32773306}
32783307
......@@ -3443,6 +3472,7 @@ fn testDecl(
34433472 .body = fn_block.instructions.items,
34443473 .cc = .none,
34453474 .align_inst = .none,
3475 .addrspace_inst = .none,
34463476 .lib_name = 0,
34473477 .is_var_args = false,
34483478 .is_inferred_error = true,
......@@ -9178,6 +9208,7 @@ const GenZir = struct {
91789208 ret_br: Zir.Inst.Index,
91799209 cc: Zir.Inst.Ref,
91809210 align_inst: Zir.Inst.Ref,
9211 addrspace_inst: Zir.Inst.Ref,
91819212 lib_name: u32,
91829213 is_var_args: bool,
91839214 is_inferred_error: bool,
......@@ -9221,7 +9252,7 @@ const GenZir = struct {
92219252
92229253 if (args.cc != .none or args.lib_name != 0 or
92239254 args.is_var_args or args.is_test or args.align_inst != .none or
9224 args.is_extern)
9255 args.addrspace_inst != .none or args.is_extern)
92259256 {
92269257 try astgen.extra.ensureUnusedCapacity(
92279258 gpa,
......@@ -9229,6 +9260,7 @@ const GenZir = struct {
92299260 args.ret_ty.len + args.body.len + src_locs.len +
92309261 @boolToInt(args.lib_name != 0) +
92319262 @boolToInt(args.align_inst != .none) +
9263 @boolToInt(args.addrspace_inst != .none) +
92329264 @boolToInt(args.cc != .none),
92339265 );
92349266 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.ExtendedFunc{
......@@ -9246,6 +9278,9 @@ const GenZir = struct {
92469278 if (args.align_inst != .none) {
92479279 astgen.extra.appendAssumeCapacity(@enumToInt(args.align_inst));
92489280 }
9281 if (args.addrspace_inst != .none) {
9282 astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_inst));
9283 }
92499284 astgen.extra.appendSliceAssumeCapacity(args.ret_ty);
92509285 astgen.extra.appendSliceAssumeCapacity(args.body);
92519286 astgen.extra.appendSliceAssumeCapacity(src_locs);
......@@ -9264,6 +9299,7 @@ const GenZir = struct {
92649299 .has_lib_name = args.lib_name != 0,
92659300 .has_cc = args.cc != .none,
92669301 .has_align = args.align_inst != .none,
9302 .has_addrspace = args.addrspace_inst != .none,
92679303 .is_test = args.is_test,
92689304 .is_extern = args.is_extern,
92699305 }),
src/Sema.zig+3
......@@ -10200,6 +10200,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
1020010200 .atomic_order => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrder"),
1020110201 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"),
1020210202 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"),
10203 .address_space => return sema.resolveBuiltinTypeFields(block, src, "AddressSpace"),
1020310204 .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"),
1020410205 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"),
1020510206 .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"),
......@@ -10594,6 +10595,7 @@ fn typeHasOnePossibleValue(
1059410595 .atomic_order,
1059510596 .atomic_rmw_op,
1059610597 .calling_convention,
10598 .address_space,
1059710599 .float_mode,
1059810600 .reduce_op,
1059910601 .call_options,
......@@ -10779,6 +10781,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
1077910781 .atomic_order => return .atomic_order_type,
1078010782 .atomic_rmw_op => return .atomic_rmw_op_type,
1078110783 .calling_convention => return .calling_convention_type,
10784 .address_space => return .address_space_type,
1078210785 .float_mode => return .float_mode_type,
1078310786 .reduce_op => return .reduce_op_type,
1078410787 .call_options => return .call_options_type,
src/Zir.zig+59-18
......@@ -488,10 +488,10 @@ pub const Inst = struct {
488488 /// this instruction; a following 'ret' instruction will do the diversion.
489489 /// Uses the `str_tok` union field.
490490 ret_err_value_code,
491 /// Create a pointer type that does not have a sentinel, alignment, or bit range specified.
491 /// Create a pointer type that does not have a sentinel, alignment, address space, or bit range specified.
492492 /// Uses the `ptr_type_simple` union field.
493493 ptr_type_simple,
494 /// Create a pointer type which can have a sentinel, alignment, and/or bit range.
494 /// Create a pointer type which can have a sentinel, alignment, address space, and/or bit range.
495495 /// Uses the `ptr_type` union field.
496496 ptr_type,
497497 /// Slice operation `lhs[rhs..]`. No sentinel and no end offset.
......@@ -1717,6 +1717,7 @@ pub const Inst = struct {
17171717 atomic_order_type,
17181718 atomic_rmw_op_type,
17191719 calling_convention_type,
1720 address_space_type,
17201721 float_mode_type,
17211722 reduce_op_type,
17221723 call_options_type,
......@@ -1973,6 +1974,10 @@ pub const Inst = struct {
19731974 .ty = Type.initTag(.type),
19741975 .val = Value.initTag(.calling_convention_type),
19751976 },
1977 .address_space_type = .{
1978 .ty = Type.initTag(.type),
1979 .val = Value.initTag(.address_space_type),
1980 },
19761981 .float_mode_type = .{
19771982 .ty = Type.initTag(.type),
19781983 .val = Value.initTag(.float_mode_type),
......@@ -2174,8 +2179,9 @@ pub const Inst = struct {
21742179 is_volatile: bool,
21752180 has_sentinel: bool,
21762181 has_align: bool,
2182 has_addrspace: bool,
21772183 has_bit_range: bool,
2178 _: u2 = undefined,
2184 _: u1 = undefined,
21792185 },
21802186 size: std.builtin.TypeInfo.Pointer.Size,
21812187 /// Index into extra. See `PtrType`.
......@@ -2303,6 +2309,7 @@ pub const Inst = struct {
23032309 /// 0. lib_name: u32, // null terminated string index, if has_lib_name is set
23042310 /// 1. cc: Ref, // if has_cc is set
23052311 /// 2. align: Ref, // if has_align is set
2312 /// 3. addrspace: Ref, // if has_addrspace is set
23062313 /// 3. return_type: Index // for each ret_body_len
23072314 /// 4. body: Index // for each body_len
23082315 /// 5. src_locs: Func.SrcLocs // if body_len != 0
......@@ -2320,9 +2327,10 @@ pub const Inst = struct {
23202327 has_lib_name: bool,
23212328 has_cc: bool,
23222329 has_align: bool,
2330 has_addrspace: bool,
23232331 is_test: bool,
23242332 is_extern: bool,
2325 _: u9 = undefined,
2333 _: u8 = undefined,
23262334 };
23272335 };
23282336
......@@ -2405,12 +2413,13 @@ pub const Inst = struct {
24052413 else_body_len: u32,
24062414 };
24072415
2408 /// Stored in extra. Depending on the flags in Data, there will be up to 4
2416 /// Stored in extra. Depending on the flags in Data, there will be up to 5
24092417 /// trailing Ref fields:
24102418 /// 0. sentinel: Ref // if `has_sentinel` flag is set
24112419 /// 1. align: Ref // if `has_align` flag is set
2412 /// 2. bit_start: Ref // if `has_bit_range` flag is set
2413 /// 3. bit_end: Ref // if `has_bit_range` flag is set
2420 /// 2. address_space: Ref // if `has_addrspace` flag is set
2421 /// 3. bit_start: Ref // if `has_bit_range` flag is set
2422 /// 4. bit_end: Ref // if `has_bit_range` flag is set
24142423 pub const PtrType = struct {
24152424 elem_type: Ref,
24162425 };
......@@ -2528,7 +2537,7 @@ pub const Inst = struct {
25282537 /// 0b000X: whether corresponding decl is pub
25292538 /// 0b00X0: whether corresponding decl is exported
25302539 /// 0b0X00: whether corresponding decl has an align expression
2531 /// 0bX000: whether corresponding decl has a linksection expression
2540 /// 0bX000: whether corresponding decl has a linksection or an address space expression
25322541 /// 5. decl: { // for every decls_len
25332542 /// src_hash: [4]u32, // hash of source bytes
25342543 /// line: u32, // line number of decl, relative to parent
......@@ -2540,7 +2549,10 @@ pub const Inst = struct {
25402549 /// this is a test decl, and the name starts at `name+1`.
25412550 /// value: Index,
25422551 /// align: Ref, // if corresponding bit is set
2543 /// link_section: Ref, // if corresponding bit is set
2552 /// link_section_or_address_space: { // if corresponding bit is set.
2553 /// link_section: Ref,
2554 /// address_space: Ref,
2555 /// }
25442556 /// }
25452557 /// 6. inst: Index // for every body_len
25462558 /// 7. flags: u32 // for every 8 fields
......@@ -2592,7 +2604,7 @@ pub const Inst = struct {
25922604 /// 0b000X: whether corresponding decl is pub
25932605 /// 0b00X0: whether corresponding decl is exported
25942606 /// 0b0X00: whether corresponding decl has an align expression
2595 /// 0bX000: whether corresponding decl has a linksection expression
2607 /// 0bX000: whether corresponding decl has a linksection or an address space expression
25962608 /// 6. decl: { // for every decls_len
25972609 /// src_hash: [4]u32, // hash of source bytes
25982610 /// line: u32, // line number of decl, relative to parent
......@@ -2604,7 +2616,10 @@ pub const Inst = struct {
26042616 /// this is a test decl, and the name starts at `name+1`.
26052617 /// value: Index,
26062618 /// align: Ref, // if corresponding bit is set
2607 /// link_section: Ref, // if corresponding bit is set
2619 /// link_section_or_address_space: { // if corresponding bit is set.
2620 /// link_section: Ref,
2621 /// address_space: Ref,
2622 /// }
26082623 /// }
26092624 /// 7. inst: Index // for every body_len
26102625 /// 8. has_bits: u32 // for every 32 fields
......@@ -2637,7 +2652,7 @@ pub const Inst = struct {
26372652 /// 0b000X: whether corresponding decl is pub
26382653 /// 0b00X0: whether corresponding decl is exported
26392654 /// 0b0X00: whether corresponding decl has an align expression
2640 /// 0bX000: whether corresponding decl has a linksection expression
2655 /// 0bX000: whether corresponding decl has a linksection or an address space expression
26412656 /// 6. decl: { // for every decls_len
26422657 /// src_hash: [4]u32, // hash of source bytes
26432658 /// line: u32, // line number of decl, relative to parent
......@@ -2649,7 +2664,10 @@ pub const Inst = struct {
26492664 /// this is a test decl, and the name starts at `name+1`.
26502665 /// value: Index,
26512666 /// align: Ref, // if corresponding bit is set
2652 /// link_section: Ref, // if corresponding bit is set
2667 /// link_section_or_address_space: { // if corresponding bit is set.
2668 /// link_section: Ref,
2669 /// address_space: Ref,
2670 /// }
26532671 /// }
26542672 /// 7. inst: Index // for every body_len
26552673 /// 8. has_bits: u32 // for every 8 fields
......@@ -2686,7 +2704,7 @@ pub const Inst = struct {
26862704 /// 0b000X: whether corresponding decl is pub
26872705 /// 0b00X0: whether corresponding decl is exported
26882706 /// 0b0X00: whether corresponding decl has an align expression
2689 /// 0bX000: whether corresponding decl has a linksection expression
2707 /// 0bX000: whether corresponding decl has a linksection or an address space expression
26902708 /// 1. decl: { // for every decls_len
26912709 /// src_hash: [4]u32, // hash of source bytes
26922710 /// line: u32, // line number of decl, relative to parent
......@@ -2698,7 +2716,10 @@ pub const Inst = struct {
26982716 /// this is a test decl, and the name starts at `name+1`.
26992717 /// value: Index,
27002718 /// align: Ref, // if corresponding bit is set
2701 /// link_section: Ref, // if corresponding bit is set
2719 /// link_section_or_address_space: { // if corresponding bit is set.
2720 /// link_section: Ref,
2721 /// address_space: Ref,
2722 /// }
27022723 /// }
27032724 pub const OpaqueDecl = struct {
27042725 decls_len: u32,
......@@ -3983,7 +4004,7 @@ const Writer = struct {
39834004 cur_bit_bag >>= 1;
39844005 const has_align = @truncate(u1, cur_bit_bag) != 0;
39854006 cur_bit_bag >>= 1;
3986 const has_section = @truncate(u1, cur_bit_bag) != 0;
4007 const has_section_or_addrspace = @truncate(u1, cur_bit_bag) != 0;
39874008 cur_bit_bag >>= 1;
39884009
39894010 const sub_index = extra_index;
......@@ -4001,12 +4022,16 @@ const Writer = struct {
40014022 extra_index += 1;
40024023 break :inst inst;
40034024 };
4004 const section_inst: Inst.Ref = if (!has_section) .none else inst: {
4025 const section_inst: Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
40054026 const inst = @intToEnum(Inst.Ref, self.code.extra[extra_index]);
40064027 extra_index += 1;
40074028 break :inst inst;
40084029 };
4009
4030 const addrspace_inst: Inst.Ref = if (!has_section_or_addrspace) .none else inst: {
4031 const inst = @intToEnum(Inst.Ref, self.code.extra[extra_index]);
4032 extra_index +=1;
4033 break :inst inst;
4034 };
40104035 const pub_str = if (is_pub) "pub " else "";
40114036 const hash_bytes = @bitCast([16]u8, hash_u32s.*);
40124037 try stream.writeByteNTimes(' ', self.indent);
......@@ -4032,6 +4057,11 @@ const Writer = struct {
40324057 try self.writeInstRef(stream, align_inst);
40334058 try stream.writeAll(")");
40344059 }
4060 if (addrspace_inst != .none) {
4061 try stream.writeAll(" addrspace(");
4062 try self.writeInstRef(stream, addrspace_inst);
4063 try stream.writeAll(")");
4064 }
40354065 if (section_inst != .none) {
40364066 try stream.writeAll(" linksection(");
40374067 try self.writeInstRef(stream, section_inst);
......@@ -4453,6 +4483,7 @@ const Writer = struct {
44534483 false,
44544484 .none,
44554485 .none,
4486 .none,
44564487 body,
44574488 src,
44584489 src_locs,
......@@ -4481,6 +4512,11 @@ const Writer = struct {
44814512 extra_index += 1;
44824513 break :blk align_inst;
44834514 };
4515 const addrspace_inst: Inst.Ref = if (!small.has_addrspace) .none else blk: {
4516 const addrspace_inst = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]);
4517 extra_index += 1;
4518 break :blk addrspace_inst;
4519 };
44844520
44854521 const ret_ty_body = self.code.extra[extra_index..][0..extra.data.ret_body_len];
44864522 extra_index += ret_ty_body.len;
......@@ -4500,6 +4536,7 @@ const Writer = struct {
45004536 small.is_extern,
45014537 cc,
45024538 align_inst,
4539 addrspace_inst,
45034540 body,
45044541 src,
45054542 src_locs,
......@@ -4582,6 +4619,7 @@ const Writer = struct {
45824619 is_extern: bool,
45834620 cc: Inst.Ref,
45844621 align_inst: Inst.Ref,
4622 addrspace_inst: Inst.Ref,
45854623 body: []const Inst.Index,
45864624 src: LazySrcLoc,
45874625 src_locs: Zir.Inst.Func.SrcLocs,
......@@ -4599,6 +4637,7 @@ const Writer = struct {
45994637
46004638 try self.writeOptionalInstRef(stream, ", cc=", cc);
46014639 try self.writeOptionalInstRef(stream, ", align=", align_inst);
4640 try self.writeOptionalInstRef(stream, ", addrspace=", addrspace_inst);
46024641 try self.writeFlag(stream, ", vargs", var_args);
46034642 try self.writeFlag(stream, ", extern", is_extern);
46044643 try self.writeFlag(stream, ", inferror", inferred_error_set);
......@@ -4876,6 +4915,7 @@ fn findDeclsInner(
48764915 extra_index += @boolToInt(small.has_lib_name);
48774916 extra_index += @boolToInt(small.has_cc);
48784917 extra_index += @boolToInt(small.has_align);
4918 extra_index += @boolToInt(small.has_addrspace);
48794919 const body = zir.extra[extra_index..][0..extra.data.body_len];
48804920 return zir.findDeclsBody(list, body);
48814921 },
......@@ -5079,6 +5119,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
50795119 extra_index += @boolToInt(small.has_lib_name);
50805120 extra_index += @boolToInt(small.has_cc);
50815121 extra_index += @boolToInt(small.has_align);
5122 extra_index += @boolToInt(small.has_addrspace);
50825123 const ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len];
50835124 extra_index += ret_ty_body.len;
50845125 const body = zir.extra[extra_index..][0..extra.data.body_len];
src/translate_c/ast.zig+2
......@@ -2706,6 +2706,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
27062706 .lhs = try c.addExtra(std.zig.Ast.Node.FnProtoOne{
27072707 .param = params.items[0],
27082708 .align_expr = align_expr,
2709 .addrspace_expr = 0, // TODO
27092710 .section_expr = section_expr,
27102711 .callconv_expr = callconv_expr,
27112712 }),
......@@ -2721,6 +2722,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
27212722 .params_start = span.start,
27222723 .params_end = span.end,
27232724 .align_expr = align_expr,
2725 .addrspace_expr = 0, // TODO
27242726 .section_expr = section_expr,
27252727 .callconv_expr = callconv_expr,
27262728 }),
src/type.zig+19
......@@ -127,6 +127,7 @@ pub const Type = extern union {
127127 .atomic_order,
128128 .atomic_rmw_op,
129129 .calling_convention,
130 .address_space,
130131 .float_mode,
131132 .reduce_op,
132133 => return .Enum,
......@@ -746,6 +747,7 @@ pub const Type = extern union {
746747 .atomic_order,
747748 .atomic_rmw_op,
748749 .calling_convention,
750 .address_space,
749751 .float_mode,
750752 .reduce_op,
751753 .call_options,
......@@ -958,6 +960,7 @@ pub const Type = extern union {
958960 .atomic_order => return writer.writeAll("std.builtin.AtomicOrder"),
959961 .atomic_rmw_op => return writer.writeAll("std.builtin.AtomicRmwOp"),
960962 .calling_convention => return writer.writeAll("std.builtin.CallingConvention"),
963 .address_space => return writer.writeAll("std.builtin.AddressSpace"),
961964 .float_mode => return writer.writeAll("std.builtin.FloatMode"),
962965 .reduce_op => return writer.writeAll("std.builtin.ReduceOp"),
963966 .call_options => return writer.writeAll("std.builtin.CallOptions"),
......@@ -1186,6 +1189,7 @@ pub const Type = extern union {
11861189 .atomic_order,
11871190 .atomic_rmw_op,
11881191 .calling_convention,
1192 .address_space,
11891193 .float_mode,
11901194 .reduce_op,
11911195 .call_options,
......@@ -1301,6 +1305,7 @@ pub const Type = extern union {
13011305 .atomic_order => return Value.initTag(.atomic_order_type),
13021306 .atomic_rmw_op => return Value.initTag(.atomic_rmw_op_type),
13031307 .calling_convention => return Value.initTag(.calling_convention_type),
1308 .address_space => return Value.initTag(.address_space_type),
13041309 .float_mode => return Value.initTag(.float_mode_type),
13051310 .reduce_op => return Value.initTag(.reduce_op_type),
13061311 .call_options => return Value.initTag(.call_options_type),
......@@ -1362,6 +1367,7 @@ pub const Type = extern union {
13621367 .atomic_order,
13631368 .atomic_rmw_op,
13641369 .calling_convention,
1370 .address_space,
13651371 .float_mode,
13661372 .reduce_op,
13671373 .call_options,
......@@ -1508,6 +1514,7 @@ pub const Type = extern union {
15081514 .atomic_order,
15091515 .atomic_rmw_op,
15101516 .calling_convention,
1517 .address_space,
15111518 .float_mode,
15121519 .reduce_op,
15131520 .call_options,
......@@ -1734,6 +1741,7 @@ pub const Type = extern union {
17341741 .atomic_order,
17351742 .atomic_rmw_op,
17361743 .calling_convention,
1744 .address_space,
17371745 .float_mode,
17381746 .reduce_op,
17391747 .call_options,
......@@ -2018,6 +2026,7 @@ pub const Type = extern union {
20182026 .atomic_order,
20192027 .atomic_rmw_op,
20202028 .calling_convention,
2029 .address_space,
20212030 .float_mode,
20222031 .reduce_op,
20232032 .call_options,
......@@ -2775,6 +2784,7 @@ pub const Type = extern union {
27752784 .atomic_order,
27762785 .atomic_rmw_op,
27772786 .calling_convention,
2787 .address_space,
27782788 .float_mode,
27792789 .reduce_op,
27802790 .call_options,
......@@ -2982,6 +2992,7 @@ pub const Type = extern union {
29822992 .atomic_order,
29832993 .atomic_rmw_op,
29842994 .calling_convention,
2995 .address_space,
29852996 .float_mode,
29862997 .reduce_op,
29872998 .call_options,
......@@ -3006,6 +3017,7 @@ pub const Type = extern union {
30063017 .atomic_order,
30073018 .atomic_rmw_op,
30083019 .calling_convention,
3020 .address_space,
30093021 .float_mode,
30103022 .reduce_op,
30113023 .call_options,
......@@ -3029,6 +3041,7 @@ pub const Type = extern union {
30293041 .atomic_order,
30303042 .atomic_rmw_op,
30313043 .calling_convention,
3044 .address_space,
30323045 .float_mode,
30333046 .reduce_op,
30343047 .call_options,
......@@ -3082,6 +3095,7 @@ pub const Type = extern union {
30823095 .atomic_order,
30833096 .atomic_rmw_op,
30843097 .calling_convention,
3098 .address_space,
30853099 .float_mode,
30863100 .reduce_op,
30873101 .call_options,
......@@ -3137,6 +3151,7 @@ pub const Type = extern union {
31373151 .atomic_order,
31383152 .atomic_rmw_op,
31393153 .calling_convention,
3154 .address_space,
31403155 .float_mode,
31413156 .reduce_op,
31423157 .call_options,
......@@ -3174,6 +3189,7 @@ pub const Type = extern union {
31743189 .atomic_order,
31753190 .atomic_rmw_op,
31763191 .calling_convention,
3192 .address_space,
31773193 .float_mode,
31783194 .reduce_op,
31793195 .call_options,
......@@ -3224,6 +3240,7 @@ pub const Type = extern union {
32243240 .atomic_order,
32253241 .atomic_rmw_op,
32263242 .calling_convention,
3243 .address_space,
32273244 .float_mode,
32283245 .reduce_op,
32293246 .call_options,
......@@ -3284,6 +3301,7 @@ pub const Type = extern union {
32843301 atomic_order,
32853302 atomic_rmw_op,
32863303 calling_convention,
3304 address_space,
32873305 float_mode,
32883306 reduce_op,
32893307 call_options,
......@@ -3407,6 +3425,7 @@ pub const Type = extern union {
34073425 .atomic_order,
34083426 .atomic_rmw_op,
34093427 .calling_convention,
3428 .address_space,
34103429 .float_mode,
34113430 .reduce_op,
34123431 .call_options,
src/value.zig+5
......@@ -63,6 +63,7 @@ pub const Value = extern union {
6363 atomic_order_type,
6464 atomic_rmw_op_type,
6565 calling_convention_type,
66 address_space_type,
6667 float_mode_type,
6768 reduce_op_type,
6869 call_options_type,
......@@ -226,6 +227,7 @@ pub const Value = extern union {
226227 .atomic_order_type,
227228 .atomic_rmw_op_type,
228229 .calling_convention_type,
230 .address_space_type,
229231 .float_mode_type,
230232 .reduce_op_type,
231233 .call_options_type,
......@@ -412,6 +414,7 @@ pub const Value = extern union {
412414 .atomic_order_type,
413415 .atomic_rmw_op_type,
414416 .calling_convention_type,
417 .address_space_type,
415418 .float_mode_type,
416419 .reduce_op_type,
417420 .call_options_type,
......@@ -625,6 +628,7 @@ pub const Value = extern union {
625628 .atomic_order_type => return out_stream.writeAll("std.builtin.AtomicOrder"),
626629 .atomic_rmw_op_type => return out_stream.writeAll("std.builtin.AtomicRmwOp"),
627630 .calling_convention_type => return out_stream.writeAll("std.builtin.CallingConvention"),
631 .address_space_type => return out_stream.writeAll("std.builtin.AddressSpace"),
628632 .float_mode_type => return out_stream.writeAll("std.builtin.FloatMode"),
629633 .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"),
630634 .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"),
......@@ -792,6 +796,7 @@ pub const Value = extern union {
792796 .atomic_order_type => Type.initTag(.atomic_order),
793797 .atomic_rmw_op_type => Type.initTag(.atomic_rmw_op),
794798 .calling_convention_type => Type.initTag(.calling_convention),
799 .address_space_type => Type.initTag(.address_space),
795800 .float_mode_type => Type.initTag(.float_mode),
796801 .reduce_op_type => Type.initTag(.reduce_op),
797802 .call_options_type => Type.initTag(.call_options),