Commit Graph

180 Commits

Author SHA1 Message Date
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 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 3bf172e272 * net/loveruby/cflat/compiler/Compiler.java: make compiler mode enum.
* net/loveruby/cflat/compiler/Options.java: ditto.
* net/loveruby/cflat/compiler/SourceFile.java: ditto.
* net/loveruby/cflat/compiler/CompilerMode.java: new enum.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4086 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 12:28:02 +00:00
Minero Aoki 83dcd37243 * net/loveruby/cflat/compiler/DereferenceChecker.java: We do not need to check an OpAssignNode as operator, because this class only check references.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4085 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 11:20:19 +00:00
Minero Aoki 89c7decdad * net/loveruby/cflat/compiler/CodeGenerator.java (compileAST): should not generate .data section when no global variable is defined.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4083 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 11:11:01 +00:00
Minero Aoki aa030b42b7 * net/loveruby/cflat/compiler/CodeGenerator.java: should access file-local gvar directly (with @GOTOFF) in PIE.
* net/loveruby/cflat/ast/Entity.java: all entities should have memref or address.
* 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/DefinedFunction.java: ditto.
* import/stdlib.hb: add new declarations.
* import/unistd.hb: add new declarations.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4082 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-16 11:01:10 +00:00
Minero Aoki 6b24625a87 * net/loveruby/cflat/compiler/Options.java: new option --readonly-plt.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4076 1b9489fe-b721-0410-924e-b54b9192deb8
2008-11-02 09:27:05 +00:00
Minero Aoki dd5d3dd4f0 * name code symbols lazily.
* separate Label and Symbol.
* net/loveruby/cflat/compiler/CodeGenerator.java: use Symbol instead of Label for entity symbol.
* net/loveruby/cflat/asm/Symbol.java: new interface.
* net/loveruby/cflat/asm/BaseSymbol.java: new class.
* net/loveruby/cflat/asm/NamedSymbol.java: new class.
* net/loveruby/cflat/asm/SuffixedSymbol.java: new class.
* net/loveruby/cflat/asm/UnnamedSymbol.java: new class.
* net/loveruby/cflat/asm/SymbolTable.java: new class.
* net/loveruby/cflat/asm/*.java: Label -> Symbol.
* net/loveruby/cflat/asm/LabelRef.java: removed.
* net/loveruby/cflat/ast/*.java: Label -> Symbol.
* net/loveruby/cflat/parser/Parser.jj: does not pass a LabelPool anymore.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4072 1b9489fe-b721-0410-924e-b54b9192deb8
2008-10-24 18:40:21 +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 cd37fb1f02 * convert all source codes to Java 5 using generics and foreach stmt.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4067 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-28 18:46:56 +00:00
Minero Aoki 9003c4fd72 * net/loveruby/cflat/compiler/Options.java (getOutputFileName): should use outputFileName always when linking, output file of linking is always 1 file.
* net/loveruby/cflat/compiler/Options.java: fixes compile error: new method #isGeneratingPIE.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4066 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-27 22:19:48 +00:00
Minero Aoki 1d35dd1665 * net/loveruby/cflat/compiler/Compiler.java: implement -shared.
* net/loveruby/cflat/compiler/Options.java: new option -shared.
* net/loveruby/cflat/compiler/CodeGeneratorOptions.java: ditto.
* net/loveruby/cflat/compiler/SourceFile.java: new method #linkedFileName.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4065 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-27 22:07:04 +00:00
Minero Aoki 94db94b1c4 cbc does not support stdin.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4064 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-27 20:37:10 +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 f94faf7fde * net/loveruby/cflat/compiler/CodeGenerator.java: remove unused labels.
* net/loveruby/cflat/asm/AsmStatistics.java: collect label usage.
* net/loveruby/cflat/asm/DirectMemoryReference.java: support collectStatistics.
* net/loveruby/cflat/asm/Literal.java: ditto.
* net/loveruby/cflat/asm/LabelRef.java: ditto.
* net/loveruby/cflat/asm/IntegerLiteral.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4054 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-23 16:10:42 +00:00
Minero Aoki df96fa80c7 * net/loveruby/cflat/asm/PeepholeOptimizer.java: unify insn optimization and jump elimination.
* net/loveruby/cflat/utils/ClonableIterator.java -> Cursor.java
* net/loveruby/cflat/compiler/Options.java: use default optimization rule set for -O.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4052 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-23 15:48:39 +00:00
Minero Aoki 637fce5053 * net/loveruby/cflat/compiler/CodeGenerator.java: apply jump elimination.
* net/loveruby/cflat/asm/PeepholeOptimizer.java: new optimization method: jump elimination.
* net/loveruby/cflat/asm/Assembler.java: refactoring: #string -> #toSource.
* net/loveruby/cflat/asm/Assembler.java: refactoring: list -> assemblies.
* net/loveruby/cflat/asm/Assembly.java: new method #isDirective and #isComment.
* net/loveruby/cflat/asm/Directive.java: implement it.
* net/loveruby/cflat/asm/AsmComment.java: implement it.
* net/loveruby/cflat/asm/Label.java: implement it.
* net/loveruby/cflat/asm/Label.java: new method #equals, #hashCode.
* net/loveruby/cflat/asm/Instruction.java: add jump related methods to analyze jump instruction.
* net/loveruby/cflat/asm/LabelRef.java: new method #label to allow extracting a Label.
* net/loveruby/cflat/asm/Register.java: new method #equals, #hashCode.
* net/loveruby/cflat/asm/AsmStatistics.java: use Object for map keys.
* net/loveruby/cflat/asm/AsmStatistics.java: new method #doesRegisterUsed.
* net/loveruby/cflat/utils/ClonableIterator.java: new utility.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4050 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-23 13:50:54 +00:00
Minero Aoki 8f3e39031a * net/loveruby/cflat/ast/Function.java: refactoring: new method #label.
* net/loveruby/cflat/compiler/CodeGenerator.java (prologue): omit loop when no-verboseAsm.
* test: check "puts = NULL" and "stdin = NULL" are compilable (of course "puts = NULL" causes segv).


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4043 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-21 09:14:34 +00:00
Minero Aoki 81bbba45af * net/loveruby/cflat/compiler/CodeGenerator.java: lhs.memref may be null when lhs is extern variable.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4042 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-21 08:22:48 +00:00
Minero Aoki 556d917fff * net/loveruby/cflat/compiler/CodeGenerator.java: optimize constant load.
* net/loveruby/cflat/asm/ImmediateValue.java: accept any Literal.
* net/loveruby/cflat/ast/LiteralNode.java: new method #asmLiteral.
* net/loveruby/cflat/ast/CastNode.java: is not constant when cast is effective.
* net/loveruby/cflat/compiler/Compiler.java: new option --verbose-asm.
* net/loveruby/cflat/compiler/Options.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/asm/Assembler.java: new method #indentComment, #unindentComment.
* net/loveruby/cflat/asm/AsmComment.java: indent comments.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4041 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-20 20:43:34 +00:00
Minero Aoki 1668b72403 * net/loveruby/cflat/compiler/CodeGenerator.java: fix local variables offset after compiling function body, to allow saving really-used callee-saved registers only.
* net/loveruby/cflat/asm/IndirectMemoryReference.java: allow fixing offset out of consructor.
* net/loveruby/cflat/asm/AsmStatistics.java: new class.
* net/loveruby/cflat/asm/Assembly.java: support #collectStatistics.
* net/loveruby/cflat/asm/Instruction.java: ditto.
* net/loveruby/cflat/asm/AsmOperand.java: ditto.
* net/loveruby/cflat/asm/Register.java: ditto.
* net/loveruby/cflat/asm/AbsoluteAddress.java: ditto.
* net/loveruby/cflat/asm/DirectMemoryReference.java: ditto.
* net/loveruby/cflat/asm/ImmediateValue.java: ditto.
* net/loveruby/cflat/ast/Scope.java: refactoring: rename method: #allChildren -> #allScopes.
* net/loveruby/cflat/ast/Scope.java (allScopes): should include receiver scope itself.
* net/loveruby/cflat/ast/LocalScope.java (allVariables): did not wrongly included current scope's variables.
* net/loveruby/cflat/ast/LocalScope.java: refactoring: rename method: allVariables -> allLocalVariables.
* net/loveruby/cflat/ast/DefinedFunction.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4040 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-20 18:04:20 +00:00
Minero Aoki 076d0dea13 * net/loveruby/cflat/compiler/Options.java: new option -O0, -O, -O1, -O2, -Os.
* net/loveruby/cflat/asm/AsmOptimizer.java: new interface to switch optimizer dynamicly.
* net/loveruby/cflat/compiler/PeepholeOptimizer.java -> asm/PeepholeOptimizer.java
* net/loveruby/cflat/compiler/CodeGenerator.java: parameterize AsmOptimizer.
* net/loveruby/cflat/ast/AST.java: holds a typeTable.
* net/loveruby/cflat/compiler/Compiler.java: follow AST change.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: ditto.
* net/loveruby/cflat/compiler/DereferenceChecker.java: ditto.
* net/loveruby/cflat/compiler/JumpResolver.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4039 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-20 15:13:09 +00:00
Minero Aoki c3bf6f1344 * net/loveruby/cflat/compiler/CodeGenerator.java: apply peep-hole optimization.
* net/loveruby/cflat/compiler/PeepholeOptimizer.java: new class.
* net/loveruby/cflat/asm/Assembler.java: export list (List<Assembly>).
* net/loveruby/cflat/asm/Instruction.java: new method #build to build an Instruction from the instruction object.
* net/loveruby/cflat/asm/OperandPattern.java: new interface.
* net/loveruby/cflat/asm/AsmOperand.java: impelements OperandPattern.
* net/loveruby/cflat/asm/Register.java: implements #isRegister.
* net/loveruby/cflat/asm/ImmediateValue.java: implement #equals to allow matching immediate integer value.
* net/loveruby/cflat/asm/IntegerLiteral.java: implement #equals.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4038 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-20 13:53:34 +00:00
Minero Aoki c335616a4c * net/loveruby/cflat/type/ComplexType.java -> CompositeType.java
* net/loveruby/cflat/ast/ComplexTypeDefinition.java -> CompositeTypeDefinition.java


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4037 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-20 10:30:54 +00:00
Minero Aoki 5c673e2b7d * net/loveruby/cflat/compiler/TypeChecker.java: reject statements whose type is struct/union/allocated array.
* test: test invalid statement expression.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4032 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 18:42:46 +00:00
Minero Aoki cc014500f8 * net/loveruby/cflat/asm: toString -> toSource.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4030 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 18:23:51 +00:00
Minero Aoki 47d4b13b1e * net/loveruby/cflat/asm/Literal.java: does not inherit AsmOperand.
* net/loveruby/cflat/asm/Assembler.java: do not use Literals in instruction operand.
* net/loveruby/cflat/asm/ImmediateValue.java: accept only Literals.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4029 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 18:12:46 +00:00
Minero Aoki a95ad7b451 * net/loveruby/cflat/asm/Symbol.java -> LabelRef.java
* net/loveruby/cflat/asm/*.java: Symbol -> LabelRef.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4028 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 17:53:12 +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 cb8b921931 * net/loveruby/cflat/ast/Function.java (address): should return $sym.
* net/loveruby/cflat/asm/Instruction.java: fix indent.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4024 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 15:59:57 +00:00
Minero Aoki 7314d4bf6f * net/loveruby/cflat/asm/Assembler.java: objectify instructions, directives, comments and labels.
* net/loveruby/cflat/asm/Label.java: inherits Assembly instead of AsmEntity.
* net/loveruby/cflat/asm/Address.java: new method #isAddress.
* net/loveruby/cflat/asm/ImmediateValue.java: accept Literals.
* net/loveruby/cflat/asm/AbsoluteAddress.java: new file.
* net/loveruby/cflat/asm/AsmComment.java: new file.
* net/loveruby/cflat/asm/Assembly.java: new file.
* net/loveruby/cflat/asm/Directive.java: new file.
* net/loveruby/cflat/asm/Reference.java -> DirectAddress.java: new file.
* net/loveruby/cflat/asm/SimpleAddress.java, CompositeAddress.java -> IndirectAddress.java
* net/loveruby/cflat/asm/Instruction.java: new file.
* net/loveruby/cflat/asm/IntegerLiteral.java: new file.
* net/loveruby/cflat/asm/Literal.java: new file.
* net/loveruby/cflat/asm/Symbol.java: new file.
* net/loveruby/cflat/compiler/CodeGenerator.java: follow asm changes.
* net/loveruby/cflat/ast/UndefinedVariable.java: 
* net/loveruby/cflat/ast/Function.java


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4022 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 15:21:14 +00:00
Minero Aoki ae0f46cee4 * net/loveruby/cflat/compiler/Compiler.java: link libcbc on making executables.
* Makefile: new file.
* lib/Makefile: new file to build libcbc.a.
* test: test varargs.
* install.sh: new file.
* README: change install.sh usage.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4021 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 12:19:11 +00:00
Minero Aoki 9a0bfed9f0 * net/loveruby/cflat/compiler/Compiler.java: handle multiple source files.
* net/loveruby/cflat/compiler/Options.java: new class forked from Compiler.java.  Command option parser.
* net/loveruby/cflat/compiler/SourceFile.java: new class.
* net/loveruby/cflat/compiler/LdOption.java: new class.
* net/loveruby/cflat/compiler/LdArg.java: new interface.
* net/loveruby/cflat/exception/OptionParseError.java: new error class.
* test: test multiple input.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4016 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 15:51:46 +00:00
Minero Aoki 688d709302 * net/loveruby/cflat/compiler/Compiler.java: use CflatToken to dump token list.
* net/loveruby/cflat/compiler/CodeGenerator.java: show stmt line in assembly.
* net/loveruby/cflat/parser/Parser.jj: pass a Token to the Location.
* net/loveruby/cflat/ast/AST.java: use CflatToken.
* net/loveruby/cflat/ast/Location.java: use CflatToken.
* net/loveruby/cflat/ast/CflatToken.java: new file.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4015 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 11:08:26 +00:00
Minero Aoki b79d20d4c3 * net/loveruby/cflat/ast/UndefinedVariable.java: should not append '$' for extern symbol address.
* import/stdio.hb: add va_list functions.
* import/stdarg.hb: new file.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4014 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 20:36:34 +00:00
Minero Aoki 09f1c83a3b * net/loveruby/cflat/compiler/TypeChecker.java: reject incomplete multi-dimension array for function parameters.
* net/loveruby/cflat/compiler/TypeChecker.java: reject array variable definition without length.
* net/loveruby/cflat/type/Type.java: remove #isAllocated.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: change #isAllocatedArray semantics.  isAllocatedArray requires the all consecutive array types have its length, recursively.
* net/loveruby/cflat/type/ArrayType.java: new method #isIncompleteArray.
* net/loveruby/cflat/compiler/Compiler.java: new option --dump-asm.
* net/loveruby/cflat/compiler/Compiler.java: handle "--" on command line.
* test/run.sh: use bash.
* test/shunit.sh: show program name on core dump.
* test/syntax1.cb: int[][] is now invalid.
* cbci: print coredump and signal.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4010 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 17:28:00 +00:00
Minero Aoki 3b0a50aaca * net/loveruby/cflat/compiler/CodeGenerator.java (arefNode): calculate element address of multi-dimension array correctly.
* net/loveruby/cflat/compiler/CodeGenerator.java (compileStmt): output statement number and line number as comment.
* net/loveruby/cflat/ast/ArefNode.java: new method #isMultiDimension.
* net/loveruby/cflat/ast/ArefNode.java: new method #baseExpr.
* net/loveruby/cflat/ast/ArefNode.java: new method #elementSize.
* net/loveruby/cflat/ast/ArefNode.java: new method #length.
* net/loveruby/cflat/type/ArrayType.java: add comment.
* test: test multi-dimension array access.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4007 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 13:15:38 +00:00
Minero Aoki 50d605a369 * net/loveruby/cflat/compiler/Compiler.java: implement -o option.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4004 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 23:36:31 +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 633a249559 * net/loveruby/cflat/compiler/CodeGenerator.java: opassign should not spill DX because division uses DX.
* net/loveruby/cflat/ast/PtrMemberNode.java: #dereferedType should return Type instead of ComplexType because DereferenceChecker checks derefered type by this method.
* test: test ptr->memb with complex pointer expression.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4002 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 22:37:39 +00:00
Minero Aoki 0206623cad * net/loveruby/cflat/compiler/CodeGenerator.java: calculate LHS value on AX, not BX.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4001 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 21:50:59 +00:00
Minero Aoki 355873c1ea * net/loveruby/cflat/parser/Parser.jj: parse sizeof expr.
* net/loveruby/cflat/compiler/Visitor.java: support SizeofTypeNode, SizeofExprNode.
* net/loveruby/cflat/compiler/TypeResolver.java: ditto.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* net/loveruby/cflat/ast/ASTVisitor.java: ditto.
* net/loveruby/cflat/ast/SizeofTypeNode.java: new file.
* net/loveruby/cflat/ast/SizeofExprNode.java: new file.
* net/loveruby/cflat/type/Type.java: default alignment equals to size, not allocSize (e.g. int[4] should be aligned on 4, not 16).
* net/loveruby/cflat/type/StructType.java: element offset calculation was wrong. Elements should be aligned on its own alignment.
* net/loveruby/cflat/type/StructType.java: size calculation was wrong.  Struct size is align(last-offset, max-element-alignment).
* net/loveruby/cflat/type/UnionType.java: union's alignment equals to element's max alignment.
* net/loveruby/cflat/type/ComplexType.java: cache computed alignment.
* net/loveruby/cflat/type/ArrayType.java: array's alignment equals to elements' alignment.
* net/loveruby/cflat/ast/Slot.java: new method #allocSize, #alignment.
* net/loveruby/cflat/asm/Assembler.java: new method #align (moved from CodeGenerator).
* test


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3999 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 20:10:49 +00:00
Minero Aoki a6c6112b29 * net/loveruby/cflat/utils/TextUtils.java (toUnsigned): simplify.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3998 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 17:57:27 +00:00
Minero Aoki 554e1e9f04 * net/loveruby/cflat/compiler/Compiler.java: use #dumpString.
* net/loveruby/cflat/compiler/Constants.java: new class.
* net/loveruby/cflat/compiler/Constants.java: define constant sourceEncoding.
* net/loveruby/cflat/parser/Parser.jj: get source encoding from Constant class.
* net/loveruby/cflat/ast/Dumper.java: use #dumpString.
* net/loveruby/cflat/asm/Assembler.java: use #dumpString.
* net/loveruby/cflat/utils/TextUtils.java: new method #dumpString, which dumps UTF-8 string correctly.
* test: test UTF-8 string literal.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3997 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 17:46:17 +00:00
Minero Aoki 960d30f461 * net/loveruby/cflat/asm/Register.java (lowerByteRegister): check wheather the register has lower-byte register or not.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3996 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 16:21:41 +00:00
Minero Aoki cd988128cc * net/loveruby/cflat/compiler/CodeGenerator.java: implement cast.
* net/loveruby/cflat/asm/Assembler.java: new method #movsx, #movzx.
* net/loveruby/cflat/type/PointerType.java: provide #isSigned for cast.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* test: test cast operation.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3995 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 15:59:02 +00:00