loci: move init function map to its own file
Dropped the header class special case, seems to work without it.
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index 5226e57..14863ca 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -514,7 +514,6 @@
#include "loci_int.h"
""")
- gen_init_map(out)
def type_data_c_gen(out, name):
common_top_matter(out, name)
@@ -2753,32 +2752,6 @@
if loxi_utils.class_is_message(cls):
gen_from_message_fn_body(cls, out)
-def gen_init_map(out):
- """
- Generate map from object ID to type coerce function
- """
- out.write("""
-/**
- * Map from object ID to type coerce function
- */
-const of_object_init_f of_object_init_map[] = {
- (of_object_init_f)NULL,
-""")
- count = 1
- for i, cls in enumerate(of_g.standard_class_order):
- if count != of_g.unified[cls]["object_id"]:
- print "Error in class mapping: object IDs not sequential"
- print cls, count, of_g.unified[cls]["object_id"]
- sys.exit(1)
- s = "(of_object_init_f)%s_init" % cls
- if cls in type_maps.inheritance_map:
- s = "(of_object_init_f)%s_header_init" % cls
- if i < len(of_g.standard_class_order) - 1:
- s += ","
- out.write(" %-65s /* %d */\n" % (s, count))
- count += 1
- out.write("};\n")
-
"""
Document generation functions
diff --git a/c_gen/codegen.py b/c_gen/codegen.py
index 592a69a..67c0904 100644
--- a/c_gen/codegen.py
+++ b/c_gen/codegen.py
@@ -39,6 +39,7 @@
import util
import c_code_gen
import c_gen.of_g_legacy as of_g
+import c_gen.type_maps as type_maps
PushWireTypesFn = namedtuple('PushWireTypesFn',
['class_name', 'versioned_type_members'])
@@ -118,3 +119,7 @@
with template_utils.open_output(install_dir, "loci/src/loci_strings.c") as out:
util.render_template(out, "loci_strings.c", object_id_strs=object_id_strs)
+
+def generate_init_map(install_dir):
+ with template_utils.open_output(install_dir, "loci/src/loci_init_map.c") as out:
+ util.render_template(out, "loci_init_map.c", classes=of_g.standard_class_order)
diff --git a/c_gen/templates/loci_init_map.c b/c_gen/templates/loci_init_map.c
new file mode 100644
index 0000000..dc4616d
--- /dev/null
+++ b/c_gen/templates/loci_init_map.c
@@ -0,0 +1,41 @@
+:: # Copyright 2013, Big Switch Networks, Inc.
+:: #
+:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+:: # the following special exception:
+:: #
+:: # LOXI Exception
+:: #
+:: # As a special exception to the terms of the EPL, you may distribute libraries
+:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
+:: # from the LoxiGen Libraries and the notice provided below is (i) included in
+:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+:: # documentation for the LoxiGen Libraries, if distributed in binary form.
+:: #
+:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+:: #
+:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+:: # a copy of the EPL at:
+:: #
+:: # http://www.eclipse.org/legal/epl-v10.html
+:: #
+:: # Unless required by applicable law or agreed to in writing, software
+:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: # EPL for the specific language governing permissions and limitations
+:: # under the EPL.
+:: include('_copyright.c')
+#include <loci/loci.h>
+#include <loci/of_object.h>
+#include "loci_log.h"
+#include "loci_int.h"
+
+/**
+ * Map from object ID to type coerce function
+ */
+const of_object_init_f of_object_init_map[] = {
+ (of_object_init_f)NULL,
+:: for cls in classes:
+ (of_object_init_f)${cls}_init,
+:: #endfor
+};