/* Create output streams to write to */
PrintWriter outclassdefs=null;
PrintWriter outstructs=null;
+ PrintWriter outrepairstructs=null;
PrintWriter outmethodheader=null;
PrintWriter outmethod=null;
PrintWriter outvirtual=null;
str=new FileOutputStream(PREFIX+"taskdefs.c");
outtaskdefs=new java.io.PrintWriter(str, true);
}
+ if (state.structfile!=null) {
+ str=new FileOutputStream(PREFIX+state.structfile+".struct");
+ outrepairstructs=new java.io.PrintWriter(str, true);
+ }
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
/* Build the virtual dispatch tables */
-
buildVirtualTables(outvirtual);
/* Output includes */
}
if (state.TASK)
outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
+
+
+ /* Output structure definitions for repair tool */
+ if (state.structfile!=null) {
+ buildRepairStructs(outrepairstructs);
+ outrepairstructs.close();
+ }
+
outstructs.close();
outmethod.close();
}
private int maxcount=0;
+ private void buildRepairStructs(PrintWriter outrepairstructs) {
+ Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+ while(classit.hasNext()) {
+ ClassDescriptor cn=(ClassDescriptor)classit.next();
+ outrepairstructs.println("structure "+cn.getSymbol()+" {");
+ outrepairstructs.println(" int __type__;");
+ if (cn.hasFlags()) {
+ outrepairstructs.println(" int __flag__;");
+ outrepairstructs.println(" int __flagptr__;");
+ }
+ printRepairStruct(cn, outrepairstructs);
+ outrepairstructs.println("}\n");
+ }
+
+ for(int i=0;i<state.numArrays();i++) {
+ TypeDescriptor tdarray=arraytable[i];
+ TypeDescriptor tdelement=tdarray.dereference();
+ outrepairstructs.println("structure "+arraytype+"_"+state.getArrayNumber(tdarray)+" {");
+ outrepairstructs.println(" int __type__;");
+ printRepairStruct(typeutil.getClass(TypeUtil.ObjectClass), outrepairstructs);
+ outrepairstructs.println(" int length;");
+ if (tdelement.isClass()||tdelement.isArray())
+ outrepairstructs.println(" "+tdelement.getRepairSymbol()+" * elem[this.length];");
+ else
+ outrepairstructs.println(" "+tdelement.getRepairSymbol()+" elem[this.length];");
+
+ outrepairstructs.println("}\n");
+ }
+
+ }
+
+ private void printRepairStruct(ClassDescriptor cn, PrintWriter output) {
+ ClassDescriptor sp=cn.getSuperDesc();
+ if (sp!=null)
+ printRepairStruct(sp, output);
+
+ Vector fields=(Vector)fieldorder.get(cn);
+
+ for(int i=0;i<fields.size();i++) {
+ FieldDescriptor fd=(FieldDescriptor)fields.get(i);
+ if (fd.getType().isArray()) {
+ output.println(" "+arraytype+"_"+ state.getArrayNumber(fd.getType()) +" * "+fd.getSymbol()+";");
+ } else if (fd.getType().isClass())
+ output.println(" "+fd.getType().getRepairSymbol()+" * "+fd.getSymbol()+";");
+ else
+ output.println(" "+fd.getType().getRepairSymbol()+" "+fd.getSymbol()+";");
+ }
+ }
+
/** This method outputs TaskDescriptor information */
void generateTaskDescriptor(PrintWriter output, TaskDescriptor task) {
for (int i=0;i<task.numParameters();i++) {
import java.util.*;
public class State {
- public String main;
-
public State() {
this.classes=new SymbolTable();
this.tasks=new SymbolTable();
/** Boolean flag which indicates whether compiler is compiling a task-based
* program. */
public boolean TASK;
+ public String structfile;
+ public String main;
public SymbolTable classes;
public SymbolTable tasks;
} else throw new Error();
}
+ public Vector parseChecks(ParseNode pn) {
+ Vector ccs=new Vector();
+ ParseNodeVector pnv=pn.getChildren();
+ for(int i=0;i<pnv.size();i++) {
+ ParseNode fn=pnv.elementAt(i);
+ ConstraintCheck cc=parseConstraintCheck(fn);
+ ccs.add(cc);
+ }
+ return ccs;
+ }
+
+ public ConstraintCheck parseConstraintCheck(ParseNode pn) {
+ if (isNode(pn,"cons_check")) {
+ String varname=pn.getChild("name").getTerminal();
+ String specname=pn.getChild("spec").getTerminal();
+ ConstraintCheck cc=new ConstraintCheck(varname, specname);
+ return cc;
+ } else throw new Error();
+ }
+
public void parseParameterList(TaskDescriptor td, ParseNode pn) {
ParseNode paramlist=pn.getChild("task_parameter_list");
if (paramlist==null)
Vector vfe=null;
if (pn.getChild("flag_effects_list")!=null)
vfe=parseFlags(pn.getChild("flag_effects_list"));
- blockstatements.add(new TaskExitNode(vfe));
+ Vector ccs=null;
+ if (pn.getChild("cons_checks")!=null)
+ ccs=parseChecks(pn.getChild("cons_checks"));
+
+ blockstatements.add(new TaskExitNode(vfe, ccs));
} else if (isNode(pn,"return")) {
if (isEmpty(pn.getTerminal()))
blockstatements.add(new ReturnNode());
--- /dev/null
+package IR.Tree;
+
+import IR.*;
+
+public class ConstraintCheck {
+ String varname;
+ String specname;
+
+ public ConstraintCheck(String varname, String specname) {
+ this.varname=varname;
+ this.specname=specname;
+ }
+
+ public String getVarName() {
+ return varname;
+ }
+
+ public String getSpec() {
+ return specname;
+ }
+
+ public String printNode(int indent) {
+ return "assert "+varname+" "+specname;
+ }
+}
return name;
}
- public int kind() {
- return Kind.FlagNode;
- }
-
public boolean getStatus() {
return status;
}
public class TaskExitNode extends BlockStatementNode {
Vector vfe;
- public TaskExitNode(Vector vfe) {
+ Vector ccs;
+ public TaskExitNode(Vector vfe, Vector ccs) {
this.vfe=vfe;
+ this.ccs=ccs;
}
public String printNode(int indent) {
return vfe;
}
+ public Vector getChecks() {
+ return ccs;
+ }
+
public int kind() {
return Kind.TaskExitNode;
}
else throw new Error("Error Type: "+type);
}
+ public String getRepairSymbol() {
+ if (isArray())
+ return IR.Flat.BuildCode.arraytype;
+ else if (isClass())
+ return class_desc.getSymbol();
+ else if (isByte())
+ return "char";
+ else if (isChar())
+ return "short";
+ else if (isShort())
+ return "short";
+ else if (isInt())
+ return "int";
+ else if (isBoolean()) //Booleans are ints in C
+ return "int";
+ else if (isLong())
+ return "long long";
+ else if (isVoid())
+ return "void";
+ else if (isDouble())
+ return "double";
+ else if (isFloat())
+ return "float";
+ else throw new Error("Error Type: "+type);
+ }
+
public String getSafeDescriptor() {
- if (isClass())
+ //Can't safely use [ in C
+ if (isArray())
+ return "_AR_"+this.dereference().getSafeDescriptor();
+ else if (isClass())
return class_desc.getSafeDescriptor();
else if (isByte())
return "C";
ClassLibraryPrefix=args[++i]+"/";
else if (option.equals("-mainclass"))
state.main=args[++i];
+ else if (option.equals("-struct"))
+ state.structfile=args[++i];
else if (option.equals("-task"))
state.TASK=true;
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("-struct structfile -- output structure declarations for repair tool");
System.out.println("-mainclass -- main function to call");
System.out.println("-precise -- use precise garbage collection");
non terminal ParseNode flag_list_opt;
non terminal ParseNode flag_change;
+non terminal ParseNode cons_checks_opt;
+non terminal ParseNode cons_checks;
+non terminal ParseNode cons_check;
+
start with goal;
:}
;
-task_exitstatement ::= TASKEXIT flag_effects_opt:opt SEMICOLON{:
- RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot();
+task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
+ RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
+ :};
+
+cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
+ | {: RESULT = new ParseNode("empty"); :}
+ ;
+
+cons_checks ::= cons_check:cc {:
+ ParseNode pn=new ParseNode("cons_checks");
+ pn.addChild(cc);
+ RESULT=pn;
+ :}
+ | cons_checks:ccs COMMA cons_check:cc {:
+ ccs.addChild(cc);
+ RESULT=ccs;
+ :};
+
+cons_check ::= IDENTIFIER:id LBRACE IDENTIFIER:spec RBRACE {:
+ ParseNode pn=new ParseNode("cons_check");
+ pn.addChild("name").addChild(id);
+ pn.addChild("spec").addChild(spec);
+ RESULT=pn;
:};
flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
MAINFILE=$1
shift
mkdir tmpbuilddirectory
-java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -task $@
+java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task $@
gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin
\ No newline at end of file