LCOV - code coverage report
Current view: top level - lib/AsmParser - Parser.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 38 41 92.7 %
Date: 2017-09-14 15:23:50 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       28227 : bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
      26             :                              SlotMapping *Slots) {
      27       56428 :   SourceMgr SM;
      28       56428 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
      29       84681 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      30             : 
      31       56428 :   return LLParser(F.getBuffer(), SM, Err, &M, Slots).Run();
      32             : }
      33             : 
      34       28227 : std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
      35             :                                             SMDiagnostic &Err,
      36             :                                             LLVMContext &Context,
      37             :                                             SlotMapping *Slots) {
      38             :   std::unique_ptr<Module> M =
      39       56428 :       make_unique<Module>(F.getBufferIdentifier(), Context);
      40             : 
      41       28227 :   if (parseAssemblyInto(F, *M, Err, Slots))
      42             :     return nullptr;
      43             : 
      44             :   return M;
      45             : }
      46             : 
      47        1856 : std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
      48             :                                                 SMDiagnostic &Err,
      49             :                                                 LLVMContext &Context,
      50             :                                                 SlotMapping *Slots) {
      51             :   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
      52        3687 :       MemoryBuffer::getFileOrSTDIN(Filename);
      53        1856 :   if (std::error_code EC = FileOrErr.getError()) {
      54           0 :     Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
      55           0 :                        "Could not open input file: " + EC.message());
      56           0 :     return nullptr;
      57             :   }
      58             : 
      59        3712 :   return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);
      60             : }
      61             : 
      62         136 : std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString,
      63             :                                                   SMDiagnostic &Err,
      64             :                                                   LLVMContext &Context,
      65             :                                                   SlotMapping *Slots) {
      66         272 :   MemoryBufferRef F(AsmString, "<string>");
      67         136 :   return parseAssembly(F, Err, Context, Slots);
      68             : }
      69             : 
      70         360 : Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,
      71             :                                    const Module &M, const SlotMapping *Slots) {
      72         720 :   SourceMgr SM;
      73         720 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
      74        1080 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      75             :   Constant *C;
      76         720 :   if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
      77         360 :           .parseStandaloneConstantValue(C, Slots))
      78             :     return nullptr;
      79         354 :   return C;
      80             : }
      81             : 
      82          11 : Type *llvm::parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
      83             :                       const SlotMapping *Slots) {
      84             :   unsigned Read;
      85          11 :   Type *Ty = parseTypeAtBeginning(Asm, Read, Err, M, Slots);
      86          11 :   if (!Ty)
      87             :     return nullptr;
      88          22 :   if (Read != Asm.size()) {
      89           2 :     SourceMgr SM;
      90           2 :     std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
      91           3 :     SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
      92           4 :     Err = SM.GetMessage(SMLoc::getFromPointer(Asm.begin() + Read),
      93             :                         SourceMgr::DK_Error, "expected end of string");
      94           1 :     return nullptr;
      95             :   }
      96             :   return Ty;
      97             : }
      98          22 : Type *llvm::parseTypeAtBeginning(StringRef Asm, unsigned &Read,
      99             :                                  SMDiagnostic &Err, const Module &M,
     100             :                                  const SlotMapping *Slots) {
     101          44 :   SourceMgr SM;
     102          44 :   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
     103          66 :   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
     104             :   Type *Ty;
     105          44 :   if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
     106          22 :           .parseTypeAtBeginning(Ty, Read, Slots))
     107             :     return nullptr;
     108          22 :   return Ty;
     109             : }

Generated by: LCOV version 1.13