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.0.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.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nyxstone_tricore_gcc-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f8a1c27178b63d64898d67274bb005e2339266f9ff156da5783fcd7f648bfb49
MD5 52c3c9c9973a9b95323089ea6ac11215
BLAKE2b-256 8abd914bf15800ac5cdd02c354bd9019f199e5885301ddc595869251c58afd03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nyxstone_tricore_gcc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 280766c3e1ec0fe8fdd485ab2b61e6d98e0df4e4e192d927344d7f55b286ed23
MD5 e0246ba1f136fe761fb2c2ccd1178364
BLAKE2b-256 12e4eaec37a4b5e2fefb2fe0667a2f51d6537e5b950c60bf50779f6fb7a94bf8

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