P4C
The P4 Compiler
Loading...
Searching...
No Matches
common/lib/format_int.h
1#ifndef BACKENDS_P4TOOLS_COMMON_LIB_FORMAT_INT_H_
2#define BACKENDS_P4TOOLS_COMMON_LIB_FORMAT_INT_H_
3
4#include <stddef.h>
5
6#include <string>
7
8#include "ir/ir.h"
9#include "lib/big_int_util.h"
10
11namespace P4::P4Tools {
12
19 bool useSeparator = false;
20
23 bool padOutput = true;
24
28 bool usePrefix = true;
29
31 bool useUpperCaseHex = true;
32};
33
35std::string formatBinOrHex(const big_int &value,
36 const FormatOptions &formatOptions = FormatOptions());
37
39std::string formatBin(const big_int &value, int width,
40 const FormatOptions &formatOptions = FormatOptions());
41
43std::string formatOctal(const big_int &value, const FormatOptions &formatOptions = FormatOptions());
44
46std::string formatHex(const big_int &value, int width,
47 const FormatOptions &formatOptions = FormatOptions());
48
52std::string formatBinOrHexExpr(const IR::Expression *expr,
53 const FormatOptions &formatOptions = FormatOptions());
54
58std::string formatBinExpr(const IR::Expression *expr,
59 const FormatOptions &formatOptions = FormatOptions());
60
64std::string formatOctalExpr(const IR::Expression *expr,
65 const FormatOptions &formatOptions = FormatOptions());
66
70std::string formatHexExpr(const IR::Expression *expr,
71 const FormatOptions &formatOptions = FormatOptions());
72
76std::string insertSeparators(const std::string &dataStr, const std::string &separator = "\\x",
77 size_t stride = 2, bool skipFirst = false);
78
80std::string insertOctalSeparators(const std::string &dataStr);
81
83std::string insertHexSeparators(const std::string &dataStr);
84
89std::vector<uint8_t> convertBigIntToBytes(const big_int &dataInt, int targetWidthBits,
90 bool padLeft = false);
91
94std::optional<std::string> convertToIpv4String(const std::vector<uint8_t> &byteArray);
95
98std::optional<std::string> convertToIpv6String(const std::vector<uint8_t> &byteArray);
99
102std::optional<std::string> convertToMacString(const std::vector<uint8_t> &byteArray);
103
104} // namespace P4::P4Tools
105
106#endif /* BACKENDS_P4TOOLS_COMMON_LIB_FORMAT_INT_H_ */
Definition common/compiler/compiler_result.cpp:3
bool useUpperCaseHex
In case of hex strings, use uppercase instead of lowercase letters.
Definition common/lib/format_int.h:31
std::optional< std::string > convertToIpv6String(const std::vector< uint8_t > &byteArray)
Definition common/lib/format_int.cpp:309
std::optional< std::string > convertToIpv4String(const std::vector< uint8_t > &byteArray)
Definition common/lib/format_int.cpp:291
std::optional< std::string > convertToMacString(const std::vector< uint8_t > &byteArray)
Definition common/lib/format_int.cpp:330
std::string insertOctalSeparators(const std::string &dataStr)
Takes an octal-formatted string as input and inserts slashes as separators.
Definition common/lib/format_int.cpp:259
std::string formatHexExpr(const IR::Expression *expr, const FormatOptions &formatOptions)
Definition common/lib/format_int.cpp:185
bool padOutput
Definition common/lib/format_int.h:23
std::string formatOctalExpr(const IR::Expression *expr, const FormatOptions &formatOptions)
Definition common/lib/format_int.cpp:152
std::string formatBinExpr(const IR::Expression *expr, const FormatOptions &formatOptions)
Definition common/lib/format_int.cpp:119
bool usePrefix
Definition common/lib/format_int.h:28
std::string formatBinOrHexExpr(const IR::Expression *expr, const FormatOptions &formatOptions)
Definition common/lib/format_int.cpp:223
std::string formatBin(const big_int &value, int width, const FormatOptions &formatOptions)
Format.
Definition common/lib/format_int.cpp:20
std::string insertHexSeparators(const std::string &dataStr)
Takes a hex-formatted string as input and inserts slashes as separators.
Definition common/lib/format_int.cpp:263
std::vector< uint8_t > convertBigIntToBytes(const big_int &dataInt, int targetWidthBits, bool padLeft)
Definition common/lib/format_int.cpp:267
bool useSeparator
Definition common/lib/format_int.h:19
std::string formatHex(const big_int &value, int width, const FormatOptions &formatOptions)
Format.
Definition common/lib/format_int.cpp:84
std::string insertSeparators(const std::string &dataStr, const std::string &separator, size_t stride, bool skipFirst)
Definition common/lib/format_int.cpp:228
Defines common formatting options.
Definition common/lib/format_int.h:14