mirror of https://github.com/Nonannet/copapy.git
win stancils added
This commit is contained in:
parent
a965ab607e
commit
c7c3ad3553
|
|
@ -10,7 +10,7 @@ jobs:
|
|||
build_stencils:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install cross compilers
|
||||
run: |
|
||||
|
|
@ -19,7 +19,8 @@ jobs:
|
|||
gcc-12-aarch64-linux-gnu \
|
||||
gcc-12-arm-linux-gnueabihf \
|
||||
gcc-12-mips-linux-gnu \
|
||||
gcc-12-riscv64-linux-gnu
|
||||
gcc-12-riscv64-linux-gnu \
|
||||
gcc-12-mingw-w64-x86-64
|
||||
|
||||
- name: Build object files
|
||||
run: bash src/copapy/obj/crosscompile.sh
|
||||
|
|
@ -38,7 +39,7 @@ jobs:
|
|||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,28 @@ on:
|
|||
branches: [main]
|
||||
|
||||
jobs:
|
||||
build_stencils:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install cross compilers
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
gcc-12-mingw-w64-x86-64
|
||||
|
||||
- name: Build ops obj files
|
||||
run: |
|
||||
bash src/copapy/obj/nativecompile.sh
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: stencil-object-files
|
||||
path: src/copapy/obj/*.o
|
||||
|
||||
build-ubuntu:
|
||||
needs: [build_stencils]
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
|
|
@ -18,6 +39,16 @@ jobs:
|
|||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: stencil-object-files
|
||||
path: src/copapy/obj
|
||||
|
||||
- name: Install compiler
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-12-mingw-w64-x86-64
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
|
|
@ -26,25 +57,20 @@ jobs:
|
|||
- name: Install Python dependencies
|
||||
run: python -m pip install -e .[dev]
|
||||
|
||||
- name: Build ops obj files
|
||||
run: |
|
||||
bash src/copapy/obj/nativecompile.sh
|
||||
|
||||
- name: Compile coparun
|
||||
run: |
|
||||
mkdir -p bin
|
||||
gcc -O3 -Wall -Wextra -Wconversion -Wsign-conversion -Wshadow -Wstrict-overflow -Werror -g src/coparun/runmem.c src/coparun/coparun.c src/coparun/mem_man.c -o bin/coparun
|
||||
|
||||
- name: Run tests with pytest
|
||||
run: pytest
|
||||
|
||||
- name: Type checking with mypy
|
||||
run: mypy
|
||||
|
||||
#- name: Lint code with flake8
|
||||
# run: flake8
|
||||
|
||||
- name: Upload obj files
|
||||
uses: actions/upload-artifact@v4
|
||||
if: strategy.job-index == 0
|
||||
with:
|
||||
name: stencil-object-files
|
||||
path: src/copapy/obj/*.o
|
||||
|
||||
- name: Upload compiled runner
|
||||
uses: actions/upload-artifact@v4
|
||||
if: strategy.job-index == 0
|
||||
|
|
@ -52,14 +78,8 @@ jobs:
|
|||
name: runner-linux
|
||||
path: bin/*
|
||||
|
||||
- name: Run tests with pytest
|
||||
run: pytest
|
||||
|
||||
- name: Type checking with mypy
|
||||
run: mypy
|
||||
|
||||
build-windows:
|
||||
needs: [build-ubuntu]
|
||||
needs: [build_stencils]
|
||||
runs-on: windows-latest
|
||||
|
||||
strategy:
|
||||
|
|
|
|||
|
|
@ -14,14 +14,9 @@ def get_var_name(var: Any, scope: dict[str, Any] = globals()) -> list[str]:
|
|||
return [name for name, value in scope.items() if value is var]
|
||||
|
||||
|
||||
def get_local_arch() -> str:
|
||||
arch_translation_table = {'AMD64': 'x86_64'}
|
||||
return arch_translation_table.get(platform.machine(), platform.machine())
|
||||
|
||||
|
||||
def stencil_db_from_package(arch: str = 'native', optimization: str = 'O3') -> stencil_database:
|
||||
if arch == 'native':
|
||||
arch = get_local_arch()
|
||||
arch = platform.machine()
|
||||
stencil_data = pkgutil.get_data(__name__, f"obj/stencils_{arch}_{optimization}.o")
|
||||
assert stencil_data, f"stencils_{arch}_{optimization} not found"
|
||||
return stencil_database(stencil_data)
|
||||
|
|
@ -485,16 +480,15 @@ class Target():
|
|||
else:
|
||||
raise ValueError(f"Unsupported variable type: {var_type}")
|
||||
|
||||
|
||||
def read_variable_remote(self, net: Net) -> None:
|
||||
dw = binw.data_writer(self.sdb.byteorder)
|
||||
add_read_command(dw, self._variables, net)
|
||||
assert coparun(dw.get_data()) > 0
|
||||
|
||||
|
||||
def add_read_command(dw: binw.data_writer, variables: dict[Net, tuple[int, int, str]], net: Net) -> None:
|
||||
assert net in variables, f"Variable {net} not found in data writer variables"
|
||||
addr, lengths, _ = variables[net]
|
||||
dw.write_com(binw.Command.READ_DATA)
|
||||
dw.write_int(addr)
|
||||
dw.write_int(lengths)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class data_writer():
|
|||
with open(path, 'wb') as f:
|
||||
f.write(self.get_data())
|
||||
|
||||
|
||||
class data_reader():
|
||||
def __init__(self, data: bytes | bytearray, byteorder: ByteOrder):
|
||||
self._data = data
|
||||
|
|
@ -77,7 +78,7 @@ class data_reader():
|
|||
self._index += 1
|
||||
return ret
|
||||
|
||||
def read_bytes(self, num_bytes: int) -> bytes:
|
||||
def read_bytes(self, num_bytes: int) -> bytes | bytearray:
|
||||
ret = self._data[self._index:self._index + num_bytes]
|
||||
self._index += num_bytes
|
||||
return ret
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/',
|
|||
|
||||
def get_function_start() -> str:
|
||||
return """
|
||||
__attribute__((ms_abi)) int function_start(){
|
||||
int function_start(){
|
||||
result_int(0); // dummy call instruction before marker gets striped
|
||||
asm volatile (".long 0xE2401F0F");
|
||||
return 1;
|
||||
|
|
@ -17,7 +17,7 @@ def get_function_start() -> str:
|
|||
|
||||
def get_function_end() -> str:
|
||||
return """
|
||||
__attribute__((ms_abi)) int function_end(){
|
||||
int function_end(){
|
||||
result_int(0);
|
||||
asm volatile (".long 0xE1401F0F");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ mkdir -p $DEST
|
|||
# Native x86_64
|
||||
gcc-12 -$OPT -c $SRC -o $DEST/stencils_x86_64_$OPT.o
|
||||
|
||||
# Windows x86_64 (ARM64)
|
||||
x86_64-w64-mingw32-gcc -$OPT -c $SRC -o $DEST/stencils_AMD64_$OPT.o
|
||||
|
||||
# ARM64
|
||||
aarch64-linux-gnu-gcc-12 -$OPT -c $SRC -o $DEST/stencils_aarch64_$OPT.o
|
||||
|
||||
|
|
|
|||
|
|
@ -12,3 +12,6 @@ gcc-12 -c $SRC -O0 -o $DEST/stencils_x86_64_O0.o
|
|||
gcc-12 -c $SRC -O1 -o $DEST/stencils_x86_64_O1.o
|
||||
gcc-12 -c $SRC -O2 -o $DEST/stencils_x86_64_O2.o
|
||||
gcc-12 -c $SRC -O3 -o $DEST/stencils_x86_64_O3.o
|
||||
|
||||
# Windows x86_64 (ARM64)
|
||||
x86_64-w64-mingw32-gcc -O3 -c $SRC -o $DEST/stencils_AMD64_$OPT.o
|
||||
|
|
@ -9,7 +9,7 @@ START_MARKER = 0xE1401F0F # Nop on x86-64
|
|||
END_MARKER = 0xE2401F0F # Nop on x86-64
|
||||
MARKER_LENGTH = 4
|
||||
|
||||
# on x86_64: call or jmp instruction when tail call optimized
|
||||
# on x86_64: call or jmp instruction when tail call optimized
|
||||
LENGTH_CALL_INSTRUCTION = 5
|
||||
|
||||
RelocationType = Enum('RelocationType', [('RELOC_RELATIVE_32', 0)])
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from copapy import const, Target
|
||||
from pytest import approx
|
||||
import time
|
||||
|
||||
|
||||
def function(c1, c2):
|
||||
i1 = c1 * 3.3 + 5
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from copapy import Write, const
|
||||
import copapy
|
||||
import subprocess
|
||||
import struct
|
||||
from copapy import binwrite
|
||||
|
||||
|
||||
|
|
@ -51,6 +50,7 @@ def test_compile():
|
|||
print(result)
|
||||
assert 'Return value: 1' in result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#test_example()
|
||||
test_compile()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from copapy import stencil_database, stencil_db, get_local_arch
|
||||
from copapy import stencil_database, stencil_db
|
||||
import platform
|
||||
|
||||
|
||||
def test_list_symbols():
|
||||
arch = get_local_arch()
|
||||
arch = platform.machine()
|
||||
sdb = stencil_database(f'src/copapy/obj/stencils_{arch}_O3.o')
|
||||
print('----')
|
||||
#print(sdb.function_definitions)
|
||||
|
|
@ -12,7 +13,7 @@ def test_list_symbols():
|
|||
|
||||
|
||||
def test_start_end_function():
|
||||
arch = get_local_arch()
|
||||
arch = platform.machine()
|
||||
sdb = stencil_database(f'src/copapy/obj/stencils_{arch}_O3.o')
|
||||
for sym_name in sdb.function_definitions.keys():
|
||||
data = sdb.elf.symbols[sym_name].data
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ buffer_index: int = 0
|
|||
end_flag: int = 0
|
||||
program_data: bytearray = bytearray([])
|
||||
|
||||
while(end_flag == 0):
|
||||
while (end_flag == 0):
|
||||
com = dr.read_com()
|
||||
|
||||
if com == Command.ALLOCATE_DATA:
|
||||
|
|
|
|||
Loading…
Reference in New Issue