17 the_program = sys.argv[0];
20 %s [options] < <cilk2c-file> 21 %s [options] <cilk2c-file> 23 Given a cilk2c file, generate line directives to partition Cilk 24 overhead by overhead type. 26 By necessity (given the use of line directives), assumes that function 27 calls are not nested in other statements. 29 """) % (the_program, the_program)
31 the_shortOpts =
"o:vhd" 32 the_longOpts = (
"output-file=",
33 "verbose",
"help",
"debug")
43 msg = (
"%s: %s\n") % (the_program, self.
msg)
44 msg = msg + (
"Try `%s --help' for more information.\n" 55 msg = (
"%s: %s\n") % (the_program, self.
msg)
71 (opts, args) =
parseCmdLine(argv, the_shortOpts, the_longOpts)
74 except (UsageExcept, FatalError), exc:
75 sys.stderr.write(
"%s" % exc)
77 except (SystemExit), exc:
80 sys.stderr.write(
"%s: Uncaught exception:\n" % the_program)
81 sys.stderr.write(
'-'*60+
"\n")
82 traceback.print_exc(file=sys.stderr)
89 """Given the results of parseCmdLine(), populate the 'ovars' dict 90 for this main routine.""" 92 if (opts.has_key(
'verbose')
or opts.has_key(
'v')):
93 ovars[
'verbose'] =
True 94 if (opts.has_key(
'debug')
or opts.has_key(
'd')):
96 if (opts.has_key(
'help')
or opts.has_key(
'h')):
100 ovars[
'inputFileNm'] =
None 101 elif (len(args) == 1):
102 ovars[
'inputFileNm'] = args[0]
110 """Given the inputs for getopt, return the parsed argv line as a 111 (dictionary-of-options, rest-of-arguments) tuple. Note that argv 112 should contain the full command line""" 114 (opts, args) = getopt.getopt(argv[1:], shortOpts, longOpts)
115 except (getopt.error), msg:
118 dashRE = re.compile(
r"^-{1,2}")
121 o = dashRE.sub(
'', o)
127 """Given a filename 'filenm', return an input stream. If 'filenm' 128 is NULL, return stdin; otherwise open the file.""" 131 stream = open(filenm,
"r") 132 except (IOError), msg:
150 'CILK2C_XPOP_FRAME_RESULT',
151 'CILK2C_XPOP_FRAME_NORESULT',
153 'CILK2C_SET_NORESULT',
154 'CILK2C_BEFORE_RETURN_FAST',
156 'CILK2C_START_THREAD_FAST',
157 'CILK2C_START_THREAD_SLOW',
159 'CILK2C_BEFORE_RETURN_FAST',
160 'CILK2C_BEFORE_RETURN_SLOW',
161 'CILK2C_BEFORE_RETURN_INLET',
163 'CILK2C_AT_SYNC_FAST',
164 'CILK2C_AT_THREAD_BOUNDARY_SLOW',
170 'CILK2C_ABORT_STANDALONE',
173 'CILK2C_BEFORE_SPAWN_FAST',
174 'CILK2C_BEFORE_SPAWN_SLOW',
175 'CILK2C_AFTER_SPAWN_FAST',
176 'CILK2C_AFTER_SPAWN_SLOW',
177 'CILK2C_BEFORE_SYNC_SLOW',
178 'CILK2C_AFTER_SYNC_SLOW',
194 self.
makeREs(CilkOverhead[
'parallel'],
'parallel');
195 self.
makeREs(CilkOverhead[
'sync'],
'sync');
196 self.
makeREs(CilkOverhead[
'cp'],
'cp');
200 redesc.make_cilk_import()
201 (self.
data[
're_lst']).append(redesc);
206 for redesc
in (self.
data[
're_lst']):
207 old_reObj = redesc.oldRE();
208 new_re = redesc.make_newRE(ppMgr.fileNm(), ppMgr.lineNo());
210 new_line = old_reObj.sub(new_re, new_line)
212 if (DBG
and new_line != line):
print "DBG:", new_line;
216 def makeREs(self, overheadFnLst, overhead_ty):
217 for fn
in overheadFnLst:
219 redesc.make_overhead(fn, overhead_ty)
220 (self.
data[
're_lst']).append(redesc);
232 return self.
data[
'old_reObj']
234 self.
data[
'old_reObj'] = x
238 txt = self.
newRE() % (lineno, lineno, filenm);
240 txt = self.
newRE() % (lineno, filenm);
247 cilk2c_post =
r'[^;]*\s*;' 248 old_re =
r"%s(%s%s)" % (cilk2c_pre, fn, cilk2c_post);
251 lush_mark =
r'#line %s "lush:%s-overhead"' % (
"%d", overhead_ty)
252 lush_unmark =
r'#line %d "%s"';
253 self.
set_newRE(
r"\n%s\n \1\n%s\n " % (lush_mark, lush_unmark));
256 old_re =
r"(^.*_cilk\w+_import\(.+$)";
259 fix_mark =
r'#line %d "%s"';
261 self.
data[
'ty_ohead'] =
False;
266 return self.
data[
'new_re']
268 self.
data[
'new_re'] = x
271 return (self.
data[
'ty_ohead']);
274 return (
"old: %s\nnew: %s") % (self.
oldRE().pattern, self.
newRE())
282 'dir_re' : re.compile(
r"^#"),
283 'linedir_re' : re.compile(
r'''^\#(?:line)?\s 285 \s*(?:" ([^"]+) ")?''', re.X),
291 return (self.
data[
'dir_re']).match(line)
294 m = (self.
data[
'linedir_re']).match(line)
300 if (DBG):
print "DBG:", self;
303 if (self.
data[
'mr_lnno']):
304 self.
data[
'mr_lnno'] += 1;
307 return self.
data[
'mr_filenm']
309 self.
data[
'mr_filenm'] = x
312 return self.
data[
'mr_lnno']
314 self.
data[
'mr_lnno'] = x
328 if (cppMgr.isDirective(line)):
329 cppMgr.processDirLine(line)
331 line = cilkMgr.processLine(line, cppMgr)
332 cppMgr.processNonDirLine()
334 print (
"%s") % (line),
341 if (__name__ ==
"__main__"):
def parseCmdLine(argv, shortOpts, longOpts)
def makeREs(self, overheadFnLst, overhead_ty)
def make_cilk_import(self)
def isDirective(self, line)
def make_newRE(self, filenm, lineno)
def processDirLine(self, line)
def make_overhead(self, fn, overhead_ty)
def processNonDirLine(self)
def closeFile(filenm, stream)
def processCmdLine(ovars, opts, args)
def processLine(self, line, ppMgr)