@jupitersim/riscv

RISC-V RV32G Parser


Keywords
risc-v, parser, rv32g, jupitersim, antlr, antlr4, grammar, javascript, node, riscv
License
Apache-2.0
Install
npm install @jupitersim/riscv@1.1.2

Documentation

RISC-V JavaScript Parser (RV32G)

license npm Build codecov

A JavaScript RISC-V RV32G Parser based on ANTLRv4

Installation

npm install @jupitersim/riscv
yarn add @jupitersim/riscv

Basic 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 errors

For more information see the documentation.