Verified Commit bb713587 authored by Tim Gymnich's avatar Tim Gymnich
Browse files

removed python scripts which were replaced by cmake

parent d4c75a85
#!/usr/bin/python3
# coding: utf-8
import argparse
import os
import subprocess
import sys
if sys.version_info[0] < 3:
print("Error: This script only supports Python 3")
sys.exit(5)
parser = argparse.ArgumentParser(description='Setup the project. This creates the necessary symbolic links in the LLVM source code and adds the entries into the right CMakeList.txt. Also initialises the configuration for the run.py script.')
parser.add_argument('--llvm-path', help='path to the LLVM build directory, containing a file bin/opt.')
parser.add_argument('--llvm-src', help='path to the LLVM source directory, containing lib/Analysis ')
parser.add_argument('--clang-path', help='path to the clang build direcotry, containing a file bin/clang')
parser.add_argument('--xcode', action='store_true', help='for builds using xcode')
args = parser.parse_args()
llvm_path = args.llvm_path
llvm_src = args.llvm_src
clang_path = args.clang_path
xcode = args.xcode
project_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
project_name = 'AbstractInterpretation'
cmake = 'cmake'
if llvm_path is None:
# Try to guess the correct path
d = os.path.abspath(project_dir)
while os.path.dirname(d) != d:
d = os.path.dirname(d)
for i in os.listdir(d):
if os.path.isfile(d + '/' + i + '/bin/opt'):
llvm_path = d + '/' + i
print('Auto-detecting llvm-path as ' + llvm_path)
break
if llvm_path is not None: break
else:
print('Error: No llvm-path specified (use --llvm-path)')
parser.print_help()
sys.exit(1)
if llvm_src is None:
# Try to guess the correct path
d = os.path.abspath(project_dir)
while os.path.dirname(d) != d:
d = os.path.dirname(d)
for i in os.listdir(d):
if os.path.isfile(d + '/' + i + '/cmake_install.cmake'):
continue
if os.path.isdir(d + '/' + i + '/lib/Analysis'):
llvm_src = d + '/' + i
print('Auto-detecting llvm-src as ' + llvm_src)
break
if llvm_src is not None: break
else:
print('Error: No llvm-src specified (use --llvm-src)')
parser.print_help()
sys.exit(1)
if clang_path is None:
clang_path = llvm_path
print('clang-path not specified, defaulting to ' + clang_path)
opt = llvm_path + ['', '/Debug'][xcode] + '/bin/opt'
llvm_dest = llvm_src + '/lib/Analysis'
clang = clang_path + ['', '/Debug'][xcode] + '/bin/clang'
if not os.path.isfile(opt):
print('Error: no opt exists at ' + opt + ' (maybe you forgot to build LLVM?)')
sys.exit(2)
if not os.path.isdir(llvm_dest):
print('Error: directory does not exist, at ' + llvm_dest)
sys.exit(2)
if not os.path.isfile(clang):
print('Error: no clang exists at ' + clang)
sys.exit(2)
# Create the symbolic link in the LLVM sources
try:
link_name = llvm_dest + '/' + project_name
os.symlink(project_dir, link_name, target_is_directory=True)
print('Created symbolic link from %s to %s' % (link_name, project_dir))
except FileExistsError:
print('Symlink already exists')
# Write the configuration for the run.py script
config_file_name = project_dir + '/.config';
config_file = open(config_file_name, 'w')
config_file.write(llvm_src+'\n'+llvm_path+'\n'+clang_path+'\n'+['make\n', 'xcode\n'][xcode])
config_file.close()
print('Wrote configuration to %s' % (config_file_name,))
# Adjust CMakeLists.txt
cmake_file_name = llvm_dest + '/CMakeLists.txt'
line_to_insert = 'add_subdirectory(%s)\n' % (project_name,)
cmake_file = open(cmake_file_name, 'r')
lines = cmake_file.readlines()
needs_changes = line_to_insert not in lines
cmake_file.close()
if needs_changes:
cmake_file = open(cmake_file_name, 'a')
cmake_file.write('\n' + line_to_insert)
cmake_file.close()
print('CMakeLists.txt modified, at %s' % (cmake_file_name,))
# Also regenerate the CMake cache
print('Rebuilding cmake cache')
subprocess.run([cmake, llvm_path], check=True)
else:
print('CMakeLists.txt is fine')
#!/usr/bin/python3
# coding: utf-8
import argparse
import os
import platform
import shlex
import subprocess
import sys
if sys.version_info[0] < 3:
print("Error: This script only supports Python 3")
sys.exit(5)
project_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
os.chdir(project_dir)
if not os.path.isfile(".config"):
print("No config file was found. Please run init.py first!")
sys.exit(-1)
config_file = open(".config", "r")
lines = config_file.readlines()
llvm_path = lines[1].strip()
clang_path = lines[2].strip()
try:
xcode = lines[3].strip() == 'xcode'
except IndexError:
xcode = false
config_file.close()
opt = llvm_path + ['', '/Debug'][xcode] + '/bin/opt'
llvm_dis = llvm_path + ['', '/Debug'][xcode] + '/bin/llvm-dis'
llvm_config = llvm_path + ['', '/Debug'][xcode] + '/bin/llvm-config'
clang = clang_path + ['', '/Debug'][xcode] + '/bin/clang'
cmake = 'cmake'
gdb = 'gdb'
lldb = 'lldb'
CXX = os.environ.get('CXX', 'c++')
if not os.path.isfile(opt):
print('Error: no opt exists at ' + opt + ' (maybe you forgot to build LLVM?)')
sys.exit(2)
if not os.path.isfile(llvm_dis):
print('Error: no llvm-dis exists at ' + llvm_dis + ' (maybe you forgot to build LLVM?)')
sys.exit(2)
if not os.path.isfile(clang):
print('Error: no clang exists at ' + clang)
sys.exit(2)
if platform.system() == 'Linux':
libeext = '.so'
elif platform.system() == 'Windows':
libeext = '.dll'
print('Error: Windows is not supported. (You can try to delete this error and proceed at your own risk.')
sys.exit(4)
elif platform.system() == 'Darwin':
libeext = '.dylib'
else:
print('Error: Unknown platform ' + platform.system())
sys.exit(4)
pass_lib = llvm_path + ['', '/Debug'][xcode] + "/lib/llvm-pain" + libeext
pass_name = "painpass"
make_target = "llvm-pain"
samples = project_dir + '/samples'
def main():
def run(arg, cwd=None, redirect=None):
if not args.only_print:
try:
if redirect:
f = open(redirect, 'w')
subprocess.run(arg, cwd=cwd, stdout=f, stderr=f, check=True)
f.close()
else:
subprocess.run(arg, cwd=cwd, check=True)
except subprocess.CalledProcessError as e:
print('Error: while executing ' + str(e.cmd))
if redirect:
f.close()
print(open(redirect, 'r').read())
sys.exit(3)
else:
cmd = ' '.join(shlex.quote(i) for i in arg)
if redirect:
cmd += ' > %s 2>&1' % (shlex.quote(redirect),)
if cwd is None:
print(' ' + cmd)
else:
print(' ( cd %s && %s )' % (shlex.quote(cwd), cmd))
parser = argparse.ArgumentParser()
parser.add_argument("file", help="run only the specfied files", nargs='*')
parser.add_argument("-n", dest='only_print', help="only print the commands, do not execute anything", action="store_true")
parser.add_argument("-v", dest='show_output', help="show output on stdout", action="store_true")
parser.add_argument("--cfg", dest='view_cfg', help="show llvm control flow graph", action="store_true")
parser.add_argument("--make", dest='do_make', help="call make before executing the script", action="store_true")
parser.add_argument("--only-make", dest='do_make_only', help="only call make, do not execute any samples", action="store_true")
parser.add_argument("--gdb", dest='do_gdb', help="open the gdb debugger for the specified file", action="store_true") # might not work with mac OS try lldb
parser.add_argument("--lldb", dest='do_lldb', help="open the lldb debugger for the specified file", action="store_true")
parser.add_argument("--run-test", dest='run_test', help="run the test for SimpleInterval", action="store_true")
parser.add_argument("--use-cxx", metavar='path', dest='use_cxx', help="use as c++ compiler when building the test")
args = parser.parse_args()
# If no files are specified, set it to all .c files in current directory
files = args.file
if args.run_test:
if files:
print('Error: you are trying to both run the test and a file. This does not really make sense.')
sys.exit(4)
elif args.do_gdb:
if len(files) != 1:
print('Error: you are trying to run the debugger on multiple files. This does not really make sense, just specify a single one.')
sys.exit(4)
elif args.do_make_only:
args.do_make = True
files = []
args.run_test = False
elif not files:
files = [i for i in os.listdir(samples) if i.endswith('.c')]
if args.do_make:
print("Building %s..." % (make_target,))
run([cmake, '--build', llvm_path, '--target', make_target])
if not os.path.isfile(pass_lib):
print('Error: Could not find shared library ' + pass_lib)
print('Please build the project (for example by running this script with the option --make')
sys.exit(7)
os.makedirs('output', exist_ok=True)
for fname in files:
f_orig = 'samples/%s' % (fname,)
f_bc = 'output/%s-tmp.bc' % (fname,)
f_optbc = 'output/%s.bc' % (fname,)
f_optll = 'output/%s.ll' % (fname,)
f_out = 'output/%s.out' % (fname,)
if not os.path.isfile(f_orig):
print("Error: " + f_orig +" not found!")
continue
print("Processing file " + fname + " ...")
if platform.system() == 'Darwin':
includes = subprocess.getoutput('xcrun --show-sdk-path')
run([clang, '--sysroot', includes, '-O0', '-emit-llvm', f_orig, '-Xclang', '-disable-O0-optnone', '-c', '-o', f_bc])
else:
run([clang, '-O0', '-emit-llvm', f_orig, '-Xclang', '-disable-O0-optnone', '-c', '-o', f_bc])
run([opt, '-mem2reg', f_bc, '-o', f_optbc])
run([llvm_dis, f_optbc, '-o', f_optll])
run(['rm', f_bc, f_optbc])
redir = None if args.show_output else f_out
args_add = []
if args.view_cfg:
args_add.append('--view-cfg')
base_args = ['-load', pass_lib, '-'+pass_name, '-S'] + args_add + ['-o', '/dev/null', f_optll]
if not args.do_gdb:
run([opt] + base_args, redirect=redir)
else:
break_at = 'pcpo::AbstractInterpretationPass::runOnModule(llvm::Module&)'
if not args.only_print:
print('In a moment, gdb is going to read in the symbols of opt. As you might notice, that takes a long time. So, here is a tip: Just restart the program using r (no need to specify arguments). Even if you rebuild the project, that is in a shared library and will thus be reloaded the next time you start the program.')
run([gdb, '-q', opt, '-ex', 'r ' + ' '.join(map(shlex.quote, base_args))])
if not args.do_lldb:
run([opt] + base_args, redirect=redir)
else:
break_at = 'pcpo::AbstractInterpretationPass::runOnModule(llvm::Module&)'
run([lldb, opt, '--', ' '.join(map(shlex.quote, base_args))])
if args.run_test:
if not os.path.isfile(llvm_config):
print('Error: no llvm-config exists at ' + llvm_config + ' (maybe you forgot to build LLVM?)')
sys.exit(2)
os.makedirs('build', exist_ok=True)
cxx = CXX
if args.use_cxx is not None:
cxx = args.use_cxx
print('Info: Building the test using %s' % (cxx,))
cxxflags = subprocess.run([llvm_config, '--cxxflags'], stdout=subprocess.PIPE).stdout.decode('ascii').split()
ldflags = subprocess.run([llvm_config, '--ldflags' ], stdout=subprocess.PIPE).stdout.decode('ascii').split()
libs = subprocess.run([llvm_config, '--libs', 'analysis'], stdout=subprocess.PIPE).stdout.decode('ascii').split()
if platform.system() == 'Darwin':
libs += '-lz -ldl -lpthread -lm -lcurses'.split()
else:
libs += '-lz -lrt -ldl -ltinfo -lpthread -lm'.split()
run([cxx, 'test/simple_interval_test.cpp', 'src/simple_interval.cpp', '-Isrc', '-fmax-errors=2'] + cxxflags
+ ['-o', 'build/SimpleIntervalTest'] + ldflags + libs)
try:
run(['build/SimpleIntervalTest'])
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment