Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/AsmParser/Parser.cpp
Line
Count
Source (jump to first uncovered line)
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
bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err,
26
27.0k
                             SlotMapping *Slots) {
27
27.0k
  SourceMgr SM;
28
27.0k
  std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
29
27.0k
  SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
30
27.0k
31
27.0k
  return LLParser(F.getBuffer(), SM, Err, &M, Slots).Run();
32
27.0k
}
33
34
std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F,
35
                                            SMDiagnostic &Err,
36
                                            LLVMContext &Context,
37
27.0k
                                            SlotMapping *Slots) {
38
27.0k
  std::unique_ptr<Module> M =
39
27.0k
      make_unique<Module>(F.getBufferIdentifier(), Context);
40
27.0k
41
27.0k
  if (parseAssemblyInto(F, *M, Err, Slots))
42
192
    return nullptr;
43
26.8k
44
26.8k
  return M;
45
26.8k
}
46
47
std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename,
48
                                                SMDiagnostic &Err,
49
                                                LLVMContext &Context,
50
1.79k
                                                SlotMapping *Slots) {
51
1.79k
  ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
52
1.79k
      MemoryBuffer::getFileOrSTDIN(Filename);
53
1.79k
  if (std::error_code 
EC1.79k
= FileOrErr.getError()) {
54
0
    Err = SMDiagnostic(Filename, SourceMgr::DK_Error,
55
0
                       "Could not open input file: " + EC.message());
56
0
    return nullptr;
57
0
  }
58
1.79k
59
1.79k
  return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);
60
1.79k
}
61
62
std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString,
63
                                                  SMDiagnostic &Err,
64
                                                  LLVMContext &Context,
65
137
                                                  SlotMapping *Slots) {
66
137
  MemoryBufferRef F(AsmString, "<string>");
67
137
  return parseAssembly(F, Err, Context, Slots);
68
137
}
69
70
Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err,
71
383
                                   const Module &M, const SlotMapping *Slots) {
72
383
  SourceMgr SM;
73
383
  std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
74
383
  SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
75
383
  Constant *C;
76
383
  if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
77
383
          .parseStandaloneConstantValue(C, Slots))
78
6
    return nullptr;
79
377
  return C;
80
377
}
81
82
Type *llvm::parseType(StringRef Asm, SMDiagnostic &Err, const Module &M,
83
11
                      const SlotMapping *Slots) {
84
11
  unsigned Read;
85
11
  Type *Ty = parseTypeAtBeginning(Asm, Read, Err, M, Slots);
86
11
  if (!Ty)
87
0
    return nullptr;
88
11
  
if (11
Read != Asm.size()11
) {
89
1
    SourceMgr SM;
90
1
    std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
91
1
    SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
92
1
    Err = SM.GetMessage(SMLoc::getFromPointer(Asm.begin() + Read),
93
1
                        SourceMgr::DK_Error, "expected end of string");
94
1
    return nullptr;
95
1
  }
96
10
  return Ty;
97
10
}
98
Type *llvm::parseTypeAtBeginning(StringRef Asm, unsigned &Read,
99
                                 SMDiagnostic &Err, const Module &M,
100
22
                                 const SlotMapping *Slots) {
101
22
  SourceMgr SM;
102
22
  std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Asm);
103
22
  SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
104
22
  Type *Ty;
105
22
  if (LLParser(Asm, SM, Err, const_cast<Module *>(&M))
106
22
          .parseTypeAtBeginning(Ty, Read, Slots))
107
0
    return nullptr;
108
22
  return Ty;
109
22
}