Skip to main content

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

nyxstone_tricore_gcc-0.1.1.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyxstone_tricore_gcc-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file nyxstone_tricore_gcc-0.1.1.tar.gz.

File metadata

  • Download URL: nyxstone_tricore_gcc-0.1.1.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

Hashes for nyxstone_tricore_gcc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cd51ab6a42dfba583493f1aa0ae84cb62ecb2f487aec1d4352eaedce234a0bbc
MD5 9720791378e6c38424409ca21b846acf
BLAKE2b-256 f9409f078712e3c313c58ab7dc5c8f55c12388932575ef5a75f19740e331b79c

See more details on using hashes here.

File details

Details for the file nyxstone_tricore_gcc-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nyxstone_tricore_gcc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3dc416ba5d1ce0af97c58d4d881ed2d3e1e4abf48fe466380be03b4d5337fcb
MD5 1d75fe2c447ff65a7f99d2d2f1ee3e79
BLAKE2b-256 0af3589bcc3c7c4f300ebe49707bc934e0f82133fed12b8dac1bf4687fe08338

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page