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):
return
dict
[
lineNum
]
.
append
(
annot
)
def
annotateVarFuncDecl
(
listISCFileNames
,
listGlobalVariables
,
listLocalVariables
):
def
annotateVarFuncDecl
(
listISCFileNames
,
list
ISCFunctions
,
list
GlobalVariables
,
listLocalVariables
):
dictAnnotVarFuncDecl
=
OrderedDict
({})
for
ISCFileName
in
listISCFileNames
:
...
...
@@ -148,28 +148,26 @@ def annotateVarFuncDecl(listISCFileNames, listGlobalVariables, listLocalVariable
if
m
is
not
None
:
inFunction
=
1
currFunctionName
=
m
.
group
(
"name"
)
currFuncRetType
=
m
.
group
(
"retType"
)
logging
.
debug
(
" Function : "
+
currFunctionName
)
funcRetType
=
m
.
group
(
"retType"
)
funcParams
=
m
.
group
(
"params"
)
if
funcParams
is
not
None
:
funcISC
=
find
(
lambda
fn
:
fn
.
functionName
==
currFunctionName
,
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
=
[]
logging
.
debug
(
" Parameters : "
+
funcParams
)
listParams
=
funcParams
.
split
(
","
)
for
param
in
listParams
:
newFuncParamsList
.
append
(
param
)
m1
=
re_VarSpec
.
match
(
param
)
if
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
""
:
# must be annotated
newFuncParamsList
.
append
(
"unsigned long
%
s_addr"
%
varName
)
annotatedFuncDecl
=
"
%
s
%
s ("
%
(
funcRetType
,
currFunctionName
)
for
param
in
funcISC
.
listParams
:
newFuncParamsList
.
append
(
param
.
type
+
param
.
name
+
param
.
len
)
if
param
.
isPointer
:
newFuncParamsList
.
append
(
"unsigned long "
+
param
.
name
+
"_addr"
)
# create the new annotation
annotatedFuncDecl
=
currFuncRetType
+
" "
+
currFunctionName
+
" ("
for
param
in
newFuncParamsList
[:
-
1
]:
annotatedFuncDecl
=
annotatedFuncDecl
+
param
+
", "
annotatedFuncDecl
=
annotatedFuncDecl
+
newFuncParamsList
[
-
1
]
+
")"
annot
=
Annotation
(
annotatedFuncDecl
,
ISCFileName
,
lineNum
,
...
...
@@ -195,26 +193,9 @@ def annotateLoadStore(listISCFunctions, listObjdumpFunctions, listLSInfo):
for
funcISC
in
listISCFunctions
:
lineNumISC
=
funcISC
.
startLine
currFuncListParamsToAnnot
=
[]
while
True
:
lineNumISC
=
lineNumISC
-
1
lineISC
=
lc
.
getline
(
funcISC
.
fileName
,
lineNumISC
)
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
for
param
in
funcISC
.
listParams
:
if
param
.
isPointer
:
currFuncListParamsToAnnot
.
append
(
param
.
name
)
funcObj
=
find
(
lambda
fn
:
fn
.
functionName
==
funcISC
.
functionName
,
listObjdumpFunctions
)
for
blockObj
in
funcObj
.
cfg
.
listBlocks
:
...
...
@@ -345,7 +326,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
# debugListLSInfo(listLSInfo)
dictAnnotVarFuncDecl
=
annotateVarFuncDecl
(
listISCFileNames
,
listGlobalVariables
,
listLocalVariables
)
dictAnnotVarFuncDecl
=
annotateVarFuncDecl
(
listISCFileNames
,
list
ISCFunctions
,
list
GlobalVariables
,
listLocalVariables
)
dictAnnotLoadStore
=
annotateLoadStore
(
listISCFunctions
,
listObjdumpFunctions
,
listLSInfo
)
...
...
@@ -353,7 +334,7 @@ def instrumentCache(listISCFileNames, listObjdumpFileNames, listBinaryFileNames,
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
optparser
=
OptionParser
()
optparser
.
add_option
(
"-i"
,
"--isc"
,
action
=
"append"
,
dest
=
"listISCFileNames"
,
...
...
instrument/cfg.py
View file @
5e56ab32
import
sys
from
collections
import
deque
import
logging
from
irc_regex
import
re_VarSpec
class
ParseError
(
Exception
):
def
__init__
(
self
,
str
):
...
...
@@ -191,16 +192,44 @@ class ControlFlowGraph:
exit
(
1
)
else
:
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
:
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
.
fileName
=
fileName
self
.
startLine
=
startLine
self
.
endLine
=
endLine
self
.
cfg
=
cfg
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
):
self
.
stackSize
=
stackSize
\ No newline at end of file
instrument/cfg_isc.py
View file @
5e56ab32
...
...
@@ -22,6 +22,7 @@ def parse_isc(fileName):
inFunctionBody
=
0
# is 1, when inside Function Body
inFuncDefArgMultiLine
=
0
# is 1, when inside multiline argument list for func Def.
currFuncName
=
""
currFuncParamStr
=
""
currFuncStartLine
=
0
currFuncEndLine
=
0
listCurrFuncBasicBlocks
=
[]
...
...
@@ -87,12 +88,14 @@ def parse_isc(fileName):
if
m
.
group
(
"openBrace"
)
==
""
:
# 1.b. Multi Line Function Arguments
inFuncDefArgMultiLine
=
1
currFuncName
=
m
.
group
(
1
)
currFuncName
=
m
.
group
(
"name"
)
currFuncParamStr
=
m
.
group
(
"params"
)
continue
else
:
# 1.a. Single Line Definition
inFunctionBody
=
1
currFuncName
=
m
.
group
(
"name"
)
currFuncParamStr
=
m
.
group
(
"params"
)
currFuncStartLine
=
lineNum
+
1
continue
...
...
@@ -102,9 +105,11 @@ def parse_isc(fileName):
if
m
is
not
None
:
if
m
.
group
(
"openBrace"
)
==
""
:
# Next line is still argument list
currFuncParamStr
=
currFuncParamStr
+
m
.
group
(
"params"
)
continue
else
:
# End of Argument List. Start of function body in next line.
currFuncParamStr
=
currFuncParamStr
+
m
.
group
(
"params"
)
inFuncDefArgMultiLine
=
0
inFunctionBody
=
1
currFuncStartLine
=
lineNum
+
1
...
...
@@ -216,12 +221,14 @@ def parse_isc(fileName):
currFuncStartLine
,
currFuncEndLine
,
ControlFlowGraph
(
listCurrFuncBasicBlocks
,
listCurrFuncBBEdges
)))
listCurrFuncBBEdges
),
paramStr
=
currFuncParamStr
))
# Resetting State Variables
inFunctionBody
=
0
inFuncDefArgMultiLine
=
0
currFuncName
=
""
currFuncParamStr
=
""
currFuncStartLine
=
0
currFuncEndLine
=
0
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