+// A class which makes it easier to insert new statements before the
+// current statement during a traversal.
+
+class Statement_inserter
+{
+ public:
+ // Empty constructor.
+ Statement_inserter()
+ : block_(NULL), pindex_(NULL), gogo_(NULL), var_(NULL)
+ { }
+
+ // Constructor for a statement in a block.
+ Statement_inserter(Block* block, size_t *pindex)
+ : block_(block), pindex_(pindex), gogo_(NULL), var_(NULL)
+ { }
+
+ // Constructor for a global variable.
+ Statement_inserter(Gogo* gogo, Variable* var)
+ : block_(NULL), pindex_(NULL), gogo_(gogo), var_(var)
+ { go_assert(var->is_global()); }
+
+ // We use the default copy constructor and assignment operator.
+
+ // Insert S before the statement we are traversing, or before the
+ // initialization expression of a global variable.
+ void
+ insert(Statement* s);
+
+ private:
+ // The block that the statement is in.
+ Block* block_;
+ // The index of the statement that we are traversing.
+ size_t* pindex_;
+ // The IR, needed when looking at an initializer expression for a
+ // global variable.
+ Gogo* gogo_;
+ // The global variable, when looking at an initializer expression.
+ Variable* var_;
+};
+
+// When translating the gogo IR into the backend data structure, this
+// is the context we pass down the blocks and statements.