SILICON
Loading...
Searching...
No Matches
num_formatting.hpp File Reference
#include <core/wire.hpp>
#include <cstddef>
#include <optional>
#include <string>
#include <string_view>
#include <boost/multiprecision/cpp_int.hpp>
Include dependency graph for num_formatting.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ParsedBusValue
 A bit-vector together with the textual interpretation that produced it. More...

Namespaces

namespace  SILICON
namespace  SILICON::core

Typedefs

using BigInt = boost::multiprecision::cpp_int

Enumerations

enum class  BusValueFormat {
  Raw , Signed , Unsigned , Hex ,
  Oct , Bin , Unknown
}

Functions

std::string formatValue (const BusValue &value, BusValueFormat format, std::size_t fixedWidth=0)
 Format an LSB-first BusValue for display.
std::string formatInteger (const BigInt &value, const BusValueFormat format, const std::size_t bitWidth)
std::optional< BigInt > parseInteger (std::string_view text, const BusValueFormat format, const std::size_t bitWidth)
ParsedBusValue valueFromStr (std::string_view text)
 Parse user-facing decimal, hexadecimal, octal, binary, or four-state text.
std::optional< BusValue > resizeParsedValue (const ParsedBusValue &parsed, std::size_t width)
 Adapts a parsed textual value to an exact destination width.
BusValue maxValueForBusWidth (const std::size_t width)
BusValue busValueFromInteger (const BigInt &value, std::size_t width)
 Builds an LSB-first BusValue from the low width bits of an integer. Negative values use two's complement and sign extension; nonnegative values use zero extension. Values are truncated to width bits; zero width is empty.
BigInt integerFromBusValue (const BusValue &value, Signedness signedness=Signedness::UNSIGNED)
 Decodes an LSB-first BusValue as an unsigned arbitrary-precision integer. Empty values yield zero. UNKNOWN or ERROR bits throw std::invalid_argument.
BusValue busValueFromBits (std::string_view bits)
 Strictly decodes an MSB-first raw string containing 0, 1, X, or E.