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 {...@@ -409,7 +409,7 @@ pub const Insn = packed struct {
409 msh = MSH,409 msh = MSH,
410 };410 };
411411
412 const AluOp = enum(u8) {412 pub const AluOp = enum(u8) {
413 add = ADD,413 add = ADD,
414 sub = SUB,414 sub = SUB,
415 mul = MUL,415 mul = MUL,
...@@ -432,7 +432,7 @@ pub const Insn = packed struct {...@@ -432,7 +432,7 @@ pub const Insn = packed struct {
432 double_word = DW,432 double_word = DW,
433 };433 };
434434
435 const JmpOp = enum(u8) {435 pub const JmpOp = enum(u8) {
436 ja = JA,436 ja = JA,
437 jeq = JEQ,437 jeq = JEQ,
438 jgt = JGT,438 jgt = JGT,
...@@ -453,7 +453,7 @@ pub const Insn = packed struct {...@@ -453,7 +453,7 @@ pub const Insn = packed struct {
453 };453 };
454454
455 fn imm_reg(code: u8, dst: Reg, src: anytype, off: i16) Insn {455 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)
457 ImmOrReg{ .reg = @as(Reg, src) }457 ImmOrReg{ .reg = @as(Reg, src) }
458 else458 else
459 ImmOrReg{ .imm = src };459 ImmOrReg{ .imm = src };
...@@ -478,7 +478,7 @@ pub const Insn = packed struct {...@@ -478,7 +478,7 @@ pub const Insn = packed struct {
478 };478 };
479 }479 }
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 {
482 const width_bitfield = switch (width) {482 const width_bitfield = switch (width) {
483 32 => ALU,483 32 => ALU,
484 64 => ALU64,484 64 => ALU64,
...@@ -540,7 +540,7 @@ pub const Insn = packed struct {...@@ -540,7 +540,7 @@ pub const Insn = packed struct {
540 return alu(64, .arsh, dst, src);540 return alu(64, .arsh, dst, src);
541 }541 }
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 {
544 return imm_reg(JMP | @enumToInt(op), dst, src, off);544 return imm_reg(JMP | @enumToInt(op), dst, src, off);
545 }545 }
546546