| # 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. |
| |
| from generic_utils import * |
| import c_gen.loxi_utils_legacy as loxi_utils |
| import loxi_globals |
| |
| # map from inheritance root class name to set of subclass names |
| inheritance_map = {} |
| |
| def class_is_virtual(cls): |
| """ |
| Returns True if cls is a virtual class |
| """ |
| if loxi_utils.class_is_list(cls): |
| return True |
| return loxi_globals.unified.class_by_name(cls).virtual |
| |
| def class_is_inheritance_root(cls): |
| return cls in inheritance_map |
| |
| def generate_maps(): |
| for ofclass in loxi_globals.unified.classes: |
| if ofclass.virtual and not ofclass.superclass: |
| inheritance_map[ofclass.name] = set() |
| |
| for version, protocol in loxi_globals.ir.items(): |
| wire_version = version.wire_version |
| for ofclass in protocol.classes: |
| root = ofclass.inheritance_root() |
| if not root or root == ofclass or root.name == "of_header": |
| continue |
| |
| inheritance_map[root.name].add(ofclass.name) |
| |
| def sub_class_map(base_type, version): |
| """ |
| Returns an iterable object giving the instance nameys and subclass types |
| for the base_type, version values |
| """ |
| rv = [] |
| if base_type not in inheritance_map: |
| return rv |
| |
| for subcls in inheritance_map[base_type]: |
| if not loxi_utils.class_in_version(subcls, version): |
| continue |
| instance = loxi_utils.class_to_instance(subcls, base_type) |
| rv.append((instance, subcls)) |
| |
| return rv |