Skip to content

Pymx is a compiler written in Python 3 for the M* language which is a toy language. The compiler is intended to support to generate rv32im code from a java-like language.

License

Notifications You must be signed in to change notification settings

cla7aye15I4nd/Pymx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pymx

A hapy compiler created in Python


Pymx is a compiler written in Python 3 for the M* language, M* is a toy language in course Compiler 2020 at ACM Class, Shanghai Jiao Tong University. The compiler is intended to support to generate rv32im code.

Usage

$ pymx -h
usage: run.py [-h] [-d] [-c] [-l IR_FILE] [-s ASM_FILE] files [files ...]

Pymx is a Mx compiler created in Python

positional arguments:
  files        Source file

optional arguments:
  -h, --help   show this help message and exit
  -d           Developer option
  -c           Syntax check only
  -l IR_FILE   Intermediate code file
  -s ASM_FILE  Target file

Implementation Overview

Stage

Lexer

Lexer is implemented in lexer, It will generate a Token List. tokens.py defines token classes and keywords table, and lexer.py matches the source code greedily.

Parser

The Parser will parse the token list to AST and do the semantic check, tree contains the definitions of the syntax tree. Parse instance is implemented in parser, it is a recursive descent parser.

IR generation

Pymx traverses the syntax tree to generate linear intermediate code called TypeLess LL. The commands' format looks like LLVM IR but just keep partial instructions and without type system. TypeLess LL only care the size of each data. It is defined in inst.py. Most optimizations are carried out at this stage.

ASM generation

Pymx generate the RISCV target code from TypeLess LL code, live analysis and register allocation will be performed at this stage, and will do some simple peephole optimization.

Optimize

Mem2reg

Peephole

CFG simplify

DCE (Dead Code Eliminate)

GVN (Global Value numbering)

Reference

About

Pymx is a compiler written in Python 3 for the M* language which is a toy language. The compiler is intended to support to generate rv32im code from a java-like language.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published