LCOV - code coverage report
Current view: top level - lib/AsmParser - Parser.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 37 39 94.9 %
Date: 2018-02-23 15:42:53 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Parser.cpp - Main dispatch module for the Parser library -----------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This library implements the functionality defined in llvm/AsmParser/Parser.h
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/AsmParser/Parser.h"
      15             : #include "LLParser.h"
      16             : #include "llvm/ADT/STLExtras.h"
      17             : #include "llvm/IR/Module.h"
      18             : #include "llvm/Support/MemoryBuffer.h"
      19             : #include "llvm/Support/SourceMgr.h"
      20             : #include "llvm/Support/raw_ostream.h"
      21             : #include <cstring>
      22             : #include <system_error>
      23             : using namespace llvm;
      24             : 
      25       30587 : bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
      26             :                              SlotMapping *Slots, bool UpgradeDebugInfo,
      27             :                              StringRef DataLayoutString) {
      28       30560 :   SourceMgr SM;
      29       30587 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
      30       91761 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      31             : 
      32       61147 :   return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo,
      33             :                   DataLayoutString)
      34       61147 :       .Run();
      35             : }
      36             : 
      37             : std::unique_ptr<Module>
      38       30587 : llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context,
      39             :                     SlotMapping *Slots, bool UpgradeDebugInfo,
      40             :                     StringRef DataLayoutString) {
      41             :   std::unique_ptr<Module> M =
      42       61147 :       make_unique<Module>(F.getBufferIdentifier(), Context);
      43             : 
      44       61174 :   if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo, DataLayoutString))
      45             :     return nullptr;
      46             : 
      47             :   return M;
      48             : }
      49             : 
      50             : std::unique_ptr<Module>
      51        1901 : llvm::parseAssemblyFile(StringRef Filename, SMDiagnostic &Err,
      52             :                         LLVMContext &Context, SlotMapping *Slots,
      53             :                         bool UpgradeDebugInfo, StringRef DataLayoutString) {
      54             :   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
      55        1901 :       MemoryBuffer::getFileOrSTDIN(Filename);
      56        1901 :   if (std::error_code EC = FileOrErr.getError()) {
      57           0 :     Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
      58           0 :                        "Could not open input file: " + EC.message());
      59             :     return nullptr;
      60             :   }
      61             : 
      62             :   return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots,
      63        3802 :                        UpgradeDebugInfo, DataLayoutString);
      64             : }
      65             : 
      66             : std::unique_ptr<Module>
      67         176 : llvm::parseAssemblyString(StringRef AsmString, SMDiagnostic &Err,
      68             :                           LLVMContext &Context, SlotMapping *Slots,
      69             :                           bool UpgradeDebugInfo, StringRef DataLayoutString) {
      70             :   MemoryBufferRef F(AsmString, "<string>");
      71             :   return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo,
      72         176 :                        DataLayoutString);
      73             : }
      74             : 
      75         510 : Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,
      76             :                                    const Module &M, const SlotMapping *Slots) {
      77         510 :   SourceMgr SM;
      78         510 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
      79        1530 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      80             :   Constant *C;
      81        1020 :   if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
      82         510 :           .parseStandaloneConstantValue(C, Slots))
      83             :     return nullptr;
      84         504 :   return C;
      85             : }
      86             : 
      87          11 : Type *llvm::parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
      88             :                       const SlotMapping *Slots) {
      89             :   unsigned Read;
      90          11 :   Type *Ty = parseTypeAtBeginning(Asm, Read, Err, M, Slots);
      91          11 :   if (!Ty)
      92             :     return nullptr;
      93          22 :   if (Read != Asm.size()) {
      94           1 :     SourceMgr SM;
      95           1 :     std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
      96           3 :     SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      97           1 :     Err = SM.GetMessage(SMLoc::getFromPointer(Asm.begin() + Read),
      98             :                         SourceMgr::DK_Error, "expected end of string");
      99             :     return nullptr;
     100             :   }
     101             :   return Ty;
     102             : }
     103          22 : Type *llvm::parseTypeAtBeginning(StringRef Asm, unsigned &Read,
     104             :                                  SMDiagnostic &Err, const Module &M,
     105             :                                  const SlotMapping *Slots) {
     106          22 :   SourceMgr SM;
     107          22 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
     108          66 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
     109             :   Type *Ty;
     110          44 :   if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
     111          22 :           .parseTypeAtBeginning(Ty, Read, Slots))
     112             :     return nullptr;
     113          22 :   return Ty;
     114             : }

Generated by: LCOV version 1.13