How to use Encode method of x86 Package

Best Syzkaller code snippet using x86.Encode

x86_64.go

Source:x86_64.go Github

copy

Full Screen

...8 "github.com/bspaans/jit-compiler/lib"9)10type X86_64 struct {11}12func (x *X86_64) EncodeExpression(expr IRExpression, ctx *IR_Context, target lib.Operand) ([]lib.Instruction, error) {13 return encodeExpression(expr, ctx, target)14}15func (x *X86_64) EncodeStatement(stmt IR, ctx *IR_Context) ([]lib.Instruction, error) {16 return encodeStatement(stmt, ctx)17}18func (x *X86_64) EncodeDataSection(stmts []IR, ctx *IR_Context) (*Segments, error) {19 segments := NewSegments()20 for _, stmt := range stmts {21 if err := encodeDataSection(stmt, ctx, segments); err != nil {22 return nil, err23 }24 }25 return segments, nil26}27func encodeExpression(e IRExpression, ctx *IR_Context, target lib.Operand) ([]lib.Instruction, error) {28 switch v := e.(type) {29 case *expr.IR_Add:30 return encode_IR_Add(v, ctx, target)31 case *expr.IR_And:32 return encode_IR_And(v, ctx, target)...

Full Screen

Full Screen

not.go

Source:not.go Github

copy

Full Screen

1package x86_642import (3 "fmt"4 . "github.com/bspaans/jit-compiler/ir/shared"5 "github.com/bspaans/jit-compiler/asm/x86_64"6 "github.com/bspaans/jit-compiler/asm/x86_64/encoding"7 "github.com/bspaans/jit-compiler/ir/expr"8 "github.com/bspaans/jit-compiler/lib"9)10func encode_IR_Not(i *expr.IR_Not, ctx *IR_Context, target lib.Operand, includeSETE bool) ([]lib.Instruction, error) {11 var reg1 lib.Operand12 result := []lib.Instruction{}13 switch c := i.Op1.(type) {14 case *expr.IR_Variable:15 variable := c.Value16 reg1 = ctx.VariableMap[variable]17 if !includeSETE {18 cmp := x86_64.CMP_immediate(1, reg1)19 result = append(result, cmp)20 ctx.AddInstruction(cmp)21 }22 case *expr.IR_Bool:23 value := uint64(0)24 if c.Value {25 value = 126 }27 reg1 = ctx.AllocateRegister(TUint64)28 defer ctx.DeallocateRegister(reg1.(*encoding.Register))29 mov := x86_64.MOV_immediate(value, reg1)30 cmp := x86_64.CMP_immediate(1, reg1)31 result = append(result, mov, cmp)32 ctx.AddInstruction(mov, cmp)33 case *expr.IR_Equals:34 var err error35 var eq []lib.Instruction36 eq, err = encode_IR_Equals(c, ctx, target, includeSETE)37 if err != nil {38 return nil, err39 }40 for _, r := range eq {41 result = append(result, r)42 }43 reg1 = target44 // TODO: introduce logical operator interface45 case *expr.IR_LT:46 var err error47 var eq []lib.Instruction48 eq, err = encode_IR_LT(c, ctx, target, includeSETE)49 if err != nil {50 return nil, err51 }52 for _, r := range eq {53 result = append(result, r)54 }55 reg1 = target56 // TODO: introduce logical operator interface57 case *expr.IR_LTE:58 var err error59 var eq []lib.Instruction60 eq, err = encode_IR_LTE(c, ctx, target, includeSETE)61 if err != nil {62 return nil, err63 }64 for _, r := range eq {65 result = append(result, r)66 }67 reg1 = target68 case *expr.IR_GT:69 var err error70 var eq []lib.Instruction71 eq, err = encode_IR_GT(c, ctx, target, includeSETE)72 if err != nil {73 return nil, err74 }75 for _, r := range eq {76 result = append(result, r)77 }78 reg1 = target79 // TODO: introduce logical operator interface80 case *expr.IR_GTE:81 var err error82 var eq []lib.Instruction83 eq, err = encode_IR_GTE(c, ctx, target, includeSETE)84 if err != nil {85 return nil, err86 }87 for _, r := range eq {88 result = append(result, r)89 }90 reg1 = target91 case *expr.IR_And:92 var err error93 var eq []lib.Instruction94 eq, err = encode_IR_And(c, ctx, target)95 if err != nil {96 return nil, err97 }98 for _, r := range eq {99 result = append(result, r)100 }101 reg1 = target102 case *expr.IR_Or:103 var err error104 var eq []lib.Instruction105 eq, err = encode_IR_Or(c, ctx, target)106 if err != nil {107 return nil, err108 }109 for _, r := range eq {110 result = append(result, r)111 }112 reg1 = target113 default:114 return nil, fmt.Errorf("Unsupported ! operation: %s", i.Op1.Type())115 }116 if includeSETE {117 tmpReg := ctx.AllocateRegister(TUint64)118 defer ctx.DeallocateRegister(tmpReg)119 instr := []lib.Instruction{}120 // TODO: use test?121 instr = append(instr, x86_64.XOR(tmpReg, tmpReg))122 instr = append(instr, x86_64.CMP_immediate(0, reg1))123 instr = append(instr, x86_64.SETE(tmpReg.(*encoding.Register).Get8BitRegister()))124 instr = append(instr, x86_64.MOV(tmpReg.(*encoding.Register).ForOperandWidth(target.Width()), target))125 for _, inst := range instr {126 result = append(result, inst)127 ctx.AddInstruction(inst)128 }129 }130 return result, nil131}...

Full Screen

Full Screen

conditional_jump.go

Source:conditional_jump.go Github

copy

Full Screen

1package x86_642import (3 "fmt"4 "github.com/bspaans/jit-compiler/asm/x86_64"5 "github.com/bspaans/jit-compiler/asm/x86_64/encoding"6 "github.com/bspaans/jit-compiler/ir/expr"7 . "github.com/bspaans/jit-compiler/ir/shared"8 "github.com/bspaans/jit-compiler/lib"9)10func conditionalJump(ctx *IR_Context, condition IRExpression, stmtLen int) ([]lib.Instruction, error) {11 jmpSize := 212 reg := ctx.AllocateRegister(TBool)13 defer ctx.DeallocateRegister(reg)14 var result []lib.Instruction15 var instr []lib.Instruction16 var err error17 switch condition.(type) {18 case *expr.IR_Equals:19 c := condition.(*expr.IR_Equals)20 result, err = encode_IR_Equals(c, ctx, reg, false)21 instr = []lib.Instruction{22 x86_64.JNE(encoding.Uint8(stmtLen + jmpSize)),23 }24 case *expr.IR_LT:25 c := condition.(*expr.IR_LT)26 result, err = encode_IR_LT(c, ctx, reg, false)27 if IsSignedInteger(c.Op1.ReturnType(ctx)) {28 instr = []lib.Instruction{29 x86_64.JNL(encoding.Uint8(stmtLen + jmpSize)),30 }31 } else {32 instr = []lib.Instruction{33 x86_64.JNB(encoding.Uint8(stmtLen + jmpSize)),34 }35 }36 case *expr.IR_LTE:37 c := condition.(*expr.IR_LTE)38 result, err = encode_IR_LTE(c, ctx, reg, false)39 if IsSignedInteger(c.Op1.ReturnType(ctx)) {40 instr = []lib.Instruction{41 x86_64.JNLE(encoding.Uint8(stmtLen + jmpSize)),42 }43 } else {44 instr = []lib.Instruction{45 x86_64.JNBE(encoding.Uint8(stmtLen + jmpSize)),46 }47 }48 case *expr.IR_GT:49 c := condition.(*expr.IR_GT)50 result, err = encode_IR_GT(c, ctx, reg, false)51 if IsSignedInteger(c.Op1.ReturnType(ctx)) {52 instr = []lib.Instruction{53 x86_64.JNG(encoding.Uint8(stmtLen + jmpSize)),54 }55 } else {56 instr = []lib.Instruction{57 x86_64.JNA(encoding.Uint8(stmtLen + jmpSize)),58 }59 }60 case *expr.IR_GTE:61 c := condition.(*expr.IR_GTE)62 result, err = encode_IR_GTE(c, ctx, reg, false)63 if IsSignedInteger(c.Op1.ReturnType(ctx)) {64 instr = []lib.Instruction{65 x86_64.JNGE(encoding.Uint8(stmtLen + jmpSize)),66 }67 } else {68 instr = []lib.Instruction{69 x86_64.JNAE(encoding.Uint8(stmtLen + jmpSize)),70 }71 }72 case *expr.IR_Not:73 result, err = encode_IR_Not(condition.(*expr.IR_Not), ctx, reg, false)74 instr = []lib.Instruction{75 x86_64.JE(encoding.Uint8(stmtLen + jmpSize)),76 }77 case *expr.IR_And:78 result, err = encode_IR_And(condition.(*expr.IR_And), ctx, reg)79 instr = []lib.Instruction{80 x86_64.JE(encoding.Uint8(stmtLen + jmpSize)),81 }82 case *expr.IR_Or:83 result, err = encode_IR_Or(condition.(*expr.IR_Or), ctx, reg)84 instr = []lib.Instruction{85 x86_64.JE(encoding.Uint8(stmtLen + jmpSize)),86 }87 case *expr.IR_Bool, *expr.IR_Variable:88 result, err = encodeExpression(condition, ctx, reg)89 instr = []lib.Instruction{90 x86_64.CMP_immediate(1, reg),91 x86_64.JNE(encoding.Uint8(stmtLen + jmpSize)),92 }93 default:94 return nil, fmt.Errorf("Unsupported condition %s (type: %v)", condition.String(), condition.Type())95 }96 if err != nil {97 return nil, err98 }99 for _, inst := range instr {100 ctx.AddInstruction(inst)101 result = append(result, inst)102 }103 return result, nil104}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful