P4C
The P4 Compiler
Loading...
Searching...
No Matches
bfas.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_BFAS_H_
19#define BACKENDS_TOFINO_BF_ASM_BFAS_H_
20
21#include <stdarg.h>
22#include <stdio.h>
23#include <string.h>
24
25#include <iostream>
26#include <memory>
27#include <string>
28
29enum config_version_t { CONFIG_OLD = 1, CONFIG_NEW = 2, CONFIG_BOTH = 3 };
30enum target_t {
31 NO_TARGET = 0,
32 TOFINO,
33 TOFINO2,
34 JBAY = TOFINO2,
35 TOFINO2H,
36 TOFINO2U,
37 TOFINO2M,
38 TOFINO2A0,
39 TARGET_INDEX_LIMIT
40};
41enum binary_type_t {
42 NO_BINARY = -3,
43 FOUR_PIPE = -2, // binary replicating to all 4 pipes
44 ONE_PIPE = -1, // binary for one pipe with pipe offset addresses
45 PIPE0 = 0, // binary with data just in pipe 0
46 PIPE1, // binary with data just in pipe 1
47 PIPE2, // binary with data just in pipe 2
48 PIPE3, // binary with data just in pipe 3
49 MAX_PIPE_COUNT, // Maximum number of pipes which bfas can create binary for
50};
51
52extern struct option_t {
53 binary_type_t binary;
54 bool condense_json;
55 bool debug_info;
56 bool disable_egress_latency_padding;
57 bool disable_gfm_parity;
58 bool disable_long_branch;
59 bool disable_power_gating;
60 bool gen_json;
61 bool high_availability_enabled;
62 bool match_compiler;
63 bool multi_parsers;
64 bool partial_input;
65 bool singlewrite;
66 std::string stage_dependency_pattern;
67 target_t target;
68 bool tof2lab44_workaround;
69 config_version_t version;
70 bool werror;
71 bool nowarn;
72 bool log_hashes;
73 std::string output_dir;
74 int num_stages_override;
75 bool tof1_egr_parse_depth_checks_disabled;
76 const char *fill_noop_slot;
77} options;
78
79extern unsigned unique_action_handle;
80struct value_t;
81
82extern std::string asmfile_name;
83extern std::string asmfile_dir;
84extern std::unique_ptr<std::ostream> gfm_out;
85
86class BaseAsmParser;
87extern BaseAsmParser *asm_parser;
88void createSingleAsmParser();
89
90std::string toString(target_t target);
91std::ostream &operator<<(std::ostream &out, target_t target);
92
93int asm_parse_file(const char *name, FILE *in);
94int asm_parse_string(const char *in);
95
96void no_sections_error_exit();
97bool no_section_error(const char *name);
98
100extern int error_count, warn_count;
101extern void error(int lineno, const char *fmt, va_list);
102void error(int lineno, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
103inline void error(int lineno, const char *fmt, ...) {
104 va_list args;
105 va_start(args, fmt);
106 error(lineno, fmt, args);
107 va_end(args);
108}
109extern void warning(int lineno, const char *fmt, va_list);
110void warning(int lineno, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
111inline void warning(int lineno, const char *fmt, ...) {
112#ifdef BAREFOOT_INTERNAL
113 if (!options.nowarn) {
114 va_list args;
115 va_start(args, fmt);
116 warning(lineno, fmt, args);
117 va_end(args);
118 }
119#endif /* BAREFOOT_INTERNAL */
120}
121
122extern std::unique_ptr<std::ostream> open_output(const char *, ...)
123 __attribute__((format(printf, 1, 2)));
124
125class VersionIter {
126 unsigned left, bit;
127 void check() {
128 while (left && !(left & 1)) {
129 ++bit;
130 left >>= 1;
131 }
132 }
133 VersionIter() : left(0), bit(0) {}
134
135 public:
136 explicit VersionIter(config_version_t v) : left(v), bit(0) { check(); }
137 VersionIter begin() { return *this; }
138 VersionIter end() { return VersionIter(); }
139 int operator*() const { return bit; }
140 bool operator==(VersionIter &a) { return (left << bit) == (a.left << a.bit); }
141 VersionIter &operator++() {
142 left &= ~1;
143 check();
144 return *this;
145 }
146};
147
148extern unsigned unique_table_offset;
149
150#endif /* BACKENDS_TOFINO_BF_ASM_BFAS_H_ */
Base class of parser assembly section.
Definition tofino/bf-asm/parser.h:40
void warning(const char *format, Args &&...args)
Report a warning with the given message.
Definition lib/error.h:128
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58
Definition bfas.h:52
Definition asm-types.h:114