completed instruction_properties.cpp
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 11 Jul 2017 01:43:00 +0000 (18:43 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 11 Jul 2017 01:43:00 +0000 (18:43 -0700)
src/generate_spirv_parser/generate.cpp
src/generate_spirv_parser/instruction_properties.cpp
src/generate_spirv_parser/instruction_properties.h

index e08bd8f8db84dccedb5bccc2afd2024e4f16648a..01617e29a1c98fb72dbb87e343d315c3046617b7 100644 (file)
@@ -1397,7 +1397,7 @@ private:
         using detail::name_from_words_all_lowercase;
         return name_from_words_all_lowercase("revision"_sv, v.import_name).to_string();
     }
-    const Enumerant_descriptor &get_capability(const std::string &capability)
+    const Enumerant_descriptor &get_capability(const std::string &capability) const
     {
         auto &enumerant_map = capability_enumeration.value()->json_name_to_enumerant_map;
         auto iter = enumerant_map.find(capability);
@@ -1405,7 +1405,7 @@ private:
             throw Generate_error("unknown capability: " + capability);
         return *std::get<1>(*iter);
     }
-    const Enumerant_descriptor &get_extension(const std::string &extension)
+    const Enumerant_descriptor &get_extension(const std::string &extension) const
     {
         auto &enumerant_map = extension_enumeration.value()->json_name_to_enumerant_map;
         auto iter = enumerant_map.find(extension);
@@ -1413,7 +1413,8 @@ private:
             throw Generate_error("unknown extension: " + extension);
         return *std::get<1>(*iter);
     }
-    std::list<Enumeration_descriptor>::const_iterator get_enumeration(const std::string &json_name)
+    std::list<Enumeration_descriptor>::const_iterator get_enumeration(
+        const std::string &json_name) const
     {
         auto iter = enumerations_map.find(json_name);
         if(iter == enumerations_map.end())
@@ -1502,7 +1503,7 @@ private:
             add_id_type_descriptor(Id_type_descriptor(operand_kind.kind));
         }
     }
-    std::list<Id_type_descriptor>::const_iterator get_id_type(const std::string &json_name)
+    std::list<Id_type_descriptor>::const_iterator get_id_type(const std::string &json_name) const
     {
         auto iter = id_type_map.find(json_name);
         if(iter == id_type_map.end())
@@ -1569,7 +1570,7 @@ private:
         }
     }
     std::list<Composite_type_descriptor>::const_iterator get_composite_type(
-        const std::string &json_name)
+        const std::string &json_name) const
     {
         auto iter = composite_type_map.find(json_name);
         if(iter == composite_type_map.end())
@@ -1691,7 +1692,7 @@ private:
         return iter;
     }
     std::list<Operand_kind_descriptor>::const_iterator get_operand_kind(
-        const std::string &json_name)
+        const std::string &json_name) const
     {
         auto iter = operand_kind_map.find(json_name);
         if(iter == operand_kind_map.end())
@@ -1957,6 +1958,31 @@ private:
                 + get_instruction_name_for_diagnostics(extension_instruction_set, json_name));
         return std::get<1>(*iter2);
     }
+    std::string generate_guessed_instruction_properties_descriptor_string(
+        const ast::Extension_instruction_set *extension_instruction_set,
+        const ast::Instructions::Instruction &instruction) const
+    {
+        std::string retval;
+        retval += "{\""_sv;
+        if(extension_instruction_set)
+            retval += extension_instruction_set->import_name;
+        retval += "\"_sv, \"";
+        retval += instruction.opname;
+        retval += "\"_sv, {"_sv;
+        auto separator = ""_sv;
+        for(auto &operand : instruction.operands.operands)
+        {
+            retval += separator;
+            separator = ", "_sv;
+            retval += '{';
+            auto operand_kind = get_operand_kind(operand.kind);
+            if(operand_kind->needs_integer_literal_size)
+                retval += "Integer_literal_size::always_32bits"_sv;
+            retval += '}';
+        }
+        retval += "}},";
+        return retval;
+    }
     void fill_instruction_descriptors(
         const ast::Extension_instruction_set *extension_instruction_set,
         const ast::Instructions &instructions)
@@ -2024,7 +2050,9 @@ private:
                             "instruction has no Instruction_properties_descriptor: "
                             + get_instruction_name_for_diagnostics(extension_instruction_set,
                                                                    instruction.opname)
-                            + "\nNeeded because operand needs IntegerLiteral size");
+                            + "\nNeeded because operand needs IntegerLiteral size\n"
+                            "instruction properties descriptor guess:\n"
+                            + generate_guessed_instruction_properties_descriptor_string(extension_instruction_set, instruction));
                     throw Generate_error(
                         "instruction operand properties has no Integer_literal_size: "
                         + get_instruction_name_for_diagnostics(extension_instruction_set,
index 9bbdf1ba1def7024fd947043f3cd9add8fbbac4c..0e296a4bb65cda1625123df3e56068177cb0b558 100644 (file)
@@ -32,7 +32,50 @@ Instruction_properties_descriptors Instruction_properties_descriptors::get() noe
     typedef Instruction_properties_descriptor::Operand_descriptor Operand_descriptor;
     typedef Operand_descriptor::Integer_literal_size Integer_literal_size;
     static constexpr Instruction_properties_descriptor descriptors[] = {
+        {""_sv, "OpSource"_sv, {{}, {Integer_literal_size::always_32bits}, {}, {}}},
+        {""_sv, "OpMemberName"_sv, {{}, {Integer_literal_size::always_32bits}, {}}},
+        {""_sv,
+         "OpLine"_sv,
+         {{}, {Integer_literal_size::always_32bits}, {Integer_literal_size::always_32bits}}},
+        {""_sv,
+         "OpTypeInt"_sv,
+         {{}, {Integer_literal_size::always_32bits}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpTypeFloat"_sv, {{}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpTypeVector"_sv, {{}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpTypeMatrix"_sv, {{}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv,
+         "OpTypeImage"_sv,
+         {{},
+          {},
+          {},
+          {Integer_literal_size::always_32bits},
+          {Integer_literal_size::always_32bits},
+          {Integer_literal_size::always_32bits},
+          {Integer_literal_size::always_32bits},
+          {},
+          {}}},
+        {""_sv, "OpConstantSampler"_sv, {{}, {}, {}, {Integer_literal_size::always_32bits}, {}}},
+        {""_sv, "OpArrayLength"_sv, {{}, {}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpMemberDecorate"_sv, {{}, {Integer_literal_size::always_32bits}, {}}},
+        {""_sv, "OpGroupMemberDecorate"_sv, {{}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpVectorShuffle"_sv, {{}, {}, {}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpCompositeExtract"_sv, {{}, {}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpCompositeInsert"_sv, {{}, {}, {}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpBranchConditional"_sv, {{}, {}, {}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpLifetimeStart"_sv, {{}, {Integer_literal_size::always_32bits}}},
+        {""_sv, "OpLifetimeStop"_sv, {{}, {Integer_literal_size::always_32bits}}},
+        {""_sv,
+         "OpConstantPipeStorage"_sv,
+         {{},
+          {},
+          {Integer_literal_size::always_32bits},
+          {Integer_literal_size::always_32bits},
+          {Integer_literal_size::always_32bits}}},
         {""_sv, "OpSwitch"_sv, {{}, {}, {Integer_literal_size::matches_type_of_operand_0}}},
+
+        {"OpenCL.std"_sv, "vloadn"_sv, {{}, {}, {Integer_literal_size::always_32bits}}},
+        {"OpenCL.std"_sv, "vload_halfn"_sv, {{}, {}, {Integer_literal_size::always_32bits}}},
+        {"OpenCL.std"_sv, "vloada_halfn"_sv, {{}, {}, {Integer_literal_size::always_32bits}}},
     };
     return Instruction_properties_descriptors(descriptors,
                                               sizeof(descriptors) / sizeof(descriptors[0]));
index bf2cad9d347a57ef3078b49d94bb8102fc936a6a..ca97a4ab1debf348fc967909c9c03d49215210db 100644 (file)
@@ -55,7 +55,7 @@ struct Instruction_properties_descriptor
     };
     struct Operand_descriptors
     {
-        static constexpr std::size_t allocated_size = 7; // increase if we run out of room
+        static constexpr std::size_t allocated_size = 10; // increase if we run out of room
     private:
         std::size_t used_size;
         Operand_descriptor operands[allocated_size];