Git Product home page Git Product logo

cplus's Introduction

made-with-C++ GitHub issues GitHub pull-requests License

Сplus

Compiler for C+ toy imperative language, based on LLVM.

Getting started

  • Code sample.cp

    routine main() is
        println "Hello C+";
        return;
    end
  • Compile

    $ ./cplus sample.cp
    
    Compilation successful. Run ./a.out to execute
  • Run

    $ ./a.out
    Hello C+
  • Generated ir.ll

    ; ModuleID = 'ir.ll'
    source_filename = "ir.ll"
    target triple = "x86_64-pc-linux-gnu"
    
    @fmt_s_ln = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
    @str = private unnamed_addr constant [9 x i8] c"Hello C+\00", align 1
    
    define i64 @main() {
    entry:
      %printfCall = call i64 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @fmt_s_ln, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str, i32 0, i32 0))
      ret i64 0
    }
    
    declare i64 @printf(i8*, ...)
  • Debug output from cplus -d sample.cp

    debug

Compilation from source (Linux)

  1. Install prerequisites: cmake flex bison clang llvm-10 using the package manager for your distro.

    • Example (Ubuntu 20.04 LTS): sudo apt install cmake flex bison clang llvm
  2. Clone repo

    git clone https://github.com/Sh3B0/cplus/
    cd cplus
  3. Build cplus binary using CMake

    mkdir build
    cmake -S . -B build
    cmake --build build
  4. Compile a source file *.cp (check tests)

    cd build
    ./cplus -d ../tests/1.cp
  5. Help

    $ ./cplus --help
    usage: cplus [options] infile
    	infile                 path to the source code file (*.cp) to compile.
    
    options:
    	-h, --help             show this help message and exit.
    	-d, --debug            show debug messages.
    	-o, --outfile outfile  specify executable file name.

Contribution

Feel free to report a bug or suggest a feature by creating an issue.

License

The source code is licensed under the MIT license, which you can find in the LICENSE file.

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.