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