| author | |
| committer | |
| log | 6769183a9d5f5ec69747f46d4d13c0f8709b2f46 |
| tree | 273a352de8765f10482336d510a995543ee3d259 |
| parent | 52c03de5c2495b369ae730ff203e5342e4f33a36 |
| signature |
and update self hosted compiler for C pointers
See #105913 files changed, 228 insertions(+), 131 deletions(-)
doc/docgen.zig+1| ... | @@ -916,6 +916,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok | ... | @@ -916,6 +916,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 916 | std.zig.Token.Id.AngleBracketAngleBracketRightEqual, | 916 | std.zig.Token.Id.AngleBracketAngleBracketRightEqual, |
| 917 | std.zig.Token.Id.Tilde, | 917 | std.zig.Token.Id.Tilde, |
| 918 | std.zig.Token.Id.BracketStarBracket, | 918 | std.zig.Token.Id.BracketStarBracket, |
| 919 | std.zig.Token.Id.BracketStarCBracket, | ||
| 919 | => try writeEscaped(out, src[token.start..token.end]), | 920 | => try writeEscaped(out, src[token.start..token.end]), |
| 920 | 921 | ||
| 921 | std.zig.Token.Id.Invalid => return parseError( | 922 | std.zig.Token.Id.Invalid => return parseError( |
src-self-hosted/codegen.zig+21-21| ... | @@ -137,10 +137,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) | ... | @@ -137,10 +137,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 137 | 137 | ||
| 138 | pub const ObjectFile = struct { | 138 | pub const ObjectFile = struct { |
| 139 | comp: *Compilation, | 139 | comp: *Compilation, |
| 140 | module: llvm.ModuleRef, | 140 | module: *llvm.Module, |
| 141 | builder: llvm.BuilderRef, | 141 | builder: *llvm.Builder, |
| 142 | dibuilder: *llvm.DIBuilder, | 142 | dibuilder: *llvm.DIBuilder, |
| 143 | context: llvm.ContextRef, | 143 | context: *llvm.Context, |
| 144 | lock: event.Lock, | 144 | lock: event.Lock, |
| 145 | arena: *std.mem.Allocator, | 145 | arena: *std.mem.Allocator, |
| 146 | 146 | ||
| ... | @@ -323,7 +323,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) | ... | @@ -323,7 +323,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 323 | 323 | ||
| 324 | fn addLLVMAttr( | 324 | fn addLLVMAttr( |
| 325 | ofile: *ObjectFile, | 325 | ofile: *ObjectFile, |
| 326 | val: llvm.ValueRef, | 326 | val: *llvm.Value, |
| 327 | attr_index: llvm.AttributeIndex, | 327 | attr_index: llvm.AttributeIndex, |
| 328 | attr_name: []const u8, | 328 | attr_name: []const u8, |
| 329 | ) !void { | 329 | ) !void { |
| ... | @@ -335,7 +335,7 @@ fn addLLVMAttr( | ... | @@ -335,7 +335,7 @@ fn addLLVMAttr( |
| 335 | 335 | ||
| 336 | fn addLLVMAttrStr( | 336 | fn addLLVMAttrStr( |
| 337 | ofile: *ObjectFile, | 337 | ofile: *ObjectFile, |
| 338 | val: llvm.ValueRef, | 338 | val: *llvm.Value, |
| 339 | attr_index: llvm.AttributeIndex, | 339 | attr_index: llvm.AttributeIndex, |
| 340 | attr_name: []const u8, | 340 | attr_name: []const u8, |
| 341 | attr_val: []const u8, | 341 | attr_val: []const u8, |
| ... | @@ -351,7 +351,7 @@ fn addLLVMAttrStr( | ... | @@ -351,7 +351,7 @@ fn addLLVMAttrStr( |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | fn addLLVMAttrInt( | 353 | fn addLLVMAttrInt( |
| 354 | val: llvm.ValueRef, | 354 | val: *llvm.Value, |
| 355 | attr_index: llvm.AttributeIndex, | 355 | attr_index: llvm.AttributeIndex, |
| 356 | attr_name: []const u8, | 356 | attr_name: []const u8, |
| 357 | attr_val: u64, | 357 | attr_val: u64, |
| ... | @@ -362,25 +362,25 @@ fn addLLVMAttrInt( | ... | @@ -362,25 +362,25 @@ fn addLLVMAttrInt( |
| 362 | llvm.AddAttributeAtIndex(val, attr_index, llvm_attr); | 362 | llvm.AddAttributeAtIndex(val, attr_index, llvm_attr); |
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | fn addLLVMFnAttr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8) !void { | 365 | fn addLLVMFnAttr(ofile: *ObjectFile, fn_val: *llvm.Value, attr_name: []const u8) !void { |
| 366 | return addLLVMAttr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name); | 366 | return addLLVMAttr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name); |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | fn addLLVMFnAttrStr(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: []const u8) !void { | 369 | fn addLLVMFnAttrStr(ofile: *ObjectFile, fn_val: *llvm.Value, attr_name: []const u8, attr_val: []const u8) !void { |
| 370 | return addLLVMAttrStr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); | 370 | return addLLVMAttrStr(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | fn addLLVMFnAttrInt(ofile: *ObjectFile, fn_val: llvm.ValueRef, attr_name: []const u8, attr_val: u64) !void { | 373 | fn addLLVMFnAttrInt(ofile: *ObjectFile, fn_val: *llvm.Value, attr_name: []const u8, attr_val: u64) !void { |
| 374 | return addLLVMAttrInt(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); | 374 | return addLLVMAttrInt(ofile, fn_val, maxInt(llvm.AttributeIndex), attr_name, attr_val); |
| 375 | } | 375 | } |
| 376 | 376 | ||
| 377 | fn renderLoadUntyped( | 377 | fn renderLoadUntyped( |
| 378 | ofile: *ObjectFile, | 378 | ofile: *ObjectFile, |
| 379 | ptr: llvm.ValueRef, | 379 | ptr: *llvm.Value, |
| 380 | alignment: Type.Pointer.Align, | 380 | alignment: Type.Pointer.Align, |
| 381 | vol: Type.Pointer.Vol, | 381 | vol: Type.Pointer.Vol, |
| 382 | name: [*]const u8, | 382 | name: [*]const u8, |
| 383 | ) !llvm.ValueRef { | 383 | ) !*llvm.Value { |
| 384 | const result = llvm.BuildLoad(ofile.builder, ptr, name) orelse return error.OutOfMemory; | 384 | const result = llvm.BuildLoad(ofile.builder, ptr, name) orelse return error.OutOfMemory; |
| 385 | switch (vol) { | 385 | switch (vol) { |
| 386 | Type.Pointer.Vol.Non => {}, | 386 | Type.Pointer.Vol.Non => {}, |
| ... | @@ -390,11 +390,11 @@ fn renderLoadUntyped( | ... | @@ -390,11 +390,11 @@ fn renderLoadUntyped( |
| 390 | return result; | 390 | return result; |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | fn renderLoad(ofile: *ObjectFile, ptr: llvm.ValueRef, ptr_type: *Type.Pointer, name: [*]const u8) !llvm.ValueRef { | 393 | fn renderLoad(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Pointer, name: [*]const u8) !*llvm.Value { |
| 394 | return renderLoadUntyped(ofile, ptr, ptr_type.key.alignment, ptr_type.key.vol, name); | 394 | return renderLoadUntyped(ofile, ptr, ptr_type.key.alignment, ptr_type.key.vol, name); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | pub fn getHandleValue(ofile: *ObjectFile, ptr: llvm.ValueRef, ptr_type: *Type.Pointer) !?llvm.ValueRef { | 397 | pub fn getHandleValue(ofile: *ObjectFile, ptr: *llvm.Value, ptr_type: *Type.Pointer) !?*llvm.Value { |
| 398 | const child_type = ptr_type.key.child_type; | 398 | const child_type = ptr_type.key.child_type; |
| 399 | if (!child_type.hasBits()) { | 399 | if (!child_type.hasBits()) { |
| 400 | return null; | 400 | return null; |
| ... | @@ -407,11 +407,11 @@ pub fn getHandleValue(ofile: *ObjectFile, ptr: llvm.ValueRef, ptr_type: *Type.Po | ... | @@ -407,11 +407,11 @@ pub fn getHandleValue(ofile: *ObjectFile, ptr: llvm.ValueRef, ptr_type: *Type.Po |
| 407 | 407 | ||
| 408 | pub fn renderStoreUntyped( | 408 | pub fn renderStoreUntyped( |
| 409 | ofile: *ObjectFile, | 409 | ofile: *ObjectFile, |
| 410 | value: llvm.ValueRef, | 410 | value: *llvm.Value, |
| 411 | ptr: llvm.ValueRef, | 411 | ptr: *llvm.Value, |
| 412 | alignment: Type.Pointer.Align, | 412 | alignment: Type.Pointer.Align, |
| 413 | vol: Type.Pointer.Vol, | 413 | vol: Type.Pointer.Vol, |
| 414 | ) !llvm.ValueRef { | 414 | ) !*llvm.Value { |
| 415 | const result = llvm.BuildStore(ofile.builder, value, ptr) orelse return error.OutOfMemory; | 415 | const result = llvm.BuildStore(ofile.builder, value, ptr) orelse return error.OutOfMemory; |
| 416 | switch (vol) { | 416 | switch (vol) { |
| 417 | Type.Pointer.Vol.Non => {}, | 417 | Type.Pointer.Vol.Non => {}, |
| ... | @@ -423,10 +423,10 @@ pub fn renderStoreUntyped( | ... | @@ -423,10 +423,10 @@ pub fn renderStoreUntyped( |
| 423 | 423 | ||
| 424 | pub fn renderStore( | 424 | pub fn renderStore( |
| 425 | ofile: *ObjectFile, | 425 | ofile: *ObjectFile, |
| 426 | value: llvm.ValueRef, | 426 | value: *llvm.Value, |
| 427 | ptr: llvm.ValueRef, | 427 | ptr: *llvm.Value, |
| 428 | ptr_type: *Type.Pointer, | 428 | ptr_type: *Type.Pointer, |
| 429 | ) !llvm.ValueRef { | 429 | ) !*llvm.Value { |
| 430 | return renderStoreUntyped(ofile, value, ptr, ptr_type.key.alignment, ptr_type.key.vol); | 430 | return renderStoreUntyped(ofile, value, ptr, ptr_type.key.alignment, ptr_type.key.vol); |
| 431 | } | 431 | } |
| 432 | 432 | ||
| ... | @@ -435,7 +435,7 @@ pub fn renderAlloca( | ... | @@ -435,7 +435,7 @@ pub fn renderAlloca( |
| 435 | var_type: *Type, | 435 | var_type: *Type, |
| 436 | name: []const u8, | 436 | name: []const u8, |
| 437 | alignment: Type.Pointer.Align, | 437 | alignment: Type.Pointer.Align, |
| 438 | ) !llvm.ValueRef { | 438 | ) !*llvm.Value { |
| 439 | const llvm_var_type = try var_type.getLlvmType(ofile.arena, ofile.context); | 439 | const llvm_var_type = try var_type.getLlvmType(ofile.arena, ofile.context); |
| 440 | const name_with_null = try std.cstr.addNullByte(ofile.arena, name); | 440 | const name_with_null = try std.cstr.addNullByte(ofile.arena, name); |
| 441 | const result = llvm.BuildAlloca(ofile.builder, llvm_var_type, name_with_null.ptr) orelse return error.OutOfMemory; | 441 | const result = llvm.BuildAlloca(ofile.builder, llvm_var_type, name_with_null.ptr) orelse return error.OutOfMemory; |
| ... | @@ -443,7 +443,7 @@ pub fn renderAlloca( | ... | @@ -443,7 +443,7 @@ pub fn renderAlloca( |
| 443 | return result; | 443 | return result; |
| 444 | } | 444 | } |
| 445 | 445 | ||
| 446 | pub fn resolveAlign(ofile: *ObjectFile, alignment: Type.Pointer.Align, llvm_type: llvm.TypeRef) u32 { | 446 | pub fn resolveAlign(ofile: *ObjectFile, alignment: Type.Pointer.Align, llvm_type: *llvm.Type) u32 { |
| 447 | return switch (alignment) { | 447 | return switch (alignment) { |
| 448 | Type.Pointer.Align.Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), | 448 | Type.Pointer.Align.Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), |
| 449 | Type.Pointer.Align.Override => |a| a, | 449 | Type.Pointer.Align.Override => |a| a, |
src-self-hosted/compilation.zig+11-11| ... | @@ -37,7 +37,7 @@ const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB | ... | @@ -37,7 +37,7 @@ const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB |
| 37 | /// Data that is local to the event loop. | 37 | /// Data that is local to the event loop. |
| 38 | pub const ZigCompiler = struct { | 38 | pub const ZigCompiler = struct { |
| 39 | loop: *event.Loop, | 39 | loop: *event.Loop, |
| 40 | llvm_handle_pool: std.atomic.Stack(llvm.ContextRef), | 40 | llvm_handle_pool: std.atomic.Stack(*llvm.Context), |
| 41 | lld_lock: event.Lock, | 41 | lld_lock: event.Lock, |
| 42 | 42 | ||
| 43 | /// TODO pool these so that it doesn't have to lock | 43 | /// TODO pool these so that it doesn't have to lock |
| ... | @@ -60,7 +60,7 @@ pub const ZigCompiler = struct { | ... | @@ -60,7 +60,7 @@ pub const ZigCompiler = struct { |
| 60 | return ZigCompiler{ | 60 | return ZigCompiler{ |
| 61 | .loop = loop, | 61 | .loop = loop, |
| 62 | .lld_lock = event.Lock.init(loop), | 62 | .lld_lock = event.Lock.init(loop), |
| 63 | .llvm_handle_pool = std.atomic.Stack(llvm.ContextRef).init(), | 63 | .llvm_handle_pool = std.atomic.Stack(*llvm.Context).init(), |
| 64 | .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)), | 64 | .prng = event.Locked(std.rand.DefaultPrng).init(loop, std.rand.DefaultPrng.init(seed)), |
| 65 | .native_libc = event.Future(LibCInstallation).init(loop), | 65 | .native_libc = event.Future(LibCInstallation).init(loop), |
| 66 | }; | 66 | }; |
| ... | @@ -70,7 +70,7 @@ pub const ZigCompiler = struct { | ... | @@ -70,7 +70,7 @@ pub const ZigCompiler = struct { |
| 70 | fn deinit(self: *ZigCompiler) void { | 70 | fn deinit(self: *ZigCompiler) void { |
| 71 | self.lld_lock.deinit(); | 71 | self.lld_lock.deinit(); |
| 72 | while (self.llvm_handle_pool.pop()) |node| { | 72 | while (self.llvm_handle_pool.pop()) |node| { |
| 73 | c.LLVMContextDispose(node.data); | 73 | llvm.ContextDispose(node.data); |
| 74 | self.loop.allocator.destroy(node); | 74 | self.loop.allocator.destroy(node); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| ... | @@ -80,11 +80,11 @@ pub const ZigCompiler = struct { | ... | @@ -80,11 +80,11 @@ pub const ZigCompiler = struct { |
| 80 | pub fn getAnyLlvmContext(self: *ZigCompiler) !LlvmHandle { | 80 | pub fn getAnyLlvmContext(self: *ZigCompiler) !LlvmHandle { |
| 81 | if (self.llvm_handle_pool.pop()) |node| return LlvmHandle{ .node = node }; | 81 | if (self.llvm_handle_pool.pop()) |node| return LlvmHandle{ .node = node }; |
| 82 | 82 | ||
| 83 | const context_ref = c.LLVMContextCreate() orelse return error.OutOfMemory; | 83 | const context_ref = llvm.ContextCreate() orelse return error.OutOfMemory; |
| 84 | errdefer c.LLVMContextDispose(context_ref); | 84 | errdefer llvm.ContextDispose(context_ref); |
| 85 | 85 | ||
| 86 | const node = try self.loop.allocator.create(std.atomic.Stack(llvm.ContextRef).Node); | 86 | const node = try self.loop.allocator.create(std.atomic.Stack(*llvm.Context).Node); |
| 87 | node.* = std.atomic.Stack(llvm.ContextRef).Node{ | 87 | node.* = std.atomic.Stack(*llvm.Context).Node{ |
| 88 | .next = undefined, | 88 | .next = undefined, |
| 89 | .data = context_ref, | 89 | .data = context_ref, |
| 90 | }; | 90 | }; |
| ... | @@ -114,7 +114,7 @@ pub const ZigCompiler = struct { | ... | @@ -114,7 +114,7 @@ pub const ZigCompiler = struct { |
| 114 | }; | 114 | }; |
| 115 | 115 | ||
| 116 | pub const LlvmHandle = struct { | 116 | pub const LlvmHandle = struct { |
| 117 | node: *std.atomic.Stack(llvm.ContextRef).Node, | 117 | node: *std.atomic.Stack(*llvm.Context).Node, |
| 118 | 118 | ||
| 119 | pub fn release(self: LlvmHandle, zig_compiler: *ZigCompiler) void { | 119 | pub fn release(self: LlvmHandle, zig_compiler: *ZigCompiler) void { |
| 120 | zig_compiler.llvm_handle_pool.push(self.node); | 120 | zig_compiler.llvm_handle_pool.push(self.node); |
| ... | @@ -128,7 +128,7 @@ pub const Compilation = struct { | ... | @@ -128,7 +128,7 @@ pub const Compilation = struct { |
| 128 | llvm_triple: Buffer, | 128 | llvm_triple: Buffer, |
| 129 | root_src_path: ?[]const u8, | 129 | root_src_path: ?[]const u8, |
| 130 | target: Target, | 130 | target: Target, |
| 131 | llvm_target: llvm.TargetRef, | 131 | llvm_target: *llvm.Target, |
| 132 | build_mode: builtin.Mode, | 132 | build_mode: builtin.Mode, |
| 133 | zig_lib_dir: []const u8, | 133 | zig_lib_dir: []const u8, |
| 134 | zig_std_dir: []const u8, | 134 | zig_std_dir: []const u8, |
| ... | @@ -212,8 +212,8 @@ pub const Compilation = struct { | ... | @@ -212,8 +212,8 @@ pub const Compilation = struct { |
| 212 | false_value: *Value.Bool, | 212 | false_value: *Value.Bool, |
| 213 | noreturn_value: *Value.NoReturn, | 213 | noreturn_value: *Value.NoReturn, |
| 214 | 214 | ||
| 215 | target_machine: llvm.TargetMachineRef, | 215 | target_machine: *llvm.TargetMachine, |
| 216 | target_data_ref: llvm.TargetDataRef, | 216 | target_data_ref: *llvm.TargetData, |
| 217 | target_layout_str: [*]u8, | 217 | target_layout_str: [*]u8, |
| 218 | target_ptr_bits: u32, | 218 | target_ptr_bits: u32, |
| 219 | 219 |
src-self-hosted/ir.zig+10-10| ... | @@ -67,7 +67,7 @@ pub const Inst = struct { | ... | @@ -67,7 +67,7 @@ pub const Inst = struct { |
| 67 | parent: ?*Inst, | 67 | parent: ?*Inst, |
| 68 | 68 | ||
| 69 | /// populated durign codegen | 69 | /// populated durign codegen |
| 70 | llvm_value: ?llvm.ValueRef, | 70 | llvm_value: ?*llvm.Value, |
| 71 | 71 | ||
| 72 | pub fn cast(base: *Inst, comptime T: type) ?*T { | 72 | pub fn cast(base: *Inst, comptime T: type) ?*T { |
| 73 | if (base.id == comptime typeToId(T)) { | 73 | if (base.id == comptime typeToId(T)) { |
| ... | @@ -129,7 +129,7 @@ pub const Inst = struct { | ... | @@ -129,7 +129,7 @@ pub const Inst = struct { |
| 129 | } | 129 | } |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | pub fn render(base: *Inst, ofile: *ObjectFile, fn_val: *Value.Fn) (error{OutOfMemory}!?llvm.ValueRef) { | 132 | pub fn render(base: *Inst, ofile: *ObjectFile, fn_val: *Value.Fn) (error{OutOfMemory}!?*llvm.Value) { |
| 133 | switch (base.id) { | 133 | switch (base.id) { |
| 134 | Id.Return => return @fieldParentPtr(Return, "base", base).render(ofile, fn_val), | 134 | Id.Return => return @fieldParentPtr(Return, "base", base).render(ofile, fn_val), |
| 135 | Id.Const => return @fieldParentPtr(Const, "base", base).render(ofile, fn_val), | 135 | Id.Const => return @fieldParentPtr(Const, "base", base).render(ofile, fn_val), |
| ... | @@ -313,10 +313,10 @@ pub const Inst = struct { | ... | @@ -313,10 +313,10 @@ pub const Inst = struct { |
| 313 | return new_inst; | 313 | return new_inst; |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | pub fn render(self: *Call, ofile: *ObjectFile, fn_val: *Value.Fn) !?llvm.ValueRef { | 316 | pub fn render(self: *Call, ofile: *ObjectFile, fn_val: *Value.Fn) !?*llvm.Value { |
| 317 | const fn_ref = self.params.fn_ref.llvm_value.?; | 317 | const fn_ref = self.params.fn_ref.llvm_value.?; |
| 318 | 318 | ||
| 319 | const args = try ofile.arena.alloc(llvm.ValueRef, self.params.args.len); | 319 | const args = try ofile.arena.alloc(*llvm.Value, self.params.args.len); |
| 320 | for (self.params.args) |arg, i| { | 320 | for (self.params.args) |arg, i| { |
| 321 | args[i] = arg.llvm_value.?; | 321 | args[i] = arg.llvm_value.?; |
| 322 | } | 322 | } |
| ... | @@ -360,7 +360,7 @@ pub const Inst = struct { | ... | @@ -360,7 +360,7 @@ pub const Inst = struct { |
| 360 | return new_inst; | 360 | return new_inst; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | pub fn render(self: *Const, ofile: *ObjectFile, fn_val: *Value.Fn) !?llvm.ValueRef { | 363 | pub fn render(self: *Const, ofile: *ObjectFile, fn_val: *Value.Fn) !?*llvm.Value { |
| 364 | return self.base.val.KnownValue.getLlvmConst(ofile); | 364 | return self.base.val.KnownValue.getLlvmConst(ofile); |
| 365 | } | 365 | } |
| 366 | }; | 366 | }; |
| ... | @@ -392,7 +392,7 @@ pub const Inst = struct { | ... | @@ -392,7 +392,7 @@ pub const Inst = struct { |
| 392 | return ira.irb.build(Return, self.base.scope, self.base.span, Params{ .return_value = casted_value }); | 392 | return ira.irb.build(Return, self.base.scope, self.base.span, Params{ .return_value = casted_value }); |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | pub fn render(self: *Return, ofile: *ObjectFile, fn_val: *Value.Fn) !?llvm.ValueRef { | 395 | pub fn render(self: *Return, ofile: *ObjectFile, fn_val: *Value.Fn) !?*llvm.Value { |
| 396 | const value = self.params.return_value.llvm_value; | 396 | const value = self.params.return_value.llvm_value; |
| 397 | const return_type = self.params.return_value.getKnownType(); | 397 | const return_type = self.params.return_value.getKnownType(); |
| 398 | 398 | ||
| ... | @@ -540,7 +540,7 @@ pub const Inst = struct { | ... | @@ -540,7 +540,7 @@ pub const Inst = struct { |
| 540 | } | 540 | } |
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | pub fn render(self: *VarPtr, ofile: *ObjectFile, fn_val: *Value.Fn) llvm.ValueRef { | 543 | pub fn render(self: *VarPtr, ofile: *ObjectFile, fn_val: *Value.Fn) *llvm.Value { |
| 544 | switch (self.params.var_scope.data) { | 544 | switch (self.params.var_scope.data) { |
| 545 | Scope.Var.Data.Const => unreachable, // turned into Inst.Const in analyze pass | 545 | Scope.Var.Data.Const => unreachable, // turned into Inst.Const in analyze pass |
| 546 | Scope.Var.Data.Param => |param| return param.llvm_value, | 546 | Scope.Var.Data.Param => |param| return param.llvm_value, |
| ... | @@ -596,7 +596,7 @@ pub const Inst = struct { | ... | @@ -596,7 +596,7 @@ pub const Inst = struct { |
| 596 | return new_inst; | 596 | return new_inst; |
| 597 | } | 597 | } |
| 598 | 598 | ||
| 599 | pub fn render(self: *LoadPtr, ofile: *ObjectFile, fn_val: *Value.Fn) !?llvm.ValueRef { | 599 | pub fn render(self: *LoadPtr, ofile: *ObjectFile, fn_val: *Value.Fn) !?*llvm.Value { |
| 600 | const child_type = self.base.getKnownType(); | 600 | const child_type = self.base.getKnownType(); |
| 601 | if (!child_type.hasBits()) { | 601 | if (!child_type.hasBits()) { |
| 602 | return null; | 602 | return null; |
| ... | @@ -935,8 +935,8 @@ pub const BasicBlock = struct { | ... | @@ -935,8 +935,8 @@ pub const BasicBlock = struct { |
| 935 | ref_instruction: ?*Inst, | 935 | ref_instruction: ?*Inst, |
| 936 | 936 | ||
| 937 | /// for codegen | 937 | /// for codegen |
| 938 | llvm_block: llvm.BasicBlockRef, | 938 | llvm_block: *llvm.BasicBlock, |
| 939 | llvm_exit_block: llvm.BasicBlockRef, | 939 | llvm_exit_block: *llvm.BasicBlock, |
| 940 | 940 | ||
| 941 | /// the basic block that is derived from this one in analysis | 941 | /// the basic block that is derived from this one in analysis |
| 942 | child: ?*BasicBlock, | 942 | child: ?*BasicBlock, |
src-self-hosted/llvm.zig+129-52| ... | @@ -11,45 +11,31 @@ const assert = @import("std").debug.assert; | ... | @@ -11,45 +11,31 @@ const assert = @import("std").debug.assert; |
| 11 | pub const AttributeIndex = c_uint; | 11 | pub const AttributeIndex = c_uint; |
| 12 | pub const Bool = c_int; | 12 | pub const Bool = c_int; |
| 13 | 13 | ||
| 14 | pub const BuilderRef = removeNullability(c.LLVMBuilderRef); | 14 | pub const Builder = c.LLVMBuilderRef.Child; |
| 15 | pub const ContextRef = removeNullability(c.LLVMContextRef); | 15 | pub const Context = c.LLVMContextRef.Child; |
| 16 | pub const ModuleRef = removeNullability(c.LLVMModuleRef); | 16 | pub const Module = c.LLVMModuleRef.Child; |
| 17 | pub const ValueRef = removeNullability(c.LLVMValueRef); | 17 | pub const Value = c.LLVMValueRef.Child; |
| 18 | pub const TypeRef = removeNullability(c.LLVMTypeRef); | 18 | pub const Type = c.LLVMTypeRef.Child; |
| 19 | pub const BasicBlockRef = removeNullability(c.LLVMBasicBlockRef); | 19 | pub const BasicBlock = c.LLVMBasicBlockRef.Child; |
| 20 | pub const AttributeRef = removeNullability(c.LLVMAttributeRef); | 20 | pub const Attribute = c.LLVMAttributeRef.Child; |
| 21 | pub const TargetRef = removeNullability(c.LLVMTargetRef); | 21 | pub const Target = c.LLVMTargetRef.Child; |
| 22 | pub const TargetMachineRef = removeNullability(c.LLVMTargetMachineRef); | 22 | pub const TargetMachine = c.LLVMTargetMachineRef.Child; |
| 23 | pub const TargetDataRef = removeNullability(c.LLVMTargetDataRef); | 23 | pub const TargetData = c.LLVMTargetDataRef.Child; |
| 24 | pub const DIBuilder = c.ZigLLVMDIBuilder; | 24 | pub const DIBuilder = c.ZigLLVMDIBuilder; |
| 25 | pub const DIFile = c.ZigLLVMDIFile; | ||
| 26 | pub const DICompileUnit = c.ZigLLVMDICompileUnit; | ||
| 25 | 27 | ||
| 26 | pub const ABIAlignmentOfType = c.LLVMABIAlignmentOfType; | 28 | pub const ABIAlignmentOfType = c.LLVMABIAlignmentOfType; |
| 27 | pub const AddAttributeAtIndex = c.LLVMAddAttributeAtIndex; | 29 | pub const AddAttributeAtIndex = c.LLVMAddAttributeAtIndex; |
| 28 | pub const AddFunction = c.LLVMAddFunction; | ||
| 29 | pub const AddGlobal = c.LLVMAddGlobal; | ||
| 30 | pub const AddModuleCodeViewFlag = c.ZigLLVMAddModuleCodeViewFlag; | 30 | pub const AddModuleCodeViewFlag = c.ZigLLVMAddModuleCodeViewFlag; |
| 31 | pub const AddModuleDebugInfoFlag = c.ZigLLVMAddModuleDebugInfoFlag; | 31 | pub const AddModuleDebugInfoFlag = c.ZigLLVMAddModuleDebugInfoFlag; |
| 32 | pub const ArrayType = c.LLVMArrayType; | ||
| 33 | pub const BuildLoad = c.LLVMBuildLoad; | ||
| 34 | pub const ClearCurrentDebugLocation = c.ZigLLVMClearCurrentDebugLocation; | 32 | pub const ClearCurrentDebugLocation = c.ZigLLVMClearCurrentDebugLocation; |
| 35 | pub const ConstAllOnes = c.LLVMConstAllOnes; | 33 | pub const ConstAllOnes = c.LLVMConstAllOnes; |
| 36 | pub const ConstArray = c.LLVMConstArray; | 34 | pub const ConstArray = c.LLVMConstArray; |
| 37 | pub const ConstBitCast = c.LLVMConstBitCast; | 35 | pub const ConstBitCast = c.LLVMConstBitCast; |
| 38 | pub const ConstInt = c.LLVMConstInt; | ||
| 39 | pub const ConstIntOfArbitraryPrecision = c.LLVMConstIntOfArbitraryPrecision; | 36 | pub const ConstIntOfArbitraryPrecision = c.LLVMConstIntOfArbitraryPrecision; |
| 40 | pub const ConstNeg = c.LLVMConstNeg; | 37 | pub const ConstNeg = c.LLVMConstNeg; |
| 41 | pub const ConstNull = c.LLVMConstNull; | ||
| 42 | pub const ConstStringInContext = c.LLVMConstStringInContext; | ||
| 43 | pub const ConstStructInContext = c.LLVMConstStructInContext; | 38 | pub const ConstStructInContext = c.LLVMConstStructInContext; |
| 44 | pub const CopyStringRepOfTargetData = c.LLVMCopyStringRepOfTargetData; | ||
| 45 | pub const CreateBuilderInContext = c.LLVMCreateBuilderInContext; | ||
| 46 | pub const CreateCompileUnit = c.ZigLLVMCreateCompileUnit; | ||
| 47 | pub const CreateDIBuilder = c.ZigLLVMCreateDIBuilder; | ||
| 48 | pub const CreateEnumAttribute = c.LLVMCreateEnumAttribute; | ||
| 49 | pub const CreateFile = c.ZigLLVMCreateFile; | ||
| 50 | pub const CreateStringAttribute = c.LLVMCreateStringAttribute; | ||
| 51 | pub const CreateTargetDataLayout = c.LLVMCreateTargetDataLayout; | ||
| 52 | pub const CreateTargetMachine = c.LLVMCreateTargetMachine; | ||
| 53 | pub const DIBuilderFinalize = c.ZigLLVMDIBuilderFinalize; | 39 | pub const DIBuilderFinalize = c.ZigLLVMDIBuilderFinalize; |
| 54 | pub const DisposeBuilder = c.LLVMDisposeBuilder; | 40 | pub const DisposeBuilder = c.LLVMDisposeBuilder; |
| 55 | pub const DisposeDIBuilder = c.ZigLLVMDisposeDIBuilder; | 41 | pub const DisposeDIBuilder = c.ZigLLVMDisposeDIBuilder; |
| ... | @@ -62,9 +48,7 @@ pub const DumpModule = c.LLVMDumpModule; | ... | @@ -62,9 +48,7 @@ pub const DumpModule = c.LLVMDumpModule; |
| 62 | pub const FP128TypeInContext = c.LLVMFP128TypeInContext; | 48 | pub const FP128TypeInContext = c.LLVMFP128TypeInContext; |
| 63 | pub const FloatTypeInContext = c.LLVMFloatTypeInContext; | 49 | pub const FloatTypeInContext = c.LLVMFloatTypeInContext; |
| 64 | pub const GetEnumAttributeKindForName = c.LLVMGetEnumAttributeKindForName; | 50 | pub const GetEnumAttributeKindForName = c.LLVMGetEnumAttributeKindForName; |
| 65 | pub const GetHostCPUName = c.ZigLLVMGetHostCPUName; | ||
| 66 | pub const GetMDKindIDInContext = c.LLVMGetMDKindIDInContext; | 51 | pub const GetMDKindIDInContext = c.LLVMGetMDKindIDInContext; |
| 67 | pub const GetNativeFeatures = c.ZigLLVMGetNativeFeatures; | ||
| 68 | pub const GetUndef = c.LLVMGetUndef; | 52 | pub const GetUndef = c.LLVMGetUndef; |
| 69 | pub const HalfTypeInContext = c.LLVMHalfTypeInContext; | 53 | pub const HalfTypeInContext = c.LLVMHalfTypeInContext; |
| 70 | pub const InitializeAllAsmParsers = c.LLVMInitializeAllAsmParsers; | 54 | pub const InitializeAllAsmParsers = c.LLVMInitializeAllAsmParsers; |
| ... | @@ -81,14 +65,11 @@ pub const Int64TypeInContext = c.LLVMInt64TypeInContext; | ... | @@ -81,14 +65,11 @@ pub const Int64TypeInContext = c.LLVMInt64TypeInContext; |
| 81 | pub const Int8TypeInContext = c.LLVMInt8TypeInContext; | 65 | pub const Int8TypeInContext = c.LLVMInt8TypeInContext; |
| 82 | pub const IntPtrTypeForASInContext = c.LLVMIntPtrTypeForASInContext; | 66 | pub const IntPtrTypeForASInContext = c.LLVMIntPtrTypeForASInContext; |
| 83 | pub const IntPtrTypeInContext = c.LLVMIntPtrTypeInContext; | 67 | pub const IntPtrTypeInContext = c.LLVMIntPtrTypeInContext; |
| 84 | pub const IntTypeInContext = c.LLVMIntTypeInContext; | ||
| 85 | pub const LabelTypeInContext = c.LLVMLabelTypeInContext; | 68 | pub const LabelTypeInContext = c.LLVMLabelTypeInContext; |
| 86 | pub const MDNodeInContext = c.LLVMMDNodeInContext; | 69 | pub const MDNodeInContext = c.LLVMMDNodeInContext; |
| 87 | pub const MDStringInContext = c.LLVMMDStringInContext; | 70 | pub const MDStringInContext = c.LLVMMDStringInContext; |
| 88 | pub const MetadataTypeInContext = c.LLVMMetadataTypeInContext; | 71 | pub const MetadataTypeInContext = c.LLVMMetadataTypeInContext; |
| 89 | pub const ModuleCreateWithNameInContext = c.LLVMModuleCreateWithNameInContext; | ||
| 90 | pub const PPCFP128TypeInContext = c.LLVMPPCFP128TypeInContext; | 72 | pub const PPCFP128TypeInContext = c.LLVMPPCFP128TypeInContext; |
| 91 | pub const PointerType = c.LLVMPointerType; | ||
| 92 | pub const SetAlignment = c.LLVMSetAlignment; | 73 | pub const SetAlignment = c.LLVMSetAlignment; |
| 93 | pub const SetDataLayout = c.LLVMSetDataLayout; | 74 | pub const SetDataLayout = c.LLVMSetDataLayout; |
| 94 | pub const SetGlobalConstant = c.LLVMSetGlobalConstant; | 75 | pub const SetGlobalConstant = c.LLVMSetGlobalConstant; |
| ... | @@ -99,50 +80,146 @@ pub const SetUnnamedAddr = c.LLVMSetUnnamedAddr; | ... | @@ -99,50 +80,146 @@ pub const SetUnnamedAddr = c.LLVMSetUnnamedAddr; |
| 99 | pub const SetVolatile = c.LLVMSetVolatile; | 80 | pub const SetVolatile = c.LLVMSetVolatile; |
| 100 | pub const StructTypeInContext = c.LLVMStructTypeInContext; | 81 | pub const StructTypeInContext = c.LLVMStructTypeInContext; |
| 101 | pub const TokenTypeInContext = c.LLVMTokenTypeInContext; | 82 | pub const TokenTypeInContext = c.LLVMTokenTypeInContext; |
| 102 | pub const VoidTypeInContext = c.LLVMVoidTypeInContext; | ||
| 103 | pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext; | 83 | pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext; |
| 104 | pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext; | 84 | pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext; |
| 105 | 85 | ||
| 86 | pub const AddGlobal = LLVMAddGlobal; | ||
| 87 | extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*]const u8) ?*Value; | ||
| 88 | |||
| 89 | pub const ConstStringInContext = LLVMConstStringInContext; | ||
| 90 | extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value; | ||
| 91 | |||
| 92 | pub const ConstInt = LLVMConstInt; | ||
| 93 | extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value; | ||
| 94 | |||
| 95 | pub const BuildLoad = LLVMBuildLoad; | ||
| 96 | extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*]const u8) ?*Value; | ||
| 97 | |||
| 98 | pub const ConstNull = LLVMConstNull; | ||
| 99 | extern fn LLVMConstNull(Ty: *Type) ?*Value; | ||
| 100 | |||
| 101 | pub const CreateStringAttribute = LLVMCreateStringAttribute; | ||
| 102 | extern fn LLVMCreateStringAttribute( | ||
| 103 | C: *Context, | ||
| 104 | K: [*]const u8, | ||
| 105 | KLength: c_uint, | ||
| 106 | V: [*]const u8, | ||
| 107 | VLength: c_uint, | ||
| 108 | ) ?*Attribute; | ||
| 109 | |||
| 110 | pub const CreateEnumAttribute = LLVMCreateEnumAttribute; | ||
| 111 | extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute; | ||
| 112 | |||
| 113 | pub const AddFunction = LLVMAddFunction; | ||
| 114 | extern fn LLVMAddFunction(M: *Module, Name: [*]const u8, FunctionTy: *Type) ?*Value; | ||
| 115 | |||
| 116 | pub const CreateCompileUnit = ZigLLVMCreateCompileUnit; | ||
| 117 | extern fn ZigLLVMCreateCompileUnit( | ||
| 118 | dibuilder: *DIBuilder, | ||
| 119 | lang: c_uint, | ||
| 120 | difile: *DIFile, | ||
| 121 | producer: [*]const u8, | ||
| 122 | is_optimized: bool, | ||
| 123 | flags: [*]const u8, | ||
| 124 | runtime_version: c_uint, | ||
| 125 | split_name: [*]const u8, | ||
| 126 | dwo_id: u64, | ||
| 127 | emit_debug_info: bool, | ||
| 128 | ) ?*DICompileUnit; | ||
| 129 | |||
| 130 | pub const CreateFile = ZigLLVMCreateFile; | ||
| 131 | extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*]const u8, directory: [*]const u8) ?*DIFile; | ||
| 132 | |||
| 133 | pub const ArrayType = LLVMArrayType; | ||
| 134 | extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type; | ||
| 135 | |||
| 136 | pub const CreateDIBuilder = ZigLLVMCreateDIBuilder; | ||
| 137 | extern fn ZigLLVMCreateDIBuilder(module: *Module, allow_unresolved: bool) ?*DIBuilder; | ||
| 138 | |||
| 139 | pub const PointerType = LLVMPointerType; | ||
| 140 | extern fn LLVMPointerType(ElementType: *Type, AddressSpace: c_uint) ?*Type; | ||
| 141 | |||
| 142 | pub const CreateBuilderInContext = LLVMCreateBuilderInContext; | ||
| 143 | extern fn LLVMCreateBuilderInContext(C: *Context) ?*Builder; | ||
| 144 | |||
| 145 | pub const IntTypeInContext = LLVMIntTypeInContext; | ||
| 146 | extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type; | ||
| 147 | |||
| 148 | pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext; | ||
| 149 | extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*]const u8, C: *Context) ?*Module; | ||
| 150 | |||
| 151 | pub const VoidTypeInContext = LLVMVoidTypeInContext; | ||
| 152 | extern fn LLVMVoidTypeInContext(C: *Context) ?*Type; | ||
| 153 | |||
| 154 | pub const ContextCreate = LLVMContextCreate; | ||
| 155 | extern fn LLVMContextCreate() ?*Context; | ||
| 156 | |||
| 157 | pub const ContextDispose = LLVMContextDispose; | ||
| 158 | extern fn LLVMContextDispose(C: *Context) void; | ||
| 159 | |||
| 160 | pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData; | ||
| 161 | extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*]u8; | ||
| 162 | |||
| 163 | pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout; | ||
| 164 | extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData; | ||
| 165 | |||
| 166 | pub const CreateTargetMachine = LLVMCreateTargetMachine; | ||
| 167 | extern fn LLVMCreateTargetMachine( | ||
| 168 | T: *Target, | ||
| 169 | Triple: [*]const u8, | ||
| 170 | CPU: [*]const u8, | ||
| 171 | Features: [*]const u8, | ||
| 172 | Level: CodeGenOptLevel, | ||
| 173 | Reloc: RelocMode, | ||
| 174 | CodeModel: CodeModel, | ||
| 175 | ) ?*TargetMachine; | ||
| 176 | |||
| 177 | pub const GetHostCPUName = LLVMGetHostCPUName; | ||
| 178 | extern fn LLVMGetHostCPUName() ?[*]u8; | ||
| 179 | |||
| 180 | pub const GetNativeFeatures = ZigLLVMGetNativeFeatures; | ||
| 181 | extern fn ZigLLVMGetNativeFeatures() ?[*]u8; | ||
| 182 | |||
| 106 | pub const GetElementType = LLVMGetElementType; | 183 | pub const GetElementType = LLVMGetElementType; |
| 107 | extern fn LLVMGetElementType(Ty: TypeRef) TypeRef; | 184 | extern fn LLVMGetElementType(Ty: *Type) *Type; |
| 108 | 185 | ||
| 109 | pub const TypeOf = LLVMTypeOf; | 186 | pub const TypeOf = LLVMTypeOf; |
| 110 | extern fn LLVMTypeOf(Val: ValueRef) TypeRef; | 187 | extern fn LLVMTypeOf(Val: *Value) *Type; |
| 111 | 188 | ||
| 112 | pub const BuildStore = LLVMBuildStore; | 189 | pub const BuildStore = LLVMBuildStore; |
| 113 | extern fn LLVMBuildStore(arg0: BuilderRef, Val: ValueRef, Ptr: ValueRef) ?ValueRef; | 190 | extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value; |
| 114 | 191 | ||
| 115 | pub const BuildAlloca = LLVMBuildAlloca; | 192 | pub const BuildAlloca = LLVMBuildAlloca; |
| 116 | extern fn LLVMBuildAlloca(arg0: BuilderRef, Ty: TypeRef, Name: ?[*]const u8) ?ValueRef; | 193 | extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*]const u8) ?*Value; |
| 117 | 194 | ||
| 118 | pub const ConstInBoundsGEP = LLVMConstInBoundsGEP; | 195 | pub const ConstInBoundsGEP = LLVMConstInBoundsGEP; |
| 119 | pub extern fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, ConstantIndices: [*]ValueRef, NumIndices: c_uint) ?ValueRef; | 196 | pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value; |
| 120 | 197 | ||
| 121 | pub const GetTargetFromTriple = LLVMGetTargetFromTriple; | 198 | pub const GetTargetFromTriple = LLVMGetTargetFromTriple; |
| 122 | extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: *TargetRef, ErrorMessage: ?*[*]u8) Bool; | 199 | extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: **Target, ErrorMessage: ?*[*]u8) Bool; |
| 123 | 200 | ||
| 124 | pub const VerifyModule = LLVMVerifyModule; | 201 | pub const VerifyModule = LLVMVerifyModule; |
| 125 | extern fn LLVMVerifyModule(M: ModuleRef, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool; | 202 | extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool; |
| 126 | 203 | ||
| 127 | pub const GetInsertBlock = LLVMGetInsertBlock; | 204 | pub const GetInsertBlock = LLVMGetInsertBlock; |
| 128 | extern fn LLVMGetInsertBlock(Builder: BuilderRef) BasicBlockRef; | 205 | extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock; |
| 129 | 206 | ||
| 130 | pub const FunctionType = LLVMFunctionType; | 207 | pub const FunctionType = LLVMFunctionType; |
| 131 | extern fn LLVMFunctionType( | 208 | extern fn LLVMFunctionType( |
| 132 | ReturnType: TypeRef, | 209 | ReturnType: *Type, |
| 133 | ParamTypes: [*]TypeRef, | 210 | ParamTypes: [*]*Type, |
| 134 | ParamCount: c_uint, | 211 | ParamCount: c_uint, |
| 135 | IsVarArg: Bool, | 212 | IsVarArg: Bool, |
| 136 | ) ?TypeRef; | 213 | ) ?*Type; |
| 137 | 214 | ||
| 138 | pub const GetParam = LLVMGetParam; | 215 | pub const GetParam = LLVMGetParam; |
| 139 | extern fn LLVMGetParam(Fn: ValueRef, Index: c_uint) ValueRef; | 216 | extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value; |
| 140 | 217 | ||
| 141 | pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext; | 218 | pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext; |
| 142 | extern fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef, Name: [*]const u8) ?BasicBlockRef; | 219 | extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*]const u8) ?*BasicBlock; |
| 143 | 220 | ||
| 144 | pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd; | 221 | pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd; |
| 145 | extern fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef) void; | 222 | extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void; |
| 146 | 223 | ||
| 147 | pub const AbortProcessAction = VerifierFailureAction.LLVMAbortProcessAction; | 224 | pub const AbortProcessAction = VerifierFailureAction.LLVMAbortProcessAction; |
| 148 | pub const PrintMessageAction = VerifierFailureAction.LLVMPrintMessageAction; | 225 | pub const PrintMessageAction = VerifierFailureAction.LLVMPrintMessageAction; |
| ... | @@ -190,17 +267,17 @@ pub const FnInline = extern enum { | ... | @@ -190,17 +267,17 @@ pub const FnInline = extern enum { |
| 190 | }; | 267 | }; |
| 191 | 268 | ||
| 192 | fn removeNullability(comptime T: type) type { | 269 | fn removeNullability(comptime T: type) type { |
| 193 | comptime assert(@typeId(T) == builtin.TypeId.Optional); | 270 | comptime assert(@typeInfo(T).Pointer.size == @import("builtin").TypeInfo.Pointer.Size.C); |
| 194 | return T.Child; | 271 | return *T.Child; |
| 195 | } | 272 | } |
| 196 | 273 | ||
| 197 | pub const BuildRet = LLVMBuildRet; | 274 | pub const BuildRet = LLVMBuildRet; |
| 198 | extern fn LLVMBuildRet(arg0: BuilderRef, V: ?ValueRef) ?ValueRef; | 275 | extern fn LLVMBuildRet(arg0: *Builder, V: ?*Value) ?*Value; |
| 199 | 276 | ||
| 200 | pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile; | 277 | pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile; |
| 201 | extern fn ZigLLVMTargetMachineEmitToFile( | 278 | extern fn ZigLLVMTargetMachineEmitToFile( |
| 202 | targ_machine_ref: TargetMachineRef, | 279 | targ_machine_ref: *TargetMachine, |
| 203 | module_ref: ModuleRef, | 280 | module_ref: *Module, |
| 204 | filename: [*]const u8, | 281 | filename: [*]const u8, |
| 205 | output_type: EmitOutputType, | 282 | output_type: EmitOutputType, |
| 206 | error_message: *[*]u8, | 283 | error_message: *[*]u8, |
| ... | @@ -209,6 +286,6 @@ extern fn ZigLLVMTargetMachineEmitToFile( | ... | @@ -209,6 +286,6 @@ extern fn ZigLLVMTargetMachineEmitToFile( |
| 209 | ) bool; | 286 | ) bool; |
| 210 | 287 | ||
| 211 | pub const BuildCall = ZigLLVMBuildCall; | 288 | pub const BuildCall = ZigLLVMBuildCall; |
| 212 | extern fn ZigLLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: [*]ValueRef, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?ValueRef; | 289 | extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?*Value; |
| 213 | 290 | ||
| 214 | pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage; | 291 | pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage; |
src-self-hosted/scope.zig+1-1| ... | @@ -362,7 +362,7 @@ pub const Scope = struct { | ... | @@ -362,7 +362,7 @@ pub const Scope = struct { |
| 362 | pub const Param = struct { | 362 | pub const Param = struct { |
| 363 | index: usize, | 363 | index: usize, |
| 364 | typ: *Type, | 364 | typ: *Type, |
| 365 | llvm_value: llvm.ValueRef, | 365 | llvm_value: *llvm.Value, |
| 366 | }; | 366 | }; |
| 367 | 367 | ||
| 368 | pub fn createParam( | 368 | pub fn createParam( |
src-self-hosted/target.zig+2-2| ... | @@ -457,8 +457,8 @@ pub const Target = union(enum) { | ... | @@ -457,8 +457,8 @@ pub const Target = union(enum) { |
| 457 | } | 457 | } |
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | pub fn llvmTargetFromTriple(triple: std.Buffer) !llvm.TargetRef { | 460 | pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target { |
| 461 | var result: llvm.TargetRef = undefined; | 461 | var result: *llvm.Target = undefined; |
| 462 | var err_msg: [*]u8 = undefined; | 462 | var err_msg: [*]u8 = undefined; |
| 463 | if (llvm.GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) { | 463 | if (llvm.GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) { |
| 464 | std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg); | 464 | std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg); |
src-self-hosted/type.zig+21-21| ... | @@ -51,8 +51,8 @@ pub const Type = struct { | ... | @@ -51,8 +51,8 @@ pub const Type = struct { |
| 51 | pub fn getLlvmType( | 51 | pub fn getLlvmType( |
| 52 | base: *Type, | 52 | base: *Type, |
| 53 | allocator: *Allocator, | 53 | allocator: *Allocator, |
| 54 | llvm_context: llvm.ContextRef, | 54 | llvm_context: *llvm.Context, |
| 55 | ) (error{OutOfMemory}!llvm.TypeRef) { | 55 | ) (error{OutOfMemory}!*llvm.Type) { |
| 56 | switch (base.id) { | 56 | switch (base.id) { |
| 57 | Id.Struct => return @fieldParentPtr(Struct, "base", base).getLlvmType(allocator, llvm_context), | 57 | Id.Struct => return @fieldParentPtr(Struct, "base", base).getLlvmType(allocator, llvm_context), |
| 58 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmType(allocator, llvm_context), | 58 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmType(allocator, llvm_context), |
| ... | @@ -196,7 +196,7 @@ pub const Type = struct { | ... | @@ -196,7 +196,7 @@ pub const Type = struct { |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | /// If you have an llvm conext handy, you can use it here. | 198 | /// If you have an llvm conext handy, you can use it here. |
| 199 | pub async fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: llvm.ContextRef) !u32 { | 199 | pub async fn getAbiAlignmentInContext(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { |
| 200 | if (await (async base.abi_alignment.start() catch unreachable)) |ptr| return ptr.*; | 200 | if (await (async base.abi_alignment.start() catch unreachable)) |ptr| return ptr.*; |
| 201 | 201 | ||
| 202 | base.abi_alignment.data = await (async base.resolveAbiAlignment(comp, llvm_context) catch unreachable); | 202 | base.abi_alignment.data = await (async base.resolveAbiAlignment(comp, llvm_context) catch unreachable); |
| ... | @@ -205,7 +205,7 @@ pub const Type = struct { | ... | @@ -205,7 +205,7 @@ pub const Type = struct { |
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | /// Lower level function that does the work. See getAbiAlignment. | 207 | /// Lower level function that does the work. See getAbiAlignment. |
| 208 | async fn resolveAbiAlignment(base: *Type, comp: *Compilation, llvm_context: llvm.ContextRef) !u32 { | 208 | async fn resolveAbiAlignment(base: *Type, comp: *Compilation, llvm_context: *llvm.Context) !u32 { |
| 209 | const llvm_type = try base.getLlvmType(comp.gpa(), llvm_context); | 209 | const llvm_type = try base.getLlvmType(comp.gpa(), llvm_context); |
| 210 | return @intCast(u32, llvm.ABIAlignmentOfType(comp.target_data_ref, llvm_type)); | 210 | return @intCast(u32, llvm.ABIAlignmentOfType(comp.target_data_ref, llvm_type)); |
| 211 | } | 211 | } |
| ... | @@ -218,7 +218,7 @@ pub const Type = struct { | ... | @@ -218,7 +218,7 @@ pub const Type = struct { |
| 218 | comp.gpa().destroy(self); | 218 | comp.gpa().destroy(self); |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | pub fn getLlvmType(self: *Struct, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 221 | pub fn getLlvmType(self: *Struct, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 222 | @panic("TODO"); | 222 | @panic("TODO"); |
| 223 | } | 223 | } |
| 224 | }; | 224 | }; |
| ... | @@ -496,13 +496,13 @@ pub const Type = struct { | ... | @@ -496,13 +496,13 @@ pub const Type = struct { |
| 496 | comp.gpa().destroy(self); | 496 | comp.gpa().destroy(self); |
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | pub fn getLlvmType(self: *Fn, allocator: *Allocator, llvm_context: llvm.ContextRef) !llvm.TypeRef { | 499 | pub fn getLlvmType(self: *Fn, allocator: *Allocator, llvm_context: *llvm.Context) !*llvm.Type { |
| 500 | const normal = &self.key.data.Normal; | 500 | const normal = &self.key.data.Normal; |
| 501 | const llvm_return_type = switch (normal.return_type.id) { | 501 | const llvm_return_type = switch (normal.return_type.id) { |
| 502 | Type.Id.Void => llvm.VoidTypeInContext(llvm_context) orelse return error.OutOfMemory, | 502 | Type.Id.Void => llvm.VoidTypeInContext(llvm_context) orelse return error.OutOfMemory, |
| 503 | else => try normal.return_type.getLlvmType(allocator, llvm_context), | 503 | else => try normal.return_type.getLlvmType(allocator, llvm_context), |
| 504 | }; | 504 | }; |
| 505 | const llvm_param_types = try allocator.alloc(llvm.TypeRef, normal.params.len); | 505 | const llvm_param_types = try allocator.alloc(*llvm.Type, normal.params.len); |
| 506 | defer allocator.free(llvm_param_types); | 506 | defer allocator.free(llvm_param_types); |
| 507 | for (llvm_param_types) |*llvm_param_type, i| { | 507 | for (llvm_param_types) |*llvm_param_type, i| { |
| 508 | llvm_param_type.* = try normal.params[i].typ.getLlvmType(allocator, llvm_context); | 508 | llvm_param_type.* = try normal.params[i].typ.getLlvmType(allocator, llvm_context); |
| ... | @@ -559,7 +559,7 @@ pub const Type = struct { | ... | @@ -559,7 +559,7 @@ pub const Type = struct { |
| 559 | comp.gpa().destroy(self); | 559 | comp.gpa().destroy(self); |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | pub fn getLlvmType(self: *Bool, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 562 | pub fn getLlvmType(self: *Bool, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 563 | @panic("TODO"); | 563 | @panic("TODO"); |
| 564 | } | 564 | } |
| 565 | }; | 565 | }; |
| ... | @@ -658,7 +658,7 @@ pub const Type = struct { | ... | @@ -658,7 +658,7 @@ pub const Type = struct { |
| 658 | comp.gpa().destroy(self); | 658 | comp.gpa().destroy(self); |
| 659 | } | 659 | } |
| 660 | 660 | ||
| 661 | pub fn getLlvmType(self: *Int, allocator: *Allocator, llvm_context: llvm.ContextRef) !llvm.TypeRef { | 661 | pub fn getLlvmType(self: *Int, allocator: *Allocator, llvm_context: *llvm.Context) !*llvm.Type { |
| 662 | return llvm.IntTypeInContext(llvm_context, self.key.bit_count) orelse return error.OutOfMemory; | 662 | return llvm.IntTypeInContext(llvm_context, self.key.bit_count) orelse return error.OutOfMemory; |
| 663 | } | 663 | } |
| 664 | }; | 664 | }; |
| ... | @@ -670,7 +670,7 @@ pub const Type = struct { | ... | @@ -670,7 +670,7 @@ pub const Type = struct { |
| 670 | comp.gpa().destroy(self); | 670 | comp.gpa().destroy(self); |
| 671 | } | 671 | } |
| 672 | 672 | ||
| 673 | pub fn getLlvmType(self: *Float, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 673 | pub fn getLlvmType(self: *Float, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 674 | @panic("TODO"); | 674 | @panic("TODO"); |
| 675 | } | 675 | } |
| 676 | }; | 676 | }; |
| ... | @@ -836,7 +836,7 @@ pub const Type = struct { | ... | @@ -836,7 +836,7 @@ pub const Type = struct { |
| 836 | return self; | 836 | return self; |
| 837 | } | 837 | } |
| 838 | 838 | ||
| 839 | pub fn getLlvmType(self: *Pointer, allocator: *Allocator, llvm_context: llvm.ContextRef) !llvm.TypeRef { | 839 | pub fn getLlvmType(self: *Pointer, allocator: *Allocator, llvm_context: *llvm.Context) !*llvm.Type { |
| 840 | const elem_llvm_type = try self.key.child_type.getLlvmType(allocator, llvm_context); | 840 | const elem_llvm_type = try self.key.child_type.getLlvmType(allocator, llvm_context); |
| 841 | return llvm.PointerType(elem_llvm_type, 0) orelse return error.OutOfMemory; | 841 | return llvm.PointerType(elem_llvm_type, 0) orelse return error.OutOfMemory; |
| 842 | } | 842 | } |
| ... | @@ -904,7 +904,7 @@ pub const Type = struct { | ... | @@ -904,7 +904,7 @@ pub const Type = struct { |
| 904 | return self; | 904 | return self; |
| 905 | } | 905 | } |
| 906 | 906 | ||
| 907 | pub fn getLlvmType(self: *Array, allocator: *Allocator, llvm_context: llvm.ContextRef) !llvm.TypeRef { | 907 | pub fn getLlvmType(self: *Array, allocator: *Allocator, llvm_context: *llvm.Context) !*llvm.Type { |
| 908 | const elem_llvm_type = try self.key.elem_type.getLlvmType(allocator, llvm_context); | 908 | const elem_llvm_type = try self.key.elem_type.getLlvmType(allocator, llvm_context); |
| 909 | return llvm.ArrayType(elem_llvm_type, @intCast(c_uint, self.key.len)) orelse return error.OutOfMemory; | 909 | return llvm.ArrayType(elem_llvm_type, @intCast(c_uint, self.key.len)) orelse return error.OutOfMemory; |
| 910 | } | 910 | } |
| ... | @@ -917,7 +917,7 @@ pub const Type = struct { | ... | @@ -917,7 +917,7 @@ pub const Type = struct { |
| 917 | comp.gpa().destroy(self); | 917 | comp.gpa().destroy(self); |
| 918 | } | 918 | } |
| 919 | 919 | ||
| 920 | pub fn getLlvmType(self: *Vector, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 920 | pub fn getLlvmType(self: *Vector, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 921 | @panic("TODO"); | 921 | @panic("TODO"); |
| 922 | } | 922 | } |
| 923 | }; | 923 | }; |
| ... | @@ -967,7 +967,7 @@ pub const Type = struct { | ... | @@ -967,7 +967,7 @@ pub const Type = struct { |
| 967 | comp.gpa().destroy(self); | 967 | comp.gpa().destroy(self); |
| 968 | } | 968 | } |
| 969 | 969 | ||
| 970 | pub fn getLlvmType(self: *Optional, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 970 | pub fn getLlvmType(self: *Optional, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 971 | @panic("TODO"); | 971 | @panic("TODO"); |
| 972 | } | 972 | } |
| 973 | }; | 973 | }; |
| ... | @@ -979,7 +979,7 @@ pub const Type = struct { | ... | @@ -979,7 +979,7 @@ pub const Type = struct { |
| 979 | comp.gpa().destroy(self); | 979 | comp.gpa().destroy(self); |
| 980 | } | 980 | } |
| 981 | 981 | ||
| 982 | pub fn getLlvmType(self: *ErrorUnion, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 982 | pub fn getLlvmType(self: *ErrorUnion, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 983 | @panic("TODO"); | 983 | @panic("TODO"); |
| 984 | } | 984 | } |
| 985 | }; | 985 | }; |
| ... | @@ -991,7 +991,7 @@ pub const Type = struct { | ... | @@ -991,7 +991,7 @@ pub const Type = struct { |
| 991 | comp.gpa().destroy(self); | 991 | comp.gpa().destroy(self); |
| 992 | } | 992 | } |
| 993 | 993 | ||
| 994 | pub fn getLlvmType(self: *ErrorSet, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 994 | pub fn getLlvmType(self: *ErrorSet, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 995 | @panic("TODO"); | 995 | @panic("TODO"); |
| 996 | } | 996 | } |
| 997 | }; | 997 | }; |
| ... | @@ -1003,7 +1003,7 @@ pub const Type = struct { | ... | @@ -1003,7 +1003,7 @@ pub const Type = struct { |
| 1003 | comp.gpa().destroy(self); | 1003 | comp.gpa().destroy(self); |
| 1004 | } | 1004 | } |
| 1005 | 1005 | ||
| 1006 | pub fn getLlvmType(self: *Enum, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 1006 | pub fn getLlvmType(self: *Enum, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 1007 | @panic("TODO"); | 1007 | @panic("TODO"); |
| 1008 | } | 1008 | } |
| 1009 | }; | 1009 | }; |
| ... | @@ -1015,7 +1015,7 @@ pub const Type = struct { | ... | @@ -1015,7 +1015,7 @@ pub const Type = struct { |
| 1015 | comp.gpa().destroy(self); | 1015 | comp.gpa().destroy(self); |
| 1016 | } | 1016 | } |
| 1017 | 1017 | ||
| 1018 | pub fn getLlvmType(self: *Union, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 1018 | pub fn getLlvmType(self: *Union, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 1019 | @panic("TODO"); | 1019 | @panic("TODO"); |
| 1020 | } | 1020 | } |
| 1021 | }; | 1021 | }; |
| ... | @@ -1035,7 +1035,7 @@ pub const Type = struct { | ... | @@ -1035,7 +1035,7 @@ pub const Type = struct { |
| 1035 | comp.gpa().destroy(self); | 1035 | comp.gpa().destroy(self); |
| 1036 | } | 1036 | } |
| 1037 | 1037 | ||
| 1038 | pub fn getLlvmType(self: *BoundFn, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 1038 | pub fn getLlvmType(self: *BoundFn, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 1039 | @panic("TODO"); | 1039 | @panic("TODO"); |
| 1040 | } | 1040 | } |
| 1041 | }; | 1041 | }; |
| ... | @@ -1055,7 +1055,7 @@ pub const Type = struct { | ... | @@ -1055,7 +1055,7 @@ pub const Type = struct { |
| 1055 | comp.gpa().destroy(self); | 1055 | comp.gpa().destroy(self); |
| 1056 | } | 1056 | } |
| 1057 | 1057 | ||
| 1058 | pub fn getLlvmType(self: *Opaque, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 1058 | pub fn getLlvmType(self: *Opaque, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 1059 | @panic("TODO"); | 1059 | @panic("TODO"); |
| 1060 | } | 1060 | } |
| 1061 | }; | 1061 | }; |
| ... | @@ -1067,7 +1067,7 @@ pub const Type = struct { | ... | @@ -1067,7 +1067,7 @@ pub const Type = struct { |
| 1067 | comp.gpa().destroy(self); | 1067 | comp.gpa().destroy(self); |
| 1068 | } | 1068 | } |
| 1069 | 1069 | ||
| 1070 | pub fn getLlvmType(self: *Promise, allocator: *Allocator, llvm_context: llvm.ContextRef) llvm.TypeRef { | 1070 | pub fn getLlvmType(self: *Promise, allocator: *Allocator, llvm_context: *llvm.Context) *llvm.Type { |
| 1071 | @panic("TODO"); | 1071 | @panic("TODO"); |
| 1072 | } | 1072 | } |
| 1073 | }; | 1073 | }; |
src-self-hosted/value.zig+8-8| ... | @@ -57,7 +57,7 @@ pub const Value = struct { | ... | @@ -57,7 +57,7 @@ pub const Value = struct { |
| 57 | std.debug.warn("{}", @tagName(base.id)); | 57 | std.debug.warn("{}", @tagName(base.id)); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?llvm.ValueRef) { | 60 | pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) { |
| 61 | switch (base.id) { | 61 | switch (base.id) { |
| 62 | Id.Type => unreachable, | 62 | Id.Type => unreachable, |
| 63 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmConst(ofile), | 63 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmConst(ofile), |
| ... | @@ -153,7 +153,7 @@ pub const Value = struct { | ... | @@ -153,7 +153,7 @@ pub const Value = struct { |
| 153 | comp.gpa().destroy(self); | 153 | comp.gpa().destroy(self); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | pub fn getLlvmConst(self: *FnProto, ofile: *ObjectFile) !?llvm.ValueRef { | 156 | pub fn getLlvmConst(self: *FnProto, ofile: *ObjectFile) !?*llvm.Value { |
| 157 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); | 157 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 158 | const llvm_fn = llvm.AddFunction( | 158 | const llvm_fn = llvm.AddFunction( |
| 159 | ofile.module, | 159 | ofile.module, |
| ... | @@ -238,7 +238,7 @@ pub const Value = struct { | ... | @@ -238,7 +238,7 @@ pub const Value = struct { |
| 238 | /// We know that the function definition will end up in an .o file somewhere. | 238 | /// We know that the function definition will end up in an .o file somewhere. |
| 239 | /// Here, all we have to do is generate a global prototype. | 239 | /// Here, all we have to do is generate a global prototype. |
| 240 | /// TODO cache the prototype per ObjectFile | 240 | /// TODO cache the prototype per ObjectFile |
| 241 | pub fn getLlvmConst(self: *Fn, ofile: *ObjectFile) !?llvm.ValueRef { | 241 | pub fn getLlvmConst(self: *Fn, ofile: *ObjectFile) !?*llvm.Value { |
| 242 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); | 242 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 243 | const llvm_fn = llvm.AddFunction( | 243 | const llvm_fn = llvm.AddFunction( |
| 244 | ofile.module, | 244 | ofile.module, |
| ... | @@ -283,7 +283,7 @@ pub const Value = struct { | ... | @@ -283,7 +283,7 @@ pub const Value = struct { |
| 283 | comp.gpa().destroy(self); | 283 | comp.gpa().destroy(self); |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | pub fn getLlvmConst(self: *Bool, ofile: *ObjectFile) ?llvm.ValueRef { | 286 | pub fn getLlvmConst(self: *Bool, ofile: *ObjectFile) ?*llvm.Value { |
| 287 | const llvm_type = llvm.Int1TypeInContext(ofile.context); | 287 | const llvm_type = llvm.Int1TypeInContext(ofile.context); |
| 288 | if (self.x) { | 288 | if (self.x) { |
| 289 | return llvm.ConstAllOnes(llvm_type); | 289 | return llvm.ConstAllOnes(llvm_type); |
| ... | @@ -381,7 +381,7 @@ pub const Value = struct { | ... | @@ -381,7 +381,7 @@ pub const Value = struct { |
| 381 | comp.gpa().destroy(self); | 381 | comp.gpa().destroy(self); |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | pub fn getLlvmConst(self: *Ptr, ofile: *ObjectFile) !?llvm.ValueRef { | 384 | pub fn getLlvmConst(self: *Ptr, ofile: *ObjectFile) !?*llvm.Value { |
| 385 | const llvm_type = self.base.typ.getLlvmType(ofile.arena, ofile.context); | 385 | const llvm_type = self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 386 | // TODO carefully port the logic from codegen.cpp:gen_const_val_ptr | 386 | // TODO carefully port the logic from codegen.cpp:gen_const_val_ptr |
| 387 | switch (self.special) { | 387 | switch (self.special) { |
| ... | @@ -391,7 +391,7 @@ pub const Value = struct { | ... | @@ -391,7 +391,7 @@ pub const Value = struct { |
| 391 | const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?; | 391 | const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?; |
| 392 | const ptr_bit_count = ofile.comp.target_ptr_bits; | 392 | const ptr_bit_count = ofile.comp.target_ptr_bits; |
| 393 | const usize_llvm_type = llvm.IntTypeInContext(ofile.context, ptr_bit_count) orelse return error.OutOfMemory; | 393 | const usize_llvm_type = llvm.IntTypeInContext(ofile.context, ptr_bit_count) orelse return error.OutOfMemory; |
| 394 | const indices = []llvm.ValueRef{ | 394 | const indices = []*llvm.Value{ |
| 395 | llvm.ConstNull(usize_llvm_type) orelse return error.OutOfMemory, | 395 | llvm.ConstNull(usize_llvm_type) orelse return error.OutOfMemory, |
| 396 | llvm.ConstInt(usize_llvm_type, base_array.elem_index, 0) orelse return error.OutOfMemory, | 396 | llvm.ConstInt(usize_llvm_type, base_array.elem_index, 0) orelse return error.OutOfMemory, |
| 397 | }; | 397 | }; |
| ... | @@ -459,7 +459,7 @@ pub const Value = struct { | ... | @@ -459,7 +459,7 @@ pub const Value = struct { |
| 459 | comp.gpa().destroy(self); | 459 | comp.gpa().destroy(self); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | pub fn getLlvmConst(self: *Array, ofile: *ObjectFile) !?llvm.ValueRef { | 462 | pub fn getLlvmConst(self: *Array, ofile: *ObjectFile) !?*llvm.Value { |
| 463 | switch (self.special) { | 463 | switch (self.special) { |
| 464 | Special.Undefined => { | 464 | Special.Undefined => { |
| 465 | const llvm_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); | 465 | const llvm_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| ... | @@ -534,7 +534,7 @@ pub const Value = struct { | ... | @@ -534,7 +534,7 @@ pub const Value = struct { |
| 534 | return self; | 534 | return self; |
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | pub fn getLlvmConst(self: *Int, ofile: *ObjectFile) !?llvm.ValueRef { | 537 | pub fn getLlvmConst(self: *Int, ofile: *ObjectFile) !?*llvm.Value { |
| 538 | switch (self.base.typ.id) { | 538 | switch (self.base.typ.id) { |
| 539 | Type.Id.Int => { | 539 | Type.Id.Int => { |
| 540 | const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context); | 540 | const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
src/ir.cpp+1-1| ... | @@ -8696,7 +8696,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -8696,7 +8696,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8696 | return result; | 8696 | return result; |
| 8697 | } | 8697 | } |
| 8698 | bool ok_allows_zero = (wanted_allows_zero && | 8698 | bool ok_allows_zero = (wanted_allows_zero && |
| 8699 | (actual_allows_zero || wanted_ptr_type->data.pointer.is_const)) || | 8699 | (actual_allows_zero || !wanted_is_mutable)) || |
| 8700 | (!wanted_allows_zero && !actual_allows_zero); | 8700 | (!wanted_allows_zero && !actual_allows_zero); |
| 8701 | if (!ok_allows_zero) { | 8701 | if (!ok_allows_zero) { |
| 8702 | result.id = ConstCastResultIdBadAllowsZero; | 8702 | result.id = ConstCastResultIdBadAllowsZero; |
std/hash_map.zig+2| ... | @@ -496,6 +496,7 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type | ... | @@ -496,6 +496,7 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type |
| 496 | builtin.TypeId.Pointer => |info| switch (info.size) { | 496 | builtin.TypeId.Pointer => |info| switch (info.size) { |
| 497 | builtin.TypeInfo.Pointer.Size.One => @compileError("TODO auto hash for single item pointers"), | 497 | builtin.TypeInfo.Pointer.Size.One => @compileError("TODO auto hash for single item pointers"), |
| 498 | builtin.TypeInfo.Pointer.Size.Many => @compileError("TODO auto hash for many item pointers"), | 498 | builtin.TypeInfo.Pointer.Size.Many => @compileError("TODO auto hash for many item pointers"), |
| 499 | builtin.TypeInfo.Pointer.Size.C => @compileError("TODO auto hash C pointers"), | ||
| 499 | builtin.TypeInfo.Pointer.Size.Slice => { | 500 | builtin.TypeInfo.Pointer.Size.Slice => { |
| 500 | const interval = std.math.max(1, key.len / 256); | 501 | const interval = std.math.max(1, key.len / 256); |
| 501 | var i: usize = 0; | 502 | var i: usize = 0; |
| ... | @@ -543,6 +544,7 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool { | ... | @@ -543,6 +544,7 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool { |
| 543 | builtin.TypeId.Pointer => |info| switch (info.size) { | 544 | builtin.TypeId.Pointer => |info| switch (info.size) { |
| 544 | builtin.TypeInfo.Pointer.Size.One => @compileError("TODO auto eql for single item pointers"), | 545 | builtin.TypeInfo.Pointer.Size.One => @compileError("TODO auto eql for single item pointers"), |
| 545 | builtin.TypeInfo.Pointer.Size.Many => @compileError("TODO auto eql for many item pointers"), | 546 | builtin.TypeInfo.Pointer.Size.Many => @compileError("TODO auto eql for many item pointers"), |
| 547 | builtin.TypeInfo.Pointer.Size.C => @compileError("TODO auto eql for C pointers"), | ||
| 546 | builtin.TypeInfo.Pointer.Size.Slice => { | 548 | builtin.TypeInfo.Pointer.Size.Slice => { |
| 547 | if (a.len != b.len) return false; | 549 | if (a.len != b.len) return false; |
| 548 | for (a) |a_item, i| { | 550 | for (a) |a_item, i| { |
test/compile_errors.zig+4-4| ... | @@ -92,15 +92,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -92,15 +92,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 92 | \\ var slice: []u8 = &buf; | 92 | \\ var slice: []u8 = &buf; |
| 93 | \\ var opt_many_ptr: [*]u8 = slice.ptr; | 93 | \\ var opt_many_ptr: [*]u8 = slice.ptr; |
| 94 | \\ var ptr_opt_many_ptr = &opt_many_ptr; | 94 | \\ var ptr_opt_many_ptr = &opt_many_ptr; |
| 95 | \\ var c_ptr: [*c]const [*c]u8 = ptr_opt_many_ptr; | 95 | \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; |
| 96 | \\} | 96 | \\} |
| 97 | , | 97 | , |
| 98 | ".tmp_source.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", | 98 | ".tmp_source.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", |
| 99 | ".tmp_source.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", | 99 | ".tmp_source.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", |
| 100 | ".tmp_source.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", | 100 | ".tmp_source.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", |
| 101 | ".tmp_source.zig:13:35: error: expected type '[*c]const [*c]u8', found '*[*]u8'", | 101 | ".tmp_source.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", |
| 102 | ".tmp_source.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]u8'", | 102 | ".tmp_source.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", |
| 103 | ".tmp_source.zig:13:35: note: mutable '[*c]u8' allows illegal null values stored to type '[*]u8'", | 103 | ".tmp_source.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", |
| 104 | ); | 104 | ); |
| 105 | 105 | ||
| 106 | cases.addTest( | 106 | cases.addTest( |
test/stage1/behavior/pointers.zig+17| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const expect = std.testing.expect; | 2 | const expect = std.testing.expect; |
| 3 | const expectError = std.testing.expectError; | ||
| 3 | 4 | ||
| 4 | test "dereference pointer" { | 5 | test "dereference pointer" { |
| 5 | comptime testDerefPtr(); | 6 | comptime testDerefPtr(); |
| ... | @@ -107,3 +108,19 @@ test "implicit casting between C pointer and optional non-C pointer" { | ... | @@ -107,3 +108,19 @@ test "implicit casting between C pointer and optional non-C pointer" { |
| 107 | ptr_opt_many_ptr = c_ptr; | 108 | ptr_opt_many_ptr = c_ptr; |
| 108 | expect(ptr_opt_many_ptr.*.?[1] == 'o'); | 109 | expect(ptr_opt_many_ptr.*.?[1] == 'o'); |
| 109 | } | 110 | } |
| 111 | |||
| 112 | test "implicit cast error unions with non-optional to optional pointer" { | ||
| 113 | const S = struct { | ||
| 114 | fn doTheTest() void { | ||
| 115 | expectError(error.Fail, foo()); | ||
| 116 | } | ||
| 117 | fn foo() anyerror!?*u8 { | ||
| 118 | return bar() orelse error.Fail; | ||
| 119 | } | ||
| 120 | fn bar() ?*u8 { | ||
| 121 | return null; | ||
| 122 | } | ||
| 123 | }; | ||
| 124 | S.doTheTest(); | ||
| 125 | comptime S.doTheTest(); | ||
| 126 | } |