authorgravatar for bjorn.linse@gmail.combfredl <bjorn.linse@gmail.com> 2022-10-15 18:35:33+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-16 11:36:11-04:00
logc750d95417ec94e91a76da769db96f6810900c03
treeb92b26a4fd4b6b3da9d570800829817b6da73a58
parentb346d48572c99f809913cced8910a04d6699701d

os.linux: some fixes to BPF module

- For ALU operations, src should be allowed to be an explicit Reg. - Expose AluOp and JmpOp as public types. This makes code generation using BPF as a backend easier, as AluOp and JmpOp can be used directly as part of an IR

1 files changed, 5 insertions(+), 5 deletions(-)

lib/std/os/linux/bpf.zig+5-5
......@@ -409,7 +409,7 @@ pub const Insn = packed struct {
409409 msh = MSH,
410410 };
411411
412 const AluOp = enum(u8) {
412 pub const AluOp = enum(u8) {
413413 add = ADD,
414414 sub = SUB,
415415 mul = MUL,
......@@ -432,7 +432,7 @@ pub const Insn = packed struct {
432432 double_word = DW,
433433 };
434434
435 const JmpOp = enum(u8) {
435 pub const JmpOp = enum(u8) {
436436 ja = JA,
437437 jeq = JEQ,
438438 jgt = JGT,
......@@ -453,7 +453,7 @@ pub const Insn = packed struct {
453453 };
454454
455455 fn imm_reg(code: u8, dst: Reg, src: anytype, off: i16) Insn {
456 const imm_or_reg = if (@typeInfo(@TypeOf(src)) == .EnumLiteral)
456 const imm_or_reg = if (@TypeOf(src) == Reg or @typeInfo(@TypeOf(src)) == .EnumLiteral)
457457 ImmOrReg{ .reg = @as(Reg, src) }
458458 else
459459 ImmOrReg{ .imm = src };
......@@ -478,7 +478,7 @@ pub const Insn = packed struct {
478478 };
479479 }
480480
481 fn alu(comptime width: comptime_int, op: AluOp, dst: Reg, src: anytype) Insn {
481 pub fn alu(comptime width: comptime_int, op: AluOp, dst: Reg, src: anytype) Insn {
482482 const width_bitfield = switch (width) {
483483 32 => ALU,
484484 64 => ALU64,
......@@ -540,7 +540,7 @@ pub const Insn = packed struct {
540540 return alu(64, .arsh, dst, src);
541541 }
542542
543 fn jmp(op: JmpOp, dst: Reg, src: anytype, off: i16) Insn {
543 pub fn jmp(op: JmpOp, dst: Reg, src: anytype, off: i16) Insn {
544544 return imm_reg(JMP | @enumToInt(op), dst, src, off);
545545 }
546546