2
0
Эх сурвалжийг харах

Update htcdb scripts (#10)

- Pass input stream for hlsl intrinsics function instead of hard-coding
      the file location.
- Keep enum namespace as a property of hlsl_db
- Compatibility changes for python3.
David Peixotto 8 жил өмнө
parent
commit
5dca710dff

+ 6 - 6
utils/hct/hctdb.py

@@ -1683,7 +1683,7 @@ class db_hlsl_intrisic_param(object):
 
 
 class db_hlsl(object):
 class db_hlsl(object):
     "A database of HLSL language data"
     "A database of HLSL language data"
-    def __init__(self):
+    def __init__(self, intrinsic_defs):
         self.base_types = {
         self.base_types = {
             "bool": "LICOMPTYPE_BOOL",
             "bool": "LICOMPTYPE_BOOL",
             "int": "LICOMPTYPE_INT",
             "int": "LICOMPTYPE_INT",
@@ -1724,20 +1724,21 @@ class db_hlsl(object):
             "col_major": "AR_QUAL_COLMAJOR",
             "col_major": "AR_QUAL_COLMAJOR",
             "row_major": "AR_QUAL_ROWMAJOR"}
             "row_major": "AR_QUAL_ROWMAJOR"}
         self.intrinsics = []
         self.intrinsics = []
-        self.load_intrinsics("gen_intrin_main.txt")
+        self.load_intrinsics(intrinsic_defs)
         self.create_namespaces()
         self.create_namespaces()
         self.populate_attributes()
         self.populate_attributes()
+        self.opcode_namespace = "hlsl::IntrinsicOp"
 
 
     def create_namespaces(self):
     def create_namespaces(self):
         last_ns = None
         last_ns = None
         self.namespaces = {}
         self.namespaces = {}
-        for i in sorted(self.intrinsics, lambda x,y: cmp(x.key, y.key)):
+        for i in sorted(self.intrinsics, key=lambda x: x.key):
             if last_ns is None or last_ns.name != i.ns:
             if last_ns is None or last_ns.name != i.ns:
                 last_ns = db_hlsl_namespace(i.ns)
                 last_ns = db_hlsl_namespace(i.ns)
                 self.namespaces[i.ns] = last_ns
                 self.namespaces[i.ns] = last_ns
             last_ns.intrinsics.append(i)
             last_ns.intrinsics.append(i)
 
 
-    def load_intrinsics(self, file_name):
+    def load_intrinsics(self, intrinsic_defs):
         import re
         import re
         blank_re = re.compile(r"^\s*$")
         blank_re = re.compile(r"^\s*$")
         comment_re = re.compile(r"^\s*//")
         comment_re = re.compile(r"^\s*//")
@@ -1904,8 +1905,7 @@ class db_hlsl(object):
             return readonly, readnone, unsigned_op, overload_param_index
             return readonly, readnone, unsigned_op, overload_param_index
 
 
         current_namespace = None
         current_namespace = None
-        intrin_file = open(file_name)
-        for line in intrin_file:
+        for line in intrinsic_defs:
             if blank_re.match(line): continue
             if blank_re.match(line): continue
             if comment_re.match(line): continue
             if comment_re.match(line): continue
             match_obj = namespace_beg_re.match(line)
             match_obj = namespace_beg_re.match(line)

+ 11 - 9
utils/hct/hctdb_instrhelp.py

@@ -14,7 +14,8 @@ g_db_hlsl = None
 def get_db_hlsl():
 def get_db_hlsl():
     global g_db_hlsl
     global g_db_hlsl
     if g_db_hlsl is None:
     if g_db_hlsl is None:
-        g_db_hlsl = db_hlsl()
+      with open("gen_intrin_main.txt", "r") as f:
+        g_db_hlsl = db_hlsl(f)
     return g_db_hlsl
     return g_db_hlsl
 
 
 def format_comment(prefix, val):
 def format_comment(prefix, val):
@@ -495,7 +496,7 @@ def get_hlsl_intrinsic_stats():
     longest_fn = db.intrinsics[0]
     longest_fn = db.intrinsics[0]
     longest_param = None
     longest_param = None
     longest_arglist_fn = db.intrinsics[0]
     longest_arglist_fn = db.intrinsics[0]
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         # Get some values for maximum lengths.
         # Get some values for maximum lengths.
         if len(i.name) > len(longest_fn.name):
         if len(i.name) > len(longest_fn.name):
             longest_fn = i
             longest_fn = i
@@ -521,7 +522,8 @@ def get_hlsl_intrinsics():
     ns_table = ""
     ns_table = ""
     id_prefix = ""
     id_prefix = ""
     arg_idx = 0
     arg_idx = 0
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    opcode_namespace = db.opcode_namespace
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         if last_ns != i.ns:
         if last_ns != i.ns:
             last_ns = i.ns
             last_ns = i.ns
             id_prefix = "IOP" if last_ns == "Intrinsics" else "MOP"
             id_prefix = "IOP" if last_ns == "Intrinsics" else "MOP"
@@ -531,7 +533,7 @@ def get_hlsl_intrinsics():
             # This used to be qualified as __declspec(selectany), but that's no longer necessary.
             # This used to be qualified as __declspec(selectany), but that's no longer necessary.
             ns_table = "static const HLSL_INTRINSIC g_%s[] =\n{\n" % (last_ns)
             ns_table = "static const HLSL_INTRINSIC g_%s[] =\n{\n" % (last_ns)
             arg_idx = 0
             arg_idx = 0
-        ns_table += "    (UINT)hlsl::IntrinsicOp::%s_%s, %s, %s, %d, %d, g_%s_Args%s,\n" % (id_prefix, i.name, str(i.readonly).lower(), str(i.readnone).lower(), i.overload_param_index,len(i.params), last_ns, arg_idx)
+        ns_table += "    (UINT)%s::%s_%s, %s, %s, %d, %d, g_%s_Args%s,\n" % (opcode_namespace, id_prefix, i.name, str(i.readonly).lower(), str(i.readnone).lower(), i.overload_param_index,len(i.params), last_ns, arg_idx)
         result += "static const HLSL_INTRINSIC_ARGUMENT g_%s_Args%s[] =\n{\n" % (last_ns, arg_idx)
         result += "static const HLSL_INTRINSIC_ARGUMENT g_%s_Args%s[] =\n{\n" % (last_ns, arg_idx)
         for p in i.params:
         for p in i.params:
             result += "    \"%s\", %s, %s, %s, %s, %s, %s, %s,\n" % (
             result += "    \"%s\", %s, %s, %s, %s, %s, %s, %s,\n" % (
@@ -546,14 +548,14 @@ def enum_hlsl_intrinsics():
     db = get_db_hlsl()
     db = get_db_hlsl()
     result = ""
     result = ""
     enumed = []
     enumed = []
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         if (i.enum_name not in enumed):
         if (i.enum_name not in enumed):
             result += "  %s,\n" % (i.enum_name)
             result += "  %s,\n" % (i.enum_name)
             enumed.append(i.enum_name)
             enumed.append(i.enum_name)
     # unsigned
     # unsigned
     result += "  // unsigned\n"
     result += "  // unsigned\n"
 
 
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         if (i.unsigned_op != ""):
         if (i.unsigned_op != ""):
           if (i.unsigned_op not in enumed):
           if (i.unsigned_op not in enumed):
             result += "  %s,\n" % (i.unsigned_op)
             result += "  %s,\n" % (i.unsigned_op)
@@ -567,7 +569,7 @@ def has_unsigned_hlsl_intrinsics():
     result = ""
     result = ""
     enumed = []
     enumed = []
     # unsigned
     # unsigned
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         if (i.unsigned_op != ""):
         if (i.unsigned_op != ""):
           if (i.enum_name not in enumed):
           if (i.enum_name not in enumed):
             result += "  case IntrinsicOp::%s:\n" % (i.enum_name)
             result += "  case IntrinsicOp::%s:\n" % (i.enum_name)
@@ -579,7 +581,7 @@ def get_unsigned_hlsl_intrinsics():
     result = ""
     result = ""
     enumed = []
     enumed = []
     # unsigned
     # unsigned
-    for i in sorted(db.intrinsics, lambda x,y: cmp(x.key, y.key)):
+    for i in sorted(db.intrinsics, key=lambda x: x.key):
         if (i.unsigned_op != ""):
         if (i.unsigned_op != ""):
           if (i.enum_name not in enumed):
           if (i.enum_name not in enumed):
             enumed.append(i.enum_name)
             enumed.append(i.enum_name)
@@ -773,7 +775,7 @@ def get_valopcode_sm_text():
         return result
         return result
 
 
     for i in instrs:
     for i in instrs:
-        if i.shader_models <> last_model:
+        if i.shader_models != last_model:
             code += flush_instrs(model_instrs, last_model)
             code += flush_instrs(model_instrs, last_model)
             model_instrs = []
             model_instrs = []
             last_model = i.shader_models
             last_model = i.shader_models