Path: blob/master/src/hotspot/share/compiler/directivesParser.hpp
40930 views
/*1* Copyright (c) 2015, 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_COMPILER_DIRECTIVESPARSER_HPP25#define SHARE_COMPILER_DIRECTIVESPARSER_HPP2627#include "utilities/json.hpp"28#include "compiler/compilerDirectives.hpp"2930enum FlagType {31boolFlag,32intxFlag,33uintxFlag,34doubleFlag,35ccstrFlag,36ccstrlistFlag,37UnknownFlagType38};3940static const char* flag_type_names[] = {41"bool",42"int",43"uint",44"double",45"string",46"string list",47"unknown"48};4950class DirectivesParserTest;5152class DirectivesParser : public JSON {53friend class DirectivesParserTest;54public:55static bool has_file();56static bool parse_from_flag();57static bool parse_from_file(const char* filename, outputStream* st);58static int parse_string(const char* string, outputStream* st);59int install_directives();6061private:62DirectivesParser(const char* text, outputStream* st, bool silent);63~DirectivesParser();6465bool callback(JSON_TYPE t, JSON_VAL* v, uint level);66static bool parse_from_file_inner(const char* filename, outputStream* st);6768// types of "keys". i.e recognized <key>:<value> pairs in our JSON syntax69typedef enum {70type_c1,71type_c2,72type_enable,73type_preset,74type_match,75type_inline,7677// After here, there is no correlation between78// keytype and keys array79//type_strategy,80type_flag,81//type_dir,8283// Synthetic.84type_dir_array,85type_directives,86type_value_array87} keytype;8889// name, type, dtd info and maybe a setter90// this is how we map key-values91typedef struct {92const char *name;93keytype type;94uint allow_array_value : 1;95uint allowedmask;96void (DirectiveSet::*set)(void* arg);97FlagType flag_type;98} key;99100// Array with valid keys for the directive file101static const key keys[];102// Marker for outermost moosewings/array103static const key dir_array_key;104// Marker for a directives set (these are "implicit" objects, as in not named)105static const key dir_key;106// Marker for a multi value107static const key value_array_key;108109// A compiler directive shouldn't be able to use more than 5 stack slots.110// Example of max stack usage:111// depth 1: type_dir_array [112// depth 2: type_directives {113// depth 3: type_c1 c1: {114// depth 4: type_inline inline:115// depth 5: type_value_array [ ...116static const uint MAX_DEPTH = 5;117const key* stack[MAX_DEPTH];118uint depth;119120bool push_key(const char* str, size_t len);121bool push_key(const key* k);122const key* current_key();123const key* pop_key();124static const key* lookup_key(const char* s, size_t len);125126bool set_option(JSON_TYPE t, JSON_VAL* v);127bool set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set);128129CompilerDirectives* current_directive;130DirectiveSet* current_directiveset;131132void push_tmp(CompilerDirectives* dir);133void clean_tmp();134CompilerDirectives* pop_tmp();135CompilerDirectives* _tmp_top; // temporary storage for dirs while parsing136int _tmp_depth; // Number of directives that has been parsed but not installed.137138static uint mask(keytype kt);139};140141#endif // SHARE_COMPILER_DIRECTIVESPARSER_HPP142143144