Skip to content

Commit

Permalink
Merge branch 'Fix-Output' of https://github.com/AdarshRawat1/p4c into…
Browse files Browse the repository at this point in the history
… Fix-Output

Signed-off-by: Adarsh <[email protected]>
  • Loading branch information
AdarshRawat1 committed Oct 1, 2024
2 parents 11583f2 + 2f874b1 commit 906b7eb
Show file tree
Hide file tree
Showing 48 changed files with 766 additions and 679 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci-test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ jobs:

- name: Install dependencies (MacOS)
run: |
# FIXME: We should not need to do this, but there are currently some complications with Github CI.
# See https://github.com/actions/runner-images/issues/4020.
# See https://github.com/actions/runner-images/issues/8838.
brew install [email protected] || true
brew link --overwrite [email protected]
brew pin [email protected]
tools/install_mac_deps.sh
- name: Build (MacOS)
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/controlFlowGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
#include "controlFlowGraph.h"

#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/tableApply.h"
#include "frontends/p4/typeMap.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/extern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

#include "extern.h"

#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "lib/json.h"

namespace P4::BMV2 {
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ limitations under the License.
#include "controlFlowGraph.h"
#include "expression.h"
#include "frontends/common/model.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "ir/ir.h"
#include "lib/cstring.h"
#include "lib/json.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ limitations under the License.

#include "lower.h"

#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/coreLibrary.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/methodInstance.h"
#include "lib/big_int_util.h"

Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.
#include "JsonObjects.h"
#include "backend.h"
#include "extern.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/coreLibrary.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "lib/algorithm.h"

namespace P4::BMV2 {
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/pna_nic/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
#include "backends/bmv2/pna_nic/options.h"
#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/portable_common/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
#include "backends/bmv2/portable_common/options.h"
#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/psa_switch/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
#include "backends/bmv2/psa_switch/options.h"
#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/simple_switch/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
#include "backends/bmv2/simple_switch/options.h"
#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/simple_switch/simpleSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ limitations under the License.

#include "backends/bmv2/common/annotations.h"
#include "backends/bmv2/simple_switch/options.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/cloner.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "lib/json.h"
#include "midend/flattenLogMsg.h"

Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/simple_switch/simpleSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ limitations under the License.
#include "backends/bmv2/common/sharedActionSelectorCheck.h"
#include "backends/common/programStructure.h"
#include "frontends/common/constantFolding.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/unusedDeclarations.h"
#include "midend/convertEnums.h"
Expand Down
2 changes: 1 addition & 1 deletion backends/dpdk/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ limitations under the License.
#include "dpdkArch.h"
#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
7 changes: 3 additions & 4 deletions backends/p4fmt/p4formatter.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "p4formatter.h"

#include <deque>
#include <sstream>
#include <string>

#include "frontends/common/options.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/getV1ModelVersion.h"
#include "frontends/parsers/p4/p4parser.hpp"
#include "ir/dump.h"

Expand Down Expand Up @@ -69,7 +68,7 @@ bool P4Formatter::preorder(const IR::P4Program *program) {
if (sourceFile.parent_path() == p4includePath) {
std::filesystem::path p = sourceFile.filename();
if (P4V1::V1Model::instance.file.name == p) {
P4V1::getV1ModelVersion g;
P4V1::GetV1ModelVersion g;
program->apply(g);
builder.append("#define V1MODEL_VERSION ");
builder.append(g.version);
Expand Down
2 changes: 1 addition & 1 deletion backends/p4test/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ limitations under the License.

#include "frontends/common/constantFolding.h"
#include "frontends/common/resolveReferences/resolveReferences.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/evaluator/evaluator.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/moveDeclarations.h"
#include "frontends/p4/simplify.h"
#include "frontends/p4/simplifyParsers.h"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/p4RuntimeArchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
#include "frontends/common/resolveReferences/referenceMap.h"
// TODO(antonin): this include should go away when we cleanup getTableSize
// implementation.
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/externInstance.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/toP4/toP4.h"
#include "frontends/p4/typeMap.h"
#include "ir/ir.h"
Expand Down
1 change: 0 additions & 1 deletion control-plane/p4RuntimeArchStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License.
#include <unordered_map>

#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4/typeMap.h"
#include "ir/ir.h"
#include "lib/log.h"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/p4RuntimeArchStandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
#define CONTROL_PLANE_P4RUNTIMEARCHSTANDARD_H_

#include "frontends/common/resolveReferences/referenceMap.h"
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/typeMap.h"
#include "ir/ir.h"
#include "p4RuntimeArchHandler.h"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ limitations under the License.
#include "frontends/p4/externInstance.h"
// TODO(antonin): this include should go away when we cleanup getMatchFields
// and tableNeedsPriority implementations.
#include "frontends/p4/fromv1.0/v1model.h"
#include "frontends/p4-14/fromv1.0/v1model.h"
#include "frontends/p4/methodInstance.h"
#include "frontends/p4/typeChecking/typeChecker.h"
#include "frontends/p4/typeMap.h"
Expand Down
15 changes: 9 additions & 6 deletions frontends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ set (P4_FRONTEND_SRCS
p4/evaluator/evaluator.cpp
p4/evaluator/substituteParameters.cpp
p4/externInstance.cpp
p4/fromv1.0/converters.cpp
p4/fromv1.0/programStructure.cpp
p4/frontend.cpp
p4/functionsInlining.cpp
p4/hierarchicalNames.cpp
p4/inlining.cpp
p4/localizeActions.cpp
p4/methodInstance.cpp
p4/modelInstances.cpp
p4/moveConstructors.cpp
p4/moveDeclarations.cpp
p4/parameterSubstitution.cpp
Expand Down Expand Up @@ -110,9 +107,6 @@ set (P4_FRONTEND_HDRS
p4/evaluator/evaluator.h
p4/evaluator/substituteParameters.h
p4/externInstance.h
p4/fromv1.0/converters.h
p4/fromv1.0/programStructure.h
p4/fromv1.0/v1model.h
p4/frontend.h
p4/functionsInlining.h
p4/hierarchicalNames.h
Expand Down Expand Up @@ -196,6 +190,11 @@ set (COMMON_FRONTEND_HDRS
set (V1_FRONTEND_SRCS
p4-14/typecheck.cpp
p4-14/header_type.cpp
p4-14/v1.cpp

p4-14/fromv1.0/converters.cpp
p4-14/fromv1.0/programStructure.cpp
p4-14/fromv1.0/v1model.cpp
)

set (IR_DEF_FILES ${IR_DEF_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/p4-14/ir-v1.def PARENT_SCOPE)
Expand All @@ -204,6 +203,10 @@ set (V1_FRONTEND_HDRS
p4-14/header_type.h
p4-14/inline_control_flow.h
p4-14/typecheck.h

p4-14/fromv1.0/converters.h
p4-14/fromv1.0/programStructure.h
p4-14/fromv1.0/v1model.h
)

set (PARSERS_SRCS
Expand Down
2 changes: 1 addition & 1 deletion frontends/common/parseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
#include <cstdio>
#include <sstream>

#include "frontends/p4/fromv1.0/converters.h"
#include "frontends/p4-14/fromv1.0/converters.h"
#include "frontends/parsers/parserDriver.h"
#include "lib/error.h"

Expand Down
2 changes: 1 addition & 1 deletion frontends/common/parseInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

#include "frontends/common/options.h"
#include "frontends/common/parser_options.h"
#include "frontends/p4/fromv1.0/converters.h"
#include "frontends/p4-14/fromv1.0/converters.h"
#include "frontends/parsers/parserDriver.h"
#include "lib/error.h"

Expand Down
20 changes: 12 additions & 8 deletions frontends/common/parser_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ void ParserOptions::dumpPass(const char *manager, unsigned seq, const char *pass
// regex_search checks if the regex is contained as substring
match = std::regex_search(name.begin(), name.end(), s_regex);
} catch (const std::regex_error &e) {
::P4::error(ErrorType::ERR_INVALID,
"Malformed toP4 regex string \"%s\".\n"
"The regex matcher follows ECMAScript syntax.",
s);
error(ErrorType::ERR_INVALID,
"Malformed toP4 regex string \"%s\".\n"
"The regex matcher follows ECMAScript syntax.",
s);
exit(1);
}
if (match) {
Expand All @@ -501,13 +501,12 @@ void ParserOptions::dumpPass(const char *manager, unsigned seq, const char *pass
std::unique_ptr<std::ostream> stream{openFile(fileName, true)};
if (stream != nullptr) {
if (Log::verbose()) std::cerr << "Writing program to " << fileName << std::endl;
// FIXME: Accept path here
P4::ToP4 toP4(stream.get(), Log::verbose(), cstring(file));
std::unique_ptr<P4::ToP4> toP4 = getToP4(stream.get(), Log::verbose(), file);
if (noIncludes) {
toP4.setnoIncludesArg(true);
toP4->setnoIncludesArg(true);
}
if (node) {
node->apply(toP4);
node->apply(*toP4);
} else {
*stream << "No P4 program returned by the pass" << std::endl;
}
Expand All @@ -517,6 +516,11 @@ void ParserOptions::dumpPass(const char *manager, unsigned seq, const char *pass
}
}

std::unique_ptr<ToP4> ParserOptions::getToP4(std::ostream *outStream, bool showIR,
std::filesystem::path mainFile) const {
return std::make_unique<ToP4>(outStream, showIR, mainFile);
}

bool ParserOptions::isAnnotationDisabled(const IR::Annotation *a) const {
if (disabledAnnotations.count(a->name.name) > 0) {
::P4::warning(ErrorType::WARN_IGNORE, "%1% is ignored because it was explicitly disabled",
Expand Down
13 changes: 10 additions & 3 deletions frontends/common/parser_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ limitations under the License.

namespace P4 {

class ToP4;

/// Standard include paths for .p4 header files. The values are determined by
/// `configure`.
extern const char *p4includePath;
Expand All @@ -50,9 +52,14 @@ class ParserOptions : public Util::Options {
mutable size_t dump_uid = 0;

protected:
/// Function that is returned by getDebugHook.
/// Implements function that is returned by getDebugHook. The hook will take the same arguments.
/// The hook uses \ref getToP4 to obtain the P4 printer.
void dumpPass(const char *manager, unsigned seq, const char *pass, const IR::Node *node) const;

/// Obtain an instance of ToP4 or its descendant. The arguments correspond to constructor
/// arguments of ToP4.
virtual std::unique_ptr<ToP4> getToP4(std::ostream *, bool, std::filesystem::path) const;

public:
explicit ParserOptions(std::string_view defaultMessage = "Parse a P4 program");

Expand Down Expand Up @@ -92,8 +99,8 @@ class ParserOptions : public Util::Options {
std::optional<ParserOptions::PreprocessorResult> preprocess() const;
/// True if we are compiling a P4 v1.0 or v1.1 program
bool isv1() const;
/// Get a debug hook function suitable for insertion
/// in the pass managers that are executed.
/// Get a debug hook function suitable for insertion in the pass managers. The hook is
/// responsible for dumping P4 according to th --top4 and related options.
DebugHook getDebugHook() const;
/// Check whether this particular annotation was disabled
bool isAnnotationDisabled(const IR::Annotation *a) const;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef FRONTENDS_P4_FROMV1_0_CONVERTERS_H_
#define FRONTENDS_P4_FROMV1_0_CONVERTERS_H_
#ifndef FRONTENDS_P4_14_FROMV1_0_CONVERTERS_H_
#define FRONTENDS_P4_14_FROMV1_0_CONVERTERS_H_

#include <typeindex>
#include <typeinfo>
Expand Down Expand Up @@ -1059,4 +1059,4 @@ class Converter : public PassManager {

} // namespace P4::P4V1

#endif /* FRONTENDS_P4_FROMV1_0_CONVERTERS_H_ */
#endif /* FRONTENDS_P4_14_FROMV1_0_CONVERTERS_H_ */
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef FRONTENDS_P4_FROMV1_0_PROGRAMSTRUCTURE_H_
#define FRONTENDS_P4_FROMV1_0_PROGRAMSTRUCTURE_H_
#ifndef FRONTENDS_P4_14_FROMV1_0_PROGRAMSTRUCTURE_H_
#define FRONTENDS_P4_14_FROMV1_0_PROGRAMSTRUCTURE_H_

#include <set>
#include <vector>
Expand Down Expand Up @@ -330,4 +330,4 @@ class ProgramStructure {

} // namespace P4::P4V1

#endif /* FRONTENDS_P4_FROMV1_0_PROGRAMSTRUCTURE_H_ */
#endif /* FRONTENDS_P4_14_FROMV1_0_PROGRAMSTRUCTURE_H_ */
11 changes: 11 additions & 0 deletions frontends/p4-14/fromv1.0/v1model.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "frontends/p4-14/fromv1.0/v1model.h"

/* These must be in the same compilation unit to ensure that P4CoreLibrary::instance
* is initialized before V1Model::instance */
namespace P4::P4V1 {

V1Model V1Model::instance;
const char *V1Model::versionInitial = "20180101";
const char *V1Model::versionCurrent = "20200408";

} // namespace P4::P4V1
Loading

0 comments on commit 906b7eb

Please sign in to comment.