• 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 #include "locations.h"
17 #include "inst.h"
18 
19 namespace panda::compiler {
LocationsInfo(ArenaAllocator * allocator,Inst * inst)20 LocationsInfo::LocationsInfo(ArenaAllocator *allocator, Inst *inst)
21     // NOLINTNEXTLINE(modernize-avoid-c-arrays)
22     : locations_(allocator->New<Location[]>(inst->GetInputsCount()), inst->GetInputsCount())
23 {
24     ASSERT(inst->IsOperandsDynamic());
25     static_cast<DynamicInputsInst *>(inst)->SetLocationsInfo(this);
26 }
27 
Dump(std::ostream & stm,Arch arch)28 void Location::Dump(std::ostream &stm, Arch arch)
29 {
30     Target target {arch};
31 
32     switch (GetKind()) {
33         case Kind::REGISTER:
34         case Kind::FP_REGISTER:
35             if (IsUnallocatedRegister()) {
36                 stm << GetName() << '?';
37             } else if (GetValue() == ACC_REG_ID) {
38                 stm << "acc";
39             } else {
40                 stm << target.GetRegName(GetValue(), IsFpRegister());
41             }
42             break;
43         case Kind::STACK:
44         case Kind::STACK_PARAMETER:
45         case Kind::STACK_ARGUMENT:
46             stm << GetName() << GetValue();
47             break;
48         default:
49             stm << GetName();
50             break;
51     }
52 }
53 
ToString(Arch arch)54 std::string Location::ToString(Arch arch)
55 {
56     std::stringstream ss;
57     Dump(ss, arch);
58     return ss.str();
59 }
60 }  // namespace panda::compiler