| author | |
| committer | |
| log | 2b8e7deeda5d4d0d74f42265a4ddf466f91c8fc2 |
| tree | d0bec44e92bf4042ec5de3f829daadf54ea0aa36 |
| parent | 99d2d9bf64aad0cc4b46bdcef43432ba48349c7a |
2 files changed, 41 insertions(+), 0 deletions(-)
src-self-hosted/zir.zig+27| ... | ... | @@ -183,6 +183,10 @@ pub const Inst = struct { |
| 183 | 183 | shl, |
| 184 | 184 | /// Integer shift-right. Arithmetic or logical depending on the signedness of the integer type. |
| 185 | 185 | shr, |
| 186 | /// Create a const pointer type based on the element type. `*const T` | |
| 187 | single_const_ptr_type, | |
| 188 | /// Create a mutable pointer type based on the element type. `*T` | |
| 189 | single_mut_ptr_type, | |
| 186 | 190 | /// Write a value to a pointer. For loading, see `deref`. |
| 187 | 191 | store, |
| 188 | 192 | /// String Literal. Makes an anonymous Decl and then takes a pointer to it. |
| ... | ... | @@ -228,6 +232,8 @@ pub const Inst = struct { |
| 228 | 232 | .ref, |
| 229 | 233 | .bitcast_lvalue, |
| 230 | 234 | .typeof, |
| 235 | .single_const_ptr_type, | |
| 236 | .single_mut_ptr_type, | |
| 231 | 237 | => UnOp, |
| 232 | 238 | |
| 233 | 239 | .add, |
| ... | ... | @@ -348,6 +354,8 @@ pub const Inst = struct { |
| 348 | 354 | .ret_type, |
| 349 | 355 | .shl, |
| 350 | 356 | .shr, |
| 357 | .single_const_ptr_type, | |
| 358 | .single_mut_ptr_type, | |
| 351 | 359 | .store, |
| 352 | 360 | .str, |
| 353 | 361 | .sub, |
| ... | ... | @@ -2095,6 +2103,25 @@ const EmitZIR = struct { |
| 2095 | 2103 | }; |
| 2096 | 2104 | return self.emitUnnamedDecl(&inttype_inst.base); |
| 2097 | 2105 | }, |
| 2106 | .Pointer => { | |
| 2107 | if (ty.isSinglePointer()) { | |
| 2108 | const inst = try self.arena.allocator.create(Inst.UnOp); | |
| 2109 | const tag: Inst.Tag = if (ty.isConstPtr()) .single_const_ptr_type else .single_mut_ptr_type; | |
| 2110 | inst.* = .{ | |
| 2111 | .base = .{ | |
| 2112 | .src = src, | |
| 2113 | .tag = tag, | |
| 2114 | }, | |
| 2115 | .positionals = .{ | |
| 2116 | .operand = (try self.emitType(src, ty.elemType())).inst, | |
| 2117 | }, | |
| 2118 | .kw_args = .{}, | |
| 2119 | }; | |
| 2120 | return self.emitUnnamedDecl(&inst.base); | |
| 2121 | } else { | |
| 2122 | std.debug.panic("TODO implement emitType for {}", .{ty}); | |
| 2123 | } | |
| 2124 | }, | |
| 2098 | 2125 | else => std.debug.panic("TODO implement emitType for {}", .{ty}), |
| 2099 | 2126 | }, |
| 2100 | 2127 | } |
src-self-hosted/zir_sema.zig+14| ... | ... | @@ -50,6 +50,8 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 50 | 50 | .ref => return analyzeInstRef(mod, scope, old_inst.castTag(.ref).?), |
| 51 | 51 | .ret_ptr => return analyzeInstRetPtr(mod, scope, old_inst.castTag(.ret_ptr).?), |
| 52 | 52 | .ret_type => return analyzeInstRetType(mod, scope, old_inst.castTag(.ret_type).?), |
| 53 | .single_const_ptr_type => return analyzeInstSingleConstPtrType(mod, scope, old_inst.castTag(.single_const_ptr_type).?), | |
| 54 | .single_mut_ptr_type => return analyzeInstSingleMutPtrType(mod, scope, old_inst.castTag(.single_mut_ptr_type).?), | |
| 53 | 55 | .store => return analyzeInstStore(mod, scope, old_inst.castTag(.store).?), |
| 54 | 56 | .str => return analyzeInstStr(mod, scope, old_inst.castTag(.str).?), |
| 55 | 57 | .int => { |
| ... | ... | @@ -1137,3 +1139,15 @@ fn analyzeDeclVal(mod: *Module, scope: *Scope, inst: *zir.Inst.DeclVal) InnerErr |
| 1137 | 1139 | |
| 1138 | 1140 | return decl; |
| 1139 | 1141 | } |
| 1142 | ||
| 1143 | fn analyzeInstSingleConstPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { | |
| 1144 | const elem_type = try resolveType(mod, scope, inst.positionals.operand); | |
| 1145 | const ty = try mod.singleConstPtrType(scope, inst.base.src, elem_type); | |
| 1146 | return mod.constType(scope, inst.base.src, ty); | |
| 1147 | } | |
| 1148 | ||
| 1149 | fn analyzeInstSingleMutPtrType(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { | |
| 1150 | const elem_type = try resolveType(mod, scope, inst.positionals.operand); | |
| 1151 | const ty = try mod.singleMutPtrType(scope, inst.base.src, elem_type); | |
| 1152 | return mod.constType(scope, inst.base.src, ty); | |
| 1153 | } |