authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 00:56:16+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-07 10:30:47+02:00
log7000316113e44ab9c6bdacaef17915d25fb764ed
tree8b9ec784be3b1dd4def9fa15e89392145f28840b
parent9394d14815d1a3105f8ea9b3a1a73ea4bc834e7a
signaturelock-open Commit is signed but in an unrecognized format.

self hosted compiler: fix calling convention in type.zig


1 files changed, 12 insertions(+), 48 deletions(-)

src-self-hosted/type.zig+12-48
...@@ -265,16 +265,7 @@ pub const Type = struct {...@@ -265,16 +265,7 @@ pub const Type = struct {
265265
266 pub const Generic = struct {266 pub const Generic = struct {
267 param_count: usize,267 param_count: usize,
268 cc: CC,268 cc: CallingConvention,
269
270 pub const CC = union(CallingConvention) {
271 Auto,
272 C,
273 Cold,
274 Naked,
275 Stdcall,
276 Async: *Type, // allocator type
277 };
278 };269 };
279270
280 pub fn hash(self: *const Key) u32 {271 pub fn hash(self: *const Key) u32 {
...@@ -283,10 +274,7 @@ pub const Type = struct {...@@ -283,10 +274,7 @@ pub const Type = struct {
283 switch (self.data) {274 switch (self.data) {
284 Kind.Generic => |generic| {275 Kind.Generic => |generic| {
285 result +%= hashAny(generic.param_count, 1);276 result +%= hashAny(generic.param_count, 1);
286 switch (generic.cc) {277 result +%= hashAny(generic.cc, 3);
287 CallingConvention.Async => |allocator_type| result +%= hashAny(allocator_type, 2),
288 else => result +%= hashAny(CallingConvention(generic.cc), 3),
289 }
290 },278 },
291 Kind.Normal => |normal| {279 Kind.Normal => |normal| {
292 result +%= hashAny(normal.return_type, 4);280 result +%= hashAny(normal.return_type, 4);
...@@ -311,14 +299,7 @@ pub const Type = struct {...@@ -311,14 +299,7 @@ pub const Type = struct {
311 Kind.Generic => |*self_generic| {299 Kind.Generic => |*self_generic| {
312 const other_generic = &other.data.Generic;300 const other_generic = &other.data.Generic;
313 if (self_generic.param_count != other_generic.param_count) return false;301 if (self_generic.param_count != other_generic.param_count) return false;
314 if (CallingConvention(self_generic.cc) != CallingConvention(other_generic.cc)) return false;302 if (self_generic.cc != other_generic.cc) return false;
315 switch (self_generic.cc) {
316 CallingConvention.Async => |self_allocator_type| {
317 const other_allocator_type = other_generic.cc.Async;
318 if (self_allocator_type != other_allocator_type) return false;
319 },
320 else => {},
321 }
322 },303 },
323 Kind.Normal => |*self_normal| {304 Kind.Normal => |*self_normal| {
324 const other_normal = &other.data.Normal;305 const other_normal = &other.data.Normal;
...@@ -337,12 +318,7 @@ pub const Type = struct {...@@ -337,12 +318,7 @@ pub const Type = struct {
337318
338 pub fn deref(key: Key, comp: *Compilation) void {319 pub fn deref(key: Key, comp: *Compilation) void {
339 switch (key.data) {320 switch (key.data) {
340 Kind.Generic => |generic| {321 Kind.Generic => {},
341 switch (generic.cc) {
342 CallingConvention.Async => |allocator_type| allocator_type.base.deref(comp),
343 else => {},
344 }
345 },
346 Kind.Normal => |normal| {322 Kind.Normal => |normal| {
347 normal.return_type.base.deref(comp);323 normal.return_type.base.deref(comp);
348 for (normal.params) |param| {324 for (normal.params) |param| {
...@@ -354,12 +330,7 @@ pub const Type = struct {...@@ -354,12 +330,7 @@ pub const Type = struct {
354330
355 pub fn ref(key: Key) void {331 pub fn ref(key: Key) void {
356 switch (key.data) {332 switch (key.data) {
357 Kind.Generic => |generic| {333 Kind.Generic => {},
358 switch (generic.cc) {
359 CallingConvention.Async => |allocator_type| allocator_type.base.ref(),
360 else => {},
361 }
362 },
363 Kind.Normal => |normal| {334 Kind.Normal => |normal| {
364 normal.return_type.base.ref();335 normal.return_type.base.ref();
365 for (normal.params) |param| {336 for (normal.params) |param| {
...@@ -370,14 +341,7 @@ pub const Type = struct {...@@ -370,14 +341,7 @@ pub const Type = struct {
370 }341 }
371 };342 };
372343
373 pub const CallingConvention = enum {344 const CallingConvention = builtin.CallingConvention;
374 Auto,
375 C,
376 Cold,
377 Naked,
378 Stdcall,
379 Async,
380 };
381345
382 pub const Param = struct {346 pub const Param = struct {
383 is_noalias: bool,347 is_noalias: bool,
...@@ -386,12 +350,12 @@ pub const Type = struct {...@@ -386,12 +350,12 @@ pub const Type = struct {
386350
387 fn ccFnTypeStr(cc: CallingConvention) []const u8 {351 fn ccFnTypeStr(cc: CallingConvention) []const u8 {
388 return switch (cc) {352 return switch (cc) {
389 CallingConvention.Auto => "",353 .Auto => "",
390 CallingConvention.C => "extern ",354 .C => "extern ",
391 CallingConvention.Cold => "coldcc ",355 .Cold => "coldcc ",
392 CallingConvention.Naked => "nakedcc ",356 .Naked => "nakedcc ",
393 CallingConvention.Stdcall => "stdcallcc ",357 .Stdcall => "stdcallcc ",
394 CallingConvention.Async => unreachable,358 .Async => "async ",
395 };359 };
396 }360 }
397361