Skip to content

Commit

Permalink
Move examples from method comments to class comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-barefoot committed May 1, 2017
1 parent 6f3edb6 commit 8bc2bc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
31 changes: 6 additions & 25 deletions frontends/p4/tableKeyNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ class KeyNameGenerator : public Inspector {
{ setName("KeyNameGenerator"); }

void error(const IR::Expression* expression) {
::error("%1%: Complex key expression requires a @name annotation", expression);
::error(
"%1%: Complex key expression requires a @name annotation",
expression);
}

void postorder(const IR::Expression* expression) override { error(expression); }
void postorder(const IR::Expression* expression) override {
error(expression);
}

/** Compute a control plane name for @expression. Eg. `".foo"` for
* `.foo`.
*/
void postorder(const IR::PathExpression* expression) override {
name.emplace(expression, expression->path->toString());
}

/** Compute a control plane name for @expression. Eg. `"foo.bar"` for
* `foo.bar`.
*/
void postorder(const IR::Member* expression) override {
auto type = typeMap->getType(expression->expr, true);
cstring fname = expression->member.name;
Expand All @@ -61,9 +59,6 @@ class KeyNameGenerator : public Inspector {
name.emplace(expression, n + "." + fname);
}

/** Compute a control plane name for @expression. Eg. `"arr[5]"` for
* `arr[5]`.
*/
void postorder(const IR::ArrayIndex* expression) override {
cstring l = getName(expression->left);
cstring r = getName(expression->right);
Expand All @@ -72,9 +67,6 @@ class KeyNameGenerator : public Inspector {
name.emplace(expression, l + "[" + r + "]");
}

/** Compute a control plane name for @expression. Eg. `"bits"` for
* `bits & 0x3` or `0x3 & bits`.
*/
void postorder(const IR::BAnd *expression) override {
// TODO: this exists for P4_14 to P4_16 conversion and should live in
// the converter, not here.
Expand All @@ -88,17 +80,11 @@ class KeyNameGenerator : public Inspector {
error(expression); }
}

/** Compute a control plane name for @expression. Eg. `"4"` for
* `16w4`.
*/
void postorder(const IR::Constant* expression) override {
name.emplace(expression, expression->toString());
}


/** Compute a control plane name for @expression. Eg. `"foo[3:0]"` for
* `foo[3:0]`.
*/
void postorder(const IR::Slice* expression) override {
cstring e0 = getName(expression->e0);
cstring e1 = getName(expression->e1);
Expand All @@ -108,11 +94,6 @@ class KeyNameGenerator : public Inspector {
name.emplace(expression, e0 + "[" + e1 + ":" + e2 + "]");
}

/** Compute a name annotation if @expression is a method call for
* `isValid()`. Eg. `"f1.isValid()"` for `f1.isValid()`.
*
* Emit a compilation error for other method calls.
*/
void postorder(const IR::MethodCallExpression* expression) override {
cstring m = getName(expression->method);
if (!m)
Expand Down
8 changes: 8 additions & 0 deletions frontends/p4/tableKeyNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ namespace P4 {
* - PathExpression,
* - Slice.
*
* Examples of control plane names generated from expressions:
* - `arr[16w5].f` : `@name("arr[5].f")`
* - `f & 0x3` : `@name("f")`
* - `.foo` : `@name(".foo")`
* - `foo.bar` : `@name("foo.bar")`
* - `f.isValid()` : `@name("f.isValid()")`
* - `f[3:0]` : `@name("f[3:0]")`
*
* @pre This must run before passes that change key expressions, eg. constant
* folding. Otherwise the generated control plane names may not match the
* syntax of the original P4 program.
Expand Down

0 comments on commit 8bc2bc5

Please sign in to comment.