3from .Attribute
import Attribute
4from .Boolean
import Boolean
11 Represent an array of boolean flags
13 Consult the constructor on details onto which C++ data these flags
24 qualifier=Attribute.Qualifier.NONE,
29 C++ offers the bitset to accommodate an array of boolean flags. While
30 a bitset provides a memory-efficient way to encode a set of booleans,
31 it is not efficient if we use it in combination with other booleans or
32 other bitsets, as the C++ compiler will insert empty bits to align
33 each attribute at least with a byte.
35 Our LLVM modification can eliminate these fill-in bits, but it does
36 not natively support bitsets (as we, in general, do not cover stuff
37 from the standard library). If you want to use the extension, you have
38 to model the bitset as an array of booleans natively.
45 Without compression (default), map array onto bitet. Otherwise,
46 use native array of boolean.
49 if qualifier != Attribute.Qualifier.NONE:
50 raise NotImplementedError(
51 f
"Attribute {name}: This data type can't work with qualifiers (yet)"
53 if initval
is not None:
54 raise NotImplementedError(
55 f
"Attribute {name}: Can't generate arrays with initial values (yet)."
58 self, name, ifdefs=ifdefs, qualifier=qualifier, initval=initval
63 def get_methods(self, _full_qualified_class_name, for_declaration=True):
67 "get" + accessor_name +
"() const",
73 +
"(const std::bitset<"
78 (
"get" + accessor_name +
"(int index) const",
"bool"),
79 (
"set" + accessor_name +
"(int index, bool value)",
"void"),
80 (
"flip" + accessor_name +
"(int index)",
"void"),
90 [
"defined(" + LLVMSymbol +
")"],
96 [
"!defined(" + LLVMSymbol +
")"],
110 if signature.startswith(
"flip")
and "index" in signature
and self.
compresscompress:
111 return name +
"[index] = not " + name +
"[index];\n"
112 if signature.startswith(
"flip")
and "index" in signature:
113 return name +
".flip(index);\n"
114 elif signature.startswith(
"get")
and "index" in signature:
115 return " return " + name +
"[index];\n"
116 elif signature.startswith(
"set")
and "index" in signature:
117 return name +
"[index] = value;\n"
120 std::bitset<{}> result;
121 for (int i=0; i<{}; i++) result[i] = {}[i];
126 elif signature.startswith(
"get"):
127 return " return " + name +
";\n"
138 elif signature.startswith(
"set"):
139 return name +
" = value;\n"
145 return [(
"MPI_UNSIGNED_LONG", 1)]
156 Return string representation of attribute.
Represent an array of boolean flags.
get_to_string(self)
Return string representation of attribute.
get_first_plain_C_attribute(self)
For MPI for example, I need to know the first attribute.
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
__init__(self, name, cardinality, compress=False, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
C++ offers the bitset to accommodate an array of boolean flags.
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
get_native_MPI_type(self)
I originally wanted to map the booleans to MPI_CXX_BOOL.
get_constructor_arguments(self)
Return list of tuple of arguments for the constructor.
use_default_copy_constructor(self)
If this routine returns False, the generator will create a copy constructor copying each attribute ov...
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.