Add Lua instruction info tests
@@ -18,6 +18,7 @@ describe("Instruction", function()
local MemorySize = require("iced_x86.MemorySize")
local Mnemonic = require("iced_x86.Mnemonic")
local MvexRegMemConv = require("iced_x86.MvexRegMemConv")
+ local OpAccess = require("iced_x86.OpAccess")
local OpKind = require("iced_x86.OpKind")
local Register = require("iced_x86.Register")
local RflagsBits = require("iced_x86.RflagsBits")
@@ -1518,4 +1519,57 @@ describe("Instruction", function()
local op_code = instr:op_code()
assert.equals(Code.Adc_AL_imm8, op_code:code())
end)
+
+ it("instr info", function()
+ local decoder = Decoder:new(64, from_hex("C4E349 48 10 41"))
+ local instr = decoder:decode()
+
+ local used_registers1, is_nil1 = instr:used_registers()
+ assert.is_nil(is_nil1)
+ local used_memory1, is_nil2 = instr:used_memory()
+ assert.is_nil(is_nil2)
+ local op_accesses1, is_nil3 = instr:op_accesses()
+ assert.is_nil(is_nil3)
+ local used_registers2, used_memory2, is_nil4 = instr:used_regs_mem()
+ assert.is_nil(is_nil4)
+ local used_registers3, used_memory3, op_accesses3, is_nil5 = instr:used_values()
+ assert.is_nil(is_nil5)
+
+ assert.same(used_registers1, used_registers2)
+ assert.same(used_registers1, used_registers3)
+ assert.same(used_memory1, used_memory2)
+ assert.same(used_memory1, used_memory3)
+ assert.same(op_accesses1, op_accesses3)
+
+ assert.same({ OpAccess.Write, OpAccess.Read, OpAccess.Read, OpAccess.Read, OpAccess.Read }, op_accesses1)
+
+ assert.equals(1, #used_memory1)
+ local mem = used_memory1[1]
+ assert.equals(Register.DS, mem:segment())
+ assert.equals(Register.RAX, mem:base())
+ assert.equals(Register.None, mem:index())
+ assert.equals(1, mem:scale())
+ assert.equals(0, mem:displacement())
+ assert.equals(MemorySize.Packed128_Float32, mem:memory_size())
+ assert.equals(OpAccess.Read, mem:access())
+ assert.equals(CodeSize.Code64, mem:address_size())
+ assert.equals(0, mem:vsib_size())
+
+ assert.equals(4, #used_registers1)
+ assert.same({ Register.ZMM2, OpAccess.Write }, { used_registers1[1]:register(), used_registers1[1]:access() })
+ assert.same({ Register.XMM6, OpAccess.Read }, { used_registers1[2]:register(), used_registers1[2]:access() })
+ assert.same({ Register.RAX, OpAccess.Read }, { used_registers1[3]:register(), used_registers1[3]:access() })
+ assert.same({ Register.XMM4, OpAccess.Read }, { used_registers1[4]:register(), used_registers1[4]:access() })
+
+ local mem2 = mem:copy()
+ assert.is_true(mem == mem2)
+ assert.is_true(mem2 == mem)
+
+ local reg1 = used_registers1[1]
+ local reg2 = reg1:copy()
+ local reg3 = used_registers1[2]
+ assert.is_true(reg1 == reg2)
+ assert.is_true(reg2 == reg1)
+ assert.is_false(reg1 == reg3)
+ end)
end)
