Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1048: Use signed integers for storage #1051

Merged
merged 19 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
replace mod types with range types
  • Loading branch information
kanigsson committed Jun 23, 2022
commit 4de2c07880b6d38261a8db2595f8cef679708631
4 changes: 2 additions & 2 deletions examples/apps/ping/src/generic_checksum.adb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ is
is
use type ICMP.Checksum;
use type Types.Index;
Checksum : ICMP.Checksum := Shift_Left (ICMP.Checksum (ICMP.To_S63 (Tag)))
+ ICMP.Checksum (ICMP.To_S63 (Code));
Checksum : ICMP.Checksum := Shift_Left (ICMP.Checksum (ICMP.To_Base_Int (Tag)))
+ ICMP.Checksum (ICMP.To_Base_Int (Code));
Index : Types.Index;
begin
Checksum := Add (Checksum, Add (ICMP.Checksum (Identifier), ICMP.Checksum (Sequence_Number)));
Expand Down
18 changes: 9 additions & 9 deletions rflx/generator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def substitution(
prefix: str,
embedded: bool = False,
public: bool = False,
target_type: Optional[ID] = const.TYPES_S63,
target_type: Optional[ID] = const.TYPES_BASE_INT,
) -> Callable[[expr.Expr], expr.Expr]:
facts = substitution_facts(message, prefix, embedded, public, target_type)

Expand Down Expand Up @@ -152,7 +152,7 @@ def byte_aggregate(aggregate: expr.Aggregate) -> expr.Aggregate:
other = expression.left
if boolean_literal and other:
return expression.__class__(
other, type_conversion(expr.Call("To_S63", [boolean_literal]))
other, type_conversion(expr.Call("To_Base_Int", [boolean_literal]))
)

def field_value(field: model.Field) -> expr.Expr:
Expand Down Expand Up @@ -194,7 +194,7 @@ def substitution_facts(
prefix: str,
embedded: bool = False,
public: bool = False,
target_type: Optional[ID] = const.TYPES_S63,
target_type: Optional[ID] = const.TYPES_BASE_INT,
) -> Mapping[expr.Name, expr.Expr]:
def prefixed(name: str) -> expr.Expr:
return expr.Variable(rid.ID("Ctx") * name) if not embedded else expr.Variable(name)
Expand Down Expand Up @@ -233,8 +233,8 @@ def field_size(field: model.Field) -> expr.Expr:
def parameter_value(parameter: model.Field, parameter_type: model.Type) -> expr.Expr:
if isinstance(parameter_type, model.Enumeration):
if embedded:
return expr.Call("To_S63", [expr.Variable(parameter.name)])
return expr.Call("To_S63", [expr.Variable("Ctx" * parameter.identifier)])
return expr.Call("To_Base_Int", [expr.Variable(parameter.name)])
return expr.Call("To_Base_Int", [expr.Variable("Ctx" * parameter.identifier)])
if isinstance(parameter_type, model.Scalar):
if embedded:
return expr.Variable(parameter.name)
Expand All @@ -245,7 +245,7 @@ def parameter_value(parameter: model.Field, parameter_type: model.Type) -> expr.
def field_value(field: model.Field, field_type: model.Type) -> expr.Expr:
if isinstance(field_type, model.Enumeration):
if public:
return expr.Call("To_S63", [expr.Call(f"Get_{field.name}", [expr.Variable("Ctx")])])
return expr.Call("To_Base_Int", [expr.Call(f"Get_{field.name}", [expr.Variable("Ctx")])])
return expr.Selected(
expr.Indexed(cursors, expr.Variable(field.affixed_name)),
"Value",
Expand Down Expand Up @@ -281,14 +281,14 @@ def type_conversion(expression: expr.Expr) -> expr.Expr:
for f, t in message.field_types.items()
},
**{
expr.Variable(l): type_conversion(expr.Call("To_S63", [expr.Variable(l)]))
expr.Variable(l): type_conversion(expr.Call("To_Base_Int", [expr.Variable(l)]))
for t in message.types.values()
if isinstance(t, model.Enumeration) and t != model.BOOLEAN
for l in t.literals.keys()
},
**{
expr.Variable(t.package * l): type_conversion(
expr.Call("To_S63", [expr.Variable(prefix * t.package * l)])
expr.Call("To_Base_Int", [expr.Variable(prefix * t.package * l)])
)
for t in message.types.values()
if isinstance(t, model.Enumeration) and t != model.BOOLEAN
Expand Down Expand Up @@ -937,7 +937,7 @@ def create_sequence_instantiation(
str(element_type.size),
prefix * element_type_package * f"Valid_{element_type.name}",
prefix * element_type_package * "To_Actual",
prefix * element_type_package * "To_S63",
prefix * element_type_package * "To_Base_Int",
],
)
else:
Expand Down
2 changes: 1 addition & 1 deletion rflx/generator/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
TYPES_TO_LAST_BIT_INDEX = TYPES * "To_Last_Bit_Index"
TYPES_OFFSET = TYPES * "Offset"
TYPES_U64 = TYPES * "U64"
TYPES_S63 = TYPES * "S63"
TYPES_BASE_INT = TYPES * "Base_Integer"
TYPES_BYTE_ORDER = TYPES * "Byte_Order"
TYPES_HIGH_ORDER_FIRST = TYPES * "High_Order_First"
TYPES_LOW_ORDER_FIRST = TYPES * "Low_Order_First"
Expand Down
28 changes: 14 additions & 14 deletions rflx/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def _integer_functions(self, integer: Integer) -> UnitPart:
]
)
else:
specification.append(UseTypeClause(self._prefix * const.TYPES_S63))
specification.append(UseTypeClause(self._prefix * const.TYPES_BASE_INT))

specification.append(
self._type_validation_function(integer.name, "Val", constraints.ada_expr())
Expand Down Expand Up @@ -777,7 +777,7 @@ def _enumeration_functions(self, enum: Enumeration) -> UnitPart:
)

if validation_expression != TRUE:
specification.append(UseTypeClause(self._prefix * const.TYPES_S63))
specification.append(UseTypeClause(self._prefix * const.TYPES_BASE_INT))

specification.append(
self._type_validation_function(
Expand Down Expand Up @@ -811,8 +811,8 @@ def _enumeration_functions(self, enum: Enumeration) -> UnitPart:
specification.append(
ExpressionFunctionDeclaration(
FunctionSpecification(
"To_S63",
self._prefix * const.TYPES_S63,
"To_Base_Int",
self._prefix * const.TYPES_BASE_INT,
[
Parameter(
["Enum"],
Expand All @@ -835,7 +835,7 @@ def _enumeration_functions(self, enum: Enumeration) -> UnitPart:
conversion_function = FunctionSpecification(
"To_Actual",
self._prefix * ID(enum.identifier),
[Parameter(["Val"], self._prefix * const.TYPES_S63)],
[Parameter(["Val"], self._prefix * const.TYPES_BASE_INT)],
)
precondition = Precondition(Call(f"Valid_{enum.name}", [Variable("Val")]))
conversion_cases: ty.List[ty.Tuple[Expr, Expr]] = []
Expand Down Expand Up @@ -869,12 +869,12 @@ def _enumeration_functions(self, enum: Enumeration) -> UnitPart:
specification.append(
ExpressionFunctionDeclaration(
FunctionSpecification(
"To_S63",
self._prefix * const.TYPES_S63,
"To_Base_Int",
self._prefix * const.TYPES_BASE_INT,
[Parameter(["Val"], self._prefix * ID(enum.identifier))],
),
If(
[(Variable("Val.Known"), Call("To_S63", [Variable("Val.Enum")]))],
[(Variable("Val.Known"), Call("To_Base_Int", [Variable("Val.Enum")]))],
Variable("Val.Raw"),
),
)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def _type_validation_function(
FunctionSpecification(
f"Valid_{type_name}",
"Boolean",
[Parameter([enum_value], self._prefix * const.TYPES_S63)],
[Parameter([enum_value], self._prefix * const.TYPES_BASE_INT)],
),
validation_expression,
)
Expand All @@ -1321,17 +1321,17 @@ def _integer_conversion_functions(self, integer: Integer) -> ty.Sequence[Subprog
return [
ExpressionFunctionDeclaration(
FunctionSpecification(
"To_S63",
self._prefix * const.TYPES_S63,
"To_Base_Int",
self._prefix * const.TYPES_BASE_INT,
[Parameter(["Val"], self._prefix * ID(integer.identifier))],
),
Call(self._prefix * const.TYPES_S63, [Variable("Val")]),
Call(self._prefix * const.TYPES_BASE_INT, [Variable("Val")]),
),
ExpressionFunctionDeclaration(
FunctionSpecification(
"To_Actual",
self._prefix * ID(integer.identifier),
[Parameter(["Val"], self._prefix * const.TYPES_S63)],
[Parameter(["Val"], self._prefix * const.TYPES_BASE_INT)],
),
Call(self._prefix * ID(integer.identifier), [Variable("Val")]),
[Precondition(Call(f"Valid_{integer.name}", [Variable("Val")]))],
Expand Down Expand Up @@ -1443,7 +1443,7 @@ def enumeration_types(enum: Enumeration) -> ty.List[Declaration]:
"Known",
[
Variant([TRUE], [Component("Enum", common.enum_name(enum))]),
Variant([FALSE], [Component("Raw", const.TYPES_S63)]),
Variant([FALSE], [Component("Raw", const.TYPES_BASE_INT)]),
],
),
)
Expand Down
32 changes: 18 additions & 14 deletions rflx/generator/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ def create_use_type_clause(composite_fields: ty.Sequence[Field], offset: bool) -
[
Pragma(
"Warnings",
[Variable("Off"), String('use clause for type "S63" * has no effect')],
[Variable("Off"), String('use clause for type "Base_Integer" * has no effect')],
),
Pragma(
"Warnings",
[
Variable("Off"),
String('"S63" is already use-visible through previous use_type_clause'),
String(
'"S63" is already use-visible through previous use_type_clause'
),
],
),
Pragma(
Expand All @@ -135,7 +137,7 @@ def create_use_type_clause(composite_fields: ty.Sequence[Field], offset: bool) -
const.TYPES_LENGTH,
const.TYPES_INDEX,
const.TYPES_BIT_INDEX,
const.TYPES_S63,
const.TYPES_BASE_INT,
*([const.TYPES_OFFSET] if offset else []),
]
],
Expand All @@ -150,12 +152,14 @@ def create_use_type_clause(composite_fields: ty.Sequence[Field], offset: bool) -
"Warnings",
[
Variable("On"),
String('"S63" is already use-visible through previous use_type_clause'),
String(
'"S63" is already use-visible through previous use_type_clause'
),
],
),
Pragma(
"Warnings",
[Variable("On"), String('use clause for type "S63" * has no effect')],
[Variable("On"), String('use clause for type "Base_Integer" * has no effect')],
),
]
)
Expand Down Expand Up @@ -234,7 +238,7 @@ def create_cursor_type() -> UnitPart:
),
Component(
"Value",
const.TYPES_S63,
const.TYPES_BASE_INT,
Number(0),
),
],
Expand Down Expand Up @@ -1296,7 +1300,7 @@ def create_valid_value_function(
"Boolean",
[
Parameter(["Fld" if scalar_fields else "Unused_Fld"], "Field"),
Parameter(["Val" if scalar_fields else "Unused_Val"], const.TYPES_S63),
Parameter(["Val" if scalar_fields else "Unused_Val"], const.TYPES_BASE_INT),
],
)

Expand Down Expand Up @@ -1516,7 +1520,7 @@ def create_field_first_function(message: Message, prefix: str) -> UnitPart:

def first(link: Link, message: Message) -> tuple[Expr, Expr]:
def substituted(
expression: expr.Expr, target_type: ty.Optional[ID] = const.TYPES_S63
expression: expr.Expr, target_type: ty.Optional[ID] = const.TYPES_BASE_INT
) -> Expr:
return (
expression.substituted(
Expand Down Expand Up @@ -1678,9 +1682,9 @@ def condition(field: Field, message: Message) -> Expr:
c: expr.Expr = expr.Or(*[l.condition for l in message.outgoing(field)])
c = c.substituted(
mapping={
expr.Size(field.name): expr.Call(const.TYPES_S63, [expr.Variable("Size")]),
expr.Size(field.name): expr.Call(const.TYPES_BASE_INT, [expr.Variable("Size")]),
expr.Last(field.name): expr.Call(
const.TYPES_S63,
const.TYPES_BASE_INT,
[
expr.Call(
"Field_Last",
Expand Down Expand Up @@ -1711,7 +1715,7 @@ def condition(field: Field, message: Message) -> Expr:
Parameter(["Ctx"], "Context"),
Parameter(["Fld"], "Field"),
*(
[Parameter(["Val"], const.TYPES_S63)]
[Parameter(["Val"], const.TYPES_BASE_INT)]
if common.has_value_dependent_condition(message)
else []
),
Expand Down Expand Up @@ -3058,7 +3062,7 @@ def _create_sufficient_buffer_length_function(message: Message, prefix: str) ->
specification,
GreaterEqual(
Call(
const.TYPES_S63,
const.TYPES_BASE_INT,
[
Add(
Call(
Expand Down Expand Up @@ -3199,13 +3203,13 @@ def func(expression: expr.Expr) -> expr.Expr:

if isinstance(field_type, Enumeration):
return expr.Call(
"To_S63",
"To_Base_Int",
[expr.Variable("Struct" * expression.identifier)],
)

if isinstance(field_type, Scalar):
return expr.Call(
const.TYPES_S63,
const.TYPES_BASE_INT,
[expr.Variable("Struct" * expression.identifier)],
)

Expand Down
4 changes: 2 additions & 2 deletions rflx/generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_get_function(
SubprogramBody(
FunctionSpecification(
"Get",
const.TYPES_S63,
const.TYPES_BASE_INT,
[Parameter(["Ctx"], "Context"), Parameter(["Fld"], "Field")],
),
[
Expand Down Expand Up @@ -371,7 +371,7 @@ def create_verify_procedure(
[
SubprogramBody(
specification,
[ObjectDeclaration(["Value"], const.TYPES_S63)],
[ObjectDeclaration(["Value"], const.TYPES_BASE_INT)],
[
IfStatement(
[
Expand Down
12 changes: 6 additions & 6 deletions rflx/generator/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def specification() -> ProcedureSpecification:
[
InOutParameter(["Ctx"], "Context"),
Parameter(["Fld"], "Field"),
Parameter(["Val"], const.TYPES_S63),
Parameter(["Val"], const.TYPES_BASE_INT),
Parameter(["Size"], const.TYPES_BIT_LENGTH),
Parameter(["State_Valid"], "Boolean"),
OutParameter(["Buffer_First"], const.TYPES_INDEX),
Expand Down Expand Up @@ -568,11 +568,11 @@ def precondition(
[
Variable("Val")
if use_enum_records_directly
else Call("To_S63", [Variable("Val")])
else Call("To_Base_Int", [Variable("Val")])
],
),
common.field_condition_call(
message, field, value=Call("To_S63", [Variable("Val")])
message, field, value=Call("To_Base_Int", [Variable("Val")])
),
common.sufficient_space_for_field_condition(Variable(field.affixed_name)),
)
Expand Down Expand Up @@ -619,7 +619,7 @@ def body(
[
Variable("Ctx"),
Variable(field.affixed_name),
Call("To_S63", [Variable("Val")]),
Call("To_Base_Int", [Variable("Val")]),
],
),
],
Expand Down Expand Up @@ -663,7 +663,7 @@ def body(
[
InOutParameter(["Ctx"], "Context"),
Parameter(["Fld"], "Field"),
Parameter(["Val"], const.TYPES_S63),
Parameter(["Val"], const.TYPES_BASE_INT),
],
),
[
Expand Down Expand Up @@ -749,7 +749,7 @@ def body(
common.sufficient_space_for_field_condition(Variable("Fld")),
In(
Call("Field_Size", [Variable("Ctx"), Variable("Fld")]),
ValueRange(Number(1), Size(const.TYPES_S63)),
ValueRange(Number(1), Size(const.TYPES_BASE_INT)),
),
Call(
const.TYPES * "Fits_Into",
Expand Down
2 changes: 1 addition & 1 deletion rflx/templates/rflx_builtin_types-conversions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ is
when others =>
False);

function To_S63 (Enum : Boolean) return {prefix}RFLX_Arithmetic.S63 is
function To_Base_Int (Enum : Boolean) return {prefix}RFLX_Arithmetic.S63 is
treiher marked this conversation as resolved.
Show resolved Hide resolved
(case Enum is
when False =>
0,
Expand Down
Loading