Skip to content

Commit

Permalink
Add missed p4tools annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed Jan 31, 2024
1 parent 9f26f2c commit 62b572e
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backends/p4tools/common/compiler/compiler_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class CompilerResult : public ICastable {
/// @returns the reference to the input P4 program, after it has been transformed by the
/// compiler.
[[nodiscard]] const IR::P4Program &getProgram() const;

DECLARE_TYPEINFO(CompilerResult);
};

/// P4Tools compilers may return an error instead of a compiler result.
Expand Down
3 changes: 3 additions & 0 deletions backends/p4tools/common/core/z3_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ir/solver.h"
#include "lib/cstring.h"
#include "lib/ordered_map.h"
#include "lib/rtti.h"
#include "lib/safe_vector.h"

namespace P4Tools {
Expand Down Expand Up @@ -127,6 +128,8 @@ class Z3Solver : public AbstractSolver {

/// Stores the timeout, as last set by @ref timeout.
std::optional<unsigned> timeout_;

DECLARE_TYPEINFO(Z3Solver, AbstractSolver);
};

} // namespace P4Tools
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/common/lib/formulae.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AbstractRepCheckedNode : public ICastable {
explicit AbstractRepCheckedNode(const Node *node, std::string classDesc) : node(*node) {
BUG_CHECK(Self::repOk(node), "%1%: Not a valid %2%.", node, classDesc);
}

DECLARE_TYPEINFO(AbstractRepCheckedNode);
};

} // namespace P4Tools
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/common/lib/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TraceEvent : public ICastable {
protected:
/// Prints this trace event to the given ostream.
virtual void print(std::ostream &) const = 0;

DECLARE_TYPEINFO(TraceEvent);
};

} // namespace P4Tools
Expand Down
24 changes: 24 additions & 0 deletions backends/p4tools/common/lib/trace_event_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Generic : public TraceEvent {
Generic(Generic &&) = default;
Generic &operator=(const Generic &) = default;
Generic &operator=(Generic &&) = default;

DECLARE_TYPEINFO(Generic, TraceEvent);
};

/* =============================================================================================
Expand All @@ -50,6 +52,8 @@ class GenericDescription : public Generic {

public:
explicit GenericDescription(cstring label, cstring description);

DECLARE_TYPEINFO(GenericDescription, Generic);
};

/* =============================================================================================
Expand All @@ -75,6 +79,8 @@ class Expression : public Generic {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(Expression, Generic);
};

/* =============================================================================================
Expand All @@ -96,6 +102,8 @@ class MethodCall : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(MethodCall, TraceEvent);
};

/* =============================================================================================
Expand All @@ -120,6 +128,8 @@ class IfStatementCondition : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(IfStatementCondition, TraceEvent);
};

/* =============================================================================================
Expand All @@ -141,6 +151,8 @@ class AssignmentStatement : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(AssignmentStatement, TraceEvent);
};

/* =============================================================================================
Expand Down Expand Up @@ -187,6 +199,8 @@ class ExtractSuccess : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(ExtractSuccess, TraceEvent);
};

/* =============================================================================================
Expand Down Expand Up @@ -219,6 +233,8 @@ class ExtractFailure : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(ExtractFailure, TraceEvent);
};

/* =============================================================================================
Expand All @@ -245,6 +261,8 @@ class Emit : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(Emit, TraceEvent);
};

/* =============================================================================================
Expand Down Expand Up @@ -281,6 +299,8 @@ class Packet : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(Packet, TraceEvent);
};

std::ostream &operator<<(std::ostream &os, const Packet::Direction &direction);
Expand All @@ -304,6 +324,8 @@ class ParserStart : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(ParserStart, TraceEvent);
};

/* =============================================================================================
Expand All @@ -328,6 +350,8 @@ class ParserState : public TraceEvent {

protected:
void print(std::ostream &os) const override;

DECLARE_TYPEINFO(ParserState, TraceEvent);
};

} // namespace P4Tools::TraceEvents
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/modules/testgen/core/compiler_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class TestgenCompilerResult : public CompilerResult {

/// @returns the coverable nodes in the analyzed P4 program.
[[nodiscard]] const P4::Coverage::CoverageSet &getCoverableNodes() const;

DECLARE_TYPEINFO(TestgenCompilerResult, CompilerResult);
};

class TestgenCompilerTarget : public CompilerTarget {
Expand Down
3 changes: 3 additions & 0 deletions backends/p4tools/modules/testgen/core/program_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "backends/p4tools/common/lib/arch_spec.h"
#include "ir/ir.h"
#include "lib/castable.h"
#include "lib/rtti.h"
#include "midend/coverage.h"

#include "backends/p4tools/modules/testgen/core/compiler_target.h"
Expand Down Expand Up @@ -114,6 +115,8 @@ class ProgramInfo : public ICastable {
const ArchSpec::ArchMember *archMember,
std::vector<Continuation::Command> *copyIns,
std::vector<Continuation::Command> *copyOuts) const;

DECLARE_TYPEINFO(ProgramInfo);
};

} // namespace P4Tools::P4Testgen
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/modules/testgen/lib/test_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class TestObject : public ICastable {
/// @returns a version of the test object where all expressions are resolved and symbolic
/// variables are substituted according to the mapping present in the @param model.
[[nodiscard]] virtual const TestObject *evaluate(const Model &model, bool doComplete) const = 0;

DECLARE_TYPEINFO(TestObject);
};

/// A map of test objects.
Expand Down
18 changes: 18 additions & 0 deletions backends/p4tools/modules/testgen/lib/test_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Packet : public TestObject {
/// is ignored.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedPayloadMask() const;

DECLARE_TYPEINFO(Packet, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -84,6 +86,8 @@ class ActionArg : public TestObject {
/// If the value is a bool, it is converted into a constant.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedValue() const;

DECLARE_TYPEINFO(ActionArg, TestObject);
};

class ActionCall : public TestObject {
Expand Down Expand Up @@ -115,6 +119,8 @@ class ActionCall : public TestObject {

/// @returns the arguments of this particular call.
[[nodiscard]] const std::vector<ActionArg> *getArgs() const;

DECLARE_TYPEINFO(ActionCall, TestObject);
};

class TableMatch : public TestObject {
Expand All @@ -127,6 +133,8 @@ class TableMatch : public TestObject {

/// @returns the key associated with this object.
[[nodiscard]] const IR::KeyElement *getKey() const;

DECLARE_TYPEINFO(TableMatch, TestObject);
};

using TableMatchMap = std::map<cstring, const TableMatch *>;
Expand Down Expand Up @@ -156,6 +164,8 @@ class Ternary : public TableMatch {
/// value needs to be a constant.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedMask() const;

DECLARE_TYPEINFO(Ternary, TableMatch);
};

class LPM : public TableMatch {
Expand Down Expand Up @@ -183,6 +193,8 @@ class LPM : public TableMatch {
/// point the prefix is expected to be a constant.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedPrefixLength() const;

DECLARE_TYPEINFO(LPM, TableMatch);
};

class Exact : public TableMatch {
Expand All @@ -200,6 +212,8 @@ class Exact : public TableMatch {
/// @returns the match value. It is expected to be a constant at this point.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedValue() const;

DECLARE_TYPEINFO(Exact, TableMatch);
};

class TableRule : public TestObject {
Expand Down Expand Up @@ -232,6 +246,8 @@ class TableRule : public TestObject {

/// @returns the time-to-live of this particular entry.
[[nodiscard]] int getTTL() const;

DECLARE_TYPEINFO(TableRule, TestObject);
};

class TableConfig : public TestObject {
Expand Down Expand Up @@ -269,6 +285,8 @@ class TableConfig : public TestObject {

/// Add a table property to the table.
void addTableProperty(cstring propertyName, const TestObject *property);

DECLARE_TYPEINFO(TableConfig, TestObject);
};

/* =========================================================================================
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/modules/testgen/targets/bmv2/bmv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class BMv2V1ModelCompilerResult : public TestgenCompilerResult {

/// @returns the map of direct extern declarations which are attached to a table.
[[nodiscard]] const DirectExternMap &getDirectExternMap() const;

DECLARE_TYPEINFO(BMv2V1ModelCompilerResult, TestgenCompilerResult);
};

class Bmv2V1ModelCompilerTarget : public TestgenCompilerTarget {
Expand Down
2 changes: 2 additions & 0 deletions backends/p4tools/modules/testgen/targets/bmv2/program_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Bmv2V1ModelProgramInfo : public ProgramInfo {

/// @see ProgramInfo::getArchSpec
static const ArchSpec ARCH_SPEC;

DECLARE_TYPEINFO(Bmv2V1ModelProgramInfo, ProgramInfo);
};

} // namespace P4Tools::P4Testgen::Bmv2
Expand Down
23 changes: 23 additions & 0 deletions backends/p4tools/modules/testgen/targets/bmv2/test_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ir/declaration.h"
#include "ir/ir.h"
#include "lib/cstring.h"
#include "lib/rtti.h"

#include "backends/p4tools/modules/testgen/lib/execution_state.h"
#include "backends/p4tools/modules/testgen/lib/test_object.h"
Expand Down Expand Up @@ -55,6 +56,8 @@ class IndexExpression : public TestObject {
bool doComplete) const override;

[[nodiscard]] cstring getObjectName() const override;

DECLARE_TYPEINFO(IndexExpression, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -88,6 +91,8 @@ class IndexMap : public TestObject {

/// Return the "writes" to this index map as a
[[nodiscard]] std::map<big_int, std::pair<int, const IR::Constant *>> unravelMap() const;

DECLARE_TYPEINFO(IndexMap, TestObject);
};

/* =========================================================================================
Expand All @@ -109,6 +114,8 @@ class Bmv2V1ModelRegisterValue : public IndexMap {

[[nodiscard]] const Bmv2V1ModelRegisterValue *evaluate(const Model &model,
bool doComplete) const override;

DECLARE_TYPEINFO(Bmv2V1ModelRegisterValue, IndexMap);
};

/* =========================================================================================
Expand All @@ -130,6 +137,8 @@ class Bmv2V1ModelMeterValue : public IndexMap {

/// @returns whether the meter associated with this meter value object is a direct meter.
[[nodiscard]] bool isDirectMeter() const;

DECLARE_TYPEINFO(Bmv2V1ModelMeterValue, IndexMap);
};

/* =========================================================================================
Expand Down Expand Up @@ -162,6 +171,8 @@ class Bmv2V1ModelActionProfile : public TestObject {

[[nodiscard]] const Bmv2V1ModelActionProfile *evaluate(const Model &model,
bool doComplete) const override;

DECLARE_TYPEINFO(Bmv2V1ModelActionProfile, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -189,6 +200,8 @@ class Bmv2V1ModelActionSelector : public TestObject {

[[nodiscard]] const Bmv2V1ModelActionSelector *evaluate(const Model &model,
bool doComplete) const override;

DECLARE_TYPEINFO(Bmv2V1ModelActionSelector, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -230,6 +243,8 @@ class Bmv2V1ModelCloneInfo : public TestObject {

/// @returns the state that was cloned at the time of generation of this object.
[[nodiscard]] const ExecutionState &getClonedState() const;

DECLARE_TYPEINFO(Bmv2V1ModelCloneInfo, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -273,6 +288,8 @@ class Bmv2V1ModelCloneSpec : public TestObject {
/// @returns the evaluated session id. This means it must be a constant.
/// The function will throw a bug if this is not the case.
[[nodiscard]] const IR::Constant *getEvaluatedSessionId() const;

DECLARE_TYPEINFO(Bmv2V1ModelCloneSpec, TestObject);
};

/* =========================================================================================
Expand All @@ -299,6 +316,8 @@ class MetadataCollection : public TestObject {

/// @returns a metadata field from the collection.
const IR::Literal *getMetadataField(cstring name);

DECLARE_TYPEINFO(MetadataCollection, TestObject);
};

/* =========================================================================================
Expand Down Expand Up @@ -326,6 +345,8 @@ class Optional : public TableMatch {

/// @returns whether to add this optional match as an exact match.
[[nodiscard]] bool addAsExactMatch() const;

DECLARE_TYPEINFO(Optional, TableMatch);
};

class Range : public TableMatch {
Expand All @@ -351,6 +372,8 @@ class Range : public TableMatch {
/// @returns the inclusive end of the range. It is expected to be a constant at this point.
/// A BUG is thrown otherwise.
[[nodiscard]] const IR::Constant *getEvaluatedHigh() const;

DECLARE_TYPEINFO(Range, TableMatch);
};

} // namespace P4Tools::P4Testgen::Bmv2
Expand Down
Loading

0 comments on commit 62b572e

Please sign in to comment.