Tue, 09 Oct 2012 16:09:31 -0700
8000592: Improve adlc usability
Summary: several changes to adlc to improve its usability
Reviewed-by: kvn
Contributed-by: goetz.lindenmaier@sap.com
duke@435 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_ADLC_ARCHDESC_HPP |
stefank@2314 | 26 | #define SHARE_VM_ADLC_ARCHDESC_HPP |
stefank@2314 | 27 | |
duke@435 | 28 | // Definitions for Error Flags |
duke@435 | 29 | #define WARN 0 |
duke@435 | 30 | #define SYNERR 1 |
duke@435 | 31 | #define SEMERR 2 |
duke@435 | 32 | #define INTERNAL_ERR 3 |
duke@435 | 33 | |
duke@435 | 34 | // Minimal declarations for include files |
duke@435 | 35 | class OutputMap; |
duke@435 | 36 | class ProductionState; |
duke@435 | 37 | class Expr; |
duke@435 | 38 | |
duke@435 | 39 | // STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES |
duke@435 | 40 | typedef BufferedFile ADLFILE; |
duke@435 | 41 | |
duke@435 | 42 | //---------------------------ChainList----------------------------------------- |
duke@435 | 43 | class ChainList { |
duke@435 | 44 | NameList _name; |
duke@435 | 45 | NameList _cost; |
duke@435 | 46 | NameList _rule; |
duke@435 | 47 | |
duke@435 | 48 | public: |
duke@435 | 49 | void insert(const char *name, const char *cost, const char *rule); |
duke@435 | 50 | bool search(const char *name); |
duke@435 | 51 | |
duke@435 | 52 | void reset(); |
duke@435 | 53 | bool iter(const char * &name, const char * &cost, const char * &rule); |
duke@435 | 54 | |
duke@435 | 55 | void dump(); |
duke@435 | 56 | void output(FILE *fp); |
duke@435 | 57 | |
duke@435 | 58 | ChainList(); |
duke@435 | 59 | ~ChainList(); |
duke@435 | 60 | }; |
duke@435 | 61 | |
duke@435 | 62 | //---------------------------MatchList----------------------------------------- |
duke@435 | 63 | class MatchList { |
duke@435 | 64 | private: |
duke@435 | 65 | MatchList *_next; |
duke@435 | 66 | Predicate *_pred; // Predicate which applies to this match rule |
duke@435 | 67 | const char *_cost; |
duke@435 | 68 | |
duke@435 | 69 | public: |
duke@435 | 70 | const char *_opcode; |
duke@435 | 71 | const char *_resultStr; |
duke@435 | 72 | const char *_lchild; |
duke@435 | 73 | const char *_rchild; |
duke@435 | 74 | |
duke@435 | 75 | MatchList(MatchList *nxt, Predicate *prd): _next(nxt), _pred(prd), _cost(NULL){ |
duke@435 | 76 | _resultStr = _lchild = _rchild = _opcode = NULL; } |
duke@435 | 77 | |
duke@435 | 78 | MatchList(MatchList *nxt, Predicate *prd, const char *cost, |
duke@435 | 79 | const char *opcode, const char *resultStr, const char *lchild, |
duke@435 | 80 | const char *rchild) |
duke@435 | 81 | : _next(nxt), _pred(prd), _cost(cost), _opcode(opcode), |
duke@435 | 82 | _resultStr(resultStr), _lchild(lchild), _rchild(rchild) { } |
duke@435 | 83 | |
duke@435 | 84 | MatchList *get_next(void) { return _next; } |
duke@435 | 85 | char *get_pred(void) { return (_pred?_pred->_pred:NULL); } |
duke@435 | 86 | Predicate *get_pred_obj(void) { return _pred; } |
duke@435 | 87 | const char *get_cost(void) { return _cost == NULL ? "0" :_cost; } |
duke@435 | 88 | bool search(const char *opc, const char *res, const char *lch, |
duke@435 | 89 | const char *rch, Predicate *pr); |
duke@435 | 90 | |
duke@435 | 91 | void dump(); |
duke@435 | 92 | void output(FILE *fp); |
duke@435 | 93 | }; |
duke@435 | 94 | |
duke@435 | 95 | //---------------------------ArchDesc------------------------------------------ |
duke@435 | 96 | class ArchDesc { |
duke@435 | 97 | private: |
duke@435 | 98 | FormDict _globalNames; // Global names |
duke@435 | 99 | Dict _idealIndex; // Map ideal names to index in enumeration |
duke@435 | 100 | ExprDict _globalDefs; // Global definitions, #defines |
duke@435 | 101 | int _internalOpCounter; // Internal Operand Counter |
duke@435 | 102 | |
duke@435 | 103 | FormList _header; // List of Source Code Forms for hpp file |
duke@435 | 104 | FormList _pre_header; // ditto for the very top of the hpp file |
duke@435 | 105 | FormList _source; // List of Source Code Forms for output |
duke@435 | 106 | FormList _instructions; // List of Instruction Forms for output |
duke@435 | 107 | FormList _machnodes; // List of Node Classes (special for pipelining) |
duke@435 | 108 | FormList _operands; // List of Operand Forms for output |
duke@435 | 109 | FormList _opclass; // List of Operand Class Forms for output |
duke@435 | 110 | FormList _attributes; // List of Attribute Forms for parsing |
duke@435 | 111 | RegisterForm *_register; // Only one Register Form allowed |
duke@435 | 112 | FrameForm *_frame; // Describe stack-frame layout |
duke@435 | 113 | EncodeForm *_encode; // Only one Encode Form allowed |
duke@435 | 114 | PipelineForm *_pipeline; // Pipeline Form for output |
duke@435 | 115 | |
duke@435 | 116 | bool _has_match_rule[_last_opcode]; // found AD rule for ideal node in <arch>.ad |
duke@435 | 117 | |
duke@435 | 118 | MatchList *_mlistab[_last_opcode]; // Array of MatchLists |
duke@435 | 119 | |
duke@435 | 120 | // The Architecture Description identifies which user-defined operand can be used |
duke@435 | 121 | // to access [stack_pointer + offset] |
duke@435 | 122 | OperandForm *_cisc_spill_operand; |
duke@435 | 123 | |
duke@435 | 124 | // Methods for outputting the DFA |
duke@435 | 125 | void gen_match(FILE *fp, MatchList &mlist, ProductionState &status, Dict &operands_chained_from); |
duke@435 | 126 | void chain_rule(FILE *fp, const char *indent, const char *ideal, |
duke@435 | 127 | const Expr *icost, const char *irule, |
duke@435 | 128 | Dict &operands_chained_from, ProductionState &status); |
duke@435 | 129 | void expand_opclass(FILE *fp, const char *indent, const Expr *cost, |
duke@435 | 130 | const char *result_type, ProductionState &status); |
duke@435 | 131 | Expr *calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status); |
duke@435 | 132 | void prune_matchlist(Dict &minimize, MatchList &mlist); |
duke@435 | 133 | |
duke@435 | 134 | // Helper function that outputs code to generate an instruction in MachNodeGenerator |
duke@435 | 135 | void buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent); |
duke@435 | 136 | |
duke@435 | 137 | public: |
duke@435 | 138 | ArchDesc(); |
duke@435 | 139 | ~ArchDesc(); |
duke@435 | 140 | |
duke@435 | 141 | // Option flags which control miscellaneous behaviors throughout the code |
duke@435 | 142 | int _TotalLines; // Line Counter |
duke@435 | 143 | int _no_output; // Flag to disable output of DFA, etc. |
duke@435 | 144 | int _quiet_mode; // Do not output banner messages, etc. |
duke@435 | 145 | int _disable_warnings; // Do not output warning messages |
duke@435 | 146 | int _dfa_debug; // Debug Flag for generated DFA |
duke@435 | 147 | int _dfa_small; // Debug Flag for generated DFA |
duke@435 | 148 | int _adl_debug; // Debug Flag for ADLC |
duke@435 | 149 | int _adlocation_debug; // Debug Flag to use ad file locations |
duke@435 | 150 | bool _cisc_spill_debug; // Debug Flag to see cisc-spill-instructions |
duke@435 | 151 | bool _short_branch_debug; // Debug Flag to see short branch instructions |
duke@435 | 152 | |
duke@435 | 153 | // Error/Warning Counts |
duke@435 | 154 | int _syntax_errs; // Count of syntax errors |
duke@435 | 155 | int _semantic_errs; // Count of semantic errors |
duke@435 | 156 | int _warnings; // Count warnings |
duke@435 | 157 | int _internal_errs; // Count of internal errors |
duke@435 | 158 | |
duke@435 | 159 | // Accessor for private data. |
duke@435 | 160 | void has_match_rule(int opc, const bool b) { _has_match_rule[opc] = b; } |
duke@435 | 161 | |
duke@435 | 162 | // I/O Files |
duke@435 | 163 | ADLFILE _ADL_file; // Input Architecture Description File |
duke@435 | 164 | // Machine dependent files, built from architecture definition |
duke@435 | 165 | ADLFILE _DFA_file; // File for definition of Matcher::DFA |
duke@435 | 166 | ADLFILE _HPP_file; // File for ArchNode class declarations |
duke@435 | 167 | ADLFILE _CPP_file; // File for ArchNode class defintions |
duke@435 | 168 | ADLFILE _CPP_CLONE_file; // File for MachNode/Oper clone defintions |
duke@435 | 169 | ADLFILE _CPP_EXPAND_file; // File for MachNode expand methods |
duke@435 | 170 | ADLFILE _CPP_FORMAT_file; // File for MachNode/Oper format defintions |
duke@435 | 171 | ADLFILE _CPP_GEN_file; // File for MachNode/Oper generator methods |
duke@435 | 172 | ADLFILE _CPP_MISC_file; // File for miscellaneous MachNode/Oper tables & methods |
duke@435 | 173 | ADLFILE _CPP_PEEPHOLE_file; // File for MachNode peephole methods |
duke@435 | 174 | ADLFILE _CPP_PIPELINE_file; // File for MachNode pipeline defintions |
duke@435 | 175 | ADLFILE _VM_file; // File for constants needed in VM code |
duke@435 | 176 | ADLFILE _bug_file; // DFA debugging file |
duke@435 | 177 | |
duke@435 | 178 | // I/O helper methods |
duke@435 | 179 | int open_file(bool required, ADLFILE & adf, const char *action); |
duke@435 | 180 | void close_file(int delete_out, ADLFILE & adf); |
duke@435 | 181 | int open_files(void); |
duke@435 | 182 | void close_files(int delete_out); |
duke@435 | 183 | |
duke@435 | 184 | Dict _chainRules; // Maps user operand names to ChainRules |
duke@435 | 185 | Dict _internalOps; // Maps match strings to internal operand names |
duke@435 | 186 | NameList _internalOpNames; // List internal operand names |
duke@435 | 187 | Dict _internalMatch; // Map internal name to its MatchNode |
duke@435 | 188 | |
duke@435 | 189 | NameList _preproc_list; // Preprocessor flag names |
duke@435 | 190 | FormDict _preproc_table;// Preprocessor flag bindings |
duke@435 | 191 | char* get_preproc_def(const char* flag); |
duke@435 | 192 | void set_preproc_def(const char* flag, const char* def); |
duke@435 | 193 | |
duke@435 | 194 | FormDict& globalNames() {return _globalNames;} // map global names to forms |
duke@435 | 195 | void initKeywords(FormDict& globals); // Add keywords to global name table |
duke@435 | 196 | |
duke@435 | 197 | ExprDict& globalDefs() {return _globalDefs;} // map global names to expressions |
duke@435 | 198 | |
duke@435 | 199 | OperandForm *constructOperand(const char *ident, bool ideal_only); |
duke@435 | 200 | void initBaseOpTypes(); // Import predefined base types. |
duke@435 | 201 | |
duke@435 | 202 | void addForm(PreHeaderForm *ptr); // Add objects to pre-header list |
duke@435 | 203 | void addForm(HeaderForm *ptr); // Add objects to header list |
duke@435 | 204 | void addForm(SourceForm *ptr); // Add objects to source list |
duke@435 | 205 | void addForm(EncodeForm *ptr); // Add objects to encode list |
duke@435 | 206 | void addForm(InstructForm *ptr); // Add objects to the instruct list |
duke@435 | 207 | void addForm(OperandForm *ptr); // Add objects to the operand list |
duke@435 | 208 | void addForm(OpClassForm *ptr); // Add objects to the opclasss list |
duke@435 | 209 | void addForm(AttributeForm *ptr); // Add objects to the attributes list |
duke@435 | 210 | void addForm(RegisterForm *ptr); // Add objects to the register list |
duke@435 | 211 | void addForm(FrameForm *ptr); // Add objects to the frame list |
duke@435 | 212 | void addForm(PipelineForm *ptr); // Add objects to the pipeline list |
duke@435 | 213 | void addForm(MachNodeForm *ptr); // Add objects to the machnode list |
duke@435 | 214 | |
duke@435 | 215 | int operandFormCount(); // Count number of OperandForms defined |
duke@435 | 216 | int opclassFormCount(); // Count number of OpClassForms defined |
duke@435 | 217 | int instructFormCount(); // Count number of InstructForms defined |
duke@435 | 218 | |
duke@435 | 219 | inline void getForm(EncodeForm **ptr) { *ptr = _encode; } |
duke@435 | 220 | |
duke@435 | 221 | bool verify(); |
duke@435 | 222 | void dump(); |
duke@435 | 223 | |
duke@435 | 224 | // Helper utility that gets MatchList components from inside MatchRule |
duke@435 | 225 | void check_optype(MatchRule *mrule); |
duke@435 | 226 | void build_chain_rule(OperandForm *oper); |
duke@435 | 227 | void add_chain_rule_entry(const char *src, const char *cost, |
duke@435 | 228 | const char *result); |
duke@435 | 229 | const char *getMatchListIndex(MatchRule &mrule); |
duke@435 | 230 | void generateMatchLists(); // Build MatchList array and populate it |
duke@435 | 231 | void inspectOperands(); // Build MatchLists for all operands |
duke@435 | 232 | void inspectOpClasses(); // Build MatchLists for all operands |
duke@435 | 233 | void inspectInstructions(); // Build MatchLists for all operands |
duke@435 | 234 | void buildDFA(FILE *fp); // Driver for constructing the DFA |
duke@435 | 235 | void gen_dfa_state_body(FILE *fp, Dict &minmize, ProductionState &status, Dict &chained, int i); // Driver for constructing the DFA state bodies |
duke@435 | 236 | |
duke@435 | 237 | // Helper utilities to generate reduction maps for internal operands |
duke@435 | 238 | const char *reduceLeft (char *internalName); |
duke@435 | 239 | const char *reduceRight(char *internalName); |
duke@435 | 240 | |
duke@435 | 241 | // Build enumerations, (1) dense operand index, (2) operands and opcodes |
duke@435 | 242 | const char *machOperEnum(const char *opName); // create dense index names using static function |
duke@435 | 243 | static const char *getMachOperEnum(const char *opName);// create dense index name |
duke@435 | 244 | void buildMachOperEnum(FILE *fp_hpp);// dense enumeration for operands |
duke@435 | 245 | void buildMachOpcodesEnum(FILE *fp_hpp);// enumeration for MachOpers & MachNodes |
duke@435 | 246 | |
duke@435 | 247 | // Helper utilities to generate Register Masks |
duke@435 | 248 | RegisterForm *get_registers() { return _register; } |
duke@435 | 249 | const char *reg_mask(OperandForm &opForm); |
duke@435 | 250 | const char *reg_mask(InstructForm &instForm); |
duke@435 | 251 | const char *reg_class_to_reg_mask(const char *reg_class); |
duke@435 | 252 | char *stack_or_reg_mask(OperandForm &opForm); // name of cisc_spillable version |
duke@435 | 253 | // This register class should also generate a stack_or_reg_mask |
duke@435 | 254 | void set_stack_or_reg(const char *reg_class_name); // for cisc-spillable reg classes |
duke@435 | 255 | // Generate an enumeration of register mask names and the RegMask objects. |
duke@435 | 256 | void declare_register_masks(FILE *fp_cpp); |
duke@435 | 257 | void build_register_masks(FILE *fp_cpp); |
duke@435 | 258 | // Generate enumeration of machine register numbers |
duke@435 | 259 | void buildMachRegisterNumbers(FILE *fp_hpp); |
duke@435 | 260 | // Generate enumeration of machine register encodings |
duke@435 | 261 | void buildMachRegisterEncodes(FILE *fp_hpp); |
duke@435 | 262 | // Generate Regsiter Size Array |
duke@435 | 263 | void declareRegSizes(FILE *fp_hpp); |
duke@435 | 264 | // Generate Pipeline Class information |
duke@435 | 265 | void declare_pipe_classes(FILE *fp_hpp); |
duke@435 | 266 | // Generate Pipeline definitions |
duke@435 | 267 | void build_pipeline_enums(FILE *fp_cpp); |
duke@435 | 268 | // Generate Pipeline Class information |
duke@435 | 269 | void build_pipe_classes(FILE *fp_cpp); |
duke@435 | 270 | |
duke@435 | 271 | // Declare and define mappings from rules to result and input types |
duke@435 | 272 | void build_map(OutputMap &map); |
duke@435 | 273 | void buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp); |
duke@435 | 274 | // build flags for signaling that our machine needs this instruction cloned |
duke@435 | 275 | void buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp); |
duke@435 | 276 | |
duke@435 | 277 | // output SUN copyright info |
duke@435 | 278 | void addSunCopyright(char* legal, int size, FILE *fp); |
stefank@2314 | 279 | // output the start of an include guard. |
stefank@2314 | 280 | void addIncludeGuardStart(ADLFILE &adlfile, const char* guardString); |
stefank@2314 | 281 | // output the end of an include guard. |
stefank@2314 | 282 | void addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString); |
stefank@2314 | 283 | // output the #include line for this file. |
stefank@2314 | 284 | void addInclude(ADLFILE &adlfile, const char* fileName); |
stefank@2314 | 285 | void addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName); |
duke@435 | 286 | // Output C preprocessor code to verify the backend compilation environment. |
duke@435 | 287 | void addPreprocessorChecks(FILE *fp); |
duke@435 | 288 | // Output C source and header (source_hpp) blocks. |
duke@435 | 289 | void addPreHeaderBlocks(FILE *fp_hpp); |
duke@435 | 290 | void addHeaderBlocks(FILE *fp_hpp); |
duke@435 | 291 | void addSourceBlocks(FILE *fp_cpp); |
duke@435 | 292 | void generate_adlc_verification(FILE *fp_cpp); |
duke@435 | 293 | |
duke@435 | 294 | // output declaration of class State |
duke@435 | 295 | void defineStateClass(FILE *fp); |
duke@435 | 296 | |
duke@435 | 297 | // Generator for MachOper objects given integer type |
duke@435 | 298 | void buildMachOperGenerator(FILE *fp_cpp); |
duke@435 | 299 | // Generator for MachNode objects given integer type |
duke@435 | 300 | void buildMachNodeGenerator(FILE *fp_cpp); |
duke@435 | 301 | |
duke@435 | 302 | // Generator for Expand methods for instructions with expand rules |
twisti@2350 | 303 | void defineExpand (FILE *fp, InstructForm *node); |
duke@435 | 304 | // Generator for Peephole methods for instructions with peephole rules |
twisti@2350 | 305 | void definePeephole (FILE *fp, InstructForm *node); |
duke@435 | 306 | // Generator for Size methods for instructions |
twisti@2350 | 307 | void defineSize (FILE *fp, InstructForm &node); |
twisti@2350 | 308 | |
twisti@2350 | 309 | public: |
twisti@2350 | 310 | // Generator for EvalConstantValue methods for instructions |
twisti@2350 | 311 | void defineEvalConstant(FILE *fp, InstructForm &node); |
duke@435 | 312 | // Generator for Emit methods for instructions |
twisti@2350 | 313 | void defineEmit (FILE *fp, InstructForm &node); |
twisti@2350 | 314 | |
duke@435 | 315 | // Define a MachOper encode method |
duke@435 | 316 | void define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals, |
duke@435 | 317 | const char *name, const char *encoding); |
duke@435 | 318 | |
duke@435 | 319 | // Methods to construct the MachNode class hierarchy |
duke@435 | 320 | // Return the type signature for the ideal operation |
duke@435 | 321 | const char *getIdealType(const char *idealOp); |
duke@435 | 322 | // Declare and define the classes derived from MachOper and MachNode |
duke@435 | 323 | void declareClasses(FILE *fp_hpp); |
duke@435 | 324 | void defineClasses(FILE *fp_cpp); |
duke@435 | 325 | |
duke@435 | 326 | // Emit an ADLC message |
duke@435 | 327 | void internal_err( const char *fmt, ...); |
duke@435 | 328 | void syntax_err ( int lineno, const char *fmt, ...); |
duke@435 | 329 | int emit_msg(int quiet, int flag, int linenum, const char *fmt, |
duke@435 | 330 | va_list args); |
duke@435 | 331 | |
duke@435 | 332 | // Generator for has_match_rule methods |
duke@435 | 333 | void buildInstructMatchCheck(FILE *fp_cpp) const; |
duke@435 | 334 | |
duke@435 | 335 | // Generator for Frame Methods |
duke@435 | 336 | void buildFrameMethods(FILE *fp_cpp); |
duke@435 | 337 | |
duke@435 | 338 | // Generate CISC_spilling oracle and MachNode::cisc_spill() methods |
duke@435 | 339 | void build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp); |
duke@435 | 340 | void identify_cisc_spill_instructions(); |
duke@435 | 341 | void identify_short_branches(); |
duke@435 | 342 | void identify_unique_operands(); |
duke@435 | 343 | void set_cisc_spill_operand(OperandForm *opForm) { _cisc_spill_operand = opForm; } |
duke@435 | 344 | OperandForm *cisc_spill_operand() { return _cisc_spill_operand; } |
duke@435 | 345 | bool can_cisc_spill() { return _cisc_spill_operand != NULL; } |
duke@435 | 346 | |
duke@435 | 347 | |
duke@435 | 348 | protected: |
duke@435 | 349 | // build MatchList from MatchRule |
duke@435 | 350 | void buildMatchList(MatchRule *mrule, const char *resultStr, |
duke@435 | 351 | const char *rootOp, Predicate *pred, const char *cost); |
duke@435 | 352 | |
duke@435 | 353 | void buildMList(MatchNode *node, const char *rootOp, const char *resultOp, |
duke@435 | 354 | Predicate *pred, const char *cost); |
duke@435 | 355 | |
duke@435 | 356 | friend class ADLParser; |
duke@435 | 357 | |
duke@435 | 358 | }; |
duke@435 | 359 | |
duke@435 | 360 | |
duke@435 | 361 | // -------------------------------- maps ------------------------------------ |
duke@435 | 362 | |
duke@435 | 363 | // Base class for generating a mapping from rule number to value. |
duke@435 | 364 | // Used with ArchDesc::build_map() for all maps except "enum MachOperands" |
duke@435 | 365 | // A derived class defines the appropriate output for a specific mapping. |
duke@435 | 366 | class OutputMap { |
duke@435 | 367 | protected: |
kvn@4161 | 368 | FILE *_hpp; |
kvn@4161 | 369 | FILE *_cpp; |
kvn@4161 | 370 | FormDict &_globals; |
kvn@4161 | 371 | ArchDesc &_AD; |
kvn@4161 | 372 | const char *_name; |
duke@435 | 373 | public: |
kvn@4161 | 374 | OutputMap (FILE *decl_file, FILE *def_file, FormDict &globals, ArchDesc &AD, const char *name) |
kvn@4161 | 375 | : _hpp(decl_file), _cpp(def_file), _globals(globals), _AD(AD), _name(name) {}; |
duke@435 | 376 | // Access files used by this routine |
duke@435 | 377 | FILE *decl_file() { return _hpp; } |
duke@435 | 378 | FILE *def_file() { return _cpp; } |
duke@435 | 379 | // Positions in iteration that derived class will be told about |
duke@435 | 380 | enum position { BEGIN_OPERANDS, |
duke@435 | 381 | BEGIN_OPCLASSES, |
duke@435 | 382 | BEGIN_INTERNALS, |
duke@435 | 383 | BEGIN_INSTRUCTIONS, |
duke@435 | 384 | BEGIN_INST_CHAIN_RULES, |
duke@435 | 385 | END_INST_CHAIN_RULES, |
duke@435 | 386 | BEGIN_REMATERIALIZE, |
duke@435 | 387 | END_REMATERIALIZE, |
duke@435 | 388 | END_INSTRUCTIONS |
duke@435 | 389 | }; |
duke@435 | 390 | // Output routines specific to the derived class |
duke@435 | 391 | virtual void declaration() {} |
duke@435 | 392 | virtual void definition() {} |
duke@435 | 393 | virtual void closing() { fprintf(_cpp, "};\n"); } |
duke@435 | 394 | virtual void map(OperandForm &oper) { } |
duke@435 | 395 | virtual void map(OpClassForm &opc) { } |
duke@435 | 396 | virtual void map(char *internal_name) { } |
duke@435 | 397 | // Allow enum-MachOperands to turn-off instructions |
duke@435 | 398 | virtual bool do_instructions() { return true; } |
duke@435 | 399 | virtual void map(InstructForm &inst) { } |
duke@435 | 400 | // Allow derived class to output name and position specific info |
duke@435 | 401 | virtual void record_position(OutputMap::position place, int index) {} |
duke@435 | 402 | }; |
stefank@2314 | 403 | |
stefank@2314 | 404 | #endif // SHARE_VM_ADLC_ARCHDESC_HPP |