• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 ASSEMBLER_ASSEMBLY_CONTEXT_H
17 #define 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 panda::pandasm {
30 
31 /*
32  * Used to move around tokens.
33  * *context :
34  * Returns current value of a token
35  * ++context :
36  * sets the next token value
37  * returns current value of a token
38  * context++ :
39  * sets the next token value
40  * returns the next value of a token
41  * similarly --context and context--
42  */
43 struct Context {
44     std::string_view token;                    /* current token */
45     std::vector<panda::pandasm::Token> tokens; /* token list */
46     size_t number = 0;                         /* line number */
47     bool end = false;                          /* end of line flag */
48     Token::Type id = Token::Type::ID_BAD;      /* current token type */
49     Token::Type signop = Token::Type::ID_BAD;  /* current token operand type (if it is an operation) */
50     panda::pandasm::Error err;                 /* current error */
51     int64_t *max_value_of_reg = nullptr;
52     size_t ins_number = 0;
53     Type curr_func_return_type;
54     std::vector<std::pair<size_t, size_t>> *function_arguments_list = nullptr;
55     std::unordered_map<std::string, std::vector<std::pair<size_t, size_t>>> function_arguments_lists;
56 
57     void Make(const std::vector<panda::pandasm::Token> &t);
58     void UpSignOperation();
59     bool ValidateRegisterName(char c, size_t n = 0) const;
60     bool ValidateParameterName(size_t number_of_params_already_is) const;
61     bool ValidateLabel();
62     bool Mask();
63     bool NextMask();
64     size_t Len() const;
65     std::string_view GiveToken();
66     Token::Type WaitFor();
67     Token::Type Next();
68 
69     Token::Type operator++(int);
70     Token::Type operator--(int);
71     Token::Type operator++();
72     Token::Type operator--();
73     Token::Type operator*();
74 };
75 
76 }  // namespace panda::pandasm
77 
78 #endif  // ASSEMBLER_ASSEMBLY_CONTEXT_H
79