[PATCH] D14273: Add a method to the BitcodeReader to parse only the identification block
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 8 15:06:12 PST 2015
> On 2015-Nov-02, at 18:10, Mehdi AMINI <mehdi.amini at apple.com> wrote:
>
> joker.eph created this revision.
> joker.eph added reviewers: dexonsmith, rafael.
> joker.eph added a subscriber: llvm-commits.
>
> Mimic parseTriple(); and exposes it to LTOModule.cpp
>
> http://reviews.llvm.org/D14273
>
> Files:
> include/llvm/Bitcode/ReaderWriter.h
> include/llvm/LTO/LTOModule.h
> lib/Bitcode/Reader/BitcodeReader.cpp
> lib/LTO/LTOModule.cpp
>
> <D14273.39022.patch>
Aside from some weird whitespace (noted below), LGTM.
> Index: lib/Bitcode/Reader/BitcodeReader.cpp
> ===================================================================
> --- lib/Bitcode/Reader/BitcodeReader.cpp
> +++ lib/Bitcode/Reader/BitcodeReader.cpp
> @@ -5805,6 +5843,19 @@
> return Triple.get();
> }
>
> +std::string
> +llvm::getBitcodeProducerString(MemoryBufferRef Buffer, LLVMContext &Context,
> + DiagnosticHandlerFunction DiagnosticHandler) {
> + std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
> + BitcodeReader R(Buf.release(), Context, DiagnosticHandler);
> + ErrorOr<std::string> ProducerString = R.parseIdentificationBlock();
> + if (ProducerString.getError())
> + return "";
> + return ProducerString.get();
> +}
> +
> +
> +
Seems like two too many blank lines here.
> // Parse the specified bitcode buffer, returning the function info index.
> // If IsLazy is false, parse the entire function summary into
> // the index. Otherwise skip the function summary section, and only create
> Index: include/llvm/LTO/LTOModule.h
> ===================================================================
> --- include/llvm/LTO/LTOModule.h
> +++ include/llvm/LTO/LTOModule.h
> @@ -74,6 +74,12 @@
> static bool isBitcodeForTarget(MemoryBuffer *memBuffer,
> StringRef triplePrefix);
>
> + /// Returns a string representing the producer identification stored in the
> + /// bitcode, or "" if the bitcode does not contains any.
> + ///
> + static std::string getProducerString(MemoryBuffer *Buffer);
> +
> +
Seems like one too many blank lines here.
> /// Create a MemoryBuffer from a memory range with an optional name.
> static std::unique_ptr<MemoryBuffer>
> makeBuffer(const void *mem, size_t length, StringRef name = "");
> Index: include/llvm/Bitcode/ReaderWriter.h
> ===================================================================
> --- include/llvm/Bitcode/ReaderWriter.h
> +++ include/llvm/Bitcode/ReaderWriter.h
> @@ -54,6 +54,14 @@
> getBitcodeTargetTriple(MemoryBufferRef Buffer, LLVMContext &Context,
> DiagnosticHandlerFunction DiagnosticHandler = nullptr);
>
> +
> + /// Read the header of the specified bitcode buffer and extract just the
> + /// producer string information. If successful, this returns a string. On
> + /// error, this returns "".
> + std::string
> + getBitcodeProducerString(MemoryBufferRef Buffer, LLVMContext &Context,
> + DiagnosticHandlerFunction DiagnosticHandler = nullptr);
Whitespace is strange. clang-format?
> +
> /// Read the specified bitcode file, returning the module.
> ErrorOr<std::unique_ptr<Module>>
> parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
>
More information about the llvm-commits
mailing list