1// Copyright (C) 2018 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPLUGIN_P_H
5#define QPLUGIN_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the QLibrary class. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qglobal_p.h>
19
20QT_BEGIN_NAMESPACE
21
22enum class QtPluginMetaDataKeys {
23 QtVersion,
24 Requirements,
25 IID,
26 ClassName,
27 MetaData,
28 URI,
29 IsDebug,
30};
31
32// F(IntKey, StringKey, Description)
33// Keep this list sorted in the order moc should output.
34#define QT_PLUGIN_FOREACH_METADATA(F) \
35 F(QtPluginMetaDataKeys::IID, "IID", "Plugin's Interface ID") \
36 F(QtPluginMetaDataKeys::ClassName, "className", "Plugin class name") \
37 F(QtPluginMetaDataKeys::MetaData, "MetaData", "Other meta data") \
38 F(QtPluginMetaDataKeys::URI, "URI", "Plugin URI") \
39 /* not output by moc in CBOR */ \
40 F(QtPluginMetaDataKeys::QtVersion, "version", "Qt version") \
41 F(QtPluginMetaDataKeys::Requirements, "archlevel", "Architectural level") \
42 F(QtPluginMetaDataKeys::IsDebug, "debug", "Debug-mode plugin") \
43 /**/
44
45namespace {
46struct DecodedArchRequirements
47{
48 quint8 level;
49 bool isDebug;
50 friend constexpr bool operator==(DecodedArchRequirements r1, DecodedArchRequirements r2)
51 {
52 return r1.level == r2.level && r1.isDebug == r2.isDebug;
53 }
54};
55
56static constexpr DecodedArchRequirements decodeVersion0ArchRequirements(quint8 value)
57{
58 // see qPluginArchRequirements() and QPluginMetaDataV2::archRequirements()
59 DecodedArchRequirements r = {};
60#ifdef Q_PROCESSOR_X86
61 if (value & 4)
62 r.level = 4; // AVX512F -> x86-64-v4
63 else if (value & 2)
64 r.level = 3; // AVX2 -> x86-64-v3
65#endif
66 if (value & 1)
67 r.isDebug = true;
68 return r;
69}
70// self checks
71static_assert(decodeVersion0ArchRequirements(value: 0) == DecodedArchRequirements{ .level: 0, .isDebug: false });
72static_assert(decodeVersion0ArchRequirements(value: 1) == DecodedArchRequirements{ .level: 0, .isDebug: true });
73#ifdef Q_PROCESSOR_X86
74static_assert(decodeVersion0ArchRequirements(value: 2) == DecodedArchRequirements{ .level: 3, .isDebug: false });
75static_assert(decodeVersion0ArchRequirements(value: 3) == DecodedArchRequirements{ .level: 3, .isDebug: true });
76static_assert(decodeVersion0ArchRequirements(value: 4) == DecodedArchRequirements{ .level: 4, .isDebug: false });
77static_assert(decodeVersion0ArchRequirements(value: 5) == DecodedArchRequirements{ .level: 4, .isDebug: true });
78#endif
79
80static constexpr DecodedArchRequirements decodeVersion1ArchRequirements(quint8 value)
81{
82 return { .level: quint8(value & 0x7f), .isDebug: bool(value & 0x80) };
83}
84// self checks
85static_assert(decodeVersion1ArchRequirements(value: 0) == DecodedArchRequirements{ .level: 0, .isDebug: false });
86static_assert(decodeVersion1ArchRequirements(value: 0x80) == DecodedArchRequirements{ .level: 0, .isDebug: true });
87#ifdef Q_PROCESSOR_X86
88static_assert(decodeVersion1ArchRequirements(value: 1) == DecodedArchRequirements{ .level: 1, .isDebug: false });
89static_assert(decodeVersion1ArchRequirements(value: 3) == DecodedArchRequirements{ .level: 3, .isDebug: false});
90static_assert(decodeVersion1ArchRequirements(value: 4) == DecodedArchRequirements{ .level: 4, .isDebug: false });
91static_assert(decodeVersion1ArchRequirements(value: 0x82) == DecodedArchRequirements{ .level: 2, .isDebug: true });
92static_assert(decodeVersion1ArchRequirements(value: 0x84) == DecodedArchRequirements{ .level: 4, .isDebug: true });
93#endif
94} // unnamed namespace
95
96QT_END_NAMESPACE
97
98#endif // QPLUGIN_P_H
99

source code of qtbase/src/corelib/plugin/qplugin_p.h