diff options
author | Karl Schimpf <kschimpf@google.com> | 2013-06-07 09:46:15 -0700 |
---|---|---|
committer | Karl Schimpf <kschimpf@google.com> | 2013-06-07 09:46:15 -0700 |
commit | 098dc634a5e6458a319617ec1737868cbf0f3d01 (patch) | |
tree | b0272b1653e50b9fc8a3c5d4ab0a7d5a854eb30e | |
parent | bcbad3ce541bc70ab3383d3d77198ceb9e813b46 (diff) |
Add CL argument -bitcode-format to llvm-dis, llc, and pnacl-llc.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3469
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/16385002
-rw-r--r-- | include/llvm/IRReader/IRReader.h | 49 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/IRReader/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/IRReader/IRReader.cpp | 71 | ||||
-rw-r--r-- | lib/IRReader/LLVMBuild.txt | 22 | ||||
-rw-r--r-- | lib/IRReader/Makefile | 14 | ||||
-rw-r--r-- | lib/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | tools/llc/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/llc/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/llc/Makefile | 3 | ||||
-rw-r--r-- | tools/llc/llc.cpp | 37 | ||||
-rw-r--r-- | tools/llvm-dis/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-dis/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/llvm-dis/Makefile | 2 | ||||
-rw-r--r-- | tools/llvm-dis/llvm-dis.cpp | 30 | ||||
-rw-r--r-- | tools/opt/opt.cpp | 16 | ||||
-rw-r--r-- | tools/pnacl-llc/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/pnacl-llc/LLVMBuild.txt | 2 | ||||
-rw-r--r-- | tools/pnacl-llc/Makefile | 3 | ||||
-rw-r--r-- | tools/pnacl-llc/pnacl-llc.cpp | 37 |
21 files changed, 276 insertions, 32 deletions
diff --git a/include/llvm/IRReader/IRReader.h b/include/llvm/IRReader/IRReader.h new file mode 100644 index 0000000000..2f84956e7e --- /dev/null +++ b/include/llvm/IRReader/IRReader.h @@ -0,0 +1,49 @@ +//===-- llvm/IRReader/IRReader.h - Reader of IR ----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header defines IR readers that understand LLVM and PNaCl file formats. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IRREADER_IRREADER_H +#define LLVM_IRREADER_IRREADER_H + +namespace llvm { + +class LLVM_Context; +class MemoryBuffer; +class SMDiagnostic; + +// \brief Define the expected format of the file. +enum NaClFileFormat { + // LLVM IR source or bitcode file (as appropriate). + LLVMFormat, + // PNaCl bitcode file. + PNaClFormat +}; + +// \brief If the given MemoryBuffer holds a bitcode image, return a Module +// for it. Otherwise, attempt to parse it as LLVM Assembly and return +// a Module for it. This function *always* takes ownership of the given +// MemoryBuffer. +Module *NaClParseIR(MemoryBuffer *Buffer, + NaClFileFormat Format, + SMDiagnostic &Err, + LLVMContext &Context); + +/// \brief If the given file holds a Bitcode image, read the file. +/// Otherwise, attempt to parse it as LLVM assembly and return a +/// Module for it. +Module *NaClParseIRFile(const std::string &Filename, + NaClFileFormat Format, + SMDiagnostic &Err, + LLVMContext &Context); + +} // end llvm namespace +#endif diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7b2adec6e8..e2a5c54756 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,6 +1,7 @@ # `Support' and `TableGen' libraries are added on the top-level CMakeLists.txt add_subdirectory(IR) +add_subdirectory(IRReader) add_subdirectory(CodeGen) add_subdirectory(Bitcode) add_subdirectory(Transforms) @@ -14,4 +15,4 @@ add_subdirectory(ExecutionEngine) add_subdirectory(Target) add_subdirectory(AsmParser) add_subdirectory(Archive) -add_subdirectory(Wrap)
\ No newline at end of file +add_subdirectory(Wrap) diff --git a/lib/IRReader/CMakeLists.txt b/lib/IRReader/CMakeLists.txt new file mode 100644 index 0000000000..cf10d8b7db --- /dev/null +++ b/lib/IRReader/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMIRReader + IRReader.cpp + ) diff --git a/lib/IRReader/IRReader.cpp b/lib/IRReader/IRReader.cpp new file mode 100644 index 0000000000..fe74a9ae51 --- /dev/null +++ b/lib/IRReader/IRReader.cpp @@ -0,0 +1,71 @@ +//===- IRReader.cpp - NaCl aware IR readers. ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/OwningPtr.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/IRReader/IRReader.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/system_error.h" + +using namespace llvm; + +// Note: Code below based on ParseIR and ParseIRFile in llvm/Support/IRReader.h + +Module *llvm::NaClParseIR(MemoryBuffer *Buffer, + NaClFileFormat Format, + SMDiagnostic &Err, + LLVMContext &Context) { + if ((Format == PNaClFormat) && + isNaClBitcode((const unsigned char *)Buffer->getBufferStart(), + (const unsigned char *)Buffer->getBufferEnd())) { + std::string ErrMsg; + Module *M = NaClParseBitcodeFile(Buffer, Context, &ErrMsg); + if (M == 0) + Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + ErrMsg); + // ParseBitcodeFile does not take ownership of the Buffer. + delete Buffer; + return M; + } else if (Format == LLVMFormat) { + if (isBitcode((const unsigned char *)Buffer->getBufferStart(), + (const unsigned char *)Buffer->getBufferEnd())) { + std::string ErrMsg; + Module *M = ParseBitcodeFile(Buffer, Context, &ErrMsg); + if (M == 0) + Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + ErrMsg); + // ParseBitcodeFile does not take ownership of the Buffer. + delete Buffer; + return M; + } + + return ParseAssembly(Buffer, 0, Err, Context); + } else { + Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, + "Did not specify correct format for file"); + return 0; + } +} + +Module *llvm::NaClParseIRFile(const std::string &Filename, + NaClFileFormat Format, + SMDiagnostic &Err, + LLVMContext &Context) { + OwningPtr<MemoryBuffer> File; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename.c_str(), File)) { + Err = SMDiagnostic(Filename, SourceMgr::DK_Error, + "Could not open input file: " + ec.message()); + return 0; + } + + return NaClParseIR(File.take(), Format, Err, Context); +} diff --git a/lib/IRReader/LLVMBuild.txt b/lib/IRReader/LLVMBuild.txt new file mode 100644 index 0000000000..2fea2e1dc4 --- /dev/null +++ b/lib/IRReader/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./lib/IRReader/LLVMBuild.txt -----------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = IRReader +parent = Libraries +required_libraries = AsmParser BitReader NaClBitReader Core Support diff --git a/lib/IRReader/Makefile b/lib/IRReader/Makefile new file mode 100644 index 0000000000..66eb4598f5 --- /dev/null +++ b/lib/IRReader/Makefile @@ -0,0 +1,14 @@ +##===- lib/IRReader/Makefile -------------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +LIBRARYNAME = LLVMIRReader +BUILD_ARCHIVE = 1 + +include $(LEVEL)/Makefile.common diff --git a/lib/LLVMBuild.txt b/lib/LLVMBuild.txt index 6c151a5e08..ee62daece4 100644 --- a/lib/LLVMBuild.txt +++ b/lib/LLVMBuild.txt @@ -16,7 +16,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = Analysis Archive AsmParser Bitcode CodeGen DebugInfo ExecutionEngine Linker IR MC Object Option Support TableGen Target Transforms Wrap +subdirectories = Analysis Archive AsmParser Bitcode CodeGen DebugInfo ExecutionEngine Linker IR IRReader MC Object Option Support TableGen Target Transforms Wrap [component_0] type = Group diff --git a/lib/Makefile b/lib/Makefile index 9d609bcc1f..ac9050db7c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -10,7 +10,7 @@ LEVEL = .. include $(LEVEL)/Makefile.config -PARALLEL_DIRS := IR AsmParser Bitcode Archive Analysis Transforms CodeGen \ +PARALLEL_DIRS := IR IRReader AsmParser Bitcode Archive Analysis Transforms CodeGen \ Target ExecutionEngine Linker MC Object Option Wrap DebugInfo ifeq ($(NACL_SANDBOX),1) diff --git a/tools/llc/CMakeLists.txt b/tools/llc/CMakeLists.txt index 1f531d07d0..da09babf46 100644 --- a/tools/llc/CMakeLists.txt +++ b/tools/llc/CMakeLists.txt @@ -1,4 +1,5 @@ -set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser naclanalysis) +set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader naclbitreader + irreader asmparser naclanalysis) add_llvm_tool(llc # This file provides wrappers to lseek(2), read(2), etc. diff --git a/tools/llc/LLVMBuild.txt b/tools/llc/LLVMBuild.txt index 2c4c17d581..ab1863a6eb 100644 --- a/tools/llc/LLVMBuild.txt +++ b/tools/llc/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = llc parent = Tools -required_libraries = AsmParser BitReader all-targets NaClAnalysis +required_libraries = AsmParser BitReader NaClBitReader IRReader all-targets NaClAnalysis diff --git a/tools/llc/Makefile b/tools/llc/Makefile index ea31fed5cd..c15af18c34 100644 --- a/tools/llc/Makefile +++ b/tools/llc/Makefile @@ -9,7 +9,8 @@ LEVEL := ../.. TOOLNAME := llc -LINK_COMPONENTS := all-targets bitreader asmparser naclanalysis nacltransforms +LINK_COMPONENTS := all-targets bitreader naclbitreader irreader \ + asmparser naclanalysis nacltransforms include $(LEVEL)/Makefile.common diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 0fcd1f3c06..592c5fbc16 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -18,12 +18,14 @@ #include "llvm/Analysis/NaCl.h" // @LOCALMOD #include "llvm/Assembly/PrintModulePass.h" #include "llvm/Support/DataStream.h" // @LOCALMOD +#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD #include "llvm/CodeGen/CommandFlags.h" #include "llvm/CodeGen/IntrinsicLowering.h" // @LOCALMOD #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Module.h" +#include "llvm/IRReader/IRReader.h" // @LOCALMOD #include "llvm/MC/SubtargetFeature.h" #include "llvm/Pass.h" #include "llvm/PassManager.h" @@ -81,6 +83,18 @@ EnableTimeIRParsing("time-ir-parsing", cl::location(TimeIRParsingIsEnabled), cl::desc("Measure the time IR parsing takes")); // @LOCALMOD-END +// @LOCALMOD-BEGIN +static cl::opt<NaClFileFormat> +InputFileFormat( + "bitcode-format", + cl::desc("Define format of input file:"), + cl::values( + clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), + clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), + clEnumValEnd), + cl::init(LLVMFormat)); +// @LOCALMOD-END + // General options for llc. Other pass-specific options are specified // within the corresponding llc passes, and target-specific options // and back-end code generation options are specified with the target machine. @@ -359,9 +373,24 @@ static int compileModule(char **argv, LLVMContext &Context) { #if defined(__native_client__) && defined(NACL_SRPC) if (LazyBitcode) { std::string StrError; - M.reset(getStreamedBitcodeModule( - std::string("<SRPC stream>"), - NaClBitcodeStreamer, Context, &StrError)); + switch (InputFileFormat) { + case LLVMFormat: + // TODO(kschimpf) Remove this case once we have fixed + // pnacl-finalize and the NaCl build system to only allow PNaCl + // bitcode files. + M.reset(getStreamedBitcodeModule( + std::string("<SRPC stream>"), + NaClBitcodeStreamer, Context, &StrError)); + break; + case PNaClFormat: + M.reset(getNaClStreamedBitcodeModule( + std::string("<SRPC stream>"), + NaClBitcodeStreamer, Context, &StrError)); + break; + default: + StrErr = "Don't understand specified bitcode format"; + break; + } if (!StrError.empty()) { Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError); } @@ -375,7 +404,7 @@ static int compileModule(char **argv, LLVMContext &Context) { // @LOCALMOD: timing is temporary, until it gets properly added upstream NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, TimeIRParsingIsEnabled); - M.reset(ParseIRFile(InputFilename, Err, Context)); + M.reset(NaClParseIRFile(InputFilename, InputFileFormat, Err, Context)); } #endif // @LOCALMOD-END diff --git a/tools/llvm-dis/CMakeLists.txt b/tools/llvm-dis/CMakeLists.txt index 9f12ecb666..d9883a2147 100644 --- a/tools/llvm-dis/CMakeLists.txt +++ b/tools/llvm-dis/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLVM_LINK_COMPONENTS bitreader analysis) +set(LLVM_LINK_COMPONENTS bitreader naclbitreader analysis) add_llvm_tool(llvm-dis llvm-dis.cpp diff --git a/tools/llvm-dis/LLVMBuild.txt b/tools/llvm-dis/LLVMBuild.txt index 4525010c1f..cf1cbf7a40 100644 --- a/tools/llvm-dis/LLVMBuild.txt +++ b/tools/llvm-dis/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = llvm-dis parent = Tools -required_libraries = Analysis BitReader +required_libraries = Analysis BitReader NaClBitReader diff --git a/tools/llvm-dis/Makefile b/tools/llvm-dis/Makefile index aeeeed0d68..0719006a15 100644 --- a/tools/llvm-dis/Makefile +++ b/tools/llvm-dis/Makefile @@ -9,7 +9,7 @@ LEVEL := ../.. TOOLNAME := llvm-dis -LINK_COMPONENTS := bitreader analysis +LINK_COMPONENTS := bitreader naclbitreader analysis # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS := 1 diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index 7af85d440a..d709ba9987 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -19,10 +19,12 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/Assembly/AssemblyAnnotationWriter.h" #include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD #include "llvm/DebugInfo.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/IRReader/IRReader.h" // @LOCALMOD #include "llvm/Support/CommandLine.h" #include "llvm/Support/DataStream.h" #include "llvm/Support/FormattedStream.h" @@ -56,6 +58,16 @@ ShowAnnotations("show-annotations", // (includes output format, soname, and dependencies). static cl::opt<bool> DumpMetadata("dump-metadata", cl::desc("Dump bitcode metadata")); + +static cl::opt<NaClFileFormat> +InputFileFormat( + "bitcode-format", + cl::desc("Define format of input bitcode file:"), + cl::values( + clEnumValN(LLVMFormat, "llvm", "LLVM bitcode file (default)"), + clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), + clEnumValEnd), + cl::init(LLVMFormat)); // @LOCALMOD-END namespace { @@ -140,8 +152,22 @@ int main(int argc, char **argv) { DisplayFilename = "<stdin>"; else DisplayFilename = InputFilename; - M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, - &ErrorMessage)); + + // @LOCALMOD-BEGIN + switch (InputFileFormat) { + case LLVMFormat: + M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context, + &ErrorMessage)); + break; + case PNaClFormat: + M.reset(getNaClStreamedBitcodeModule(DisplayFilename, streamer, Context, + &ErrorMessage)); + break; + default: + ErrorMessage = "Don't understand specified bitcode format"; + break; + } + // @LOCALMOD-END if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) { M.reset(); } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 490d1bc6e3..866597ec72 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -27,6 +27,7 @@ #include "llvm/DebugInfo.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Module.h" +#include "llvm/IRReader/IRReader.h" // @LOCALMOD #include "llvm/LinkAllIR.h" #include "llvm/LinkAllPasses.h" #include "llvm/MC/SubtargetFeature.h" @@ -171,18 +172,13 @@ DefaultDataLayout("default-data-layout", cl::value_desc("layout-string"), cl::init("")); // @LOCALMOD-BEGIN -enum BcFormat { - LLVMFormat, - PNaClFormat -}; - -static cl::opt<BcFormat> -BitcodeFormat( +static cl::opt<NaClFileFormat> +OutputFileFormat( "bitcode-format", cl::desc("Define format of generated bitcode file:"), cl::values( - clEnumValN(LLVMFormat, "llvm", "LLVM bitcode (default)"), - clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode"), + clEnumValN(LLVMFormat, "llvm", "LLVM bitcode file (default)"), + clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), clEnumValEnd), cl::init(LLVMFormat)); // @LOCALMOD-END @@ -902,7 +898,7 @@ int main(int argc, char **argv) { // @LOCALMOD-BEGIN // Write bitcode to the output. if (!NoOutput && !AnalyzeOnly && !OutputAssembly) { - switch (BitcodeFormat) { + switch (OutputFileFormat) { case LLVMFormat: WriteBitcodeToFile(M.get(), Out->os()); break; diff --git a/tools/pnacl-llc/CMakeLists.txt b/tools/pnacl-llc/CMakeLists.txt index 7e5cc10eb1..9e53a28aff 100644 --- a/tools/pnacl-llc/CMakeLists.txt +++ b/tools/pnacl-llc/CMakeLists.txt @@ -1,4 +1,5 @@ -set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader asmparser naclanalysis) +set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} bitreader naclbitreader + irreader asmparser naclanalysis) add_llvm_tool(pnacl-llc # This file provides wrappers to lseek(2), read(2), etc. diff --git a/tools/pnacl-llc/LLVMBuild.txt b/tools/pnacl-llc/LLVMBuild.txt index 934bed061a..8d441f5a70 100644 --- a/tools/pnacl-llc/LLVMBuild.txt +++ b/tools/pnacl-llc/LLVMBuild.txt @@ -19,4 +19,4 @@ type = Tool name = pnacl-llc parent = Tools -required_libraries = AsmParser BitReader all-targets NaClAnalysis +required_libraries = AsmParser BitReader NaClBitReader IRReader all-targets NaClAnalysis diff --git a/tools/pnacl-llc/Makefile b/tools/pnacl-llc/Makefile index b28c6d7417..bf4a0e8be8 100644 --- a/tools/pnacl-llc/Makefile +++ b/tools/pnacl-llc/Makefile @@ -9,7 +9,8 @@ LEVEL := ../.. TOOLNAME := pnacl-llc -LINK_COMPONENTS := all-targets bitreader asmparser naclanalysis nacltransforms +LINK_COMPONENTS := all-targets bitreader naclbitreader irreader \ + asmparser naclanalysis nacltransforms include $(LEVEL)/Makefile.common diff --git a/tools/pnacl-llc/pnacl-llc.cpp b/tools/pnacl-llc/pnacl-llc.cpp index 060c1b6c94..5f2a5ce0b8 100644 --- a/tools/pnacl-llc/pnacl-llc.cpp +++ b/tools/pnacl-llc/pnacl-llc.cpp @@ -15,12 +15,14 @@ #include "llvm/Analysis/NaCl.h" #include "llvm/Assembly/PrintModulePass.h" #include "llvm/Support/DataStream.h" +#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" // @LOCALMOD #include "llvm/CodeGen/CommandFlags.h" #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IRReader/IRReader.h" // @LOCALMOD #include "llvm/MC/SubtargetFeature.h" #include "llvm/Pass.h" #include "llvm/PassManager.h" @@ -71,6 +73,18 @@ EnableTimeIRParsing("time-ir-parsing", cl::location(TimeIRParsingIsEnabled), cl::desc("Measure the time IR parsing takes")); // @LOCALMOD-END +// @LOCALMOD-BEGIN +cl::opt<NaClFileFormat> +InputFileFormat( + "bitcode-format", + cl::desc("Define format of input file:"), + cl::values( + clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"), + clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), + clEnumValEnd), + cl::init(LLVMFormat)); +// @LOCALMOD-END + // General options for llc. Other pass-specific options are specified // within the corresponding llc passes, and target-specific options // and back-end code generation options are specified with the target machine. @@ -293,9 +307,24 @@ static int compileModule(char **argv, LLVMContext &Context) { #if defined(__native_client__) && defined(NACL_SRPC) if (LazyBitcode) { std::string StrError; - M.reset(getStreamedBitcodeModule( - std::string("<SRPC stream>"), - NaClBitcodeStreamer, Context, &StrError)); + switch (InputFileFormat) { + case LLVMFormat: + // TODO(kschimpf) Remove this case once we have fixed + // pnacl-finalize and the NaCl build system to only allow PNaCl + // bitcode files. + M.reset(getStreamedBitcodeModule( + std::string("<SRPC stream>"), + NaClBitcodeStreamer, Context, &StrError)); + break; + case PNaClFormat: + M.reset(getNaClStreamedBitcodeModule( + std::string("<SRPC stream>"), + NaClBitcodeStreamer, Context, &StrError)); + break; + default: + StrErr = "Don't understand specified bitcode format"; + break; + } if (!StrError.empty()) { Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError); } @@ -309,7 +338,7 @@ static int compileModule(char **argv, LLVMContext &Context) { // @LOCALMOD: timing is temporary, until it gets properly added upstream NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, TimeIRParsingIsEnabled); - M.reset(ParseIRFile(InputFilename, Err, Context)); + M.reset(NaClParseIRFile(InputFilename, InputFileFormat, Err, Context)); } #endif // @LOCALMOD-END |