1 /* CGEN generic assembler support code.
3 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 This file is part of the GNU Binutils and GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program 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.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "libiberty.h"
32 #include "opcode/cgen.h"
34 /* This is not published as part of the public interface so we don't
35 declare this in cgen.h. */
36 extern CGEN_OPCODE_DATA
*cgen_current_opcode_data
;
38 /* Assembler instruction hash table. */
39 static CGEN_INSN_LIST
**asm_hash_table
;
46 free (asm_hash_table
);
47 asm_hash_table
= NULL
;
51 /* Build the assembler instruction hash table. */
54 build_asm_hash_table ()
58 int count
= cgen_insn_count ();
59 CGEN_OPCODE_DATA
*data
= cgen_current_opcode_data
;
60 CGEN_INSN_TABLE
*insn_table
= data
->insn_table
;
61 unsigned int hash_size
= insn_table
->asm_hash_table_size
;
62 const CGEN_INSN
*insn
;
63 CGEN_INSN_LIST
*insn_lists
,*new_insns
;
65 /* The space allocated for the hash table consists of two parts:
66 the hash table and the hash lists. */
68 asm_hash_table
= (CGEN_INSN_LIST
**)
69 xmalloc (hash_size
* sizeof (CGEN_INSN_LIST
*)
70 + count
* sizeof (CGEN_INSN_LIST
));
71 memset (asm_hash_table
, 0,
72 hash_size
* sizeof (CGEN_INSN_LIST
*)
73 + count
* sizeof (CGEN_INSN_LIST
));
74 insn_lists
= (CGEN_INSN_LIST
*) (asm_hash_table
+ hash_size
);
76 /* Add compiled in insns.
77 The table is scanned backwards as later additions are inserted in
78 front of earlier ones and we want earlier ones to be prefered.
79 We stop at the first one as it is a reserved entry. */
81 for (insn
= insn_table
->init_entries
+ insn_table
->num_init_entries
- 1;
82 insn
> insn_table
->init_entries
;
85 hash
= (*insn_table
->asm_hash
) (insn
->syntax
.mnemonic
);
86 insn_lists
->next
= asm_hash_table
[hash
];
87 insn_lists
->insn
= insn
;
88 asm_hash_table
[hash
] = insn_lists
;
91 /* Add runtime added insns.
92 ??? Currently later added insns will be prefered over earlier ones.
93 Not sure this is a bug or not. */
94 for (new_insns
= insn_table
->new_entries
;
96 new_insns
= new_insns
->next
, ++insn_lists
)
98 hash
= (*insn_table
->asm_hash
) (new_insns
->insn
->syntax
.mnemonic
);
99 insn_lists
->next
= asm_hash_table
[hash
];
100 insn_lists
->insn
= new_insns
->insn
;
101 asm_hash_table
[hash
] = insn_lists
;
105 /* Return the first entry in the hash list for INSN. */
108 cgen_asm_lookup_insn (insn
)
113 if (asm_hash_table
== NULL
)
114 build_asm_hash_table ();
116 hash
= (*cgen_current_opcode_data
->insn_table
->asm_hash
) (insn
);
117 return asm_hash_table
[hash
];
121 The result is NULL upon success or an error message.
122 If successful, *STRP is updated to point passed the keyword.
124 ??? At present we have a static notion of how to pick out a keyword.
125 Later we can allow a target to customize this if necessary [say by
126 recording something in the keyword table]. */
129 cgen_parse_keyword (strp
, keyword_table
, valuep
)
131 struct cgen_keyword
*keyword_table
;
134 const struct cgen_keyword_entry
*ke
;
140 /* Allow any first character. */
144 /* Now allow letters, digits, and _. */
145 while (isalnum (*p
) || *p
== '_')
149 return "unrecognized keyword/register name";
151 memcpy (buf
, *strp
, p
- *strp
);
154 ke
= cgen_keyword_lookup_name (keyword_table
, buf
);
163 return "unrecognized keyword/register name";
166 /* Signed integer parser. */
169 cgen_parse_signed_integer (strp
, opindex
, min
, max
, valuep
)
176 enum cgen_asm_result result
;
179 errmsg
= cgen_asm_parse_operand (strp
, opindex
, BFD_RELOC_NONE
,
181 /* FIXME: Examine `result'. */
184 if (value
< min
|| value
> max
)
185 return "integer operand out of range";
191 /* Unsigned integer parser. */
194 cgen_parse_unsigned_integer (strp
, opindex
, min
, max
, valuep
)
197 unsigned long min
, max
;
198 unsigned long *valuep
;
201 enum cgen_asm_result result
;
204 errmsg
= cgen_asm_parse_operand (strp
, opindex
, BFD_RELOC_NONE
,
206 /* FIXME: Examine `result'. */
209 if (value
< min
|| value
> max
)
210 return "integer operand out of range";
216 /* Address parser. */
219 cgen_parse_address (strp
, opindex
, opinfo
, valuep
)
226 enum cgen_asm_result result
;
229 errmsg
= cgen_asm_parse_operand (strp
, opindex
, opinfo
, &result
, &value
);
230 /* FIXME: Examine `result'. */
238 /* Signed integer validation routine. */
241 cgen_validate_signed_integer (value
, min
, max
)
242 long value
, min
, max
;
244 if (value
< min
|| value
> max
)
247 "operand out of range (%ld not between %ld and %ld)";
248 static char buf
[100];
250 sprintf (buf
, err
, value
, min
, max
);
257 /* Unsigned integer validation routine.
258 Supplying `min' here may seem unnecessary, but we also want to handle
259 cases where min != 0 (and max > LONG_MAX). */
262 cgen_validate_unsigned_integer (value
, min
, max
)
263 unsigned long value
, min
, max
;
265 if (value
< min
|| value
> max
)
268 "operand out of range (%lu not between %lu and %lu)";
269 static char buf
[100];
271 sprintf (buf
, err
, value
, min
, max
);
This page took 0.036365 seconds and 5 git commands to generate.