P4C
The P4 Compiler
Loading...
Searching...
No Matches
register-matcher.h
1
17
18
#ifndef BACKENDS_TOFINO_BF_ASM_GTEST_REGISTER_MATCHER_H_
19
#define BACKENDS_TOFINO_BF_ASM_GTEST_REGISTER_MATCHER_H_
20
21
#include <gtest/gtest.h>
22
23
#include <cstdint>
24
#include <iosfwd>
25
#include <sstream>
26
27
#include "backends/tofino/bf-asm/ubits.h"
28
#include "lib/bitvec.h"
29
30
namespace
BfAsm
{
31
32
namespace
Test {
33
34
class
RegisterMatcher {
35
private
:
36
bitvec
expected;
37
uint32_t bitsize;
38
39
public
:
40
explicit
RegisterMatcher(
const
char
*spec);
41
42
bool
checkRegister(std::ostream &os,
const
uint8_t reg[], uint32_t size)
const
;
43
44
template
<
int
N>
45
bool
checkRegister(std::ostream &os,
const
ubits<N>
&bits)
const
{
46
static_assert
(N > 0 && N <= 64);
47
const
uint64_t value(bits);
48
return
checkRegister(os,
reinterpret_cast<
const
uint8_t *
>
(&value), (N + 7) / 8);
49
}
50
51
private
:
52
void
pushBits(
const
bitvec
&bits, uint32_t width);
53
};
54
55
}
// namespace Test
56
57
}
// namespace BfAsm
58
59
#define EXPECT_REGISTER(reg, expected) \
60
do { \
61
RegisterMatcher matcher(expected); \
62
std::ostringstream oss; \
63
if (!matcher.checkRegister(oss, reg)) { \
64
ADD_FAILURE() << "check of the register " << #reg << " has failed:\n" << oss.str(); \
65
} \
66
} while (false)
67
68
#endif
/* BACKENDS_TOFINO_BF_ASM_GTEST_REGISTER_MATCHER_H_ */
P4::bitvec
Definition
bitvec.h:120
BfAsm
Definition
register-matcher.cpp:23
ubits
Definition
ubits.h:82
backends
tofino
bf-asm
gtest
register-matcher.h
Generated by
1.13.2