micro_asm.py (4503:0f812a876221) micro_asm.py (4507:487b70cfd58d)
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
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):
67class Combinational_Macroop(Micro_Container):
68 pass
69
68 pass
69
70class Rom_Macroop(object):
71 def __init__(self, name, target):
72 self.name = name
73 self.target = target
74
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'
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."
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'
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'
320 t[0] = t[4]
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
321
333
334
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
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
441 def __init__(self, macro_type, microops, rom):
454 def __init__(self, macro_type, microops,
455 rom = None, rom_macroop_type = None):
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
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
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
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