diff options
| author | J08nY | 2020-02-19 18:29:53 +0100 |
|---|---|---|
| committer | J08nY | 2020-02-19 18:29:53 +0100 |
| commit | 5da1d167c203395103d220c450e29fece08f4198 (patch) | |
| tree | fdc8fb7f0fbf2d2aaab46c2cb8a90a8176058292 /pyecsca/codegen/render.py | |
| parent | f04c640c05e9ffe894f67194832623e28a8000f5 (diff) | |
| download | pyecsca-codegen-5da1d167c203395103d220c450e29fece08f4198.tar.gz pyecsca-codegen-5da1d167c203395103d220c450e29fece08f4198.tar.zst pyecsca-codegen-5da1d167c203395103d220c450e29fece08f4198.zip | |
Flesh out client, add implementation tests.
Diffstat (limited to 'pyecsca/codegen/render.py')
| -rw-r--r-- | pyecsca/codegen/render.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/pyecsca/codegen/render.py b/pyecsca/codegen/render.py index ead1470..6ea1e36 100644 --- a/pyecsca/codegen/render.py +++ b/pyecsca/codegen/render.py @@ -26,9 +26,9 @@ env = Environment( loader=PackageLoader("pyecsca.codegen") ) - env.globals["isinstance"] = isinstance + def render_op(op: OpType, result: str, left: str, right: str, mod: str) -> Optional[str]: if op == OpType.Add: return "bn_mod_add(&{}, &{}, &{}, &{});".format(left, right, mod, result) @@ -48,8 +48,10 @@ def render_op(op: OpType, result: str, left: str, right: str, mod: str) -> Optio print(op, result, left, right, mod) return None + env.globals["render_op"] = render_op + def render_defs(model: CurveModel, coords: CoordinateModel) -> str: return env.get_template("defs.h").render(params=model.parameter_names, variables=coords.variables) @@ -233,7 +235,7 @@ def render(config: DeviceConfiguration) -> Tuple[str, str, str]: @public def build(dir: str, elf_file: str, hex_file: str, outdir: str, strip: bool = False, - remove : bool = True) -> subprocess.CompletedProcess: + remove: bool = True) -> subprocess.CompletedProcess: """ :param dir: @@ -248,7 +250,8 @@ def build(dir: str, elf_file: str, hex_file: str, outdir: str, strip: bool = Fal if res.returncode != 0: raise ValueError("Build failed!") if strip: - subprocess.run(["strip", elf_file], cwd=dir) + s = subprocess.run(["strip", elf_file], cwd=dir) + s.returncode full_elf_path = path.join(dir, elf_file) full_hex_path = path.join(dir, hex_file) shutil.copy(full_elf_path, outdir) @@ -271,4 +274,4 @@ def render_and_build(config: DeviceConfiguration, outdir: str, strip: bool = Fal """ dir, elf_file, hex_file = render(config) res = build(dir, elf_file, hex_file, outdir, strip, remove) - return dir, elf_file, hex_file, res
\ No newline at end of file + return dir, elf_file, hex_file, res |
