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
e4d2c02f
Commit
e4d2c02f
authored
Sep 01, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes to irc_regex
Signed-off-by:
Gaurav Kukreja
<
gaurav@gauravk.in
>
parent
bf148626
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
15 deletions
+98
-15
irc_regex.py
instrument/irc_regex.py
+98
-15
No files found.
instrument/irc_regex.py
View file @
e4d2c02f
import
re
import
re
import
logging
import
logging
from
cGrammar
import
parse_statement
# Comments
# Comments
re_CommentStart
=
re
.
compile
(
"
\
s*/
\
*.*"
)
re_CommentStart
=
re
.
compile
(
"
\
s*/
\
*.*"
)
...
@@ -13,14 +14,20 @@ PreProcDir = "\s*#(?:include|define|ifndef|endif).*"
...
@@ -13,14 +14,20 @@ PreProcDir = "\s*#(?:include|define|ifndef|endif).*"
re_PreProcDir
=
re
.
compile
(
"(?:
%
s)"
%
PreProcDir
)
re_PreProcDir
=
re
.
compile
(
"(?:
%
s)"
%
PreProcDir
)
# Variable Declarations
# Variable Declarations
TypeSpecifiers
=
"char|int|float|double"
TypeSpecifiers
=
"char|int|float|double
|short|long
"
OptionalSpecifiers
=
"signed|unsigned
|short|long
"
OptionalSpecifiers
=
"signed|unsigned"
StorageClass
=
"(?:static|extern|auto|register)"
StorageClass
=
"(?:static|extern|auto|register)"
UserDefined
=
"struct
\
s*[
\
w_]*"
UserDefined
=
"struct
\
s*[
\
w_]*"
IRCSpecific
=
"uintptr_t"
IRCSpecific
=
"uintptr_t"
DataTypes
=
"(
?:
%
s)?
\
s*(?:
%
s
\
s*)*
\
s*(?:(?:
%
s)|(?:
%
s)|(?:
%
s))?
\
s*
(?:
\
*)*"
%
(
StorageClass
,
OptionalSpecifiers
,
TypeSpecifiers
,
UserDefined
,
IRCSpecific
)
DataTypes
=
"(
(?:(?:
%
s)|(?:
%
s)|(?:
%
s)|(?:
%
s)|(?:
%
s))
\
s*)+
(?:
\
*)*"
%
(
StorageClass
,
OptionalSpecifiers
,
TypeSpecifiers
,
UserDefined
,
IRCSpecific
)
VarSpec
=
"(?P<varType>
%
s)
\
s*(?P<varName>
\
w*)
\
s*(?P<varLen>(?:
\
[.*
\
])*)?"
%
(
DataTypes
)
VarSpec
=
"(?P<varType>
%
s)
\
s*(?P<varName>
\
w*)
\
s*(?P<varLen>(?:
\
[.*
\
])*)?"
%
(
DataTypes
)
re_VarDecl
=
re
.
compile
(
"
\
s*(?:
%
s);"
%
(
VarSpec
))
VarSpecInitOneLine
=
"(?:
%
s)
\
s*=
\
s*((?:
\
{.*
\
})|(?:.*))"
%
(
VarSpec
)
VarSpecInitMultiLine
=
"(?:
%
s)
\
s*=
\
s*(?:
\
{.*)"
%
(
VarSpec
)
VarSpecInitMultiLineEnd
=
"
\
s*.*}
\
s*"
re_VarDecl
=
re
.
compile
(
"
\
s*(?:
%
s)
\
s*;"
%
(
VarSpec
))
re_VarDeclInitOneLine
=
re
.
compile
(
"
\
s*(?:
%
s)
\
s*;"
%
(
VarSpecInitOneLine
))
re_VarDeclInitMultiLine
=
re
.
compile
(
"
\
s*(?:
%
s)"
%
(
VarSpecInitMultiLine
))
re_VarDeclInitMultiLineEnd
=
re
.
compile
(
"
\
s*(?:
%
s)
\
s*;"
%
(
VarSpecInitMultiLineEnd
))
# Function Definition Start
# Function Definition Start
VarSpec_
=
"(?:
%
s)
\
s*(?:
\
w*)
\
s*(?:(?:
\
[.*
\
])*)?"
%
(
DataTypes
)
VarSpec_
=
"(?:
%
s)
\
s*(?:
\
w*)
\
s*(?:(?:
\
[.*
\
])*)?"
%
(
DataTypes
)
...
@@ -31,11 +38,30 @@ re_FuncDefStart = re.compile("\s*(?P<retType>%s)?\s*(?P<name>\w*)\s*\((?P<params
...
@@ -31,11 +38,30 @@ re_FuncDefStart = re.compile("\s*(?P<retType>%s)?\s*(?P<name>\w*)\s*\((?P<params
# Label
# Label
re_Label
=
re
.
compile
(
"
\
s*(?P<label>
\
w*):"
)
re_Label
=
re
.
compile
(
"
\
s*(?P<label>
\
w*):"
)
# Assignment/Arithmetic
# If Statement
Var
=
"(?:
\
s*
\
w*
\
s*)"
re_ifStatement
=
re
.
compile
(
"
\
s*if
\
s*
\
(.*
\
)"
)
Const
=
"(?:
\
s*
\
d*
\
s*)"
re_elseStatement
=
re
.
compile
(
"
\
s*else
\
s*"
)
Oper
=
"(?:
\
+|
\
-|
\
*|/)"
re_Assign
=
re
.
compile
(
"
\
s*.*
\
s*=
\
s*.*;"
)
# Goto Instructions
re_gotoStatement
=
re
.
compile
(
"
\
s*goto
\
s*
\
w*;"
)
# Struct Declaration Start
re_structDecl
=
re
.
compile
(
"
\
s*struct
\
s*
\
w*
\
s*{.*};$"
)
re_structDeclMultiLine
=
re
.
compile
(
"
\
s*struct
\
s*
\
w*
\
s*{
\
s*$"
)
# Extra
re_BlockStartLBrace
=
re
.
compile
(
"^
\
s*
\
{
\
s*$"
)
re_BlockEndRBrace
=
re
.
compile
(
"^
\
s*
\
}
\
s*$"
)
re_returnStatement
=
re
.
compile
(
"^
\
s*return
\
s*.*;
\
s*$"
)
re_functionCallStatement
=
re
.
compile
(
"
\
s*
\
w*
\
s*
\
(.*
\
);
\
s*"
)
# [&\s,\w\[\]\(\)\*]
#
# # Assignment/Arithmetic
# Var = "(?:\s*\w*\s*)"
# Const = "(?:\s*\d*\s*)"
# Oper = "(?:\+|\-|\*|/)"
# re_Assign = re.compile("\s*.*\s*=\s*.*;")
inMultiLineComment
=
False
inMultiLineComment
=
False
...
@@ -78,18 +104,34 @@ def shouldIgnore(line, lineNum):
...
@@ -78,18 +104,34 @@ def shouldIgnore(line, lineNum):
elif
isPreProcDir
(
line
,
lineNum
):
elif
isPreProcDir
(
line
,
lineNum
):
return
True
return
True
elif
line
==
""
:
elif
line
.
isspace
():
# logging.debug("%d: Empty Line" % lineNum)
return
True
elif
re_BlockStartLBrace
.
match
(
line
):
return
True
elif
re_BlockEndRBrace
.
match
(
line
):
return
True
elif
re_returnStatement
.
match
(
line
):
return
True
elif
re_functionCallStatement
.
match
(
line
):
return
True
return
True
return
False
return
False
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
# fileName = "examples/adpcm/my_ctop_IR.c"
# fileName = "examples/adpcm/my_ctop_IR.c"
fileName
=
"examples/adpcm/adpcm_IR.c"
# fileName = "examples/adpcm/adpcm_IR.c"
fileName
=
"examples/sieve/erat_sieve_no_print_IR.c"
file
=
open
(
fileName
,
"r"
)
file
=
open
(
fileName
,
"r"
)
inMultiLineVarInit
=
0
inStructDeclaration
=
0
lineNum
=
0
lineNum
=
0
for
line
in
file
:
for
line
in
file
:
...
@@ -98,6 +140,28 @@ if __name__ == "__main__":
...
@@ -98,6 +140,28 @@ if __name__ == "__main__":
if
shouldIgnore
(
line
,
lineNum
):
if
shouldIgnore
(
line
,
lineNum
):
continue
continue
if
inMultiLineVarInit
==
1
:
m
=
re_VarDeclInitMultiLineEnd
.
match
(
line
)
if
m
is
not
None
:
logging
.
debug
(
"
%
d: VarDecl MultiLine End "
%
(
lineNum
))
inMultiLineVarInit
=
0
continue
else
:
continue
m
=
re_VarDeclInitOneLine
.
match
(
line
)
if
m
is
not
None
:
varName
=
m
.
group
(
"varName"
)
logging
.
debug
(
"
%
d: VarDecl InitOneLine:
\"
%
s
\"
"
%
(
lineNum
,
varName
))
continue
m
=
re_VarDeclInitMultiLine
.
match
(
line
)
if
m
is
not
None
:
varName
=
m
.
group
(
"varName"
)
logging
.
debug
(
"
%
d: VarDecl InitMultiLine:
\"
%
s
\"
"
%
(
lineNum
,
varName
))
inMultiLineVarInit
=
1
;
continue
m
=
re_VarDecl
.
match
(
line
)
m
=
re_VarDecl
.
match
(
line
)
if
m
is
not
None
:
if
m
is
not
None
:
varName
=
m
.
group
(
"varName"
)
varName
=
m
.
group
(
"varName"
)
...
@@ -116,7 +180,26 @@ if __name__ == "__main__":
...
@@ -116,7 +180,26 @@ if __name__ == "__main__":
logging
.
debug
(
"
%
d: Label:
\"
%
s
\"
"
%
(
lineNum
,
label
))
logging
.
debug
(
"
%
d: Label:
\"
%
s
\"
"
%
(
lineNum
,
label
))
continue
continue
m
=
m
=
re_ifStatement
.
match
(
line
)
if
m
is
not
None
:
logging
.
debug
(
"
%
d: If Statement."
)
continue
m
=
re_elseStatement
.
match
(
line
)
if
m
is
not
None
:
logging
.
debug
(
"
%
d: Else Statement."
)
continue
m
=
re_gotoStatement
.
match
(
line
)
if
m
is
not
None
:
logging
.
debug
(
"
%
d: Goto Statement."
)
continue
print
""
logging
.
info
(
"
%
d:
%
s"
%
(
lineNum
,
line
[
0
:
-
1
]))
annotations
=
parse_statement
(
line
)
for
annotation
in
annotations
:
print
"
%
s ::
%
s"
%
(
annotation
[
0
],
annotation
[
1
])
continue
continue
\ No newline at end of file
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