mirror of https://github.com/aamine/cbc
* 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
This commit is contained in:
parent
8bc055ed4e
commit
8ca82908c1
29
ChangeLog
29
ChangeLog
|
@ -1,3 +1,32 @@
|
||||||
|
Sat Jan 5 12:52:38 2008 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Sat Jan 5 12:23:25 2008 Minero Aoki <aamine@loveruby.net>
|
Sat Jan 5 12:23:25 2008 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* net/loveruby/cflat/compiler/Compiler.java: show error location.
|
* net/loveruby/cflat/compiler/Compiler.java: show error location.
|
||||||
|
|
4
ToDo
4
ToDo
|
@ -180,8 +180,8 @@
|
||||||
- parse command line option
|
- parse command line option
|
||||||
- --dump-tokens
|
- --dump-tokens
|
||||||
- --dump-ast
|
- --dump-ast
|
||||||
|
- print node location in error message
|
||||||
* parse command line option more precisely
|
* parse command line option more precisely
|
||||||
* print node location in error message
|
|
||||||
* --dump-semantic
|
* --dump-semantic
|
||||||
* generate IR
|
* generate IR
|
||||||
* --dump-ir
|
* --dump-ir
|
||||||
|
@ -197,4 +197,4 @@
|
||||||
* semantic check (dflow)
|
* semantic check (dflow)
|
||||||
* register allocation
|
* register allocation
|
||||||
* vararg retrieve
|
* vararg retrieve
|
||||||
* 64bit long_long support
|
? 64bit long_long support
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
|
||||||
import net.loveruby.cflat.type.*;
|
import net.loveruby.cflat.type.*;
|
||||||
import net.loveruby.cflat.asm.*;
|
import net.loveruby.cflat.asm.*;
|
||||||
|
|
||||||
public class ArefNode extends ExprNode implements LHSNode {
|
public class ArefNode extends ExprNode {
|
||||||
protected ExprNode expr, index;
|
protected ExprNode expr, index;
|
||||||
|
|
||||||
public ArefNode(ExprNode expr, ExprNode index) {
|
public ArefNode(ExprNode expr, ExprNode index) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.loveruby.cflat.ast;
|
package net.loveruby.cflat.ast;
|
||||||
import net.loveruby.cflat.type.*;
|
import net.loveruby.cflat.type.*;
|
||||||
|
import net.loveruby.cflat.asm.*;
|
||||||
|
|
||||||
public class CastNode extends ExprNode {
|
public class CastNode extends ExprNode {
|
||||||
protected TypeNode typeNode;
|
protected TypeNode typeNode;
|
||||||
|
@ -26,10 +27,22 @@ public class CastNode extends ExprNode {
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConstant() {
|
||||||
|
return expr.isConstant();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAssignable() {
|
public boolean isAssignable() {
|
||||||
return expr.isAssignable();
|
return expr.isAssignable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConstantAddress() {
|
||||||
|
return expr.isConstantAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsmEntity address() {
|
||||||
|
return expr.address();
|
||||||
|
}
|
||||||
|
|
||||||
public Location location() {
|
public Location location() {
|
||||||
return typeNode.location();
|
return typeNode.location();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
|
||||||
import net.loveruby.cflat.type.*;
|
import net.loveruby.cflat.type.*;
|
||||||
import net.loveruby.cflat.asm.*;
|
import net.loveruby.cflat.asm.*;
|
||||||
|
|
||||||
public class DereferenceNode extends UnaryOpNode implements LHSNode {
|
public class DereferenceNode extends UnaryOpNode {
|
||||||
public DereferenceNode(ExprNode n) {
|
public DereferenceNode(ExprNode n) {
|
||||||
super(n);
|
super(n);
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,8 @@ public class DereferenceNode extends UnaryOpNode implements LHSNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAssignable() { return true; }
|
public boolean isAssignable() { return true; }
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public boolean isConstantAddress() { return false; }
|
public boolean isConstantAddress() { return false; }
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public AsmEntity address() {
|
|
||||||
throw new Error("DereferenceNode#address");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,18 @@ abstract public class ExprNode extends Node {
|
||||||
return type().isDereferable();
|
return type().isDereferable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConstant() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAssignable() {
|
public boolean isAssignable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: move this method to LHSNode
|
public boolean isConstantAddress() {
|
||||||
|
throw new Error("ExprNode#isConstantAddress called");
|
||||||
|
}
|
||||||
|
|
||||||
public AsmEntity address() {
|
public AsmEntity address() {
|
||||||
throw new Error("ExprNode#address called");
|
throw new Error("ExprNode#address called");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package net.loveruby.cflat.ast;
|
|
||||||
import net.loveruby.cflat.asm.*;
|
|
||||||
|
|
||||||
public interface LHSNode {
|
|
||||||
public boolean isAssignable();
|
|
||||||
public boolean isConstantAddress();
|
|
||||||
public AsmEntity address();
|
|
||||||
}
|
|
|
@ -22,4 +22,8 @@ abstract public class LiteralNode extends ExprNode {
|
||||||
public TypeNode typeNode() {
|
public TypeNode typeNode() {
|
||||||
return typeNode;
|
return typeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConstant() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import net.loveruby.cflat.type.*;
|
||||||
import net.loveruby.cflat.asm.AsmEntity;
|
import net.loveruby.cflat.asm.AsmEntity;
|
||||||
import net.loveruby.cflat.exception.*;
|
import net.loveruby.cflat.exception.*;
|
||||||
|
|
||||||
public class MemberNode extends ExprNode implements LHSNode {
|
public class MemberNode extends ExprNode {
|
||||||
protected ExprNode expr;
|
protected ExprNode expr;
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
@ -41,14 +41,16 @@ public class MemberNode extends ExprNode implements LHSNode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
public boolean isConstant() {
|
||||||
public boolean isConstantAddress() {
|
return expr.isConstantAddress();
|
||||||
return ((LHSNode)expr).isConstantAddress();
|
}
|
||||||
|
|
||||||
|
public boolean isConstantAddress() {
|
||||||
|
return expr.isConstantAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public AsmEntity address() {
|
public AsmEntity address() {
|
||||||
return ((LHSNode)expr).address().add(offset());
|
return expr.address().add(offset());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location location() {
|
public Location location() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import net.loveruby.cflat.type.*;
|
||||||
import net.loveruby.cflat.asm.*;
|
import net.loveruby.cflat.asm.*;
|
||||||
import net.loveruby.cflat.exception.*;
|
import net.loveruby.cflat.exception.*;
|
||||||
|
|
||||||
public class PtrMemberNode extends ExprNode implements LHSNode {
|
public class PtrMemberNode extends ExprNode {
|
||||||
public ExprNode expr;
|
public ExprNode expr;
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
|
@ -38,12 +38,10 @@ public class PtrMemberNode extends ExprNode implements LHSNode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public boolean isConstantAddress() {
|
public boolean isConstantAddress() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public AsmEntity address() {
|
public AsmEntity address() {
|
||||||
throw new Error("PtrMemberNode#address");
|
throw new Error("PtrMemberNode#address");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.loveruby.cflat.ast;
|
||||||
import net.loveruby.cflat.type.Type;
|
import net.loveruby.cflat.type.Type;
|
||||||
import net.loveruby.cflat.asm.*;
|
import net.loveruby.cflat.asm.*;
|
||||||
|
|
||||||
public class VariableNode extends ExprNode implements LHSNode {
|
public class VariableNode extends ExprNode {
|
||||||
protected Location location;
|
protected Location location;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Entity entity;
|
protected Entity entity;
|
||||||
|
@ -40,12 +40,10 @@ public class VariableNode extends ExprNode implements LHSNode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public boolean isConstantAddress() {
|
public boolean isConstantAddress() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LHS node requirement
|
|
||||||
public AsmEntity address() {
|
public AsmEntity address() {
|
||||||
return entity.address();
|
return entity.address();
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,8 +399,7 @@ static public void p(String s) { System.err.println(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visit(AssignNode node) {
|
public void visit(AssignNode node) {
|
||||||
// FIXME
|
if (node.lhs().isConstantAddress()) {
|
||||||
if (((LHSNode)node.lhs()).isConstantAddress()) {
|
|
||||||
compile(node.rhs());
|
compile(node.rhs());
|
||||||
saveWords(node.type(), "ax", node.lhs().address());
|
saveWords(node.type(), "ax", node.lhs().address());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import stdio;
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int* ptr = &i;
|
||||||
|
|
||||||
|
(int)i = 666;
|
||||||
|
printf("%d", i);
|
||||||
|
*(int*)ptr = 777;
|
||||||
|
printf(";%d", *ptr);
|
||||||
|
puts("");
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -196,6 +196,7 @@ assert_out "1;2;1073741824;2147483648;0" ./ulongops # 32bit
|
||||||
|
|
||||||
assert_out "25000000" ./cast
|
assert_out "25000000" ./cast
|
||||||
assert_out "777;666" ./cast2
|
assert_out "777;666" ./cast2
|
||||||
|
assert_out "666;777" ./cast3
|
||||||
|
|
||||||
assert_out "2" ./block
|
assert_out "2" ./block
|
||||||
assert_out "1;2;3" ./defvar
|
assert_out "1;2;3" ./defvar
|
||||||
|
|
Loading…
Reference in New Issue