1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_ASSEMBLER_ASSEMBLY_CONTEXT_H 17 #define PANDA_ASSEMBLER_ASSEMBLY_CONTEXT_H 18 19 #include <string> 20 #include <string_view> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "assembly-ins.h" 25 #include "assembly-type.h" 26 #include "error.h" 27 #include "lexer.h" 28 29 namespace ark::pandasm { 30 31 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 32 /* 33 * Used to move around tokens. 34 * *context : 35 * Returns current value of a token 36 * ++context : 37 * sets the next token value 38 * returns current value of a token 39 * context++ : 40 * sets the next token value 41 * returns the next value of a token 42 * similarly --context and context-- 43 */ 44 struct Context { 45 std::string_view token; /* current token */ 46 std::vector<ark::pandasm::Token> tokens; /* token list */ 47 size_t number = 0; /* line number */ 48 bool end = false; /* end of line flag */ 49 Token::Type id = Token::Type::ID_BAD; /* current token type */ 50 Token::Type signop = Token::Type::ID_BAD; /* current token operand type (if it is an operation) */ 51 ark::pandasm::Error err; /* current error */ 52 int64_t *maxValueOfReg = nullptr; 53 size_t insNumber = 0; 54 Type currFuncReturnType; 55 std::vector<std::pair<size_t, size_t>> *functionArgumentsList = nullptr; 56 std::unordered_map<std::string, std::vector<std::pair<size_t, size_t>>> functionArgumentsLists; 57 58 void Make(const std::vector<ark::pandasm::Token> &t); 59 void UpSignOperation(); 60 bool ValidateRegisterName(char c, size_t n = 0) const; 61 bool ValidateFoundedRegisterName(char c, size_t n) const; 62 bool ValidateParameterName(size_t numberOfParamsAlreadyIs) const; 63 bool ValidateLabel(); 64 bool Mask(); 65 bool NextMask(); 66 size_t Len() const; 67 std::string_view GiveToken(); 68 Token::Type WaitFor(); 69 Token::Type Next(); 70 71 Token::Type operator++(int); // NOLINT(cert-dcl21-cpp) 72 Token::Type operator--(int); // NOLINT(cert-dcl21-cpp) 73 Token::Type operator++(); 74 Token::Type operator--(); 75 Token::Type operator*(); 76 }; 77 // NOLINTEND(misc-non-private-member-variables-in-classes) 78 79 } // namespace ark::pandasm 80 81 #endif // PANDA_ASSEMBLER_ASSEMBLY_CONTEXT_H 82