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
37eafe49
Commit
37eafe49
authored
May 28, 2014
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverted all python files in ir2c code, to solve issues
Signed-off-by:
Gaurav Kukreja
<
gaurav@gauravk.in
>
parent
f2aa5106
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
357 additions
and
388 deletions
+357
-388
AliasFile.py
ir2c/src/AliasFile.py
+26
-41
BlocksFile.py
ir2c/src/BlocksFile.py
+126
-128
CFile.py
ir2c/src/CFile.py
+87
-99
fn.py
ir2c/src/fn.py
+18
-22
ir2c.py
ir2c/src/ir2c.py
+3
-2
mem.py
ir2c/src/mem.py
+97
-96
No files found.
ir2c/src/AliasFile.py
View file @
37eafe49
#
import sys
import
sys
import
re
import
fn
import
logging
def
process
(
sourceFile
,
fnHash
):
"""
Reads the '.alias' file generated by the compiler frontend, to create a hash
table of the local and global variables accessed by a function in the source
code.
"""
# Open alias file
f
=
open
(
sourceFile
+
'.055t.alias
'
);
def
process
(
sourceFile
,
fnHash
):
f
=
open
(
sourceFile
+
'.055t.alias'
);
#'.t29.alias1
');
line
=
f
.
readline
();
# Regular Expressions
re_fnStart
=
re
.
compile
(
';; Function'
);
re_word
=
re
.
compile
(
'
\
w+'
);
re_varStart
=
re
.
compile
(
'Referenced variables in '
);
re_varLine
=
re
.
compile
(
'Variable:'
);
re_getVar
=
re
.
compile
(
'Variable: |, |
\n
'
);
var_read
=
0
;
re_fnStart
=
re
.
compile
(
';; Function'
);
re_word
=
re
.
compile
(
'
\
w+'
);
re_varStart
=
re
.
compile
(
'Referenced variables in '
);
re_varLine
=
re
.
compile
(
'Variable:'
);
re_getVar
=
re
.
compile
(
'Variable: |, |
\n
'
);
var_read
=
0
while
line
:
if
re_fnStart
.
match
(
line
):
m
=
re_word
.
findall
(
line
);
fnName
=
m
[
1
];
fnHash
[
fnName
]
=
fn
.
Function
(
fnName
);
logging
.
debug
(
"Function Name: "
+
fnName
);
m
=
re_word
.
findall
(
line
);
fnName
=
m
[
1
];
fnHash
[
fnName
]
=
fn
.
Function
(
fnName
);
#print fnName; #############debugging
if
var_read
==
1
:
if
re_varLine
.
match
(
line
):
m
=
re_getVar
.
split
(
line
);
m
[
3
]
=
re
.
sub
(
r'\{.*\}'
,
''
,
m
[
3
]);
logging
.
debug
(
"
\t
Variable Name: "
+
m
[
1
]
+
", Variable Type: "
+
m
[
3
]);
fnHash
[
fnName
]
.
addVar
(
varName
=
m
[
1
]
.
strip
(),
varType
=
m
[
3
]
.
strip
());
fnHash
[
fnName
]
.
addVar
(
m
[
1
]
.
strip
(),
m
[
3
]
.
strip
());
elif
line
.
strip
():
var_read
=
0
;
if
re_varStart
.
match
(
line
):
var_read
=
1
;
line
=
f
.
readline
();
f
.
close
();
return
1
;
ir2c/src/BlocksFile.py
View file @
37eafe49
import
re
#
import sys
#
import fn
import
sys
import
fn
import
mem
#20 Feb 2012 - modified var declaration end mark. There is no BLOCK 0.
#modified logic which sets memFlag. Earlier it wasn't getting set - Suhas
#31 Mar 2012 - added logic to preprocess block beginnings and convert
...
...
@@ -16,8 +15,8 @@ import mem
#8-10 Oct 2012 - removing [*_expr] sort of patterns.
def
process
(
sourceFile
,
fnHash
):
labelStart
=
"bb "
;
#
assuming that all labels names start with BB.
#
Change if label prefix changes - Suhas, 31 March 2012
labelStart
=
"bb "
;
#
assuming that all labels names start with BB.
#
Change if label prefix changes - Suhas, 31 March 2012
f
=
open
(
sourceFile
+
".127t.blocks"
);
#".t99.blocks");
line
=
f
.
readline
();
printFlag
=
1
;
...
...
@@ -154,5 +153,4 @@ def process(sourceFile,fnHash):
print
line
,
printFlag
=
1
;
line
=
f
.
readline
()
return
1
;
ir2c/src/CFile.py
View file @
37eafe49
import
sys
import
re
import
fn
import
keywords
import
logging
#2 April 2012 - Original function line pattern doesn't work when fn args are
# in different lines. Changing logic to check for that
...
...
@@ -9,11 +10,6 @@ import logging
# Not completely verified though
def
readGlobalData
(
sourceFile
,
fnHash
):
"""
Reads Global Data like comments, include macros and global declarations,
which are not included in the Blocks File.
"""
f
=
open
(
sourceFile
);
line
=
f
.
readline
();
stopPrint
=
0
;
...
...
@@ -25,11 +21,11 @@ def readGlobalData(sourceFile,fnHash):
re_commentEnd
=
re
.
compile
(
'
\
*/'
);
re_comment
=
re
.
compile
(
'
\
s*//'
);
re_functionLine
=
re
.
compile
(
'[
\
w
\
s]*
\
w+
\
s+
\
w+
\
s*
\
(.*
\
)
\
s*($|
\
{)'
);
#
pattern to match function with pointer return type.
#
pattern to match function with pointer return type.
re_functionLine2
=
re
.
compile
(
'[
\
w
\
s]*
\
w+
\
s*
\
*
\
s*
\
w+
\
s*
\
(.*
\
)
\
s*($|
\
{)'
);
re_fnLineAltStart
=
re
.
compile
(
'[
\
w
\
s]*
\
w+
\
s+
\
w+
\
s*
\
([^)]*$'
);
#
multiline fn arg list
re_fnLineAltStart
=
re
.
compile
(
'[
\
w
\
s]*
\
w+
\
s+
\
w+
\
s*
\
([^)]*$'
);
#
multiline fn arg list
re_fnLineAltEnd
=
re
.
compile
(
'.*
\
)
\
s*($|
\
{)'
);
re_functionDesc
=
re
.
compile
(
'.+
\
)'
)
#
remove comments or '{' from function line
re_functionDesc
=
re
.
compile
(
'.+
\
)'
)
#
remove comments or '{' from function line
re_functionName
=
re
.
compile
(
'
\
w+
\
s*
\
('
)
lineNum
=
0
commentLineNum
=
0
...
...
@@ -39,9 +35,8 @@ def readGlobalData(sourceFile,fnHash):
while
line
:
lineNum
=
lineNum
+
1
# if not in the middle of a multiline comment and not in the middle of
# multiline fn arg list
#if not in the middle of a multiline comment and not in the middle of
#multiline fn arg list
if
(
comment
==
0
)
and
(
not
fnAltArgStart
):
m
=
re_functionLine
.
search
(
line
);
if
m
==
None
:
...
...
@@ -64,11 +59,11 @@ def readGlobalData(sourceFile,fnHash):
if
(
m
.
start
()
<
cS
.
start
()
):
fnDesc_b4_Comment
=
1
if
(
((
cS
==
None
)
and
(
comment
==
0
))
or
\
((
commentLineNum
==
lineNum
)
and
(
fnDesc_b4_Comment
))
)
\
and
(
not
re_ppDirective
.
match
(
line
)):
# in function params, if only "short" or "long" is mentioned,
# replaces it with "short int" or "long int" respectively.
line
=
re
.
sub
(
r'(^|\s)long(\s+)(?!(int|double))'
,
'
\
g<1>long int
\
g<2>'
,
line
)
line
=
re
.
sub
(
r'(^|\s)short(\s+)(?!(int|double))'
,
'
\
g<1>short int
\
g<2>'
,
line
)
m
=
re_functionLine
.
search
(
line
);
...
...
@@ -80,41 +75,36 @@ def readGlobalData(sourceFile,fnHash):
m
=
re_functionName
.
search
(
fnDesc
);
m
=
re
.
match
(
'
\
w+'
,
m
.
group
());
fnName
=
m
.
group
();
logging
.
debug
(
"In main Fnmatch pattern, Fn = "
+
fnName
)
if
fnName
in
fnHash
:
# This could be a function within ifdef, which is finally not defined
#print"Debug. In main Fnmatch pattern\nFn = " + fnName
if
fnName
in
fnHash
:
#This could be a function within ifdef,
#which is finally not defined
if
not
(
fnName
in
keywords
.
keywords
):
fnHash
[
fnName
]
.
setDesc
(
fnDesc
);
logging
.
debug
(
"In main Fnmatch pattern, Fn desc = "
+
fnDesc
)
#print"Debug. In main Fnmatch pattern\nFn desc = " + fnDesc
stopPrint
=
1
;
# This is part of multiline fn arg list pattern search.
# pushing it above the search for start of multiline arg list
# so that it doesn't repeat the recording of the first line of the list
if
fnAltArgStart
:
# still going through function arg list
if
fnName
in
fnHash
:
# This could be a function within ifdef,
# which is finally not defined, absent in Alias file
#This is part of multiline fn arg list pattern search.
#pushing it above the search for start of multiline arg list
#so that it doesn't repeat the recording of the first line of the list
if
fnAltArgStart
:
#still going through function arg list
if
fnName
in
fnHash
:
#This could be a function within ifdef,
#which is finally not defined, absent in Alias file
curFnDesc
=
fnHash
[
fnName
]
.
getDesc
();
newDesc
=
curFnDesc
+
line
;
fnHash
[
fnName
]
.
setDesc
(
newDesc
);
m
=
re_fnLineAltStart
.
search
(
line
);
# main pattern doesn't match multiline function arg list
if
m
and
(
not
fnAltArgStart
):
#This is an alternate search pattern
fnAltArgStart
=
1
;
#function arg list starts
m
=
re_fnLineAltStart
.
search
(
line
);
#main pattern doesn't match multiline function arg list
if
m
and
(
not
fnAltArgStart
):
#This is an alternate search pattern
fnAltArgStart
=
1
;
#function arg list starts
m
=
re_functionName
.
search
(
m
.
group
());
m
=
re
.
match
(
'
\
w+'
,
m
.
group
());
fnName
=
m
.
group
();
#print"Debug. In Alt. Fnstartmatch pattern \nFn = " + fnName
if
fnName
in
fnHash
:
#This could be a function within ifdef,
if
fnName
in
fnHash
:
#This could be a function within ifdef,
#which is finally not defined
if
not
(
fnName
in
keywords
.
keywords
):
fnHash
[
fnName
]
.
setDesc
(
line
);
#add description line by line
fnHash
[
fnName
]
.
setDesc
(
line
);
#add description line by line
#print"Debug. In Alt. Fnstartmatch pattern\nFn desc = " + fnHash[fnName].getDesc()
stopPrint
=
1
;
...
...
@@ -132,9 +122,7 @@ def readGlobalData(sourceFile,fnHash):
if
stopPrint
==
0
:
#print "Debug. Printing lines from C file"
print
line
,;
line
=
f
.
readline
();
f
.
close
();
return
1
;
ir2c/src/fn.py
View file @
37eafe49
...
...
@@ -5,24 +5,20 @@ class Function:
self
.
name
=
name
;
self
.
varHash
=
{};
self
.
ptrList
=
[];
def
setDesc
(
self
,
desc
):
self
.
desc
=
desc
;
def
getDesc
(
self
):
#print self.name;
return
self
.
desc
;
def
getName
(
self
):
return
self
.
name
;
def
addVar
(
self
,
varName
,
varType
):
self
.
varHash
[
varName
]
=
varType
;
if
re
.
search
(
'[
\
*
\
[]'
,
varType
):
self
.
ptrList
.
append
(
varName
);
def
getVars
(
self
):
return
self
.
varHash
;
def
getPtrs
(
self
):
return
self
.
ptrList
;
ir2c/src/ir2c.py
View file @
37eafe49
import
sys
import
re
import
CFile
import
BlocksFile
import
fn
import
AliasFile
sourceFile
=
sys
.
argv
[
1
];
...
...
@@ -17,8 +19,7 @@ print ""
print
" ***********************************************************/"
print
"#include <limits.h>"
print
"#include <stdint.h>"
print
"#include
<ir2c.h>
"
print
"#include
\"
ir2c.h
\"
"
print
""
CFile
.
readGlobalData
(
sourceFile
,
fnHash
);
BlocksFile
.
process
(
sourceFile
,
fnHash
);
ir2c/src/mem.py
View file @
37eafe49
import
re
import
fn
import
keywords
TARGET_BITWIDTH
=
32
...
...
@@ -42,7 +43,7 @@ def resolveMEM(mem,func,lhs):
varHash
=
func
.
getVars
()
re_memsplit
=
re
.
compile
(
'
\
w+: [^,|^
\
]]+'
);
#('\w+: [\w|\.]+')
re_tokensplit
=
re
.
compile
(
': '
);
#
re_plus=re.compile('\+\s*(\([\w\s]+\))?');
re_plus
=
re
.
compile
(
'
\
+
\
s*(
\
([
\
w
\
s]+
\
))?'
);
re_cast
=
re
.
compile
(
'
\
s*
\
([
\
w
\
s]+
\
)'
)
mem_components
=
{};
# resolve type
...
...
@@ -125,25 +126,25 @@ def resolveIndirection(istr, varHash):
return
istr
;
def
removePtrCast
(
str
ing
):
def
removePtrCast
(
str
):
re_ptrCast
=
re
.
compile
(
'
\
([^
\
(]+
\
*
\
)'
);
str
ing
=
re_ptrCast
.
sub
(
""
,
string
);
return
str
ing
;
str
=
re_ptrCast
.
sub
(
""
,
str
);
return
str
;
def
resolvePtrMath
(
str
ing
,
ptrList
,
broad
=
0
):
def
resolvePtrMath
(
str
,
ptrList
,
broad
=
0
):
re_var
=
re
.
compile
(
'([
\
w
\
.]+)'
)
#possible variable
re_fn
=
re
.
compile
(
'(
\
w+
\
s*
\
(.*
\
))'
);
#function call ... not to be modified
re_word
=
re
.
compile
(
'
\
w+'
);
m
=
re_fn
.
split
(
str
ing
);
str
ing
=
""
;
m
=
re_fn
.
split
(
str
);
str
=
""
;
for
i
in
range
(
len
(
m
)):
flag
=
1
;
if
i
%
2
==
1
:
flag
=
0
;
m1
=
re_word
.
match
(
m
[
i
]);
if
not
(
m1
.
group
()
in
keywords
.
keywords
):
string
=
string
+
m
[
i
];
str
=
str
+
m
[
i
];
else
:
flag
=
1
;
if
flag
:
...
...
@@ -154,25 +155,25 @@ def resolvePtrMath(string,ptrList,broad=0):
if
(
j
%
2
==
1
)
and
a
[
j
]
.
isdigit
():
# if negative, make sure it is properly sign extended
if
int
(
a
[
j
])
>=
2
**
(
TARGET_BITWIDTH
-
1
):
string
=
string
+
"(int)"
str
=
str
+
"(int)"
# ptr variable
elif
(
j
%
2
==
1
)
and
a
[
j
]
in
ptrList
:
# remove address-of operator
addr
=
0
cast
=
1
re_str
=
re
.
compile
(
'(&)'
)
strTemp
=
re_str
.
split
(
string
);
strTemp
=
re_str
.
split
(
str
);
if
len
(
strTemp
)
>
1
and
not
strTemp
[
-
1
]
.
strip
():
addr
=
1
string
=
''
.
join
(
strTemp
[:
-
2
])
str
=
''
.
join
(
strTemp
[:
-
2
])
# remove unnecessary (and wrong) pointer type cast
re_str
=
re
.
compile
(
'(
\
([
\
w
\
s]+
\
*?
\
s*
\
))'
)
strTemp
=
re_str
.
split
(
string
)
strTemp
=
re_str
.
split
(
str
)
if
len
(
strTemp
)
>
1
and
not
strTemp
[
-
1
]
.
strip
():
if
strTemp
[
-
2
]
.
find
(
'*'
)
>=
0
:
cast
=
0
else
:
string
=
''
.
join
(
strTemp
[:
-
2
])
str
=
''
.
join
(
strTemp
[:
-
2
])
# if it was plain array access, don't cast
if
j
+
1
<
len
(
a
)
and
a
[
j
+
1
]
.
strip
()
.
startswith
(
'['
):
if
not
addr
:
...
...
@@ -182,15 +183,15 @@ def resolvePtrMath(string,ptrList,broad=0):
if
not
addr
:
cast
=
0
# likewise if the pointer is immediately dereferenced
if
string
.
strip
()
.
endswith
(
'*'
):
if
str
.
strip
()
.
endswith
(
'*'
):
cast
=
0
# create properly casted pointer-taking operation
if
cast
:
string
=
string
+
UINTPTR_CAST
if
addr
:
string
=
string
+
"&"
string
=
string
+
a
[
j
];
if
cast
:
str
=
str
+
UINTPTR_CAST
if
addr
:
str
=
str
+
"&"
str
=
str
+
a
[
j
];
else
:
string
=
string
+
m
[
i
];
return
str
ing
;
str
=
str
+
m
[
i
];
return
str
;
...
...
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