~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to src/relooper/Relooper.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
  BlockBranchMap ProcessedBranchesOut;
58
58
  BlockSet ProcessedBranchesIn;
59
59
  Shape *Parent; // The shape we are directly inside
60
 
  int Id; // A unique identifier
 
60
  int Id; // A unique identifier, defined when added to relooper
61
61
  const char *Code; // The string representation of the code in this block. Owning pointer (we copy the input)
62
62
  const char *BranchVar; // If we have more than one branch out, the variable whose value determines where we go
63
63
  bool IsCheckedMultipleEntry; // If true, we are a multiple entry, so reaching us requires setting the label variable
69
69
 
70
70
  // Prints out the instructions code and branchings
71
71
  void Render(bool InLoop);
72
 
 
73
 
  // INTERNAL
74
 
  static int IdCounter;
75
72
};
76
73
 
77
74
// Represents a structured control flow shape, one of
92
89
//            setjmp returns, etc.)
93
90
//
94
91
 
95
 
class SimpleShape;
96
 
class LabeledShape;
97
 
class MultipleShape;
98
 
class LoopShape;
 
92
struct SimpleShape;
 
93
struct LabeledShape;
 
94
struct MultipleShape;
 
95
struct LoopShape;
 
96
struct EmulatedShape;
99
97
 
100
98
struct Shape {
101
 
  int Id; // A unique identifier. Used to identify loops, labels are Lx where x is the Id.
 
99
  int Id; // A unique identifier. Used to identify loops, labels are Lx where x is the Id. Defined when added to relooper
102
100
  Shape *Next; // The shape that will appear in the code right after this one
103
101
  Shape *Natural; // The shape that control flow gets to naturally (if there is Next, then this is Next)
104
102
 
105
103
  enum ShapeType {
106
104
    Simple,
107
105
    Multiple,
108
 
    Loop
 
106
    Loop,
 
107
    Emulated
109
108
  };
110
109
  ShapeType Type;
111
110
 
112
 
  Shape(ShapeType TypeInit) : Id(Shape::IdCounter++), Next(NULL), Type(TypeInit) {}
 
111
  Shape(ShapeType TypeInit) : Id(-1), Next(NULL), Type(TypeInit) {}
113
112
  virtual ~Shape() {}
114
113
 
115
114
  virtual void Render(bool InLoop) = 0;
118
117
  static MultipleShape *IsMultiple(Shape *It) { return It && It->Type == Multiple ? (MultipleShape*)It : NULL; }
119
118
  static LoopShape *IsLoop(Shape *It) { return It && It->Type == Loop ? (LoopShape*)It : NULL; }
120
119
  static LabeledShape *IsLabeled(Shape *It) { return IsMultiple(It) || IsLoop(It) ? (LabeledShape*)It : NULL; }
121
 
 
122
 
  // INTERNAL
123
 
  static int IdCounter;
 
120
  static EmulatedShape *IsEmulated(Shape *It) { return It && It->Type == Emulated ? (EmulatedShape*)It : NULL; }
124
121
};
125
122
 
126
123
struct SimpleShape : public Shape {
162
159
  void Render(bool InLoop);
163
160
};
164
161
 
165
 
/*
166
 
struct EmulatedShape : public Shape {
167
 
  std::deque<Block*> Blocks;
 
162
// TODO EmulatedShape is only partially functional. Currently it can be used for the
 
163
//      entire set of blocks being relooped, but not subsets.
 
164
struct EmulatedShape : public LabeledShape {
 
165
  Block *Entry;
 
166
  BlockSet Blocks;
 
167
 
 
168
  EmulatedShape() : LabeledShape(Emulated) { Labeled = true; }
168
169
  void Render(bool InLoop);
169
170
};
170
 
*/
171
171
 
172
172
// Implements the relooper algorithm for a function's blocks.
173
173
//
184
184
  std::deque<Block*> Blocks;
185
185
  std::deque<Shape*> Shapes;
186
186
  Shape *Root;
 
187
  bool Emulate;
 
188
  int BlockIdCounter;
 
189
  int ShapeIdCounter;
187
190
 
188
191
  Relooper();
189
192
  ~Relooper();
197
200
  void Render();
198
201
 
199
202
  // Sets the global buffer all printing goes to. Must call this or MakeOutputBuffer.
 
203
  // XXX: this is deprecated, see MakeOutputBuffer
200
204
  static void SetOutputBuffer(char *Buffer, int Size);
201
205
 
202
 
  // Creates an output buffer. Must call this or SetOutputBuffer.
 
206
  // Creates an internal output buffer. Must call this or SetOutputBuffer. Size is
 
207
  // a hint for the initial size of the buffer, it can be resized later one demand.
 
208
  // For that reason this is more recommended than SetOutputBuffer.
203
209
  static void MakeOutputBuffer(int Size);
204
210
 
 
211
  static char *GetOutputBuffer();
 
212
 
205
213
  // Sets asm.js mode on or off (default is off)
206
214
  static void SetAsmJSMode(int On);
 
215
 
 
216
  // Sets whether we must emulate everything with switch-loop code
 
217
  void SetEmulate(int E) { Emulate = E; }
207
218
};
208
219
 
209
220
typedef std::map<Block*, BlockSet> BlockBlockSetMap;