Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions compiler/back_end/cpp/header_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,20 @@ def _offset_storage_adapter(buffer_type, alignment, static_offset):

def _bytes_to_bits_convertor(buffer_type, byte_order, size):
assert byte_order, "byte_order should not be empty."
return "{}::BitBlock</**/{}::{}ByteOrderer<typename {}>, {}>".format(
_SUPPORT_NAMESPACE, _SUPPORT_NAMESPACE, byte_order, buffer_type, size
)
if size > 64:
# For wide bits (>64 bits), use the specialized WideBitBlock classes
return "{}::{}WideBitBlock</**/{}::{}ByteOrderer<typename {}>, {}>".format(
_SUPPORT_NAMESPACE,
byte_order,
_SUPPORT_NAMESPACE,
byte_order,
buffer_type,
size,
)
else:
return "{}::BitBlock</**/{}::{}ByteOrderer<typename {}>, {}>".format(
_SUPPORT_NAMESPACE, _SUPPORT_NAMESPACE, byte_order, buffer_type, size
)


def _get_fully_qualified_namespace(name, ir):
Expand Down
15 changes: 4 additions & 11 deletions compiler/front_end/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _check_allowed_in_bits(type_ir, type_definition, source_file_name, ir, error


def _check_size_of_bits(type_ir, type_definition, source_file_name, errors):
"""Checks that `bits` types are fixed size, less than 64 bits."""
"""Checks that `bits` types are fixed size."""
del type_ir # Unused
if type_definition.addressable_unit != ir_data.AddressableUnit.BIT:
return
Expand All @@ -508,16 +508,9 @@ def _check_size_of_bits(type_ir, type_definition, source_file_name, errors):
]
)
return
if fixed_size > 64:
errors.append(
[
error.error(
source_file_name,
type_definition.source_location,
"`bits` types must be 64 bits or smaller.",
)
]
)
# Note: We allow bits types wider than 64 bits. Individual integer fields
# within the bits type are still limited to 64 bits by the type constraints
# in prelude.emb (UInt, Int, Bcd are all limited to 64 bits).


_RESERVED_WORDS = None
Expand Down
23 changes: 8 additions & 15 deletions compiler/front_end/constraints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,23 +1010,16 @@ def test_bits_must_be_fixed_size(self):
error.filter_errors(constraints.check_constraints(ir)),
)

def test_bits_must_be_small(self):
def test_wide_bits_allowed(self):
# bits types wider than 64 bits are allowed as long as they're
# fixed size. Individual fields are still limited to 64 bits.
ir = _make_ir_from_emb(
"bits Big:\n" " 0 [+64] UInt x\n" " 64 [+1] UInt y\n"
)
error_type = ir.module[0].type[0]
self.assertEqual(
[
[
error.error(
"m.emb",
error_type.source_location,
"`bits` types must be 64 bits or smaller.",
)
]
],
error.filter_errors(constraints.check_constraints(ir)),
"bits WideBits:\n"
" 0 [+64] UInt first_64\n"
" 64 [+64] UInt second_64\n"
" 128 [+64] UInt third_64\n"
)
self.assertEqual([], error.filter_errors(constraints.check_constraints(ir)))

def test_constant_expressions_must_be_small(self):
ir = _make_ir_from_emb(
Expand Down
Loading