Commit Graph

406 Commits

Author SHA1 Message Date
Minero Aoki ac8256550c add suffix rule for .cb
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4023 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-15 15:53:53 +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 30433983ca * bin/cbc: allow overriding java runtime by setting JAVA environment variable.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4020 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 16:31:31 +00:00
Minero Aoki bdfd802a9c * bin/cbc: follow last directory tree change.
* test/test_cbc.sh: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4019 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 16:25:04 +00:00
Minero Aoki 97ff5aafe0 * cbc -> bin/cbc
* cbci -> bin/cbci.rb
* bin/cbci.sh: new file.
* lib/libcbc.cb: new file.
* build.properties: create jar file in lib/.
* install.sh: new file.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4018 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 16:19:44 +00:00
Minero Aoki 7524fb4468 updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4017 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-14 16:07:31 +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 b484f96864 new option --dump-asm.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4013 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 18:33:43 +00:00
Minero Aoki 64e9e0f34a add task
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4012 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 18:33:29 +00:00
Minero Aoki 85f7003bf5 updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4011 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 18:32:43 +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 ffba97e811 fix typo
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4009 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 16:23:11 +00:00
Minero Aoki 50c4f0ecd5 * cbci: new command. Simple Cflat interpriter.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4008 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 15:13:41 +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 5b4def1bd7 * test: test void function without return.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4006 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-13 12:34:51 +00:00
Minero Aoki 6f9d7714f5 write all FIXMEs
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4005 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 23:46:36 +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 353ae35e8b fill missing text
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4000 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 20:11:17 +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
Minero Aoki 744e790e5d * net/loveruby/cflat/ast/Entity.java (alignment): fetch value from its type.
* net/loveruby/cflat/type/ArrayType.java: should compute allocated size from member's #allocSize, not #size.
* net/loveruby/cflat/type/StructType.java (alignment): do not depend on Entity#size.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3994 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-06 14:19:55 +00:00
Minero Aoki 553623b53f updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3992 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 16:55:27 +00:00
Minero Aoki 7d6555c583 * test/test_cbc.sh: run tests for switch stmt.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3991 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 16:54:40 +00:00
Minero Aoki b99c2c277d * net/loveruby/cflat/parser/Parser.jj: pass location node to the CaseNode explicitly.
* net/loveruby/cflat/ast/CaseNode.java: default clause does not have value, we cannot extract location node from values.  Receive a location node as a first argument explicitly.
* net/loveruby/cflat/compiler/CodeGenerator.java: must define end label.
* net/loveruby/cflat/compiler/CodeGenerator.java: implement default clause.
* test: test switch stmt.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3990 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 16:49:26 +00:00
Minero Aoki 94002785bd updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3989 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 16:27:25 +00:00
Minero Aoki c0b83c8998 * net/loveruby/cflat/compiler/CodeGenerator.java: static function should be local in the file.
* test: test it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3988 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 16:27:08 +00:00
Minero Aoki 458679c32b change file format
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3987 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 15:04:19 +00:00
Minero Aoki 113a440880 change indent
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3986 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 15:00:05 +00:00
Minero Aoki 694891005c * net/loveruby/cflat/ast/CastNode.java: remove unused method #resolve.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3985 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 11:09:14 +00:00
Minero Aoki 7011d0057f ArefNode is not a constant address.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3984 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 11:07:10 +00:00
Minero Aoki 21fdd60b8e * net/loveruby/cflat/compiler/Compiler.java: better help message.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3983 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 11:02:58 +00:00
Minero Aoki f041f5d296 * net/loveruby/cflat/ast/MemberNode.java: has always non-constant address.
* net/loveruby/cflat/asm/AsmEntity.java: remove method #add.
* net/loveruby/cflat/asm/Label.java: ditto.
* net/loveruby/cflat/asm/Reference.java: ditto.
* net/loveruby/cflat/asm/ImmediateValue.java: ditto.
* net/loveruby/cflat/asm/Register.java: ditto.
* net/loveruby/cflat/asm/SimpleAddress.java: ditto.
* net/loveruby/cflat/asm/CompositeAddress.java: ditto.
* test: test nested struct member access.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3982 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 10:59:40 +00:00
Minero Aoki ec7a3285fe * net/loveruby/cflat/ast/Function.java: reduce a warning using Reference.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3981 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 10:40:30 +00:00
Minero Aoki c846043242 updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3980 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 10:39:58 +00:00
Minero Aoki eca722f362 * net/loveruby/cflat/compiler/TypeChecker.java: transform pointer arithmetic to normal arithmetic (e.g. ptr+7 => ptr+(7*sizeof(*ptr))).
* net/loveruby/cflat/compiler/TypeChecker.java: int-ptr is invalid.
* net/loveruby/cflat/compiler/CodeGenerator.java: implement pointer arithmetic correctly (e.g. *(ptr+1) for various types work now).
* net/loveruby/cflat/ast/PrefixOpNode.java: inherit UnaryArithmeticOpNode.
* net/loveruby/cflat/ast/SuffixOpNode.java: ditto.
* net/loveruby/cflat/ast/UnaryArithmeticOpNode.java: new file.
* net/loveruby/cflat/ast/CastNode.java: is not assignable.
* net/loveruby/cflat/type/TypeTable.java: new method #pointerSize, #ptrDiffTypeRef.
* net/loveruby/cflat/type/ArrayType.java: fetch pointer size from a TypeTable.
* net/loveruby/cflat/type/ArrayType.java: we can cast any pointers to void*.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/IntegerTypeRef.java (equals): check name equality by #equals, not ==.
* test: test pointer arithmetic.
* test: CastNode does not becomes LHS, do not check it.
* import/string.hb: add mem* functions.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3979 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 10:24:40 +00:00
Minero Aoki 0229e05728 * net/loveruby/cflat/ast/Declarations.java: reject duplicated symbols to support duplicated import.
* net/loveruby/cflat/compiler/LibraryLoader.java: should return previous loaded symbols for the same import file.
* test: test duplicated import.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3978 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-31 06:18:26 +00:00
Minero Aoki fae7f1e085 * net/loveruby/cflat/parser/Parser.jj: implement NULL.
* test: use it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3977 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-30 11:21:49 +00:00
Minero Aoki 2437c9e4a2 updated
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3976 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-30 11:14:12 +00:00
Minero Aoki 80651a70cc * net/loveruby/cflat/compiler/TypeChecker.java: ptr==ptr should work.
* net/loveruby/cflat/compiler/TypeChecker.java: ptr&&ptr should work.
* net/loveruby/cflat/compiler/TypeChecker.java: any==any should always returns int.
* net/loveruby/cflat/compiler/CodeGenerator.java: ditto.
* test: test it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3975 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-30 11:07:44 +00:00
Minero Aoki 7e39838625 * test/test_cbc.sh: test overrapped lvar.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3974 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-30 09:01:14 +00:00
Minero Aoki 737fb40fb5 * test/assign.cb: test case was wrong (caused SEGV). I don't know why this test case did not crash.
* test/test_cbc.sh: follow it.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3973 1b9489fe-b721-0410-924e-b54b9192deb8
2008-08-30 08:39:31 +00:00