Commit ec2dc851 authored by Gaurav Kukreja's avatar Gaurav Kukreja

fixing minor bug

Signed-off-by: Gaurav Kukreja's avatarGaurav Kukreja <gaurav@gauravk.in>
parent 4ddd677c
...@@ -47,6 +47,9 @@ def addAnnotationToDict(dict, lineNum, annot): ...@@ -47,6 +47,9 @@ def addAnnotationToDict(dict, lineNum, annot):
if lineNum not in dict: if lineNum not in dict:
dict[lineNum] = [annot] dict[lineNum] = [annot]
else: else:
for a in dict[lineNum]:
if a.annotation == annot.annotation and a.fileName == annot.fileName:
return
dict[lineNum].append(annot) dict[lineNum].append(annot)
def annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariables): def annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariables):
...@@ -191,7 +194,7 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo): ...@@ -191,7 +194,7 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
for funcISC in listISCFunctions: for funcISC in listISCFunctions:
lineNumISC = funcISC.startLine lineNumISC = funcISC.startLine
currFuncListParams = [] currFuncListParamsToAnnot = []
while True: while True:
lineNumISC = lineNumISC - 1 lineNumISC = lineNumISC - 1
lineISC = lc.getline(funcISC.fileName, lineNumISC) lineISC = lc.getline(funcISC.fileName, lineNumISC)
...@@ -205,8 +208,12 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo): ...@@ -205,8 +208,12 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
for param in listParams: for param in listParams:
m1 = re_VarSpec.match(param) m1 = re_VarSpec.match(param)
assert(m1 is not None) assert(m1 is not None)
paramName = m1.group("varName") varType = m1.group("varType")
currFuncListParams.append(paramName) varName = m1.group("varName")
varLen = m1.group("varLen")
m2 = re.match("(?:\s*\w*)*\*+\s*", varType)
if m2 is not None or varLen is not "":
currFuncListParamsToAnnot.append(varName)
break break
funcObj = find(lambda fn: fn.functionName == funcISC.functionName, listObjdumpFunctions) funcObj = find(lambda fn: fn.functionName == funcISC.functionName, listObjdumpFunctions)
...@@ -222,8 +229,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo): ...@@ -222,8 +229,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
lineAnnotations = parse_statement(lineISC) lineAnnotations = parse_statement(lineISC)
if lineAnnotations == None: if lineAnnotations == None:
continue continue
for annotation in lineAnnotations: while lineAnnotations:
if annotation[0] in currFuncListParams: annotation = lineAnnotations.pop()
if annotation[0] in currFuncListParamsToAnnot:
annot_str = annotation[1] annot_str = annotation[1]
annot = Annotation(annot_str, funcISC.fileName, lineNumISC, False) annot = Annotation(annot_str, funcISC.fileName, lineNumISC, False)
annot.debug() annot.debug()
...@@ -232,7 +240,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo): ...@@ -232,7 +240,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
annot) annot)
else: else:
for lsInfo in blockLSInfo: lenBlockLSInfo = len(blockLSInfo)
for i in range(lenBlockLSInfo):
lsInfo = blockLSInfo.pop(0)
if lsInfo.var != None and annotation[0] == lsInfo.var.name: if lsInfo.var != None and annotation[0] == lsInfo.var.name:
annot_str = annotation[1] annot_str = annotation[1]
annot = Annotation(annot_str, funcISC.fileName, lineNumISC, False) annot = Annotation(annot_str, funcISC.fileName, lineNumISC, False)
...@@ -240,23 +250,32 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo): ...@@ -240,23 +250,32 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
addAnnotationToDict(dictAnnotLoadStore, addAnnotationToDict(dictAnnotLoadStore,
lineNumISC, lineNumISC,
annot) annot)
break
else:
blockLSInfo.append(lsInfo)
print "******* LS Info could not be mapped in block %s" % blockObj.name
for lsInfo in blockLSInfo:
lsInfo.debug()
print "*******"
debugDictAnnot(dictAnnotLoadStore) debugDictAnnot(dictAnnotLoadStore)
return dictAnnotLoadStore return dictAnnotLoadStore
def generateOutputFileName(inFileName): def generateOutputFileName(outputPath, inFileName):
re_fileName = re.compile("(?P<path>/?(?:\w*/)*)(?P<fileName>\w*)\.(?P<fileExt>\w*)") re_fileName = re.compile("(?P<path>/?(?:\w*/)*)(?P<fileName>\w*)\.(?P<fileExt>\w*)")
m = re_fileName.match(inFileName) m = re_fileName.match(inFileName)
assert(m is not None) assert(m is not None)
filePath = m.group("path") inFilePath = m.group("path")
inFileNameWOExt = m.group("fileName") inFileNameWOExt = m.group("fileName")
inFileExt = m.group("fileExt") inFileExt = m.group("fileExt")
return filePath + inFileNameWOExt + "_ins." + inFileExt if outputPath is None:
outputPath = inFilePath
return outputPath + inFileNameWOExt + "_ins." + inFileExt
def annotateCache(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames): def generateAnnotatedSourceFiles(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames, outputPath):
for inFileName in listISCFileNames: for inFileName in listISCFileNames:
outFileName = generateOutputFileName(inFileName) outFileName = generateOutputFileName(outputPath, inFileName)
inFile = open(inFileName, "r") inFile = open(inFileName, "r")
outFile = open(outFileName, "w") outFile = open(outFileName, "w")
lineNum = 0 lineNum = 0
...@@ -309,7 +328,7 @@ def annotateCache(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames): ...@@ -309,7 +328,7 @@ def annotateCache(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames):
print ("Output to file : %s" % outFileName) print ("Output to file : %s" % outFileName)
def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames): def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames, outputPath):
(listISCFunctions, listObjdumpFunctions) = match_cfg(listISCFileNames, (listISCFunctions, listObjdumpFunctions) = match_cfg(listISCFileNames,
listObjdumpFileNames, listObjdumpFileNames,
...@@ -324,13 +343,13 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames) ...@@ -324,13 +343,13 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames)
listGlobalVariables, listGlobalVariables,
listLocalVariables) listLocalVariables)
debugListLSInfo(listLSInfo) # debugListLSInfo(listLSInfo)
dictAnnotVarFuncDecl = annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariables) dictAnnotVarFuncDecl = annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariables)
dictAnnotLoadStore = annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo) dictAnnotLoadStore = annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo)
annotateCache(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames) generateAnnotatedSourceFiles(dictAnnotVarFuncDecl, dictAnnotLoadStore, listISCFileNames, outputPath)
if __name__ == "__main__": if __name__ == "__main__":
...@@ -348,6 +367,10 @@ if __name__ == "__main__": ...@@ -348,6 +367,10 @@ if __name__ == "__main__":
type="string", dest="listBinaryFileNames", type="string", dest="listBinaryFileNames",
help="Binary Filename. For multiple files, use -b <filename> multiple times.", help="Binary Filename. For multiple files, use -b <filename> multiple times.",
metavar="FILE") metavar="FILE")
optparser.add_option("-p", "--outpath", action="store",
type="string", dest="outputPath",
help="Output Path to store the annotated source files.",
metavar="PATH")
(options, args) = optparser.parse_args() (options, args) = optparser.parse_args()
...@@ -357,5 +380,6 @@ if __name__ == "__main__": ...@@ -357,5 +380,6 @@ if __name__ == "__main__":
listISCFileNames = options.listISCFileNames listISCFileNames = options.listISCFileNames
listObjdumpFileNames = options.listObjdumpFileNames listObjdumpFileNames = options.listObjdumpFileNames
listBinaryFileNames = options.listBinaryFileNames listBinaryFileNames = options.listBinaryFileNames
outputPath = options.outputPath
instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames) instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames, outputPath)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment