LLVM 22.0.0git
Parser.cpp
Go to the documentation of this file.
1//===- Parser.cpp - Top-Level TableGen Parser implementation --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "TGParser.h"
14
15using namespace llvm;
16
17bool llvm::TableGenParseFile(SourceMgr &InputSrcMgr, RecordKeeper &Records) {
18 // Initialize the global TableGen source manager by temporarily taking control
19 // of the input buffer in `SrcMgr`. This is kind of a hack, but allows for
20 // preserving TableGen's current awkward diagnostic behavior. If we can remove
21 // this reliance, we could drop all of this.
22 SrcMgr = SourceMgr();
23 SrcMgr.takeSourceBuffersFrom(InputSrcMgr);
24 SrcMgr.setIncludeDirs(InputSrcMgr.getIncludeDirs());
25 SrcMgr.setVirtualFileSystem(InputSrcMgr.getVirtualFileSystem());
26 SrcMgr.setDiagHandler(InputSrcMgr.getDiagHandler(),
27 InputSrcMgr.getDiagContext());
28
29 // Setup the record keeper and try to parse the file.
30 auto *MainFileBuffer = SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID());
31 Records.saveInputFilename(MainFileBuffer->getBufferIdentifier().str());
32
33 TGParser Parser(SrcMgr, /*Macros=*/{}, Records,
34 /*NoWarnOnUnusedTemplateArgs=*/false,
35 /*TrackReferenceLocs=*/true);
36 bool ParseResult = Parser.ParseFile();
37
38 // After parsing, reclaim the source manager buffers from TableGen's global
39 // manager.
40 InputSrcMgr.takeSourceBuffersFrom(SrcMgr);
41 SrcMgr = SourceMgr();
42 return ParseResult;
43}
Defines the virtual file system interface vfs::FileSystem.
This class represents success/failure for parsing-like operations that find it important to chain tog...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
void * getDiagContext() const
Definition SourceMgr.h:134
ArrayRef< std::string > getIncludeDirs() const
Return the include directories of this source manager.
Definition SourceMgr.h:120
DiagHandlerTy getDiagHandler() const
Definition SourceMgr.h:133
IntrusiveRefCntPtr< vfs::FileSystem > getVirtualFileSystem() const
Definition SourceMgr.cpp:50
void takeSourceBuffersFrom(SourceMgr &SrcMgr, SMLoc MainBufferIncludeLoc=SMLoc())
Takes the source buffers from the given source manager and append them to the current manager.
Definition SourceMgr.h:173
This is an optimization pass for GlobalISel generic memory operations.
SourceMgr SrcMgr
Definition Error.cpp:24
bool TableGenParseFile(SourceMgr &InputSrcMgr, RecordKeeper &Records)
Parse the TableGen file defined within the main buffer of the given SourceMgr.
Definition Parser.cpp:17