Giter Site home page Giter Site logo

xevor11 / e-graph-optimizer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 33 KB

The project will involve building an optimizer that can analyze the intermediate code generated by the compiler

License: BSD 3-Clause "New" or "Revised" License

Haskell 99.15% Nix 0.85%

e-graph-optimizer's Introduction

Project Description

This is a compiler project built using Haskell and the E-Graph open-source library (Egg) for optimizing code. The compiler takes source code as input, performs lexical analysis, parsing, semantic analysis, code generation and optimization, and generates machine code as output.

  • The project directory structure includes:
  • app/ directory containing the entry point of the application (Main.hs) and the optimizer module (Optimizer.hs).
  • src/ directory containing the compiler modules (Lexer.hs, Parser.hs, SemanticAnalyzer.hs, SymbolTable.hs, CodeGenerator.hs) and a general library module (Lib.hs).
  • test/ directory containing the test modules (Spec.hs and subdirectories LexerSpec.hs, ParserSpec.hs, SemanticAnalyzerSpec.hs, SymbolTableSpec.hs, CodeGeneratorSpec.hs, and OptimizerSpec.hs) using the Hspec library.
  • The E-Graph library is used to represent and manipulate expressions, which is a key part of optimizing code. The Optimizer.hs module uses the egg library to perform various optimizations on the code generated by the compiler.

About the Project

The goal of this project is to demonstrate the use of E-graphs as a powerful tool for optimizing code in compilers. E-graphs are a data structure that can be used to represent and manipulate expressions in a way that is both efficient and flexible.

By using E-graphs in the optimizer, this compiler is able to perform advanced optimizations on the generated code, such as constant folding and common subexpression elimination. This results in code that is faster and more efficient than what would be generated by a traditional compiler.

Overall, this project demonstrates the potential for E-graphs to be used in a variety of applications where efficient expression manipulation is required, including compilers, theorem provers, and program synthesizers.

Directory Structure

.
├── app/
│   ├── Main.hs
│   └── Optimizer.hs
├── src/
│   ├── Compiler/
│   │   ├── Lexer.hs
│   │   ├── Parser.hs
│   │   ├── SemanticAnalyzer.hs
│   │   ├── SymbolTable.hs
│   │   └── CodeGenerator.hs
│   └── Lib.hs
│
├── test/
│    ├── Spec.hs
│    └── TestCompiler/
│        ├── LexerSpec.hs
│        ├── ParserSpec.hs
│        ├── SemanticAnalyzerSpec.hs
│        ├── SymbolTableSpec.hs
│        ├── CodeGeneratorSpec.hs
│        └── OptimizerSpec.hs
├── README.md
├── LICENSE
├── .gitignore
├── stack.yaml
└── project.cabal

Installation Instructions

Prerequisites

To run this project, you need to have the following software installed on your system:

The Haskell programming language (version 8.10 or later) The Rust programming language (version 1.55 or later)

Setup

  1. Clone the repository: git clone https://github.com/Vtewari2311/E-Graph-Optimizer.git
  2. Navigate to the project directory: cd project
  3. Install the required Haskell packages: cabal install --dependencies-only
  4. Build the project: cabal build
  5. Install the egg library: cargo install egg
  6. Start the application: cabal run

Testing

To run the tests, navigate to the project directory and run the following command: cabal test. This will run all the tests in the test/ directory.

Usage Instructions

To use the compiler, create a file containing the source code to compile, and run the following command from the project directory: cabal run your-file-name. This will compile your code and generate machine code as output. If you want to optimize the code, add the -o flag: cabal run -o your-file-name.

Additionally, To use the compiler, navigate to the app directory and run the Main executable. The executable takes a single argument, which is the path to the source code file that you want to compile. For example, to compile a source file named example.src, you would run the following command:

./Main ../example.src The compiled code will be output to a file named out.s in the same directory as the source file.

e-graph-optimizer's People

Contributors

xevor11 avatar

Stargazers

 avatar

Watchers

 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.