14483Sgblack@eecs.umich.edu# Copyright (c) 2007 The Regents of The University of Michigan 24483Sgblack@eecs.umich.edu# All rights reserved. 34483Sgblack@eecs.umich.edu# 44483Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 54483Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 64483Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 74483Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 84483Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 94483Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 104483Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 114483Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 124483Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 134483Sgblack@eecs.umich.edu# this software without specific prior written permission. 144483Sgblack@eecs.umich.edu# 154483Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 164483Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 174483Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 184483Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 194483Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 204483Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 214483Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 224483Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 234483Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 244483Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 254483Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264483Sgblack@eecs.umich.edu# 274483Sgblack@eecs.umich.edu# Authors: Gabe Black 284483Sgblack@eecs.umich.edu 2912563Sgabeblack@google.comfrom __future__ import print_function 3012563Sgabeblack@google.com 314507Sgblack@eecs.umich.edufrom micro_asm import MicroAssembler, Combinational_Macroop, Rom_Macroop, Rom 324483Sgblack@eecs.umich.edu 334483Sgblack@eecs.umich.educlass Bah(object): 344483Sgblack@eecs.umich.edu def __init__(self): 354483Sgblack@eecs.umich.edu self.mnemonic = "bah" 364483Sgblack@eecs.umich.edu 374483Sgblack@eecs.umich.educlass Bah_Tweaked(object): 384483Sgblack@eecs.umich.edu def __init__(self): 394483Sgblack@eecs.umich.edu self.mnemonic = "bah_tweaked" 404483Sgblack@eecs.umich.edu 414483Sgblack@eecs.umich.educlass Hoop(object): 424483Sgblack@eecs.umich.edu def __init__(self, first_param, second_param): 434483Sgblack@eecs.umich.edu self.mnemonic = "hoop_%s_%s" % (first_param, second_param) 444483Sgblack@eecs.umich.edu def __str__(self): 454483Sgblack@eecs.umich.edu return "%s" % self.mnemonic 464483Sgblack@eecs.umich.edu 474483Sgblack@eecs.umich.educlass Dah(object): 484483Sgblack@eecs.umich.edu def __init__(self): 494483Sgblack@eecs.umich.edu self.mnemonic = "dah" 504483Sgblack@eecs.umich.edu 514483Sgblack@eecs.umich.edumicroops = { 524483Sgblack@eecs.umich.edu "bah": Bah, 534483Sgblack@eecs.umich.edu "hoop": Hoop, 544483Sgblack@eecs.umich.edu "dah": Dah 554483Sgblack@eecs.umich.edu} 564483Sgblack@eecs.umich.edu 574507Sgblack@eecs.umich.educlass TestMacroop(Combinational_Macroop): 584483Sgblack@eecs.umich.edu def tweak(self): 594483Sgblack@eecs.umich.edu microops["bah"] = Bah_Tweaked 604483Sgblack@eecs.umich.edu def untweak(self): 614483Sgblack@eecs.umich.edu microops["bah"] = Bah 624503Sgblack@eecs.umich.edu def print_debug(self, message): 6312563Sgabeblack@google.com print(message) 644483Sgblack@eecs.umich.edu 654483Sgblack@eecs.umich.edu def __init__(self, name): 664483Sgblack@eecs.umich.edu super(TestMacroop, self).__init__(name) 674483Sgblack@eecs.umich.edu self.directives = { 684483Sgblack@eecs.umich.edu "tweak": self.tweak, 694503Sgblack@eecs.umich.edu "untweak": self.untweak, 704503Sgblack@eecs.umich.edu "print": self.print_debug 714483Sgblack@eecs.umich.edu } 724483Sgblack@eecs.umich.edu 734507Sgblack@eecs.umich.eduassembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'), Rom_Macroop) 744483Sgblack@eecs.umich.edu 754483Sgblack@eecs.umich.edutestAssembly = ''' 764502Sgblack@eecs.umich.edu# Single line comment 774502Sgblack@eecs.umich.edu 784483Sgblack@eecs.umich.edudef rom { 794483Sgblack@eecs.umich.edu goo: bah 804483Sgblack@eecs.umich.edu extern la: hoop 4*8, "a" 814502Sgblack@eecs.umich.edu}; /* multiline comment on one line */ 824502Sgblack@eecs.umich.edu 834502Sgblack@eecs.umich.edu/* multi line comment across lines 844502Sgblack@eecs.umich.edu to make sure they work */ 854483Sgblack@eecs.umich.edu 864483Sgblack@eecs.umich.edudef macroop squishy { 874483Sgblack@eecs.umich.edu .tweak 884483Sgblack@eecs.umich.edu bah 894483Sgblack@eecs.umich.edu .untweak 904503Sgblack@eecs.umich.edu .print "In the midst" 914483Sgblack@eecs.umich.edu bah 924502Sgblack@eecs.umich.edu dah # single line comment after something 934483Sgblack@eecs.umich.edu .tweak 944483Sgblack@eecs.umich.edu}; 954483Sgblack@eecs.umich.edu 964509Sgblack@eecs.umich.edu#Extending the rom... 974509Sgblack@eecs.umich.edudef rom 984509Sgblack@eecs.umich.edu{ 994509Sgblack@eecs.umich.edu #Here's more stuff for the rom 1004509Sgblack@eecs.umich.edu bah 1014509Sgblack@eecs.umich.edu}; 1024509Sgblack@eecs.umich.edu 1034483Sgblack@eecs.umich.edudef macroop squashy { 1044483Sgblack@eecs.umich.edu bah 1054483Sgblack@eecs.umich.edu}; 1064483Sgblack@eecs.umich.edu 1074502Sgblack@eecs.umich.edudef macroop jumper (bar); 1084483Sgblack@eecs.umich.edu''' 1094483Sgblack@eecs.umich.eduassembler.assemble(testAssembly) 110