From 3478df95cb0471a12d7546dfae41f097a70e910d Mon Sep 17 00:00:00 2001 From: Chris Dodd Date: Wed, 15 Feb 2017 16:36:35 -0800 Subject: [PATCH] misc cleanups --- backends/bmv2/bmv2stf.py | 6 +++++- frontends/common/options.cpp | 6 +++--- frontends/common/parseInput.cpp | 1 + frontends/p4/fromv1.0/programStructure.cpp | 4 ++-- frontends/p4/frontend.h | 1 + 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backends/bmv2/bmv2stf.py b/backends/bmv2/bmv2stf.py index f2bc7cac907..1c6a680a728 100755 --- a/backends/bmv2/bmv2stf.py +++ b/backends/bmv2/bmv2stf.py @@ -363,7 +363,11 @@ def do_command(self, cmd): interface, data = nextWord(cmd) data = ''.join(data.split()) time.sleep(self.packetDelay) - self.interfaces[interface]._write_packet(HexToByte(data)) + try: + self.interfaces[interface]._write_packet(HexToByte(data)) + except ValueError: + reportError("Invalid packet data", data) + return FAILURE self.interfaces[interface].flush() self.packetDelay = 0 elif first == "expect": diff --git a/frontends/common/options.cpp b/frontends/common/options.cpp index 89790785ea5..90a8aeced1b 100644 --- a/frontends/common/options.cpp +++ b/frontends/common/options.cpp @@ -280,13 +280,13 @@ void CompilerOptions::dumpPass(const char* manager, unsigned seq, const char* pa P4::ToP4 toP4(stream, Log::verbose(), file); node->apply(toP4); } + break; } } } DebugHook CompilerOptions::getDebugHook() const { - auto dp = std::bind(&CompilerOptions::dumpPass, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4); + using namespace std::placeholders; + auto dp = std::bind(&CompilerOptions::dumpPass, this, _1, _2, _3, _4); return dp; } diff --git a/frontends/common/parseInput.cpp b/frontends/common/parseInput.cpp index 07c626b4c47..1c177738568 100644 --- a/frontends/common/parseInput.cpp +++ b/frontends/common/parseInput.cpp @@ -30,6 +30,7 @@ const IR::P4Program* parseP4File(CompilerOptions& options) { bool compiling10 = options.isv1(); if (compiling10) { P4V1::Converter converter; + converter.addDebugHook(options.getDebugHook()); converter.loadModel(); // Model is loaded before parsing the input file. // In this way the SourceInfo in the model comes first. diff --git a/frontends/p4/fromv1.0/programStructure.cpp b/frontends/p4/fromv1.0/programStructure.cpp index 65154086c2f..858007db5f5 100644 --- a/frontends/p4/fromv1.0/programStructure.cpp +++ b/frontends/p4/fromv1.0/programStructure.cpp @@ -474,9 +474,9 @@ void ProgramStructure::include(cstring filename) { options.file = path.toString(); if (FILE* file = options.preprocess()) { if (!::errorCount()) { - if (auto std = parse_P4_16_file(options.file, file)) { + if (auto code = parse_P4_16_file(options.file, file)) { if (!::errorCount()) { - for (auto decl : *std->declarations) { + for (auto decl : *code->declarations) { declarations->push_back(decl); } } } } options.closeInput(file); } } diff --git a/frontends/p4/frontend.h b/frontends/p4/frontend.h index d8587b037ce..e6d2652f00a 100644 --- a/frontends/p4/frontend.h +++ b/frontends/p4/frontend.h @@ -26,6 +26,7 @@ class FrontEnd { std::vector hooks; public: FrontEnd() = default; + explicit FrontEnd(DebugHook hook) { hooks.push_back(hook); } void addDebugHook(DebugHook hook) { hooks.push_back(hook); } const IR::P4Program* run(const CompilerOptions& options, const IR::P4Program* program); };