]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/testsuite/gas/all/itbl-test.c
Jakub Jelinek <jj@ultra.linux.cz>
[thirdparty/binutils-gdb.git] / gas / testsuite / gas / all / itbl-test.c
CommitLineData
252b5132
RH
1
2
3/* itbl-test.c
4
5 Copyright (C) 1997 Free Software Foundation, Inc.
6
7 This file is part of GAS, the GNU Assembler.
8
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 02111-1307, USA. */
23
24/* Stand-alone test for instruction specification table support.
25 Run using "itbl-test <itbl> <asm.s>"
26 where <itbl> is the name of the instruction table,
27 and <asm.s> is the name of the assembler fie. */
28
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include "itbl-ops.h"
34
35static int test_reg (e_processor processor, e_type type, char *name,
36 unsigned long val);
37
38int
39main (int argc, char **argv)
40{
41 unsigned int insn;
42 FILE *fas;
43 int aline = 0;
44 char s[81], *name;
45
46 if (argc < 3)
47 {
48 printf ("usage: %s itbl asm.s\n", argv[0]);
49 exit (0);
50 }
51 if (itbl_parse (argv[1]) != 0)
52 {
53 printf ("failed to parse itbl\n");
54 exit (0);
55 }
56
57 fas = fopen (argv[2], "r");
58 if (fas == 0)
59 {
60 printf ("failed to open asm file %s\n", argv[2]);
61 exit (0);
62 }
63 while (fgets (s, 80, fas))
64 {
65 char *p;
66 aline++;
67
68 if (p = strchr (s, ';'), p) /* strip comments */
69 *p = 0;
70 if (p = strchr (s, '#'), p) /* strip comments */
71 *p = 0;
72 p = s + strlen (s) - 1;
73 while (p >= s && (*p == ' ' || *p == '\t' || *p == '\n')) /* strip trailing spaces */
74 p--;
75 *(p + 1) = 0;
76 p = s;
77 while (*p && (*p == ' ' || *p == '\t' || *p == '\n')) /* strip leading spaces */
78 p++;
79 if (!*p)
80 continue;
81
82 name = itbl_get_field (&p);
83 insn = itbl_assemble (name, p);
84 if (insn == 0)
85 printf ("line %d: Invalid instruction (%s)\n", aline, s);
86 else
87 {
88 char buf[128];
89 printf ("line %d: insn(%s) = 0x%x)\n", aline, s, insn);
90 if (!itbl_disassemble (buf, insn))
91 printf ("line %d: Can't disassemble instruction "
92 "(0x%x)\n", aline, insn);
93 else
94 printf ("line %d: disasm(0x%x) = %s)\n", aline, insn, buf);
95 }
96 }
97
98 test_reg (1, e_dreg, "d1", 1);
99 test_reg (3, e_creg, "c2", 22);
100 test_reg (3, e_dreg, "d3", 3);
101
102 return 0;
103}
104
105static int
106test_reg (e_processor processor, e_type type, char *name,
107 unsigned long val)
108{
109 char *n;
110 unsigned long v;
111
112 n = itbl_get_name (processor, type, val);
113 if (!n || strcmp (n, name))
114 printf ("Error - reg name not found for proessor=%d, type=%d, val=%d\n",
115 processor, type, val);
116 else
117 printf ("name=%s found for processor=%d, type=%d, val=%d\n",
118 n, processor, type, val);
119
120 /* We require that names be unique amoung processors and types. */
121 v = itbl_get_reg_val (name);
122 if (!v || v != val)
123 printf ("Error - reg val not found for processor=%d, type=%d, name=%s\n",
124 processor, type, name);
125 else
126 printf ("val=0x%x found for processor=%d, type=%d, name=%s\n",
127 v, processor, type, name);
128 return 0;
129}