Mercurial > projects > dang
comparison 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 |
comparison
equal
deleted
inserted
replaced
159:a2d9121d6dff | 160:6cb2f4201e2a |
---|---|
293 case NumberType.Double: | 293 case NumberType.Double: |
294 return RValue(ConstantReal.Get(Type.Double, integerLit.number.floating)); | 294 return RValue(ConstantReal.Get(Type.Double, integerLit.number.floating)); |
295 case NumberType.Real: | 295 case NumberType.Real: |
296 return RValue(ConstantReal.Get(Type.X86_FP80, integerLit.number.floating)); | 296 return RValue(ConstantReal.Get(Type.X86_FP80, integerLit.number.floating)); |
297 } | 297 } |
298 case ExpType.StringExp: | |
299 auto stringExp = cast(StringExp)exp; | |
300 char[] data = cast(char[])stringExp.data; | |
301 auto string_constant = ConstantArray.GetString(data, true); | |
302 auto gv = m.addGlobal(string_constant, "string"); | |
303 gv.linkage = Linkage.Internal; | |
304 gv.globalConstant = true; | |
305 return RValue(gv); | |
298 case ExpType.Negate: | 306 case ExpType.Negate: |
299 auto negateExp = cast(NegateExp)exp; | 307 auto negateExp = cast(NegateExp)exp; |
300 auto target = genExpression(negateExp.exp); | 308 auto target = genExpression(negateExp.exp); |
301 return RValue(b.buildNeg(target.value, "neg")); | 309 return RValue(b.buildNeg(target.value, "neg")); |
302 case ExpType.Deref: | 310 case ExpType.Deref: |
344 | 352 |
345 return genTypeCast(value, exp.type, castExp.type); | 353 return genTypeCast(value, exp.type, castExp.type); |
346 | 354 |
347 case ExpType.Identifier: | 355 case ExpType.Identifier: |
348 auto id = cast(Identifier)exp; | 356 auto id = cast(Identifier)exp; |
349 if(id.type.isStruct() || id.type.isArray()) | 357 if (id.type.isStruct() |
358 || id.type.isArray() | |
359 || id.type.isStaticArray()) | |
350 return RValue(table.find(id.get)); | 360 return RValue(table.find(id.get)); |
351 else | 361 else |
352 return RValue(b.buildLoad(table.find(id.get), id.get)); | 362 return RValue(b.buildLoad(table.find(id.get), id.get)); |
353 case ExpType.MemberReference: | 363 case ExpType.MemberReference: |
354 return loadLValue(genLValue(exp)); | 364 return loadLValue(genLValue(exp)); |
699 auto a = cast(PointerType)to.type; | 709 auto a = cast(PointerType)to.type; |
700 assert(a !is null, "Can only store through pointers"); | 710 assert(a !is null, "Can only store through pointers"); |
701 | 711 |
702 if (auto st = t.asStruct()) | 712 if (auto st = t.asStruct()) |
703 genMemcpy(to, from, t); | 713 genMemcpy(to, from, t); |
714 else if (auto sa = t.asStaticArray()) | |
715 genMemcpy(to, from, t, sa.arrayOf.byteSize); | |
704 else | 716 else |
705 b.buildStore(from, to); | 717 b.buildStore(from, to); |
706 } | 718 } |
707 | 719 |
708 /** | 720 /** |
709 Copy from src into dst. The values are assumed to have the same size, | 721 Copy from src into dst. The values are assumed to have the same size, |
710 and the amount of bytes to copy is taken from t. | 722 and the amount of bytes to copy is taken from t. |
711 **/ | 723 **/ |
712 void genMemcpy(Value dst, Value src, DType t) | 724 void genMemcpy(Value dst, Value src, DType t, int alignment = 16) |
713 { | 725 { |
714 Value from = b.buildBitCast(src, BytePtr, ".copy_from"); | 726 Value from = b.buildBitCast(src, BytePtr, ".copy_from"); |
715 Value to = b.buildBitCast(dst, BytePtr, ".copy_to"); | 727 Value to = b.buildBitCast(dst, BytePtr, ".copy_to"); |
716 Value[4] args; | 728 Value[4] args; |
717 args[0] = to; | 729 args[0] = to; |
718 args[1] = from; | 730 args[1] = from; |
719 args[2] = ConstantInt.GetS(Type.Int32, t.byteSize()); | 731 args[2] = ConstantInt.GetS(Type.Int32, t.byteSize()); |
720 args[3] = ConstantInt.GetS(Type.Int32, 32); | 732 args[3] = ConstantInt.GetS(Type.Int32, alignment); |
721 b.buildCall(llvm_memcpy, args[], null); | 733 b.buildCall(llvm_memcpy, args[], null); |
722 } | 734 } |
723 | 735 |
724 /** | 736 /** |
725 Generate the statements necessary to convert V, from type 'from' to type | 737 Generate the statements necessary to convert V, from type 'from' to type |