# Path: x86tokenizer.py
# class tokenizeError(Exception):pass
# REGISTER,OPCODE,COMMA,OPERAND,LBRACKET,RBRACKET,NUMBER,SYMBOL,STRING = range(1,10)
# def tokenizeString(s,reToProcess):
# def tokenizeInstDef(s):
# def tokenizeInst(s):
# 
# Path: x86inst.py
# class OpcodeTooShort(Exception):pass
# class OpcodeNeedsModRM(Exception):pass # for /d info and SIB calculation
# class x86instError(Exception):pass
# class OpcodeDict(dict):
# class MnemonicDict(dict):
# class ModRM:
# class instruction:
# class instructionInstance:
#     def __getitem__(self,key):
#     def __setitem__(self,key,value):
#     def GetOp(self,opcode,modRM=None):
#     def __setitem__(self,key,val):
# def longToBytes(long, bytes=4):
# def longToString(long, bytes=4):
# def longToBytesRepr(long,bytes=4):
#     def __init__(self,byte=None):
#     def LoadFromByte(self,byte):
#     def SaveToByte(self):
#     def HasSIB(self):
#     def RegOpString(self,typ):
#     def RMString(self,typ=None):
#     def GetDisplacementSize(self):
#     def __init__(self,opstr,inststr,desc):
#     def loadRBWD(self,plus,reg):
#     def setOpcodeAndFlags(self):
#     def setHasFlags(self):
#     def GetInstance(self):
#     def __str__(self):
#     def __init__(self,inst):
#     def GetSymbolPatchins(self,modrm=None):
#     def GetSuffixSize(self,modrm=None):
#     def GetInstructionSize(self):
#     def NextInstructionLoc(self):
#     def LoadData(self, data):
#     def DataText(self,data,size,skip=False):
#     def LoadConcreteValues(self, toks):
#     def OpDataAsString(self):
#     def OpText(self):
#             OS = self.OpcodeString
#             IS = self.InstructionString
#             ID = self.Description
#             OS = OS.replace(plus,plus[1:])
#             OS = OS.replace("%X" % self.Opcode[0], '%X' % (self.Opcode[0] + i))
#             IS = IS.replace(reg, regOpcode[reg][i])
# RELATIVE,DIRECT = range(1,3)


from x86tokenizer import (tokenizeInst,
                          REGISTER,OPCODE,COMMA,OPERAND,
                          LBRACKET,RBRACKET,NUMBER,SYMBOL,STRING,
                          symbolRe,stringRe)
from x86inst import mnemonicDict, rb, rw, rd, instructionInstance
from tokenize import Number
from pyasm.loggers import x86asmLogger, x86sourceLogger, x86apiLogger
import types, re
        possibleLookup = getProperLookup(*rest)
        for val in registerVals:
            for restMatches in possibleLookup(*rest):
                yldVal = [val]
                yldVal.extend(restMatches)
                yield yldVal

def possibleIndirect(*toks):
    """
    This is pretty much an r/m value
        i.e. it doesn't make sense to move an r/m8 into an r32
    """    
    possibleVals = []
    lbracket,operand,rest = toks[0],toks[1],toks[2:]

    if operand[0] in (NUMBER,SYMBOL):
        # TODO: CAN WE OPTIMIZE THIS?
        possibleVals.append((OPERAND,'r/m32'))
        possibleVals.append((OPERAND,'r/m16'))
        possibleVals.append((OPERAND,'r/m8'))
    elif operand[0] == REGISTER:        
        regName = operand[1]
        if rest[0][0] == RBRACKET:
            #Special case
            possibleVals.append((REGISTER, '[%s]' % regName))
        
        if regName in rb:
            possibleVals.append((OPERAND, 'r/m8'))
        elif regName in rw:
            possibleVals.append((OPERAND,'r/m16'))

# Path: x86tokenizer.py
# class tokenizeError(Exception):pass
# REGISTER,OPCODE,COMMA,OPERAND,LBRACKET,RBRACKET,NUMBER,SYMBOL,STRING = range(1,10)
# def tokenizeString(s,reToProcess):
# def tokenizeInstDef(s):
# def tokenizeInst(s):
# 
# Path: x86inst.py
# class OpcodeTooShort(Exception):pass
# class OpcodeNeedsModRM(Exception):pass # for /d info and SIB calculation
# class x86instError(Exception):pass
# class OpcodeDict(dict):
# class MnemonicDict(dict):
# class ModRM:
# class instruction:
# class instructionInstance:
#     def __getitem__(self,key):
#     def __setitem__(self,key,value):
#     def GetOp(self,opcode,modRM=None):
#     def __setitem__(self,key,val):
# def longToBytes(long, bytes=4):
# def longToString(long, bytes=4):
# def longToBytesRepr(long,bytes=4):
#     def __init__(self,byte=None):
#     def LoadFromByte(self,byte):
#     def SaveToByte(self):
#     def HasSIB(self):
#     def RegOpString(self,typ):
#     def RMString(self,typ=None):
#     def GetDisplacementSize(self):
#     def __init__(self,opstr,inststr,desc):
#     def loadRBWD(self,plus,reg):
#     def setOpcodeAndFlags(self):
#     def setHasFlags(self):
#     def GetInstance(self):
#     def __str__(self):
#     def __init__(self,inst):
#     def GetSymbolPatchins(self,modrm=None):
#     def GetSuffixSize(self,modrm=None):
#     def GetInstructionSize(self):
#     def NextInstructionLoc(self):
#     def LoadData(self, data):
#     def DataText(self,data,size,skip=False):
#     def LoadConcreteValues(self, toks):
#     def OpDataAsString(self):
#     def OpText(self):
#             OS = self.OpcodeString
#             IS = self.InstructionString
#             ID = self.Description
#             OS = OS.replace(plus,plus[1:])
#             OS = OS.replace("%X" % self.Opcode[0], '%X' % (self.Opcode[0] + i))
#             IS = IS.replace(reg, regOpcode[reg][i])
# RELATIVE,DIRECT = range(1,3)


# Path: x86asm.py
from x86tokenizer import (tokenizeInst,
                          REGISTER,OPCODE,COMMA,OPERAND,
                          LBRACKET,RBRACKET,NUMBER,SYMBOL,STRING,
                          symbolRe,stringRe)
from x86inst import mnemonicDict, rb, rw, rd, instructionInstance
from tokenize import Number
from pyasm.loggers import x86asmLogger, x86sourceLogger, x86apiLogger
import types, re

        possibleLookup = getProperLookup(*rest)
        for val in registerVals:
            for restMatches in possibleLookup(*rest):
                yldVal = [val]
                yldVal.extend(restMatches)
                yield yldVal

def possibleIndirect(*toks):
    """
    This is pretty much an r/m value
        i.e. it doesn't make sense to move an r/m8 into an r32
    """    
    possibleVals = []
    lbracket,operand,rest = toks[0],toks[1],toks[2:]

    if operand[0] in (NUMBER,SYMBOL):
        # TODO: CAN WE OPTIMIZE THIS?
        possibleVals.append((OPERAND,'r/m32'))
        possibleVals.append((OPERAND,'r/m16'))
        possibleVals.append((OPERAND,'r/m8'))
    elif operand[0] == REGISTER:        
        regName = operand[1]
        if rest[0][0] == RBRACKET:
            #Special case
            possibleVals.append((REGISTER, '[%s]' % regName))
        
        if regName in rb:
            possibleVals.append((OPERAND, 'r/m8'))
        elif regName in rw:
            possibleVals.append((OPERAND,'r/m16'))

        elif regName in rd: