Mercurial > projects > dang
comparison gen/CodeGen.d @ 183:8ea749b7da91
Fixed a few errors so that two more tests passes. Also, now you only need a type in a function param.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 10:59:16 +0200 |
parents | 59cd211a1bd3 |
children | 7b274cfdc1dc |
comparison
equal
deleted
inserted
replaced
182:4e703658eca0 | 183:8ea749b7da91 |
---|---|
93 | 93 |
94 auto registerFunc = | 94 auto registerFunc = |
95 (FuncDecl fd) | 95 (FuncDecl fd) |
96 { | 96 { |
97 Type[] param_types; | 97 Type[] param_types; |
98 foreach (i, p; fd.funcArgs) | 98 foreach (i, p; fd.type.params) |
99 { | 99 { |
100 DType t = p.identifier.type; | 100 if (auto st = p.asStruct()) |
101 if (auto st = t.asStruct()) | |
102 { | 101 { |
103 Type pointer = PointerType.Get(llvm(st)); | 102 Type pointer = PointerType.Get(llvm(st)); |
104 param_types ~= pointer; | 103 param_types ~= pointer; |
105 } | 104 } |
106 else if (auto ar = t.asArray()) | 105 else if (auto ar = p.asArray()) |
107 { | 106 { |
108 Type pointer = PointerType.Get(llvm(ar)); | 107 Type pointer = PointerType.Get(llvm(ar)); |
109 param_types ~= pointer; | 108 param_types ~= pointer; |
110 } | 109 } |
111 else | 110 else |
112 param_types ~= llvm(t); | 111 param_types ~= llvm(p); |
113 } | 112 } |
114 auto ret_t = fd.identifier.type; | 113 auto ret_t = fd.type.returnType; |
115 if(auto st = cast(DStruct)ret_t) | 114 if(auto st = cast(DStruct)ret_t) |
116 ret_t = DType.Void; | 115 ret_t = DType.Void; |
117 else if(auto f = cast(DFunction)ret_t) | 116 else if(auto f = cast(DFunction)ret_t) |
118 ret_t = f.returnType; | 117 ret_t = f.returnType; |
119 auto func_t = FunctionType.Get(llvm(ret_t), param_types); | 118 auto func_t = FunctionType.Get(llvm(ret_t), param_types); |
122 foreach (i, p; fd.funcArgs) | 121 foreach (i, p; fd.funcArgs) |
123 { | 122 { |
124 if(i == 0 && fd.sret) | 123 if(i == 0 && fd.sret) |
125 llfunc.addParamAttr(0, ParamAttr.StructRet); | 124 llfunc.addParamAttr(0, ParamAttr.StructRet); |
126 | 125 |
127 DType t = p.identifier.type; | 126 DType t = fd.type.params[i]; |
128 if (auto st = t.asStruct) | 127 if (auto st = t.asStruct) |
129 { | 128 { |
130 if (i == 0 && fd.sret) | 129 if (i == 0 && fd.sret) |
131 continue; | 130 continue; |
132 llfunc.addParamAttr(i, ParamAttr.ByVal); | 131 llfunc.addParamAttr(i, ParamAttr.ByVal); |
596 genLoop(stmt.env, wStmt.cond, true, wStmt.whileBody); | 595 genLoop(stmt.env, wStmt.cond, true, wStmt.whileBody); |
597 break; | 596 break; |
598 +/ | 597 +/ |
599 case StmtType.For: | 598 case StmtType.For: |
600 auto fStmt = cast(ForStmt)stmt; | 599 auto fStmt = cast(ForStmt)stmt; |
601 genStmt(fStmt.init); | 600 Stmt[] stmts; |
602 scope inc = new ExpStmt(fStmt.incre); | 601 if(fStmt.init) |
603 genLoop(stmt.env, fStmt.cond, false, fStmt.forBody, inc); | 602 genStmt(fStmt.init); |
603 ExpStmt inc; | |
604 if(fStmt.incre) | |
605 stmts ~= new ExpStmt(fStmt.incre); | |
606 Exp cond; | |
607 if(fStmt.cond) | |
608 cond = fStmt.cond; | |
609 else | |
610 { | |
611 auto i = new IntegerLit(fStmt.loc,"1"); | |
612 i.number.type = NumberType.Int; | |
613 i.number.integer = 1; | |
614 cond = i; | |
615 } | |
616 stmts ~= fStmt.forBody; | |
617 genLoop(stmt.env, cond, false, stmts); | |
604 break; | 618 break; |
605 case StmtType.Switch: | 619 case StmtType.Switch: |
606 auto sw = cast(SwitchStmt)stmt; | 620 auto sw = cast(SwitchStmt)stmt; |
607 Value cond = genExpression(sw.cond).value; | 621 Value cond = genExpression(sw.cond).value; |
608 | 622 |