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 | |
20 | QT_BEGIN_NAMESPACE |
21 | |
22 | enum 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 | |
45 | namespace { |
46 | struct 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 | |
56 | static 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 |
71 | static_assert(decodeVersion0ArchRequirements(value: 0) == DecodedArchRequirements{ .level: 0, .isDebug: false }); |
72 | static_assert(decodeVersion0ArchRequirements(value: 1) == DecodedArchRequirements{ .level: 0, .isDebug: true }); |
73 | #ifdef Q_PROCESSOR_X86 |
74 | static_assert(decodeVersion0ArchRequirements(value: 2) == DecodedArchRequirements{ .level: 3, .isDebug: false }); |
75 | static_assert(decodeVersion0ArchRequirements(value: 3) == DecodedArchRequirements{ .level: 3, .isDebug: true }); |
76 | static_assert(decodeVersion0ArchRequirements(value: 4) == DecodedArchRequirements{ .level: 4, .isDebug: false }); |
77 | static_assert(decodeVersion0ArchRequirements(value: 5) == DecodedArchRequirements{ .level: 4, .isDebug: true }); |
78 | #endif |
79 | |
80 | static constexpr DecodedArchRequirements decodeVersion1ArchRequirements(quint8 value) |
81 | { |
82 | return { .level: quint8(value & 0x7f), .isDebug: bool(value & 0x80) }; |
83 | } |
84 | // self checks |
85 | static_assert(decodeVersion1ArchRequirements(value: 0) == DecodedArchRequirements{ .level: 0, .isDebug: false }); |
86 | static_assert(decodeVersion1ArchRequirements(value: 0x80) == DecodedArchRequirements{ .level: 0, .isDebug: true }); |
87 | #ifdef Q_PROCESSOR_X86 |
88 | static_assert(decodeVersion1ArchRequirements(value: 1) == DecodedArchRequirements{ .level: 1, .isDebug: false }); |
89 | static_assert(decodeVersion1ArchRequirements(value: 3) == DecodedArchRequirements{ .level: 3, .isDebug: false}); |
90 | static_assert(decodeVersion1ArchRequirements(value: 4) == DecodedArchRequirements{ .level: 4, .isDebug: false }); |
91 | static_assert(decodeVersion1ArchRequirements(value: 0x82) == DecodedArchRequirements{ .level: 2, .isDebug: true }); |
92 | static_assert(decodeVersion1ArchRequirements(value: 0x84) == DecodedArchRequirements{ .level: 4, .isDebug: true }); |
93 | #endif |
94 | } // unnamed namespace |
95 | |
96 | QT_END_NAMESPACE |
97 | |
98 | #endif // QPLUGIN_P_H |
99 | |