micro_asm_test.py revision 4502:766acd3fa962
14202Sbinkertn@umich.edu# Copyright (c) 2007 The Regents of The University of Michigan 24202Sbinkertn@umich.edu# All rights reserved. 34202Sbinkertn@umich.edu# 44202Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 54202Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 64202Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 74202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 84202Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 94202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 104202Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 114202Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 124202Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 134202Sbinkertn@umich.edu# this software without specific prior written permission. 144202Sbinkertn@umich.edu# 154202Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 164202Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 174202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 184202Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 194202Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 204202Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 214202Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 224202Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 234202Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 244202Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 254202Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264202Sbinkertn@umich.edu# 274202Sbinkertn@umich.edu# Authors: Gabe Black 284202Sbinkertn@umich.edu 294202Sbinkertn@umich.edufrom micro_asm import MicroAssembler, Macroop, Rom 304202Sbinkertn@umich.edu 314202Sbinkertn@umich.educlass Bah(object): 324202Sbinkertn@umich.edu def __init__(self): 339398Sandreas.hansson@arm.com self.mnemonic = "bah" 349398Sandreas.hansson@arm.com 359398Sandreas.hansson@arm.comclass Bah_Tweaked(object): 369398Sandreas.hansson@arm.com def __init__(self): 379398Sandreas.hansson@arm.com self.mnemonic = "bah_tweaked" 389398Sandreas.hansson@arm.com 399850Sandreas.hansson@arm.comclass Hoop(object): 409259SAli.Saidi@ARM.com def __init__(self, first_param, second_param): 414486Sbinkertn@umich.edu self.mnemonic = "hoop_%s_%s" % (first_param, second_param) 424486Sbinkertn@umich.edu def __str__(self): 4310146Sandreas.hansson@arm.com return "%s" % self.mnemonic 446165Ssanchezd@stanford.edu 459850Sandreas.hansson@arm.comclass Dah(object): 466168Snate@binkert.org def __init__(self): 479850Sandreas.hansson@arm.com self.mnemonic = "dah" 489259SAli.Saidi@ARM.com 494202Sbinkertn@umich.edumicroops = { 504202Sbinkertn@umich.edu "bah": Bah, 519036Sandreas.hansson@arm.com "hoop": Hoop, 5210146Sandreas.hansson@arm.com "dah": Dah 534202Sbinkertn@umich.edu} 548761Sgblack@eecs.umich.edu 559036Sandreas.hansson@arm.comclass TestMacroop(Macroop): 564202Sbinkertn@umich.edu def tweak(self): 574202Sbinkertn@umich.edu microops["bah"] = Bah_Tweaked 588914Sandreas.hansson@arm.com def untweak(self): 594202Sbinkertn@umich.edu microops["bah"] = Bah 608853Sandreas.hansson@arm.com 619850Sandreas.hansson@arm.com def __init__(self, name): 629850Sandreas.hansson@arm.com super(TestMacroop, self).__init__(name) 636168Snate@binkert.org self.directives = { 649850Sandreas.hansson@arm.com "tweak": self.tweak, 659850Sandreas.hansson@arm.com "untweak": self.untweak 669850Sandreas.hansson@arm.com } 678763Sgblack@eecs.umich.edu 687768SAli.Saidi@ARM.comassembler = MicroAssembler(TestMacroop, microops, Rom('main ROM')) 6910131Sandreas.hansson@arm.com 7010131Sandreas.hansson@arm.comtestAssembly = ''' 7110131Sandreas.hansson@arm.com# Single line comment 7210131Sandreas.hansson@arm.com 7310066Sandreas.hansson@arm.comdef rom { 749036Sandreas.hansson@arm.com goo: bah 758335Snate@binkert.org extern la: hoop 4*8, "a" 769036Sandreas.hansson@arm.com}; /* multiline comment on one line */ 779036Sandreas.hansson@arm.com 789036Sandreas.hansson@arm.com/* multi line comment across lines 799036Sandreas.hansson@arm.com to make sure they work */ 809036Sandreas.hansson@arm.com 819164Sandreas.hansson@arm.comdef macroop squishy { 828981Sandreas.hansson@arm.com .tweak 839243Sandreas.hansson@arm.com bah 8410247Sandreas.hansson@arm.com .untweak 8510208Sandreas.hansson@arm.com bah 868335Snate@binkert.org dah # single line comment after something 878335Snate@binkert.org .tweak 888335Snate@binkert.org}; 898914Sandreas.hansson@arm.com 907780Snilay@cs.wisc.edudef macroop squashy { 9110066Sandreas.hansson@arm.com bah 92}; 93 94def macroop jumper (bar); 95''' 96assembler.assemble(testAssembly) 97