root/trunk/src/argtypes.c

Revision 718, 3.6 kB (checked in by walter, 2 years ago)

add argtypes.c

Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 2010-2010 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // http://www.dsource.org/projects/dmd/browser/branches/dmd-1.x/src/argtypes.c
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
10
11 #include <stdio.h>
12 #include <assert.h>
13
14 #include "mars.h"
15 #include "dsymbol.h"
16 #include "mtype.h"
17 #include "scope.h"
18 #include "init.h"
19 #include "expression.h"
20 #include "attrib.h"
21 #include "declaration.h"
22 #include "template.h"
23 #include "id.h"
24 #include "enum.h"
25 #include "import.h"
26 #include "aggregate.h"
27 #include "hdrgen.h"
28
29 /****************************************************
30  * This breaks a type down into 'simpler' types that can be passed to a function
31  * in registers, and returned in registers.
32  * It's highly platform dependent.
33  * Returning a tuple of zero length means the type cannot be passed/returned in registers.
34  */
35
36
37 TypeTuple *Type::toArgTypes()
38 {
39     return NULL;        // not valid for a parameter
40 }
41
42
43 TypeTuple *TypeBasic::toArgTypes()
44 {   Type *t1 = NULL;
45     Type *t2 = NULL;
46     switch (ty)
47     {
48         case Tvoid:
49              return NULL;
50
51         case Tbool:
52         case Tint8:
53         case Tuns8:
54         case Tint16:
55         case Tuns16:
56         case Tint32:
57         case Tuns32:
58         case Tfloat32:
59         case Tint64:
60         case Tuns64:
61         case Tfloat64:
62         case Tfloat80:
63             t1 = this;
64             break;
65
66         case Timaginary32:
67             t1 = Type::tfloat32;
68             break;
69
70         case Timaginary64:
71             t1 = Type::tfloat64;
72             break;
73
74         case Timaginary80:
75             t1 = Type::tfloat80;
76             break;
77
78         case Tcomplex32:
79             if (global.params.isX86_64)
80                 t1 = Type::tfloat64;            // weird, eh?
81             else
82             {
83                 t1 = Type::tfloat64;
84                 t2 = Type::tfloat64;
85             }
86             break;
87
88         case Tcomplex64:
89             t1 = Type::tfloat64;
90             t2 = Type::tfloat64;
91             break;
92
93         case Tcomplex80:
94             t1 = Type::tfloat80;
95             t2 = Type::tfloat80;
96             break;
97
98         case Tascii:
99             t1 = Type::tuns8;
100             break;
101
102         case Twchar:
103             t1 = Type::tuns16;
104             break;
105
106         case Tdchar:
107             t1 = Type::tuns32;
108             break;
109
110         default:        assert(0);
111     }
112
113     TypeTuple *t;
114     if (t1)
115     {
116         if (t2)
117             t = new TypeTuple(t1, t2);
118         else
119             t = new TypeTuple(t1);
120     }
121     else
122         t = new TypeTuple();
123     return t;
124 }
125
126 TypeTuple *TypeSArray::toArgTypes()
127 {
128 #if DMDV2
129     return new TypeTuple();     // pass on the stack for efficiency
130 #else
131     return new TypeTuple(Type::tvoidptr);
132 #endif
133 }
134
135 TypeTuple *TypeDArray::toArgTypes()
136 {
137     return new TypeTuple();     // pass on the stack for efficiency
138 }
139
140 TypeTuple *TypeAArray::toArgTypes()
141 {
142     return new TypeTuple(Type::tvoidptr);
143 }
144
145 TypeTuple *TypePointer::toArgTypes()
146 {
147     return new TypeTuple(this);
148 }
149
150 TypeTuple *TypeDelegate::toArgTypes()
151 {
152     return new TypeTuple();     // pass on the stack for efficiency
153 }
154
155 TypeTuple *TypeStruct::toArgTypes()
156 {
157     return new TypeTuple();     // pass on the stack for efficiency
158 }
159
160 TypeTuple *TypeEnum::toArgTypes()
161 {
162     return toBasetype()->toArgTypes();
163 }
164
165 TypeTuple *TypeTypedef::toArgTypes()
166 {
167     return sym->basetype->toArgTypes();
168 }
169
170 TypeTuple *TypeClass::toArgTypes()
171 {
172     return new TypeTuple(Type::tvoidptr);
173 }
Note: See TracBrowser for help on using the browser.