def test_ab(): ''' Initialize core with 100 blocks. Core is automatically initialized with DAT.F $0, $0. Only 3 blocks are required, but MOD core_size is being applied to some operations, so core_size must be greater. ''' test_core = core.Core(100) # add instructions to core test_core.set_at( 0, instruction.Instruction(None, test_core.size, "MOD", "AB", "$", 1, "$", 2)) test_core.set_at( 1, instruction.Instruction(None, test_core.size, "ADD", "B", "#", 3, "*", 4)) test_core.set_at( 2, instruction.Instruction(None, test_core.size, "SUB", "AB", "{", 5, "}", 7)) # execute only the first instruction test_core.execute(0) # check if it was executed correctly (if third block was updated with correct values) assert test_core.get_at(2) == instruction.Instruction( None, test_core.size, "SUB", "AB", "{", 5, "}", 1)
def chech_for_modifier(modifier): ''' Initialize core with 100 blocks. Core is automatically initialized with DAT.F $0, $0. Only 3 blocks are required, but MOD core_size is being applied to some operations, so core_size must be greater. ''' test_core = core.Core(100) test_warior = warior.Warior("test_warior", "#ff0000") test_core.add_warior(test_warior) # add instruction to core test_core.set_at( 0, instruction.Instruction(test_warior, test_core.size, "DAT", modifier, "$", 0, "$", 0)) # execute only the first instruction test_core.execute_current_ins() # check if it was executed correctly (if no blocks have been changed) assert test_core.get_at(0) == instruction.Instruction( test_warior, test_core.size, "DAT", modifier, "$", 0, "$", 0) for i in range(1, 100): assert test_core.get_at(i) == instruction.Instruction( None, test_core.size, "DAT", "F", "$", 0, "$", 0) # check if process has been terminated assert len(test_warior.processes) == 0
def test_a_zero(): ''' Initialize core with 100 blocks. Core is automatically initialized with DAT.F $0, $0. Only 3 blocks are required, but MOD core_size is being applied to some operations, so core_size must be greater. ''' test_core = core.Core(100) test_warior = warior.Warior("test_warior", "#ff0000") test_core.add_warior(test_warior) # add instructions to core test_core.set_at( 0, instruction.Instruction(test_warior, test_core.size, "MOD", "A", "$", 1, "$", 2)) test_core.set_at( 1, instruction.Instruction(None, test_core.size, "ADD", "B", "#", 0, "*", 4)) test_core.set_at( 2, instruction.Instruction(None, test_core.size, "SUB", "AB", "{", 5, "}", 7)) # execute only the first instruction test_core.execute_current_ins() # check if it was executed correctly (if process has been terminated) assert len(test_warior.processes) == 0
def new_inst(self): inst_rand = util.get_inst() for inst in inst_rand: if (inst == 0): self.inst.append( instruction.Instruction(self.id.value, "CALC", None)) elif (inst == 1): addr = util.get_randint(0, 15) self.inst.append( instruction.Instruction(self.id.value, "READ", [addr])) elif (inst == 2): addr = util.get_randint(0, 15) data = util.get_randint(0, 65535) self.inst.append( instruction.Instruction(self.id.value, "WRITE", [addr, data])) """
def chech_for_modifier(modifier): ''' Initialize core with 100 blocks. Core is automatically initialized with DAT.F $0, $0. Only 3 blocks are required, but MOD core_size is being applied to some operations, so core_size must be greater. ''' test_core = core.Core(100) # add instructions to core test_core.set_at( 0, instruction.Instruction(None, test_core.size, "NOP", modifier, "$", 1, "$", 2)) test_core.set_at( 1, instruction.Instruction(None, test_core.size, "ADD", "B", "#", 3, "*", 4)) test_core.set_at( 2, instruction.Instruction(None, test_core.size, "MOV", "AB", "{", 5, "}", 7)) # execute only the first instruction test_core.execute(0) # check if it was executed correctly (if no blocks have been changed) assert test_core.get_at(0) == instruction.Instruction( None, test_core.size, "NOP", modifier, "$", 1, "$", 2) assert test_core.get_at(1) == instruction.Instruction( None, test_core.size, "ADD", "B", "#", 3, "*", 4) assert test_core.get_at(2) == instruction.Instruction( None, test_core.size, "MOV", "AB", "{", 5, "}", 7) for i in range(3, 100): assert test_core.get_at(i) == instruction.Instruction( None, test_core.size, "DAT", "F", "$", 0, "$", 0)
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.instructions = [] # 2. Process text (if any) if text is not None and len(text) > 0: for line in text: self.instructions.append(instruction.Instruction(text=line, part2=part2))
def __init__(self, size): self.size = size self.__core = [] for _ in range(size): def_ins = instruction.Instruction(None, self.size, "DAT", "F", "$", 0, "$", 0) self.__core.append(def_ins) # fill core with DAT instructions self.ins_reg = register.Register() # instruction register self.src_reg = register.Register() # source register self.dst_reg = register.Register() # destination register self.wariors = [] self.curr_warior_index = 0 self.gui = None
def test_a(): ''' Initialize core with 100 blocks. Core is automatically initialized with DAT.F $0, $0. Only 3 blocks are required, but MOD core_size is being applied to some operations, so core_size must be greater. ''' test_core = core.Core(100) test_warior = warior.Warior("test_warior", "#ff0000") test_warior.add_process(3) test_core.add_warior(test_warior) # add instruction to core test_core.set_at(3, instruction.Instruction( test_warior, test_core.size, "JMP", "A", "$", 5, "$", 0)) # execute only the first instruction test_core.execute_current_ins() # check if warior address has been changed properly assert test_warior.processes[test_warior.curr_proc_index] == 8
def add(self, time, action_str, *args, **kwargs): if kwargs.has_key("enable"): enable = bool(kwargs.pop("enable")) else: enable = True time = int(time) functions = None if "functions" in kwargs.keys(): functions = kwargs["functions"].copy() del kwargs["functions"] action = self.system.action_list.get(str(action_str), *args, **kwargs) if functions is not None: if "funct_enable" in functions: funct_enable = functions["funct_enable"] del functions["funct_enable"] else: funct_enable = True if funct_enable: for f_key in functions: if f_key == "time": time_ms = functions[f_key](self.system.get_time(time)) time = self.system.set_time(time_ms) else: setattr(action, f_key, functions[f_key](getattr(action, f_key))) if isinstance(action, lib_ramp.Ramp): action = action.get_prg() if isinstance(action, (lib_action.Action, Program)): istr = lib_instructions.Instruction(time, action, enable=enable, parents=self) self.instructions[istr.uuid] = istr else: print "WARNING: trying to add at time %d of program \"%s\" an action of type \"%s\" (instead of \"%s\" or \"%s\")" % ( time, self.name, str(action), str( lib_action.Action), str(Program))
def __init__(self, source): self.instructions = [] self.machine_code = [] self.registers = [0] * 32 self.registers[29] = 0x1000 self.labels = {} self.pc = 0 self.memory = stack.Stack(self.registers[29]) self.hi = 0 self.lo = 0 counter = 0 # build the label dictionary ahead of time addr_counter = 0 for line in source: # remove comments and whitespace tokens = line.split("#")[0].split() tokens = [i.split(",")[0].lstrip().rstrip() for i in tokens] i = 0 while i < len(tokens): if tokens[i].find(":") != -1: self.labels[tokens[i][:-1]] = addr_counter tokens.pop(i) else: i += 1 if len(tokens) > 0: addr_counter += ins.Instruction.SIZE # now create instructions line_counter = 0 for line in source: inst = conv.convert_line(line, counter, self.labels) if inst != None: new_instruction = ins.Instruction(self, line, line_counter) self.machine_code.append(inst) self.instructions.append(new_instruction) counter += ins.Instruction.SIZE line_counter += 1 self.inst_count = counter // 4
def main(): if len(sys.argv) != 2: print("Missing input file") inst = [] labels = [] with open(sys.argv[1], "r") as f: for l in f: # Remove pre and post whitespace l = l.strip() if len(l) != 0 and l[0] != "#": if l[-1:] == ":": # This is a label label_text = l[:-1] for label in labels: if label.label == label_text: raise instruction.InvalidInstruction(l) labels.append(Label(label_text, len(inst))) else: # This is an instruction inst.append(instruction.Instruction(l)) for i in range(len(inst)): if inst[i].label != "": for label in labels: if label.label == inst[i].label: inst[i].set_offset(label.calc_offset(i)) if not inst[i].is_set_offset(): raise instruction.InvalidInstruction(inst[i].asm) with open(OUT_FILE, "w") as f: for i in inst: f.write("%08x\n" % i.to_binary())
def __init__(self,partNumber): #Initialize properties self.PartNumber = partNumber self.Instructions = {} self.Builder = None self.RawResponse = None self.PartGuid = None self.SerialGuid = None self.SerialNumber = None self.StartBuildTime = None self.StopBuildTime = None #self.BuildTime = None item = ITEM_TEMPLATE%(partNumber) self.RawResponse = araslib.ApplyItem(item) i = 0 root = ET.fromstring(self.RawResponse) self.PartGuid = root.find(".//Item[@type='Part']").get("id") for instructionItem in root.findall(".//Item[@type='Part Assembly Instructions']"): i += 1 sort_order = instructionItem.find('sort_order').text t1 = instructionItem.findall(".//Item[@type='Assembly Instruction']") t2 = t1[0] instructionText = t2.find('rl_instruction').text imageEl = t2.find('rl_image') if not imageEl is None: instructionImageGuid = t2.find('rl_image').text instructionImageName = t2.find('rl_image').get('keyed_name') instructionUrl = 'http://' + server + '/' + vault + '?dbName=' + database + '&fileID=' + instructionImageGuid + '&fileName=' + instructionImageName else: instructionImageGuid = "" instructionImageName = "" instructionUrl = "" #print sort_order, instructionText, instructionImageGuid, instructionImageName, instructionUrl instructionInstance = INSTR.Instruction(sort_order, instructionText, instructionImageName, instructionImageGuid, instructionUrl) self.Instructions[i] = instructionInstance
def disassembleBlock(data): """Converts binary data into MIPS""" return [ instruction.Instruction(w) for w in struct.unpack('>' + 'L' * (len(data) // 4), data) ]
def test_something(self): i = "J" args = [1, 2, 3] jump_instruction = instruction.Instruction() jump_instruction.from_raw(i, args) print(jump_instruction.to_command())
def instruction(self): """Show screen with intructions to game""" instruction.Instruction(self.screen).run()
## Random number generator for load targets randLoadTarget = RandomInteger( ) # Load target: 0 -- (numHistRegs-1) e.g., r0 -- r15 randLoadTarget.setBinType(1) randLoadTarget.addBin(numHistRegs, 0) if (verbosity > 0): randLoadTarget.printBins() insts = [[] for i in range(numThreads)] for thread in range(numThreads): for inst in range(numInsts): instType = randInstType.genRand() address = randAddress.genRand() loadTarget = randLoadTarget.genRand() currInst = instruction.Instruction(instType, address, loadTarget) insts[thread].append(currInst) # Print generated instructions if (verbosity > 0): print("### Printing generated instructions") for thread in range(numThreads): print("Thread %d" % (thread)) for inst in range(len(insts[thread])): insts[thread][inst].printInst() ############################################################ ## Create constraint edges (intra-thread) ############################################################ ## Memory reordering rules (either different or same address)