Resources for working with RISC-V in Python
Project description
riscvlib
Resources for working with RISC-V assembly in Python. Supporting RV32IMB(Zba, Zbb, Zbc, Zbs) 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 supports RV32IMB (RISC-V 32 bit I,M and B(Zba,Zbb,Zbc,Zbs) extensions)
Future
- Add F extension
- 64 bit support
Project details
Release history Release notifications | RSS feed
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 riscvlib-0.5.0.tar.gz.
File metadata
- Download URL: riscvlib-0.5.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29ee034b69b09efd252800b7be2d943c160e9eb7204896a537279faa6817ffd8
|
|
| MD5 |
65549cd7b9e52154853dc81218ca5920
|
|
| BLAKE2b-256 |
c3da52a43e99d0dcb5eb40a5cb43b19598b32ec032a639731cb01860004d49c9
|
Provenance
The following attestation bundles were made for riscvlib-0.5.0.tar.gz:
Publisher:
python-publish.yml on Mike451/riscvlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riscvlib-0.5.0.tar.gz -
Subject digest:
29ee034b69b09efd252800b7be2d943c160e9eb7204896a537279faa6817ffd8 - Sigstore transparency entry: 186941760
- Sigstore integration time:
-
Permalink:
Mike451/riscvlib@174e28e9ccea6b009edbe1d808906929744cc122 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/Mike451
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@174e28e9ccea6b009edbe1d808906929744cc122 -
Trigger Event:
release
-
Statement type:
File details
Details for the file riscvlib-0.5.0-py3-none-any.whl.
File metadata
- Download URL: riscvlib-0.5.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb7790e61e4000aff08a40c4d5b81040e5616c89f545de5e36c1ceebf53fba7
|
|
| MD5 |
10c72fb25ae55c4410f26cb98ce4bd9c
|
|
| BLAKE2b-256 |
1075294405a05f26592089b854b1b02af9896307edecc06855273ddf22d9027b
|
Provenance
The following attestation bundles were made for riscvlib-0.5.0-py3-none-any.whl:
Publisher:
python-publish.yml on Mike451/riscvlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riscvlib-0.5.0-py3-none-any.whl -
Subject digest:
eeb7790e61e4000aff08a40c4d5b81040e5616c89f545de5e36c1ceebf53fba7 - Sigstore transparency entry: 186941761
- Sigstore integration time:
-
Permalink:
Mike451/riscvlib@174e28e9ccea6b009edbe1d808906929744cc122 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/Mike451
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@174e28e9ccea6b009edbe1d808906929744cc122 -
Trigger Event:
release
-
Statement type: