Skip to content
Draft

Chexo #759

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ asdl==0.1.5
build==1.2.2.post1
z3-solver==4.14.0.0
yapf==0.43.0
scipy==1.13.1
hsnf==0.3.16
pythonmonkey==1.1.0
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ install_requires =
build>=1.2.1
z3-solver>=4.13.0.0
yapf>=0.40.2
scipy>=1.13.1
hsnf>=0.3.16
pythonmonkey>=1.1.0

[options.packages.find]
where = src
Expand Down
46 changes: 36 additions & 10 deletions src/exo/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
# Moved to new file
from .core.proc_eqv import decl_new_proc, derive_proc, assert_eqv_proc, check_eqv_proc
from .frontend.pyparser import get_ast_from_python, Parser, get_parent_scope
from .frontend.typecheck import TypeChecker
from .frontend.typecheck import TypeChecker, CheckMode

from . import API_cursors as C
from .core import internal_cursors as IC
from .backend.LoopIR_compiler import DEFAULT_CHECK_MODE

# --------------------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# Top-level decorator


def proc(f, _instr=None) -> "Procedure":
def proc(f, _instr=None, _check_mode: Optional[CheckMode] = None) -> "Procedure":
if not isinstance(f, types.FunctionType):
raise TypeError("@proc decorator must be applied to a function")

Expand All @@ -42,22 +43,22 @@ def proc(f, _instr=None) -> "Procedure":
parser = Parser(
body,
src_info,
parent_scope=get_parent_scope(depth=3 if _instr else 2),
parent_scope=get_parent_scope(depth=3 if _instr or _check_mode else 2),
instr=_instr,
as_func=True,
)
return Procedure(parser.result())
return Procedure(parser.result(), _check_mode=_check_mode)


def instr(c_instr, c_global=""):
def instr(c_instr, c_global="", check_mode=None):
if not isinstance(c_instr, str):
raise TypeError("@instr decorator must be @instr(<your instuction>)")

def inner(f):
if not isinstance(f, types.FunctionType):
raise TypeError("@instr decorator must be applied to a function")

return proc(f, _instr=(c_instr, c_global))
return proc(f, _instr=(c_instr, c_global), _check_mode=check_mode)

return inner

Expand All @@ -84,6 +85,14 @@ def parse_config(cls):
return parse_config(_cls)


def chexo(f):
return proc(f, _check_mode="dynamic")


def chexo_debug(f):
return proc(f, _check_mode="both")


# --------------------------------------------------------------------------- #
# --------------------------------------------------------------------------- #
# iPython Display Object
Expand Down Expand Up @@ -150,7 +159,11 @@ def compile_procs(proc_list, basedir: Path, c_file: str, h_file: str):
def compile_procs_to_strings(proc_list, h_file_name: str):
assert isinstance(proc_list, list)
assert all(isinstance(p, Procedure) for p in proc_list)
return run_compile([p._loopir_proc for p in proc_list], h_file_name)
return run_compile(
[p._loopir_proc for p in proc_list],
h_file_name,
"dynamic" if any(p._check_mode == "dynamic" for p in proc_list) else "static",
)


class Procedure(ProcedureBase):
Expand All @@ -160,14 +173,25 @@ def __init__(
_provenance_eq_Procedure: "Procedure" = None,
_forward=None,
_mod_config=None,
_check_mode: Optional[CheckMode] = None,
):
super().__init__()

_mod_config = _mod_config or frozenset()

self._check_mode = (
(
_provenance_eq_Procedure._check_mode
if _provenance_eq_Procedure is not None
else DEFAULT_CHECK_MODE
)
if _check_mode is None
else _check_mode
)
if isinstance(proc, LoopIR.UAST.proc):
proc = TypeChecker(proc).get_loopir()
CheckBounds(proc)
proc = TypeChecker(proc, self._check_mode).get_loopir()
if self._check_mode != "dynamic":
CheckBounds(proc)
Check_Aliasing(proc)

assert isinstance(proc, LoopIR.LoopIR.proc)
Expand Down Expand Up @@ -294,7 +318,9 @@ def find_all(self, pattern):
# ---------------------------------------------- #

def c_code_str(self):
decls, defns = compile_to_strings("c_code_str", [self._loopir_proc])
decls, defns = compile_to_strings(
"c_code_str", [self._loopir_proc], check_mode=self._check_mode
)
return decls + "\n" + defns

def compile_c(self, directory: Path, filename: str):
Expand Down
Loading