changeset 187:08b6ce45b456

Changed the way static arrays are represented Now uses [3 x i32] rather than [3 x i32]*, and when using constants they are copied before use. Also dixed a test or two
author Anders Halager <halager@gmail.com>
date Fri, 25 Jul 2008 12:53:58 +0200
parents e1e170c2cd44
children b3e0729c8524
files gen/CodeGen.d tests/code/function_pointer_2.d tests/code/struct_7.d tests/parser/for_2.d.s tests/parser/function_pointer.d tests/parser/string_1.d
diffstat 6 files changed, 46 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/gen/CodeGen.d	Fri Jul 25 12:50:09 2008 +0200
+++ b/gen/CodeGen.d	Fri Jul 25 12:53:58 2008 +0200
@@ -325,14 +325,9 @@
                     case NumberType.Real:
                         return RValue(ConstantReal.Get(Type.X86_FP80, integerLit.number.floating));
                 }
-            case ExpType.StringExp:
-                auto stringExp = cast(StringExp)exp;
-                char[] data = cast(char[])stringExp.data;
-                auto string_constant = ConstantArray.GetString(data, true);
-                auto gv = m.addGlobal(string_constant, "string");
-                gv.linkage = Linkage.Internal;
-                gv.globalConstant = true;
-                return RValue(gv);
+            case ExpType.StringExp,
+                 ExpType.ArrayLiteralExp:
+                return loadLValue(genLValue(exp));
             case ExpType.Negate:
                 auto negateExp = cast(NegateExp)exp;
                 auto target = genExpression(negateExp.exp);
@@ -354,14 +349,6 @@
             case ExpType.Index:
                 auto indexExp = cast(IndexExp)exp;
                 return loadLValue(genLValue(exp));
-            case ExpType.ArrayLiteralExp:
-                auto arrayLiteralExp = cast(ArrayLiteralExp)exp;
-                Constant[] c;
-                foreach (a ; arrayLiteralExp.exps)
-                    c ~= cast(Constant)genExpression(a).value;
-                return RValue(
-                        ConstantArray.Get(
-                            llvm(arrayLiteralExp.type.asStaticArray.arrayOf), c));
             case ExpType.NewExp:
                 auto newExp = cast(NewExp)exp;
                 DClass type = newExp.newType.type().asClass();
@@ -423,7 +410,6 @@
                 auto type = id.type;
                 if (type.isStruct()
                         || type.isArray()
-                        || type.isStaticArray()
                         || type.isClass())
                     return RValue(table.find(id.get));
                 else if (type.isFunction())
@@ -728,6 +714,27 @@
                 if (v is null)
                     v = m.getNamedFunction(id.getSymbol().getMangledFQN());
                 return LValue(v);
+            case ExpType.StringExp:
+                auto stringExp = cast(StringExp)exp;
+                char[] data = cast(char[])stringExp.data;
+                auto string_constant = ConstantArray.GetString(data, true);
+                auto gv = m.addGlobal(string_constant, "string");
+                gv.linkage = Linkage.Internal;
+                gv.globalConstant = true;
+                return LValue(gv);
+            case ExpType.ArrayLiteralExp:
+                auto arrayLiteralExp = cast(ArrayLiteralExp)exp;
+                SmallArray!(Constant) constants;
+                foreach (e; arrayLiteralExp.exps)
+                    constants ~= cast(Constant)genExpression(e).value;
+                auto array_constant = 
+                        ConstantArray.Get(constants[0].type, constants[]);
+                auto gv = m.addGlobal(array_constant, "array");
+                gv.linkage = Linkage.Internal;
+                gv.globalConstant = true;
+                return LValue(gv);
+            case ExpType.AddressOfExp:
+                assert(0, "&&x wont work, &x isn't an LValue");
             case ExpType.Deref:
                 // LValue(*x): load(x)
                 // RValue(*x): load(load(x))
@@ -839,8 +846,6 @@
 
         if (auto st = t.asStruct())
             genMemcpy(to, from, t);
-        else if (auto sa = t.asStaticArray())
-            genMemcpy(to, from, t, sa.arrayOf.byteSize);
         else
             b.buildStore(from, to);
     }
--- a/tests/code/function_pointer_2.d	Fri Jul 25 12:50:09 2008 +0200
+++ b/tests/code/function_pointer_2.d	Fri Jul 25 12:53:58 2008 +0200
@@ -1,10 +1,11 @@
-
+//fail
 int main()
 {
     int function(int) f = &foo;
-    f();
+    return f();
 }
 
 int foo(int x)
 {
+    return x*x*x;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/code/struct_7.d	Fri Jul 25 12:53:58 2008 +0200
@@ -0,0 +1,11 @@
+struct A { int a; }
+A f()
+{
+    A a;
+    return a;
+}
+
+void main() {
+    A a = f();
+}
+
--- a/tests/parser/for_2.d.s	Fri Jul 25 12:50:09 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-
-
-	.text
-	.align	16
-	.globl	_D4mainFZv
-	.type	_D4mainFZv,@function
-_D4mainFZv:
-.Leh_func_begin1:
-.Llabel1:
-.LBB1_1:	# done
-	ret
-	.size	_D4mainFZv, .-_D4mainFZv
-.Leh_func_end1:
-	.section	.eh_frame,"aw",@progbits
-EH_frame0:
-.Lsection_eh_frame:
-.Leh_frame_common:
-	.long	.Leh_frame_common_end-.Leh_frame_common_begin
-.Leh_frame_common_begin:
-	.long	0x0
-	.byte	0x1
-	.asciz	"zR"
-	.uleb128	1
-	.sleb128	-4
-	.byte	0x8
-	.uleb128	1
-	.byte	0x1b
-	.byte	0xc
-	.uleb128	4
-	.uleb128	4
-	.byte	0x88
-	.uleb128	1
-	.align	4
-.Leh_frame_common_end:
-
-_D4mainFZv.eh = 0
-
-	.section	.note.GNU-stack,"",@progbits
--- a/tests/parser/function_pointer.d	Fri Jul 25 12:50:09 2008 +0200
+++ b/tests/parser/function_pointer.d	Fri Jul 25 12:53:58 2008 +0200
@@ -1,7 +1,9 @@
 
 int main()
 {
-    f = &&foo;
+    g = &foo;
+    f = &g;
+    return g(2);
 }
 
 int foo(int x)
@@ -10,3 +12,4 @@
 }
 
 int function(int x)* f;
+int function(int x) g;
--- a/tests/parser/string_1.d	Fri Jul 25 12:50:09 2008 +0200
+++ b/tests/parser/string_1.d	Fri Jul 25 12:53:58 2008 +0200
@@ -24,14 +24,14 @@
 
     /* And some custom ones */
 
-    char[8]     s16 = "\x61\u05D0\U000201A4";
+    char[7]     s16 = "\x61\u05D0\U000201A4";
     char[2]     s17 = "\122\522";
-    char[6]     s18 = x"61 62 63 64
+    char[8]     s18 = x"61 62 63 64
                         65 66 67 68";
 
-    char[4]     s19 = "\&reg;\&amp;";
+    char[3]     s19 = "\&reg;\&amp;";
 
-    char[4]     s20 = "\&reg;\&amp;"c;
+    char[3]     s20 = "\&reg;\&amp;"c;
     wchar[2]    s21 = "\&reg;\&amp;"w;
     dchar[2]    s22 = "\&reg;\&amp;"d;