Mercurial > projects > ldc
comparison ir/irfuncty.h @ 1051:dc608dc33081
Make IrFuncTy a member of TypeFunction. Reset between modules compiled in the
same LDC call.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 07 Mar 2009 14:25:30 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1050:32ead42679d1 | 1051:dc608dc33081 |
---|---|
1 #ifndef LDC_IR_IRFUNCTY_H | |
2 #define LDC_IR_IRFUNCTY_H | |
3 | |
4 #include "ir/ir.h" | |
5 #include "llvm/ADT/SmallVector.h" | |
6 | |
7 #include <vector> | |
8 | |
9 struct ABIRewrite; | |
10 namespace llvm { | |
11 class Type; | |
12 class Value; | |
13 class Instruction; | |
14 class Function; | |
15 } | |
16 | |
17 // represents a function type argument | |
18 // both explicit and implicit as well as return values | |
19 struct IrFuncTyArg : IrBase | |
20 { | |
21 /** This is the original D type as the frontend knows it | |
22 * May NOT be rewritten!!! */ | |
23 Type* type; | |
24 | |
25 /// This is the final LLVM Type used for the parameter/return value type | |
26 const llvm::Type* ltype; | |
27 | |
28 /** These are the final LLVM attributes used for the function. | |
29 * Must be valid for the LLVM Type and byref setting */ | |
30 unsigned attrs; | |
31 | |
32 /** 'true' if the final LLVM argument is a LLVM reference type. | |
33 * Must be true when the D Type is a value type, but the final | |
34 * LLVM Type is a reference type! */ | |
35 bool byref; | |
36 | |
37 /** Pointer to the ABIRewrite structure needed to rewrite LLVM ValueS | |
38 * to match the final LLVM Type when passing arguments and getting | |
39 * return values */ | |
40 ABIRewrite* rewrite; | |
41 | |
42 /// Helper to check if the 'inreg' attribute is set | |
43 bool isInReg() const; | |
44 /// Helper to check if the 'sret' attribute is set | |
45 bool isSRet() const; | |
46 /// Helper to check if the 'byval' attribute is set | |
47 bool isByVal() const; | |
48 | |
49 /** @param t D type of argument/return value as known by the frontend | |
50 * @param byref Initial value for the 'byref' field. If true the initial | |
51 * LLVM Type will be of DtoType(type->pointerTo()), instead | |
52 * of just DtoType(type) */ | |
53 IrFuncTyArg(Type* t, bool byref, unsigned a = 0); | |
54 }; | |
55 | |
56 // represents a function type | |
57 struct IrFuncTy : IrBase | |
58 { | |
59 // return value | |
60 IrFuncTyArg* ret; | |
61 | |
62 // null if not applicable | |
63 IrFuncTyArg* arg_sret; | |
64 IrFuncTyArg* arg_this; | |
65 IrFuncTyArg* arg_nest; | |
66 IrFuncTyArg* arg_arguments; | |
67 IrFuncTyArg* arg_argptr; | |
68 | |
69 // normal explicit arguments | |
70 // typedef llvm::SmallVector<IrFuncTyArg*, 4> ArgList; | |
71 typedef std::vector<IrFuncTyArg*> ArgList; | |
72 typedef ArgList::iterator ArgIter; | |
73 ArgList args; | |
74 | |
75 // C varargs | |
76 bool c_vararg; | |
77 | |
78 // range of normal parameters to reverse | |
79 bool reverseParams; | |
80 | |
81 IrFuncTy() | |
82 : ret(NULL), | |
83 arg_sret(NULL), | |
84 arg_this(NULL), | |
85 arg_nest(NULL), | |
86 arg_arguments(NULL), | |
87 arg_argptr(NULL), | |
88 c_vararg(false), | |
89 reverseParams(false) | |
90 {} | |
91 | |
92 void reset() { | |
93 ret = NULL; | |
94 arg_sret = arg_this = arg_nest = arg_arguments = arg_argptr = NULL; | |
95 args.clear(); | |
96 c_vararg = false; | |
97 reverseParams = false; | |
98 } | |
99 | |
100 llvm::Value* putRet(Type* dty, DValue* dval); | |
101 llvm::Value* getRet(Type* dty, DValue* dval); | |
102 | |
103 llvm::Value* putParam(Type* dty, int idx, DValue* dval); | |
104 llvm::Value* getParam(Type* dty, int idx, DValue* dval); | |
105 void getParam(Type* dty, int idx, DValue* dval, llvm::Value* lval); | |
106 }; | |
107 | |
108 #endif |