• 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 "bbt.h"
17 namespace maplebe {
18 #if DEBUG
Dump(const MIRModule & mod) const19 void BBT::Dump(const MIRModule &mod) const
20 {
21     if (IsTry()) {
22         LogInfo::MapleLogger() << "Try" << '\n';
23     } else if (IsEndTry()) {
24         LogInfo::MapleLogger() << "EndTry" << '\n';
25     } else if (IsCatch()) {
26         LogInfo::MapleLogger() << "Catch" << '\n';
27     } else {
28         LogInfo::MapleLogger() << "Plain" << '\n';
29     }
30     if (firstStmt != nullptr) {
31         firstStmt->Dump(0);
32         LogInfo::MapleLogger() << '\n';
33         if (keyStmt != nullptr) {
34             keyStmt->Dump(0);
35             LogInfo::MapleLogger() << '\n';
36         } else {
37             LogInfo::MapleLogger() << "<<No-Key-Stmt>>" << '\n';
38         }
39         if (lastStmt != nullptr) {
40             lastStmt->Dump(0);
41         }
42         LogInfo::MapleLogger() << '\n';
43     } else {
44         LogInfo::MapleLogger() << "<<Empty>>" << '\n';
45     }
46 }
47 
ValidateStmtList(StmtNode * head,StmtNode * detached)48 void BBT::ValidateStmtList(StmtNode *head, StmtNode *detached)
49 {
50     static int nStmts = 0;
51     int n = 0;
52     int m = 0;
53     if (head == nullptr && detached == nullptr) {
54         nStmts = 0;
55         return;
56     }
57     for (StmtNode *s = head; s != nullptr; s = s->GetNext()) {
58         if (s->GetNext() != nullptr) {
59             CHECK_FATAL(s->GetNext()->GetPrev() == s, "make sure the prev node of s' next is s");
60         }
61         if (s->GetPrev() != nullptr) {
62             CHECK_FATAL(s->GetPrev()->GetNext() == s, "make sure the next node of s' prev is s");
63         }
64         ++n;
65     }
66     for (StmtNode *s = detached; s != nullptr; s = s->GetNext()) {
67         if (s->GetNext() != nullptr) {
68             CHECK_FATAL(s->GetNext()->GetPrev() == s, "make sure the prev node of s' next is s");
69         }
70         if (s->GetPrev() != nullptr) {
71             CHECK_FATAL(s->GetPrev()->GetNext() == s, "make sure the next node of s' prev is s");
72         }
73         ++m;
74     }
75     CHECK_FATAL(nStmts <= n + m, "make sure nStmts <= n + m");
76     nStmts = n + m;
77 }
78 #endif
79 } /* namespace maplebe */
80