/LLVM-Loader-POC

LLVM Loader POC is an accepted Proof of Concept for LLVM Loader for Metacall core.

Primary LanguageC++

LLVM Loader POC

123

What is a loader in Metacall?

Loaders in Metacall are important for loading code from one specific language and converting it into an intermediate representation called Meta Object Protocol. This intermediate representation is then used to extract all the functions, parameters, and logic using self-reflection which is the ability of code to investigate itself. This extracted code can then be used and re-converted back to any other language's specifics so as to generate a similar logic in that language and get the same output. Because of this inter-conversion, polyglot programming is made possible which eases your development life in many ways.

A loader generally has five important methods. They are

  • initialize()
  • load()
  • discover()
  • clear()
  • destroy()

These methods have specific functionalities and they're mapped as follows

Mapping

What is this POC about?

Through this POC, I want to create a simple LLVM loader which would essentially take a C file as input, convert it to LLVM IR (Intermediate Representation) and then write a loader to extract all the important stuff from this LLVM IR file. This extracted stuff would be reflected and converted into Meta Object Protocol for further use. This POC as of now addresses only the initialize(), load(), and discover() methods.

How to run?

Install the required dependencies

  • LLVM v11 (Be sure to install v11 only!)
  • clang

After installing the above dependencies

  • Clone this repository and navigate to the project directory.
  • Build and run the project using make input.ll && make && ./main command.

What happens internally?

The following stuff happens internally and is abstracted from the user.

  • C (.c) file is converted to an LLVM IR (.ll) file.
  • Loader extracts and stores all the functions and parameters.
  • Loader also tries to execute a simple addition method by dynamically passing arguments through C++ to LLVM IR. This is an additional important functionality.

This intermediate representation is converted to Meta Object Protocol and can hence be used to generate similar logic in other programming languages. This enables polyglot programming.

Created by Yash Dekate.