-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile2.py
More file actions
executable file
·51 lines (44 loc) · 2.09 KB
/
compile2.py
File metadata and controls
executable file
·51 lines (44 loc) · 2.09 KB
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
#!/usr/bin/env python3
import os
import subprocess
import time
from pathlib import Path
import sys
from config import BASE_DIR, CATEGORIES, BUILD_DIR ,BENCHMARK_DIR
from compilers.compiler_setup import get_compilers
#TODO support version in the compiled file name
def compile_files(programdir, builddir, prefix, compilers):
"""Recursively compile files with a prefix in the given directory using multiple compilers."""
assert isinstance (programdir, Path)
assert isinstance (builddir, Path)
builddir.mkdir(parents=True,exist_ok=True)
files = sorted(programdir.glob('**/*.' + prefix))
for compiler in compilers:
print ("Compiling for " + compiler.name)
length = len (files)
for i, file in enumerate (files,start = 1):
target_name = file.stem
directory = file.parent.name
assert target_name == directory
input_file = file.as_posix()
delimiter = "_"
if compiler.suffix is None:
output_filename = delimiter.join([target_name, compiler.name.lower()])
else:
output_filename = delimiter.join([target_name, compiler.name.lower(), compiler.suffix])
output_file = os.path.join(builddir,output_filename)
print("Compiling: " + file.name + " to " + output_filename + " " + str(i) + "/" + str (length))
compiler.compile(input_file,output_file)
if __name__ == "__main__":
benchmark_base_dir = "."
# Just in case directory to output isn't in repo directory"
output_base_dir = './out'
# List of SML compilers as instantiated objects
compilers_by_lang = get_compilers(base_dir=BASE_DIR)
sml_compilers = compilers_by_lang.get("sml", [])
cakeml_compilers = compilers_by_lang.get("cakeml", [])
for category in CATEGORIES:
directory_to_search = BENCHMARK_DIR.joinpath(category)
directory_to_output = BUILD_DIR.joinpath(category)
compile_files(directory_to_search,directory_to_output,"cml", cakeml_compilers)
compile_files(directory_to_search,directory_to_output,"sml", sml_compilers)