Path: blob/master/src/hotspot/share/adlc/adlparse.hpp
41144 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_ADLC_ADLPARSE_HPP25#define SHARE_ADLC_ADLPARSE_HPP2627// ADLPARSE.HPP - Definitions for Architecture Description Language Parser28// Authors: Chris Vick and Mike Paleczny2930// Class List31class Form;32// ***** Top Level, 1, classes *****33class InstructForm;34class OperandForm;35class OpClassForm;36class AttributeForm;37class RegisterForm;38class PipelineForm;39class SourceForm;40class Peephole;41// ***** Level 2 classes *****42class Component;43class Predicate;44class MatchRule;45class Encode;46class Attribute;47class Effect;48class ExpandRule;49class RewriteRule;50class Constraint;51class ConstructRule;52// ***** Register Section *****53class RegDef;54class RegClass;55class CodeSnippetRegClass;56class ConditionalRegClass;57class AllocClass;58class ResourceForm;59// ***** Pipeline Section *****60class PipeDesc;61class PipeClass;62class RegList;63// ***** Peephole Section *****64class PeepMatch;65class PeepConstraint;66class PeepReplace;6768extern char *toUpper(const char *str);6970//---------------------------ADLParser-----------------------------------------71class ADLParser {72protected:73char *_curline; // Start of current line74char *_ptr; // Pointer into current location in File Buffer75char _curchar; // Current character from buffer76FormDict &_globalNames; // Global names7778enum { _preproc_limit = 20 };79int _preproc_depth; // How deep are we into ifdefs?80int _preproc_not_taken; // How deep in not-taken ifdefs?81bool _preproc_taken[_preproc_limit]; // Are we taking this ifdef level?82bool _preproc_else[_preproc_limit]; // Did this level have an else yet?8384// ***** Level 1 Parse functions *****85void instr_parse(void); // Parse instruction definitions86void oper_parse(void); // Parse operand definitions87void opclass_parse(void); // Parse operand class definitions88void ins_attr_parse(void); // Parse instruction attrubute definitions89void op_attr_parse(void); // Parse operand attrubute definitions90void source_parse(void); // Parse source section91void source_hpp_parse(void); // Parse source_hpp section92void reg_parse(void); // Parse register section93void encode_parse(void); // Parse encoding section94void frame_parse(void); // Parse frame section95void pipe_parse(void); // Parse pipeline section96void definitions_parse(void); // Parse definitions section97void peep_parse(void); // Parse peephole rule definitions98void preproc_line(void); // Parse a #line statement99void preproc_define(void); // Parse a #define statement100void preproc_undef(void); // Parse an #undef statement101102// Helper functions for instr_parse().103void adjust_set_rule(InstructForm *instr);104void matchrule_clone_and_swap(MatchRule *rule, const char* instr_ident, int& match_rules_cnt);105106// ***** Level 2 Parse functions *****107// Parse the components of the encode section108void enc_class_parse(void); // Parse encoding class definition109void enc_class_parse_block(EncClass* encoding, char* ec_name);110111// Parse the components of the frame section112void sync_stack_slots_parse(FrameForm *frame);113void frame_pointer_parse(FrameForm *frame, bool native);114void interpreter_frame_pointer_parse(FrameForm *frame, bool native);115void inline_cache_parse(FrameForm *frame, bool native);116void interpreter_arg_ptr_parse(FrameForm *frame, bool native);117void interpreter_method_parse(FrameForm *frame, bool native);118void cisc_spilling_operand_name_parse(FrameForm *frame, bool native);119void stack_alignment_parse(FrameForm *frame);120void return_addr_parse(FrameForm *frame, bool native);121char *return_value_parse();122123// Parse components of the register section124void reg_def_parse(void); // Parse register definition125void reg_class_parse(void); // Parse register class definition126void reg_class_dynamic_parse(void); // Parse dynamic register class definition127void alloc_class_parse(void); // Parse allocation class definition128129// Parse components of the definition section130void int_def_parse(void); // Parse an integer definition131132// Parse components of a pipeline rule133void resource_parse(PipelineForm &pipe); // Parse resource definition134void pipe_desc_parse(PipelineForm &pipe); // Parse pipeline description definition135void pipe_class_parse(PipelineForm &pipe); // Parse pipeline class definition136137// Parse components of a peephole rule138void peep_match_parse(Peephole &peep); // Parse the peephole match rule139void peep_constraint_parse(Peephole &peep);// Parse the peephole constraints140void peep_replace_parse(Peephole &peep); // Parse peephole replacement rule141142// Parse the peep match rule tree143InstructForm *peep_match_child_parse(PeepMatch &match, int parent, int &position, int input);144145// Parse components of an operand and/or instruction form146Predicate *pred_parse(void); // Parse predicate rule147// Parse match rule, and internal nodes148MatchRule *match_parse(FormDict &operands);149MatchNode *matchNode_parse(FormDict &operands, int &depth,150int &numleaves, bool atroot);151MatchNode *matchChild_parse(FormDict &operands, int &depth,152int &numleaves, bool atroot);153154Attribute *attr_parse(char *ident);// Parse instr/operand attribute rule155// Parse instruction encode rule156void ins_encode_parse(InstructForm &inst);157void ins_encode_parse_block(InstructForm &inst);158void ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name);159// Parse instruction postalloc expand rule.160void postalloc_expand_parse(InstructForm &inst);161162void constant_parse(InstructForm& inst);163void constant_parse_expression(EncClass* encoding, char* ec_name);164165Opcode *opcode_parse(InstructForm *insr); // Parse instruction opcode166char *size_parse(InstructForm *insr); // Parse instruction size167Interface *interface_parse(); // Parse operand interface rule168Interface *mem_interface_parse(); // Parse memory interface rule169Interface *cond_interface_parse(); // Parse conditional interface rule170char *interface_field_parse(const char** format = NULL);// Parse field contents171172FormatRule *format_parse(void); // Parse format rule173FormatRule *template_parse(void); // Parse format rule174void effect_parse(InstructForm *instr); // Parse effect rule175ExpandRule *expand_parse(InstructForm *instr); // Parse expand rule176RewriteRule *rewrite_parse(void); // Parse rewrite rule177Constraint *constraint_parse(void); // Parse constraint rule178ConstructRule *construct_parse(void); // Parse construct rule179void ins_pipe_parse(InstructForm &instr); // Parse ins_pipe rule180181// ***** Preprocessor functions *****182void begin_if_def(bool taken) {183assert(_preproc_depth < _preproc_limit, "#ifdef nesting limit");184int ppn = _preproc_depth++;185_preproc_taken[ppn] = taken;186// Invariant: _preproc_not_taken = SUM !_preproc_taken[0.._preproc_depth)187if (!_preproc_taken[ppn]) _preproc_not_taken += 1;188_preproc_else[ppn] = false;189}190void invert_if_def() {191assert(_preproc_depth > 0, "#ifdef matching");192int ppn = _preproc_depth - 1;193assert(!_preproc_else[ppn], "multiple #else lines");194_preproc_else[ppn] = true;195if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;196_preproc_taken[ppn] = !_preproc_taken[ppn];197if (!_preproc_taken[ppn]) _preproc_not_taken += 1;198}199void end_if_def() {200assert(_preproc_depth > 0, "#ifdef matching");201int ppn = --_preproc_depth;202if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;203}204bool preproc_taken() {205// Return true only if there is no directive hiding this text position.206return _preproc_not_taken == 0;207}208// Handle a '#' token. Return true if it disappeared.209bool handle_preproc_token();210211// ***** Utility Functions for ADL Parser ******212213// Parse one string argument inside parens: '(' string ')' ';'214char *parse_one_arg(const char *description);215216// Return the next identifier given a pointer into a line of the buffer.217char *get_ident() { return get_ident_common(true); }218char *get_ident_no_preproc() { return get_ident_common(false); }219char *get_ident_common(bool do_preproc); // Grab it from the file buffer220char *get_ident_dup(void); // Grab a duplicate of the identifier221char *get_ident_or_literal_constant(const char* description);222// Grab unique identifier from file buffer223char *get_unique_ident(FormDict &dict, const char *nameDescription);224// Return the next replacement variable identifier225char *get_rep_var_ident(void);226// Skip first '$' and make a duplicate of the string227char *get_rep_var_ident_dup(void);228// Return the next token given as a signed integer.229int get_int(void);230// Return the next token, a relational operator { ==, !=, <=, >= }231char *get_relation_dup(void);232233void get_oplist(NameList ¶meters, FormDict &operands);// Parse type-operand pairs234void get_effectlist(FormDict &effects, FormDict &operands, bool& has_call); // Parse effect-operand pairs235// Return the contents of a parenthesized expression.236// Requires initial '(' and consumes final ')', which is replaced by '\0'.237char *get_paren_expr(const char *description, bool include_location = false);238// Return expression up to next stop-char, which terminator replaces.239// Does not require initial '('. Does not consume final stop-char.240// Final stop-char is left in _curchar, but is also is replaced by '\0'.241char *get_expr(const char *description, const char *stop_chars);242char *find_cpp_block(const char *description); // Parse a C++ code block243// Issue parser error message & go to EOL244void parse_err(int flag, const char *fmt, ...);245// Create a location marker for this file and line.246char *get_line_string(int linenum = 0);247// Return a location marker which tells the C preprocessor to248// forget the previous location marker. (Requires awk postprocessing.)249char *end_line_marker() { return (char*)"\n#line 999999\n"; }250251// Return pointer to current character252inline char cur_char(void);253// Advance to next character, assign this to _curchar254inline void next_char(void);255inline void next_char_or_line(void);256// Advance File Buffer to next line, updating _curline257inline void next_line(void);258// Issue an error if we are not at the beginning of a line (exc. whitespace).259void ensure_start_of_line(void);260// Issue an error if we are not at the end of a line (exc. whitespace).261void ensure_end_of_line(void);262// Skip whitespace, leaving ptr pointing to first non-whitespace character263// Also handle preprocessor constructs like "#ifdef".264void skipws() { skipws_common(true); }265// Skip comments and spaces but not newlines or preprocessor constructs.266void skipws_no_preproc() { skipws_common(false); }267void skipws_common(bool do_preproc);268269FileBuff &_buf; // File buffer to be parsed270ArchDesc &_AD; // Architecture Description being built271272public:273274ADLParser(FileBuff &buf, ArchDesc &archDesc); // Create new ADLParser object275~ADLParser(); // Destroy ADLParser object276277void parse(void); // Do the parsing & build forms lists278279int linenum() { return _buf.linenum(); }280281static bool is_literal_constant(const char *hex_string);282static bool is_hex_digit(char digit);283static bool is_int_token(const char* token, int& intval);284static bool equivalent_expressions(const char* str1, const char* str2);285static void trim(char* &token); // trim leading & trailing spaces286};287288#endif // SHARE_ADLC_ADLPARSE_HPP289290291