GithubHelp home page GithubHelp logo

shivansh / gogo Goto Github PK

View Code? Open in Web Editor NEW
27.0 6.0 6.0 1.03 MB

Go to MIPS compiler, written in Go. Course project for Compiler Design (CS335).

License: MIT License

Makefile 0.48% Shell 2.56% Go 70.78% Assembly 20.15% HTML 6.03%
go mips compiler peephole reaching-definitions garbage-collection gocc

gogo's Introduction

gogo

Build Status

Go to MIPS compiler, written in Go.

Logo

Gopher vector imported from egonelbre/gophers .


Components

Component Demo
Token generation / Lexer test1.out
Parser struct.go ➡️ struct.html
IR generation scope.go ➡️ scope.ir
Code generation pascalTriangle.ir ➡️ pascalTriangle.asm

Setting up

Run ./scripts/setup.sh from the root directory of the project to set up the pre-commit git hooks.

Dependencies

Build

The following should generate relevant binaries inside the directory bin -

make

The generated binary bin/gogo can be used as follows -

Usage: gogo (-r | -r2s | -s) <filename>
  -p	Generates rightmost derivations used in bottom-up parsing
  -r	Generates IR instructions from go program
  -r2s  Generates the MIPS assembly from IR
  -s	Generates MIPS assembly from go program

NOTE: The generated MIPS assembly has been tested to work on SPIM MIPS32 simulator.

Testing

The tests can be built via -

make test

gogo's People

Contributors

aniketp avatar kpsunil avatar shivansh avatar tvatsal1996 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gogo's Issues

Figure out data types

Currently every variable and value is being treated as a string, and the type information is stored in SrcVar.Typ ; Instead of this resolve types when reading from IR file itself, and store for e.g. 1 as int instead of string (which is the case currently). This update should be done in the lexing step too where everything was also a string despite of the actual data type. This will be useful in the parsing step.

SrcVar should be renamed to something like SymInfo and each entity read from the IR file should point to a SymInfo object where the information about that entity (data type, scoping info etc.) will be located.

Handle function calls

The return value of a function should be stored somewhere for cases like -

val = func()

Something in lines of callee/caller saved registers.

parser: test failure when parsing slices

package parser

type Node struct {
	n     int
	child []*Node
}

func main() {
	fmt.Println("Hello, World!")
}

The offending line number is 5.

2018/03/19 11:56:02 Error in S1604: identifier(10,Node), Pos(offset=55, line=5, column=13), expected one of: ( * kwdFunc [ type kwdStruct 

Support for comments in the (handwritten) IR file

What I have in mind is something like this, consider an example (handwritten) IR file -

0, #, This test demonstrates register re-use when a variable is already loaded.
1, label, main
2, =, v1, 1
3, =, v2, 2
3, =, v1, 4, #, should update the register in which v1 is already present instead of re-allocating
4, ret,

The following diff demonstrates the current and the expected behavior for the generated assembly (in term of comments which were introduced) -

diff --git a/current.asm b/expected.asm
index 7967333..85a4f71 100644
--- a/current.asm
+++ b/expected.asm
@@ -1,3 +1,4 @@
+; This test demonstrates register re-use when a variable is already loaded.
        .data
 v1:    .word   0
 v2:    .word   0
@@ -8,7 +9,8 @@ main:
        li, $t2, 1              ; v1 -> {reg: $t2, mem: $t1}
        la $t3, v2
        li, $t4, 2              ; v2 -> {reg: $t4, mem: $t3}
-       li, $t2, 4
+       li, $t2, 4              ; should update the register in which v1 is
+                               ; already present instead of re-allocating.
 
        ; Store variables back into memory
        sw $t2, ($t1)

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.