a new compiler flag, "-printlinenum", has been added to print out line numbers in...
authoryeom <yeom>
Fri, 18 Mar 2011 00:17:01 +0000 (00:17 +0000)
committeryeom <yeom>
Fri, 18 Mar 2011 00:17:01 +0000 (00:17 +0000)
Robust/src/IR/ClassDescriptor.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/FlatCall.java
Robust/src/IR/Flat/FlatNode.java
Robust/src/IR/State.java
Robust/src/IR/Tree/BuildIR.java
Robust/src/IR/Tree/SemanticCheck.java
Robust/src/IR/Tree/TreeNode.java
Robust/src/IR/TypeUtil.java
Robust/src/Main/Main.java
Robust/src/buildscript

index d9d611d5d1f9e16b2867b759884d969650406998..8a8ca629bb4010b57f8b068f6d2ab2614aa73a64 100644 (file)
@@ -42,6 +42,8 @@ public class ClassDescriptor extends Descriptor {
   
   boolean isClassLibrary=false;
   
+  String sourceFileName;
+  
   public ClassDescriptor(String classname, boolean isInterface) {
     this("", classname, isInterface);
   }
@@ -393,4 +395,12 @@ public class ClassDescriptor extends Descriptor {
     return isClassLibrary;
   }
   
+  public void setSourceFileName(String sourceFileName){
+    this.sourceFileName=sourceFileName;
+  }
+  
+  public String getSourceFileName(){
+    return this.sourceFileName;
+  }
+  
 }
index eb1fa51f52e778f7105af23d03e300366f6c1078..6820811b927901d65876e3da4432a35e10ea6098 100644 (file)
@@ -2202,9 +2202,9 @@ public class BuildCode {
 
 
   protected void generateFlatNode(FlatMethod fm, FlatNode fn, PrintWriter output) {
+    if(state.LINENUM) printSourceLineNumber(fm,fn,output);
     additionalCodePreNode(fm, fn, output);
 
-
     switch(fn.kind()) {
     case FKind.FlatAtomicEnterNode:
       generateFlatAtomicEnterNode(fm, (FlatAtomicEnterNode) fn, output);
@@ -2622,6 +2622,7 @@ public class BuildCode {
   }
 
   protected void generateFlatFieldNode(FlatMethod fm, FlatFieldNode ffn, PrintWriter output) {
+    
     if(ffn.getField().isStatic()) {
       // static field
       if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
@@ -3547,6 +3548,34 @@ public class BuildCode {
   }
   protected void additionalCodePostNode(FlatMethod fm, FlatNode fn, PrintWriter output) {
   }
+  
+  private void printSourceLineNumber(FlatMethod fm, FlatNode fn, PrintWriter output) {
+    // we do not print out line number if no one explicitly set the number
+    if(fn.getNumLine()!=-1){
+      
+      int lineNum=fn.getNumLine();
+
+      // do not generate the line number if it is same as the previous one
+      boolean needtoprint;
+      if(fn.prev.size()==0){
+        needtoprint=true;
+      }else{
+        needtoprint=false;
+      }
+
+      for(int i=0;i<fn.prev.size();i++){
+        int prevLineNum=((FlatNode)fn.prev.get(i)).getNumLine();
+        if(prevLineNum!=lineNum){
+          needtoprint=true;
+          break;
+        }
+      }
+      if(needtoprint){
+        output.println("// "+fm.getMethod().getClassDesc().getSourceFileName()+":"+fn.getNumLine());
+      }
+    }
+  }
+  
 }
 
 
index ed24815cf05f7e21153708baad436ee001229f2e..f2ca858ea6a2a932961a991cde20a1d486f51e29 100644 (file)
@@ -27,6 +27,7 @@ public class FlatCall extends FlatNode {
     TempDescriptor[] nargs=new TempDescriptor[args.length];
     for(int i=0;i<nargs.length;i++)
       nargs[i]=t.tempMap(args[i]);
+    
     return new FlatCall(method, ndst, nthis, nargs);
   }
 
index 12e9be9156dc3d495d82869651af145f5acc13ba..38b78e06dbe850a97f0cbb1524216b703bc0ec46 100644 (file)
@@ -9,7 +9,7 @@ public class FlatNode {
   protected Vector prev;
   static int idcounter=0;
   public final int nodeid;
-  public int numLine;
+  public int numLine=-1;
 
   public FlatNode() {
     next=new Vector();
index eb61444024c5c3874a858c4e3d2fdec2f77e6d87..0caa0ba7469e40973da0dbcabbbd8727b95447ee 100644 (file)
@@ -193,6 +193,7 @@ public class State {
   private int arraycount=0;
   public Hashtable cd2locationOrderMap;
   public boolean OPTIMIZE=false;
+  public boolean LINENUM=false;
 
   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
index 5a1a7652cea9c6fd6417772eb778f27cffc0bfb8..04ba43b1f4c7dc7299828c37d29f487e5f6c1fe3 100644 (file)
@@ -16,8 +16,8 @@ public class BuildIR {
     this.m_taskexitnum = 0;
   }
 
-  public void buildtree(ParseNode pn, Set toanalyze) {
-    parseFile(pn, toanalyze);
+  public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
+    parseFile(pn, toanalyze,sourcefile);
     
     // numering the interfaces
     int if_num = 0;
@@ -35,7 +35,7 @@ public class BuildIR {
   NameDescriptor packages;
 
   /** Parse the classes in this file */
-  public void parseFile(ParseNode pn, Set toanalyze) {
+  public void parseFile(ParseNode pn, Set toanalyze,String sourcefile) {
     singleimports=new Vector();
     multiimports=new Vector();
     
@@ -64,6 +64,7 @@ public class BuildIR {
          continue;
        if (isNode(type_pn,"class_declaration")) {
          ClassDescriptor cn=parseTypeDecl(type_pn);
+         cn.setSourceFileName(sourcefile);
          parseInitializers(cn);
          if (toanalyze!=null)
            toanalyze.add(cn);
@@ -82,6 +83,7 @@ public class BuildIR {
            if(toanalyze != null) {
              toanalyze.add(cd);
            }
+           cd.setSourceFileName(sourcefile);
            state.addClass(cd);
            
            Iterator it_ics = cd.getInnerClasses();
@@ -95,6 +97,7 @@ public class BuildIR {
              if(toanalyze != null) {
                toanalyze.add(iecd);
              }
+             iecd.setSourceFileName(sourcefile);
              state.addClass(iecd);
            }
          }
@@ -105,6 +108,7 @@ public class BuildIR {
            if(toanalyze != null) {
              toanalyze.add(ecd);
            }
+           ecd.setSourceFileName(sourcefile);
            state.addClass(ecd);
          }
        } else if (isNode(type_pn,"task_declaration")) {
@@ -117,6 +121,7 @@ public class BuildIR {
          ClassDescriptor cn = parseInterfaceDecl(type_pn);
          if (toanalyze!=null)
            toanalyze.add(cn);
+         cn.setSourceFileName(sourcefile);
          state.addClass(cn);
          
          // for enum
@@ -126,6 +131,7 @@ public class BuildIR {
            if(toanalyze != null) {
              toanalyze.add(ecd);
            }
+           ecd.setSourceFileName(sourcefile);
            state.addClass(ecd);
          }
        } else if (isNode(type_pn,"enum_declaration")) {
@@ -133,6 +139,7 @@ public class BuildIR {
          ClassDescriptor cn = parseEnumDecl(null, type_pn);
          if (toanalyze!=null)
            toanalyze.add(cn);
+         cn.setSourceFileName(sourcefile);
          state.addClass(cn);
        } else {
          throw new Error(type_pn.getLabel());
@@ -671,6 +678,7 @@ public void parseInitializers(ClassDescriptor cn){
       ExpressionNode en=null;
       if (epn!=null) {
         en=parseExpression(epn.getFirstChild());
+        en.setNumLine(epn.getFirstChild().getLine());
         if(m.isStatic()) {
           // for static field, the initializer should be considered as a 
           // static block
@@ -690,6 +698,7 @@ public void parseInitializers(ClassDescriptor cn){
           cn.incStaticBlocks();
           BlockNode bn=new BlockNode();
           NameNode nn=new NameNode(new NameDescriptor(identifier));
+          nn.setNumLine(en.getNumLine());
           AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
           an.setNumLine(pn.getLine());
           bn.addBlockStatement(new BlockExpressionNode(an));
@@ -738,14 +747,18 @@ public void parseInitializers(ClassDescriptor cn){
       ParseNode left=pnv.elementAt(0);
       ParseNode right=pnv.elementAt(1);
       Operation op=new Operation(pn.getLabel());
-      return new OpNode(parseExpression(left),parseExpression(right),op);
+      OpNode on=new OpNode(parseExpression(left),parseExpression(right),op);
+      on.setNumLine(pn.getLine());
+      return on;
     } else if (isNode(pn,"unaryplus")||
                isNode(pn,"unaryminus")||
                isNode(pn,"not")||
                isNode(pn,"comp")) {
       ParseNode left=pn.getFirstChild();
       Operation op=new Operation(pn.getLabel());
-      return new OpNode(parseExpression(left),op);
+      OpNode on=new OpNode(parseExpression(left),op);
+      on.setNumLine(pn.getLine());
+      return on;
     } else if (isNode(pn,"postinc")||
                isNode(pn,"postdec")) {
       ParseNode left=pn.getFirstChild();
@@ -765,8 +778,10 @@ public void parseInitializers(ClassDescriptor cn){
     } else if (isNode(pn,"literal")) {
       String literaltype=pn.getTerminal();
       ParseNode literalnode=pn.getChild(literaltype);
-      Object literal_obj=literalnode.getLiteral();
-      return new LiteralNode(literaltype, literal_obj);
+      Object literal_obj=literalnode.getLiteral();      
+      LiteralNode ln=new LiteralNode(literaltype, literal_obj);
+      ln.setNumLine(pn.getLine());
+      return ln;
     } else if (isNode(pn,"createobject")) {
       TypeDescriptor td=parseTypeDescriptor(pn);
       
@@ -842,7 +857,9 @@ public void parseInitializers(ClassDescriptor cn){
       return nn;
     } else if (isNode(pn,"isavailable")) {
       NameDescriptor nd=new NameDescriptor(pn.getTerminal());
-      return new OpNode(new NameNode(nd),null,new Operation(Operation.ISAVAILABLE));
+      NameNode nn=new NameNode(nd);
+      nn.setNumLine(pn.getLine());
+      return new OpNode(nn,null,new Operation(Operation.ISAVAILABLE));
     } else if (isNode(pn,"methodinvoke1")) {
       NameDescriptor nd=parseName(pn.getChild("name"));
       Vector args=parseArgumentList(pn);
index b9021ab23811727d70f6c72a8f1adf053c3e28e6..ea430cfc079541f8055426d600940f5cc36e8574 100644 (file)
@@ -626,6 +626,7 @@ public class SemanticCheck {
 
     if (fd.getType().iswrapper()) {
       FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
+      fan2.setNumLine(left.getNumLine());
       fan2.setField(fd);
       fan.left=fan2;
       fan.fieldname="value";
@@ -709,7 +710,7 @@ public class SemanticCheck {
     if (nd.getBase()!=null) {
       /* Big hack */
       /* Rewrite NameNode */
-      ExpressionNode en=translateNameDescriptorintoExpression(nd);
+      ExpressionNode en=translateNameDescriptorintoExpression(nd,nn.getNumLine());
       nn.setExpression(en);
       checkExpressionNode(md,nametable,en,td);
     } else {
@@ -780,9 +781,11 @@ public class SemanticCheck {
          String id=nd.getIdentifier();
          NameDescriptor base=nd.getBase();
          NameNode n=new NameNode(nn.getName());
+         n.setNumLine(nn.getNumLine());
          n.setField(fd);
          n.setVar((VarDescriptor)nametable.get("this"));        /* Need a pointer to this */
          FieldAccessNode fan=new FieldAccessNode(n,"value");
+         fan.setNumLine(n.getNumLine());
          FieldDescriptor fdval=(FieldDescriptor) fd.getType().getClassDesc().getFieldTable().get("value");
          fan.setField(fdval);
          nn.setExpression(fan);
@@ -923,6 +926,7 @@ public class SemanticCheck {
 
       if (!(an.getSrc().getType().isString()&&(an.getSrc() instanceof OpNode))) {
        MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+       rightmin.setNumLine(an.getSrc().getNumLine());
        rightmin.addArgument(an.getSrc());
        an.right=rightmin;
        checkExpressionNode(md, nametable, an.getSrc(), null);
@@ -1107,13 +1111,18 @@ NextMethod:
 
 
 
-  ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd) {
+  ExpressionNode translateNameDescriptorintoExpression(NameDescriptor nd, int numLine) {
     String id=nd.getIdentifier();
     NameDescriptor base=nd.getBase();
-    if (base==null)
-      return new NameNode(nd);
-    else
-      return new FieldAccessNode(translateNameDescriptorintoExpression(base),id);
+    if (base==null){
+      NameNode nn=new NameNode(nd);
+      nn.setNumLine(numLine);
+      return nn;
+    }else{
+      FieldAccessNode fan=new FieldAccessNode(translateNameDescriptorintoExpression(base,numLine),id);
+      fan.setNumLine(numLine);
+      return fan;
+    }
   }
 
 
@@ -1154,12 +1163,12 @@ NextMethod:
         typetolookin=new TypeDescriptor(cd);
       } else if (nametable.get(rootname)!=null) {
        //we have an expression
-       min.setExpression(translateNameDescriptorintoExpression(min.getBaseName()));
+       min.setExpression(translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine()));
        checkExpressionNode(md, nametable, min.getExpression(), null);
        typetolookin=min.getExpression().getType();
       } else {
        if(!min.getBaseName().getSymbol().equals("System.out")) {
-         ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName());
+         ExpressionNode nn = translateNameDescriptorintoExpression(min.getBaseName(),min.getNumLine());
          checkExpressionNode(md, nametable, nn, null);
          typetolookin = nn.getType();
          if(!((nn.kind()== Kind.NameNode) && (((NameNode)nn).getField() == null)
@@ -1405,6 +1414,7 @@ NextMethod:
        NameDescriptor valuend=new NameDescriptor(nd, "valueOf");
        if (!(ltd.isString()&&(on.getLeft() instanceof OpNode))) {
          MethodInvokeNode leftmin=new MethodInvokeNode(valuend);
+         leftmin.setNumLine(on.getLeft().getNumLine());
          leftmin.addArgument(on.getLeft());
          on.left=leftmin;
          checkExpressionNode(md, nametable, on.getLeft(), null);
@@ -1412,6 +1422,7 @@ NextMethod:
 
        if (!(rtd.isString()&&(on.getRight() instanceof OpNode))) {
          MethodInvokeNode rightmin=new MethodInvokeNode(valuend);
+         rightmin.setNumLine(on.getRight().getNumLine());
          rightmin.addArgument(on.getRight());
          on.right=rightmin;
          checkExpressionNode(md, nametable, on.getRight(), null);
index 25b16795c4c0ccba0d4d3bca8c7bcf2cf1115897..f779a04690055a6b6bf8e841926d423d43d20b1f 100644 (file)
@@ -2,7 +2,7 @@ package IR.Tree;
 
 public class TreeNode {
   public static final int INDENT=2;
-  int numLine;
+  int numLine=-1;
 
   public String printNode(int indent) {
     return null;
index 80b401913e3aa37bfe45b0abef9e069781f40f4e..0d7efcba7cec11caab51ba260b25b3c5e24cb305 100644 (file)
@@ -34,7 +34,7 @@ public class TypeUtil {
       if (f.exists()) {
        try {
          ParseNode pn=Main.readSourceFile(state, f.getCanonicalPath());
-         bir.buildtree(pn, todo);
+         bir.buildtree(pn, todo,f.getCanonicalPath());
          return;
        } catch (Exception e) {
          throw new Error(e);
index e665e4f8d364a113ecf8570928fc9fbf7da108b7..f8570beeb6f6c625e38634d6ae94bdd7a3749b94 100644 (file)
@@ -343,7 +343,9 @@ public class Main {
        state.NOSTALLTR = true;     
       } else if (option.equals("-ssjava")){
   state.SSJAVA = true;     
-      } else if (option.equals("-help")) {      
+      } else if (option.equals("-printlinenum")){
+  state.LINENUM=true;
+      }else if (option.equals("-help")) {      
        System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
        System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
        System.out.println("-dir outputdirectory -- output code in outputdirectory");
@@ -387,6 +389,7 @@ public class Main {
        System.out.println("-printscheduling -- print out scheduling graphs");
        System.out.println("-printschedulesim -- print out scheduling simulation result graphs");
        System.out.println("-webinterface -- enable web interface");
+       System.out.println("-linenum print out line numbers in generated C codes");
        System.out.println("-help -- print out help");
        System.exit(0);
       } else {
@@ -657,7 +660,7 @@ public class Main {
   public static void loadClass(State state, BuildIR bir, String sourcefile) {
     try {
       ParseNode pn=readSourceFile(state, sourcefile);
-      bir.buildtree(pn, null);
+      bir.buildtree(pn, null,sourcefile);
     } catch (Exception e) {
       System.out.println("Error in sourcefile:"+sourcefile);
       e.printStackTrace();
index 27a5cd0abe0d612726715efb843783e337f13f85..a6890d86b3804331354cae9cd906b0ed4e6a7111 100755 (executable)
@@ -146,6 +146,7 @@ echo -recovery compile recovery code
 echo -dsmtask support work and task class library
 echo -recoverystats print out recovery record 
 echo -src-after-pp prints source code after preprocessor to tmp.c
+echo -printlinenum print out line numbers in generated C codes
 echo -help help
 }
 
@@ -591,6 +592,10 @@ elif [[ $1 = '-nostalltr' ]]
 then
 JAVAOPTS="$JAVAOPTS -nostalltr"
 
+elif [[ $1 = '-printlinenum' ]]
+then
+JAVAOPTS="$JAVAOPTS -printlinenum"
+
 elif [[ $1 = '-rcr' ]]
 then
 JAVAOPTS="$JAVAOPTS -rcr"