docstrings added and descriptions for c files added

This commit is contained in:
Nicolas Kruse 2026-02-05 14:26:07 +01:00
parent 7131483a22
commit e52cbe9e1b
8 changed files with 55 additions and 6 deletions

View File

@ -429,8 +429,8 @@ class Op(Node):
def __hash__(self) -> int:
return self.node_hash
# Interface for vector and tensor types
class ArrayType(Generic[TNum]):
"""Interface for vector and tensor types."""
def __init__(self, shape: tuple[int, ...]) -> None:
self.shape = shape
self.values: tuple[TNum | value[TNum], ...] = ()

View File

@ -134,7 +134,7 @@ def get_const_nets(nodes: list[Node]) -> list[Net]:
def add_load_ops(node_list: list[Node]) -> Generator[tuple[Net | None, Node], None, None]:
"""Add read node before each op where arguments are not already positioned
"""Add load/read node before each op where arguments are not already positioned
correctly in the registers
Arguments:
@ -172,7 +172,7 @@ def add_load_ops(node_list: list[Node]) -> Generator[tuple[Net | None, Node], No
def add_store_ops(net_node_list: list[tuple[Net | None, Node]], const_nets: list[Net]) -> Generator[tuple[Net | None, Node], None, None]:
"""Add write operation for each new defined net if a read operation is later followed
"""Add store/write operation for each new defined net if a read operation is later followed
Returns:
Yields tuples of a net and a node. The associated net is provided for read and write nodes.

View File

@ -32,11 +32,14 @@ class relocation_entry:
@dataclass
class patch_entry:
"""
A dataclass for representing a relocation entry
A dataclass for representing a patch entry
Attributes:
addr (int): address of first byte to patch relative to the start of the symbol
type (RelocationType): relocation type
mask (int): Bit-mask to apply to the patched value
address (int): Address where to patch
value (int): The value to write at the patch address
scale (int): The scale factor for the patch value
patch_type (int): The type of patch
"""
mask: int
address: int
@ -46,6 +49,11 @@ class patch_entry:
def detect_process_arch() -> str:
"""
For running the code locally in the python module
the architecture of the current process is detected
by this function to load the correct stencil database.
"""
bits = struct.calcsize("P") * 8
arch = platform.machine().lower()

View File

@ -1,3 +1,15 @@
/*
* file: coparun.c
* Description: This file alows to run copapy programs in the command line
* reading copapy data, code and patch instructions from a file and jump to the
* entry point to execute it or dump the patched code memory for debugging to a file.
*
* It's intended for testing and debugging purposes, to run copapy programs in a
* debugger or emulator like qemu.
*
* Usage: coparun <code_file> [memory_dump_file]
*/
#include <stdio.h>
#include <stdlib.h>
#include "runmem.h"

View File

@ -1,3 +1,10 @@
/*
* file: coparun_module.c
* Description: This file defines a Python C extension module that provides an
* interface to the core functions of the coparun runner, to run copapy programs
* directly local in Python.
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "runmem.h"

View File

@ -1,3 +1,11 @@
/*
* file: mem_man.c
* Description: This file contains memory management functions for the coparun
* runner, including allocation and deallocation of executable and data memory.
* Depending of the target operating system or bare metal environment, it
* handles memory management accordingly.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

View File

@ -1,3 +1,10 @@
/*
* file: runmem.c
* Description: This file contain the core functions of the runner
* to receive data, code and patch instruction, does the patching
* and jumps to the entry point of the copapy program
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,3 +1,10 @@
/**
* @file runmem.h
* @brief Header file for runmem.c, which contains core functions of
* the runner to receive data, code and patch instructions, perform
* patching, and jump to the entry point of the copapy program.
*/
#ifndef RUNMEM_H
#define RUNMEM_H