outstructs.close();
}
+
/* This code just generates the main C method for java programs.
* The main C method packs up the arguments into a string array
* and passes it to the java main method. */
//Store the sizes of classes & array elements
generateSizeArray(outmethod);
+
//Store table of supertypes
generateSuperTypeTable(outmethod);
}
}
-
/** Generate array that contains the sizes of class objects. The
* object allocation functions in the runtime use this
* information. */
}
outclassdefs.println("};");
+
+ ClassDescriptor objectclass=typeutil.getClass(TypeUtil.ObjectClass);
+ needcomma=false;
+ outclassdefs.print("int typearray[]={");
+ for(int i=0;i<state.numClasses();i++) {
+ ClassDescriptor cd=cdarray[i];
+ ClassDescriptor supercd=cd.getSuperDesc();
+ if (needcomma)
+ outclassdefs.print(", ");
+ if (supercd==null)
+ outclassdefs.print("-1");
+ else
+ outclassdefs.print(supercd.getId());
+ needcomma=true;
+ }
+
+ for(int i=0;i<state.numArrays();i++) {
+ TypeDescriptor arraytd=arraytable[i];
+ ClassDescriptor arraycd=arraytd.getClassDesc();
+ if (arraycd==null) {
+ if (needcomma)
+ outclassdefs.print(", ");
+ outclassdefs.print(objectclass.getId());
+ needcomma=true;
+ continue;
+ }
+ ClassDescriptor cd=arraycd.getSuperDesc();
+ int type=-1;
+ while(cd!=null) {
+ TypeDescriptor supertd=new TypeDescriptor(cd);
+ supertd.setArrayCount(arraytd.getArrayCount());
+ type=state.getArrayNumber(supertd);
+ if (type!=-1) {
+ type+=state.numClasses();
+ break;
+ }
+ cd=cd.getSuperDesc();
+ }
+ if (needcomma)
+ outclassdefs.print(", ");
+ outclassdefs.print(type);
+ needcomma=true;
+ }
+
+ outclassdefs.println("};");
+
+ needcomma=false;
+
+
+ outclassdefs.print("int typearray2[]={");
+ for(int i=0;i<state.numArrays();i++) {
+ TypeDescriptor arraytd=arraytable[i];
+ ClassDescriptor arraycd=arraytd.getClassDesc();
+ if (arraycd==null) {
+ if (needcomma)
+ outclassdefs.print(", ");
+ outclassdefs.print("-1");
+ needcomma=true;
+ continue;
+ }
+ ClassDescriptor cd=arraycd.getSuperDesc();
+ int level=arraytd.getArrayCount()-1;
+ int type=-1;
+ for(;level>0;level--) {
+ TypeDescriptor supertd=new TypeDescriptor(objectclass);
+ supertd.setArrayCount(level);
+ type=state.getArrayNumber(supertd);
+ if (type!=-1) {
+ type+=state.numClasses();
+ break;
+ }
+ }
+ if (needcomma)
+ outclassdefs.print(", ");
+ outclassdefs.print(type);
+ needcomma=true;
+ }
+
+ outclassdefs.println("};");
}
/** Constructs params and temp objects for each method or task.
generateFlatAtomicExitNode(fm, lb, (FlatAtomicExitNode) fn, output);
return;
+ case FKind.FlatInstanceOfNode:
+ generateFlatInstanceOfNode(fm, lb, (FlatInstanceOfNode)fn, output);
+ return;
+
case FKind.FlatSESEEnterNode:
generateFlatSESEEnterNode(fm, lb, (FlatSESEEnterNode) fn, output);
return;
}
}
+ public void generateFlatInstanceOfNode(FlatMethod fm, LocalityBinding lb, FlatInstanceOfNode fion, PrintWriter output) {
+ int type;
+ if (fion.getType().isArray()) {
+ type=state.getArrayNumber(fion.getType())+state.numClasses();
+ } else {
+ type=fion.getType().getClassDesc().getId();
+ }
+
+ if (fion.getType().getSymbol().equals(TypeUtil.ObjectClass))
+ output.println(generateTemp(fm, fion.getDst(), lb)+"=1;");
+ else
+ output.println(generateTemp(fm, fion.getDst(), lb)+"=instanceof("+generateTemp(fm,fion.getSrc(),lb)+","+type+");");
+ }
+
public void generateFlatAtomicEnterNode(FlatMethod fm, LocalityBinding lb, FlatAtomicEnterNode faen, PrintWriter output) {
/* Check to see if we need to generate code for this atomic */
if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0)
case Kind.TertiaryNode:
return flattenTertiaryNode((TertiaryNode)en,out_temp);
+
+ case Kind.InstanceOfNode:
+ return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
}
throw new Error();
}
return new NodePair(fn,null);
}
+ private NodePair flattenInstanceOfNode(InstanceOfNode tn, TempDescriptor out_temp) {
+ TempDescriptor expr_temp=TempDescriptor.tempFactory("expr",tn.getExpr().getType());
+ NodePair cond=flattenExpressionNode(tn.getExpr(), expr_temp);
+ FlatInstanceOfNode fion=new FlatInstanceOfNode(tn.getExprType(), expr_temp, out_temp);
+ cond.getEnd().addNext(fion);
+ return new NodePair(cond.getBegin(),fion);
+ }
+
private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
TempDescriptor cond_temp=TempDescriptor.tempFactory("tert_cond",new TypeDescriptor(TypeDescriptor.BOOLEAN));
TempDescriptor true_temp=TempDescriptor.tempFactory("tert_true",tn.getTrueExpr().getType());
case Kind.TertiaryNode:
checkTertiaryNode(md, nametable, (TertiaryNode)en, td);
return;
+
+ case Kind.InstanceOfNode:
+ checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
+ return;
}
throw new Error();
}
checkExpressionNode(md, nametable, tn.getFalseExpr(), td );
}
+ void checkInstanceOfNode(Descriptor md, SymbolTable nametable, InstanceOfNode tn, TypeDescriptor td) {
+ if (!td.isBoolean())
+ throw new Error("Expecting type "+td+"for instanceof expression");
+
+ checkTypeDescriptor(tn.getExprType());
+ checkExpressionNode(md, nametable, tn.getExpr(), null);
+ }
+
void checkAssignmentNode(Descriptor md, SymbolTable nametable, AssignmentNode an, TypeDescriptor td) {
boolean postinc=true;