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:
Minero Aoki 2009-05-24 11:23:29 +00:00
parent 0fd4bbfad3
commit 4d889a2588
9 changed files with 74 additions and 7 deletions

View File

@ -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>
* net/loveruby/cflat/compiler/TypeResolver.java: now 3 pathes

View File

@ -1,11 +1,16 @@
package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.*;
import net.loveruby.cflat.type.Type;
public class AddressNode extends UnaryOpNode {
protected Type type;
public class AddressNode extends ExprNode {
final ExprNode expr;
Type type;
public AddressNode(ExprNode n) {
super("&", n);
public AddressNode(ExprNode expr) {
this.expr = expr;
}
public ExprNode expr() {
return expr;
}
public Type type() {
@ -14,12 +19,23 @@ public class AddressNode extends UnaryOpNode {
}
/** Decides type of this node.
* This method is called in TypeChecker. */
* This method is called from DereferenceChecker. */
public void setType(Type type) {
if (this.type != null) throw new Error("type set twice");
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) {
return visitor.visit(this);
}

View File

@ -45,6 +45,9 @@ public class ArefNode extends LHSNode {
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
d.printMember("index", index);
}

View File

@ -27,6 +27,9 @@ public class DereferenceNode extends LHSNode {
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
}

View File

@ -44,6 +44,9 @@ public class MemberNode extends LHSNode {
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
d.printMember("member", member);
}

View File

@ -56,6 +56,9 @@ public class PtrMemberNode extends LHSNode {
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
d.printMember("member", member);
}

View File

@ -707,7 +707,8 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
// #@@range/Dereference{
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;
}
// #@@}

26
test/implicitaddr.cb Normal file
View File

@ -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");
}
}

View File

@ -246,6 +246,7 @@ test_25_block() {
test_26_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-semcheck2.cb
assert_compile_error defun-semcheck3.cb