Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
H
hostCompiledSimulation
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
hostCompiledSimulation
Commits
5e56ab32
Commit
5e56ab32
authored
Sep 07, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization about function parameters, Dont Trust
Signed-off-by:
Gaurav Kukreja
<
gaurav@gauravk.in
>
parent
4887d42d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
44 deletions
+61
-44
cacheSimInstrument.py
instrument/cacheSimInstrument.py
+21
-40
cfg.py
instrument/cfg.py
+31
-2
cfg_isc.py
instrument/cfg_isc.py
+9
-2
No files found.
instrument/cacheSimInstrument.py
View file @
5e56ab32
...
@@ -52,7 +52,7 @@ def addAnnotationToDict(dict, lineNum, annot):
...
@@ -52,7 +52,7 @@ def addAnnotationToDict(dict, lineNum, annot):
return
return
dict
[
lineNum
]
.
append
(
annot
)
dict
[
lineNum
]
.
append
(
annot
)
def
annotateVarFuncDecl
(
listISCFileNames
,
listGlobalVariables
,
listLocalVariables
):
def
annotateVarFuncDecl
(
listISCFileNames
,
list
ISCFunctions
,
list
GlobalVariables
,
listLocalVariables
):
dictAnnotVarFuncDecl
=
OrderedDict
({})
dictAnnotVarFuncDecl
=
OrderedDict
({})
for
ISCFileName
in
listISCFileNames
:
for
ISCFileName
in
listISCFileNames
:
...
@@ -148,28 +148,26 @@ def annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariable
...
@@ -148,28 +148,26 @@ def annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariable
if
m
is
not
None
:
if
m
is
not
None
:
inFunction
=
1
inFunction
=
1
currFunctionName
=
m
.
group
(
"name"
)
currFunctionName
=
m
.
group
(
"name"
)
currFuncRetType
=
m
.
group
(
"retType"
)
logging
.
debug
(
" Function : "
+
currFunctionName
)
logging
.
debug
(
" Function : "
+
currFunctionName
)
funcRetType
=
m
.
group
(
"retType"
)
funcParams
=
m
.
group
(
"params"
)
funcISC
=
find
(
lambda
fn
:
fn
.
functionName
==
currFunctionName
,
if
funcParams
is
not
None
:
listISCFunctions
)
if
funcISC
.
listParams
:
# Create a list of new parameters for the annotated function signature
# Add <name>_addr parameter for each param that is a pointer
newFuncParamsList
=
[]
newFuncParamsList
=
[]
logging
.
debug
(
" Parameters : "
+
funcParams
)
for
param
in
funcISC
.
listParams
:
listParams
=
funcParams
.
split
(
","
)
newFuncParamsList
.
append
(
param
.
type
+
param
.
name
+
param
.
len
)
for
param
in
listParams
:
if
param
.
isPointer
:
newFuncParamsList
.
append
(
param
)
newFuncParamsList
.
append
(
"unsigned long "
+
param
.
name
+
"_addr"
)
m1
=
re_VarSpec
.
match
(
param
)
if
m1
is
not
None
:
# create the new annotation
varType
=
m1
.
group
(
"varType"
)
annotatedFuncDecl
=
currFuncRetType
+
" "
+
currFunctionName
+
" ("
varName
=
m1
.
group
(
"varName"
)
varLen
=
m1
.
group
(
"varLen"
)
m2
=
re
.
match
(
"(?:
\
s*
\
w*)*
\
*+
\
s*"
,
varType
)
if
m2
is
not
None
or
varLen
is
not
""
:
# must be annotated
newFuncParamsList
.
append
(
"unsigned long
%
s_addr"
%
varName
)
annotatedFuncDecl
=
"
%
s
%
s ("
%
(
funcRetType
,
currFunctionName
)
for
param
in
newFuncParamsList
[:
-
1
]:
for
param
in
newFuncParamsList
[:
-
1
]:
annotatedFuncDecl
=
annotatedFuncDecl
+
param
+
", "
annotatedFuncDecl
=
annotatedFuncDecl
+
param
+
", "
annotatedFuncDecl
=
annotatedFuncDecl
+
newFuncParamsList
[
-
1
]
+
")"
annotatedFuncDecl
=
annotatedFuncDecl
+
newFuncParamsList
[
-
1
]
+
")"
annot
=
Annotation
(
annotatedFuncDecl
,
annot
=
Annotation
(
annotatedFuncDecl
,
ISCFileName
,
ISCFileName
,
lineNum
,
lineNum
,
...
@@ -195,26 +193,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
...
@@ -195,26 +193,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
for
funcISC
in
listISCFunctions
:
for
funcISC
in
listISCFunctions
:
lineNumISC
=
funcISC
.
startLine
lineNumISC
=
funcISC
.
startLine
currFuncListParamsToAnnot
=
[]
currFuncListParamsToAnnot
=
[]
while
True
:
for
param
in
funcISC
.
listParams
:
lineNumISC
=
lineNumISC
-
1
if
param
.
isPointer
:
lineISC
=
lc
.
getline
(
funcISC
.
fileName
,
lineNumISC
)
currFuncListParamsToAnnot
.
append
(
param
.
name
)
m
=
re_FuncDefStart
.
match
(
lineISC
)
if
m
is
None
:
continue
else
:
funcParams
=
m
.
group
(
"params"
)
if
funcParams
is
not
None
:
listParams
=
funcParams
.
split
(
","
)
for
param
in
listParams
:
m1
=
re_VarSpec
.
match
(
param
)
assert
(
m1
is
not
None
)
varType
=
m1
.
group
(
"varType"
)
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
funcObj
=
find
(
lambda
fn
:
fn
.
functionName
==
funcISC
.
functionName
,
listObjdumpFunctions
)
funcObj
=
find
(
lambda
fn
:
fn
.
functionName
==
funcISC
.
functionName
,
listObjdumpFunctions
)
for
blockObj
in
funcObj
.
cfg
.
listBlocks
:
for
blockObj
in
funcObj
.
cfg
.
listBlocks
:
...
@@ -345,7 +326,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
...
@@ -345,7 +326,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
# debugListLSInfo(listLSInfo)
# debugListLSInfo(listLSInfo)
dictAnnotVarFuncDecl
=
annotateVarFuncDecl
(
listISCFileNames
,
listGlobalVariables
,
listLocalVariables
)
dictAnnotVarFuncDecl
=
annotateVarFuncDecl
(
listISCFileNames
,
list
ISCFunctions
,
list
GlobalVariables
,
listLocalVariables
)
dictAnnotLoadStore
=
annotateLoadStore
(
listISCFunctions
,
listObjdumpFunctions
,
listLSInfo
)
dictAnnotLoadStore
=
annotateLoadStore
(
listISCFunctions
,
listObjdumpFunctions
,
listLSInfo
)
...
@@ -353,7 +334,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
...
@@ -353,7 +334,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
optparser
=
OptionParser
()
optparser
=
OptionParser
()
optparser
.
add_option
(
"-i"
,
"--isc"
,
action
=
"append"
,
dest
=
"listISCFileNames"
,
optparser
.
add_option
(
"-i"
,
"--isc"
,
action
=
"append"
,
dest
=
"listISCFileNames"
,
...
...
instrument/cfg.py
View file @
5e56ab32
import
sys
import
sys
from
collections
import
deque
from
collections
import
deque
import
logging
import
logging
from
irc_regex
import
re_VarSpec
class
ParseError
(
Exception
):
class
ParseError
(
Exception
):
def
__init__
(
self
,
str
):
def
__init__
(
self
,
str
):
...
@@ -191,16 +192,44 @@ class ControlFlowGraph:
...
@@ -191,16 +192,44 @@ class ControlFlowGraph:
exit
(
1
)
exit
(
1
)
else
:
else
:
self
.
listBlocks
[
currBlockIndex
]
.
flow
=
currBlockFlow
self
.
listBlocks
[
currBlockIndex
]
.
flow
=
currBlockFlow
class
FunctionParam
:
def
__init__
(
self
,
type
,
name
,
len
,
isPointer
):
self
.
type
=
type
self
.
name
=
name
self
.
len
=
len
self
.
isPointer
=
isPointer
class
FunctionDesc
:
class
FunctionDesc
:
def
__init__
(
self
,
functionName
,
fileName
,
startLine
,
endLine
,
cfg
,
stackSize
=
-
1
):
def
__init__
(
self
,
functionName
,
fileName
,
startLine
,
endLine
,
cfg
,
stackSize
=
-
1
,
paramStr
=
None
):
self
.
functionName
=
functionName
self
.
functionName
=
functionName
self
.
fileName
=
fileName
self
.
fileName
=
fileName
self
.
startLine
=
startLine
self
.
startLine
=
startLine
self
.
endLine
=
endLine
self
.
endLine
=
endLine
self
.
cfg
=
cfg
self
.
cfg
=
cfg
self
.
stackSize
=
stackSize
self
.
stackSize
=
stackSize
self
.
paramStr
=
paramStr
self
.
listParams
=
[]
if
paramStr
is
not
None
and
paramStr
is
not
""
:
print
"******"
print
paramStr
print
"******"
listParams
=
paramStr
.
split
(
","
)
for
param
in
listParams
:
m
=
re_VarSpec
.
match
(
param
)
paramType
=
m
.
group
(
"varType"
)
paramName
=
m
.
group
(
"varName"
)
paramLen
=
m
.
group
(
"varLen"
)
if
paramType
.
endswith
(
"*"
)
or
paramLen
is
not
""
:
print
"GKUKREJA:
%
s is param pointer"
%
paramName
paramIsPointer
=
True
else
:
paramIsPointer
=
False
print
"GKUKREJA:
%
s is not param pointer"
%
paramName
self
.
listParams
.
append
(
FunctionParam
(
paramType
,
paramName
,
paramLen
,
paramIsPointer
))
else
:
print
"GKUKREJA: No Params"
def
setStackSize
(
self
,
stackSize
):
def
setStackSize
(
self
,
stackSize
):
self
.
stackSize
=
stackSize
self
.
stackSize
=
stackSize
\ No newline at end of file
instrument/cfg_isc.py
View file @
5e56ab32
...
@@ -22,6 +22,7 @@ def parse_isc(fileName):
...
@@ -22,6 +22,7 @@ def parse_isc(fileName):
inFunctionBody
=
0
# is 1, when inside Function Body
inFunctionBody
=
0
# is 1, when inside Function Body
inFuncDefArgMultiLine
=
0
# is 1, when inside multiline argument list for func Def.
inFuncDefArgMultiLine
=
0
# is 1, when inside multiline argument list for func Def.
currFuncName
=
""
currFuncName
=
""
currFuncParamStr
=
""
currFuncStartLine
=
0
currFuncStartLine
=
0
currFuncEndLine
=
0
currFuncEndLine
=
0
listCurrFuncBasicBlocks
=
[]
listCurrFuncBasicBlocks
=
[]
...
@@ -87,12 +88,14 @@ def parse_isc(fileName):
...
@@ -87,12 +88,14 @@ def parse_isc(fileName):
if
m
.
group
(
"openBrace"
)
==
""
:
if
m
.
group
(
"openBrace"
)
==
""
:
# 1.b. Multi Line Function Arguments
# 1.b. Multi Line Function Arguments
inFuncDefArgMultiLine
=
1
inFuncDefArgMultiLine
=
1
currFuncName
=
m
.
group
(
1
)
currFuncName
=
m
.
group
(
"name"
)
currFuncParamStr
=
m
.
group
(
"params"
)
continue
continue
else
:
else
:
# 1.a. Single Line Definition
# 1.a. Single Line Definition
inFunctionBody
=
1
inFunctionBody
=
1
currFuncName
=
m
.
group
(
"name"
)
currFuncName
=
m
.
group
(
"name"
)
currFuncParamStr
=
m
.
group
(
"params"
)
currFuncStartLine
=
lineNum
+
1
currFuncStartLine
=
lineNum
+
1
continue
continue
...
@@ -102,9 +105,11 @@ def parse_isc(fileName):
...
@@ -102,9 +105,11 @@ def parse_isc(fileName):
if
m
is
not
None
:
if
m
is
not
None
:
if
m
.
group
(
"openBrace"
)
==
""
:
if
m
.
group
(
"openBrace"
)
==
""
:
# Next line is still argument list
# Next line is still argument list
currFuncParamStr
=
currFuncParamStr
+
m
.
group
(
"params"
)
continue
continue
else
:
else
:
# End of Argument List. Start of function body in next line.
# End of Argument List. Start of function body in next line.
currFuncParamStr
=
currFuncParamStr
+
m
.
group
(
"params"
)
inFuncDefArgMultiLine
=
0
inFuncDefArgMultiLine
=
0
inFunctionBody
=
1
inFunctionBody
=
1
currFuncStartLine
=
lineNum
+
1
currFuncStartLine
=
lineNum
+
1
...
@@ -216,12 +221,14 @@ def parse_isc(fileName):
...
@@ -216,12 +221,14 @@ def parse_isc(fileName):
currFuncStartLine
,
currFuncStartLine
,
currFuncEndLine
,
currFuncEndLine
,
ControlFlowGraph
(
listCurrFuncBasicBlocks
,
ControlFlowGraph
(
listCurrFuncBasicBlocks
,
listCurrFuncBBEdges
)))
listCurrFuncBBEdges
),
paramStr
=
currFuncParamStr
))
# Resetting State Variables
# Resetting State Variables
inFunctionBody
=
0
inFunctionBody
=
0
inFuncDefArgMultiLine
=
0
inFuncDefArgMultiLine
=
0
currFuncName
=
""
currFuncName
=
""
currFuncParamStr
=
""
currFuncStartLine
=
0
currFuncStartLine
=
0
currFuncEndLine
=
0
currFuncEndLine
=
0
listCurrFuncBasicBlocks
=
[]
listCurrFuncBasicBlocks
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment