| author | |
| committer | |
| log | 7da9fa6fe2e982d10ebc9c3844d1249a4eb1d514 |
| tree | 73599545ff9e5a93799c33ad5e7ac04f99718a2a |
| parent | ccc7f9987debd2112d1432f7aa58a81a0814e81d |
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 { |
| 166 | 166 | SysV, |
| 167 | 167 | }; |
| 168 | 168 | |
| 169 | /// This data structure is used by the Zig language code generation and | |
| 170 | /// therefore must be kept in sync with the compiler implementation. | |
| 171 | pub const AddressSpace = enum { | |
| 172 | generic, | |
| 173 | }; | |
| 174 | ||
| 169 | 175 | /// This data structure is used by the Zig language code generation and |
| 170 | 176 | /// therefore must be kept in sync with the compiler implementation. |
| 171 | 177 | pub const SourceLocation = struct { |
src/AstGen.zig+43-7| ... | ... | @@ -1116,6 +1116,11 @@ fn fnProtoExpr( |
| 1116 | 1116 | const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: { |
| 1117 | 1117 | break :inst try expr(gz, scope, align_rl, fn_proto.ast.align_expr); |
| 1118 | 1118 | }; |
| 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 | ||
| 1119 | 1124 | if (fn_proto.ast.section_expr != 0) { |
| 1120 | 1125 | return astgen.failNode(fn_proto.ast.section_expr, "linksection not allowed on function prototypes", .{}); |
| 1121 | 1126 | } |
| ... | ... | @@ -1148,6 +1153,7 @@ fn fnProtoExpr( |
| 1148 | 1153 | .body = &[0]Zir.Inst.Index{}, |
| 1149 | 1154 | .cc = cc, |
| 1150 | 1155 | .align_inst = align_inst, |
| 1156 | .addrspace_inst = addrspace_inst, | |
| 1151 | 1157 | .lib_name = 0, |
| 1152 | 1158 | .is_var_args = is_var_args, |
| 1153 | 1159 | .is_inferred_error = false, |
| ... | ... | @@ -2714,6 +2720,7 @@ fn ptrType( |
| 2714 | 2720 | const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type); |
| 2715 | 2721 | |
| 2716 | 2722 | const simple = ptr_info.ast.align_node == 0 and |
| 2723 | ptr_info.ast.addrspace_node == 0 and | |
| 2717 | 2724 | ptr_info.ast.sentinel == 0 and |
| 2718 | 2725 | ptr_info.ast.bit_range_start == 0; |
| 2719 | 2726 | |
| ... | ... | @@ -2732,6 +2739,7 @@ fn ptrType( |
| 2732 | 2739 | |
| 2733 | 2740 | var sentinel_ref: Zir.Inst.Ref = .none; |
| 2734 | 2741 | var align_ref: Zir.Inst.Ref = .none; |
| 2742 | var addrspace_ref: Zir.Inst.Ref = .none; | |
| 2735 | 2743 | var bit_start_ref: Zir.Inst.Ref = .none; |
| 2736 | 2744 | var bit_end_ref: Zir.Inst.Ref = .none; |
| 2737 | 2745 | var trailing_count: u32 = 0; |
| ... | ... | @@ -2744,6 +2752,10 @@ fn ptrType( |
| 2744 | 2752 | align_ref = try expr(gz, scope, align_rl, ptr_info.ast.align_node); |
| 2745 | 2753 | trailing_count += 1; |
| 2746 | 2754 | } |
| 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 | } | |
| 2747 | 2759 | if (ptr_info.ast.bit_range_start != 0) { |
| 2748 | 2760 | assert(ptr_info.ast.bit_range_end != 0); |
| 2749 | 2761 | bit_start_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_start); |
| ... | ... | @@ -2764,6 +2776,9 @@ fn ptrType( |
| 2764 | 2776 | if (align_ref != .none) { |
| 2765 | 2777 | gz.astgen.extra.appendAssumeCapacity(@enumToInt(align_ref)); |
| 2766 | 2778 | } |
| 2779 | if (addrspace_ref != .none) { | |
| 2780 | gz.astgen.extra.appendAssumeCapacity(@enumToInt(addrspace_ref)); | |
| 2781 | } | |
| 2767 | 2782 | if (bit_start_ref != .none) { |
| 2768 | 2783 | gz.astgen.extra.appendAssumeCapacity(@enumToInt(bit_start_ref)); |
| 2769 | 2784 | gz.astgen.extra.appendAssumeCapacity(@enumToInt(bit_end_ref)); |
| ... | ... | @@ -2779,6 +2794,7 @@ fn ptrType( |
| 2779 | 2794 | .is_volatile = ptr_info.volatile_token != null, |
| 2780 | 2795 | .has_sentinel = sentinel_ref != .none, |
| 2781 | 2796 | .has_align = align_ref != .none, |
| 2797 | .has_addrspace = addrspace_ref != .none, | |
| 2782 | 2798 | .has_bit_range = bit_start_ref != .none, |
| 2783 | 2799 | }, |
| 2784 | 2800 | .size = ptr_info.size, |
| ... | ... | @@ -2847,7 +2863,7 @@ const WipDecls = struct { |
| 2847 | 2863 | is_pub: bool, |
| 2848 | 2864 | is_export: bool, |
| 2849 | 2865 | has_align: bool, |
| 2850 | has_section: bool, | |
| 2866 | has_section_or_addrspace: bool, | |
| 2851 | 2867 | ) Allocator.Error!void { |
| 2852 | 2868 | if (wip_decls.decl_index % fields_per_u32 == 0 and wip_decls.decl_index != 0) { |
| 2853 | 2869 | try wip_decls.bit_bag.append(gpa, wip_decls.cur_bit_bag); |
| ... | ... | @@ -2857,7 +2873,7 @@ const WipDecls = struct { |
| 2857 | 2873 | (@as(u32, @boolToInt(is_pub)) << 28) | |
| 2858 | 2874 | (@as(u32, @boolToInt(is_export)) << 29) | |
| 2859 | 2875 | (@as(u32, @boolToInt(has_align)) << 30) | |
| 2860 | (@as(u32, @boolToInt(has_section)) << 31); | |
| 2876 | (@as(u32, @boolToInt(has_section_or_addrspace)) << 31); | |
| 2861 | 2877 | wip_decls.decl_index += 1; |
| 2862 | 2878 | } |
| 2863 | 2879 | |
| ... | ... | @@ -2922,7 +2938,8 @@ fn fnDecl( |
| 2922 | 2938 | const maybe_inline_token = fn_proto.extern_export_inline_token orelse break :blk false; |
| 2923 | 2939 | break :blk token_tags[maybe_inline_token] == .keyword_inline; |
| 2924 | 2940 | }; |
| 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); | |
| 2926 | 2943 | |
| 2927 | 2944 | var params_scope = &fn_gz.base; |
| 2928 | 2945 | const is_var_args = is_var_args: { |
| ... | ... | @@ -3011,6 +3028,9 @@ fn fnDecl( |
| 3011 | 3028 | const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: { |
| 3012 | 3029 | break :inst try expr(&decl_gz, params_scope, align_rl, fn_proto.ast.align_expr); |
| 3013 | 3030 | }; |
| 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 | }; | |
| 3014 | 3034 | const section_inst: Zir.Inst.Ref = if (fn_proto.ast.section_expr == 0) .none else inst: { |
| 3015 | 3035 | break :inst try comptimeExpr(&decl_gz, params_scope, .{ .ty = .const_slice_u8_type }, fn_proto.ast.section_expr); |
| 3016 | 3036 | }; |
| ... | ... | @@ -3060,6 +3080,7 @@ fn fnDecl( |
| 3060 | 3080 | .body = &[0]Zir.Inst.Index{}, |
| 3061 | 3081 | .cc = cc, |
| 3062 | 3082 | .align_inst = .none, // passed in the per-decl data |
| 3083 | .addrspace_inst = .none, // passed in the per-decl data | |
| 3063 | 3084 | .lib_name = lib_name, |
| 3064 | 3085 | .is_var_args = is_var_args, |
| 3065 | 3086 | .is_inferred_error = false, |
| ... | ... | @@ -3099,6 +3120,7 @@ fn fnDecl( |
| 3099 | 3120 | .body = fn_gz.instructions.items, |
| 3100 | 3121 | .cc = cc, |
| 3101 | 3122 | .align_inst = .none, // passed in the per-decl data |
| 3123 | .addrspace_inst = .none, // passed in the per-decl data | |
| 3102 | 3124 | .lib_name = lib_name, |
| 3103 | 3125 | .is_var_args = is_var_args, |
| 3104 | 3126 | .is_inferred_error = is_inferred_error, |
| ... | ... | @@ -3127,8 +3149,10 @@ fn fnDecl( |
| 3127 | 3149 | if (align_inst != .none) { |
| 3128 | 3150 | wip_decls.payload.appendAssumeCapacity(@enumToInt(align_inst)); |
| 3129 | 3151 | } |
| 3130 | if (section_inst != .none) { | |
| 3152 | ||
| 3153 | if (has_section_or_addrspace) { | |
| 3131 | 3154 | wip_decls.payload.appendAssumeCapacity(@enumToInt(section_inst)); |
| 3155 | wip_decls.payload.appendAssumeCapacity(@enumToInt(addrspace_inst)); | |
| 3132 | 3156 | } |
| 3133 | 3157 | } |
| 3134 | 3158 | |
| ... | ... | @@ -3175,10 +3199,14 @@ fn globalVarDecl( |
| 3175 | 3199 | const align_inst: Zir.Inst.Ref = if (var_decl.ast.align_node == 0) .none else inst: { |
| 3176 | 3200 | break :inst try expr(&block_scope, &block_scope.base, align_rl, var_decl.ast.align_node); |
| 3177 | 3201 | }; |
| 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 | }; | |
| 3178 | 3205 | const section_inst: Zir.Inst.Ref = if (var_decl.ast.section_node == 0) .none else inst: { |
| 3179 | 3206 | break :inst try comptimeExpr(&block_scope, &block_scope.base, .{ .ty = .const_slice_u8_type }, var_decl.ast.section_node); |
| 3180 | 3207 | }; |
| 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); | |
| 3182 | 3210 | |
| 3183 | 3211 | const is_threadlocal = if (var_decl.threadlocal_token) |tok| blk: { |
| 3184 | 3212 | if (!is_mutable) { |
| ... | ... | @@ -3271,8 +3299,9 @@ fn globalVarDecl( |
| 3271 | 3299 | if (align_inst != .none) { |
| 3272 | 3300 | wip_decls.payload.appendAssumeCapacity(@enumToInt(align_inst)); |
| 3273 | 3301 | } |
| 3274 | if (section_inst != .none) { | |
| 3302 | if (has_section_or_addrspace) { | |
| 3275 | 3303 | wip_decls.payload.appendAssumeCapacity(@enumToInt(section_inst)); |
| 3304 | wip_decls.payload.appendAssumeCapacity(@enumToInt(addrspace_inst)); | |
| 3276 | 3305 | } |
| 3277 | 3306 | } |
| 3278 | 3307 | |
| ... | ... | @@ -3443,6 +3472,7 @@ fn testDecl( |
| 3443 | 3472 | .body = fn_block.instructions.items, |
| 3444 | 3473 | .cc = .none, |
| 3445 | 3474 | .align_inst = .none, |
| 3475 | .addrspace_inst = .none, | |
| 3446 | 3476 | .lib_name = 0, |
| 3447 | 3477 | .is_var_args = false, |
| 3448 | 3478 | .is_inferred_error = true, |
| ... | ... | @@ -9178,6 +9208,7 @@ const GenZir = struct { |
| 9178 | 9208 | ret_br: Zir.Inst.Index, |
| 9179 | 9209 | cc: Zir.Inst.Ref, |
| 9180 | 9210 | align_inst: Zir.Inst.Ref, |
| 9211 | addrspace_inst: Zir.Inst.Ref, | |
| 9181 | 9212 | lib_name: u32, |
| 9182 | 9213 | is_var_args: bool, |
| 9183 | 9214 | is_inferred_error: bool, |
| ... | ... | @@ -9221,7 +9252,7 @@ const GenZir = struct { |
| 9221 | 9252 | |
| 9222 | 9253 | if (args.cc != .none or args.lib_name != 0 or |
| 9223 | 9254 | 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) | |
| 9225 | 9256 | { |
| 9226 | 9257 | try astgen.extra.ensureUnusedCapacity( |
| 9227 | 9258 | gpa, |
| ... | ... | @@ -9229,6 +9260,7 @@ const GenZir = struct { |
| 9229 | 9260 | args.ret_ty.len + args.body.len + src_locs.len + |
| 9230 | 9261 | @boolToInt(args.lib_name != 0) + |
| 9231 | 9262 | @boolToInt(args.align_inst != .none) + |
| 9263 | @boolToInt(args.addrspace_inst != .none) + | |
| 9232 | 9264 | @boolToInt(args.cc != .none), |
| 9233 | 9265 | ); |
| 9234 | 9266 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.ExtendedFunc{ |
| ... | ... | @@ -9246,6 +9278,9 @@ const GenZir = struct { |
| 9246 | 9278 | if (args.align_inst != .none) { |
| 9247 | 9279 | astgen.extra.appendAssumeCapacity(@enumToInt(args.align_inst)); |
| 9248 | 9280 | } |
| 9281 | if (args.addrspace_inst != .none) { | |
| 9282 | astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_inst)); | |
| 9283 | } | |
| 9249 | 9284 | astgen.extra.appendSliceAssumeCapacity(args.ret_ty); |
| 9250 | 9285 | astgen.extra.appendSliceAssumeCapacity(args.body); |
| 9251 | 9286 | astgen.extra.appendSliceAssumeCapacity(src_locs); |
| ... | ... | @@ -9264,6 +9299,7 @@ const GenZir = struct { |
| 9264 | 9299 | .has_lib_name = args.lib_name != 0, |
| 9265 | 9300 | .has_cc = args.cc != .none, |
| 9266 | 9301 | .has_align = args.align_inst != .none, |
| 9302 | .has_addrspace = args.addrspace_inst != .none, | |
| 9267 | 9303 | .is_test = args.is_test, |
| 9268 | 9304 | .is_extern = args.is_extern, |
| 9269 | 9305 | }), |
src/Sema.zig+3| ... | ... | @@ -10200,6 +10200,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 10200 | 10200 | .atomic_order => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrder"), |
| 10201 | 10201 | .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"), |
| 10202 | 10202 | .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"), |
| 10203 | .address_space => return sema.resolveBuiltinTypeFields(block, src, "AddressSpace"), | |
| 10203 | 10204 | .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"), |
| 10204 | 10205 | .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"), |
| 10205 | 10206 | .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"), |
| ... | ... | @@ -10594,6 +10595,7 @@ fn typeHasOnePossibleValue( |
| 10594 | 10595 | .atomic_order, |
| 10595 | 10596 | .atomic_rmw_op, |
| 10596 | 10597 | .calling_convention, |
| 10598 | .address_space, | |
| 10597 | 10599 | .float_mode, |
| 10598 | 10600 | .reduce_op, |
| 10599 | 10601 | .call_options, |
| ... | ... | @@ -10779,6 +10781,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |
| 10779 | 10781 | .atomic_order => return .atomic_order_type, |
| 10780 | 10782 | .atomic_rmw_op => return .atomic_rmw_op_type, |
| 10781 | 10783 | .calling_convention => return .calling_convention_type, |
| 10784 | .address_space => return .address_space_type, | |
| 10782 | 10785 | .float_mode => return .float_mode_type, |
| 10783 | 10786 | .reduce_op => return .reduce_op_type, |
| 10784 | 10787 | .call_options => return .call_options_type, |
src/Zir.zig+59-18| ... | ... | @@ -488,10 +488,10 @@ pub const Inst = struct { |
| 488 | 488 | /// this instruction; a following 'ret' instruction will do the diversion. |
| 489 | 489 | /// Uses the `str_tok` union field. |
| 490 | 490 | 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. | |
| 492 | 492 | /// Uses the `ptr_type_simple` union field. |
| 493 | 493 | 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. | |
| 495 | 495 | /// Uses the `ptr_type` union field. |
| 496 | 496 | ptr_type, |
| 497 | 497 | /// Slice operation `lhs[rhs..]`. No sentinel and no end offset. |
| ... | ... | @@ -1717,6 +1717,7 @@ pub const Inst = struct { |
| 1717 | 1717 | atomic_order_type, |
| 1718 | 1718 | atomic_rmw_op_type, |
| 1719 | 1719 | calling_convention_type, |
| 1720 | address_space_type, | |
| 1720 | 1721 | float_mode_type, |
| 1721 | 1722 | reduce_op_type, |
| 1722 | 1723 | call_options_type, |
| ... | ... | @@ -1973,6 +1974,10 @@ pub const Inst = struct { |
| 1973 | 1974 | .ty = Type.initTag(.type), |
| 1974 | 1975 | .val = Value.initTag(.calling_convention_type), |
| 1975 | 1976 | }, |
| 1977 | .address_space_type = .{ | |
| 1978 | .ty = Type.initTag(.type), | |
| 1979 | .val = Value.initTag(.address_space_type), | |
| 1980 | }, | |
| 1976 | 1981 | .float_mode_type = .{ |
| 1977 | 1982 | .ty = Type.initTag(.type), |
| 1978 | 1983 | .val = Value.initTag(.float_mode_type), |
| ... | ... | @@ -2174,8 +2179,9 @@ pub const Inst = struct { |
| 2174 | 2179 | is_volatile: bool, |
| 2175 | 2180 | has_sentinel: bool, |
| 2176 | 2181 | has_align: bool, |
| 2182 | has_addrspace: bool, | |
| 2177 | 2183 | has_bit_range: bool, |
| 2178 | _: u2 = undefined, | |
| 2184 | _: u1 = undefined, | |
| 2179 | 2185 | }, |
| 2180 | 2186 | size: std.builtin.TypeInfo.Pointer.Size, |
| 2181 | 2187 | /// Index into extra. See `PtrType`. |
| ... | ... | @@ -2303,6 +2309,7 @@ pub const Inst = struct { |
| 2303 | 2309 | /// 0. lib_name: u32, // null terminated string index, if has_lib_name is set |
| 2304 | 2310 | /// 1. cc: Ref, // if has_cc is set |
| 2305 | 2311 | /// 2. align: Ref, // if has_align is set |
| 2312 | /// 3. addrspace: Ref, // if has_addrspace is set | |
| 2306 | 2313 | /// 3. return_type: Index // for each ret_body_len |
| 2307 | 2314 | /// 4. body: Index // for each body_len |
| 2308 | 2315 | /// 5. src_locs: Func.SrcLocs // if body_len != 0 |
| ... | ... | @@ -2320,9 +2327,10 @@ pub const Inst = struct { |
| 2320 | 2327 | has_lib_name: bool, |
| 2321 | 2328 | has_cc: bool, |
| 2322 | 2329 | has_align: bool, |
| 2330 | has_addrspace: bool, | |
| 2323 | 2331 | is_test: bool, |
| 2324 | 2332 | is_extern: bool, |
| 2325 | _: u9 = undefined, | |
| 2333 | _: u8 = undefined, | |
| 2326 | 2334 | }; |
| 2327 | 2335 | }; |
| 2328 | 2336 | |
| ... | ... | @@ -2405,12 +2413,13 @@ pub const Inst = struct { |
| 2405 | 2413 | else_body_len: u32, |
| 2406 | 2414 | }; |
| 2407 | 2415 | |
| 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 | |
| 2409 | 2417 | /// trailing Ref fields: |
| 2410 | 2418 | /// 0. sentinel: Ref // if `has_sentinel` flag is set |
| 2411 | 2419 | /// 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 | |
| 2414 | 2423 | pub const PtrType = struct { |
| 2415 | 2424 | elem_type: Ref, |
| 2416 | 2425 | }; |
| ... | ... | @@ -2528,7 +2537,7 @@ pub const Inst = struct { |
| 2528 | 2537 | /// 0b000X: whether corresponding decl is pub |
| 2529 | 2538 | /// 0b00X0: whether corresponding decl is exported |
| 2530 | 2539 | /// 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 | |
| 2532 | 2541 | /// 5. decl: { // for every decls_len |
| 2533 | 2542 | /// src_hash: [4]u32, // hash of source bytes |
| 2534 | 2543 | /// line: u32, // line number of decl, relative to parent |
| ... | ... | @@ -2540,7 +2549,10 @@ pub const Inst = struct { |
| 2540 | 2549 | /// this is a test decl, and the name starts at `name+1`. |
| 2541 | 2550 | /// value: Index, |
| 2542 | 2551 | /// 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 | /// } | |
| 2544 | 2556 | /// } |
| 2545 | 2557 | /// 6. inst: Index // for every body_len |
| 2546 | 2558 | /// 7. flags: u32 // for every 8 fields |
| ... | ... | @@ -2592,7 +2604,7 @@ pub const Inst = struct { |
| 2592 | 2604 | /// 0b000X: whether corresponding decl is pub |
| 2593 | 2605 | /// 0b00X0: whether corresponding decl is exported |
| 2594 | 2606 | /// 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 | |
| 2596 | 2608 | /// 6. decl: { // for every decls_len |
| 2597 | 2609 | /// src_hash: [4]u32, // hash of source bytes |
| 2598 | 2610 | /// line: u32, // line number of decl, relative to parent |
| ... | ... | @@ -2604,7 +2616,10 @@ pub const Inst = struct { |
| 2604 | 2616 | /// this is a test decl, and the name starts at `name+1`. |
| 2605 | 2617 | /// value: Index, |
| 2606 | 2618 | /// 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 | /// } | |
| 2608 | 2623 | /// } |
| 2609 | 2624 | /// 7. inst: Index // for every body_len |
| 2610 | 2625 | /// 8. has_bits: u32 // for every 32 fields |
| ... | ... | @@ -2637,7 +2652,7 @@ pub const Inst = struct { |
| 2637 | 2652 | /// 0b000X: whether corresponding decl is pub |
| 2638 | 2653 | /// 0b00X0: whether corresponding decl is exported |
| 2639 | 2654 | /// 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 | |
| 2641 | 2656 | /// 6. decl: { // for every decls_len |
| 2642 | 2657 | /// src_hash: [4]u32, // hash of source bytes |
| 2643 | 2658 | /// line: u32, // line number of decl, relative to parent |
| ... | ... | @@ -2649,7 +2664,10 @@ pub const Inst = struct { |
| 2649 | 2664 | /// this is a test decl, and the name starts at `name+1`. |
| 2650 | 2665 | /// value: Index, |
| 2651 | 2666 | /// 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 | /// } | |
| 2653 | 2671 | /// } |
| 2654 | 2672 | /// 7. inst: Index // for every body_len |
| 2655 | 2673 | /// 8. has_bits: u32 // for every 8 fields |
| ... | ... | @@ -2686,7 +2704,7 @@ pub const Inst = struct { |
| 2686 | 2704 | /// 0b000X: whether corresponding decl is pub |
| 2687 | 2705 | /// 0b00X0: whether corresponding decl is exported |
| 2688 | 2706 | /// 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 | |
| 2690 | 2708 | /// 1. decl: { // for every decls_len |
| 2691 | 2709 | /// src_hash: [4]u32, // hash of source bytes |
| 2692 | 2710 | /// line: u32, // line number of decl, relative to parent |
| ... | ... | @@ -2698,7 +2716,10 @@ pub const Inst = struct { |
| 2698 | 2716 | /// this is a test decl, and the name starts at `name+1`. |
| 2699 | 2717 | /// value: Index, |
| 2700 | 2718 | /// 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 | /// } | |
| 2702 | 2723 | /// } |
| 2703 | 2724 | pub const OpaqueDecl = struct { |
| 2704 | 2725 | decls_len: u32, |
| ... | ... | @@ -3983,7 +4004,7 @@ const Writer = struct { |
| 3983 | 4004 | cur_bit_bag >>= 1; |
| 3984 | 4005 | const has_align = @truncate(u1, cur_bit_bag) != 0; |
| 3985 | 4006 | 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; | |
| 3987 | 4008 | cur_bit_bag >>= 1; |
| 3988 | 4009 | |
| 3989 | 4010 | const sub_index = extra_index; |
| ... | ... | @@ -4001,12 +4022,16 @@ const Writer = struct { |
| 4001 | 4022 | extra_index += 1; |
| 4002 | 4023 | break :inst inst; |
| 4003 | 4024 | }; |
| 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: { | |
| 4005 | 4026 | const inst = @intToEnum(Inst.Ref, self.code.extra[extra_index]); |
| 4006 | 4027 | extra_index += 1; |
| 4007 | 4028 | break :inst inst; |
| 4008 | 4029 | }; |
| 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 | }; | |
| 4010 | 4035 | const pub_str = if (is_pub) "pub " else ""; |
| 4011 | 4036 | const hash_bytes = @bitCast([16]u8, hash_u32s.*); |
| 4012 | 4037 | try stream.writeByteNTimes(' ', self.indent); |
| ... | ... | @@ -4032,6 +4057,11 @@ const Writer = struct { |
| 4032 | 4057 | try self.writeInstRef(stream, align_inst); |
| 4033 | 4058 | try stream.writeAll(")"); |
| 4034 | 4059 | } |
| 4060 | if (addrspace_inst != .none) { | |
| 4061 | try stream.writeAll(" addrspace("); | |
| 4062 | try self.writeInstRef(stream, addrspace_inst); | |
| 4063 | try stream.writeAll(")"); | |
| 4064 | } | |
| 4035 | 4065 | if (section_inst != .none) { |
| 4036 | 4066 | try stream.writeAll(" linksection("); |
| 4037 | 4067 | try self.writeInstRef(stream, section_inst); |
| ... | ... | @@ -4453,6 +4483,7 @@ const Writer = struct { |
| 4453 | 4483 | false, |
| 4454 | 4484 | .none, |
| 4455 | 4485 | .none, |
| 4486 | .none, | |
| 4456 | 4487 | body, |
| 4457 | 4488 | src, |
| 4458 | 4489 | src_locs, |
| ... | ... | @@ -4481,6 +4512,11 @@ const Writer = struct { |
| 4481 | 4512 | extra_index += 1; |
| 4482 | 4513 | break :blk align_inst; |
| 4483 | 4514 | }; |
| 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 | }; | |
| 4484 | 4520 | |
| 4485 | 4521 | const ret_ty_body = self.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 4486 | 4522 | extra_index += ret_ty_body.len; |
| ... | ... | @@ -4500,6 +4536,7 @@ const Writer = struct { |
| 4500 | 4536 | small.is_extern, |
| 4501 | 4537 | cc, |
| 4502 | 4538 | align_inst, |
| 4539 | addrspace_inst, | |
| 4503 | 4540 | body, |
| 4504 | 4541 | src, |
| 4505 | 4542 | src_locs, |
| ... | ... | @@ -4582,6 +4619,7 @@ const Writer = struct { |
| 4582 | 4619 | is_extern: bool, |
| 4583 | 4620 | cc: Inst.Ref, |
| 4584 | 4621 | align_inst: Inst.Ref, |
| 4622 | addrspace_inst: Inst.Ref, | |
| 4585 | 4623 | body: []const Inst.Index, |
| 4586 | 4624 | src: LazySrcLoc, |
| 4587 | 4625 | src_locs: Zir.Inst.Func.SrcLocs, |
| ... | ... | @@ -4599,6 +4637,7 @@ const Writer = struct { |
| 4599 | 4637 | |
| 4600 | 4638 | try self.writeOptionalInstRef(stream, ", cc=", cc); |
| 4601 | 4639 | try self.writeOptionalInstRef(stream, ", align=", align_inst); |
| 4640 | try self.writeOptionalInstRef(stream, ", addrspace=", addrspace_inst); | |
| 4602 | 4641 | try self.writeFlag(stream, ", vargs", var_args); |
| 4603 | 4642 | try self.writeFlag(stream, ", extern", is_extern); |
| 4604 | 4643 | try self.writeFlag(stream, ", inferror", inferred_error_set); |
| ... | ... | @@ -4876,6 +4915,7 @@ fn findDeclsInner( |
| 4876 | 4915 | extra_index += @boolToInt(small.has_lib_name); |
| 4877 | 4916 | extra_index += @boolToInt(small.has_cc); |
| 4878 | 4917 | extra_index += @boolToInt(small.has_align); |
| 4918 | extra_index += @boolToInt(small.has_addrspace); | |
| 4879 | 4919 | const body = zir.extra[extra_index..][0..extra.data.body_len]; |
| 4880 | 4920 | return zir.findDeclsBody(list, body); |
| 4881 | 4921 | }, |
| ... | ... | @@ -5079,6 +5119,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 5079 | 5119 | extra_index += @boolToInt(small.has_lib_name); |
| 5080 | 5120 | extra_index += @boolToInt(small.has_cc); |
| 5081 | 5121 | extra_index += @boolToInt(small.has_align); |
| 5122 | extra_index += @boolToInt(small.has_addrspace); | |
| 5082 | 5123 | const ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len]; |
| 5083 | 5124 | extra_index += ret_ty_body.len; |
| 5084 | 5125 | 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 { |
| 2706 | 2706 | .lhs = try c.addExtra(std.zig.Ast.Node.FnProtoOne{ |
| 2707 | 2707 | .param = params.items[0], |
| 2708 | 2708 | .align_expr = align_expr, |
| 2709 | .addrspace_expr = 0, // TODO | |
| 2709 | 2710 | .section_expr = section_expr, |
| 2710 | 2711 | .callconv_expr = callconv_expr, |
| 2711 | 2712 | }), |
| ... | ... | @@ -2721,6 +2722,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex { |
| 2721 | 2722 | .params_start = span.start, |
| 2722 | 2723 | .params_end = span.end, |
| 2723 | 2724 | .align_expr = align_expr, |
| 2725 | .addrspace_expr = 0, // TODO | |
| 2724 | 2726 | .section_expr = section_expr, |
| 2725 | 2727 | .callconv_expr = callconv_expr, |
| 2726 | 2728 | }), |
src/type.zig+19| ... | ... | @@ -127,6 +127,7 @@ pub const Type = extern union { |
| 127 | 127 | .atomic_order, |
| 128 | 128 | .atomic_rmw_op, |
| 129 | 129 | .calling_convention, |
| 130 | .address_space, | |
| 130 | 131 | .float_mode, |
| 131 | 132 | .reduce_op, |
| 132 | 133 | => return .Enum, |
| ... | ... | @@ -746,6 +747,7 @@ pub const Type = extern union { |
| 746 | 747 | .atomic_order, |
| 747 | 748 | .atomic_rmw_op, |
| 748 | 749 | .calling_convention, |
| 750 | .address_space, | |
| 749 | 751 | .float_mode, |
| 750 | 752 | .reduce_op, |
| 751 | 753 | .call_options, |
| ... | ... | @@ -958,6 +960,7 @@ pub const Type = extern union { |
| 958 | 960 | .atomic_order => return writer.writeAll("std.builtin.AtomicOrder"), |
| 959 | 961 | .atomic_rmw_op => return writer.writeAll("std.builtin.AtomicRmwOp"), |
| 960 | 962 | .calling_convention => return writer.writeAll("std.builtin.CallingConvention"), |
| 963 | .address_space => return writer.writeAll("std.builtin.AddressSpace"), | |
| 961 | 964 | .float_mode => return writer.writeAll("std.builtin.FloatMode"), |
| 962 | 965 | .reduce_op => return writer.writeAll("std.builtin.ReduceOp"), |
| 963 | 966 | .call_options => return writer.writeAll("std.builtin.CallOptions"), |
| ... | ... | @@ -1186,6 +1189,7 @@ pub const Type = extern union { |
| 1186 | 1189 | .atomic_order, |
| 1187 | 1190 | .atomic_rmw_op, |
| 1188 | 1191 | .calling_convention, |
| 1192 | .address_space, | |
| 1189 | 1193 | .float_mode, |
| 1190 | 1194 | .reduce_op, |
| 1191 | 1195 | .call_options, |
| ... | ... | @@ -1301,6 +1305,7 @@ pub const Type = extern union { |
| 1301 | 1305 | .atomic_order => return Value.initTag(.atomic_order_type), |
| 1302 | 1306 | .atomic_rmw_op => return Value.initTag(.atomic_rmw_op_type), |
| 1303 | 1307 | .calling_convention => return Value.initTag(.calling_convention_type), |
| 1308 | .address_space => return Value.initTag(.address_space_type), | |
| 1304 | 1309 | .float_mode => return Value.initTag(.float_mode_type), |
| 1305 | 1310 | .reduce_op => return Value.initTag(.reduce_op_type), |
| 1306 | 1311 | .call_options => return Value.initTag(.call_options_type), |
| ... | ... | @@ -1362,6 +1367,7 @@ pub const Type = extern union { |
| 1362 | 1367 | .atomic_order, |
| 1363 | 1368 | .atomic_rmw_op, |
| 1364 | 1369 | .calling_convention, |
| 1370 | .address_space, | |
| 1365 | 1371 | .float_mode, |
| 1366 | 1372 | .reduce_op, |
| 1367 | 1373 | .call_options, |
| ... | ... | @@ -1508,6 +1514,7 @@ pub const Type = extern union { |
| 1508 | 1514 | .atomic_order, |
| 1509 | 1515 | .atomic_rmw_op, |
| 1510 | 1516 | .calling_convention, |
| 1517 | .address_space, | |
| 1511 | 1518 | .float_mode, |
| 1512 | 1519 | .reduce_op, |
| 1513 | 1520 | .call_options, |
| ... | ... | @@ -1734,6 +1741,7 @@ pub const Type = extern union { |
| 1734 | 1741 | .atomic_order, |
| 1735 | 1742 | .atomic_rmw_op, |
| 1736 | 1743 | .calling_convention, |
| 1744 | .address_space, | |
| 1737 | 1745 | .float_mode, |
| 1738 | 1746 | .reduce_op, |
| 1739 | 1747 | .call_options, |
| ... | ... | @@ -2018,6 +2026,7 @@ pub const Type = extern union { |
| 2018 | 2026 | .atomic_order, |
| 2019 | 2027 | .atomic_rmw_op, |
| 2020 | 2028 | .calling_convention, |
| 2029 | .address_space, | |
| 2021 | 2030 | .float_mode, |
| 2022 | 2031 | .reduce_op, |
| 2023 | 2032 | .call_options, |
| ... | ... | @@ -2775,6 +2784,7 @@ pub const Type = extern union { |
| 2775 | 2784 | .atomic_order, |
| 2776 | 2785 | .atomic_rmw_op, |
| 2777 | 2786 | .calling_convention, |
| 2787 | .address_space, | |
| 2778 | 2788 | .float_mode, |
| 2779 | 2789 | .reduce_op, |
| 2780 | 2790 | .call_options, |
| ... | ... | @@ -2982,6 +2992,7 @@ pub const Type = extern union { |
| 2982 | 2992 | .atomic_order, |
| 2983 | 2993 | .atomic_rmw_op, |
| 2984 | 2994 | .calling_convention, |
| 2995 | .address_space, | |
| 2985 | 2996 | .float_mode, |
| 2986 | 2997 | .reduce_op, |
| 2987 | 2998 | .call_options, |
| ... | ... | @@ -3006,6 +3017,7 @@ pub const Type = extern union { |
| 3006 | 3017 | .atomic_order, |
| 3007 | 3018 | .atomic_rmw_op, |
| 3008 | 3019 | .calling_convention, |
| 3020 | .address_space, | |
| 3009 | 3021 | .float_mode, |
| 3010 | 3022 | .reduce_op, |
| 3011 | 3023 | .call_options, |
| ... | ... | @@ -3029,6 +3041,7 @@ pub const Type = extern union { |
| 3029 | 3041 | .atomic_order, |
| 3030 | 3042 | .atomic_rmw_op, |
| 3031 | 3043 | .calling_convention, |
| 3044 | .address_space, | |
| 3032 | 3045 | .float_mode, |
| 3033 | 3046 | .reduce_op, |
| 3034 | 3047 | .call_options, |
| ... | ... | @@ -3082,6 +3095,7 @@ pub const Type = extern union { |
| 3082 | 3095 | .atomic_order, |
| 3083 | 3096 | .atomic_rmw_op, |
| 3084 | 3097 | .calling_convention, |
| 3098 | .address_space, | |
| 3085 | 3099 | .float_mode, |
| 3086 | 3100 | .reduce_op, |
| 3087 | 3101 | .call_options, |
| ... | ... | @@ -3137,6 +3151,7 @@ pub const Type = extern union { |
| 3137 | 3151 | .atomic_order, |
| 3138 | 3152 | .atomic_rmw_op, |
| 3139 | 3153 | .calling_convention, |
| 3154 | .address_space, | |
| 3140 | 3155 | .float_mode, |
| 3141 | 3156 | .reduce_op, |
| 3142 | 3157 | .call_options, |
| ... | ... | @@ -3174,6 +3189,7 @@ pub const Type = extern union { |
| 3174 | 3189 | .atomic_order, |
| 3175 | 3190 | .atomic_rmw_op, |
| 3176 | 3191 | .calling_convention, |
| 3192 | .address_space, | |
| 3177 | 3193 | .float_mode, |
| 3178 | 3194 | .reduce_op, |
| 3179 | 3195 | .call_options, |
| ... | ... | @@ -3224,6 +3240,7 @@ pub const Type = extern union { |
| 3224 | 3240 | .atomic_order, |
| 3225 | 3241 | .atomic_rmw_op, |
| 3226 | 3242 | .calling_convention, |
| 3243 | .address_space, | |
| 3227 | 3244 | .float_mode, |
| 3228 | 3245 | .reduce_op, |
| 3229 | 3246 | .call_options, |
| ... | ... | @@ -3284,6 +3301,7 @@ pub const Type = extern union { |
| 3284 | 3301 | atomic_order, |
| 3285 | 3302 | atomic_rmw_op, |
| 3286 | 3303 | calling_convention, |
| 3304 | address_space, | |
| 3287 | 3305 | float_mode, |
| 3288 | 3306 | reduce_op, |
| 3289 | 3307 | call_options, |
| ... | ... | @@ -3407,6 +3425,7 @@ pub const Type = extern union { |
| 3407 | 3425 | .atomic_order, |
| 3408 | 3426 | .atomic_rmw_op, |
| 3409 | 3427 | .calling_convention, |
| 3428 | .address_space, | |
| 3410 | 3429 | .float_mode, |
| 3411 | 3430 | .reduce_op, |
| 3412 | 3431 | .call_options, |
src/value.zig+5| ... | ... | @@ -63,6 +63,7 @@ pub const Value = extern union { |
| 63 | 63 | atomic_order_type, |
| 64 | 64 | atomic_rmw_op_type, |
| 65 | 65 | calling_convention_type, |
| 66 | address_space_type, | |
| 66 | 67 | float_mode_type, |
| 67 | 68 | reduce_op_type, |
| 68 | 69 | call_options_type, |
| ... | ... | @@ -226,6 +227,7 @@ pub const Value = extern union { |
| 226 | 227 | .atomic_order_type, |
| 227 | 228 | .atomic_rmw_op_type, |
| 228 | 229 | .calling_convention_type, |
| 230 | .address_space_type, | |
| 229 | 231 | .float_mode_type, |
| 230 | 232 | .reduce_op_type, |
| 231 | 233 | .call_options_type, |
| ... | ... | @@ -412,6 +414,7 @@ pub const Value = extern union { |
| 412 | 414 | .atomic_order_type, |
| 413 | 415 | .atomic_rmw_op_type, |
| 414 | 416 | .calling_convention_type, |
| 417 | .address_space_type, | |
| 415 | 418 | .float_mode_type, |
| 416 | 419 | .reduce_op_type, |
| 417 | 420 | .call_options_type, |
| ... | ... | @@ -625,6 +628,7 @@ pub const Value = extern union { |
| 625 | 628 | .atomic_order_type => return out_stream.writeAll("std.builtin.AtomicOrder"), |
| 626 | 629 | .atomic_rmw_op_type => return out_stream.writeAll("std.builtin.AtomicRmwOp"), |
| 627 | 630 | .calling_convention_type => return out_stream.writeAll("std.builtin.CallingConvention"), |
| 631 | .address_space_type => return out_stream.writeAll("std.builtin.AddressSpace"), | |
| 628 | 632 | .float_mode_type => return out_stream.writeAll("std.builtin.FloatMode"), |
| 629 | 633 | .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"), |
| 630 | 634 | .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"), |
| ... | ... | @@ -792,6 +796,7 @@ pub const Value = extern union { |
| 792 | 796 | .atomic_order_type => Type.initTag(.atomic_order), |
| 793 | 797 | .atomic_rmw_op_type => Type.initTag(.atomic_rmw_op), |
| 794 | 798 | .calling_convention_type => Type.initTag(.calling_convention), |
| 799 | .address_space_type => Type.initTag(.address_space), | |
| 795 | 800 | .float_mode_type => Type.initTag(.float_mode), |
| 796 | 801 | .reduce_op_type => Type.initTag(.reduce_op), |
| 797 | 802 | .call_options_type => Type.initTag(.call_options), |