copapy/tools/make_example.py

56 lines
1.3 KiB
Python
Raw Normal View History

from copapy import variable
from copapy.backend import Write, compile_to_dag, stencil_db_from_package
import copapy as cp
from copapy._binwrite import Command
2025-11-03 14:21:33 +00:00
def compile_to_x86_64() -> None:
"""Test compilation of a simple program for x86_64."""
c1 = variable(9.0)
2025-10-12 20:22:30 +00:00
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
ret = [c1 // 3.3 + 5]
#ret = [cp.sqrt(c1)]
#c2 = cp._math.get_42()
#ret = [c2]
2025-10-12 20:22:30 +00:00
out = [Write(r) for r in ret]
2025-11-03 14:21:33 +00:00
sdb = stencil_db_from_package('x86_64')
dw, _ = compile_to_dag(out, sdb)
2025-10-12 20:22:30 +00:00
2025-11-03 14:21:33 +00:00
dw.write_com(Command.DUMP_CODE)
2025-10-12 20:22:30 +00:00
print('* Data to runner:')
dw.print()
2025-10-12 20:22:30 +00:00
dw.to_file('bin/test.copapy')
2025-10-12 20:22:30 +00:00
2025-11-03 14:21:33 +00:00
def compile_to_aarch64() -> None:
"""Test compilation of a simple program for aarch64."""
c1 = variable(9.0)
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
#ret = [cp.sin(c1), cp.sqrt(c1) + 5]
2025-11-03 14:21:33 +00:00
ret = [c1 // 3.3 + 5]
#c2 = cp._math.get_42()
#ret = [c2]
out = [Write(r) for r in ret]
sdb = stencil_db_from_package('aarch64')
2025-11-03 14:21:33 +00:00
dw, _ = compile_to_dag(out, sdb)
dw.write_com(Command.DUMP_CODE)
print('* Data to runner:')
dw.print()
dw.to_file('bin/test-aarch64.copapy')
2025-10-12 20:22:30 +00:00
if __name__ == "__main__":
2025-11-03 14:21:33 +00:00
compile_to_x86_64()
compile_to_aarch64()