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 /lib | |
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
Diffstat (limited to 'lib')
-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 |
7 files changed, 114 insertions, 3 deletions
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) |