1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import sys
import os
RTYPERORDER = os.getenv('RTYPERORDER').split(',')
if len(RTYPERORDER) == 2:
module_list = RTYPERORDER[1]
else:
module_list = 'module-list'
lst = open(module_list, 'r')
try:
print "reading module-list: %s" % module_list
prefixes = lst.readlines()
finally:
lst.close()
prefixes = [line.strip() for line in prefixes]
prefixes = [line for line in prefixes if line and not line.startswith('#')]
NOMATCH = sys.maxint
def order(annotator, pending):
cache = {}
annotated = annotator.annotated
def indx(block):
func = annotated[block]
module = func.__module__
if module is None:
module = 'None'
tag = "%s:%s" % (module, func.__name__)
try:
return cache[tag]
except KeyError:
match = NOMATCH
i = 0
for pfx in prefixes:
if tag.startswith(pfx):
if match == NOMATCH:
match = i
else:
if len(pfx) > len(prefixes[match]):
match = i
i += 1
cache[tag] = match, module
return match
pending.sort(lambda blk1, blk2: cmp(indx(blk1), indx(blk2)))
cur_module = ['$']
def track(block):
module = annotated[block].__module__
if module != cur_module[0]:
print "--- Specializing blocks in module: %s" % module
cur_module[0] = module
return track
|