1.1.2 • Published 5 years ago
@jupitersim/riscv v1.1.2
RISC-V JavaScript Parser (RV32G)
A JavaScript RISC-V RV32G Parser based on ANTLRv4
Installation
npm install @jupitersim/riscvyarn add @jupitersim/riscvBasic Usage
You should extend the base RISCV RV32G listener and then override the methods that listen to the instructions that you want to handle in your application. Here is an example of a basic translator that listens to add instructions and converts each one to their raw form (i.e without register mnemonics).
import RISCV from '@jupitersim/riscv';
// Extends from RISCV RV32G listeners
class Translator extends RISCV {
// listens to add instructions
add(ctx) {
console.log(`add x${ctx.rd}, x${ctx.rs1}, x${ctx.rs2}`);
}
}
// input data
const data = {
filename: 'test.s',
code: `
add a0, a1, a2
`,
globals: {}
};
// parser options
const options = {
allowPseudos: false // if pseudos are used, will be considered as errors
};
const translator = new Translator(data, options);
translator.parse(); // prints add x10, x11, x12
console.log(translator.errors); // prints a list of errorsFor more information see the documentation.