Deleted Added
sdiff udiff text old ( 4503:0f812a876221 ) new ( 4507:487b70cfd58d )
full compact
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 Macroop(Micro_Container):
68 pass
69
70class Rom(Micro_Container):
71 def __init__(self, name):
72 super(Rom, self).__init__(name)
73 self.externs = {}
74
75##########################################################################
76#
77# Support classes

--- 227 unchanged lines hidden (view full) ---

305 'block : LBRACE statements RBRACE'
306 block = Block()
307 block.statements = t[2]
308 t[0] = block
309
310# Defines a section of microcode that should go in the current ROM
311def p_rom_block(t):
312 'rom_block : DEF ROM block SEMI'
313 for statement in t[3].statements:
314 handle_statement(t.parser, t.parser.rom, statement)
315 t[0] = t.parser.rom
316
317# Defines a macroop that jumps to an external label in the ROM
318def p_macroop_def_0(t):
319 'macroop_def : DEF MACROOP ID LPAREN ID RPAREN SEMI'
320 t[0] = t[4]
321
322# Defines a macroop that is combinationally generated
323def p_macroop_def_1(t):
324 'macroop_def : DEF MACROOP ID block SEMI'
325 try:
326 curop = t.parser.macro_type(t[3])
327 except TypeError:
328 print_error("Error creating macroop object.")
329 raise

--- 103 unchanged lines hidden (view full) ---

433def p_error(t):
434 if t:
435 error(t.lineno, "syntax error at '%s'" % t.value)
436 else:
437 error(0, "unknown syntax error", True)
438
439class MicroAssembler(object):
440
441 def __init__(self, macro_type, microops, rom):
442 self.lexer = lex.lex()
443 self.parser = yacc.yacc()
444 self.parser.macro_type = macro_type
445 self.parser.macroops = {}
446 self.parser.microops = microops
447 self.parser.rom = rom
448
449 def assemble(self, asm):
450 self.parser.parse(asm, lexer=self.lexer)
451 # Begin debug printing
452 for macroop in self.parser.macroops.values():
453 print macroop
454 print self.parser.rom
455 # End debug printing
456 macroops = self.parser.macroops
457 self.parser.macroops = {}
458 return macroops