blob: 7718d481547b2c90442e39a131087cad22ffa750 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001# Copyright 2013, Big Switch Networks, Inc.
2#
3# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4# the following special exception:
5#
6# LOXI Exception
7#
8# As a special exception to the terms of the EPL, you may distribute libraries
9# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10# that copyright and licensing notices generated by LoxiGen are not altered or removed
11# from the LoxiGen Libraries and the notice provided below is (i) included in
12# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13# documentation for the LoxiGen Libraries, if distributed in binary form.
14#
15# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16#
17# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18# a copy of the EPL at:
19#
20# http://www.eclipse.org/legal/epl-v10.html
21#
22# Unless required by applicable law or agreed to in writing, software
23# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25# EPL for the specific language governing permissions and limitations
26# under the EPL.
27
28"""
29@brief C language specific LOXI generating configuration
30
31This language specific file defines a dictionary 'targets' that
32defines the generated files and the functions used to generate them.
33"""
34
35import os
Andreas Wundsam76db0062013-11-15 13:34:41 -080036import c_gen.of_g_legacy as of_g
37import c_gen.build_of_g as build_of_g
Rich Lanea06d0c32013-03-25 08:52:03 -070038import c_gen.c_code_gen as c_code_gen
39import c_gen.c_test_gen as c_test_gen
40import c_gen.c_dump_gen as c_dump_gen
41import c_gen.c_show_gen as c_show_gen
42import c_gen.c_validator_gen as c_validator_gen
43import c_gen.util
Rich Lanebdd8e292013-12-06 17:37:39 -080044import c_gen.codegen
Rich Laneda5446f2013-11-10 17:21:48 -080045import loxi_utils.loxi_utils as loxi_utils
Andreas Wundsam76db0062013-11-15 13:34:41 -080046import template_utils
Rich Lanea06d0c32013-03-25 08:52:03 -070047
48def static(out, name):
49 c_gen.util.render_template(out, os.path.basename(name))
50
51targets = {
52 # LOCI headers
53 'loci/inc/loci/loci.h': c_code_gen.top_h_gen,
54 'loci/inc/loci/loci_idents.h': c_code_gen.identifiers_gen,
55 'loci/inc/loci/loci_base.h': c_code_gen.base_h_gen,
56 'loci/inc/loci/of_match.h': c_code_gen.match_h_gen,
57 'loci/inc/loci/loci_doc.h': c_code_gen.gen_accessor_doc,
58 'loci/inc/loci/loci_obj_dump.h': c_dump_gen.gen_obj_dump_h,
59 'loci/inc/loci/loci_obj_show.h': c_show_gen.gen_obj_show_h,
60 'loci/inc/loci/loci_validator.h': c_validator_gen.gen_h,
61
62 # Static LOCI headers
63 'loci/inc/loci/bsn_ext.h': static,
64 'loci/inc/loci/loci_dox.h': static,
65 'loci/inc/loci/loci_dump.h': static,
66 'loci/inc/loci/loci_show.h': static,
67 'loci/inc/loci/of_buffer.h': static,
68 'loci/inc/loci/of_doc.h': static,
69 'loci/inc/loci/of_message.h': static,
70 'loci/inc/loci/of_object.h': static,
71 'loci/inc/loci/of_utils.h': static,
72 'loci/inc/loci/of_wire_buf.h': static,
73
74 # LOCI code
75 'loci/src/loci.c': c_code_gen.top_c_gen,
76 'loci/src/of_type_data.c': c_code_gen.type_data_c_gen,
77 'loci/src/of_match.c': c_code_gen.match_c_gen,
78 'loci/src/loci_obj_dump.c': c_dump_gen.gen_obj_dump_c,
79 'loci/src/loci_obj_show.c': c_show_gen.gen_obj_show_c,
80 'loci/src/loci_validator.c': c_validator_gen.gen_c,
81
82 # Static LOCI code
83 'loci/src/loci_int.h': static,
84 'loci/src/loci_log.c': static,
85 'loci/src/loci_log.h': static,
86 'loci/src/of_object.c': static,
87 'loci/src/of_type_maps.c': static,
88 'loci/src/of_utils.c': static,
89 'loci/src/of_wire_buf.c': static,
90
91 # Static LOCI documentation
92 'loci/README': static,
93 'loci/Doxyfile': static,
94
95 # locitest code
96 'locitest/inc/locitest/of_dup.h': c_test_gen.dup_h_gen,
97 'locitest/inc/locitest/test_common.h': c_test_gen.gen_common_test_header,
98 'locitest/src/of_dup.c': c_test_gen.dup_c_gen,
99 'locitest/src/test_common.c': c_test_gen.gen_common_test,
100 'locitest/src/test_list.c': c_test_gen.gen_list_test,
101 'locitest/src/test_match.c': c_test_gen.gen_match_test,
102 'locitest/src/test_msg.c': c_test_gen.gen_msg_test,
103 'locitest/src/test_scalar_acc.c': c_test_gen.gen_message_scalar_test,
104 'locitest/src/test_uni_acc.c': c_test_gen.gen_unified_accessor_tests,
Rich Laneccae0312013-07-21 23:34:13 -0700105 'locitest/src/test_data.c': c_test_gen.gen_datafiles_tests,
Rich Lanea06d0c32013-03-25 08:52:03 -0700106
107 # Static locitest code
108 'locitest/inc/locitest/unittest.h': static,
109 'locitest/src/test_ext.c': static,
110 'locitest/src/test_list_limits.c': static,
111 'locitest/src/test_match_utils.c': static,
112 'locitest/src/test_setup_from_add.c': static,
113 'locitest/src/test_utils.c': static,
114 'locitest/src/test_validator.c': static,
Rich Lane99c29c32013-05-29 17:09:21 -0700115 'locitest/src/main.c': static,
Rich Lane9ff6d162013-07-21 23:32:27 -0700116 'locitest/Makefile': static,
Rich Lanea06d0c32013-03-25 08:52:03 -0700117}
Rich Laneda5446f2013-11-10 17:21:48 -0800118
Andreas Wundsam76db0062013-11-15 13:34:41 -0800119################################################################
120#
121# Configuration related
122#
123################################################################
124
125def config_check(str, dictionary = of_g.code_gen_config):
126 """
127 Return config value if in dictionary; else return False.
128 @param str The lookup index
129 @param dictionary The dict to check; use code_gen_config if None
130 """
131
132 if str in dictionary:
133 return dictionary[str]
134
135 return False
136
137def config_sanity_check():
138 """
139 Check the configuration for basic consistency
140
141 @fixme Needs update for generic language support
142 """
143
144 rv = True
145 # For now, only "error" supported for get returns
146 if config_check("copy_semantics") != "read":
147 debug("Only 'read' is supported for copy_semantics");
148 rv = False
149 if config_check("get_returns") != "error":
150 debug("Only 'error' is supported for get-accessor return types\m");
151 rv = False
152 if not config_check("use_fn_ptrs") and not config_check("gen_unified_fns"):
153 debug("Must have gen_fn_ptrs and/or gen_unified_fns set in config")
154 rv = False
155 if config_check("use_obj_id"):
156 debug("use_obj_id is set but not yet supported (change \
157config_sanity_check if it is)")
158 rv = False
159 if config_check("gen_unified_macros") and config_check("gen_unified_fns") \
160 and config_check("gen_unified_macro_lower"):
161 debug("Conflict: Cannot generate unified functions and lower case \
162unified macros")
163 rv = False
164
165 return rv
166
167def generate(install_dir):
168 build_of_g.initialize_versions()
169 build_of_g.build_ordered_classes()
170 build_of_g.populate_type_maps()
171 build_of_g.analyze_input()
172 build_of_g.unify_input()
173 build_of_g.order_and_assign_object_ids()
Rich Laneda5446f2013-11-10 17:21:48 -0800174 for (name, fn) in targets.items():
Andreas Wundsam76db0062013-11-15 13:34:41 -0800175 with template_utils.open_output(install_dir, name) as outfile:
Rich Laneda5446f2013-11-10 17:21:48 -0800176 fn(outfile, os.path.basename(name))
Rich Lanebdd8e292013-12-06 17:37:39 -0800177 c_gen.codegen.gen_push_wire_types(install_dir)