Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 102 lines (80 sloc) 3.22 KB
#!/usr/bin/env python
import sys,os,subprocess
#Usage of this script
def usage(name,valid_actions,message=None):
if message: print message
print 'Usage: %s example_name transform_suffix [actions] (example: %s moldyn_fst cpack_cpack)'%(name,name)
print ' Valid actions: '+' '.join(valid_actions)
sys.exit(1)
#Valid actions
valid_actions=['notrans','trans','compile','run','remove']
#Define default actions (all False, do nothing)
for action in valid_actions:
exec('%s=False'%(action))
#Process command line arguments
if len(sys.argv)<3:
usage(sys.argv[0],valid_actions,'Not enough arguments')
elif 3==len(sys.argv):
#No actions given, run everything (all True)
for action in valid_actions:
exec('%s=True'%(action))
else:
#Get the list of actions
actions=sys.argv[3:]
#Process the list of actions
for action in actions:
if action in valid_actions:
exec('%s=True'%(action))
else:
usage(sys.argv[0],valid_actions,"Invalid action '%s'"%(action))
#Get the name of the example to run
example_name=sys.argv[1]
transform_suffix=sys.argv[2]
#Path to the main iegen script
iegen_path='iegen'+os.sep+'bin'+os.sep+'iegen'
#Examples directory prefix
ex_pre='examples'+os.sep
#Create the names of the spec files to run
spec_notrans=ex_pre+example_name+'_notrans.spec'
spec_trans=ex_pre+example_name+'_'+transform_suffix+'.spec'
#Create the output file names
out_notrans=ex_pre+example_name+'_notrans.c'
out_trans=ex_pre+example_name+'_trans.c'
#Create the name of the driver file and output binary
driver_file=ex_pre+example_name+'_'+transform_suffix+'.c'
driver_out=ex_pre+example_name+'_'+transform_suffix
#Create the arguments for calling iegen
args_notrans=[iegen_path,spec_notrans,'-o',out_notrans,'--inspector-name=inspector_notrans','--executor-name=executor_notrans']
args_trans=[iegen_path,spec_trans,'-o',out_trans,'--inspector-name=inspector_trans','--executor-name=executor_trans']
#Create the arguments for compiling
args_compile=['g++',driver_file,'-g','-I./src/dev','src/dev/ExplicitRelation.c','src/dev/RectDomain.c','src/dev/RectUnionDomain.c','src/dev/Tuple.c','src/dev/util.c','src/dev/ERG_cpack.c','-o',driver_out]
#Create the arguments for running
args_run=[driver_out]
#Create the arguments for removing
args_remove=['rm','-f',out_notrans,out_trans,driver_out]
#Run iegen for no transformations
exit_code=0
if notrans and not exit_code:
print '---------- Generating Untransformed Code ----------'
print 'Command line:',' '.join(args_notrans)
exit_code=subprocess.call(args_notrans)
#Run iegen for transformations
if trans and not exit_code:
print '---------- Generating Transformed Code ----------'
print 'Command line:',' '.join(args_trans)
exit_code=subprocess.call(args_trans)
#Compile the code
if compile and not exit_code:
print '---------- Compiling code ----------'
print 'Command line:',' '.join(args_compile)
exit_code=subprocess.call(args_compile)
#Run the compiled code
if run and not exit_code:
print '---------- Running driver ----------'
print 'Command line:',' '.join(args_run)
exit_code=subprocess.call(args_run)
#Remove the generated code files
if remove and not exit_code:
print '---------- Removing generated code ----------'
print 'Command line:',' '.join(args_remove)
exit_code=subprocess.call(args_remove)