• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "mir_symbol_builder.h"
17 
18 namespace maple {
GetLocalDecl(const MIRSymbolTable & symbolTable,const GStrIdx & strIdx) const19 MIRSymbol *MIRSymbolBuilder::GetLocalDecl(const MIRSymbolTable &symbolTable, const GStrIdx &strIdx) const
20 {
21     if (strIdx != 0u) {
22         const StIdx stIdx = symbolTable.GetStIdxFromStrIdx(strIdx);
23         if (stIdx.FullIdx() != 0) {
24             return symbolTable.GetSymbolFromStIdx(stIdx.Idx());
25         }
26     }
27     return nullptr;
28 }
29 
30 // when func is null, create global symbol, otherwise create local symbol
CreateSymbol(TyIdx tyIdx,GStrIdx strIdx,MIRSymKind mClass,MIRStorageClass sClass,MIRFunction * func,uint8 scpID) const31 MIRSymbol *MIRSymbolBuilder::CreateSymbol(TyIdx tyIdx, GStrIdx strIdx, MIRSymKind mClass, MIRStorageClass sClass,
32                                           MIRFunction *func, uint8 scpID) const
33 {
34     MIRSymbol *st =
35         (func != nullptr) ? func->GetSymTab()->CreateSymbol(scpID) : GlobalTables::GetGsymTable().CreateSymbol(scpID);
36     CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol");
37     st->SetStorageClass(sClass);
38     st->SetSKind(mClass);
39     st->SetNameStrIdx(strIdx);
40     st->SetTyIdx(tyIdx);
41     if (func != nullptr) {
42         (void)func->GetSymTab()->AddToStringSymbolMap(*st);
43     } else {
44         (void)GlobalTables::GetGsymTable().AddToStringSymbolMap(*st);
45     }
46     return st;
47 }
48 
49 
CreatePregFormalSymbol(TyIdx tyIdx,PregIdx pRegIdx,MIRFunction & func) const50 MIRSymbol *MIRSymbolBuilder::CreatePregFormalSymbol(TyIdx tyIdx, PregIdx pRegIdx, MIRFunction &func) const
51 {
52     MIRSymbol *st = func.GetSymTab()->CreateSymbol(kScopeLocal);
53     CHECK_FATAL(st != nullptr, "Failed to create MIRSymbol");
54     st->SetStorageClass(kScFormal);
55     st->SetSKind(kStPreg);
56     st->SetTyIdx(tyIdx);
57     MIRPregTable *pregTab = func.GetPregTab();
58     st->SetPreg(pregTab->PregFromPregIdx(pRegIdx));
59     return st;
60 }
61 }  // namespace maple
62