Commit 37eafe49 authored by Gaurav Kukreja's avatar Gaurav Kukreja

Reverted all python files in ir2c code, to solve issues

Signed-off-by: Gaurav Kukreja's avatarGaurav Kukreja <gaurav@gauravk.in>
parent f2aa5106
# 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');
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;
while line:
def process(sourceFile,fnHash):
f=open(sourceFile+ '.055t.alias');#'.t29.alias1');
line = f.readline();
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("\tVariable Name: " + m[1] +", Variable Type: " + m[3]);
fnHash[fnName].addVar(varName = m[1].strip(), varType = m[3].strip());
elif line.strip():
var_read=0;
if re_varLine.match(line):
m=re_getVar.split(line);
m[3]=re.sub(r'\{.*\}', '', m[3]);
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;
\ No newline at end of file
var_read=1;
line=f.readline();
f.close();
return 1;
This diff is collapsed.
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,132 +10,119 @@ 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;
comment= 0;
fnAltArgStart = 0;
fnName = ""
re_ppDirective=re.compile('\s*#')
re_commentStart = re.compile('/\*');
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.
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_fnLineAltEnd = re.compile('.*\)\s*($|\{)');
re_functionDesc = re.compile('.+\)') # remove comments or '{' from function line
re_functionName = re.compile('\w+\s*\(')
lineNum = 0
commentLineNum = 0
m = None
fnDesc_b4_Comment = 0
while line:
f=open(sourceFile);
line = f.readline();
stopPrint = 0;
comment= 0;
fnAltArgStart = 0;
fnName = ""
re_ppDirective=re.compile('\s*#')
re_commentStart = re.compile('/\*');
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.
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_fnLineAltEnd = re.compile('.*\)\s*($|\{)');
re_functionDesc = re.compile('.+\)') #remove comments or '{' from function line
re_functionName = re.compile('\w+\s*\(')
lineNum = 0
commentLineNum = 0
m = None
fnDesc_b4_Comment = 0
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);
m =re_functionLine.search(line);
if m == None:
m = re_fnLineAltStart.search(line)
if m == None:
m = re_fnLineAltStart.search(line)
if m == None:
m = re_functionLine2.search(line);
m = re_functionLine2.search(line);
cM = re_commentStart.search(line)
if cM != None:
comment=1;
commentLineNum = lineNum
if m != None:
if ( m.start() < cM.start() ):
fnDesc_b4_Comment = 1
comment=1;
commentLineNum = lineNum
if m != None:
if ( m.start() < cM.start() ):
fnDesc_b4_Comment = 1
cS = re_comment.match(line)
if cS != None:
commentLineNum = lineNum
if m != None:
if ( m.start() < cS.start() ):
fnDesc_b4_Comment = 1
commentLineNum = lineNum
if m != None:
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);
if m == None:
m = re_functionLine2.search(line);
if m and (not fnAltArgStart):
((commentLineNum == lineNum) and (fnDesc_b4_Comment)) )\
and (not re_ppDirective.match(line)):
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);
if m == None:
m = re_functionLine2.search(line);
if m and (not fnAltArgStart):
m=re_functionDesc.match(m.group());
fnDesc=m.group();
m =re_functionName.search(fnDesc);
fnDesc=m.group();
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
if not (fnName in keywords.keywords):
fnHash[fnName].setDesc(fnDesc);
logging.debug("In main Fnmatch pattern, Fn desc = " + fnDesc)
stopPrint = 1;
fnName=m.group();
#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);
#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
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
#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_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,
#which is finally not defined
if not (fnName in keywords.keywords):
fnHash[fnName].setDesc(line);
#add description line by line
#print"Debug. In Alt. Fnstartmatch pattern\nFn desc = " + fnHash[fnName].getDesc()
stopPrint = 1;
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
#print"Debug. In Alt. Fnstartmatch pattern\nFn desc = " + fnHash[fnName].getDesc()
stopPrint = 1;
m = re_fnLineAltEnd.search(line); #search for end of fn arg list
if m and fnAltArgStart:
m = re_fnLineAltEnd.search(line); #search for end of fn arg list
if m and fnAltArgStart:
fnAltArgStart = 0; #function arg list ends
#if fnName in fnHash: #Debug
# print"Debug. Fn desc = " + fnHash[fnName].getDesc()
if re_commentEnd.search(line):
comment=0;
comment=0;
fnDesc_b4_Comment = 0
if stopPrint == 0:
#print "Debug. Printing lines from C file"
print line,;
line=f.readline();
f.close();
return 1;
#print "Debug. Printing lines from C file"
print line,;
line=f.readline();
f.close();
return 1;
import re
class Function:
def __init__(self,name):
self.name=name;
self.varHash={};
def __init__(self,name):
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;
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);
self.ptrList.append(varName);
def getVars(self):
return self.varHash;
def getPtrs(self):
return self.ptrList;
def getVars(self):
return self.varHash;
def getPtrs(self):
return self.ptrList;
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);
This diff is collapsed.
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