Skip to content

Commit

Permalink
[P4Testgen] Refactor the P4Testgen extern implementation. (#4728)
Browse files Browse the repository at this point in the history
* Refactor the P4Testgen extern implementation.

Signed-off-by: fruffy <fruffy@nyu.edu>

* Add if directive for unused code.

Signed-off-by: fruffy <fruffy@nyu.edu>

---------

Signed-off-by: fruffy <fruffy@nyu.edu>
  • Loading branch information
fruffy authored Jul 17, 2024
1 parent e04fdec commit fcaa90d
Show file tree
Hide file tree
Showing 24 changed files with 1,460 additions and 1,522 deletions.
1 change: 0 additions & 1 deletion backends/p4tools/modules/testgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set(
testgen.cpp

core/compiler_result.cpp
core/externs.cpp
core/program_info.cpp
core/small_step/abstract_stepper.cpp
core/small_step/cmd_stepper.cpp
Expand Down
40 changes: 40 additions & 0 deletions backends/p4tools/modules/testgen/core/extern_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXTERN_INFO_H_
#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXTERN_INFO_H_

#include <sys/types.h>

#include "ir/id.h"
#include "ir/ir.h"
#include "ir/vector.h"

namespace P4Tools::P4Testgen {

/// This class defines parameters useful for the invocation of P4 extern and P4Testgen-internal
/// functions.
class ExternInfo {
public:
/// Reference to the original P4 extern call.
const IR::MethodCallExpression &originalCall;
/// Name of the extern object the call was a member of, if any.
const IR::PathExpression &externObjectRef;
/// Name of the extern method.
const IR::ID &methodName;
/// Arguments to the extern method.
const IR::Vector<IR::Argument> &externArguments;

ExternInfo(const IR::MethodCallExpression &originalCall,
const IR::PathExpression &externObjectRef, const IR::ID &methodName,
const IR::Vector<IR::Argument> &externArguments)
: originalCall(originalCall),
externObjectRef(externObjectRef),
methodName(methodName),
externArguments(externArguments) {}

/// Do not accidentally copy-assign the extern info. It is only passed as reference.
ExternInfo &operator=(const ExternInfo &) = delete;
ExternInfo &operator=(ExternInfo &&) = delete;
};

} // namespace P4Tools::P4Testgen

#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXTERN_INFO_H_ */
108 changes: 0 additions & 108 deletions backends/p4tools/modules/testgen/core/externs.cpp

This file was deleted.

75 changes: 0 additions & 75 deletions backends/p4tools/modules/testgen/core/externs.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "ir/node.h"
#include "ir/solver.h"
#include "lib/exceptions.h"
#include "lib/log.h"
#include "lib/null.h"
#include "lib/source_file.h"
#include "midend/coverage.h"
Expand Down Expand Up @@ -178,7 +177,8 @@ bool ExprStepper::preorder(const IR::MethodCallExpression *call) {
call->method->type,
new IR::PathExpression(new IR::Type_Extern("*method"), new IR::Path("*method")),
path->path->name);
evalExternMethodCall(call, member->expr, member->member, call->arguments, state);
evalExternMethodCall({*call, *member->expr->checkedTo<IR::PathExpression>(),
member->member, *call->arguments});
return false;
}

Expand All @@ -198,7 +198,8 @@ bool ExprStepper::preorder(const IR::MethodCallExpression *call) {
// Handle extern calls. They may also be of Type_SpecializedCanonical.
if (method->expr->type->is<IR::Type_Extern>() ||
method->expr->type->is<IR::Type_SpecializedCanonical>()) {
evalExternMethodCall(call, method->expr, method->member, call->arguments, state);
evalExternMethodCall({*call, *method->expr->checkedTo<IR::PathExpression>(),
method->member, *call->arguments});
return false;
}

Expand Down
Loading

0 comments on commit fcaa90d

Please sign in to comment.