Skip to main content

Resources for working with RiscV in Python

Reason this release was yanked:

Contains Major Bugs

Project description

riscvlib

Resources for working with RiscV assembly in Python. Supporting RV32IM instruction creation, pseudo instruction translation and register lookup.

Installation

The package can be installed using pip:

 $ pip install riscvlib  

Examples

Instruction, Static creation from a string

>> from riscvlib.instruction import Instruction  

>> i = Instruction.from_line("add x1, x2, x3")  
>> print(i) 
add x1, x2, x3  
>> i.to_bytes() 
b'\xb3\x001\x00'  
>> i  
RInstruction 'add' ['x1', 'x2', 'x3']

Specific Instruction Type

>> from riscvlib.instruction import RInstruction, IInstruction

>> r_instr = RInstruction("add", "x1", "x2", "a2")
>> print(r_instr)
add x1, x2, a2

>> i_instr = IInstruction("andi", "a0", "a1", -13)
>> print(i_instr)
andi a0, a1, -13
>> i_instr.to_bytes()  # note: bytes are 'little endian' ordered
b'\x13\xf55\xff'

Pseudo Instruction Translation

>> from riscvlib.instruction import translate_pseudo_instruction

>> out_list = translate_pseudo_instruction("mv", "a0", "x30")
>> print(out_list)
['addi a0, x30, 0']

>> out_list = translate_pseudo_instruction("la", "a0", "400")
>> print(out_list)
['lui a0, %hi(400)', 'addi a0, a0, %lo(400)']

Instruction Data

>> from riscvlib.risvdata import INSTRUCTION_MAP

>> INSTRUCTION_MAP['mul']
('MUL', '0110011', '000', '0000001', 'R', 'm')
# (name, opcode, func3, func7, itype, extension)

Limitations

  • Currently only supports RV32IM (RiscV 32 bit I and M extensions)

Future

  • Add B extension
  • Add F extension/register look-ups
  • 64 bit support (far future)

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

riscvlib-0.4.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

riscvlib-0.4.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file riscvlib-0.4.0.tar.gz.

File metadata

  • Download URL: riscvlib-0.4.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for riscvlib-0.4.0.tar.gz
Algorithm Hash digest
SHA256 520df7fcf237afa6958609c8e022f0c3392069d9ffab31357b75a7d16a4bfd2f
MD5 d39cfce004b7eb5ca9cfb97729e11ec3
BLAKE2b-256 50197cf998f06b9205de6d8a9729ab3119572c5502f07cbccd9adc7f5203e16f

See more details on using hashes here.

Provenance

The following attestation bundles were made for riscvlib-0.4.0.tar.gz:

Publisher: python-publish.yml on Mike451/riscvlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file riscvlib-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: riscvlib-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for riscvlib-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51756370b2890f8959c847a2dc20f5abf54549bcc9aa7168aa6bb5fe3802ca29
MD5 865839d69f44bcffff765873c9a8bd2d
BLAKE2b-256 1e23d791d8dcd22558b4e80201cf93a826abc0405d3a2aacf8ff0f6d1adc22bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for riscvlib-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on Mike451/riscvlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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