OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [sim/] [igen/] [gen-itable.c] - Blame information for rev 1778

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 markom
/*  This file is part of the program psim.
2
 
3
    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
 
5
    This program is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
9
 
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
 
15
    You should have received a copy of the GNU General Public License
16
    along with this program; if not, write to the Free Software
17
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
19
    */
20
 
21
 
22
 
23
#include "misc.h"
24
#include "lf.h"
25
#include "table.h"
26
#include "filter.h"
27
#include "igen.h"
28
 
29
#include "ld-insn.h"
30
#include "ld-decode.h"
31
 
32
#include "gen.h"
33
 
34
#include "gen-itable.h"
35
 
36
#ifndef NULL
37
#define NULL 0
38
#endif
39
 
40
 
41
 
42
typedef struct _itable_info {
43
  int sizeof_form;
44
  int sizeof_name;
45
  int sizeof_file;
46
} itable_info;
47
 
48
 
49
static void
50
itable_h_insn (lf *file,
51
               insn_table *entry,
52
               insn_entry *instruction,
53
               void *data)
54
{
55
  int len;
56
  itable_info *info = data;
57
  lf_print__line_ref (file, instruction->line);
58
  lf_printf (file, "  ");
59
  print_function_name (file,
60
                       instruction->name,
61
                       instruction->format_name,
62
                       NULL,
63
                       NULL,
64
                       function_name_prefix_itable);
65
  lf_printf (file, ",\n");
66
  /* update summary info */
67
  len = strlen (instruction->format_name);
68
  if (info->sizeof_form <= len)
69
    info->sizeof_form = len + 1;
70
  len = strlen (instruction->name);
71
  if (info->sizeof_name <= len)
72
    info->sizeof_name = len + 1;
73
  len = strlen (filter_filename (instruction->line->file_name));
74
  if (info->sizeof_file <= len)
75
    info->sizeof_file = len + 1;
76
}
77
 
78
 
79
/* print the list of all the different options */
80
 
81
static void
82
itable_print_enum (lf *file,
83
                   filter *set,
84
                   char *name)
85
{
86
  char *elem;
87
  lf_printf (file, "typedef enum {\n");
88
  lf_indent (file, +2);
89
  for (elem = filter_next (set, "");
90
       elem != NULL;
91
       elem = filter_next (set, elem))
92
    {
93
      lf_printf (file, "%sitable_%s_%s,\n",
94
                 options.module.itable.prefix.l, name, elem);
95
      if (strlen (options.module.itable.prefix.l) > 0)
96
        {
97
          lf_indent_suppress (file);
98
          lf_printf (file, "#define itable_%s_%s %sitable_%s_%s\n",
99
                     name, elem, options.module.itable.prefix.l, name, elem);
100
        }
101
    }
102
  lf_printf (file, "nr_%sitable_%ss,\n", options.module.itable.prefix.l, name);
103
 
104
  lf_indent (file, -2);
105
  lf_printf (file, "} %sitable_%ss;\n", options.module.itable.prefix.l, name);
106
  if (strlen (options.module.itable.prefix.l) > 0)
107
    {
108
      lf_indent_suppress (file);
109
      lf_printf (file, "#define itable_%ss %sitable_%ss\n",
110
                 name, options.module.itable.prefix.l, name);
111
      lf_indent_suppress (file);
112
      lf_printf (file, "#define nr_itable_%ss nr_%sitable_%ss\n",
113
                 name, options.module.itable.prefix.l, name);
114
    }
115
}
116
 
117
/* print an array of the option names as strings */
118
 
119
static void
120
itable_print_names (lf *file,
121
                    filter *set,
122
                    char *name)
123
{
124
  char *elem;
125
  lf_printf (file, "const char *%sitable_%s_names[nr_%sitable_%ss + 1] = {\n",
126
             options.module.itable.prefix.l, name,
127
             options.module.itable.prefix.l, name);
128
  lf_indent (file, +2);
129
  for (elem = filter_next (set, "");
130
       elem != NULL;
131
       elem = filter_next (set, elem))
132
    {
133
      lf_printf (file, "\"%s\",\n", elem);
134
    }
135
  lf_printf (file, "0,\n");
136
  lf_indent (file, -2);
137
  lf_printf (file, "};\n");
138
}
139
 
140
extern void
141
gen_itable_h (lf *file,
142
              insn_table *isa)
143
{
144
  itable_info *info = ZALLOC (itable_info);
145
 
146
  /* output an enumerated type for each instruction */
147
  lf_printf (file, "typedef enum {\n");
148
  insn_table_traverse_insn (file, isa, itable_h_insn, info);
149
  lf_printf (file, "  nr_%sitable_entries,\n", options.module.itable.prefix.l);
150
  lf_printf (file, "} %sitable_index;\n", options.module.itable.prefix.l);
151
  lf_printf (file, "\n");
152
 
153
  /* output an enumeration type for each flag */
154
  itable_print_enum (file, isa->flags, "flag");
155
  lf_printf (file, "extern const char *%sitable_flag_names[];\n",
156
             options.module.itable.prefix.l);
157
  lf_printf (file, "\n");
158
 
159
  /* output an enumeration of all the possible options */
160
  itable_print_enum (file, isa->options, "option");
161
  lf_printf (file, "extern const char *%sitable_option_names[];\n",
162
             options.module.itable.prefix.l);
163
  lf_printf (file, "\n");
164
 
165
  /* output an enumeration of all the processor models */
166
  itable_print_enum (file, isa->model->processors, "processor");
167
  lf_printf (file, "extern const char *%sitable_processor_names[];\n",
168
             options.module.itable.prefix.l);
169
  lf_printf (file, "\n");
170
 
171
  /* output the table that contains the actual instruction info */
172
  lf_printf (file, "typedef struct _%sitable_instruction_info {\n",
173
             options.module.itable.prefix.l);
174
  lf_printf (file, "  %sitable_index nr;\n", options.module.itable.prefix.l);
175
  lf_printf (file, "  char *format;\n");
176
  lf_printf (file, "  char *form;\n");
177
  lf_printf (file, "  char *flags;\n");
178
 
179
  /* nr_itable_* may be zero, so we add 1 to avoid an
180
     illegal zero-sized array. */
181
  lf_printf (file, "  char flag[nr_%sitable_flags + 1];\n",
182
             options.module.itable.prefix.l);
183
  lf_printf (file, "  char *options;\n");
184
  lf_printf (file, "  char option[nr_%sitable_options + 1];\n",
185
             options.module.itable.prefix.l);
186
  lf_printf (file, "  char *processors;\n");
187
  lf_printf (file, "  char processor[nr_%sitable_processors + 1];\n",
188
             options.module.itable.prefix.l);
189
  lf_printf (file, "  char *name;\n");
190
  lf_printf (file, "  char *file;\n");
191
  lf_printf (file, "  int line_nr;\n");
192
  lf_printf (file, "} %sitable_info;\n", options.module.itable.prefix.l);
193
  lf_printf (file, "\n");
194
  lf_printf (file, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
195
             options.module.itable.prefix.l, options.module.itable.prefix.l,
196
             options.module.itable.prefix.l);
197
  if (strlen (options.module.itable.prefix.l) > 0)
198
    {
199
      lf_indent_suppress (file);
200
      lf_printf (file, "#define itable %sitable\n",
201
                 options.module.itable.prefix.l);
202
    }
203
  lf_printf (file, "\n");
204
 
205
  /* output an enum defining the max size of various itable members */
206
  lf_printf (file, "enum {\n");
207
  lf_printf (file, "  sizeof_%sitable_form = %d,\n",
208
             options.module.itable.prefix.l, info->sizeof_form);
209
  lf_printf (file, "  sizeof_%sitable_name = %d,\n",
210
             options.module.itable.prefix.l, info->sizeof_name);
211
  lf_printf (file, "  sizeof_%sitable_file = %d,\n",
212
             options.module.itable.prefix.l, info->sizeof_file);
213
  lf_printf (file, "};\n");
214
}
215
 
216
 
217
/****************************************************************/
218
 
219
static void
220
itable_print_set (lf *file,
221
                  filter *set,
222
                  filter *members)
223
{
224
  char *elem;
225
  lf_printf (file, "\"");
226
  elem = filter_next (members, "");
227
  if (elem != NULL)
228
    {
229
      while (1)
230
        {
231
          lf_printf (file, "%s", elem);
232
          elem = filter_next (members, elem);
233
          if (elem == NULL)
234
            break;
235
          lf_printf (file, ",");
236
        }
237
    }
238
  lf_printf (file, "\",\n");
239
 
240
  lf_printf(file, "{");
241
  for (elem = filter_next (set, "");
242
       elem != NULL;
243
       elem = filter_next (set, elem))
244
    {
245
      if (filter_is_member (members, elem))
246
        {
247
          lf_printf (file, " 1,");
248
        }
249
      else
250
        {
251
          lf_printf (file, " 0,");
252
        }
253
 
254
    }
255
  /* always print a dummy element, to avoid empty initializers. */
256
  lf_printf(file, " 99 },\n");
257
}
258
 
259
 
260
static void
261
itable_c_insn (lf *file,
262
               insn_table *isa,
263
               insn_entry *instruction,
264
               void *data)
265
{
266
  lf_printf (file, "{ ");
267
  lf_indent (file, +2);
268
  print_function_name (file,
269
                       instruction->name,
270
                       instruction->format_name,
271
                       NULL,
272
                       NULL,
273
                       function_name_prefix_itable);
274
  lf_printf (file, ",\n");
275
  lf_printf (file, "\"");
276
  print_insn_words (file, instruction);
277
  lf_printf (file, "\",\n");
278
  lf_printf (file, "\"%s\",\n", instruction->format_name);
279
 
280
  itable_print_set (file, isa->flags, instruction->flags);
281
  itable_print_set (file, isa->options, instruction->options);
282
  itable_print_set (file, isa->model->processors, instruction->processors);
283
 
284
  lf_printf(file, "\"%s\",\n", instruction->name);
285
  lf_printf(file, "\"%s\",\n",
286
            filter_filename (instruction->line->file_name));
287
  lf_printf(file, "%d,\n", instruction->line->line_nr);
288
  lf_printf(file, "},\n");
289
  lf_indent (file, -2);
290
}
291
 
292
 
293
extern void
294
gen_itable_c (lf *file,
295
              insn_table *isa)
296
{
297
  /* leader */
298
  lf_printf(file, "#include \"%sitable.h\"\n", options.module.itable.prefix.l);
299
  lf_printf(file, "\n");
300
 
301
  /* FIXME - output model data??? */
302
  /* FIXME - output assembler data??? */
303
 
304
  /* output the flag, option and processor name tables */
305
  itable_print_names (file, isa->flags, "flag");
306
  itable_print_names (file, isa->options, "option");
307
  itable_print_names (file, isa->model->processors, "processor");
308
 
309
  /* output the table that contains the actual instruction info */
310
  lf_printf (file, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
311
             options.module.itable.prefix.l,
312
             options.module.itable.prefix.l,
313
             options.module.itable.prefix.l);
314
  insn_table_traverse_insn (file, isa, itable_c_insn, NULL);
315
 
316
  lf_printf(file, "};\n");
317
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.