Git Product home page Git Product logo

qcc's Introduction

QCC

  • qcc is a small toy compiler for C language.
  • waiting for pull-req!

FEATURES

  • qcc generates bitcode from C source code with LLVM. so we have to convert bitcode to native.
  • the shell script './qcc.sh' does it. or do yourself such as below:
$ ./qcc c.c -o c.bc # qcc generates c.bc
$ llc-3.8 c.bc # c.bc -> c.s
$ clang c.s # c.s -> a.out

BUILD

  • used tools: clang, llvm-3.8
  • if you are using Ubuntu or Debian, maybe you can see what you have to apt-get install if you look at Dockerfile.
$ make
$ make test
$ ./qcc.sh <SOURCE CODE>

TRY ON DOCKER

  • follow below
docker build -t="qcc" .
docker run -it "qcc" .

qcc's People

Contributors

equal-l2 avatar kariya-mitsuru avatar maekawatoshiki 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

qcc's Issues

SEGV on global string

QCC runs into SEGV if any string literal exists in global scope.

Sample code:

const char *s = "Hello World";

Stack trace from clang address sanitizer:

    #0 0x102e06970 in llvm::IRBuilderBase::CreateGlobalString(llvm::StringRef, llvm::Twine const&, unsigned int) (qcc+0x10016b970)
    #1 0x102cb189f in Codegen::statement(StringAST*) (qcc+0x10001689f)
    #2 0x102ca55d3 in Codegen::statement(AST*) (qcc+0x10000a5d3)
    #3 0x102cad87c in Codegen::statement(VarDeclarationAST*) (qcc+0x10001287c)
    #4 0x102ca55c4 in Codegen::statement(AST*) (qcc+0x10000a5c4)
    #5 0x102ca4ea0 in Codegen::run(std::__1::vector<AST*, std::__1::allocator<AST*> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) (qcc+0x100009ea0)
    #6 0x102d09f70 in QCC::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) (qcc+0x10006ef70)
    #7 0x102d0a68f in QCC::run() (qcc+0x10006f68f)
    #8 0x102cf5ecd in main (qcc+0x10005aecd)
    #9 0x7fffac57d254 in start (libdyld.dylib+0x5254)

Migration to newer LLVM

I heard you were planning to migrate LLVM 3.8 on #8 (comment).

How is it going?

Since homebrew (macOS community-driven package manager) only support LLVM 3.7 and higher now, I cannot try qcc.

More accurate implementation for array subscript operator

According to C standard, this code is well-formed but QCC hasn't support some part yet.

int a[] = {1,2,3,4,5};
a[0]; // of course this has no problem.
0[a]; // this is also good, though QCC hasn't supported yet.
'\0'[a] // even this is well-formed (at least under ASCII), though QCC hasn't supported yet.

According to C89, subscript operator E1[E2] is identical to (*(E1+(E2))).
According to C99 and C11, it is identical to (*((E1)+(E2))).

Replacing array expression might be needed.

Escape sequences aren't handled correctly

Any escape sequences (e.g. \n,\r) are output as typical characters.

Test code:

#include <stdio.h>
int main(){
  printf("hello world\n");
}

Expected output:

hello world

Actual output:

hello world\n

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.