cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
104 lines
4.4 KiB
C++
104 lines
4.4 KiB
C++
//===- Parser.cpp - MLIR Unified Parser Interface -------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the parser for the MLIR textual form.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Parser/Parser.h"
|
|
#include "mlir/AsmParser/AsmParser.h"
|
|
#include "mlir/Bytecode/BytecodeReader.h"
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
using namespace mlir;
|
|
|
|
LogicalResult mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
|
|
Block *block, const ParserConfig &config,
|
|
LocationAttr *sourceFileLoc) {
|
|
const auto *sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID());
|
|
if (sourceFileLoc) {
|
|
*sourceFileLoc = FileLineColLoc::get(config.getContext(),
|
|
sourceBuf->getBufferIdentifier(),
|
|
/*line=*/0, /*column=*/0);
|
|
}
|
|
if (isBytecode(*sourceBuf))
|
|
return readBytecodeFile(*sourceBuf, block, config);
|
|
return parseAsmSourceFile(sourceMgr, block, config);
|
|
}
|
|
LogicalResult
|
|
mlir::parseSourceFile(const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
|
|
Block *block, const ParserConfig &config,
|
|
LocationAttr *sourceFileLoc) {
|
|
const auto *sourceBuf =
|
|
sourceMgr->getMemoryBuffer(sourceMgr->getMainFileID());
|
|
if (sourceFileLoc) {
|
|
*sourceFileLoc = FileLineColLoc::get(config.getContext(),
|
|
sourceBuf->getBufferIdentifier(),
|
|
/*line=*/0, /*column=*/0);
|
|
}
|
|
if (isBytecode(*sourceBuf))
|
|
return readBytecodeFile(sourceMgr, block, config);
|
|
return parseAsmSourceFile(*sourceMgr, block, config);
|
|
}
|
|
|
|
LogicalResult mlir::parseSourceFile(llvm::StringRef filename, Block *block,
|
|
const ParserConfig &config,
|
|
LocationAttr *sourceFileLoc) {
|
|
auto sourceMgr = std::make_shared<llvm::SourceMgr>();
|
|
return parseSourceFile(filename, sourceMgr, block, config, sourceFileLoc);
|
|
}
|
|
|
|
static LogicalResult loadSourceFileBuffer(llvm::StringRef filename,
|
|
llvm::SourceMgr &sourceMgr,
|
|
MLIRContext *ctx) {
|
|
if (sourceMgr.getNumBuffers() != 0) {
|
|
// TODO: Extend to support multiple buffers.
|
|
return emitError(mlir::UnknownLoc::get(ctx),
|
|
"only main buffer parsed at the moment");
|
|
}
|
|
auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename);
|
|
if (fileOrErr.getError())
|
|
return emitError(mlir::UnknownLoc::get(ctx),
|
|
"could not open input file " + filename);
|
|
|
|
// Load the MLIR source file.
|
|
sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
|
|
return success();
|
|
}
|
|
|
|
LogicalResult mlir::parseSourceFile(llvm::StringRef filename,
|
|
llvm::SourceMgr &sourceMgr, Block *block,
|
|
const ParserConfig &config,
|
|
LocationAttr *sourceFileLoc) {
|
|
if (failed(loadSourceFileBuffer(filename, sourceMgr, config.getContext())))
|
|
return failure();
|
|
return parseSourceFile(sourceMgr, block, config, sourceFileLoc);
|
|
}
|
|
LogicalResult mlir::parseSourceFile(
|
|
llvm::StringRef filename, const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
|
|
Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc) {
|
|
if (failed(loadSourceFileBuffer(filename, *sourceMgr, config.getContext())))
|
|
return failure();
|
|
return parseSourceFile(sourceMgr, block, config, sourceFileLoc);
|
|
}
|
|
|
|
LogicalResult mlir::parseSourceString(llvm::StringRef sourceStr, Block *block,
|
|
const ParserConfig &config,
|
|
StringRef sourceName,
|
|
LocationAttr *sourceFileLoc) {
|
|
auto memBuffer =
|
|
llvm::MemoryBuffer::getMemBuffer(sourceStr, sourceName,
|
|
/*RequiresNullTerminator=*/false);
|
|
if (!memBuffer)
|
|
return failure();
|
|
|
|
llvm::SourceMgr sourceMgr;
|
|
sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc());
|
|
return parseSourceFile(sourceMgr, block, config, sourceFileLoc);
|
|
}
|