Skip to content

dejlek/SDC

 
 

Repository files navigation

SDC - The Stupid D Compiler

This is the home of a D compiler. SDC is at the moment, particularly stupid; it is a work in progress. Feel free to poke around, but don't expect it to compile your code. I don't know what I'm doing in terms of compiler writing. If you find some horrible design decision, that's most likely why.

The code is released under the GPL (see the LICENCE file for more details). Contact me at b.helyer@gmail.com

Features

What follows is a very high level overview of what's done, and what's still to do. This list is incomplete. SDC is in a state of flux, and this is likely to be out of date.

Lexer

  • Scan and handle multiple encoding formats. [yes.] -- in so far all code is treated as UTF-8 and its BOM is eaten; other BOMs are rejected. ]
  • Handle leading script lines. [yes.]
  • Split source into tokens. [yes.]
  • Replace special tokens. [yes.]
  • Process special token sequences. [no.]

Parser

  • Parse module declarations. [yes.]
  • Parse attribute declarations. [yes.]
  • Parse import declarations. [yes.]
  • Parse enum declarations. [yes.]
  • Parse class declarations. [partially.]
  • Parse interface declarations. [no.]
  • Parse aggregate declarations. [partially.]
  • Parse declarations. [partially.]
  • Parse constructors. [yes.]
  • Parse destructors. [yes.]
  • Parse invariants. [no.]
  • Parse unittests. [yes.]
  • Parse static constructors. [yes.]
  • Parse static destructors. [yes.]
  • Parse shared static constructors. [yes.]
  • Parse shared static destructors. [yes.]
  • Parse conditional declarations. [yes.]
  • Parse static asserts. [yes.]
  • Parse template declarations. [partially.]
  • Parse template mixins. [no.]
  • Parse mixin declarations. [partially.]
  • Parse statements. [partially.]

Codegen

  • Import symbols from other modules. [yes.]
  • Apply attributes. [partially.]
  • Enums. [yes.]
  • Structs. [partially.]
  • Classes. [partially.]
  • Functions. [partially.]
  • Overloaded functions. [yes.]
  • Function pointers. [yes.]
  • Local variables. [yes.]
  • Global variables. [yes.]
  • Alias declarations. [partially.]
  • Expressions. [partially.]
  • Label statement. [yes.]
  • If statement. [yes.]
  • While statement. [yes.]
  • Do statement. [yes.]
  • For statement. [yes.]
  • Switch statement. [no.]
  • Final switch statement. [no.]
  • Case statement. [no.]
  • Case range statement. [no.]
  • Default statement. [no.]
  • Continue statement. [no.]
  • Break statement. [no.]
  • Return statement. [yes.]
  • Goto statement. [partially.]
  • With statement. [no.]
  • Synchronized statement. [no.]
  • Try statement. [no.]
  • Scope guard statement. [no.]
  • Throw statement. [no.]
  • Asm statement. [no.]
  • Pragma statement. [no.]
  • Mixin statement. [yes.]
  • Foreach range statement. [yes.]
  • Conditional statement. [yes.]
  • Static assert. [yes.]
  • Template mixin. [no.]
  • Templated scope. [partially.]

What Can It Compile?

See the compiler_tests directory for a sample of what is/should-be working. libs/object.d contains the current (temporary) object.d file for SDC.

Roadmap

This just me thinking outloud about what features I want, when.

0.1

  • druntime compiles
  • phobos compiles

0.2

  • inline assembler

0.3

  • CTFE (this may be required in 0.1, not sure)

1.0

  • dmd calling convention compatibility
  • self hosting

2.0

  • extern (C++)

Compiling SDC on Linux

You'll need make and the latest DMD installed. Download the Clang Binaries for Linux/x86 copy every libLLVM*.a into a directory 'llvm' at the source directory's root. Make a directory named 'bin'. Run make. Copy bin/sdc into the root. Compile the runner using dmd, and run it to run the tests using SDC. You'll need LLVM's llc in your $PATH, and opt if you want to use --optimise. If you build a 64 bit SDC, be aware that DMD has some bugs that make it crash and kill your parents, particularly on errors and warnings.

SDC with DMD/Windows

(These instructions are from Jakob, so please don't contact me regarding them.)

The following are required for LLVM to function on Windows:

  • LLVM >= 2.9
    • SDC requires the core libraries as a DLL, and the llc and opt tools
  • MinGW
    • SDC requires gcc, as well as GNU make for the makefile

A copy of llvm-2.9.dll and llvm-2.9.lib in DMD-compatible OMF format can be downloaded from here for convenience. For the LLVM tools, grab "LLVM Binaries for Mingw32/x86" on the LLVM download page.

Setup

Extract the LLVM DLL binary archive to the SDC repository, then build with make -f Makefile.windows. When running SDC, make sure gcc, llc and opt are available in your PATH.

To run the tests, execute dmd runner.d to build the test-runner application found in compiler_tests/, then run it with runner.

About

The Stupid D Compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • D 99.0%
  • C++ 1.0%