micro_asm_test.py revision 4507
110249Sstephan.diestelhorst@arm.com# Copyright (c) 2007 The Regents of The University of Michigan
210249Sstephan.diestelhorst@arm.com# All rights reserved.
310249Sstephan.diestelhorst@arm.com#
410249Sstephan.diestelhorst@arm.com# Redistribution and use in source and binary forms, with or without
510249Sstephan.diestelhorst@arm.com# modification, are permitted provided that the following conditions are
610249Sstephan.diestelhorst@arm.com# met: redistributions of source code must retain the above copyright
710249Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer;
810249Sstephan.diestelhorst@arm.com# redistributions in binary form must reproduce the above copyright
910249Sstephan.diestelhorst@arm.com# notice, this list of conditions and the following disclaimer in the
1010249Sstephan.diestelhorst@arm.com# documentation and/or other materials provided with the distribution;
1110249Sstephan.diestelhorst@arm.com# neither the name of the copyright holders nor the names of its
1210249Sstephan.diestelhorst@arm.com# contributors may be used to endorse or promote products derived from
1310249Sstephan.diestelhorst@arm.com# this software without specific prior written permission.
1410249Sstephan.diestelhorst@arm.com#
1510249Sstephan.diestelhorst@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1610249Sstephan.diestelhorst@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1710249Sstephan.diestelhorst@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1810249Sstephan.diestelhorst@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1910249Sstephan.diestelhorst@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2010249Sstephan.diestelhorst@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2110249Sstephan.diestelhorst@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2210249Sstephan.diestelhorst@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2310249Sstephan.diestelhorst@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2410249Sstephan.diestelhorst@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2510249Sstephan.diestelhorst@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2610249Sstephan.diestelhorst@arm.com#
2710249Sstephan.diestelhorst@arm.com# Authors: Gabe Black
2810249Sstephan.diestelhorst@arm.com
2910249Sstephan.diestelhorst@arm.comfrom micro_asm import MicroAssembler, Combinational_Macroop, Rom_Macroop, Rom
3010249Sstephan.diestelhorst@arm.com
3110249Sstephan.diestelhorst@arm.comclass Bah(object):
3210249Sstephan.diestelhorst@arm.com    def __init__(self):
3310249Sstephan.diestelhorst@arm.com        self.mnemonic = "bah"
3410249Sstephan.diestelhorst@arm.com
3510249Sstephan.diestelhorst@arm.comclass Bah_Tweaked(object):
3610249Sstephan.diestelhorst@arm.com    def __init__(self):
3710249Sstephan.diestelhorst@arm.com        self.mnemonic = "bah_tweaked"
3810249Sstephan.diestelhorst@arm.com
3910249Sstephan.diestelhorst@arm.comclass Hoop(object):
4010249Sstephan.diestelhorst@arm.com    def __init__(self, first_param, second_param):
4110249Sstephan.diestelhorst@arm.com        self.mnemonic = "hoop_%s_%s" % (first_param, second_param)
4211793Sbrandon.potter@amd.com    def __str__(self):
4311793Sbrandon.potter@amd.com        return "%s" % self.mnemonic
4410249Sstephan.diestelhorst@arm.com
4510249Sstephan.diestelhorst@arm.comclass Dah(object):
4610249Sstephan.diestelhorst@arm.com    def __init__(self):
4712334Sgabeblack@google.com        self.mnemonic = "dah"
4811800Sbrandon.potter@amd.com
4910249Sstephan.diestelhorst@arm.commicroops = {
5010249Sstephan.diestelhorst@arm.com    "bah": Bah,
5110249Sstephan.diestelhorst@arm.com    "hoop": Hoop,
5211800Sbrandon.potter@amd.com    "dah": Dah
5310249Sstephan.diestelhorst@arm.com}
5410249Sstephan.diestelhorst@arm.com
5510249Sstephan.diestelhorst@arm.comclass TestMacroop(Combinational_Macroop):
5610249Sstephan.diestelhorst@arm.com    def tweak(self):
5710249Sstephan.diestelhorst@arm.com        microops["bah"] = Bah_Tweaked
5810249Sstephan.diestelhorst@arm.com    def untweak(self):
5910249Sstephan.diestelhorst@arm.com        microops["bah"] = Bah
6010249Sstephan.diestelhorst@arm.com    def print_debug(self, message):
6110249Sstephan.diestelhorst@arm.com        print message
6210249Sstephan.diestelhorst@arm.com
6310249Sstephan.diestelhorst@arm.com    def __init__(self, name):
6410249Sstephan.diestelhorst@arm.com        super(TestMacroop, self).__init__(name)
6510249Sstephan.diestelhorst@arm.com        self.directives = {
6610249Sstephan.diestelhorst@arm.com            "tweak": self.tweak,
6710249Sstephan.diestelhorst@arm.com            "untweak": self.untweak,
6810249Sstephan.diestelhorst@arm.com            "print": self.print_debug
6911321Ssteve.reinhardt@amd.com        }
7010249Sstephan.diestelhorst@arm.com
7110249Sstephan.diestelhorst@arm.comassembler = MicroAssembler(TestMacroop, microops, Rom('main ROM'), Rom_Macroop)
7210249Sstephan.diestelhorst@arm.com
7310249Sstephan.diestelhorst@arm.comtestAssembly = '''
7410249Sstephan.diestelhorst@arm.com# Single line comment
7510249Sstephan.diestelhorst@arm.com
7610249Sstephan.diestelhorst@arm.comdef rom {
7710249Sstephan.diestelhorst@arm.com    goo: bah
7810249Sstephan.diestelhorst@arm.com    extern la: hoop 4*8, "a"
7910249Sstephan.diestelhorst@arm.com}; /* multiline comment on one line */
8010249Sstephan.diestelhorst@arm.com
8110249Sstephan.diestelhorst@arm.com/* multi line comment across lines
8210249Sstephan.diestelhorst@arm.com   to make sure they work */
8310249Sstephan.diestelhorst@arm.com
8410249Sstephan.diestelhorst@arm.comdef macroop squishy {
8510249Sstephan.diestelhorst@arm.com    .tweak
8610249Sstephan.diestelhorst@arm.com    bah
8710395Sstephan.diestelhorst@arm.com    .untweak
8810395Sstephan.diestelhorst@arm.com    .print "In the midst"
8910395Sstephan.diestelhorst@arm.com    bah
9010249Sstephan.diestelhorst@arm.com    dah # single line comment after something
9110249Sstephan.diestelhorst@arm.com    .tweak
9210249Sstephan.diestelhorst@arm.com};
9310249Sstephan.diestelhorst@arm.com
9410249Sstephan.diestelhorst@arm.comdef macroop squashy {
9510249Sstephan.diestelhorst@arm.com    bah
9610395Sstephan.diestelhorst@arm.com};
9710395Sstephan.diestelhorst@arm.com
9810395Sstephan.diestelhorst@arm.comdef macroop jumper (bar);
9910395Sstephan.diestelhorst@arm.com'''
10010395Sstephan.diestelhorst@arm.comassembler.assemble(testAssembly)
10110395Sstephan.diestelhorst@arm.com