This is an attempt to add support for the WDC 65816 to LLVM. Don't even try to use it yet.
Go to file
Jeremy Rand 3def47d32f Make a step towards getting memory reads working. 2016-07-17 22:46:47 -04:00
autoconf Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
bindings Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
cmake Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
docs Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
examples Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
include Lots of basic infrastructure. And get it compiling. 2015-07-17 20:05:36 -05:00
lib Make a step towards getting memory reads working. 2016-07-17 22:46:47 -04:00
projects Adding project sources to the repository 2015-07-18 00:13:38 -05:00
test Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
tools Adjust the target and ABI info for WDC65816 in clang. 2015-08-06 23:01:00 -04:00
unittests Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
utils Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
.arcconfig Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
.clang-format Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
.gitignore Do not ignore project code either 2015-07-18 00:13:14 -05:00
CMakeLists.txt Lots of basic infrastructure. And get it compiling. 2015-07-17 20:05:36 -05:00
CODE_OWNERS.TXT Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
CREDITS.TXT Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
LICENSE.TXT Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
LLVMBuild.txt Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
Makefile Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
Makefile.common Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
Makefile.config.in Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
Makefile.rules Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
README.md Get my first test source file compiling into valid ORCA/M assembly source. 2016-05-13 22:56:40 -04:00
README.txt Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00
configure Add a basic configuration for the 65816 target - build fails now… 2014-07-04 23:41:51 -04:00
llvm.spec.in Initial commit with LLVM 3.4.1, cfe 3.4.1 and compiler-rt 3.4 2014-07-04 22:48:00 -04:00

README.md

What is LLVM?

LLVM is an open source suite of compiler tools. LLVM itself takes source code in an intermediate format and turns it into assembly (or object files) for a particular architecture. There are other projects which build on top of that. Clang takes C/C++/Objective C code in and spits out the intermediate format. Put those together and you get a C compiler which can target many architectures.

What is LLVM-65816?

This is my project to add 65816 support in LLVM. If this is successful, it will be able to convert LLVM intermediate representation into 65816 assembly. Ideally, this assembly would be in a format which Merlin 32 could then assemble into object files and ultimately executables. If we have this, we would have a modern C compiler which can be used to build Apple //GS executables.

What is the status?

The LLVM documentation recommends that new targets use the Sparc target as a guide and that is what I have done. Mostly, I have created 65816 versions of each of the files for the Sparc target. I have disabled large blocks of the Sparc code that I copied and marked them up with “WDC_TODO” comments. I have spent a fair bit of time to describe the registers (actually didnt take long to describe the registers because we dont have many) and the instruction set. That is in reasonable shape but there is definitely work there too.

Right now, you can get the code and compile it. You will be left with a clang binary that appears to have 65816 support. The following code will compile successfully:

int answer(void)
{
    return 42; // The answer
}

You can compile it with this commandline:

bin/clang --target=wdc65816 -S -o answer.s answer.c

I have copied that answer.s file to my Apple //GS and can assemble it using ORCA/M and link it into an executable that works. Of course, it compiles two opcodes (LDA and RTL) so not very impressive.

What is next?

My next goal is to get the compiler to produce assembly for this C code:

int myGlobal=42;

int answer2(void)
{
    return myGlobal; // The answer
}

How to build the project?

Here are the steps to checkout the code and build it:

$ cd some/good/place/to/put/this
$ git clone https://github.com/jeremysrand/llvm-65816.git
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE:STRING=Debug -G "Unix Makefiles" ../llvm-65816
$ make

That works for me on my Mac. Note, you probably need to download cmake.

How to help?

There is lots of work to be done here before this becomes a useful tool. But, now that it builds and I have dozens of WDC_TODOs sprinkled around the code, it is maybe a reasonable time to open this up to anyone else who wants to contribute.

Below is the text from the LLVM README:

Low Level Virtual Machine (LLVM)

This directory and its subdirectories contain source code for the Low Level Virtual Machine, a toolkit for the construction of highly optimized compilers, optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further assistance with LLVM, and in particular docs/GettingStarted.rst for getting started with LLVM and docs/README.txt for an overview of LLVM's documentation setup.

If you're writing a package for LLVM, see docs/Packaging.rst for our suggestions.