Code Monkey home page Code Monkey logo

decaf-compiler's Introduction

DECAF Compiler

Sai Teja Reddy Moolamalla

Make instructions:

  • From the directory where the Makefile is present, run: make
  • Using the Compiler: ./decaf_compiler <input_file>
  • Running the generated LLVM IR: lli output_final.decaf
  • To delete all the object files: make clean

File Breakdown

.
|-- Decafspec.pdf - The Specifications of the _decaf_ compiler
|-- Makefile - The Makefile to build the source code
|-- PostfixVisitor.h - Visitor Pattern for traversing the built AST
|-- ast.cpp - AST code file
|-- ast.h - AST header file and class declarations
|-- common.cpp - Common Static Variables for AST Building
|-- common.h - Header File for common.cpp
|-- decaf_lib.c - Personalised library made by user for DECAF compiler to use
|-- decaf_linker.sh - Linker for decaf scripts
|-- parser.ypp - Parser File
|-- scanner.l - Scanner File
|-- test-programs - Few test-programs

Description

Implementation Details: The scanner.l code is utilized in scanning the tokens from the input file, the stream of the generated tokens is given as input to the parser. The parser.ypp file generates an AST representation of the given input file. We then do a traversal of the constructed AST using PostfixVisitor.h to check for few semantic errors in the constructed AST. Then, using the generate_code function in each AST node we get a dump of the LLVM IR from the AST, into the output_final.decaf file. decaf_lib.c is the file to add custom functions by the user in C-Language for the decaf compiler to support. These library functions are linked to the generated LLVM dump using decaf_linker.sh.

Things to Complete:

  • Exhaustive Testing for Errors
  • Run Time Checking - dynamically during runtime, checking for the subscript of an array if in bounds.

Example Runs

GCD Example - prints out GCD of two numbers

$ ./decaf_compiler test-programs/gcd.dcf 
Now generating code
Errors during IR Generation: 0
Generating LLVM IR Code

Done linking decaf code

Parsing Over

$ lli output_final.decaf 
gcd of 3 and 12 is 3

MergeSort Example - Sort an array recursively

$ ./decaf_compiler test-programs/merge_sort.dcf
Now generating code
Errors during IR Generation: 0
Generating LLVM IR Code

Done linking decaf code

Parsing Over

$ lli output_final.decaf 
sorted array : 1 2 3 4 5 6 7 8 9 10 

ArraySum Example - sum of elements in input array

$ ./decaf_compiler test-programs/arraysum.dcf 
Now generating code
Errors during IR Generation: 0
Generating LLVM IR Code

Done linking decaf code

Parsing Over

$ lli output_final.decaf 
Enter the number of elements in the array: 3
Enter the elements in the array: 
1 12 -1
The sum of elements in the array is: 12

decaf-compiler's People

Contributors

saiteja-reddy avatar

Watchers

James Cloos 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.