2025-10-26 21:30:38 +00:00
|
|
|
from copapy import variable
|
2025-10-30 09:55:23 +00:00
|
|
|
from copapy.backend import Write, compile_to_dag, stencil_db_from_package
|
2025-10-26 21:30:38 +00:00
|
|
|
from copapy._binwrite import Command
|
2025-11-10 19:09:54 +00:00
|
|
|
import copapy as cp
|
2025-11-03 14:01:42 +00:00
|
|
|
|
|
|
|
|
|
2025-11-03 14:21:33 +00:00
|
|
|
def compile_to_x86_64() -> None:
|
|
|
|
|
"""Test compilation of a simple program for x86_64."""
|
2025-10-26 12:21:35 +00:00
|
|
|
c1 = variable(9.0)
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
2025-10-26 21:30:38 +00:00
|
|
|
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:')
|
2025-10-26 21:30:38 +00:00
|
|
|
dw.print()
|
2025-10-12 20:22:30 +00:00
|
|
|
|
2025-10-26 21:30:38 +00:00
|
|
|
dw.to_file('bin/test.copapy')
|
2025-10-12 20:22:30 +00:00
|
|
|
|
|
|
|
|
|
2025-11-10 19:09:54 +00:00
|
|
|
def compile_to_x86() -> None:
|
|
|
|
|
"""Test compilation of a simple program for x86 32 bit."""
|
|
|
|
|
c1 = variable(9.0)
|
|
|
|
|
|
|
|
|
|
#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]
|
|
|
|
|
ret = [cp.sin(variable(2.5))]
|
|
|
|
|
|
|
|
|
|
out = [Write(r) for r in ret]
|
|
|
|
|
|
|
|
|
|
sdb = stencil_db_from_package('x86')
|
|
|
|
|
dw, _ = compile_to_dag(out, sdb)
|
|
|
|
|
|
|
|
|
|
dw.write_com(Command.DUMP_CODE)
|
|
|
|
|
|
|
|
|
|
print('* Data to runner:')
|
|
|
|
|
dw.print()
|
|
|
|
|
|
|
|
|
|
dw.to_file('bin/test-x86.copapy')
|
|
|
|
|
|
|
|
|
|
|
2025-11-03 14:21:33 +00:00
|
|
|
def compile_to_aarch64() -> None:
|
2025-11-11 07:47:52 +00:00
|
|
|
"""Test compilation of a simple program for arm64."""
|
2025-10-30 09:55:23 +00:00
|
|
|
c1 = variable(9.0)
|
|
|
|
|
|
|
|
|
|
#ret = [c1 / 4, c1 / -4, c1 // 4, c1 // -4, (c1 * -1) // 4]
|
2025-11-03 14:01:42 +00:00
|
|
|
#ret = [cp.sin(c1), cp.sqrt(c1) + 5]
|
2025-11-03 14:21:33 +00:00
|
|
|
ret = [c1 // 3.3 + 5]
|
2025-10-30 09:55:23 +00:00
|
|
|
#c2 = cp._math.get_42()
|
|
|
|
|
#ret = [c2]
|
|
|
|
|
|
|
|
|
|
out = [Write(r) for r in ret]
|
|
|
|
|
|
2025-11-10 19:09:54 +00:00
|
|
|
sdb = stencil_db_from_package('arm64')
|
2025-11-03 14:21:33 +00:00
|
|
|
dw, _ = compile_to_dag(out, sdb)
|
2025-10-30 09:55:23 +00:00
|
|
|
|
2025-11-03 14:01:42 +00:00
|
|
|
dw.write_com(Command.DUMP_CODE)
|
2025-10-30 09:55:23 +00:00
|
|
|
|
|
|
|
|
print('* Data to runner:')
|
|
|
|
|
dw.print()
|
|
|
|
|
|
2025-11-11 07:47:52 +00:00
|
|
|
dw.to_file('bin/test-arm64.copapy')
|
2025-10-30 09:55:23 +00:00
|
|
|
|
|
|
|
|
|
2025-10-12 20:22:30 +00:00
|
|
|
if __name__ == "__main__":
|
2025-11-03 14:21:33 +00:00
|
|
|
compile_to_x86_64()
|
2025-11-10 19:09:54 +00:00
|
|
|
compile_to_x86()
|
2025-11-03 14:21:33 +00:00
|
|
|
compile_to_aarch64()
|