Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/bbannier/spicy-hook-priority'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Apr 25, 2024
2 parents 6ea3102 + 4e7f29c commit b1f54e4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
18 changes: 18 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
1.11.0-dev.137 | 2024-04-25 13:38:42 +0200

* Remove Spicy parser support for unsupported `&priority` attribute. (Benjamin Bannier, Corelight)

* Make spelling of hook `priority` consistent across Spicy and HILTI. (Benjamin Bannier, Corelight)

We were naming the priority attribute differently in Spicy (`priority`)
and HILTI (`&priority`). While e.g., a Spicy `Hook` could correct
extract its priority, this still could have lead to potential issues if
we were attempting to access the priority of a Spicy hook from HILTI as
we do not perform any adjustment of this attribute when lowering to
HILTI. This distinction also made it hard to generate intended code from
the outside using our API (e.g., from Zeek) since one needed to be aware
at which level the attribute was injected (Spicy or HILTI).

With this patch we internally translate a Spicy `priority` attribute to
`&attribute` syntax.

1.11.0-dev.134 | 2024-04-25 13:36:59 +0200

* Fix incremental skipping. (Benjamin Bannier, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.0-dev.134
1.11.0-dev.137
2 changes: 1 addition & 1 deletion spicy/toolchain/include/ast/declarations/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Hook : public Declaration {
auto unitFieldIndex() { return _unit_field_index; }

hilti::Expression* priority() const {
if ( auto attr = attributes()->find("priority") )
if ( auto attr = attributes()->find("&priority") )
return *attr->valueAsExpression();
else
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion spicy/toolchain/src/compiler/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ unit_hook_id: { driver->enableHookIDMode(); }

unit_hook_attribute
: FOREACH { $$ = builder->attribute("foreach", __loc__); }
| PRIORITY '=' expr { $$ = builder->attribute("priority", std::move($3), __loc__); }
| PRIORITY '=' expr { $$ = builder->attribute("&priority", std::move($3), __loc__); }
| PROPERTY { if ( $1 != "%debug" ) error(@$, "unexpected hook property, only %debug permitted");
$$ = builder->attribute("%debug", __loc__);
}
Expand Down
2 changes: 1 addition & 1 deletion spicy/toolchain/src/compiler/parser/scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ doc_field [ \t]*##<[^\n]*\n?
doc_text [ \t]*##[^\n]*\n?
comment [ \t]*#[^#\n]*\n?

attribute \&(bit-order|byte-order|chunked|convert|count|cxxname|default|eod|internal|ipv4|ipv6|hilti_type|length|max-size|no-emit|nosub|on-heap|optional|originator|parse-at|parse-from|priority|requires|responder|size|static|synchronize|transient|try|type|until|until-including|while|have_prototype)
attribute \&(bit-order|byte-order|chunked|convert|count|cxxname|default|eod|internal|ipv4|ipv6|hilti_type|length|max-size|no-emit|nosub|on-heap|optional|originator|parse-at|parse-from|requires|responder|size|static|synchronize|transient|try|type|until|until-including|while|have_prototype)
blank [ \t]
digit [0-9]
digits {digit}+
Expand Down
5 changes: 4 additions & 1 deletion tests/Baseline/spicy.types.unit.hooks-priorities/output
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
A: prio 15, 12345
B: prio 10, 12345
A: prio 7, 12345
A: prio 0, 12345
A: prio -5, 12345
B: prio 10, 12345
B: prio -10, 12345
B: prio 15
B: default prio
B: prio -5
33 changes: 23 additions & 10 deletions tests/spicy/types/unit/hooks-priorities.spicy
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# @TEST-EXEC: echo 12345| spicy-driver -p A::tA %INPUT b.spicy | sort -s -k 1,1 >output
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: echo 12345| spicy-driver -p test1::A %INPUT b.spicy >>output
# @TEST-EXEC: echo | spicy-driver -p test1::B %INPUT b.spicy >>output
# @TEST-EXEC: btest-diff output

module A;
module test1;

public type tA = unit {
public type A = unit {
a: bytes &size=5 {
print "A: prio 0", self.a;
}
Expand All @@ -13,24 +14,36 @@ public type tA = unit {
}
};

on tA::a priority=-5 {
on A::a priority=-5 {
print "A: prio -5", self.a;
}

on tA::a priority=15 {
on A::a priority=15 {
print "A: prio 15", self.a;
}

public type B = unit {
on %done {
print "B: default prio";
}
on %done priority=-5 {
print "B: prio -5";
}
on %done priority=15 {
print "B: prio 15";
}
};

### @TEST-START-FILE b.spicy
module B;
module test2;

import A;
import test1;

on A::tA::a priority=-10 {
on test1::A::a priority=-10 {
print "B: prio -10", self.a;
}

on A::tA::a priority=10 {
on test1::A::a priority=10 {
print "B: prio 10", self.a;
}
### @TEST-END-FILE test.txt

0 comments on commit b1f54e4

Please sign in to comment.