loci: split accessors into one file per class
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index fa4db2a..cbaba56 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -543,7 +543,7 @@
 """)
     gen_object_enum_str(out)
     if config_check("gen_unified_fns"):
-        gen_accessor_definitions(out)
+        gen_all_accessor_definitions(out)
     gen_new_function_definitions(out)
     gen_init_map(out)
     out.write("\n/* This code should be broken out to a different file */\n")
@@ -2160,7 +2160,7 @@
     out.write("%s\n%s_%s_get(\n    %s)\n" % (ret_type, cls, m_name, params))
     gen_unified_acc_body(out, cls, m_name, ver_type_map, "get", m_type)
 
-def gen_accessor_definitions(out):
+def gen_all_accessor_definitions(out):
     """
     Generate the body of each version independent accessor
 
@@ -2182,6 +2182,10 @@
             gen_list_accessors(out, cls)
             continue
         out.write("/** \\ingroup %s \n * @{ */\n" % cls)
+        #gen_accessor_definitions(out, cls)
+        out.write("\n/** @} */\n")
+
+def gen_accessor_definitions(out, cls):
         for m_name in of_g.ordered_members[cls]:
             if m_name in of_g.skip_members:
                 continue
@@ -2222,8 +2226,6 @@
             out.write("%s\n%s_%s_set(\n    %s)\n" % (ret_type, cls, m_name, params))
             gen_unified_acc_body(out, cls, m_name, ver_type_map, "set", m_type)
 
-        out.write("\n/** @} */\n")
-
 def gen_acc_pointer_typedefs(out):
     """
     Generate the function pointer typedefs for in-struct accessors
diff --git a/c_gen/codegen.py b/c_gen/codegen.py
index 0d7832a..7258514 100644
--- a/c_gen/codegen.py
+++ b/c_gen/codegen.py
@@ -37,6 +37,7 @@
 import loxi_globals
 import loxi_ir.ir as ir
 import util
+import c_code_gen
 
 PushWireTypesFn = namedtuple('PushWireTypesFn',
     ['class_name', 'versioned_type_members'])
@@ -77,3 +78,10 @@
 
     with template_utils.open_output(install_dir, "loci/src/loci_push_wire_types.h") as out:
         util.render_template(out, "loci_push_wire_types.h", fns=fns)
+
+def generate_classes(install_dir):
+    for uclass in loxi_globals.unified.classes:
+        with template_utils.open_output(install_dir, "loci/src/%s.c" % uclass.name) as out:
+            util.render_template(out, "class.c")
+            # Append legacy generated code
+            c_code_gen.gen_accessor_definitions(out, uclass.name)
diff --git a/c_gen/templates/class.c b/c_gen/templates/class.c
new file mode 100644
index 0000000..849ea80
--- /dev/null
+++ b/c_gen/templates/class.c
@@ -0,0 +1,35 @@
+:: # 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('_pragmas.c')
+
+#include <loci/loci.h>
+#include <loci/of_object.h>
+#include "loci_log.h"
+#include "loci_push_wire_types.h"
+#include "loci_int.h"
diff --git a/lang_c.py b/lang_c.py
index 7718d48..b8663ef 100644
--- a/lang_c.py
+++ b/lang_c.py
@@ -175,3 +175,4 @@
         with template_utils.open_output(install_dir, name) as outfile:
             fn(outfile, os.path.basename(name))
     c_gen.codegen.gen_push_wire_types(install_dir)
+    c_gen.codegen.generate_classes(install_dir)