aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorKarl Schimpf <kschimpf@google.com>2013-05-24 12:04:22 -0700
committerKarl Schimpf <kschimpf@google.com>2013-05-24 12:04:22 -0700
commitfde18fe06ae70f60e0f184a9d384055c4f08cbbb (patch)
tree96a77030079d2d53a706131a39e606db31bd19dc /tools
parent80b7ba7480724c773b96da24999d817b6b46ef29 (diff)
Allow generation of pnacl bitcode files in several llvm commnads.
Adds command line option '-pnacl-freeze' to generate a pnacl bit code file instead of an llvm bitcode file. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3405 R=dschuff@chromium.org Review URL: https://codereview.chromium.org/15178005
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-as/CMakeLists.txt2
-rw-r--r--tools/llvm-as/LLVMBuild.txt2
-rw-r--r--tools/llvm-as/Makefile2
-rw-r--r--tools/llvm-as/llvm-as.cpp20
-rw-r--r--tools/llvm-link/CMakeLists.txt2
-rw-r--r--tools/lto/CMakeLists.txt2
-rw-r--r--tools/lto/LTOCodeGenerator.cpp16
-rw-r--r--tools/lto/Makefile2
-rw-r--r--tools/opt/CMakeLists.txt2
-rw-r--r--tools/opt/LLVMBuild.txt2
-rw-r--r--tools/opt/Makefile2
-rw-r--r--tools/opt/opt.cpp21
12 files changed, 61 insertions, 14 deletions
diff --git a/tools/llvm-as/CMakeLists.txt b/tools/llvm-as/CMakeLists.txt
index d5620e7297..c7a017afc3 100644
--- a/tools/llvm-as/CMakeLists.txt
+++ b/tools/llvm-as/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS asmparser bitwriter)
+set(LLVM_LINK_COMPONENTS asmparser bitwriter naclbitwriter)
add_llvm_tool(llvm-as
llvm-as.cpp
diff --git a/tools/llvm-as/LLVMBuild.txt b/tools/llvm-as/LLVMBuild.txt
index 542470bbdd..166bcc5120 100644
--- a/tools/llvm-as/LLVMBuild.txt
+++ b/tools/llvm-as/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Tool
name = llvm-as
parent = Tools
-required_libraries = AsmParser BitWriter
+required_libraries = AsmParser BitWriter NaClBitWriter
diff --git a/tools/llvm-as/Makefile b/tools/llvm-as/Makefile
index dfd71b295a..d7c3d35f40 100644
--- a/tools/llvm-as/Makefile
+++ b/tools/llvm-as/Makefile
@@ -9,7 +9,7 @@
LEVEL := ../..
TOOLNAME := llvm-as
-LINK_COMPONENTS := asmparser bitwriter
+LINK_COMPONENTS := asmparser bitwriter naclbitwriter
# This tool has no plugins, optimize startup time.
TOOL_NO_EXPORTS := 1
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index 273c4274b5..57820a59bd 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -19,6 +19,9 @@
#include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/Parser.h"
#include "llvm/Bitcode/ReaderWriter.h"
+// @LOCALMOD-BEGIN
+#include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
+// @LOCALMOD-END
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
@@ -50,6 +53,13 @@ static cl::opt<bool>
DisableVerify("disable-verify", cl::Hidden,
cl::desc("Do not run verifier on input LLVM (dangerous!)"));
+// @LOCALMOD-BEGIN
+static cl::opt<bool>
+GeneratePNaClBitcode("pnacl-freeze",
+ cl::desc("Generate a pnacl-frozen bitcode file"),
+ cl::init(false));
+// @LOCALMOD-END
+
static void WriteOutputFile(const Module *M) {
// Infer the output filename if needed.
if (OutputFilename.empty()) {
@@ -77,8 +87,14 @@ static void WriteOutputFile(const Module *M) {
exit(1);
}
- if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
- WriteBitcodeToFile(M, Out->os());
+ // @LOCALMOD-BEGIN
+ if (Force || !CheckBitcodeOutputToConsole(Out->os(), true)) {
+ if (GeneratePNaClBitcode)
+ NaClWriteBitcodeToFile(M, Out->os());
+ else
+ WriteBitcodeToFile(M, Out->os());
+ }
+ // @LOCALMOD-END
// Declare success.
Out->keep();
diff --git a/tools/llvm-link/CMakeLists.txt b/tools/llvm-link/CMakeLists.txt
index 11933f7f95..a5850c9716 100644
--- a/tools/llvm-link/CMakeLists.txt
+++ b/tools/llvm-link/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS linker bitreader bitwriter asmparser)
+set(LLVM_LINK_COMPONENTS linker bitreader bitwriter naclbitwriter asmparser)
add_llvm_tool(llvm-link
llvm-link.cpp
diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt
index 5820b1415b..e984601ced 100644
--- a/tools/lto/CMakeLists.txt
+++ b/tools/lto/CMakeLists.txt
@@ -1,6 +1,6 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
- ipo scalaropts linker bitreader bitwriter mcdisassembler vectorize)
+ ipo scalaropts linker bitreader bitwriter naclbitwriter mcdisassembler vectorize)
add_definitions( -DLLVM_VERSION_INFO=\"${PACKAGE_VERSION}\" )
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 720924807e..a8959aeae4 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -18,6 +18,7 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD
#include "llvm/CodeGen/IntrinsicLowering.h" // @LOCALMOD
#include "llvm/Config/config.h"
#include "llvm/IR/Constants.h"
@@ -55,6 +56,14 @@ static cl::opt<bool>
DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
cl::desc("Do not run the GVN load PRE pass"));
+// @LOCALMOD-BEGIN
+static llvm::cl::opt<bool>
+GeneratePNaClBitcode("pnacl-freeze",
+ llvm::cl::desc("Generate a pnacl-frozen bitcode file"),
+ llvm::cl::init(false));
+
+// @LOCALMOD-END
+
const char* LTOCodeGenerator::getVersionString() {
#ifdef LLVM_VERSION_INFO
return PACKAGE_NAME " version " PACKAGE_VERSION ", " LLVM_VERSION_INFO;
@@ -286,8 +295,13 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
return true;
}
+ // @LOCALMOD-BEGIN
// write bitcode to it
- WriteBitcodeToFile(_linker.getModule(), Out.os());
+ if (GeneratePNaClBitcode)
+ NaClWriteBitcodeToFile(_linker.getModule(), Out.os());
+ else
+ WriteBitcodeToFile(_linker.getModule(), Out.os());
+ // @LOCALMOD-END
Out.os().close();
if (Out.os().has_error()) {
diff --git a/tools/lto/Makefile b/tools/lto/Makefile
index c13a0ba7f6..082082026c 100644
--- a/tools/lto/Makefile
+++ b/tools/lto/Makefile
@@ -10,7 +10,7 @@
LEVEL := ../..
LIBRARYNAME := LTO
LINK_COMPONENTS := all-targets ipo scalaropts linker bitreader bitwriter \
- mcdisassembler vectorize
+ naclbitwriter mcdisassembler vectorize
LINK_LIBS_IN_SHARED := 1
SHARED_LIBRARY := 1
diff --git a/tools/opt/CMakeLists.txt b/tools/opt/CMakeLists.txt
index 3b268a4205..9d41db9dda 100644
--- a/tools/opt/CMakeLists.txt
+++ b/tools/opt/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser bitwriter instrumentation naclanalysis nacltransforms scalaropts objcarcopts ipo vectorize)
+set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser bitwriter naclbitwriter instrumentation naclanalysis nacltransforms scalaropts objcarcopts ipo vectorize)
add_llvm_tool(opt
AnalysisWrappers.cpp
diff --git a/tools/opt/LLVMBuild.txt b/tools/opt/LLVMBuild.txt
index 02567c2234..b69b7cbb83 100644
--- a/tools/opt/LLVMBuild.txt
+++ b/tools/opt/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Tool
name = opt
parent = Tools
-required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar ObjCARC all-targets NaClTransforms NaClAnalysis
+required_libraries = AsmParser BitReader BitWriter NaClBitWriter IPO Instrumentation Scalar ObjCARC all-targets NaClTransforms NaClAnalysis
diff --git a/tools/opt/Makefile b/tools/opt/Makefile
index ff07e3fe4f..92622102d9 100644
--- a/tools/opt/Makefile
+++ b/tools/opt/Makefile
@@ -9,6 +9,6 @@
LEVEL := ../..
TOOLNAME := opt
-LINK_COMPONENTS := bitreader bitwriter asmparser instrumentation scalaropts objcarcopts ipo vectorize nacltransforms naclanalysis all-targets
+LINK_COMPONENTS := bitreader bitwriter naclbitwriter asmparser instrumentation scalaropts objcarcopts ipo vectorize nacltransforms naclanalysis all-targets
include $(LEVEL)/Makefile.common
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index fbacdfc63d..94ff313937 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -22,6 +22,7 @@
#include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/DebugInfo.h"
#include "llvm/IR/DataLayout.h"
@@ -156,6 +157,13 @@ DefaultDataLayout("default-data-layout",
cl::desc("data layout string to use if not specified by module"),
cl::value_desc("layout-string"), cl::init(""));
+// @LOCALMOD-BEGIN
+static cl::opt<bool>
+GeneratePNaClBitcode("pnacl-freeze",
+ cl::desc("Generate a pnacl-frozen bitcode file"),
+ cl::init(false));
+// @LOCALMOD-END
+
// ---------- Define Printers for module and function passes ------------
namespace {
@@ -831,8 +839,7 @@ int main(int argc, char **argv) {
if (!NoOutput && !AnalyzeOnly) {
if (OutputAssembly)
Passes.add(createPrintModulePass(&Out->os()));
- else
- Passes.add(createBitcodeWriterPass(Out->os()));
+ // @LOCALMOD
}
// Before executing passes, print the final values of the LLVM options.
@@ -841,6 +848,16 @@ int main(int argc, char **argv) {
// Now that we have all of the passes ready, run them.
Passes.run(*M.get());
+// @LOCALMOD-BEGIN
+ // Write bitcode to the output.
+ if (!NoOutput && !AnalyzeOnly && !OutputAssembly) {
+ if (GeneratePNaClBitcode)
+ NaClWriteBitcodeToFile(M.get(), Out->os());
+ else
+ WriteBitcodeToFile(M.get(), Out->os());
+ }
+// @LOCALMOD-END
+
// Declare success.
if (!NoOutput || PrintBreakpoints)
Out->keep();