Tags will let us group objects together and specify these groups in the task declaration
public static final int FlatFlagActionNode=13;
public static final int FlatCheckNode=14;
public static final int FlatBackEdge=15;
+ public static final int FlatTagActionNode=16;
}
--- /dev/null
+package IR;
+
+/**
+ * Descriptor
+ *
+ * represents a symbol in the language (var name, function name, etc).
+ */
+
+public class TagDescriptor extends Descriptor {
+
+ public TagDescriptor(String identifier) {
+ super(identifier);
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof TagDescriptor) {
+ TagDescriptor t=(TagDescriptor) o;
+ return getSymbol()==t.getSymbol();
+ } else return false;
+ }
+
+ public int hashCode() {
+ return getSymbol().hashCode();
+ }
+
+ public String toString() {
+ return "Tag "+getSymbol();
+ }
+}
--- /dev/null
+package IR;
+
+/**
+ * Descriptor
+ *
+ * represents a symbol in the language (var name, function name, etc).
+ */
+
+public class TagVarDescriptor extends Descriptor {
+
+ protected TagDescriptor td;
+ protected String identifier;
+
+ public TagVarDescriptor(TagDescriptor t, String identifier) {
+ super(identifier);
+ this.td=t;
+ this.identifier=identifier;
+ this.safename = "___" + name + "___";
+ this.uniqueid=count++;
+ }
+
+ public String getName() {
+ return identifier;
+ }
+
+ public TagDescriptor getTag() {
+ return td;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof TagVarDescriptor) {
+ TagVarDescriptor tvd=(TagVarDescriptor)o;
+ return tvd.identifier.equals(identifier)&&tvd.td.equals(td);
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return identifier.hashCode()^td.hashcode();
+ }
+
+ public String toString() {
+ return td.toString()+" "+identifier;
+ }
+}
package IR;
import IR.Tree.FlagExpressionNode;
+import IR.Tree.TagExpressionList;
import IR.Tree.FlagEffects;
import java.util.Vector;
import java.util.Hashtable;
public class TaskDescriptor extends Descriptor {
protected Hashtable flagstable;
+ protected Hashtable tagstable;
protected Vector vfe;
protected String identifier;
protected Vector params;
this.identifier=identifier;
this.uniqueid=count++;
flagstable=new Hashtable();
+ tagstable=new Hashtable(); //BUGFIX - added initialization here
params=new Vector();
paramtable=new SymbolTable();
}
return paramtable;
}
- public void addParameter(TypeDescriptor type, String paramname, FlagExpressionNode fen) {
+ public void addParameter(TypeDescriptor type, String paramname, FlagExpressionNode fen, TagExpressionList tel) {
if (paramname.equals("this"))
throw new Error("Can't have parameter named this");
VarDescriptor vd=new VarDescriptor(type, paramname);
params.add(vd);
flagstable.put(vd, fen);
+ if (tel!=null) {//BUGFIX - added null check here...test with any bristlecone program
+ tagstable.put(vd, tel);
+ for(int i=0;i<tel.numTags();i++) {
+ TagVarDescriptor tvd=new TagVarDescriptor(new TagDescriptor(tel.getType(i)), tel.getName(i));
+ if (!(paramtable.getFromSameScope(tel.getName(i)) instanceof TagVarDescriptor))
+ throw new Error("Parameter "+paramname+" already defined");
+ paramtable.add(tvd);
+ }
+ }
+
if (paramtable.getFromSameScope(paramname)!=null) {
throw new Error("Parameter "+paramname+" already defined");
}
return (FlagExpressionNode) flagstable.get(vd);
}
+ public TagExpressionList getTag(VarDescriptor vd) {
+ return (TagExpressionList) flagstable.get(vd);
+ }
+
public String toString() {
String st=identifier+"(";
for(int i=0;i<params.size();i++) {
if (isNode(pn,"flag_effect")) {
String flagname=pn.getChild("name").getTerminal();
FlagEffects fe=new FlagEffects(flagname);
- parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("flag_list")!=null)
+ parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("tag_list")!=null)
+ parseTagEffect(fe, pn.getChild("tag_list"));
return fe;
} else throw new Error();
}
+
+ public void parseTagEffect(FlagEffects fes, ParseNode pn) {
+ ParseNodeVector pnv=pn.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode pn2=pnv.elementAt(i);
+ boolean status=true;
+ if (isNode(pn2,"not")) {
+ status=false;
+ pn2=pn2.getChild("name");
+ }
+ String name=pn2.getTerminal();
+ fes.addTagEffect(new TagEffect(name,status));
+ }
+ }
public void parseFlagEffect(FlagEffects fes, ParseNode pn) {
ParseNodeVector pnv=pn.getChildren();
ParseNode paramn=pnv.elementAt(i);
TypeDescriptor type=parseTypeDescriptor(paramn);
- ParseNode tmp=paramn;
- while (tmp.getChild("single")==null) {
- type=type.makeArray(state);
- tmp=tmp.getChild("array");
- }
- String paramname=tmp.getChild("single").getTerminal();
+ String paramname=paramn.getChild("single").getTerminal();
FlagExpressionNode fen=parseFlagExpression(paramn.getChild("flag").getFirstChild());
+
+ ParseNode tagnode=paramn.getChild("tag");
+
+ TagExpressionList tel=null;
+ if (tagnode!=null) {
+ tel=parseTagExpressionList(tagnode);
+ }
- td.addParameter(type,paramname,fen);
+ td.addParameter(type,paramname,fen, tel);
}
}
+ public TagExpressionList parseTagExpressionList(ParseNode pn) {
+ ParseNodeVector pnv=pn.getChildren();
+ TagExpressionList tel=new TagExpressionList();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode tn=pnv.elementAt(i);
+ String type=tn.getChild("type").getTerminal();
+ String name=tn.getChild("single").getTerminal();
+ tel.addTag(type, name);
+ }
+ return tel;
+ }
+
public ClassDescriptor parseTypeDecl(ParseNode pn) {
ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal());
if (!isEmpty(pn.getChild("super").getTerminal())) {
for(int i=0;i<args.size();i++) {
con.addArgument((ExpressionNode)args.get(i));
}
- /* Could have flag set here */
- if (pn.getChild("flag_list")!=null) {
+ /* Could have flag set or tag added here */
+ if (pn.getChild("flag_list")!=null||pn.getChild("tag_list")!=null) {
FlagEffects fe=new FlagEffects(null);
- parseFlagEffect(fe, pn.getChild("flag_list"));
+ if (pn.getChild("flag_list")!=null)
+ parseFlagEffect(fe, pn.getChild("flag_list"));
+
+ if (pn.getChild("tag_list")!=null)
+ parseTagEffect(fe, pn.getChild("tag_list"));
con.addFlagEffects(fe);
}
+
return con;
} else if (isNode(pn,"createarray")) {
//System.out.println(pn.PPrint(3,true));
public Vector parseBlockStatement(ParseNode pn) {
Vector blockstatements=new Vector();
- if (isNode(pn,"local_variable_declaration")) {
+ if (isNode(pn,"tag_declaration")) {
+ String name=pn.getChild("single").getTerminal();
+ String type=pn.getChild("type").getTerminal();
+
+ blockstatements.add(new TagDeclarationNode(name, type));
+ } else if (isNode(pn,"local_variable_declaration")) {
TypeDescriptor t=parseTypeDescriptor(pn);
ParseNode vn=pn.getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
public class FlagEffects {
Vector effects;
+ Vector tageffects;
String name;
VarDescriptor vd;
public FlagEffects(String name) {
effects=new Vector();
+ tageffects=new Vector();
this.name=name;
}
effects.add(fe);
}
+ public void addTagEffect(TagEffect te) {
+ tageffects.add(te);
+ }
+
+ public int numTagEffects() {
+ return tageffects.size();
+ }
+
+ public TagEffect getTagEffect(int i) {
+ return (TagEffect) tageffects.get(i);
+ }
+
public int numEffects() {
return effects.size();
}
public final static int FlagNode=17;
public final static int FlagOpNode=18;
public final static int TaskExitNode=19;
+ public final static int TagDeclarationNode=20;
}
}
}
- public void checkFlagEffects(TaskDescriptor td, Vector vfe) {
+ public void checkFlagEffects(TaskDescriptor td, Vector vfe, SymbolTable nametable) {
if (vfe==null)
return; /* No flag effects to check */
for(int i=0;i<vfe.size();i++) {
throw new Error("Attempting to modify external flag: "+name);
flag.setFlag(flag_d);
}
+ for(int j=0;j<fe.numTagEffects();j++) {
+ TagEffect tag=fe.getTagEffect(j);
+ String name=tag.getName();
+
+ Descriptor d=(Descriptor)nametable.get(name);
+ if (d==null)
+ throw new Error("Tag descriptor "+name+" undeclared");
+ else if (!(d instanceof TagVarDescriptor))
+ throw new Error(name+" is not a tag descriptor");
+ tag.setTag((TagVarDescriptor)d);
+ }
}
}
checkFlagExpressionNode(cd, fen);
}
- checkFlagEffects(td, td.getFlagEffects());
+ checkFlagEffects(td, td.getFlagEffects(),td.getParameterTable());
/* Check that the task code is valid */
BlockNode bn=state.getMethodBody(td);
checkBlockNode(td, td.getParameterTable(),bn);
case Kind.DeclarationNode:
checkDeclarationNode(md, nametable, (DeclarationNode)bsn);
return;
+
+ case Kind.TagDeclarationNode:
+ checkTagDeclarationNode(md, nametable, (TagDeclarationNode)bsn);
+ return;
case Kind.IfStatementNode:
checkIfStatementNode(md, nametable, (IfStatementNode)bsn);
if (dn.getExpression()!=null)
checkExpressionNode(md, nametable, dn.getExpression(), vd.getType());
}
+
+ void checkTagDeclarationNode(Descriptor md, SymbolTable nametable, TagDeclarationNode dn) {
+ TagVarDescriptor vd=dn.getTagVarDescriptor();
+ Descriptor d=nametable.get(vd.getSymbol());
+ if ((d==null)||
+ (d instanceof FieldDescriptor)) {
+ nametable.add(vd);
+ } else
+ throw new Error(vd.getSymbol()+" defined a second time");
+ }
void checkSubBlockNode(Descriptor md, SymbolTable nametable, SubBlockNode sbn) {
checkBlockNode(md, nametable, sbn.getBlockNode());
void checkTaskExitNode(Descriptor md, SymbolTable nametable, TaskExitNode ten) {
if (md instanceof MethodDescriptor)
throw new Error("Illegal taskexit appears in Method: "+md.getSymbol());
- checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects());
+ checkFlagEffects((TaskDescriptor)md, ten.getFlagEffects(),nametable);
checkConstraintCheck((TaskDescriptor) md, nametable, ten.getChecks());
}
} else if (d instanceof FieldDescriptor) {
nn.setField((FieldDescriptor)d);
nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
- }
+ } else throw new Error("Wrong type of descriptor");
if (td!=null)
if (!typeutil.isSuperorType(td,nn.getType()))
throw new Error("Field node returns "+nn.getType()+", but need "+td);
throw new Error("Attempting to modify external flag: "+name);
flag.setFlag(flag_d);
}
+ for(int j=0;j<fe.numTagEffects();j++) {
+ TagEffect tag=fe.getTagEffect(j);
+ String name=tag.getName();
+
+ Descriptor d=(Descriptor)nametable.get(name);
+ if (d==null)
+ throw new Error("Tag descriptor "+name+" undeclared");
+ else if (!(d instanceof TagVarDescriptor))
+ throw new Error(name+" is not a tag descriptor");
+ tag.setTag((TagVarDescriptor)d);
+ }
}
--- /dev/null
+package IR.Tree;
+import IR.TagVarDescriptor;
+import IR.TagDescriptor;
+
+public class TagDeclarationNode extends BlockStatementNode {
+ String name;
+ String type;
+ TagVarDescriptor tvd;
+
+ public TagDeclarationNode(String name, String type) {
+ this.name=name;
+ this.type=type;
+ tvd=new TagVarDescriptor(new TagDescriptor(type), name);
+ }
+
+ public String printNode(int indent) {
+ return "Tag "+name+"=new("+type+")";
+ }
+
+ public TagVarDescriptor getTagVarDescriptor() {
+ return tvd;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public int kind() {
+ return Kind.TagDeclarationNode;
+ }
+}
--- /dev/null
+package IR.Tree;
+
+import IR.*;
+
+public class TagEffect {
+ TagVarDescriptor tag;
+ boolean status;
+ String name;
+
+ public TagEffect(String tag, boolean status) {
+ this.name=tag;
+ this.status=status;
+ }
+
+ public void setTag(TagVarDescriptor tag) {
+ this.tag=tag;
+ }
+
+ public TagVarDescriptor getTag() {
+ return tag;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean getStatus() {
+ return status;
+ }
+
+ public String printNode(int indent) {
+ if (status)
+ return name;
+ else
+ return "!"+name;
+ }
+}
--- /dev/null
+package IR.Tree;
+import java.util.Vector;
+
+public class TagExpressionList {
+ Vector names;
+ Vector types;
+
+ public TagExpressionList() {
+ names=new Vector();
+ types=new Vector();
+ }
+
+ public void addTag(String type, String name) {
+ types.add(type);
+ names.add(name);
+ }
+
+ public int numTags() {
+ return names.size();
+ }
+
+ public String getName(int i) {
+ return (String) names.get(i);
+ }
+
+ public String getType(int i) {
+ return (String) types.get(i);
+ }
+}
non terminal ParseNode cons_checks;
non terminal ParseNode cons_check;
+non terminal ParseNode tag_variable_declaration_statement;
+non terminal ParseNode tag_expression_list;
+non terminal ParseNode tag_expression;
+non terminal ParseNode tag_list;
+non terminal ParseNode tag_list_opt;
+non terminal ParseNode tag_change;
+
start with goal;
pn.addChild(name);
pn.addChild("flag").addChild(exp);
RESULT=pn;
+ :}
+ | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
+ ParseNode pn=new ParseNode("task_parameter");
+ pn.addChild(type);
+ pn.addChild(name);
+ pn.addChild("flag").addChild(exp);
+ pn.addChild("tag").addChild(texp);
+ RESULT=pn;
+ :}
+ ;
+
+tag_expression_list ::= tag_expression:te {:
+ ParseNode pn=new ParseNode("tag_expression_list");
+ pn.addChild(te);
+ RESULT=pn;
+ :}
+ | tag_expression_list:tel COMMA tag_expression:te {:
+ tel.addChild(te);
+ RESULT=tel;
+ :}
+ ;
+
+tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
+ ParseNode pn=new ParseNode("tag_expression");
+ pn.addChild("type").addChild(type);
+ pn.addChild("single").addChild(id);
+ RESULT=pn;
:}
;
+tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
+ | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
+ | {: RESULT = new ParseNode("empty"); :}
+ ;
+
+tag_list ::= tag_change:fc {:
+ ParseNode pn=new ParseNode("tag_list");
+ pn.addChild(fc);
+ RESULT=pn;
+ :}
+ | tag_list:fl COMMA tag_change:fc {:
+ fl.addChild(fc);
+ RESULT=fl;
+ :};
+
+tag_change ::= IDENTIFIER:id {:
+ RESULT=new ParseNode("name").addChild(id).getRoot();
+ :}
+ | NOT IDENTIFIER:id {:
+ RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
+ :};
+
flag_expression ::=
flag_andexpression:exp {:
RESULT=exp;
RESULT=fes;
:};
-flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE {:
+flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
ParseNode pn=new ParseNode("flag_effect");
pn.addChild("name").addChild(id);
pn.addChild(fl);
+ pn.addChild(tlo);
+ RESULT=pn;
+ :}
+ | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
+ ParseNode pn=new ParseNode("flag_effect");
+ pn.addChild("name").addChild(id);
+ pn.addChild(tl);
RESULT=pn;
:};
:}
;
block_statement ::=
- local_variable_declaration_statement:lvds {:
+ tag_variable_declaration_statement:tvds {:
+ RESULT=tvds;
+ :}
+ | local_variable_declaration_statement:lvds {:
RESULT=lvds;
:}
| statement:statement {:
// | class_declaration
// | interface_declaration
;
+tag_variable_declaration_statement ::=
+ TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
+ ParseNode pn=new ParseNode("tag_declaration");
+ pn.addChild("single").addChild(id);
+ pn.addChild("type").addChild(type);
+ RESULT=pn;
+ :}
+ ;
local_variable_declaration_statement ::=
local_variable_declaration:lvd SEMICOLON {:
RESULT=lvd;
pn.addChild(feo);
RESULT=pn;
:}
+ | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
+ ParseNode pn=new ParseNode("createobject");
+ pn.addChild(type);
+ pn.addChild(args);
+ pn.addChild(tl);
+ RESULT=pn;
+ :}
+ | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
+ ParseNode pn=new ParseNode("createobject");
+ pn.addChild(type);
+ pn.addChild(args);
+ pn.addChild(fl);
+ pn.addChild(tl);
+ RESULT=pn;
+ :}
+
// | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
// | primary DOT NEW IDENTIFIER
// LPAREN argument_list_opt RPAREN {:
client:
- gcc -g -o client trans.c testclient.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c
+ gcc -g -O0 -o client trans.c testclient.c mlookup.c clookup.c llookup.c dstm.c objstr.c dstmserver.c plookup.c
server:
- gcc -g -o server dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c
+ gcc -g -O0 -o server dstmserver.c testserver.c plookup.c mlookup.c clookup.c llookup.c dstm.c objstr.c trans.c
clean:
rm client server
1) Type must contain flags
2) Apply flag additions to all states
+Tags operations:
+create_tag operation(type)
+
+tag name=new tag(type);
+
+associate_with_tag operation(object, tag)
+
+Dispatch:
+after flag status, allow tag status...
+each tag state is of the form: Type(name)
+
+Other approach:
+Tag sets: {x, y, z, ... in R
+
+Allow additions/removals of tuples in taskexit:
+remove <x, y, z, ...> from R
+add <x, y> to R
+
+Allow addition of new tuples in object allocation
+add <new, y> to R
------------------------------------------------------------------------------