mirror of https://github.com/aamine/cbc
r4907@macbookpro: aamine | 2009-05-24 20:23:14 +0900
* net/loveruby/cflat/compiler/IRGenerator.java (Dereference): do not generate Mem for unloadable object (implicit address generation handling). * net/loveruby/cflat/ast: dump #type for LHS nodes. * net/loveruby/cflat/ast/AddressNode.java: do not inherit UnaryOpNode. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4241 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
0fd4bbfad3
commit
4d889a2588
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Sun May 24 20:24:01 2009 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* net/loveruby/cflat/compiler/IRGenerator.java (Dereference): do
|
||||||
|
not generate Mem for unloadable object (implicit address
|
||||||
|
generation handling).
|
||||||
|
|
||||||
|
* net/loveruby/cflat/ast: dump #type for LHS nodes.
|
||||||
|
|
||||||
|
* net/loveruby/cflat/ast/AddressNode.java: do not inherit
|
||||||
|
UnaryOpNode.
|
||||||
|
|
||||||
Sun May 24 19:23:28 2009 Minero Aoki <aamine@loveruby.net>
|
Sun May 24 19:23:28 2009 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* net/loveruby/cflat/compiler/TypeResolver.java: now 3 pathes
|
* net/loveruby/cflat/compiler/TypeResolver.java: now 3 pathes
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package net.loveruby.cflat.ast;
|
package net.loveruby.cflat.ast;
|
||||||
import net.loveruby.cflat.type.*;
|
import net.loveruby.cflat.type.Type;
|
||||||
|
|
||||||
public class AddressNode extends UnaryOpNode {
|
public class AddressNode extends ExprNode {
|
||||||
protected Type type;
|
final ExprNode expr;
|
||||||
|
Type type;
|
||||||
|
|
||||||
public AddressNode(ExprNode n) {
|
public AddressNode(ExprNode expr) {
|
||||||
super("&", n);
|
this.expr = expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExprNode expr() {
|
||||||
|
return expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type type() {
|
public Type type() {
|
||||||
|
@ -14,12 +19,23 @@ public class AddressNode extends UnaryOpNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Decides type of this node.
|
/** Decides type of this node.
|
||||||
* This method is called in TypeChecker. */
|
* This method is called from DereferenceChecker. */
|
||||||
public void setType(Type type) {
|
public void setType(Type type) {
|
||||||
if (this.type != null) throw new Error("type set twice");
|
if (this.type != null) throw new Error("type set twice");
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location location() {
|
||||||
|
return expr.location();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void _dump(Dumper d) {
|
||||||
|
if (type != null) {
|
||||||
|
d.printMember("type", type);
|
||||||
|
}
|
||||||
|
d.printMember("expr", expr);
|
||||||
|
}
|
||||||
|
|
||||||
public <S,E> E accept(ASTVisitor<S,E> visitor) {
|
public <S,E> E accept(ASTVisitor<S,E> visitor) {
|
||||||
return visitor.visit(this);
|
return visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ public class ArefNode extends LHSNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _dump(Dumper d) {
|
protected void _dump(Dumper d) {
|
||||||
|
if (type != null) {
|
||||||
|
d.printMember("type", type);
|
||||||
|
}
|
||||||
d.printMember("expr", expr);
|
d.printMember("expr", expr);
|
||||||
d.printMember("index", index);
|
d.printMember("index", index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@ public class DereferenceNode extends LHSNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _dump(Dumper d) {
|
protected void _dump(Dumper d) {
|
||||||
|
if (type != null) {
|
||||||
|
d.printMember("type", type);
|
||||||
|
}
|
||||||
d.printMember("expr", expr);
|
d.printMember("expr", expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ public class MemberNode extends LHSNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _dump(Dumper d) {
|
protected void _dump(Dumper d) {
|
||||||
|
if (type != null) {
|
||||||
|
d.printMember("type", type);
|
||||||
|
}
|
||||||
d.printMember("expr", expr);
|
d.printMember("expr", expr);
|
||||||
d.printMember("member", member);
|
d.printMember("member", member);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,9 @@ public class PtrMemberNode extends LHSNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _dump(Dumper d) {
|
protected void _dump(Dumper d) {
|
||||||
|
if (type != null) {
|
||||||
|
d.printMember("type", type);
|
||||||
|
}
|
||||||
d.printMember("expr", expr);
|
d.printMember("expr", expr);
|
||||||
d.printMember("member", member);
|
d.printMember("member", member);
|
||||||
}
|
}
|
||||||
|
|
|
@ -707,7 +707,8 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
|
||||||
|
|
||||||
// #@@range/Dereference{
|
// #@@range/Dereference{
|
||||||
public Expr visit(DereferenceNode node) {
|
public Expr visit(DereferenceNode node) {
|
||||||
return new Mem(asmType(node.type()), transformExpr(node.expr()));
|
Expr addr = transformExpr(node.expr());
|
||||||
|
return node.isLoadable() ? mem(addr, node.type()) : addr;
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import stdio;
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
void *p = &printf;
|
||||||
|
|
||||||
|
check(printf, p);
|
||||||
|
check(*printf, p);
|
||||||
|
check(**printf, p);
|
||||||
|
check(***printf, p);
|
||||||
|
check(****printf, p);
|
||||||
|
puts("");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
check(void* f, void* p)
|
||||||
|
{
|
||||||
|
if (f == p) {
|
||||||
|
printf(";OK");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf(";NG");
|
||||||
|
}
|
||||||
|
}
|
|
@ -246,6 +246,7 @@ test_25_block() {
|
||||||
|
|
||||||
test_26_funcptr() {
|
test_26_funcptr() {
|
||||||
assert_out "OK;OK;OK;OK" ./funcptr
|
assert_out "OK;OK;OK;OK" ./funcptr
|
||||||
|
assert_out ";OK;OK;OK;OK;OK" ./implicitaddr
|
||||||
assert_compile_error defun-semcheck.cb
|
assert_compile_error defun-semcheck.cb
|
||||||
assert_compile_error defun-semcheck2.cb
|
assert_compile_error defun-semcheck2.cb
|
||||||
assert_compile_error defun-semcheck3.cb
|
assert_compile_error defun-semcheck3.cb
|
||||||
|
|
Loading…
Reference in New Issue