In-process TriCore assembler/disassembler, Python bindings around binutils-tricore (gas + libopcodes).
Project description
nyxstone-tricore-gcc (Python)
Python bindings to the NyxstoneTricoreGCC in-process TriCore assembler/disassembler.
Uses CFFI to compile a small C extension that statically links the C++
side (libnyxstone_tricore.a) and the binutils archives. No runtime
shared library needed.
The API mirrors that of the sibling project
Nyxstone (LLVM-MC based, covers
LLVM-supported architectures; this package uses GNU binutils for TriCore).
Four methods named assemble, assemble_to_instructions, disassemble,
and disassemble_to_instructions, each taking an absolute address (and
for the assembly entry points, an iterable of LabelDefinition).
Install
The C++ library must be built first:
(cd ..; make)
Then install the Python package:
pip install ./ # from the python/ directory
Or develop in-place:
python setup.py build_ext --inplace
python examples/smoke.py
Usage
from nyxstone_tricore_gcc import LabelDefinition, NyxstoneTricoreGCC
nx = NyxstoneTricoreGCC()
# Assemble.
bytes_ = nx.assemble("start:\n nop\n j here\nhere:\n ret\n", address=0)
assert bytes_ == b"\x00\x00\x1d\x00\x00\x00\x00\x90"
# Assemble with an external label.
bytes2 = nx.assemble(
"nop\n j ext\n",
address=0x1000,
labels=[LabelDefinition("ext", 0x2000)],
)
# Disassemble to instructions.
for ins in nx.disassemble_to_instructions(bytes_, address=0x80000000):
print(f"0x{ins.address:08x} {ins.assembly}")
# Or as a single string.
print(nx.disassemble(bytes_, address=0x80000000))
# Limit the number of instructions decoded.
first_two = nx.disassemble_to_instructions(bytes_, address=0, count=2)
Errors
from nyxstone_tricore_gcc import NyxstoneTricoreGCC, AssembleError, SectionViolationError
nx = NyxstoneTricoreGCC()
try:
nx.assemble("not_a_real_mnemonic %d4")
except AssembleError as e:
print("encoder failed:", e)
try:
nx.assemble(".data\n .byte 0x42\n")
except (SectionViolationError, AssembleError) as e:
# The library is .text-only; data/bss/section .foo are rejected.
print("non-.text section:", e)
Threading
Methods are safe to call from multiple threads, a process-wide
threading.Lock serializes them.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nyxstone_tricore_gcc-0.1.2.tar.gz.
File metadata
- Download URL: nyxstone_tricore_gcc-0.1.2.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42ae02bfa3cd5e8e65f9c6ca0ea548d2664c05643291508741256814c348976d
|
|
| MD5 |
cbdbc204285ea67c4f17eecf430456fc
|
|
| BLAKE2b-256 |
d440bc9d7dc8fc6490fcdb32a8f01e096d8edae72681559004c4f599b8602566
|
File details
Details for the file nyxstone_tricore_gcc-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nyxstone_tricore_gcc-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e012d340d614d4c6e62ac812c20c63db081fbbe6b1bbe9e9212320d5dfac5ed6
|
|
| MD5 |
62fe950c3b6092de3c476914e14b7bc0
|
|
| BLAKE2b-256 |
67eafa026f9a0e8ac549307e6b1ef3e59758259a3f14e339b9086f8a0250a703
|