# HG changeset patch # User Anders Johnsen # Date 1216589063 -7200 # Node ID 85d609399fdf6838b100dd0ed9bac8f9d956bda6 # Parent 927ae00bd9d26efd2eadac0594ce2942b0d09192# Parent a22e3663de8987d952214070865bb9676f87bdc2 Merge diff -r 927ae00bd9d2 -r 85d609399fdf ast/Exp.d --- a/ast/Exp.d Sun Jul 20 23:23:56 2008 +0200 +++ b/ast/Exp.d Sun Jul 20 23:24:23 2008 +0200 @@ -104,6 +104,14 @@ return f.returnType; } + override CallExp simplify() + { + foreach (ref arg; args) + arg = arg.simplify(); + exp = exp.simplify(); + return this; + } + Exp exp; Exp[] args; bool sret = false; @@ -115,51 +123,6 @@ res = res + args[$ - 1].sourceRange; return res; } - - Exp simplify() - { - /* - if(auto t = type.asStruct) - { - DFunction func_t = cast(DFunction)exp.type(); - assert(func_t !is null, "Calling on something that isn't a function"); - if (cast(DStruct)func_t.returnType is null) - return this; - - auto call = cast(Identifier)exp; - FuncDecl f = env.parentFunction; - auto i = new Identifier("temp.var"); - i.env = f.env; - f.env.add(i); - f.env.find(i).setType(t); - auto ty = new Identifier(t.name); - auto var = new VarDecl(ty, i, null); - Exp[] args; - args ~= i; - args ~= this.args; - auto callExp = new CallExp(exp, args); - callExp.env = f.env; - var.env = f.env; - auto stmtVar = new DeclStmt(var); - auto stmtCall = new ExpStmt(callExp); - Stmt[] stmts; - foreach( index, s ; f.statements) - { - if(stmtIndex == index) - { - stmts ~= stmtVar; - stmts ~= stmtCall; - } - stmts ~= s; - } - f.statements = stmts; - callExp.sret = true; - - return i; - } - */ - return this; - } } class AssignExp : BinaryExp @@ -171,10 +134,10 @@ this.exp = exp; } - Exp simplify() + override AssignExp simplify() { - identifier = identifier.simplify; - exp = exp.simplify; + identifier = identifier.simplify(); + exp = exp.simplify(); return this; } @@ -275,10 +238,10 @@ return null; } - Exp simplify() + override BinaryExp simplify() { - left = left.simplify; - right = right.simplify; + left = left.simplify(); + right = right.simplify(); return this; } @@ -295,9 +258,9 @@ this.exp = exp; } - Exp simplify() + override NegateExp simplify() { - exp = exp.simplify; + exp = exp.simplify(); return this; } @@ -319,9 +282,9 @@ this.exp = exp; } - Exp simplify() + override DerefExp simplify() { - exp = exp.simplify; + exp = exp.simplify(); return this; } @@ -352,7 +315,7 @@ return name; } - Exp simplify() + override IntegerLit simplify() { return this; } @@ -412,9 +375,9 @@ return null; } - Exp simplify() + override MemberReference simplify() { - target = target.simplify; + target = target.simplify(); return this; } @@ -471,10 +434,10 @@ return target.sourceRange + SourceRange(right_bracket); } - Exp simplify() + override IndexExp simplify() { - target = target.simplify; - index = index.simplify; + target = target.simplify(); + index = index.simplify(); return this; } @@ -497,10 +460,10 @@ return env.findType(this.castType); } - Exp simplify() + override CastExp simplify() { - castType.simplify; - exp.simplify; + castType = castType.simplify(); + exp = exp.simplify(); return this; } @@ -656,7 +619,7 @@ return 0; } - Exp simplify() + override Identifier simplify() { return this; } diff -r 927ae00bd9d2 -r 85d609399fdf ast/Stmt.d --- a/ast/Stmt.d Sun Jul 20 23:23:56 2008 +0200 +++ b/ast/Stmt.d Sun Jul 20 23:24:23 2008 +0200 @@ -46,10 +46,10 @@ this.statements = stmts; } - void simplify() + override void simplify() { - foreach ( stmt ; statements ) - stmt.simplify; + foreach (stmt; statements ) + stmt.simplify(); } Stmt[] statements; @@ -62,12 +62,13 @@ super(StmtType.Return); } - void simplify() + // Needed? + override void simplify() { FuncDecl f = env.parentFunction; - if(exp) - exp.simplify; - if(f !is null && f.sret) + if (exp) + exp = exp.simplify(); + if (f !is null && f.sret) { auto i = new Identifier("ret.val"); i.env = f.env; @@ -85,7 +86,6 @@ stmts ~= stmt; } f.statements = stmts; - exp = null; } } @@ -101,9 +101,9 @@ this.decl = decl; } - void simplify() + override void simplify() { - decl.simplify; + decl.simplify(); } public Decl decl; @@ -117,9 +117,9 @@ this.exp = exp; } - void simplify() + override void simplify() { - exp = exp.simplify; + exp = exp.simplify(); } public Exp exp; @@ -135,12 +135,12 @@ this.else_body = el; } - void simplify() + override void simplify() { - cond.simplify; - then_body.simplify; + cond = cond.simplify(); + then_body.simplify(); if (else_body) - else_body.simplify; + else_body.simplify(); } Exp cond; @@ -157,10 +157,10 @@ this.whileBody = stmts; } - void simplify() + override void simplify() { - cond.simplify; - whileBody.simplify; + cond = cond.simplify(); + whileBody.simplify(); } Exp cond; @@ -225,14 +225,14 @@ cases[$ - 1].followedByDefault = true; } - void simplify() + override void simplify() { - cond.simplify; + cond = cond.simplify(); foreach ( stmt ; defaultBlock ) - stmt.simplify; + stmt.simplify(); foreach ( c ; cases ) foreach ( stmt ; c.stmts ) - stmt.simplify; + stmt.simplify(); } Exp cond; diff -r 927ae00bd9d2 -r 85d609399fdf gen/CodeGen.d --- a/gen/CodeGen.d Sun Jul 20 23:23:56 2008 +0200 +++ b/gen/CodeGen.d Sun Jul 20 23:24:23 2008 +0200 @@ -53,7 +53,7 @@ { b = new Builder; ZeroIndex = ConstantInt.GetU(Type.Int32, 0); - + table = new SimpleSymbolTable(); createBasicTypes(); @@ -220,12 +220,6 @@ g.initializer = ConstantInt.GetS(t, 0); table[varDecl.identifier.get] = g; break; - - case DeclType.StructDecl: - auto structDecl = cast(StructDecl)decl; - llvm(structDecl.type); - //m.addTypeName(structDecl.identifier.get, llvm(structDecl.type)); - break; default: break; @@ -256,8 +250,9 @@ case DeclType.FuncDecl: genRootDecl(decl); break; - + default: + break; } } @@ -271,34 +266,6 @@ } /** - Takes two iX and overwrite the smaller one, with a sign-extended version - so both values can be operated on without worrying about the exact types. - - Used when adding a int and a long or similar. - - Currently unused - **/ - void sextSmallerToLarger(ref Value left, ref Value right) - { - if (left.type != right.type) - { - // try to find a convertion - only works for iX - IntegerType l = cast(IntegerType) left.type; - IntegerType r = cast(IntegerType) right.type; - if (l is null || r is null) - assert(0, PE.NoImplicitConversion); - /* - .arg(left.type.toString) - .arg(right.type.toString);*/ - - if (l.numBits() < r.numBits()) - left = b.buildSExt(left, r, ".cast"); - else - right = b.buildSExt(right, l, ".cast"); - } - } - - /** Generate a single expression. This is the most general way of generating expressions and therefore @@ -496,20 +463,6 @@ assert(0, PE.VoidRetInNonVoidFunc); RValue v = genExpression(ret.exp); -/* if (v.type != t) - { - IntegerType v_t = cast(IntegerType) v.type; - IntegerType i_t = cast(IntegerType) t; - if (v_t is null || i_t is null) - throw error(__LINE__, PE.NoImplicitConversion) - .arg(v.type.toString) - .arg(t.toString); - - if (v_t.numBits() < i_t.numBits()) - v = b.buildSExt(v, t, ".cast"); - else - v = b.buildTrunc(v, t, ".cast"); - }*/ b.buildRet(v.value); break; case StmtType.Decl: