Ejemplo n.º 1
0
def main():
    # test code
    from asmyacc import parser

    flat = []
    for line in open('../benchmarks/pi.s', 'r').readlines():
        if not line.strip(): continue
        flat.append(parser.parse(line))
    c = CFG(flat)
    return c
Ejemplo n.º 2
0
def main():
    # test code
    from asmyacc import parser

    flat = []
    for line in open('../benchmarks/pi.s', 'r').readlines():
        if not line.strip(): continue
        flat.append(parser.parse(line))
    flat = parse_instr.parse(flat)
    c = CFG(flat)
    d = Dataflow(c)
    d.print_sets()
    #d.get_reach(c.get_block("$L7"))
    
    
    return c
Ejemplo n.º 3
0
def main():
    # test code
    from asmyacc import parser

    flat = []
    for line in open('../benchmarks/whet.s', 'r').readlines():
        if not line.strip(): continue
        flat.append(parser.parse(line))
        
    for inst in flat:
        if type(inst)==Instr:
            try:
                Instruction(inst)
            except Exception as e:
                print inst.instr, inst.args
                raise e
Ejemplo n.º 4
0
    def __init__(self, lines, verbosity = 0):
        """
        Convert expressions to IR.
        """
        
        self.verbosity = verbosity
        self.stats = {'cp':0,'cf':0,'dc':0}
        self.logger = logging.getLogger('Optimiser')

        self.logger.info('parsing assembly')
        # Parse assembly and store in flat.
        self.flat = []
        for line in lines:
            if not line.strip():
                # We skip empty lines. We could also tell yacc to put them in a Raw.
                continue
            self.flat.append(parser.parse(line))
        self.flat = parse_instr.parse(self.flat)
Ejemplo n.º 5
0
def main():
    # test code
    from asmyacc import parser

    flat = []
    for line in open('../benchmarks/pi.s', 'r').readlines():
        if not line.strip(): continue
        flat.append(parser.parse(line))
    flat = parse_instr.parse(flat)
    c = CFG(flat)
    d = Dataflow(c)
    l = Liveness(c)
    change = True
    while change:
        l.analyse()
        change = l.optimise()  
    for ins in flat:
        print ins
    #1d.print_sets()
    #d.get_reach(c.get_block("$L7"))
    
    
    return c
Ejemplo n.º 6
0
    def __init__(self, lines, verbosity = 0, enabled_optimisations = None):
        """
        Convert expressions to IR.
        """
        
        self.verbosity = verbosity
        self.logger = logging.getLogger('Optimiser')
        if enabled_optimisations == None:
            self.enabled_optimisations = 'abcdefghijkl'
        else:
            self.enabled_optimisations = enabled_optimisations

        self.stats = {'cp':0, 'cf':0, 'dc':0}

        self.logger.info('parsing assembly')
        # Parse assembly and store in flat.
        self.flat = []
        for line in lines:
            if not line.strip():
                # We skip empty lines. We could also tell yacc to put them in a Raw.
                # TODO: skippet yacc dit niet sowieso?
                continue
            self.flat.append(parser.parse(line))
        self.flat = parse_instr.parse(self.flat)
Ejemplo n.º 7
0
for line in open(filename):
	# for every macro currently defined, replace the macro with the value
	for (macro, value) in macros.items():
		line = line.replace(macro, value)
	b = define.match(line)
	if b is not None:
		# add new macros found by the preprocessor
		macro, value = b.groups() 
		macros[macro] = value
		
		data += '\n'
	else:
		data += line

# run the parser
result = parser.parse(data)
if result is not None:	
	# write out the encoded value of all the instructions
	size = 0
	b = open(file=outfile, mode="w")
	for instr in result:
		size += instr.size
		b.write(instr.encode(symbol_table))
		b.write("\n")
	if padTo is not None:
		b.write("0000\n"*(padTo - size))

	# Print out information for the user.
	if summary or recall or dump:
			
		if dump or recall:
Ejemplo n.º 8
0
 def addlines(self, lines):
     for line in lines:
         if not line.strip():
             continue
         self.flat.append(parser.parse(line))
Ejemplo n.º 9
0
                
    
def optimise(instruction_list):
    """
    This functions calls a number of flat optimalization routines and
    returns the improved list.
    """
    old_len = 1
    new_len = 0
    while old_len != new_len:
        old_len = len(instruction_list)
        instruction_list = optimize_jump(instruction_list)
        instruction_list = optimize_brench(instruction_list)
        new_len = len(instruction_list)
    return instruction_list
    
if __name__ == '__main__':
    if len(sys.argv) > 1:
        raise_on_error = True
        instruction_list = []
        for line in open(sys.argv[1], 'r').readlines():
           if not line.strip(): continue
           instruction_list.append(parser.parse(line))

        instruction_list = optimise(instruction_list)
        for ins in instruction_list:
            if type(ins) == Label:
                print ins
            elif type(ins) != Comment:
                print "\t" + str(ins)