def __init__(self, args): self.args = args self.mutations = [] self.execution_time = 0 self.min_time = 0 self.max_time = 0 self.living = True self.foutname = "_".join([ str(random.randint(0, 1000000)), os.path.basename(args.sources[0]) ]) # create workspace self.ws = pyrops.pworkspace(self.args.sources, verbose=args.verbose > 1, recoverInclude=True, parents=[workspace_gettime.workspace]) self.ws.activate("MUST_REGIONS") self.ws.activate("PRECONDITIONS_INTER_FULL") self.ws.activate("TRANSFORMERS_INTER_FULL") self.ws.activate("RICE_SEMANTICS_DEPENDENCE_GRAPH") self.ws.activate("RICE_REGIONS_DEPENDENCE_GRAPH") self.ws.activate("REGION_CHAINS") self.ws.props.RICEDG_STATISTICS_ALL_ARRAYS = True self.ws.props.C89_CODE_GENERATION = True self.ws.props.CONSTANT_PATH_EFFECTS = False self.ws.props.PRETTYPRINT_SEQUENTIAL_STYLE = "seq"
def perform(source_path, op, advanced=False, **params): mod = import_module(op) try: ws = pworkspace(str(source_path), deleteOnClose=True) if advanced: # Set properties for props in params.get('properties', {}).values(): for p in props: if p['checked']: val = str(p['val']) if isinstance( p['val'], unicode) else p['val'] ##TODO setattr(ws.props, p['id'], val) # Activate analyses for a in params.get('analyses', []): if a['checked']: ws.activate(str(a['val'])) # Apply phases for p in params.get('phases', []): if p['checked']: getattr(ws.all, p['id'])() functions = '' for fu in ws.fun: functions += mod.invoke_function(fu, ws) ws.close() return functions except: ws.close() raise
def main(): parser = OptionParser(description = "Try several sac optimisations") parser.add_option("-f", "--function", dest = "function", help = "function to try and optimize") parser.add_option("-v", "--verbose", dest = "verbose", action = "count", default = 0, help = "be verbose") parser.add_option("-o", "--outdir", dest = "outdir", help = "directory to store the resulting transformation") (args, sources) = parser.parse_args() for p in permutations(): print "Trying permutation", p ws = pyrops.pworkspace(sources, verbose = (args.verbose >= 2), parents = [sac.workspace], driver = "sse") module = ws[args.function] try: module.sac(verbose = (args.verbose >= 3), **p) if args.verbose >= 1: module.display() print "OK:", p if args.outdir: ws.save(rep = args.outdir) ws.close() exit(0) except RuntimeError, e: print "NOK", e.args if args.verbose: print "".join(Pyro.util.getPyroTraceback(e)) ws.close()
def get_functions(sources): ws = pworkspace(*sources, deleteOnClose=True) ##TODO: cast source file names to str functions = [] for fu in ws.fun: functions.append(fu.name) ws.close() return functions
def dependence_graph_multi(request): """ """ dirname = create_workdir(request) sources = request.session['sources'] ws = pworkspace(*sources, name=dirname, deleteOnClose=True) functions = _get_ws_functions(ws) images = create_graph_images(request, functions) ws.close() return dict(images=images)
def dependence_graph(request): """ """ form = request.params code = form.get('code') lang = form.get('lang') source = _create_file(request, '', code, lang) dirname = create_workdir(request) ws = pworkspace(str(source), name=dirname, deleteOnClose=True) functions = _get_ws_functions(ws) images = create_graph_images(request, functions) #_delete_dir(source) ws.close() return dict(images=images)
def perform_multiple(sources, op, function_name, advanced=False, **params): mod = import_module(op) try: ws = pworkspace( *sources, deleteOnClose=True) ##TODO: cast source file names to str if advanced: if (properties != ""): set_properties(ws, str(properties).split(';')[:-1]) if (analysis != ""): activate(ws, analysis) if (phases != ""): apply_phases(ws, phases) result = mod.invoke_function(ws.fun.__getattr__(function_name), ws) ws.close() return result except: ws.close() raise
from __future__ import with_statement # this is to work with python2.5 from pyrops import pworkspace w2 = pworkspace("basics0.c", deleteOnClose=True) w1 = pworkspace("cat.c", deleteOnClose=True) # Should display only functions from w1 w1.all_functions.display() w1.close() w2.close()
from __future__ import with_statement # this is to work with python2.5 #!/usr/bin/env python # import everything so that a session looks like tpips one from pyrops import pworkspace import shutil, os, pyrops #launcher = pyrops.getWorkspaceLauncher(["properties.c"]) #w = launcher.getObj() with pworkspace("properties.c", "cat.c", deleteOnClose=True) as w: #Get foo function foo = w.fun.foo #Test for default value (should be True) print "Prop INLINING_USE_INITIALIZATION_LIST is " + str( w.props.INLINING_USE_INITIALIZATION_LIST) #Should not purge labels foo.inlining(callers="bar", USE_INITIALIZATION_LIST=False) #Environment should have been restored, so USE_INITIALIZATION_LIST is True print "Prop INLINING_USE_INITIALIZATION_LIST is " + str( w.props.INLINING_USE_INITIALIZATION_LIST) #Test if we success changing environment w.props.INLINING_USE_INITIALIZATION_LIST = False print "Prop INLINING_USE_INITIALIZATION_LIST is " + str( w.props.INLINING_USE_INITIALIZATION_LIST) #Test keep it back to an other value w.props.INLINING_USE_INITIALIZATION_LIST = True
from __future__ import with_statement # this is to work with python2.5 #!/usr/bin/env python #This script is an adaptation of basics0.py for Pyrops # import everything so that a session looks like tpips one from pyrops import pworkspace import shutil, os, pyrops # a worspace ID is automagically created ... may be not a good feature #launcher = pyrops.Launcher() #pyrops.getWorkspaceLauncher(["basics0.c"]) #cp = launcher.getObj() #w = workspace(["basics0.c"], cpypips = cp) with pworkspace("basics0.c", deleteOnClose=True) as w: # you can get module object from the modules table foo = w.fun.foo bar = w.fun.bar malabar = w.fun.malabar mb = w.fun.megablast # and apply transformation to modules foo.inlining(callers="bar", USE_INITIALIZATION_LIST=False) #the good old display, default to PRINTED_FILE, but you can give args foo.display() bar.display() malabar.display() bar.print_code() # you can also preform operations on loops mb.display(rc="loops_file")