Giter Site home page Giter Site logo

dragoncompiler's Introduction

DragonCompiler

PASCAL compiler implemented in C for CS445


Haiku

Dragon Compiler,
which took a whole semester,
it breathes fire at last.

User Guide

PASCAL files can be compiled using the command ./compiler <file_name.p>. The command gcc <file_name.s> will then convert the generated assembly file to an executable, which can be run with ./a.out.

Status Report

At this point, I think my compiler has successfully implemented all of the required components of a compiler for this class. For more details regarding the specified requirements, please see checklist.txt. All test cases are located in the subdirectory testing/.

Unique Feature

My compiler has an incredibly unique strategy to resolve potential if then if then else conflicts. Rather than specifying that each else belongs to the nearest if, I instead modified the keywords so that the two control flow statements are if then and if than else. This will reduce programmer confusion and make it immediately apparent to which if clause the else begins.

I also included a few additional control flow statements, such as repeat ... until and do ... while.

Design Document

  1. Register Usage:
	rax = return value, division
	rbx = for loops
	rcx = nonlocal variable access
	rsp = stack pointer
	rbp = base pointer
	rip = instruction pointer

	rdi = reserved for io use, temp regs
	rsi = reserved for io use, temp regs
	rdx = reserved for io use, division
	

	r8  = temp var (top of stack)
	r9  = temp var
	r10 = temp var	
	r11 = temp var
	r12 = temp var
	r13 = temp var
	r14 = temp var
	r15 = temp var (bottom of stack)
  1. Stack Frame Contents:
   low memory addresses
            .
            .
            .
   -------------------
   |     temp_reg3   | 	<--- rsp
   -------------------
   |     temp_reg2   |
   -------------------
   |     temp_reg1   |
   -------------------
   |     local3      |
   -------------------
   |     local2      |
   -------------------
   |     local1      |
   -------------------
   |     parent      |  rbp - 16
   -------------------
   |     return_val  |  rbp - 8
   -------------------
   |     old_rbp     | 	<--- rbp
   -------------------
   |     old_rip     |	(automatically added/removed by call/ret)
   -------------------
   |     param3      |
   -------------------
   |     param2      |
   -------------------
   |     param1      |
   -------------------
            .
            .
            .
   high memory addresses
  1. Register Stack
   -------------------  		the value of each register is its initial index
   |       r8        | 7		positive-index values are stored in reg array
   -------------------			register name is given by static name list
   |       r9        | 6
   -------------------
   |       r10       | 5
   -------------------
   |       r11       | 4
   -------------------
   |       r12       | 3
   -------------------
   |       r13       | 2
   -------------------
   |       r14       | 1
   -------------------
   |       r15       | 0
-------------------------		negative-index values stored in temp array
   |      temp1      | -1		index 0 of temp array is never used
   -------------------			names are calculated based on offset from rbp
   |      temp2      | -2		temp array can grow to arbitrary size
   -------------------
   |      temp3      | -3
   -------------------
            .
            .
            .

Room for Improvement

Some potential extensions of my existing compiler are:

  • adding support for strings or pointers
  • generating code for arrays and floating point numbers

dragoncompiler's People

Contributors

timd1 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.