Skip to content

WCTC: Who Compiles The Compiler is a compiler made as a part of the course project for the course CS335 "Compiler Design" at IIT-K in 2022-23 II Sem.

Notifications You must be signed in to change notification settings

cliche-niche/WCTC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WCTC: Who Compiles the Compiler

A compiler made as a part of the course project for the course CS335: Compiler Design at IIT-K in 2022-23 II Sem. in a team of three (Soham CrypthiccCrypto Samaddar, Janhvi Janhvi-Rochwani Rochwani, and me, Aditya cliche-niche Tanwar).

Introduction

For all your integral only java needs (rounded to the nearest 8 bytes, {using only this class [no object arrays]}), we present to you WCTC, a compiler that compiles Java code to x86_64 assembly code.
A complete summary of the functionalities provided can be found in Milestone 4's report, and the final presentation of the project is available here.

Running

cd src
make
./WCTC.o -h

This will let you know how to run WCTC.o, however, you can also use run.sh to run the WCTC.o against an input java file.

Dependencies

The source code is written in Flex, Bison (C++ used) and C++. Dot is used to construct the syntax trees. gcc is used to compile the generated assembly code.

Functionalities

Basic Functionalities

  • Primitive data types (int-like data types, booleans too, as long as true and false are not used explicitly)
  • Multi-dimensional arrays
  • Printing integers
  • All basic operators
  • Control flow using if-else, and for/while loops
  • Methods and method calls (both static and non-static)
  • Recursion
  • Classes and objects (using this pointer only)
  • Declarative and Non-declarative statements

Bonus Features Implemented

  • Arrays can have any number of dimensions, and size can be resolved at run-time
  • Support for default constructors
  • Static polymorphism (Method overloading)
  • Passing arrays as function arguments
  • Passing objects as function arguments
  • Passing by reference
  • Primitive Typecasting
  • 3AC optimizations
    • Removed redundant temporaries
    • Renamed temporaries and jump instructions
    • Constant Folding
    • Constant Propagation
    • Algebraic Simplification

Unsupported Functionalities

  • Accessing an object's member variables without using this pointer
  • static and final not supported

Miscellaneous bug feature

Variable name l is not supported as the WCTC compiler does not take any L's. (We really do not know why there is undefined behaviour on using the variable name l, we tried to debug it a lot.)


Milestones

Milestone 1

Make a lexer and a parser for Java 17 which can generate ASTs for correct Java programs.
98/100. Minor edge case missed

Milestone 2

Extend the compiler to generate 3AC (three address code) for correct Java programs. Report errors like type errors, if any.
100/100.

Milestone 3

Extend the 3AC to include stack pointer manipulations.
70/100. Static and final not supported (should have been 80/100).

Milestone 4

Extend the compiler to generate x86_64 assembly code which can be compiled using gcc.
98/100. No feedback provided.

Project Implementation

Awarded 3/3 for implementation and bonus (mean was 0.6).

Parting Comments

To a stressful four months, and being one of the last few batches to ever have to do 'cs335'. We are very proud of what we have built, no matter how rudimentary, or how buggy, even if it led to a lot of sleepless nights and missing (cs335) classes.
- JAZ Hands

About

WCTC: Who Compiles The Compiler is a compiler made as a part of the course project for the course CS335 "Compiler Design" at IIT-K in 2022-23 II Sem.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published