pyloxi: use IR to generate enums
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index 66e0454..fb2e48c 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -129,16 +129,8 @@
util.render_template(out, 'common.py', ofclasses=ofclasses, version=version)
def generate_const(out, name, version):
- groups = {}
- for (group, idents) in of_g.identifiers_by_group.items():
- items = []
- for ident in idents:
- info = of_g.identifiers[ident]
- if version in info["values_by_version"]:
- items.append((info["ofp_name"], info["values_by_version"][version]))
- if items:
- groups[group] = items
- util.render_template(out, 'const.py', version=version, groups=groups)
+ util.render_template(out, 'const.py', version=version,
+ enums=of_g.ir[version].enums)
def generate_instruction(out, name, version):
ofclasses = [x for x in build_ofclasses(version)
diff --git a/py_gen/templates/const.py b/py_gen/templates/const.py
index ef09585..4567d56 100644
--- a/py_gen/templates/const.py
+++ b/py_gen/templates/const.py
@@ -36,10 +36,9 @@
OFP_VERSION = ${version}
-:: for (group, idents) in sorted(groups.items()):
-:: idents.sort(key=lambda (ident, value): value)
-# Identifiers from group ${group}
-:: for (ident, value) in idents:
+:: for enum in sorted(enums, key=lambda enum: enum.name):
+# Identifiers from group ${enum.name}
+:: for (ident, value) in enum.values:
:: if version == 1 and ident.startswith('OFPP_'):
:: # HACK loxi converts these to 32-bit
${ident} = ${"%#x" % (value & 0xffff)}
@@ -48,9 +47,9 @@
:: #endif
:: #endfor
-:: if group not in blacklisted_map_groups:
-${group}_map = {
-:: for (ident, value) in idents:
+:: if enum.name not in blacklisted_map_groups:
+${enum.name}_map = {
+:: for (ident, value) in enum.values:
:: if ident in blacklisted_map_idents:
:: pass
:: elif version == 1 and ident.startswith('OFPP_'):