|
1 | 1 | import logging
|
2 | 2 | import sys
|
3 | 3 | from pathlib import Path
|
4 |
| -from subprocess import CalledProcessError |
5 | 4 | from typing import Final, Iterable, List, Optional
|
6 | 5 |
|
7 |
| -from pyk.cli_utils import run_process |
8 | 6 | from pyk.cterm import CTerm
|
9 | 7 | from pyk.kast.inner import KApply, KInner, KLabel, KSort, KToken, KVariable, build_assoc
|
10 | 8 | from pyk.kast.manip import flatten_label, get_cell
|
11 | 9 | from pyk.kast.outer import KFlatModule
|
12 |
| -from pyk.ktool.kompile import KompileBackend |
| 10 | +from pyk.ktool.kompile import KompileBackend, kompile |
13 | 11 | from pyk.ktool.kprint import SymbolTable, paren
|
14 | 12 | from pyk.ktool.kprove import KProve
|
15 | 13 | from pyk.ktool.krun import KRun
|
|
20 | 18 | from pyk.prelude.string import stringToken
|
21 | 19 | from pyk.utils import unique
|
22 | 20 |
|
23 |
| -from .utils import add_include_arg |
24 |
| - |
25 | 21 | _LOGGER: Final = logging.getLogger(__name__)
|
26 | 22 |
|
27 | 23 |
|
@@ -76,33 +72,28 @@ def kompile(
|
76 | 72 | llvm_kompile: bool = True,
|
77 | 73 | optimization: int = 0,
|
78 | 74 | ) -> 'KEVM':
|
79 |
| - command = ['kompile', '--output-definition', str(definition_dir), str(main_file)] |
80 |
| - if debug: |
81 |
| - command += ['--debug'] |
82 |
| - command += ['--backend', backend.value] |
83 |
| - command += ['--main-module', main_module_name] if main_module_name else [] |
84 |
| - command += ['--syntax-module', syntax_module_name] if syntax_module_name else [] |
85 |
| - command += ['--md-selector', md_selector] if md_selector else [] |
86 |
| - command += ['--hook-namespaces', ' '.join(KEVM.hook_namespaces())] |
87 |
| - command += add_include_arg(includes) |
88 |
| - if emit_json: |
89 |
| - command += ['--emit-json'] |
90 |
| - if backend == KompileBackend.HASKELL: |
91 |
| - command += ['--concrete-rules', ','.join(KEVM.concrete_rules())] |
92 |
| - if backend == KompileBackend.LLVM: |
93 |
| - if ccopts: |
94 |
| - for ccopt in ccopts: |
95 |
| - command += ['-ccopt', ccopt] |
96 |
| - if 0 < optimization and optimization <= 3: |
97 |
| - command += [f'-O{optimization}'] |
98 |
| - if not llvm_kompile: |
99 |
| - command += ['--no-llvm-kompile'] |
100 | 75 | try:
|
101 |
| - run_process(command, logger=_LOGGER, profile=profile) |
102 |
| - except CalledProcessError as err: |
103 |
| - sys.stderr.write(f'\nkompile stdout:\n{err.stdout}\n') |
104 |
| - sys.stderr.write(f'\nkompile stderr:\n{err.stderr}\n') |
105 |
| - sys.stderr.write(f'\nkompile returncode:\n{err.returncode}\n') |
| 76 | + kompile( |
| 77 | + main_file=main_file, |
| 78 | + output_dir=definition_dir, |
| 79 | + backend=backend, |
| 80 | + emit_json=emit_json, |
| 81 | + include_dirs=[include for include in includes if Path(include).exists()], |
| 82 | + main_module=main_module_name, |
| 83 | + syntax_module=syntax_module_name, |
| 84 | + md_selector=md_selector, |
| 85 | + hook_namespaces=KEVM.hook_namespaces(), |
| 86 | + debug=debug, |
| 87 | + concrete_rules=KEVM.concrete_rules() if backend == KompileBackend.HASKELL else (), |
| 88 | + ccopts=ccopts, |
| 89 | + no_llvm_kompile=not llvm_kompile, |
| 90 | + opt_level=optimization or None, |
| 91 | + profile=profile, |
| 92 | + ) |
| 93 | + except RuntimeError as err: |
| 94 | + sys.stderr.write(f'\nkompile stdout:\n{err.args[1]}\n') |
| 95 | + sys.stderr.write(f'\nkompile stderr:\n{err.args[2]}\n') |
| 96 | + sys.stderr.write(f'\nkompile returncode:\n{err.args[3]}\n') |
106 | 97 | sys.stderr.flush()
|
107 | 98 | raise
|
108 | 99 | return KEVM(definition_dir, main_file=main_file)
|
|
0 commit comments