Giter VIP home page Giter VIP logo

ravel's Introduction

ravel

master dev
Build Status Build Status

Introduction

ravel is a RISC-V simulator written for the compiler course taught at Shanghai Jiao Tong University, where the students are typically second-year undergraduates at ACM Honers Class. In this course, students are required to implement a toy compiler that turns Mx* (a toy language used in the course) to RISC-V assembly. This simulator is used to test the correctness of the implementation and measure the quality of the optimization.

Getting started

The only prerequisites are CMake (>= 3.10) and a cpp-17 supporting compiler. You can install the simulator with the following commands.

git clone https://github.com/Engineev/ravel.git
cd ravel
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/opt  # or any directory you want
make 
make install
export PATH="/usr/local/opt/bin:$PATH"  # optional

The easiest way to start a simulation is to use the OJ mode, that is,

ravel --oj-mode

Under this mode, the simulator takes test.s and builtin.s as the source code, test.in as the input and redirect the program output into test.out. The results (e.g. exit code) of the simulation will still be outputted directly to stdout. This is equivalent to

ravel --input-file=test.in --output-file=test.out test.s builtin.s 

If you'd like to see the instructions being executed, you may pass in command line option --print-instructions, but note that this will slow down the simulation significantly. Also, if --keep-debug-info is passed in, ravel will perform more checks on memory access and will print information like the call stack if an error occurred, which might be helpful.

Support

In short, if the assembly resembles the one generated with the following command,

riscv32-unknown-linux-gnu-gcc -S -std=c99 -fno-section-anchors main.c

where the build of gcc is configured with

./configure --prefix=/opt/riscv --with-arch=rv32ima --with-abi=ilp32

then in most cases it is supported by the simulator. For LLVM users, the command should be

llc --march=riscv32 --mattr=+m main.ll

See this for information on the risc-v toolchain. For detail on supported directives, instructions and libc functions, see this.

Computing the running time

The output of ravel contains a time filed. This is computed in the following way. For each type of instructions, the number of execution is recorded during the interpretation, and time is computed by a weighted summation. The default weights are listed in the following table. You can change the weights by passing in command line options like -wsimple=2. By default, cache is disabled. You may enable it by passing in --enable-cache.

Type Weight
simple 1
cache 4
mul 4
br 8
div 8
mem 64
libcIO 64
libcMem function-dependent

Note: Unconditional jumps are viewed as simple instructions, and the weights used in the test are still subject to change.

ravel's People

Contributors

engineev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.