summaryrefslogtreecommitdiff
path: root/sim/ppc/gen-itable.c
blob: 132aa291e083caf8084b0ec0d208d2e2f1a46026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*  This file is part of the program psim.

    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
    */



#include "misc.h"
#include "lf.h"
#include "table.h"

#include "filter.h"

#include "ld-decode.h"
#include "ld-insn.h"

#include "igen.h"
#include "gen-itable.h"

#ifndef NULL
#define NULL 0
#endif



static void
itable_h_insn(insn_table *entry,
	      lf *file,
	      void *data,
	      insn *instruction,
	      int depth)
{
  lf_printf(file, "  ");
  print_function_name(file,
		      instruction->file_entry->fields[insn_name],
		      NULL,
		      function_name_prefix_itable);
  lf_printf(file, ",\n");
}


extern void 
gen_itable_h(insn_table *table, lf *file)
{
  /* output an enumerated type for each instruction */
  lf_printf(file, "typedef enum {\n");
  insn_table_traverse_insn(table,
			   file, NULL,
			   itable_h_insn);
  lf_printf(file, "  nr_itable_entries,\n");
  lf_printf(file, "} itable_index;\n");
  lf_printf(file, "\n");

  /* output the table that contains the actual instruction info */
  lf_printf(file, "typedef struct _itable_instruction_info {\n");
  lf_printf(file, "  itable_index nr;\n");
  lf_printf(file, "  char *format;\n");
  lf_printf(file, "  char *form;\n");
  lf_printf(file, "  char *flags;\n");
  lf_printf(file, "  char *mnemonic;\n");
  lf_printf(file, "  char *name;\n");
  lf_printf(file, "  char *file;\n");
  lf_printf(file, "  int line_nr;\n");
  lf_printf(file, "} itable_info;\n");
  lf_printf(file, "\n");
  lf_printf(file, "extern itable_info itable[nr_itable_entries];\n");
}

/****************************************************************/

static void
itable_c_insn(insn_table *entry,
	      lf *file,
	      void *data,
	      insn *instruction,
	      int depth)
{
  char **fields = instruction->file_entry->fields;
  lf_printf(file, "  { ");
  print_function_name(file,
		      instruction->file_entry->fields[insn_name],
		      NULL,
		      function_name_prefix_itable);
  lf_printf(file, ",\n");
  lf_printf(file, "    \"%s\",\n", fields[insn_format]);
  lf_printf(file, "    \"%s\",\n", fields[insn_form]);
  lf_printf(file, "    \"%s\",\n", fields[insn_flags]);
  lf_printf(file, "    \"%s\",\n", fields[insn_mnemonic]);
  lf_printf(file, "    \"%s\",\n", fields[insn_name]);
  lf_printf(file, "    \"%s\",\n", filter_filename (instruction->file_entry->file_name));
  lf_printf(file, "    %d,\n", instruction->file_entry->line_nr);
  lf_printf(file, "    },\n");
}


extern void 
gen_itable_c(insn_table *table, lf *file)
{
  /* output the table that contains the actual instruction info */
  lf_printf(file, "#include \"itable.h\"\n");
  lf_printf(file, "\n");
  lf_printf(file, "itable_info itable[nr_itable_entries] = {\n");
  insn_table_traverse_insn(table,
			   file, NULL,
			   itable_c_insn);
  lf_printf(file, "};\n");
}