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