ref: dc27d590d3a3f1ee4ec055c50c7829303ac72af9
parent: 03ac35586687e146835216f8339dbe31ead84d98
author: Ori Bernstein <[email protected]>
date: Mon Jul 30 20:36:23 EDT 2012
Make struct returns work.
--- a/8/isel.c
+++ b/8/isel.c
@@ -51,6 +51,12 @@
[Ole] = {Icmp, Ijle, Isetle}
};
+static int stacktype(Type *t)
+{
+ /* the types are arranged in types.def such that this is true */
+ return t->type >= Tyslice;
+}
+
static Mode mode(Node *n)
{
Type *t;
@@ -60,6 +66,8 @@
case Tyfloat32: return ModeF; break;
case Tyfloat64: return ModeD; break;
default:
+ if (stacktype(t))
+ return ModeNone;
switch (size(n)) {
case 1: return ModeB; break;
case 2: return ModeS; break;
@@ -359,6 +367,8 @@
rsp = locphysreg(Rrsp);
if (tybase(exprtype(n))->type == Tyvoid)
rax = NULL;
+ else if (stacktype(exprtype(n)))
+ rax = locphysreg(Rrax);
else
rax = coreg(Rrax, mode(n));
argsz = 0;
--- a/parse/types.def
+++ b/parse/types.def
@@ -27,16 +27,20 @@
Ty(Tyfloat64, "float64")
Ty(Tyvalist, NULL)
-/*end atomic types*/
+/* end atomic types */
Ty(Typtr, NULL)
+Ty(Tyfunc, NULL)
+
+/* these types live on the stack */
Ty(Tyslice, NULL)
Ty(Tyarray, NULL)
-Ty(Tyfunc, NULL)
Ty(Tytuple, NULL)
+Ty(Tystruct, NULL)
+Ty(Tyunion, NULL)
+
+/* these have no memory repr */
Ty(Tyvar, NULL)
Ty(Typaram, NULL)
Ty(Tyname, NULL)
-Ty(Tystruct, NULL)
-Ty(Tyunion, NULL)
Ty(Tyalias, NULL)
Ty(Ntypes, NULL)