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
d1dbeff0
Commit
d1dbeff0
authored
Sep 03, 2014
by
supriti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handling if statements
Signed-off-by:
Supriti Singh
<
supritisingh08@gmail.com
>
parent
957cf78e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
11 deletions
+29
-11
cGrammar.py
instrument/cGrammar.py
+29
-11
No files found.
instrument/cGrammar.py
View file @
d1dbeff0
...
@@ -82,7 +82,7 @@ array_name = ""
...
@@ -82,7 +82,7 @@ array_name = ""
array_index_lbrace_seen
=
0
array_index_lbrace_seen
=
0
array_index_string
=
""
array_index_string
=
""
assign_operator_seen
=
0
assign_operator_seen
=
0
isConditionalStatement
=
0
list_identifiers
=
[]
list_identifiers
=
[]
list_annotations
=
[]
list_annotations
=
[]
...
@@ -91,6 +91,8 @@ list_annotations = []
...
@@ -91,6 +91,8 @@ list_annotations = []
################################################################3
################################################################3
list_type_names
=
[
"short"
,
"int"
,
"long"
,
"char"
,
"float"
,
"double"
,
"void"
,
"signed"
,
"unsigned"
,
"uintptr_t"
]
list_type_names
=
[
"short"
,
"int"
,
"long"
,
"char"
,
"float"
,
"double"
,
"void"
,
"signed"
,
"unsigned"
,
"uintptr_t"
]
list_keywords
=
[
"if"
,
"else"
,
"switch"
,
"case"
,
"for"
,
"while"
,
"do"
,
"return"
]
# TODO: Extend this : struct_or_union, enum
# TODO: Extend this : struct_or_union, enum
type_specifier
=
(
SHORT
type_specifier
=
(
SHORT
...
@@ -136,7 +138,7 @@ def act_identifier(tokens):
...
@@ -136,7 +138,7 @@ def act_identifier(tokens):
global
list_identifiers
global
list_identifiers
global
list_annotations
global
list_annotations
if
tokens
[
0
]
not
in
list_type_names
:
if
tokens
[
0
]
not
in
list_type_names
and
tokens
[
0
]
not
in
list_keywords
:
# Deref Operation
# Deref Operation
if
deref_operator_seen
==
1
:
if
deref_operator_seen
==
1
:
# Deref Operation with Index
# Deref Operation with Index
...
@@ -380,8 +382,21 @@ expression << ( assignment_expression )
...
@@ -380,8 +382,21 @@ expression << ( assignment_expression )
# Full statement with ';'
# Full statement with ';'
statement
=
(
expression
+
SEMICOLON
+
stringEnd
)
expression_statement
=
(
expression
+
SEMICOLON
+
stringEnd
)
# statement.ignore(cStyleComment)
IF
=
Literal
(
"if"
)
ELSE
=
Literal
(
"else"
)
def
actConditionalStatement
(
tokens
):
global
isConditionalStatement
global
assign_operator_seen
isConditionalStatement
=
1
assign_operator_seen
=
1
selection_statement
=
(
IF
.
setParseAction
(
actConditionalStatement
)
+
LPAREN
+
expression
+
RPAREN
)
statement
=
(
expression_statement
|
selection_statement
)
def
ignore_statement
(
line
):
def
ignore_statement
(
line
):
m
=
re_Comment
.
match
(
line
)
m
=
re_Comment
.
match
(
line
)
...
@@ -389,11 +404,6 @@ def ignore_statement(line):
...
@@ -389,11 +404,6 @@ def ignore_statement(line):
logging
.
debug
(
"One Line Comment :
%
s"
%
line
)
logging
.
debug
(
"One Line Comment :
%
s"
%
line
)
return
True
return
True
m
=
re_ifStatement
.
match
(
line
)
if
m
is
not
None
:
logging
.
debug
(
"If Statement :
%
s"
%
line
)
return
True
m
=
re_elseStatement
.
match
(
line
)
m
=
re_elseStatement
.
match
(
line
)
if
m
is
not
None
:
if
m
is
not
None
:
logging
.
debug
(
"Else Statement :
%
s"
%
line
)
logging
.
debug
(
"Else Statement :
%
s"
%
line
)
...
@@ -419,6 +429,7 @@ def parse_statement(line):
...
@@ -419,6 +429,7 @@ def parse_statement(line):
global
array_name
global
array_name
global
array_index_lbrace_seen
global
array_index_lbrace_seen
global
array_index_string
global
array_index_string
global
isConditionalStatement
global
list_identifiers
global
list_identifiers
global
list_annotations
global
list_annotations
global
assign_operator_seen
global
assign_operator_seen
...
@@ -438,10 +449,12 @@ def parse_statement(line):
...
@@ -438,10 +449,12 @@ def parse_statement(line):
array_index_lbrace_seen
=
0
array_index_lbrace_seen
=
0
array_index_string
=
""
array_index_string
=
""
assign_operator_seen
=
0
assign_operator_seen
=
0
isConditionalStatement
=
0
list_identifiers
=
[]
list_identifiers
=
[]
list_annotations
=
[]
list_annotations
=
[]
r
=
statement
.
parseString
(
line
)
r
=
statement
.
parseString
(
line
)
print
r
return
list_annotations
return
list_annotations
...
@@ -455,6 +468,7 @@ def test():
...
@@ -455,6 +468,7 @@ def test():
,
"valpred = state->valprev;"
,
"valpred = state->valprev;"
,
"valpred = state.valprev;"
,
"valpred = state.valprev;"
,
"valpred_41 = (valpred_34 > -32768) ? valpred_35 : -32768;"
,
"valpred_41 = (valpred_34 > -32768) ? valpred_35 : -32768;"
,
"if (a == b)"
]
]
expected_annotations
=
[[(
"start"
,
"simDCache((start_addr), 0);"
),
expected_annotations
=
[[(
"start"
,
"simDCache((start_addr), 0);"
),
...
@@ -487,7 +501,9 @@ def test():
...
@@ -487,7 +501,9 @@ def test():
[(
"valpred_41"
,
"simDCache((valpred_41_addr), 0);"
),
[(
"valpred_41"
,
"simDCache((valpred_41_addr), 0);"
),
(
"valpred_34"
,
"simDCache((valpred_34_addr), 1);"
),
(
"valpred_34"
,
"simDCache((valpred_34_addr), 1);"
),
(
"valpred_35"
,
"simDCache((valpred_35_addr), 1);"
)
(
"valpred_35"
,
"simDCache((valpred_35_addr), 1);"
)
]
],
[(
"a"
,
"simDCache((a_addr), 1);"
),
(
"b"
,
"simDCache((b_addr), 1);"
)]
]
]
...
@@ -504,6 +520,8 @@ def test():
...
@@ -504,6 +520,8 @@ def test():
return
-
1
return
-
1
print
"Tests passed!"
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
...
...
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