Mercurial > projects > dang
diff gen/CodeGen.d @ 119:c0b531362ca6
Non compileing commit. Work on floating points and casts
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Sun, 25 May 2008 19:13:07 +0200 |
parents | 54585ad7e426 |
children | 7d0898f77685 |
line wrap: on
line diff
--- a/gen/CodeGen.d Sun May 25 18:24:16 2008 +0200 +++ b/gen/CodeGen.d Sun May 25 19:13:07 2008 +0200 @@ -11,7 +11,8 @@ ast.Exp, ast.Module : DModule = Module; -import basic.SmallArray; +import basic.SmallArray, + basic.LiteralParsing; import lexer.Token; @@ -306,9 +307,22 @@ case ExpType.Binary: return RValue(genBinExp(cast(BinaryExp)exp)); case ExpType.IntegerLit: - auto integetLit = cast(IntegerLit)exp; - auto val = Integer.parse(integetLit.get); - return RValue(ConstantInt.GetS(Type.Int32, val)); + auto integerLit = cast(IntegerLit)exp; + switch(integerLit.number.type) + { + case NumberType.Int: + return RValue(ConstantInt.GetS(Type.Int32, integerLit.number.integer)); + case NumberType.Long: + return RValue(ConstantInt.GetS(Type.Int64, integerLit.number.integer)); + case NumberType.ULong: + return RValue(ConstantInt.GetS(Type.Int64, integerLit.number.integer)); + case NumberType.Float: + return RValue(ConstantReal.Get(Type.Float, integerLit.number.floating)); + case NumberType.Double: + return RValue(ConstantReal.Get(Type.Double, integerLit.number.floating)); + case NumberType.Real: + return RValue(ConstantReal.Get(Type.X86_FP80, integerLit.number.floating)); + } case ExpType.Negate: auto negateExp = cast(NegateExp)exp; auto target = genExpression(negateExp.exp); @@ -345,14 +359,10 @@ auto castExp = cast(CastExp)exp; auto value = genExpression(castExp.exp).value; - if (!castExp.type.hasImplicitConversionTo(castExp.type)) + if (!castExp.exp.type.hasImplicitConversionTo(castExp.type)) assert(0, "Invalid cast"); - Value v; - if(castExp.exp.type.byteSize <= castExp.type.byteSize) - v = b.buildZExt(value, llvm(castExp.type), "zext"); - else - v = b.buildTrunc(value, llvm(castExp.type), "trunc"); + Value v = buildCastLoad(castExp.exp.type, castExp.type, value); return RValue(v); @@ -820,6 +830,25 @@ assert(0, "Only integers, structs and functions are supported"); } + Value buildCastLoad(DType from, DType to, Value value) + { + if(typeof(from) == DInteger) + { + if(to == Type.Double) + return b.buildFPTrunc(value, llvm(_to), "fptrunc"); + if(to == Type.Float) + return b.buildFPTrunc(value, llvm(_to), "fptrunc"); + } + /* + if(from == Type.Int64) + if(castExp.exp.type.byteSize <= castExp.type.byteSize) + v = b.buildZExt(value, llvm(castExp.type), "zext"); + else + v = b.buildTrunc(value, llvm(castExp.type), "trunc"); + } +*/ + assert(0, "implicit cast need implimentation"); + } // Might as well insert all the basic types from the start void createBasicTypes() {