diff options
Diffstat (limited to 'tools/llvmc/example')
-rw-r--r-- | tools/llvmc/example/Hello/Hello.cpp | 30 | ||||
-rw-r--r-- | tools/llvmc/example/Hello/Makefile | 14 | ||||
-rw-r--r-- | tools/llvmc/example/Simple/Makefile | 15 | ||||
-rw-r--r-- | tools/llvmc/example/Simple/PluginMain.cpp | 1 | ||||
-rw-r--r-- | tools/llvmc/example/Simple/Simple.td | 37 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/Makefile | 24 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/README | 6 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/driver/Main.cpp | 14 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/driver/Makefile | 22 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/plugins/Makefile | 18 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/plugins/Plugin/Makefile | 17 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/plugins/Plugin/Plugin.td | 7 | ||||
-rw-r--r-- | tools/llvmc/example/Skeleton/plugins/Plugin/PluginMain.cpp | 1 |
13 files changed, 206 insertions, 0 deletions
diff --git a/tools/llvmc/example/Hello/Hello.cpp b/tools/llvmc/example/Hello/Hello.cpp new file mode 100644 index 0000000000000..23a13a57c2b84 --- /dev/null +++ b/tools/llvmc/example/Hello/Hello.cpp @@ -0,0 +1,30 @@ +//===- 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 <iostream> + +namespace { +struct MyPlugin : public llvmc::BasePlugin { + void PopulateLanguageMap(llvmc::LanguageMap&) const + { std::cout << "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 new file mode 100644 index 0000000000000..10325e6a6d5f8 --- /dev/null +++ b/tools/llvmc/example/Hello/Makefile @@ -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_PLUGIN = Hello + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/Simple/Makefile b/tools/llvmc/example/Simple/Makefile new file mode 100644 index 0000000000000..d7adb5d851e58 --- /dev/null +++ b/tools/llvmc/example/Simple/Makefile @@ -0,0 +1,15 @@ +##===- 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 new file mode 100644 index 0000000000000..add8acb4a574d --- /dev/null +++ b/tools/llvmc/example/Simple/PluginMain.cpp @@ -0,0 +1 @@ +#include "AutoGenerated.inc" diff --git a/tools/llvmc/example/Simple/Simple.td b/tools/llvmc/example/Simple/Simple.td new file mode 100644 index 0000000000000..87bc385b7a70c --- /dev/null +++ b/tools/llvmc/example/Simple/Simple.td @@ -0,0 +1,37 @@ +//===- 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 new file mode 100644 index 0000000000000..2e4cbb944a607 --- /dev/null +++ b/tools/llvmc/example/Skeleton/Makefile @@ -0,0 +1,24 @@ +##===- 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. +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 new file mode 100644 index 0000000000000..92216ae504510 --- /dev/null +++ b/tools/llvmc/example/Skeleton/README @@ -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/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 new file mode 100644 index 0000000000000..b1f5b6798ae69 --- /dev/null +++ b/tools/llvmc/example/Skeleton/driver/Main.cpp @@ -0,0 +1,14 @@ +//===--- 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 new file mode 100644 index 0000000000000..bf6d7a588de31 --- /dev/null +++ b/tools/llvmc/example/Skeleton/driver/Makefile @@ -0,0 +1,22 @@ +##===- 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)/.. + +TOOLNAME = $(LLVMC_BASED_DRIVER_NAME) +LLVMLIBS = CompilerDriver + +ifneq ($(LLVMC_BUILTIN_PLUGINS),) +USEDLIBS += $(patsubst %,plugin_llvmc_%,$(LLVMC_BUILTIN_PLUGINS)) +endif + +LINK_COMPONENTS = support system +REQUIRES_EH := 1 + +include $(LEVEL)/Makefile.common diff --git a/tools/llvmc/example/Skeleton/plugins/Makefile b/tools/llvmc/example/Skeleton/plugins/Makefile new file mode 100644 index 0000000000000..fb07f23d58e50 --- /dev/null +++ b/tools/llvmc/example/Skeleton/plugins/Makefile @@ -0,0 +1,18 @@ +##===- 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 new file mode 100644 index 0000000000000..54f722165dc7f --- /dev/null +++ b/tools/llvmc/example/Skeleton/plugins/Plugin/Makefile @@ -0,0 +1,17 @@ +##===- 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 new file mode 100644 index 0000000000000..febb9ad374eb6 --- /dev/null +++ b/tools/llvmc/example/Skeleton/plugins/Plugin/Plugin.td @@ -0,0 +1,7 @@ +//===- 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 new file mode 100644 index 0000000000000..add8acb4a574d --- /dev/null +++ b/tools/llvmc/example/Skeleton/plugins/Plugin/PluginMain.cpp @@ -0,0 +1 @@ +#include "AutoGenerated.inc" |