loci: generate lists from the IR
diff --git a/c_gen/build_of_g.py b/c_gen/build_of_g.py
index 4d37b36..9b19af6 100755
--- a/c_gen/build_of_g.py
+++ b/c_gen/build_of_g.py
@@ -242,6 +242,7 @@
         of_g.base_length[(cls, wire_version)] = fixed_offset
         if (offset != -1):
             of_g.is_fixed_length.add((cls, wire_version))
+
     for list_type in lists:
         classes[list_type] = []
         of_g.ordered_classes[wire_version].append(list_type)
diff --git a/c_gen/codegen.py b/c_gen/codegen.py
index e2646e4..b88c111 100644
--- a/c_gen/codegen.py
+++ b/c_gen/codegen.py
@@ -43,7 +43,8 @@
 import c_gen.of_g_legacy as of_g
 import c_gen.type_maps as type_maps
 import c_gen.c_type_maps as c_type_maps
-import c_gen.loxi_utils_legacy as loxi_utils
+import loxi_utils.loxi_utils as loxi_utils
+import c_gen.loxi_utils_legacy as loxi_utils_legacy
 
 CLASS_CHUNK_SIZE = 32
 
@@ -146,9 +147,19 @@
             legacy_code=tmp.getvalue())
 
 def generate_lists(install_dir):
-    for cls in of_g.ordered_list_objects:
+    # Collect all the lists in use
+    list_oftypes = set()
+    for uclass in loxi_globals.unified.classes:
+        for version, ofclass in sorted(uclass.version_classes.items()):
+            for m in ofclass.members:
+                if isinstance(m, ir.OFDataMember):
+                    if loxi_utils.oftype_is_list(m.oftype):
+                        list_oftypes.add(m.oftype)
+
+    for oftype in sorted(list(list_oftypes)):
+        cls, e_cls = loxi_utils_legacy.list_name_extract(oftype)
+        e_cls = e_cls[:-2]
         with template_utils.open_output(install_dir, "loci/src/%s.c" % cls) as out:
-            e_cls = loxi_utils.list_to_entry_type(cls)
             util.render_template(out, "list.c", cls=cls, e_cls=e_cls)
             # Append legacy generated code
             c_code_gen.gen_new_function_definitions(out, cls)
diff --git a/loxi_utils/loxi_utils.py b/loxi_utils/loxi_utils.py
index 865891f..c86c503 100644
--- a/loxi_utils/loxi_utils.py
+++ b/loxi_utils/loxi_utils.py
@@ -177,3 +177,11 @@
         return enum.params['wire_type']
     else:
         return oftype
+
+def oftype_is_list(oftype):
+    return (oftype.find("list(") == 0)
+
+# Converts "list(of_flow_stats_entry_t)" to "of_flow_stats_entry"
+def oftype_list_elem(oftype):
+    assert oftype.find("list(") == 0
+    return oftype[5:-3]