diff --git a/src/bin/jbc2mpl b/src/bin/jbc2mpl index 9c0cd89c81e83fcbde4837864c683d380cecb060..a37f7269b4fa9d9a5e6ed47458b08456d3be3dd5 100755 Binary files a/src/bin/jbc2mpl and b/src/bin/jbc2mpl differ diff --git a/src/bin/maple b/src/bin/maple index f606b801c06e3e79d4c028b25039f7715b14f755..ca7759adca8fa036566c5f6814098959c016e248 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/bin/mplcg b/src/bin/mplcg index 6de14003c47c333a0bf8b7add1ba24d98ef43a20..74860e0b7cc4c0af80e6aca6fc5dd41746d5f6fd 100755 Binary files a/src/bin/mplcg and b/src/bin/mplcg differ diff --git a/src/deplibs/libmaple_driverutil.a b/src/deplibs/libmaple_driverutil.a deleted file mode 100644 index 0a278241b4db6475765c4e598589657560f1a085..0000000000000000000000000000000000000000 Binary files a/src/deplibs/libmaple_driverutil.a and /dev/null differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 099d1f112c6b781a87e9f735edd6bdc7af38bb85..ae96249a2a597d9bbcac2c7ec3355fbc74878f1b 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplphase.a b/src/deplibs/libmplphase.a index 85788812a7eed0b20b4c3b3ab93912816335f701..5548da460e160e785e02080520b02449cedaad31 100644 Binary files a/src/deplibs/libmplphase.a and b/src/deplibs/libmplphase.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 246d81511572a66a579ca70128df051a0944fff5..29f99e06dfe6faaf4fe06be748d87fc64ed32c99 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_driver/BUILD.gn b/src/maple_driver/BUILD.gn index 4295974185ec0591d49613a3eb3bf8cd1974a6f1..8ed8cd69d2f173923dc4624e01f210e597de8fd1 100644 --- a/src/maple_driver/BUILD.gn +++ b/src/maple_driver/BUILD.gn @@ -32,8 +32,8 @@ executable("maple") { "src/jbc2mpl_compiler.cpp", "src/maple.cpp", "src/maple_comb_compiler.cpp", - "src/mplcg_compiler.cpp", "src/mpl_options.cpp", + "src/mplcg_compiler.cpp", ] cflags_cc += [ "-DOPTION_PARSER_EXTRAOPT" ] @@ -41,6 +41,7 @@ executable("maple") { include_dirs = include_directories deps = [ + ":liboption_parser_extra", "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", "${MAPLEALL_ROOT}/maple_ipa:libmplipa", "${MAPLEALL_ROOT}/maple_ir:libmplir", @@ -52,6 +53,39 @@ executable("maple") { libs += [ "${OPENSOURCE_DEPS}/libmplphase.a", "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmaple_driverutil.a", + "${OPENSOURCE_DEPS}/libmplutil.a", + ] +} + +static_library("liboption_parser_extra") { + sources = [ + "src/option_parser.cpp", + ] + + cflags_cc += [ + "-DOPTION_PARSER_EXTRAOPT", + "-DOPTION_PARSER_DEBUG", + ] + + include_dirs = [ + "${MAPLEALL_ROOT}/maple_util/include", + "${MAPLEALL_ROOT}/maple_driver/include", + "${MAPLEALL_ROOT}/maple_ir/include", + "${MAPLEALL_ROOT}/mempool/include", + "${MAPLEALL_ROOT}/huawei_secure_c/include", + ] +} + +static_library("liboption_parser") { + sources = [ + "src/option_parser.cpp", + ] + + include_dirs = [ + "${MAPLEALL_ROOT}/maple_util/include", + "${MAPLEALL_ROOT}/maple_driver/include", + "${MAPLEALL_ROOT}/maple_ir/include", + "${MAPLEALL_ROOT}/mempool/include", + "${MAPLEALL_ROOT}/huawei_secure_c/include", ] } diff --git a/src/maple_driver/defs/default/O0_options_jbc2mpl.def b/src/maple_driver/defs/default/O0_options_jbc2mpl.def index 6dbf160e648825f1c685a46d41c2ebb3e2722bd5..d6f2c48860d2e63cd5d4a862392b2544148fef34 100644 --- a/src/maple_driver/defs/default/O0_options_jbc2mpl.def +++ b/src/maple_driver/defs/default/O0_options_jbc2mpl.def @@ -12,4 +12,4 @@ * FIT FOR A PARTICULAR PURPOSE. * See the Mulan PSL v1 for more details. */ -// option name, option value, option connect sysmbol, can append?, append spilter. +// option name, option value, option connect sysmbol, can append?, append spilter. diff --git a/src/maple_driver/include/compiler.h b/src/maple_driver/include/compiler.h index e061e61d6bbe31f0d4091a0f07e87f712cf24620..2881f4f9a882ad4fea4ef642b82e3180860337a7 100644 --- a/src/maple_driver/include/compiler.h +++ b/src/maple_driver/include/compiler.h @@ -74,7 +74,7 @@ class Compiler { return std::vector(); } - bool CanAppendOptimization(const std::string &optionStr) const; + bool CanAppendOptimization() const; private: const std::string name; diff --git a/src/maple_driver/include/driver_runner.h b/src/maple_driver/include/driver_runner.h index bf1f981a54acb4508de7b0aca00ece0c298194e8..7ca19e26c7dee24ed02e31c29432cbc865d0484c 100644 --- a/src/maple_driver/include/driver_runner.h +++ b/src/maple_driver/include/driver_runner.h @@ -57,7 +57,6 @@ class DriverRunner final { static bool FuncOrderLessThan(const MIRFunction *left, const MIRFunction *right); bool IsFramework() const; - bool VerifyModule(MIRModulePtr &mModule) const; ErrorCode ParseInput(const std::string &outputFile, const std::string &oriBasename) const; std::string GetPostfix() const; void InitPhases(InterleavedManager &mgr, const std::vector &phases) const; diff --git a/src/maple_util/include/option_parser.h b/src/maple_driver/include/option_parser.h similarity index 97% rename from src/maple_util/include/option_parser.h rename to src/maple_driver/include/option_parser.h index 49b07dfd17e4585ab8f37bfcce86221c312c7ed3..f228412da855bbb834ab01fe295a6a52b567ccfe 100644 --- a/src/maple_util/include/option_parser.h +++ b/src/maple_driver/include/option_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -54,7 +54,7 @@ struct Descriptor { // Unique option index const unsigned int index; - // Unique option type + // Unique option type const int type; // Short form option key @@ -213,7 +213,7 @@ class OptionParser { private: bool HandleKeyValue(const std::string &key, const std::string &value, bool isValueEmpty, - std::vector &inputOption, const std::string &exeName, + std::vector &inputOption, const std::string &exeName, bool isAllOption = true); bool CheckOpt(const std::string option, std::string &lastKey, bool &isLastMatch, std::vector &inputOption, const std::string &exeName); diff --git a/src/maple_driver/include/safe_exe.h b/src/maple_driver/include/safe_exe.h index cda8a4fb88828b8c17cd542931fd1f8601d2970b..626782ebf06ebcbd61477ffadd57376349782ade 100644 --- a/src/maple_driver/include/safe_exe.h +++ b/src/maple_driver/include/safe_exe.h @@ -57,7 +57,7 @@ class SafeExe { // child process fflush(nullptr); if (execv(cmd.c_str(), argv) < 0) { - for (int j = 0; j < vectorArgs.size(); ++j) { + for (size_t j = 0; j < vectorArgs.size(); ++j) { delete [] argv[j]; } delete [] argv; @@ -76,7 +76,7 @@ class SafeExe { } } - for (int j = 0; j < vectorArgs.size(); ++j) { + for (size_t j = 0; j < vectorArgs.size(); ++j) { delete [] argv[j]; } delete [] argv; diff --git a/src/maple_driver/src/compiler.cpp b/src/maple_driver/src/compiler.cpp index 42baa791156e2476e772f47260572585fe203c73..3ea6b5d93b628e87d978ff604e6a7d763fa5be95 100644 --- a/src/maple_driver/src/compiler.cpp +++ b/src/maple_driver/src/compiler.cpp @@ -151,13 +151,13 @@ void Compiler::AppendOptions(std::map &finalOptions, con } } -bool Compiler::CanAppendOptimization(const std::string &optionStr) const { +bool Compiler::CanAppendOptimization() const { // there're some issues for passing -Ox to each component, let users determine self. return false; } std::string Compiler::AppendOptimization(const MplOptions &options, const std::string &optionStr) const { - if (!CanAppendOptimization(optionStr)) { + if (!CanAppendOptimization()) { return optionStr; } return optionStr + " " + options.OptimizationLevelStr(); diff --git a/src/maple_driver/src/driver_runner.cpp b/src/maple_driver/src/driver_runner.cpp index 13760bfdd6d3d65f2f6f7d67e72cac7d884e023d..67886338eb0fd823f4fe3a554517a9d31d3d9920 100644 --- a/src/maple_driver/src/driver_runner.cpp +++ b/src/maple_driver/src/driver_runner.cpp @@ -78,7 +78,6 @@ ErrorCode DriverRunner::Run() { std::string outputFile = baseName.append(GetPostfix()); ErrorCode ret = ParseInput(outputFile, originBaseName); - if (ret != kErrorNoError) { return kErrorExit; } @@ -129,13 +128,6 @@ ErrorCode DriverRunner::ParseInput(const std::string &outputFile, const std::str return ret; } -bool DriverRunner::VerifyModule(MIRModulePtr &mModule) const { - LogInfo::MapleLogger() << "========== Starting Verify Module =====================" << '\n'; - bool res = true; - LogInfo::MapleLogger() << "========== Finished Verify Module =====================" << '\n'; - return res; -} - void DriverRunner::ProcessMpl2mplAndMePhases(const std::string &outputFile, const std::string &vtableImplFile) const { CHECK_MODULE(); diff --git a/src/maple_driver/src/file_utils.cpp b/src/maple_driver/src/file_utils.cpp index c571f176efea4467a27309e1c46f7fb30811e25c..b30a48b2e02fdc3273886eb291b51078700ea936 100644 --- a/src/maple_driver/src/file_utils.cpp +++ b/src/maple_driver/src/file_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_driver/src/option_parser.cpp b/src/maple_driver/src/option_parser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b639a8f6a72b4d1d57cb40ec7092cb7debb33333 --- /dev/null +++ b/src/maple_driver/src/option_parser.cpp @@ -0,0 +1,254 @@ +/* + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. + * + * OpenArkCompiler is licensed under the Mulan PSL v1. + * You can use this software according to the terms and conditions of the Mulan PSL v1. + * You may obtain a copy of Mulan PSL v1 at: + * + * http://license.coscl.org.cn/MulanPSL + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR + * FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v1 for more details. + */ +#include "option_parser.h" +#include +#include +#include +#include "mpl_logging.h" + +using namespace maple; +using namespace mapleOption; + +OptionParser::OptionParser(const Descriptor usage[]) : rawUsages(usage) { + for (size_t i = 0; usage[i].help != nullptr; ++i) { + if (usage[i].shortOption != nullptr) { + InsertOption(std::string(usage[i].shortOption), usage[i]); + } + if (usage[i].longOption != nullptr) { + InsertOption(std::string(usage[i].longOption), usage[i]); + } + } +} + +void OptionParser::PrintUsage() const { + for (size_t i = 0; rawUsages[i].help != nullptr; ++i) { + if (rawUsages[i].IsEnabledForCurrentBuild()) { + LogInfo::MapleLogger() << rawUsages[i].help << '\n'; + } + } +} + +#ifdef OPTION_PARSER_EXTRAOPT +void OptionParser::PrintUsage(const std::string &helpType) const { + for (size_t i = 0; rawUsages[i].help != nullptr; ++i) { + if (rawUsages[i].IsEnabledForCurrentBuild() && rawUsages[i].exeName == helpType) { + LogInfo::MapleLogger() << rawUsages[i].help << '\n'; + } + } +} +#endif + + +bool OptionParser::HandleKeyValue(const std::string &key, const std::string &value, bool isValueEmpty, + std::vector &inputOption, const std::string &exeName, + bool isAllOption) { + if (key.empty()) { + if (!isAllOption) { + LogInfo::MapleLogger(kLlErr) << "Cannot recognize " << value << '\n'; + return false; + } + nonOptionsArgs.push_back(value); + return true; + } + int count = usages.count(key); + auto item = usages.find(key); +#ifdef OPTION_PARSER_EXTRAOPT + while (count > 0 && item->second.exeName != exeName) { + ++item; + --count; + } +#endif + if (count == 0) { + LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + key) << '\n'; + return false; + } + switch (item->second.checkPolicy) { + case kArgCheckPolicyUnknown: + LogInfo::MapleLogger(kLlErr) << ("Unknown option " + key) << '\n'; + return false; + case kArgCheckPolicyNone: + case kArgCheckPolicyOptional: + break; + case kArgCheckPolicyRequired: + if (value.empty() && !isValueEmpty) { + LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires an argument.") << '\n'; + return false; + } + break; + case kArgCheckPolicyNumeric: + if (value.empty()) { + LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires an argument.") << '\n'; + return false; + } else { + std::regex rx("^(-|)[0-9]+\\b"); + bool isNumeric = std::regex_match(value.begin(), value.end(), rx); + if (!isNumeric) { + LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires a numeric argument.") << '\n'; + return false; + } + } + break; + default: + break; + } + inputOption.push_back(Option(item->second, key, value)); + return true; +} + +#ifdef OPTION_PARSER_EXTRAOPT +bool OptionParser::SetOption(const std::string &rawKey, const std::string &value, const std::string &exeName, + std::vector &exeOption) { + constexpr char kOptionMark = '-'; + if (rawKey.empty()) { + LogInfo::MapleLogger(kLlErr) << "Invalid key" << '\n'; + PrintUsage("all"); + return false; + } + int index = 0; + if (rawKey[0] == kOptionMark) { + ++index; + if (rawKey[1] == kOptionMark) { + ++index; + } + } + std::string key = rawKey.substr(index); + int count = usages.count(key); + auto item = usages.find(key); + while (count > 0) { + if (item->second.exeName != exeName) { + ++item; + --count; + continue; + } + switch (item->second.checkPolicy) { + case kArgCheckPolicyNone: + case kArgCheckPolicyOptional: + break; + case kArgCheckPolicyRequired: + if (value.empty()) { + LogInfo::MapleLogger(kLlErr) << ("Option " + key + " requires an argument.") << '\n'; + return false; + } + break; + default: + break; + } + break; + } + exeOption.push_back(Option(item->second, key, value)); + return true; +} +#endif + +bool OptionParser::CheckOpt(const std::string option, std::string &lastKey, + bool &isLastMatch, std::vector &inputOption, + const std::string &exeName) { + std::vector temps; + size_t pos = option.find('='); + if (pos != std::string::npos) { + ASSERT(pos > 0, "option should not begin with symbol '='"); + isLastMatch = false; + std::string key = option.substr(0, pos); + std::string value = option.substr(pos + 1); + return HandleKeyValue(key, value, value.empty(), inputOption, exeName); + } else { + auto item = usages.find(option); + if (item != usages.end()) { + if (item->second.checkPolicy == kArgCheckPolicyRequired || item->second.checkPolicy == kArgCheckPolicyNumeric) { + lastKey = option; + isLastMatch = true; + } else { + return HandleKeyValue(option, "", false, inputOption, exeName); + } + } else { + LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + option) << '\n'; + return false; + } + } + return true; +} + +ErrorCode OptionParser::HandleInputArgs(const std::vector &inputArgs, const std::string &exeName, + std::vector &inputOption) { + bool isLastMatchOpt = false; + std::string lastKey = ""; + bool ret = true; + for (size_t i = 0; i < inputArgs.size(); ++i) { + if (inputArgs[i] == "") { + continue; + } + bool isMatchLongOpt = false; + bool isMatchShortOpt = false; + int index = 0; + if (inputArgs[i][0] == '-') { + index = 1; + if (inputArgs[i][1] == '-') { + index = 2; + } + } + if (index == 1) { + isMatchShortOpt = true; + } else if (index == 2) { + isMatchLongOpt = true; + } + std::string arg = inputArgs[i].substr(index); + bool isAllOption = (exeName == "all") ? true : false; + bool isOptMatched = isMatchLongOpt || isMatchShortOpt; + if (!isLastMatchOpt && isOptMatched) { + ret = CheckOpt(arg, lastKey, isLastMatchOpt, inputOption, exeName); + } else if (isLastMatchOpt && !isOptMatched) { + isLastMatchOpt = false; + ret = HandleKeyValue(lastKey, arg, false, inputOption, exeName, isAllOption); + } else if (isLastMatchOpt && isOptMatched) { + LogInfo::MapleLogger(kLlErr) << ("Unknown Option: " + arg) << '\n'; + return kErrorInvalidParameter; + } else { + ret = HandleKeyValue("", arg, false, inputOption, exeName, isAllOption); + } + if (i == inputArgs.size() - 1 && isLastMatchOpt) { + LogInfo::MapleLogger(kLlErr) << ("Option " + lastKey + " requires an argument.") << '\n'; + return kErrorInvalidParameter; + } + if (!ret) { + return kErrorInvalidParameter; + } + } + return kErrorNoError; +} + +ErrorCode OptionParser::Parse(int argc, char **argv) { + if (argc > 0) { + --argc; + ++argv; // skip program name argv[0] if present + } + if (argc == 0 || *argv == nullptr) { +#ifdef OPTION_PARSER_EXTRAOPT + PrintUsage("all"); +#else + PrintUsage(); +#endif + LogInfo::MapleLogger(kLlErr) << "No input files!" << '\n'; + return kErrorInitFail; + } + // transform char* to string + std::vector inputArgs; + while (argc != 0 && *argv != nullptr) { + inputArgs.push_back(*argv); + ++argv; + --argc; + } + ErrorCode ret = HandleInputArgs(inputArgs, "all", options); + return ret; +} diff --git a/src/maple_ir/BUILD.gn b/src/maple_ir/BUILD.gn index 274dd23188e56e58611fbb4c580138d78f7e9a71..d96abd2d037564c3d53faa7e14cd62886e1e898d 100644 --- a/src/maple_ir/BUILD.gn +++ b/src/maple_ir/BUILD.gn @@ -2,6 +2,7 @@ include_directories = [ "${MAPLEALL_ROOT}/maple_ir/include", "${MAPLEALL_ROOT}/mpl2mpl/include", "${MAPLEALL_ROOT}/maple_util/include", + "${MAPLEALL_ROOT}/maple_driver/include", "${MAPLEALL_ROOT}/mempool/include", "${MAPLEALL_ROOT}/huawei_secure_c/include", "${MAPLEALL_ROOT}/maple_ipa/include", @@ -44,6 +45,9 @@ static_library("libmplir") { output_dir = "${root_out_dir}/lib/${HOST_ARCH}" libs = [] libs += [ "${OPENSOURCE_DEPS}/libmplutil.a" ] + deps = [ + "${MAPLEALL_ROOT}/maple_driver:liboption_parser", + ] } executable("irbuild") { @@ -52,12 +56,13 @@ executable("irbuild") { deps = [ ":libmplir", "${MAPLEALL_ROOT}/huawei_secure_c:libHWSecureC", + "${MAPLEALL_ROOT}/maple_driver:liboption_parser", "${MAPLEALL_ROOT}/mpl2mpl:libmpl2mpl", ] libs = [] libs += [ "${OPENSOURCE_DEPS}/libmplphase.a", "${OPENSOURCE_DEPS}/libmempool.a", - "${OPENSOURCE_DEPS}/libmaple_driverutil.a", + "${OPENSOURCE_DEPS}/libmplutil.a", ] } diff --git a/src/maple_ir/include/all_attributes.def b/src/maple_ir/include/all_attributes.def index 9593da91458e0f3f1fed095cf1648913bddc3285..3c81c255069993125598dcc37bcee528f4b47739 100644 --- a/src/maple_ir/include/all_attributes.def +++ b/src/maple_ir/include/all_attributes.def @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/lexer.h b/src/maple_ir/include/lexer.h index 246bf0f55e48130ff0a26401211fd40a070763ac..796bb0a8e95e1ffa7fa2e3229922bdd1f5396080 100644 --- a/src/maple_ir/include/lexer.h +++ b/src/maple_ir/include/lexer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -73,7 +73,7 @@ class MIRLexer { private: MIRModule &module; // for storing the different types of constant values - int64 theIntVal = 0; // also indicates preg number under kTkPreg + int64 theIntVal = 0; // also indicates preg number under TK_preg float theFloatVal = 0.0; double theDoubleVal = 0.0; MapleVector seenComments; @@ -84,7 +84,7 @@ class MIRLexer { uint32 currentLineSize = 0; uint32 curIdx = 0; uint32 lineNum = 0; - TokenKind kind = kTkInvalid; + TokenKind kind = TK_invalid; std::string name = ""; // store the name token without the % or $ prefix MapleUnorderedMap keywordMap; @@ -152,7 +152,7 @@ inline bool IsPrimitiveType(TokenKind tk) { } inline bool IsVarName(TokenKind tk) { - return (tk == kTkLname) || (tk == kTkGname); + return (tk == TK_lname) || (tk == TK_gname); } inline bool IsExprBinary(TokenKind tk) { @@ -160,7 +160,7 @@ inline bool IsExprBinary(TokenKind tk) { } inline bool IsConstValue(TokenKind tk) { - return (tk >= kTkIntconst) && (tk <= kTkDoubleconst); + return (tk >= TK_intconst) && (tk <= TK_doubleconst); } inline bool IsConstAddrExpr(TokenKind tk) { diff --git a/src/maple_ir/include/metadata_layout.h b/src/maple_ir/include/metadata_layout.h index d6e8bd49f1e82616e18163e75c21891cde2824d0..a26751599bb58f79ac2318a4b3ff3f31be8faa75 100644 --- a/src/maple_ir/include/metadata_layout.h +++ b/src/maple_ir/include/metadata_layout.h @@ -144,7 +144,7 @@ struct MByteRef { kBiasBitPosition = sizeof(refVal) * 8 - 4, // the most significant 3 bits }; - static constexpr uintptr_t FarthestOffset = 256*1024*1024; // according to kDsoLoadedAddessEnd = 0xF0000000 + static constexpr uintptr_t FarthestOffset = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 static constexpr uintptr_t PositiveOffsetBias = static_cast(6) << kBiasBitPosition; static constexpr uintptr_t PositiveOffsetMin = 0 + PositiveOffsetBias; @@ -157,7 +157,7 @@ struct MByteRef { struct MByteRef32 { uint32_t refVal; - static constexpr uint32_t FarthestOffset = 256*1024*1024; // according to kDsoLoadedAddessEnd = 0xF0000000 + static constexpr uint32_t FarthestOffset = 256 * 1024 * 1024; // according to kDsoLoadedAddessEnd = 0xF0000000 static constexpr uint32_t PositiveOffsetBias = 0x60000000; // the most significant 4 bits 0110 static constexpr uint32_t PositiveOffsetMin = 0 + PositiveOffsetBias; @@ -166,7 +166,7 @@ struct MByteRef32 { static constexpr uint32_t DirectRefMin = 0xC0000000; // according to kDsoLoadedAddessStart = 0xC0000000 static constexpr uint32_t DirectRefMax = 0xF0000000; // according to kDsoLoadedAddessEnd = 0xF0000000 - static constexpr int32_t NegativeOffsetMin = - FarthestOffset; + static constexpr int32_t NegativeOffsetMin = -FarthestOffset; static constexpr int32_t NegativeOffsetMax = 0; inline void *GetRef() const; diff --git a/src/maple_ir/include/mir_builder.h b/src/maple_ir/include/mir_builder.h index e71374778c09febba7dc3a0f643959109b1a38a7..8203754f277f928d9e206df5fac1cb551e4cb612 100644 --- a/src/maple_ir/include/mir_builder.h +++ b/src/maple_ir/include/mir_builder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_config.h b/src/maple_ir/include/mir_config.h index d3d1463af41f91bf3336f39b66f7a949c4606fbf..2f44c380c69da6c707791fae76a53f4204d0136f 100644 --- a/src/maple_ir/include/mir_config.h +++ b/src/maple_ir/include/mir_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_const.h b/src/maple_ir/include/mir_const.h index c56fbc2f5b148c6117d542e128ac2b317d1ec987..755ccca980c5b8f7b143b00862905c6e9c76ae83 100644 --- a/src/maple_ir/include/mir_const.h +++ b/src/maple_ir/include/mir_const.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_function.h b/src/maple_ir/include/mir_function.h index dd7caf2e19a1031c91175489986f25c3141dc2db..d98b82ced7b85987dd6dbec0c6fc53bc78085184 100644 --- a/src/maple_ir/include/mir_function.h +++ b/src/maple_ir/include/mir_function.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_module.h b/src/maple_ir/include/mir_module.h index 266a3b4c78f3daad5e350580d6d7c1c668929814..236c4dd41e45208a105aa570bf274f0557aaa93d 100644 --- a/src/maple_ir/include/mir_module.h +++ b/src/maple_ir/include/mir_module.h @@ -141,11 +141,11 @@ class MIRModule { return functionList; } - const MIRFunction *GetFunction(int cnt) const { + const MIRFunction *GetFunction(size_t cnt) const { CHECK_FATAL(cnt < functionList.size(), "array index out of range"); return functionList[cnt]; } - MIRFunction *GetFunction(int cnt) { + MIRFunction *GetFunction(size_t cnt) { CHECK_FATAL(cnt < functionList.size(), "array index out of range"); return functionList[cnt]; } diff --git a/src/maple_ir/include/mir_nodes.h b/src/maple_ir/include/mir_nodes.h index 4e0d7aa7fbbb4650df3efaa6d272835b28d7abfc..1190b8bfac9f70f514ef22944291315b936b9c11 100644 --- a/src/maple_ir/include/mir_nodes.h +++ b/src/maple_ir/include/mir_nodes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/mir_parser.h b/src/maple_ir/include/mir_parser.h index e60f946d99890f2a65bce7d5320aa1323f033c15..3ade4ca106fed86ec961d0a7bd17b6ac2a431864 100644 --- a/src/maple_ir/include/mir_parser.h +++ b/src/maple_ir/include/mir_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -262,8 +262,8 @@ class MIRParser { void SetSrcPos(StmtNodePtr stmt, uint32 mplNum); // func for ParseExpr - Opcode paramOpForStmt = kOpUndef; - TokenKind paramTokenKindForStmt = kTkInvalid; + Opcode paramOpForStmt = OP_undef; + TokenKind paramTokenKindForStmt = TK_invalid; // func and param for ParseStmtBlock MIRFunction *paramCurrFuncForParseStmtBlock = nullptr; MIRLexer lexer; @@ -284,7 +284,7 @@ class MIRParser { uint32 paramFileIdx = 0; // param for ParseMIR() bool paramIsIPA = false; bool paramIsComb = false; - TokenKind paramTokenKind = kTkInvalid; + TokenKind paramTokenKind = TK_invalid; std::vector paramImportFileList; }; } // namespace maple diff --git a/src/maple_ir/include/mir_pragma.h b/src/maple_ir/include/mir_pragma.h index df125480afccca9e4503ac49ae820726457ea299..b388167ae7a38d3fd724ef93950fe123612b69c2 100644 --- a/src/maple_ir/include/mir_pragma.h +++ b/src/maple_ir/include/mir_pragma.h @@ -102,27 +102,27 @@ class MIRPragmaElement { return typeStrIdx; } - const PragmaValueType GetType() const { + PragmaValueType GetType() const { return valueType; } - const int32 GetI32Val() const { + int32 GetI32Val() const { return val.i; } - const int64 GetI64Val() const { + int64 GetI64Val() const { return val.j; } - const uint64 GetU64Val() const { + uint64 GetU64Val() const { return val.u; } - const float GetFloatVal() const { + float GetFloatVal() const { return val.f; } - const double GetDoubleVal() const { + double GetDoubleVal() const { return val.d; } diff --git a/src/maple_ir/include/mir_type.h b/src/maple_ir/include/mir_type.h index 67cdb047557d8795e3fdf24dbbee5278bcd72026..ff5dfb79835e73ddb13976caec732219ff9daadf 100644 --- a/src/maple_ir/include/mir_type.h +++ b/src/maple_ir/include/mir_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/include/opcode_info.h b/src/maple_ir/include/opcode_info.h index 05705bc948294b2c6359edbe4447429d6a9a5d68..c4d1aa145a5c3d9d287a3deb5337c8fd1836768e 100644 --- a/src/maple_ir/include/opcode_info.h +++ b/src/maple_ir/include/opcode_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -59,86 +59,86 @@ class OpcodeTable { ~OpcodeTable() = default; OpcodeDesc GetTableItemAt(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o]; } bool IsStmt(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISSTMT; } bool IsVarSize(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISVARSIZE; } bool NotMMPL(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODENOTMMPL; } bool IsCompare(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISCOMPARE; } bool IsTypeCvt(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISTYPECVT; } bool HasSSAUse(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEHASSSAUSE; } bool HasSSADef(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEHASSSADEF; } bool IsCall(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISCALL; } bool IsCallAssigned(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEISCALLASSIGNED; } bool NotPure(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODENOTPURE; } bool MayThrowException(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].flag & OPCODEMAYTHROWEXCEPTION; } bool HasSideEffect(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return MayThrowException(o); } const char *GetName(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return table[o].name; } bool IsCondBr(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return o == OP_brtrue || o == OP_brfalse; } bool AssignActualVar(Opcode o) const { - ASSERT(o < kOpLast, "invalid opcode"); + ASSERT(o < OP_last, "invalid opcode"); return o == OP_dassign || o == OP_regassign; } private: - OpcodeDesc table[kOpLast]; + OpcodeDesc table[OP_last]; }; extern const OpcodeTable kOpcodeInfo; } // namespace maple diff --git a/src/maple_ir/include/opcodes.h b/src/maple_ir/include/opcodes.h index e85f42f914e63c24897fc7d22c17ab8f565cd1c6..7fb3fce192ec6c66790c488a78a9f34faabfaf43 100644 --- a/src/maple_ir/include/opcodes.h +++ b/src/maple_ir/include/opcodes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -18,11 +18,11 @@ namespace maple { enum Opcode : uint8 { - kOpUndef, + OP_undef, #define OPCODE(STR, YY, ZZ, SS) OP_##STR, #include "opcodes.def" #undef OPCODE - kOpLast, + OP_last, }; inline constexpr bool IsDAssign(Opcode code) { @@ -106,7 +106,10 @@ constexpr bool IsStmtMustRequire(Opcode opcode) { case OP_membarstorestore: case OP_assertnonnull: case OP_eval: - case OP_free: { + case OP_free: + case OP_incref: + case OP_decref: + case OP_decrefreset: { return true; } default: diff --git a/src/maple_ir/include/tokens.h b/src/maple_ir/include/tokens.h index 56842432e3d1c0babf3bafad134e6a0336ebc50b..e27f7f2c19edb8cb8353d493f800d7fc5b7c3558 100644 --- a/src/maple_ir/include/tokens.h +++ b/src/maple_ir/include/tokens.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -17,47 +17,47 @@ namespace maple { enum TokenKind { - kTkInvalid, + TK_invalid, // keywords from this file #define KEYWORD(STR) TK_##STR, #include "keywords.def" #undef KEYWORD // non-keywords starting here // constants - kTkIntconst, - kTkFloatconst, - kTkDoubleconst, + TK_intconst, + TK_floatconst, + TK_doubleconst, // local name - kTkLname, + TK_lname, // global name - kTkGname, + TK_gname, // function name - kTkFname, + TK_fname, // pseudo register - kTkPreg, + TK_preg, // special register - kTkSpecialreg, + TK_specialreg, // parent field - kTkPrntfield, + TK_prntfield, // type parameter name - kTkTypeparam, + TK_typeparam, // misc. - kTkNewline, - kTkLparen, // ( - kTkRparen, // ) - kTkLbrace, // { - kTkRbrace, // } - kTkLbrack, // [ - kTkRbrack, // ] - kTkLangle, // < - kTkRangle, // > - kTkEqsign, // = - kTkComa, // , - kTkDotdotdot, // ... - kTkColon, // : - kTkAsterisk, // * - kTkString, // a literal string enclosed between " - kTkEof + TK_newline, + TK_lparen, // ( + TK_rparen, // ) + TK_lbrace, // { + TK_rbrace, // } + TK_lbrack, // [ + TK_rbrack, // ] + TK_langle, // < + TK_rangle, // > + TK_eqsign, // = + TK_coma, // , + TK_dotdotdot, // ... + TK_colon, // : + TK_asterisk, // * + TK_string, // a literal string enclosed between " + TK_eof }; } // namespace maple #endif // MAPLE_IR_INCLUDE_TOKENS_H diff --git a/src/maple_ir/src/bin_mpl_export.cpp b/src/maple_ir/src/bin_mpl_export.cpp index 0f64c1577960eb29bfecac79769250c50e9be05d..95d238ca0631e70699acc8d2b58b69958598ebc2 100644 --- a/src/maple_ir/src/bin_mpl_export.cpp +++ b/src/maple_ir/src/bin_mpl_export.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/src/global_tables.cpp b/src/maple_ir/src/global_tables.cpp index 8d0a8094c313633b29b91f1a703c219096927042..c7968ca4b45fc52a2d2765579251b97f68b27a60 100644 --- a/src/maple_ir/src/global_tables.cpp +++ b/src/maple_ir/src/global_tables.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/src/lexer.cpp b/src/maple_ir/src/lexer.cpp index af96c361cdcf771489c964609f05d3e99889aab6..7f6745a0f4bf23a572f3d556af0266c08e7c74ff 100644 --- a/src/maple_ir/src/lexer.cpp +++ b/src/maple_ir/src/lexer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -85,7 +85,7 @@ void MIRLexer::PrepareForFile(const std::string &filename) { } else { lineNum = 1; } - kind = kTkInvalid; + kind = TK_invalid; } void MIRLexer::PrepareForString(const std::string &src) { @@ -122,7 +122,7 @@ TokenKind MIRLexer::GetConstVal(){ if (c == '-') { c = GetNextCurrentCharWithUpperCheck(); TokenKind tk = GetSpecialFloatConst(); - if (tk != kTkInvalid) { + if (tk != TK_invalid) { return tk; } negative = true; @@ -138,7 +138,7 @@ TokenKind MIRLexer::GetConstVal(){ } char cs = GetCharAtWithUpperCheck(startIdx); if (!isdigit(cs) && c != '.') { - return kTkInvalid; + return TK_invalid; } if (c != '.' && c != 'f' && c != 'F' && c != 'e' && c != 'E') { curIdx = startIdx; @@ -153,31 +153,31 @@ TokenKind MIRLexer::GetSpecialFloatConst() { if (line.compare(curIdx, lenSpecFloat, "inff") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { curIdx += lenSpecFloat; theFloatVal = -INFINITY; - return kTkFloatconst; + return TK_floatconst; } if (line.compare(curIdx, lenSpecDouble, "inf") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { curIdx += lenSpecDouble; theDoubleVal = -INFINITY; - return kTkDoubleconst; + return TK_doubleconst; } if (line.compare(curIdx, lenSpecFloat, "nanf") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecFloat))) { curIdx += lenSpecFloat; theFloatVal = -NAN; - return kTkFloatconst; + return TK_floatconst; } if (line.compare(curIdx, lenSpecDouble, "nan") == 0 && !isalnum(GetCharAtWithUpperCheck(curIdx + lenSpecDouble))) { curIdx += lenSpecDouble; theDoubleVal = -NAN; - return kTkDoubleconst; + return TK_doubleconst; } - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetHexConst(uint32 valStart, bool negative) { char c = GetCharAtWithUpperCheck(curIdx); if (!isxdigit(c)) { name = line.substr(valStart, curIdx - valStart); - return kTkInvalid; + return TK_invalid; } uint64 tmp = static_cast(HexCharToDigit(c)); c = GetNextCurrentCharWithUpperCheck(); @@ -196,7 +196,7 @@ TokenKind MIRLexer::GetHexConst(uint32 valStart, bool negative) { theDoubleVal = -theDoubleVal; } name = line.substr(valStart, curIdx - valStart); - return kTkIntconst; + return TK_intconst; } TokenKind MIRLexer::GetIntConst(uint32 valStart, bool negative) { @@ -236,7 +236,7 @@ TokenKind MIRLexer::GetIntConst(uint32 valStart, bool negative) { theFloatVal = -theFloatVal; theDoubleVal = -theDoubleVal; } - return kTkIntconst; + return TK_intconst; } TokenKind MIRLexer::GetFloatConst(uint32 valStart, uint32 startIdx, bool negative) { @@ -252,7 +252,7 @@ TokenKind MIRLexer::GetFloatConst(uint32 valStart, uint32 startIdx, bool negativ c = GetNextCurrentCharWithUpperCheck(); if (!isdigit(c) && c != '-' && c != '+') { name = line.substr(valStart, curIdx - valStart); - return kTkInvalid; + return TK_invalid; } if (c == '-' || c == '+') { c = GetNextCurrentCharWithUpperCheck(); @@ -285,7 +285,7 @@ TokenKind MIRLexer::GetFloatConst(uint32 valStart, uint32 startIdx, bool negativ theDoubleVal = -theDoubleVal; } name = line.substr(valStart, curIdx - valStart); - return kTkFloatconst; + return TK_floatconst; } else { int eNum = sscanf_s(floatStr.c_str(), "%le", &theDoubleVal); CHECK_FATAL(eNum == 1, "sscanf_s failed"); @@ -299,7 +299,7 @@ TokenKind MIRLexer::GetFloatConst(uint32 valStart, uint32 startIdx, bool negativ theFloatVal = -theFloatVal; } name = line.substr(valStart, curIdx - valStart); - return kTkDoubleconst; + return TK_doubleconst; } } @@ -308,12 +308,12 @@ TokenKind MIRLexer::GetTokenWithPrefixDollar() { char c = GetCharAtWithUpperCheck(curIdx); if (isalpha(c) || c == '_' || c == '$') { GenName(); - return kTkGname; + return TK_gname; } else { // for error reporting. const uint32 printLength = 2; name = line.substr(curIdx - 1, printLength); - return kTkInvalid; + return TK_invalid; } } @@ -329,18 +329,18 @@ TokenKind MIRLexer::GetTokenWithPrefixPercent() { c = GetNextCurrentCharWithUpperCheck(); } name = line.substr(valStart, curIdx - valStart); - return kTkPreg; + return TK_preg; } if (isalpha(c) || c == '_' || c == '$') { GenName(); - return kTkLname; + return TK_lname; } if (c == '%' && isalpha(GetCharAtWithUpperCheck(curIdx + 1))) { ++curIdx; GenName(); - return kTkSpecialreg; + return TK_specialreg; } - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetTokenWithPrefixAmpersand() { @@ -348,12 +348,12 @@ TokenKind MIRLexer::GetTokenWithPrefixAmpersand() { char c = GetCurrentCharWithUpperCheck(); if (isalpha(c) || c == '_') { GenName(); - return kTkFname; + return TK_fname; } // for error reporting. constexpr uint32 printLength = 2; name = line.substr(curIdx - 1, printLength); - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetTokenWithPrefixAtOrCircumflex(char prefix) { @@ -364,9 +364,9 @@ TokenKind MIRLexer::GetTokenWithPrefixAtOrCircumflex(char prefix) { if (prefix == '@') { return TK_label; } - return kTkPrntfield; + return TK_prntfield; } - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetTokenWithPrefixExclamation() { @@ -374,21 +374,21 @@ TokenKind MIRLexer::GetTokenWithPrefixExclamation() { char c = GetCurrentCharWithUpperCheck(); if (isalpha(c)) { GenName(); - return kTkTypeparam; + return TK_typeparam; } // for error reporting. const uint32 printLength = 2; name = line.substr(curIdx - 1, printLength); - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetTokenWithPrefixQuotation() { if (GetCharAtWithUpperCheck(curIdx + 1) == '\'') { theIntVal = GetCharAtWithUpperCheck(curIdx); curIdx += 2; - return kTkIntconst; + return TK_intconst; } - return kTkInvalid; + return TK_invalid; } TokenKind MIRLexer::GetTokenWithPrefixDoubleQuotation() { @@ -476,7 +476,7 @@ TokenKind MIRLexer::GetTokenWithPrefixDoubleQuotation() { c = GetNextCurrentCharWithUpperCheck(); } if (c != '\"') { - return kTkInvalid; + return TK_invalid; } // for empty string if (startIdx == curIdx) { @@ -485,7 +485,7 @@ TokenKind MIRLexer::GetTokenWithPrefixDoubleQuotation() { name = line.substr(startIdx, curIdx - startIdx - shift); } ++curIdx; - return kTkString; + return TK_string; } TokenKind MIRLexer::GetTokenSpecial() { @@ -497,22 +497,22 @@ TokenKind MIRLexer::GetTokenSpecial() { switch (tk) { case TK_nanf: theFloatVal = NAN; - return kTkFloatconst; + return TK_floatconst; case TK_nan: theDoubleVal = NAN; - return kTkDoubleconst; + return TK_doubleconst; case TK_inff: theFloatVal = INFINITY; - return kTkFloatconst; + return TK_floatconst; case TK_inf: theDoubleVal = INFINITY; - return kTkDoubleconst; + return TK_doubleconst; default: return tk; } } MIR_ERROR("error in input file\n"); - return kTkEof; + return TK_eof; } TokenKind MIRLexer::LexToken() { @@ -527,7 +527,7 @@ TokenKind MIRLexer::LexToken() { seenComments.push_back(line.substr(curIdx + 1, currentLineSize - curIdx - 1)); } if (ReadALine() < 0) { - return kTkEof; + return TK_eof; } ++lineNum; // a new line readed. // skip spaces @@ -540,36 +540,36 @@ TokenKind MIRLexer::LexToken() { ++curIdx; switch (curChar) { case '\n': - return kTkNewline; + return TK_newline; case '(': - return kTkLparen; + return TK_lparen; case ')': - return kTkRparen; + return TK_rparen; case '{': - return kTkLbrace; + return TK_lbrace; case '}': - return kTkRbrace; + return TK_rbrace; case '[': - return kTkLbrack; + return TK_lbrack; case ']': - return kTkRbrack; + return TK_rbrack; case '<': - return kTkLangle; + return TK_langle; case '>': - return kTkRangle; + return TK_rangle; case '=': - return kTkEqsign; + return TK_eqsign; case ',': - return kTkComa; + return TK_coma; case ':': - return kTkColon; + return TK_colon; case '*': - return kTkAsterisk; + return TK_asterisk; case '.': if (GetCharAtWithUpperCheck(curIdx) == '.') { const uint32 lenDotdot = 2; curIdx += lenDotdot; - return kTkDotdotdot; + return TK_dotdotdot; } // fall thru for .9100 == 0.9100 case '0': @@ -613,18 +613,18 @@ TokenKind MIRLexer::NextToken() { std::string MIRLexer::GetTokenString() const { std::string temp; switch (kind) { - case kTkGname: { + case TK_gname: { temp = "$"; temp.append(name); return temp; } - case kTkLname: - case kTkPreg: { + case TK_lname: + case TK_preg: { temp = "%"; temp.append(name); return temp; } - case kTkSpecialreg: { + case TK_specialreg: { temp = "%%"; temp.append(name); return temp; @@ -634,81 +634,81 @@ std::string MIRLexer::GetTokenString() const { temp.append(name); return temp; } - case kTkPrntfield: { + case TK_prntfield: { temp = "^"; temp.append(name); return temp; } - case kTkIntconst: { + case TK_intconst: { temp = std::to_string(theIntVal); return temp; } - case kTkFloatconst: { + case TK_floatconst: { temp = std::to_string(theFloatVal); return temp; } - case kTkDoubleconst: { + case TK_doubleconst: { temp = std::to_string(theDoubleVal); return temp; } // misc. - case kTkNewline: { + case TK_newline: { temp = "\\n"; return temp; } - case kTkLparen: { + case TK_lparen: { temp = "("; return temp; } - case kTkRparen: { + case TK_rparen: { temp = ")"; return temp; } - case kTkLbrace: { + case TK_lbrace: { temp = "{"; return temp; } - case kTkRbrace: { + case TK_rbrace: { temp = "}"; return temp; } - case kTkLbrack: { + case TK_lbrack: { temp = "["; return temp; } - case kTkRbrack: { + case TK_rbrack: { temp = "]"; return temp; } - case kTkLangle: { + case TK_langle: { temp = "<"; return temp; } - case kTkRangle: { + case TK_rangle: { temp = ">"; return temp; } - case kTkEqsign: { + case TK_eqsign: { temp = "="; return temp; } - case kTkComa: { + case TK_coma: { temp = ","; return temp; } - case kTkDotdotdot: { + case TK_dotdotdot: { temp = "..."; return temp; } - case kTkColon: { + case TK_colon: { temp = ":"; return temp; } - case kTkAsterisk: { + case TK_asterisk: { temp = "*"; return temp; } - case kTkString: { + case TK_string: { temp = "\""; temp.append(name); temp.append("\""); diff --git a/src/maple_ir/src/mir_function.cpp b/src/maple_ir/src/mir_function.cpp index 9cb1db022c7d1971afa40d275d8406a72d8e1f45..fb0d24b3e212dba7da6e0ac58c126b239067bbb0 100644 --- a/src/maple_ir/src/mir_function.cpp +++ b/src/maple_ir/src/mir_function.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. diff --git a/src/maple_ir/src/mir_parser.cpp b/src/maple_ir/src/mir_parser.cpp index b3b8c4aaf95b59f04d76a72c063a204960d3e7ea..4d2810e998e366b01bf64e5535994b4fbca2bd0b 100644 --- a/src/maple_ir/src/mir_parser.cpp +++ b/src/maple_ir/src/mir_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -43,7 +43,7 @@ bool MIRParser::ParseStmtDassign(StmtNodePtr &stmt) { assignStmt->SetStIdx(stidx); TokenKind nextToken = lexer.NextToken(); // parse field id - if (nextToken == kTkIntconst) { // may be a field id + if (nextToken == TK_intconst) { // may be a field id assignStmt->SetFieldID(lexer.GetTheIntVal()); (void)lexer.NextToken(); } @@ -66,14 +66,14 @@ bool MIRParser::ParseStmtRegassign(StmtNodePtr &stmt) { auto *regAssign = mod.CurFuncCodeMemPool()->New(); regAssign->SetPrimType(GetPrimitiveType(lexer.GetTokenKind())); lexer.NextToken(); - if (lexer.GetTokenKind() == kTkSpecialreg) { + if (lexer.GetTokenKind() == TK_specialreg) { PregIdx tempPregIdx = regAssign->GetRegIdx(); bool isSuccess = ParseSpecialReg(tempPregIdx); regAssign->SetRegIdx(tempPregIdx); if (!isSuccess) { return false; } - } else if (lexer.GetTokenKind() == kTkPreg) { + } else if (lexer.GetTokenKind() == TK_preg) { PregIdx tempPregIdx = regAssign->GetRegIdx(); bool isSuccess = ParsePseudoReg(regAssign->GetPrimType(), tempPregIdx); regAssign->SetRegIdx(tempPregIdx); @@ -126,7 +126,7 @@ bool MIRParser::ParseStmtIassign(StmtNodePtr &stmt) { } auto *iAssign = mod.CurFuncCodeMemPool()->New(); iAssign->SetTyIdx(tyIdx); - if (lexer.GetTokenKind() == kTkIntconst) { + if (lexer.GetTokenKind() == TK_intconst) { iAssign->SetFieldID(lexer.theIntVal); lexer.NextToken(); } @@ -151,7 +151,7 @@ bool MIRParser::ParseStmtIassignoff(StmtNodePtr &stmt) { // iassign ( , ) auto *iAssignOff = mod.CurFuncCodeMemPool()->New(); iAssignOff->SetPrimType(GetPrimitiveType(lexer.GetTokenKind())); - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect offset but get "); return false; } @@ -177,7 +177,7 @@ bool MIRParser::ParseStmtIassignFPoff(StmtNodePtr &stmt) { // iassignfpoff ( ) auto *iAssignOff = mod.CurFuncCodeMemPool()->New(); iAssignOff->SetPrimType(GetPrimitiveType(lexer.GetTokenKind())); - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect offset but get "); return false; } @@ -199,7 +199,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { auto *doLoopNode = mod.CurFuncCodeMemPool()->New(); stmt = doLoopNode; lexer.NextToken(); - if (lexer.GetTokenKind() == kTkPreg) { + if (lexer.GetTokenKind() == TK_preg) { PregIdx pregIdx = LookupOrCreatePregIdx(static_cast(lexer.GetTheIntVal()), false, *mod.CurFunction()); doLoopNode->SetIsPreg(true); doLoopNode->SetDoVarStFullIdx(pregIdx); @@ -220,7 +220,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { doLoopNode->SetDoVarStIdx(stIdx); } // parse ( - if (lexer.NextToken() != kTkLparen) { + if (lexer.NextToken() != TK_lparen) { Error("expect ( but get "); return false; } @@ -239,7 +239,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { mpReg->SetPrimType(start->GetPrimType()); } } - if (lexer.GetTokenKind() != kTkComa) { + if (lexer.GetTokenKind() != TK_coma) { Error("expect , after start expression but get "); return false; } @@ -251,7 +251,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { Error("ParseStmtDoloop when parsing end expression"); return false; } - if (lexer.GetTokenKind() != kTkComa) { + if (lexer.GetTokenKind() != TK_coma) { Error("expect , after condition expression but get "); return false; } @@ -264,7 +264,7 @@ bool MIRParser::ParseStmtDoloop(StmtNodePtr &stmt) { return false; } // parse ) - if (lexer.GetTokenKind() != kTkRparen) { + if (lexer.GetTokenKind() != TK_rparen) { Error("expect ) parsing doloop but get "); return false; } @@ -331,7 +331,7 @@ bool MIRParser::ParseStmtIf(StmtNodePtr &stmt) { return false; } ifStmt->SetOpnd(expr); - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { begin if body but get "); return false; } @@ -344,7 +344,7 @@ bool MIRParser::ParseStmtIf(StmtNodePtr &stmt) { BlockNode *elseBlock = nullptr; if (lexer.GetTokenKind() == TK_else) { // has else part - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { begin if body but get "); return false; } @@ -373,7 +373,7 @@ bool MIRParser::ParseStmtWhile(StmtNodePtr &stmt) { return false; } whileStmt->SetOpnd(expr); - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { begin if body but get "); return false; } @@ -393,7 +393,7 @@ bool MIRParser::ParseStmtDowhile(StmtNodePtr &stmt) { return false; } auto *whileStmt = mod.CurFuncCodeMemPool()->New(OP_dowhile); - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { begin if body but get "); return false; } @@ -493,12 +493,12 @@ bool MIRParser::ParseStmtBr(StmtNodePtr &stmt) { bool MIRParser::ParseSwitchCase(int32 &constVal, LabelIdx &lblIdx) { // syntax : goto - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect intconst in switch but get "); return false; } constVal = lexer.GetTheIntVal(); - if (lexer.NextToken() != kTkColon) { + if (lexer.NextToken() != TK_colon) { Error("expect : in switch but get "); return false; } @@ -534,7 +534,7 @@ bool MIRParser::ParseStmtSwitch(StmtNodePtr &stmt) { Error("expect label in switch but get "); return false; } - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { in switch but get "); return false; } @@ -544,7 +544,7 @@ bool MIRParser::ParseStmtSwitch(StmtNodePtr &stmt) { // : goto TokenKind tk = lexer.NextToken(); std::set casesSet; - while (tk != kTkRbrace) { + while (tk != TK_rbrace) { int32 constVal = 0; LabelIdx lbl = 0; if (!ParseSwitchCase(constVal, lbl)) { @@ -576,13 +576,13 @@ bool MIRParser::ParseStmtRangegoto(StmtNodePtr &stmt) { Error("expect expression return integer but get "); return false; } - if (lexer.NextToken() == kTkIntconst) { + if (lexer.NextToken() == TK_intconst) { rangeGotoNode->SetTagOffset(lexer.GetTheIntVal()); } else { Error("expect tag offset in rangegoto but get "); return false; } - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { in switch but get "); return false; } @@ -594,7 +594,7 @@ bool MIRParser::ParseStmtRangegoto(StmtNodePtr &stmt) { std::set casesSet; int32 minIdx = UINT16_MAX; int32 maxIdx = 0; - while (tk != kTkRbrace) { + while (tk != TK_rbrace) { int32 constVal = 0; LabelIdx lbl = 0; if (!ParseSwitchCase(constVal, lbl)) { @@ -644,7 +644,7 @@ bool MIRParser::ParseStmtMultiway(StmtNodePtr &stmt) { Error("expect label in multiway but get "); return false; } - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { in switch but get "); return false; } @@ -653,12 +653,12 @@ bool MIRParser::ParseStmtMultiway(StmtNodePtr &stmt) { // ... // (): goto TokenKind tk = lexer.NextToken(); - while (tk != kTkRbrace) { + while (tk != TK_rbrace) { BaseNode *x = nullptr; if (!ParseExprOneOperand(x)) { return false; } - if (lexer.NextToken() != kTkColon) { + if (lexer.NextToken() != TK_colon) { Error("expect : parsing multiway case tag specification but get "); return false; } @@ -751,7 +751,7 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { TyIdx polymophicTyidx(0); if (o == OP_polymorphiccallassigned || o == OP_polymorphiccall) { TokenKind nextTk = lexer.NextToken(); - if (nextTk == kTkLangle) { + if (nextTk == TK_langle) { nextTk = lexer.NextToken(); if (nextTk == TK_func) { lexer.NextToken(); @@ -769,7 +769,7 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { } } TokenKind funcTk = lexer.NextToken(); - if (funcTk != kTkFname) { + if (funcTk != TK_fname) { Error("expect func name in call but get "); return false; } @@ -789,12 +789,12 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { callStmt->SetTyIdx(polymophicTyidx); } else if (hasInstant) { TokenKind langleTk = lexer.GetTokenKind(); - if (langleTk != kTkLangle) { + if (langleTk != TK_langle) { Error("missing < in generic method instantiation at "); return false; } TokenKind lbraceTk = lexer.NextToken(); - if (lbraceTk != kTkLbrace) { + if (lbraceTk != TK_lbrace) { Error("missing { in generic method instantiation at "); return false; } @@ -804,7 +804,7 @@ bool MIRParser::ParseStmtCall(StmtNodePtr &stmt) { return false; } TokenKind rangleTk = lexer.GetTokenKind(); - if (rangleTk != kTkRangle) { + if (rangleTk != TK_rangle) { Error("missing > in generic method instantiation at "); return false; } @@ -982,12 +982,12 @@ bool MIRParser::ParseCallReturns(CallReturnVector &retsvec) { // regassign // regassign // } - if (lexer.NextToken() != kTkLbrace) { + if (lexer.NextToken() != TK_lbrace) { Error("expect { parsing call return values. "); return false; } TokenKind tk = lexer.NextToken(); - while (tk != kTkRbrace) { + while (tk != TK_rbrace) { if (lexer.GetTokenKind() != TK_dassign && lexer.GetTokenKind() != TK_regassign) { Error("expect dassign/regassign but get "); return false; @@ -1001,7 +1001,7 @@ bool MIRParser::ParseCallReturns(CallReturnVector &retsvec) { if (!ParseDeclaredSt(stidx)) { return false; } - if (lexer.GetTokenKind() == kTkLname) { + if (lexer.GetTokenKind() == TK_lname) { MIRSymbolTable *lSymTab = mod.CurFunction()->GetSymTab(); MIRSymbol *lSym = lSymTab->GetSymbolFromStIdx(stidx.Idx(), 0); ASSERT(lSym != nullptr, "lsym MIRSymbol is null"); @@ -1022,7 +1022,7 @@ bool MIRParser::ParseCallReturns(CallReturnVector &retsvec) { uint16 fieldId = 0; TokenKind nextToken = lexer.NextToken(); // parse field id - if (nextToken == kTkIntconst) { + if (nextToken == TK_intconst) { fieldId = lexer.GetTheIntVal(); } else { Error("expect a fieldID parsing ParseCallAssignedStmts. "); @@ -1047,12 +1047,12 @@ bool MIRParser::ParseCallReturns(CallReturnVector &retsvec) { } PrimType ptype = GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(tyidx); PregIdx pregIdx; - if (lexer.GetTokenKind() == kTkSpecialreg) { + if (lexer.GetTokenKind() == TK_specialreg) { if (!ParseSpecialReg(pregIdx)) { Error("expect specialreg parsing callassign CallReturnVector"); return false; } - } else if (lexer.GetTokenKind() == kTkPreg) { + } else if (lexer.GetTokenKind() == TK_preg) { if (!ParsePseudoReg(ptype, pregIdx)) { Error("expect pseudoreg parsing callassign CallReturnVector"); return false; @@ -1076,7 +1076,7 @@ bool MIRParser::ParseStmtJsTry(StmtNodePtr &stmt) { auto *tryNode = mod.CurFuncCodeMemPool()->New(); lexer.NextToken(); // parse handler label - if (lexer.GetTokenKind() == kTkIntconst && lexer.GetTheIntVal() == 0) { + if (lexer.GetTokenKind() == TK_intconst && lexer.GetTheIntVal() == 0) { tryNode->SetCatchOffset(0); } else { if (lexer.GetTokenKind() != TK_label) { @@ -1094,7 +1094,7 @@ bool MIRParser::ParseStmtJsTry(StmtNodePtr &stmt) { } lexer.NextToken(); // parse finally label - if (lexer.GetTokenKind() == kTkIntconst && lexer.GetTheIntVal() == 0) { + if (lexer.GetTokenKind() == TK_intconst && lexer.GetTheIntVal() == 0) { tryNode->SetFinallyOffset(0); } else { if (lexer.GetTokenKind() != TK_label) { @@ -1118,10 +1118,10 @@ bool MIRParser::ParseStmtJsTry(StmtNodePtr &stmt) { bool MIRParser::ParseStmtTry(StmtNodePtr &stmt) { auto *tryNode = mod.CurFuncCodeMemPool()->New(mod); lexer.NextToken(); - ASSERT(lexer.GetTokenKind() == kTkLbrace, "expect left brace in try but get "); + ASSERT(lexer.GetTokenKind() == TK_lbrace, "expect left brace in try but get "); lexer.NextToken(); // parse handler label - while (lexer.GetTokenKind() != kTkRbrace) { + while (lexer.GetTokenKind() != TK_rbrace) { if (lexer.GetTokenKind() != TK_label) { Error("expect handler label in try but get "); return false; @@ -1144,9 +1144,9 @@ bool MIRParser::ParseStmtTry(StmtNodePtr &stmt) { bool MIRParser::ParseStmtCatch(StmtNodePtr &stmt) { auto *catchNode = mod.CurFuncCodeMemPool()->New(mod); lexer.NextToken(); - ASSERT(lexer.GetTokenKind() == kTkLbrace, "expect left brace in catch but get "); + ASSERT(lexer.GetTokenKind() == TK_lbrace, "expect left brace in catch but get "); lexer.NextToken(); - while (lexer.GetTokenKind() != kTkRbrace) { + while (lexer.GetTokenKind() != TK_rbrace) { TyIdx tyidx(0); if (!ParseType(tyidx)) { Error("expect type parsing java catch statement"); @@ -1284,12 +1284,12 @@ bool MIRParser::ParseBinaryStmtAssertLT(StmtNodePtr &stmt) { bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { auto *stmtReturn = mod.CurFuncCodeMemPool()->New(mod, op); - if (lexer.NextToken() != kTkLparen) { + if (lexer.NextToken() != TK_lparen) { Error("expect return with ( but get "); return false; } TokenKind exprTk = lexer.NextToken(); - if (exprTk == kTkRparen) { // no operand + if (exprTk == TK_rparen) { // no operand stmt = stmtReturn; lexer.NextToken(); return true; @@ -1301,7 +1301,7 @@ bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { } stmtReturn->GetNopnd().push_back(expr); if (op == OP_syncenter) { - if (lexer.GetTokenKind() == kTkComa) { + if (lexer.GetTokenKind() == TK_coma) { lexer.NextToken(); BaseNode *exprSync = nullptr; if (!ParseExpression(exprSync)) { @@ -1320,7 +1320,7 @@ bool MIRParser::ParseNaryStmt(StmtNodePtr &stmt, Opcode op) { stmtReturn->SetNumOpnds(stmtReturn->GetNopndSize()); } } - if (lexer.GetTokenKind() != kTkRparen) { + if (lexer.GetTokenKind() != TK_rparen) { Error("expect ) parsing return but get "); return false; } @@ -1343,12 +1343,12 @@ bool MIRParser::ParseNaryStmtSyncExit(StmtNodePtr &stmt) { } bool MIRParser::ParseLoc(StmtNodePtr &stmt) { - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect intconst in LOC but get "); return false; } lastFileNum = lexer.GetTheIntVal(); - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect intconst in LOC but get "); return false; } @@ -1384,7 +1384,7 @@ bool MIRParser::ParseStatement(StmtNodePtr &stmt) { /* parse the statements enclosed by { and } */ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { - if (lexer.GetTokenKind() != kTkLbrace) { + if (lexer.GetTokenKind() != TK_lbrace) { Error("expect { for func body but get "); return false; } @@ -1418,7 +1418,7 @@ bool MIRParser::ParseStmtBlock(BlockNodePtr &blk) { } else { std::map::iterator itFuncPtr = funcPtrMapForParseStmtBlock.find(stmtTk); if (itFuncPtr == funcPtrMapForParseStmtBlock.end()) { - if (stmtTk == kTkRbrace) { + if (stmtTk == TK_rbrace) { ParseStmtBlockForSeenComment(blk, mplNum); lexer.NextToken(); return true; @@ -1476,7 +1476,7 @@ bool MIRParser::ParseStmtBlockForTempVar() { bool MIRParser::ParseStmtBlockForReg() { lexer.NextToken(); - if (lexer.GetTokenKind() != kTkPreg) { + if (lexer.GetTokenKind() != TK_preg) { Error("expect %%preg after reg"); return false; } @@ -1493,7 +1493,7 @@ bool MIRParser::ParseStmtBlockForReg() { ASSERT(tyidx > 0, "parse declare var failed "); MIRType *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); preg->SetMIRType(mirType); - if (lexer.GetTokenKind() == kTkIntconst) { + if (lexer.GetTokenKind() == TK_intconst) { int64 theIntVal = lexer.GetTheIntVal(); if (theIntVal != 0 && theIntVal != 1) { Error("parseDeclareReg failed"); @@ -1519,7 +1519,7 @@ bool MIRParser::ParseStmtBlockForType() { bool MIRParser::ParseStmtBlockForFrameSize() { MIRFunction *fn = paramCurrFuncForParseStmtBlock; lexer.NextToken(); - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect integer after frameSize but get "); return false; } @@ -1531,7 +1531,7 @@ bool MIRParser::ParseStmtBlockForFrameSize() { bool MIRParser::ParseStmtBlockForUpformalSize() { MIRFunction *fn = paramCurrFuncForParseStmtBlock; lexer.NextToken(); - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect integer after upFormalSize but get "); return false; } @@ -1543,7 +1543,7 @@ bool MIRParser::ParseStmtBlockForUpformalSize() { bool MIRParser::ParseStmtBlockForModuleID() { MIRFunction *fn = paramCurrFuncForParseStmtBlock; lexer.NextToken(); - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect integer after moduleid but get "); return false; } @@ -1555,7 +1555,7 @@ bool MIRParser::ParseStmtBlockForModuleID() { bool MIRParser::ParseStmtBlockForFuncSize() { MIRFunction *fn = paramCurrFuncForParseStmtBlock; lexer.NextToken(); - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect integer after funcSize but get "); return false; } @@ -1568,7 +1568,7 @@ bool MIRParser::ParseStmtBlockForFuncID() { // funcid is for debugging purpose MIRFunction *fn = paramCurrFuncForParseStmtBlock; lexer.NextToken(); - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect integer after funcid but get "); return false; } @@ -1638,7 +1638,7 @@ static Opcode GetUnaryOp(TokenKind tk) { #include "unary_op.def" #undef UNARYOP default: - return kOpUndef; + return OP_undef; } } @@ -1650,7 +1650,7 @@ static Opcode GetBinaryOp(TokenKind tk) { #include "binary_op.def" #undef BINARYOP default: - return kOpUndef; + return OP_undef; } } @@ -1667,12 +1667,12 @@ static Opcode GetConvertOp(TokenKind tk) { case TK_trunc: return OP_trunc; default: - return kOpUndef; + return OP_undef; } } bool MIRParser::ParseExprOneOperand(BaseNodePtr &expr) { - if (lexer.GetTokenKind() != kTkLparen) { + if (lexer.GetTokenKind() != TK_lparen) { Error("expect ( parsing operand parsing unary "); return false; } @@ -1681,7 +1681,7 @@ bool MIRParser::ParseExprOneOperand(BaseNodePtr &expr) { Error("expect expression as openrand of unary expression "); return false; } - if (lexer.GetTokenKind() != kTkRparen) { + if (lexer.GetTokenKind() != TK_rparen) { Error("expect ) parsing operand parsing unary "); return false; } @@ -1689,7 +1689,7 @@ bool MIRParser::ParseExprOneOperand(BaseNodePtr &expr) { } bool MIRParser::ParseExprTwoOperand(BaseNodePtr &opnd0, BaseNodePtr &opnd1) { - if (lexer.GetTokenKind() != kTkLparen) { + if (lexer.GetTokenKind() != TK_lparen) { Error("expect ( parsing operand parsing unary "); return false; } @@ -1697,7 +1697,7 @@ bool MIRParser::ParseExprTwoOperand(BaseNodePtr &opnd0, BaseNodePtr &opnd1) { if (!ParseExpression(opnd0)) { return false; } - if (lexer.GetTokenKind() != kTkComa) { + if (lexer.GetTokenKind() != TK_coma) { Error("expect , between two operands but get "); return false; } @@ -1705,7 +1705,7 @@ bool MIRParser::ParseExprTwoOperand(BaseNodePtr &opnd0, BaseNodePtr &opnd1) { if (!ParseExpression(opnd1)) { return false; } - if (lexer.GetTokenKind() != kTkRparen) { + if (lexer.GetTokenKind() != TK_rparen) { Error("expect ) parsing operand parsing unary "); return false; } @@ -1713,12 +1713,12 @@ bool MIRParser::ParseExprTwoOperand(BaseNodePtr &opnd0, BaseNodePtr &opnd1) { } bool MIRParser::ParseExprNaryOperand(MapleVector &opndVec) { - if (lexer.GetTokenKind() != kTkLparen) { + if (lexer.GetTokenKind() != TK_lparen) { Error("expect ( parsing operand parsing nary operands "); return false; } TokenKind tk = lexer.NextToken(); - while (tk != kTkRparen) { + while (tk != TK_rparen) { BaseNode *opnd = nullptr; if (!ParseExpression(opnd)) { Error("expect expression parsing nary operands "); @@ -1726,7 +1726,7 @@ bool MIRParser::ParseExprNaryOperand(MapleVector &opndVec) { } opndVec.push_back(opnd); tk = lexer.GetTokenKind(); - if (tk == kTkComa) { + if (tk == TK_coma) { tk = lexer.NextToken(); } } @@ -1742,13 +1742,13 @@ bool MIRParser::ParseDeclaredSt(StIdx &stidx) { stidx.SetFullIdx(0); return false; } - if (varTk == kTkGname) { + if (varTk == TK_gname) { stidx = GlobalTables::GetGsymTable().GetStIdxFromStrIdx(stridx); if (stidx.FullIdx() == 0) { Error("global symbol not declared "); return false; } - } else if (varTk == kTkLname) { + } else if (varTk == TK_lname) { stidx = mod.CurFunction()->GetSymTab()->GetStIdxFromStrIdx(stridx); if (stidx.FullIdx() == 0) { Error("local symbol not declared "); @@ -1807,7 +1807,7 @@ bool MIRParser::ParseExprDread(BaseNodePtr &expr) { } dexpr->SetStIdx(stidx); TokenKind endtk = lexer.NextToken(); - if (endtk == kTkIntconst) { + if (endtk == TK_intconst) { dexpr->SetFieldID(lexer.GetTheIntVal()); lexer.NextToken(); } else if (!IsDelimitationTK(endtk)) { @@ -1836,13 +1836,13 @@ bool MIRParser::ParseExprRegread(BaseNodePtr &expr) { return false; } expr->SetPrimType(GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(tyidx)); - if (lexer.GetTokenKind() == kTkSpecialreg) { + if (lexer.GetTokenKind() == TK_specialreg) { PregIdx tempPregIdx = regRead->GetRegIdx(); bool isSuccess = ParseSpecialReg(tempPregIdx); regRead->SetRegIdx(tempPregIdx); return isSuccess; } - if (lexer.GetTokenKind() == kTkPreg) { + if (lexer.GetTokenKind() == TK_preg) { if (expr->GetPrimType() == PTY_ptr || expr->GetPrimType() == PTY_ref) { PregIdx tempPregIdx = regRead->GetRegIdx(); bool isSuccess = ParseRefPseudoReg(tempPregIdx); @@ -1892,7 +1892,7 @@ bool MIRParser::ParseExprConststr(BaseNodePtr &expr) { return false; } tk = lexer.NextToken(); - if (tk != kTkString) { + if (tk != TK_string) { Error("expect string literal for conststr but get "); return false; } @@ -1915,7 +1915,7 @@ bool MIRParser::ParseExprConststr16(BaseNodePtr &expr) { return false; } tk = lexer.NextToken(); - if (tk != kTkString) { + if (tk != TK_string) { Error("expect string literal for conststr16 but get "); return false; } @@ -1966,13 +1966,13 @@ bool MIRParser::ParseExprFieldsDist(BaseNodePtr &expr) { } node->SetTyIdx(tyIdx); TokenKind tk = lexer.GetTokenKind(); - if (tk != kTkIntconst) { + if (tk != TK_intconst) { Error("expect type int but get"); return false; } node->SetFiledID1(lexer.GetTheIntVal()); tk = lexer.NextToken(); - if (tk != kTkIntconst) { + if (tk != TK_intconst) { Error("expect type int but get"); return false; } @@ -1984,7 +1984,7 @@ bool MIRParser::ParseExprFieldsDist(BaseNodePtr &expr) { bool MIRParser::ParseExprBinary(BaseNodePtr &expr) { Opcode opcode = GetBinaryOp(lexer.GetTokenKind()); - if (opcode == kOpUndef) { + if (opcode == OP_undef) { Error("expect add operator but get "); return false; } @@ -2047,12 +2047,12 @@ bool MIRParser::ParseExprDepositbits(BaseNodePtr &expr) { return false; } dpsbNode->SetPrimType(ptyp); - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect boffset but get "); return false; } dpsbNode->SetBitsOffset(lexer.GetTheIntVal()); - if (lexer.NextToken() != kTkIntconst) { + if (lexer.NextToken() != TK_intconst) { Error("expect bSize but get "); return false; } @@ -2087,7 +2087,7 @@ bool MIRParser::ParseExprIreadIaddrof(IreadNode &expr) { return false; } expr.SetTyIdx(tyidx); - if (lexer.GetTokenKind() == kTkIntconst) { + if (lexer.GetTokenKind() == TK_intconst) { expr.SetFieldID(lexer.theIntVal); lexer.NextToken(); } @@ -2139,7 +2139,7 @@ bool MIRParser::ParseExprIreadoff(BaseNodePtr &expr) { Error("only scalar types allowed for ireadoff"); return false; } - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect offset but get "); return false; } @@ -2172,7 +2172,7 @@ bool MIRParser::ParseExprIreadFPoff(BaseNodePtr &expr) { Error("only scalar types allowed for ireadoff"); return false; } - if (lexer.GetTokenKind() != kTkIntconst) { + if (lexer.GetTokenKind() != TK_intconst) { Error("expect offset but get "); return false; } @@ -2208,7 +2208,7 @@ bool MIRParser::ParseExprAddrof(BaseNodePtr &expr) { TokenKind tk = lexer.NextToken(); if (IsDelimitationTK(tk)) { addrofNode->SetFieldID(0); - } else if (tk == kTkIntconst) { + } else if (tk == TK_intconst) { addrofNode->SetFieldID(lexer.GetTheIntVal()); lexer.NextToken(); } else { @@ -2231,7 +2231,7 @@ bool MIRParser::ParseExprAddroffunc(BaseNodePtr &expr) { return false; } addrOfFuncNode->SetPrimType(GlobalTables::GetTypeTable().GetPrimTypeFromTyIdx(tyidx)); - if (lexer.GetTokenKind() != kTkFname) { + if (lexer.GetTokenKind() != TK_fname) { Error("expect function name but get "); return false; } @@ -2276,7 +2276,7 @@ bool MIRParser::ParseExprAddroflabel(BaseNodePtr &expr) { bool MIRParser::ParseExprUnary(BaseNodePtr &expr) { // syntax op