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