Commit Graph

22 Commits

Author SHA1 Message Date
Minero Aoki 118d27b4ef r4941@macbookpro: aamine | 2009-05-24 21:54:18 +0900
* net/loveruby/cflat/ast: remove useless methods: ExprNode#isConstantAddress.
 


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4246 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-24 12:56:37 +00:00
Minero Aoki 3b29c039bd r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900
* net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*.  Function type is int(int,int).
 * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function.
 * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies.
 * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression.
 * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer.
 * net/loveruby/cflat/compiler/TypeChecker.java: ditto.
 * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto.
 * net/loveruby/cflat/compiler/IRGenerator.java: ditto.
 * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays).
 * net/loveruby/cflat/type/Type.java: remove #isDereferable.
 * net/loveruby/cflat/type/UserType.java: ditto.
 * net/loveruby/cflat/type/ArrayType.java: is not a scalar.
 * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself.
 * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays.
 * net/loveruby/cflat/type/IntegerType.java: ditto.
 * net/loveruby/cflat/type/FunctionType.java: is callable.
 * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types.
 * net/loveruby/cflat/type/TypeTable.java: new method #getParamType.
 * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue.
 * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable.
 * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable.
 * net/loveruby/cflat/ast/CastNode.java: delegate them.
 * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes.
 * net/loveruby/cflat/ast/VariableNode.java: ditto.
 * net/loveruby/cflat/ast/DereferenceNode.java: ditto.
 * net/loveruby/cflat/ast/ArefNode.java: ditto.
 * net/loveruby/cflat/ast/MemberNode.java: ditto.
 * net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
 * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad.
 * net/loveruby/cflat/entity/Function.java: ditto.
 * net/loveruby/cflat/entity/Variable.java: ditto.
 * net/loveruby/cflat/entity/Constant.java: ditto.
 * net/loveruby/cflat/ir/Addr.java: is not LHS node now.
 


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-17 18:35:02 +00:00
Minero Aoki e66d1b59d9 * net/loveruby/cflat/entity: new package.
* net/loveruby/cflat/ast: move Entity and its subclasses under entity/.
* net/loveruby/cflat/ast: move Scope and its subclasses under entity/.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4162 1b9489fe-b721-0410-924e-b54b9192deb8
2009-04-26 17:55:46 +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 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 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 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 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 11e6f1ab64 * net/loveruby/cflat/ast/*.java: minimize references to asm/*.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4071 1b9489fe-b721-0410-924e-b54b9192deb8
2008-10-24 14:03:31 +00:00
Minero Aoki 69862827dc * implement PIC generation.
* lib/Makefile: should generate PIC for libcbc.o.
* net/loveruby/cflat/compiler/Compiler.java: pass CodeGeneratorOptions to CodeGenerator.
* net/loveruby/cflat/compiler/Options.java: new options -fpic, -fPIC.
* net/loveruby/cflat/compiler/CodeGenerator.java: use position independent address for global variables, common symbols, defined/undefined functions and string constants.
* net/loveruby/cflat/compiler/CodeGeneratorOptions.java: new class.
* net/loveruby/cflat/asm/ELFConstants.java: new interface to define ELF-related constants.
* net/loveruby/cflat/asm/Assembler.java: new method #hidden.
* net/loveruby/cflat/asm/Assembler.java: new overload #section(s,s,s,s,s).
* net/loveruby/cflat/asm/IndirectMemoryReference.java: offset may not long, but Literal.
* net/loveruby/cflat/asm/Literal.java: new method #isZero.
* net/loveruby/cflat/asm/IntegerLiteral.java: ditto.
* net/loveruby/cflat/asm/LabelRef.java: ditto.
* net/loveruby/cflat/ast/ExprNode.java: new method #shouldEvaluatedToAddres.
* net/loveruby/cflat/ast/VariableNode.java: override it.
* net/loveruby/cflat/ast/CastNode.java: override it.
* net/loveruby/cflat/ast/Entity.java: new method #cannotLoad, to implement #shouldEvaluatedToAddress.
* net/loveruby/cflat/ast/Variable.java: override it.
* net/loveruby/cflat/ast/Function.java: override it.
* net/loveruby/cflat/ast/ExprNode.java: rename method: #AsmLiteral -> #AsmValue because it now returns ImmediateValue instead of Literal.
* net/loveruby/cflat/ast/CastNode.java: override it.
* net/loveruby/cflat/ast/LiteralNode.java: rename method also.
* net/loveruby/cflat/ast/IntegerLiteralNode.java: ditto.
* net/loveruby/cflat/ast/StringLiteralNode.java: ditto.
* net/loveruby/cflat/ast/Variable.java: holds memref and address here, not in subclasses.
* net/loveruby/cflat/ast/DefinedVariable.java: ditto.
* net/loveruby/cflat/ast/UndefinedVariable.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: new method #memref.
* net/loveruby/cflat/ast/IntegerLiteralNode.java: implement it.
* net/loveruby/cflat/ast/StringLiteralNode.java: implement it.
* net/loveruby/cflat/ast/ConstantEntry.java: holds memref and address.
* net/loveruby/cflat/ast/AST.java: new method #allFunctions, to access undefined functions from code generator.
* net/loveruby/cflat/ast/ToplevelScope.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4057 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-27 20:07:49 +00:00
Minero Aoki de82f43658 * net/loveruby/cflat/asm/AsmEntity.java -> AsmOperand.java
* net/loveruby/cflat/*/*.java: AsmEntity -> AsmOperand.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4027 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 17:49:29 +00:00
Minero Aoki 19ca32a89d * net/loveruby/cflat/asm/Address.java -> MemoryReference.java
* net/loveruby/cflat/asm/DirectAddress.java -> DirectMemoryReference.java
* net/loveruby/cflat/asm/IndirectAddress.java -> IndirectMemoryReference.java
* net/loveruby/cflat/compiler/CodeGenerator.java: Address -> MemoryReference.
* net/loveruby/cflat/asm/AsmEntity.java: ditto.
* net/loveruby/cflat/asm/AbsoluteAddress.java: ditto.
* net/loveruby/cflat/ast/Entity.java: ditto.
* net/loveruby/cflat/ast/Variable.java: ditto.
* net/loveruby/cflat/ast/DefinedVariable.java: ditto.
* net/loveruby/cflat/ast/UndefinedVariable.java: ditto.
* net/loveruby/cflat/ast/Function.java: ditto.
* net/loveruby/cflat/ast/ExprNode.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.
* net/loveruby/cflat/ast/CastNode.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4026 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 17:37:49 +00:00
Minero Aoki 9af6bc364f * net/loveruby/cflat/compiler/CodeGenerator.java: both of "puts" and "&puts" should be evaluated to its address.
* net/loveruby/cflat/compiler/CodeGenerator.java: address -> memref.
* net/loveruby/cflat/ast/Entity.java: ditto.
* net/loveruby/cflat/ast/Function.java: ditto.
* net/loveruby/cflat/ast/Variable.java: ditto.
* net/loveruby/cflat/ast/UndefinedVariable.java: ditto.
* net/loveruby/cflat/ast/DefinedVariable.java: ditto.
* net/loveruby/cflat/ast/ExprNode.java: ditto.: ditto.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.
* net/loveruby/cflat/ast/CastNode.java: ditto.
* test: test "puts", "&puts", "myputs", "&myputs".


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4025 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 17:18:16 +00:00
Minero Aoki 9ea468d3db * net/loveruby/cflat/compiler/CodeGenerator.java: split compileLHS by using visitor pattern.
* net/loveruby/cflat/ast/ASTLHSVisitor.java: new interface.
* net/loveruby/cflat/ast/DereferenceNode.java: implement #acceptLHS.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/ast/Node.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4003 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 23:06:41 +00:00
Minero Aoki 67c1972a8a * net/loveruby/cflat/compiler/TypeChecker.java: check returning void value.
* net/loveruby/cflat/compiler/TypeChecker.java: allow array LHS, only when LHS is a parameter.
* net/loveruby/cflat/ast/Entity.java: define #isParameter here.
* net/loveruby/cflat/ast/Variable.java: remove #isVariable, #isParameter.
* net/loveruby/cflat/ast/ExprNode.java: new method #isParameter.
* net/loveruby/cflat/ast/VariableNode.java: override it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3912 1b9489fe-b721-0410-924e-b54b9192deb8
2008-02-17 19:08:48 +00:00
Minero Aoki fd5caed6fc * net/loveruby/cflat/compiler/TypeChecker.java: fork DereferenceChecker, to reduce catch(SemanticError).
* net/loveruby/cflat/compiler/DereferenceChecker.java: new class.
* net/loveruby/cflat/ast/ExprNode.java (isAssignable, isDereferable): catch SemanticError which may occuer on type.isXXXX.
* net/loveruby/cflat/compiler/Visitor.java: refactoring: rename method: #resolve -> #visitNode.
* net/loveruby/cflat/compiler/Visitor.java: refactoring: rename method: #resolveNodeList -> #visitNodeList.
* net/loveruby/cflat/compiler/JumpResolver.java: ditto.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/Compiler.java: parse command line options more precisely.
* net/loveruby/cflat/compiler/Compiler.java: new option --compile.
* net/loveruby/cflat/compiler/Compiler.java: new option --dump-reference.
* net/loveruby/cflat/compiler/Compiler.java: new option --dump-semantic.
* net/loveruby/cflat/ast/VariableNode.java (dump): show resolved or not.
* net/loveruby/cflat/ast/TypeNode.java (dump): ditto.
* net/loveruby/cflat/ast/Dumper.java (printMember): ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3819 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-12 19:48:31 +00:00
Minero Aoki 8ca82908c1 * net/loveruby/cflat/ast/ExprNode.java: has all LHSNode methods.
* net/loveruby/cflat/ast/LHSNode.java: removed (methods merged into ExprNode).
* net/loveruby/cflat/ast/CastNode.java: should implement #isConstantAddress.
* net/loveruby/cflat/ast/DereferenceNode.java: does not implement LHSNode.
* net/loveruby/cflat/ast/ArefNode.java: ditto.
* net/loveruby/cflat/ast/PtrMemberNode.java: ditto.
* net/loveruby/cflat/ast/MemberNode.java: ditto.
* net/loveruby/cflat/ast/VariableNode.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: cast not needed.
* test/cast3.cb: test cast on LHS.
* test/test.sh: run it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3802 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 03:52:41 +00:00
Minero Aoki 879738ba62 * net/loveruby/cflat/ast/Node.java: all nodes must contain Location.
* net/loveruby/cflat/ast/*Node.java: ditto.
* net/loveruby/cflat/ast/Location.java: new class.
* net/loveruby/cflat/ast/Dumper.java (printClass): show location.
* net/loveruby/cflat/type/*Ref.java: support Location.
* net/loveruby/cflat/parser/Parser.jj: pass location to nodes.
* net/loveruby/cflat/parser/Parser.jj: long long removed.
* net/loveruby/cflat/type/SignedLongLongRef.java: ditto.
* net/loveruby/cflat/type/UnsignedLongLongRef.java: ditto.
* net/loveruby/cflat/type/SignedLongLongType.java: ditto.
* net/loveruby/cflat/type/UnsignedLongLongType.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/ast/LiteralNode.java: introduce new superclass of all literal nodes.
* net/loveruby/cflat/ast/StmtNode.java: introduce new superclass of all statement nodes.
* net/loveruby/cflat/ast/Declaration.java: is subclass of Node.
* net/loveruby/cflat/ast/Dumpable.java: removed: Now declarations are subclass of Node.
* net/loveruby/cflat/ast/Dumper.java: follow new class hierarchy.
* net/loveruby/cflat/ast/DefinitionVisitor.java: removed: merge into ASTVisitor again.
* net/loveruby/cflat/compiler/Visitor.java: follow new class hierarchy.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3800 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-05 01:34:27 +00:00
Minero Aoki 132e4cbbb2 * net/loveruby/cflat/compiler/Compiler.java: implement command line option --dump-ast.
* net/loveruby/cflat/compiler/Compiler.java: implement command line option --dump-tokens.
* net/loveruby/cflat/ast/Dumper.java: new class; AST dumper.
* net/loveruby/cflat/ast/Dumpable.java: new interface; AST dumper interface.
* net/loveruby/cflat/ast/*.java: define #dump, #_dump.
* net/loveruby/cflat/asm/Assembler.java: fork utils/TextUtils.java.
* net/loveruby/cflat/utils/TextUtils.java: new file.
* test/stdlib.hb: new header file.
* test/unistd.hb: new header file.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3787 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 23:01:49 +00:00
Minero Aoki e3282566a4 * introduce ExprNode class for all expression nodes.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3773 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 11:53:41 +00:00
Minero Aoki 16a2210512 * net/loveruby/cflat/compiler/TypeChecker.java: check &expr is assignable.
* net/loveruby/cflat/ast/Node.java: new generic method #isAssignable.
* net/loveruby/cflat/ast/VariableNode.java: is assignable.
* net/loveruby/cflat/ast/DereferenceNode.java: is assignable.
* net/loveruby/cflat/ast/ArefNode.java: is assignable.
* net/loveruby/cflat/ast/MemberNode.java: is assignable.
* net/loveruby/cflat/ast/PtrMemberNode.java: is assignable.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3772 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-02 10:46:28 +00:00
Minero Aoki dd209e191b import cbc from stdcompiler repository (rev185)
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3753 1b9489fe-b721-0410-924e-b54b9192deb8
2007-12-24 08:19:51 +00:00