annotate src/share/vm/adlc/adlparse.cpp @ 17795:a9becfeecd1b

Merge
author kvn
date Wed, 22 Jan 2014 17:42:23 -0800
parents 55fb97c4c58d 318d0622a6d7
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12323
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 628
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 628
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 628
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // ADLPARSE.CPP - Architecture Description Language Parser
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // Authors: Chris Vick and Mike Paleczny
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include "adlc.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 //----------------------------ADLParser----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Create a new ADL parser
a61af66fc99e Initial load
duke
parents:
diff changeset
31 ADLParser::ADLParser(FileBuff& buffer, ArchDesc& archDesc)
a61af66fc99e Initial load
duke
parents:
diff changeset
32 : _buf(buffer), _AD(archDesc),
a61af66fc99e Initial load
duke
parents:
diff changeset
33 _globalNames(archDesc.globalNames()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 _AD._syntax_errs = _AD._semantic_errs = 0; // No errors so far this file
a61af66fc99e Initial load
duke
parents:
diff changeset
35 _AD._warnings = 0; // No warnings either
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _curline = _ptr = NULL; // No pointers into buffer yet
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 _preproc_depth = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _preproc_not_taken = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Delimit command-line definitions from in-file definitions:
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _AD._preproc_list.add_signal();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //------------------------------~ADLParser-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Delete an ADL parser.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ADLParser::~ADLParser() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 if (!_AD._quiet_mode)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 fprintf(stderr,"---------------------------- Errors and Warnings ----------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
50 #ifndef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
51 fprintf(stderr, "**************************************************************\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 fprintf(stderr, "***** WARNING: ASSERT is undefined, assertions disabled. *****\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 fprintf(stderr, "**************************************************************\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if( _AD._syntax_errs + _AD._semantic_errs + _AD._warnings == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (!_AD._quiet_mode)
a61af66fc99e Initial load
duke
parents:
diff changeset
57 fprintf(stderr,"No errors or warnings to report from phase-1 parse.\n" );
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if( _AD._syntax_errs ) { // Any syntax errors?
a61af66fc99e Initial load
duke
parents:
diff changeset
61 fprintf(stderr,"%s: Found %d syntax error", _buf._fp->_name, _AD._syntax_errs);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if( _AD._syntax_errs > 1 ) fprintf(stderr,"s.\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 else fprintf(stderr,".\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if( _AD._semantic_errs ) { // Any semantic errors?
a61af66fc99e Initial load
duke
parents:
diff changeset
66 fprintf(stderr,"%s: Found %d semantic error", _buf._fp->_name, _AD._semantic_errs);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if( _AD._semantic_errs > 1 ) fprintf(stderr,"s.\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
68 else fprintf(stderr,".\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if( _AD._warnings ) { // Any warnings?
a61af66fc99e Initial load
duke
parents:
diff changeset
71 fprintf(stderr,"%s: Found %d warning", _buf._fp->_name, _AD._warnings);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if( _AD._warnings > 1 ) fprintf(stderr,"s.\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 else fprintf(stderr,".\n\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (!_AD._quiet_mode)
a61af66fc99e Initial load
duke
parents:
diff changeset
77 fprintf(stderr,"-----------------------------------------------------------------------------\n");
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
78 _AD._TotalLines += linenum()-1; // -1 for overshoot in "nextline" routine
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Write out information we have stored
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // // UNIXism == fsync(stderr);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 //------------------------------parse------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Each top-level keyword should appear as the first non-whitespace on a line.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 //
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void ADLParser::parse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // Iterate over the lines in the file buffer parsing Level 1 objects
a61af66fc99e Initial load
duke
parents:
diff changeset
91 for( next_line(); _curline != NULL; next_line()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _ptr = _curline; // Reset ptr to start of new line
a61af66fc99e Initial load
duke
parents:
diff changeset
93 skipws(); // Skip any leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
94 ident = get_ident(); // Get first token
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (ident == NULL) { // Empty line
a61af66fc99e Initial load
duke
parents:
diff changeset
96 continue; // Get the next line
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
98 if (!strcmp(ident, "instruct")) instr_parse();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 else if (!strcmp(ident, "operand")) oper_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 else if (!strcmp(ident, "opclass")) opclass_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 else if (!strcmp(ident, "ins_attrib")) ins_attr_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 else if (!strcmp(ident, "op_attrib")) op_attr_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 else if (!strcmp(ident, "source")) source_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 else if (!strcmp(ident, "source_hpp")) source_hpp_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 else if (!strcmp(ident, "register")) reg_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 else if (!strcmp(ident, "frame")) frame_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 else if (!strcmp(ident, "encode")) encode_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 else if (!strcmp(ident, "pipeline")) pipe_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 else if (!strcmp(ident, "definitions")) definitions_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 else if (!strcmp(ident, "peephole")) peep_parse();
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
111 else if (!strcmp(ident, "#line")) preproc_line();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 else if (!strcmp(ident, "#define")) preproc_define();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 else if (!strcmp(ident, "#undef")) preproc_undef();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 parse_err(SYNERR, "expected one of - instruct, operand, ins_attrib, op_attrib, source, register, pipeline, encode\n Found %s",ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
118 // Add reg_class spill_regs after parsing.
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
119 RegisterForm *regBlock = _AD.get_registers();
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
120 if (regBlock == NULL) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
121 parse_err(SEMERR, "Did not declare 'register' definitions");
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
122 }
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
123 regBlock->addSpillRegClass();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Done with parsing, check consistency.
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (_preproc_depth != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 parse_err(SYNERR, "End of file inside #ifdef");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // AttributeForms ins_cost and op_cost must be defined for default behaviour
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (_globalNames[AttributeForm::_ins_cost] == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 parse_err(SEMERR, "Did not declare 'ins_cost' attribute");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (_globalNames[AttributeForm::_op_cost] == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 parse_err(SEMERR, "Did not declare 'op_cost' attribute");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // ******************** Private Level 1 Parse Functions ********************
a61af66fc99e Initial load
duke
parents:
diff changeset
141 //------------------------------instr_parse------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Parse the contents of an instruction definition, build the InstructForm to
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // represent that instruction, and add it to the InstructForm list.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void ADLParser::instr_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 InstructForm *instr;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 MatchRule *rule;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int match_rules_cnt = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // First get the name of the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
151 if( (ident = get_unique_ident(_globalNames,"instruction")) == NULL )
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 instr = new InstructForm(ident); // Create new instruction form
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
154 instr->_linenum = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 _globalNames.Insert(ident, instr); // Add name to the name table
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (_AD._adl_debug > 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
158 fprintf(stderr,"Parsing Instruction Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Then get the operands
a61af66fc99e Initial load
duke
parents:
diff changeset
161 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 parse_err(SYNERR, "missing '(' in instruct definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Parse the operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
166 else get_oplist(instr->_parameters, instr->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // Check for block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
170 || ( next_char(), (_curchar != '{')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
171 parse_err(SYNERR, "missing '%%{' in instruction definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 next_char(); // Maintain the invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
175 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (!strcmp(ident, "predicate")) instr->_predicate = pred_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 else if (!strcmp(ident, "match")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // Allow one instruction have several match rules.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 rule = instr->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (rule == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // This is first match rule encountered
a61af66fc99e Initial load
duke
parents:
diff changeset
187 rule = match_parse(instr->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if (rule) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 instr->_matrule = rule;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // Special case the treatment of Control instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if( instr->is_ideal_control() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Control instructions return a special result, 'Universe'
a61af66fc99e Initial load
duke
parents:
diff changeset
193 rule->_result = "Universe";
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // Check for commutative operations with tree operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
196 matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Find the end of the match rule list
a61af66fc99e Initial load
duke
parents:
diff changeset
200 while (rule->_next != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
201 rule = rule->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // Add the new match rule to the list
a61af66fc99e Initial load
duke
parents:
diff changeset
203 rule->_next = match_parse(instr->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 if (rule->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 rule = rule->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if( instr->is_ideal_control() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 parse_err(SYNERR, "unique match rule expected for %s\n", rule->_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 assert(match_rules_cnt < 100," too many match rule clones");
a61af66fc99e Initial load
duke
parents:
diff changeset
211 char* buf = (char*) malloc(strlen(instr->_ident) + 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 sprintf(buf, "%s_%d", instr->_ident, match_rules_cnt++);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 rule->_result = buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Check for commutative operations with tree operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
215 matchrule_clone_and_swap(rule, instr->_ident, match_rules_cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 else if (!strcmp(ident, "encode")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 parse_err(SYNERR, "Instructions specify ins_encode, not encode\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
222 else if (!strcmp(ident, "ins_encode")) ins_encode_parse(*instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
223 // Parse late expand keyword.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
224 else if (!strcmp(ident, "postalloc_expand")) postalloc_expand_parse(*instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
225 else if (!strcmp(ident, "opcode")) instr->_opcode = opcode_parse(instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
226 else if (!strcmp(ident, "size")) instr->_size = size_parse(instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
227 else if (!strcmp(ident, "effect")) effect_parse(instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
228 else if (!strcmp(ident, "expand")) instr->_exprule = expand_parse(instr);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
229 else if (!strcmp(ident, "rewrite")) instr->_rewrule = rewrite_parse();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
230 else if (!strcmp(ident, "constraint")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 parse_err(SYNERR, "Instructions do not specify a constraint\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 else if (!strcmp(ident, "construct")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 parse_err(SYNERR, "Instructions do not specify a construct\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
236 else if (!strcmp(ident, "format")) instr->_format = format_parse();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
237 else if (!strcmp(ident, "interface")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 parse_err(SYNERR, "Instructions do not specify an interface\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
240 else if (!strcmp(ident, "ins_pipe")) ins_pipe_parse(*instr);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
241 else { // Done with staticly defined parts of instruction definition
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // Check identifier to see if it is the name of an attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
243 const Form *form = _globalNames[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
244 AttributeForm *attr = form ? form->is_attribute() : NULL;
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
245 if (attr && (attr->_atype == INS_ATTR)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // Insert the new attribute into the linked list.
a61af66fc99e Initial load
duke
parents:
diff changeset
247 Attribute *temp = attr_parse(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 temp->_next = instr->_attribs;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 instr->_attribs = temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 } else {
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
251 parse_err(SYNERR, "expected one of:\n predicate, match, encode, or the name of"
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
252 " an instruction attribute at %s\n", ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
256 } while(_curchar != '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
257 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (_curchar != '}') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
259 parse_err(SYNERR, "missing '%%}' in instruction definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // Check for "Set" form of chain rule
a61af66fc99e Initial load
duke
parents:
diff changeset
263 adjust_set_rule(instr);
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
264 if (_AD._pipeline) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
265 // No pipe required for late expand.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
266 if (instr->expands() || instr->postalloc_expands()) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
267 if (instr->_ins_pipe) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
268 parse_err(WARN, "ins_pipe and expand rule both specified for instruction \"%s\";"
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
269 " ins_pipe will be unused\n", instr->_ident);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
270 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
271 } else {
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
272 if (!instr->_ins_pipe) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
273 parse_err(WARN, "No ins_pipe specified for instruction \"%s\"\n", instr->_ident);
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
274 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // Add instruction to tail of instruction list
a61af66fc99e Initial load
duke
parents:
diff changeset
278 _AD.addForm(instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // Create instruction form for each additional match rule
a61af66fc99e Initial load
duke
parents:
diff changeset
281 rule = instr->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 if (rule != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 rule = rule->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 while (rule != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ident = (char*)rule->_result;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 InstructForm *clone = new InstructForm(ident, instr, rule); // Create new instruction form
a61af66fc99e Initial load
duke
parents:
diff changeset
287 _globalNames.Insert(ident, clone); // Add name to the name table
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
289 if (_AD._adl_debug > 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
290 fprintf(stderr,"Parsing Instruction Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Check for "Set" form of chain rule
a61af66fc99e Initial load
duke
parents:
diff changeset
292 adjust_set_rule(clone);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Add instruction to tail of instruction list
a61af66fc99e Initial load
duke
parents:
diff changeset
294 _AD.addForm(clone);
a61af66fc99e Initial load
duke
parents:
diff changeset
295 rule = rule->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 clone->_matrule->_next = NULL; // One match rule per clone
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 //------------------------------matchrule_clone_and_swap-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // Check for commutative operations with subtree operands,
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // create clones and swap operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
304 void ADLParser::matchrule_clone_and_swap(MatchRule* rule, const char* instr_ident, int& match_rules_cnt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Check for commutative operations with tree operands.
a61af66fc99e Initial load
duke
parents:
diff changeset
306 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 rule->count_commutative_op(count);
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (count > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // Clone match rule and swap commutative operation's operands.
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
310 rule->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314 //------------------------------adjust_set_rule--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // Check for "Set" form of chain rule
a61af66fc99e Initial load
duke
parents:
diff changeset
316 void ADLParser::adjust_set_rule(InstructForm *instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 if (instr->_matrule == NULL || instr->_matrule->_rChild == NULL) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
318 const char *rch = instr->_matrule->_rChild->_opType;
a61af66fc99e Initial load
duke
parents:
diff changeset
319 const Form *frm = _globalNames[rch];
a61af66fc99e Initial load
duke
parents:
diff changeset
320 if( (! strcmp(instr->_matrule->_opType,"Set")) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
321 frm && frm->is_operand() && (! frm->ideal_only()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // Previous implementation, which missed leaP*, but worked for loadCon*
a61af66fc99e Initial load
duke
parents:
diff changeset
323 unsigned position = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 const char *result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 const char *name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 const char *optype = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
327 MatchNode *right = instr->_matrule->_rChild;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 if (right->base_operand(position, _globalNames, result, name, optype)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 position = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 const char *result2 = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 const char *name2 = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 const char *optype2 = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Can not have additional base operands in right side of match!
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if ( ! right->base_operand( position, _globalNames, result2, name2, optype2) ) {
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
335 if (instr->_predicate != NULL)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
336 parse_err(SYNERR, "ADLC does not support instruction chain rules with predicates");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // Chain from input _ideal_operand_type_,
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Needed for shared roots of match-trees
a61af66fc99e Initial load
duke
parents:
diff changeset
339 ChainList *lst = (ChainList *)_AD._chainRules[optype];
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (lst == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 lst = new ChainList();
a61af66fc99e Initial load
duke
parents:
diff changeset
342 _AD._chainRules.Insert(optype, lst);
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344 if (!lst->search(instr->_matrule->_lChild->_opType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
345 const char *cost = instr->cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
346 if (cost == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // The ADLC does not support chaining from the ideal operand type
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // of a predicated user-defined operand
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if( frm->is_operand() == NULL || frm->is_operand()->_predicate == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // Chain from input _user_defined_operand_type_,
a61af66fc99e Initial load
duke
parents:
diff changeset
356 lst = (ChainList *)_AD._chainRules[result];
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (lst == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 lst = new ChainList();
a61af66fc99e Initial load
duke
parents:
diff changeset
359 _AD._chainRules.Insert(result, lst);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 if (!lst->search(instr->_matrule->_lChild->_opType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 const char *cost = instr->cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 if (cost == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 // It is safe to chain from the top-level user-defined operand even
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // if it has a predicate, since the predicate is checked before
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // the user-defined type is available.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
372 // May have instruction chain rule if root of right-tree is an ideal
a61af66fc99e Initial load
duke
parents:
diff changeset
373 OperandForm *rightOp = _globalNames[right->_opType]->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if( rightOp ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 const Form *rightRoot = _globalNames[rightOp->_matrule->_opType];
a61af66fc99e Initial load
duke
parents:
diff changeset
376 if( rightRoot && rightRoot->ideal_only() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 const char *chain_op = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if( rightRoot->is_instruction() )
a61af66fc99e Initial load
duke
parents:
diff changeset
379 chain_op = rightOp->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if( chain_op ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 // Look-up the operation in chain rule table
a61af66fc99e Initial load
duke
parents:
diff changeset
382 ChainList *lst = (ChainList *)_AD._chainRules[chain_op];
a61af66fc99e Initial load
duke
parents:
diff changeset
383 if (lst == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 lst = new ChainList();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 _AD._chainRules.Insert(chain_op, lst);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // if (!lst->search(instr->_matrule->_lChild->_opType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 const char *cost = instr->cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
389 if (cost == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
390 cost = ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // This chains from a top-level operand whose predicate, if any,
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // has been checked.
a61af66fc99e Initial load
duke
parents:
diff changeset
394 lst->insert(instr->_matrule->_lChild->_opType,cost,instr->_ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399 } // end chain rule from right-tree's ideal root
a61af66fc99e Initial load
duke
parents:
diff changeset
400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402 }
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405 //------------------------------oper_parse-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
406 void ADLParser::oper_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 OperandForm *oper;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 AttributeForm *attr;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 MatchRule *rule;
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // First get the name of the operand
a61af66fc99e Initial load
duke
parents:
diff changeset
413 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if( (ident = get_unique_ident(_globalNames,"operand")) == NULL )
a61af66fc99e Initial load
duke
parents:
diff changeset
415 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 oper = new OperandForm(ident); // Create new operand form
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
417 oper->_linenum = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
418 _globalNames.Insert(ident, oper); // Add name to the name table
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
421 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Operand Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Get the component operands
a61af66fc99e Initial load
duke
parents:
diff changeset
424 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
425 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
426 parse_err(SYNERR, "missing '(' in operand definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
427 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429 else get_oplist(oper->_parameters, oper->_localNames); // Parse the component operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
430 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
431 // Check for block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
432 if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
433 parse_err(SYNERR, "missing '%%{' in operand definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
434 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
436 next_char(); next_char(); // Skip over "%{" symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
437 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443 if (!strcmp(ident, "predicate")) oper->_predicate = pred_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
444 else if (!strcmp(ident, "match")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // Find the end of the match rule list
a61af66fc99e Initial load
duke
parents:
diff changeset
446 rule = oper->_matrule;
a61af66fc99e Initial load
duke
parents:
diff changeset
447 if (rule) {
a61af66fc99e Initial load
duke
parents:
diff changeset
448 while (rule->_next) rule = rule->_next;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // Add the new match rule to the list
a61af66fc99e Initial load
duke
parents:
diff changeset
450 rule->_next = match_parse(oper->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 if (rule->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 rule->_next->_result = oper->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // This is first match rule encountered
a61af66fc99e Initial load
duke
parents:
diff changeset
457 oper->_matrule = match_parse(oper->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 if (oper->_matrule) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 oper->_matrule->_result = oper->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461 }
a61af66fc99e Initial load
duke
parents:
diff changeset
462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
463 else if (!strcmp(ident, "encode")) oper->_interface = interface_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
464 else if (!strcmp(ident, "ins_encode")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
465 parse_err(SYNERR, "Operands specify 'encode', not 'ins_encode'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 else if (!strcmp(ident, "opcode")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 parse_err(SYNERR, "Operands do not specify an opcode\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470 else if (!strcmp(ident, "effect")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 parse_err(SYNERR, "Operands do not specify an effect\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 else if (!strcmp(ident, "expand")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 parse_err(SYNERR, "Operands do not specify an expand\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476 else if (!strcmp(ident, "rewrite")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 parse_err(SYNERR, "Operands do not specify a rewrite\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 else if (!strcmp(ident, "constraint"))oper->_constraint= constraint_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
480 else if (!strcmp(ident, "construct")) oper->_construct = construct_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
481 else if (!strcmp(ident, "format")) oper->_format = format_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
482 else if (!strcmp(ident, "interface")) oper->_interface = interface_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
483 // Check identifier to see if it is the name of an attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
484 else if (((attr = _globalNames[ident]->is_attribute()) != NULL) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
485 (attr->_atype == OP_ATTR)) oper->_attribs = attr_parse(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
487 parse_err(SYNERR, "expected one of - constraint, predicate, match, encode, format, construct, or the name of a defined operand attribute at %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
490 } while(_curchar != '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
491 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (_curchar != '}') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
493 parse_err(SYNERR, "missing '%%}' in operand definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
494 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // Add operand to tail of operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
497 _AD.addForm(oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 //------------------------------opclass_parse----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // Operand Classes are a block with a comma delimited list of operand names
a61af66fc99e Initial load
duke
parents:
diff changeset
502 void ADLParser::opclass_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
504 OpClassForm *opc;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 OperandForm *opForm;
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 // First get the name of the operand class
a61af66fc99e Initial load
duke
parents:
diff changeset
508 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 if( (ident = get_unique_ident(_globalNames,"opclass")) == NULL )
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 opc = new OpClassForm(ident); // Create new operand class form
a61af66fc99e Initial load
duke
parents:
diff changeset
512 _globalNames.Insert(ident, opc); // Add name to the name table
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (_AD._adl_debug > 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
516 fprintf(stderr,"Parsing Operand Class Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // Get the list of operands
a61af66fc99e Initial load
duke
parents:
diff changeset
519 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
521 parse_err(SYNERR, "missing '(' in operand definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
522 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
524 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 next_char(); // Skip past open paren or comma
a61af66fc99e Initial load
duke
parents:
diff changeset
526 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // Check identifier to see if it is the name of an operand
a61af66fc99e Initial load
duke
parents:
diff changeset
532 const Form *form = _globalNames[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
533 opForm = form ? form->is_operand() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 if ( opForm ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 opc->_oplst.addName(ident); // Add operand to opclass list
a61af66fc99e Initial load
duke
parents:
diff changeset
536 opForm->_classes.addName(opc->_ident);// Add opclass to operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
538 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 parse_err(SYNERR, "expected name of a defined operand at %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541 skipws(); // skip trailing whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
542 } while (_curchar == ','); // Check for the comma
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // Check for closing ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
544 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 parse_err(SYNERR, "missing ')' or ',' in opclass definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
546 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548 next_char(); // Consume the ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
549 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
550 // Check for closing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
551 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
552 parse_err(SYNERR, "missing ';' in opclass definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
553 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555 next_char(); // Consume the ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Add operand to tail of operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
557 _AD.addForm(opc);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 //------------------------------ins_attr_parse---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
561 void ADLParser::ins_attr_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 char *aexpr;
a61af66fc99e Initial load
duke
parents:
diff changeset
564 AttributeForm *attrib;
a61af66fc99e Initial load
duke
parents:
diff changeset
565
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // get name for the instruction attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
567 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
568 if( (ident = get_unique_ident(_globalNames,"inst_attrib")) == NULL )
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
571 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Ins_Attribute Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
572
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // Get default value of the instruction attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
574 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
575 if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
576 parse_err(SYNERR, "missing '(' in ins_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
577 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
578 }
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
580 if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // Check for terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
583 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
584 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
585 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 next_char(); // Advance past the ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // Construct the attribute, record global name, and store in ArchDesc
a61af66fc99e Initial load
duke
parents:
diff changeset
590 attrib = new AttributeForm(ident, INS_ATTR, aexpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 _globalNames.Insert(ident, attrib); // Add name to the name table
a61af66fc99e Initial load
duke
parents:
diff changeset
592 _AD.addForm(attrib);
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 //------------------------------op_attr_parse----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
596 void ADLParser::op_attr_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
597 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 char *aexpr;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 AttributeForm *attrib;
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601 // get name for the operand attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
602 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if( (ident = get_unique_ident(_globalNames,"op_attrib")) == NULL )
a61af66fc99e Initial load
duke
parents:
diff changeset
604 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
606 if (_AD._adl_debug > 1) fprintf(stderr,"Parsing Op_Attribute Form %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
607
a61af66fc99e Initial load
duke
parents:
diff changeset
608 // Get default value of the instruction attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
609 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
610 if ((aexpr = get_paren_expr("attribute default expression string")) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 parse_err(SYNERR, "missing '(' in op_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
612 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
613 }
a61af66fc99e Initial load
duke
parents:
diff changeset
614 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
615 if (_AD._adl_debug > 1) fprintf(stderr,"Attribute Expression: %s\n", aexpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
616
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // Check for terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
618 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 parse_err(SYNERR, "missing ';' in op_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
620 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
621 }
a61af66fc99e Initial load
duke
parents:
diff changeset
622 next_char(); // Advance past the ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // Construct the attribute, record global name, and store in ArchDesc
a61af66fc99e Initial load
duke
parents:
diff changeset
625 attrib = new AttributeForm(ident, OP_ATTR, aexpr);
a61af66fc99e Initial load
duke
parents:
diff changeset
626 _globalNames.Insert(ident, attrib);
a61af66fc99e Initial load
duke
parents:
diff changeset
627 _AD.addForm(attrib);
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 //------------------------------definitions_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
631 void ADLParser::definitions_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
633 if (_curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
634 next_char(); next_char(); // Skip "%{"
a61af66fc99e Initial load
duke
parents:
diff changeset
635 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
636 while (_curchar != '%' && *(_ptr+1) != '}') {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 // Process each definition until finding closing string "%}"
a61af66fc99e Initial load
duke
parents:
diff changeset
638 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
639 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 parse_err(SYNERR, "missing identifier inside definitions block.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
641 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643 if (strcmp(token,"int_def")==0) { int_def_parse(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
644 // if (strcmp(token,"str_def")==0) { str_def_parse(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
645 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
646 }
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 parse_err(SYNERR, "Missing %%{ ... %%} block after definitions keyword.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
650 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
653
a61af66fc99e Initial load
duke
parents:
diff changeset
654 //------------------------------int_def_parse----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
655 // Parse Example:
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // int_def MEMORY_REF_COST ( 200, DEFAULT_COST * 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // <keyword> <name> ( <int_value>, <description> );
a61af66fc99e Initial load
duke
parents:
diff changeset
658 //
a61af66fc99e Initial load
duke
parents:
diff changeset
659 void ADLParser::int_def_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 char *name = NULL; // Name of definition
a61af66fc99e Initial load
duke
parents:
diff changeset
661 char *value = NULL; // its value,
a61af66fc99e Initial load
duke
parents:
diff changeset
662 int int_value = -1; // positive values only
a61af66fc99e Initial load
duke
parents:
diff changeset
663 char *description = NULL; // textual description
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 // Get definition name
a61af66fc99e Initial load
duke
parents:
diff changeset
666 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
667 name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
668 if (name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 parse_err(SYNERR, "missing definition name after int_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
670 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
671 }
a61af66fc99e Initial load
duke
parents:
diff changeset
672
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // Check for value of int_def dname( integer_value [, string_expression ] )
a61af66fc99e Initial load
duke
parents:
diff changeset
674 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
675 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
676
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // Parse the integer value.
a61af66fc99e Initial load
duke
parents:
diff changeset
678 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
679 value = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
680 if (value == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 parse_err(SYNERR, "missing value in int_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
684 if( !is_int_token(value, int_value) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 parse_err(SYNERR, "value in int_def is not recognized as integer\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
686 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // Check for description
a61af66fc99e Initial load
duke
parents:
diff changeset
691 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
692 next_char(); // skip ','
a61af66fc99e Initial load
duke
parents:
diff changeset
693
a61af66fc99e Initial load
duke
parents:
diff changeset
694 description = get_expr("int_def description", ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
695 if (description == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
696 parse_err(SYNERR, "invalid or missing description in int_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
697 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699 trim(description);
a61af66fc99e Initial load
duke
parents:
diff changeset
700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
701
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 parse_err(SYNERR, "missing ')' in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
704 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 // Check for closing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
710 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
711 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
712 parse_err(SYNERR, "missing ';' after int_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
713 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715 next_char(); // move past ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
716
a61af66fc99e Initial load
duke
parents:
diff changeset
717 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
718 if (_AD._adl_debug > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 fprintf(stderr,"int_def: %s ( %s, %s )\n", name,
a61af66fc99e Initial load
duke
parents:
diff changeset
720 (value), (description ? description : ""));
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 // Record new definition.
a61af66fc99e Initial load
duke
parents:
diff changeset
724 Expr *expr = new Expr(name, description, int_value, int_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
725 const Expr *old_expr = _AD.globalDefs().define(name, expr);
a61af66fc99e Initial load
duke
parents:
diff changeset
726 if (old_expr != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
727 parse_err(SYNERR, "Duplicate definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
728 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
730
a61af66fc99e Initial load
duke
parents:
diff changeset
731 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734
a61af66fc99e Initial load
duke
parents:
diff changeset
735 //------------------------------source_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
736 void ADLParser::source_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 SourceForm *source; // Encode class for instruction/operand
a61af66fc99e Initial load
duke
parents:
diff changeset
738 char *rule = NULL; // String representation of encode rule
a61af66fc99e Initial load
duke
parents:
diff changeset
739
a61af66fc99e Initial load
duke
parents:
diff changeset
740 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
741 if ( (rule = find_cpp_block("source block")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 parse_err(SYNERR, "incorrect or missing block for 'source'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
743 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
746 if (_AD._adl_debug > 1) fprintf(stderr,"Source Form: %s\n", rule);
a61af66fc99e Initial load
duke
parents:
diff changeset
747
a61af66fc99e Initial load
duke
parents:
diff changeset
748 source = new SourceForm(rule); // Build new Source object
a61af66fc99e Initial load
duke
parents:
diff changeset
749 _AD.addForm(source);
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752
a61af66fc99e Initial load
duke
parents:
diff changeset
753 //------------------------------source_hpp_parse-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
754 // Parse a source_hpp %{ ... %} block.
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // The code gets stuck into the ad_<arch>.hpp file.
a61af66fc99e Initial load
duke
parents:
diff changeset
756 // If the source_hpp block appears before the register block in the AD
a61af66fc99e Initial load
duke
parents:
diff changeset
757 // file, it goes up at the very top of the ad_<arch>.hpp file, so that
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // it can be used by register encodings, etc. Otherwise, it goes towards
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // the bottom, where it's useful as a global definition to *.cpp files.
a61af66fc99e Initial load
duke
parents:
diff changeset
760 void ADLParser::source_hpp_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 char *rule = NULL; // String representation of encode rule
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
764 if ( (rule = find_cpp_block("source_hpp block")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
765 parse_err(SYNERR, "incorrect or missing block for 'source_hpp'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
766 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
768 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
769 if (_AD._adl_debug > 1) fprintf(stderr,"Header Form: %s\n", rule);
a61af66fc99e Initial load
duke
parents:
diff changeset
770
a61af66fc99e Initial load
duke
parents:
diff changeset
771 if (_AD.get_registers() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // Very early in the file, before reg_defs, we collect pre-headers.
a61af66fc99e Initial load
duke
parents:
diff changeset
773 PreHeaderForm* pre_header = new PreHeaderForm(rule);
a61af66fc99e Initial load
duke
parents:
diff changeset
774 _AD.addForm(pre_header);
a61af66fc99e Initial load
duke
parents:
diff changeset
775 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 // Normally, we collect header info, placed at the bottom of the hpp file.
a61af66fc99e Initial load
duke
parents:
diff changeset
777 HeaderForm* header = new HeaderForm(rule);
a61af66fc99e Initial load
duke
parents:
diff changeset
778 _AD.addForm(header);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 //------------------------------reg_parse--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
783 void ADLParser::reg_parse(void) {
6179
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
784 RegisterForm *regBlock = _AD.get_registers(); // Information about registers encoding
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
785 if (regBlock == NULL) {
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
786 // Create the RegisterForm for the architecture description.
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
787 regBlock = new RegisterForm(); // Build new Source object
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
788 _AD.addForm(regBlock);
8c92982cbbc4 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 4121
diff changeset
789 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
790
a61af66fc99e Initial load
duke
parents:
diff changeset
791 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
792 if (_curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 next_char(); next_char(); // Skip "%{"
a61af66fc99e Initial load
duke
parents:
diff changeset
794 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
795 while (_curchar != '%' && *(_ptr+1) != '}') {
a61af66fc99e Initial load
duke
parents:
diff changeset
796 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
797 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
798 parse_err(SYNERR, "missing identifier inside register block.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
799 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 }
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
801 if (strcmp(token,"reg_def")==0) { reg_def_parse(); }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
802 else if (strcmp(token,"reg_class")==0) { reg_class_parse(); }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
803 else if (strcmp(token,"alloc_class")==0) { alloc_class_parse(); }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
804 else if (strcmp(token,"#define")==0) { preproc_define(); }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
805 else { parse_err(SYNERR, "bad token %s inside register block.\n", token); break; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
806 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
809 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 parse_err(SYNERR, "Missing %c{ ... %c} block after register keyword.\n",'%','%');
a61af66fc99e Initial load
duke
parents:
diff changeset
811 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
812 }
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814
a61af66fc99e Initial load
duke
parents:
diff changeset
815 //------------------------------encode_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
816 void ADLParser::encode_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 EncodeForm *encBlock; // Information about instruction/operand encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
818
a61af66fc99e Initial load
duke
parents:
diff changeset
819 _AD.getForm(&encBlock);
a61af66fc99e Initial load
duke
parents:
diff changeset
820 if ( encBlock == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // Create the EncodeForm for the architecture description.
a61af66fc99e Initial load
duke
parents:
diff changeset
822 encBlock = new EncodeForm(); // Build new Source object
a61af66fc99e Initial load
duke
parents:
diff changeset
823 _AD.addForm(encBlock);
a61af66fc99e Initial load
duke
parents:
diff changeset
824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
825
a61af66fc99e Initial load
duke
parents:
diff changeset
826 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
827 if (_curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 next_char(); next_char(); // Skip "%{"
a61af66fc99e Initial load
duke
parents:
diff changeset
829 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
830 while (_curchar != '%' && *(_ptr+1) != '}') {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
832 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 parse_err(SYNERR, "missing identifier inside encoding block.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
834 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
835 }
a61af66fc99e Initial load
duke
parents:
diff changeset
836 if (strcmp(token,"enc_class")==0) { enc_class_parse(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
837 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
840 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
841 parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
a61af66fc99e Initial load
duke
parents:
diff changeset
842 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
844 }
a61af66fc99e Initial load
duke
parents:
diff changeset
845
a61af66fc99e Initial load
duke
parents:
diff changeset
846 //------------------------------enc_class_parse--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
847 void ADLParser::enc_class_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 char *ec_name; // Name of encoding class being defined
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 // Get encoding class name
a61af66fc99e Initial load
duke
parents:
diff changeset
851 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
852 ec_name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (ec_name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 parse_err(SYNERR, "missing encoding class name after encode.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
855 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858 EncClass *encoding = _AD._encode->add_EncClass(ec_name);
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
859 encoding->_linenum = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
860
a61af66fc99e Initial load
duke
parents:
diff changeset
861 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
862 // Check for optional parameter list
a61af66fc99e Initial load
duke
parents:
diff changeset
863 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
864 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
865 char *pType = NULL; // parameter type
a61af66fc99e Initial load
duke
parents:
diff changeset
866 char *pName = NULL; // parameter name
a61af66fc99e Initial load
duke
parents:
diff changeset
867
a61af66fc99e Initial load
duke
parents:
diff changeset
868 next_char(); // skip open paren & comma characters
a61af66fc99e Initial load
duke
parents:
diff changeset
869 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
870 if (_curchar == ')') break;
a61af66fc99e Initial load
duke
parents:
diff changeset
871
a61af66fc99e Initial load
duke
parents:
diff changeset
872 // Get parameter type
a61af66fc99e Initial load
duke
parents:
diff changeset
873 pType = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
874 if (pType == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 parse_err(SYNERR, "parameter type expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878
a61af66fc99e Initial load
duke
parents:
diff changeset
879 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
880 // Get parameter name
a61af66fc99e Initial load
duke
parents:
diff changeset
881 pName = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
882 if (pName == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
883 parse_err(SYNERR, "parameter name expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
884 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 }
a61af66fc99e Initial load
duke
parents:
diff changeset
886
a61af66fc99e Initial load
duke
parents:
diff changeset
887 // Record parameter type and name
a61af66fc99e Initial load
duke
parents:
diff changeset
888 encoding->add_parameter( pType, pName );
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
891 } while(_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
892
a61af66fc99e Initial load
duke
parents:
diff changeset
893 if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
894 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
895 next_char(); // Skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
896 }
a61af66fc99e Initial load
duke
parents:
diff changeset
897 } // Done with parameter list
a61af66fc99e Initial load
duke
parents:
diff changeset
898
a61af66fc99e Initial load
duke
parents:
diff changeset
899 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
900 // Check for block starting delimiters
a61af66fc99e Initial load
duke
parents:
diff changeset
901 if ((_curchar != '%') || (*(_ptr+1) != '{')) { // If not open block
a61af66fc99e Initial load
duke
parents:
diff changeset
902 parse_err(SYNERR, "missing '%c{' in enc_class definition\n", '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
903 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
905 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
906 next_char(); // Skip '{'
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 enc_class_parse_block(encoding, ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 void ADLParser::enc_class_parse_block(EncClass* encoding, char* ec_name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 skipws_no_preproc(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
a61af66fc99e Initial load
duke
parents:
diff changeset
915 if (_AD._adlocation_debug) {
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
916 encoding->add_code(get_line_string());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
917 }
a61af66fc99e Initial load
duke
parents:
diff changeset
918
a61af66fc99e Initial load
duke
parents:
diff changeset
919 // Collect the parts of the encode description
a61af66fc99e Initial load
duke
parents:
diff changeset
920 // (1) strings that are passed through to output
a61af66fc99e Initial load
duke
parents:
diff changeset
921 // (2) replacement/substitution variable, preceeded by a '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
922 while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 // (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
925 // Check if there is a string to pass through to output
a61af66fc99e Initial load
duke
parents:
diff changeset
926 char *start = _ptr; // Record start of the next string
a61af66fc99e Initial load
duke
parents:
diff changeset
927 while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
928 // If at the start of a comment, skip past it
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
931 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 // ELSE advance to the next character, or start of the next line
a61af66fc99e Initial load
duke
parents:
diff changeset
933 next_char_or_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // If a string was found, terminate it and record in EncClass
a61af66fc99e Initial load
duke
parents:
diff changeset
937 if ( start != _ptr ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
938 *_ptr = '\0'; // Terminate the string
a61af66fc99e Initial load
duke
parents:
diff changeset
939 encoding->add_code(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941
a61af66fc99e Initial load
duke
parents:
diff changeset
942 // (2)
a61af66fc99e Initial load
duke
parents:
diff changeset
943 // If we are at a replacement variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
944 // copy it and record in EncClass
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
945 if (_curchar == '$') {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
946 // Found replacement Variable
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
947 char* rep_var = get_rep_var_ident_dup();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
948 // Add flag to _strings list indicating we should check _rep_vars
a61af66fc99e Initial load
duke
parents:
diff changeset
949 encoding->add_rep_var(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
950 }
a61af66fc99e Initial load
duke
parents:
diff changeset
951 } // end while part of format description
a61af66fc99e Initial load
duke
parents:
diff changeset
952 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
953 next_char(); // Skip '}'
a61af66fc99e Initial load
duke
parents:
diff changeset
954
a61af66fc99e Initial load
duke
parents:
diff changeset
955 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
956
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
957 if (_AD._adlocation_debug) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
958 encoding->add_code(end_line_marker());
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
959 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
960
0
a61af66fc99e Initial load
duke
parents:
diff changeset
961 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
962 if (_AD._adl_debug > 1) fprintf(stderr,"EncodingClass Form: %s\n", ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
963 }
a61af66fc99e Initial load
duke
parents:
diff changeset
964
a61af66fc99e Initial load
duke
parents:
diff changeset
965 //------------------------------frame_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
966 void ADLParser::frame_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
967 FrameForm *frame; // Information about stack-frame layout
a61af66fc99e Initial load
duke
parents:
diff changeset
968 char *desc = NULL; // String representation of frame
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 frame = new FrameForm(); // Build new Frame object
a61af66fc99e Initial load
duke
parents:
diff changeset
973 // Check for open block sequence
a61af66fc99e Initial load
duke
parents:
diff changeset
974 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
975 if (_curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
976 next_char(); next_char(); // Skip "%{"
a61af66fc99e Initial load
duke
parents:
diff changeset
977 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
978 while (_curchar != '%' && *(_ptr+1) != '}') {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
980 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 parse_err(SYNERR, "missing identifier inside frame block.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
982 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
983 }
a61af66fc99e Initial load
duke
parents:
diff changeset
984 if (strcmp(token,"stack_direction")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 stack_dir_parse(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
986 }
a61af66fc99e Initial load
duke
parents:
diff changeset
987 if (strcmp(token,"sync_stack_slots")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
988 sync_stack_slots_parse(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
989 }
a61af66fc99e Initial load
duke
parents:
diff changeset
990 if (strcmp(token,"frame_pointer")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
991 frame_pointer_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
993 if (strcmp(token,"interpreter_frame_pointer")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
994 interpreter_frame_pointer_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
995 }
a61af66fc99e Initial load
duke
parents:
diff changeset
996 if (strcmp(token,"inline_cache_reg")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
997 inline_cache_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
998 }
a61af66fc99e Initial load
duke
parents:
diff changeset
999 if (strcmp(token,"compiler_method_oop_reg")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 parse_err(WARN, "Using obsolete Token, compiler_method_oop_reg");
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 if (strcmp(token,"interpreter_method_oop_reg")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 interpreter_method_oop_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 if (strcmp(token,"cisc_spilling_operand_name")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 cisc_spilling_operand_name_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 if (strcmp(token,"stack_alignment")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 stack_alignment_parse(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 if (strcmp(token,"return_addr")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 return_addr_parse(frame, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 if (strcmp(token,"in_preserve_stack_slots")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 preserve_stack_parse(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 if (strcmp(token,"out_preserve_stack_slots")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 parse_err(WARN, "Using obsolete token, out_preserve_stack_slots");
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (strcmp(token,"varargs_C_out_slots_killed")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 frame->_varargs_C_out_slots_killed = parse_one_arg("varargs C out slots killed");
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 if (strcmp(token,"calling_convention")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 frame->_calling_convention = calling_convention_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 if (strcmp(token,"return_value")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 frame->_return_value = return_value_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 if (strcmp(token,"c_frame_pointer")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 frame_pointer_parse(frame, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 if (strcmp(token,"c_return_addr")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 return_addr_parse(frame, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 if (strcmp(token,"c_calling_convention")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 frame->_c_calling_convention = calling_convention_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 if (strcmp(token,"c_return_value")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 frame->_c_return_value = return_value_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1043
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 parse_err(SYNERR, "Missing %c{ ... %c} block after encode keyword.\n",'%','%');
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 // All Java versions are required, native versions are optional
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 if(frame->_frame_pointer == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 parse_err(SYNERR, "missing frame pointer definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 // !!!!! !!!!!
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 // if(frame->_interpreter_frame_ptr_reg == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // parse_err(SYNERR, "missing interpreter frame pointer definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 // return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 if(frame->_alignment == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 parse_err(SYNERR, "missing alignment definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 if(frame->_return_addr == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 parse_err(SYNERR, "missing return address location in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 if(frame->_in_preserve_slots == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 parse_err(SYNERR, "missing stack slot preservation definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 if(frame->_varargs_C_out_slots_killed == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 parse_err(SYNERR, "missing varargs C out slots killed definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 if(frame->_calling_convention == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 parse_err(SYNERR, "missing calling convention definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 if(frame->_return_value == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 parse_err(SYNERR, "missing return value definition in frame section.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 // Fill natives in identically with the Java versions if not present.
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 if(frame->_c_frame_pointer == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 frame->_c_frame_pointer = frame->_frame_pointer;
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 if(frame->_c_return_addr == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 frame->_c_return_addr = frame->_return_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 frame->_c_return_addr_loc = frame->_return_addr_loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 if(frame->_c_calling_convention == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 frame->_c_calling_convention = frame->_calling_convention;
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 if(frame->_c_return_value == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 frame->_c_return_value = frame->_return_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1099
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 if (_AD._adl_debug > 1) fprintf(stderr,"Frame Form: %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 // Create the EncodeForm for the architecture description.
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 _AD.addForm(frame);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 // skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1107
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 //------------------------------stack_dir_parse--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 void ADLParser::stack_dir_parse(FrameForm *frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 char *direction = parse_one_arg("stack direction entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 if (strcmp(direction, "TOWARDS_LOW") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 frame->_direction = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 else if (strcmp(direction, "TOWARDS_HIGH") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 frame->_direction = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 parse_err(SYNERR, "invalid value inside stack direction entry.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1122
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 //------------------------------sync_stack_slots_parse-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 void ADLParser::sync_stack_slots_parse(FrameForm *frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 // Assign value into frame form
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 frame->_sync_stack_slots = parse_one_arg("sync stack slots entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 //------------------------------frame_pointer_parse----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 void ADLParser::frame_pointer_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 char *frame_pointer = parse_one_arg("frame pointer entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 // Assign value into frame form
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 if (native) { frame->_c_frame_pointer = frame_pointer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 else { frame->_frame_pointer = frame_pointer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1136
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 //------------------------------interpreter_frame_pointer_parse----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 void ADLParser::interpreter_frame_pointer_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 frame->_interpreter_frame_pointer_reg = parse_one_arg("interpreter frame pointer entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1141
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 //------------------------------inline_cache_parse-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 void ADLParser::inline_cache_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 frame->_inline_cache_reg = parse_one_arg("inline cache reg entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1146
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 //------------------------------interpreter_method_oop_parse------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 void ADLParser::interpreter_method_oop_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 frame->_interpreter_method_oop_reg = parse_one_arg("method oop reg entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 //------------------------------cisc_spilling_operand_parse---------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 void ADLParser::cisc_spilling_operand_name_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 frame->_cisc_spilling_operand_name = parse_one_arg("cisc spilling operand name");
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1156
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 //------------------------------stack_alignment_parse--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 void ADLParser::stack_alignment_parse(FrameForm *frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 char *alignment = parse_one_arg("stack alignment entry");
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 // Assign value into frame
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 frame->_alignment = alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 //------------------------------parse_one_arg-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 char *ADLParser::parse_one_arg(const char *description) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 char *token = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 if(_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 token = get_expr(description, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 parse_err(SYNERR, "missing value inside %s.\n", description);
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 next_char(); // skip the close paren
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 if(_curchar != ';') { // check for semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 parse_err(SYNERR, "missing %c in.\n", ';', description);
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 next_char(); // skip the semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 parse_err(SYNERR, "Missing %c in.\n", '(', description);
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1186
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 trim(token);
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 return token;
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1190
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 //------------------------------return_addr_parse------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 void ADLParser::return_addr_parse(FrameForm *frame, bool native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 bool in_register = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 if(_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 parse_err(SYNERR, "missing value inside return address entry.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 // check for valid values for stack/register
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 if (strcmp(token, "REG") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 in_register = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 else if (strcmp(token, "STACK") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 in_register = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 parse_err(SYNERR, "invalid value inside return_address entry.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 if (native) { frame->_c_return_addr_loc = in_register; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 else { frame->_return_addr_loc = in_register; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1215
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 // Parse expression that specifies register or stack position
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 char *token2 = get_expr("return address entry", ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 if (token2 == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 parse_err(SYNERR, "missing value inside return address entry.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 next_char(); // skip the close paren
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 if (native) { frame->_c_return_addr = token2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 else { frame->_return_addr = token2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1226
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 if(_curchar != ';') { // check for semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 parse_err(SYNERR, "missing %c in return address entry.\n", ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 next_char(); // skip the semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 parse_err(SYNERR, "Missing %c in return_address entry.\n", '(');
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1237
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 //------------------------------preserve_stack_parse---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 void ADLParser::preserve_stack_parse(FrameForm *frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 if(_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 char *token = get_paren_expr("preserve_stack_slots");
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 frame->_in_preserve_slots = token;
a61af66fc99e Initial load
duke
parents:
diff changeset
1243
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 if(_curchar != ';') { // check for semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 parse_err(SYNERR, "missing %c in preserve stack slot entry.\n", ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 next_char(); // skip the semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 parse_err(SYNERR, "Missing %c in preserve stack slot entry.\n", '(');
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1254
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 //------------------------------calling_convention_parse-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 char *ADLParser::calling_convention_parse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 char *desc = NULL; // String representation of calling_convention
a61af66fc99e Initial load
duke
parents:
diff changeset
1258
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 if ( (desc = find_cpp_block("calling convention block")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 parse_err(SYNERR, "incorrect or missing block for 'calling_convention'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 return desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1265
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 //------------------------------return_value_parse-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 char *ADLParser::return_value_parse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 char *desc = NULL; // String representation of calling_convention
a61af66fc99e Initial load
duke
parents:
diff changeset
1269
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 if ( (desc = find_cpp_block("return value block")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 parse_err(SYNERR, "incorrect or missing block for 'return_value'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 return desc;
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1276
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 //------------------------------ins_pipe_parse---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 void ADLParser::ins_pipe_parse(InstructForm &instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 char * ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1280
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 if ( _curchar != '(' ) { // Check for delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 parse_err(SYNERR, "missing \"(\" in ins_pipe definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1286
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1289
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1294
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 if ( _curchar != ')' ) { // Check for delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 parse_err(SYNERR, "missing \")\" in ins_pipe definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1300
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 next_char(); // skip the close paren
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 if(_curchar != ';') { // check for semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 parse_err(SYNERR, "missing %c in return value entry.\n", ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 next_char(); // skip the semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1307
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 // Check ident for validity
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 if (_AD._pipeline && !_AD._pipeline->_classlist.search(ident)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1313
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 // Add this instruction to the list in the pipeline class
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 _AD._pipeline->_classdict[ident]->is_pipeclass()->_instructs.addName(instr._ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1316
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 // Set the name of the pipeline class in the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 instr._ins_pipe = ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1321
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 //------------------------------pipe_parse-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 void ADLParser::pipe_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 PipelineForm *pipeline; // Encode class for instruction/operand
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 char * ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1326
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 pipeline = new PipelineForm(); // Build new Source object
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 _AD.addForm(pipeline);
a61af66fc99e Initial load
duke
parents:
diff changeset
1329
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 // Check for block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 || ( next_char(), (_curchar != '{')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1334 parse_err(SYNERR, "missing '%%{' in pipeline definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 next_char(); // Maintain the invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 parse_err(SYNERR, "keyword identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 if (!strcmp(ident, "resources" )) resource_parse(*pipeline);
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 else if (!strcmp(ident, "pipe_desc" )) pipe_desc_parse(*pipeline);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 else if (!strcmp(ident, "pipe_class")) pipe_class_parse(*pipeline);
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 else if (!strcmp(ident, "define")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 || ( next_char(), (_curchar != '{')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1351 parse_err(SYNERR, "expected '%%{'\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1355
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 char *node_class = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 if (node_class == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1361
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 if (_curchar != ',' && _curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1368
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 char *pipe_class = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 if (pipe_class == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 parse_err(SYNERR, "expected identifier, found \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 if (_curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 parse_err(SYNERR, "expected `;`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 next_char(); // Skip over semi-colon
a61af66fc99e Initial load
duke
parents:
diff changeset
1379
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 || ( next_char(), (_curchar != '}')) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 parse_err(SYNERR, "expected '%%}', found \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1386
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 // Check ident for validity
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 if (_AD._pipeline && !_AD._pipeline->_classlist.search(pipe_class)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 parse_err(SYNERR, "\"%s\" is not a valid pipeline class\n", pipe_class);
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1392
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 // Add this machine node to the list in the pipeline class
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 _AD._pipeline->_classdict[pipe_class]->is_pipeclass()->_instructs.addName(node_class);
a61af66fc99e Initial load
duke
parents:
diff changeset
1395
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 MachNodeForm *machnode = new MachNodeForm(node_class); // Create new machnode form
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 machnode->_machnode_pipe = pipe_class;
a61af66fc99e Initial load
duke
parents:
diff changeset
1398
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 _AD.addForm(machnode);
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 else if (!strcmp(ident, "attributes")) {
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1402 bool vsi_seen = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1403
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 || ( next_char(), (_curchar != '{')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1407 parse_err(SYNERR, "expected '%%{'\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1411
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 while (_curchar != '%') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 if (ident == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1416
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 if (!strcmp(ident, "variable_size_instructions")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1422
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 pipeline->_variableSizeInstrs = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 vsi_seen = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1427
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 if (!strcmp(ident, "fixed_size_instructions")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1433
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 pipeline->_variableSizeInstrs = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 vsi_seen = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1438
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 if (!strcmp(ident, "branch_has_delay_slot")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1444
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 pipeline->_branchHasDelaySlot = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1448
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 if (!strcmp(ident, "max_instructions_per_bundle")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 parse_err(SYNERR, "expected `=`\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1455
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 pipeline->_maxInstrsPerBundle = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1459
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1463
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1466
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 if (!strcmp(ident, "max_bundles_per_cycle")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 parse_err(SYNERR, "expected `=`\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1473
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 pipeline->_maxBundlesPerCycle = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1477
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1481
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1484
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 if (!strcmp(ident, "instruction_unit_size")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1491
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 pipeline->_instrUnitSize = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1495
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1499
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1502
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 if (!strcmp(ident, "bundle_unit_size")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1509
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 pipeline->_bundleUnitSize = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1513
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1517
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1520
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 if (!strcmp(ident, "instruction_fetch_unit_size")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1527
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 pipeline->_instrFetchUnitSize = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1531
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1535
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1538
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 if (!strcmp(ident, "instruction_fetch_units")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 parse_err(SYNERR, "expected `=`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1545
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 pipeline->_instrFetchUnits = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1549
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1553
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1556
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 if (!strcmp(ident, "nops")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 parse_err(SYNERR, "expected `(`, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1563
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1565
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 while (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 parse_err(SYNERR, "expected identifier for nop instruction, found '%c'\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1572
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 pipeline->_noplist.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 pipeline->_nopcnt++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1576
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1581
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1583
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 if (_curchar == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1587
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1590
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 parse_err(SYNERR, "unknown specifier \"%s\"\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1593
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 || ( next_char(), (_curchar != '}')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1596 parse_err(SYNERR, "expected '%%}', found \"%c\"\n", _curchar);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1599
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 if (pipeline->_maxInstrsPerBundle == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 parse_err(SYNERR, "\"max_instructions_per_bundle\" unspecified\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 if (pipeline->_instrUnitSize == 0 && pipeline->_bundleUnitSize == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 parse_err(SYNERR, "\"instruction_unit_size\" and \"bundle_unit_size\" unspecified\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 if (pipeline->_instrFetchUnitSize == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 parse_err(SYNERR, "\"instruction_fetch_unit_size\" unspecified\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 if (pipeline->_instrFetchUnits == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 parse_err(SYNERR, "\"instruction_fetch_units\" unspecified\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 if (!vsi_seen)
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 parse_err(SYNERR, "\"variable_size_instruction\" or \"fixed_size_instruction\" unspecified\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 else { // Done with staticly defined parts of instruction definition
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 parse_err(SYNERR, "expected one of \"resources\", \"pipe_desc\", \"pipe_class\", found \"%s\"\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 if (_curchar == ';')
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 } while(_curchar != '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
1619
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 if (_curchar != '}') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1622 parse_err(SYNERR, "missing \"%%}\" in pipeline definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1625
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1628
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 //------------------------------resource_parse----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 void ADLParser::resource_parse(PipelineForm &pipeline) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 ResourceForm *resource;
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 char * ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 char * expr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 unsigned mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 pipeline._rescount = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1636
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1638
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 parse_err(SYNERR, "missing \"(\" in resource definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1643
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 next_char(); // Skip "(" or ","
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1647
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1648 if (_AD._adl_debug > 1) {
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1649 if (ident != NULL) {
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1650 fprintf(stderr, "resource_parse: identifier: %s\n", ident);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1651 }
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1652 }
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
1653
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1659
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 if (_curchar != '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 mask = (1 << pipeline._rescount++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1664 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 expr = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 if (expr == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 resource = (ResourceForm *) pipeline._resdict[expr];
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 if (resource == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 mask = resource->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
1676
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 while (_curchar == '|') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1680
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 expr = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 if (expr == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1686
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 resource = (ResourceForm *) pipeline._resdict[expr]; // Look up the value
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 if (resource == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 parse_err(SYNERR, "resource \"%s\" is not defined\n", expr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1692
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 mask |= resource->mask();
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1697
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 resource = new ResourceForm(mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1699
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 pipeline._resdict.Insert(ident, resource);
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 pipeline._reslist.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 } while (_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
1703
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1708
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 next_char(); // Skip ")"
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 if (_curchar == ';')
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 next_char(); // Skip ";"
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1713
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 //------------------------------resource_parse----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 void ADLParser::pipe_desc_parse(PipelineForm &pipeline) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 char * ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1717
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1719
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 parse_err(SYNERR, "missing \"(\" in pipe_desc definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1724
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 next_char(); // Skip "(" or ","
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1732
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 // Add the name to the list
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 pipeline._stages.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 pipeline._stagecnt++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1736
a61af66fc99e Initial load
duke
parents:
diff changeset
1737 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 } while (_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
1739
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1744
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 next_char(); // Skip ")"
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 if (_curchar == ';')
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 next_char(); // Skip ";"
a61af66fc99e Initial load
duke
parents:
diff changeset
1748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1749
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 //------------------------------pipe_class_parse--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1751 void ADLParser::pipe_class_parse(PipelineForm &pipeline) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 PipeClassForm *pipe_class;
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 char * ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 char * stage;
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 char * read_or_write;
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 int is_write;
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 int is_read;
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 OperandForm *oper;
a61af66fc99e Initial load
duke
parents:
diff changeset
1759
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1761
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1763
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1768
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 // Create a record for the pipe_class
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 pipe_class = new PipeClassForm(ident, ++pipeline._classcnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 pipeline._classdict.Insert(ident, pipe_class);
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 pipeline._classlist.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1773
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 // Then get the operands
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 parse_err(SYNERR, "missing \"(\" in pipe_class definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 // Parse the operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 else get_oplist(pipe_class->_parameters, pipe_class->_localNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 // Check for block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 if ( (_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 || ( next_char(), (_curchar != '{')) ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
1785 parse_err(SYNERR, "missing \"%%{\" in pipe_class definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1786 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1789
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 parse_err(SYNERR, "keyword identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1797
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 if (!strcmp(ident, "fixed_latency")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 parse_err(SYNERR, "missing \"(\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 if( !isdigit(_curchar) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 parse_err(SYNERR, "number expected for \"%c\" in latency definition\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 int fixed_latency = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1811 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 parse_err(SYNERR, "missing \")\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 parse_err(SYNERR, "missing \";\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1820
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 pipe_class->setFixedLatency(fixed_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1825
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 if (!strcmp(ident, "zero_instructions") ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 !strcmp(ident, "no_instructions")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1830 parse_err(SYNERR, "missing \";\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1833
a61af66fc99e Initial load
duke
parents:
diff changeset
1834 pipe_class->setInstructionCount(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1835 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1838
a61af66fc99e Initial load
duke
parents:
diff changeset
1839 if (!strcmp(ident, "one_instruction_with_delay_slot") ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 !strcmp(ident, "single_instruction_with_delay_slot")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1841 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1842 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1843 parse_err(SYNERR, "missing \";\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1844 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1846
a61af66fc99e Initial load
duke
parents:
diff changeset
1847 pipe_class->setInstructionCount(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1848 pipe_class->setBranchDelay(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1849 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1850 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1852
a61af66fc99e Initial load
duke
parents:
diff changeset
1853 if (!strcmp(ident, "one_instruction") ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1854 !strcmp(ident, "single_instruction")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1855 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1856 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1857 parse_err(SYNERR, "missing \";\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1858 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1860
a61af66fc99e Initial load
duke
parents:
diff changeset
1861 pipe_class->setInstructionCount(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1862 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1863 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1865
a61af66fc99e Initial load
duke
parents:
diff changeset
1866 if (!strcmp(ident, "instructions_in_first_bundle") ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1867 !strcmp(ident, "instruction_count")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1868 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1869
a61af66fc99e Initial load
duke
parents:
diff changeset
1870 int number_of_instructions = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1871
a61af66fc99e Initial load
duke
parents:
diff changeset
1872 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1873 parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1876
a61af66fc99e Initial load
duke
parents:
diff changeset
1877 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1878 number_of_instructions = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1879
a61af66fc99e Initial load
duke
parents:
diff changeset
1880 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1885
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1887 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 parse_err(SYNERR, "missing \";\" in latency definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1890 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1891
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 pipe_class->setInstructionCount(number_of_instructions);
a61af66fc99e Initial load
duke
parents:
diff changeset
1893 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1896
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 if (!strcmp(ident, "multiple_bundles")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 parse_err(SYNERR, "missing \";\" after multiple bundles\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1901 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1903
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 pipe_class->setMultipleBundles(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1906 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1908
a61af66fc99e Initial load
duke
parents:
diff changeset
1909 if (!strcmp(ident, "has_delay_slot")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1910 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1911 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1912 parse_err(SYNERR, "missing \";\" after \"has_delay_slot\"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1913 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1915
a61af66fc99e Initial load
duke
parents:
diff changeset
1916 pipe_class->setBranchDelay(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1917 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1918 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1920
a61af66fc99e Initial load
duke
parents:
diff changeset
1921 if (!strcmp(ident, "force_serialization")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1922 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1923 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1924 parse_err(SYNERR, "missing \";\" after \"force_serialization\"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1925 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1927
a61af66fc99e Initial load
duke
parents:
diff changeset
1928 pipe_class->setForceSerialization(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1929 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1930 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1931 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1932
a61af66fc99e Initial load
duke
parents:
diff changeset
1933 if (!strcmp(ident, "may_have_no_code")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1934 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1935 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1936 parse_err(SYNERR, "missing \";\" after \"may_have_no_code\"\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1937 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1939
a61af66fc99e Initial load
duke
parents:
diff changeset
1940 pipe_class->setMayHaveNoCode(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1941 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1942 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1944
a61af66fc99e Initial load
duke
parents:
diff changeset
1945 const Form *parm = pipe_class->_localNames[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
1946 if (parm != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 oper = parm->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
1948 if (oper == NULL && !parm->is_opclass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1949 parse_err(SYNERR, "operand name expected at %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
1950 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1952
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 if (_curchar != ':') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1954 parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1955 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1956 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 stage = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 if (stage == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1960 parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1961 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1963
a61af66fc99e Initial load
duke
parents:
diff changeset
1964 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1965 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1966 parse_err(SYNERR, "\"(\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1967 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1969
a61af66fc99e Initial load
duke
parents:
diff changeset
1970 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
1971 read_or_write = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
1972 if (read_or_write == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1973 parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1976
a61af66fc99e Initial load
duke
parents:
diff changeset
1977 is_read = strcmp(read_or_write, "read") == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 is_write = strcmp(read_or_write, "write") == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1979 if (!is_read && !is_write) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 parse_err(SYNERR, "\"read\" or \"write\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1981 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1983
a61af66fc99e Initial load
duke
parents:
diff changeset
1984 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1986 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1988 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1989
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 int more_instrs = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1992 if (_curchar == '+') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1993 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
1994 if (_curchar < '0' || _curchar > '9') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1995 parse_err(SYNERR, "<number> expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
1996 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 while (_curchar >= '0' && _curchar <= '9') {
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 more_instrs *= 10;
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 more_instrs += _curchar - '0';
a61af66fc99e Initial load
duke
parents:
diff changeset
2001 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2003 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2005
a61af66fc99e Initial load
duke
parents:
diff changeset
2006 PipeClassOperandForm *pipe_operand = new PipeClassOperandForm(stage, is_write, more_instrs);
a61af66fc99e Initial load
duke
parents:
diff changeset
2007 pipe_class->_localUsage.Insert(ident, pipe_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
2008
a61af66fc99e Initial load
duke
parents:
diff changeset
2009 if (_curchar == '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
2010 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2011
a61af66fc99e Initial load
duke
parents:
diff changeset
2012 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2016 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2017 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2019
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 // Scan for Resource Specifier
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 const Form *res = pipeline._resdict[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
2022 if (res != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2023 int cyclecnt = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
2024 if (_curchar != ':') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2025 parse_err(SYNERR, "\":\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2029 stage = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2030 if (stage == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 parse_err(SYNERR, "pipeline stage identifier expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2034
a61af66fc99e Initial load
duke
parents:
diff changeset
2035 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2038 cyclecnt = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
2039
a61af66fc99e Initial load
duke
parents:
diff changeset
2040 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2041 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 parse_err(SYNERR, "\")\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
2043 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2045
a61af66fc99e Initial load
duke
parents:
diff changeset
2046 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2047 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2048
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 PipeClassResourceForm *resource = new PipeClassResourceForm(ident, stage, cyclecnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 int stagenum = pipeline._stages.index(stage);
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 if (pipeline._maxcycleused < (stagenum+cyclecnt))
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 pipeline._maxcycleused = (stagenum+cyclecnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
2053 pipe_class->_resUsage.addForm(resource);
a61af66fc99e Initial load
duke
parents:
diff changeset
2054
a61af66fc99e Initial load
duke
parents:
diff changeset
2055 if (_curchar == '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2057
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 parse_err(SYNERR, "\";\" expected at \"%c\"\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
2060 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2062 next_char(); skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2063 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
2064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2065
a61af66fc99e Initial load
duke
parents:
diff changeset
2066 parse_err(SYNERR, "resource expected at \"%s\"\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
2067 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2068 } while(_curchar != '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
2069
a61af66fc99e Initial load
duke
parents:
diff changeset
2070 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2071 if (_curchar != '}') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
2072 parse_err(SYNERR, "missing \"%%}\" in pipe_class definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2073 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2074 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2075
a61af66fc99e Initial load
duke
parents:
diff changeset
2076 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2077 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2078
a61af66fc99e Initial load
duke
parents:
diff changeset
2079 //------------------------------peep_parse-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2080 void ADLParser::peep_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2081 Peephole *peep; // Pointer to current peephole rule form
a61af66fc99e Initial load
duke
parents:
diff changeset
2082 char *desc = NULL; // String representation of rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2083
a61af66fc99e Initial load
duke
parents:
diff changeset
2084 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2085
a61af66fc99e Initial load
duke
parents:
diff changeset
2086 peep = new Peephole(); // Build new Peephole object
a61af66fc99e Initial load
duke
parents:
diff changeset
2087 // Check for open block sequence
a61af66fc99e Initial load
duke
parents:
diff changeset
2088 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2089 if (_curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2090 next_char(); next_char(); // Skip "%{"
a61af66fc99e Initial load
duke
parents:
diff changeset
2091 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2092 while (_curchar != '%' && *(_ptr+1) != '}') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2093 char *token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2094 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2095 parse_err(SYNERR, "missing identifier inside peephole rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2096 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2097 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2098 // check for legal subsections of peephole rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2099 if (strcmp(token,"peepmatch")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2100 peep_match_parse(*peep); }
a61af66fc99e Initial load
duke
parents:
diff changeset
2101 else if (strcmp(token,"peepconstraint")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2102 peep_constraint_parse(*peep); }
a61af66fc99e Initial load
duke
parents:
diff changeset
2103 else if (strcmp(token,"peepreplace")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2104 peep_replace_parse(*peep); }
a61af66fc99e Initial load
duke
parents:
diff changeset
2105 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2106 parse_err(SYNERR, "expected peepmatch, peepconstraint, or peepreplace for identifier %s.\n", token);
a61af66fc99e Initial load
duke
parents:
diff changeset
2107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2108 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2111 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2112 parse_err(SYNERR, "Missing %%{ ... %%} block after peephole keyword.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2113 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2115 next_char(); // Skip past '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
2116 next_char(); // Skip past '}'
a61af66fc99e Initial load
duke
parents:
diff changeset
2117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2118
a61af66fc99e Initial load
duke
parents:
diff changeset
2119 // ******************** Private Level 2 Parse Functions ********************
a61af66fc99e Initial load
duke
parents:
diff changeset
2120 //------------------------------constraint_parse------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2121 Constraint *ADLParser::constraint_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2122 char *func;
a61af66fc99e Initial load
duke
parents:
diff changeset
2123 char *arg;
a61af66fc99e Initial load
duke
parents:
diff changeset
2124
a61af66fc99e Initial load
duke
parents:
diff changeset
2125 // Check for constraint expression
a61af66fc99e Initial load
duke
parents:
diff changeset
2126 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2127 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2128 parse_err(SYNERR, "missing constraint expression, (...)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2129 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2131 next_char(); // Skip past '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2132
a61af66fc99e Initial load
duke
parents:
diff changeset
2133 // Get constraint function
a61af66fc99e Initial load
duke
parents:
diff changeset
2134 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2135 func = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2136 if (func == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2137 parse_err(SYNERR, "missing function in constraint expression.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2138 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2140 if (strcmp(func,"ALLOC_IN_RC")==0
a61af66fc99e Initial load
duke
parents:
diff changeset
2141 || strcmp(func,"IS_R_CLASS")==0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2142 // Check for '(' before argument
a61af66fc99e Initial load
duke
parents:
diff changeset
2143 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2144 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2145 parse_err(SYNERR, "missing '(' for constraint function's argument.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2146 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2148 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2149
a61af66fc99e Initial load
duke
parents:
diff changeset
2150 // Get it's argument
a61af66fc99e Initial load
duke
parents:
diff changeset
2151 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2152 arg = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2153 if (arg == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2154 parse_err(SYNERR, "missing argument for constraint function %s\n",func);
a61af66fc99e Initial load
duke
parents:
diff changeset
2155 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2157 // Check for ')' after argument
a61af66fc99e Initial load
duke
parents:
diff changeset
2158 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2159 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2160 parse_err(SYNERR, "missing ')' after constraint function argument %s\n",arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
2161 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2163 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2164 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2165 parse_err(SYNERR, "Invalid constraint function %s\n",func);
a61af66fc99e Initial load
duke
parents:
diff changeset
2166 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2168
a61af66fc99e Initial load
duke
parents:
diff changeset
2169 // Check for closing paren and ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2170 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2171 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2172 parse_err(SYNERR, "Missing ')' for constraint function %s\n",func);
a61af66fc99e Initial load
duke
parents:
diff changeset
2173 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2175 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2176 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2177 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2178 parse_err(SYNERR, "Missing ';' after constraint.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2179 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2181 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2182
a61af66fc99e Initial load
duke
parents:
diff changeset
2183 // Create new "Constraint"
a61af66fc99e Initial load
duke
parents:
diff changeset
2184 Constraint *constraint = new Constraint(func,arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
2185 return constraint;
a61af66fc99e Initial load
duke
parents:
diff changeset
2186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2187
a61af66fc99e Initial load
duke
parents:
diff changeset
2188 //------------------------------constr_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2189 ConstructRule *ADLParser::construct_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2190 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2192
a61af66fc99e Initial load
duke
parents:
diff changeset
2193
a61af66fc99e Initial load
duke
parents:
diff changeset
2194 //------------------------------reg_def_parse----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2195 void ADLParser::reg_def_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2196 char *rname; // Name of register being defined
a61af66fc99e Initial load
duke
parents:
diff changeset
2197
a61af66fc99e Initial load
duke
parents:
diff changeset
2198 // Get register name
a61af66fc99e Initial load
duke
parents:
diff changeset
2199 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2200 rname = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2201 if (rname == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2202 parse_err(SYNERR, "missing register name after reg_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2203 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2205
a61af66fc99e Initial load
duke
parents:
diff changeset
2206 // Check for definition of register calling convention (save on call, ...),
a61af66fc99e Initial load
duke
parents:
diff changeset
2207 // register save type, and register encoding value.
a61af66fc99e Initial load
duke
parents:
diff changeset
2208 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2209 char *callconv = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2210 char *c_conv = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2211 char *idealtype = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2212 char *encoding = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2213 char *concrete = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2214 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2215 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2216 callconv = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2217 // Parse the internal calling convention, must be NS, SOC, SOE, or AS.
a61af66fc99e Initial load
duke
parents:
diff changeset
2218 if (callconv == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2219 parse_err(SYNERR, "missing register calling convention value\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2220 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2222 if(strcmp(callconv, "SOC") && strcmp(callconv,"SOE") &&
a61af66fc99e Initial load
duke
parents:
diff changeset
2223 strcmp(callconv, "NS") && strcmp(callconv, "AS")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2224 parse_err(SYNERR, "invalid value for register calling convention\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2226 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2227 if (_curchar != ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2228 parse_err(SYNERR, "missing comma in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2229 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2231 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2232
a61af66fc99e Initial load
duke
parents:
diff changeset
2233 // Parse the native calling convention, must be NS, SOC, SOE, AS
a61af66fc99e Initial load
duke
parents:
diff changeset
2234 c_conv = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2235 if (c_conv == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2236 parse_err(SYNERR, "missing register native calling convention value\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2237 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2239 if(strcmp(c_conv, "SOC") && strcmp(c_conv,"SOE") &&
a61af66fc99e Initial load
duke
parents:
diff changeset
2240 strcmp(c_conv, "NS") && strcmp(c_conv, "AS")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2241 parse_err(SYNERR, "invalid value for register calling convention\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2243 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2244 if (_curchar != ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2245 parse_err(SYNERR, "missing comma in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2246 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2248 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2249 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2250
a61af66fc99e Initial load
duke
parents:
diff changeset
2251 // Parse the ideal save type
a61af66fc99e Initial load
duke
parents:
diff changeset
2252 idealtype = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2253 if (idealtype == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2254 parse_err(SYNERR, "missing register save type value\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2255 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2257 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2258 if (_curchar != ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2259 parse_err(SYNERR, "missing comma in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2260 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2262 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2263 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2264
a61af66fc99e Initial load
duke
parents:
diff changeset
2265 // Parse the encoding value
a61af66fc99e Initial load
duke
parents:
diff changeset
2266 encoding = get_expr("encoding", ",");
a61af66fc99e Initial load
duke
parents:
diff changeset
2267 if (encoding == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2268 parse_err(SYNERR, "missing register encoding value\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2269 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2271 trim(encoding);
a61af66fc99e Initial load
duke
parents:
diff changeset
2272 if (_curchar != ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2273 parse_err(SYNERR, "missing comma in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2274 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2276 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2277 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2278 // Parse the concrete name type
a61af66fc99e Initial load
duke
parents:
diff changeset
2279 // concrete = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2280 concrete = get_expr("concrete", ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
2281 if (concrete == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2282 parse_err(SYNERR, "missing vm register name value\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2283 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2285
a61af66fc99e Initial load
duke
parents:
diff changeset
2286 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2287 parse_err(SYNERR, "missing ')' in register definition statement\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2288 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2290 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2292
a61af66fc99e Initial load
duke
parents:
diff changeset
2293 // Check for closing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2294 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2295 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2296 parse_err(SYNERR, "missing ';' after reg_def\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2297 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2299 next_char(); // move past ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2300
a61af66fc99e Initial load
duke
parents:
diff changeset
2301 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
2302 if (_AD._adl_debug > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2303 fprintf(stderr,"Register Definition: %s ( %s, %s %s )\n", rname,
a61af66fc99e Initial load
duke
parents:
diff changeset
2304 (callconv ? callconv : ""), (c_conv ? c_conv : ""), concrete);
a61af66fc99e Initial load
duke
parents:
diff changeset
2305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2306
a61af66fc99e Initial load
duke
parents:
diff changeset
2307 // Record new register definition.
a61af66fc99e Initial load
duke
parents:
diff changeset
2308 _AD._register->addRegDef(rname, callconv, c_conv, idealtype, encoding, concrete);
a61af66fc99e Initial load
duke
parents:
diff changeset
2309 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2311
a61af66fc99e Initial load
duke
parents:
diff changeset
2312 //------------------------------reg_class_parse--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2313 void ADLParser::reg_class_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2314 char *cname; // Name of register class being defined
a61af66fc99e Initial load
duke
parents:
diff changeset
2315
a61af66fc99e Initial load
duke
parents:
diff changeset
2316 // Get register class name
a61af66fc99e Initial load
duke
parents:
diff changeset
2317 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2318 cname = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2319 if (cname == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2320 parse_err(SYNERR, "missing register class name after 'reg_class'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2321 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2323 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
2324 if (_AD._adl_debug >1) fprintf(stderr,"Register Class: %s\n", cname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2325
a61af66fc99e Initial load
duke
parents:
diff changeset
2326 RegClass *reg_class = _AD._register->addRegClass(cname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2327
a61af66fc99e Initial load
duke
parents:
diff changeset
2328 // Collect registers in class
a61af66fc99e Initial load
duke
parents:
diff changeset
2329 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2330 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2331 next_char(); // Skip '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2332 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2333 while (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2334 char *rname = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2335 if (rname==NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2336 parse_err(SYNERR, "missing identifier inside reg_class list.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2337 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2339 RegDef *regDef = _AD._register->getRegDef(rname);
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2340 if (!regDef) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2341 parse_err(SEMERR, "unknown identifier %s inside reg_class list.\n", rname);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2342 } else {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2343 reg_class->addReg(regDef); // add regDef to regClass
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2344 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2345
a61af66fc99e Initial load
duke
parents:
diff changeset
2346 // Check for ',' and position to next token.
a61af66fc99e Initial load
duke
parents:
diff changeset
2347 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2348 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2349 next_char(); // Skip trailing ','
a61af66fc99e Initial load
duke
parents:
diff changeset
2350 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2353 next_char(); // Skip closing ')'
4121
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2354 } else if (_curchar == '%') {
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2355 char *code = find_cpp_block("reg class");
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2356 if (code == NULL) {
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2357 parse_err(SYNERR, "missing code declaration for reg class.\n");
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2358 return;
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2359 }
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2360 reg_class->_user_defined = code;
db2e64ca2d5a 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 4120
diff changeset
2361 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2363
a61af66fc99e Initial load
duke
parents:
diff changeset
2364 // Check for terminating ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2365 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2366 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2367 parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2368 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2370 next_char(); // Skip trailing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2371
a61af66fc99e Initial load
duke
parents:
diff changeset
2372 // Check RegClass size, must be <= 32 registers in class.
a61af66fc99e Initial load
duke
parents:
diff changeset
2373
a61af66fc99e Initial load
duke
parents:
diff changeset
2374 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2376
a61af66fc99e Initial load
duke
parents:
diff changeset
2377 //------------------------------alloc_class_parse------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2378 void ADLParser::alloc_class_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2379 char *name; // Name of allocation class being defined
a61af66fc99e Initial load
duke
parents:
diff changeset
2380
a61af66fc99e Initial load
duke
parents:
diff changeset
2381 // Get allocation class name
a61af66fc99e Initial load
duke
parents:
diff changeset
2382 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2383 name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2384 if (name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2385 parse_err(SYNERR, "missing allocation class name after 'reg_class'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2386 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2388 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
2389 if (_AD._adl_debug >1) fprintf(stderr,"Allocation Class: %s\n", name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2390
a61af66fc99e Initial load
duke
parents:
diff changeset
2391 AllocClass *alloc_class = _AD._register->addAllocClass(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2392
a61af66fc99e Initial load
duke
parents:
diff changeset
2393 // Collect registers in class
a61af66fc99e Initial load
duke
parents:
diff changeset
2394 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2395 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2396 next_char(); // Skip '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2397 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2398 while (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2399 char *rname = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2400 if (rname==NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2401 parse_err(SYNERR, "missing identifier inside reg_class list.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2402 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2404 // Check if name is a RegDef
a61af66fc99e Initial load
duke
parents:
diff changeset
2405 RegDef *regDef = _AD._register->getRegDef(rname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2406 if (regDef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2407 alloc_class->addReg(regDef); // add regDef to allocClass
a61af66fc99e Initial load
duke
parents:
diff changeset
2408 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2409
a61af66fc99e Initial load
duke
parents:
diff changeset
2410 // name must be a RegDef or a RegClass
a61af66fc99e Initial load
duke
parents:
diff changeset
2411 parse_err(SYNERR, "name %s should be a previously defined reg_def.\n", rname);
a61af66fc99e Initial load
duke
parents:
diff changeset
2412 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2414
a61af66fc99e Initial load
duke
parents:
diff changeset
2415 // Check for ',' and position to next token.
a61af66fc99e Initial load
duke
parents:
diff changeset
2416 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2417 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2418 next_char(); // Skip trailing ','
a61af66fc99e Initial load
duke
parents:
diff changeset
2419 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2422 next_char(); // Skip closing ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2424
a61af66fc99e Initial load
duke
parents:
diff changeset
2425 // Check for terminating ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2426 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2427 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2428 parse_err(SYNERR, "missing ';' at end of reg_class definition.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2429 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2431 next_char(); // Skip trailing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2432
a61af66fc99e Initial load
duke
parents:
diff changeset
2433 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2435
a61af66fc99e Initial load
duke
parents:
diff changeset
2436 //------------------------------peep_match_child_parse-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2437 InstructForm *ADLParser::peep_match_child_parse(PeepMatch &match, int parent, int &position, int input){
a61af66fc99e Initial load
duke
parents:
diff changeset
2438 char *token = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2439 int lparen = 0; // keep track of parenthesis nesting depth
a61af66fc99e Initial load
duke
parents:
diff changeset
2440 int rparen = 0; // position of instruction at this depth
a61af66fc99e Initial load
duke
parents:
diff changeset
2441 InstructForm *inst_seen = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2442
a61af66fc99e Initial load
duke
parents:
diff changeset
2443 // Walk the match tree,
a61af66fc99e Initial load
duke
parents:
diff changeset
2444 // Record <parent, position, instruction name, input position>
a61af66fc99e Initial load
duke
parents:
diff changeset
2445 while ( lparen >= rparen ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2446 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2447 // Left paren signals start of an input, collect with recursive call
a61af66fc99e Initial load
duke
parents:
diff changeset
2448 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2449 ++lparen;
a61af66fc99e Initial load
duke
parents:
diff changeset
2450 next_char();
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
2451 ( void ) peep_match_child_parse(match, parent, position, rparen);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2453 // Right paren signals end of an input, may be more
a61af66fc99e Initial load
duke
parents:
diff changeset
2454 else if (_curchar == ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2455 ++rparen;
a61af66fc99e Initial load
duke
parents:
diff changeset
2456 if( rparen == lparen ) { // IF rparen matches an lparen I've seen
a61af66fc99e Initial load
duke
parents:
diff changeset
2457 next_char(); // move past ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2458 } else { // ELSE leave ')' for parent
a61af66fc99e Initial load
duke
parents:
diff changeset
2459 assert( rparen == lparen + 1, "Should only see one extra ')'");
a61af66fc99e Initial load
duke
parents:
diff changeset
2460 // if an instruction was not specified for this paren-pair
a61af66fc99e Initial load
duke
parents:
diff changeset
2461 if( ! inst_seen ) { // record signal entry
a61af66fc99e Initial load
duke
parents:
diff changeset
2462 match.add_instruction( parent, position, NameList::_signal, input );
a61af66fc99e Initial load
duke
parents:
diff changeset
2463 ++position;
a61af66fc99e Initial load
duke
parents:
diff changeset
2464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2465 // ++input; // TEMPORARY
a61af66fc99e Initial load
duke
parents:
diff changeset
2466 return inst_seen;
a61af66fc99e Initial load
duke
parents:
diff changeset
2467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2469 // if no parens, then check for instruction name
a61af66fc99e Initial load
duke
parents:
diff changeset
2470 // This instruction is the parent of a sub-tree
a61af66fc99e Initial load
duke
parents:
diff changeset
2471 else if ((token = get_ident_dup()) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2472 const Form *form = _AD._globalNames[token];
a61af66fc99e Initial load
duke
parents:
diff changeset
2473 if (form) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2474 InstructForm *inst = form->is_instruction();
a61af66fc99e Initial load
duke
parents:
diff changeset
2475 // Record the first instruction at this level
a61af66fc99e Initial load
duke
parents:
diff changeset
2476 if( inst_seen == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2477 inst_seen = inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
2478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2479 if (inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2480 match.add_instruction( parent, position, token, input );
a61af66fc99e Initial load
duke
parents:
diff changeset
2481 parent = position;
a61af66fc99e Initial load
duke
parents:
diff changeset
2482 ++position;
a61af66fc99e Initial load
duke
parents:
diff changeset
2483 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2484 parse_err(SYNERR, "instruction name expected at identifier %s.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
2485 token);
a61af66fc99e Initial load
duke
parents:
diff changeset
2486 return inst_seen;
a61af66fc99e Initial load
duke
parents:
diff changeset
2487 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2489 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2490 parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2491 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2494 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2495 parse_err(SYNERR, "missing identifier in peepmatch rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2496 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2498
a61af66fc99e Initial load
duke
parents:
diff changeset
2499 } // end while
a61af66fc99e Initial load
duke
parents:
diff changeset
2500
a61af66fc99e Initial load
duke
parents:
diff changeset
2501 assert( false, "ShouldNotReachHere();");
a61af66fc99e Initial load
duke
parents:
diff changeset
2502 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2504
a61af66fc99e Initial load
duke
parents:
diff changeset
2505 //------------------------------peep_match_parse-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2506 // Syntax for a peepmatch rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2507 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2508 // peepmatch ( root_instr_name [(instruction subtree)] [,(instruction subtree)]* );
a61af66fc99e Initial load
duke
parents:
diff changeset
2509 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2510 void ADLParser::peep_match_parse(Peephole &peep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2511
a61af66fc99e Initial load
duke
parents:
diff changeset
2512 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2513 // Check the structure of the rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2514 // Check for open paren
a61af66fc99e Initial load
duke
parents:
diff changeset
2515 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2516 parse_err(SYNERR, "missing '(' at start of peepmatch rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2517 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2519 next_char(); // skip '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2520
a61af66fc99e Initial load
duke
parents:
diff changeset
2521 // Construct PeepMatch and parse the peepmatch rule.
a61af66fc99e Initial load
duke
parents:
diff changeset
2522 PeepMatch *match = new PeepMatch(_ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2523 int parent = -1; // parent of root
a61af66fc99e Initial load
duke
parents:
diff changeset
2524 int position = 0; // zero-based positions
a61af66fc99e Initial load
duke
parents:
diff changeset
2525 int input = 0; // input position in parent's operands
a61af66fc99e Initial load
duke
parents:
diff changeset
2526 InstructForm *root= peep_match_child_parse( *match, parent, position, input);
a61af66fc99e Initial load
duke
parents:
diff changeset
2527 if( root == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2528 parse_err(SYNERR, "missing instruction-name at start of peepmatch.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2529 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2531
a61af66fc99e Initial load
duke
parents:
diff changeset
2532 if( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2533 parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2534 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2536 next_char(); // skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2537
a61af66fc99e Initial load
duke
parents:
diff changeset
2538 // Check for closing semicolon
a61af66fc99e Initial load
duke
parents:
diff changeset
2539 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2540 if( _curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2541 parse_err(SYNERR, "missing ';' at end of peepmatch.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2542 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2544 next_char(); // skip ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2545
a61af66fc99e Initial load
duke
parents:
diff changeset
2546 // Store match into peep, and store peep into instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2547 peep.add_match(match);
a61af66fc99e Initial load
duke
parents:
diff changeset
2548 root->append_peephole(&peep);
a61af66fc99e Initial load
duke
parents:
diff changeset
2549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2550
a61af66fc99e Initial load
duke
parents:
diff changeset
2551 //------------------------------peep_constraint_parse--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2552 // Syntax for a peepconstraint rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2553 // A parenthesized list of relations between operands in peepmatch subtree
a61af66fc99e Initial load
duke
parents:
diff changeset
2554 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2555 // peepconstraint %{
a61af66fc99e Initial load
duke
parents:
diff changeset
2556 // (instruction_number.operand_name
a61af66fc99e Initial load
duke
parents:
diff changeset
2557 // relational_op
a61af66fc99e Initial load
duke
parents:
diff changeset
2558 // instruction_number.operand_name OR register_name
a61af66fc99e Initial load
duke
parents:
diff changeset
2559 // [, ...] );
a61af66fc99e Initial load
duke
parents:
diff changeset
2560 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2561 // // instruction numbers are zero-based using topological order in peepmatch
a61af66fc99e Initial load
duke
parents:
diff changeset
2562 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2563 void ADLParser::peep_constraint_parse(Peephole &peep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2564
a61af66fc99e Initial load
duke
parents:
diff changeset
2565 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2566 // Check the structure of the rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2567 // Check for open paren
a61af66fc99e Initial load
duke
parents:
diff changeset
2568 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2569 parse_err(SYNERR, "missing '(' at start of peepconstraint rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2570 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2571 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2572 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2573 next_char(); // Skip '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2575
a61af66fc99e Initial load
duke
parents:
diff changeset
2576 // Check for a constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
2577 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2578 while( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2579 // Get information on the left instruction and its operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2580 // left-instructions's number
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
2581 int left_inst = get_int();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2582 // Left-instruction's operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2583 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2584 if( _curchar != '.' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2585 parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2586 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2587 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2588 next_char(); // Skip '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
2589 char *left_op = get_ident_dup();
a61af66fc99e Initial load
duke
parents:
diff changeset
2590
a61af66fc99e Initial load
duke
parents:
diff changeset
2591 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2592 // Collect relational operator
a61af66fc99e Initial load
duke
parents:
diff changeset
2593 char *relation = get_relation_dup();
a61af66fc99e Initial load
duke
parents:
diff changeset
2594
a61af66fc99e Initial load
duke
parents:
diff changeset
2595 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2596 // Get information on the right instruction and its operand
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
2597 int right_inst; // Right-instructions's number
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2598 if( isdigit(_curchar) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2599 right_inst = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
2600 // Right-instruction's operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2601 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2602 if( _curchar != '.' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2603 parse_err(SYNERR, "missing '.' in peepconstraint after instruction number.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2604 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2606 next_char(); // Skip '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
2607 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2608 right_inst = -1; // Flag as being a register constraint
a61af66fc99e Initial load
duke
parents:
diff changeset
2609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2610
a61af66fc99e Initial load
duke
parents:
diff changeset
2611 char *right_op = get_ident_dup();
a61af66fc99e Initial load
duke
parents:
diff changeset
2612
a61af66fc99e Initial load
duke
parents:
diff changeset
2613 // Construct the next PeepConstraint
a61af66fc99e Initial load
duke
parents:
diff changeset
2614 PeepConstraint *constraint = new PeepConstraint( left_inst, left_op,
a61af66fc99e Initial load
duke
parents:
diff changeset
2615 relation,
a61af66fc99e Initial load
duke
parents:
diff changeset
2616 right_inst, right_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
2617 // And append it to the list for this peephole rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2618 peep.append_constraint( constraint );
a61af66fc99e Initial load
duke
parents:
diff changeset
2619
a61af66fc99e Initial load
duke
parents:
diff changeset
2620 // Check for another constraint, or end of rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2621 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2622 if( _curchar == ',' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2623 next_char(); // Skip ','
a61af66fc99e Initial load
duke
parents:
diff changeset
2624 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2626 else if( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2627 parse_err(SYNERR, "expected ',' or ')' after peephole constraint.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2628 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2630 } // end while( processing constraints )
a61af66fc99e Initial load
duke
parents:
diff changeset
2631 next_char(); // Skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2632
a61af66fc99e Initial load
duke
parents:
diff changeset
2633 // Check for terminating ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2634 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2635 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2636 parse_err(SYNERR, "missing ';' at end of peepconstraint.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2637 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2639 next_char(); // Skip trailing ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2641
a61af66fc99e Initial load
duke
parents:
diff changeset
2642
a61af66fc99e Initial load
duke
parents:
diff changeset
2643 //------------------------------peep_replace_parse-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2644 // Syntax for a peepreplace rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2645 // root instruction name followed by a
a61af66fc99e Initial load
duke
parents:
diff changeset
2646 // parenthesized list of whitespace separated instruction.operand specifiers
a61af66fc99e Initial load
duke
parents:
diff changeset
2647 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2648 // peepreplace ( instr_name ( [instruction_number.operand_name]* ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
2649 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2650 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2651 void ADLParser::peep_replace_parse(Peephole &peep) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2652 int lparen = 0; // keep track of parenthesis nesting depth
a61af66fc99e Initial load
duke
parents:
diff changeset
2653 int rparen = 0; // keep track of parenthesis nesting depth
a61af66fc99e Initial load
duke
parents:
diff changeset
2654 int icount = 0; // count of instructions in rule for naming
a61af66fc99e Initial load
duke
parents:
diff changeset
2655 char *str = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2656 char *token = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2657
a61af66fc99e Initial load
duke
parents:
diff changeset
2658 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2659 // Check for open paren
a61af66fc99e Initial load
duke
parents:
diff changeset
2660 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2661 parse_err(SYNERR, "missing '(' at start of peepreplace rule.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2662 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2664 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2665 lparen++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2666 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2668
a61af66fc99e Initial load
duke
parents:
diff changeset
2669 // Check for root instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2670 char *inst = get_ident_dup();
a61af66fc99e Initial load
duke
parents:
diff changeset
2671 const Form *form = _AD._globalNames[inst];
a61af66fc99e Initial load
duke
parents:
diff changeset
2672 if( form == NULL || form->is_instruction() == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2673 parse_err(SYNERR, "Instruction name expected at start of peepreplace.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2674 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2676
a61af66fc99e Initial load
duke
parents:
diff changeset
2677 // Store string representation of rule into replace
a61af66fc99e Initial load
duke
parents:
diff changeset
2678 PeepReplace *replace = new PeepReplace(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
2679 replace->add_instruction( inst );
a61af66fc99e Initial load
duke
parents:
diff changeset
2680
a61af66fc99e Initial load
duke
parents:
diff changeset
2681 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2682 // Start of root's operand-list
a61af66fc99e Initial load
duke
parents:
diff changeset
2683 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2684 parse_err(SYNERR, "missing '(' at peepreplace root's operand-list.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2685 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2687 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2688 lparen++;
a61af66fc99e Initial load
duke
parents:
diff changeset
2689 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
2690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2691
a61af66fc99e Initial load
duke
parents:
diff changeset
2692 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2693 // Get the list of operands
a61af66fc99e Initial load
duke
parents:
diff changeset
2694 while( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2695 // Get information on an instruction and its operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2696 // instructions's number
a61af66fc99e Initial load
duke
parents:
diff changeset
2697 int inst_num = get_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
2698 // Left-instruction's operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2699 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2700 if( _curchar != '.' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2701 parse_err(SYNERR, "missing '.' in peepreplace after instruction number.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2702 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2704 next_char(); // Skip '.'
a61af66fc99e Initial load
duke
parents:
diff changeset
2705 char *inst_op = get_ident_dup();
a61af66fc99e Initial load
duke
parents:
diff changeset
2706 if( inst_op == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2707 parse_err(SYNERR, "missing operand identifier in peepreplace.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2708 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2710
a61af66fc99e Initial load
duke
parents:
diff changeset
2711 // Record this operand's position in peepmatch
a61af66fc99e Initial load
duke
parents:
diff changeset
2712 replace->add_operand( inst_num, inst_op );
a61af66fc99e Initial load
duke
parents:
diff changeset
2713 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2715
a61af66fc99e Initial load
duke
parents:
diff changeset
2716 // Check for the end of operands list
a61af66fc99e Initial load
duke
parents:
diff changeset
2717 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2718 assert( _curchar == ')', "While loop should have advanced to ')'.");
a61af66fc99e Initial load
duke
parents:
diff changeset
2719 next_char(); // Skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2720
a61af66fc99e Initial load
duke
parents:
diff changeset
2721 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2722 // Check for end of peepreplace
a61af66fc99e Initial load
duke
parents:
diff changeset
2723 if( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2724 parse_err(SYNERR, "missing ')' at end of peepmatch.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2725 parse_err(SYNERR, "Support one replacement instruction.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2726 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2728 next_char(); // Skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
2729
a61af66fc99e Initial load
duke
parents:
diff changeset
2730 // Check for closing semicolon
a61af66fc99e Initial load
duke
parents:
diff changeset
2731 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2732 if( _curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2733 parse_err(SYNERR, "missing ';' at end of peepreplace.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2734 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
2735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2736 next_char(); // skip ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
2737
a61af66fc99e Initial load
duke
parents:
diff changeset
2738 // Store replace into peep
a61af66fc99e Initial load
duke
parents:
diff changeset
2739 peep.add_replace( replace );
a61af66fc99e Initial load
duke
parents:
diff changeset
2740 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2741
a61af66fc99e Initial load
duke
parents:
diff changeset
2742 //------------------------------pred_parse-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2743 Predicate *ADLParser::pred_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2744 Predicate *predicate; // Predicate class for operand
a61af66fc99e Initial load
duke
parents:
diff changeset
2745 char *rule = NULL; // String representation of predicate
a61af66fc99e Initial load
duke
parents:
diff changeset
2746
a61af66fc99e Initial load
duke
parents:
diff changeset
2747 skipws(); // Skip leading whitespace
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2748 int line = linenum();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
2749 if ( (rule = get_paren_expr("pred expression", true)) == NULL ) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2750 parse_err(SYNERR, "incorrect or missing expression for 'predicate'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2751 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2753 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
2754 if (_AD._adl_debug > 1) fprintf(stderr,"Predicate: %s\n", rule);
a61af66fc99e Initial load
duke
parents:
diff changeset
2755 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2756 parse_err(SYNERR, "missing ';' in predicate definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2757 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
2758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2759 next_char(); // Point after the terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
2760
a61af66fc99e Initial load
duke
parents:
diff changeset
2761 predicate = new Predicate(rule); // Build new predicate object
a61af66fc99e Initial load
duke
parents:
diff changeset
2762 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2763 return predicate;
a61af66fc99e Initial load
duke
parents:
diff changeset
2764 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2765
a61af66fc99e Initial load
duke
parents:
diff changeset
2766
a61af66fc99e Initial load
duke
parents:
diff changeset
2767 //------------------------------ins_encode_parse_block-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2768 // Parse the block form of ins_encode. See ins_encode_parse for more details
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2769 void ADLParser::ins_encode_parse_block(InstructForm& inst) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2770 // Create a new encoding name based on the name of the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2771 // definition, which should be unique.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2772 const char* prefix = "__ins_encode_";
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2773 char* ec_name = (char*) malloc(strlen(inst._ident) + strlen(prefix) + 1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2774 sprintf(ec_name, "%s%s", prefix, inst._ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
2775
a61af66fc99e Initial load
duke
parents:
diff changeset
2776 assert(_AD._encode->encClass(ec_name) == NULL, "shouldn't already exist");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2777 EncClass* encoding = _AD._encode->add_EncClass(ec_name);
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
2778 encoding->_linenum = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2779
a61af66fc99e Initial load
duke
parents:
diff changeset
2780 // synthesize the arguments list for the enc_class from the
a61af66fc99e Initial load
duke
parents:
diff changeset
2781 // arguments to the instruct definition.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2782 const char* param = NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2783 inst._parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2784 while ((param = inst._parameters.iter()) != NULL) {
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2785 OperandForm* opForm = (OperandForm*) inst._localNames[param];
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2786 encoding->add_parameter(opForm->_ident, param);
a61af66fc99e Initial load
duke
parents:
diff changeset
2787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2788
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2789 if (!inst._is_postalloc_expand) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2790 // Define a MacroAssembler instance for use by the encoding. The
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2791 // name is chosen to match the __ idiom used for assembly in other
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2792 // parts of hotspot and assumes the existence of the standard
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2793 // #define __ _masm.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2794 encoding->add_code(" MacroAssembler _masm(&cbuf);\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2795 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2796
a61af66fc99e Initial load
duke
parents:
diff changeset
2797 // Parse the following %{ }% block
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2798 ins_encode_parse_block_impl(inst, encoding, ec_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2799
a61af66fc99e Initial load
duke
parents:
diff changeset
2800 // Build an encoding rule which invokes the encoding rule we just
a61af66fc99e Initial load
duke
parents:
diff changeset
2801 // created, passing all arguments that we received.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2802 InsEncode* encrule = new InsEncode(); // Encode class for instruction
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2803 NameAndList* params = encrule->add_encode(ec_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2804 inst._parameters.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2805 while ((param = inst._parameters.iter()) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2806 params->add_entry(param);
a61af66fc99e Initial load
duke
parents:
diff changeset
2807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2808
3793
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2809 // Check for duplicate ins_encode sections after parsing the block
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2810 // so that parsing can continue and find any other errors.
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2811 if (inst._insencode != NULL) {
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2812 parse_err(SYNERR, "Multiple ins_encode sections defined\n");
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2813 return;
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2814 }
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
2815
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2816 // Set encode class of this instruction.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2817 inst._insencode = encrule;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2818 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2819
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2820
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2821 void ADLParser::ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2822 skipws_no_preproc(); // Skip leading whitespace
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2823 // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2824 if (_AD._adlocation_debug) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2825 encoding->add_code(get_line_string());
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2826 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2827
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2828 // Collect the parts of the encode description
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2829 // (1) strings that are passed through to output
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2830 // (2) replacement/substitution variable, preceeded by a '$'
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2831 while ((_curchar != '%') && (*(_ptr+1) != '}')) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2832
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2833 // (1)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2834 // Check if there is a string to pass through to output
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2835 char *start = _ptr; // Record start of the next string
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2836 while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2837 // If at the start of a comment, skip past it
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2838 if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2839 skipws_no_preproc();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2840 } else {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2841 // ELSE advance to the next character, or start of the next line
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2842 next_char_or_line();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2843 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2844 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2845 // If a string was found, terminate it and record in EncClass
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2846 if (start != _ptr) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2847 *_ptr = '\0'; // Terminate the string
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2848 encoding->add_code(start);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2849 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2850
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2851 // (2)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2852 // If we are at a replacement variable,
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2853 // copy it and record in EncClass
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2854 if (_curchar == '$') {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2855 // Found replacement Variable
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2856 char* rep_var = get_rep_var_ident_dup();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2857
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2858 // Add flag to _strings list indicating we should check _rep_vars
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2859 encoding->add_rep_var(rep_var);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2860
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2861 skipws();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2862
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2863 // Check if this instruct is a MachConstantNode.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2864 if (strcmp(rep_var, "constanttablebase") == 0) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2865 // This instruct is a MachConstantNode.
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2866 inst.set_needs_constant_base(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2867 if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2868 inst.set_is_mach_constant(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2869 }
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2870
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2871 if (_curchar == '(') {
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2872 parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
2873 "(only constantaddress and constantoffset)", ec_name);
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2874 return;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2875 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2876 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2877 else if ((strcmp(rep_var, "constantaddress") == 0) ||
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2878 (strcmp(rep_var, "constantoffset") == 0)) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2879 // This instruct is a MachConstantNode.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2880 inst.set_is_mach_constant(true);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2881
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2882 // If the constant keyword has an argument, parse it.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2883 if (_curchar == '(') constant_parse(inst);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2884 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2885 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2886 } // end while part of format description
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2887 next_char(); // Skip '%'
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2888 next_char(); // Skip '}'
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2889
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2890 skipws();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2891
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2892 if (_AD._adlocation_debug) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2893 encoding->add_code(end_line_marker());
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2894 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2895
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2896 // Debug Stuff
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2897 if (_AD._adl_debug > 1) fprintf(stderr, "EncodingClass Form: %s\n", ec_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2899
a61af66fc99e Initial load
duke
parents:
diff changeset
2900
a61af66fc99e Initial load
duke
parents:
diff changeset
2901 //------------------------------ins_encode_parse-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2902 // Encode rules have the form
a61af66fc99e Initial load
duke
parents:
diff changeset
2903 // ins_encode( encode_class_name(parameter_list), ... );
a61af66fc99e Initial load
duke
parents:
diff changeset
2904 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2905 // The "encode_class_name" must be defined in the encode section
a61af66fc99e Initial load
duke
parents:
diff changeset
2906 // The parameter list contains $names that are locals.
a61af66fc99e Initial load
duke
parents:
diff changeset
2907 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2908 // Alternatively it can be written like this:
a61af66fc99e Initial load
duke
parents:
diff changeset
2909 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2910 // ins_encode %{
a61af66fc99e Initial load
duke
parents:
diff changeset
2911 // ... // body
a61af66fc99e Initial load
duke
parents:
diff changeset
2912 // %}
a61af66fc99e Initial load
duke
parents:
diff changeset
2913 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2914 // which synthesizes a new encoding class taking the same arguments as
a61af66fc99e Initial load
duke
parents:
diff changeset
2915 // the InstructForm, and automatically prefixes the definition with:
a61af66fc99e Initial load
duke
parents:
diff changeset
2916 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2917 // MacroAssembler masm(&cbuf);\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2918 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2919 // making it more compact to take advantage of the MacroAssembler and
a61af66fc99e Initial load
duke
parents:
diff changeset
2920 // placing the assembly closer to it's use by instructions.
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2921 void ADLParser::ins_encode_parse(InstructForm& inst) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2922
a61af66fc99e Initial load
duke
parents:
diff changeset
2923 // Parse encode class name
a61af66fc99e Initial load
duke
parents:
diff changeset
2924 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
2925 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2926 // Check for ins_encode %{ form
a61af66fc99e Initial load
duke
parents:
diff changeset
2927 if ((_curchar == '%') && (*(_ptr+1) == '{')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2928 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
2929 next_char(); // Skip '{'
a61af66fc99e Initial load
duke
parents:
diff changeset
2930
a61af66fc99e Initial load
duke
parents:
diff changeset
2931 // Parse the block form of ins_encode
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2932 ins_encode_parse_block(inst);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2933 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2935
a61af66fc99e Initial load
duke
parents:
diff changeset
2936 parse_err(SYNERR, "missing '%%{' or '(' in ins_encode definition\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2937 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2939 next_char(); // move past '('
a61af66fc99e Initial load
duke
parents:
diff changeset
2940 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2941
a61af66fc99e Initial load
duke
parents:
diff changeset
2942 InsEncode *encrule = new InsEncode(); // Encode class for instruction
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
2943 encrule->_linenum = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2944 char *ec_name = NULL; // String representation of encode rule
a61af66fc99e Initial load
duke
parents:
diff changeset
2945 // identifier is optional.
a61af66fc99e Initial load
duke
parents:
diff changeset
2946 while (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2947 ec_name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
2948 if (ec_name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2949 parse_err(SYNERR, "Invalid encode class name after 'ins_encode('.\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
2950 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2952 // Check that encoding is defined in the encode section
a61af66fc99e Initial load
duke
parents:
diff changeset
2953 EncClass *encode_class = _AD._encode->encClass(ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2954 if (encode_class == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2955 // Like to defer checking these till later...
a61af66fc99e Initial load
duke
parents:
diff changeset
2956 // parse_err(WARN, "Using an undefined encode class '%s' in 'ins_encode'.\n", ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2958
a61af66fc99e Initial load
duke
parents:
diff changeset
2959 // Get list for encode method's parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
2960 NameAndList *params = encrule->add_encode(ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
2961
a61af66fc99e Initial load
duke
parents:
diff changeset
2962 // Parse the parameters to this encode method.
a61af66fc99e Initial load
duke
parents:
diff changeset
2963 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
2964 if ( _curchar == '(' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2965 next_char(); // move past '(' for parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
2966
a61af66fc99e Initial load
duke
parents:
diff changeset
2967 // Parse the encode method's parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
2968 while (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
2969 char *param = get_ident_or_literal_constant("encoding operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
2970 if ( param != NULL ) {
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2971
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2972 // Check if this instruct is a MachConstantNode.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2973 if (strcmp(param, "constanttablebase") == 0) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2974 // This instruct is a MachConstantNode.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2975 inst.set_needs_constant_base(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2976 if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2977 inst.set_is_mach_constant(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2978 }
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2979
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2980 if (_curchar == '(') {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2981 parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2982 "(only constantaddress and constantoffset)", ec_name);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2983 return;
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2984 }
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2985 } else {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2986 // Found a parameter:
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2987 // Check it is a local name, add it to the list, then check for more
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2988 // New: allow hex constants as parameters to an encode method.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2989 // New: allow parenthesized expressions as parameters.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2990 // New: allow "primary", "secondary", "tertiary" as parameters.
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2991 // New: allow user-defined register name as parameter
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2992 if ( (inst._localNames[param] == NULL) &&
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2993 !ADLParser::is_literal_constant(param) &&
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2994 (Opcode::as_opcode_type(param) == Opcode::NOT_AN_OPCODE) &&
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2995 ((_AD._register == NULL ) || (_AD._register->getRegDef(param) == NULL)) ) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2996 parse_err(SYNERR, "Using non-locally defined parameter %s for encoding %s.\n", param, ec_name);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2997 return;
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
2998 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2999 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3000 params->add_entry(param);
a61af66fc99e Initial load
duke
parents:
diff changeset
3001
a61af66fc99e Initial load
duke
parents:
diff changeset
3002 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3003 if (_curchar == ',' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3004 // More parameters to come
a61af66fc99e Initial load
duke
parents:
diff changeset
3005 next_char(); // move past ',' between parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3006 skipws(); // Skip to next parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
3007 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3008 else if (_curchar == ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3009 // Done with parameter list
a61af66fc99e Initial load
duke
parents:
diff changeset
3010 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3011 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3012 // Only ',' or ')' are valid after a parameter name
a61af66fc99e Initial load
duke
parents:
diff changeset
3013 parse_err(SYNERR, "expected ',' or ')' after parameter %s.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
3014 ec_name);
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3015 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3017
a61af66fc99e Initial load
duke
parents:
diff changeset
3018 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3019 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3020 // Did not find a parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
3021 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3022 parse_err(SYNERR, "Expected encode parameter before ',' in encoding %s.\n", ec_name);
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3023 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3025 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3026 parse_err(SYNERR, "Expected ')' after encode parameters.\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3027 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3028 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3030 } // WHILE loop collecting parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3031 next_char(); // move past ')' at end of parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3032 } // done with parameter list for encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
3033
a61af66fc99e Initial load
duke
parents:
diff changeset
3034 // Check for ',' or ')' after encoding
a61af66fc99e Initial load
duke
parents:
diff changeset
3035 skipws(); // move to character after parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3036 if ( _curchar == ',' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3037 // Found a ','
a61af66fc99e Initial load
duke
parents:
diff changeset
3038 next_char(); // move past ',' between encode methods
a61af66fc99e Initial load
duke
parents:
diff changeset
3039 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3040 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3041 else if ( _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3042 // If not a ',' then only a ')' is allowed
a61af66fc99e Initial load
duke
parents:
diff changeset
3043 parse_err(SYNERR, "Expected ')' after encoding %s.\n", ec_name);
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3044 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3045 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3046
a61af66fc99e Initial load
duke
parents:
diff changeset
3047 // Check for ',' separating parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3048 // if ( _curchar != ',' && _curchar != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3049 // parse_err(SYNERR, "expected ',' or ')' after encode method inside ins_encode.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3050 // return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3051 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
3052
a61af66fc99e Initial load
duke
parents:
diff changeset
3053 } // done parsing ins_encode methods and their parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
3054 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3055 parse_err(SYNERR, "Missing ')' at end of ins_encode description.\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3056 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3057 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3058 next_char(); // move past ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
3059 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3060
a61af66fc99e Initial load
duke
parents:
diff changeset
3061 if ( _curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3062 parse_err(SYNERR, "Missing ';' at end of ins_encode.\n");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3063 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3065 next_char(); // move past ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3066 skipws(); // be friendly to oper_parse()
a61af66fc99e Initial load
duke
parents:
diff changeset
3067
3793
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3068 // Check for duplicate ins_encode sections after parsing the block
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3069 // so that parsing can continue and find any other errors.
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3070 if (inst._insencode != NULL) {
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3071 parse_err(SYNERR, "Multiple ins_encode sections defined\n");
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3072 return;
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3073 }
fe240d87c6ec 7061101: adlc should complain about mixing block and expression forms of ins_encode
never
parents: 2008
diff changeset
3074
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3075 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
3076 if (_AD._adl_debug > 1) fprintf(stderr,"Instruction Encode: %s\n", ec_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
3077
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3078 // Set encode class of this instruction.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3079 inst._insencode = encrule;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3080 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3081
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3082 //------------------------------postalloc_expand_parse---------------------------
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3083 // Encode rules have the form
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3084 // postalloc_expand( encode_class_name(parameter_list) );
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3085 //
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3086 // The "encode_class_name" must be defined in the encode section.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3087 // The parameter list contains $names that are locals.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3088 //
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3089 // This is just a copy of ins_encode_parse without the loop.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3090 void ADLParser::postalloc_expand_parse(InstructForm& inst) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3091 inst._is_postalloc_expand = true;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3092
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3093 // Parse encode class name.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3094 skipws(); // Skip whitespace.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3095 if (_curchar != '(') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3096 // Check for postalloc_expand %{ form
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3097 if ((_curchar == '%') && (*(_ptr+1) == '{')) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3098 next_char(); // Skip '%'
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3099 next_char(); // Skip '{'
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3100
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3101 // Parse the block form of postalloc_expand
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3102 ins_encode_parse_block(inst);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3103 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3104 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3105
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3106 parse_err(SYNERR, "missing '(' in postalloc_expand definition\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3107 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3108 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3109 next_char(); // Move past '('.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3110 skipws();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3111
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3112 InsEncode *encrule = new InsEncode(); // Encode class for instruction.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3113 encrule->_linenum = linenum();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3114 char *ec_name = NULL; // String representation of encode rule.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3115 // identifier is optional.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3116 if (_curchar != ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3117 ec_name = get_ident();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3118 if (ec_name == NULL) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3119 parse_err(SYNERR, "Invalid postalloc_expand class name after 'postalloc_expand('.\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3120 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3121 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3122 // Check that encoding is defined in the encode section.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3123 EncClass *encode_class = _AD._encode->encClass(ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3124
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3125 // Get list for encode method's parameters
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3126 NameAndList *params = encrule->add_encode(ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3127
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3128 // Parse the parameters to this encode method.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3129 skipws();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3130 if (_curchar == '(') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3131 next_char(); // Move past '(' for parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3132
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3133 // Parse the encode method's parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3134 while (_curchar != ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3135 char *param = get_ident_or_literal_constant("encoding operand");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3136 if (param != NULL) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3137 // Found a parameter:
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3138
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3139 // First check for constant table support.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3140
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3141 // Check if this instruct is a MachConstantNode.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3142 if (strcmp(param, "constanttablebase") == 0) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3143 // This instruct is a MachConstantNode.
14434
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3144 inst.set_needs_constant_base(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3145 if (strncmp("MachCall", inst.mach_base_class(_globalNames), strlen("MachCall")) != 0 ) {
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3146 inst.set_is_mach_constant(true);
318d0622a6d7 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 14431
diff changeset
3147 }
14428
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3148
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3149 if (_curchar == '(') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3150 parse_err(SYNERR, "constanttablebase in instruct %s cannot have an argument "
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3151 "(only constantaddress and constantoffset)", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3152 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3153 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3154 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3155 else if ((strcmp(param, "constantaddress") == 0) ||
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3156 (strcmp(param, "constantoffset") == 0)) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3157 // This instruct is a MachConstantNode.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3158 inst.set_is_mach_constant(true);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3159
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3160 // If the constant keyword has an argument, parse it.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3161 if (_curchar == '(') constant_parse(inst);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3162 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3163
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3164 // Else check it is a local name, add it to the list, then check for more.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3165 // New: allow hex constants as parameters to an encode method.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3166 // New: allow parenthesized expressions as parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3167 // New: allow "primary", "secondary", "tertiary" as parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3168 // New: allow user-defined register name as parameter.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3169 else if ((inst._localNames[param] == NULL) &&
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3170 !ADLParser::is_literal_constant(param) &&
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3171 (Opcode::as_opcode_type(param) == Opcode::NOT_AN_OPCODE) &&
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3172 ((_AD._register == NULL) || (_AD._register->getRegDef(param) == NULL))) {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3173 parse_err(SYNERR, "Using non-locally defined parameter %s for encoding %s.\n", param, ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3174 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3175 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3176 params->add_entry(param);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3177
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3178 skipws();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3179 if (_curchar == ',') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3180 // More parameters to come.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3181 next_char(); // Move past ',' between parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3182 skipws(); // Skip to next parameter.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3183 } else if (_curchar == ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3184 // Done with parameter list
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3185 } else {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3186 // Only ',' or ')' are valid after a parameter name.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3187 parse_err(SYNERR, "expected ',' or ')' after parameter %s.\n", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3188 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3189 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3190
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3191 } else {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3192 skipws();
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3193 // Did not find a parameter.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3194 if (_curchar == ',') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3195 parse_err(SYNERR, "Expected encode parameter before ',' in postalloc_expand %s.\n", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3196 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3197 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3198 if (_curchar != ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3199 parse_err(SYNERR, "Expected ')' after postalloc_expand parameters.\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3200 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3201 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3202 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3203 } // WHILE loop collecting parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3204 next_char(); // Move past ')' at end of parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3205 } // Done with parameter list for encoding.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3206
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3207 // Check for ',' or ')' after encoding.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3208 skipws(); // Move to character after parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3209 if (_curchar != ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3210 // Only a ')' is allowed.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3211 parse_err(SYNERR, "Expected ')' after postalloc_expand %s.\n", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3212 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3213 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3214 } // Done parsing postalloc_expand method and their parameters.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3215 if (_curchar != ')') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3216 parse_err(SYNERR, "Missing ')' at end of postalloc_expand description.\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3217 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3218 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3219 next_char(); // Move past ')'.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3220 skipws(); // Skip leading whitespace.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3221
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3222 if (_curchar != ';') {
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3223 parse_err(SYNERR, "Missing ';' at end of postalloc_expand.\n");
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3224 return;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3225 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3226 next_char(); // Move past ';'.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3227 skipws(); // Be friendly to oper_parse().
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3228
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3229 // Debug Stuff.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3230 if (_AD._adl_debug > 1) fprintf(stderr, "Instruction postalloc_expand: %s\n", ec_name);
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3231
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3232 // Set encode class of this instruction.
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3233 inst._insencode = encrule;
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3234 }
044b28168e20 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 12323
diff changeset
3235
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3236
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3237 //------------------------------constant_parse---------------------------------
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3238 // Parse a constant expression.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3239 void ADLParser::constant_parse(InstructForm& inst) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3240 // Create a new encoding name based on the name of the instruction
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3241 // definition, which should be unique.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3242 const char* prefix = "__constant_";
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3243 char* ec_name = (char*) malloc(strlen(inst._ident) + strlen(prefix) + 1);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3244 sprintf(ec_name, "%s%s", prefix, inst._ident);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3245
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3246 assert(_AD._encode->encClass(ec_name) == NULL, "shouldn't already exist");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3247 EncClass* encoding = _AD._encode->add_EncClass(ec_name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3248 encoding->_linenum = linenum();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3249
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3250 // synthesize the arguments list for the enc_class from the
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3251 // arguments to the instruct definition.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3252 const char* param = NULL;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3253 inst._parameters.reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3254 while ((param = inst._parameters.iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3255 OperandForm* opForm = (OperandForm*) inst._localNames[param];
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3256 encoding->add_parameter(opForm->_ident, param);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3257 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3258
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3259 // Parse the following ( ) expression.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3260 constant_parse_expression(encoding, ec_name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3261
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3262 // Build an encoding rule which invokes the encoding rule we just
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3263 // created, passing all arguments that we received.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3264 InsEncode* encrule = new InsEncode(); // Encode class for instruction
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3265 NameAndList* params = encrule->add_encode(ec_name);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3266 inst._parameters.reset();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3267 while ((param = inst._parameters.iter()) != NULL) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3268 params->add_entry(param);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3269 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3270
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3271 // Set encode class of this instruction.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3272 inst._constant = encrule;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3273 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3274
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3275
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3276 //------------------------------constant_parse_expression----------------------
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3277 void ADLParser::constant_parse_expression(EncClass* encoding, char* ec_name) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3278 skipws();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3279
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3280 // Prepend location descriptor, for debugging; cf. ADLParser::find_cpp_block
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3281 if (_AD._adlocation_debug) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3282 encoding->add_code(get_line_string());
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3283 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3284
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3285 // Start code line.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3286 encoding->add_code(" _constant = C->constant_table().add");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3287
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3288 // Parse everything in ( ) expression.
4114
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3842
diff changeset
3289 encoding->add_code("(this, ");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3290 next_char(); // Skip '('
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3291 int parens_depth = 1;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3292
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3293 // Collect the parts of the constant expression.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3294 // (1) strings that are passed through to output
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3295 // (2) replacement/substitution variable, preceeded by a '$'
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3296 while (parens_depth > 0) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3297 if (_curchar == '(') {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3298 parens_depth++;
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3299 encoding->add_code("(");
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3300 next_char();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3301 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3302 else if (_curchar == ')') {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3303 parens_depth--;
4114
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3842
diff changeset
3304 if (parens_depth > 0)
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3842
diff changeset
3305 encoding->add_code(")");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3306 next_char();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3307 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3308 else {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3309 // (1)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3310 // Check if there is a string to pass through to output
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3311 char *start = _ptr; // Record start of the next string
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3312 while ((_curchar != '$') && (_curchar != '(') && (_curchar != ')')) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3313 next_char();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3314 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3315 // If a string was found, terminate it and record in EncClass
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3316 if (start != _ptr) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3317 *_ptr = '\0'; // Terminate the string
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3318 encoding->add_code(start);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3319 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3320
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3321 // (2)
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3322 // If we are at a replacement variable, copy it and record in EncClass.
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3323 if (_curchar == '$') {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3324 // Found replacement Variable
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3325 char* rep_var = get_rep_var_ident_dup();
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3326 encoding->add_rep_var(rep_var);
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3327 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3328 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3329 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3330
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3331 // Finish code line.
4114
6729bbc1fcd6 7003454: order constants in constant table by number of references in code
twisti
parents: 3842
diff changeset
3332 encoding->add_code(");");
2008
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3333
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3334 if (_AD._adlocation_debug) {
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3335 encoding->add_code(end_line_marker());
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3336 }
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3337
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3338 // Debug Stuff
2f644f85485d 6961690: load oops from constant table on SPARC
twisti
parents: 1972
diff changeset
3339 if (_AD._adl_debug > 1) fprintf(stderr, "EncodingClass Form: %s\n", ec_name);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3341
a61af66fc99e Initial load
duke
parents:
diff changeset
3342
a61af66fc99e Initial load
duke
parents:
diff changeset
3343 //------------------------------size_parse-----------------------------------
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
3344 // Parse a 'size(<expr>)' attribute which specifies the size of the
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
3345 // emitted instructions in bytes. <expr> can be a C++ expression,
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
3346 // e.g. a constant.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3347 char* ADLParser::size_parse(InstructForm *instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3348 char* sizeOfInstr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3349
a61af66fc99e Initial load
duke
parents:
diff changeset
3350 // Get value of the instruction's size
a61af66fc99e Initial load
duke
parents:
diff changeset
3351 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3352
a61af66fc99e Initial load
duke
parents:
diff changeset
3353 // Parse size
a61af66fc99e Initial load
duke
parents:
diff changeset
3354 sizeOfInstr = get_paren_expr("size expression");
a61af66fc99e Initial load
duke
parents:
diff changeset
3355 if (sizeOfInstr == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3356 parse_err(SYNERR, "size of opcode expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
3357 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3359
a61af66fc99e Initial load
duke
parents:
diff changeset
3360 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3361
a61af66fc99e Initial load
duke
parents:
diff changeset
3362 // Check for terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
3363 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3364 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3365 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3367 next_char(); // Advance past the ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3368 skipws(); // necessary for instr_parse()
a61af66fc99e Initial load
duke
parents:
diff changeset
3369
a61af66fc99e Initial load
duke
parents:
diff changeset
3370 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
3371 if (_AD._adl_debug > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3372 if (sizeOfInstr != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3373 fprintf(stderr,"size of opcode: %s\n", sizeOfInstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3376
a61af66fc99e Initial load
duke
parents:
diff changeset
3377 return sizeOfInstr;
a61af66fc99e Initial load
duke
parents:
diff changeset
3378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3379
a61af66fc99e Initial load
duke
parents:
diff changeset
3380
a61af66fc99e Initial load
duke
parents:
diff changeset
3381 //------------------------------opcode_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3382 Opcode * ADLParser::opcode_parse(InstructForm *instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3383 char *primary = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3384 char *secondary = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3385 char *tertiary = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3386
a61af66fc99e Initial load
duke
parents:
diff changeset
3387 char *val = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3388 Opcode *opcode = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3389
a61af66fc99e Initial load
duke
parents:
diff changeset
3390 // Get value of the instruction's opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3391 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3392 if (_curchar != '(') { // Check for parenthesized operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
3393 parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3394 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3396 next_char(); // skip open paren
a61af66fc99e Initial load
duke
parents:
diff changeset
3397 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3398 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3399 // Parse primary, secondary, and tertiary opcodes, if provided.
a61af66fc99e Initial load
duke
parents:
diff changeset
3400 if ( ((primary = get_ident_or_literal_constant("primary opcode")) == NULL) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3401 parse_err(SYNERR, "primary hex opcode expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
3402 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3404 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3405 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3406 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
3407 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3408 // Parse secondary opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3409 if ( ((secondary = get_ident_or_literal_constant("secondary opcode")) == NULL) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3410 parse_err(SYNERR, "secondary hex opcode expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
3411 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3413 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3414 if (_curchar == ',') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3415 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
3416 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3417 // Parse tertiary opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
3418 if ( ((tertiary = get_ident_or_literal_constant("tertiary opcode")) == NULL) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3419 parse_err(SYNERR,"tertiary hex opcode expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
3420 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3422 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3425 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3426 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3427 parse_err(SYNERR, "Missing ')' in opcode description\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3428 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3430 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3431 next_char(); // Skip ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
3432 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3433 // Check for terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
3434 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3435 parse_err(SYNERR, "missing ';' in ins_attrib definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3436 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3438 next_char(); // Advance past the ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3439 skipws(); // necessary for instr_parse()
a61af66fc99e Initial load
duke
parents:
diff changeset
3440
a61af66fc99e Initial load
duke
parents:
diff changeset
3441 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
3442 if (_AD._adl_debug > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3443 if (primary != NULL) fprintf(stderr,"primary opcode: %s\n", primary);
a61af66fc99e Initial load
duke
parents:
diff changeset
3444 if (secondary != NULL) fprintf(stderr,"secondary opcode: %s\n", secondary);
a61af66fc99e Initial load
duke
parents:
diff changeset
3445 if (tertiary != NULL) fprintf(stderr,"tertiary opcode: %s\n", tertiary);
a61af66fc99e Initial load
duke
parents:
diff changeset
3446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3447
a61af66fc99e Initial load
duke
parents:
diff changeset
3448 // Generate new object and return
a61af66fc99e Initial load
duke
parents:
diff changeset
3449 opcode = new Opcode(primary, secondary, tertiary);
a61af66fc99e Initial load
duke
parents:
diff changeset
3450 return opcode;
a61af66fc99e Initial load
duke
parents:
diff changeset
3451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3452
a61af66fc99e Initial load
duke
parents:
diff changeset
3453
a61af66fc99e Initial load
duke
parents:
diff changeset
3454 //------------------------------interface_parse--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3455 Interface *ADLParser::interface_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3456 char *iface_name = NULL; // Name of interface class being used
a61af66fc99e Initial load
duke
parents:
diff changeset
3457 char *iface_code = NULL; // Describe components of this class
a61af66fc99e Initial load
duke
parents:
diff changeset
3458
a61af66fc99e Initial load
duke
parents:
diff changeset
3459 // Get interface class name
a61af66fc99e Initial load
duke
parents:
diff changeset
3460 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3461 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3462 parse_err(SYNERR, "Missing '(' at start of interface description.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3463 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3465 next_char(); // move past '('
a61af66fc99e Initial load
duke
parents:
diff changeset
3466 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3467 iface_name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
3468 if (iface_name == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3469 parse_err(SYNERR, "missing interface name after 'interface'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3470 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3471 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3472 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3473 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3474 parse_err(SYNERR, "Missing ')' after name of interface.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3475 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3476 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3477 next_char(); // move past ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
3478
a61af66fc99e Initial load
duke
parents:
diff changeset
3479 // Get details of the interface,
a61af66fc99e Initial load
duke
parents:
diff changeset
3480 // for the type of interface indicated by iface_name.
a61af66fc99e Initial load
duke
parents:
diff changeset
3481 Interface *inter = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3482 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3483 if ( _curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3484 if ( strcmp(iface_name,"MEMORY_INTER") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3485 inter = mem_interface_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3487 else if ( strcmp(iface_name,"COND_INTER") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3488 inter = cond_interface_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3490 // The parse routines consume the "%}"
a61af66fc99e Initial load
duke
parents:
diff changeset
3491
a61af66fc99e Initial load
duke
parents:
diff changeset
3492 // Check for probable extra ';' after defining block.
a61af66fc99e Initial load
duke
parents:
diff changeset
3493 if ( _curchar == ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3494 parse_err(SYNERR, "Extra ';' after defining interface block.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3495 next_char(); // Skip ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3496 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3498 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3499 next_char(); // move past ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3500
a61af66fc99e Initial load
duke
parents:
diff changeset
3501 // Create appropriate interface object
a61af66fc99e Initial load
duke
parents:
diff changeset
3502 if ( strcmp(iface_name,"REG_INTER") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3503 inter = new RegInterface();
a61af66fc99e Initial load
duke
parents:
diff changeset
3504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3505 else if ( strcmp(iface_name,"CONST_INTER") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3506 inter = new ConstInterface();
a61af66fc99e Initial load
duke
parents:
diff changeset
3507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3509 skipws(); // be friendly to oper_parse()
a61af66fc99e Initial load
duke
parents:
diff changeset
3510 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
3511 if (_AD._adl_debug > 1) fprintf(stderr,"Interface Form: %s\n", iface_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
3512
a61af66fc99e Initial load
duke
parents:
diff changeset
3513 // Create appropriate interface object and return.
a61af66fc99e Initial load
duke
parents:
diff changeset
3514 return inter;
a61af66fc99e Initial load
duke
parents:
diff changeset
3515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3516
a61af66fc99e Initial load
duke
parents:
diff changeset
3517
a61af66fc99e Initial load
duke
parents:
diff changeset
3518 //------------------------------mem_interface_parse----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3519 Interface *ADLParser::mem_interface_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3520 // Fields for MemInterface
a61af66fc99e Initial load
duke
parents:
diff changeset
3521 char *base = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3522 char *index = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3523 char *scale = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3524 char *disp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3525
a61af66fc99e Initial load
duke
parents:
diff changeset
3526 if (_curchar != '%') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3527 parse_err(SYNERR, "Missing '%%{' for 'interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3528 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3530 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3531 if (_curchar != '{') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3532 parse_err(SYNERR, "Missing '%%{' for 'interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3533 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3535 next_char(); // Skip '{'
a61af66fc99e Initial load
duke
parents:
diff changeset
3536 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3537 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
3538 char *field = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
3539 if (field == NULL) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3540 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%%}' ending interface.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3541 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3543 if ( strcmp(field,"base") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3544 base = interface_field_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3546 else if ( strcmp(field,"index") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3547 index = interface_field_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3549 else if ( strcmp(field,"scale") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3550 scale = interface_field_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3551 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3552 else if ( strcmp(field,"disp") == 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3553 disp = interface_field_parse();
a61af66fc99e Initial load
duke
parents:
diff changeset
3554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3555 else {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3556 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%%}' ending interface.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3557 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3559 } while( _curchar != '%' );
a61af66fc99e Initial load
duke
parents:
diff changeset
3560 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3561 if ( _curchar != '}' ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3562 parse_err(SYNERR, "Missing '%%}' for 'interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3563 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3565 next_char(); // Skip '}'
a61af66fc99e Initial load
duke
parents:
diff changeset
3566
a61af66fc99e Initial load
duke
parents:
diff changeset
3567 // Construct desired object and return
a61af66fc99e Initial load
duke
parents:
diff changeset
3568 Interface *inter = new MemInterface(base, index, scale, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3569 return inter;
a61af66fc99e Initial load
duke
parents:
diff changeset
3570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3571
a61af66fc99e Initial load
duke
parents:
diff changeset
3572
a61af66fc99e Initial load
duke
parents:
diff changeset
3573 //------------------------------cond_interface_parse---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3574 Interface *ADLParser::cond_interface_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3575 char *equal;
a61af66fc99e Initial load
duke
parents:
diff changeset
3576 char *not_equal;
a61af66fc99e Initial load
duke
parents:
diff changeset
3577 char *less;
a61af66fc99e Initial load
duke
parents:
diff changeset
3578 char *greater_equal;
a61af66fc99e Initial load
duke
parents:
diff changeset
3579 char *less_equal;
a61af66fc99e Initial load
duke
parents:
diff changeset
3580 char *greater;
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3581 char *overflow;
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3582 char *no_overflow;
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3583 const char *equal_format = "eq";
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3584 const char *not_equal_format = "ne";
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3585 const char *less_format = "lt";
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3586 const char *greater_equal_format = "ge";
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3587 const char *less_equal_format = "le";
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3588 const char *greater_format = "gt";
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3589 const char *overflow_format = "o";
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3590 const char *no_overflow_format = "no";
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3591
a61af66fc99e Initial load
duke
parents:
diff changeset
3592 if (_curchar != '%') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3593 parse_err(SYNERR, "Missing '%%{' for 'cond_interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3594 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3596 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3597 if (_curchar != '{') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3598 parse_err(SYNERR, "Missing '%%{' for 'cond_interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3599 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3601 next_char(); // Skip '{'
a61af66fc99e Initial load
duke
parents:
diff changeset
3602 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3603 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
3604 char *field = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
3605 if (field == NULL) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3606 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%%}' ending interface.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3607 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3609 if ( strcmp(field,"equal") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3610 equal = interface_field_parse(&equal_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3612 else if ( strcmp(field,"not_equal") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3613 not_equal = interface_field_parse(&not_equal_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3615 else if ( strcmp(field,"less") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3616 less = interface_field_parse(&less_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3617 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3618 else if ( strcmp(field,"greater_equal") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3619 greater_equal = interface_field_parse(&greater_equal_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3621 else if ( strcmp(field,"less_equal") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3622 less_equal = interface_field_parse(&less_equal_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3624 else if ( strcmp(field,"greater") == 0 ) {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3625 greater = interface_field_parse(&greater_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3626 }
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3627 else if ( strcmp(field,"overflow") == 0 ) {
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3628 overflow = interface_field_parse(&overflow_format);
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3629 }
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3630 else if ( strcmp(field,"no_overflow") == 0 ) {
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3631 no_overflow = interface_field_parse(&no_overflow_format);
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3632 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3633 else {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3634 parse_err(SYNERR, "Expected keyword, base|index|scale|disp, or '%%}' ending interface.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3635 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3637 } while( _curchar != '%' );
a61af66fc99e Initial load
duke
parents:
diff changeset
3638 next_char(); // Skip '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3639 if ( _curchar != '}' ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3640 parse_err(SYNERR, "Missing '%%}' for 'interface' block.\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3641 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3643 next_char(); // Skip '}'
a61af66fc99e Initial load
duke
parents:
diff changeset
3644
a61af66fc99e Initial load
duke
parents:
diff changeset
3645 // Construct desired object and return
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3646 Interface *inter = new CondInterface(equal, equal_format,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3647 not_equal, not_equal_format,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3648 less, less_format,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3649 greater_equal, greater_equal_format,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3650 less_equal, less_equal_format,
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3651 greater, greater_format,
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3652 overflow, overflow_format,
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 7996
diff changeset
3653 no_overflow, no_overflow_format);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3654 return inter;
a61af66fc99e Initial load
duke
parents:
diff changeset
3655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3656
a61af66fc99e Initial load
duke
parents:
diff changeset
3657
a61af66fc99e Initial load
duke
parents:
diff changeset
3658 //------------------------------interface_field_parse--------------------------
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3659 char *ADLParser::interface_field_parse(const char ** format) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3660 char *iface_field = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3661
a61af66fc99e Initial load
duke
parents:
diff changeset
3662 // Get interface field
a61af66fc99e Initial load
duke
parents:
diff changeset
3663 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3664 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3665 parse_err(SYNERR, "Missing '(' at start of interface field.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3666 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3668 next_char(); // move past '('
a61af66fc99e Initial load
duke
parents:
diff changeset
3669 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3670 if ( _curchar != '0' && _curchar != '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3671 parse_err(SYNERR, "missing or invalid interface field contents.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3672 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3674 iface_field = get_rep_var_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
3675 if (iface_field == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3676 parse_err(SYNERR, "missing or invalid interface field contents.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3677 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3679 skipws();
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3680 if (format != NULL && _curchar == ',') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3681 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3682 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3683 if (_curchar != '"') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3684 parse_err(SYNERR, "Missing '\"' in field format .\n");
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3685 return NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3686 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3687 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3688 char *start = _ptr; // Record start of the next string
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3689 while ((_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3690 if (_curchar == '\\') next_char(); // superquote
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3691 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3692 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3693 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3694 if (_curchar != '"') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3695 parse_err(SYNERR, "Missing '\"' at end of field format .\n");
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3696 return NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3697 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3698 // If a string was found, terminate it and record in FormatRule
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3699 if ( start != _ptr ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3700 *_ptr = '\0'; // Terminate the string
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3701 *format = start;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3702 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3703 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3704 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3705 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3706 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3707 parse_err(SYNERR, "Missing ')' after interface field.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3708 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3710 next_char(); // move past ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
3711 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3712 if ( _curchar != ';' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3713 parse_err(SYNERR, "Missing ';' at end of interface field.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
3714 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3716 next_char(); // move past ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3717 skipws(); // be friendly to interface_parse()
a61af66fc99e Initial load
duke
parents:
diff changeset
3718
a61af66fc99e Initial load
duke
parents:
diff changeset
3719 return iface_field;
a61af66fc99e Initial load
duke
parents:
diff changeset
3720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3721
a61af66fc99e Initial load
duke
parents:
diff changeset
3722
a61af66fc99e Initial load
duke
parents:
diff changeset
3723 //------------------------------match_parse------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3724 MatchRule *ADLParser::match_parse(FormDict &operands) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3725 MatchRule *match; // Match Rule class for instruction/operand
a61af66fc99e Initial load
duke
parents:
diff changeset
3726 char *cnstr = NULL; // Code for constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
3727 int depth = 0; // Counter for matching parentheses
a61af66fc99e Initial load
duke
parents:
diff changeset
3728 int numleaves = 0; // Counter for number of leaves in rule
a61af66fc99e Initial load
duke
parents:
diff changeset
3729
a61af66fc99e Initial load
duke
parents:
diff changeset
3730 // Parse the match rule tree
a61af66fc99e Initial load
duke
parents:
diff changeset
3731 MatchNode *mnode = matchNode_parse(operands, depth, numleaves, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
3732
a61af66fc99e Initial load
duke
parents:
diff changeset
3733 // Either there is a block with a constructor, or a ';' here
a61af66fc99e Initial load
duke
parents:
diff changeset
3734 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3735 if ( _curchar == ';' ) { // Semicolon is valid terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
3736 cnstr = NULL; // no constructor for this form
a61af66fc99e Initial load
duke
parents:
diff changeset
3737 next_char(); // Move past the ';', replaced with '\0'
a61af66fc99e Initial load
duke
parents:
diff changeset
3738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3739 else if ((cnstr = find_cpp_block("match constructor")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3740 parse_err(SYNERR, "invalid construction of match rule\n"
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3741 "Missing ';' or invalid '%%{' and '%%}' constructor\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3742 return NULL; // No MatchRule to return
a61af66fc99e Initial load
duke
parents:
diff changeset
3743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3744 if (_AD._adl_debug > 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3745 if (cnstr) fprintf(stderr,"Match Constructor: %s\n", cnstr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3746 // Build new MatchRule object
a61af66fc99e Initial load
duke
parents:
diff changeset
3747 match = new MatchRule(_AD, mnode, depth, cnstr, numleaves);
a61af66fc99e Initial load
duke
parents:
diff changeset
3748 skipws(); // Skip any trailing whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3749 return match; // Return MatchRule object
a61af66fc99e Initial load
duke
parents:
diff changeset
3750 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3751
a61af66fc99e Initial load
duke
parents:
diff changeset
3752 //------------------------------format_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3753 FormatRule* ADLParser::format_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3754 char *desc = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3755 FormatRule *format = (new FormatRule(desc));
a61af66fc99e Initial load
duke
parents:
diff changeset
3756
a61af66fc99e Initial load
duke
parents:
diff changeset
3757 // Without expression form, MUST have a code block;
a61af66fc99e Initial load
duke
parents:
diff changeset
3758 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
3759 if ( _curchar == ';' ) { // Semicolon is valid terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
3760 desc = NULL; // no constructor for this form
a61af66fc99e Initial load
duke
parents:
diff changeset
3761 next_char(); // Move past the ';', replaced with '\0'
a61af66fc99e Initial load
duke
parents:
diff changeset
3762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3763 else if ( _curchar == '%' && *(_ptr+1) == '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3764 next_char(); // Move past the '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3765 next_char(); // Move past the '{'
a61af66fc99e Initial load
duke
parents:
diff changeset
3766
a61af66fc99e Initial load
duke
parents:
diff changeset
3767 skipws();
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3768 if (_curchar == '$') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3769 char* ident = get_rep_var_ident();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3770 if (strcmp(ident, "$$template") == 0) return template_parse();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3771 parse_err(SYNERR, "Unknown \"%s\" directive in format", ident);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3772 return NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3773 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3774 // Check for the opening '"' inside the format description
a61af66fc99e Initial load
duke
parents:
diff changeset
3775 if ( _curchar == '"' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3776 next_char(); // Move past the initial '"'
a61af66fc99e Initial load
duke
parents:
diff changeset
3777 if( _curchar == '"' ) { // Handle empty format string case
a61af66fc99e Initial load
duke
parents:
diff changeset
3778 *_ptr = '\0'; // Terminate empty string
a61af66fc99e Initial load
duke
parents:
diff changeset
3779 format->_strings.addName(_ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3781
a61af66fc99e Initial load
duke
parents:
diff changeset
3782 // Collect the parts of the format description
a61af66fc99e Initial load
duke
parents:
diff changeset
3783 // (1) strings that are passed through to tty->print
a61af66fc99e Initial load
duke
parents:
diff changeset
3784 // (2) replacement/substitution variable, preceeded by a '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
3785 // (3) multi-token ANSIY C style strings
a61af66fc99e Initial load
duke
parents:
diff changeset
3786 while ( true ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3787 if ( _curchar == '%' || _curchar == '\n' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3788 if ( _curchar != '"' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3789 parse_err(SYNERR, "missing '\"' at end of format block");
a61af66fc99e Initial load
duke
parents:
diff changeset
3790 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3793
a61af66fc99e Initial load
duke
parents:
diff changeset
3794 // (1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3795 // Check if there is a string to pass through to output
a61af66fc99e Initial load
duke
parents:
diff changeset
3796 char *start = _ptr; // Record start of the next string
a61af66fc99e Initial load
duke
parents:
diff changeset
3797 while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3798 if (_curchar == '\\') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3799 next_char(); // superquote
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3800 if ((_curchar == '$') || (_curchar == '%'))
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3801 // hack to avoid % escapes and warnings about undefined \ escapes
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3802 *(_ptr-1) = _curchar;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
3803 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3804 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
a61af66fc99e Initial load
duke
parents:
diff changeset
3805 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
3806 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3807 // If a string was found, terminate it and record in FormatRule
a61af66fc99e Initial load
duke
parents:
diff changeset
3808 if ( start != _ptr ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3809 *_ptr = '\0'; // Terminate the string
a61af66fc99e Initial load
duke
parents:
diff changeset
3810 format->_strings.addName(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
3811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3812
a61af66fc99e Initial load
duke
parents:
diff changeset
3813 // (2)
a61af66fc99e Initial load
duke
parents:
diff changeset
3814 // If we are at a replacement variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
3815 // copy it and record in FormatRule
a61af66fc99e Initial load
duke
parents:
diff changeset
3816 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3817 next_char(); // Move past the '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
3818 char* rep_var = get_ident(); // Nil terminate the variable name
a61af66fc99e Initial load
duke
parents:
diff changeset
3819 rep_var = strdup(rep_var);// Copy the string
a61af66fc99e Initial load
duke
parents:
diff changeset
3820 *_ptr = _curchar; // and replace Nil with original character
a61af66fc99e Initial load
duke
parents:
diff changeset
3821 format->_rep_vars.addName(rep_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
3822 // Add flag to _strings list indicating we should check _rep_vars
a61af66fc99e Initial load
duke
parents:
diff changeset
3823 format->_strings.addName(NameList::_signal);
a61af66fc99e Initial load
duke
parents:
diff changeset
3824 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3825
a61af66fc99e Initial load
duke
parents:
diff changeset
3826 // (3)
a61af66fc99e Initial load
duke
parents:
diff changeset
3827 // Allow very long strings to be broken up,
a61af66fc99e Initial load
duke
parents:
diff changeset
3828 // using the ANSI C syntax "foo\n" <newline> "bar"
a61af66fc99e Initial load
duke
parents:
diff changeset
3829 if ( _curchar == '"') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3830 next_char(); // Move past the '"'
a61af66fc99e Initial load
duke
parents:
diff changeset
3831 skipws(); // Skip white space before next string token
a61af66fc99e Initial load
duke
parents:
diff changeset
3832 if ( _curchar != '"') {
a61af66fc99e Initial load
duke
parents:
diff changeset
3833 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3834 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3835 // Found one. Skip both " and the whitespace in between.
a61af66fc99e Initial load
duke
parents:
diff changeset
3836 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
3837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3839 } // end while part of format description
a61af66fc99e Initial load
duke
parents:
diff changeset
3840
a61af66fc99e Initial load
duke
parents:
diff changeset
3841 // Check for closing '"' and '%}' in format description
a61af66fc99e Initial load
duke
parents:
diff changeset
3842 skipws(); // Move to closing '%}'
a61af66fc99e Initial load
duke
parents:
diff changeset
3843 if ( _curchar != '%' ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3844 parse_err(SYNERR, "non-blank characters between closing '\"' and '%%' in format");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3845 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3847 } // Done with format description inside
a61af66fc99e Initial load
duke
parents:
diff changeset
3848
a61af66fc99e Initial load
duke
parents:
diff changeset
3849 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3850 // Past format description, at '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3851 if ( _curchar != '%' || *(_ptr+1) != '}' ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3852 parse_err(SYNERR, "missing '%%}' at end of format block");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3853 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3855 next_char(); // Move past the '%'
a61af66fc99e Initial load
duke
parents:
diff changeset
3856 next_char(); // Move past the '}'
a61af66fc99e Initial load
duke
parents:
diff changeset
3857 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3858 else { // parameter list alone must terminate with a ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
3859 parse_err(SYNERR, "missing ';' after Format expression");
a61af66fc99e Initial load
duke
parents:
diff changeset
3860 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
3861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3862 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
3863 if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
3864
a61af66fc99e Initial load
duke
parents:
diff changeset
3865 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
3866 return format;
a61af66fc99e Initial load
duke
parents:
diff changeset
3867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3868
a61af66fc99e Initial load
duke
parents:
diff changeset
3869
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3870 //------------------------------template_parse-----------------------------------
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3871 FormatRule* ADLParser::template_parse(void) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3872 char *desc = NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3873 FormatRule *format = (new FormatRule(desc));
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3874
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3875 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3876 while ( (_curchar != '%') && (*(_ptr+1) != '}') ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3877
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3878 // (1)
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3879 // Check if there is a string to pass through to output
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3880 {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3881 char *start = _ptr; // Record start of the next string
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3882 while ((_curchar != '$') && ((_curchar != '%') || (*(_ptr+1) != '}')) ) {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3883 // If at the start of a comment, skip past it
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3884 if( (_curchar == '/') && ((*(_ptr+1) == '/') || (*(_ptr+1) == '*')) ) {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3885 skipws_no_preproc();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3886 } else {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3887 // ELSE advance to the next character, or start of the next line
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3888 next_char_or_line();
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3889 }
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3890 }
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3891 // If a string was found, terminate it and record in EncClass
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3892 if ( start != _ptr ) {
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3893 *_ptr = '\0'; // Terminate the string
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3894 // Add flag to _strings list indicating we should check _rep_vars
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3895 format->_strings.addName(NameList::_signal2);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3896 format->_strings.addName(start);
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3897 }
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3898 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3899
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3900 // (2)
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3901 // If we are at a replacement variable,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3902 // copy it and record in EncClass
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3903 if ( _curchar == '$' ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3904 // Found replacement Variable
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3905 char *rep_var = get_rep_var_ident_dup();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3906 if (strcmp(rep_var, "$emit") == 0) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3907 // switch to normal format parsing
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3908 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3909 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3910 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3911 // Check for the opening '"' inside the format description
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3912 if ( _curchar == '"' ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3913 next_char(); // Move past the initial '"'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3914 if( _curchar == '"' ) { // Handle empty format string case
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3915 *_ptr = '\0'; // Terminate empty string
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3916 format->_strings.addName(_ptr);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3917 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3918
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3919 // Collect the parts of the format description
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3920 // (1) strings that are passed through to tty->print
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3921 // (2) replacement/substitution variable, preceeded by a '$'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3922 // (3) multi-token ANSIY C style strings
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3923 while ( true ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3924 if ( _curchar == '%' || _curchar == '\n' ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3925 parse_err(SYNERR, "missing '\"' at end of format block");
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3926 return NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3927 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3928
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3929 // (1)
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3930 // Check if there is a string to pass through to output
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3931 char *start = _ptr; // Record start of the next string
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3932 while ((_curchar != '$') && (_curchar != '"') && (_curchar != '%') && (_curchar != '\n')) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3933 if (_curchar == '\\') next_char(); // superquote
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3934 if (_curchar == '\n') parse_err(SYNERR, "newline in string"); // unimplemented!
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3935 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3936 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3937 // If a string was found, terminate it and record in FormatRule
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3938 if ( start != _ptr ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3939 *_ptr = '\0'; // Terminate the string
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3940 format->_strings.addName(start);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3941 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3942
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3943 // (2)
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3944 // If we are at a replacement variable,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3945 // copy it and record in FormatRule
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3946 if ( _curchar == '$' ) {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3947 next_char(); // Move past the '$'
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3948 char* next_rep_var = get_ident(); // Nil terminate the variable name
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3949 next_rep_var = strdup(next_rep_var);// Copy the string
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3950 *_ptr = _curchar; // and replace Nil with original character
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
3951 format->_rep_vars.addName(next_rep_var);
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3952 // Add flag to _strings list indicating we should check _rep_vars
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3953 format->_strings.addName(NameList::_signal);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3954 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3955
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3956 // (3)
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3957 // Allow very long strings to be broken up,
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3958 // using the ANSI C syntax "foo\n" <newline> "bar"
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3959 if ( _curchar == '"') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3960 next_char(); // Move past the '"'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3961 skipws(); // Skip white space before next string token
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3962 if ( _curchar != '"') {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3963 break;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3964 } else {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3965 // Found one. Skip both " and the whitespace in between.
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3966 next_char();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3967 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3968 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3969 } // end while part of format description
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3970 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3971 } else {
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3972 // Add flag to _strings list indicating we should check _rep_vars
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3973 format->_rep_vars.addName(rep_var);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3974 // Add flag to _strings list indicating we should check _rep_vars
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3975 format->_strings.addName(NameList::_signal3);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3976 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3977 } // end while part of format description
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3978 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3979
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3980 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3981 // Past format description, at '%'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3982 if ( _curchar != '%' || *(_ptr+1) != '}' ) {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
3983 parse_err(SYNERR, "missing '%%}' at end of format block");
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3984 return NULL;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3985 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3986 next_char(); // Move past the '%'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3987 next_char(); // Move past the '}'
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3988
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3989 // Debug Stuff
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3990 if (_AD._adl_debug > 1) fprintf(stderr,"Format Rule: %s\n", desc);
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3991
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3992 skipws();
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3993 return format;
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3994 }
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3995
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
3996
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3997 //------------------------------effect_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
3998 void ADLParser::effect_parse(InstructForm *instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3999 char* desc = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4000
a61af66fc99e Initial load
duke
parents:
diff changeset
4001 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
4002 if (_curchar != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4003 parse_err(SYNERR, "missing '(' in effect definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4004 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4006 // Get list of effect-operand pairs and insert into dictionary
4120
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4007 else get_effectlist(instr->_effects, instr->_localNames, instr->_has_call);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4008
a61af66fc99e Initial load
duke
parents:
diff changeset
4009 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4010 if (_AD._adl_debug > 1) fprintf(stderr,"Effect description: %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4011 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4012 parse_err(SYNERR, "missing ';' in Effect definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4014 next_char(); // Skip ';'
a61af66fc99e Initial load
duke
parents:
diff changeset
4015
a61af66fc99e Initial load
duke
parents:
diff changeset
4016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4017
a61af66fc99e Initial load
duke
parents:
diff changeset
4018 //------------------------------expand_parse-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4019 ExpandRule* ADLParser::expand_parse(InstructForm *instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4020 char *ident, *ident2;
a61af66fc99e Initial load
duke
parents:
diff changeset
4021 NameAndList *instr_and_operands = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4022 ExpandRule *exp = new ExpandRule();
a61af66fc99e Initial load
duke
parents:
diff changeset
4023
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4024 // Expand is a block containing an ordered list of operands with initializers,
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4025 // or instructions, each of which has an ordered list of operands.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4026 // Check for block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
4027 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
4028 if ((_curchar != '%')
a61af66fc99e Initial load
duke
parents:
diff changeset
4029 || (next_char(), (_curchar != '{')) ) { // If not open block
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
4030 parse_err(SYNERR, "missing '%%{' in expand definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4031 return(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
4032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4033 next_char(); // Maintain the invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
4034 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
4035 ident = get_ident(); // Grab next identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
4036 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4037 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4038 continue;
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4039 }
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4040
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4041 // Check whether we should parse an instruction or operand.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4042 const Form *form = _globalNames[ident];
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4043 bool parse_oper = false;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4044 bool parse_ins = false;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4045 if (form == NULL) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4046 skipws();
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4047 // Check whether this looks like an instruction specification. If so,
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4048 // just parse the instruction. The declaration of the instruction is
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4049 // not needed here.
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4050 if (_curchar == '(') parse_ins = true;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4051 } else if (form->is_instruction()) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4052 parse_ins = true;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4053 } else if (form->is_operand()) {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4054 parse_oper = true;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4055 } else {
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4056 parse_err(SYNERR, "instruction/operand name expected at %s\n", ident);
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4057 continue;
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4058 }
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4059
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4060 if (parse_oper) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4061 // This is a new operand
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4062 OperandForm *oper = form->is_operand();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4063 if (oper == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4064 parse_err(SYNERR, "instruction/operand name expected at %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4065 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4066 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4067 // Throw the operand on the _newopers list
a61af66fc99e Initial load
duke
parents:
diff changeset
4068 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4069 ident = get_unique_ident(instr->_localNames,"Operand");
a61af66fc99e Initial load
duke
parents:
diff changeset
4070 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4071 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4072 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4074 exp->_newopers.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4075 // Add new operand to LocalNames
a61af66fc99e Initial load
duke
parents:
diff changeset
4076 instr->_localNames.Insert(ident, oper);
a61af66fc99e Initial load
duke
parents:
diff changeset
4077 // Grab any constructor code and save as a string
a61af66fc99e Initial load
duke
parents:
diff changeset
4078 char *c = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4079 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4080 if (_curchar == '%') { // Need a constructor for the operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4081 c = find_cpp_block("Operand Constructor");
a61af66fc99e Initial load
duke
parents:
diff changeset
4082 if (c == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4083 parse_err(SYNERR, "Invalid code block for operand constructor\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4084 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4086 // Add constructor to _newopconst Dict
a61af66fc99e Initial load
duke
parents:
diff changeset
4087 exp->_newopconst.Insert(ident, c);
a61af66fc99e Initial load
duke
parents:
diff changeset
4088 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4089 else if (_curchar != ';') { // If no constructor, need a ;
a61af66fc99e Initial load
duke
parents:
diff changeset
4090 parse_err(SYNERR, "Missing ; in expand rule operand declaration\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4091 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4092 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4093 else next_char(); // Skip the ;
a61af66fc99e Initial load
duke
parents:
diff changeset
4094 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4095 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4096 else {
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4097 assert(parse_ins, "sanity");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4098 // Add instruction to list
a61af66fc99e Initial load
duke
parents:
diff changeset
4099 instr_and_operands = new NameAndList(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4100 // Grab operands, build nameList of them, and then put into dictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
4101 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4102 if (_curchar != '(') { // Check for parenthesized operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
4103 parse_err(SYNERR, "missing '(' in expand instruction declaration\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4104 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4106 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
4107 next_char(); // skip open paren & comma characters
a61af66fc99e Initial load
duke
parents:
diff changeset
4108 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4109 if (_curchar == ')') break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4110 ident2 = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4111 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4112 if (ident2 == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4113 parse_err(SYNERR, "identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4114 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4115 } // Check that you have a valid operand
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
4116 const Form *form2 = instr->_localNames[ident2];
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
4117 if (!form2) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4118 parse_err(SYNERR, "operand name expected at %s\n", ident2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4119 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4120 }
14431
1410ad6b05f1 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 14428
diff changeset
4121 OperandForm *oper = form2->is_operand();
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
4122 if (oper == NULL && !form2->is_opclass()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4123 parse_err(SYNERR, "operand name expected at %s\n", ident2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4124 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4125 } // Add operand to list
a61af66fc99e Initial load
duke
parents:
diff changeset
4126 instr_and_operands->add_entry(ident2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4127 } while(_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
4128 if (_curchar != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4129 parse_err(SYNERR, "missing ')'in expand instruction declaration\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4130 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4132 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4133 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4134 parse_err(SYNERR, "missing ';'in expand instruction declaration\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4135 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
4136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4137 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4138
a61af66fc99e Initial load
duke
parents:
diff changeset
4139 // Record both instruction name and its operand list
a61af66fc99e Initial load
duke
parents:
diff changeset
4140 exp->add_instruction(instr_and_operands);
a61af66fc99e Initial load
duke
parents:
diff changeset
4141
a61af66fc99e Initial load
duke
parents:
diff changeset
4142 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4144
a61af66fc99e Initial load
duke
parents:
diff changeset
4145 } while(_curchar != '%');
a61af66fc99e Initial load
duke
parents:
diff changeset
4146 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4147 if (_curchar != '}') {
7996
39901f2f1abe 8007403: Incorrect format arguments in adlparse.cpp
mikael
parents: 6850
diff changeset
4148 parse_err(SYNERR, "missing '%%}' in expand rule definition\n");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4149 return(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
4150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4151 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4152
a61af66fc99e Initial load
duke
parents:
diff changeset
4153 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4154 if (_AD._adl_debug > 1) fprintf(stderr,"Expand Rule:\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4155
a61af66fc99e Initial load
duke
parents:
diff changeset
4156 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4157 return (exp);
a61af66fc99e Initial load
duke
parents:
diff changeset
4158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4159
a61af66fc99e Initial load
duke
parents:
diff changeset
4160 //------------------------------rewrite_parse----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4161 RewriteRule* ADLParser::rewrite_parse(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4162 char* params = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4163 char* desc = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4164
a61af66fc99e Initial load
duke
parents:
diff changeset
4165
a61af66fc99e Initial load
duke
parents:
diff changeset
4166 // This feature targeted for second generation description language.
a61af66fc99e Initial load
duke
parents:
diff changeset
4167
a61af66fc99e Initial load
duke
parents:
diff changeset
4168 skipws(); // Skip whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
4169 // Get parameters for rewrite
a61af66fc99e Initial load
duke
parents:
diff changeset
4170 if ((params = get_paren_expr("rewrite parameters")) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4171 parse_err(SYNERR, "missing '(' in rewrite rule\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4172 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4174 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4175 if (_AD._adl_debug > 1) fprintf(stderr,"Rewrite parameters: %s\n", params);
a61af66fc99e Initial load
duke
parents:
diff changeset
4176
a61af66fc99e Initial load
duke
parents:
diff changeset
4177 // For now, grab entire block;
a61af66fc99e Initial load
duke
parents:
diff changeset
4178 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4179 if ( (desc = find_cpp_block("rewrite block")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4180 parse_err(SYNERR, "incorrect or missing block for 'rewrite'.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4181 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4183 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4184 if (_AD._adl_debug > 1) fprintf(stderr,"Rewrite Rule: %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4185
a61af66fc99e Initial load
duke
parents:
diff changeset
4186 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4187 return (new RewriteRule(params,desc));
a61af66fc99e Initial load
duke
parents:
diff changeset
4188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4189
a61af66fc99e Initial load
duke
parents:
diff changeset
4190 //------------------------------attr_parse-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4191 Attribute *ADLParser::attr_parse(char* ident) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4192 Attribute *attrib; // Attribute class
a61af66fc99e Initial load
duke
parents:
diff changeset
4193 char *cost = NULL; // String representation of cost attribute
a61af66fc99e Initial load
duke
parents:
diff changeset
4194
a61af66fc99e Initial load
duke
parents:
diff changeset
4195 skipws(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
4196 if ( (cost = get_paren_expr("attribute")) == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4197 parse_err(SYNERR, "incorrect or missing expression for 'attribute'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4198 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4200 // Debug Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4201 if (_AD._adl_debug > 1) fprintf(stderr,"Attribute: %s\n", cost);
a61af66fc99e Initial load
duke
parents:
diff changeset
4202 if (_curchar != ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4203 parse_err(SYNERR, "missing ';' in attribute definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4204 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4206 next_char(); // Point after the terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
4207
a61af66fc99e Initial load
duke
parents:
diff changeset
4208 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4209 attrib = new Attribute(ident,cost,INS_ATTR); // Build new predicate object
a61af66fc99e Initial load
duke
parents:
diff changeset
4210 return attrib;
a61af66fc99e Initial load
duke
parents:
diff changeset
4211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4212
a61af66fc99e Initial load
duke
parents:
diff changeset
4213
a61af66fc99e Initial load
duke
parents:
diff changeset
4214 //------------------------------matchNode_parse--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4215 MatchNode *ADLParser::matchNode_parse(FormDict &operands, int &depth, int &numleaves, bool atroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4216 // Count depth of parenthesis nesting for both left and right children
a61af66fc99e Initial load
duke
parents:
diff changeset
4217 int lParens = depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
4218 int rParens = depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
4219
a61af66fc99e Initial load
duke
parents:
diff changeset
4220 // MatchNode objects for left, right, and root of subtree.
a61af66fc99e Initial load
duke
parents:
diff changeset
4221 MatchNode *lChild = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4222 MatchNode *rChild = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4223 char *token; // Identifier which may be opcode or operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4224
a61af66fc99e Initial load
duke
parents:
diff changeset
4225 // Match expression starts with a '('
a61af66fc99e Initial load
duke
parents:
diff changeset
4226 if (cur_char() != '(')
a61af66fc99e Initial load
duke
parents:
diff changeset
4227 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4228
a61af66fc99e Initial load
duke
parents:
diff changeset
4229 next_char(); // advance past '('
a61af66fc99e Initial load
duke
parents:
diff changeset
4230
a61af66fc99e Initial load
duke
parents:
diff changeset
4231 // Parse the opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
4232 token = get_ident(); // Get identifier, opcode
a61af66fc99e Initial load
duke
parents:
diff changeset
4233 if (token == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4234 parse_err(SYNERR, "missing opcode in match expression\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4235 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4237
a61af66fc99e Initial load
duke
parents:
diff changeset
4238 // Take note if we see one of a few special operations - those that are
a61af66fc99e Initial load
duke
parents:
diff changeset
4239 // treated differently on different architectures in the sense that on
a61af66fc99e Initial load
duke
parents:
diff changeset
4240 // one architecture there is a match rule and on another there isn't (so
a61af66fc99e Initial load
duke
parents:
diff changeset
4241 // a call will eventually be generated).
a61af66fc99e Initial load
duke
parents:
diff changeset
4242
a61af66fc99e Initial load
duke
parents:
diff changeset
4243 for (int i = _last_machine_leaf + 1; i < _last_opcode; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4244 if (strcmp(token, NodeClassNames[i]) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4245 _AD.has_match_rule(i, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
4246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4248
a61af66fc99e Initial load
duke
parents:
diff changeset
4249 // Lookup the root value in the operands dict to perform substitution
a61af66fc99e Initial load
duke
parents:
diff changeset
4250 const char *result = NULL; // Result type will be filled in later
a61af66fc99e Initial load
duke
parents:
diff changeset
4251 const char *name = token; // local name associated with this node
a61af66fc99e Initial load
duke
parents:
diff changeset
4252 const char *operation = token; // remember valid operation for later
a61af66fc99e Initial load
duke
parents:
diff changeset
4253 const Form *form = operands[token];
a61af66fc99e Initial load
duke
parents:
diff changeset
4254 OpClassForm *opcForm = form ? form->is_opclass() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4255 if (opcForm != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4256 // If this token is an entry in the local names table, record its type
a61af66fc99e Initial load
duke
parents:
diff changeset
4257 if (!opcForm->ideal_only()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4258 operation = opcForm->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4259 result = operation; // Operands result in their own type
a61af66fc99e Initial load
duke
parents:
diff changeset
4260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4261 // Otherwise it is an ideal type, and so, has no local name
a61af66fc99e Initial load
duke
parents:
diff changeset
4262 else name = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4264
a61af66fc99e Initial load
duke
parents:
diff changeset
4265 // Parse the operands
a61af66fc99e Initial load
duke
parents:
diff changeset
4266 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4267 if (cur_char() != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4268
a61af66fc99e Initial load
duke
parents:
diff changeset
4269 // Parse the left child
a61af66fc99e Initial load
duke
parents:
diff changeset
4270 if (strcmp(operation,"Set"))
a61af66fc99e Initial load
duke
parents:
diff changeset
4271 lChild = matchChild_parse(operands, lParens, numleaves, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
4272 else
a61af66fc99e Initial load
duke
parents:
diff changeset
4273 lChild = matchChild_parse(operands, lParens, numleaves, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
4274
a61af66fc99e Initial load
duke
parents:
diff changeset
4275 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4276 if (cur_char() != ')' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4277 if(strcmp(operation, "Set"))
a61af66fc99e Initial load
duke
parents:
diff changeset
4278 rChild = matchChild_parse(operands,rParens,numleaves,false);
a61af66fc99e Initial load
duke
parents:
diff changeset
4279 else
a61af66fc99e Initial load
duke
parents:
diff changeset
4280 rChild = matchChild_parse(operands,rParens,numleaves,true);
a61af66fc99e Initial load
duke
parents:
diff changeset
4281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4283
a61af66fc99e Initial load
duke
parents:
diff changeset
4284 // Check for required ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
4285 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4286 if (cur_char() != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4287 parse_err(SYNERR, "missing ')' in match expression\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4288 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4290 next_char(); // skip the ')'
a61af66fc99e Initial load
duke
parents:
diff changeset
4291
a61af66fc99e Initial load
duke
parents:
diff changeset
4292 MatchNode* mroot = new MatchNode(_AD,result,name,operation,lChild,rChild);
a61af66fc99e Initial load
duke
parents:
diff changeset
4293
a61af66fc99e Initial load
duke
parents:
diff changeset
4294 // If not the root, reduce this subtree to an internal operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4295 if (!atroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4296 mroot->build_internalop();
a61af66fc99e Initial load
duke
parents:
diff changeset
4297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4298 // depth is greater of left and right paths.
a61af66fc99e Initial load
duke
parents:
diff changeset
4299 depth = (lParens > rParens) ? lParens : rParens;
a61af66fc99e Initial load
duke
parents:
diff changeset
4300
a61af66fc99e Initial load
duke
parents:
diff changeset
4301 return mroot;
a61af66fc99e Initial load
duke
parents:
diff changeset
4302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4303
a61af66fc99e Initial load
duke
parents:
diff changeset
4304
a61af66fc99e Initial load
duke
parents:
diff changeset
4305 //------------------------------matchChild_parse-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4306 MatchNode *ADLParser::matchChild_parse(FormDict &operands, int &parens, int &numleaves, bool atroot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4307 MatchNode *child = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4308 const char *result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4309 const char *token = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4310 const char *opType = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4311
a61af66fc99e Initial load
duke
parents:
diff changeset
4312 if (cur_char() == '(') { // child is an operation
a61af66fc99e Initial load
duke
parents:
diff changeset
4313 ++parens;
a61af66fc99e Initial load
duke
parents:
diff changeset
4314 child = matchNode_parse(operands, parens, numleaves, atroot);
a61af66fc99e Initial load
duke
parents:
diff changeset
4315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4316 else { // child is an operand
a61af66fc99e Initial load
duke
parents:
diff changeset
4317 token = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4318 const Form *form = operands[token];
a61af66fc99e Initial load
duke
parents:
diff changeset
4319 OpClassForm *opcForm = form ? form->is_opclass() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4320 if (opcForm != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4321 opType = opcForm->_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4322 result = opcForm->_ident; // an operand's result matches its type
a61af66fc99e Initial load
duke
parents:
diff changeset
4323 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4324 parse_err(SYNERR, "undefined operand %s in match rule\n", token);
a61af66fc99e Initial load
duke
parents:
diff changeset
4325 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4327
a61af66fc99e Initial load
duke
parents:
diff changeset
4328 if (opType == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4329 parse_err(SYNERR, "missing type for argument '%s'\n", token);
a61af66fc99e Initial load
duke
parents:
diff changeset
4330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4331
a61af66fc99e Initial load
duke
parents:
diff changeset
4332 child = new MatchNode(_AD, result, token, opType);
a61af66fc99e Initial load
duke
parents:
diff changeset
4333 ++numleaves;
a61af66fc99e Initial load
duke
parents:
diff changeset
4334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4335
a61af66fc99e Initial load
duke
parents:
diff changeset
4336 return child;
a61af66fc99e Initial load
duke
parents:
diff changeset
4337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4338
a61af66fc99e Initial load
duke
parents:
diff changeset
4339
a61af66fc99e Initial load
duke
parents:
diff changeset
4340
a61af66fc99e Initial load
duke
parents:
diff changeset
4341 // ******************** Private Utility Functions *************************
a61af66fc99e Initial load
duke
parents:
diff changeset
4342
a61af66fc99e Initial load
duke
parents:
diff changeset
4343
a61af66fc99e Initial load
duke
parents:
diff changeset
4344 char* ADLParser::find_cpp_block(const char* description) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4345 char *next; // Pointer for finding block delimiters
a61af66fc99e Initial load
duke
parents:
diff changeset
4346 char* cppBlock = NULL; // Beginning of C++ code block
a61af66fc99e Initial load
duke
parents:
diff changeset
4347
a61af66fc99e Initial load
duke
parents:
diff changeset
4348 if (_curchar == '%') { // Encoding is a C++ expression
a61af66fc99e Initial load
duke
parents:
diff changeset
4349 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4350 if (_curchar != '{') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4351 parse_err(SYNERR, "missing '{' in %s \n", description);
a61af66fc99e Initial load
duke
parents:
diff changeset
4352 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4354 next_char(); // Skip block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
4355 skipws_no_preproc(); // Skip leading whitespace
a61af66fc99e Initial load
duke
parents:
diff changeset
4356 cppBlock = _ptr; // Point to start of expression
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4357 int line = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4358 next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4359 while(((_curchar != '%') || (*next != '}')) && (_curchar != '\0')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4360 next_char_or_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
4361 next = _ptr+1; // Maintain the next pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
4362 } // Grab string
a61af66fc99e Initial load
duke
parents:
diff changeset
4363 if (_curchar == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4364 parse_err(SYNERR, "invalid termination of %s \n", description);
a61af66fc99e Initial load
duke
parents:
diff changeset
4365 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4367 *_ptr = '\0'; // Terminate string
a61af66fc99e Initial load
duke
parents:
diff changeset
4368 _ptr += 2; // Skip block delimiter
a61af66fc99e Initial load
duke
parents:
diff changeset
4369 _curchar = *_ptr; // Maintain invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
4370
a61af66fc99e Initial load
duke
parents:
diff changeset
4371 // Prepend location descriptor, for debugging.
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4372 if (_AD._adlocation_debug) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4373 char* location = get_line_string(line);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4374 char* end_loc = end_line_marker();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4375 char* result = (char *)malloc(strlen(location) + strlen(cppBlock) + strlen(end_loc) + 1);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4376 strcpy(result, location);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4377 strcat(result, cppBlock);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4378 strcat(result, end_loc);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4379 cppBlock = result;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4380 free(location);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4381 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4383
a61af66fc99e Initial load
duke
parents:
diff changeset
4384 return cppBlock;
a61af66fc99e Initial load
duke
parents:
diff changeset
4385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4386
a61af66fc99e Initial load
duke
parents:
diff changeset
4387 // Move to the closing token of the expression we are currently at,
a61af66fc99e Initial load
duke
parents:
diff changeset
4388 // as defined by stop_chars. Match parens and quotes.
a61af66fc99e Initial load
duke
parents:
diff changeset
4389 char* ADLParser::get_expr(const char *desc, const char *stop_chars) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4390 char* expr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4391 int paren = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4392
a61af66fc99e Initial load
duke
parents:
diff changeset
4393 expr = _ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4394 while (paren > 0 || !strchr(stop_chars, _curchar)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4395 if (_curchar == '(') { // Down level of nesting
a61af66fc99e Initial load
duke
parents:
diff changeset
4396 paren++; // Bump the parenthesis counter
a61af66fc99e Initial load
duke
parents:
diff changeset
4397 next_char(); // maintain the invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
4398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4399 else if (_curchar == ')') { // Up one level of nesting
a61af66fc99e Initial load
duke
parents:
diff changeset
4400 if (paren == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4401 // Paren underflow: We didn't encounter the required stop-char.
a61af66fc99e Initial load
duke
parents:
diff changeset
4402 parse_err(SYNERR, "too many )'s, did not find %s after %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4403 stop_chars, desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4404 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4406 paren--; // Drop the parenthesis counter
a61af66fc99e Initial load
duke
parents:
diff changeset
4407 next_char(); // Maintain the invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
4408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4409 else if (_curchar == '"' || _curchar == '\'') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4410 int qchar = _curchar;
a61af66fc99e Initial load
duke
parents:
diff changeset
4411 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4412 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4413 if (_curchar == qchar) { next_char(); break; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4414 if (_curchar == '\\') next_char(); // superquote
a61af66fc99e Initial load
duke
parents:
diff changeset
4415 if (_curchar == '\n' || _curchar == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4416 parse_err(SYNERR, "newline in string in %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4417 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4418 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4421 else if (_curchar == '%' && (_ptr[1] == '{' || _ptr[1] == '}')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4422 // Make sure we do not stray into the next ADLC-level form.
a61af66fc99e Initial load
duke
parents:
diff changeset
4423 parse_err(SYNERR, "unexpected %%%c in %s\n", _ptr[1], desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4424 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4426 else if (_curchar == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4427 parse_err(SYNERR, "unexpected EOF in %s\n", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4428 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4430 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4431 // Always walk over whitespace, comments, preprocessor directives, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
4432 char* pre_skip_ptr = _ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4433 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4434 // If the parser declined to make progress on whitespace,
a61af66fc99e Initial load
duke
parents:
diff changeset
4435 // skip the next character, which is therefore NOT whitespace.
a61af66fc99e Initial load
duke
parents:
diff changeset
4436 if (pre_skip_ptr == _ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4437 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4438 } else if (pre_skip_ptr+strlen(pre_skip_ptr) != _ptr+strlen(_ptr)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4439 parse_err(SYNERR, "unimplemented: preprocessor must not elide subexpression in %s", desc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4443
a61af66fc99e Initial load
duke
parents:
diff changeset
4444 assert(strchr(stop_chars, _curchar), "non-null return must be at stop-char");
a61af66fc99e Initial load
duke
parents:
diff changeset
4445 *_ptr = '\0'; // Replace ')' or other stop-char with '\0'
a61af66fc99e Initial load
duke
parents:
diff changeset
4446 return expr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4448
a61af66fc99e Initial load
duke
parents:
diff changeset
4449 // Helper function around get_expr
a61af66fc99e Initial load
duke
parents:
diff changeset
4450 // Sets _curchar to '(' so that get_paren_expr will search for a matching ')'
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4451 char *ADLParser::get_paren_expr(const char *description, bool include_location) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4452 int line = linenum();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4453 if (_curchar != '(') // Escape if not valid starting position
a61af66fc99e Initial load
duke
parents:
diff changeset
4454 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4455 next_char(); // Skip the required initial paren.
a61af66fc99e Initial load
duke
parents:
diff changeset
4456 char *token2 = get_expr(description, ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
4457 if (_curchar == ')')
a61af66fc99e Initial load
duke
parents:
diff changeset
4458 next_char(); // Skip required final paren.
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4459 int junk = 0;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4460 if (include_location && _AD._adlocation_debug && !is_int_token(token2, junk)) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4461 // Prepend location descriptor, for debugging.
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4462 char* location = get_line_string(line);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4463 char* end_loc = end_line_marker();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4464 char* result = (char *)malloc(strlen(location) + strlen(token2) + strlen(end_loc) + 1);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4465 strcpy(result, location);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4466 strcat(result, token2);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4467 strcat(result, end_loc);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4468 token2 = result;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4469 free(location);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4470 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4471 return token2;
a61af66fc99e Initial load
duke
parents:
diff changeset
4472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4473
a61af66fc99e Initial load
duke
parents:
diff changeset
4474 //------------------------------get_ident_common-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4475 // Looks for an identifier in the buffer, and turns it into a null terminated
a61af66fc99e Initial load
duke
parents:
diff changeset
4476 // string(still inside the file buffer). Returns a pointer to the string or
a61af66fc99e Initial load
duke
parents:
diff changeset
4477 // NULL if some other token is found instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
4478 char *ADLParser::get_ident_common(bool do_preproc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4479 register char c;
a61af66fc99e Initial load
duke
parents:
diff changeset
4480 char *start; // Pointer to start of token
a61af66fc99e Initial load
duke
parents:
diff changeset
4481 char *end; // Pointer to end of token
a61af66fc99e Initial load
duke
parents:
diff changeset
4482
a61af66fc99e Initial load
duke
parents:
diff changeset
4483 if( _curline == NULL ) // Return NULL at EOF.
a61af66fc99e Initial load
duke
parents:
diff changeset
4484 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4485
a61af66fc99e Initial load
duke
parents:
diff changeset
4486 skipws_common(do_preproc); // Skip whitespace before identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
4487 start = end = _ptr; // Start points at first character
a61af66fc99e Initial load
duke
parents:
diff changeset
4488 end--; // unwind end by one to prepare for loop
a61af66fc99e Initial load
duke
parents:
diff changeset
4489 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
4490 end++; // Increment end pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
4491 c = *end; // Grab character to test
a61af66fc99e Initial load
duke
parents:
diff changeset
4492 } while ( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))
a61af66fc99e Initial load
duke
parents:
diff changeset
4493 || ((c >= '0') && (c <= '9'))
a61af66fc99e Initial load
duke
parents:
diff changeset
4494 || ((c == '_')) || ((c == ':')) || ((c == '#')) );
a61af66fc99e Initial load
duke
parents:
diff changeset
4495 if (start == end) { // We popped out on the first try
6850
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4496 // It can occur that `start' contains the rest of the input file.
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4497 // In this case the output should be truncated.
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4498 if (strlen(start) > 24) {
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4499 char buf[32];
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4500 strncpy(buf, start, 20);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4501 buf[20] = '\0';
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4502 strcat(buf, "[...]");
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4503 parse_err(SYNERR, "Identifier expected, but found '%s'.", buf);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4504 } else {
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4505 parse_err(SYNERR, "Identifier expected, but found '%s'.", start);
d336b3173277 8000592: Improve adlc usability
kvn
parents: 6179
diff changeset
4506 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4507 start = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4508 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4509 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4510 _curchar = c; // Save the first character of next token
a61af66fc99e Initial load
duke
parents:
diff changeset
4511 *end = '\0'; // NULL terminate the string in place
a61af66fc99e Initial load
duke
parents:
diff changeset
4512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4513 _ptr = end; // Reset _ptr to point to next char after token
a61af66fc99e Initial load
duke
parents:
diff changeset
4514
a61af66fc99e Initial load
duke
parents:
diff changeset
4515 // Make sure we do not try to use #defined identifiers. If start is
a61af66fc99e Initial load
duke
parents:
diff changeset
4516 // NULL an error was already reported.
a61af66fc99e Initial load
duke
parents:
diff changeset
4517 if (do_preproc && start != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4518 const char* def = _AD.get_preproc_def(start);
a61af66fc99e Initial load
duke
parents:
diff changeset
4519 if (def != NULL && strcmp(def, start)) {
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4520 const char* def1 = def;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4521 const char* def2 = _AD.get_preproc_def(def1);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4522 // implement up to 2 levels of #define
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4523 if (def2 != NULL && strcmp(def2, def1)) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4524 def = def2;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4525 const char* def3 = _AD.get_preproc_def(def2);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4526 if (def3 != NULL && strcmp(def3, def2) && strcmp(def3, def1)) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4527 parse_err(SYNERR, "unimplemented: using %s defined as %s => %s => %s",
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4528 start, def1, def2, def3);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4529 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4531 start = strdup(def);
a61af66fc99e Initial load
duke
parents:
diff changeset
4532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4534
a61af66fc99e Initial load
duke
parents:
diff changeset
4535 return start; // Pointer to token in filebuf
a61af66fc99e Initial load
duke
parents:
diff changeset
4536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4537
a61af66fc99e Initial load
duke
parents:
diff changeset
4538 //------------------------------get_ident_dup----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4539 // Looks for an identifier in the buffer, and returns a duplicate
a61af66fc99e Initial load
duke
parents:
diff changeset
4540 // or NULL if some other token is found instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
4541 char *ADLParser::get_ident_dup(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4542 char *ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4543
a61af66fc99e Initial load
duke
parents:
diff changeset
4544 // Duplicate an identifier before returning and restore string.
a61af66fc99e Initial load
duke
parents:
diff changeset
4545 if( ident != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4546 ident = strdup(ident); // Copy the string
a61af66fc99e Initial load
duke
parents:
diff changeset
4547 *_ptr = _curchar; // and replace Nil with original character
a61af66fc99e Initial load
duke
parents:
diff changeset
4548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4549
a61af66fc99e Initial load
duke
parents:
diff changeset
4550 return ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4551 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4552
a61af66fc99e Initial load
duke
parents:
diff changeset
4553 //----------------------get_ident_or_literal_constant--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4554 // Looks for an identifier in the buffer, or a parenthesized expression.
a61af66fc99e Initial load
duke
parents:
diff changeset
4555 char *ADLParser::get_ident_or_literal_constant(const char* description) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4556 char* param = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4557 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4558 if (_curchar == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4559 // Grab a constant expression.
a61af66fc99e Initial load
duke
parents:
diff changeset
4560 param = get_paren_expr(description);
a61af66fc99e Initial load
duke
parents:
diff changeset
4561 if (param[0] != '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4562 char* buf = (char*) malloc(strlen(param) + 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
4563 sprintf(buf, "(%s)", param);
a61af66fc99e Initial load
duke
parents:
diff changeset
4564 param = buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
4565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4566 assert(is_literal_constant(param),
a61af66fc99e Initial load
duke
parents:
diff changeset
4567 "expr must be recognizable as a constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
4568 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4569 param = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4571 return param;
a61af66fc99e Initial load
duke
parents:
diff changeset
4572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4573
a61af66fc99e Initial load
duke
parents:
diff changeset
4574 //------------------------------get_rep_var_ident-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4575 // Do NOT duplicate,
a61af66fc99e Initial load
duke
parents:
diff changeset
4576 // Leave nil terminator in buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
4577 // Preserve initial '$'(s) in string
a61af66fc99e Initial load
duke
parents:
diff changeset
4578 char *ADLParser::get_rep_var_ident(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4579 // Remember starting point
a61af66fc99e Initial load
duke
parents:
diff changeset
4580 char *rep_var = _ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4581
a61af66fc99e Initial load
duke
parents:
diff changeset
4582 // Check for replacement variable indicator '$' and pass if present
a61af66fc99e Initial load
duke
parents:
diff changeset
4583 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4584 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4585 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4586 // Check for a subfield indicator, a second '$', and pass if present
a61af66fc99e Initial load
duke
parents:
diff changeset
4587 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4588 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4590
a61af66fc99e Initial load
duke
parents:
diff changeset
4591 // Check for a control indicator, a third '$':
a61af66fc99e Initial load
duke
parents:
diff changeset
4592 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4593 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4595
a61af66fc99e Initial load
duke
parents:
diff changeset
4596 // Check for more than three '$'s in sequence, SYNERR
a61af66fc99e Initial load
duke
parents:
diff changeset
4597 if( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4598 parse_err(SYNERR, "Replacement variables and field specifiers can not start with '$$$$'");
a61af66fc99e Initial load
duke
parents:
diff changeset
4599 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4600 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4602
a61af66fc99e Initial load
duke
parents:
diff changeset
4603 // Nil terminate the variable name following the '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
4604 char *rep_var_name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4605 assert( rep_var_name != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
4606 "Missing identifier after replacement variable indicator '$'");
a61af66fc99e Initial load
duke
parents:
diff changeset
4607
a61af66fc99e Initial load
duke
parents:
diff changeset
4608 return rep_var;
a61af66fc99e Initial load
duke
parents:
diff changeset
4609 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4610
a61af66fc99e Initial load
duke
parents:
diff changeset
4611
a61af66fc99e Initial load
duke
parents:
diff changeset
4612
a61af66fc99e Initial load
duke
parents:
diff changeset
4613 //------------------------------get_rep_var_ident_dup-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4614 // Return the next replacement variable identifier, skipping first '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
4615 // given a pointer into a line of the buffer.
a61af66fc99e Initial load
duke
parents:
diff changeset
4616 // Null terminates string, still inside the file buffer,
a61af66fc99e Initial load
duke
parents:
diff changeset
4617 // Returns a pointer to a copy of the string, or NULL on failure
a61af66fc99e Initial load
duke
parents:
diff changeset
4618 char *ADLParser::get_rep_var_ident_dup(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4619 if( _curchar != '$' ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4620
a61af66fc99e Initial load
duke
parents:
diff changeset
4621 next_char(); // Move past the '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
4622 char *rep_var = _ptr; // Remember starting point
a61af66fc99e Initial load
duke
parents:
diff changeset
4623
a61af66fc99e Initial load
duke
parents:
diff changeset
4624 // Check for a subfield indicator, a second '$':
a61af66fc99e Initial load
duke
parents:
diff changeset
4625 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4626 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4628
a61af66fc99e Initial load
duke
parents:
diff changeset
4629 // Check for a control indicator, a third '$':
a61af66fc99e Initial load
duke
parents:
diff changeset
4630 if ( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4631 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4633
a61af66fc99e Initial load
duke
parents:
diff changeset
4634 // Check for more than three '$'s in sequence, SYNERR
a61af66fc99e Initial load
duke
parents:
diff changeset
4635 if( _curchar == '$' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4636 parse_err(SYNERR, "Replacement variables and field specifiers can not start with '$$$$'");
a61af66fc99e Initial load
duke
parents:
diff changeset
4637 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4638 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4640
a61af66fc99e Initial load
duke
parents:
diff changeset
4641 // Nil terminate the variable name following the '$'
a61af66fc99e Initial load
duke
parents:
diff changeset
4642 char *rep_var_name = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4643 assert( rep_var_name != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
4644 "Missing identifier after replacement variable indicator '$'");
a61af66fc99e Initial load
duke
parents:
diff changeset
4645 rep_var = strdup(rep_var); // Copy the string
a61af66fc99e Initial load
duke
parents:
diff changeset
4646 *_ptr = _curchar; // and replace Nil with original character
a61af66fc99e Initial load
duke
parents:
diff changeset
4647
a61af66fc99e Initial load
duke
parents:
diff changeset
4648 return rep_var;
a61af66fc99e Initial load
duke
parents:
diff changeset
4649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4650
a61af66fc99e Initial load
duke
parents:
diff changeset
4651
a61af66fc99e Initial load
duke
parents:
diff changeset
4652 //------------------------------get_unique_ident------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4653 // Looks for an identifier in the buffer, terminates it with a NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
4654 // and checks that it is unique
a61af66fc99e Initial load
duke
parents:
diff changeset
4655 char *ADLParser::get_unique_ident(FormDict& dict, const char* nameDescription){
a61af66fc99e Initial load
duke
parents:
diff changeset
4656 char* ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4657
a61af66fc99e Initial load
duke
parents:
diff changeset
4658 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4659 parse_err(SYNERR, "missing %s identifier at %c\n", nameDescription, _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4661 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4662 if (dict[ident] != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4663 parse_err(SYNERR, "duplicate name %s for %s\n", ident, nameDescription);
a61af66fc99e Initial load
duke
parents:
diff changeset
4664 ident = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4665 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4667
a61af66fc99e Initial load
duke
parents:
diff changeset
4668 return ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4670
a61af66fc99e Initial load
duke
parents:
diff changeset
4671
a61af66fc99e Initial load
duke
parents:
diff changeset
4672 //------------------------------get_int----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4673 // Looks for a character string integer in the buffer, and turns it into an int
a61af66fc99e Initial load
duke
parents:
diff changeset
4674 // invokes a parse_err if the next token is not an integer.
a61af66fc99e Initial load
duke
parents:
diff changeset
4675 // This routine does not leave the integer null-terminated.
a61af66fc99e Initial load
duke
parents:
diff changeset
4676 int ADLParser::get_int(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4677 register char c;
a61af66fc99e Initial load
duke
parents:
diff changeset
4678 char *start; // Pointer to start of token
a61af66fc99e Initial load
duke
parents:
diff changeset
4679 char *end; // Pointer to end of token
a61af66fc99e Initial load
duke
parents:
diff changeset
4680 int result; // Storage for integer result
a61af66fc99e Initial load
duke
parents:
diff changeset
4681
a61af66fc99e Initial load
duke
parents:
diff changeset
4682 if( _curline == NULL ) // Return NULL at EOF.
603
dbbe28fc66b5 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 488
diff changeset
4683 return 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4684
a61af66fc99e Initial load
duke
parents:
diff changeset
4685 skipws(); // Skip whitespace before identifier
a61af66fc99e Initial load
duke
parents:
diff changeset
4686 start = end = _ptr; // Start points at first character
a61af66fc99e Initial load
duke
parents:
diff changeset
4687 c = *end; // Grab character to test
a61af66fc99e Initial load
duke
parents:
diff changeset
4688 while ((c >= '0') && (c <= '9')
a61af66fc99e Initial load
duke
parents:
diff changeset
4689 || ((c == '-') && (end == start))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4690 end++; // Increment end pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
4691 c = *end; // Grab character to test
a61af66fc99e Initial load
duke
parents:
diff changeset
4692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4693 if (start == end) { // We popped out on the first try
a61af66fc99e Initial load
duke
parents:
diff changeset
4694 parse_err(SYNERR, "integer expected at %c\n", c);
a61af66fc99e Initial load
duke
parents:
diff changeset
4695 result = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4697 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4698 _curchar = c; // Save the first character of next token
a61af66fc99e Initial load
duke
parents:
diff changeset
4699 *end = '\0'; // NULL terminate the string in place
a61af66fc99e Initial load
duke
parents:
diff changeset
4700 result = atoi(start); // Convert the string to an integer
a61af66fc99e Initial load
duke
parents:
diff changeset
4701 *end = _curchar; // Restore buffer to original condition
a61af66fc99e Initial load
duke
parents:
diff changeset
4702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4703
a61af66fc99e Initial load
duke
parents:
diff changeset
4704 // Reset _ptr to next char after token
a61af66fc99e Initial load
duke
parents:
diff changeset
4705 _ptr = end;
a61af66fc99e Initial load
duke
parents:
diff changeset
4706
a61af66fc99e Initial load
duke
parents:
diff changeset
4707 return result; // integer
a61af66fc99e Initial load
duke
parents:
diff changeset
4708 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4709
a61af66fc99e Initial load
duke
parents:
diff changeset
4710
a61af66fc99e Initial load
duke
parents:
diff changeset
4711 //------------------------------get_relation_dup------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4712 // Looks for a relational operator in the buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
4713 // invokes a parse_err if the next token is not a relation
a61af66fc99e Initial load
duke
parents:
diff changeset
4714 // This routine creates a duplicate of the string in the buffer.
a61af66fc99e Initial load
duke
parents:
diff changeset
4715 char *ADLParser::get_relation_dup(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4716 char *result = NULL; // relational operator being returned
a61af66fc99e Initial load
duke
parents:
diff changeset
4717
a61af66fc99e Initial load
duke
parents:
diff changeset
4718 if( _curline == NULL ) // Return NULL at EOF.
a61af66fc99e Initial load
duke
parents:
diff changeset
4719 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4720
a61af66fc99e Initial load
duke
parents:
diff changeset
4721 skipws(); // Skip whitespace before relation
a61af66fc99e Initial load
duke
parents:
diff changeset
4722 char *start = _ptr; // Store start of relational operator
a61af66fc99e Initial load
duke
parents:
diff changeset
4723 char first = *_ptr; // the first character
a61af66fc99e Initial load
duke
parents:
diff changeset
4724 if( (first == '=') || (first == '!') || (first == '<') || (first == '>') ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4725 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4726 char second = *_ptr; // the second character
a61af66fc99e Initial load
duke
parents:
diff changeset
4727 if( (second == '=') ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4728 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
4729 char tmp = *_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4730 *_ptr = '\0'; // NULL terminate
a61af66fc99e Initial load
duke
parents:
diff changeset
4731 result = strdup(start); // Duplicate the string
a61af66fc99e Initial load
duke
parents:
diff changeset
4732 *_ptr = tmp; // restore buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
4733 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4734 parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4736 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4737 parse_err(SYNERR, "relational operator expected at %s\n", _ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4739
a61af66fc99e Initial load
duke
parents:
diff changeset
4740 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
4741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4742
a61af66fc99e Initial load
duke
parents:
diff changeset
4743
a61af66fc99e Initial load
duke
parents:
diff changeset
4744
a61af66fc99e Initial load
duke
parents:
diff changeset
4745 //------------------------------get_oplist-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4746 // Looks for identifier pairs where first must be the name of an operand, and
a61af66fc99e Initial load
duke
parents:
diff changeset
4747 // second must be a name unique in the scope of this instruction. Stores the
a61af66fc99e Initial load
duke
parents:
diff changeset
4748 // names with a pointer to the OpClassForm of their type in a local name table.
a61af66fc99e Initial load
duke
parents:
diff changeset
4749 void ADLParser::get_oplist(NameList &parameters, FormDict &operands) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4750 OpClassForm *opclass = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4751 char *ident = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4752
a61af66fc99e Initial load
duke
parents:
diff changeset
4753 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
4754 next_char(); // skip open paren & comma characters
a61af66fc99e Initial load
duke
parents:
diff changeset
4755 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4756 if (_curchar == ')') break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4757
a61af66fc99e Initial load
duke
parents:
diff changeset
4758 // Get operand type, and check it against global name table
a61af66fc99e Initial load
duke
parents:
diff changeset
4759 ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4760 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4761 parse_err(SYNERR, "optype identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4762 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4764 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4765 const Form *form = _globalNames[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
4766 if( form == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4767 parse_err(SYNERR, "undefined operand type %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4768 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4770
a61af66fc99e Initial load
duke
parents:
diff changeset
4771 // Check for valid operand type
a61af66fc99e Initial load
duke
parents:
diff changeset
4772 OpClassForm *opc = form->is_opclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
4773 OperandForm *oper = form->is_operand();
a61af66fc99e Initial load
duke
parents:
diff changeset
4774 if((oper == NULL) && (opc == NULL)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4775 parse_err(SYNERR, "identifier %s not operand type\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4776 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4778 opclass = opc;
a61af66fc99e Initial load
duke
parents:
diff changeset
4779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4780 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4781 if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Type: %s\t", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4782
a61af66fc99e Initial load
duke
parents:
diff changeset
4783 // Get name of operand and add it to local name table
a61af66fc99e Initial load
duke
parents:
diff changeset
4784 if( (ident = get_unique_ident(operands, "operand")) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4785 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4787 // Parameter names must not be global names.
a61af66fc99e Initial load
duke
parents:
diff changeset
4788 if( _globalNames[ident] != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4789 parse_err(SYNERR, "Reuse of global name %s as operand.\n",ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4790 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4792 operands.Insert(ident, opclass);
a61af66fc99e Initial load
duke
parents:
diff changeset
4793 parameters.addName(ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4794
a61af66fc99e Initial load
duke
parents:
diff changeset
4795 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4796 if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Name: %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4797 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4798 } while(_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
4799
a61af66fc99e Initial load
duke
parents:
diff changeset
4800 if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4801 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4802 next_char(); // set current character position past the close paren
a61af66fc99e Initial load
duke
parents:
diff changeset
4803 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4805
a61af66fc99e Initial load
duke
parents:
diff changeset
4806
a61af66fc99e Initial load
duke
parents:
diff changeset
4807 //------------------------------get_effectlist---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4808 // Looks for identifier pairs where first must be the name of a pre-defined,
a61af66fc99e Initial load
duke
parents:
diff changeset
4809 // effect, and the second must be the name of an operand defined in the
a61af66fc99e Initial load
duke
parents:
diff changeset
4810 // operand list of this instruction. Stores the names with a pointer to the
a61af66fc99e Initial load
duke
parents:
diff changeset
4811 // effect form in a local effects table.
4120
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4812 void ADLParser::get_effectlist(FormDict &effects, FormDict &operands, bool& has_call) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4813 OperandForm *opForm;
a61af66fc99e Initial load
duke
parents:
diff changeset
4814 Effect *eForm;
a61af66fc99e Initial load
duke
parents:
diff changeset
4815 char *ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
4816
a61af66fc99e Initial load
duke
parents:
diff changeset
4817 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
4818 next_char(); // skip open paren & comma characters
a61af66fc99e Initial load
duke
parents:
diff changeset
4819 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4820 if (_curchar == ')') break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4821
a61af66fc99e Initial load
duke
parents:
diff changeset
4822 // Get effect type, and check it against global name table
a61af66fc99e Initial load
duke
parents:
diff changeset
4823 ident = get_ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
4824 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4825 parse_err(SYNERR, "effect type identifier expected at %c\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4826 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4827 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4828 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4829 // Check for valid effect type
a61af66fc99e Initial load
duke
parents:
diff changeset
4830 const Form *form = _globalNames[ident];
a61af66fc99e Initial load
duke
parents:
diff changeset
4831 if( form == NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4832 parse_err(SYNERR, "undefined effect type %s\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4833 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4834 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4835 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4836 if( (eForm = form->is_effect()) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4837 parse_err(SYNERR, "identifier %s not effect type\n", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4838 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4842 // Debugging Stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
4843 if (_AD._adl_debug > 1) fprintf(stderr, "\tEffect Type: %s\t", ident);
a61af66fc99e Initial load
duke
parents:
diff changeset
4844 skipws();
4120
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4845 if (eForm->is(Component::CALL)) {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4846 if (_AD._adl_debug > 1) fprintf(stderr, "\n");
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4847 has_call = true;
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4848 } else {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4849 // Get name of operand and check that it is in the local name table
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4850 if( (ident = get_unique_ident(effects, "effect")) == NULL) {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4851 parse_err(SYNERR, "missing operand identifier in effect list\n");
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4852 return;
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4853 }
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4854 const Form *form = operands[ident];
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4855 opForm = form ? form->is_operand() : NULL;
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4856 if( opForm == NULL ) {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4857 if( form && form->is_opclass() ) {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4858 const char* cname = form->is_opclass()->_ident;
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4859 parse_err(SYNERR, "operand classes are illegal in effect lists (found %s %s)\n", cname, ident);
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4860 } else {
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4861 parse_err(SYNERR, "undefined operand %s in effect list\n", ident);
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4862 }
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4863 return;
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4864 }
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4865 // Add the pair to the effects table
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4866 effects.Insert(ident, eForm);
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4867 // Debugging Stuff
f03a3c8bd5e5 7077312: Provide a CALL effect for instruct declaration in the ad file
roland
parents: 4114
diff changeset
4868 if (_AD._adl_debug > 1) fprintf(stderr, "\tOperand Name: %s\n", ident);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4870 skipws();
a61af66fc99e Initial load
duke
parents:
diff changeset
4871 } while(_curchar == ',');
a61af66fc99e Initial load
duke
parents:
diff changeset
4872
a61af66fc99e Initial load
duke
parents:
diff changeset
4873 if (_curchar != ')') parse_err(SYNERR, "missing ')'\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4874 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4875 next_char(); // set current character position past the close paren
a61af66fc99e Initial load
duke
parents:
diff changeset
4876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4878
a61af66fc99e Initial load
duke
parents:
diff changeset
4879
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4880 //-------------------------------preproc_line----------------------------------
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4881 // A "#line" keyword has been seen, so parse the rest of the line.
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4882 void ADLParser::preproc_line(void) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4883 int line = get_int();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4884 skipws_no_preproc();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4885 const char* file = NULL;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4886 if (_curchar == '"') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4887 next_char(); // Move past the initial '"'
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4888 file = _ptr;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4889 while (true) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4890 if (_curchar == '\n') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4891 parse_err(SYNERR, "missing '\"' at end of #line directive");
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4892 return;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4893 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4894 if (_curchar == '"') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4895 *_ptr = '\0'; // Terminate the string
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4896 next_char();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4897 skipws_no_preproc();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4898 break;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4899 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4900 next_char();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4901 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4902 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4903 ensure_end_of_line();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4904 if (file != NULL)
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4905 _AD._ADL_file._name = file;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4906 _buf.set_linenum(line);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4907 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4908
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4909 //------------------------------preproc_define---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4910 // A "#define" keyword has been seen, so parse the rest of the line.
a61af66fc99e Initial load
duke
parents:
diff changeset
4911 void ADLParser::preproc_define(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4912 char* flag = get_ident_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4913 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4914 // only #define x y is supported for now
a61af66fc99e Initial load
duke
parents:
diff changeset
4915 char* def = get_ident_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4916 _AD.set_preproc_def(flag, def);
a61af66fc99e Initial load
duke
parents:
diff changeset
4917 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4918 if (_curchar != '\n') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4919 parse_err(SYNERR, "non-identifier in preprocessor definition\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4922
a61af66fc99e Initial load
duke
parents:
diff changeset
4923 //------------------------------preproc_undef----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4924 // An "#undef" keyword has been seen, so parse the rest of the line.
a61af66fc99e Initial load
duke
parents:
diff changeset
4925 void ADLParser::preproc_undef(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4926 char* flag = get_ident_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4927 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4928 ensure_end_of_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
4929 _AD.set_preproc_def(flag, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
4930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4931
a61af66fc99e Initial load
duke
parents:
diff changeset
4932
a61af66fc99e Initial load
duke
parents:
diff changeset
4933
a61af66fc99e Initial load
duke
parents:
diff changeset
4934 //------------------------------parse_err--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4935 // Issue a parser error message, and skip to the end of the current line
a61af66fc99e Initial load
duke
parents:
diff changeset
4936 void ADLParser::parse_err(int flag, const char *fmt, ...) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4937 va_list args;
a61af66fc99e Initial load
duke
parents:
diff changeset
4938
a61af66fc99e Initial load
duke
parents:
diff changeset
4939 va_start(args, fmt);
a61af66fc99e Initial load
duke
parents:
diff changeset
4940 if (flag == 1)
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
4941 _AD._syntax_errs += _AD.emit_msg(0, flag, linenum(), fmt, args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4942 else if (flag == 2)
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
4943 _AD._semantic_errs += _AD.emit_msg(0, flag, linenum(), fmt, args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4944 else
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
4945 _AD._warnings += _AD.emit_msg(0, flag, linenum(), fmt, args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4946
a61af66fc99e Initial load
duke
parents:
diff changeset
4947 int error_char = _curchar;
a61af66fc99e Initial load
duke
parents:
diff changeset
4948 char* error_ptr = _ptr+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4949 for(;*_ptr != '\n'; _ptr++) ; // Skip to the end of the current line
a61af66fc99e Initial load
duke
parents:
diff changeset
4950 _curchar = '\n';
a61af66fc99e Initial load
duke
parents:
diff changeset
4951 va_end(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
4952 _AD._no_output = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4953
a61af66fc99e Initial load
duke
parents:
diff changeset
4954 if (flag == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4955 char* error_tail = strchr(error_ptr, '\n');
a61af66fc99e Initial load
duke
parents:
diff changeset
4956 char tem = *error_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
4957 error_ptr[-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4958 char* error_head = error_ptr-1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4959 while (error_head > _curline && *error_head) --error_head;
a61af66fc99e Initial load
duke
parents:
diff changeset
4960 if (error_tail) *error_tail = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4961 fprintf(stderr, "Error Context: %s>>>%c<<<%s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
4962 error_head, error_char, error_ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4963 if (error_tail) *error_tail = '\n';
a61af66fc99e Initial load
duke
parents:
diff changeset
4964 error_ptr[-1] = tem;
a61af66fc99e Initial load
duke
parents:
diff changeset
4965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4966 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4967
a61af66fc99e Initial load
duke
parents:
diff changeset
4968 //---------------------------ensure_start_of_line------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4969 // A preprocessor directive has been encountered. Be sure it has fallen at
605
98cb887364d3 6810672: Comment typos
twisti
parents: 603
diff changeset
4970 // the beginning of a line, or else report an error.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4971 void ADLParser::ensure_start_of_line(void) {
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
4972 if (_curchar == '\n') { next_line(); return; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4973 assert( _ptr >= _curline && _ptr < _curline+strlen(_curline),
a61af66fc99e Initial load
duke
parents:
diff changeset
4974 "Must be able to find which line we are in" );
a61af66fc99e Initial load
duke
parents:
diff changeset
4975
a61af66fc99e Initial load
duke
parents:
diff changeset
4976 for (char *s = _curline; s < _ptr; s++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4977 if (*s > ' ') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4978 parse_err(SYNERR, "'%c' must be at beginning of line\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4979 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4983
a61af66fc99e Initial load
duke
parents:
diff changeset
4984 //---------------------------ensure_end_of_line--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4985 // A preprocessor directive has been parsed. Be sure there is no trailing
a61af66fc99e Initial load
duke
parents:
diff changeset
4986 // garbage at the end of this line. Set the scan point to the beginning of
a61af66fc99e Initial load
duke
parents:
diff changeset
4987 // the next line.
a61af66fc99e Initial load
duke
parents:
diff changeset
4988 void ADLParser::ensure_end_of_line(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4989 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
4990 if (_curchar != '\n' && _curchar != '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
4991 parse_err(SYNERR, "garbage char '%c' at end of line\n", _curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
4992 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4993 next_char_or_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
4994 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4995 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4996
a61af66fc99e Initial load
duke
parents:
diff changeset
4997 //---------------------------handle_preproc------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
4998 // The '#' character introducing a preprocessor directive has been found.
a61af66fc99e Initial load
duke
parents:
diff changeset
4999 // Parse the whole directive name (e.g., #define, #endif) and take appropriate
a61af66fc99e Initial load
duke
parents:
diff changeset
5000 // action. If we are in an "untaken" span of text, simply keep track of
a61af66fc99e Initial load
duke
parents:
diff changeset
5001 // #ifdef nesting structure, so we can find out when to start taking text
a61af66fc99e Initial load
duke
parents:
diff changeset
5002 // again. (In this state, we "sort of support" C's #if directives, enough
a61af66fc99e Initial load
duke
parents:
diff changeset
5003 // to disregard their associated #else and #endif lines.) If we are in a
a61af66fc99e Initial load
duke
parents:
diff changeset
5004 // "taken" span of text, there are two cases: "#define" and "#undef"
a61af66fc99e Initial load
duke
parents:
diff changeset
5005 // directives are preserved and passed up to the caller, which eventually
a61af66fc99e Initial load
duke
parents:
diff changeset
5006 // passes control to the top-level parser loop, which handles #define and
a61af66fc99e Initial load
duke
parents:
diff changeset
5007 // #undef directly. (This prevents these directives from occurring in
a61af66fc99e Initial load
duke
parents:
diff changeset
5008 // arbitrary positions in the AD file--we require better structure than C.)
a61af66fc99e Initial load
duke
parents:
diff changeset
5009 // In the other case, and #ifdef, #ifndef, #else, or #endif is silently
a61af66fc99e Initial load
duke
parents:
diff changeset
5010 // processed as whitespace, with the "taken" state of the text correctly
a61af66fc99e Initial load
duke
parents:
diff changeset
5011 // updated. This routine returns "false" exactly in the case of a "taken"
a61af66fc99e Initial load
duke
parents:
diff changeset
5012 // #define or #undef, which tells the caller that a preprocessor token
a61af66fc99e Initial load
duke
parents:
diff changeset
5013 // has appeared which must be handled explicitly by the parse loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
5014 bool ADLParser::handle_preproc_token() {
a61af66fc99e Initial load
duke
parents:
diff changeset
5015 assert(*_ptr == '#', "must be at start of preproc");
a61af66fc99e Initial load
duke
parents:
diff changeset
5016 ensure_start_of_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5017 next_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
5018 skipws_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
5019 char* start_ident = _ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5020 char* ident = (_curchar == '\n') ? NULL : get_ident_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
5021 if (ident == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5022 parse_err(SYNERR, "expected preprocessor command, got end of line\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
5023 } else if (!strcmp(ident, "ifdef") ||
a61af66fc99e Initial load
duke
parents:
diff changeset
5024 !strcmp(ident, "ifndef")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5025 char* flag = get_ident_no_preproc();
a61af66fc99e Initial load
duke
parents:
diff changeset
5026 ensure_end_of_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5027 // Test the identifier only if we are already in taken code:
a61af66fc99e Initial load
duke
parents:
diff changeset
5028 bool flag_def = preproc_taken() && (_AD.get_preproc_def(flag) != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
5029 bool now_taken = !strcmp(ident, "ifdef") ? flag_def : !flag_def;
a61af66fc99e Initial load
duke
parents:
diff changeset
5030 begin_if_def(now_taken);
a61af66fc99e Initial load
duke
parents:
diff changeset
5031 } else if (!strcmp(ident, "if")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5032 if (preproc_taken())
a61af66fc99e Initial load
duke
parents:
diff changeset
5033 parse_err(SYNERR, "unimplemented: #%s %s", ident, _ptr+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
5034 next_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5035 // Intelligently skip this nested C preprocessor directive:
a61af66fc99e Initial load
duke
parents:
diff changeset
5036 begin_if_def(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
5037 } else if (!strcmp(ident, "else")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5038 ensure_end_of_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5039 invert_if_def();
a61af66fc99e Initial load
duke
parents:
diff changeset
5040 } else if (!strcmp(ident, "endif")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5041 ensure_end_of_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5042 end_if_def();
a61af66fc99e Initial load
duke
parents:
diff changeset
5043 } else if (preproc_taken()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5044 // pass this token up to the main parser as "#define" or "#undef"
a61af66fc99e Initial load
duke
parents:
diff changeset
5045 _ptr = start_ident;
a61af66fc99e Initial load
duke
parents:
diff changeset
5046 _curchar = *--_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5047 if( _curchar != '#' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5048 parse_err(SYNERR, "no space allowed after # in #define or #undef");
a61af66fc99e Initial load
duke
parents:
diff changeset
5049 assert(_curchar == '#', "no space allowed after # in #define or #undef");
a61af66fc99e Initial load
duke
parents:
diff changeset
5050 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5051 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
5052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5053 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
5054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5055
a61af66fc99e Initial load
duke
parents:
diff changeset
5056 //---------------------------skipws_common-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5057 // Skip whitespace, including comments and newlines, while keeping an accurate
a61af66fc99e Initial load
duke
parents:
diff changeset
5058 // line count.
a61af66fc99e Initial load
duke
parents:
diff changeset
5059 // Maybe handle certain preprocessor constructs: #ifdef, #ifndef, #else, #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
5060 void ADLParser::skipws_common(bool do_preproc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5061 char *start = _ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5062 char *next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5063
a61af66fc99e Initial load
duke
parents:
diff changeset
5064 if (*_ptr == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5065 // Check for string terminator
a61af66fc99e Initial load
duke
parents:
diff changeset
5066 if (_curchar > ' ') return;
a61af66fc99e Initial load
duke
parents:
diff changeset
5067 if (_curchar == '\n') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5068 if (!do_preproc) return; // let caller handle the newline
a61af66fc99e Initial load
duke
parents:
diff changeset
5069 next_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5070 _ptr = _curline; next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5071 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5072 else if (_curchar == '#' ||
a61af66fc99e Initial load
duke
parents:
diff changeset
5073 (_curchar == '/' && (*next == '/' || *next == '*'))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5074 parse_err(SYNERR, "unimplemented: comment token in a funny place");
a61af66fc99e Initial load
duke
parents:
diff changeset
5075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5076 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5077 while(_curline != NULL) { // Check for end of file
a61af66fc99e Initial load
duke
parents:
diff changeset
5078 if (*_ptr == '\n') { // keep proper track of new lines
a61af66fc99e Initial load
duke
parents:
diff changeset
5079 if (!do_preproc) break; // let caller handle the newline
a61af66fc99e Initial load
duke
parents:
diff changeset
5080 next_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5081 _ptr = _curline; next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5083 else if ((*_ptr == '/') && (*next == '/')) // C++ comment
a61af66fc99e Initial load
duke
parents:
diff changeset
5084 do { _ptr++; next++; } while(*_ptr != '\n'); // So go to end of line
a61af66fc99e Initial load
duke
parents:
diff changeset
5085 else if ((*_ptr == '/') && (*next == '*')) { // C comment
a61af66fc99e Initial load
duke
parents:
diff changeset
5086 _ptr++; next++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5087 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
5088 _ptr++; next++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5089 if (*_ptr == '\n') { // keep proper track of new lines
a61af66fc99e Initial load
duke
parents:
diff changeset
5090 next_line(); // skip newlines within comments
a61af66fc99e Initial load
duke
parents:
diff changeset
5091 if (_curline == NULL) { // check for end of file
a61af66fc99e Initial load
duke
parents:
diff changeset
5092 parse_err(SYNERR, "end-of-file detected inside comment\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
5093 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
5094 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5095 _ptr = _curline; next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5096 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5097 } while(!((*_ptr == '*') && (*next == '/'))); // Go to end of comment
a61af66fc99e Initial load
duke
parents:
diff changeset
5098 _ptr = ++next; next++; // increment _ptr past comment end
a61af66fc99e Initial load
duke
parents:
diff changeset
5099 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5100 else if (do_preproc && *_ptr == '#') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5101 // Note that this calls skipws_common(false) recursively!
a61af66fc99e Initial load
duke
parents:
diff changeset
5102 bool preproc_handled = handle_preproc_token();
a61af66fc99e Initial load
duke
parents:
diff changeset
5103 if (!preproc_handled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5104 if (preproc_taken()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5105 return; // short circuit
a61af66fc99e Initial load
duke
parents:
diff changeset
5106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5107 ++_ptr; // skip the preprocessor character
a61af66fc99e Initial load
duke
parents:
diff changeset
5108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5109 next = _ptr+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5110 } else if(*_ptr > ' ' && !(do_preproc && !preproc_taken())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5111 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
5112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5113 else if (*_ptr == '"' || *_ptr == '\'') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5114 assert(do_preproc, "only skip strings if doing preproc");
a61af66fc99e Initial load
duke
parents:
diff changeset
5115 // skip untaken quoted string
a61af66fc99e Initial load
duke
parents:
diff changeset
5116 int qchar = *_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5117 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5118 ++_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5119 if (*_ptr == qchar) { ++_ptr; break; }
a61af66fc99e Initial load
duke
parents:
diff changeset
5120 if (*_ptr == '\\') ++_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5121 if (*_ptr == '\n' || *_ptr == '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5122 parse_err(SYNERR, "newline in string");
a61af66fc99e Initial load
duke
parents:
diff changeset
5123 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
5124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5126 next = _ptr + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
5127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5128 else { ++_ptr; ++next; }
a61af66fc99e Initial load
duke
parents:
diff changeset
5129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5130 if( _curline != NULL ) // at end of file _curchar isn't valid
a61af66fc99e Initial load
duke
parents:
diff changeset
5131 _curchar = *_ptr; // reset _curchar to maintain invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
5132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5133
a61af66fc99e Initial load
duke
parents:
diff changeset
5134 //---------------------------cur_char-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5135 char ADLParser::cur_char() {
a61af66fc99e Initial load
duke
parents:
diff changeset
5136 return (_curchar);
a61af66fc99e Initial load
duke
parents:
diff changeset
5137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5138
a61af66fc99e Initial load
duke
parents:
diff changeset
5139 //---------------------------next_char-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5140 void ADLParser::next_char() {
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5141 if (_curchar == '\n') parse_err(WARN, "must call next_line!");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
5142 _curchar = *++_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5143 // if ( _curchar == '\n' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5144 // next_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5145 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
5146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5147
a61af66fc99e Initial load
duke
parents:
diff changeset
5148 //---------------------------next_char_or_line---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5149 void ADLParser::next_char_or_line() {
a61af66fc99e Initial load
duke
parents:
diff changeset
5150 if ( _curchar != '\n' ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5151 _curchar = *++_ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
5152 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
5153 next_line();
a61af66fc99e Initial load
duke
parents:
diff changeset
5154 _ptr = _curline;
a61af66fc99e Initial load
duke
parents:
diff changeset
5155 _curchar = *_ptr; // maintain invariant
a61af66fc99e Initial load
duke
parents:
diff changeset
5156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5158
a61af66fc99e Initial load
duke
parents:
diff changeset
5159 //---------------------------next_line-----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5160 void ADLParser::next_line() {
415
4d9884b01ba6 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 0
diff changeset
5161 _curline = _buf.get_line();
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5162 _curchar = ' ';
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5163 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5164
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5165 //------------------------get_line_string--------------------------------------
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5166 // Prepended location descriptor, for debugging.
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5167 // Must return a malloced string (that can be freed if desired).
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5168 char* ADLParser::get_line_string(int linenum) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5169 const char* file = _AD._ADL_file._name;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5170 int line = linenum ? linenum : this->linenum();
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5171 char* location = (char *)malloc(strlen(file) + 100);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5172 sprintf(location, "\n#line %d \"%s\"\n", line, file);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5173 return location;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
5174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5175
a61af66fc99e Initial load
duke
parents:
diff changeset
5176 //-------------------------is_literal_constant---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5177 bool ADLParser::is_literal_constant(const char *param) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5178 if (param[0] == 0) return false; // null string
a61af66fc99e Initial load
duke
parents:
diff changeset
5179 if (param[0] == '(') return true; // parenthesized expression
a61af66fc99e Initial load
duke
parents:
diff changeset
5180 if (param[0] == '0' && (param[1] == 'x' || param[1] == 'X')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5181 // Make sure it's a hex constant.
a61af66fc99e Initial load
duke
parents:
diff changeset
5182 int i = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
5183 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
5184 if( !ADLParser::is_hex_digit(*(param+i)) ) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
5185 ++i;
a61af66fc99e Initial load
duke
parents:
diff changeset
5186 } while( *(param+i) != 0 );
a61af66fc99e Initial load
duke
parents:
diff changeset
5187 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
5188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5189 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
5190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5191
a61af66fc99e Initial load
duke
parents:
diff changeset
5192 //---------------------------is_hex_digit--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5193 bool ADLParser::is_hex_digit(char digit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5194 return ((digit >= '0') && (digit <= '9'))
a61af66fc99e Initial load
duke
parents:
diff changeset
5195 ||((digit >= 'a') && (digit <= 'f'))
a61af66fc99e Initial load
duke
parents:
diff changeset
5196 ||((digit >= 'A') && (digit <= 'F'));
a61af66fc99e Initial load
duke
parents:
diff changeset
5197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5198
a61af66fc99e Initial load
duke
parents:
diff changeset
5199 //---------------------------is_int_token--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5200 bool ADLParser::is_int_token(const char* token, int& intval) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5201 const char* cp = token;
a61af66fc99e Initial load
duke
parents:
diff changeset
5202 while (*cp != '\0' && *cp <= ' ') cp++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5203 if (*cp == '-') cp++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5204 int ndigit = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
5205 while (*cp >= '0' && *cp <= '9') { cp++; ndigit++; }
a61af66fc99e Initial load
duke
parents:
diff changeset
5206 while (*cp != '\0' && *cp <= ' ') cp++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5207 if (ndigit == 0 || *cp != '\0') {
a61af66fc99e Initial load
duke
parents:
diff changeset
5208 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
5209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5210 intval = atoi(token);
a61af66fc99e Initial load
duke
parents:
diff changeset
5211 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
5212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
5213
475
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5214 static const char* skip_expr_ws(const char* str) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5215 const char * cp = str;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5216 while (cp[0]) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5217 if (cp[0] <= ' ') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5218 ++cp;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5219 } else if (cp[0] == '#') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5220 ++cp;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5221 while (cp[0] == ' ') ++cp;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5222 assert(0 == strncmp(cp, "line", 4), "must be a #line directive");
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5223 const char* eol = strchr(cp, '\n');
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5224 assert(eol != NULL, "must find end of line");
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5225 if (eol == NULL) eol = cp + strlen(cp);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5226 cp = eol;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5227 } else {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5228 break;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5229 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5230 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5231 return cp;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5232 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5233
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5234 //-----------------------equivalent_expressions--------------------------------
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5235 bool ADLParser::equivalent_expressions(const char* str1, const char* str2) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5236 if (str1 == str2)
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5237 return true;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5238 else if (str1 == NULL || str2 == NULL)
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5239 return false;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5240 const char* cp1 = str1;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5241 const char* cp2 = str2;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5242 char in_quote = '\0';
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5243 while (cp1[0] && cp2[0]) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5244 if (!in_quote) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5245 // skip spaces and/or cpp directives
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5246 const char* cp1a = skip_expr_ws(cp1);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5247 const char* cp2a = skip_expr_ws(cp2);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5248 if (cp1a > cp1 && cp2a > cp2) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5249 cp1 = cp1a; cp2 = cp2a;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5250 continue;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5251 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5252 if (cp1a > cp1 || cp2a > cp2) break; // fail
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5253 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5254 // match one non-space char
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5255 if (cp1[0] != cp2[0]) break; // fail
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5256 char ch = cp1[0];
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5257 cp1++; cp2++;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5258 // watch for quotes
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5259 if (in_quote && ch == '\\') {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5260 if (cp1[0] != cp2[0]) break; // fail
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5261 if (!cp1[0]) break;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5262 cp1++; cp2++;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5263 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5264 if (in_quote && ch == in_quote) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5265 in_quote = '\0';
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5266 } else if (!in_quote && (ch == '"' || ch == '\'')) {
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5267 in_quote = ch;
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5268 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5269 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5270 return (!cp1[0] && !cp2[0]);
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5271 }
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5272
284d0af00d53 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 415
diff changeset
5273
0
a61af66fc99e Initial load
duke
parents:
diff changeset
5274 //-------------------------------trim------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
5275 void ADLParser::trim(char* &token) {
a61af66fc99e Initial load
duke
parents:
diff changeset
5276 while (*token <= ' ') token++;
a61af66fc99e Initial load
duke
parents:
diff changeset
5277 char* end = token + strlen(token);
a61af66fc99e Initial load
duke
parents:
diff changeset
5278 while (end > token && *(end-1) <= ' ') --end;
a61af66fc99e Initial load
duke
parents:
diff changeset
5279 *end = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
5280 }