Skip to content

Commit b939be2

Browse files
authored
Merge pull request #511 from pbalcer/params-cleanups
small changes for params pretty printing
2 parents 620ddb1 + 5584776 commit b939be2

File tree

11 files changed

+450
-394
lines changed

11 files changed

+450
-394
lines changed

scripts/templates/helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def is_flags(cls, name):
148148
except:
149149
return False
150150

151+
@classmethod
152+
def get_flag_type(cls, name):
153+
return re.sub(r"(\w+)_flags_t", r"\1_flag_t", name)
154+
151155
@staticmethod
152156
def is_known(name, meta):
153157
try:

scripts/templates/params.hpp.mako

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from templates import helper as th
2727
%if iname == "pNext":
2828
${x}_params::serializeStruct(os, ${caller.body()});
2929
%elif th.type_traits.is_flags(itype):
30-
${x}_params::serializeFlag_${itype}(os, ${caller.body()});
30+
${x}_params::serializeFlag<${th.type_traits.get_flag_type(itype)}>(os, ${caller.body()});
3131
%elif not loop and th.type_traits.is_pointer(itype):
3232
${x}_params::serializePtr(os, ${caller.body()});
3333
%elif loop and th.type_traits.is_pointer_to_pointer(itype):
@@ -57,7 +57,7 @@ from templates import helper as th
5757
%endif
5858
## can't iterate over 'void *'...
5959
%if th.param_traits.is_range(item) and "void*" not in itype:
60-
os << ".${iname} = [";
60+
os << ".${iname} = {";
6161
for (size_t i = ${th.param_traits.range_start(item)}; ${deref}(params${access}${pname}) != NULL && i < ${deref}params${access}${prefix + th.param_traits.range_end(item)}; ++i) {
6262
if (i != 0) {
6363
os << ", ";
@@ -66,10 +66,10 @@ from templates import helper as th
6666
(${deref}(params${access}${pname}))[i]
6767
</%call>
6868
}
69-
os << "]";
69+
os << "}";
7070
%elif typename is not None:
7171
os << ".${iname} = ";
72-
${x}_params::serializeTaggedTyped_${underlying_type}(os, ${deref}(params${access}${pname}), ${deref}(params${access}${prefix}${typename}), ${deref}(params${access}${prefix}${typename_size}));
72+
${x}_params::serializeTagged(os, ${deref}(params${access}${pname}), ${deref}(params${access}${prefix}${typename}), ${deref}(params${access}${prefix}${typename_size}));
7373
%else:
7474
os << ".${iname} = ";
7575
<%call expr="member(iname, itype, False)">
@@ -80,19 +80,23 @@ from templates import helper as th
8080

8181
namespace ${x}_params {
8282
template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
83+
template <typename T> inline void serializeFlag(std::ostream &os, uint32_t flag);
84+
template <typename T> inline void serializeTagged(std::ostream &os, const void *ptr, T value, size_t size);
8385

8486
%for spec in specs:
8587
%for obj in spec['objects']:
8688
## ENUM #######################################################################
8789
%if re.match(r"enum", obj['type']):
8890
%if obj.get('typed_etors', False) is True:
89-
inline void serializeTaggedTyped_${th.make_enum_name(n, tags, obj)}(std::ostream &os, const void *ptr, enum ${th.make_enum_name(n, tags, obj)} value, size_t size);
91+
template <> inline void serializeTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size);
9092
%elif "structure_type" in obj['name']:
9193
inline void serializeStruct(std::ostream &os, const void *ptr);
9294
%endif
9395
%endif
96+
97+
9498
%if th.type_traits.is_flags(obj['name']):
95-
inline void serializeFlag_${th.make_type_name(n, tags, obj)}(std::ostream &os, ${th.make_type_name(n, tags, obj)} flag);
99+
template<> inline void serializeFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag);
96100
%endif
97101
%endfor # obj in spec['objects']
98102
%endfor
@@ -138,7 +142,8 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
138142
%endif
139143
%if obj.get('typed_etors', False) is True:
140144
namespace ${x}_params {
141-
inline void serializeTaggedTyped_${th.make_enum_name(n, tags, obj)}(std::ostream &os, const void *ptr, enum ${th.make_enum_name(n, tags, obj)} value, size_t size) {
145+
template <>
146+
inline void serializeTagged(std::ostream &os, const void *ptr, ${th.make_enum_name(n, tags, obj)} value, size_t size) {
142147
if (ptr == NULL) {
143148
serializePtr(os, ptr);
144149
return;
@@ -157,7 +162,7 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
157162
%if "char" in atype: ## print char* arrays as simple NULL-terminated strings
158163
serializePtr(os, tptr);
159164
%else:
160-
os << "[";
165+
os << "{";
161166
size_t nelems = size / sizeof(${atype});
162167
for (size_t i = 0; i < nelems; ++i) {
163168
if (i != 0) {
@@ -167,7 +172,7 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
167172
tptr[i]
168173
</%call>
169174
}
170-
os << "]";
175+
os << "}";
171176
%endif
172177
%else:
173178
const ${vtype} *tptr = (const ${vtype} *)ptr;
@@ -218,7 +223,9 @@ template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
218223
%endif
219224
%if th.type_traits.is_flags(obj['name']):
220225
namespace ${x}_params {
221-
inline void serializeFlag_${th.make_type_name(n, tags, obj)}(std::ostream &os, ${th.make_type_name(n, tags, obj)} flag) {
226+
227+
template<>
228+
inline void serializeFlag<${th.make_enum_name(n, tags, obj)}>(std::ostream &os, uint32_t flag) {
222229
uint32_t val = flag;
223230
bool first = true;
224231
%for n, item in enumerate(obj['etors']):

source/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_library(${PROJECT_NAME}::common ALIAS ur_common)
66

77
target_include_directories(ur_common INTERFACE
88
${CMAKE_CURRENT_SOURCE_DIR}
9+
${CMAKE_SOURCE_DIR}/include
910
)
1011

1112
add_subdirectory(unified_memory_allocation)

0 commit comments

Comments
 (0)