llvmc: Update examples.
authorMikhail Glushenkov <foldr@codedgers.com>
Thu, 19 Aug 2010 20:04:19 +0000 (20:04 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Thu, 19 Aug 2010 20:04:19 +0000 (20:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111553 91177308-0d34-0410-b5e6-96231b3b80d8

39 files changed:
tools/llvmc/Makefile
tools/llvmc/example/Hello/Hello.cpp [deleted file]
tools/llvmc/example/Hello/Makefile [deleted file]
tools/llvmc/example/Simple/Makefile [deleted file]
tools/llvmc/example/Simple/PluginMain.cpp [deleted file]
tools/llvmc/example/Simple/Simple.td [deleted file]
tools/llvmc/example/Skeleton/Makefile [deleted file]
tools/llvmc/example/Skeleton/README [deleted file]
tools/llvmc/example/Skeleton/driver/Main.cpp [deleted file]
tools/llvmc/example/Skeleton/driver/Makefile [deleted file]
tools/llvmc/example/Skeleton/plugins/Makefile [deleted file]
tools/llvmc/example/Skeleton/plugins/Plugin/Makefile [deleted file]
tools/llvmc/example/Skeleton/plugins/Plugin/Plugin.td [deleted file]
tools/llvmc/example/Skeleton/plugins/Plugin/PluginMain.cpp [deleted file]
tools/llvmc/example/mcc16/Makefile [deleted file]
tools/llvmc/example/mcc16/README [deleted file]
tools/llvmc/example/mcc16/driver/Main.cpp [deleted file]
tools/llvmc/example/mcc16/driver/Makefile [deleted file]
tools/llvmc/example/mcc16/plugins/Makefile [deleted file]
tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile [deleted file]
tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td [deleted file]
tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp [deleted file]
tools/llvmc/examples/Hello/Hello.cpp [new file with mode: 0644]
tools/llvmc/examples/Hello/Makefile [new file with mode: 0644]
tools/llvmc/examples/Makefile [new file with mode: 0644]
tools/llvmc/examples/Simple/Makefile [new file with mode: 0644]
tools/llvmc/examples/Simple/Simple.cpp [new file with mode: 0644]
tools/llvmc/examples/Simple/Simple.td [new file with mode: 0644]
tools/llvmc/examples/Skeleton/AutoGenerated.td [new file with mode: 0644]
tools/llvmc/examples/Skeleton/Hooks.cpp [new file with mode: 0644]
tools/llvmc/examples/Skeleton/Main.cpp [new file with mode: 0644]
tools/llvmc/examples/Skeleton/Makefile [new file with mode: 0644]
tools/llvmc/examples/Skeleton/README [new file with mode: 0644]
tools/llvmc/examples/mcc16/Hooks.cpp [new file with mode: 0644]
tools/llvmc/examples/mcc16/Main.cpp [new file with mode: 0644]
tools/llvmc/examples/mcc16/Makefile [new file with mode: 0644]
tools/llvmc/examples/mcc16/PIC16.td [new file with mode: 0644]
tools/llvmc/examples/mcc16/README [new file with mode: 0644]
utils/TableGen/LLVMCConfigurationEmitter.cpp

index 9bcb96c954e1a46faffb2b3425d720f7df2272fa..7c03e2a74f7c6b2f97161a0cf1e1103c5ac79899 100644 (file)
@@ -11,4 +11,8 @@ LEVEL = ../..
 
 DIRS = src
 
+ifeq ($(BUILD_EXAMPLES),1)
+  OPTIONAL_DIRS += examples
+endif
+
 include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Hello/Hello.cpp b/tools/llvmc/example/Hello/Hello.cpp
deleted file mode 100644 (file)
index a7179ea..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-//===- Hello.cpp - Example code from "Writing an LLVMC Plugin" ------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Test plugin for LLVMC. Shows how to write plugins without using TableGen.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CompilerDriver/CompilationGraph.h"
-#include "llvm/CompilerDriver/Plugin.h"
-#include "llvm/Support/raw_ostream.h"
-
-namespace {
-struct MyPlugin : public llvmc::BasePlugin {
-
-  void PreprocessOptions() const
-  {}
-
-  void PopulateLanguageMap(llvmc::LanguageMap&) const
-  { outs() << "Hello!\n"; }
-
-  void PopulateCompilationGraph(llvmc::CompilationGraph&) const
-  {}
-};
-
-static llvmc::RegisterPlugin<MyPlugin> RP("Hello", "Hello World plugin");
-
-}
diff --git a/tools/llvmc/example/Hello/Makefile b/tools/llvmc/example/Hello/Makefile
deleted file mode 100644 (file)
index 10325e6..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-##===- tools/llvmc/plugins/Hello/Makefile ------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../../..
-
-LLVMC_PLUGIN = Hello
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Simple/Makefile b/tools/llvmc/example/Simple/Makefile
deleted file mode 100644 (file)
index d7adb5d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-##===- tools/llvmc/plugins/Simple/Makefile -----------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = ../../../..
-
-LLVMC_PLUGIN = Simple
-BUILT_SOURCES = AutoGenerated.inc
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Simple/PluginMain.cpp b/tools/llvmc/example/Simple/PluginMain.cpp
deleted file mode 100644 (file)
index add8acb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "AutoGenerated.inc"
diff --git a/tools/llvmc/example/Simple/Simple.td b/tools/llvmc/example/Simple/Simple.td
deleted file mode 100644 (file)
index 87bc385..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-//===- Simple.td - A simple plugin for LLVMC ------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// A simple LLVMC-based gcc wrapper that shows how to write LLVMC plugins.
-//
-// To compile, use this command:
-//
-//      $ cd $LLVMC_DIR/example/Simple
-//      $ make
-//
-// Run as:
-//
-//      $ llvmc -load $LLVM_DIR/Release/lib/plugin_llvmc_Simple.so
-//
-// For instructions on how to build your own LLVMC-based driver, see
-// the 'example/Skeleton' directory.
-//===----------------------------------------------------------------------===//
-
-include "llvm/CompilerDriver/Common.td"
-
-def gcc : Tool<
-[(in_language "c"),
- (out_language "executable"),
- (output_suffix "out"),
- (cmd_line "gcc $INFILE -o $OUTFILE"),
- (sink)
-]>;
-
-def LanguageMap : LanguageMap<[LangToSuffixes<"c", ["c"]>]>;
-
-def CompilationGraph : CompilationGraph<[Edge<"root", "gcc">]>;
diff --git a/tools/llvmc/example/Skeleton/Makefile b/tools/llvmc/example/Skeleton/Makefile
deleted file mode 100644 (file)
index f489abf..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-##===- llvmc/example/Skeleton/Makefile ---------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-# Change this so that $(BASE_LEVEL)/Makefile.common refers to
-# $LLVM_DIR/Makefile.common or $YOUR_LLVM_BASED_PROJECT/Makefile.common.
-export LLVMC_BASE_LEVEL = ../../../..
-
-# Change this to the name of your LLVMC-based driver.
-export LLVMC_BASED_DRIVER_NAME = llvmc-skeleton
-
-# List your plugin names here
-export LLVMC_BUILTIN_PLUGINS = # Plugin
-
-LEVEL = $(LLVMC_BASE_LEVEL)
-
-DIRS = plugins driver
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Skeleton/README b/tools/llvmc/example/Skeleton/README
deleted file mode 100644 (file)
index 92216ae..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-This is a template that can be used to create your own LLVMC-based drivers. Just
-copy the `Skeleton` directory to the location of your preference and edit
-`Skeleton/Makefile` and `Skeleton/plugins/Plugin`.
-
-The build system assumes that your project is based on LLVM.
diff --git a/tools/llvmc/example/Skeleton/driver/Main.cpp b/tools/llvmc/example/Skeleton/driver/Main.cpp
deleted file mode 100644 (file)
index b1f5b67..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Just include CompilerDriver/Main.inc.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CompilerDriver/Main.inc"
diff --git a/tools/llvmc/example/Skeleton/driver/Makefile b/tools/llvmc/example/Skeleton/driver/Makefile
deleted file mode 100644 (file)
index 93e795b..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-##===- llvmc/example/Skeleton/driver/Makefile --------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/..
-LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME)
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Skeleton/plugins/Makefile b/tools/llvmc/example/Skeleton/plugins/Makefile
deleted file mode 100644 (file)
index fb07f23..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-##===- llvmc/example/Skeleton/plugins/Makefile -------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/..
-
-ifneq ($(LLVMC_BUILTIN_PLUGINS),)
-DIRS = $(LLVMC_BUILTIN_PLUGINS)
-endif
-
-export LLVMC_BUILTIN_PLUGIN=1
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Skeleton/plugins/Plugin/Makefile b/tools/llvmc/example/Skeleton/plugins/Plugin/Makefile
deleted file mode 100644 (file)
index 54f7221..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-##===- llvmc/example/Skeleton/plugins/Plugin/Makefile ------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/../..
-
-# Change this to the name of your plugin.
-LLVMC_PLUGIN = Plugin
-
-BUILT_SOURCES = AutoGenerated.inc
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/Skeleton/plugins/Plugin/Plugin.td b/tools/llvmc/example/Skeleton/plugins/Plugin/Plugin.td
deleted file mode 100644 (file)
index febb9ad..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-//===- Plugin.td - A skeleton plugin for LLVMC -------------*- tablegen -*-===//
-//
-// Write the code for your plugin here.
-//
-//===----------------------------------------------------------------------===//
-
-include "llvm/CompilerDriver/Common.td"
diff --git a/tools/llvmc/example/Skeleton/plugins/Plugin/PluginMain.cpp b/tools/llvmc/example/Skeleton/plugins/Plugin/PluginMain.cpp
deleted file mode 100644 (file)
index add8acb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "AutoGenerated.inc"
diff --git a/tools/llvmc/example/mcc16/Makefile b/tools/llvmc/example/mcc16/Makefile
deleted file mode 100644 (file)
index e94bca2..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-##===- llvmc/example/mcc16/Makefile ------------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-export LLVMC_BASE_LEVEL = ../../../..
-export LLVMC_BASED_DRIVER_NAME = mcc16
-export LLVMC_BUILTIN_PLUGINS = PIC16Base
-
-LEVEL = $(LLVMC_BASE_LEVEL)
-
-DIRS = plugins driver
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/mcc16/README b/tools/llvmc/example/mcc16/README
deleted file mode 100644 (file)
index eeef6a4..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-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 example/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
diff --git a/tools/llvmc/example/mcc16/driver/Main.cpp b/tools/llvmc/example/mcc16/driver/Main.cpp
deleted file mode 100644 (file)
index e66e2f9..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open
-// Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Usually this file just includes CompilerDriver/Main.inc, but here we apply
-//  some trickery to make the built-in '-save-temps' option hidden and enable
-//  '--temp-dir' by default.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Config/config.h"
-#include "llvm/CompilerDriver/BuiltinOptions.h"
-#include "llvm/CompilerDriver/ForceLinkage.h"
-#include "llvm/System/Path.h"
-#include <iostream>
-
-namespace llvmc {
-  int Main(int argc, char** argv);
-}
-
-// Modify the PACKAGE_VERSION to use build number in top level configure file.
-void PIC16VersionPrinter(void) {
-  std::cout << "MPLAB C16 1.0 " << PACKAGE_VERSION << "\n";
-}
-
-int main(int argc, char** argv) {
-
-  // HACK
-  SaveTemps.setHiddenFlag(llvm::cl::Hidden);
-  TempDirname.setHiddenFlag(llvm::cl::Hidden);
-  Languages.setHiddenFlag(llvm::cl::Hidden);
-  DryRun.setHiddenFlag(llvm::cl::Hidden);
-
-  llvm::cl::SetVersionPrinter(PIC16VersionPrinter); 
-
-  // Ask for a standard temp dir, but just cache its basename., and delete it.
-  llvm::sys::Path tempDir;
-  tempDir = llvm::sys::Path::GetTemporaryDirectory();
-  TempDirname = tempDir.getBasename();
-  tempDir.eraseFromDisk(true);
-
-  // We are creating a temp dir in current dir, with the cached name.
-  //  But before that remove if one already exists with that name..
-  tempDir = TempDirname;
-  tempDir.eraseFromDisk(true);
-
-  llvmc::ForceLinkage();
-  return llvmc::Main(argc, argv);
-}
diff --git a/tools/llvmc/example/mcc16/driver/Makefile b/tools/llvmc/example/mcc16/driver/Makefile
deleted file mode 100644 (file)
index 670d8bd..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-##===- llvmc/example/mcc16/driver/Makefile -----------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/..
-LLVMC_BASED_DRIVER = $(LLVMC_BASED_DRIVER_NAME)
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/mcc16/plugins/Makefile b/tools/llvmc/example/mcc16/plugins/Makefile
deleted file mode 100644 (file)
index fb07f23..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-##===- llvmc/example/Skeleton/plugins/Makefile -------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open
-# Source License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/..
-
-ifneq ($(LLVMC_BUILTIN_PLUGINS),)
-DIRS = $(LLVMC_BUILTIN_PLUGINS)
-endif
-
-export LLVMC_BUILTIN_PLUGIN=1
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile b/tools/llvmc/example/mcc16/plugins/PIC16Base/Makefile
deleted file mode 100644 (file)
index 5d785fd..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-##===- llvmc/example/Skeleton/plugins/Plugin/Makefile ------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL = $(LLVMC_BASE_LEVEL)/../..
-
-# Change this to the name of your plugin.
-LLVMC_PLUGIN = PIC16Base
-
-BUILT_SOURCES = AutoGenerated.inc
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td
deleted file mode 100644 (file)
index 25149ad..0000000
+++ /dev/null
@@ -1,234 +0,0 @@
-//===- PIC16Base.td - PIC16 toolchain driver ---------------*- tablegen -*-===//
-//
-// A basic driver for the PIC16 toolchain.
-//
-//===----------------------------------------------------------------------===//
-
-include "llvm/CompilerDriver/Common.td"
-
-// Options
-
-def OptionList : OptionList<[
- (switch_option "g",
-    (help "Enable Debugging")),
- (switch_option "E",
-    (help "Stop after preprocessing, do not compile")),
- (switch_option "S",
-    (help "Stop after compilation, do not assemble")),
- (switch_option "bc",
-    (help "Stop after b-code generation, do not compile")),
- (switch_option "c",
-    (help "Stop after assemble, do not link")),
- (prefix_option "p",
-    (help "Specify part name")),
- (prefix_list_option "I",
-    (help "Add a directory to include path")),
- (prefix_list_option "L",
-    (help "Add a directory to library path")),
- (prefix_list_option "K",
-    (help "Add a directory to linker script search path")),
- (parameter_option "l",
-    (help "Specify a library to link")),
- (parameter_option "k",
-    (help "Specify a linker script")),
- (parameter_option "m",
-    (help "Generate linker map file with the given name")),
- (prefix_list_option "D",
-    (help "Define a macro")),
- (switch_option "X",
-    (help "Do not invoke mp2hex to create an output hex file.")),
- (switch_option "O0",
-    (help "Do not optimize")),
- (switch_option "O1",
-    (help "Optimization Level 1.")),
- (switch_option "O2",
-    (help "Optimization Level 2.")),
- (switch_option "O3",
-    (help "Optimization Level 3.")),
- (switch_option "Od",
-    (help "Perform Debug-safe Optimizations only.")),
- (switch_option "w",
-    (help "Disable all warnings.")),
-// (switch_option "O1",
-//    (help "Optimization level 1")),
-// (switch_option "O2",
-//    (help "Optimization level 2. (Default)")),
-// (parameter_option "pre-RA-sched",
-//    (help "Example of an option that is passed to llc")),
- (parameter_option "regalloc",
-    (help "Register allocator to use (possible values: simple, linearscan, pbqp, local; default=linearscan)")),
- (prefix_list_option "Wa,", (comma_separated),
-    (help "Pass options to assembler (Run 'gpasm -help' for assembler options)")),
- (prefix_list_option "Wl,", (comma_separated),
-    (help "Pass options to linker (Run 'mplink -help' for linker options)"))
-// (prefix_list_option "Wllc,",
-//    (help "Pass options to llc")),
-// (prefix_list_option "Wo,",
-//    (help "Pass options to llvm-ld"))
-]>;
-
-// Tools
-class clang_based<string language, string cmd, string ext_E> : Tool<
-[(in_language language),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (command cmd),
- (actions (case
-                (and (multiple_input_files),
-                     (or (switch_on "S"), (switch_on "c"))),
-                  (error "cannot specify -o with -c or -S with multiple files"),
-                (switch_on "E"), [(forward "E"),
-                                  (stop_compilation), (output_suffix ext_E)],
-                (and (switch_on "E"), (empty "o")), (no_out_file),
-                (switch_on "bc"),[(stop_compilation), (output_suffix "bc")],
-                (switch_on "g"), (append_cmd "-g"),
-                (switch_on "w"), (append_cmd "-w"),
-                (switch_on "O1"), (append_cmd ""),
-                (switch_on "O2"), (append_cmd ""),
-                (switch_on "O3"), (append_cmd ""),
-                (switch_on "Od"), (append_cmd ""),
-                (not_empty "D"), (forward "D"),
-                (not_empty "I"), (forward "I"),
-                (switch_on "O0"), (append_cmd "-O0"),
-                (default), (append_cmd "-O1")))
-// (sink)
-]>;
-
-def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang -cc1                                                        -I $CALL(GetStdHeadersDir)                                                      -D $CALL(GetLowerCasePartDefine)                                                -D $CALL(GetUpperCasePartDefine) -triple=pic16-                                 -emit-llvm-bc ", "i">;
-
-//def clang_cc : Tool<[
-// (in_language "c"),
-// (out_language "llvm-bitcode"),
-// (output_suffix "bc"),
-// (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc "),
-// (cmd_line kkkkk
-// (actions (case
-//          (switch_on "g"), (append_cmd "g"),
-//          (not_empty "I"), (forward "I"))),
-// (sink)
-//]>;
-
-
-// pre-link-and-lto step.
-def llvm_ld : Tool<[
- (in_language "llvm-bitcode"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
- (command "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -disable-licm-promotion -l std"),
- (out_file_option "-b"),
- (actions (case
-          (switch_on "O0"), (append_cmd "-disable-opt"),
-          (switch_on "O1"), (append_cmd "-disable-opt"),
-// Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
-          (switch_on "O2"), (append_cmd ""),
-          (switch_on "O3"), (append_cmd ""),
-          (default), (append_cmd "-disable-inlining"))),
- (join)
-]>;
-
-// optimize single file
-def llvm_ld_optimizer : Tool<[
- (in_language "llvm-bitcode"),
- (out_language "llvm-bitcode"),
- (output_suffix "bc"),
-// FIXME: we are still not disabling licm-promotion.
-// -disable-licm-promotion and building stdn library causes c16-71 to fail.
- (command "$CALL(GetBinDir)llvm-ld "),
- (out_file_option "-b"),
- (actions (case
-          (switch_on "O0"), (append_cmd "-disable-opt"),
-          (switch_on "O1"), (append_cmd "-disable-opt"),
-// Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
-          (switch_on "O2"), (append_cmd ""),
-          (switch_on "O3"), (append_cmd ""),
-          (default), (append_cmd "-disable-inlining")))
-]>;
-
-// optimizer step.
-def pic16passes : Tool<[
- (in_language "llvm-bitcode"),
- (out_language "llvm-bitcode"),
- (output_suffix "obc"),
- (command "$CALL(GetBinDir)opt -pic16cloner -pic16overlay -f"),
- (actions (case
-          (switch_on "O0"), (append_cmd "-disable-opt")))
-]>;
-
-def llc : Tool<[
- (in_language "llvm-bitcode"),
- (out_language "assembler"),
- (output_suffix "s"),
- (command "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -f"),
- (actions (case
-          (switch_on "S"), (stop_compilation),
-//          (not_empty "Wllc,"), (unpack_values "Wllc,"),
-//         (not_empty "pre-RA-sched"), (forward "pre-RA-sched")))
-         (not_empty "regalloc"), (forward "regalloc"),
-         (empty "regalloc"), (append_cmd "-regalloc=linearscan")))
-]>;
-
-def gpasm : Tool<[
- (in_language "assembler"),
- (out_language "object-code"),
- (output_suffix "o"),
- (command "$CALL(GetBinDir)gpasm -z -r decimal -I $CALL(GetStdAsmHeadersDir) -C -c -w 2"),
- (actions (case
-          (switch_on "c"), (stop_compilation),
-          (switch_on "g"), (append_cmd "-g"),
-          (not_empty "p"), (forward "p"),
-          (empty "p"), (append_cmd "-p 16f1xxx"),
-          (not_empty "Wa,"), (forward_value "Wa,")))
-]>;
-
-def mplink : Tool<[
- (in_language "object-code"),
- (out_language "executable"),
- (output_suffix "cof"),
- (command "$CALL(GetBinDir)mplink -e -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) intrinsics.lib stdn.lib"),
- (actions (case
-          (not_empty "Wl,"), (forward_value "Wl,"),
-          (switch_on "X"), (append_cmd "-x"),
-          (not_empty "L"), (forward_as "L", "-l"),
-          (not_empty "K"), (forward_as "K", "-k"),
-          (not_empty "m"), (forward "m"),
-          (not_empty "p"), [(forward "p"), (append_cmd "-c")],
-          (empty "p"), (append_cmd "-p 16f1xxx -c"),
-//          (not_empty "l"), [(unpack_values "l"),(append_cmd ".lib")])),
-          (not_empty "k"), (forward "k"),
-          (not_empty "l"), (forward "l"))),
- (join)
-]>;
-
-// Language map
-
-def LanguageMap : LanguageMap<[
-    LangToSuffixes<"c", ["c"]>,
-    LangToSuffixes<"c-cpp-output", ["i"]>,
-    LangToSuffixes<"assembler", ["s"]>,
-    LangToSuffixes<"assembler-with-cpp", ["S"]>,
-    LangToSuffixes<"llvm-assembler", ["ll"]>,
-    LangToSuffixes<"llvm-bitcode", ["bc"]>,
-    LangToSuffixes<"object-code", ["o"]>,
-    LangToSuffixes<"executable", ["cof"]>
-]>;
-
-// Compilation graph
-
-def CompilationGraph : CompilationGraph<[
-    Edge<"root", "clang_cc">,
-    Edge<"root", "llvm_ld">,
-    OptionalEdge<"root", "llvm_ld_optimizer", (case
-                                         (switch_on "S"), (inc_weight),
-                                         (switch_on "c"), (inc_weight))>,
-    Edge<"root", "gpasm">,
-    Edge<"root", "mplink">,
-    Edge<"clang_cc", "llvm_ld">,
-    OptionalEdge<"clang_cc", "llvm_ld_optimizer", (case
-                                         (switch_on "S"), (inc_weight),
-                                         (switch_on "c"), (inc_weight))>,
-    Edge<"llvm_ld", "pic16passes">,
-    Edge<"llvm_ld_optimizer", "pic16passes">,
-    Edge<"pic16passes", "llc">,
-    Edge<"llc", "gpasm">,
-    Edge<"gpasm", "mplink">
-]>;
diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp
deleted file mode 100644 (file)
index e7db750..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-#include "AutoGenerated.inc"
-
-#include "llvm/System/Path.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-
-namespace llvmc {
-  extern char *ProgramName;
-}
-
-  
-
-// Returns the platform specific directory separator via #ifdefs.
-// FIXME: This currently work on linux and windows only. It does not 
-// work on other unices. 
-static std::string GetDirSeparator() {
-#if __linux__ || __APPLE__
-  return "/";
-#else
-  return "\\";
-#endif
-}
-
-namespace hooks {
-// Get preprocessor define for the part.
-// It is __partname format in lower case.
-std::string
-GetLowerCasePartDefine(void) {
-  std::string Partname;
-  if (AutoGeneratedParameter_p.empty()) {
-    Partname = "16f1xxx";
-  } else {
-    Partname = AutoGeneratedParameter_p;
-  }
-
-  std::string LowerCase;
-  for (unsigned i = 0; i < Partname.size(); i++) {
-    LowerCase.push_back(std::tolower(Partname[i]));
-  }
-
-  return "__" + LowerCase;
-}
-
-std::string
-GetUpperCasePartDefine(void) {
-  std::string Partname;
-  if (AutoGeneratedParameter_p.empty()) {
-    Partname = "16f1xxx";
-  } else {
-    Partname = AutoGeneratedParameter_p;
-  }
-
-  std::string UpperCase;
-  for (unsigned i = 0; i < Partname.size(); i++) {
-    UpperCase.push_back(std::toupper(Partname[i]));
-  }
-
-  return "__" +  UpperCase;
-}
-
-
-// Get the dir where c16 executables reside.
-std::string GetBinDir() {
-  // Construct a Path object from the program name.  
-  void *P = (void*) (intptr_t) GetBinDir;
-  sys::Path ProgramFullPath 
-    = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
-
-  // Get the dir name for the program. It's last component should be 'bin'.
-  std::string BinDir = ProgramFullPath.getDirname();
-
-  // llvm::errs() << "BinDir: " << BinDir << '\n';
-  return BinDir + GetDirSeparator();
-}
-
-// Get the Top-level Installation dir for c16.
-std::string GetInstallDir() {
-  sys::Path BinDirPath = sys::Path(GetBinDir());
-
-  // Go one more level up to get the install dir.
-  std::string InstallDir  = BinDirPath.getDirname();
-  
-  return InstallDir + GetDirSeparator();
-}
-
-// Get the dir where the c16 header files reside.
-std::string GetStdHeadersDir() {
-  return GetInstallDir() + "include";
-}
-
-// Get the dir where the assembler header files reside.
-std::string GetStdAsmHeadersDir() {
-  return GetInstallDir() + "inc";
-}
-
-// Get the dir where the linker scripts reside.
-std::string GetStdLinkerScriptsDir() {
-  return GetInstallDir() + "lkr";
-}
-
-// Get the dir where startup code, intrinsics and lib reside.
-std::string GetStdLibsDir() {
-  return GetInstallDir() + "lib";
-}
-}
diff --git a/tools/llvmc/examples/Hello/Hello.cpp b/tools/llvmc/examples/Hello/Hello.cpp
new file mode 100644 (file)
index 0000000..71f04fd
--- /dev/null
@@ -0,0 +1,29 @@
+//===- Hello.cpp - Example code from "Writing an LLVMC Plugin" ------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Shows how to write llvmc-based drivers without using TableGen.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CompilerDriver/AutoGenerated.h"
+#include "llvm/CompilerDriver/Main.inc"
+
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvmc {
+namespace autogenerated {
+
+int PreprocessOptions () { return 0; }
+
+int PopulateLanguageMap (LanguageMap&) { llvm::outs() << "Hello!\n"; return 0; }
+
+int PopulateCompilationGraph (CompilationGraph&) { return 0; }
+
+}
+}
diff --git a/tools/llvmc/examples/Hello/Makefile b/tools/llvmc/examples/Hello/Makefile
new file mode 100644 (file)
index 0000000..5b7dccb
--- /dev/null
@@ -0,0 +1,14 @@
+##===- tools/llvmc/plugins/Hello/Makefile ------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../../..
+
+LLVMC_BASED_DRIVER = Hello
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/examples/Makefile b/tools/llvmc/examples/Makefile
new file mode 100644 (file)
index 0000000..8468e93
--- /dev/null
@@ -0,0 +1,14 @@
+##===- tools/llvmc/examples/Makefile -----------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL=../../..
+
+PARALLEL_DIRS := Hello Simple mcc16 Skeleton
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/examples/Simple/Makefile b/tools/llvmc/examples/Simple/Makefile
new file mode 100644 (file)
index 0000000..c10387c
--- /dev/null
@@ -0,0 +1,15 @@
+##===- llvmc/examples/Simple/Makefile ----------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../../..
+
+LLVMC_BASED_DRIVER = Simple
+BUILT_SOURCES = Simple.inc
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/examples/Simple/Simple.cpp b/tools/llvmc/examples/Simple/Simple.cpp
new file mode 100644 (file)
index 0000000..8ac7313
--- /dev/null
@@ -0,0 +1,2 @@
+#include "llvm/CompilerDriver/Main.inc"
+#include "Simple.inc"
diff --git a/tools/llvmc/examples/Simple/Simple.td b/tools/llvmc/examples/Simple/Simple.td
new file mode 100644 (file)
index 0000000..7ceee93
--- /dev/null
@@ -0,0 +1,41 @@
+//===- Simple.td - A simple LLVMC-based driver ----------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// A simple LLVMC-based gcc wrapper.
+//
+// To compile, use this command:
+//
+//      $ cd $LLVM_OBJ_DIR/tools/llvmc
+//      $ make BUILD_EXAMPLES=1
+//
+// Run as:
+//
+//      $ $LLVM_OBJ_DIR/$(BuildMode)/bin/Simple
+//
+// For instructions on how to build your own LLVMC-based driver, see
+// the 'examples/Skeleton' directory.
+//===----------------------------------------------------------------------===//
+
+include "llvm/CompilerDriver/Common.td"
+
+def gcc : Tool<
+[(in_language "c"),
+ (out_language "executable"),
+ (output_suffix "out"),
+ (command "gcc"),
+ (sink),
+
+ // -o is what is used by default, out_file_option here is included for
+ // instructive purposes.
+ (out_file_option "-o")
+]>;
+
+def LanguageMap : LanguageMap<[LangToSuffixes<"c", ["c"]>]>;
+
+def CompilationGraph : CompilationGraph<[Edge<"root", "gcc">]>;
diff --git a/tools/llvmc/examples/Skeleton/AutoGenerated.td b/tools/llvmc/examples/Skeleton/AutoGenerated.td
new file mode 100644 (file)
index 0000000..97483ce
--- /dev/null
@@ -0,0 +1,7 @@
+//===- AutoGenerated.td ------------------------------------*- tablegen -*-===//
+//
+// Write the TableGen description of your llvmc-based driver here.
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/CompilerDriver/Common.td"
diff --git a/tools/llvmc/examples/Skeleton/Hooks.cpp b/tools/llvmc/examples/Skeleton/Hooks.cpp
new file mode 100644 (file)
index 0000000..ddd38f6
--- /dev/null
@@ -0,0 +1,12 @@
+//===--- Hooks.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Hook definitions should go here.
+//
+//===----------------------------------------------------------------------===//
diff --git a/tools/llvmc/examples/Skeleton/Main.cpp b/tools/llvmc/examples/Skeleton/Main.cpp
new file mode 100644 (file)
index 0000000..24c7768
--- /dev/null
@@ -0,0 +1,15 @@
+//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Just include CompilerDriver/Main.inc and AutoGenerated.inc.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CompilerDriver/Main.inc"
+#include "AutoGenerated.inc"
diff --git a/tools/llvmc/examples/Skeleton/Makefile b/tools/llvmc/examples/Skeleton/Makefile
new file mode 100644 (file)
index 0000000..41ca823
--- /dev/null
@@ -0,0 +1,20 @@
+##===- llvmc/examples/Skeleton/Makefile --------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open
+# Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+# Change this so that $(LEVEL)/Makefile.common refers to
+# $LLVM_OBJ_DIR/Makefile.common or $YOUR_LLVM_BASED_PROJECT/Makefile.common.
+export LEVEL = ../../../..
+
+# Change this to the name of your LLVMC-based driver.
+LLVMC_BASED_DRIVER = llvmc-skeleton
+
+# Change this to the name of .inc file built from your .td file.
+BUILT_SOURCES = AutoGenerated.inc
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/examples/Skeleton/README b/tools/llvmc/examples/Skeleton/README
new file mode 100644 (file)
index 0000000..61ff6fb
--- /dev/null
@@ -0,0 +1,6 @@
+
+This is a template that can be used to create your own LLVMC-based drivers. Just
+copy the `Skeleton` directory to the location of your preference and edit
+`Skeleton/Makefile` and `Skeleton/AutoGenerated.inc`.
+
+The build system assumes that your project is based on LLVM.
diff --git a/tools/llvmc/examples/mcc16/Hooks.cpp b/tools/llvmc/examples/mcc16/Hooks.cpp
new file mode 100644 (file)
index 0000000..aa31c89
--- /dev/null
@@ -0,0 +1,106 @@
+#include "llvm/System/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <string>
+
+using namespace llvm;
+
+namespace llvmc {
+  extern char *ProgramName;
+}
+
+extern cl::opt<std::string> AutoGeneratedParameter_p;
+
+// Returns the platform specific directory separator via #ifdefs.
+// FIXME: This currently work on linux and windows only. It does not
+// work on other unices.
+static std::string GetDirSeparator() {
+#if __linux__ || __APPLE__
+  return "/";
+#else
+  return "\\";
+#endif
+}
+
+namespace hooks {
+// Get preprocessor define for the part.
+// It is __partname format in lower case.
+std::string
+GetLowerCasePartDefine(void) {
+  std::string Partname;
+  if (AutoGeneratedParameter_p.empty()) {
+    Partname = "16f1xxx";
+  } else {
+    Partname = AutoGeneratedParameter_p;
+  }
+
+  std::string LowerCase;
+  for (unsigned i = 0; i < Partname.size(); i++) {
+    LowerCase.push_back(std::tolower(Partname[i]));
+  }
+
+  return "__" + LowerCase;
+}
+
+std::string
+GetUpperCasePartDefine(void) {
+  std::string Partname;
+  if (AutoGeneratedParameter_p.empty()) {
+    Partname = "16f1xxx";
+  } else {
+    Partname = AutoGeneratedParameter_p;
+  }
+
+  std::string UpperCase;
+  for (unsigned i = 0; i < Partname.size(); i++) {
+    UpperCase.push_back(std::toupper(Partname[i]));
+  }
+
+  return "__" +  UpperCase;
+}
+
+// Get the dir where c16 executables reside.
+std::string GetBinDir() {
+  // Construct a Path object from the program name.
+  void *P = (void*) (intptr_t) GetBinDir;
+  sys::Path ProgramFullPath
+    = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
+
+  // Get the dir name for the program. It's last component should be 'bin'.
+  std::string BinDir = ProgramFullPath.getDirname();
+
+  // llvm::errs() << "BinDir: " << BinDir << '\n';
+  return BinDir + GetDirSeparator();
+}
+
+// Get the Top-level Installation dir for c16.
+std::string GetInstallDir() {
+  sys::Path BinDirPath = sys::Path(GetBinDir());
+
+  // Go one more level up to get the install dir.
+  std::string InstallDir  = BinDirPath.getDirname();
+
+  return InstallDir + GetDirSeparator();
+}
+
+// Get the dir where the c16 header files reside.
+std::string GetStdHeadersDir() {
+  return GetInstallDir() + "include";
+}
+
+// Get the dir where the assembler header files reside.
+std::string GetStdAsmHeadersDir() {
+  return GetInstallDir() + "inc";
+}
+
+// Get the dir where the linker scripts reside.
+std::string GetStdLinkerScriptsDir() {
+  return GetInstallDir() + "lkr";
+}
+
+// Get the dir where startup code, intrinsics and lib reside.
+std::string GetStdLibsDir() {
+  return GetInstallDir() + "lib";
+}
+}
diff --git a/tools/llvmc/examples/mcc16/Main.cpp b/tools/llvmc/examples/mcc16/Main.cpp
new file mode 100644 (file)
index 0000000..55ae912
--- /dev/null
@@ -0,0 +1,57 @@
+//===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open
+// Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Usually this file just includes CompilerDriver/Main.inc, but here we apply
+//  some trickery to make the built-in '-save-temps' option hidden and enable
+//  '--temp-dir' by default.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CompilerDriver/BuiltinOptions.h"
+#include "llvm/CompilerDriver/Main.h"
+
+#include "llvm/System/Path.h"
+#include "llvm/Config/config.h"
+
+#include <iostream>
+
+#include "PIC16.inc"
+
+namespace {
+
+// Modify the PACKAGE_VERSION to use build number in top level configure file.
+void PIC16VersionPrinter(void) {
+  std::cout << "MPLAB C16 1.0 " << PACKAGE_VERSION << "\n";
+}
+
+}
+
+int main(int argc, char** argv) {
+
+  // HACK
+  SaveTemps.setHiddenFlag(llvm::cl::Hidden);
+  TempDirname.setHiddenFlag(llvm::cl::Hidden);
+  Languages.setHiddenFlag(llvm::cl::Hidden);
+  DryRun.setHiddenFlag(llvm::cl::Hidden);
+
+  llvm::cl::SetVersionPrinter(PIC16VersionPrinter);
+
+  // Ask for a standard temp dir, but just cache its basename., and delete it.
+  llvm::sys::Path tempDir;
+  tempDir = llvm::sys::Path::GetTemporaryDirectory();
+  TempDirname = tempDir.getBasename();
+  tempDir.eraseFromDisk(true);
+
+  // We are creating a temp dir in current dir, with the cached name.
+  //  But before that remove if one already exists with that name..
+  tempDir = TempDirname;
+  tempDir.eraseFromDisk(true);
+
+  return llvmc::Main(argc, argv);
+}
diff --git a/tools/llvmc/examples/mcc16/Makefile b/tools/llvmc/examples/mcc16/Makefile
new file mode 100644 (file)
index 0000000..4409cff
--- /dev/null
@@ -0,0 +1,15 @@
+##===- llvmc/examples/mcc16/Makefile -----------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../../..
+
+LLVMC_BASED_DRIVER = mcc16
+BUILT_SOURCES = PIC16.inc
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/llvmc/examples/mcc16/PIC16.td b/tools/llvmc/examples/mcc16/PIC16.td
new file mode 100644 (file)
index 0000000..4f07284
--- /dev/null
@@ -0,0 +1,234 @@
+//===- PIC16.td - PIC16 toolchain driver -------------------*- tablegen -*-===//
+//
+// A basic driver for the PIC16 toolchain.
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/CompilerDriver/Common.td"
+
+// Options
+
+def OptionList : OptionList<[
+ (switch_option "g",
+    (help "Enable Debugging")),
+ (switch_option "E",
+    (help "Stop after preprocessing, do not compile")),
+ (switch_option "S",
+    (help "Stop after compilation, do not assemble")),
+ (switch_option "bc",
+    (help "Stop after b-code generation, do not compile")),
+ (switch_option "c",
+    (help "Stop after assemble, do not link")),
+ (prefix_option "p",
+    (help "Specify part name")),
+ (prefix_list_option "I",
+    (help "Add a directory to include path")),
+ (prefix_list_option "L",
+    (help "Add a directory to library path")),
+ (prefix_list_option "K",
+    (help "Add a directory to linker script search path")),
+ (parameter_option "l",
+    (help "Specify a library to link")),
+ (parameter_option "k",
+    (help "Specify a linker script")),
+ (parameter_option "m",
+    (help "Generate linker map file with the given name")),
+ (prefix_list_option "D",
+    (help "Define a macro")),
+ (switch_option "X",
+    (help "Do not invoke mp2hex to create an output hex file.")),
+ (switch_option "O0",
+    (help "Do not optimize")),
+ (switch_option "O1",
+    (help "Optimization Level 1.")),
+ (switch_option "O2",
+    (help "Optimization Level 2.")),
+ (switch_option "O3",
+    (help "Optimization Level 3.")),
+ (switch_option "Od",
+    (help "Perform Debug-safe Optimizations only.")),
+ (switch_option "w",
+    (help "Disable all warnings.")),
+// (switch_option "O1",
+//    (help "Optimization level 1")),
+// (switch_option "O2",
+//    (help "Optimization level 2. (Default)")),
+// (parameter_option "pre-RA-sched",
+//    (help "Example of an option that is passed to llc")),
+ (parameter_option "regalloc",
+    (help "Register allocator to use (possible values: simple, linearscan, pbqp, local; default=linearscan)")),
+ (prefix_list_option "Wa,", (comma_separated),
+    (help "Pass options to assembler (Run 'gpasm -help' for assembler options)")),
+ (prefix_list_option "Wl,", (comma_separated),
+    (help "Pass options to linker (Run 'mplink -help' for linker options)"))
+// (prefix_list_option "Wllc,",
+//    (help "Pass options to llc")),
+// (prefix_list_option "Wo,",
+//    (help "Pass options to llvm-ld"))
+]>;
+
+// Tools
+class clang_based<string language, string cmd, string ext_E> : Tool<
+[(in_language language),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (command cmd),
+ (actions (case
+                (and (multiple_input_files),
+                     (or (switch_on "S"), (switch_on "c"))),
+                  (error "cannot specify -o with -c or -S with multiple files"),
+                (switch_on "E"), [(forward "E"),
+                                  (stop_compilation), (output_suffix ext_E)],
+                (and (switch_on "E"), (empty "o")), (no_out_file),
+                (switch_on "bc"),[(stop_compilation), (output_suffix "bc")],
+                (switch_on "g"), (append_cmd "-g"),
+                (switch_on "w"), (append_cmd "-w"),
+                (switch_on "O1"), (append_cmd ""),
+                (switch_on "O2"), (append_cmd ""),
+                (switch_on "O3"), (append_cmd ""),
+                (switch_on "Od"), (append_cmd ""),
+                (not_empty "D"), (forward "D"),
+                (not_empty "I"), (forward "I"),
+                (switch_on "O0"), (append_cmd "-O0"),
+                (default), (append_cmd "-O1")))
+// (sink)
+]>;
+
+def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang -cc1                                                        -I $CALL(GetStdHeadersDir)                                                      -D $CALL(GetLowerCasePartDefine)                                                -D $CALL(GetUpperCasePartDefine) -triple=pic16-                                 -emit-llvm-bc ", "i">;
+
+//def clang_cc : Tool<[
+// (in_language "c"),
+// (out_language "llvm-bitcode"),
+// (output_suffix "bc"),
+// (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc "),
+// (cmd_line kkkkk
+// (actions (case
+//          (switch_on "g"), (append_cmd "g"),
+//          (not_empty "I"), (forward "I"))),
+// (sink)
+//]>;
+
+
+// pre-link-and-lto step.
+def llvm_ld : Tool<[
+ (in_language "llvm-bitcode"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+ (command "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -disable-licm-promotion -l std"),
+ (out_file_option "-b"),
+ (actions (case
+          (switch_on "O0"), (append_cmd "-disable-opt"),
+          (switch_on "O1"), (append_cmd "-disable-opt"),
+// Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
+          (switch_on "O2"), (append_cmd ""),
+          (switch_on "O3"), (append_cmd ""),
+          (default), (append_cmd "-disable-inlining"))),
+ (join)
+]>;
+
+// optimize single file
+def llvm_ld_optimizer : Tool<[
+ (in_language "llvm-bitcode"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "bc"),
+// FIXME: we are still not disabling licm-promotion.
+// -disable-licm-promotion and building stdn library causes c16-71 to fail.
+ (command "$CALL(GetBinDir)llvm-ld "),
+ (out_file_option "-b"),
+ (actions (case
+          (switch_on "O0"), (append_cmd "-disable-opt"),
+          (switch_on "O1"), (append_cmd "-disable-opt"),
+// Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
+          (switch_on "O2"), (append_cmd ""),
+          (switch_on "O3"), (append_cmd ""),
+          (default), (append_cmd "-disable-inlining")))
+]>;
+
+// optimizer step.
+def pic16passes : Tool<[
+ (in_language "llvm-bitcode"),
+ (out_language "llvm-bitcode"),
+ (output_suffix "obc"),
+ (command "$CALL(GetBinDir)opt -pic16cloner -pic16overlay -f"),
+ (actions (case
+          (switch_on "O0"), (append_cmd "-disable-opt")))
+]>;
+
+def llc : Tool<[
+ (in_language "llvm-bitcode"),
+ (out_language "assembler"),
+ (output_suffix "s"),
+ (command "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -f"),
+ (actions (case
+          (switch_on "S"), (stop_compilation),
+//          (not_empty "Wllc,"), (unpack_values "Wllc,"),
+//         (not_empty "pre-RA-sched"), (forward "pre-RA-sched")))
+         (not_empty "regalloc"), (forward "regalloc"),
+         (empty "regalloc"), (append_cmd "-regalloc=linearscan")))
+]>;
+
+def gpasm : Tool<[
+ (in_language "assembler"),
+ (out_language "object-code"),
+ (output_suffix "o"),
+ (command "$CALL(GetBinDir)gpasm -z -r decimal -I $CALL(GetStdAsmHeadersDir) -C -c -w 2"),
+ (actions (case
+          (switch_on "c"), (stop_compilation),
+          (switch_on "g"), (append_cmd "-g"),
+          (not_empty "p"), (forward "p"),
+          (empty "p"), (append_cmd "-p 16f1xxx"),
+          (not_empty "Wa,"), (forward_value "Wa,")))
+]>;
+
+def mplink : Tool<[
+ (in_language "object-code"),
+ (out_language "executable"),
+ (output_suffix "cof"),
+ (command "$CALL(GetBinDir)mplink -e -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) intrinsics.lib stdn.lib"),
+ (actions (case
+          (not_empty "Wl,"), (forward_value "Wl,"),
+          (switch_on "X"), (append_cmd "-x"),
+          (not_empty "L"), (forward_as "L", "-l"),
+          (not_empty "K"), (forward_as "K", "-k"),
+          (not_empty "m"), (forward "m"),
+          (not_empty "p"), [(forward "p"), (append_cmd "-c")],
+          (empty "p"), (append_cmd "-p 16f1xxx -c"),
+//          (not_empty "l"), [(unpack_values "l"),(append_cmd ".lib")])),
+          (not_empty "k"), (forward "k"),
+          (not_empty "l"), (forward "l"))),
+ (join)
+]>;
+
+// Language map
+
+def LanguageMap : LanguageMap<[
+    LangToSuffixes<"c", ["c"]>,
+    LangToSuffixes<"c-cpp-output", ["i"]>,
+    LangToSuffixes<"assembler", ["s"]>,
+    LangToSuffixes<"assembler-with-cpp", ["S"]>,
+    LangToSuffixes<"llvm-assembler", ["ll"]>,
+    LangToSuffixes<"llvm-bitcode", ["bc"]>,
+    LangToSuffixes<"object-code", ["o"]>,
+    LangToSuffixes<"executable", ["cof"]>
+]>;
+
+// Compilation graph
+
+def CompilationGraph : CompilationGraph<[
+    Edge<"root", "clang_cc">,
+    Edge<"root", "llvm_ld">,
+    OptionalEdge<"root", "llvm_ld_optimizer", (case
+                                         (switch_on "S"), (inc_weight),
+                                         (switch_on "c"), (inc_weight))>,
+    Edge<"root", "gpasm">,
+    Edge<"root", "mplink">,
+    Edge<"clang_cc", "llvm_ld">,
+    OptionalEdge<"clang_cc", "llvm_ld_optimizer", (case
+                                         (switch_on "S"), (inc_weight),
+                                         (switch_on "c"), (inc_weight))>,
+    Edge<"llvm_ld", "pic16passes">,
+    Edge<"llvm_ld_optimizer", "pic16passes">,
+    Edge<"pic16passes", "llc">,
+    Edge<"llc", "gpasm">,
+    Edge<"gpasm", "mplink">
+]>;
diff --git a/tools/llvmc/examples/mcc16/README b/tools/llvmc/examples/mcc16/README
new file mode 100644 (file)
index 0000000..6d2b73d
--- /dev/null
@@ -0,0 +1,75 @@
+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
index 2d4455078216d9c97098b4113d6aa59ca855beff..b091419f91e546dc826039dfba178b483b218a13 100644 (file)
@@ -2950,8 +2950,6 @@ void EmitIncludes(raw_ostream& O) {
     << "using namespace llvm;\n"
     << "using namespace llvmc;\n\n"
 
-    << "extern cl::opt<std::string> OutputFilename;\n\n"
-
     << "inline const char* checkCString(const char* s)\n"
     << "{ return s == NULL ? \"\" : s; }\n\n";
 }