Skip to content

raghudotcc/pywasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pycomp

Experimental(toy) python compiler written in Python with support for x86 and WASM targets.

Features

  • Implement x86 IR and WAT
  • Add closure support
  • Primitive Escape Analysis for closure
  • Generate Inteference Graph for register allocatoin
  • Fixed point register allocation(using graph coloring) for x86
  • Create CFG with BB
  • Fixed point liveness analysis on the basic blocks
  • Basic dead store elimination using liveness analysis
  • Constant Propagation/Copy Folding using Local value numbering on the CFG
  • Support for Control Flow Statement (Ternary, If and While)
  • Support for Lambda Function (Anonymous, Named and Closure)
  • Support for Class
  • Support for Comparison and Logical Operator
  • Support for Arithmetic Operator
  • Add Single Static Assignment (SSA)
  • Add Dominance Analysis
  • Add Dominance Frontier Analysis
  • Add Reaching Definition Analysis
  • Resolve Phi Nodes
  • Convert CRuntime to WASM using Emscripten

Usage

  1. Compilation:
./pycomp [--wasm | -w] [--x86 | -x] <input_file.py>

Flags are optional. > --wasm: Compile to WebAssembly. > --x86: Compile to x86-64. > <input_file.py>: Input file.

x86

  1. Execution:
./input_file_binary

WASM

  1. Execution:

Start the web server from the root folder:

python3 -m http.server
  1. Checking the output:
  • Go to http://localhost:8000/ on your browser.
  • Open the index.html file.
  • Open DevTools and click on the Console tab.
  • Call the wasm function that you are interested in.