From: jzhou Date: Tue, 2 Nov 2010 22:30:03 +0000 (+0000) Subject: Add support for volatile keyword in mgc version. For Tilera, as we execute a process... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=09429d53fc40ed5689016ade47f0dac77f2715da;p=IRC.git Add support for volatile keyword in mgc version. For Tilera, as we execute a process on each core, to make all the 'threads' share the volatile field, make it as a shared field in global shared heap like static fields. Add keywords and rules for enumarated type, but still have bugs and when parsing the test code, the compiler throw errors. --- diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index 8e00b5bf..98bb261c 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -26,9 +26,17 @@ public class ClassDescriptor extends Descriptor { // for inner classes boolean isInnerClass=false; + + // inner classes/enum can have these String surroundingclass=null; ClassDescriptor surroudingdesc=null; SymbolTable innerdescs; + + // for enum type + boolean isEnum = false; + SymbolTable enumdescs; + HashMap enumConstantTbl; + int enumconstantid = 0; public ClassDescriptor(String classname, boolean isInterface) { this("", classname, isInterface); @@ -50,6 +58,7 @@ public class ClassDescriptor extends Descriptor { superinterfaces = new Vector(); superIFdesc = new SymbolTable(); this.innerdescs = new SymbolTable(); + this.enumdescs = new SymbolTable(); } public int getId() { @@ -141,6 +150,28 @@ public class ClassDescriptor extends Descriptor { } if (printcr) st+="\n"; + + for(Iterator it=this.getEnum(); it.hasNext();) { + ClassDescriptor icd = (ClassDescriptor)it.next(); + st += icd.getModifier().toString() + " enum " + icd.getSymbol() + " {\n "; + Set keys = icd.getEnumConstantTbl().keySet(); + String[] econstants = new String[keys.size()]; + Iterator it_keys = keys.iterator(); + while(it_keys.hasNext()) { + String key = (String)it_keys.next(); + econstants[icd.getEnumConstant(key)] = key; + } + for(int i = 0; i < econstants.length; i++) { + st += econstants[i]; + if(i < econstants.length-1) { + st += ", "; + } + } + st+="\n}\n"; + printcr=true; + } + if (printcr) + st+="\n"; for(Iterator it=getMethods(); it.hasNext();) { MethodDescriptor md=(MethodDescriptor)it.next(); @@ -168,7 +199,7 @@ public class ClassDescriptor extends Descriptor { throw new Error(fd.getSymbol()+" already defined"); fields.add(fd); fieldvec.add(fd); - if(fd.isStatic()) { + if((fd.isStatic()) || (fd.isVolatile())) { this.incStaticFields(); } } @@ -273,19 +304,51 @@ public class ClassDescriptor extends Descriptor { return this.innerdescs; } - /*public String getSymbol() { - if(this.isInnerClass) { - return this.surroudingdesc.getSymbol() + "." + name; + public void setAsEnum() { + this.isEnum = true; + } + + public boolean isEnum() { + return this.isEnum; + } + + public void addEnum(ClassDescriptor icd) { + this.enumdescs.add(icd); + } + + public Iterator getEnum() { + return this.enumdescs.getDescriptorsIterator(); + } + + public SymbolTable getEnumTable() { + return this.enumdescs; + } + + public void addEnumConstant(String econstant) { + if(this.enumConstantTbl == null) { + this.enumConstantTbl = new HashMap(); + } + if(this.enumConstantTbl.containsKey(econstant)) { + return; } else { - return name; + this.enumConstantTbl.put(econstant, this.enumconstantid++); } + return; } - - public String getSafeSymbol() { - if(this.isInnerClass) { - return this.surroudingdesc.getSafeSymbol()+ "." + safename; + + public int getEnumConstant(String econstant) { + if(this.enumConstantTbl.containsKey(econstant)) { + return this.enumConstantTbl.get(econstant).intValue(); } else { - return safename; + return -1; } - }*/ + } + + public HashMap getEnumConstantTbl() { + return this.enumConstantTbl; + } + + public Modifiers getModifier() { + return this.modifiers; + } } diff --git a/Robust/src/IR/FieldDescriptor.java b/Robust/src/IR/FieldDescriptor.java index 42951328..ecd6777a 100644 --- a/Robust/src/IR/FieldDescriptor.java +++ b/Robust/src/IR/FieldDescriptor.java @@ -33,6 +33,10 @@ public class FieldDescriptor extends Descriptor { return modifier.isStatic(); } + public boolean isVolatile() { + return modifier.isVolatile(); + } + public boolean isGlobal() { return isglobal; } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 0d713f23..ee4560cf 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1623,7 +1623,16 @@ public class BuildCode { else if ((state.MGC) && (fd.isStatic())) { // TODO add version for normal Java later // static field - globaldefout.println(" "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + if(fd.isVolatile()) { + globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + } else { + globaldefout.println(" "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); + } + classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";"); + } else if ((state.MGC) && (fd.isVolatile())) { + // TODO add version for normal Java later + // static field + globaldefout.println(" volatile "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";"); classdefout.println(" "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";"); } else classdefout.println(" "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";"); @@ -2171,8 +2180,8 @@ public class BuildCode { for(int i=0; i"+fd.getSafeSymbol()+"=&(global_defs_p->"+cn.getSafeSymbol()+fd.getSafeSymbol()+");"); } } @@ -5054,7 +5063,7 @@ public class BuildCode { // DEBUG } if(state.MGC) { // TODO add version for normal Java later - if(ffn.getField().isStatic()) { + if((ffn.getField().isStatic()) || (ffn.getField().isVolatile())) { // static field if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block @@ -5200,7 +5209,7 @@ public class BuildCode { // DEBUG } if(state.MGC) { // TODO add version for normal Java later - if(fsfn.getField().isStatic()) { + if((fsfn.getField().isStatic()) || (fsfn.getField().isVolatile())) { // static field if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index cf43c80c..2e9f1aa2 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -55,7 +55,7 @@ public class BuildIR { if (toanalyze!=null) toanalyze.add(cn); state.addClass(cn); - // for inner classes + // for inner classes/enum if(state.MGC) { // TODO add version for normal Java later HashSet tovisit = new HashSet(); @@ -77,6 +77,24 @@ public class BuildIR { while(it_ics.hasNext()) { tovisit.add(it_ics.next()); } + + Iterator it_ienums = cd.getEnum(); + while(it_ienums.hasNext()) { + ClassDescriptor iecd = (ClassDescriptor)it_ienums.next(); + if(toanalyze != null) { + toanalyze.add(iecd); + } + state.addClass(iecd); + } + } + + Iterator it_enums = cn.getEnum(); + while(it_enums.hasNext()) { + ClassDescriptor ecd = (ClassDescriptor)it_enums.next(); + if(toanalyze != null) { + toanalyze.add(ecd); + } + state.addClass(ecd); } } } else if (isNode(type_pn,"task_declaration")) { @@ -90,6 +108,25 @@ public class BuildIR { if (toanalyze!=null) toanalyze.add(cn); state.addClass(cn); + + // for enum + if(state.MGC) { + // TODO add version for normal Java later + Iterator it_enums = cn.getEnum(); + while(it_enums.hasNext()) { + ClassDescriptor ecd = (ClassDescriptor)it_enums.next(); + if(toanalyze != null) { + toanalyze.add(ecd); + } + state.addClass(ecd); + } + } + } else if ((state.MGC) && isNode(type_pn,"enum_declaration")) { + // TODO add version for normal Java later + ClassDescriptor cn = parseEnumDecl(null, type_pn); + if (toanalyze!=null) + toanalyze.add(cn); + state.addClass(cn); } else { throw new Error(type_pn.getLabel()); } @@ -97,6 +134,40 @@ public class BuildIR { } } + private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) { + ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false); + ecd.setAsEnum(); + if(cn != null) { + ecd.setSurroundingClass(cn.getSymbol()); + ecd.setSurrounding(cn); + } + cn.addEnum(ecd); + if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)|| + ecd.getSymbol().equals(TypeUtil.TagClass))) { + ecd.setSuper(TypeUtil.ObjectClass); + } + ecd.setModifiers(parseModifiersList(pn.getChild("modifiers"))); + parseEnumBody(ecd, pn.getChild("enumbody")); + return ecd; + } + + private void parseEnumBody(ClassDescriptor cn, ParseNode pn) { + ParseNode decls=pn.getChild("enum_constants_list"); + if (decls!=null) { + ParseNodeVector pnv=decls.getChildren(); + for(int i=0; i