annotate gen/toir.c @ 67:f918f3e2e99e trunk

[svn r71] Fixed accessing parent function arguments from inside nested delegates. Some cleanups in VarExp::toElem.
author lindquist
date Sun, 28 Oct 2007 02:46:06 +0200
parents 0c5f410d973c
children c4b3f5d2cd9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1 // Backend stubs
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 /* DMDFE backend stubs
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 * This file contains the implementations of the backend routines.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 * For dmdfe these do nothing but print a message saying the module
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 * has been parsed. Substitute your own behaviors for these routimes.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 #include <stdio.h>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10 #include <math.h>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 #include <sstream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12 #include <fstream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
13 #include <iostream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
14
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
15 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 #include "total.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
19 #include "symbol.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 #include "hdrgen.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 #include "port.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
23
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
24 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
25 #include "gen/elem.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
26 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
27 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
28 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
29 #include "gen/arrays.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33 elem* DeclarationExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
34 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
38
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39 // variable declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40 if (VarDeclaration* vd = declaration->isVarDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
42 Logger::println("VarDeclaration");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
44 // static
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
45 if (vd->isDataseg())
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
46 {
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
47 vd->toObjFile();
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
48 }
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
49 else
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
50 {
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
51 Logger::println("vdtype = %s", vd->type->toChars());
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
52 // referenced by nested delegate?
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
53 if (vd->nestedref) {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
54 Logger::println("has nestedref set");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
55 vd->llvmValue = p->func().decl->llvmNested;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
56 assert(vd->llvmValue);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
57 assert(vd->llvmNestedIndex >= 0);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
58 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
59 // normal stack variable
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
60 else {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
61 // allocate storage on the stack
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
62 const llvm::Type* lltype = LLVM_DtoType(vd->type);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
63 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint());
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
64 //allocainst->setAlignment(vd->type->alignsize()); // TODO
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
65 vd->llvmValue = allocainst;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
66 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
67 LLVM_DtoInitializer(vd->init);
26
99737f94abfb [svn r30] * Fixed static function-local variables.
lindquist
parents: 25
diff changeset
68 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
69 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
70 // struct declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
71 else if (StructDeclaration* s = declaration->isStructDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
72 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
73 Logger::println("StructDeclaration");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
74 s->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
75 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
76 // function declaration
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
77 else if (FuncDeclaration* f = declaration->isFuncDeclaration())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
78 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
79 Logger::println("FuncDeclaration");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
80 f->toObjFile();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
81 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
82 // alias declaration
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
83 else if (AliasDeclaration* a = declaration->isAliasDeclaration())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
84 {
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
85 Logger::println("AliasDeclaration - no work");
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
86 // do nothing
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
87 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
88 else if (EnumDeclaration* e = declaration->isEnumDeclaration())
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
89 {
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
90 Logger::println("EnumDeclaration - no work");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
91 // do nothing
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
92 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
93 // unsupported declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 error("Only Var/Struct-Declaration is supported for DeclarationExp");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
97 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
101
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 elem* VarExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 Logger::print("VarExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
108
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
110
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 assert(var);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 if (VarDeclaration* vd = var->isVarDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113 {
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
114 Logger::println("VarDeclaration %s", vd->toChars());
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
115
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
116 // _arguments
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
117 if (vd->ident == Id::_arguments)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
118 {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
119 vd->llvmValue = p->func().decl->llvmArguments;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
120 assert(vd->llvmValue);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
121 e->mem = vd->llvmValue;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
122 e->type = elem::VAR;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
123 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
124 // _argptr
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
125 else if (vd->ident == Id::_argptr)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
126 {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
127 vd->llvmValue = p->func().decl->llvmArgPtr;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
128 assert(vd->llvmValue);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
129 e->mem = vd->llvmValue;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
130 e->type = elem::VAR;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
131 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
132 // _dollar
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
133 else if (vd->ident == Id::dollar)
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
134 {
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
135 assert(!p->arrays.empty());
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
136 llvm::Value* tmp = LLVM_DtoGEPi(p->arrays.back(),0,0,"tmp",p->scopebb());
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
137 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb());
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
138 e->type = elem::VAL;
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
139 }
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
140 // typeinfo
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
141 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
142 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
143 Logger::println("TypeInfoDeclaration");
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
144 tid->toObjFile();
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
145 assert(tid->llvmValue);
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
146 const llvm::Type* vartype = LLVM_DtoType(type);
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
147 if (tid->llvmValue->getType() != llvm::PointerType::get(vartype))
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
148 e->mem = p->ir->CreateBitCast(tid->llvmValue, vartype, "tmp");
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
149 else
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
150 e->mem = tid->llvmValue;
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
151 e->type = elem::VAR;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
153 // nested variable
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
154 else if (vd->nestedref) {
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
155 e->mem = LLVM_DtoNestedVariable(vd);
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
156 e->type = elem::VAR;
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
157 e->vardecl = vd;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
159 // function parameter
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
160 else if (vd->isParameter()) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
161 Logger::println("function param");
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
162 assert(vd->llvmValue);
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
163 if (vd->isRef() || vd->isOut()) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164 e->mem = vd->llvmValue;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
165 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
166 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
168 if (LLVM_DtoIsPassedByRef(vd->type)) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169 e->mem = vd->llvmValue;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
170 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
172 else {
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
173 if (llvm::isa<llvm::Argument>(vd->llvmValue)) {
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
174 e->val = vd->llvmValue;
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
175 e->type = elem::VAL;
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
176 e->vardecl = vd;
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
177 }
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
178 else if (llvm::isa<llvm::AllocaInst>(vd->llvmValue)) {
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
179 e->mem = vd->llvmValue;
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
180 e->type = elem::VAR;
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
181 }
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
182 else
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
183 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
184 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
186 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
187 else {
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
188 // take care of forward references of global variables
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
189 if (!vd->llvmTouched && vd->isDataseg())
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
190 vd->toObjFile();
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
191 assert(vd->llvmValue);
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
192 e->mem = vd->llvmValue;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
193 e->vardecl = vd;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
194 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
195 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
196
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
197 assert(e->mem || e->val);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
198 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
199 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
200 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
201 Logger::println("FuncDeclaration");
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
202 if (fdecl->llvmInternal != LLVMva_arg && fdecl->llvmValue == 0)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
203 fdecl->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
204 e->val = fdecl->llvmValue;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
205 e->type = elem::FUNC;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
206 e->funcdecl = fdecl;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
207 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
208 else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
209 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
210 // this seems to be the static initialiser for structs
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
211 Type* sdecltype = LLVM_DtoDType(sdecl->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
212 Logger::print("Sym: type=%s\n", sdecltype->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
213 assert(sdecltype->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
214 TypeStruct* ts = (TypeStruct*)sdecltype;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 e->mem = ts->llvmInit;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
216 assert(e->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
219 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
221 assert(0 && "Unimplemented VarExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
222 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
223
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
224 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
225 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
226
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
227 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
228
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
229 llvm::Constant* VarExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
230 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
231 Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
232 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
233 if (SymbolDeclaration* sdecl = var->isSymbolDeclaration())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
234 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
235 // this seems to be the static initialiser for structs
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
236 Type* sdecltype = LLVM_DtoDType(sdecl->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
237 Logger::print("Sym: type=%s\n", sdecltype->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
238 assert(sdecltype->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
239 TypeStruct* ts = (TypeStruct*)sdecltype;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
240 assert(ts->sym->llvmInitZ);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
241 return ts->sym->llvmInitZ;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
242 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
243 assert(0 && "Only support const var exp is SymbolDeclaration");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
244 return NULL;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
245 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
246
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
247 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
248
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
249 elem* IntegerExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
250 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
251 Logger::print("IntegerExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
252 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
253 elem* e = new elem;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
254 e->val = toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
255 e->type = elem::CONST;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
256 return e;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
257 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
258
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
259 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
260
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
261 llvm::Constant* IntegerExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
262 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
263 Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
264 LOG_SCOPE;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
265 const llvm::Type* t = LLVM_DtoType(type);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
266 if (llvm::isa<llvm::PointerType>(t)) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
267 llvm::Constant* i = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)value,false);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
268 return llvm::ConstantExpr::getIntToPtr(i, t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
269 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
270 else if (llvm::isa<llvm::IntegerType>(t)) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
271 return llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
272 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
273 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
274 return NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
275 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
276
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
277 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
278
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
279 elem* RealExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
280 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
281 Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
282 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
283 elem* e = new elem;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
284 e->val = toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
285 e->type = elem::CONST;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
286 return e;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
287 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
288
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
289 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
290
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
291 llvm::Constant* RealExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
292 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
293 Logger::print("RealExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
294 LOG_SCOPE;
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
295 Type* t = LLVM_DtoDType(type);
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
296 const llvm::Type* fty = LLVM_DtoType(t);
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
297 if (t->ty == Tfloat32 || t->ty == Timaginary32)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
298 return llvm::ConstantFP::get(fty,float(value));
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
299 else if (t->ty == Tfloat64 || t->ty == Timaginary64 || t->ty == Tfloat80 || t->ty == Timaginary80)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
300 return llvm::ConstantFP::get(fty,double(value));
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
301 assert(0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
302 return NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
303 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
304
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
305 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
306
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
307 elem* NullExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
308 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
309 Logger::print("NullExp::toElem(type=%s): %s\n", type->toChars(),toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
310 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
311 elem* e = new elem;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
312 e->val = toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
313 e->type = elem::NUL;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
314 //Logger::cout() << "null value is now " << *e->val << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
315 return e;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
316 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
317
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
318 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
319
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
320 llvm::Constant* NullExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
321 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
322 Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
323 LOG_SCOPE;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
324 const llvm::Type* t = LLVM_DtoType(type);
28
1c80c18f3c82 [svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents: 27
diff changeset
325 if (type->ty == Tarray) {
1c80c18f3c82 [svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents: 27
diff changeset
326 assert(llvm::isa<llvm::StructType>(t));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
327 return llvm::ConstantAggregateZero::get(t);
28
1c80c18f3c82 [svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents: 27
diff changeset
328 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
329 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
330 return llvm::Constant::getNullValue(t);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
331 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
332 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
333 return NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
334 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
335
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
336 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
337
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
338 elem* StringExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
339 {
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
340 Logger::print("StringExp::toElem: %s | %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
341 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
342
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
343 Type* dtype = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
344
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
345 assert(dtype->next->ty == Tchar && "Only char is supported");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
346 assert(sz == 1);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
347
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
348 const llvm::Type* ct = LLVM_DtoType(dtype->next);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
349 //printf("ct = %s\n", type->next->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
350 const llvm::ArrayType* at = llvm::ArrayType::get(ct,len+1);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
351
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
352 uint8_t* str = (uint8_t*)string;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
353 std::string cont((char*)str, len);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
354
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
355 llvm::Constant* _init = llvm::ConstantArray::get(cont,true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
356
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
357 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
358 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,"stringliteral",gIR->module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
359
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
360 llvm::ConstantInt* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
361 llvm::Constant* idxs[2] = { zero, zero };
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
362 llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
363
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
364 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
365
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
366 if (dtype->ty == Tarray) {
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
367 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
368 if (!p->topexp() || p->topexp()->e2 != this) {
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
369 llvm::Value* tmpmem = new llvm::AllocaInst(LLVM_DtoType(dtype),"tmp",p->topallocapoint());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
370 LLVM_DtoSetArray(tmpmem, clen, arrptr);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
371 e->mem = tmpmem;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
372 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
373 else if (p->topexp()->e2 == this) {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
374 llvm::Value* arr = p->topexp()->v;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
375 assert(arr);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
376 LLVM_DtoSetArray(arr, clen, arrptr);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
377 e->inplace = true;
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
378 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
379 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
380 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
381 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
382 else if (dtype->ty == Tsarray) {
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
383 const llvm::Type* dstType = llvm::PointerType::get(llvm::ArrayType::get(ct, len));
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
384 e->mem = new llvm::BitCastInst(gvar, dstType, "tmp", gIR->scopebb());
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
385 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
386 else if (dtype->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
387 e->mem = arrptr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
388 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
389 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
390 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
391 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
392
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
393 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
394
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
395 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
396 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
397
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
398 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
399
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
400 llvm::Constant* StringExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
401 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
402 Logger::print("StringExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
403 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
404
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
405 uint8_t* str = (uint8_t*)string;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
406 std::string cont((char*)str, len);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
407
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
408 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
409
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
410 if (t->ty == Tsarray) {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
411 return llvm::ConstantArray::get(cont,false);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
412 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
413 llvm::Constant* _init = llvm::ConstantArray::get(cont,true);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
414
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
415 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
416 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_init->getType(),true,_linkage,_init,"stringliteral",gIR->module);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
417
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
418 llvm::ConstantInt* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
419 llvm::Constant* idxs[2] = { zero, zero };
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
420 llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
421
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
422 if (t->ty == Tpointer) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
423 return arrptr;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
424 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
425
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
426 if (t->ty == Tarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
427 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
428 return LLVM_DtoConstantSlice(clen, arrptr);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
429 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
430
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
431 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
432 return NULL;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
433 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
434
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
435 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
436
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
437 elem* AssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
438 {
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
439 Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
440 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
441
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
442 p->exps.push_back(IRExp(e1,e2,NULL));
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
443
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
444 elem* l = e1->toElem(p);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
445 p->topexp()->v = l->mem;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
446 elem* r = e2->toElem(p);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
447
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
448 p->exps.pop_back();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
449
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
450 if (l->type == elem::ARRAYLEN)
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
451 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
452 LLVM_DtoResizeDynArray(l->mem, r->getValue());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
453 delete r;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
454 delete l;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
455 return 0;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
456 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
457
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
458 // handle function argument - allocate temp storage for it :/ annoying
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
459 if (l->mem == 0) {
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
460 assert(l->val);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
461 if (llvm::isa<llvm::Argument>(l->val))
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
462 LLVM_DtoGiveArgumentStorage(l);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
463 else {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
464 Logger::cout() << "here it comes... " << *l->val << '\n';
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
465 assert(0);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
466 }
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
467 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
468 //e->val = l->store(r->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
469
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
470 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
471 Type* e2type = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
472 TY e1ty = e1type->ty;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
473 TY e2ty = e2type->ty;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
474
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
475 elem* e = new elem;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
476 e->type = elem::VAR;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
477
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
478 // struct
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
479 if (e1ty == Tstruct) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
480 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
481 // struct + struct
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
482 if (e2ty == Tstruct) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
483 // struct literals do the assignment themselvs (in place)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
484 if (!r->inplace) {
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
485 LLVM_DtoStructCopy(l->mem,r->getValue());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
486 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
487 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
488 e->inplace = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
489 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
490 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
491 // struct + const int
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
492 else if (e2type->isintegral()){
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
493 IntegerExp* iexp = (IntegerExp*)e2;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
494 assert(iexp->value == 0 && "Only integral struct initializer allowed is zero");
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
495 LLVM_DtoStructZeroInit(l->mem);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
496 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
497 // :x
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
498 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
499 assert(0 && "struct = unknown");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
500 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
501 else if (e1ty == Tsarray) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
502 assert(0 && "static array not supported");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
503 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
504 else if (e1ty == Tarray) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
505 if (e2type->isscalar() || e2type->ty == Tclass){
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
506 LLVM_DtoArrayInit(l->mem, r->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
507 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
508 else if (e2ty == Tarray) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
509 //new llvm::StoreInst(r->val,l->val,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
510 if (r->type == elem::NUL) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
511 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
512 assert(c->isNullValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
513 LLVM_DtoNullArray(l->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
514 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
515 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
516 else if (r->type == elem::SLICE) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
517 if (l->type == elem::SLICE) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
518 LLVM_DtoArrayCopy(l,r);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
519 e->type = elem::SLICE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
520 e->mem = l->mem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
521 e->arg = l->arg;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
522 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
523 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
524 LLVM_DtoSetArray(l->mem,r->arg,r->mem);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
525 e->mem = l->mem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
526 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
527 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
528 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
529 // new expressions write directly to the array reference
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
530 // so do string literals
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
531 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
532 if (!r->inplace) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
533 assert(r->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
534 LLVM_DtoArrayAssign(l->mem, r->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
535 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
536 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
537 e->inplace = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
538 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
539 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
540 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
541 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
542 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
543 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
544 else if (e1ty == Tpointer) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
545 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 if (e2ty == Tpointer) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
547 llvm::Value* v = r->field ? r->mem : r->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
548 Logger::cout() << "*=*: " << *v << ", " << *l->mem << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
549 new llvm::StoreInst(v, l->mem, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
550 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
551 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
552 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
553 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
554 else if (e1ty == Tclass) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
555 if (e2ty == Tclass) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
556 llvm::Value* tmp = r->getValue();
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
557 Logger::cout() << "tmp: " << *tmp << " ||| " << *l->mem << '\n';
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
558 // assignment to this in constructor special case
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
559 if (l->isthis) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
560 FuncDeclaration* fdecl = p->func().decl;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
561 // respecify the this param
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
562 if (!llvm::isa<llvm::AllocaInst>(fdecl->llvmThisVar))
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
563 fdecl->llvmThisVar = new llvm::AllocaInst(tmp->getType(), "newthis", p->topallocapoint());
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
564 new llvm::StoreInst(tmp, fdecl->llvmThisVar, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
565 e->mem = fdecl->llvmThisVar;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
566 }
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
567 // regular class ref -> class ref assignment
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
568 else {
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
569 new llvm::StoreInst(tmp, l->mem, p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
570 e->mem = l->mem;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
571 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
572 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
573 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
574 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
575 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
576 else if (e1ty == Tdelegate) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
577 Logger::println("Assigning to delegate");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
578 if (e2ty == Tdelegate) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
579 if (r->type == elem::NUL) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
580 llvm::Constant* c = llvm::cast<llvm::Constant>(r->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
581 if (c->isNullValue()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
582 LLVM_DtoNullDelegate(l->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
583 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
584 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
585 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
586 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
587 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
588 else if (r->inplace) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
589 // do nothing
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
590 e->inplace = true;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
591 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
592 }
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
593 else {
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
594 LLVM_DtoDelegateCopy(l->mem, r->getValue());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
595 e->mem = l->mem;
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
596 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
597 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
598 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
599 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
600 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
601 // !struct && !array && !pointer && !class
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
602 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
603 Logger::cout() << *l->mem << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
604 new llvm::StoreInst(r->getValue(),l->mem,p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
605 e->mem = l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
606 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
607
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
608 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
609 delete l;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
610
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
611 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
612 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
613
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
614 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
615
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
616 elem* AddExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
617 {
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
618 Logger::print("AddExp::toElem: %s | %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
619 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
620 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
621 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
622 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
623
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
624 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
625 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
626 Type* e2type = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
627
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
628 if (e1type != e2type) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
629 if (e1type->ty == Tpointer && e1type->next->ty == Tstruct) {
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
630 //assert(l->field);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
631 assert(r->type == elem::CONST);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
632 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
633
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
634 TypeStruct* ts = (TypeStruct*)e1type->next;
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
635 std::vector<unsigned> offsets(1,0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
636 ts->sym->offsetToIndex(t->next, cofs->getZExtValue(), offsets);
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
637 e->mem = LLVM_DtoGEP(l->getValue(), offsets, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
638 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
639 e->field = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
640 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
641 else if (e1->type->ty == Tpointer) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
642 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
643 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
644 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
645 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
646 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
647 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
648 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
649 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
650 e->val = llvm::BinaryOperator::createAdd(l->getValue(), r->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
651 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
652 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
653 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
654 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
655 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
656 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
657
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
658 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
659
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
660 elem* AddAssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
661 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
662 Logger::print("AddAssignExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
663 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
664
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
665 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
666 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
667
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
668 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
669
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
670 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
671 llvm::Value* val = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
672 if (e1type->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
673 val = e->mem = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
674 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
675 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
676 val = e->val = llvm::BinaryOperator::createAdd(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
677 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
678
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
679 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
680 if (llvm::isa<llvm::PointerType>(storeVal->getType()) && storeVal->getType()->getContainedType(0) != tmp->getType())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
681 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
682 tmp = LLVM_DtoPointedType(storeVal, tmp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
683 }*/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
684
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
685 if (l->mem == 0)
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
686 LLVM_DtoGiveArgumentStorage(l);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
687 new llvm::StoreInst(val,l->mem,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
688 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
689
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
690 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
691 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
692 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
693 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
694
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
695 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
696
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
697 elem* MinExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
698 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
699 Logger::print("MinExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
700 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
701 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
702 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
703 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
704
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
705 llvm::Value* left = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
706 if (llvm::isa<llvm::PointerType>(left->getType()))
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
707 left = new llvm::PtrToIntInst(left,LLVM_DtoSize_t(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
708
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
709 llvm::Value* right = r->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
710 if (llvm::isa<llvm::PointerType>(right->getType()))
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
711 right = new llvm::PtrToIntInst(right,LLVM_DtoSize_t(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
712
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
713 e->val = llvm::BinaryOperator::createSub(left,right,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
714 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
715
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
716 const llvm::Type* totype = LLVM_DtoType(type);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
717 if (e->val->getType() != totype) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
718 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
719 assert(llvm::isa<llvm::PointerType>(e->val->getType()));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
720 assert(llvm::isa<llvm::IntegerType>(totype));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
721 e->val = new llvm::IntToPtrInst(e->val,totype,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
722 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
723
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
724 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
725 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
726 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
727 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
728
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
729 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
730
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
731 elem* MinAssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
732 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
733 Logger::print("MinAssignExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
734 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
735
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
736 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
737 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
738
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
739 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
740
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
741 llvm::Value* tmp = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
742 if (e1type->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
743 tmp = r->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
744 llvm::Value* zero = llvm::ConstantInt::get(tmp->getType(),0,false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
745 tmp = llvm::BinaryOperator::createSub(zero,tmp,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
746 tmp = new llvm::GetElementPtrInst(l->getValue(),tmp,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
747 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
748 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
749 tmp = llvm::BinaryOperator::createSub(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
750 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
751
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
752 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
753 if (storeVal->getType()->getContainedType(0) != tmp->getType())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
754 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
755 tmp = LLVM_DtoPointedType(storeVal, tmp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
756 }*/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
757
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
758 if (l->mem == 0)
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
759 LLVM_DtoGiveArgumentStorage(l);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
760 new llvm::StoreInst(tmp, l->mem, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
761
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
762 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
763 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
764
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
765 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
766 e->val = tmp;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
767 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
768 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
769 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
770
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
771 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
772
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
773 elem* MulExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
774 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
775 Logger::print("MulExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
776 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
777 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
778 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
779 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
780 llvm::Value* vl = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
781 llvm::Value* vr = r->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
782 Logger::cout() << "mul: " << *vl << ", " << *vr << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
783 e->val = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
784 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
785 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
786 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
787 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
788 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
789
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
790 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
791
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
792 elem* MulAssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
793 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
794 Logger::print("MulAssignExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
795 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
796
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
797 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
798 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
799 llvm::Value* vl = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
800 llvm::Value* vr = r->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
801 Logger::cout() << "mulassign: " << *vl << ", " << *vr << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
802 llvm::Value* tmp = llvm::BinaryOperator::createMul(vl,vr,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
803
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
804 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
805 if (storeVal->getType()->getContainedType(0) != tmp->getType())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
806 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
807 tmp = LLVM_DtoPointedType(storeVal, tmp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
808 }*/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
809
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
810 if (l->mem == 0)
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
811 LLVM_DtoGiveArgumentStorage(l);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
812 new llvm::StoreInst(tmp,l->mem,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
813
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
814 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
815 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
816
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
817 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
818 e->val = tmp;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
819 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
820 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
821 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
822
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
823 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
824
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
825 elem* DivExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
826 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
827 Logger::print("DivExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
828 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
829 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
830 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
831 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
832
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
833 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
834
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
835 if (t->isunsigned())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
836 e->val = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
837 else if (t->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
838 e->val = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
839 else if (t->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
840 e->val = llvm::BinaryOperator::createFDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
841 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
842 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
843 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
844 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
845 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
846 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
847 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
848
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
849 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
850
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
851 elem* DivAssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
852 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
853 Logger::print("DivAssignExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
854 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
855
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
856 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
857 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
858
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
859 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
860
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
861 llvm::Value* tmp;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
862 if (t->isunsigned())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
863 tmp = llvm::BinaryOperator::createUDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
864 else if (t->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
865 tmp = llvm::BinaryOperator::createSDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
866 else if (t->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
867 tmp = llvm::BinaryOperator::createFDiv(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
868 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
869 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
870
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
871 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
872 if (storeVal->getType()->getContainedType(0) != tmp->getType())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
873 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
874 tmp = LLVM_DtoPointedType(storeVal, tmp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
875 }*/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
876
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
877 if (l->mem == 0)
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
878 LLVM_DtoGiveArgumentStorage(l);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
879 new llvm::StoreInst(tmp,l->mem,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
880
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
881 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
882 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
883
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
884 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
885 e->val = tmp;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
886 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
887 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
888 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
889
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
890 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
891
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
892 elem* ModExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
893 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
894 Logger::print("ModExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
895 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
896 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
897 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
898 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
899
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
900 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
901
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
902 if (t->isunsigned())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
903 e->val = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
904 else if (t->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
905 e->val = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
906 else if (t->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
907 e->val = llvm::BinaryOperator::createFRem(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
908 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
909 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
910 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
911 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
912 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
913 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
914 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
915
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
916 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
917
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
918 elem* ModAssignExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
919 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
920 Logger::print("ModAssignExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
921 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
922
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
923 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
924 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
925
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
926 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
927
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
928 llvm::Value* tmp;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
929 if (t->isunsigned())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
930 tmp = llvm::BinaryOperator::createURem(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
931 else if (t->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
932 tmp = llvm::BinaryOperator::createSRem(l->getValue(),r->getValue(),"tmp",p->scopebb());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
933 else if (t->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
934 tmp = llvm::BinaryOperator::createFRem(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
935 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
936 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
937
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
938 /*llvm::Value* storeVal = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
939 if (storeVal->getType()->getContainedType(0) != tmp->getType())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
940 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
941 tmp = LLVM_DtoPointedType(storeVal, tmp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
942 }*/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
943
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
944 if (l->mem == 0)
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
945 LLVM_DtoGiveArgumentStorage(l);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
946 new llvm::StoreInst(tmp,l->mem,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
947
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
948 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
949 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
950
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
951 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
952 e->val = tmp;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
953 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
954 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
955 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
956
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
957 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
958
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
959 elem* CallExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
960 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
961 Logger::print("CallExp::toElem: %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
962 LOG_SCOPE;
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
963
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
964 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
965 elem* fn = e1->toElem(p);
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
966
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
967 TypeFunction* tf = 0;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
968 Type* e1type = LLVM_DtoDType(e1->type);
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
969
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
970 bool delegateCall = false;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
971 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
972 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false);
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
973 LINK dlink = LINKdefault;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
974
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
975 // hidden struct return parameter handling
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
976 bool retinptr = false;
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
977
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
978 // regular functions
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
979 if (e1type->ty == Tfunction) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
980 tf = (TypeFunction*)e1type;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
981 if (tf->llvmRetInPtr) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
982 retinptr = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
983 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
984 dlink = tf->linkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
985 }
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
986
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
987 // delegates
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
988 else if (e1type->ty == Tdelegate) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
989 Logger::println("delegateTy = %s\n", e1type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
990 assert(e1type->next->ty == Tfunction);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
991 tf = (TypeFunction*)e1type->next;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
992 if (tf->llvmRetInPtr) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
993 retinptr = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
994 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
995 dlink = tf->linkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
996 delegateCall = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
997 }
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
998
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
999 // invalid
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1000 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1001 assert(tf);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1002 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1003
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1004 // va args
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1005 bool va_magic = false;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1006 bool va_intrinsic = false;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1007 if (fn->funcdecl) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1008 if (fn->funcdecl->llvmInternal == LLVMva_intrinsic) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1009 va_magic = true;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1010 va_intrinsic = true;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1011 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1012 else if (fn->funcdecl->llvmInternal == LLVMva_start) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1013 va_magic = true;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1014 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1015 else if (fn->funcdecl->llvmInternal == LLVMva_arg) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1016 Argument* fnarg = Argument::getNth(tf->parameters, 0);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1017 Expression* exp = (Expression*)arguments->data[0];
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1018 elem* expelem = exp->toElem(p);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1019 assert(expelem->mem);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1020 elem* e = new elem;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1021 Type* t = LLVM_DtoDType(type);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1022 const llvm::Type* llt = LLVM_DtoType(type);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1023 if (LLVM_DtoIsPassedByRef(t))
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1024 llt = llvm::PointerType::get(llt);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1025 e->type = elem::VAL;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1026 e->val = p->ir->CreateVAArg(expelem->mem,llt,"tmp");
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1027 delete expelem;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1028 return e;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1029 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1030 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1031
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1032 // args
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1033 size_t n = arguments->dim;
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1034 if (fn->funcdecl && fn->funcdecl->llvmInternal == LLVMva_start)
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1035 n = 1;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1036 if (fn->arg || delegateCall) n++;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1037 if (retinptr) n++;
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1038 if (tf->linkage == LINKd && tf->varargs == 1) n+=2;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1039
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1040 llvm::Value* funcval = fn->getValue();
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
1041 assert(funcval != 0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1042 std::vector<llvm::Value*> llargs(n, 0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1043
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1044 const llvm::FunctionType* llfnty = 0;
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 15
diff changeset
1045
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1046 // normal function call
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1047 if (llvm::isa<llvm::FunctionType>(funcval->getType())) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1048 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1049 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1050 // pointer to something
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1051 else if (llvm::isa<llvm::PointerType>(funcval->getType())) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1052 // pointer to function pointer - I think this not really supposed to happen, but does :/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1053 // seems like sometimes we get a func* other times a func**
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1054 if (llvm::isa<llvm::PointerType>(funcval->getType()->getContainedType(0))) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1055 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1056 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1057 // function pointer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1058 if (llvm::isa<llvm::FunctionType>(funcval->getType()->getContainedType(0))) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1059 //Logger::cout() << "function pointer type:\n" << *funcval << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1060 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1061 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1062 // struct pointer - delegate
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1063 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1064 funcval = LLVM_DtoGEP(funcval,zero,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1065 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1066 const llvm::Type* ty = funcval->getType()->getContainedType(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1067 llfnty = llvm::cast<llvm::FunctionType>(ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1068 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1069 // unknown
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1070 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1071 Logger::cout() << "what kind of pointer are we calling? : " << *funcval->getType() << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1072 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1073 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1074 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1075 Logger::cout() << "what are we calling? : " << *funcval << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1076 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1077 assert(llfnty);
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1078 //Logger::cout() << "Function LLVM type: " << *llfnty << '\n';
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1079
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1080 // argument handling
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1081 llvm::FunctionType::param_iterator argiter = llfnty->param_begin();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1082 int j = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1083
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1084 IRExp* topexp = p->topexp();
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1085
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1086 // hidden struct return arguments
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1087 if (retinptr) {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1088 if (topexp && topexp->e2 == this) {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1089 assert(topexp->v);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1090 assert(llvm::isa<llvm::StructType>(topexp->v->getType()->getContainedType(0)));
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1091 llargs[j] = topexp->v;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1092 if (LLVM_DtoIsPassedByRef(tf->next)) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1093 e->inplace = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1094 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1095 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1096 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1097 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1098 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1099 llargs[j] = new llvm::AllocaInst(argiter->get()->getContainedType(0),"rettmp",p->topallocapoint());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1100 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1101 ++j;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1102 ++argiter;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1103 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1104 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1105 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1106 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1107 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1108
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1109 // this arguments
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1110 if (fn->arg) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1111 Logger::println("This Call");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1112 if (fn->arg->getType() != argiter->get()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1113 //Logger::cout() << *fn->thisparam << '|' << *argiter->get() << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1114 llargs[j] = new llvm::BitCastInst(fn->arg, argiter->get(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1115 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1116 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1117 llargs[j] = fn->arg;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1118 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1119 ++j;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1120 ++argiter;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1121 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1122 // delegate context arguments
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1123 else if (delegateCall) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1124 Logger::println("Delegate Call");
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1125 llvm::Value* contextptr = LLVM_DtoGEP(fn->mem,zero,zero,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1126 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1127 ++j;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1128 ++argiter;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1129 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1130
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1131 // va arg function special argument passing
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1132 if (va_magic) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1133 size_t n = va_intrinsic ? arguments->dim : 1;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1134 for (int i=0; i<n; i++,j++)
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1135 {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1136 Argument* fnarg = Argument::getNth(tf->parameters, i);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1137 Expression* exp = (Expression*)arguments->data[i];
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1138 elem* expelem = exp->toElem(p);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1139 assert(expelem->mem);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1140 llargs[j] = p->ir->CreateBitCast(expelem->mem, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1141 delete expelem;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1142 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1143 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1144 // regular arguments
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1145 else {
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1146 if (tf->linkage == LINKd && tf->varargs == 1)
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1147 {
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1148 Logger::println("doing d-style variadic arguments");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1149
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1150 std::vector<const llvm::Type*> vtypes;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1151 std::vector<llvm::Value*> vvalues;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1152 std::vector<llvm::Value*> vtypeinfos;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1153
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1154 for (int i=0; i<arguments->dim; i++) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1155 Argument* fnarg = Argument::getNth(tf->parameters, i);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1156 Expression* argexp = (Expression*)arguments->data[i];
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1157 vvalues.push_back(LLVM_DtoArgument(NULL, fnarg, argexp));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1158 vtypes.push_back(vvalues.back()->getType());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1159
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1160 TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration();
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1161 tidecl->toObjFile();
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1162 assert(tidecl->llvmValue);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1163 vtypeinfos.push_back(tidecl->llvmValue);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1164 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1165
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1166 const llvm::StructType* vtype = llvm::StructType::get(vtypes);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1167 llvm::Value* mem = new llvm::AllocaInst(vtype,"_argptr_storage",p->topallocapoint());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1168 for (unsigned i=0; i<vtype->getNumElements(); ++i)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1169 p->ir->CreateStore(vvalues[i], LLVM_DtoGEPi(mem,0,i,"tmp"));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1170
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1171 //llvm::Constant* typeinfoparam = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(llfnty->getParamType(j)));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1172 assert(Type::typeinfo->llvmInitZ);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1173 const llvm::Type* typeinfotype = llvm::PointerType::get(Type::typeinfo->llvmInitZ->getType());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1174 Logger::cout() << "typeinfo ptr type: " << *typeinfotype << '\n';
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1175 const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1176 llvm::Value* typeinfomem = new llvm::AllocaInst(typeinfoarraytype,"_arguments_storage",p->topallocapoint());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1177 for (unsigned i=0; i<vtype->getNumElements(); ++i) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1178 llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[i], typeinfotype, "tmp");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1179 p->ir->CreateStore(v, LLVM_DtoGEPi(typeinfomem,0,i,"tmp"));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1180 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1181
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1182 llvm::Value* typeinfoarrayparam = new llvm::AllocaInst(llfnty->getParamType(j)->getContainedType(0),"_arguments_array",p->topallocapoint());
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1183 p->ir->CreateStore(LLVM_DtoConstSize_t(vtype->getNumElements()), LLVM_DtoGEPi(typeinfoarrayparam,0,0,"tmp"));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1184 llvm::Value* casttypeinfomem = p->ir->CreateBitCast(typeinfomem, llvm::PointerType::get(typeinfotype), "tmp");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1185 p->ir->CreateStore(casttypeinfomem, LLVM_DtoGEPi(typeinfoarrayparam,0,1,"tmp"));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1186
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1187 llargs[j] = typeinfoarrayparam;;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1188 j++;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1189 llargs[j] = p->ir->CreateBitCast(mem, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1190 j++;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1191 llargs.resize(2);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1192 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1193 else {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1194 Logger::println("doing normal arguments");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1195 for (int i=0; i<arguments->dim; i++,j++) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1196 Argument* fnarg = Argument::getNth(tf->parameters, i);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1197 llargs[j] = LLVM_DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1198 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1199 Logger::println("%d params passed", n);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1200 for (int i=0; i<n; ++i) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1201 Logger::cout() << *llargs[i] << '\n';
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1202 }
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1203 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1204 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1205
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1206 // void returns cannot not be named
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1207 const char* varname = "";
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1208 if (llfnty->getReturnType() != llvm::Type::VoidTy)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1209 varname = "tmp";
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1210
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
1211 Logger::cout() << "Calling: " << *funcval->getType() << '\n';
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1212
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1213 // call the function
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1214 llvm::CallInst* call = new llvm::CallInst(funcval, llargs.begin(), llargs.end(), varname, p->scopebb());
27
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 26
diff changeset
1215 if (retinptr)
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 26
diff changeset
1216 e->mem = llargs[0];
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 26
diff changeset
1217 else
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 26
diff changeset
1218 e->val = call;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1219
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1220 // set calling convention
66
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1221 if (fn->funcdecl) {
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1222 int li = fn->funcdecl->llvmInternal;
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1223 if (li != LLVMintrinsic && li != LLVMva_start && li != LLVMva_intrinsic) {
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1224 call->setCallingConv(LLVM_DtoCallingConv(dlink));
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1225 }
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1226 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
1227 else if (delegateCall) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1228 call->setCallingConv(LLVM_DtoCallingConv(dlink));
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
1229 }
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
1230 else if (fn->callconv != (unsigned)-1) {
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
1231 call->setCallingConv(fn->callconv);
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
1232 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1233
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1234 delete fn;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1235 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1236 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1237
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1238 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1239
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1240 elem* CastExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1241 {
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1242 Logger::print("CastExp::toElem: %s | %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1243 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1244 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1245 elem* u = e1->toElem(p);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1246 const llvm::Type* tolltype = LLVM_DtoType(to);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1247 Type* fromtype = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1248 Type* totype = LLVM_DtoDType(to);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1249 int lsz = fromtype->size();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1250 int rsz = totype->size();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1251
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1252 // this makes sure the strange lvalue casts don't screw things up
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1253 e->mem = u->mem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1254
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1255 if (fromtype->isintegral()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1256 if (totype->isintegral()) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1257 if (lsz < rsz) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1258 Logger::cout() << *tolltype << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1259 if (fromtype->isunsigned() || fromtype->ty == Tbool) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1260 e->val = new llvm::ZExtInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1261 } else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1262 e->val = new llvm::SExtInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1263 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1264 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1265 else if (lsz > rsz) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1266 e->val = new llvm::TruncInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1267 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1268 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1269 e->val = new llvm::BitCastInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1270 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1271 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1272 else if (totype->isfloating()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1273 if (fromtype->isunsigned()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1274 e->val = new llvm::UIToFPInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1275 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1276 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1277 e->val = new llvm::SIToFPInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1278 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1279 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1280 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1281 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1282 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1283 //e->storeVal = u->storeVal ? u->storeVal : u->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1284 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1285 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1286 else if (fromtype->isfloating()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1287 if (totype->isfloating()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1288 if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1289 e->val = u->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1290 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1291 else if (lsz < rsz) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1292 e->val = new llvm::FPExtInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1293 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1294 else if (lsz > rsz) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1295 e->val = new llvm::FPTruncInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1296 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1297 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1298 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1299 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1300 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1301 else if (totype->isintegral()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1302 if (totype->isunsigned()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1303 e->val = new llvm::FPToUIInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1304 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1305 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1306 e->val = new llvm::FPToSIInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1307 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1308 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1309 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1310 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1311 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1312 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1313 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1314 else if (fromtype->ty == Tclass) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1315 //assert(to->ty == Tclass);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1316 e->val = new llvm::BitCastInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1317 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1318 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1319 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1320 Logger::cout() << "from array or sarray" << '\n';
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1321 if (totype->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1322 Logger::cout() << "to pointer" << '\n';
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1323 assert(fromtype->next == totype->next || totype->next->ty == Tvoid);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1324 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1325 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1326 llvm::Value* ptr = LLVM_DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1327 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1328 if (fromtype->next != totype->next)
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1329 e->val = p->ir->CreateBitCast(e->val, llvm::PointerType::get(llvm::Type::Int8Ty), "tmp");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1330 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1331 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1332 else if (totype->ty == Tarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1333 Logger::cout() << "to array" << '\n';
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1334 const llvm::Type* ptrty = LLVM_DtoType(totype->next);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1335 if (ptrty == llvm::Type::VoidTy)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1336 ptrty = llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1337 ptrty = llvm::PointerType::get(ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1338
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1339 const llvm::Type* ety = LLVM_DtoType(fromtype->next);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1340 if (ety == llvm::Type::VoidTy)
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1341 ety = llvm::Type::Int8Ty;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1342
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1343 if (u->type == elem::SLICE) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1344 e->mem = new llvm::BitCastInst(u->mem, ptrty, "tmp", p->scopebb());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1345 if (fromtype->next->size() == totype->next->size())
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1346 e->arg = u->arg;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1347 else
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1348 e->arg = LLVM_DtoArrayCastLength(u->arg, ety, ptrty->getContainedType(0));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1349 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1350 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1351 llvm::Value* uval = u->getValue();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1352 if (fromtype->ty == Tsarray) {
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1353 Logger::cout() << "uvalTy = " << *uval->getType() << '\n';
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1354 assert(llvm::isa<llvm::PointerType>(uval->getType()));
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1355 const llvm::ArrayType* arrty = llvm::cast<llvm::ArrayType>(uval->getType()->getContainedType(0));
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1356 e->arg = llvm::ConstantInt::get(LLVM_DtoSize_t(), arrty->getNumElements(), false);
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1357 e->arg = LLVM_DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0));
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1358 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1359 }
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1360 else {
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1361 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1362 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1363 e->arg = LLVM_DtoGEP(uval,zero,zero,"tmp",p->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1364 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1365 e->arg = LLVM_DtoArrayCastLength(e->arg, ety, ptrty->getContainedType(0));
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1366
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1367 e->mem = LLVM_DtoGEP(uval,zero,one,"tmp",p->scopebb());
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1368 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1369 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n';
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1370 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb());
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
1371 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1372 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1373 e->type = elem::SLICE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1374 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1375 else if (totype->ty == Tsarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1376 Logger::cout() << "to sarray" << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1377 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1378 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1379 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1380 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1381 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1382 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1383 else if (fromtype->ty == Tpointer) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1384 if (totype->ty == Tpointer || totype->ty == Tclass) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1385 llvm::Value* src = u->getValue();
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1386 Logger::cout() << *src << '|' << *tolltype << '\n';
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1387 e->val = new llvm::BitCastInst(src, tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1388 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1389 else if (totype->isintegral()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1390 e->val = new llvm::PtrToIntInst(u->getValue(), tolltype, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1391 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1392 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1393 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1394 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1395 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1396 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1397 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1398 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1399 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1400 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1401 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1402
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1403 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1404
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1405 elem* SymOffExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1406 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1407 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1408 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1409 elem* e = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1410 if (VarDeclaration* vd = var->isVarDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1411 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1412 Logger::println("VarDeclaration");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1413 if (!vd->llvmTouched && vd->isDataseg())
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1414 vd->toObjFile();
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1415
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1416 if (vd->isTypedefDeclaration()) {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1417 e->istypeinfo = true;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1418 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1419
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
1420 assert(vd->llvmValue);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1421 Type* t = LLVM_DtoDType(type);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1422 Type* vdtype = LLVM_DtoDType(vd->type);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1423
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1424 llvm::Value* llvalue = vd->nestedref ? LLVM_DtoNestedVariable(vd) : vd->llvmValue;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1425
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1426 if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1427 TypeStruct* vdt = (TypeStruct*)vdtype;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1428 e = new elem;
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
1429 std::vector<unsigned> dst(1,0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1430 vdt->sym->offsetToIndex(t->next, offset, dst);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1431 llvm::Value* ptr = llvalue;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1432 assert(ptr);
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1433 e->mem = LLVM_DtoGEP(ptr,dst,"tmp");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1434 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1435 e->field = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1436 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1437 else if (vdtype->ty == Tsarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1438 e = new elem;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1439 assert(llvalue);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1440 e->arg = llvalue;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1441 e->type = elem::VAL;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1442
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1443 const llvm::Type* llt = LLVM_DtoType(t);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1444 llvm::Value* off = 0;
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1445 if (offset != 0) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1446 Logger::println("offset = %d\n", offset);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1447 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1448 if (llvalue->getType() != llt) {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1449 e->mem = p->ir->CreateBitCast(llvalue, llt, "tmp");
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1450 if (offset != 0)
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1451 e->mem = LLVM_DtoGEPi(e->mem, offset, "tmp");
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1452 }
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1453 else {
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1454 assert(offset == 0);
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1455 e->mem = LLVM_DtoGEPi(llvalue,0,0,"tmp");
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1456 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1457 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1458 else if (offset == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1459 e = new elem;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1460 e->type = elem::VAL;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1461 assert(llvalue);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1462 e->mem = llvalue;
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1463
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1464 const llvm::Type* llt = LLVM_DtoType(t);
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1465 if (llvalue->getType() != llt) {
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1466 e->mem = p->ir->CreateBitCast(e->mem, llt, "tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1467 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1468 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1469 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1470 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1471 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1472 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1473 else if (FuncDeclaration* fd = var->isFuncDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1474 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1475 Logger::println("FuncDeclaration");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1476 e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1477 if (fd->llvmValue == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1478 fd->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1479 e->val = fd->llvmValue;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1480 e->type = elem::FUNC;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1481 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1482 assert(e != 0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1483 assert(e->type != elem::NONE);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1484 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1485 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1486
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1487 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1488
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1489 elem* PtrExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1490 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1491 Logger::print("PtrExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1492 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1493 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1494 elem* a = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1495
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1496 if (a->mem)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1497 Logger::cout() << "mem: " << *a->mem << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1498 if (a->val)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1499 Logger::cout() << "val: " << *a->val << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1500
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1501 if (a->field)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1502 e->mem = a->mem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1503 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1504 e->mem = a->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1505 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1506
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1507 delete a;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1508 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1509 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1510
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1511 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1512
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1513 elem* DotVarExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1514 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1515 Logger::print("DotVarExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1516 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1517 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1518
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1519 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1520
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1521 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1522 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1523
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1524 Logger::print("e1->type=%s\n", e1type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1525
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1526 if (VarDeclaration* vd = var->isVarDeclaration()) {
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
1527 std::vector<unsigned> vdoffsets(1,0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1528 llvm::Value* src = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1529 if (e1type->ty == Tpointer) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1530 assert(e1type->next->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1531 TypeStruct* ts = (TypeStruct*)e1type->next;
24
25bb577878e8 [svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents: 23
diff changeset
1532 ts->sym->offsetToIndex(vd->type, vd->offset, vdoffsets);
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
1533 Logger::println("Struct member offset:%d", vd->offset);
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1534 src = l->val ? l->val : l->mem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1535 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1536 else if (e1->type->ty == Tclass) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1537 TypeClass* tc = (TypeClass*)e1type;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1538 Logger::println("Class member offset: %d", vd->offset);
24
25bb577878e8 [svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
lindquist
parents: 23
diff changeset
1539 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1540 src = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1541 }
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
1542 assert(vdoffsets.size() != 1);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1543 assert(src != 0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1544 Logger::cout() << "src: " << *src << '\n';
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
1545 llvm::Value* arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1546 e->mem = arrptr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1547 Logger::cout() << "mem: " << *e->mem << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1548 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1549 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1550 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1551 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1552 if (fdecl->llvmValue == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1553 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1554 fdecl->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1555 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1556
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1557 llvm::Value* funcval = fdecl->llvmValue;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1558 e->arg = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1559
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1560 // virtual call
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1561 if (fdecl->isVirtual()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1562 assert(fdecl->vtblIndex > 0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1563 assert(e1type->ty == Tclass);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1564
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1565 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1566 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false);
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1567 funcval = LLVM_DtoGEP(e->arg, zero, zero, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1568 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1569 funcval = LLVM_DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1570 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1571 assert(funcval->getType() == fdecl->llvmValue->getType());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
1572 e->callconv = LLVM_DtoCallingConv(fdecl->linkage);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1573 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1574 e->val = funcval;
66
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1575 e->type = elem::FUNC;
0c5f410d973c [svn r70] Fixed bug where correct calling convention was not set on calling aggregate methods
lindquist
parents: 64
diff changeset
1576 e->funcdecl = fdecl;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1577 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1578 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1579 printf("unknown: %s\n", var->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1580 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1581 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1582
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1583 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1584
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1585 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1586 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1587
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1588 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1589
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1590 elem* ThisExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1591 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1592 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1593 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1594 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1595
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1596 if (VarDeclaration* vd = var->isVarDeclaration()) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1597 llvm::Value* v = p->func().decl->llvmThisVar;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1598 if (llvm::isa<llvm::AllocaInst>(v))
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1599 v = new llvm::LoadInst(v, "tmp", p->scopebb());
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1600 e->mem = v;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1601 e->type = elem::VAL;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
1602 e->isthis = true;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1603 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1604 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1605 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1606 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1607
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1608 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1609 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1610
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1611 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1612
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1613 elem* AddrExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1614 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1615 Logger::print("AddrExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1616 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1617 elem* e = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1618 e->field = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1619 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1620 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1621
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1622 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1623
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1624 elem* StructLiteralExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1625 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1626 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1627 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1628 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1629
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1630 llvm::Value* sptr = 0;
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1631
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1632 // if there is no lval, this is probably a temporary struct literal. correct?
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1633 if (!p->topexp() || p->topexp()->e2 != this)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1634 {
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1635 sptr = new llvm::AllocaInst(LLVM_DtoType(type),"tmpstructliteral",p->topallocapoint());
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1636 e->mem = sptr;
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1637 e->type = elem::VAR;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1638 }
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1639 // already has memory
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1640 else if (p->topexp()->e2 == this)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1641 {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1642 sptr = p->topexp()->v;
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1643 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1644 else
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1645 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1646
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1647 assert(sptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1648
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1649 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1650
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1651 unsigned n = elements->dim;
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1652 for (unsigned i=0; i<n; ++i)
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1653 {
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1654 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1655 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1656
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1657 Expression* vx = (Expression*)elements->data[i];
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1658 if (vx != 0) {
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1659 p->exps.push_back(IRExp(NULL,vx,arrptr));
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1660 elem* ve = vx->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1661 p->exps.pop_back();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1662
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1663 if (!ve->inplace) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1664 llvm::Value* val = ve->getValue();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1665 Logger::cout() << *val << " | " << *arrptr << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1666
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1667 Type* vxtype = LLVM_DtoDType(vx->type);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1668 LLVM_DtoAssign(vxtype, arrptr, val);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1669 }
30
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1670 delete ve;
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1671 }
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1672 else {
881158a93592 [svn r34] * Fixed passing a struct literal as function argument
lindquist
parents: 29
diff changeset
1673 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1674 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1675 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1676
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1677 e->inplace = true;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1678
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1679 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1680 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1681
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1682 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1683
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1684 llvm::Constant* StructLiteralExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1685 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1686 Logger::print("StructLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1687 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1688
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1689 unsigned n = elements->dim;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1690 std::vector<llvm::Constant*> vals(n, NULL);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1691
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1692 for (unsigned i=0; i<n; ++i)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1693 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1694 Expression* vx = (Expression*)elements->data[i];
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1695 vals[i] = vx->toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1696 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1697
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1698 assert(LLVM_DtoDType(type)->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1699 const llvm::Type* t = LLVM_DtoType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1700 const llvm::StructType* st = llvm::cast<llvm::StructType>(t);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1701 return llvm::ConstantStruct::get(st,vals);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1702 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1703
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1704 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1705
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1706 elem* IndexExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1707 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1708 Logger::print("IndexExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1709 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1710
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1711 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1712
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1713 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1714
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1715 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1716
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1717 p->arrays.push_back(l->mem); // if $ is used it must be an array so this is fine.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1718 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1719 p->arrays.pop_back();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1720
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1721 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1722 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1723
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1724 llvm::Value* arrptr = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1725 if (e1type->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1726 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1727 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1728 else if (e1type->ty == Tsarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1729 arrptr = LLVM_DtoGEP(l->getValue(), zero, r->getValue(),"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1730 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1731 else if (e1type->ty == Tarray) {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1732 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1733 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1734 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1735 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1736 assert(arrptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1737
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1738 e->mem = arrptr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1739 e->type = elem::VAR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1740
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1741 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1742 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1743
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1744 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1745 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1746
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1747 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1748
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1749 elem* SliceExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1750 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1751 Logger::print("SliceExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1752 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1753
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1754 Type* t = LLVM_DtoDType(type);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1755 assert(t->ty == Tarray);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1756
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1757 elem* v = e1->toElem(p);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1758 Type* e1type = LLVM_DtoDType(e1->type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1759
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1760 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1761 assert(v->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1762 e->type = elem::SLICE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1763
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1764 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1765 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1766
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1767 // partial slice
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1768 if (lwr)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1769 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1770 assert(upr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1771 p->arrays.push_back(v->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1772 elem* lo = lwr->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1773
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1774 bool lwr_is_zero = false;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1775 if (lo->type == elem::CONST)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1776 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1777 assert(lo->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1778 assert(llvm::isa<llvm::ConstantInt>(lo->val));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1779
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1780 if (e1type->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1781 e->mem = v->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1782 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1783 else if (e1type->ty == Tarray) {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
1784 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1785 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1786 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1787 else if (e1type->ty == Tsarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1788 e->mem = LLVM_DtoGEP(v->mem,zero,zero,"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1789 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1790 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1791 assert(e->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1792
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1793 llvm::ConstantInt* c = llvm::cast<llvm::ConstantInt>(lo->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1794 if (!(lwr_is_zero = c->isZero())) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1795 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1796 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1797 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1798 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1799 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1800 if (e1type->ty == Tarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1801 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1802 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1803 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1804 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1805 else if (e1type->ty == Tsarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1806 e->mem = LLVM_DtoGEP(v->mem,zero,lo->getValue(),"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1807 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1808 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1809 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1810 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1811
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1812 elem* up = upr->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1813 p->arrays.pop_back();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1814
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1815 if (up->type == elem::CONST)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1816 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1817 assert(up->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1818 assert(llvm::isa<llvm::ConstantInt>(up->val));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1819 if (lwr_is_zero) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1820 e->arg = up->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1821 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1822 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1823 if (lo->type == elem::CONST) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1824 llvm::Constant* clo = llvm::cast<llvm::Constant>(lo->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1825 llvm::Constant* cup = llvm::cast<llvm::Constant>(up->val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1826 e->arg = llvm::ConstantExpr::getSub(cup, clo);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1827 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1828 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1829 e->arg = llvm::BinaryOperator::createSub(up->val, lo->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1830 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1831 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1832 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1833 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1834 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1835 if (lwr_is_zero) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1836 e->arg = up->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1837 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1838 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1839 e->arg = llvm::BinaryOperator::createSub(up->getValue(), lo->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1840 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1841 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1842
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1843 delete lo;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1844 delete up;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1845
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1846 /*
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1847 llvm::Value* tmpmem = new llvm::AllocaInst(LLVM_DtoType(t),"tmp",p->topallocapoint());
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1848 llvm::Value* ptr = LLVM_DtoGEPi(tmpmem,0,0,"tmp");
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1849 p->ir->CreateStore(e->arg, ptr);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1850 ptr = LLVM_DtoGEPi(tmpmem,0,1,"tmp");
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1851 p->ir->CreateStore(e->mem, ptr);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1852 e->arg = NULL;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1853 e->mem = tmpmem;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
1854 */
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1855 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1856 // full slice
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1857 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1858 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1859 e->mem = v->mem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1860 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1861
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1862 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1863
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1864 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1865 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1866
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1867 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1868
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1869 elem* CmpExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1870 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1871 Logger::print("CmpExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1872 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1873
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1874 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1875
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1876 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1877 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1878
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1879 Type* t = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1880 Type* e2t = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1881 assert(t == e2t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1882
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1883 if (t->isintegral() || t->ty == Tpointer)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1884 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1885 llvm::ICmpInst::Predicate cmpop;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1886 bool skip = false;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1887 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1888 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1889 case TOKlt:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1890 case TOKul:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1891 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1892 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1893 case TOKle:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1894 case TOKule:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1895 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1896 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1897 case TOKgt:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1898 case TOKug:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1899 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1900 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1901 case TOKge:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1902 case TOKuge:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1903 cmpop = t->isunsigned() ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1904 break;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1905 case TOKue:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1906 cmpop = llvm::ICmpInst::ICMP_EQ;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1907 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1908 case TOKlg:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1909 cmpop = llvm::ICmpInst::ICMP_NE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1910 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1911 case TOKleg:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1912 skip = true;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1913 e->val = llvm::ConstantInt::getTrue();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1914 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1915 case TOKunord:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1916 skip = true;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1917 e->val = llvm::ConstantInt::getFalse();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1918 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1919
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1920 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1921 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1922 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1923 if (!skip)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1924 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1925 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1926 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1927 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1928 else if (t->isfloating())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1929 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1930 llvm::FCmpInst::Predicate cmpop;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1931 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1932 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1933 case TOKlt:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1934 cmpop = llvm::FCmpInst::FCMP_OLT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1935 case TOKle:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1936 cmpop = llvm::FCmpInst::FCMP_OLE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1937 case TOKgt:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1938 cmpop = llvm::FCmpInst::FCMP_OGT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1939 case TOKge:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1940 cmpop = llvm::FCmpInst::FCMP_OGE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1941 case TOKunord:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1942 cmpop = llvm::FCmpInst::FCMP_UNO;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1943 case TOKule:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1944 cmpop = llvm::FCmpInst::FCMP_ULE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1945 case TOKul:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1946 cmpop = llvm::FCmpInst::FCMP_ULT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1947 case TOKuge:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1948 cmpop = llvm::FCmpInst::FCMP_UGE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1949 case TOKug:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1950 cmpop = llvm::FCmpInst::FCMP_UGT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1951 case TOKue:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1952 cmpop = llvm::FCmpInst::FCMP_UEQ;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1953 case TOKlg:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1954 cmpop = llvm::FCmpInst::FCMP_ONE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1955 case TOKleg:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1956 cmpop = llvm::FCmpInst::FCMP_ORD;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1957
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1958 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1959 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1960 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1961 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1962 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1963 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1964 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1965 assert(0 && "Unsupported CmpExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1966 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1967
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1968 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1969 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1970
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1971 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1972
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1973 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1974 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1975
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1976 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1977
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1978 elem* EqualExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1979 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1980 Logger::print("EqualExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1981 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1982
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1983 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1984
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1985 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1986 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1987
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1988 Type* t = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1989 Type* e2t = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1990 assert(t == e2t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1991
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1992 if (t->isintegral() || t->ty == Tpointer)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1993 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1994 Logger::println("integral or pointer");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1995 llvm::ICmpInst::Predicate cmpop;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1996 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1997 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1998 case TOKequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1999 cmpop = llvm::ICmpInst::ICMP_EQ;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2000 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2001 case TOKnotequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2002 cmpop = llvm::ICmpInst::ICMP_NE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2003 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2004 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2005 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2006 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2007 e->val = new llvm::ICmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2008 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2009 else if (t->isfloating())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2010 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
2011 Logger::println("floating");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2012 llvm::FCmpInst::Predicate cmpop;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2013 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2014 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2015 case TOKequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2016 cmpop = llvm::FCmpInst::FCMP_OEQ;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2017 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2018 case TOKnotequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2019 cmpop = llvm::FCmpInst::FCMP_UNE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2020 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2021 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2022 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2023 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2024 e->val = new llvm::FCmpInst(cmpop, l->getValue(), r->getValue(), "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2025 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2026 else if (t->ty == Tsarray)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2027 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
2028 Logger::println("static array");
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2029 e->val = LLVM_DtoStaticArrayCompare(op,l->mem,r->mem);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2030 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2031 else if (t->ty == Tarray)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2032 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
2033 Logger::println("dynamic array");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
2034 e->val = LLVM_DtoDynArrayCompare(op,l->mem,r->mem);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2035 }
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
2036 else if (t->ty == Tdelegate)
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
2037 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
2038 Logger::println("delegate");
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
2039 e->val = LLVM_DtoCompareDelegate(op,l->mem,r->mem);
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
2040 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2041 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2042 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2043 assert(0 && "Unsupported EqualExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2044 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2045
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2046 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2047 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2048
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2049 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2050
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2051 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2052 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2053
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2054 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2055
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2056 elem* PostExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2057 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2058 Logger::print("PostExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2059 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2060
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2061 elem* l = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2062 elem* r = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2063
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2064 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2065 e->mem = l->mem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2066 e->val = l->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2067 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2068
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2069 llvm::Value* val = e->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2070 llvm::Value* post = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2071
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2072 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2073 Type* e2type = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2074
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2075 if (e1type->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2076 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2077 assert(e2type->isintegral());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2078 llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2079 if (op == TOKplusplus) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2080 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2081 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2082 else if (op == TOKminusminus) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2083 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2084 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2085 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2086 else if (e1type->ty == Tpointer)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2087 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2088 assert(e2type->isintegral());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2089 llvm::Constant* minusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)-1,true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2090 llvm::Constant* plusone = llvm::ConstantInt::get(LLVM_DtoSize_t(),(uint64_t)1,false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2091 llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2092 post = new llvm::GetElementPtrInst(val, whichone, "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2093 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2094 else if (e1type->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2095 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2096 assert(e2type->isfloating());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2097 llvm::Value* one = llvm::ConstantFP::get(val->getType(), 1.0f);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2098 if (op == TOKplusplus) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2099 post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2100 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2101 else if (op == TOKminusminus) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2102 post = llvm::BinaryOperator::createSub(val,one,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2103 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2104 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2105 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2106 assert(post);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2107
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2108 //llvm::Value* tostore = l->storeVal ? l->storeVal : l->val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2109 new llvm::StoreInst(post,l->mem,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2110
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2111 delete l;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2112 delete r;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2113
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2114 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2115 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2116
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2117 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2118
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2119 elem* NewExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2120 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2121 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2122 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2123
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2124 assert(!thisexp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2125 assert(!newargs);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2126 assert(newtype);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2127 assert(!allocator);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2128
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2129 elem* e = new elem;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2130 e->inplace = true;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2131
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2132 Type* ntype = LLVM_DtoDType(newtype);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2133
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2134 const llvm::Type* t = LLVM_DtoType(ntype);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2135
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2136 if (onstack) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2137 assert(ntype->ty == Tclass);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2138 e->mem = new llvm::AllocaInst(t->getContainedType(0),"tmp",p->topallocapoint());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2139 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2140 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2141 if (ntype->ty == Tclass) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2142 e->mem = new llvm::MallocInst(t->getContainedType(0),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2143 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2144 else if (ntype->ty == Tarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2145 assert(arguments);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2146 if (arguments->dim == 1) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2147 elem* sz = ((Expression*)arguments->data[0])->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2148 llvm::Value* dimval = sz->getValue();
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2149 Type* nnt = LLVM_DtoDType(ntype->next);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2150 if (nnt->ty == Tvoid)
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2151 nnt = Type::tint8;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2152 if (!p->topexp() || p->topexp()->e2 != this) {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2153 const llvm::Type* restype = LLVM_DtoType(type);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2154 Logger::cout() << "restype = " << *restype << '\n';
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2155 e->mem = new llvm::AllocaInst(restype,"tmp",p->topallocapoint());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2156 LLVM_DtoNewDynArray(e->mem, dimval, nnt);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2157 e->inplace = false;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2158 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2159 else if (p->topexp() || p->topexp()->e2 != this) {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2160 assert(p->topexp()->v);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2161 e->mem = p->topexp()->v;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2162 LLVM_DtoNewDynArray(e->mem, dimval, nnt);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2163 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2164 else
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2165 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2166 delete sz;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2167 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2168 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2169 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2170 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2171 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2172 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2173 e->mem = new llvm::MallocInst(t,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2174 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2175 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2176
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2177 if (ntype->ty == Tclass) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2178 // first apply the static initializer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2179 assert(e->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2180 LLVM_DtoInitClass((TypeClass*)ntype, e->mem);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2181
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2182 // then call constructor
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2183 if (arguments) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2184 assert(member);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2185 assert(member->llvmValue);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2186 llvm::Function* fn = llvm::cast<llvm::Function>(member->llvmValue);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2187 TypeFunction* tf = (TypeFunction*)LLVM_DtoDType(member->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2188
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2189 std::vector<llvm::Value*> ctorargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2190 ctorargs.push_back(e->mem);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2191 for (size_t i=0; i<arguments->dim; ++i)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2192 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2193 Expression* ex = (Expression*)arguments->data[i];
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2194 Argument* fnarg = Argument::getNth(tf->parameters, i);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2195 llvm::Value* a = LLVM_DtoArgument(fn->getFunctionType()->getParamType(i+1), fnarg, ex);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2196 ctorargs.push_back(a);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2197 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2198 e->mem = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2199 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2200 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2201 else if (ntype->ty == Tstruct) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2202 TypeStruct* ts = (TypeStruct*)ntype;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2203 if (ts->isZeroInit()) {
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
2204 LLVM_DtoStructZeroInit(e->mem);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2205 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2206 else {
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
2207 LLVM_DtoStructCopy(e->mem,ts->llvmInit);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2208 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2209 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2210
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2211 e->type = elem::VAR;
15
37a4fdab33fc [svn r19] * Added support for reassigning 'this' inside class constructors.
lindquist
parents: 14
diff changeset
2212
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2213 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2214 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2215
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2216 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2217
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2218 elem* DeleteExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2219 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2220 Logger::print("DeleteExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2221 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2222
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2223 //assert(e1->type->ty != Tclass);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2224
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2225 elem* v = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2226 llvm::Value* val = v->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2227 llvm::Value* ldval = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2228
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2229 const llvm::Type* t = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2230 llvm::Constant* z = llvm::Constant::getNullValue(t);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2231
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2232 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2233
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2234 if (e1type->ty == Tpointer) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2235 ldval = v->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2236 new llvm::FreeInst(ldval, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2237
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2238 Logger::cout() << *z << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2239 Logger::cout() << *val << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2240 new llvm::StoreInst(z, v->mem, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2241 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2242 else if (e1type->ty == Tclass) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2243 TypeClass* tc = (TypeClass*)e1type;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2244 LLVM_DtoCallClassDtors(tc, val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2245
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2246 if (v->vardecl && !v->vardecl->onstack) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2247 new llvm::FreeInst(val, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2248 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2249 new llvm::StoreInst(z, v->mem, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2250 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2251 else if (e1type->ty == Tarray) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2252 // must be on the heap (correct?)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2253 ldval = v->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2254
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2255 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2256 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2257
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
2258 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2259 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2260 new llvm::FreeInst(ptr, p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2261 LLVM_DtoNullArray(val);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2262 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2263 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2264 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2265 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2266
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2267 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2268
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2269 // this expression produces no useful data
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2270 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2271 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2272
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2273 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2274
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2275 elem* ArrayLengthExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2276 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2277 Logger::print("ArrayLengthExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2278 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2279
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2280 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2281 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2282
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2283 if (p->topexp() && p->topexp()->e1 == this)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2284 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2285 e->mem = u->mem;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2286 e->type = elem::ARRAYLEN;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2287 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2288 else
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2289 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2290 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2291 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2292 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2293 e->type = elem::VAL;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2294 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2295 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2296
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2297 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2298 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2299
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2300 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2301
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2302 elem* AssertExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2303 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2304 Logger::print("AssertExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2305 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2306
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2307 elem* u = e1->toElem(p);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2308 elem* m = msg ? msg->toElem(p) : NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2309
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2310 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2311 LLVM_DtoAssert(u->getValue(), loca, m ? m->val : NULL);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2312
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2313 delete m;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2314 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2315
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 32
diff changeset
2316 return new elem;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2317 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2318
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2319 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2320
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2321 elem* NotExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2322 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2323 Logger::print("NotExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2324 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2325
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2326 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2327 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2328
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2329 llvm::Value* b = LLVM_DtoBoolean(u->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2330
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2331 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2332 e->val = p->ir->CreateICmpEQ(b,zero);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2333 //e->val = new llvm::ICmpInst(llvm::ICmpInst::ICMP_EQ,b,zero,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2334 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2335
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2336 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2337
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2338 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2339 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2340
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2341 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2342
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2343 elem* AndAndExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2344 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2345 Logger::print("AndAndExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2346 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2347
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2348 // allocate a temporary for the final result. failed to come up with a better way :/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2349 llvm::Value* resval = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2350 llvm::BasicBlock* entryblock = &p->topfunc()->front();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2351 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"andandtmp",p->topallocapoint());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2352
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2353 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2354 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2355
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2356 llvm::BasicBlock* oldend = p->scopeend();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2357 llvm::BasicBlock* andand = new llvm::BasicBlock("andand", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2358 llvm::BasicBlock* andandend = new llvm::BasicBlock("andandend", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2359
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2360 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2361 new llvm::StoreInst(ubool,resval,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2362 new llvm::BranchInst(andand,andandend,ubool,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2363
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2364 p->scope() = IRScope(andand, andandend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2365 elem* v = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2366
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2367 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2368 llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2369 new llvm::StoreInst(uandvbool,resval,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2370 new llvm::BranchInst(andandend,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2371
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2372 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2373 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2374
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2375 p->scope() = IRScope(andandend, oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2376
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2377 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2378 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2379
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2380 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2381 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2382
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2383 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2384
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2385 elem* OrOrExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2386 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2387 Logger::print("OrOrExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2388 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2389
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2390 // allocate a temporary for the final result. failed to come up with a better way :/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2391 llvm::Value* resval = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2392 llvm::BasicBlock* entryblock = &p->topfunc()->front();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2393 resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"orortmp",p->topallocapoint());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2394
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2395 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2396 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2397
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2398 llvm::BasicBlock* oldend = p->scopeend();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2399 llvm::BasicBlock* oror = new llvm::BasicBlock("oror", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2400 llvm::BasicBlock* ororend = new llvm::BasicBlock("ororend", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2401
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2402 llvm::Value* ubool = LLVM_DtoBoolean(u->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2403 new llvm::StoreInst(ubool,resval,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2404 new llvm::BranchInst(ororend,oror,ubool,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2405
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2406 p->scope() = IRScope(oror, ororend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2407 elem* v = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2408
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2409 llvm::Value* vbool = LLVM_DtoBoolean(v->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2410 new llvm::StoreInst(vbool,resval,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2411 new llvm::BranchInst(ororend,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2412
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2413 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2414 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2415
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2416 p->scope() = IRScope(ororend, oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2417
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2418 e->val = new llvm::LoadInst(resval,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2419 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2420
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2421 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2422 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2423
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2424 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2425
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2426 #define BinBitExp(X,Y) \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2427 elem* X##Exp::toElem(IRState* p) \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2428 { \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2429 Logger::print("%sExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2430 LOG_SCOPE; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2431 elem* e = new elem; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2432 elem* u = e1->toElem(p); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2433 elem* v = e2->toElem(p); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2434 e->val = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getValue(), v->getValue(), "tmp", p->scopebb()); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2435 e->type = elem::VAL; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2436 delete u; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2437 delete v; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2438 return e; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2439 } \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2440 \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2441 elem* X##AssignExp::toElem(IRState* p) \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2442 { \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2443 Logger::print("%sAssignExp::toElem: %s | %s\n", #X, toChars(), type->toChars()); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2444 LOG_SCOPE; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2445 elem* u = e1->toElem(p); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2446 elem* v = e2->toElem(p); \
42
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2447 llvm::Value* uval = u->getValue(); \
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2448 assert(uval); \
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2449 llvm::Value* vval = v->getValue(); \
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2450 assert(vval); \
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2451 llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
2452 if (u->mem == 0) \
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 28
diff changeset
2453 LLVM_DtoGiveArgumentStorage(u); \
42
0b9b286b67b6 [svn r46] fix for shift operations
lindquist
parents: 40
diff changeset
2454 Logger::cout() << *tmp << '|' << *u->mem << '\n'; \
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2455 new llvm::StoreInst(LLVM_DtoPointedType(u->mem, tmp), u->mem, p->scopebb()); \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2456 delete u; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2457 delete v; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2458 elem* e = new elem; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2459 e->mem = u->mem; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2460 e->type = elem::VAR; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2461 return e; \
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2462 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2463
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2464 BinBitExp(And,And);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2465 BinBitExp(Or,Or);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2466 BinBitExp(Xor,Xor);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2467 BinBitExp(Shl,Shl);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2468 BinBitExp(Shr,AShr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2469 BinBitExp(Ushr,LShr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2470
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2471 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2472
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2473 elem* HaltExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2474 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2475 Logger::print("HaltExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2476 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2477
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2478 llvm::Value* loca = llvm::ConstantInt::get(llvm::Type::Int32Ty, loc.linnum, false);
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2479 LLVM_DtoAssert(llvm::ConstantInt::getFalse(), loca, NULL);
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2480
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2481 new llvm::UnreachableInst(p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2482 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2483 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2484
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2485 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2486
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2487 elem* DelegateExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2488 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2489 Logger::print("DelegateExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2490 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2491
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2492 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2493 elem* u = e1->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2494
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2495 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2496 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2497
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2498 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2499
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2500 assert(p->topexp() && p->topexp()->e2 == this && p->topexp()->v);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2501 llvm::Value* lval = p->topexp()->v;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2502
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
2503 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2504 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2505 new llvm::StoreInst(castcontext, context, p->scopebb());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2506
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 5
diff changeset
2507 llvm::Value* fptr = LLVM_DtoGEP(lval,zero,one,"tmp",p->scopebb());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2508
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2509 assert(func->llvmValue);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2510 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2511 new llvm::StoreInst(castfptr, fptr, p->scopebb());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2512
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2513 e->inplace = true;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2514
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2515 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2516 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2517 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2518
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2519 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2520
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2521 elem* IdentityExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2522 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2523 Logger::print("IdentityExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2524 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2525
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2526 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2527 elem* v = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2528
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2529 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2530
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2531 llvm::Value* l = u->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2532 llvm::Value* r = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2533 if (v->type == elem::NUL)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2534 r = llvm::ConstantPointerNull::get(llvm::cast<llvm::PointerType>(l->getType()));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2535 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2536 r = v->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2537
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2538 Type* t1 = LLVM_DtoDType(e1->type);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2539
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2540 if (t1->ty == Tarray) {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2541 assert(l->getType() == r->getType());
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2542 e->val = LLVM_DtoDynArrayIs(op,l,r);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2543 }
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2544 else {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2545 llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2546 e->val = new llvm::ICmpInst(pred, l, r, "tmp", p->scopebb());
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2547 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2548 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2549
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2550 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2551 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2552
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2553 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2554 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2555
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2556 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2557
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2558 elem* CommaExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2559 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2560 Logger::print("CommaExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2561 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2562
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2563 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2564 elem* v = e2->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2565 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2566 return v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2567 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2568
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2569 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2570
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2571 elem* CondExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2572 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2573 Logger::print("CondExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2574 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2575
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2576 Type* dtype = LLVM_DtoDType(type);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2577 const llvm::Type* resty = LLVM_DtoType(dtype);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2578
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2579 // allocate a temporary for the final result. failed to come up with a better way :/
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2580 llvm::BasicBlock* entryblock = &p->topfunc()->front();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2581 llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2582
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2583 llvm::BasicBlock* oldend = p->scopeend();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2584 llvm::BasicBlock* condtrue = new llvm::BasicBlock("condtrue", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2585 llvm::BasicBlock* condfalse = new llvm::BasicBlock("condfalse", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2586 llvm::BasicBlock* condend = new llvm::BasicBlock("condend", gIR->topfunc(), oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2587
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2588 elem* c = econd->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2589 llvm::Value* cond_val = LLVM_DtoBoolean(c->getValue());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2590 delete c;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2591 new llvm::BranchInst(condtrue,condfalse,cond_val,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2592
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2593 p->scope() = IRScope(condtrue, condfalse);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2594 elem* u = e1->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2595 LLVM_DtoAssign(dtype, resval, u->getValue());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2596 new llvm::BranchInst(condend,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2597 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2598
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2599 p->scope() = IRScope(condfalse, condend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2600 elem* v = e2->toElem(p);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2601 LLVM_DtoAssign(dtype, resval, v->getValue());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2602 new llvm::BranchInst(condend,p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2603 delete v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2604
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2605 p->scope() = IRScope(condend, oldend);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2606
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2607 elem* e = new elem;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2608 e->mem = resval;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2609 e->type = elem::VAR;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2610 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2611 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2612
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2613 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2614
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2615 elem* ComExp::toElem(IRState* p)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2616 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2617 Logger::print("ComExp::toElem: %s | %s\n", toChars(), type->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2618 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2619
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2620 elem* e = new elem;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2621 elem* u = e1->toElem(p);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2622
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2623 llvm::Value* value = u->getValue();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2624 llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2625 e->val = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2626
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2627 delete u;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2628
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2629 e->type = elem::VAL;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2630
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2631 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2632 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2633
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2634 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2635
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2636 elem* NegExp::toElem(IRState* p)
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2637 {
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2638 Logger::print("NegExp::toElem: %s | %s\n", toChars(), type->toChars());
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2639 LOG_SCOPE;
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2640 elem* e = new elem;
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2641 elem* l = e1->toElem(p);
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2642 llvm::Value* val = l->getValue();
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2643 delete l;
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2644
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2645 Type* t = LLVM_DtoDType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2646
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2647 llvm::Value* zero = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2648 if (t->isintegral())
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2649 zero = llvm::ConstantInt::get(val->getType(), 0, true);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2650 else if (t->isfloating()) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2651 if (t->ty == Tfloat32)
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2652 zero = llvm::ConstantFP::get(val->getType(), float(0));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2653 else if (t->ty == Tfloat64 || t->ty == Tfloat80)
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2654 zero = llvm::ConstantFP::get(val->getType(), double(0));
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2655 else
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2656 assert(0);
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2657 }
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2658 else
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2659 assert(0);
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2660
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2661 e->val = llvm::BinaryOperator::createSub(zero,val,"tmp",p->scopebb());
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2662 e->type = elem::VAL;
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2663
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2664 return e;
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2665 }
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2666
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2667 //////////////////////////////////////////////////////////////////////////////////////////
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2668
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2669 elem* CatExp::toElem(IRState* p)
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2670 {
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2671 Logger::print("CatExp::toElem: %s | %s\n", toChars(), type->toChars());
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2672 LOG_SCOPE;
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2673
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2674 Type* t = LLVM_DtoDType(type);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2675
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2676 bool inplace = false;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2677 llvm::Value* dst = 0;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2678 IRExp* ex = p->topexp();
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2679 if (ex && ex->e2 == this) {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2680 assert(ex->v);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2681 dst = ex->v;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2682 inplace = true;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2683 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2684 else {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2685 assert(t->ty == Tarray);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2686 const llvm::Type* arrty = LLVM_DtoType(t);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2687 dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2688 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2689
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2690 LLVM_DtoCatArrays(dst,e1,e2);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2691
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2692 elem* e = new elem;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2693 e->mem = dst;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2694 e->type = elem::VAR;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2695 e->inplace = inplace;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2696
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2697 return e;
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2698 }
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2699
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2700 //////////////////////////////////////////////////////////////////////////////////////////
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2701
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2702 elem* CatAssignExp::toElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2703 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2704 Logger::print("CatAssignExp::toElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2705 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2706
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2707 elem* l = e1->toElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2708 assert(l->mem);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2709
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2710 Type* e1type = LLVM_DtoDType(e1->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2711 Type* elemtype = LLVM_DtoDType(e1type->next);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2712 Type* e2type = LLVM_DtoDType(e2->type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2713
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2714 if (e2type == elemtype) {
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
2715 LLVM_DtoCatAssignElement(l->mem,e2);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2716 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2717 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2718 assert(0 && "only one element at a time right now");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2719
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2720 return 0;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2721 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2722
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2723 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2724
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2725 elem* ArrayLiteralExp::toElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2726 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2727 Logger::print("ArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2728 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2729
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2730 const llvm::Type* t = LLVM_DtoType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2731 Logger::cout() << "array literal has llvm type: " << *t << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2732
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2733 llvm::Value* mem = 0;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2734 if (!p->topexp() || p->topexp()->e2 != this) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2735 assert(LLVM_DtoDType(type)->ty == Tsarray);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2736 mem = new llvm::AllocaInst(t,"tmparrayliteral",p->topallocapoint());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2737 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2738 else if (p->topexp()->e2 == this) {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2739 mem = p->topexp()->v;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2740 assert(mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2741 if (!llvm::isa<llvm::PointerType>(mem->getType()) ||
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2742 !llvm::isa<llvm::ArrayType>(mem->getType()->getContainedType(0)))
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2743 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2744 error("TODO array literals can currently only be used to initialise static arrays");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2745 fatal();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2746 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2747 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2748 else
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2749 assert(0);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2750
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2751 for (unsigned i=0; i<elements->dim; ++i)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2752 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2753 Expression* expr = (Expression*)elements->data[i];
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2754 llvm::Value* elemAddr = LLVM_DtoGEPi(mem,0,i,"tmp",p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2755 elem* e = expr->toElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2756 new llvm::StoreInst(e->getValue(), elemAddr, p->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2757 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2758
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2759 elem* e = new elem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2760 e->mem = mem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2761 e->type = elem::VAL;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2762 e->inplace = true;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2763
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2764 return e;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2765 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2766
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2767 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2768
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2769 llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2770 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2771 Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2772 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2773
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2774 const llvm::Type* t = LLVM_DtoType(type);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2775 Logger::cout() << "array literal has llvm type: " << *t << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2776 assert(llvm::isa<llvm::ArrayType>(t));
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2777 const llvm::ArrayType* arrtype = llvm::cast<llvm::ArrayType>(t);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2778
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2779 assert(arrtype->getNumElements() == elements->dim);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2780 std::vector<llvm::Constant*> vals(elements->dim, NULL);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2781 for (unsigned i=0; i<elements->dim; ++i)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2782 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2783 Expression* expr = (Expression*)elements->data[i];
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2784 vals[i] = expr->toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2785 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2786
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2787 return llvm::ConstantArray::get(arrtype, vals);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2788 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2789
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2790 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2791
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2792 elem* FuncExp::toElem(IRState* p)
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2793 {
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2794 Logger::print("FuncExp::toElem: %s | %s\n", toChars(), type->toChars());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2795 LOG_SCOPE;
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2796
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2797 assert(fd);
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2798
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2799 if (fd->isNested()) Logger::println("nested");
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2800 Logger::println("kind = %s\n", fd->kind());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2801
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2802 fd->toObjFile();
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2803
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2804 llvm::Value* lval = NULL;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2805 if (!p->topexp() || p->topexp()->e2 != this) {
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2806 const llvm::Type* dgty = LLVM_DtoType(type);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2807 Logger::cout() << "delegate without explicit storage:" << '\n' << *dgty << '\n';
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2808 lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint());
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2809 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2810 else if (p->topexp()->e2 == this) {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2811 lval = p->topexp()->v;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2812 assert(lval);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2813 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2814 else
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2815 assert(0);
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2816
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2817 elem* e = new elem;
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2818
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2819 llvm::Value* context = LLVM_DtoGEPi(lval,0,0,"tmp",p->scopebb());
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2820 const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(context->getType()->getContainedType(0));
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2821 llvm::Value* llvmNested = p->func().decl->llvmNested;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2822 if (llvmNested == NULL) {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2823 llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2824 p->ir->CreateStore(nullcontext, context);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2825 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2826 else {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2827 llvm::Value* nestedcontext = p->ir->CreateBitCast(llvmNested, pty, "tmp");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2828 p->ir->CreateStore(nestedcontext, context);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2829 }
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2830
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2831 llvm::Value* fptr = LLVM_DtoGEPi(lval,0,1,"tmp",p->scopebb());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2832
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2833 assert(fd->llvmValue);
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2834 llvm::Value* castfptr = new llvm::BitCastInst(fd->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2835 new llvm::StoreInst(castfptr, fptr, p->scopebb());
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2836
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2837 e->inplace = true;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2838 e->mem = lval;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
2839 e->type = elem::VAR;
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2840
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2841 return e;
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2842 }
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2843
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2844 //////////////////////////////////////////////////////////////////////////////////////////
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2845
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2846 #define STUB(x) elem *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2847 //STUB(IdentityExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2848 //STUB(CondExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2849 //STUB(EqualExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2850 STUB(InExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2851 //STUB(CmpExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2852 //STUB(AndAndExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2853 //STUB(OrOrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2854 //STUB(AndExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2855 //STUB(AndAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2856 //STUB(OrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2857 //STUB(OrAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2858 //STUB(XorExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2859 //STUB(XorAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2860 //STUB(ShrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2861 //STUB(ShrAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2862 //STUB(ShlExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2863 //STUB(ShlAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2864 //STUB(UshrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2865 //STUB(UshrAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2866 //STUB(DivExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2867 //STUB(DivAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2868 //STUB(MulExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2869 //STUB(MulAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2870 //STUB(ModExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2871 //STUB(ModAssignExp);
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2872 //STUB(CatExp);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2873 //STUB(CatAssignExp);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2874 //STUB(AddExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2875 //STUB(AddAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2876 STUB(Expression);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2877 //STUB(MinExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2878 //STUB(MinAssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2879 //STUB(PostExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2880 //STUB(NullExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2881 //STUB(ThisExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2882 //STUB(CallExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2883 STUB(DotTypeExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2884 STUB(TypeDotIdExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2885 //STUB(DotVarExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2886 //STUB(AssertExp);
49
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2887 //STUB(FuncExp);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2888 //STUB(DelegateExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2889 //STUB(VarExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2890 //STUB(DeclarationExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2891 //STUB(NewExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2892 //STUB(SymOffExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2893 STUB(ScopeExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2894 //STUB(AssignExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2895
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2896 STUB(TypeExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2897 //STUB(RealExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2898 STUB(ComplexExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2899 //STUB(StringExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2900 //STUB(IntegerExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2901 STUB(BoolExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2902
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2903 //STUB(NotExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2904 //STUB(ComExp);
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2905 //STUB(NegExp);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2906 //STUB(PtrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2907 //STUB(AddrExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2908 //STUB(SliceExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2909 //STUB(CastExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2910 //STUB(DeleteExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2911 //STUB(IndexExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2912 //STUB(CommaExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2913 //STUB(ArrayLengthExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2914 //STUB(HaltExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2915 STUB(RemoveExp);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2916 //STUB(ArrayLiteralExp);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2917 STUB(AssocArrayLiteralExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2918 //STUB(StructLiteralExp);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2919
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2920 #define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); assert(0); fatal(); return NULL; }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2921 CONSTSTUB(Expression);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2922 //CONSTSTUB(IntegerExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2923 //CONSTSTUB(RealExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2924 //CONSTSTUB(NullExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2925 //CONSTSTUB(StringExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2926 //CONSTSTUB(VarExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2927 //CONSTSTUB(ArrayLiteralExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2928 CONSTSTUB(AssocArrayLiteralExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2929 //CONSTSTUB(StructLiteralExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2930
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2931 unsigned Type::totym() { return 0; }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2932
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2933 type * Type::toCtype()
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2934 {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2935 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2936 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2937 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2938
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2939 type * Type::toCParamtype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2940 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2941 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2942 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2943 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2944 Symbol * Type::toSymbol()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2945 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2946 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2947 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2948 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2949
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2950 type *
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2951 TypeTypedef::toCtype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2952 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2953 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2954 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2955 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2956
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2957 type *
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2958 TypeTypedef::toCParamtype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2959 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2960 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2961 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2962 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2963
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2964 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2965 TypedefDeclaration::toDebug()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2966 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2967 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2968 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2969
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2970
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2971 type *
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2972 TypeEnum::toCtype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2973 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2974 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2975 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2976 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2977
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2978 type *
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2979 TypeStruct::toCtype()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2980 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2981 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2982 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2983 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2984
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2985 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2986 StructDeclaration::toDebug()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2987 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2988 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2989 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2990
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2991 Symbol * TypeClass::toSymbol()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2992 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2993 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2994 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2995 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2996
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2997 unsigned TypeFunction::totym()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2998 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
2999 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3000 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3001 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3002
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3003 type * TypeFunction::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3004 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3005 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3006 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3007 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3008
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3009 type * TypeSArray::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3010 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3011 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3012 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3013 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3014
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3015 type *TypeSArray::toCParamtype()
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3016 {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3017 assert(0);
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3018 return 0;
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3019 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3020
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3021 type * TypeDArray::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3022 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3023 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3024 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3025 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3026
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3027 type * TypeAArray::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3028 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3029 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3030 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3031 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3032
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3033 type * TypePointer::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3034 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3035 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3036 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3037 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3038
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3039 type * TypeDelegate::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3040 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3041 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3042 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3043 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3044
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3045 type * TypeClass::toCtype()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3046 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3047 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3048 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3049 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3050
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3051 void ClassDeclaration::toDebug()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3052 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3053 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3054 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3055
14
0e86428ee567 [svn r18] * Initial support for switch statements - No string switches yet.
lindquist
parents: 11
diff changeset
3056 //////////////////////////////////////////////////////////////////////////////
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3057
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3058 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3059 EnumDeclaration::toDebug()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3060 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3061 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3062 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3063
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3064 int Dsymbol::cvMember(unsigned char*)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3065 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3066 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3067 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3068 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3069 int EnumDeclaration::cvMember(unsigned char*)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3070 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3071 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3072 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3073 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3074 int FuncDeclaration::cvMember(unsigned char*)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3075 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3076 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3077 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3078 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3079 int VarDeclaration::cvMember(unsigned char*)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3080 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3081 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3082 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3083 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3084 int TypedefDeclaration::cvMember(unsigned char*)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3085 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3086 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3087 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3088 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3089
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3090 void obj_includelib(char*){}
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3091
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3092 AsmStatement::AsmStatement(Loc loc, Token *tokens) :
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3093 Statement(loc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3094 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3095 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3096 }
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3097 Statement *AsmStatement::syntaxCopy()
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3098 {
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3099 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3100 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3101 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3102
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3103 Statement *AsmStatement::semantic(Scope *sc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3104 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3105 return Statement::semantic(sc);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3106 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3107
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3108
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3109 void AsmStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3110 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3111 Statement::toCBuffer(buf, hgs);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3112 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3113
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3114 int AsmStatement::comeFrom()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3115 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3116 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3117 return FALSE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3118 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3119
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3120 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3121 backend_init()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3122 {
37
77cdca8c210f [svn r41] new'd dynamic arrays are now initialized with the element type's default initializer.
lindquist
parents: 36
diff changeset
3123 // now lazily loaded
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3124 //LLVM_D_InitRuntime();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3125 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3126
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3127 void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3128 backend_term()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3129 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3130 LLVM_D_FreeRuntime();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3131 }