This repository has been archived by the owner on Aug 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Sampler descriptor #195
Merged
Merged
Sampler descriptor #195
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e1f83b
Factor CMakeLists backend ProcTable generation
Kangz 632e4f0
Factor autogen validation utilities out of ProcTable
Kangz 7ea1dee
Make WireTests not rely on SamplerBuilder
Kangz 40ec358
generator: Add support for structure of non-object values
Kangz 41988d8
Change Sampler creation to use a descriptor instead of a builder
Kangz 446af59
WireTests: introduce a MatchesLambda GMock helper
Kangz 8f6168a
WireTests: Add a test for sending structs of non-object values
Kangz af2c6fc
Add a GetDefaultSamplerDescriptor helper.
Kangz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,19 @@ def __init__(self, name, record): | |
self.native_methods = [] | ||
self.built_type = None | ||
|
||
class StructureMember: | ||
def __init__(self, name, typ, annotation): | ||
self.name = name | ||
self.type = typ | ||
self.annotation = annotation | ||
self.length = None | ||
|
||
class StructureType(Type): | ||
def __init__(self, name, record): | ||
Type.__init__(self, name, record) | ||
self.extensible = record.get("extensible", False) | ||
self.members = [] | ||
|
||
############################################################ | ||
# PARSE | ||
############################################################ | ||
|
@@ -112,9 +125,13 @@ def make_method(record): | |
arguments_by_name[arg.name.canonical_case()] = arg | ||
|
||
for (arg, a) in zip(arguments, record.get('args', [])): | ||
assert(arg.annotation == 'value' or 'length' in a) | ||
if arg.annotation != 'value': | ||
if a['length'] == 'strlen': | ||
if not 'length' in a: | ||
if arg.type.category == 'structure': | ||
arg.length = "constant_one" | ||
else: | ||
assert(false) | ||
elif a['length'] == 'strlen': | ||
arg.length = 'strlen' | ||
else: | ||
arg.length = arguments_by_name[a['length']] | ||
|
@@ -133,13 +150,21 @@ def make_method(record): | |
break | ||
assert(obj.built_type != None) | ||
|
||
def link_structure(struct, types): | ||
def make_member(m): | ||
return StructureMember(Name(m['name']), types[m['type']], m.get('annotation', 'value')) | ||
|
||
# TODO([email protected]): Handle pointer members and their length | ||
struct.members = [make_member(m) for m in struct.record['members']] | ||
|
||
def parse_json(json): | ||
category_to_parser = { | ||
'bitmask': BitmaskType, | ||
'enum': EnumType, | ||
'native': NativeType, | ||
'natively defined': NativelyDefined, | ||
'object': ObjectType, | ||
'structure': StructureType, | ||
} | ||
|
||
types = {} | ||
|
@@ -159,6 +184,9 @@ def parse_json(json): | |
for obj in by_category['object']: | ||
link_object(obj, types) | ||
|
||
for struct in by_category['structure']: | ||
link_structure(struct, types) | ||
|
||
for category in by_category.keys(): | ||
by_category[category] = sorted(by_category[category], key=lambda typ: typ.name.canonical_case()) | ||
|
||
|
@@ -434,7 +462,11 @@ def main(): | |
backend_params = { | ||
'namespace': backend, | ||
} | ||
renders.append(FileRender('BackendProcTable.cpp', backend + '/ProcTable.' + extension, base_backend_params + [backend_params])) | ||
renders.append(FileRender('backend/ProcTable.cpp', 'backend/' + backend + '/ProcTable.' + extension, base_backend_params + [backend_params])) | ||
|
||
if 'backend_utils' in targets: | ||
renders.append(FileRender('backend/ValidationUtils.h', 'backend/ValidationUtils_autogen.h', base_backend_params)) | ||
renders.append(FileRender('backend/ValidationUtils.cpp', 'backend/ValidationUtils_autogen.cpp', base_backend_params)) | ||
|
||
if 'wire' in targets: | ||
renders.append(FileRender('wire/WireCmd.h', 'wire/WireCmd_autogen.h', base_backend_params)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//* Copyright 2018 The NXT Authors | ||
//* | ||
//* Licensed under the Apache License, Version 2.0 (the "License"); | ||
//* you may not use this file except in compliance with the License. | ||
//* You may obtain a copy of the License at | ||
//* | ||
//* http://www.apache.org/licenses/LICENSE-2.0 | ||
//* | ||
//* Unless required by applicable law or agreed to in writing, software | ||
//* distributed under the License is distributed on an "AS IS" BASIS, | ||
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
//* See the License for the specific language governing permissions and | ||
//* limitations under the License. | ||
|
||
#include "backend/ValidationUtils_autogen.h" | ||
|
||
namespace backend { | ||
|
||
{% for type in by_category["enum"] %} | ||
bool IsValid{{type.name.CamelCase()}}(nxt::{{as_cppType(type.name)}} value) { | ||
switch (value) { | ||
{% for value in type.values %} | ||
case nxt::{{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}: | ||
return true; | ||
{% endfor %} | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
{% endfor %} | ||
|
||
{% for type in by_category["bitmask"] %} | ||
bool IsValid{{type.name.CamelCase()}}(nxt::{{as_cppType(type.name)}} value) { | ||
return (value & static_cast<nxt::{{as_cppType(type.name)}}>(~{{type.full_mask}})) == 0; | ||
} | ||
|
||
{% endfor %} | ||
|
||
} // namespace backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//* Copyright 2018 The NXT Authors | ||
//* | ||
//* Licensed under the Apache License, Version 2.0 (the "License"); | ||
//* you may not use this file except in compliance with the License. | ||
//* You may obtain a copy of the License at | ||
//* | ||
//* http://www.apache.org/licenses/LICENSE-2.0 | ||
//* | ||
//* Unless required by applicable law or agreed to in writing, software | ||
//* distributed under the License is distributed on an "AS IS" BASIS, | ||
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
//* See the License for the specific language governing permissions and | ||
//* limitations under the License. | ||
|
||
#ifndef BACKEND_VALIDATIONUTILS_H_ | ||
#define BACKEND_VALIDATIONUTILS_H_ | ||
|
||
#include "nxt/nxtcpp.h" | ||
|
||
namespace backend { | ||
|
||
// Helper functions to check the value of enums and bitmasks | ||
{% for type in by_category["enum"] + by_category["bitmask"] %} | ||
bool IsValid{{type.name.CamelCase()}}(nxt::{{as_cppType(type.name)}} value); | ||
{% endfor %} | ||
|
||
} // namespace backend | ||
|
||
#endif // BACKEND_VALIDATIONUTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be a "<" since our enums should be contiguous? Maybe with some extra asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping that the switch would be future proof for when we start to have sparse enums for extensions. Compilers do a good job of optimizing this pattern when it is dense, see https://godbolt.org/g/HjWVZH
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.