Commit bfd8bf5b authored by gaurav's avatar gaurav

Fixing indentation in mem.py, and a small bug in CFile.py

parent 71105773
#Define install directory
export MYBASEDIR:=/home/gaurav/eclipse-workspace/pycparser_examples
export MYBASEDIR:=/home/gaurav/eclipse-workspace/sls_thesis_project
#Directory for IR to C tool source
IR2CDIR=$(MYBASEDIR)/ir2c
......
......@@ -18,7 +18,7 @@ import mem
def process(sourceFile,fnHash):
labelStart = "bb "; # assuming that all labels names start with BB.
# Change if label prefix changes - Suhas, 31 March 2012
f=open(sourceFile+".125t.blocks");#".t99.blocks");
f=open(sourceFile+".127t.blocks");#".t99.blocks");
line=f.readline();
printFlag=1;
memFlag=0;
......@@ -154,4 +154,5 @@ def process(sourceFile,fnHash):
print line,
printFlag = 1;
line = f.readline()
return 1;
......@@ -131,7 +131,7 @@ def readGlobalData(sourceFile,fnHash):
if stopPrint == 0:
#print "Debug. Printing lines from C file"
print line;
print line,;
line=f.readline();
......
......@@ -126,25 +126,25 @@ def resolveIndirection(istr, varHash):
return istr;
def removePtrCast(str):
def removePtrCast(string):
re_ptrCast=re.compile('\([^\(]+ \*\)');
str=re_ptrCast.sub("",str);
return str;
string=re_ptrCast.sub("",string);
return string;
def resolvePtrMath(str,ptrList,broad=0):
def resolvePtrMath(string,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);
str="";
m=re_fn.split(string);
string="";
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):
str=str+m[i];
string=string+m[i];
else:
flag=1;
if flag:
......@@ -155,25 +155,25 @@ def resolvePtrMath(str,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):
str = str + "(int)"
string = string + "(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(str);
strTemp=re_str.split(string);
if len(strTemp) > 1 and not strTemp[-1].strip():
addr = 1
str = ''.join(strTemp[:-2])
string = ''.join(strTemp[:-2])
# remove unnecessary (and wrong) pointer type cast
re_str=re.compile('(\([\w\s]+\*?\s*\))')
strTemp=re_str.split(str)
strTemp=re_str.split(string)
if len(strTemp) > 1 and not strTemp[-1].strip():
if strTemp[-2].find('*') >= 0:
cast = 0
else:
str = ''.join(strTemp[:-2])
string = ''.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:
......@@ -183,15 +183,15 @@ def resolvePtrMath(str,ptrList,broad=0):
if not addr:
cast = 0
# likewise if the pointer is immediately dereferenced
if str.strip().endswith('*'):
if string.strip().endswith('*'):
cast = 0
# create properly casted pointer-taking operation
if cast: str = str+UINTPTR_CAST
if addr: str = str+"&"
str=str+a[j];
if cast: string = string+UINTPTR_CAST
if addr: string = string+"&"
string=string+a[j];
else:
str=str+m[i];
return str;
string=string+m[i];
return string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment