Path: blob/main/contrib/llvm-project/llvm/lib/TableGen/Parser.cpp
35233 views
//===- Parser.cpp - Top-Level TableGen Parser implementation --------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/TableGen/Parser.h"9#include "TGParser.h"10#include "llvm/Support/MemoryBuffer.h"11#include "llvm/TableGen/Record.h"1213using namespace llvm;1415bool llvm::TableGenParseFile(SourceMgr &InputSrcMgr, RecordKeeper &Records) {16// Initialize the global TableGen source manager by temporarily taking control17// of the input buffer in `SrcMgr`. This is kind of a hack, but allows for18// preserving TableGen's current awkward diagnostic behavior. If we can remove19// this reliance, we could drop all of this.20SrcMgr = SourceMgr();21SrcMgr.takeSourceBuffersFrom(InputSrcMgr);22SrcMgr.setIncludeDirs(InputSrcMgr.getIncludeDirs());23SrcMgr.setDiagHandler(InputSrcMgr.getDiagHandler(),24InputSrcMgr.getDiagContext());2526// Setup the record keeper and try to parse the file.27auto *MainFileBuffer = SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID());28Records.saveInputFilename(MainFileBuffer->getBufferIdentifier().str());2930TGParser Parser(SrcMgr, /*Macros=*/std::nullopt, Records,31/*NoWarnOnUnusedTemplateArgs=*/false,32/*TrackReferenceLocs=*/true);33bool ParseResult = Parser.ParseFile();3435// After parsing, reclaim the source manager buffers from TableGen's global36// manager.37InputSrcMgr.takeSourceBuffersFrom(SrcMgr);38SrcMgr = SourceMgr();39return ParseResult;40}414243