From 0fe75ee7bfe9fbbdc60923430dff1114cb25bc9e Mon Sep 17 00:00:00 2001 From: yeom Date: Fri, 18 Mar 2011 00:17:01 +0000 Subject: [PATCH] a new compiler flag, "-printlinenum", has been added to print out line numbers in the generated C codes --- Robust/src/IR/ClassDescriptor.java | 10 ++++++++ Robust/src/IR/Flat/BuildCode.java | 31 ++++++++++++++++++++++++- Robust/src/IR/Flat/FlatCall.java | 1 + Robust/src/IR/Flat/FlatNode.java | 2 +- Robust/src/IR/State.java | 1 + Robust/src/IR/Tree/BuildIR.java | 33 ++++++++++++++++++++------- Robust/src/IR/Tree/SemanticCheck.java | 27 +++++++++++++++------- Robust/src/IR/Tree/TreeNode.java | 2 +- Robust/src/IR/TypeUtil.java | 2 +- Robust/src/Main/Main.java | 7 ++++-- Robust/src/buildscript | 5 ++++ 11 files changed, 99 insertions(+), 22 deletions(-) diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index d9d611d5..8a8ca629 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -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; + } + } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index eb1fa51f..6820811b 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -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> optionaltaskdescriptors; private Hashtable>> analysisresults; diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 5a1a7652..04ba43b1 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -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); diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index b9021ab2..ea430cfc 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -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); diff --git a/Robust/src/IR/Tree/TreeNode.java b/Robust/src/IR/Tree/TreeNode.java index 25b16795..f779a046 100644 --- a/Robust/src/IR/Tree/TreeNode.java +++ b/Robust/src/IR/Tree/TreeNode.java @@ -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; diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 80b40191..0d7efcba 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -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); diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index e665e4f8..f8570bee 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -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(); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 27a5cd0a..a6890d86 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -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" -- 2.34.1