1# Copyright (c) 2003-2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 50 unchanged lines hidden (view full) --- 59 self.microops.append(microop) 60 61 def __str__(self): 62 string = "%s:\n" % self.name 63 for microop in self.microops: 64 string += " %s\n" % microop 65 return string 66 |
67class Combinational_Macroop(Micro_Container): |
68 pass 69 |
70class Rom_Macroop(object): 71 def __init__(self, name, target): 72 self.name = name 73 self.target = target 74 |
75class Rom(Micro_Container): 76 def __init__(self, name): 77 super(Rom, self).__init__(name) 78 self.externs = {} 79 80########################################################################## 81# 82# Support classes --- 227 unchanged lines hidden (view full) --- 310 'block : LBRACE statements RBRACE' 311 block = Block() 312 block.statements = t[2] 313 t[0] = block 314 315# Defines a section of microcode that should go in the current ROM 316def p_rom_block(t): 317 'rom_block : DEF ROM block SEMI' |
318 if not t.parser.rom: 319 print_error("Rom block found, but no Rom object specified.") 320 raise TypeError, "Rom block found, but no Rom object was specified." |
321 for statement in t[3].statements: 322 handle_statement(t.parser, t.parser.rom, statement) 323 t[0] = t.parser.rom 324 325# Defines a macroop that jumps to an external label in the ROM 326def p_macroop_def_0(t): 327 'macroop_def : DEF MACROOP ID LPAREN ID RPAREN SEMI' |
328 if not t.parser.rom_macroop_type: 329 print_error("ROM based macroop found, but no ROM macroop class was specified.") 330 raise TypeError, "ROM based macroop found, but no ROM macroop class was specified." 331 macroop = t.parser.rom_macroop_type(t[3], t[5]) 332 t[0] = macroop |
333 |
334 |
335# Defines a macroop that is combinationally generated 336def p_macroop_def_1(t): 337 'macroop_def : DEF MACROOP ID block SEMI' 338 try: 339 curop = t.parser.macro_type(t[3]) 340 except TypeError: 341 print_error("Error creating macroop object.") 342 raise --- 103 unchanged lines hidden (view full) --- 446def p_error(t): 447 if t: 448 error(t.lineno, "syntax error at '%s'" % t.value) 449 else: 450 error(0, "unknown syntax error", True) 451 452class MicroAssembler(object): 453 |
454 def __init__(self, macro_type, microops, 455 rom = None, rom_macroop_type = None): |
456 self.lexer = lex.lex() 457 self.parser = yacc.yacc() 458 self.parser.macro_type = macro_type 459 self.parser.macroops = {} 460 self.parser.microops = microops 461 self.parser.rom = rom |
462 self.parser.rom_macroop_type = rom_macroop_type |
463 464 def assemble(self, asm): 465 self.parser.parse(asm, lexer=self.lexer) 466 # Begin debug printing 467 for macroop in self.parser.macroops.values(): 468 print macroop 469 print self.parser.rom 470 # End debug printing 471 macroops = self.parser.macroops 472 self.parser.macroops = {} 473 return macroops |