llvm-6502/tools/llvmc/examples/mcc16
Oscar Fuentes 5fe5203c23 Builds llvmc and its examples with CMake.
Patch by arrowdodger!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135919 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-25 17:25:10 +00:00
..
CMakeLists.txt Builds llvmc and its examples with CMake. 2011-07-25 17:25:10 +00:00
Hooks.cpp Fixes VS support for llvmc mcc16 llvmc example. 2011-07-25 17:24:54 +00:00
Main.cpp I swear I did a make clean and make before committing all this... 2010-11-29 18:47:54 +00:00
Makefile Resurrect mcc16, it is useful as an example. 2010-10-23 07:33:02 +00:00
PIC16.td Resurrect mcc16, it is useful as an example. 2010-10-23 07:33:02 +00:00
README Resurrect mcc16, it is useful as an example. 2010-10-23 07:33:02 +00:00

This is a basic compiler driver for the PIC16 toolchain that shows how to create
your own llvmc-based drivers. It is based on the examples/Skeleton template.

The PIC16 toolchain looks like this:

clang-cc (FE) -> llvm-ld (optimizer) -> llc (codegen) -> native-as -> native-ld

Following features were requested by Sanjiv:

From: Sanjiv Gupta <sanjiv.gupta <at> microchip.com>
Subject: Re: llvmc for PIC16
Newsgroups: gmane.comp.compilers.llvm.devel
Date: 2009-06-05 06:51:14 GMT

The salient features that we want to have in the driver are:
1. llvm-ld will be used as "The Optimizer".
2. If the user has specified to generate the final executable, then
llvm-ld should run on all the .bc files generated by clang and create a
single optimized .bc file for further tools.
3. -Wo <options> - pass optimizations to the llvm-ld
4. mcc16 -Wl <options> - pass options to native linker.
5. mcc16 -Wa <options> - pass options to native assembler.

Here are some example command lines and sample command invocations as to
what should be done.

$ mcc16 -S foo.c
// [clang-cc foo.c] -> foo.bc
// [llvm-ld foo.bc] -> foo.opt.bc
// [llc foo.opt.bc] -> foo.s

$ mcc16 -S foo.c bar.c
// [clang-cc foo.c] -> foo.bc
// [llvm-ld foo.bc] -> foo.opt.bc
// [llc foo.opt.bc] -> foo.s
// [clang-cc bar.c] -> bar.bc
// [llvm-ld bar.bc] -> bar.opt.bc
// [llc bar.opt.bc] -> bar.s

** Use of -g causes llvm-ld to run with -disable-opt
$ mcc16 -S -g foo.c
// [clang-cc foo.c] -> foo.bc
// [llvm-ld -disable-opt foo.bc] -> foo.opt.bc
// [llc foo.opt.bc] -> foo.s

** -I is passed to clang-cc, -pre-RA-sched=list-burr to llc.
$ mcc16 -S -g -I ../include -pre-RA-sched=list-burr foo.c
// [clang-cc -I ../include foo.c] -> foo.bc
// [llvm-ld -disable-opt foo.bc] -> foo.opt.bc
// [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s

** -Wo passes options to llvm-ld
$ mcc16 -Wo=opt1,opt2 -S -I ../include -pre-RA-sched=list-burr foo.c
// [clang-cc -I ../include foo.c] -> foo.bc
// [llvm-ld -opt1 -opt2 foo.bc] -> foo.opt.bc
// [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s

** -Wa passes options to native as.
$ mcc16 -c foo.c -Wa=opt1
// [clang-cc foo.c] -> foo.bc
// [llvm-ld foo.bc] -> foo.opt.bc
// [llc foo.opt.bc] -> foo.s
// [native-as -opt1 foo.s] -> foo.o

$ mcc16 -Wo=opt1 -Wl=opt2 -Wa=opt3 foo.c bar.c
// [clang-cc foo.c] -> foo.bc
// [clang-cc bar.c] -> bar.bc
// [llvm-ld -opt1 foo.bc bar.bc] -> a.out.bc
// [llc a.out.bc] -> a.out.s
// [native-as -opt3 a.out.s] -> a.out.o
// [native-ld -opt2 a.out.o] -> a.out

Is this achievable by a tablegen based driver ?

- Sanjiv