micro_asm_test.py revision 4503
15627Sgblack@eecs.umich.edu# Copyright (c) 2007 The Regents of The University of Michigan 25627Sgblack@eecs.umich.edu# All rights reserved. 35627Sgblack@eecs.umich.edu# 45627Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 57087Snate@binkert.org# modification, are permitted provided that the following conditions are 67087Snate@binkert.org# met: redistributions of source code must retain the above copyright 77087Snate@binkert.org# notice, this list of conditions and the following disclaimer; 87087Snate@binkert.org# redistributions in binary form must reproduce the above copyright 97087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 107087Snate@binkert.org# documentation and/or other materials provided with the distribution; 117087Snate@binkert.org# neither the name of the copyright holders nor the names of its 127087Snate@binkert.org# contributors may be used to endorse or promote products derived from 135627Sgblack@eecs.umich.edu# this software without specific prior written permission. 147087Snate@binkert.org# 157087Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 167087Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 177087Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 187087Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 197087Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 207087Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 217087Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 225627Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 237087Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245627Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 255627Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265627Sgblack@eecs.umich.edu# 275627Sgblack@eecs.umich.edu# Authors: Gabe Black 285627Sgblack@eecs.umich.edu 295627Sgblack@eecs.umich.edufrom micro_asm import MicroAssembler, Macroop, Rom 305627Sgblack@eecs.umich.edu 315627Sgblack@eecs.umich.educlass Bah(object): 325627Sgblack@eecs.umich.edu def __init__(self): 335627Sgblack@eecs.umich.edu self.mnemonic = "bah" 345627Sgblack@eecs.umich.edu 355627Sgblack@eecs.umich.educlass Bah_Tweaked(object): 365627Sgblack@eecs.umich.edu def __init__(self): 375627Sgblack@eecs.umich.edu self.mnemonic = "bah_tweaked" 385627Sgblack@eecs.umich.edu 395627Sgblack@eecs.umich.educlass Hoop(object): 405627Sgblack@eecs.umich.edu def __init__(self, first_param, second_param): 4111793Sbrandon.potter@amd.com self.mnemonic = "hoop_%s_%s" % (first_param, second_param) 425627Sgblack@eecs.umich.edu def __str__(self): 438229Snate@binkert.org return "%s" % self.mnemonic 448229Snate@binkert.org 458229Snate@binkert.orgclass Dah(object): 468229Snate@binkert.org def __init__(self): 475627Sgblack@eecs.umich.edu self.mnemonic = "dah" 485627Sgblack@eecs.umich.edu 495627Sgblack@eecs.umich.edumicroops = { 505627Sgblack@eecs.umich.edu "bah": Bah, 515627Sgblack@eecs.umich.edu "hoop": Hoop, 525627Sgblack@eecs.umich.edu "dah": Dah 535627Sgblack@eecs.umich.edu} 545627Sgblack@eecs.umich.edu 555627Sgblack@eecs.umich.educlass TestMacroop(Macroop): 565627Sgblack@eecs.umich.edu def tweak(self): 575627Sgblack@eecs.umich.edu microops["bah"] = Bah_Tweaked 585627Sgblack@eecs.umich.edu def untweak(self): 595627Sgblack@eecs.umich.edu microops["bah"] = Bah 605627Sgblack@eecs.umich.edu def print_debug(self, message): 615627Sgblack@eecs.umich.edu print message 625627Sgblack@eecs.umich.edu 635627Sgblack@eecs.umich.edu def __init__(self, name): 645627Sgblack@eecs.umich.edu super(TestMacroop, self).__init__(name) 655627Sgblack@eecs.umich.edu self.directives = { 665627Sgblack@eecs.umich.edu "tweak": self.tweak, 675627Sgblack@eecs.umich.edu "untweak": self.untweak, 685627Sgblack@eecs.umich.edu "print": self.print_debug 695627Sgblack@eecs.umich.edu } 705627Sgblack@eecs.umich.edu 715627Sgblack@eecs.umich.eduassembler = MicroAssembler(TestMacroop, microops, Rom('main ROM')) 725627Sgblack@eecs.umich.edu 735627Sgblack@eecs.umich.edutestAssembly = ''' 745627Sgblack@eecs.umich.edu# Single line comment 755627Sgblack@eecs.umich.edu 765627Sgblack@eecs.umich.edudef rom { 775627Sgblack@eecs.umich.edu goo: bah 785627Sgblack@eecs.umich.edu extern la: hoop 4*8, "a" 795627Sgblack@eecs.umich.edu}; /* multiline comment on one line */ 805627Sgblack@eecs.umich.edu 815627Sgblack@eecs.umich.edu/* multi line comment across lines 825627Sgblack@eecs.umich.edu to make sure they work */ 835627Sgblack@eecs.umich.edu 845627Sgblack@eecs.umich.edudef macroop squishy { 855627Sgblack@eecs.umich.edu .tweak 865627Sgblack@eecs.umich.edu bah 875627Sgblack@eecs.umich.edu .untweak 885627Sgblack@eecs.umich.edu .print "In the midst" 895627Sgblack@eecs.umich.edu bah 905627Sgblack@eecs.umich.edu dah # single line comment after something 91 .tweak 92}; 93 94def macroop squashy { 95 bah 96}; 97 98def macroop jumper (bar); 99''' 100assembler.assemble(testAssembly) 101