From: bdemsky Date: Mon, 27 Mar 2006 23:58:38 +0000 (+0000) Subject: Changes X-Git-Tag: preEdgeChange~953 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d440f2170bcd209fb63943c7b6513037c43c36ad;p=IRC.git Changes --- diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index c3419d60..e5888b3d 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -13,8 +13,10 @@ public class ClassDescriptor extends Descriptor { superclass=null; fields=new SymbolTable(); methods=new SymbolTable(); + classid=UIDCount++; } - + private static int UIDCount=0; + private final int classid; String classname; String superclass; ClassDescriptor superdesc; @@ -24,6 +26,9 @@ public class ClassDescriptor extends Descriptor { SymbolTable fields; SymbolTable methods; + public int getId() { + return classid; + } public Iterator getMethods() { return methods.getDescriptorsIterator(); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index e7e815d9..168c253d 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -89,7 +89,7 @@ public class BuildCode { if (type.isPtr()&&GENERATEPRECISEGC) objecttemps.addPtr(temp); else - objecttemps.addPrim(temp); + objecttemps.addPrim(temp); } } } @@ -195,7 +195,6 @@ public class BuildCode { tovisit.add(fm.methodEntryNode()); FlatNode current_node=null; - //Assign labels 1st //Node needs a label if it is while(!tovisit.isEmpty()) { @@ -312,7 +311,7 @@ public class BuildCode { private void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) { MethodDescriptor md=fm.getMethod(); ClassDescriptor cn=md.getClassDesc(); - output.println(" {"); + output.println("{"); boolean needcomma=false; if (GENERATEPRECISEGC) { output.print(" struct "+cn.getSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __paramlist__={"); @@ -346,23 +345,43 @@ public class BuildCode { } private void generateFlatNew(FlatMethod fm, FlatNew fn, PrintWriter output) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); } private void generateFlatOpNode(FlatMethod fm, FlatOpNode fon, PrintWriter output) { - if (fon.getOp().getOp()==Operation.ASSIGN) - output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); - else if (fon.getRight()!=null) + + if (fon.getRight()!=null) output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+fon.getOp().toString()+generateTemp(fm,fon.getRight())+";"); + else if (fon.getOp().getOp()==Operation.ASSIGN) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.UNARYPLUS) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.UNARYMINUS) + output.println(generateTemp(fm, fon.getDest())+" = -"+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.POSTINC) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+"++;"); + else if (fon.getOp().getOp()==Operation.POSTDEC) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+"--;"); + else if (fon.getOp().getOp()==Operation.PREINC) + output.println(generateTemp(fm, fon.getDest())+" = ++"+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.PREDEC) + output.println(generateTemp(fm, fon.getDest())+" = --"+generateTemp(fm, fon.getLeft())+";"); else output.println(generateTemp(fm, fon.getDest())+fon.getOp().toString()+generateTemp(fm, fon.getLeft())+";"); } private void generateFlatCastNode(FlatMethod fm, FlatCastNode fcn, PrintWriter output) { /* TODO: Make call into runtime */ - output.println(fcn.getDst()+"=("+fcn.getType().getSafeSymbol()+")"+fcn.getSrc()+";"); + output.println(generateTemp(fm,fcn.getDst())+"=("+fcn.getType().getSafeSymbol()+")"+generateTemp(fm,fcn.getSrc())+";"); } private void generateFlatLiteralNode(FlatMethod fm, FlatLiteralNode fln, PrintWriter output) { + if (fln.getValue()==null) + output.println(generateTemp(fm, fln.getDst())+"=0;"); + else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) + output.println(generateTemp(fm, fln.getDst())+"=newstring(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\");"); + else + output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";"); } private void generateFlatReturnNode(FlatMethod fm, FlatReturnNode frn, PrintWriter output) { diff --git a/Robust/src/IR/Flat/FlatLiteralNode.java b/Robust/src/IR/Flat/FlatLiteralNode.java index c27836bc..ba5e58cb 100644 --- a/Robust/src/IR/Flat/FlatLiteralNode.java +++ b/Robust/src/IR/Flat/FlatLiteralNode.java @@ -12,6 +12,14 @@ public class FlatLiteralNode extends FlatNode { this.dst=dst; } + public TypeDescriptor getType() { + return type; + } + + public TempDescriptor getDst() { + return dst; + } + public Object getValue() { return value; } @@ -22,7 +30,7 @@ public class FlatLiteralNode extends FlatNode { else return dst+"="+escapeString(value.toString()); } - private static String escapeString(String st) { + protected static String escapeString(String st) { String new_st=""; for(int i=0;i