/* Classify parameters */
MethodDescriptor md=(MethodDescriptor)methodit.next();
FlatMethod fm=state.getMethodFlat(md);
- generateFlatMethod(fm,outmethod);
+ if (!md.getModifiers().isNative())
+ generateFlatMethod(fm,outmethod);
}
}
outmethod.close();
thisvd=null;
}
+
+ public Modifiers getModifiers() {
+ return modifier;
+ }
+
public boolean matches(MethodDescriptor md) {
/* Check the name */
if (!identifier.equals(md.identifier))
import java.util.*;
public class State {
- public State(ParseNode parsetree) {
- this.parsetree=parsetree;
+ public String main;
+
+ public State() {
this.classes=new SymbolTable();
this.treemethodmap=new Hashtable();
this.flatmethodmap=new Hashtable();
+ this.parsetrees=new HashSet();
+ }
+
+ public void addParseNode(ParseNode parsetree) {
+ parsetrees.add(parsetree);
}
public SymbolTable classes;
- public ParseNode parsetree;
+ public Set parsetrees;
public Hashtable treemethodmap;
public Hashtable flatmethodmap;
package IR.Tree;
import IR.*;
-import java.util.Vector;
+import java.util.*;
+
public class BuildIR {
State state;
this.state=state;
}
public void buildtree() {
- ParseNode pn=state.parsetree;
- parseFile(pn);
+ for(Iterator it=state.parsetrees.iterator();it.hasNext();) {
+ ParseNode pn=(ParseNode)it.next();
+ parseFile(pn);
+ }
}
/** Parse the classes in this file */
ParseNode snn=pn.getChild("super").getChild("type").getChild("class").getChild("name");
NameDescriptor nd=parseName(snn);
cn.setSuper(nd.toString());
+ } else {
+ if (!cn.getSymbol().equals(TypeUtil.ObjectClass))
+ cn.setSuper(TypeUtil.ObjectClass);
}
cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
parseClassBody(cn, pn.getChild("classbody"));
return ((value&STATIC)!=0);
}
+ public boolean isNative() {
+ return ((value&NATIVE)!=0);
+ }
+
public String toString() {
String st="";
if ((value&PUBLIC)!=0)
ln.setType(new TypeDescriptor(TypeDescriptor.LONG));
} else if (o instanceof Float) {
ln.setType(new TypeDescriptor(TypeDescriptor.FLOAT));
+ } else if (o instanceof Boolean) {
+ ln.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
} else if (o instanceof Double) {
ln.setType(new TypeDescriptor(TypeDescriptor.DOUBLE));
} else if (o instanceof Character) {
ln.setType(new TypeDescriptor(TypeDescriptor.CHAR));
} else if (o instanceof String) {
ln.setType(new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass)));
- }
+ }
if (td!=null)
if (!typeutil.isSuperorType(td,ln.getType()))
public class TypeUtil {
public static final String StringClass="String";
+ public static final String ObjectClass="Object";
State state;
Hashtable supertable;
Hashtable subclasstable;
public class Main {
public static void main(String args[]) throws Exception {
+ String ClassLibraryPrefix="./ClassLibrary/";
if (args.length<1) {
System.out.println("Must input source file");
System.exit(-1);
}
- for(int i=1;i<args.length;i++) {
+ State state=new State();
+
+ for(int i=0;i<args.length;i++) {
String option=args[i];
if (option.equals("-precise"))
IR.Flat.BuildCode.GENERATEPRECISEGC=true;
else if (option.equals("-dir"))
IR.Flat.BuildCode.PREFIX=args[++i]+"/";
+ else if (option.equals("-classlibrary"))
+ ClassLibraryPrefix=args[++i]+"/";
+ else if (option.equals("-mainclass"))
+ state.main=args[++i];
else if (option.equals("-help")) {
+ System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
System.out.println("-dir outputdirectory -- output code in outputdirectory");
+ System.out.println("-mainclass -- main function to call");
System.out.println("-precise -- use precise garbage collection");
+
System.out.println("-help -- print out help");
System.exit(0);
+ } else {
+ readSourceFile(state, args[i]);
}
}
- Reader fr = new BufferedReader(new FileReader(args[0]));
- Lex.Lexer l = new Lex.Lexer(fr);
- java_cup.runtime.lr_parser g;
- g = new Parse.Parser(l);
- ParseNode p=(ParseNode) g./*debug_*/parse().value;
- State state=new State(p);
+ readSourceFile(state, ClassLibraryPrefix+"Object.java");
+
BuildIR bir=new BuildIR(state);
bir.buildtree();
BuildCode bc=new BuildCode(state, bf.getMap(), tu);
bc.buildCode();
-
- System.exit(l.numErrors());
+ System.exit(0);
}
+
+ private static void readSourceFile(State state, String sourcefile) throws Exception {
+ Reader fr = new BufferedReader(new FileReader(sourcefile));
+ Lex.Lexer l = new Lex.Lexer(fr);
+ java_cup.runtime.lr_parser g;
+ g = new Parse.Parser(l);
+ ParseNode p=(ParseNode) g./*debug_*/parse().value;
+ state.addParseNode(p);
+ if (l.numErrors()!=0) {
+ System.out.println("Error parsing Object.java");
+ System.exit(l.numErrors());
+ }
+ }
}