• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_COMPILER_SEA_IR_IR_SEA_NODE_H_
18 #define ART_COMPILER_SEA_IR_IR_SEA_NODE_H_
19 
20 #include "base/stringprintf.h"
21 
22 namespace sea_ir {
23 class Region;
24 class IRVisitor;
25 
26 class IVisitable {
27  public:
28   virtual void Accept(IRVisitor* visitor) = 0;
~IVisitable()29   virtual ~IVisitable() {}
30 };
31 
32 // This abstract class provides the essential services that
33 // we want each SEA IR element to have.
34 // At the moment, these are:
35 // - an id and corresponding string representation.
36 // - a .dot graph language representation for .dot output.
37 //
38 // Note that SEA IR nodes could also be Regions, Projects
39 // which are not instructions.
40 class SeaNode: public IVisitable {
41  public:
SeaNode()42   explicit SeaNode():id_(GetNewId()), string_id_() {
43     string_id_ = art::StringPrintf("%d", id_);
44   }
45 
46   // Adds CFG predecessors and successors to each block.
47   void AddSuccessor(Region* successor);
48   void AddPredecessor(Region* predecesor);
49 
50   // Returns the id of the current block as string
StringId()51   const std::string& StringId() const {
52     return string_id_;
53   }
54   // Returns the id of this node as int. The id is supposed to be unique among
55   // all instances of all subclasses of this class.
Id()56   int Id() const {
57     return id_;
58   }
59 
~SeaNode()60   virtual ~SeaNode() { }
61 
62  protected:
GetNewId()63   static int GetNewId() {
64     return current_max_node_id_++;
65   }
66 
67   const int id_;
68   std::string string_id_;
69 
70  private:
71   static int current_max_node_id_;
72   // Creating new instances of sea node objects should not be done through copy or assignment
73   // operators because that would lead to duplication of their unique ids.
74   DISALLOW_COPY_AND_ASSIGN(SeaNode);
75 };
76 }  // namespace sea_ir
77 #endif  // ART_COMPILER_SEA_IR_IR_SEA_NODE_H_
78