diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/AbstractPlaceTree.java b/x10.compiler/src/x10/optimizations/atOptimzer/AbstractPlaceTree.java new file mode 100644 index 0000000000..d7f27ccf4a --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/AbstractPlaceTree.java @@ -0,0 +1,20 @@ +package x10.optimizations.atOptimzer; + +import x10.optimizations.atOptimzer.PlaceNode; + +public class AbstractPlaceTree +{ + public PlaceNode absPlTree; + + public AbstractPlaceTree(PlaceNode plNode) { + this.absPlTree = plNode; + } + + public AbstractPlaceTree() { + this.absPlTree = null; + } + + public void addPlaceNode(PlaceNode plNode) { + this.absPlTree = plNode; + } +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ClassInfo.java b/x10.compiler/src/x10/optimizations/atOptimzer/ClassInfo.java new file mode 100644 index 0000000000..80f54e9068 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ClassInfo.java @@ -0,0 +1,34 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; + +public class ClassInfo { + + public String classifier; + public String type; + public String name; + /* x10Type also using it for parameter optimization as well. + * for field X10Type is used for storing the type. + * for parameter x10Type is used to maintain the count + */ + public String x10Type = ""; + public int classNo = 0; + public int methodNo = 0; + public int methodNoIn = 0; + public LinkedList methodPara = null; + /* field to store the unique id for identifying function-overloading - for method only*/ + public String uniqueId; + + public ClassInfo() { + this.classifier = null; + this.type = null; + this.name = null; + } + + public ClassInfo(String f_classifier, String f_type, String f_name) { + this.classifier = f_classifier; + this.type = f_type; + this.name = f_name; + } + +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ClosureDetails.java b/x10.compiler/src/x10/optimizations/atOptimzer/ClosureDetails.java new file mode 100644 index 0000000000..47939378c1 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ClosureDetails.java @@ -0,0 +1,23 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; + +public class ClosureDetails { + public String name; + public int fromClass = 0; + public int fromMethod = 0; + public int fromplace = 0; + public int toClass = 0; + public int toMethod = 0; + public int toplace = 0; + public int countCRSWS = -1; + + public ClosureDetails(String closureName, int fromClass, int fromMethod, int fromplace ) { + this.name = closureName; + this.fromClass = fromClass; + this.fromMethod = fromMethod; + this.fromplace = fromplace; + } + +} + diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/EdgeRep.java b/x10.compiler/src/x10/optimizations/atOptimzer/EdgeRep.java new file mode 100644 index 0000000000..0305fd5bea --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/EdgeRep.java @@ -0,0 +1,42 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; + +public class EdgeRep { + + public String edgeType; + public String desName; + public String fieldName = ""; + public String edgeName = ""; + public boolean copyFlag = false; + + public EdgeRep(String edgeType, String desName) { + this.edgeType = edgeType; + this.desName = desName; + } + + public EdgeRep(String edgeType, String desName, boolean copyFlag) { + this.edgeType = edgeType; + this.desName = desName; + this.copyFlag = copyFlag; + } + + public EdgeRep(String edgeType, String desName, String fieldName) { + this.edgeType = edgeType; + this.desName = desName; + this.fieldName = fieldName; + } + + public EdgeRep(String edgeType, String desName, String fieldName, boolean copyFlag) { + this.edgeType = edgeType; + this.desName = desName; + this.fieldName = fieldName; + this.copyFlag = copyFlag; + } + + public EdgeRep() { + this.edgeType = ""; + this.desName = ""; + this.fieldName = ""; + } +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObject.java b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObject.java new file mode 100644 index 0000000000..0bbbc2ad16 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObject.java @@ -0,0 +1,23 @@ +package x10.optimizations.atOptimzer; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Stack; + +import x10.optimizations.atOptimzer.ForClosureObjectField; + +public class ForClosureObject { + public String varName = ""; + public boolean ambiguity = false; + public LinkedList fieldDetails = null; + + public ForClosureObject () { + } + + public ForClosureObject(String varName, boolean ambiguity) { + this.varName = varName; + this.ambiguity = ambiguity; + this.fieldDetails = new LinkedList(); + } + +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectField.java b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectField.java new file mode 100644 index 0000000000..262aa8ace7 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectField.java @@ -0,0 +1,32 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Stack; + +public class ForClosureObjectField { + public String fieldName = ""; + public String tempStoredName = ""; + public String fieldType = ""; + public boolean ambiguity = false; + public String fieldObjName = ""; + + public ForClosureObjectField () { + + } + + public ForClosureObjectField(String fieldName, String tempStoredName, String fieldType) { + this.fieldName = fieldName; + this.tempStoredName = tempStoredName; + this.fieldType = fieldType; + } + + public ForClosureObjectField(String fieldName, String tempStoredName, String fieldType, boolean ambiguity, String fieldObjName) { + this.fieldName = fieldName; + this.tempStoredName = tempStoredName; + this.fieldType = fieldType; + this.ambiguity = ambiguity; + this.fieldObjName = fieldObjName; + } +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectcpp.java b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectcpp.java new file mode 100644 index 0000000000..5f38dd8783 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ForClosureObjectcpp.java @@ -0,0 +1,17 @@ +package x10.optimizations.atOptimzer; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Stack; + +import x10.optimizations.atOptimzer.ForClosureObjectField; + +public class ForClosureObjectcpp { + public String fldName = ""; + public String zzName = ""; + public String type = ""; + + public ForClosureObjectcpp () { + } + +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/ObjNode.java b/x10.compiler/src/x10/optimizations/atOptimzer/ObjNode.java new file mode 100644 index 0000000000..f3497d5f9d --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/ObjNode.java @@ -0,0 +1,21 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; + +public class ObjNode { + public String name; + public String objType; + public boolean copyFlag = false; + public int counter = 0; + + public ObjNode(String objName, String objType) { + this.name = objName; + this.objType = objType; + } + + public ObjNode(String objName, String objType, boolean copyFlag) { + this.name = objName; + this.objType = objType; + this.copyFlag = copyFlag; + } +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/PlaceNode.java b/x10.compiler/src/x10/optimizations/atOptimzer/PlaceNode.java new file mode 100644 index 0000000000..d7477eb39b --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/PlaceNode.java @@ -0,0 +1,40 @@ +package x10.optimizations.atOptimzer; + +public class PlaceNode +{ + public String toName; + public PlaceNode child; + public PlaceNode sibling; + + public PlaceNode(String placeName) { + this.toName = placeName; + this.child = null; + this.sibling = null; + } + + public PlaceNode() { + this.toName = null; + this.child = null; + this.sibling = null; + } + + public void addChild(PlaceNode plNode) { + PlaceNode temp = this; + + if(temp.child == null) { + temp.child = plNode; + } + else { + PlaceNode temp1 = temp.child; + + while(temp1.sibling != null) { + temp1 = temp1.sibling; + } + temp1.sibling = plNode; + + } + } + + public void addSibling() { + } +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/VarWithLineNo.java b/x10.compiler/src/x10/optimizations/atOptimzer/VarWithLineNo.java new file mode 100644 index 0000000000..9f71df85b3 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/VarWithLineNo.java @@ -0,0 +1,14 @@ +package x10.optimizations.atOptimzer; + +import java.util.*; + +public class VarWithLineNo { + public String name; + public int lineNo; + + public VarWithLineNo(String varName, int lineNo) { + this.name = varName; + this.lineNo = lineNo; + } + +} diff --git a/x10.compiler/src/x10/optimizations/atOptimzer/processInfo.java b/x10.compiler/src/x10/optimizations/atOptimzer/processInfo.java new file mode 100644 index 0000000000..c6dcb2d260 --- /dev/null +++ b/x10.compiler/src/x10/optimizations/atOptimzer/processInfo.java @@ -0,0 +1,14 @@ +package x10.optimizations.atOptimzer; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Stack; + +import x10.optimizations.atOptimzer.processInfo; + +public class processInfo +{ + public Stack currClass = new Stack(); + public HashMap> classDetails = new HashMap>(); + +} diff --git a/x10.compiler/src/x10cpp/visit/Emitter.java b/x10.compiler/src/x10cpp/visit/Emitter.java index 445ff8b48c..6daf785847 100644 --- a/x10.compiler/src/x10cpp/visit/Emitter.java +++ b/x10.compiler/src/x10cpp/visit/Emitter.java @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -108,10 +109,24 @@ import x10cpp.debug.LineNumberMap; import x10cpp.types.X10CPPContext_c; +//Nobita code +import static x10cpp.visit.MessagePassingCodeGenerator.currClass; +import static x10cpp.visit.MessagePassingCodeGenerator.currMethod; +import static x10cpp.visit.MessagePassingCodeGenerator.iterationCount; +import static x10cpp.visit.MessagePassingCodeGenerator.classDetails; +import x10.optimizations.atOptimzer.VarWithLineNo; +import x10.optimizations.atOptimzer.ClassInfo; + + + public class Emitter { private final Translator tr; private ASTQuery query; + //nobita code + public static String fieldDec = ""; + public static boolean field = false; + public Emitter(Translator tr) { this.tr = tr; query = new ASTQuery(tr); @@ -240,7 +255,14 @@ void printType(Type type, CodeWriter w) { printType(type,w,null); } void printType(Type type, CodeWriter w, Context ctx) { + if (field) { + String str = translateType(type, true, true, ctx); + fieldDec = str; + w.write(str); + } + else { w.write(translateType(type, true, true, ctx)); + } } /** @@ -915,7 +937,21 @@ void printHeader(FieldDecl_c n, CodeWriter h, Translator tr, boolean qualify) { h.write("volatile "); } + //Nobita code + if (iterationCount == 0) { field = true; fieldDec = "";} printType(n.type().type(), h); + if (field) { + field = false; + VarWithLineNo temp1 = currClass.peek(); + + ClassInfo fieldDetails = new ClassInfo("field", n.type().nameString(), n.name().toString()); + fieldDetails.x10Type = fieldDec; + + LinkedList fi = classDetails.get(temp1.name); + fi.add(fieldDetails); + fieldDec = ""; + } + h.allowBreak(2, 2, " ", 1); if (qualify) { X10ClassType declClass = (X10ClassType)n.fieldDef().asInstance().container().toClass(); diff --git a/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java b/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java index 6cb0cae1b0..188e435a03 100644 --- a/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java +++ b/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java @@ -21,6 +21,7 @@ import static x10cpp.visit.Emitter.translateFQN; import static x10cpp.visit.Emitter.translate_mangled_FQN; import static x10cpp.visit.Emitter.voidTemplateInstantiation; +import static x10cpp.visit.MessagePassingCodeGenerator.classDetails; import static x10cpp.visit.SharedVarsMethods.CONSTRUCTOR; import static x10cpp.visit.SharedVarsMethods.DESERIALIZATION_BUFFER; import static x10cpp.visit.SharedVarsMethods.DESERIALIZE_METHOD; @@ -55,9 +56,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.Map; +import java.util.Stack; import polyglot.ast.Allocation_c; import polyglot.ast.AmbReceiver; @@ -243,6 +246,15 @@ import x10cpp.debug.LineNumberMap; import x10cpp.types.X10CPPContext_c; +/* Nobita's Addition */ +import x10.optimizations.atOptimzer.VarWithLineNo; +import x10.optimizations.atOptimzer.ClassInfo; +import x10.optimizations.atOptimzer.EdgeRep; +import x10.optimizations.atOptimzer.ObjNode; +import x10.optimizations.atOptimzer.ForClosureObjectcpp; + +/* Nobita's Addition */ + /** * Primary visitor for the C++ codegenerator. */ @@ -255,6 +267,48 @@ public class MessagePassingCodeGenerator extends X10DelegatingVisitor { protected ASTQuery query; protected Reporter reporter; + /* Nobita code */ + + //the required static fields + public static int lineNo = 0; + public static int zzCounter = 0; + //to store the last points-to graph + public static Stack>> lastGraphInfo = new Stack>>(); + + //the class details (fields and methods) + public static HashMap> classDetails = new HashMap>(); + + // to continue for next iteration + public static boolean nextIteration_cpp = false; + public static String firstClass = ""; + public static int iterationCount = -1; + + //stack data structure to help maintaining the class, methods and places + public static Stack currClass = new Stack(); + public static Stack currMethod = new Stack(); + public static Stack currPlace = new Stack(); + + //the graph data structure + public static HashMap>>>>> graphInfo = + new HashMap>>>>>(); + + //the set data structure + public static HashMap>>>>> setInfo = new + HashMap>>>>>(); + + //the object data structure + public static HashMap>>> objInfo = new + HashMap>>>(); + + //the condition + public static boolean theCond = false; + + //the code generator assistant + public static HashMap> theAssistant = new HashMap>(); + + + /* Nobita code */ + public MessagePassingCodeGenerator(StreamWrapper sw, Translator tr) { this.sw = sw; this.tr = tr; @@ -330,7 +384,75 @@ public void visit(LocalTypeDef_c n) { } public void visit(X10ClassDecl_c n) { + /* Nobita code */ + if(firstClass.equalsIgnoreCase("")) { + firstClass = n.name().toString(); + nextIteration_cpp = true; + } + else { + if(firstClass.equalsIgnoreCase(n.name().toString()) && currClass.size() == 0) { + lineNo = 0; zzCounter = 0;theAssistant = new HashMap>(); + + nextIteration_cpp = false; + iterationCount++; + + //System.out.println("Printing the iteration: " + iterationCount); + //System.out.println("-------------------------------end of one iteration-----------------------------"); + //System.out.println("-------------------------------end of one iteration-----------------------------"); + + } + } + + //System.out.println("Printing the class name: " + n.name().toString()); + + lineNo++; + + //updating the class stack with current class + VarWithLineNo temp = new VarWithLineNo(n.name().toString(), lineNo); + currClass.push(temp); + + //updating the class details + if (!classDetails.containsKey(n.name().toString())) { + classDetails.put(n.name().toString(), new LinkedList()); + } + + //the graph + if (!graphInfo.containsKey(lineNo)) { + graphInfo.put(lineNo, new HashMap>>>>()); + } + + //the object + if (!objInfo.containsKey(lineNo)) { + objInfo.put(lineNo, new HashMap>>()); + } + + //the set + if (!setInfo.containsKey(lineNo)) { + setInfo.put(lineNo, new HashMap>>>>()); + } + //>// + + /* Nobita code */ + processClass(n); + + /* Nobita code */ + //the printer + /* + if (iterationCount == 0) { + System.out.println("The class details: " + n.name().toString()); + LinkedList fi = classDetails.get(n.name().toString()); + + if (fi != null) { + for (ClassInfo ci:fi) { + System.out.println("The classifier:" + ci.classifier + " Name:" + ci.name + " Type:" + ci.type + " X10TYPE:" + ci.x10Type); + } + } + } + */ + + currClass.pop(); + /* Nobita code */ } /** @@ -1440,6 +1562,183 @@ public static String createMainStub(String container, X10CPPCompilerOptions opti public static final QName HEADER_ANNOTATION = QName.make("x10.compiler.Header"); public void visit(X10MethodDecl_c dec) { + /* Nobita code */ + + lineNo++; + //System.out.println("The name of the method: " + dec.name().toString() + ":" + lineNo); + if (currClass.size() > 0) { + + //the class details + VarWithLineNo temp = currClass.peek(); + + //the current method details + VarWithLineNo temp1 = new VarWithLineNo(dec.name().toString(), lineNo); + currMethod.push(temp1); + + //adding the method details to the class info + if (iterationCount == 0) { + ClassInfo fieldDetails = new ClassInfo("method", dec.returnType().toString(), dec.name().toString()); + fieldDetails.classNo = temp.lineNo; + fieldDetails.methodNo = lineNo; + LinkedList fi = classDetails.get(temp.name); + fi.add(fieldDetails); + } + + //adding the place details + VarWithLineNo temp2 = new VarWithLineNo(Integer.toString(lineNo), lineNo); + currPlace.push(temp2); + + //the sets initialization + HashMap>>>> setMethodInfo = setInfo.get(temp.lineNo); + + if (setMethodInfo != null && iterationCount < 4) { + setMethodInfo.put(lineNo, new HashMap>>>()); + + HashMap>>> placeInfo = setMethodInfo.get(lineNo); + + if(!placeInfo.containsKey(lineNo)) { + placeInfo.put(lineNo, new HashMap>>()); + } + + HashMap>> setDetails = placeInfo.get(lineNo); + + if (!setDetails.containsKey("RS")) { + setDetails.put("RS", new HashMap>()); + setDetails.put("CRS", new HashMap>()); + setDetails.put("WS", new HashMap>()); + setDetails.put("MWS", new HashMap>()); + setDetails.put("CWS", new HashMap>()); + setDetails.put("OS", new HashMap>()); + setDetails.put("OVS", new HashMap>()); + } + } + + //the objects + HashMap>> methodInfo2 = objInfo.get(temp.lineNo); + if (iterationCount < 4) { + + //the method part creation + methodInfo2.put(lineNo, new HashMap>()); + + //the place part creation + HashMap> placeInfo2 = methodInfo2.get(lineNo); + placeInfo2.put(lineNo, new HashMap()); + + //creating and inserting the this and null object + //creation + ObjNode nullObj = new ObjNode("Obj-null", "null"); + ObjNode thisObj = new ObjNode("obj-this", temp.name); + + //insertion + HashMap objDetails = placeInfo2.get(lineNo); + objDetails.put("Obj-null", nullObj); + objDetails.put("obj-this", thisObj); + + //the sets for the this object + HashMap>>>> setMethodInfo1 = setInfo.get(temp.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(lineNo); + if (placeInfoSet != null) { + HashMap>> setDetails = placeInfoSet.get(lineNo); + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if (!readSet.containsKey("obj-this")) { + readSet.put("obj-this", new HashSet()); + //update modifier boolean + } + HashMap> cumReadSet = setDetails.get("CRS"); + if (!cumReadSet.containsKey("obj-this")) { + cumReadSet.put("obj-this", new HashSet()); + //update modifier boolean + } + HashMap> writeSet = setDetails.get("WS"); + if (!writeSet.containsKey("obj-this")) { + writeSet.put("obj-this", new HashSet()); + //update modifier boolean + } + HashMap> mWriteSet = setDetails.get("MWS"); + if (!mWriteSet.containsKey("obj-this")) { + mWriteSet.put("obj-this", new HashSet()); + //update modifier boolean + } + HashMap> cumWriteSet = setDetails.get("CWS"); + if (!cumWriteSet.containsKey("obj-this")) { + cumWriteSet.put("obj-this", new HashSet()); + //update modifier boolean + } + + HashMap> objectVarSet = setDetails.get("OVS"); + if (!objectVarSet.containsKey("global-ovs")) { + objectVarSet.put("global-ovs", new HashSet()); + //update modifier boolean + } + //you should update the OVS for the analysis of weak updates:TODO: Done + } + } + } + + } + + //the graph + HashMap>>>> methodInfo1 = graphInfo.get(temp.lineNo); + if (methodInfo1 != null) { + + //creating the object for method + methodInfo1.put(lineNo, new HashMap>>>()); + + //creating the object for the place + HashMap>>> placeInfo = methodInfo1.get(lineNo); + placeInfo.put(lineNo, new HashMap>>()); + + //creating the object for the line + HashMap>> lineInfo = placeInfo.get(lineNo); + lineInfo.put(lineNo, new HashMap>()); + + //creating points to graph for the this object + HashMap> varInfo = lineInfo.get(lineNo); + varInfo.put("this", new LinkedList()); + + LinkedList edgeIncl = varInfo.get("this"); + EdgeRep edgeInfo = new EdgeRep("P","obj-this"); + edgeIncl.addLast(edgeInfo); + + //the field edges of the this object + LinkedList ll = classDetails.get(temp.name); + if (ll != null) { + Iterator it = ll.iterator(); + + while (it.hasNext()) { + ClassInfo fd = (ClassInfo)it.next(); + if (fd.classifier.equalsIgnoreCase("field")) { + if((fd != null) && !((fd.type.equalsIgnoreCase("Long")) || (fd.type.equalsIgnoreCase("Float")) || (fd.type.equalsIgnoreCase("String")) || (fd.type.equalsIgnoreCase("FileReader")) || (fd.type.equalsIgnoreCase("Printer")) || (fd.type.equalsIgnoreCase("Random")) || (fd.type.equalsIgnoreCase("FileWriter")) || + (fd.type.equalsIgnoreCase("Double")) || (fd.type.equalsIgnoreCase("Char")) || (fd.type.equalsIgnoreCase("PlaceGroup")) || (fd.type.equalsIgnoreCase("File")) || (fd.type.equalsIgnoreCase("FailedDynamicCheckException")) || (fd.type.equalsIgnoreCase("FinishState")) || (fd.type.equalsIgnoreCase("LongRange")) || + (fd.type.equalsIgnoreCase("Boolean")) || (fd.type.equalsIgnoreCase("Rail")) || (fd.type.equalsIgnoreCase("Place")) || (fd.type.equalsIgnoreCase("Dist")) || (fd.type.equalsIgnoreCase("ArrayList")) || (fd.type.equalsIgnoreCase("Iterator")) || (fd.type.equalsIgnoreCase("Point")) || (fd.type.equalsIgnoreCase("Int")) || + (fd.type.equalsIgnoreCase("Array")) || (fd.type.equalsIgnoreCase("DistArray")) || (fd.type.equalsIgnoreCase("Region")) || (fd.type.equalsIgnoreCase("GlobalRef")))) { + + if(!(varInfo.containsKey("obj-this"))) { + varInfo.put("obj-this", new LinkedList()); + //update modifier boolean + } + + LinkedList edgeInclField = varInfo.get("obj-this"); + if (edgeInclField != null) { + EdgeRep edgeInfo1 = new EdgeRep("F","Obj-null",fd.name); + edgeInclField.addLast(edgeInfo1); + } + } + } + } + } + } + + //inserting into the last graph + HashMap>>> placeInfo = methodInfo1.get(lineNo); + HashMap>> lineInfo = placeInfo.get(lineNo); + HashMap> varInfo = lineInfo.get(lineNo); + lastGraphInfo.push(deepCopy(varInfo)); + } + /* Nobita code */ + X10CPPContext_c context = (X10CPPContext_c) tr.context(); TypeSystem xts = tr.typeSystem(); Flags flags = dec.flags().flags(); @@ -1571,6 +1870,56 @@ public void visit(X10MethodDecl_c dec) { context.genericFunctions.writeln("#endif // "+guard+"_"+Emitter.mangled_method_name(mi.name().toString())+"_"+mid); } context.closures = saved_closure_stream; + + + + /* Nobita code */ + //the pirnter + /* + if ((currClass.size() > 0) && (currMethod.size() > 0)) { + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo = setMethodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> setDetails = placeInfo.get(temp3.lineNo); + if (setDetails != null) { + + System.out.println("THE READ SET"); + HashMap> rs = setDetails.get("RS"); + if (rs != null) { + HashSet rsSet = rs.get("obj-this"); + if (rsSet != null) { + for (String str:rsSet) { + System.out.println(str); + } + } + } + + System.out.println("THE CUMULATIVE READ SET"); + HashMap> crs = setDetails.get("CRS"); + if (rs != null) { + HashSet crsSet = crs.get("obj-this"); + if(crsSet != null) { + for (String str:crsSet) { + System.out.println(str); + } + } + } + + System.out.println("---------------------------EN DOF ONE FUNCTION CALL-------------------------------------------------"); + } + } + } + } + */ + + + currMethod.pop(); + currPlace.pop(); + /* Nobita code */ } @@ -2114,6 +2463,377 @@ public void visit(Labeled_c label) { public void visit(Assign_c asgn) { + + /* Nobita code */ +if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4 && (asgn.right() instanceof X10Cast_c || asgn.right() instanceof X10Call_c)) { + + Expr expr = asgn.right(); + if (asgn.right() instanceof X10Cast_c) { + X10Cast_c ca = (X10Cast_c)asgn.right(); + expr = ca.expr(); + } + + if (expr instanceof X10Call_c) { + X10Call_c call = (X10Call_c)expr; + + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + + //getting the graph + HashMap> varInfo = lastGraphInfo.peek(); + + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(lineNo + 1); + } + } + + if(varInfo != null && setDetails != null && call.name().toString().equals("evalAt")) { + Iterator it = varInfo.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it.next(); + LinkedList edgeIncl = ((LinkedList)phase3.getValue()); + + if (edgeIncl != null && edgeIncl.size() == 1) { + String objName = edgeIncl.getFirst().desName; + LinkedList ll = classDetails.get(temp1.name); + + if (objName.equalsIgnoreCase("obj-this")) { + theAssistant.put("saved_this", new LinkedList()); + LinkedList llcl = theAssistant.get("saved_this"); + + HashMap> rs = setDetails.get("RS"); + HashMap> crs = setDetails.get("CRS"); + HashSet crsSet = crs.get(objName); + HashSet rsSet = rs.get(objName); + rsSet.addAll(crsSet); + if (rsSet != null) { + for (String str:rsSet) { + + if (ll != null) { + for(ClassInfo ci:ll) { + if(ci.classifier.equalsIgnoreCase("field") && ci.name.equalsIgnoreCase(str)) { + + sw.write(ci.x10Type); sw.write(" zztemp"+zzCounter+ " = "); + if (currPlace.size() > 1) { + sw.write("saved_this->FMGL("+str+");"); + } else { + sw.write("this->FMGL("+str+");"); + } + sw.newline(); + ForClosureObjectcpp cl1 = new ForClosureObjectcpp(); + cl1.fldName = str;cl1.zzName = "zztemp"+zzCounter;cl1.type=ci.x10Type; + llcl.addLast(cl1); + zzCounter++; + break; + } + } + } + + } + } + } + else { + //TODO + } + } + } + + } + } + } + + if ((currClass.size() > 0) && (currMethod.size() > 0) && asgn.leftType().toType().name().toString() != null) { + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + + String varType = asgn.leftType().toType().name().toString(); + + if(!((varType.equalsIgnoreCase("Long")) || (varType.equalsIgnoreCase("Float")) || (varType.equalsIgnoreCase("String")) || (varType.equalsIgnoreCase("FileReader")) || (varType.equalsIgnoreCase("Printer")) || (varType.equalsIgnoreCase("Random")) || (varType.equalsIgnoreCase("FileWriter")) || + (varType.equalsIgnoreCase("Double")) || (varType.equalsIgnoreCase("Char")) || (varType.equalsIgnoreCase("PlaceGroup")) || (varType.equalsIgnoreCase("File")) || (varType.equalsIgnoreCase("FailedDynamicCheckException")) || (varType.equalsIgnoreCase("FinishState")) || (varType.equalsIgnoreCase("LongRange")) || + (varType.equalsIgnoreCase("Boolean")) || (varType.equalsIgnoreCase("Rail")) || (varType.equalsIgnoreCase("Place")) || (varType.equalsIgnoreCase("Dist")) || (varType.equalsIgnoreCase("ArrayList")) || (varType.equalsIgnoreCase("Iterator")) || (varType.equalsIgnoreCase("Point")) || (varType.equalsIgnoreCase("Int")) || + (varType.equalsIgnoreCase("Array")) || (varType.equalsIgnoreCase("DistArray")) || (varType.equalsIgnoreCase("Region")) || (varType.equalsIgnoreCase("GlobalRef")))) { + if(asgn.right() instanceof Field_c || asgn.left() instanceof Field_c) { + if (asgn.right() instanceof Field_c && asgn.left() instanceof Field_c) { + //will do it later:TODO + } + else if (asgn.right() instanceof Field_c) { + //TODO + } + else if (asgn.left() instanceof Field_c) { + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + + HashMap> varInfo = lineInfo.get(lineNo); + + //the RHS is not field type; + String rhsName = ""; boolean isNull = false; + if (asgn.right() instanceof Local_c) { + Local_c tl = (Local_c)asgn.right(); + rhsName = tl.name().toString(); + } + else if (asgn.right() instanceof X10Special_c) { + rhsName = "this"; + } + + if(asgn.right() instanceof NullLit_c) { + isNull = true; + } + + LinkedList fielder = new LinkedList(); + Field_c tf = (Field_c)asgn.left(); + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + break; + } + } + + String varName = fielder.removeFirst(); + + LinkedList dest = varInfo.get(varName); + LinkedList src = varInfo.get(rhsName); + + //to collect the OVS Set + Stack ovs = new Stack(); + if (dest != null) { + if(dest.size() > 1) { + ovs.add(rhsName); + } + + if (fielder.size() > 0) { + String fldName = fielder.removeFirst(); + + HashMap>> setDetails = null; + for (EdgeRep er:dest) { + //copying the RHS List + LinkedList fielderAsst = new LinkedList(); + for (String str:fielder) { + fielderAsst.addLast(str); + } + + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(lineNo); + } + } + + //calling the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, src, ovs, varInfo, setDetails); + + } + } + } + } + } + } + } + } + } + else { + if(asgn.right() instanceof Field_c || asgn.left() instanceof Field_c) { + if (asgn.right() instanceof Field_c && asgn.left() instanceof Field_c) { + //will do it later:TODO + } + else if (asgn.right() instanceof Field_c) { + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + + HashMap> varInfo = lineInfo.get(lineNo); + + LinkedList fielder = new LinkedList(); + Field_c tf = (Field_c)asgn.right(); + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + break; + } + } + + String varName = fielder.removeFirst(); + + LinkedList dest = varInfo.get(varName); + + if (fielder.size() > 0) { + String fldName = fielder.removeFirst(); + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(temp3.lineNo); + } + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + for (EdgeRep er:dest) { + HashSet rs = readSet.get(er.desName); + if (rs != null) { + rs.add(fldName); + } + //calling the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, src, ovs, varInfo, setDetails); + + } + } + } + + //the back up after the changes in points to graph. NOTE:##! check to stop whether it can be done once alone + /*varInfo = lineInfo.get(lineNo); + if (varInfo != null) { + lastGraphInfo.push(deepCopy(varInfo)); + }*/ + } + } + } + } + else if (asgn.left() instanceof Field_c) { + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + + HashMap> varInfo = lineInfo.get(lineNo); + + LinkedList fielder = new LinkedList(); + Field_c tf = (Field_c)asgn.left(); + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + //System.out.println("The first value2:" + tf.target().toString()); + break; + } + } + + if (fielder.size() > 1) { + String varName = fielder.removeFirst(); //System.out.println("The first value1:" + varName); + + LinkedList dest = varInfo.get(varName); + + String fldName = fielder.removeFirst(); //System.out.println("The first value2:" + fldName); + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(temp3.lineNo); + } + } + + if (setDetails != null && dest != null) { + HashMap> readSet = setDetails.get("RS"); + for (EdgeRep er:dest) { + HashSet rs = readSet.get(er.desName); + if (rs != null) { + rs.add(fldName); + } + //calling the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, src, ovs, varInfo, setDetails); + + } + } + + //the back up after the changes in points to graph. NOTE:##! check to stop whether it can be done once alone + /*varInfo = lineInfo.get(lineNo); + if (varInfo != null) { + lastGraphInfo.push(deepCopy(varInfo)); + }*/ + } + } + } + } + } + } + } + } + /* Nobita code */ + X10CPPContext_c context = (X10CPPContext_c) tr.context(); boolean unsigned_op = false; String opString = asgn.operator().toString(); @@ -2216,6 +2936,468 @@ public void visit(Formal_c n) { public void visit(LocalDecl_c dec) { + + /* Nobita code */ + lineNo++; + + if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4 && (dec.init() instanceof X10Cast_c || dec.init() instanceof X10Call_c)) { + + Expr expr = dec.init(); + if (dec.init() instanceof X10Cast_c) { + X10Cast_c ca = (X10Cast_c)dec.init(); + expr = ca.expr(); + } + + if (expr instanceof X10Call_c) { + X10Call_c call = (X10Call_c)expr; + + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + + //getting the graph + HashMap> varInfo = lastGraphInfo.peek(); + + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(lineNo + 1); + } + } + + if(varInfo != null && setDetails != null && call.name().toString().equals("evalAt")) { + Iterator it = varInfo.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it.next(); + LinkedList edgeIncl = ((LinkedList)phase3.getValue()); + + if (edgeIncl != null && edgeIncl.size() == 1) { + String objName = edgeIncl.getFirst().desName; + LinkedList ll = classDetails.get(temp1.name); + + if (objName.equalsIgnoreCase("obj-this")) { + theAssistant.put("saved_this", new LinkedList()); + LinkedList llcl = theAssistant.get("saved_this"); + + HashMap> rs = setDetails.get("RS"); + HashMap> crs = setDetails.get("CRS"); + HashSet crsSet = crs.get(objName); + HashSet rsSet = rs.get(objName); + rsSet.addAll(crsSet); + if (rsSet != null) { + for (String str:rsSet) { + + if (ll != null) { + for(ClassInfo ci:ll) { + if(ci.classifier.equalsIgnoreCase("field") && ci.name.equalsIgnoreCase(str)) { + + sw.write(ci.x10Type); sw.write(" zztemp"+zzCounter+ " = "); + if (currPlace.size() > 1) { + sw.write("saved_this->FMGL("+str+");"); + } else { + sw.write("this->FMGL("+str+");"); + } + sw.newline(); + ForClosureObjectcpp cl1 = new ForClosureObjectcpp(); + cl1.fldName = str;cl1.zzName = "zztemp"+zzCounter;cl1.type=ci.x10Type; + llcl.addLast(cl1); + zzCounter++; + break; + } + } + } + + } + } + } + else { + //TODO + } + } + } + + } + } + } + + //System.out.println("The name of local decl:" + dec.name().toString()); + //if (dec.init() instanceof Field_c) {Field_c tf = (Field_c)dec.init(); System.out.println("the name:---" + tf.target().toString()); } + + if ((currClass.size() > 0) && (currMethod.size() > 0) && (dec.type().nameString()) != null && dec.init() != null) { + + //getting the threes + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + + String varType = dec.type().nameString(); + if((varType != null) && !((varType.equalsIgnoreCase("Long")) || (varType.equalsIgnoreCase("Float")) || (varType.equalsIgnoreCase("String")) || (varType.equalsIgnoreCase("FileReader")) || (varType.equalsIgnoreCase("Printer")) || (varType.equalsIgnoreCase("Random")) || (varType.equalsIgnoreCase("FileWriter")) || + (varType.equalsIgnoreCase("Double")) || (varType.equalsIgnoreCase("Char")) || (varType.equalsIgnoreCase("PlaceGroup")) || (varType.equalsIgnoreCase("File")) || (varType.equalsIgnoreCase("FailedDynamicCheckException")) || (varType.equalsIgnoreCase("FinishState")) || (varType.equalsIgnoreCase("LongRange")) || + (varType.equalsIgnoreCase("Boolean")) || (varType.equalsIgnoreCase("Rail")) || (varType.equalsIgnoreCase("Place")) || (varType.equalsIgnoreCase("Dist")) || (varType.equalsIgnoreCase("ArrayList")) || (varType.equalsIgnoreCase("Iterator")) || (varType.equalsIgnoreCase("Point")) || (varType.equalsIgnoreCase("Int")) || + (varType.equalsIgnoreCase("Array")) || (varType.equalsIgnoreCase("DistArray")) || (varType.equalsIgnoreCase("Region")) || (varType.equalsIgnoreCase("GlobalRef")))) { + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + + HashMap> varInfo = lineInfo.get(lineNo); + if(!(varInfo.containsKey(dec.name().toString()))) { + varInfo.put(dec.name().toString(), new LinkedList()); + } + + if (dec.init() instanceof New_c) { + String objName = "obj"+lineNo; + + //the object creation + HashMap>> methodInfo2 = objInfo.get(temp1.lineNo); + if (methodInfo2 != null) { + HashMap> placeInfo2 = methodInfo2.get(temp2.lineNo); + if (placeInfo2 != null) { + HashMap objDetail2 = placeInfo2.get(temp3.lineNo); + if (objDetail2 != null) { + if (!objDetail2.containsKey(objName)) { + ObjNode temp = new ObjNode(objName, varType); + objDetail2.put(objName, temp); + //update modifier boolean + } + } + } + } + + //the graph updates + LinkedList edgeIncl = varInfo.get(dec.name().toString()); + if (edgeIncl != null) { + Iterator it = edgeIncl.iterator(); + boolean found = false; + while (it.hasNext()) { + EdgeRep er1 = (EdgeRep)it.next(); + + if(er1.desName.equalsIgnoreCase(objName)) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgeInfo = new EdgeRep("P",objName); + edgeIncl.addLast(edgeInfo); + //update modifier boolean + } + } + + //the sets updates + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo2 = setMethodInfo.get(temp2.lineNo); + if (placeInfo2 != null) { + HashMap>> setDetails = placeInfo2.get(temp3.lineNo); + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if (readSet != null && !readSet.containsKey(objName)) { + readSet.put(objName, new HashSet()); + //update modifier boolean + } + HashMap> cumReadSet = setDetails.get("CRS"); + if (cumReadSet != null && !cumReadSet.containsKey(objName)) { + cumReadSet.put(objName, new HashSet()); + //update modifier boolean + } + HashMap> writeSet = setDetails.get("WS"); + if (writeSet != null && !writeSet.containsKey(objName)) { + writeSet.put(objName, new HashSet()); + //update modifier boolean + } + HashMap> mWriteSet = setDetails.get("MWS"); + if (mWriteSet != null && !mWriteSet.containsKey(objName)) { + mWriteSet.put(objName, new HashSet()); + //update modifier boolean + } + HashMap> cumWriteSet = setDetails.get("CWS"); + if (cumWriteSet != null && !cumWriteSet.containsKey(objName)) { + cumWriteSet.put(objName, new HashSet()); + //update modifier boolean + } + HashMap> objectSet = setDetails.get("OS"); + if (objectSet != null && !objectSet.containsKey(objName)) { + objectSet.put(objName, new HashSet()); + //update modifier boolean + } + } + } + } + + //inter-needs to be added + } + else if (dec.init() instanceof Field_c ) { + LinkedList fielder = new LinkedList(); + + Field_c tf = (Field_c)dec.init(); + + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + break; + } + } + + String varName = fielder.removeFirst(); + + LinkedList dest = varInfo.get(dec.name().toString()); + LinkedList src = varInfo.get(varName); + + //to collect the OVS Set + Stack ovs = new Stack(); + + if (src != null && dest != null && fielder.size() > 0) { + + if(src.size() > 1) { + ovs.add(varName); + } + + if (fielder.size() > 0) { + String fldName = fielder.removeFirst(); + + HashMap>> setDetails = null; + for (EdgeRep er:src) { + //copying the RHS List + LinkedList fielderAsst = new LinkedList(); + for (String str:fielder) { + fielderAsst.addLast(str); + } + + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(temp3.lineNo); + } + } + + //calling the function + assistlocalfldDec(er.desName, fldName, fielderAsst, dest, ovs, varInfo, setDetails); + + } + } + + //add the OVS from the stack + /* HashMap> ovSet = setDetails.get("OVS"); + if (ovSet != null) { + HashSet ovs1 = ovSet.get("global-ovs"); + for (String str:ovs) { + ovs1.add(str); + } + } */ + + } + + + } + else if (dec.init() instanceof NullLit_c) { + if(!(varInfo.containsKey(dec.name().toString()))) { + varInfo.put(dec.name().toString(), new LinkedList()); + //update modifier boolean + } + + LinkedList edgeIncl = varInfo.get(dec.name().toString()); + + if (edgeIncl != null) { + Iterator it = edgeIncl.iterator(); + boolean found = false; + while (it.hasNext()) { + EdgeRep er = (EdgeRep)it.next(); + + if (er.desName.equalsIgnoreCase("Obj-null")) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgeInfo = new EdgeRep("P","Obj-null"); + edgeIncl.addLast(edgeInfo); + //update modifier boolean + } + } + } + else if (dec.init() instanceof Local_c) { + Local_c tempLocal = (Local_c)dec.init(); + String rhsVar = tempLocal.name().toString(); + LinkedList src = varInfo.get(rhsVar); + LinkedList dest = varInfo.get(dec.name().toString()); + + if (src != null && dest != null) { + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo2 = setMethodInfo.get(temp2.lineNo); + if (placeInfo2 != null) { + HashMap>> setDetails = placeInfo2.get(temp3.lineNo); + if (setDetails != null) { + HashMap> ovSet = setDetails.get("OVS"); + if (ovSet != null) { + HashSet set1 = ovSet.get("global-ovs"); + if (set1 != null) { + set1.add(rhsVar); + set1.add(dec.name().toString()); + } + } + } + } + } + + Iterator it = src.iterator(); + while (it.hasNext()) + { + EdgeRep er = (EdgeRep)it.next(); + + Iterator it1 = dest.iterator(); + boolean found = false; + while (it1.hasNext()) { + EdgeRep er1 = (EdgeRep)it1.next(); + if (er1.desName.equalsIgnoreCase(er.desName)) { + found = true; + break; + } + } + + if (!found) { + EdgeRep edgIncl = new EdgeRep("P",er.desName); + dest.addLast(edgIncl); + //update modifier boolean + } + } + } + } + + //the back up after the changes in points to graph. NOTE:##! check to stop whether it can be done once alone + /*varInfo = lineInfo.get(lineNo); + if (varInfo != null) { + lastGraphInfo.push(deepCopy(varInfo)); + }*/ + } + } + } + + } else { + //the remaining part + if(dec.init() instanceof Field_c) { + LinkedList fielder = new LinkedList(); + + Field_c tf = (Field_c)dec.init(); + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + break; + } + } + + String varName = fielder.removeFirst(); + + + //the graph + //System.out.println("The value of temp3:" + temp3.lineNo); + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + HashMap> varInfo = lineInfo.get(lineNo); + + //the sets + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(temp3.lineNo); + } + } + + LinkedList src = varInfo.get(varName); + + //to collect the OVS Set + Stack ovs = new Stack(); + + if (src != null) { + if(src.size() > 1) { + ovs.add(varName); + } + + if (fielder.size() > 0) { + String fldName = fielder.removeFirst(); + + for (EdgeRep er:src) { + //copying the RHS List + LinkedList fielderAsst = new LinkedList(); + for (String str:fielder) { + fielderAsst.addLast(str); + } + + //calling the function + assistlocalfldDec_1(er.desName, fldName, fielderAsst, ovs, varInfo, setDetails); + + } + } + } + } + } + } + } + } + + + } + + + /* Nobita code */ + X10CPPContext_c context = (X10CPPContext_c) tr.context(); TypeSystem xts = (TypeSystem)context.typeSystem(); @@ -2418,7 +3600,9 @@ public void visit(For_c n) { sw.allowBreak(0); if (n.cond() != null) { + theCond = true; n.printBlock(n.cond(), sw, tr); + theCond = false; } sw.write(";"); @@ -2505,7 +3689,9 @@ public void visit(Do_c n) { sw.allowBreak(0, " "); sw.write("while ("); sw.begin(0); + theCond = true; n.printBlock(n.cond(), sw, tr); + theCond = false; sw.end(); sw.write(");"); @@ -2527,7 +3713,9 @@ public void visit(While_c n) { sw.write("while ("); sw.begin(0); + theCond = true; n.printBlock(n.cond(), sw, tr); + theCond = false; sw.end(); sw.write(")"); sw.allowBreak(0, " "); @@ -2562,7 +3750,9 @@ public void visit(While_c n) { public void visit(If_c n) { sw.write("if ("); + theCond = true; n.printBlock(n.cond(), sw, tr); + theCond = false; sw.write(")"); sw.allowBreak(0, " "); n.print(n.consequent(), sw, tr); @@ -2609,6 +3799,193 @@ private static boolean needsNullCheck(Receiver e) { } public void visit(X10Call_c n) { + + /* Nobita code */ + //System.out.println("Start of call"); + lineNo++; + String funName = n.name().toString(); + + + //code generation phase + if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4 && (funName.equalsIgnoreCase("runAt") || funName.equalsIgnoreCase("runAsync"))) { + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + + //getting the graph + HashMap> varInfo = lastGraphInfo.peek(); + + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(lineNo); + } + } + + if(varInfo != null && setDetails != null) { + Iterator it = varInfo.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it.next(); + LinkedList edgeIncl = ((LinkedList)phase3.getValue()); + + if (edgeIncl != null && edgeIncl.size() == 1 && !currMethod.peek().name.equalsIgnoreCase("main")) { + String objName = edgeIncl.getFirst().desName; + LinkedList ll = classDetails.get(temp1.name); + + if (objName.equalsIgnoreCase("obj-this")) { + + theAssistant.put("saved_this", new LinkedList()); + LinkedList llcl = theAssistant.get("saved_this"); + + HashMap> rs = setDetails.get("RS"); + HashMap> crs = setDetails.get("CRS"); + HashSet crsSet = crs.get(objName); + HashSet rsSet = rs.get(objName); + rsSet.addAll(crsSet); + if (rsSet != null) { + for (String str:rsSet) { + + if (ll != null) { + for(ClassInfo ci:ll) { + if(ci.classifier.equalsIgnoreCase("field") && ci.name.equalsIgnoreCase(str)) { + + sw.write(ci.x10Type); sw.write(" zztemp"+zzCounter+ " = "); + if (currPlace.size() > 1) { + sw.write("saved_this->FMGL("+str+");"); + } else { + sw.write("this->FMGL("+str+");"); + } + sw.newline(); + ForClosureObjectcpp cl1 = new ForClosureObjectcpp(); + cl1.fldName = str;cl1.zzName = "zztemp"+zzCounter;cl1.type=ci.x10Type; + llcl.addLast(cl1); + zzCounter++; + break; + } + } + } + + } + } + } + else { + //TODO + } + } + } + + } + } + + + int parentPlace = 0; + if(funName.equalsIgnoreCase("runAt") || funName.equalsIgnoreCase("evalAt") || funName.equalsIgnoreCase("runAsync")) { + //the previous place number + parentPlace = currPlace.peek().lineNo; + VarWithLineNo temp4 = new VarWithLineNo(Integer.toString(lineNo), lineNo); + currPlace.push(temp4); + + if ((currClass.size() > 0) && (currMethod.size() > 0)) { + + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + + //the sets + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo = setMethodInfo.get(temp2.lineNo); + if (placeInfo != null) { + //copying the object alone from the parent place + HashMap>> setDetails1 = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails1 = placeInfoSet.get(parentPlace); + } + } + + if (setDetails1 != null) { + if(!placeInfo.containsKey(lineNo)) { + placeInfo.put(lineNo, deepCopySet(setDetails1)); + } + } + } + } + + //the graphs + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + placeInfo.put(temp3.lineNo, new HashMap>>()); + + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + + lineInfo.put(lineNo, lastGraphInfo.peek()); + } + } + + //the objects + //not required: TODO + } + } + + + //for the other functions + String op = "operator"; + boolean pass = true; + for (int i=0;i<8; i++) { + if(op.charAt(i) != funName.charAt(i)) { + pass = false; + break; + } + } + if((currClass.size() > 0) && (currMethod.size() > 0) && !(funName.equalsIgnoreCase("runAt") || funName.equalsIgnoreCase("evalAt") || funName.equalsIgnoreCase("runAsync") || pass || + funName.equalsIgnoreCase("equals") || funName.equalsIgnoreCase("Places"))) { + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + + //to get method number of the copying + //System.out.println("The Name Mr Arun"+temp1.name); + LinkedList ll = classDetails.get(temp1.name); + int methodNum = 0; + if (ll != null) { + for(ClassInfo ci:ll) { + if(ci.classifier.equalsIgnoreCase("method") && ci.name.equalsIgnoreCase(funName)) { + methodNum = ci.methodNo; + break; + } + } + } + + HashMap> desRS = null; + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo = setMethodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> setDetails1 = placeInfo.get(temp3.lineNo); + if(setDetails1 != null) { + desRS = setDetails1.get("RS"); + } + } + + HashMap>>> placeInfo1 = setMethodInfo.get(methodNum); + if (placeInfo1 != null) { + setDetails = placeInfo1.get(methodNum); + } + } + + if (desRS != null && setDetails != null) { + mergeForPlaces(setDetails,desRS); + } + } + /* Nobita code */ + X10CPPContext_c context = (X10CPPContext_c) tr.context(); TypeSystem xts = tr.typeSystem(); @@ -2807,6 +4184,35 @@ public void visit(X10Call_c n) { if (needsCast) { sw.write(")"); } + + + /* Nobita code */ + if(funName.equalsIgnoreCase("runAt") || funName.equalsIgnoreCase("evalAt") || funName.equalsIgnoreCase("runAsync")) { + if ((currClass.size() > 0) && (currMethod.size() > 0)) { + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + + //the sets + HashMap>>>> setMethodInfo = setInfo.get(temp1.lineNo); + if (setMethodInfo != null) { + HashMap>>> placeInfo = setMethodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> setDetails1 = placeInfo.get(temp3.lineNo); + HashMap>> setDetails2 = placeInfo.get(parentPlace); + + if (setDetails1 != null && setDetails2 != null) { + //call the function + HashMap> desCRS = setDetails2.get("CRS"); + mergeForPlaces(setDetails1,desCRS); + } + } + } + } + currPlace.pop(); + } + /* Nobita code */ + //System.out.println("End of call"); } private void invokeInterface(Node_c n, Expr target, List args, String dispType, Type contType, @@ -2854,6 +4260,101 @@ private void printCallActuals(Node_c n, X10CPPContext_c context, TypeSystem xts, public void visit(Field_c n) { + /* Nobita code */ + if(true) { + if ((currClass.size() > 0) && (currMethod.size() > 0)) { + //getting the threes + VarWithLineNo temp1 = currClass.peek(); + VarWithLineNo temp2 = currMethod.peek(); + VarWithLineNo temp3 = currPlace.peek(); + String varType = n.type().name().toString(); + if((varType != null) && !((varType.equalsIgnoreCase("Long")) || (varType.equalsIgnoreCase("Float")) || (varType.equalsIgnoreCase("String")) || (varType.equalsIgnoreCase("FileReader")) || (varType.equalsIgnoreCase("Printer")) || (varType.equalsIgnoreCase("Random")) || (varType.equalsIgnoreCase("FileWriter")) || + (varType.equalsIgnoreCase("Double")) || (varType.equalsIgnoreCase("Char")) || (varType.equalsIgnoreCase("PlaceGroup")) || (varType.equalsIgnoreCase("File")) || (varType.equalsIgnoreCase("FailedDynamicCheckException")) || (varType.equalsIgnoreCase("FinishState")) || (varType.equalsIgnoreCase("LongRange")) || + (varType.equalsIgnoreCase("Boolean")) || (varType.equalsIgnoreCase("Rail")) || (varType.equalsIgnoreCase("Place")) || (varType.equalsIgnoreCase("Dist")) || (varType.equalsIgnoreCase("ArrayList")) || (varType.equalsIgnoreCase("Iterator")) || (varType.equalsIgnoreCase("Point")) || (varType.equalsIgnoreCase("Int")) || + (varType.equalsIgnoreCase("Array")) || (varType.equalsIgnoreCase("DistArray")) || (varType.equalsIgnoreCase("Region")) || (varType.equalsIgnoreCase("GlobalRef")))) { + //TODO + } + else { + HashMap>>>> methodInfo = graphInfo.get(temp1.lineNo); + if (methodInfo != null) { + HashMap>>> placeInfo = methodInfo.get(temp2.lineNo); + if (placeInfo != null) { + HashMap>> lineInfo = placeInfo.get(temp3.lineNo); + if (lineInfo != null) { + if (lastGraphInfo.size() > 0) { + lineInfo.put(lineNo, lastGraphInfo.peek()); //check for whether back needs to take for second pass also + //update modifier boolean + } + else { + lineInfo.put(lineNo, new HashMap>()); + //update modifier boolean + } + + HashMap> varInfo = lineInfo.get(lineNo); + + LinkedList fielder = new LinkedList(); + + Field_c tf = (Field_c)n; + + fielder.addFirst(tf.fieldInstance().name().toString()); + + while (true) { + + if (tf.target() instanceof Field_c) { + tf = (Field_c)tf.target(); + fielder.addFirst(tf.fieldInstance().name().toString()); + } + else if (tf.target() instanceof Local_c) { + Local_c tl = (Local_c)tf.target(); + fielder.addFirst(tl.name().toString()); + break; + } + else if (tf.target() instanceof X10Special_c) { + fielder.addFirst("this"); + break; + } + else { + break; + } + } + + if (fielder.size() > 1) { + String varName = fielder.removeFirst(); + + LinkedList dest = varInfo.get(varName); + String fldName = fielder.removeFirst(); + + HashMap>> setDetails = null; + HashMap>>>> setMethodInfo1 = setInfo.get(temp1.lineNo); + if (setMethodInfo1 != null) { + HashMap>>> placeInfoSet = setMethodInfo1.get(temp2.lineNo); + if (placeInfoSet != null) { + setDetails = placeInfoSet.get(temp3.lineNo); + } + } + + if (setDetails != null && dest != null) { + HashMap> readSet = setDetails.get("RS"); + for (EdgeRep er:dest) { + HashSet rs = readSet.get(er.desName); + if (rs != null) { + rs.add(fldName); + } + //calling the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, src, ovs, varInfo, setDetails); + + } + } + + } + + } + } + } + } + } + } + /* Nobita code */ X10CPPContext_c context = (X10CPPContext_c) tr.context(); Receiver target = n.target(); Type t = target.type(); @@ -3422,6 +4923,8 @@ private void extractParameterTypes(Type t) { } public void visit(Closure_c n) { + + //System.out.println("Printing the closure name: "); X10CPPContext_c c = (X10CPPContext_c) tr.context(); emitter.enterClosure(c); @@ -3678,6 +5181,127 @@ public void visit(Closure_c n) { } sw.end(); sw.write(" { }"); sw.newline(); sw.forceNewline(); + + + + //nobite dec: stack of strings: also its start + Stack theRemains = new Stack(); + boolean passed = true; + + sw.write(cname+"("); + for (int i = 0; i < env.size(); i++) { + //nobita code IF True condition + if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4) { + if (i > 0) sw.write(", "); + VarInstance var = (VarInstance) env.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + if(theAssistant.containsKey(name)) { + LinkedList llcc = theAssistant.get(name); + if(llcc.size() > 0) { + passed = false; + int ii=0; + for(ForClosureObjectcpp cl:llcc) { + if (ii > 0) sw.write(", "); + sw.write(cl.type+ " "+cl.zzName); + ii++; + } + + } + else { + theRemains.push(name); + if (refs.contains(var)) { + sw.write(make_captured_lval(var.type()) + " " + name); + } else { + sw.write(Emitter.translateType(var.type(), true) + " " + name); + } + } + } + else { + theRemains.push(name); + if (refs.contains(var)) { + sw.write(make_captured_lval(var.type()) + " " + name); + } else { + sw.write(Emitter.translateType(var.type(), true) + " " + name); + } + } + } + else { + if (i > 0) sw.write(", "); + VarInstance var = (VarInstance) env.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + if (refs.contains(var)) { + sw.write(make_captured_lval(var.type()) + " " + name); + } else { + sw.write(Emitter.translateType(var.type(), true) + " " + name); + } + } + } + if(passed) { + if (env.size() > 0) { + sw.write(",x10_long zzztemp"); + } + else { + sw.write("x10_long zzztemp"); + } + } + sw.write(")"); + sw.begin(0); + // FIXME: factor out this loop + //boolean h1 = false; + if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4) { + sw.newline(); + sw.write("{ "); + sw.newline(); + + for (String str:theRemains) { + sw.write("this->"+str+" = "+str+";"); + sw.newline(); + } + + if(!passed) { + Iterator it = theAssistant.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it.next(); + String str = (String)phase3.getKey(); + LinkedList llcc = ((LinkedList)phase3.getValue()); + if (llcc.size() > 0) { + sw.write("this->"+str+" = "+"::"+currClass.peek().name+"::_make();"); + sw.newline(); + for(ForClosureObjectcpp cl:llcc) { + sw.write("this->"+str+"->FMGL("+cl.fldName+") = "+cl.zzName+";"); + sw.newline(); + } + } + } + } + + sw.write(" }"); + } + else { + for (int i = 0 ; i < env.size() ; i++) { + VarInstance var = (VarInstance) env.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) + name = SAVED_THIS; + else name = mangled_non_method_name(name); + //if (name.equalsIgnoreCase("h1")) {h1 = true;} + //if (!h1) { + if (i > 0) sw.write(", "); else sw.write(" : "); + sw.write(name + "(" + name + ")"); + //} + } + sw.end(); + sw.write(" { }"); + } + + //may be the end of the nobita code + sw.newline(); sw.forceNewline(); sw.write("static const ::x10aux::serialization_id_t "+SERIALIZATION_ID_FIELD+";"); sw.newline(); sw.forceNewline(); @@ -3752,25 +5376,80 @@ public void visit(Closure_c n) { } sw.write(cname+templateArgs+"("); for (int i = 0; i < env.size(); i++) { - if (i > 0) sw.write(", "); - VarInstance var = (VarInstance) env.get(i); - String name = var.name().toString(); - if (name.equals(THIS)) { - // FIXME: Hack upon hack... - if (((X10CPPContext_c)c.pop()).isInsideClosure()) { - name = SAVED_THIS; - } else if (xts.isStruct(var.type())) { - name = STRUCT_THIS; + //Nobitas modified code only true condition + if ((currClass.size() > 0) && (currMethod.size() > 0) && iterationCount>=4) { + if (i > 0) sw.write(", "); + VarInstance var = (VarInstance) env.get(i); + String name = var.name().toString(); + String theName = ""; + if(name.equalsIgnoreCase("this")) { + theName = "saved_this"; } - } else { - name = mangled_non_method_name(name); - } - if (refs.contains(var)) { - sw.write("&("+name+")"); - } else { - sw.write(name); - } + else { + theName = name; + } + if (name.equals(THIS)) { + // FIXME: Hack upon hack... + if (((X10CPPContext_c)c.pop()).isInsideClosure()) { + name = SAVED_THIS; + } else if (xts.isStruct(var.type())) { + name = STRUCT_THIS; + } + } else { + name = mangled_non_method_name(name); + } + + + + if(theAssistant.containsKey(theName)) { + LinkedList llcc = theAssistant.get(theName); + if(llcc.size() > 0) { + int ii=0; + for(ForClosureObjectcpp cl:llcc) { + if (ii > 0) sw.write(", "); + sw.write(cl.zzName); + ii++; + } + } + else { + if (refs.contains(var)) { + sw.write("&("+name+")"); + } else { + sw.write(name); + } + } + } + else { + if (refs.contains(var)) { + sw.write("&("+name+")"); + } else { + sw.write(name); + } + } + } + else { + if (i > 0) sw.write(", "); + VarInstance var = (VarInstance) env.get(i); + String name = var.name().toString(); + if (name.equals(THIS)) { + // FIXME: Hack upon hack... + if (((X10CPPContext_c)c.pop()).isInsideClosure()) { + name = SAVED_THIS; + } else if (xts.isStruct(var.type())) { + name = STRUCT_THIS; + } + } else { + name = mangled_non_method_name(name); + } + if (refs.contains(var)) { + sw.write("&("+name+")"); + } else { + sw.write(name); + } + } } + //nobita code + theAssistant = new HashMap>(); sw.write(")"); if (!stackAllocateClosure) { sw.write("))"); @@ -3907,6 +5586,11 @@ private Closure_c getClosureLiteral(Expr target) { // (b) a function type // (c) an class (anonymous or not) that has an operator() public void visit(ClosureCall_c c) { + + /* Nobita code */ + + /* Nobita code */ + X10CPPContext_c context = (X10CPPContext_c) tr.context(); Expr target = c.target(); Type t = target.type(); @@ -4199,5 +5883,408 @@ void emitNativeAnnotation(String pat, List typeParams, List } emitter.nativeSubst("Native", components, tr, pat, sw); } + + /* Nobita new methods */ + //for the graph + public HashMap> deepCopy (HashMap> src) { + HashMap> copyGraphInfo = new HashMap>(); + if (src != null) { + //the copier + Iterator it = src.entrySet().iterator(); + + while (it.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it.next(); + LinkedList edgeIncl = ((LinkedList)phase3.getValue()); + + if(edgeIncl != null) { + Iterator it1 = edgeIncl.iterator(); + + //inserting into new DS + copyGraphInfo.put(phase3.getKey(), new LinkedList()); + LinkedList edgeCopy = copyGraphInfo.get(phase3.getKey()); + + while (it1.hasNext()) { + EdgeRep er = (EdgeRep)it1.next(); + EdgeRep edgeDest = new EdgeRep(er.edgeType, er.desName, er.fieldName, er.copyFlag); + edgeDest.edgeName = er.edgeName; + edgeCopy.addLast(edgeDest); + } + } + } + } + + return copyGraphInfo; + } + + + //for the local decleration - object fields + public void assistlocalfldDec(String desName, String fldName, LinkedList fielderAsst, LinkedList dest, Stack ovs, + HashMap> varInfo, HashMap>> setDetails) { + + int forOvs = 0; + String edgeName = ""; + if(fielderAsst.size() > 0) { + if (desName.equalsIgnoreCase("Obj-null")) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals("Obj-null")) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgIncl = new EdgeRep("P","Obj-null"); + dest.addLast(edgIncl); + } + } + else { + LinkedList src = varInfo.get(desName); + + if (fielderAsst.size() > 0) { + fldName = fielderAsst.removeFirst(); + + if (src != null) { + for (EdgeRep er:src) { + //copying the RHS List + LinkedList fielderAsst1 = new LinkedList(); + for (String str:fielderAsst) { + fielderAsst1.addLast(str); + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if(readSet != null) { + HashSet rs = readSet.get(desName); + if (rs != null) { + //note sure whether contains works fine for HashSet + if (!rs.contains(fldName)) { + rs.add(fldName); + //update modifier boolean + } + } + } + } + + + //calling the function + assistlocalfldDec(er.desName, fldName, fielderAsst1, dest, ovs, varInfo, setDetails); + } + } + } + + //call the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, dest, ovs, varInfo, setDetails); + } + } + else { + LinkedList src = varInfo.get(desName); + if (src != null) { + for (EdgeRep er:src) { + if (er.edgeType.equalsIgnoreCase("F") && (er.fieldName.equalsIgnoreCase(fldName))) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals(er.desName)) { + found = true; + forOvs++; + edgeName = er.edgeName; + break; + } + } + + if (!found) { + forOvs++; + edgeName = er.edgeName; + EdgeRep edgIncl = new EdgeRep("P",er.desName); + dest.addLast(edgIncl); + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + HashMap> writeSet = setDetails.get("WS"); + if(readSet != null && writeSet != null) { + HashSet ws = writeSet.get(desName); + if ( ws != null && !(ws.contains(fldName))) { + HashSet rs = readSet.get(desName); + if (rs != null) { + //note sure whether contains works fine for HashSet + if (!rs.contains(fldName)) { + rs.add(fldName); + //update modifier boolean + } + } + } + } + } + } + } + + if (forOvs > 1) { + ovs.add(edgeName); + } + + } + else if (desName.equalsIgnoreCase("Obj-null")) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals("Obj-null")) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgIncl = new EdgeRep("P","Obj-null"); + dest.addLast(edgIncl); + } + } + } + } + + + + //local decleration - non-object fields + public void assistlocalfldDec_1(String desName, String fldName, LinkedList fielderAsst, Stack ovs, + HashMap> varInfo, HashMap>> setDetails) { + + int forOvs = 0; + String edgeName = ""; + if(fielderAsst.size() > 0) { + + if (desName.equalsIgnoreCase("Obj-null")) { + + } + else { + LinkedList src = varInfo.get(desName); + + if (fielderAsst.size() > 0) { + fldName = fielderAsst.removeFirst(); + + if (src != null) { + for (EdgeRep er:src) { + //copying the RHS List + LinkedList fielderAsst1 = new LinkedList(); + for (String str:fielderAsst) { + fielderAsst1.addLast(str); + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if(readSet != null) { + HashSet rs = readSet.get(desName); + if (rs != null) { + //note sure whether contains works fine for HashSet + if (!rs.contains(fldName)) { + rs.add(fldName); + //update modifier boolean + } + } + } + } + + + //calling the function + assistlocalfldDec_1(er.desName, fldName, fielderAsst1, ovs, varInfo, setDetails); + } + } + } + + //call the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, dest, ovs, varInfo, setDetails); + } + } + else { + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if(readSet != null) { + HashSet rs = readSet.get(desName); + rs.add(fldName); + } + } + } + } + + //for the field assign assistance + public void assistfldAssig(String desName, String fldName, LinkedList fielderAsst, LinkedList dest, Stack ovs, + HashMap> varInfo, HashMap>> setDetails) { + + int forOvs = 0; + String edgeName = ""; + if(fielderAsst.size() > 0) { + if (desName.equalsIgnoreCase("Obj-null")) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals("Obj-null")) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgIncl = new EdgeRep("P","Obj-null"); + dest.addLast(edgIncl); + } + } + else { + LinkedList src = varInfo.get(desName); + fldName = fielderAsst.removeFirst(); + + for (EdgeRep er:src) { + //copying the RHS List + LinkedList fielderAsst1 = new LinkedList(); + for (String str:fielderAsst) { + fielderAsst1.addLast(str); + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + if(readSet != null) { + HashSet rs = readSet.get(desName); + if (rs != null) { + //note sure whether contains works fine for HashSet + if (!rs.contains(fldName)) { + rs.add(fldName); + //update modifier boolean + } + } + } + } + + + //calling the function + assistlocalfldDec(er.desName, fldName, fielderAsst1, dest, ovs, varInfo, setDetails); + } + + //call the function + //assistlocalfldDec(er.desName, fldName, fielderAsst, dest, ovs, varInfo, setDetails); + } + } + else { + LinkedList src = varInfo.get(desName); + if (src != null) { + for (EdgeRep er:src) { + if (er.edgeType.equalsIgnoreCase("F") && (er.fieldName.equalsIgnoreCase(fldName))) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals(er.desName)) { + found = true; + forOvs++; + edgeName = er.edgeName; + break; + } + } + + if (!found) { + forOvs++; + edgeName = er.edgeName; + EdgeRep edgIncl = new EdgeRep("P",er.desName); + dest.addLast(edgIncl); + } + + if (setDetails != null) { + HashMap> readSet = setDetails.get("RS"); + HashMap> writeSet = setDetails.get("WS"); + if(readSet != null && writeSet != null) { + HashSet ws = writeSet.get(desName); + if ( ws != null && !(ws.contains(fldName))) { + HashSet rs = readSet.get(desName); + if (rs != null) { + //note sure whether contains works fine for HashSet + if (!rs.contains(fldName)) { + rs.add(fldName); + //update modifier boolean + } + } + } + } + } + } + } + + if (forOvs > 1) { + ovs.add(edgeName); + } + + } + else if (desName.equalsIgnoreCase("Obj-null")) { + boolean found = false; + for (EdgeRep er1: dest) { + if (er1.desName.equals("Obj-null")) { + found = true; + break; + } + } + if (!found) { + EdgeRep edgIncl = new EdgeRep("P","Obj-null"); + dest.addLast(edgIncl); + } + } + } + } + + /* Nobita code - a method */ + public HashMap>> deepCopySet (HashMap>> src) { + HashMap>> setDetails = new HashMap>>(); + + if (src != null) { + //the iterator + Iterator it = src.entrySet().iterator(); + + while (it.hasNext()) { + Map.Entry>> phase2 = (Map.Entry>>) it.next(); + + //inserting sets into new [setDetails] + setDetails.put(phase2.getKey(), new HashMap>()); + HashMap> sets = (HashMap>)phase2.getValue(); + + if (sets != null) { + //the variable insertion-1 + HashMap> variable = setDetails.get(phase2.getKey()); + + Iterator it1 = sets.entrySet().iterator(); + while (it1.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it1.next(); + + //the variable insertion-2 + variable.put(phase3.getKey(), new HashSet()); + } + } + } + } + return setDetails; + } + + + public void mergeForPlaces (HashMap>> src, HashMap> desCRS) { + + if (src != null) { + //the iterator + Iterator it = src.entrySet().iterator(); + + while (it.hasNext()) { + Map.Entry>> phase2 = (Map.Entry>>) it.next(); + + if (phase2.getKey().equalsIgnoreCase("RS") || phase2.getKey().equalsIgnoreCase("CRS")) { + HashMap> sets = (HashMap>)phase2.getValue(); + + if (sets != null) { + Iterator it1 = sets.entrySet().iterator(); + while (it1.hasNext()) { + Map.Entry> phase3 = (Map.Entry>)it1.next(); + HashSet srcSet = (HashSet)phase3.getValue(); + HashSet desSet = desCRS.get(phase3.getKey()); + if (srcSet != null && desSet != null) { + for (String str:srcSet) { + desSet.add(str); + } + } + } + } + } + } + } + } } // end of MessagePassingCodeGenerator // vim:tabstop=4:shiftwidth=4:expandtab + + + + + diff --git a/x10.compiler/src/x10cpp/visit/X10CPPTranslator.java b/x10.compiler/src/x10cpp/visit/X10CPPTranslator.java index a61777910c..e09e51451e 100644 --- a/x10.compiler/src/x10cpp/visit/X10CPPTranslator.java +++ b/x10.compiler/src/x10cpp/visit/X10CPPTranslator.java @@ -98,8 +98,17 @@ import x10cpp.postcompiler.SharedLibProperties; import x10cpp.types.X10CPPContext_c; +/* Nobita code */ +import static x10cpp.visit.MessagePassingCodeGenerator.nextIteration_cpp; +/* Nobita code */ + public class X10CPPTranslator extends Translator { + /* Nobita code */ + public static int chance = 0; + public static String pathFile = ""; + /* Nobita code */ + public X10CPPTranslator(Job job, TypeSystem ts, NodeFactory nf, TargetFactory tf) { super(job, ts, nf, tf); } @@ -346,6 +355,15 @@ private static void maybeCopyTo (String file, String src_path_, String dest_path * @see polyglot.visit.Translator#translateSource(polyglot.ast.SourceFile) */ protected boolean translateSource(SourceFile sfn) { + + /*Nobita code */ + boolean first = false; + if (pathFile.equalsIgnoreCase("")) { + first = true; + pathFile = sfn.toString(); + } + /*Nobita code */ + int outputWidth = job.compiler().outputWidth(); @@ -463,6 +481,18 @@ protected boolean translateSource(SourceFile sfn) { fstreams.commitStreams(); } + + /* Nobita code */ + if (nextIteration_cpp && pathFile.equalsIgnoreCase(sfn.toString())) { + translateSource(sfn); + } + + if((chance <= 4) && pathFile.equalsIgnoreCase(sfn.toString())) { + chance++; + translateSource(sfn); + } + /* Nobita code */ + return true; } catch (IOException e) { @@ -559,7 +589,13 @@ public static boolean postCompile(X10CPPCompilerOptions options, Compiler compil compiler.outputWidth()); List mainMethods = new ArrayList(); for (Job job : ext.scheduler().commandLineJobs()) { - mainMethods.addAll(getMainMethods(job)); + List mainMethods_temp = new ArrayList(); + /* nobita's modified code */ + mainMethods_temp.addAll(getMainMethods(job)); + if (mainMethods_temp.size() > 0) { + mainMethods.add(mainMethods_temp.get(0)); + } + /* nobita's modified code */ } if (mainMethods.size() < 1) { // If there are no main() methods in the command-line jobs, try other files diff --git a/x10.dist/rushabh-testing/HelloWholeWorld.cc b/x10.dist/rushabh-testing/HelloWholeWorld.cc new file mode 100644 index 0000000000..2d7cad15eb --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWholeWorld.cc @@ -0,0 +1,195 @@ +/*************************************************/ +/* START of HelloWholeWorld */ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef HELLOWHOLEWORLD__CLOSURE__7_CLOSURE +#define HELLOWHOLEWORLD__CLOSURE__7_CLOSURE +#include +#include +class HelloWholeWorld__closure__7 : public ::x10::lang::Closure { + public: + + static ::x10::lang::VoidFun_0_0::itable _itable; + static ::x10aux::itable_entry _itables[2]; + + virtual ::x10aux::itable_entry* _getITables() { return _itables; } + + void __apply(){ + ::x10::io::Console::FMGL(OUT__get)()->x10::io::Printer::println(reinterpret_cast< ::x10::lang::Any*>(::x10::lang::String::__plus(::x10::lang::String::__plus(::x10::lang::Place::_make(::x10aux::here), (&::HelloWholeWorld_Strings::sl__225)), ::x10aux::nullCheck(args)->x10::lang::Rail< ::x10::lang::String* >::__apply( + ((x10_long)0ll))))); + } + + // captured environment + ::x10::lang::Rail< ::x10::lang::String* >* args; + + ::x10aux::serialization_id_t _get_serialization_id() { + return _serialization_id; + } + + ::x10aux::serialization_id_t _get_network_id() { + return _network_id; + } + + void _serialize_body(::x10aux::serialization_buffer &buf) { + buf.write(this->args); + } + + static x10::lang::Reference* _deserialize(::x10aux::deserialization_buffer &buf) { + HelloWholeWorld__closure__7* storage = ::x10aux::alloc_z(); + buf.record_reference(storage); + ::x10::lang::Rail< ::x10::lang::String* >* that_args = buf.read< ::x10::lang::Rail< ::x10::lang::String* >*>(); + HelloWholeWorld__closure__7* this_ = new (storage) HelloWholeWorld__closure__7(that_args); + return this_; + } + + HelloWholeWorld__closure__7(::x10::lang::Rail< ::x10::lang::String* >* args) : args(args) { } + + HelloWholeWorld__closure__7(::x10::lang::Rail< ::x10::lang::String* >* args,x10_long zzztemp){ + this->args = args; + } + + static const ::x10aux::serialization_id_t _serialization_id; + + static const ::x10aux::serialization_id_t _network_id; + + static const ::x10aux::RuntimeType* getRTT() { return ::x10aux::getRTT< ::x10::lang::VoidFun_0_0>(); } + virtual const ::x10aux::RuntimeType *_type() const { return ::x10aux::getRTT< ::x10::lang::VoidFun_0_0>(); } + + const char* toNativeString() { + return "HelloWholeWorld.x10:38"; + } + + }; + + #endif // HELLOWHOLEWORLD__CLOSURE__7_CLOSURE + +//#line 31 "HelloWholeWorld.x10" +void HelloWholeWorld::main(::x10::lang::Rail< ::x10::lang::String* >* args) { + + //#line 32 "HelloWholeWorld.x10" + if ((((x10_long)(::x10aux::nullCheck(args)->FMGL(size))) < (((x10_long)1ll)))) + { + + //#line 33 "HelloWholeWorld.x10" + ::x10::io::Console::FMGL(OUT__get)()->x10::io::Printer::println( + reinterpret_cast< ::x10::lang::Any*>((&::HelloWholeWorld_Strings::sl__224))); + + //#line 34 "HelloWholeWorld.x10" + return; + } + { + + //#line 37 "HelloWholeWorld.x10" + ::x10::xrx::Runtime::ensureNotInAtomic(); + ::x10::xrx::FinishState* fs__187 = ::x10::xrx::Runtime::startFinish(); + try { + { + { + ::x10::lang::Iterator< ::x10::lang::Place>* p__181; + for (p__181 = ::x10::lang::Place::places()->iterator(); + ::x10::lang::Iterator< ::x10::lang::Place>::hasNext(::x10aux::nullCheck(p__181)); + ) { + ::x10::lang::Place p = ::x10::lang::Iterator< ::x10::lang::Place>::next(::x10aux::nullCheck(p__181)); + + //#line 38 "HelloWholeWorld.x10" + ::x10::xrx::Runtime::runAsync(p, reinterpret_cast< ::x10::lang::VoidFun_0_0*>((new (::x10aux::alloc< ::x10::lang::VoidFun_0_0>(sizeof(HelloWholeWorld__closure__7)))HelloWholeWorld__closure__7(args))), + ::x10aux::class_cast_unchecked< ::x10::xrx::Runtime__Profile*>(reinterpret_cast< ::x10::lang::NullType*>(X10_NULL))); + } + } + + } + } + catch (::x10::lang::CheckedThrowable* __exc25) { + { + ::x10::lang::CheckedThrowable* ct__185 = __exc25; + { + ::x10::xrx::Runtime::pushException(ct__185); + } + } + } + ::x10::xrx::Runtime::stopFinish(fs__187); + } + + //#line 40 "HelloWholeWorld.x10" + ::x10::io::Console::FMGL(OUT__get)()->x10::io::Printer::println( + reinterpret_cast< ::x10::lang::Any*>((&::HelloWholeWorld_Strings::sl__226))); +} + +//#line 30 "HelloWholeWorld.x10" +::HelloWholeWorld* HelloWholeWorld::HelloWholeWorld____this__HelloWholeWorld( + ) { + return this; + +} +void HelloWholeWorld::_constructor() { + this->HelloWholeWorld::__fieldInitializers_HelloWholeWorld(); +} +::HelloWholeWorld* HelloWholeWorld::_make() { + ::HelloWholeWorld* this_ = new (::x10aux::alloc_z< ::HelloWholeWorld>()) ::HelloWholeWorld(); + this_->_constructor(); + return this_; +} + + +void HelloWholeWorld::__fieldInitializers_HelloWholeWorld( + ) { + +} +const ::x10aux::serialization_id_t HelloWholeWorld::_serialization_id = + ::x10aux::DeserializationDispatcher::addDeserializer(::HelloWholeWorld::_deserializer); + +void HelloWholeWorld::_serialize_body(::x10aux::serialization_buffer& buf) { + +} + +::x10::lang::Reference* ::HelloWholeWorld::_deserializer(::x10aux::deserialization_buffer& buf) { + ::HelloWholeWorld* this_ = new (::x10aux::alloc_z< ::HelloWholeWorld>()) ::HelloWholeWorld(); + buf.record_reference(this_); + this_->_deserialize_body(buf); + return this_; +} + +void HelloWholeWorld::_deserialize_body(::x10aux::deserialization_buffer& buf) { + +} + +::x10aux::RuntimeType HelloWholeWorld::rtt; +void HelloWholeWorld::_initRTT() { + if (rtt.initStageOne(&rtt)) return; + const ::x10aux::RuntimeType** parents = NULL; + rtt.initStageTwo("HelloWholeWorld",::x10aux::RuntimeType::class_kind, 0, parents, 0, NULL, NULL); +} + +::x10::lang::String HelloWholeWorld_Strings::sl__225(" says hello and "); +::x10::lang::String HelloWholeWorld_Strings::sl__224("Usage: HelloWholeWorld message"); +::x10::lang::String HelloWholeWorld_Strings::sl__226("Goodbye"); + +::x10::lang::VoidFun_0_0::itableHelloWholeWorld__closure__7::_itable(&::x10::lang::Reference::equals, &::x10::lang::Closure::hashCode, &HelloWholeWorld__closure__7::__apply, &HelloWholeWorld__closure__7::toString, &::x10::lang::Closure::typeName); +::x10aux::itable_entry HelloWholeWorld__closure__7::_itables[2] = {::x10aux::itable_entry(&::x10aux::getRTT< ::x10::lang::VoidFun_0_0>, &HelloWholeWorld__closure__7::_itable),::x10aux::itable_entry(NULL, NULL)}; + +const ::x10aux::serialization_id_t HelloWholeWorld__closure__7::_serialization_id = + ::x10aux::DeserializationDispatcher::addDeserializer(HelloWholeWorld__closure__7::_deserialize); +const ::x10aux::serialization_id_t HelloWholeWorld__closure__7::_network_id = + ::x10aux::NetworkDispatcher::addNetworkDeserializer(HelloWholeWorld__closure__7::_deserialize,::x10aux::CLOSURE_KIND_ASYNC_CLOSURE); + +/* END of HelloWholeWorld */ +/*************************************************/ diff --git a/x10.dist/rushabh-testing/HelloWholeWorld.h b/x10.dist/rushabh-testing/HelloWholeWorld.h new file mode 100644 index 0000000000..8f5de0888f --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWholeWorld.h @@ -0,0 +1,99 @@ +#ifndef __HELLOWHOLEWORLD_H +#define __HELLOWHOLEWORLD_H + +#include + + +namespace x10 { namespace lang { +template class Rail; +} } +namespace x10 { namespace lang { +class String; +} } +namespace x10 { namespace io { +class Printer; +} } +namespace x10 { namespace io { +class Console; +} } +namespace x10 { namespace lang { +class Any; +} } +namespace x10 { namespace xrx { +class Runtime; +} } +namespace x10 { namespace xrx { +class FinishState; +} } +namespace x10 { namespace lang { +template class Iterator; +} } +namespace x10 { namespace lang { +class Place; +} } +namespace x10 { namespace lang { +template class Iterable; +} } +namespace x10 { namespace lang { +class PlaceGroup; +} } +namespace x10 { namespace lang { +class VoidFun_0_0; +} } +namespace x10 { namespace compiler { +class AsyncClosure; +} } +namespace x10 { namespace xrx { +class Runtime__Profile; +} } +namespace x10 { namespace lang { +class CheckedThrowable; +} } +namespace x10 { namespace compiler { +class Synthetic; +} } + +class HelloWholeWorld_Strings { + public: + static ::x10::lang::String sl__225; + static ::x10::lang::String sl__224; + static ::x10::lang::String sl__226; +}; + +class HelloWholeWorld : public ::x10::lang::X10Class { + public: + RTT_H_DECLS_CLASS + + static void main(::x10::lang::Rail< ::x10::lang::String* >* args); + virtual ::HelloWholeWorld* HelloWholeWorld____this__HelloWholeWorld(); + void _constructor(); + + static ::HelloWholeWorld* _make(); + + virtual void __fieldInitializers_HelloWholeWorld(); + + // Serialization + public: static const ::x10aux::serialization_id_t _serialization_id; + + public: virtual ::x10aux::serialization_id_t _get_serialization_id() { + return _serialization_id; + } + + public: virtual void _serialize_body(::x10aux::serialization_buffer& buf); + + public: static ::x10::lang::Reference* _deserializer(::x10aux::deserialization_buffer& buf); + + public: void _deserialize_body(::x10aux::deserialization_buffer& buf); + +}; + +#endif // HELLOWHOLEWORLD_H + +class HelloWholeWorld; + +#ifndef HELLOWHOLEWORLD_H_NODEPS +#define HELLOWHOLEWORLD_H_NODEPS +#ifndef HELLOWHOLEWORLD_H_GENERICS +#define HELLOWHOLEWORLD_H_GENERICS +#endif // HELLOWHOLEWORLD_H_GENERICS +#endif // __HELLOWHOLEWORLD_H_NODEPS diff --git a/x10.dist/rushabh-testing/HelloWholeWorld.x10 b/x10.dist/rushabh-testing/HelloWholeWorld.x10 new file mode 100644 index 0000000000..54beb2a324 --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWholeWorld.x10 @@ -0,0 +1,44 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2016. + */ + +import x10.io.Console; + +/** + * The classic hello world program, with a twist - prints a message + * from the command line at every Place. + * The messages from each Place may appear in any order, but the + * finish ensures that the last message printed will be "Goodbye" + *
+ * Typical output:
+ * [dgrove@linchen samples]$ ./HelloWholeWorld 'best wishes'
+ * Place(1) says hello and best wishes
+ * Place(2) says hello and best wishes
+ * Place(3) says hello and best wishes
+ * Place(0) says hello and best wishes
+ * Goodbye 
+ * [dgrove@linchen samples]$
+ * 
+ */ +public class HelloWholeWorld { + public static def main(args:Rail[String]):void { + if (args.size < 1) { + Console.OUT.println("Usage: HelloWholeWorld message"); + return; + } + + finish for (p in Place.places()) { + at (p) async Console.OUT.println(here+" says hello and "+args(0)); + } + Console.OUT.println("Goodbye"); + } +} + + diff --git a/x10.dist/rushabh-testing/HelloWorld.cc b/x10.dist/rushabh-testing/HelloWorld.cc new file mode 100644 index 0000000000..b2f1a6b964 --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWorld.cc @@ -0,0 +1,66 @@ +/*************************************************/ +/* START of HelloWorld */ +#include + +#include +#include +#include +#include +#include +#include +#include + +//#line 18 "HelloWorld.x10" +void HelloWorld::main(::x10::lang::Rail< ::x10::lang::String* >* id__0) { + + //#line 19 "HelloWorld.x10" + ::x10::io::Console::FMGL(OUT__get)()->x10::io::Printer::println(reinterpret_cast< ::x10::lang::Any*>((&::HelloWorld_Strings::sl__17))); +} + +//#line 17 "HelloWorld.x10" +::HelloWorld* HelloWorld::HelloWorld____this__HelloWorld() { + return this; + +} +void HelloWorld::_constructor() { + this->HelloWorld::__fieldInitializers_HelloWorld(); +} +::HelloWorld* HelloWorld::_make() { + ::HelloWorld* this_ = new (::x10aux::alloc_z< ::HelloWorld>()) ::HelloWorld(); + this_->_constructor(); + return this_; +} + + +void HelloWorld::__fieldInitializers_HelloWorld() { + +} +const ::x10aux::serialization_id_t HelloWorld::_serialization_id = + ::x10aux::DeserializationDispatcher::addDeserializer(::HelloWorld::_deserializer); + +void HelloWorld::_serialize_body(::x10aux::serialization_buffer& buf) { + +} + +::x10::lang::Reference* ::HelloWorld::_deserializer(::x10aux::deserialization_buffer& buf) { + ::HelloWorld* this_ = new (::x10aux::alloc_z< ::HelloWorld>()) ::HelloWorld(); + buf.record_reference(this_); + this_->_deserialize_body(buf); + return this_; +} + +void HelloWorld::_deserialize_body(::x10aux::deserialization_buffer& buf) { + +} + +::x10aux::RuntimeType HelloWorld::rtt; +void HelloWorld::_initRTT() { + if (rtt.initStageOne(&rtt)) return; + const ::x10aux::RuntimeType** parents = NULL; + rtt.initStageTwo("HelloWorld",::x10aux::RuntimeType::class_kind, 0, parents, 0, NULL, NULL); +} + +::x10::lang::String HelloWorld_Strings::sl__17("Hello World!"); + +/* END of HelloWorld */ +/*************************************************/ diff --git a/x10.dist/rushabh-testing/HelloWorld.h b/x10.dist/rushabh-testing/HelloWorld.h new file mode 100644 index 0000000000..af0ea62a38 --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWorld.h @@ -0,0 +1,67 @@ +#ifndef __HELLOWORLD_H +#define __HELLOWORLD_H + +#include + + +namespace x10 { namespace lang { +template class Rail; +} } +namespace x10 { namespace lang { +class String; +} } +namespace x10 { namespace io { +class Printer; +} } +namespace x10 { namespace io { +class Console; +} } +namespace x10 { namespace lang { +class Any; +} } +namespace x10 { namespace compiler { +class Synthetic; +} } + +class HelloWorld_Strings { + public: + static ::x10::lang::String sl__17; +}; + +class HelloWorld : public ::x10::lang::X10Class { + public: + RTT_H_DECLS_CLASS + + static void main(::x10::lang::Rail< ::x10::lang::String* >* id__0); + virtual ::HelloWorld* HelloWorld____this__HelloWorld(); + void _constructor(); + + static ::HelloWorld* _make(); + + virtual void __fieldInitializers_HelloWorld(); + + // Serialization + public: static const ::x10aux::serialization_id_t _serialization_id; + + public: virtual ::x10aux::serialization_id_t _get_serialization_id() { + return _serialization_id; + } + + public: virtual void _serialize_body(::x10aux::serialization_buffer& buf); + + public: static ::x10::lang::Reference* _deserializer(::x10aux::deserialization_buffer& buf); + + public: void _deserialize_body(::x10aux::deserialization_buffer& buf); + +}; + +#endif // HELLOWORLD_H + +class HelloWorld; + +#ifndef HELLOWORLD_H_NODEPS +#define HELLOWORLD_H_NODEPS +#ifndef HELLOWORLD_H_GENERICS +#define HELLOWORLD_H_GENERICS +#endif // HELLOWORLD_H_GENERICS +#endif // __HELLOWORLD_H_NODEPS diff --git a/x10.dist/rushabh-testing/HelloWorld.x10 b/x10.dist/rushabh-testing/HelloWorld.x10 new file mode 100644 index 0000000000..2efd4d9ac2 --- /dev/null +++ b/x10.dist/rushabh-testing/HelloWorld.x10 @@ -0,0 +1,23 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2016. + */ + +import x10.io.Console; + +/** + * The classic hello world program, shows how to output to the console. + */ +public class HelloWorld { + public static def main(Rail[String]) { + Console.OUT.println("Hello World!" ); + } +} + + diff --git a/x10.dist/rushabh-testing/a.out b/x10.dist/rushabh-testing/a.out new file mode 100755 index 0000000000..8f6b5768ea Binary files /dev/null and b/x10.dist/rushabh-testing/a.out differ diff --git a/x10.dist/rushabh-testing/xxx_main_xxx.cc b/x10.dist/rushabh-testing/xxx_main_xxx.cc new file mode 100644 index 0000000000..d4464444d7 --- /dev/null +++ b/x10.dist/rushabh-testing/xxx_main_xxx.cc @@ -0,0 +1,3 @@ +#include +#include +extern "C" { int main(int ac, char **av) { return ::x10aux::template_main< ::HelloWholeWorld>(ac,av); } }