-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New classes provide useful abstractions, such as le_bitrange/nw_bitrange.
- Loading branch information
Showing
6 changed files
with
833 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
set (IR_SRCS | ||
base.cpp | ||
bitrange.cpp | ||
dbprint.cpp | ||
dbprint-expression.cpp | ||
dbprint-stmt.cpp | ||
|
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,32 @@ | ||
/* | ||
Copyright 2024 Intel Corp. | ||
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 "ir/bitrange.h" | ||
|
||
#include "ir/json_generator.h" | ||
#include "ir/json_loader.h" | ||
|
||
void registerRangeJsonHelpers() { | ||
RangeJsonHelpers::rangeToJSON = [](JSONGenerator &json, int lo, int hi) -> void { | ||
json.toJSON(std::make_pair(lo, hi)); | ||
}; | ||
|
||
RangeJsonHelpers::rangeFromJSON = [](JSONLoader &json) -> std::pair<int, int> { | ||
std::pair<int, int> endpoints; | ||
json >> endpoints; | ||
return endpoints; | ||
}; | ||
} |
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,32 @@ | ||
/* | ||
Copyright 2024 Intel Corp. | ||
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 IR_BITRANGE_H_ | ||
#define IR_BITRANGE_H_ | ||
|
||
#include "lib/bitrange.h" | ||
|
||
/// Register helper functions for HalfOpenRange/ClosedRange JSON serialization/deserialization. | ||
/// | ||
/// These functions can't be defined in lib/bitrange.cpp because lib is compiled before the IR | ||
/// generator runs, preventing the use of JSONGenerator/JSONLoader. Instead, lib/bitrange.cpp | ||
/// defines a pair of placeholder functions that call BUG if called. | ||
/// | ||
/// This function does not need to be invoked if HalfOpenRange/ClosedRange objects are never | ||
/// serialized. | ||
void registerRangeJsonHelpers(); | ||
|
||
#endif /* IR_BITRANGE_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2024 Intel Corp. | ||
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 "lib/bitrange.h" | ||
|
||
#include <iostream> | ||
#include <utility> | ||
|
||
RangeToJSONHandler RangeJsonHelpers::rangeToJSON = ::rangeToJSON; | ||
RangeFromJSONHandler RangeJsonHelpers::rangeFromJSON = ::rangeFromJSON; | ||
|
||
// See ir/bitrange.h:registerRangeJsonHelpers() | ||
void rangeToJSON(JSONGenerator &, int, int) { BUG("Unimplemented rangeToJSON functionality"); } | ||
|
||
// See ir/bitrange.h:registerRangeJsonHelpers() | ||
std::pair<int, int> rangeFromJSON(JSONLoader &) { | ||
BUG("Unimplemented rangeFromJSON functionality"); | ||
return std::make_pair(-1, -1); | ||
} | ||
|
||
std::ostream &toStream(std::ostream &out, RangeUnit unit, Endian order, int lo, int hi, | ||
bool closed) { | ||
if (unit == RangeUnit::Bit) | ||
out << "bit"; | ||
else if (unit == RangeUnit::Byte) | ||
out << "byte"; | ||
else | ||
BUG("unknown range unit"); | ||
|
||
out << (!closed && order == Endian::Little ? "(" : "["); | ||
|
||
if (order == Endian::Little) std::swap(lo, hi); | ||
|
||
out << std::dec << lo; | ||
if (lo != hi) out << ".." << hi; | ||
|
||
out << (!closed && order == Endian::Network ? ")" : "]"); | ||
|
||
return out; | ||
} |
Oops, something went wrong.