LLVM: lib/AsmParser/Parser.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

20#include <system_error>

21

22using namespace llvm;

23

32

33 std::optional OptContext;

34 return LLParser(F.getBuffer(), SM, Err, M, Index,

35 M ? M->getContext() : OptContext.emplace(), Slots,

36 ParserContext)

38}

39

45 return ::parseAssemblyInto(F, M, Index, Err, Slots,

46 true, DataLayoutCallback,

47 ParserContext);

48}

49

50std::unique_ptr

54 std::unique_ptr M =

55 std::make_unique(F.getBufferIdentifier(), Context);

56

57 if (parseAssemblyInto(F, M.get(), nullptr, Err, Slots, DataLayoutCallback,

58 ParserContext))

59 return nullptr;

60

61 return M;

62}

63

70 if (std::error_code EC = FileOrErr.getError()) {

72 "Could not open input file: " + EC.message());

73 return nullptr;

74 }

75

76 return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots);

77}

78

84 std::unique_ptr M =

85 std::make_unique(F.getBufferIdentifier(), Context);

86 std::unique_ptr Index =

87 std::make_unique(true);

88

90 DataLayoutCallback))

91 return {nullptr, nullptr};

92

93 return {std::move(M), std::move(Index)};

94}

95

100 return ::parseAssemblyWithIndex(

101 F, Err, Context, Slots,

102 true,

104}

105

113 if (std::error_code EC = FileOrErr.getError()) {

115 "Could not open input file: " + EC.message());

116 return {nullptr, nullptr};

117 }

118

121 DataLayoutCallback);

122}

123

128 return ::parseAssemblyFileWithIndex(Filename, Err, Context, Slots,

129 true,

130 DataLayoutCallback);

131}

132

136 return ::parseAssemblyFileWithIndex(Filename, Err, Context, Slots,

137 false,

138 DataLayoutCallback);

139}

140

141std::unique_ptr

147 F, Err, Context, Slots, [](StringRef, StringRef) { return std::nullopt; },

148 ParserContext);

149}

150

157

158

159

161 return LLParser(F.getBuffer(), SM, Err, nullptr, &Index, unusedContext)

163}

164

165std::unique_ptr

167 std::unique_ptr Index =

168 std::make_unique(false);

169

171 return nullptr;

172

173 return Index;

174}

175

176std::unique_ptr

180 if (std::error_code EC = FileOrErr.getError()) {

182 "Could not open input file: " + EC.message());

183 return nullptr;

184 }

185

187}

188

189std::unique_ptr

194

203 return nullptr;

204 return C;

205}

206

209 unsigned Read;

211 if (!Ty)

212 return nullptr;

213 if (Read != Asm.size()) {

219 return nullptr;

220 }

221 return Ty;

222}

232 return nullptr;

233 return Ty;

234}

235

237 unsigned &Read,

247 return nullptr;

249}

static bool parseSummaryIndexAssemblyInto(MemoryBufferRef F, ModuleSummaryIndex &Index, SMDiagnostic &Err)

Definition Parser.cpp:151

Module.h This file contains the declarations for the Module class.

ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...

Registry of file location information for LLVM IR constructs.

This is an important base class in LLVM.

Represents either an error or a value T.

std::error_code getError() const

bool parseDIExpressionBodyAtBeginning(MDNode *&Result, unsigned &Read, const SlotMapping *Slots)

bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)

bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)

bool Run(bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})

Run: module ::= toplevelentity*.

This is an important class for using LLVM in a threaded context.

static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)

Open the specified memory range as a MemoryBuffer.

static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)

Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".

Class to hold module path string table and global value map, and encapsulate methods for operating on...

A Module instance is used to store all the information related to an LLVM module.

LLVMContext & getContext() const

Get the global data context.

Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...

Represents a location in source code.

static SMLoc getFromPointer(const char *Ptr)

This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.

LLVM_ABI SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const

Return an SMDiagnostic at the specified location with the specified string.

unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)

Add a new source buffer to this source manager.

StringRef - Represent a constant reference to a string, i.e.

The instances of the Type class are immutable: once they are created, they are never changed.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI std::unique_ptr< Module > parseAssemblyString(StringRef AsmString, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, AsmParserContext *ParserContext=nullptr)

The function is a secondary interface to the LLVM Assembly Parser.

Definition Parser.cpp:142

LLVM_ABI std::unique_ptr< ModuleSummaryIndex > parseSummaryIndexAssemblyString(StringRef AsmString, SMDiagnostic &Err)

The function is a secondary interface to the LLVM Assembly Parser.

Definition Parser.cpp:190

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

LLVM_ABI Type * parseTypeAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)

Parse a string Asm that starts with a type.

Definition Parser.cpp:223

LLVM_ABI std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;}, AsmParserContext *ParserContext=nullptr)

parseAssemblyFile and parseAssemblyString are wrappers around this function.

Definition Parser.cpp:51

LLVM_ABI std::unique_ptr< ModuleSummaryIndex > parseSummaryIndexAssemblyFile(StringRef Filename, SMDiagnostic &Err)

This function is a main interface to the LLVM Assembly Parser.

Definition Parser.cpp:177

LLVM_ABI DIExpression * parseDIExpressionBodyAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots)

Definition Parser.cpp:236

LLVM_ABI bool parseAssemblyInto(MemoryBufferRef F, Module *M, ModuleSummaryIndex *Index, SMDiagnostic &Err, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;}, AsmParserContext *ParserContext=nullptr)

This function is the low-level interface to the LLVM Assembly Parser.

Definition Parser.cpp:40

LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndexNoUpgradeDebugInfo(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots, DataLayoutCallbackTy DataLayoutCallback)

Only for use in llvm-as for testing; this does not produce a valid module.

Definition Parser.cpp:133

llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy

LLVM_ABI ParsedModuleAndIndex parseAssemblyWithIndex(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)

Parse LLVM Assembly including the summary index from a MemoryBuffer.

Definition Parser.cpp:96

LLVM_ABI std::unique_ptr< Module > parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)

This function is a main interface to the LLVM Assembly Parser.

Definition Parser.cpp:64

LLVM_ABI Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)

Parse a type and a constant value in the given string.

Definition Parser.cpp:195

LLVM_ABI bool UpgradeDebugInfo(Module &M)

Check the debug info version number, if it is out-dated, drop the debug info.

LLVM_ABI Type * parseType(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)

Parse a type in the given string.

Definition Parser.cpp:207

LLVM_ABI ParsedModuleAndIndex parseAssemblyFileWithIndex(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})

This function is a main interface to the LLVM Assembly Parser.

Definition Parser.cpp:125

LLVM_ABI std::unique_ptr< ModuleSummaryIndex > parseSummaryIndexAssembly(MemoryBufferRef F, SMDiagnostic &Err)

Parse LLVM Assembly for summary index from a MemoryBuffer.

Definition Parser.cpp:166

Holds the Module and ModuleSummaryIndex returned by the interfaces that parse both.

This struct contains the mappings from the slot numbers to unnamed metadata nodes,...