blob: 7332b2a7ea89169668c41c8df87e3ccd28850346 [file] [log] [blame]
Andrew Walbran16937d02019-10-22 13:54:20 +01001//===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- C++ -*-===//
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//
9/// \file
10/// This is a verifier for AMDGPU HSA metadata, which can verify both
11/// well-typed metadata and untyped metadata. When verifying in the non-strict
12/// mode, untyped metadata is coerced into the correct type if possible.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
17#define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
18
Andrew Walbran3d2c1972020-04-07 12:24:26 +010019#include "llvm/BinaryFormat/MsgPackDocument.h"
Andrew Walbran16937d02019-10-22 13:54:20 +010020
21namespace llvm {
22namespace AMDGPU {
23namespace HSAMD {
24namespace V3 {
25
26/// Verifier for AMDGPU HSA metadata.
27///
28/// Operates in two modes:
29///
30/// In strict mode, metadata must already be well-typed.
31///
32/// In non-strict mode, metadata is coerced into expected types when possible.
33class MetadataVerifier {
34 bool Strict;
35
Andrew Walbran3d2c1972020-04-07 12:24:26 +010036 bool verifyScalar(msgpack::DocNode &Node, msgpack::Type SKind,
37 function_ref<bool(msgpack::DocNode &)> verifyValue = {});
38 bool verifyInteger(msgpack::DocNode &Node);
39 bool verifyArray(msgpack::DocNode &Node,
40 function_ref<bool(msgpack::DocNode &)> verifyNode,
Andrew Walbran16937d02019-10-22 13:54:20 +010041 Optional<size_t> Size = None);
Andrew Walbran3d2c1972020-04-07 12:24:26 +010042 bool verifyEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
43 function_ref<bool(msgpack::DocNode &)> verifyNode);
Andrew Walbran16937d02019-10-22 13:54:20 +010044 bool
Andrew Walbran3d2c1972020-04-07 12:24:26 +010045 verifyScalarEntry(msgpack::MapDocNode &MapNode, StringRef Key, bool Required,
46 msgpack::Type SKind,
47 function_ref<bool(msgpack::DocNode &)> verifyValue = {});
48 bool verifyIntegerEntry(msgpack::MapDocNode &MapNode, StringRef Key,
Andrew Walbran16937d02019-10-22 13:54:20 +010049 bool Required);
Andrew Walbran3d2c1972020-04-07 12:24:26 +010050 bool verifyKernelArgs(msgpack::DocNode &Node);
51 bool verifyKernel(msgpack::DocNode &Node);
Andrew Walbran16937d02019-10-22 13:54:20 +010052
53public:
54 /// Construct a MetadataVerifier, specifying whether it will operate in \p
55 /// Strict mode.
56 MetadataVerifier(bool Strict) : Strict(Strict) {}
57
58 /// Verify given HSA metadata.
59 ///
60 /// \returns True when successful, false when metadata is invalid.
Andrew Walbran3d2c1972020-04-07 12:24:26 +010061 bool verify(msgpack::DocNode &HSAMetadataRoot);
Andrew Walbran16937d02019-10-22 13:54:20 +010062};
63
64} // end namespace V3
65} // end namespace HSAMD
66} // end namespace AMDGPU
67} // end namespace llvm
68
69#endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H