ir: convert version fields to OFTypeMembers
The frontend gets a new OFVersionMember field type, which is lowered to
OFTypeMember when generating the IR (which is when the version is first known).
diff --git a/loxi_front_end/frontend.py b/loxi_front_end/frontend.py
index a84508a..545b5bc 100644
--- a/loxi_front_end/frontend.py
+++ b/loxi_front_end/frontend.py
@@ -54,6 +54,8 @@
elif m_ast[2] == 'actions_len':
# HACK only usage so far
return ir.OFFieldLengthMember(name=m_ast[2], oftype=get_type(m_ast[1], ctx), field_name='actions')
+ if m_ast[2] == 'version': # Should be moved to parser
+ return ir.OFVersionMember(name=m_ast[2], oftype=get_type(m_ast[1], ctx))
else:
return ir.OFDataMember(name=m_ast[2], oftype=get_type(m_ast[1], ctx))
elif m_ast[0] == 'discriminator':
diff --git a/loxi_front_end/frontend_ir.py b/loxi_front_end/frontend_ir.py
index a927f94..af3f223 100644
--- a/loxi_front_end/frontend_ir.py
+++ b/loxi_front_end/frontend_ir.py
@@ -38,6 +38,7 @@
'OFLengthMember',
'OFFieldLengthMember',
'OFPadMember',
+ 'OFVersionMember',
'OFEnum',
'OFEnumEntry'
]
@@ -128,6 +129,16 @@
OFPadMember = namedtuple('OFPadMember', ['length'])
"""
+Field with the version of an OpenFlow object
+
+@param name
+@param oftype C-like type string
+
+Example: hello.version
+"""
+OFVersionMember = namedtuple('OFVersionMember', ['name', 'oftype'])
+
+"""
An OpenFlow enumeration
All values are Python ints.
diff --git a/loxi_ir/ir.py b/loxi_ir/ir.py
index 8553f62..3785a6f 100644
--- a/loxi_ir/ir.py
+++ b/loxi_ir/ir.py
@@ -33,6 +33,7 @@
from collections import namedtuple, OrderedDict
from generic_utils import find, memoize, OrderedSet
from loxi_ir import ir_offset
+import loxi_front_end.frontend_ir as frontend_ir
logger = logging.getLogger(__name__)
@@ -356,11 +357,18 @@
return { name if name != "length" else "pad_length" : value for name, value in props.items() }
def build_member(of_class, fe_member, length_info):
- ir_class = globals()[type(fe_member).__name__]
- member = ir_class(offset = length_info.offset,
- base_length = length_info.base_length,
- is_fixed_length=length_info.is_fixed_length,
- **convert_member_properties(fe_member._asdict()))
+ if isinstance(fe_member, frontend_ir.OFVersionMember):
+ member = OFTypeMember(offset = length_info.offset,
+ base_length = length_info.base_length,
+ is_fixed_length=length_info.is_fixed_length,
+ value = version.wire_version,
+ **convert_member_properties(fe_member._asdict()))
+ else:
+ ir_class = globals()[type(fe_member).__name__]
+ member = ir_class(offset = length_info.offset,
+ base_length = length_info.base_length,
+ is_fixed_length=length_info.is_fixed_length,
+ **convert_member_properties(fe_member._asdict()))
member.of_class = of_class
return member