1#!/usr/local/bin/perl
2#/******************************************************************************
3#  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4#  more contributor license agreements.  See the NOTICE file distributed
5#  with this work for additional information regarding copyright ownership.
6#  Accellera licenses this file to you under the Apache License, Version 2.0
7#  (the "License"); you may not use this file except in compliance with the
8#  License.  You may obtain a copy of the License at
9#
10#   http://www.apache.org/licenses/LICENSE-2.0
11#
12#  Unless required by applicable law or agreed to in writing, software
13#  distributed under the License is distributed on an "AS IS" BASIS,
14#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15#  implied.  See the License for the specific language governing
16#  permissions and limitations under the License.
17#
18#******************************************************************************/
19#/******************************************************************************
20#
21#    assembler.pl -- Simple Assembler in Perl
22#
23#    Original Author: Martin Wang. Synopsys, Inc. (mwang@synopsys.com)
24#
25#******************************************************************************/
26#
27#/******************************************************************************
28#
29#    MODIFICATION LOG - modifiers, enter your name, affliation and
30#    changes you are making here:
31#
32#    Modifier Name & Affiliation:
33#    Description of Modification:
34#
35#
36#******************************************************************************/
37#
38#/***************************************************************************
39#
40#   Copyright (c) 1998-1999 Synopsys, Inc.
41#   ALL RIGHTS RESERVED
42#
43#*****************************************************************************/
44#
45#Change the above line for your perl
46
47if ($ARGV[1] eq "-code") {
48	$CODEGEN = 1;
49}else {
50	$CODEGEN = 0;
51}
52#print "Input source name = $ARGV[0]\n";
53
54$pc = 5;
55$filename = $ARGV[0];
56open(FP,"$filename");
57
58printf ("0x00000000\n");
59printf ("0x00000000\n");
60printf ("0x00000000\n");
61printf ("0x00000000\n");
62printf ("0x00000000\n");
63while(<FP>){
64	chop($_);
65	$_ =~ s/\s+/ /g;
66	($opcode, $destC, $sourceA, $sourceB) = split(/ /,$_);
67	$destC =~ s/R//g;
68	$sourceA =~ s/R//g;
69	$sourceB =~ s/R//g;
70	if ($opcode =~ /\badd\b/) {
71		printf ("0x01");
72		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
73	}
74	if ($opcode =~ /\bmod\b/) {
75		printf ("0x0e");
76		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
77	}
78	if ($opcode =~ /\baddi\b/) {
79		printf ("0x02");
80		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
81	}
82	if ($opcode =~ /\baddc\b/) {
83		printf ("0x03");
84		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
85	}
86	if ($opcode =~ /\bsub\b/) {
87		printf ("0x04");
88		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
89	}
90	if ($opcode =~ /\bsubi\b/) {
91		printf ("0x05");
92		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
93	}
94	if ($opcode =~ /\bsubc\b/) {
95		printf ("0x06");
96		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
97	}
98	if ($opcode =~ /\bmul\b/) {
99		printf ("0x07");
100		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
101	}
102	if ($opcode =~ /\bdiv\b/) {
103		printf ("0x08");
104		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
105	}
106	if ($opcode =~ /\bnand\b/) {
107		printf ("0x09");
108		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
109	}
110	if ($opcode =~ /\band\b/) {
111		printf ("0x0a");
112		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
113	}
114	if ($opcode =~ /\bor\b/) {
115		printf ("0x0b");
116		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
117	}
118	if ($opcode =~ /\bxor\b/) {
119		printf ("0x0c");
120		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
121	}
122	if ($opcode =~ /\bnot\b/) {
123		printf ("0x0d");
124		printf ("%01x%01x0000",$destC, $sourceA);
125	}
126	if ($opcode =~ /\blw\b/) {
127		printf ("0x4d");
128		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
129	}
130	if ($opcode =~ /\bsw\b/) {
131		printf ("0x4e");
132		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
133	}
134	if ($opcode =~ /\bmov\b/) {
135		printf ("0x0f");
136		printf ("%01x%01x%01x000",$destC, $sourceA, 0);
137	}
138	if ($opcode =~ /\bmovi\b/) {
139		printf ("0xf1");
140		printf ("%01x%05x",$destC, $sourceA);
141	}
142	if ($opcode =~ /\bbeq\b/) {
143		printf ("0x10");
144                $sourceB = 0x0000ffff & $sourceB;
145		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
146	}
147	if ($opcode =~ /\bbne\b/) {
148		printf ("0x11");
149                $sourceB = 0x0000ffff & $sourceB;
150		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
151	}
152	if ($opcode =~ /\bbgt\b/) {
153		printf ("0x12");
154                $sourceB = 0x0000ffff & $sourceB;
155		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
156	}
157	if ($opcode =~ /\bbge\b/) {
158		printf ("0x13");
159                $sourceB = 0x0000ffff & $sourceB;
160		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
161	}
162	if ($opcode =~ /\bblt\b/) {
163		printf ("0x14");
164                $sourceB = 0x0000ffff & $sourceB;
165		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
166	}
167	if ($opcode =~ /\bble\b/) {
168		printf ("0x15");
169                $sourceB = 0x0000ffff & $sourceB;
170		printf ("%01x%01x%04x",$destC, $sourceA, $sourceB);
171	}
172	if ($opcode =~ /\bj\b/) {
173		printf ("0x16");
174                $sourceB = 0x0000ffff & $sourceB;
175		printf ("%06x",$destC);
176	}
177	if ($opcode =~ /\bfadd\b/) {
178		printf ("0x29");
179		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
180	}
181	if ($opcode =~ /\bfsub\b/) {
182		printf ("0x2a");
183		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
184	}
185	if ($opcode =~ /\bfmul\b/) {
186		printf ("0x2b");
187		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
188	}
189	if ($opcode =~ /\bfdiv\b/) {
190		printf ("0x2c");
191		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
192	}
193	if ($opcode =~ /\bmmxadd\b/) {
194		printf ("0x31");
195		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
196	}
197	if ($opcode =~ /\bmmxadds\b/) {
198		printf ("0x32");
199		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
200	}
201	if ($opcode =~ /\bmmxsub\b/) {
202		printf ("0x33");
203		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
204	}
205	if ($opcode =~ /\bmmxsubs\b/) {
206		printf ("0x34");
207		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
208	}
209	if ($opcode =~ /\bpmadd\b/) {
210		printf ("0x35");
211		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
212	}
213	if ($opcode =~ /\bpack\b/) {
214		printf ("0x36");
215		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
216	}
217	if ($opcode =~ /\bmmxck\b/) {
218		printf ("0x37");
219		printf ("%01x%01x%01x000",$destC, $sourceA, $sourceB);
220	}
221	if ($opcode =~ /\bldpid\b/) {
222		printf ("0xf0");
223		printf ("%06x",$destC);
224	}
225	if ($opcode =~ /\bflush\b/) {
226		printf ("0xe0000000");
227	}
228	if ($CODEGEN) {
229		printf ("\n");
230	} else {
231		printf("\t/* %s * pc = 0x%x=%d/\n",$_, $pc, $pc);
232	}
233	$pc ++;
234	if ($CODEGEN) {
235		printf ("0x00000000\n");
236	} else {
237		printf ("0x00000000");
238		printf("\t\t\t\t\t/* REGISTER DUMP * pc = %d/\n", $pc);
239	}
240	$pc ++;
241
242
243
244}
245printf ("0xffffffff\n");
246