Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/IceCfg.cpp

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Introduce IceGlobalContext, and rearrange other things around that Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the IceCfg class, including constant pool
11 // management.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "IceCfg.h"
16 #include "IceCfgNode.h"
17 #include "IceDefs.h"
18 #include "IceInst.h"
19 #include "IceOperand.h"
20
21 IceCfg::IceCfg(IceGlobalContext *Ctx)
22 : Ctx(Ctx), Name(""), Type(IceType_void), IsInternal(false),
23 HasError(false), ErrorMessage(""), Entry(NULL), NextInstNumber(1),
24 CurrentNode(NULL) {}
25
26 IceCfg::~IceCfg() {}
27
28 void IceCfg::setError(const IceString &Message) {
29 HasError = true;
30 ErrorMessage = Message;
31 Ctx->StrDump << "ICE translation error: " << ErrorMessage << "\n";
32 }
33
34 IceCfgNode *IceCfg::makeNode(const IceString &Name) {
35 uint32_t LabelIndex = Nodes.size();
36 IceCfgNode *Node = IceCfgNode::create(this, LabelIndex, Name);
37 Nodes.push_back(Node);
38 return Node;
39 }
40
41 // Create a new IceVariable with a particular type and an optional
42 // name. The Node argument is the node where the variable is defined.
43 IceVariable *IceCfg::makeVariable(IceType Type, const IceCfgNode *Node,
44 const IceString &Name) {
45 uint32_t Index = Variables.size();
46 Variables.push_back(IceVariable::create(this, Type, Node, Index, Name));
47 return Variables[Index];
48 }
49
50 void IceCfg::addArg(IceVariable *Arg) {
51 Arg->setIsArg(this);
52 Args.push_back(Arg);
53 }
54
55 void IceCfg::registerEdges() {
56 for (IceNodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
57 (*I)->registerEdges();
58 }
59 }
60
61 // ======================== Dump routines ======================== //
62
63 void IceCfg::dump() {
64 IceOstream &Str = Ctx->StrDump;
65 setCurrentNode(getEntryNode());
66 // Print function name+args
67 if (getContext()->isVerbose(IceV_Instructions)) {
68 Str << "define ";
69 if (getInternal())
70 Str << "internal ";
71 Str << Type << " @" << Name << "(";
72 for (uint32_t i = 0; i < Args.size(); ++i) {
73 if (i > 0)
74 Str << ", ";
75 Str << Args[i]->getType() << " ";
76 Args[i]->dump(this);
77 }
78 Str << ") {\n";
79 }
80 setCurrentNode(NULL);
81 // Print each basic block
82 for (IceNodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E;
83 ++I) {
84 (*I)->dump(this);
85 }
86 if (getContext()->isVerbose(IceV_Instructions)) {
87 Str << "}\n";
88 }
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698