forked from floodlight/loxigen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang_c.py
135 lines (123 loc) · 5.26 KB
/
lang_c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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.
"""
@brief C language specific LOXI generating configuration
This language specific file defines a dictionary 'targets' that
defines the generated files and the functions used to generate them.
"""
import os
import c_gen.of_g_legacy as of_g
import c_gen.build_of_g as build_of_g
import c_gen.c_code_gen as c_code_gen
import c_gen.c_test_gen as c_test_gen
import c_gen.c_dump_gen as c_dump_gen
import c_gen.c_show_gen as c_show_gen
import c_gen.util
import c_gen.codegen
import c_gen.match
import loxi_utils.loxi_utils as loxi_utils
import template_utils
def static(out, name):
c_gen.util.render_template(out, os.path.basename(name))
targets = {
# LOCI headers
'loci/inc/loci/loci.h': c_code_gen.top_h_gen,
'loci/inc/loci/loci_idents.h': c_code_gen.identifiers_gen,
'loci/inc/loci/loci_base.h': c_code_gen.base_h_gen,
'loci/inc/loci/of_match.h': c_code_gen.match_h_gen,
'loci/inc/loci/loci_doc.h': c_code_gen.gen_accessor_doc,
'loci/inc/loci/loci_obj_dump.h': c_dump_gen.gen_obj_dump_h,
'loci/inc/loci/loci_obj_show.h': c_show_gen.gen_obj_show_h,
'loci/inc/loci/loci_validator.h': static,
# Static LOCI headers
'loci/inc/loci/bsn_ext.h': static,
'loci/inc/loci/loci_dox.h': static,
'loci/inc/loci/loci_dump.h': static,
'loci/inc/loci/loci_show.h': static,
'loci/inc/loci/of_buffer.h': static,
'loci/inc/loci/of_doc.h': static,
'loci/inc/loci/of_message.h': static,
'loci/inc/loci/of_object.h': static,
'loci/inc/loci/of_utils.h': static,
'loci/inc/loci/of_wire_buf.h': static,
# LOCI code
'loci/src/of_match.c': c_code_gen.match_c_gen,
'loci/src/loci_obj_dump.c': c_dump_gen.gen_obj_dump_c,
'loci/src/loci_obj_show.c': c_show_gen.gen_obj_show_c,
'loci/src/loci_validator.c': static,
# Static LOCI code
'loci/src/loci_int.h': static,
'loci/src/loci_log.c': static,
'loci/src/loci_log.h': static,
'loci/src/of_object.c': static,
'loci/src/of_utils.c': static,
'loci/src/of_wire_buf.c': static,
# Static LOCI documentation
'loci/README': static,
'loci/Doxyfile': static,
# locitest code
'locitest/inc/locitest/of_dup.h': c_test_gen.dup_h_gen,
'locitest/inc/locitest/test_common.h': c_test_gen.gen_common_test_header,
'locitest/src/of_dup.c': c_test_gen.dup_c_gen,
'locitest/src/test_common.c': c_test_gen.gen_common_test,
'locitest/src/test_scalar_setcheck.c': c_test_gen.gen_scalar_set_check,
'locitest/src/test_unified_setcheck.c': c_test_gen.gen_unified_set_check,
'locitest/src/test_list.c': c_test_gen.gen_list_test,
'locitest/src/test_match.c': c_test_gen.gen_match_test,
'locitest/src/test_msg.c': c_test_gen.gen_msg_test,
'locitest/src/test_scalar_accessor.c': c_test_gen.gen_message_scalar_test,
'locitest/src/test_unified_accessor.c': c_test_gen.gen_unified_accessor_tests,
'locitest/src/test_data.c': c_test_gen.gen_datafiles_tests,
# Static locitest code
'locitest/inc/locitest/unittest.h': static,
'locitest/src/test_ext.c': static,
'locitest/src/test_list_limits.c': static,
'locitest/src/test_match_utils.c': static,
'locitest/src/test_utils.c': static,
'locitest/src/test_validator.c': static,
'locitest/src/main.c': static,
'locitest/Makefile': static,
}
def generate(install_dir):
c_gen.match.build()
build_of_g.initialize_versions()
build_of_g.build_ordered_classes()
build_of_g.populate_type_maps()
build_of_g.analyze_input()
build_of_g.unify_input()
build_of_g.order_and_assign_object_ids()
for (name, fn) in targets.items():
with template_utils.open_output(install_dir, name) as outfile:
fn(outfile, os.path.basename(name))
c_gen.codegen.build_class_metadata()
c_gen.codegen.generate_classes(install_dir)
c_gen.codegen.generate_classes_header(install_dir)
c_gen.codegen.generate_lists(install_dir)
c_gen.codegen.generate_strings(install_dir)
c_gen.codegen.generate_init_map(install_dir)
c_gen.codegen.generate_type_maps(install_dir)
c_gen.codegen.generate_class_metadata(install_dir)