P4C
The P4 Compiler
Loading...
Searching...
No Matches
binary_output.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_BINARY_OUTPUT_H_
19#define BACKENDS_TOFINO_BF_ASM_BINARY_OUTPUT_H_
20
21#include <iomanip>
22#include <iostream>
23
24namespace binout {
25
26class tag {
27 char data[4] = {0, 0, 0, 0};
28
29 public:
30 tag(char ch) { data[3] = ch; } // NOLINT(runtime/explicit)
31 friend std::ostream &operator<<(std::ostream &out, const tag &e) {
32 return out.write(e.data, 4);
33 }
34};
35
36class byte4 {
37 char data[4];
38
39 public:
40 byte4(uint32_t v) { // NOLINT(runtime/explicit)
41 data[0] = v & 0xff;
42 data[1] = (v >> 8) & 0xff;
43 data[2] = (v >> 16) & 0xff;
44 data[3] = (v >> 24) & 0xff;
45 }
46 friend std::ostream &operator<<(std::ostream &out, const byte4 &e) {
47 return out.write(e.data, 4);
48 }
49};
50
51class byte8 {
52 char data[8];
53
54 public:
55 byte8(uint64_t v) { // NOLINT(runtime/explicit)
56 data[0] = v & 0xff;
57 data[1] = (v >> 8) & 0xff;
58 data[2] = (v >> 16) & 0xff;
59 data[3] = (v >> 24) & 0xff;
60 data[4] = (v >> 32) & 0xff;
61 data[5] = (v >> 40) & 0xff;
62 data[6] = (v >> 48) & 0xff;
63 data[7] = (v >> 56) & 0xff;
64 }
65 friend std::ostream &operator<<(std::ostream &out, const byte8 &e) {
66 return out.write(e.data, 8);
67 }
68};
69
70} // end namespace binout
71
72#endif /* BACKENDS_TOFINO_BF_ASM_BINARY_OUTPUT_H_ */
Definition binary_output.h:24