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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [sim/] [igen/] [gen-model.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 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
#include "misc.h"
23
#include "lf.h"
24
#include "table.h"
25
 
26
#include "filter.h"
27
 
28
#include "ld-decode.h"
29
#include "ld-insn.h"
30
 
31
#include "gen-model.h"
32
 
33
#ifndef NULL
34
#define NULL 0
35
#endif
36
 
37
 
38
#if 0
39
static void
40
model_c_or_h_data(insn_table *table,
41
                  lf *file,
42
                  table_entry *data)
43
{
44
  if (data->annex) {
45
    table_entry_print_cpp_line_nr(file, data->annex_line);
46
    lf_print__c_code(file, data->annex);
47
    lf_print__internal_reference(file);
48
    lf_printf(file, "\n");
49
  }
50
}
51
 
52
static void
53
model_c_or_h_function(insn_table *entry,
54
                      lf *file,
55
                      table_entry *function,
56
                      char *prefix)
57
{
58
  if (function->fields[function_type] == NULL
59
      || function->fields[function_type][0] == '\0') {
60
    error("Model function type not specified for %s", function->fields[function_name]);
61
  }
62
  lf_printf(file, "\n");
63
  lf_print_function_type(file, function->fields[function_type], prefix, " ");
64
  lf_printf(file, "%s\n(%s);\n",
65
            function->fields[function_name],
66
            function->fields[function_param]);
67
  lf_printf(file, "\n");
68
}
69
 
70
void
71
gen_model_h(insn_table *table, lf *file)
72
{
73
  insn *insn_ptr;
74
  model *model_ptr;
75
  insn *macro;
76
  char *name;
77
  int model_create_p = 0;
78
  int model_init_p = 0;
79
  int model_halt_p = 0;
80
  int model_mon_info_p = 0;
81
  int model_mon_info_free_p = 0;
82
 
83
  for(macro = model_macros; macro; macro = macro->next) {
84
    model_c_or_h_data(table, file, macro->file_entry);
85
  }
86
 
87
  lf_printf(file, "typedef enum _model_enum {\n");
88
  lf_printf(file, "  MODEL_NONE,\n");
89
  for (model_ptr = models; model_ptr; model_ptr = model_ptr->next) {
90
    lf_printf(file, "  MODEL_%s,\n", model_ptr->name);
91
  }
92
  lf_printf(file, "  nr_models\n");
93
  lf_printf(file, "} model_enum;\n");
94
  lf_printf(file, "\n");
95
 
96
  lf_printf(file, "#define DEFAULT_MODEL MODEL_%s\n", (models) ? models->name : "NONE");
97
  lf_printf(file, "\n");
98
 
99
  lf_printf(file, "typedef struct _model_data model_data;\n");
100
  lf_printf(file, "typedef struct _model_time model_time;\n");
101
  lf_printf(file, "\n");
102
 
103
  lf_printf(file, "extern model_enum current_model;\n");
104
  lf_printf(file, "extern const char *model_name[ (int)nr_models ];\n");
105
  lf_printf(file, "extern const char *const *const model_func_unit_name[ (int)nr_models ];\n");
106
  lf_printf(file, "extern const model_time *const model_time_mapping[ (int)nr_models ];\n");
107
  lf_printf(file, "\n");
108
 
109
  for(insn_ptr = model_functions; insn_ptr; insn_ptr = insn_ptr->next) {
110
    model_c_or_h_function(table, file, insn_ptr->file_entry, "INLINE_MODEL");
111
    name = insn_ptr->file_entry->fields[function_name];
112
    if (strcmp (name, "model_create") == 0)
113
      model_create_p = 1;
114
    else if (strcmp (name, "model_init") == 0)
115
      model_init_p = 1;
116
    else if (strcmp (name, "model_halt") == 0)
117
      model_halt_p = 1;
118
    else if (strcmp (name, "model_mon_info") == 0)
119
      model_mon_info_p = 1;
120
    else if (strcmp (name, "model_mon_info_free") == 0)
121
      model_mon_info_free_p = 1;
122
  }
123
 
124
  if (!model_create_p) {
125
    lf_print_function_type(file, "model_data *", "INLINE_MODEL", " ");
126
    lf_printf(file, "model_create\n");
127
    lf_printf(file, "(sim_cpu *cpu);\n");
128
    lf_printf(file, "\n");
129
  }
130
 
131
  if (!model_init_p) {
132
    lf_print_function_type(file, "void", "INLINE_MODEL", " ");
133
    lf_printf(file, "model_init\n");
134
    lf_printf(file, "(model_data *model_ptr);\n");
135
    lf_printf(file, "\n");
136
  }
137
 
138
  if (!model_halt_p) {
139
    lf_print_function_type(file, "void", "INLINE_MODEL", " ");
140
    lf_printf(file, "model_halt\n");
141
    lf_printf(file, "(model_data *model_ptr);\n");
142
    lf_printf(file, "\n");
143
  }
144
 
145
  if (!model_mon_info_p) {
146
    lf_print_function_type(file, "model_print *", "INLINE_MODEL", " ");
147
    lf_printf(file, "model_mon_info\n");
148
    lf_printf(file, "(model_data *model_ptr);\n");
149
    lf_printf(file, "\n");
150
  }
151
 
152
  if (!model_mon_info_free_p) {
153
    lf_print_function_type(file, "void", "INLINE_MODEL", " ");
154
    lf_printf(file, "model_mon_info_free\n");
155
    lf_printf(file, "(model_data *model_ptr,\n");
156
    lf_printf(file, " model_print *info_ptr);\n");
157
    lf_printf(file, "\n");
158
  }
159
 
160
  lf_print_function_type(file, "void", "INLINE_MODEL", " ");
161
  lf_printf(file, "model_set\n");
162
  lf_printf(file, "(const char *name);\n");
163
}
164
 
165
/****************************************************************/
166
 
167
typedef struct _model_c_passed_data model_c_passed_data;
168
struct _model_c_passed_data {
169
  lf *file;
170
  model *model_ptr;
171
};
172
 
173
static void
174
model_c_insn(insn_table *entry,
175
             lf *phony_file,
176
             void *data,
177
             insn *instruction,
178
             int depth)
179
{
180
  model_c_passed_data *data_ptr = (model_c_passed_data *)data;
181
  lf *file = data_ptr->file;
182
  char *current_name = data_ptr->model_ptr->printable_name;
183
  table_model_entry *model_ptr = instruction->file_entry->model_first;
184
 
185
  while (model_ptr) {
186
    if (model_ptr->fields[insn_model_name] == current_name) {
187
      lf_printf(file, "  { %-*s },  /* %s */\n",
188
                max_model_fields_len,
189
                model_ptr->fields[insn_model_fields],
190
                instruction->file_entry->fields[insn_name]);
191
      return;
192
    }
193
 
194
    model_ptr = model_ptr->next;
195
  }
196
 
197
  lf_printf(file, "  { %-*s },  /* %s */\n",
198
            max_model_fields_len,
199
            data_ptr->model_ptr->insn_default,
200
            instruction->file_entry->fields[insn_name]);
201
}
202
 
203
static void
204
model_c_function(insn_table *table,
205
                 lf *file,
206
                 table_entry *function,
207
                 const char *prefix)
208
{
209
  if (function->fields[function_type] == NULL
210
      || function->fields[function_type][0] == '\0')
211
    {
212
      error("Model function return type not specified for %s",
213
            function->fields[function_name]);
214
    }
215
  else
216
    {
217
      lf_printf(file, "\n");
218
      lf_print_function_type(file, function->fields[function_type], prefix, "\n");
219
      lf_printf(file, "%s(%s)\n",
220
                function->fields[function_name],
221
                function->fields[function_param]);
222
    }
223
  lf_printf(file, "{\n");
224
  if (function->annex)
225
    {
226
      lf_indent(file, +2);
227
      table_entry_print_cpp_line_nr(file, function->annex_line);
228
      lf_print__c_code(file, function->annex);
229
      lf_indent(file, -2);
230
    }
231
  lf_printf(file, "}\n");
232
  lf_print__internal_reference(file);
233
  lf_printf(file, "\n");
234
}
235
 
236
void
237
gen_model_c(insn_table *table, lf *file)
238
{
239
  insn *insn_ptr;
240
  model *model_ptr;
241
  char *name;
242
  int model_create_p = 0;
243
  int model_init_p = 0;
244
  int model_halt_p = 0;
245
  int model_mon_info_p = 0;
246
  int model_mon_info_free_p = 0;
247
 
248
  lf_printf(file, "\n");
249
  lf_printf(file, "#include \"cpu.h\"\n");
250
  lf_printf(file, "#include \"mon.h\"\n");
251
  lf_printf(file, "\n");
252
  lf_printf(file, "#ifdef HAVE_STDLIB_H\n");
253
  lf_printf(file, "#include <stdlib.h>\n");
254
  lf_printf(file, "#endif\n");
255
  lf_printf(file, "\n");
256
 
257
  for(insn_ptr = model_data; insn_ptr; insn_ptr = insn_ptr->next) {
258
    model_c_or_h_data(table, file, insn_ptr->file_entry);
259
  }
260
 
261
  for(insn_ptr = model_static; insn_ptr; insn_ptr = insn_ptr->next) {
262
    model_c_or_h_function(table, file, insn_ptr->file_entry, "/*h*/STATIC");
263
  }
264
 
265
  for(insn_ptr = model_internal; insn_ptr; insn_ptr = insn_ptr->next) {
266
    model_c_or_h_function(table, file, insn_ptr->file_entry, "STATIC_INLINE_MODEL");
267
  }
268
 
269
  for(insn_ptr = model_static; insn_ptr; insn_ptr = insn_ptr->next) {
270
    model_c_function(table, file, insn_ptr->file_entry, "/*c*/STATIC");
271
  }
272
 
273
  for(insn_ptr = model_internal; insn_ptr; insn_ptr = insn_ptr->next) {
274
    model_c_function(table, file, insn_ptr->file_entry, "STATIC_INLINE_MODEL");
275
  }
276
 
277
  for(insn_ptr = model_functions; insn_ptr; insn_ptr = insn_ptr->next) {
278
    model_c_function(table, file, insn_ptr->file_entry, "INLINE_MODEL");
279
    name = insn_ptr->file_entry->fields[function_name];
280
    if (strcmp (name, "model_create") == 0)
281
      model_create_p = 1;
282
    else if (strcmp (name, "model_init") == 0)
283
      model_init_p = 1;
284
    else if (strcmp (name, "model_halt") == 0)
285
      model_halt_p = 1;
286
    else if (strcmp (name, "model_mon_info") == 0)
287
      model_mon_info_p = 1;
288
    else if (strcmp (name, "model_mon_info_free") == 0)
289
      model_mon_info_free_p = 1;
290
  }
291
 
292
  if (!model_create_p) {
293
    lf_print_function_type(file, "model_data *", "INLINE_MODEL", "\n");
294
    lf_printf(file, "model_create(sim_cpu *cpu)\n");
295
    lf_printf(file, "{\n");
296
    lf_printf(file, "  return (model_data *)0;\n");
297
    lf_printf(file, "}\n");
298
    lf_printf(file, "\n");
299
  }
300
 
301
  if (!model_init_p) {
302
    lf_print_function_type(file, "void", "INLINE_MODEL", "\n");
303
    lf_printf(file, "model_init(model_data *model_ptr)\n");
304
    lf_printf(file, "{\n");
305
    lf_printf(file, "}\n");
306
    lf_printf(file, "\n");
307
  }
308
 
309
  if (!model_halt_p) {
310
    lf_print_function_type(file, "void", "INLINE_MODEL", "\n");
311
    lf_printf(file, "model_halt(model_data *model_ptr)\n");
312
    lf_printf(file, "{\n");
313
    lf_printf(file, "}\n");
314
    lf_printf(file, "\n");
315
  }
316
 
317
  if (!model_mon_info_p) {
318
    lf_print_function_type(file, "model_print *", "INLINE_MODEL", "\n");
319
    lf_printf(file, "model_mon_info(model_data *model_ptr)\n");
320
    lf_printf(file, "{\n");
321
    lf_printf(file, "  return (model_print *)0;\n");
322
    lf_printf(file, "}\n");
323
    lf_printf(file, "\n");
324
  }
325
 
326
  if (!model_mon_info_free_p) {
327
    lf_print_function_type(file, "void", "INLINE_MODEL", "\n");
328
    lf_printf(file, "model_mon_info_free(model_data *model_ptr,\n");
329
    lf_printf(file, "                    model_print *info_ptr)\n");
330
    lf_printf(file, "{\n");
331
    lf_printf(file, "}\n");
332
    lf_printf(file, "\n");
333
  }
334
 
335
  lf_printf(file, "/* Insn functional unit info */\n");
336
  for(model_ptr = models; model_ptr; model_ptr = model_ptr->next) {
337
    model_c_passed_data data;
338
 
339
    lf_printf(file, "static const model_time model_time_%s[] = {\n", model_ptr->name);
340
    data.file = file;
341
    data.model_ptr = model_ptr;
342
    insn_table_traverse_insn(table,
343
                             NULL, (void *)&data,
344
                             model_c_insn);
345
 
346
    lf_printf(file, "};\n");
347
    lf_printf(file, "\n");
348
    lf_printf(file, "\f\n");
349
  }
350
 
351
  lf_printf(file, "#ifndef _INLINE_C_\n");
352
  lf_printf(file, "const model_time *const model_time_mapping[ (int)nr_models ] = {\n");
353
  lf_printf(file, "  (const model_time *const)0,\n");
354
  for(model_ptr = models; model_ptr; model_ptr = model_ptr->next) {
355
    lf_printf(file, "  model_time_%s,\n", model_ptr->name);
356
  }
357
  lf_printf(file, "};\n");
358
  lf_printf(file, "#endif\n");
359
  lf_printf(file, "\n");
360
 
361
  lf_printf(file, "\f\n");
362
  lf_printf(file, "/* map model enumeration into printable string */\n");
363
  lf_printf(file, "#ifndef _INLINE_C_\n");
364
  lf_printf(file, "const char *model_name[ (int)nr_models ] = {\n");
365
  lf_printf(file, "  \"NONE\",\n");
366
  for (model_ptr = models; model_ptr; model_ptr = model_ptr->next) {
367
    lf_printf(file, "  \"%s\",\n", model_ptr->printable_name);
368
  }
369
  lf_printf(file, "};\n");
370
  lf_printf(file, "#endif\n");
371
  lf_printf(file, "\n");
372
 
373
  lf_print_function_type(file, "void", "INLINE_MODEL", "\n");
374
  lf_printf(file, "model_set(const char *name)\n");
375
  lf_printf(file, "{\n");
376
  if (models) {
377
    lf_printf(file, "  model_enum model;\n");
378
    lf_printf(file, "  for(model = MODEL_%s; model < nr_models; model++) {\n", models->name);
379
    lf_printf(file, "    if(strcmp(name, model_name[model]) == 0) {\n");
380
    lf_printf(file, "      current_model = model;\n");
381
    lf_printf(file, "      return;\n");
382
    lf_printf(file, "    }\n");
383
    lf_printf(file, "  }\n");
384
    lf_printf(file, "\n");
385
    lf_printf(file, "  error(\"Unknown model '%%s', Models which are known are:%%s\n\",\n");
386
    lf_printf(file, "        name,\n");
387
    lf_printf(file, "        \"");
388
    for(model_ptr = models; model_ptr; model_ptr = model_ptr->next) {
389
      lf_printf(file, "\\n\\t%s", model_ptr->printable_name);
390
    }
391
    lf_printf(file, "\");\n");
392
  } else {
393
    lf_printf(file, "  error(\"No models are currently known about\");\n");
394
  }
395
 
396
  lf_printf(file, "}\n");
397
}
398
 
399
#endif
400
 
401
 
402
 
403
void
404
gen_model_h (lf *file,
405
             insn_table *table)
406
{
407
  lf_print__this_file_is_empty (file, "suffering bit rot");
408
}
409
 
410
 
411
void
412
gen_model_c (lf *file,
413
             insn_table *table)
414
{
415
  lf_print__this_file_is_empty (file, "suffering bit rot");
416
}

powered by: WebSVN 2.1.0

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