* net/loveruby/cflat/asm/Reference.java: new constructor Reference(String) for instance.

* net/loveruby/cflat/ast/AST.java: #declarations should include vardecls.
* net/loveruby/cflat/ast/UndefinedVariable.java: #address should return variable symbol.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java: declarations may include variable declaration.
* test/vardecl.cb: test reference of declared external variable.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3884 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-02-10 13:33:19 +00:00
parent 23ada77110
commit 0af37dc9cf
7 changed files with 57 additions and 23 deletions

View File

@ -1,3 +1,19 @@
Sun Feb 10 22:33:15 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/asm/Reference.java: new constructor
Reference(String) for instance.
* net/loveruby/cflat/ast/AST.java: #declarations should include
vardecls.
* net/loveruby/cflat/ast/UndefinedVariable.java: #address should
return variable symbol.
* net/loveruby/cflat/compiler/LocalReferenceResolver.java:
declarations may include variable declaration.
* test/vardecl.cb: test reference of declared external variable.
Fri Feb 8 04:59:38 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/JumpResolver.java: remove

View File

@ -3,6 +3,10 @@ package net.loveruby.cflat.asm;
public class Reference extends Address {
protected Label label;
public Reference(String sym) {
this(new Label(sym));
}
public Reference(Label label) {
this.label = label;
}

View File

@ -35,6 +35,13 @@ public class AST extends Node {
return result.iterator();
}
public Iterator declarations() {
List result = new ArrayList();
result.addAll(declarations.funcdecls());
result.addAll(declarations.vardecls());
return result.iterator();
}
public Iterator entities() {
List result = new ArrayList();
result.addAll(declarations.defvars());
@ -42,14 +49,6 @@ public class AST extends Node {
return result.iterator();
}
public Iterator globalVariables() {
return scope.globalVariables().iterator();
}
public Iterator commonSymbols() {
return scope.commonSymbols().iterator();
}
public Iterator variables() {
return declarations.defvars().iterator();
}
@ -62,22 +61,18 @@ public class AST extends Node {
return declarations.defuns().iterator();
}
public void declare(UndefinedFunction f) {
declarations.funcdecls().add(f);
}
public Iterator declarations() {
List result = new ArrayList();
//result.addAll(declarations.defvars());
//result.addAll(declarations.defuns());
result.addAll(declarations.funcdecls());
return result.iterator();
}
public ToplevelScope scope() {
return scope;
}
public Iterator globalVariables() {
return scope.globalVariables().iterator();
}
public Iterator commonSymbols() {
return scope.commonSymbols().iterator();
}
public ConstantTable constantTable() {
return constantTable;
}

View File

@ -19,6 +19,14 @@ public class UndefinedVariable extends Variable {
throw new Error("UndefinedVariable#defineIn called");
}
public void setAddress(AsmEntity addr) {
throw new Error("UndefinedVariable#setAddress");
}
public AsmEntity address() {
return new Reference(symbol());
}
protected void _dump(Dumper d) {
d.printMember("name", name);
d.printMember("isPrivate", isPrivate());

View File

@ -632,6 +632,7 @@ static public void p(String s) { System.err.println(s); }
saveWords(node.type(), "ax", node.lhs().address());
}
// FIXME: use -4(%edx,%esi,4) addressing
public void visit(ArefNode node) {
if (node.expr().type().isPointerAlike()) {
compile(node.expr());

View File

@ -38,9 +38,9 @@ public class LocalReferenceResolver extends Visitor {
}
}
protected void declareToplevelEntities(Iterator funcdecls) {
while (funcdecls.hasNext()) {
toplevel.declare((UndefinedFunction)funcdecls.next());
protected void declareToplevelEntities(Iterator decls) {
while (decls.hasNext()) {
toplevel.declare((Entity)decls.next());
}
}

10
test/vardecl.cb Normal file
View File

@ -0,0 +1,10 @@
import stdio;
import errno;
int
main(int argc, char **argv)
{
printf("<<%s>>\n", sys_errlist[3]);
printf("printf=%p\n", printf);
return 0;
}