P4C
The P4 Compiler
Loading...
Searching...
No Matches
backends/tofino/bf-p4c/logging/pass_manager.h
1
19#ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_PASS_MANAGER_H_
20#define _BACKENDS_TOFINO_BF_P4C_LOGGING_PASS_MANAGER_H_
21
22#include "bf-p4c/bf-p4c-options.h"
23#include "bf-p4c/logging/filelog.h"
24#include "ir/ir.h"
25#include "ir/pass_manager.h"
26#include "lib/cstring.h"
27
28namespace Logging {
29
36class PassManager : public ::PassManager {
37 protected:
38 cstring _logFilePrefix;
39 Logging::Mode _logMode;
40 Logging::FileLog *_logFile;
41
44 static int invocationCount;
45
46 public:
47 explicit PassManager(cstring logFilePrefix, Logging::Mode logMode = Logging::Mode::CREATE)
48 : _logFilePrefix(logFilePrefix), _logMode(logMode), _logFile(nullptr) {}
49
50 static cstring getNewLogFileName(const cstring &prefix) {
51 return prefix + std::to_string(invocationCount) + ".log";
52 }
53
54 protected:
55 profile_t init_apply(const IR::Node *root) override {
56 if (BackendOptions().verbose == 0) {
57 return ::PassManager::init_apply(root);
58 }
59
60 auto pipe = root->to<IR::BFN::Pipe>();
61 if (pipe) {
62 if (_logMode == Logging::Mode::CREATE) {
64 auto logFileName = getNewLogFileName(_logFilePrefix);
65 _logFile = new Logging::FileLog(pipe->canon_id(), logFileName, _logMode);
66 } else {
67 auto logFileName = _logFilePrefix + ".log";
68 _logFile = new Logging::FileLog(pipe->canon_id(), logFileName, _logMode);
69 }
70 }
71
72 return ::PassManager::init_apply(root);
73 }
74
75 void end_apply() override {
77 ::PassManager::end_apply();
78 }
79};
80} // end namespace Logging
81
82#endif // _BACKENDS_TOFINO_BF_P4C_LOGGING_PASS_MANAGER_H_
A FileLog is used to redirect the logging output of a visitor pass to a file.
Definition filelog.h:48
void close()
Untie the file and close the filestream.
Definition filelog.h:94
Definition backends/tofino/bf-p4c/logging/pass_manager.h:36
static int invocationCount
Definition backends/tofino/bf-p4c/logging/pass_manager.h:44
Definition ir/pass_manager.h:40
Definition cstring.h:85
Definition filelog.h:32
Mode
specifies how the log file is created and/or reused.
Definition filelog.h:35
@ CREATE
Creates a new log. Overwrites if the log already exists.
Definition filelog.h:40