1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

llvmc: Update examples.

llvm-svn: 111553
This commit is contained in:
Mikhail Glushenkov 2010-08-19 20:04:19 +00:00
parent 36df8f356e
commit 201390919b
27 changed files with 116 additions and 187 deletions

View File

@ -11,4 +11,8 @@ LEVEL = ../..
DIRS = src
ifeq ($(BUILD_EXAMPLES),1)
OPTIONAL_DIRS += examples
endif
include $(LEVEL)/Makefile.common

View File

@ -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");
}

View File

@ -1 +0,0 @@
#include "AutoGenerated.inc"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1 +0,0 @@
#include "AutoGenerated.inc"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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; }
}
}

View File

@ -9,6 +9,6 @@
LEVEL = ../../../..
LLVMC_PLUGIN = Hello
LLVMC_BASED_DRIVER = Hello
include $(LEVEL)/Makefile.common

View File

@ -1,4 +1,4 @@
##===- llvmc/example/Skeleton/plugins/Plugin/Makefile ------*- Makefile -*-===##
##===- tools/llvmc/examples/Makefile -----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@ -7,11 +7,8 @@
#
##===----------------------------------------------------------------------===##
LEVEL = $(LLVMC_BASE_LEVEL)/../..
LEVEL=../../..
# Change this to the name of your plugin.
LLVMC_PLUGIN = Plugin
BUILT_SOURCES = AutoGenerated.inc
PARALLEL_DIRS := Hello Simple mcc16 Skeleton
include $(LEVEL)/Makefile.common

View File

@ -1,4 +1,4 @@
##===- tools/llvmc/plugins/Simple/Makefile -----------------*- Makefile -*-===##
##===- llvmc/examples/Simple/Makefile ----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@ -9,7 +9,7 @@
LEVEL = ../../../..
LLVMC_PLUGIN = Simple
BUILT_SOURCES = AutoGenerated.inc
LLVMC_BASED_DRIVER = Simple
BUILT_SOURCES = Simple.inc
include $(LEVEL)/Makefile.common

View File

@ -0,0 +1,2 @@
#include "llvm/CompilerDriver/Main.inc"
#include "Simple.inc"

View File

@ -1,4 +1,4 @@
//===- Simple.td - A simple plugin for LLVMC ------------------------------===//
//===- Simple.td - A simple LLVMC-based driver ----------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -7,19 +7,19 @@
//
//===----------------------------------------------------------------------===//
//
// A simple LLVMC-based gcc wrapper that shows how to write LLVMC plugins.
// A simple LLVMC-based gcc wrapper.
//
// To compile, use this command:
//
// $ cd $LLVMC_DIR/example/Simple
// $ make
// $ cd $LLVM_OBJ_DIR/tools/llvmc
// $ make BUILD_EXAMPLES=1
//
// Run as:
//
// $ llvmc -load $LLVM_DIR/Release/lib/plugin_llvmc_Simple.so
// $ $LLVM_OBJ_DIR/$(BuildMode)/bin/Simple
//
// For instructions on how to build your own LLVMC-based driver, see
// the 'example/Skeleton' directory.
// the 'examples/Skeleton' directory.
//===----------------------------------------------------------------------===//
include "llvm/CompilerDriver/Common.td"
@ -28,8 +28,12 @@ def gcc : Tool<
[(in_language "c"),
(out_language "executable"),
(output_suffix "out"),
(cmd_line "gcc $INFILE -o $OUTFILE"),
(sink)
(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"]>]>;

View File

@ -1,6 +1,6 @@
//===- Plugin.td - A skeleton plugin for LLVMC -------------*- tablegen -*-===//
//===- AutoGenerated.td ------------------------------------*- tablegen -*-===//
//
// Write the code for your plugin here.
// Write the TableGen description of your llvmc-based driver here.
//
//===----------------------------------------------------------------------===//

View File

@ -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.
//
//===----------------------------------------------------------------------===//

View File

@ -7,8 +7,9 @@
//
//===----------------------------------------------------------------------===//
//
// Just include CompilerDriver/Main.inc.
// Just include CompilerDriver/Main.inc and AutoGenerated.inc.
//
//===----------------------------------------------------------------------===//
#include "llvm/CompilerDriver/Main.inc"
#include "AutoGenerated.inc"

View File

@ -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

View File

@ -1,6 +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`.
`Skeleton/Makefile` and `Skeleton/AutoGenerated.inc`.
The build system assumes that your project is based on LLVM.

View File

@ -1,19 +1,20 @@
#include "AutoGenerated.inc"
#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.
// FIXME: This currently work on linux and windows only. It does not
// work on other unices.
static std::string GetDirSeparator() {
#if __linux__ || __APPLE__
return "/";
@ -59,12 +60,11 @@ GetUpperCasePartDefine(void) {
return "__" + UpperCase;
}
// Get the dir where c16 executables reside.
std::string GetBinDir() {
// Construct a Path object from the program name.
// Construct a Path object from the program name.
void *P = (void*) (intptr_t) GetBinDir;
sys::Path ProgramFullPath
sys::Path ProgramFullPath
= sys::Path::GetMainExecutable(llvmc::ProgramName, P);
// Get the dir name for the program. It's last component should be 'bin'.
@ -80,7 +80,7 @@ std::string GetInstallDir() {
// Go one more level up to get the install dir.
std::string InstallDir = BinDirPath.getDirname();
return InstallDir + GetDirSeparator();
}

View File

@ -13,21 +13,25 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Config/config.h"
#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/ForceLinkage.h"
#include "llvm/CompilerDriver/Main.h"
#include "llvm/System/Path.h"
#include "llvm/Config/config.h"
#include <iostream>
namespace llvmc {
int Main(int argc, char** argv);
}
#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
@ -36,7 +40,7 @@ int main(int argc, char** argv) {
Languages.setHiddenFlag(llvm::cl::Hidden);
DryRun.setHiddenFlag(llvm::cl::Hidden);
llvm::cl::SetVersionPrinter(PIC16VersionPrinter);
llvm::cl::SetVersionPrinter(PIC16VersionPrinter);
// Ask for a standard temp dir, but just cache its basename., and delete it.
llvm::sys::Path tempDir;
@ -49,6 +53,5 @@ int main(int argc, char** argv) {
tempDir = TempDirname;
tempDir.eraseFromDisk(true);
llvmc::ForceLinkage();
return llvmc::Main(argc, argv);
}

View File

@ -1,4 +1,4 @@
##===- llvmc/example/Skeleton/plugins/Plugin/Makefile ------*- Makefile -*-===##
##===- llvmc/examples/mcc16/Makefile -----------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@ -7,11 +7,9 @@
#
##===----------------------------------------------------------------------===##
LEVEL = $(LLVMC_BASE_LEVEL)/../..
LEVEL = ../../../..
# Change this to the name of your plugin.
LLVMC_PLUGIN = PIC16Base
BUILT_SOURCES = AutoGenerated.inc
LLVMC_BASED_DRIVER = mcc16
BUILT_SOURCES = PIC16.inc
include $(LEVEL)/Makefile.common

View File

@ -1,4 +1,4 @@
//===- PIC16Base.td - PIC16 toolchain driver ---------------*- tablegen -*-===//
//===- PIC16.td - PIC16 toolchain driver -------------------*- tablegen -*-===//
//
// A basic driver for the PIC16 toolchain.
//

View File

@ -1,5 +1,5 @@
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.
your own llvmc-based drivers. It is based on the examples/Skeleton template.
The PIC16 toolchain looks like this:

View 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";
}