Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BPF lexer #2004

Merged
merged 6 commits into from
Oct 24, 2023
Merged

Update BPF lexer #2004

merged 6 commits into from
Oct 24, 2023

Conversation

pchaigno
Copy link
Contributor

This pull request updates the BPF lexer to highlight several constructs and keywords that were either missed in the initial lexer or were recently added to BPF:

  • The s8, s16, s32, and s64 type keywords.
  • The call helper_name syntax.
  • The existing le16, le32, le64 and the new bswap16, bswap32, bswap64 keywords.
  • The -0xa5 syntax for negative hexadecimal.
  • The goto 0x1234 <label> syntax for jumps.
  • The gotol keyword for long jumps.

All come with visual examples.

Signed type keywords such as s16 have always been supported by BPF but
recently became more frequent. They were missing in the original lexer
so this commit adds them, with an example.

Signed-off-by: Paul Chaignon <[email protected]>
The lexer already supports the following syntax for call instructions:

    call bpf_skb_load_bytes#1234

but a simpler syntax without the number at the end is now also possible.
This commit adds support for it, with an example.

Signed-off-by: Paul Chaignon <[email protected]>
The original lexer was missing support for the little-endian
byte-swapping instructions le{16,32,64}. This commit adds them, together
with the new bswap{16,32,64} instructions. The later are unconditional
byte-swapping instructions, meaning they don't depend on the
architecture.

Signed-off-by: Paul Chaignon <[email protected]>
Hexadecimal literals can also have a sign in BPF. This commit fixes this
error in the lexer and adds a corresponding example.

Signed-off-by: Paul Chaignon <[email protected]>
The offset of BPF jump instructions is now sometimes displayed in
hexadecimal format. This commit adds support for that, together with an
example. It also adds an example to cover the syntax where the jump has
both an offset literal and an offset label (ex. "+1 <LBB0_2>").

Signed-off-by: Paul Chaignon <[email protected]>
Jump instructions with a 32-bit offset are displayed as "gotol" instead
of "goto".

Signed-off-by: Paul Chaignon <[email protected]>
@tancnle
Copy link
Collaborator

tancnle commented Oct 24, 2023

Thank you for the contribution @pchaigno ❤️ The changes LGTM 🚀

@tancnle tancnle added this pull request to the merge queue Oct 24, 2023
Merged via the queue into rouge-ruby:master with commit fdfcbd4 Oct 24, 2023
7 checks passed
@pchaigno pchaigno deleted the update-bpf branch October 25, 2023 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants