|
| 1 | +"""Module for building and extracting builder from a set of self-contained |
| 2 | +C/c++ files.""" |
| 3 | + |
| 4 | +import subprocess |
| 5 | +import os |
| 6 | + |
| 7 | +from mlgo.corpus import extract_ir_lib |
| 8 | +from mlgo.corpus import make_corpus_lib |
| 9 | + |
| 10 | + |
| 11 | +def compile_file(source_file, object_file): |
| 12 | + command_vector = [ |
| 13 | + 'clang', '-Xclang', '-fembed-bitcode=all', source_file, '-o', object_file |
| 14 | + ] |
| 15 | + compile_process = subprocess.run( |
| 16 | + command_vector, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) |
| 17 | + assert (compile_process.returncode == 0) |
| 18 | + |
| 19 | + |
| 20 | +def perform_build(source_file_list, build_dir, corpus_dir): |
| 21 | + for source_file in source_file_list: |
| 22 | + object_file = os.path.join(build_dir, os.path.basename(source_file) + '.o') |
| 23 | + compile_file(source_file, object_file) |
| 24 | + |
| 25 | + return { |
| 26 | + 'targets': [{ |
| 27 | + 'success': True, |
| 28 | + 'build_log': None, |
| 29 | + 'name': 'self_contained' |
| 30 | + }] |
| 31 | + } |
| 32 | + |
| 33 | + |
| 34 | +# TODO(boomanaiden154): This is duplicated with extract_ir in the manual builder. |
| 35 | +# We might want to look into refactoring to consolidate the two functions at some |
| 36 | +# point. |
| 37 | +def extract_ir(build_dir, corpus_dir, threads): |
| 38 | + objects = extract_ir_lib.load_from_directory(build_dir, corpus_dir) |
| 39 | + relative_output_paths = extract_ir_lib.run_extraction(objects, threads, |
| 40 | + "llvm-objcopy", None, |
| 41 | + None, ".llvmcmd", |
| 42 | + ".llvmbc") |
| 43 | + extract_ir_lib.write_corpus_manifest(None, relative_output_paths, corpus_dir) |
0 commit comments