slang namespace

Root namespace.

Namespaces

namespace ast
The SystemVerilog AST.
namespace driver
Frontend tool driver.
namespace parsing
Lexing, preprocessing, and parsing functionality.
namespace syntax
Syntax tree manipulation.

Classes

struct AssociativeArray
Represents a SystemVerilog associative array, for use during constant evaluation.
class Bag
template<typename T>
class bitmask
struct BufferID
class BumpAllocator
class CommandLine
struct ConstantRange
class ConstantValue
template<typename T>
class CopyPtr
class CVConstIterator
class CVIterator
class DiagCode
A compact code that represents a diagnostic.
class Diagnostic
Wraps up a reported diagnostic along with location in source and any arguments.
class DiagnosticEngine
class Diagnostics
A collection of diagnostics.
template<typename Fn>
class function_ref
template<typename TKey, typename TValue>
class IntervalMap
A data structure that maps from intervals (closed ranges) to values.
template<typename DerivedT, typename IteratorCategoryT, typename T, typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T*, typename ReferenceT = T&>
class iterator_facade
template<typename TIterator>
class iterator_range
A range represented by an interator pair, begin and end.
class JsonWriter
struct logic_t
template<typename T>
class not_null
class OS
A collection of various OS-specific utility functions.
template<typename TPointer, uint32_t IntBits, uint32_t LowBitsAvailable, typename TInt = uint32_t>
class PointerIntPair
template<typename T, size_t Size = sizeof(T), size_t Align = alignof(T)>
class PoolAllocator
A simple pool allocator built on top of a bump allocator.
struct real_t
template<typename T, typename Index>
class SafeIndexedVector
template<typename F>
class ScopeGuard
struct shortreal_t
template<typename K, typename V, size_t N, typename Entry = std::pair<const K, V>, typename Alloc = detail::hashing::StackAllocator<Entry, N* sizeof(Entry)>>
class SmallMap
template<typename T, size_t N, typename Alloc = detail::hashing::StackAllocator<T, N* sizeof(T)>>
class SmallSet
template<typename T, size_t N = detail::calculateDefaultSmallVectorElems<T>()>
class SmallVector
template<typename T>
class SmallVectorBase
Base class for a fast growable array.
struct SourceBuffer
class SourceLocation
class SourceManager
class SourceRange
Combines a pair of source locations that denote a range of source text.
class SVInt
class SVIntStorage
struct SVQueue
Represents a SystemVerilog queue, for use during constant evaluation.
struct SVUnion
Represents a SystemVerilog unpacked union, for use during constant evaluation.
class ThreadPool
A lightweight thread pool for running concurrent jobs.
struct TimeScale
struct TimeScaleValue
A combination of a unit and magnitude for a time scale value.
class TimeTrace
class TimeTraceScope
class type_index
template<typename T>
class TypedBumpAllocator
struct UninitializedTag
class VersionInfo
Provides access to compile-time generated version info about the library.

Enums

enum class TimeScaleMagnitude: uint8_t { One = 1, Ten = 10, Hundred = 100 }

Typedefs

using bitwidth_t = uint32_t
A type that can represent the largest possible bit width of a SystemVerilog integer.

Functions

auto checkedAddS32(int32_t a, int32_t b) -> std::optional<int32_t>
auto checkedSubS32(int32_t a, int32_t b) -> std::optional<int32_t>
auto checkedMulU32(uint32_t a, uint32_t b) -> std::optional<uint32_t>
auto literalBaseFromChar(char base, LiteralBase& result) -> bool
Specifies the base of an integer (for converting to/from a string)
auto clog2(const SVInt& v) -> uint32_t
Returns the ceiling of the log_2 of the value. If value is zero, returns zero.
auto suffixToTimeUnit(std::string_view timeSuffix, size_t& lengthConsumed) -> std::optional<TimeUnit>
Scale unit for a time value.
auto isASCII(char c) -> bool constexpr
Returns whether the given character is a valid ASCII character.
auto isPrintableASCII(char c) -> bool constexpr
Returns whether the given character is considered "printable".
auto isPrintableUnicode(uint32_t c) -> bool
auto charWidthUnicode(uint32_t c) -> int
auto isWhitespace(char c) -> bool constexpr
Returns whether the given character is considered whitespace.
auto isNewline(char c) -> bool constexpr
Returns whether the given character is considered a new line.
auto isDecimalDigit(char c) -> bool constexpr
Returns whether the given character is considered a decimal digit.
auto isOctalDigit(char c) -> bool constexpr
Returns whether the given character is considered an octal digit.
auto isHexDigit(char c) -> bool constexpr
Returns whether the given character is considered a hexadecimal digit.
auto isBinaryDigit(char c) -> bool constexpr
Returns whether the given character is considered a binary digit.
auto isAlphaNumeric(char c) -> bool constexpr
Returns whether the given character is considered an alphanumeric character.
auto isValidCIdChar(char c) -> bool constexpr
auto isBase64Char(char c) -> bool constexpr
Returns whether the given characrer is a valid in base64 encoding.
auto isLogicDigit(char c) -> bool constexpr
auto getDigitValue(char c) -> uint8_t constexpr
auto getHexDigitValue(char c) -> uint8_t constexpr
auto getHexForDigit(uint32_t num, bool lowerCase = false) -> char constexpr
Gets the hexadecimal character for the given number (which should be less than 16).
auto utf8Len(unsigned char first) -> int constexpr
auto utf8Decode(const char* b, uint32_t* c, int* e) -> const char* constexpr
template<typename T, typename... Rest>
void hash_combine(size_t& seed, const T& v, Rest... rest)
template<typename T>
auto make_range(T begin, T end) -> iterator_range<T>
Constructs an iterator_range from two provided iterators (inferring the types involved).
template<typename TContainer>
auto make_reverse_range(TContainer&& container) -> auto
template<typename TGenerator, typename TValue>
static auto getUniformIntDist(TGenerator& gen, TValue min, TValue max) -> TValue
template<typename T>
static auto createRandomGenerator() -> T
Create a randomly seeded random number generator.
auto toStringView(std::span<char> text) -> std::string_view
Converts a span of characters into a std::string_view.
void uintToStr(SmallVectorBase<char>& buffer, uint32_t value)
Converts the provided value into a string, storing it into buffer.
void uintToStr(SmallVectorBase<char>& buffer, uint64_t value)
Converts the provided value into a string, storing it into buffer.
auto strToInt(std::string_view str, size_t* pos = nullptr, int base = 10) -> std::optional<int32_t>
auto strToUInt(std::string_view str, size_t* pos = nullptr, int base = 10) -> std::optional<uint32_t>
auto strToDouble(std::string_view str, size_t* pos = nullptr) -> std::optional<double>
void strToUpper(std::string& str)
void strToLower(std::string& str)
auto charToUpper(char c) -> char
Converts a character to uppercase (assuming ASCII).
auto charToLower(char c) -> char
Converts a character to lowercase (assuming ASCII).
auto editDistance(std::string_view left, std::string_view right, bool allowReplacements = true, int maxDistance = 0) -> int
auto getU8Str(const std::filesystem::path& path) -> std::string
auto widen(std::string_view str) -> std::string_view
Widens the provided UTF8 string into UTF16 wchars.
auto narrow(std::string_view str) -> std::string_view
Widens the provided UTF16 string into UTF8.

Enum documentation

enum class slang::TimeScaleMagnitude: uint8_t

As allowed by SystemVerilog, time scales can be expressed in one of only a few magnitudes.

Typedef documentation

using slang::bitwidth_t = uint32_t

A type that can represent the largest possible bit width of a SystemVerilog integer.

Function documentation

std::optional<int32_t> slang::checkedAddS32(int32_t a, int32_t b)

Performs an addition of two signed 32-bit integers and returns the result if it does not overflow. If it does, nullopt is returned instead.

std::optional<int32_t> slang::checkedSubS32(int32_t a, int32_t b)

Performs a subtraction of two signed 32-bit integers and returns the result if it does not overflow. If it does, nullopt is returned instead.

std::optional<uint32_t> slang::checkedMulU32(uint32_t a, uint32_t b)

Performs a multiplication of two unsigned 32-bit integers and returns the result if it does not overflow. If it does, nullopt is returned instead.

bool slang::literalBaseFromChar(char base, LiteralBase& result)

Specifies the base of an integer (for converting to/from a string)

uint32_t slang::clog2(const SVInt& v)

Returns the ceiling of the log_2 of the value. If value is zero, returns zero.

std::optional<TimeUnit> slang::suffixToTimeUnit(std::string_view timeSuffix, size_t& lengthConsumed)

Scale unit for a time value.

bool slang::isASCII(char c) constexpr

Returns whether the given character is a valid ASCII character.

bool slang::isPrintableASCII(char c) constexpr

Returns whether the given character is considered "printable".

bool slang::isPrintableUnicode(uint32_t c)

Returns whether the given Unicode character is considered "printable". Unicode code points of the categories L, M, N, P, S and Zs are considered printable. In addition, U+00AD SOFT HYPHEN is also considered printable, as it's actually displayed on most terminals.

int slang::charWidthUnicode(uint32_t c)

Returns

Character width:

  • 0 for non-spacing and enclosing combining marks;
  • 2 for CJK characters excluding halfwidth forms;
  • 1 for all remaining characters.

Gets the number of positions a character is likely to occupy when output on a terminal ("character width"). This depends on the implementation of the terminal, and there's no standard definition of character width. The implementation defines it in a way that is expected to be compatible with a generic Unicode-capable terminal.

bool slang::isWhitespace(char c) constexpr

Returns whether the given character is considered whitespace.

bool slang::isNewline(char c) constexpr

Returns whether the given character is considered a new line.

bool slang::isDecimalDigit(char c) constexpr

Returns whether the given character is considered a decimal digit.

bool slang::isOctalDigit(char c) constexpr

Returns whether the given character is considered an octal digit.

bool slang::isHexDigit(char c) constexpr

Returns whether the given character is considered a hexadecimal digit.

bool slang::isBinaryDigit(char c) constexpr

Returns whether the given character is considered a binary digit.

bool slang::isAlphaNumeric(char c) constexpr

Returns whether the given character is considered an alphanumeric character.

bool slang::isValidCIdChar(char c) constexpr

Returns whether the given character is valid in a C language identifier. That includes all alphanumeric characters and the underscore.

bool slang::isBase64Char(char c) constexpr

Returns whether the given characrer is a valid in base64 encoding.

bool slang::isLogicDigit(char c) constexpr

Returns whether the given character is considered a special logic digit, which encompasses various ways to say Unknown (X) or High Impedance (Z).

uint8_t slang::getDigitValue(char c) constexpr

Gets the numeric value of the given decimal digit. If the given character is not a valid decimal digit, the result is undefined.

uint8_t slang::getHexDigitValue(char c) constexpr

Gets the numeric value of the given hexadecimal digit. If the given character is not a valid hexadecimal digit, the result is undefined.

char slang::getHexForDigit(uint32_t num, bool lowerCase = false) constexpr

Gets the hexadecimal character for the given number (which should be less than 16).

int slang::utf8Len(unsigned char first) constexpr

Gets the length of the UTF-8 sequence starting with the given first character. Returns 0 if the given character is invalid for a UTF-8 sequence.

const char* slang::utf8Decode(const char* b, uint32_t* c, int* e) constexpr

Decode the next character, c from buf

Since this is a branchless decoder, four bytes will be read from the buffer regardless of the actual length of the next character. This means the buffer must have at least three bytes of zero padding following the end of the data stream.

Errors are reported in e which will be non-zero if the parsed character was somehow invalid: invalid byte sequence, non-canonical encoding, or a surrogate half.

The function returns a pointer to the next character. When an error occurs, this pointer will be a guess that depends on the particular error, but it will always advance at least one byte.

template<typename T, typename... Rest>
void slang::hash_combine(size_t& seed, const T& v, Rest... rest)

Hash combining function, based on the function from Boost. It hashes the provided v object and combines it with the previous hash value in seed.

template<typename T>
iterator_range<T> slang::make_range(T begin, T end)

Constructs an iterator_range from two provided iterators (inferring the types involved).

template<typename TContainer>
auto slang::make_reverse_range(TContainer&& container)

Constructs a reversed iterator_range from the provided container, using std::make_reverse_iterator.

template<typename TGenerator, typename TValue>
static TValue slang::getUniformIntDist(TGenerator& gen, TValue min, TValue max)

Gets a (mostly) uniformly distributed value within the provided [min,max] range. This is a poor man's implementation of std::uniform_int_distribution because the standard type isn't required to produce identical results across implementations.

This implementation is potentially slightly biased if you use a large range but slang doesn't need super precisely distributed random numbers for anything so it's fine.

template<typename T>
static T slang::createRandomGenerator()

Create a randomly seeded random number generator.

std::string_view slang::toStringView(std::span<char> text)

Converts a span of characters into a std::string_view.

void slang::uintToStr(SmallVectorBase<char>& buffer, uint32_t value)

Converts the provided value into a string, storing it into buffer.

void slang::uintToStr(SmallVectorBase<char>& buffer, uint64_t value)

Converts the provided value into a string, storing it into buffer.

std::optional<int32_t> slang::strToInt(std::string_view str, size_t* pos = nullptr, int base = 10)

Returns the converted value, or nullopt if conversion fails (invalid string, overflow, etc).

Parses the provided str in the specified base into a signed integer. If pos is non-null, it will be set to point to the first character in the source string that was not part of the conversion.

std::optional<uint32_t> slang::strToUInt(std::string_view str, size_t* pos = nullptr, int base = 10)

Returns the converted value, or nullopt if conversion fails (invalid string, overflow, etc).

Parses the provided str in the specified base into an unsigned integer. If pos is non-null, it will be set to point to the first character in the source string that was not part of the conversion.

std::optional<double> slang::strToDouble(std::string_view str, size_t* pos = nullptr)

Returns the converted value, or nullopt if conversion fails (invalid string, overflow, etc).

Parses the provided str into a floating point value. If pos is non-null, it will be set to point to the first character in the source string that was not part of the conversion.

void slang::strToUpper(std::string& str)

Converts the provided string to all uppercase characters (assuming ASCII contents). The string is converted in place.

void slang::strToLower(std::string& str)

Converts the provided string to all lowercase characters (assuming ASCII contents). The string is converted in place.

char slang::charToUpper(char c)

Converts a character to uppercase (assuming ASCII).

char slang::charToLower(char c)

Converts a character to lowercase (assuming ASCII).

int slang::editDistance(std::string_view left, std::string_view right, bool allowReplacements = true, int maxDistance = 0)

Determines the number of edits to the left string that are required to change it into the right string. If allowReplacements is true, characters can be substituted as needed. Otherwise, only swaps are allowed.

If maxDistance is >0 and the computed distance is at least that much, give up and return maxDistance + 1.

std::string slang::getU8Str(const std::filesystem::path& path)

C++20 is dumb and provides no way to get a std::string with the UTF-8 contents of a fs::path, so we have to use this method to copy the chars :(

std::string_view slang::widen(std::string_view str)

Widens the provided UTF8 string into UTF16 wchars.

std::string_view slang::narrow(std::string_view str)

Widens the provided UTF16 string into UTF8.