Skip to content

A C compiler that targets a VM, written is Rust

Notifications You must be signed in to change notification settings

itamar8910/c_to_vm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c_to_vm

A C compiler that targets a VM, written is Rust

This project has 3 components:

  • Virtual Machine:

    An emulation of a CPU that has 8 regiters, can execute instructions with 17 different opcodes, use memory, and perform IO with memory mapped registers.

  • C compiler:

    A C compiler that targets the VM's instructions set.

    list of compiler features

    • Evaluate expressions
    • Local & global variables
    • Flow control: if/else & loops
    • Scopes
    • Functions
    • Arrays & structs
    • Pointers
    • C strings

    Includes a linker and a basic preprocessor.

    Lexing & Parsing is performed using pycparser.

  • Operating System:

    Can load programs to memory, has an assembler and a assembly-level debugger. Offers a minimal libc with print functions and malloc & free implementation.

Usage:

  • To run the tests: ./run_tests
  • To compile & run a program: cargo run run <main_source_file> <optionally other files to link with>
  • To compile & debug a program: cargo run debug <main_source_file> <optionally other files to link with>

TODO list:

  • Improve preprocessor: Add #define, #ifdef, macros.
  • Add typedef, check type validity at compile time.
  • Ultimately the goal is to compile gnu libc

About

A C compiler that targets a VM, written is Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published