def __init__(self, text): bit_format, effect_format = text.split('@', 2) items = bit_format.split(None, 3) self.bitPattern = items[0] self.cycles = int(items[1]) self.name = items[2] operandText = "" if len(items) >= 4: operandText = items[3] if not operandText: self.operands = [] else: self.operands = [x.strip() for x in operandText.split(", ")] if "v16" in operandText: self.argSize = 2 elif "v8" in operandText: self.argSize = 1 else: self.argSize = 0 assert len(self.bitPattern) == 8 self.effect = OpcodeEffect(effect_format)
def __init__(self, text): """ Initialise the Single Opcode Decoder by parsing the opcode text string which contains the various details of each instruction, such as the bit format, argument details etc. An example of the format of text is: 00011000 3 JP v8_rel @ read: write: sideeffects; :param text: """ bit_format, effect_format = text.split('@', 2) #the bit_format is the format such as bit pattern, cycles and name # the effect_format is what registers it effects both for read and write items = bit_format.split(None, 3) self.bitPattern = items[0] self.cycles = int(items[1]) self.name = items[2]; operandText = ""; #operands are the arguments/parameters to the opcode (not all opcode have them) if len(items) >= 4: operandText = items[3] if not operandText: self.operands = [] else: self.operands = [x.strip() for x in operandText.split(", ")] if "v16" in operandText: #check if 16 bit opcode arguments self.argSize = 2; elif "v8" in operandText: #check if 8 bit opcode arguments self.argSize = 1; else: self.argSize = 0; #otherwise no opcode arguments (e.g NOP) assert len(self.bitPattern) == 8 #make sure we haven't missed a bit in the bit pattern self.effect = OpcodeEffect(effect_format) #the effect on running the opcode (register/memory changes)