Skip to content
/ succ Public

Compiling a laughably small subset of C to unoptimised assembly since 2019

License

Notifications You must be signed in to change notification settings

jgthomas/succ

Repository files navigation

succ Build Status codecov

Super Useless C Compiler

  • Multi-pass compiler
  • Growing support for C language features
  • Compiles C to x86-64 assembly
  • Robust error handling system, with pretty printed error messages
  • Basic type checking, supports int, int* and int[]

testing

Unit tests are in this repo's test directory

Functional tests are in their own repo

supported language elements

Integer literals

  • Return statements (return 1)

Unary operators

  • Sign (-, +)
  • Logical (!)
  • Bitwise (~)
  • Prefix (++, --)
  • Postfix (++, --)

Binary operators

  • Additive (+, -)
  • Multiplicative (*, /, %)
  • Equality (==, !=)
  • Relational (>, <, >=, <=)
  • Logical (&&, ||)
  • Bitwise (^, <<, >>, &, |)
  • Assignment (=, +=, -=, *=, /=, %=, ^=, |=, &=, <<=, >>=)

Local variables

  • Declaration (int a)
  • Assignment (a = 10)
  • Declaration and assignment (int a = 10)

Conditionals

  • if
  • else
  • conditional expressions (a = 1 ? 2 : 3)

Loops

  • for
  • while
  • do while
  • break
  • continue

Multiple functions

  • Function calls
  • Function declarations
  • Function definitions
  • Passing parameters using x86-64 calling convention

Global variables

  • Declaration
  • Definition
  • Initialized in .data
  • Uninitialized in .bss

Pointers

  • Declared and defined locally or globally
  • Pointing to local or global variables
  • Passing as arguments
  • Pass without assignment using '&'

Rudimentary Type Checking

  • int vs. int*
  • Check sides of assignments match
  • Compare parameters to arguments
  • Check function declaration against return values

acknowledgements

Nora Sandler, who broke down compilers in a practical way.

Bartosz Milewski, who gave me a glimpse into how this might be done in Haskell.

About

Compiling a laughably small subset of C to unoptimised assembly since 2019

Topics

Resources

License

Stars

Watchers

Forks

Languages