Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Headers.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Kessenich <cepheus@frii.com>2019-06-12 09:17:15 +0300
committerJohn Kessenich <cepheus@frii.com>2019-06-12 09:17:15 +0300
commitcca9cc7f39131073ab0aa8989159f96e4ba1abf3 (patch)
treeae234dcf052e5d8003df4e13e39b373f0333bd12 /tools
parenta7741727e25171acee151396691672dc88e6d85e (diff)
Grammar: Add instruction-printing classes.
Each instruction belongs to exactly one instruction class. @exclude will put in the headers, but not in the specification. Reserved is for instructions that are both to be reserved in the specification and not yet put into another printing class. (It is okay to establish a printing class for a reserved instruction.)
Diffstat (limited to 'tools')
-rw-r--r--tools/buildHeaders/jsonToSpirv.cpp50
-rw-r--r--tools/buildHeaders/jsonToSpirv.h14
2 files changed, 44 insertions, 20 deletions
diff --git a/tools/buildHeaders/jsonToSpirv.cpp b/tools/buildHeaders/jsonToSpirv.cpp
index e6cab48..2190bd3 100644
--- a/tools/buildHeaders/jsonToSpirv.cpp
+++ b/tools/buildHeaders/jsonToSpirv.cpp
@@ -27,6 +27,7 @@
#include <algorithm>
#include <iostream>
#include <unordered_map>
+#include <unordered_set>
#include <utility>
#include <fstream>
@@ -40,6 +41,10 @@ namespace spv {
// parameterization information.
InstructionValues InstructionDesc;
+// The ordered list (in printing order) of printing classes
+// (specification subsections).
+PrintingClasses InstructionPrintingClasses;
+
// Note: There is no entry for OperandOpcode. Use InstructionDesc instead.
EnumDefinition OperandClassParams[OperandOpcode];
EnumValues SourceLanguageParams;
@@ -229,20 +234,6 @@ unsigned int NumberStringToBit(const std::string& str)
return bit;
}
-bool ExcludeInstruction(unsigned op, bool buildingHeaders)
-{
- // Some instructions in the grammar don't need to be reflected
- // in the specification.
-
- if (buildingHeaders)
- return false;
-
- if (op >= 5699 /* OpVmeImageINTEL */ && op <= 5816 /* OpSubgroupAvcSicGetInterRawSadsINTEL */)
- return true;
-
- return false;
-}
-
void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders)
{
// only do this once.
@@ -298,11 +289,36 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders)
return result;
};
+ // set up the printing classes
+ std::unordered_set<std::string> tags; // short-lived local for error checking below
+ const Json::Value printingClasses = root["instruction_printing_class"];
+ for (const auto& printingClass : printingClasses) {
+ if (printingClass["tag"].asString().size() > 0)
+ tags.insert(printingClass["tag"].asString()); // just for error checking
+ else
+ std::cerr << "Error: each instruction_printing_class requires a non-empty \"tag\"" << std::endl;
+ if (buildingHeaders || printingClass["tag"].asString() != "@exclude") {
+ InstructionPrintingClasses.push_back({printingClass["tag"].asString(),
+ printingClass["heading"].asString()});
+ }
+ }
+
+ // process the instructions
const Json::Value insts = root["instructions"];
for (const auto& inst : insts) {
- const unsigned int opcode = inst["opcode"].asUInt();
- if (ExcludeInstruction(opcode, buildingHeaders))
+ const auto printingClass = inst["class"].asString();
+ if (printingClass.size() == 0) {
+ std::cerr << "Error: " << inst["opname"].asString()
+ << " requires a non-empty printing \"class\" tag" << std::endl;
+ }
+ if (!buildingHeaders && printingClass == "@exclude")
continue;
+ if (tags.find(printingClass) == tags.end()) {
+ std::cerr << "Error: " << inst["opname"].asString()
+ << " requires a \"class\" declared as a \"tag\" in \"instruction printing_class\""
+ << std::endl;
+ }
+ const auto opcode = inst["opcode"].asUInt();
const std::string name = inst["opname"].asString();
EnumCaps caps = getCaps(inst);
std::string version = inst["version"].asString();
@@ -324,7 +340,7 @@ void jsonToSpirv(const std::string& jsonPath, bool buildingHeaders)
std::move(EnumValue(opcode, name,
std::move(caps), std::move(version), std::move(lastVersion), std::move(exts),
std::move(operands))),
- defTypeId, defResultId);
+ printingClass, defTypeId, defResultId);
}
// Specific additional context-dependent operands
diff --git a/tools/buildHeaders/jsonToSpirv.h b/tools/buildHeaders/jsonToSpirv.h
index beec01c..0764de3 100644
--- a/tools/buildHeaders/jsonToSpirv.h
+++ b/tools/buildHeaders/jsonToSpirv.h
@@ -89,6 +89,13 @@ enum OperandClass {
OperandCount
};
+// For direct representation of the JSON grammar "instruction_printing_class".
+struct PrintingClass {
+ std::string tag;
+ std::string heading;
+};
+using PrintingClasses = std::vector<PrintingClass>;
+
// Any specific enum can have a set of capabilities that allow it:
typedef std::vector<std::string> EnumCaps;
@@ -238,10 +245,10 @@ public:
// per OperandParameters above.
class InstructionValue : public EnumValue {
public:
- InstructionValue(EnumValue&& e, bool has_type, bool has_result)
+ InstructionValue(EnumValue&& e, const std::string& printClass, bool has_type, bool has_result)
: EnumValue(std::move(e)),
+ printingClass(printClass),
opDesc("TBD"),
- opClass(0),
typePresent(has_type),
resultPresent(has_result),
alias(this) { }
@@ -257,8 +264,8 @@ public:
const InstructionValue& getAlias() const { return *alias; }
bool isAlias() const { return alias != this; }
+ std::string printingClass;
const char* opDesc;
- int opClass;
protected:
int typePresent : 1;
@@ -270,6 +277,7 @@ using InstructionValues = EnumValuesContainer<InstructionValue>;
// Parameterization info for all instructions.
extern InstructionValues InstructionDesc;
+extern PrintingClasses InstructionPrintingClasses;
// These hold definitions of the enumerants used for operands.
// This is indexed by OperandClass, but not including OperandOpcode.