add traits to instructions for decoder table
This commit is contained in:
parent
dbec45533b
commit
5e8ddc2c32
1 changed files with 50 additions and 10 deletions
60
genc.py
60
genc.py
|
|
@ -23,12 +23,34 @@ class Instruction:
|
|||
|
||||
def get_type(self):
|
||||
pass
|
||||
|
||||
def has_rex(self):
|
||||
return False
|
||||
|
||||
def has_digit(self):
|
||||
return False
|
||||
|
||||
def has_modrm(self):
|
||||
pass
|
||||
return False
|
||||
|
||||
def has_imm(self):
|
||||
return False
|
||||
|
||||
def has_value(self):
|
||||
return False
|
||||
|
||||
def has_opreg(self):
|
||||
return False
|
||||
|
||||
def does_modrm(self):
|
||||
if self.has_modrm():
|
||||
if self.has_digit():
|
||||
return self.modrm or self.digit is not None
|
||||
else: return self.modrm is not None
|
||||
else: return False
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.get_type()}> {self.mnemonic} bytes {self.bytes} has_modrm {self.has_modrm()}"
|
||||
return f"<{self.get_type()}> {self.mnemonic} bytes {self.bytes} does_modrm {self.does_modrm()}"
|
||||
|
||||
class InstructionCommon:
|
||||
REX_REGEX = re.compile("^REX\\.(.)")
|
||||
|
|
@ -69,8 +91,23 @@ class StandardInstruction(Instruction):
|
|||
def get_type(self):
|
||||
return InstructionType.STANDARD
|
||||
|
||||
def has_rex(self):
|
||||
return self.rex is not None
|
||||
|
||||
def has_digit(self):
|
||||
return self.digit is not None
|
||||
|
||||
def has_modrm(self):
|
||||
return self.modrm or self.digit is not None
|
||||
return self.modrm
|
||||
|
||||
def has_imm(self):
|
||||
return self.imm is not None
|
||||
|
||||
def has_value(self):
|
||||
return self.value is not None
|
||||
|
||||
def has_opreg(self):
|
||||
return self.opreg is not None
|
||||
|
||||
def __str__(self):
|
||||
return f"{super().__str__()} rex {self.rex} digit {self.digit} modrm {self.modrm} imm {self.imm} value {self.value} opreg {self.opreg}"
|
||||
|
|
@ -111,9 +148,6 @@ class VEXInstruction(Instruction):
|
|||
|
||||
self.modrm = True if modrm else False
|
||||
self.imm = imm.group(1) if imm else None
|
||||
|
||||
print(self)
|
||||
|
||||
|
||||
def get_type(self):
|
||||
return InstructionType.VEX
|
||||
|
|
@ -121,6 +155,9 @@ class VEXInstruction(Instruction):
|
|||
def has_modrm(self):
|
||||
return self.modrm
|
||||
|
||||
def has_imm(self):
|
||||
return self.imm is not None
|
||||
|
||||
def __str__(self):
|
||||
return f"{super().__str__()} l {self.l} lig {self.lig} w {self.w} wig {self.wig}"
|
||||
|
||||
|
|
@ -161,8 +198,6 @@ class EVEXInstruction(Instruction):
|
|||
|
||||
self.modrm = True if modrm else False
|
||||
self.imm = imm.group(1) if imm else None
|
||||
|
||||
print(self)
|
||||
|
||||
def get_type(self):
|
||||
return InstructionType.EVEX
|
||||
|
|
@ -170,6 +205,9 @@ class EVEXInstruction(Instruction):
|
|||
def has_modrm(self):
|
||||
return self.modrm
|
||||
|
||||
def has_imm(self):
|
||||
return self.imm is not None
|
||||
|
||||
def __str__(self):
|
||||
return f"{super().__str__()} l {self.l} lig {self.lig} w {self.w} wig {self.wig}"
|
||||
|
||||
|
|
@ -193,5 +231,7 @@ def parse_file(path):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#parse_file("xml/raw/x86/Intel/AZ.xml")
|
||||
parse_file("xml/raw/x86/Intel/AVX512_r22.xml")
|
||||
groups = parse_file("xml/raw/x86/Intel/AZ.xml")
|
||||
for group in groups:
|
||||
for instruction in group.instructions:
|
||||
print(instruction)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue