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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: src/IceCfg.cpp
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..757f4a902b2432fa929caac65d41b9324dfaf9ce
--- /dev/null
+++ b/src/IceCfg.cpp
@@ -0,0 +1,89 @@
+//===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the IceCfg class, including constant pool
+// management.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceCfg.h"
+#include "IceCfgNode.h"
+#include "IceDefs.h"
+#include "IceInst.h"
+#include "IceOperand.h"
+
+IceCfg::IceCfg(IceGlobalContext *Ctx)
+ : Ctx(Ctx), Name(""), Type(IceType_void), IsInternal(false),
+ HasError(false), ErrorMessage(""), Entry(NULL), NextInstNumber(1),
+ CurrentNode(NULL) {}
+
+IceCfg::~IceCfg() {}
+
+void IceCfg::setError(const IceString &Message) {
+ HasError = true;
+ ErrorMessage = Message;
+ Ctx->StrDump << "ICE translation error: " << ErrorMessage << "\n";
+}
+
+IceCfgNode *IceCfg::makeNode(const IceString &Name) {
+ uint32_t LabelIndex = Nodes.size();
+ IceCfgNode *Node = IceCfgNode::create(this, LabelIndex, Name);
+ Nodes.push_back(Node);
+ return Node;
+}
+
+// Create a new IceVariable with a particular type and an optional
+// name. The Node argument is the node where the variable is defined.
+IceVariable *IceCfg::makeVariable(IceType Type, const IceCfgNode *Node,
+ const IceString &Name) {
+ uint32_t Index = Variables.size();
+ Variables.push_back(IceVariable::create(this, Type, Node, Index, Name));
+ return Variables[Index];
+}
+
+void IceCfg::addArg(IceVariable *Arg) {
+ Arg->setIsArg(this);
+ Args.push_back(Arg);
+}
+
+void IceCfg::registerEdges() {
+ for (IceNodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
+ (*I)->registerEdges();
+ }
+}
+
+// ======================== Dump routines ======================== //
+
+void IceCfg::dump() {
+ IceOstream &Str = Ctx->StrDump;
+ setCurrentNode(getEntryNode());
+ // Print function name+args
+ if (getContext()->isVerbose(IceV_Instructions)) {
+ Str << "define ";
+ if (getInternal())
+ Str << "internal ";
+ Str << Type << " @" << Name << "(";
+ for (uint32_t i = 0; i < Args.size(); ++i) {
+ if (i > 0)
+ Str << ", ";
+ Str << Args[i]->getType() << " ";
+ Args[i]->dump(this);
+ }
+ Str << ") {\n";
+ }
+ setCurrentNode(NULL);
+ // Print each basic block
+ for (IceNodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E;
+ ++I) {
+ (*I)->dump(this);
+ }
+ if (getContext()->isVerbose(IceV_Instructions)) {
+ Str << "}\n";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698