Git Product home page Git Product logo

c-compiler's Introduction

cc

C compiler

The C language grammar (c.y and c.l files) have been taken from:

http://www.quut.com/c/ANSI-C-grammar-y-2011.html

Instructions on how to use this library

  1. Open the terminal and cd into the source code directory
  2. type make to compile all the source code
  3. run the binary cc which has the following usage (<outfile.ll> is optional and if not provided default filename would be a.ll)
     Usage: ./cc <prog.c>  -dumpast
            ./cc <prog.c>  -scopechk
            ./cc <prog.c>  -emit-ir [<outfile.ll>]
  4. NOTE : this program doesn't exhaustively support all C constructs but supports most of them and you'll get appropriate warnings/error for invalid/unsupported programs
  5. some sample programs are also provided (in examples directory) to test the AST implementation
  6. their corresponding sample output is in out/ directory

Example : emit code for hello_world.c program in examples dir into out/ dir

./cc examples/hello_world.c -emit-ir out/a.ll

resulting a.ll can be compiled using llc and run using lli

Supported Types

  • All the integer types (i.e int, long int, short int etc.) are supported, if some combination of type specifiers is not supported you'll get the appropriate error message
  • Floating point types are also supported (i.e float and double)
  • Implicit type conversion among int types, float types and across int and float types are supported (using llvm instructions such as sitofp or fptoui etc.)
  • Storage type specifiers are not supported (they're not part of the language)
  • Type qualifiers are not supported (they're just ignored)

Supported C constructs

  • All the declarations/expressions are supported
  • Among the control-flow statements, except for-loop all the C statements are supported (i.e. if-else, while, do-while, switch statements, case and default statements, labeled statements and gotos, break, continue, return etc.)
  • old C style for loop is supported for scope checking
  • Gracefull exiting of invalid C program is supported (i.e. proper error mentioning during codegen/scope checking)
  • Any construct that is not supported you'll get an appropriate error message for it

Supported Optimization

  • Some basic local optimizations like local-constant-folding, local-deadcode removal are supported
  • local-constant folding is supported for logical and/or operations only
  • dead-code removal is supported for if-else, while statements (removal of statement code that is unreachable)
  • REMARK on deadcode removal :
    • for example : if condition of if stmt is true but else block has a label inside it then both then as well as else statement codes are generated, this is because there can be a goto in the program that branches to those labels, similarly for while statements

c-compiler's People

Contributors

bsorav avatar harsh-apcr 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.