-
Notifications
You must be signed in to change notification settings - Fork 445
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
Fix for issue #133 #135
Closed
Closed
Fix for issue #133 #135
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7e96c63
Fix for issue #130
c319386
Fix for issue #133: implement nested structure copying
8f9c46f
Merge remote-tracking branch 'upstream/master'
b001773
Fixed copyright
815ac15
removed junk file
55dbf36
Fix for issue ##136
787c254
Fix for issue #137
9bd3df8
Fix for issue #138
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2016 VMware, Inc. | ||
|
||
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 "copyStructures.h" | ||
|
||
namespace BMV2 { | ||
|
||
const IR::Node* DoCopyStructures::postorder(IR::AssignmentStatement* statement) { | ||
auto ltype = typeMap->getType(statement->left, true); | ||
if (!ltype->is<IR::Type_StructLike>()) | ||
return statement; | ||
|
||
auto retval = new IR::Vector<IR::StatOrDecl>(); | ||
auto strct = ltype->to<IR::Type_StructLike>(); | ||
if (statement->right->is<IR::ListExpression>()) { | ||
auto list = statement->right->to<IR::ListExpression>(); | ||
unsigned index = 0; | ||
for (auto f : *strct->fields) { | ||
auto right = list->components->at(index); | ||
auto left = new IR::Member(Util::SourceInfo(), statement->left, f->name); | ||
retval->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); | ||
index++; | ||
} | ||
} else { | ||
if (ltype->is<IR::Type_Header>()) | ||
// Leave headers as they are -- copy_header will also copy the valid bit | ||
return statement; | ||
|
||
for (auto f : *strct->fields) { | ||
auto right = new IR::Member(Util::SourceInfo(), statement->right, f->name); | ||
auto left = new IR::Member(Util::SourceInfo(), statement->left, f->name); | ||
retval->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); | ||
} | ||
} | ||
|
||
return retval; | ||
} | ||
|
||
} // namespace BMV2 |
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,46 @@ | ||
/* | ||
Copyright 2016 VMware, Inc. | ||
|
||
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 _BACKENDS_BMV2_COPYSTRUCTURES_H_ | ||
#define _BACKENDS_BMV2_COPYSTRUCTURES_H_ | ||
|
||
#include "ir/ir.h" | ||
#include "frontends/p4/typeChecking/typeChecker.h" | ||
|
||
namespace BMV2 { | ||
|
||
// Convert assignments between structures to assignments between fields | ||
class DoCopyStructures : public Transform { | ||
P4::TypeMap* typeMap; | ||
public: | ||
explicit DoCopyStructures(P4::TypeMap* typeMap) : typeMap(typeMap) | ||
{ CHECK_NULL(typeMap); setName("DoCopyStructures"); } | ||
const IR::Node* postorder(IR::AssignmentStatement* statement) override; | ||
}; | ||
|
||
class CopyStructures : public PassRepeated { | ||
public: | ||
CopyStructures(P4::ReferenceMap* refMap, P4::TypeMap* typeMap) : | ||
PassManager({}) { | ||
CHECK_NULL(refMap); CHECK_NULL(typeMap); setName("CopyStructures"); | ||
passes.emplace_back(new P4::TypeChecking(refMap, typeMap)); | ||
passes.emplace_back(new DoCopyStructures(typeMap)); | ||
} | ||
}; | ||
|
||
} // namespace BMV2 | ||
|
||
#endif /* _BACKENDS_BMV2_COPYSTRUCTURES_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
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,19 @@ | ||
#include "validateProperties.h" | ||
|
||
namespace BMV2 { | ||
|
||
void ValidateTableProperties::postorder(const IR::TableProperty* property) { | ||
static cstring knownProperties[] = { | ||
"actions", | ||
"default_action", | ||
"key", | ||
"implementation", | ||
"size" | ||
}; | ||
for (size_t i=0; i < ELEMENTS(knownProperties); i++) | ||
if (property->name.name == knownProperties[i]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer
|
||
return; | ||
::warning("Unknown table property: %1%", property); | ||
} | ||
|
||
} // namespace BMV2 |
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,35 @@ | ||
/* | ||
Copyright 2016 VMware, Inc. | ||
|
||
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 _BACKENDS_BMV2_VALIDATEPROPERTIES_H_ | ||
#define _BACKENDS_BMV2_VALIDATEPROPERTIES_H_ | ||
|
||
#include "ir/ir.h" | ||
#include "frontends/p4/typeMap.h" | ||
|
||
namespace BMV2 { | ||
|
||
// Checks to see if there are any unknown properties. | ||
class ValidateTableProperties : public Inspector { | ||
public: | ||
ValidateTableProperties() | ||
{ setName("ValidateTableProperties"); } | ||
void postorder(const IR::TableProperty* property) override; | ||
}; | ||
|
||
} // namespace BMV2 | ||
|
||
#endif /* _BACKENDS_BMV2_VALIDATEPROPERTIES_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
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
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.
Shouldn't this be a preorder so that assignments of nested structs will get flattened properly too? However, that would likely require fixing the code to use and maintain the types in the expression nodes properly, rather than the typeMap, which will be out of date after the first flattening.