1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
98 if (!strcmp(ident, "instruct")) instr_parse();
99 else if (!strcmp(ident, "operand")) oper_parse();
100 else if (!strcmp(ident, "opclass")) opclass_parse();
101 else if (!strcmp(ident, "ins_attrib")) ins_attr_parse();
102 else if (!strcmp(ident, "op_attrib")) op_attr_parse();
103 else if (!strcmp(ident, "source")) source_parse();
104 else if (!strcmp(ident, "source_hpp")) source_hpp_parse();
105 else if (!strcmp(ident, "register")) reg_parse();
106 else if (!strcmp(ident, "frame")) frame_parse();
107 else if (!strcmp(ident, "encode")) encode_parse();
108 else if (!strcmp(ident, "pipeline")) pipe_parse();
109 else if (!strcmp(ident, "definitions")) definitions_parse();
110 else if (!strcmp(ident, "peephole")) peep_parse();
111 else if (!strcmp(ident, "#line")) preproc_line();
112 else if (!strcmp(ident, "#define")) preproc_define();
113 else if (!strcmp(ident, "#undef")) preproc_undef();
114 else {
115 parse_err(SYNERR, "expected one of - instruct, operand, ins_attrib, op_attrib, source, register, pipeline, encode\n Found %s",ident);
116 }
117 }
118
119 // Done with parsing, check consistency.
120
121 if (_preproc_depth != 0) {
122 parse_err(SYNERR, "End of file inside #ifdef");
123 }
124
125 // AttributeForms ins_cost and op_cost must be defined for default behaviour
126 if (_globalNames[AttributeForm::_ins_cost] == NULL) {
127 parse_err(SEMERR, "Did not declare 'ins_cost' attribute");
128 }
129 if (_globalNames[AttributeForm::_op_cost] == NULL) {
130 parse_err(SEMERR, "Did not declare 'op_cost' attribute");
131 }
132 }
133
134 // ******************** Private Level 1 Parse Functions ********************
135 //------------------------------instr_parse------------------------------------
136 // Parse the contents of an instruction definition, build the InstructForm to
137 // represent that instruction, and add it to the InstructForm list.
751 if ( (rule = find_cpp_block("source_hpp block")) == NULL ) {
752 parse_err(SYNERR, "incorrect or missing block for 'source_hpp'.\n");
753 return;
754 }
755 // Debug Stuff
756 if (_AD._adl_debug > 1) fprintf(stderr,"Header Form: %s\n", rule);
757
758 if (_AD.get_registers() == NULL) {
759 // Very early in the file, before reg_defs, we collect pre-headers.
760 PreHeaderForm* pre_header = new PreHeaderForm(rule);
761 _AD.addForm(pre_header);
762 } else {
763 // Normally, we collect header info, placed at the bottom of the hpp file.
764 HeaderForm* header = new HeaderForm(rule);
765 _AD.addForm(header);
766 }
767 }
768
769 //------------------------------reg_parse--------------------------------------
770 void ADLParser::reg_parse(void) {
771
772 // Create the RegisterForm for the architecture description.
773 RegisterForm *regBlock = new RegisterForm(); // Build new Source object
774 regBlock->_linenum = linenum();
775 _AD.addForm(regBlock);
776
777 skipws(); // Skip leading whitespace
778 if (_curchar == '%' && *(_ptr+1) == '{') {
779 next_char(); next_char(); // Skip "%{"
780 skipws();
781 while (_curchar != '%' && *(_ptr+1) != '}') {
782 char *token = get_ident();
783 if (token == NULL) {
784 parse_err(SYNERR, "missing identifier inside register block.\n");
785 return;
786 }
787 if (strcmp(token,"reg_def")==0) { reg_def_parse(); }
788 else if (strcmp(token,"reg_class")==0) { reg_class_parse(); }
789 else if (strcmp(token,"alloc_class")==0) { alloc_class_parse(); }
790 else if (strcmp(token,"#define")==0) { preproc_define(); }
791 else { parse_err(SYNERR, "bad token %s inside register block.\n", token); break; }
792 skipws();
793 }
794 }
795 else {
796 parse_err(SYNERR, "Missing %c{ ... %c} block after register keyword.\n",'%','%');
797 return;
798 }
799
800 // Add reg_class spill_regs
801 regBlock->addSpillRegClass();
802 }
803
804 //------------------------------encode_parse-----------------------------------
805 void ADLParser::encode_parse(void) {
806 EncodeForm *encBlock; // Information about instruction/operand encoding
807 char *desc = NULL; // String representation of encode rule
808
809 _AD.getForm(&encBlock);
810 if ( encBlock == NULL) {
811 // Create the EncodeForm for the architecture description.
812 encBlock = new EncodeForm(); // Build new Source object
813 _AD.addForm(encBlock);
814 }
815
816 skipws(); // Skip leading whitespace
817 if (_curchar == '%' && *(_ptr+1) == '{') {
818 next_char(); next_char(); // Skip "%{"
819 skipws();
820 while (_curchar != '%' && *(_ptr+1) != '}') {
821 char *token = get_ident();
822 if (token == NULL) {
823 parse_err(SYNERR, "missing identifier inside encoding block.\n");
824 return;
825 }
826 if (strcmp(token,"enc_class")==0) { enc_class_parse(); }
827 skipws();
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
98 if (!strcmp(ident, "instruct")) instr_parse();
99 else if (!strcmp(ident, "operand")) oper_parse();
100 else if (!strcmp(ident, "opclass")) opclass_parse();
101 else if (!strcmp(ident, "ins_attrib")) ins_attr_parse();
102 else if (!strcmp(ident, "op_attrib")) op_attr_parse();
103 else if (!strcmp(ident, "source")) source_parse();
104 else if (!strcmp(ident, "source_hpp")) source_hpp_parse();
105 else if (!strcmp(ident, "register")) reg_parse();
106 else if (!strcmp(ident, "frame")) frame_parse();
107 else if (!strcmp(ident, "encode")) encode_parse();
108 else if (!strcmp(ident, "pipeline")) pipe_parse();
109 else if (!strcmp(ident, "definitions")) definitions_parse();
110 else if (!strcmp(ident, "peephole")) peep_parse();
111 else if (!strcmp(ident, "#line")) preproc_line();
112 else if (!strcmp(ident, "#define")) preproc_define();
113 else if (!strcmp(ident, "#undef")) preproc_undef();
114 else {
115 parse_err(SYNERR, "expected one of - instruct, operand, ins_attrib, op_attrib, source, register, pipeline, encode\n Found %s",ident);
116 }
117 }
118 // Add reg_class spill_regs after parsing.
119 RegisterForm *regBlock = _AD.get_registers();
120 if (regBlock == NULL) {
121 parse_err(SEMERR, "Did not declare 'register' definitions");
122 }
123 regBlock->addSpillRegClass();
124
125 // Done with parsing, check consistency.
126
127 if (_preproc_depth != 0) {
128 parse_err(SYNERR, "End of file inside #ifdef");
129 }
130
131 // AttributeForms ins_cost and op_cost must be defined for default behaviour
132 if (_globalNames[AttributeForm::_ins_cost] == NULL) {
133 parse_err(SEMERR, "Did not declare 'ins_cost' attribute");
134 }
135 if (_globalNames[AttributeForm::_op_cost] == NULL) {
136 parse_err(SEMERR, "Did not declare 'op_cost' attribute");
137 }
138 }
139
140 // ******************** Private Level 1 Parse Functions ********************
141 //------------------------------instr_parse------------------------------------
142 // Parse the contents of an instruction definition, build the InstructForm to
143 // represent that instruction, and add it to the InstructForm list.
757 if ( (rule = find_cpp_block("source_hpp block")) == NULL ) {
758 parse_err(SYNERR, "incorrect or missing block for 'source_hpp'.\n");
759 return;
760 }
761 // Debug Stuff
762 if (_AD._adl_debug > 1) fprintf(stderr,"Header Form: %s\n", rule);
763
764 if (_AD.get_registers() == NULL) {
765 // Very early in the file, before reg_defs, we collect pre-headers.
766 PreHeaderForm* pre_header = new PreHeaderForm(rule);
767 _AD.addForm(pre_header);
768 } else {
769 // Normally, we collect header info, placed at the bottom of the hpp file.
770 HeaderForm* header = new HeaderForm(rule);
771 _AD.addForm(header);
772 }
773 }
774
775 //------------------------------reg_parse--------------------------------------
776 void ADLParser::reg_parse(void) {
777 RegisterForm *regBlock = _AD.get_registers(); // Information about registers encoding
778 if (regBlock == NULL) {
779 // Create the RegisterForm for the architecture description.
780 regBlock = new RegisterForm(); // Build new Source object
781 _AD.addForm(regBlock);
782 }
783
784 skipws(); // Skip leading whitespace
785 if (_curchar == '%' && *(_ptr+1) == '{') {
786 next_char(); next_char(); // Skip "%{"
787 skipws();
788 while (_curchar != '%' && *(_ptr+1) != '}') {
789 char *token = get_ident();
790 if (token == NULL) {
791 parse_err(SYNERR, "missing identifier inside register block.\n");
792 return;
793 }
794 if (strcmp(token,"reg_def")==0) { reg_def_parse(); }
795 else if (strcmp(token,"reg_class")==0) { reg_class_parse(); }
796 else if (strcmp(token,"alloc_class")==0) { alloc_class_parse(); }
797 else if (strcmp(token,"#define")==0) { preproc_define(); }
798 else { parse_err(SYNERR, "bad token %s inside register block.\n", token); break; }
799 skipws();
800 }
801 }
802 else {
803 parse_err(SYNERR, "Missing %c{ ... %c} block after register keyword.\n",'%','%');
804 return;
805 }
806 }
807
808 //------------------------------encode_parse-----------------------------------
809 void ADLParser::encode_parse(void) {
810 EncodeForm *encBlock; // Information about instruction/operand encoding
811
812 _AD.getForm(&encBlock);
813 if ( encBlock == NULL) {
814 // Create the EncodeForm for the architecture description.
815 encBlock = new EncodeForm(); // Build new Source object
816 _AD.addForm(encBlock);
817 }
818
819 skipws(); // Skip leading whitespace
820 if (_curchar == '%' && *(_ptr+1) == '{') {
821 next_char(); next_char(); // Skip "%{"
822 skipws();
823 while (_curchar != '%' && *(_ptr+1) != '}') {
824 char *token = get_ident();
825 if (token == NULL) {
826 parse_err(SYNERR, "missing identifier inside encoding block.\n");
827 return;
828 }
829 if (strcmp(token,"enc_class")==0) { enc_class_parse(); }
830 skipws();
|