Mercurial > projects > dang
diff gen/CodeGen.d @ 160:6cb2f4201e2a
Improved static arrays
Here is a list of some stuff that works
char[3] s = "hey"
char[3] s2 = s;
s2[1] = 98 // no support for chars, but 98 = 'b' :)
int[2] i;
i[0] = 2;
Still can't pass static arrays to functions
author | Anders Halager <halager@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 13:29:20 +0200 |
parents | 2149f4a7b48d |
children | 9cfa33517526 |
line wrap: on
line diff
--- a/gen/CodeGen.d Tue Jul 22 00:34:49 2008 +0200 +++ b/gen/CodeGen.d Tue Jul 22 13:29:20 2008 +0200 @@ -295,6 +295,14 @@ 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.Negate: auto negateExp = cast(NegateExp)exp; auto target = genExpression(negateExp.exp); @@ -346,7 +354,9 @@ case ExpType.Identifier: auto id = cast(Identifier)exp; - if(id.type.isStruct() || id.type.isArray()) + if (id.type.isStruct() + || id.type.isArray() + || id.type.isStaticArray()) return RValue(table.find(id.get)); else return RValue(b.buildLoad(table.find(id.get), id.get)); @@ -701,6 +711,8 @@ 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); } @@ -709,7 +721,7 @@ Copy from src into dst. The values are assumed to have the same size, and the amount of bytes to copy is taken from t. **/ - void genMemcpy(Value dst, Value src, DType t) + void genMemcpy(Value dst, Value src, DType t, int alignment = 16) { Value from = b.buildBitCast(src, BytePtr, ".copy_from"); Value to = b.buildBitCast(dst, BytePtr, ".copy_to"); @@ -717,7 +729,7 @@ args[0] = to; args[1] = from; args[2] = ConstantInt.GetS(Type.Int32, t.byteSize()); - args[3] = ConstantInt.GetS(Type.Int32, 32); + args[3] = ConstantInt.GetS(Type.Int32, alignment); b.buildCall(llvm_memcpy, args[], null); }