Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/adlparse.hpp
32285 views
/*1* Copyright (c) 1997, 2013, 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_VM_ADLC_ADLPARSE_HPP25#define SHARE_VM_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;6768// class ostream; // ostream is a typedef in some systems6970extern char *toUpper(const char *str);7172//---------------------------ADLParser-----------------------------------------73class ADLParser {74protected:75char *_curline; // Start of current line76char *_ptr; // Pointer into current location in File Buffer77char _curchar; // Current character from buffer78FormDict &_globalNames; // Global names7980enum { _preproc_limit = 20 };81int _preproc_depth; // How deep are we into ifdefs?82int _preproc_not_taken; // How deep in not-taken ifdefs?83bool _preproc_taken[_preproc_limit]; // Are we taking this ifdef level?84bool _preproc_else[_preproc_limit]; // Did this level have an else yet?8586// ***** Level 1 Parse functions *****87void instr_parse(void); // Parse instruction definitions88void oper_parse(void); // Parse operand definitions89void opclass_parse(void); // Parse operand class definitions90void ins_attr_parse(void); // Parse instruction attrubute definitions91void op_attr_parse(void); // Parse operand attrubute definitions92void source_parse(void); // Parse source section93void source_hpp_parse(void); // Parse source_hpp section94void reg_parse(void); // Parse register section95void encode_parse(void); // Parse encoding section96void frame_parse(void); // Parse frame section97void pipe_parse(void); // Parse pipeline section98void definitions_parse(void); // Parse definitions section99void peep_parse(void); // Parse peephole rule definitions100void preproc_line(void); // Parse a #line statement101void preproc_define(void); // Parse a #define statement102void preproc_undef(void); // Parse an #undef statement103104// Helper functions for instr_parse().105void adjust_set_rule(InstructForm *instr);106void matchrule_clone_and_swap(MatchRule *rule, const char* instr_ident, int& match_rules_cnt);107108// ***** Level 2 Parse functions *****109// Parse the components of the encode section110void enc_class_parse(void); // Parse encoding class definition111void enc_class_parse_block(EncClass* encoding, char* ec_name);112113// Parse the components of the frame section114void stack_dir_parse(FrameForm *frame); // Parse the stack direction entry115void sync_stack_slots_parse(FrameForm *frame);116void frame_pointer_parse(FrameForm *frame, bool native);117void interpreter_frame_pointer_parse(FrameForm *frame, bool native);118void inline_cache_parse(FrameForm *frame, bool native);119void interpreter_arg_ptr_parse(FrameForm *frame, bool native);120void interpreter_method_oop_parse(FrameForm *frame, bool native);121void cisc_spilling_operand_name_parse(FrameForm *frame, bool native);122void stack_alignment_parse(FrameForm *frame);123void return_addr_parse(FrameForm *frame, bool native);124void preserve_stack_parse(FrameForm *frame);125char *calling_convention_parse();126char *return_value_parse();127128// Parse components of the register section129void reg_def_parse(void); // Parse register definition130void reg_class_parse(void); // Parse register class definition131void reg_class_dynamic_parse(void); // Parse dynamic register class definition132void alloc_class_parse(void); // Parse allocation class definition133134// Parse components of the definition section135void int_def_parse(void); // Parse an integer definition136137// Parse components of a pipeline rule138void resource_parse(PipelineForm &pipe); // Parse resource definition139void pipe_desc_parse(PipelineForm &pipe); // Parse pipeline description definition140void pipe_class_parse(PipelineForm &pipe); // Parse pipeline class definition141142// Parse components of a peephole rule143void peep_match_parse(Peephole &peep); // Parse the peephole match rule144void peep_constraint_parse(Peephole &peep);// Parse the peephole constraints145void peep_replace_parse(Peephole &peep); // Parse peephole replacement rule146147// Parse the peep match rule tree148InstructForm *peep_match_child_parse(PeepMatch &match, int parent, int &position, int input);149150// Parse components of an operand and/or instruction form151Predicate *pred_parse(void); // Parse predicate rule152// Parse match rule, and internal nodes153MatchRule *match_parse(FormDict &operands);154MatchNode *matchNode_parse(FormDict &operands, int &depth,155int &numleaves, bool atroot);156MatchNode *matchChild_parse(FormDict &operands, int &depth,157int &numleaves, bool atroot);158159Attribute *attr_parse(char *ident);// Parse instr/operand attribute rule160// Parse instruction encode rule161void ins_encode_parse(InstructForm &inst);162void ins_encode_parse_block(InstructForm &inst);163void ins_encode_parse_block_impl(InstructForm& inst, EncClass* encoding, char* ec_name);164// Parse instruction postalloc expand rule.165void postalloc_expand_parse(InstructForm &inst);166167void constant_parse(InstructForm& inst);168void constant_parse_expression(EncClass* encoding, char* ec_name);169170Opcode *opcode_parse(InstructForm *insr); // Parse instruction opcode171char *size_parse(InstructForm *insr); // Parse instruction size172Interface *interface_parse(); // Parse operand interface rule173Interface *mem_interface_parse(); // Parse memory interface rule174Interface *cond_interface_parse(); // Parse conditional interface rule175char *interface_field_parse(const char** format = NULL);// Parse field contents176177FormatRule *format_parse(void); // Parse format rule178FormatRule *template_parse(void); // Parse format rule179void effect_parse(InstructForm *instr); // Parse effect rule180ExpandRule *expand_parse(InstructForm *instr); // Parse expand rule181RewriteRule *rewrite_parse(void); // Parse rewrite rule182Constraint *constraint_parse(void); // Parse constraint rule183ConstructRule *construct_parse(void); // Parse construct rule184void ins_pipe_parse(InstructForm &instr); // Parse ins_pipe rule185186// ***** Preprocessor functions *****187void begin_if_def(bool taken) {188assert(_preproc_depth < _preproc_limit, "#ifdef nesting limit");189int ppn = _preproc_depth++;190_preproc_taken[ppn] = taken;191// Invariant: _preproc_not_taken = SUM !_preproc_taken[0.._preproc_depth)192if (!_preproc_taken[ppn]) _preproc_not_taken += 1;193_preproc_else[ppn] = false;194}195void invert_if_def() {196assert(_preproc_depth > 0, "#ifdef matching");197int ppn = _preproc_depth - 1;198assert(!_preproc_else[ppn], "multiple #else lines");199_preproc_else[ppn] = true;200if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;201_preproc_taken[ppn] = !_preproc_taken[ppn];202if (!_preproc_taken[ppn]) _preproc_not_taken += 1;203}204void end_if_def() {205assert(_preproc_depth > 0, "#ifdef matching");206int ppn = --_preproc_depth;207if (!_preproc_taken[ppn]) _preproc_not_taken -= 1;208}209bool preproc_taken() {210// Return true only if there is no directive hiding this text position.211return _preproc_not_taken == 0;212}213// Handle a '#' token. Return true if it disappeared.214bool handle_preproc_token();215216// ***** Utility Functions for ADL Parser ******217218// Parse one string argument inside parens: '(' string ')' ';'219char *parse_one_arg(const char *description);220221// Return the next identifier given a pointer into a line of the buffer.222char *get_ident() { return get_ident_common(true); }223char *get_ident_no_preproc() { return get_ident_common(false); }224char *get_ident_common(bool do_preproc); // Grab it from the file buffer225char *get_ident_dup(void); // Grab a duplicate of the identifier226char *get_ident_or_literal_constant(const char* description);227// Grab unique identifier from file buffer228char *get_unique_ident(FormDict &dict, const char *nameDescription);229// Return the next replacement variable identifier230char *get_rep_var_ident(void);231// Skip first '$' and make a duplicate of the string232char *get_rep_var_ident_dup(void);233// Return the next token given as a signed integer.234int get_int(void);235// Return the next token, a relational operator { ==, !=, <=, >= }236char *get_relation_dup(void);237238void get_oplist(NameList ¶meters, FormDict &operands);// Parse type-operand pairs239void get_effectlist(FormDict &effects, FormDict &operands, bool& has_call); // Parse effect-operand pairs240// Return the contents of a parenthesized expression.241// Requires initial '(' and consumes final ')', which is replaced by '\0'.242char *get_paren_expr(const char *description, bool include_location = false);243// Return expression up to next stop-char, which terminator replaces.244// Does not require initial '('. Does not consume final stop-char.245// Final stop-char is left in _curchar, but is also is replaced by '\0'.246char *get_expr(const char *description, const char *stop_chars);247char *find_cpp_block(const char *description); // Parse a C++ code block248// Issue parser error message & go to EOL249void parse_err(int flag, const char *fmt, ...);250// Create a location marker for this file and line.251char *get_line_string(int linenum = 0);252// Return a location marker which tells the C preprocessor to253// forget the previous location marker. (Requires awk postprocessing.)254char *end_line_marker() { return (char*)"\n#line 999999\n"; }255256// Return pointer to current character257inline char cur_char(void);258// Advance to next character, assign this to _curchar259inline void next_char(void);260inline void next_char_or_line(void);261// Advance File Buffer to next line, updating _curline262inline void next_line(void);263// Issue an error if we are not at the beginning of a line (exc. whitespace).264void ensure_start_of_line(void);265// Issue an error if we are not at the end of a line (exc. whitespace).266void ensure_end_of_line(void);267// Skip whitespace, leaving ptr pointing to first non-whitespace character268// Also handle preprocessor constructs like "#ifdef".269void skipws() { skipws_common(true); }270// Skip comments and spaces but not newlines or preprocessor constructs.271void skipws_no_preproc() { skipws_common(false); }272void skipws_common(bool do_preproc);273274FileBuff &_buf; // File buffer to be parsed275ArchDesc &_AD; // Architecture Description being built276277public:278279ADLParser(FileBuff &buf, ArchDesc &archDesc); // Create new ADLParser object280~ADLParser(); // Destroy ADLParser object281282void parse(void); // Do the parsing & build forms lists283284int linenum() { return _buf.linenum(); }285286static bool is_literal_constant(const char *hex_string);287static bool is_hex_digit(char digit);288static bool is_int_token(const char* token, int& intval);289static bool equivalent_expressions(const char* str1, const char* str2);290static void trim(char* &token); // trim leading & trailing spaces291};292293#endif // SHARE_VM_ADLC_ADLPARSE_HPP294295296