slang-netlist  0.9.0
Loading...
Searching...
No Matches
DriverBitRange.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "slang/numeric/ConstantValue.h"
4#include "slang/util/Util.h"
5
6#include <cstdint>
7#include <fmt/format.h>
8#include <optional>
9#include <string>
10
11namespace slang::netlist {
12
14struct DriverBitRange : public ConstantRange {
15 using ConstantRange::ConstantRange;
16
17 auto toPair() const -> std::pair<int32_t, int32_t> {
18 return {lower(), upper()};
19 }
20
23 [[nodiscard]] auto isContiguousWith(DriverBitRange other) const -> bool {
24 return upper() + 1 >= other.lower() && other.upper() + 1 >= lower();
25 }
26
29 [[nodiscard]] auto unionWith(DriverBitRange other) const -> DriverBitRange {
30 SLANG_ASSERT(isContiguousWith(other));
31 return {std::min(lower(), other.lower()), std::max(upper(), other.upper())};
32 }
33
36 [[nodiscard]] auto intersection(DriverBitRange other) const
37 -> std::optional<DriverBitRange> {
38 if (!overlaps(other)) {
39 return std::nullopt;
40 }
41 return DriverBitRange{std::max(lower(), other.lower()),
42 std::min(upper(), other.upper())};
43 }
44};
45
46static inline auto toString(DriverBitRange const &range) -> std::string {
47 if (range.lower() == range.upper()) {
48 return fmt::format("[{}]", range.lower());
49 }
50 return fmt::format("[{}:{}]", range.upper(), range.lower());
51}
52
53static inline auto toString(std::pair<int32_t, int32_t> bounds) -> std::string {
54 return toString(DriverBitRange{bounds.first, bounds.second});
55}
56
57} // namespace slang::netlist
Definition Utilities.hpp:16
A range over which a symbol is driven.
Definition DriverBitRange.hpp:14
auto toPair() const -> std::pair< int32_t, int32_t >
Definition DriverBitRange.hpp:17
auto intersection(DriverBitRange other) const -> std::optional< DriverBitRange >
Definition DriverBitRange.hpp:36
auto unionWith(DriverBitRange other) const -> DriverBitRange
Definition DriverBitRange.hpp:29
auto isContiguousWith(DriverBitRange other) const -> bool
Definition DriverBitRange.hpp:23