Giter Club home page Giter Club logo

clownhead's Introduction

clownhead

Only god knows what is inside the clown head

This project demonstrates a process of converting a high-level representation of a program, for ex the Fibonacci sequence calculation, into LLVM Intermediate Representation (IR), then compiling and executing the generated assembly.

This is specially made for Rinha de Compiladores.

Contents

  • main.py: The main driver script that parses an abstract syntax tree (AST) from a JSON file, then converts this AST into a high-level IR and eventually into LLVM IR.
  • my_ast.py: Defines the data structures and classes for the abstract syntax tree representation.
  • codegen.py: Contains the code generation logic that translates our high-level IR to LLVM IR.

Workflow example

  • The main.py script reads the example.json to get a JSON representation of the AST.
  • The script then converts this JSON AST into our high-level IR using the structures defined in my_ast.py.
  • This high-level IR is then converted to LLVM IR using the codegen.py module.
  • External LLVM tools (llvm-as, llc) and the Clang compiler are used to compile the LLVM IR into an executable.
  • Running the fib executable calculates the 10th Fibonacci number, resulting in 55.

How to run?

  1. Build the Docker Image
docker build -t clownhead .
  1. To compile the JSON-based AST and generate an executable, place your input file at /var/rinha/source.rinha.json in your project directory. Then, run the following command:
docker run -v <local_path_to_project_directory>:/app clownhead

Replace <local_path_to_project_directory> with the path to your project directory on your local machine. For example, if your project is located in ~/Proj/clownhead, you would run:

docker run -v ~/Proj/clownhead:/app clownhead
  1. After running the above command, an LLVM-IR file with the .ll extension and an executable will be generated in your project directory.

For the example above, you would get comb.ll and comb (the executable).

  1. To run the generated executable:
./<output_name>

clownhead's People

Contributors

massakera avatar

Stargazers

Diego avatar Paulo B. S. avatar Samuel Haidu 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.