OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 """ | 3 """ |
4 | 4 |
5 (c) 2002, 2003, 2004, 2005 Simon Burton <simon@arrowtheory.com> | 5 (c) 2002, 2003, 2004, 2005 Simon Burton <simon@arrowtheory.com> |
6 Released under GNU LGPL license. | 6 Released under GNU LGPL license. |
7 | 7 |
8 version 0.xx | 8 version 0.xx |
9 | 9 |
10 """ | 10 """ |
11 | 11 |
12 | 12 |
13 import sys | 13 import sys |
14 import os | 14 import os |
15 | 15 |
16 import cparse | 16 import cparse |
17 import ir | 17 import ir |
18 | 18 |
| 19 def callcmd(cmd): |
| 20 try: |
| 21 from subprocess import call |
| 22 try: |
| 23 retcode = call(cmd, shell=True) |
| 24 assert retcode == 0, "command failed: %s"%cmd |
| 25 except OSError, e: |
| 26 assert False, "command failed: %s"%e |
| 27 except ImportError: |
| 28 status = os.system( cmd ) |
| 29 assert status == 0, "command failed: %s"%cmd |
| 30 |
19 class WorkUnit(object): | 31 class WorkUnit(object): |
20 def __init__(self, files, modname, filename, | 32 def __init__(self, files, modname, filename, |
21 std=False, strip=False, mark_cb=None, | 33 std=False, strip=False, mark_cb=None, |
22 extradefs="", use_header=None, CC="gcc", CPP="gcc -E", | 34 extradefs="", use_header=None, CC="gcc", CPP="gcc -E", |
23 CPPFLAGS=""): | 35 CPPFLAGS=""): |
24 self.files = tuple(files) | 36 self.files = tuple(files) |
25 self.modname = modname | 37 self.modname = modname |
26 self.filename = filename | 38 self.filename = filename |
27 self.CPPFLAGS = CPPFLAGS | 39 self.CPPFLAGS = CPPFLAGS |
28 self.CPP = CPP | 40 self.CPP = CPP |
(...skipping 26 matching lines...) Expand all Loading... |
55 for filename in self.files: | 67 for filename in self.files: |
56 if self.std: | 68 if self.std: |
57 line = '#include <%s>\n'%filename | 69 line = '#include <%s>\n'%filename |
58 else: | 70 else: |
59 line = '#include "%s"\n'%filename | 71 line = '#include "%s"\n'%filename |
60 ifile.write( line ) | 72 ifile.write( line ) |
61 print line, | 73 print line, |
62 ifile.close() | 74 ifile.close() |
63 cmd = '%s %s %s > %s'%(self.CPP,name+'.h',self.CPPFLAGS,name+'.E') | 75 cmd = '%s %s %s > %s'%(self.CPP,name+'.h',self.CPPFLAGS,name+'.E') |
64 sys.stderr.write( "# %s\n" % cmd ) | 76 sys.stderr.write( "# %s\n" % cmd ) |
65 status = os.system( cmd ) | 77 callcmd( cmd ) |
66 assert status == 0, "command failed: %s"%cmd | |
67 assert open(name+'.E').read().count('\n') > 10, "failed to run preproces
sor" | 78 assert open(name+'.E').read().count('\n') > 10, "failed to run preproces
sor" |
68 cmd = '%s -dM %s %s > %s'%(self.CPP,name+'.h',self.CPPFLAGS,name+'.dM') | 79 cmd = '%s -dM %s %s > %s'%(self.CPP,name+'.h',self.CPPFLAGS,name+'.dM') |
69 sys.stderr.write( "# %s\n" % cmd ) | 80 sys.stderr.write( "# %s\n" % cmd ) |
70 status = os.system( cmd ) | 81 callcmd( cmd ) |
71 assert status == 0, "command failed: %s"%cmd | |
72 assert open(name+'.dM').read().count('\n') > 10, "failed to run preproce
ssor with -dM" | 82 assert open(name+'.dM').read().count('\n') > 10, "failed to run preproce
ssor with -dM" |
73 return name | 83 return name |
74 | 84 |
75 def parse(self, verbose=False): | 85 def parse(self, verbose=False): |
76 sys.stderr.write( "# parse %s\n" % str(self.files) ) | 86 sys.stderr.write( "# parse %s\n" % str(self.files) ) |
77 name = self.mkheader() | 87 name = self.mkheader() |
78 # read macros | 88 # read macros |
79 f = open(name+'.dM') | 89 f = open(name+'.dM') |
80 macros = {} | 90 macros = {} |
81 for line in f.readlines(): | 91 for line in f.readlines(): |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if file_exists(path): | 160 if file_exists(path): |
151 libnames.append(path) | 161 libnames.append(path) |
152 break | 162 break |
153 #else: | 163 #else: |
154 #print "cannot find %s lib as %s in %s" % ( lib, libname, libdir
) | 164 #print "cannot find %s lib as %s in %s" % ( lib, libname, libdir
) |
155 print 'libnames:', libnames | 165 print 'libnames:', libnames |
156 syms = {} | 166 syms = {} |
157 accept = [ ' %s '%c for c in 'TVWBCDGRS' ] | 167 accept = [ ' %s '%c for c in 'TVWBCDGRS' ] |
158 #f = open('syms.out','w') | 168 #f = open('syms.out','w') |
159 for libname in libnames: | 169 for libname in libnames: |
160 fin, fout = os.popen2( 'nm %s' % libname ) | 170 try: |
| 171 from subprocess import Popen, PIPE |
| 172 p = Popen(['nm', libname], bufsize=1, stdout=PIPE) |
| 173 fout = p.stdout |
| 174 except ImportError: |
| 175 fin, fout = os.popen2( 'nm %s' % libname ) |
161 for line in fout.readlines(): | 176 for line in fout.readlines(): |
162 for acc in accept: | 177 for acc in accept: |
163 if line.count(acc): | 178 if line.count(acc): |
164 left, right = line.split(acc) | 179 left, right = line.split(acc) |
165 sym = right.strip() | 180 sym = right.strip() |
166 if sys.platform.count('darwin'): | 181 if sys.platform.count('darwin'): |
167 if sym[0] == '_': | 182 if sym[0] == '_': |
168 sym = sym[1:] # remove underscore prefix | 183 sym = sym[1:] # remove underscore prefix |
169 if sym.endswith('.eh'): | 184 if sym.endswith('.eh'): |
170 sym = sym[:-len('.eh')] | 185 sym = sym[:-len('.eh')] |
171 syms[sym] = None | 186 syms[sym] = None |
172 #f.write( '%s: %s %s\n' % (sym,line[:-1],libname) ) | 187 #f.write( '%s: %s %s\n' % (sym,line[:-1],libname) ) |
173 break | 188 break |
174 return syms | 189 return syms |
175 | 190 |
176 | 191 |
177 | 192 |
OLD | NEW |