Commit Graph

313 Commits

Author SHA1 Message Date
Minero Aoki 524db547c6 * net/loveruby/cflat/ir: implement IR#dump.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4156 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 14:35:10 +00:00
Minero Aoki 04f5d8e6cc * net/loveruby/cflat/compiler/IRGenerator.java (BlockNode): static variables are special case.
* net/loveruby/cflat/compiler/IRGenerator.java (SwitchNode): Switch must precedes Case bodies to prevent programs from infinite loop.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix MOD problem.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix LSHIFT problem.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4155 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 13:41:19 +00:00
Minero Aoki 0b3098612a * now IR nodes are separated from AST. Sources are compilable but not tested yet.
* ir/*: new classes.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4154 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 13:08:40 +00:00
Minero Aoki eaba86066f * ast/ASTVisitor.java: fork DeclarationVisitor.
* ast/DeclarationVisitor.java: new class.
* compiler/Visitor.java: do not visit declarations.
* compiler/TypeResolver.java: visit declarations explicitly.
* compiler/IRGenerator.java: remove useless declarations acceptor.
* compiler/CodeGenerator.java: ditto.
* ast/Entity.java: accept DeclarationVisitor.
* ast/DefinedFunction.java: ditto.
* ast/UndefinedFunction.java: ditto.
* ast/DefinedVariable.java: ditto.
* ast/UndefinedVariable.java: ditto.
* ast/TypeDefinition.java: ditto.
* ast/StructNode.java: ditto.
* ast/UnionNode.java: ditto.
* ast/TypedefNode.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4153 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 09:09:52 +00:00
Minero Aoki 68a99258e5 * net/loveruby/cflat/compiler/IRGenerator.java (SuffixOp): do not calculate twice. Save expr value and reuse it.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4152 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 08:45:30 +00:00
Minero Aoki f23dd70dd2 * net/loveruby/cflat/compiler/IRGenerator.java: must compile initializer.
* net/loveruby/cflat/compiler/IRGenerator.java: f = &puts generated addr(addr(puts)), so remove redundant AddressNode.
* net/loveruby/cflat/compiler/CodeGenerator.java: now --verbose-asm works.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4151 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 08:25:30 +00:00
Minero Aoki 41e5e61c16 * net/loveruby/cflat/compiler/IRGenerator.java: treat LHS specially and remove AddressNode at the top of the LHS tree (e.g. printf = 0 generates &printf = 0).
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4150 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 07:51:05 +00:00
Minero Aoki e8f10dc3f6 * net/loveruby/cflat/compiler/Simplifier.java -> IRGenerator.java
* net/loveruby/cflat/compiler/Compiler.java: rename class.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4149 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 07:19:33 +00:00
Minero Aoki 732ebf51d4 * net/loveruby/cflat/compiler/Simplifier.java (SwitchNode): missing end label.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4148 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 07:10:29 +00:00
Minero Aoki 9e9f65d6ce * net/loveruby/cflat/ast/FuncallNode.java: make a static funcall really static funcall (not use pointer).
net/loveruby/cflat/compiler/Simplifier.java: set aref result type.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4147 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 06:48:12 +00:00
Minero Aoki 78a2217cd9 * net/loveruby/cflat/ast/FuncallNode.java: detect static call.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4146 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 04:50:57 +00:00
Minero Aoki 1074c0177f * net/loveruby/cflat/compiler/Simplifier.java (While): must loop.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4145 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 04:30:15 +00:00
Minero Aoki 487cf1a714 * net/loveruby/cflat/compiler/Simplifier.java (SuffixOp): too few deref.
* net/loveruby/cflat/compiler/Simplifier.java (MemberNode): should set type.
* net/loveruby/cflat/compiler/Simplifier.java (PtrMemberNode): should set type.
* net/loveruby/cflat/compiler/Simplifier.java (Deref, Addr): should compile child expr.
* net/loveruby/cflat/ast/BinaryOpNode.java (ctor): accept type.
* net/loveruby/cflat/ast/TypeNode.java (location): do not raise exception when no typeRef exist.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4144 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 04:22:42 +00:00
Minero Aoki 99b5be5455 * net/loveruby/cflat/asm/PeepholeOptimizer.java: fix bad operator mnemonic. (fixes 4E)
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4143 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 03:18:09 +00:00
Minero Aoki 63170db30b * now many tests work (30/1709 failed).
* net/loveruby/cflat/compiler/Simplifier.java: set location of AssignStmtNode.
* net/loveruby/cflat/compiler/Simplifier.java: allocate tmp variable in scope.
* net/loveruby/cflat/compiler/Simplifier.java: opAssign/inc/dec handling was completely wrong (there still be some problems yet).
* net/loveruby/cflat/compiler/CodeGenerator.java (compileLHS): implemented for IR.
* net/loveruby/cflat/compiler/CodeGenerator.java (loadVarible): implemented for IR.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4142 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-19 18:52:12 +00:00
Minero Aoki 97fbe0672c * net/loveruby/cflat/ast/IR.java: new class to represents IR.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4141 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-19 15:39:18 +00:00
Minero Aoki ecdfcff254 * new class Simplifier (it is really a IR generator). Passes compilation, but not tested.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4140 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-19 14:52:48 +00:00
Minero Aoki 1e80fec3ab * refactoring: rename class: compiler/Simplifier.java -> IRGenerator.java.
* compiler/Compiler.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4139 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-19 05:57:41 +00:00
Minero Aoki ae4073e7c3 revert r4136 (no IR)
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4138 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-19 05:50:16 +00:00
Minero Aoki 444c8e1bd9 * net/loveruby/cflat/compiler/IRGenerator.java: generates IR (intermediate representation) tree (work is still incomplete but commit for logging).
* net/loveruby/cflat/ir: new package to hold IR tree nodes.
* net/loveruby/cflat/ir/IRTree.java: new class.
* net/loveruby/cflat/ir/Stmt.java: new class.
* net/loveruby/cflat/ir/StmtKind.java: new enum.
* net/loveruby/cflat/ir/Expr.java: new class.
* net/loveruby/cflat/ir/ExprKind.java: new enum.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4136 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-12 16:53:28 +00:00
Minero Aoki 5a287a7b48 * net/loveruby/cflat/compiler/TypeChecker.java: split IRGenerator.
* net/loveruby/cflat/compiler/IRGenerator.java: new class.
* net/loveruby/cflat/compiler/Compiler.java: call IRGenerator.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4135 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-12 08:49:23 +00:00
Minero Aoki 8d208c36cc * net/loveruby/cflat/compiler/TypeChecker.java: simplify BinaryOp checking, utilizing destructive methods.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4134 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-12 07:48:17 +00:00
Minero Aoki f69902e1d7 * net/loveruby/cflat/compiler/Visitor.java: make destructive again.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/LocalResolver.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/compiler/DereferenceChecker.java: ditto.
* net/loveruby/cflat/compiler/JumpResolver.java: ditto.
* net/loveruby/cflat/ast/AbstractAssignNode.java: ditto.
* net/loveruby/cflat/ast/CondExprNode.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4133 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-12 07:37:18 +00:00
Minero Aoki d514300aef * net/loveruby/cflat/compiler/Visitor.java: make all return types generic.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/ast/*.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4132 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-12 06:31:12 +00:00
Minero Aoki 33dcef983b * net/loveruby/cflat/compiler/Compiler.java: call JumpResolver at last.
* net/loveruby/cflat/compiler/TypeChecker.java: TypeChecker has required ReturnNode.function, provide "current function" by myself.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4131 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-05 22:04:35 +00:00
Minero Aoki 043859df0b * net/loveruby/cflat/ast/ASTVisitor.java: #visit returns a node which has same type with the argument, to allow non-destructive AST rewriting.
* net/loveruby/cflat/ast/*Node.java (#accept): ditto.
* net/loveruby/cflat/compiler/Visitor.java: ditto.
* net/loveruby/cflat/compiler/*.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: make non-destructive.
* net/loveruby/cflat/parser/Parser.jj: use StmtNode/ExprNode instead of Node.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4130 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-04 14:47:11 +00:00
Minero Aoki c558b27a8e add more preproc tags
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4116 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-23 19:22:19 +00:00
Minero Aoki b09c3f044f * lib/sizeof_jmpbuf.c: new analysis program.
* lib/Makefile: add a rule to build sizeof_jmpbuf.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4115 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-23 18:43:17 +00:00
Minero Aoki 4df58b564d use exactly same size for jmp_buf.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4114 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-23 17:56:48 +00:00
Minero Aoki 4cb2818d45 * import/setjmp.hb: new file to support setjmp.
* test: test setjmp.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4113 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-23 17:54:11 +00:00
Minero Aoki 0d9cdf252d add preproc tags
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4112 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-23 16:23:14 +00:00
Minero Aoki b1b1c77cbd add preproc tags
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4111 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-21 22:36:32 +00:00
Minero Aoki f6a1df9142 * introduce virtual stack again, for only local variables and tmp variables. Function arguments use true push & pop.
* --verbose-asm prints stack frame layout in detail.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4110 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-14 15:05:20 +00:00
Minero Aoki 3fa59ba6f8 do not remove alloca.s.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4109 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-14 12:06:37 +00:00
Minero Aoki 73ecd8d50b * test: test alloca more.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4108 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-14 12:04:58 +00:00
Minero Aoki e0105bda01 * net/loveruby/cflat/compiler/CodeGenerator.java (compileFunctionBody): remove bp from saveRegs first.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4107 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-14 11:43:51 +00:00
Minero Aoki 0defdae27a test alloca
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4104 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 15:58:04 +00:00
Minero Aoki 76fd64dc52 * lib/alloca.s: alloca() implemeted.
* lib/Makefile: build it.
* import/alloca.hb: declare alloca.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4103 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 15:55:40 +00:00
Minero Aoki b598628af9 * net: revert r4100; implementing alloca() is too difficult for current architecture.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4102 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 14:26:56 +00:00
Minero Aoki 37476f6839 * lib/libcbc.cb -> lib/stdarg.cb
* lib/Makefile: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4101 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 14:25:31 +00:00
Minero Aoki e64c1373c0 * net/loveruby/cflat/compiler/CodeGenerator.java: manage stack offset by generator, instead of using machine push/pop.
* net/loveruby/cflat/asm/Assembler.java: new method relocatableMov.
* net/loveruby/cflat/asm/Assembly.java: allow fixing indirect memory access offset.
* net/loveruby/cflat/asm/Instruction.java: ditto.
* net/loveruby/cflat/asm/AsmOperand.java: ditto.
* net/loveruby/cflat/asm/IndirectMemoryReference.java: ditto.
* net/loveruby/cflat/asm/IntegerLiteral.java: ditto.
* net/loveruby/cflat/asm/Literal.java: ditto.
* net/loveruby/cflat/asm/BaseSymbol.java: ditto.
* net/loveruby/cflat/asm/SuffixedSymbol.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4100 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 13:27:54 +00:00
Minero Aoki 278c5bea47 * net/loveruby/cflat/compiler/LocalReferenceResolver.java -> LocalResolver.java
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4099 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 08:13:47 +00:00
Minero Aoki 545515b5e0 * net/loveruby/cflat/ast/ToplevelScope.java: use SemanticException instead of SemanticError for duplicated declarations/definitions.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4098 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 08:09:20 +00:00
Minero Aoki b469db1b82 * test: test declaration override (error path).
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4097 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 08:08:29 +00:00
Minero Aoki 1524d3d719 * test: test declaration override.
* test/run.sh: new option --help.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4096 1b9489fe-b721-0410-924e-b54b9192deb8
2008-12-07 07:56:00 +00:00
Minero Aoki 96fb88ec26 * net/loveruby/cflat/compiler/CodeGenerator.java: refactoring: reduce lvar.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4091 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-24 09:49:31 +00:00
Minero Aoki d0d97c01d6 all ToDo completed
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4090 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 15:02:27 +00:00
Minero Aoki 234bd96642 * net/loveruby/cflat/compiler/TypeResolver.java: an array on the parameter list is a pointer really.
* net/loveruby/cflat/compiler/TypeChecker.java: an array for stmt value *is* valid because it is a pointer really.
* net/loveruby/cflat/compiler/CodeGenerator.java: st.x while st.x is an array should make a pointer.
* net/loveruby/cflat/type/Type.java: remove #isPointerAlike, there is only a Pointer and an Array already.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/Variable.java: ditto.
* net/loveruby/cflat/ast/ExprNode.java: ditto.
* test: check st.x[1] access.
* test: check pst->x[1] access.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4089 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 14:57:11 +00:00
Minero Aoki 1f47ab6771 * net/loveruby/cflat/compiler/TypeResolver.java: "f = puts" implies "f = &puts", adjust type for such expressions.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4088 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 13:29:35 +00:00
Minero Aoki 5659150c08 resolved: make compiler mode enum.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4087 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 12:30:46 +00:00