{\r
// branch to the top of the merge block stack\r
createBranch(switchMerges.top());\r
+ createAndSetNoPredecessorBlock("post-switch-break");\r
}\r
\r
// Comments in header\r
void Builder::createAndSetNoPredecessorBlock(const char* name)\r
{\r
Block* block = new Block(getUniqueId(), buildPoint->getParent());\r
+ block->setUnreachable();\r
buildPoint->getParent().addBlock(block);\r
setBuildPoint(block);\r
\r
- if (name)\r
- addName(block->getId(), name);\r
+ //if (name)\r
+ // addName(block->getId(), name);\r
}\r
\r
// Comments in header\r
\r
class Block {\r
public:\r
- // Setting insert to true indicates to add this new block \r
- // to the end of the parent function.\r
Block(Id id, Function& parent);\r
virtual ~Block()\r
{\r
void addPredecessor(Block* pred) { predecessors.push_back(pred); }\r
void addLocalVariable(Instruction* inst) { localVariables.push_back(inst); }\r
int getNumPredecessors() const { return (int)predecessors.size(); }\r
+ void setUnreachable() { unreachable = true; }\r
+ bool isUnreachable() const { return unreachable; }\r
\r
bool isTerminated() const\r
{\r
\r
void dump(std::vector<unsigned int>& out) const\r
{\r
+ // skip the degenerate unreachable blocks\r
+ // TODO: code gen: skip all unreachable blocks (transitive closure)\r
+ // (but, until that's done safer to keep non-degenerate unreachable blocks, in case others depend on something)\r
+ if (unreachable && instructions.size() <= 2)\r
+ return;\r
+\r
instructions[0]->dump(out);\r
for (int i = 0; i < (int)localVariables.size(); ++i)\r
localVariables[i]->dump(out);\r
std::vector<Block*> predecessors;\r
std::vector<Instruction*> localVariables;\r
Function& parent;\r
+\r
+ // track whether this block is known to be uncreachable (not necessarily \r
+ // true for all unreachable blocks, but should be set at least\r
+ // for the extraneous ones introduced by the builder).\r
+ bool unreachable;\r
};\r
\r
//\r
parent.mapInstruction(inst);\r
}\r
\r
-__inline Block::Block(Id id, Function& parent) : parent(parent)\r
+__inline Block::Block(Id id, Function& parent) : parent(parent), unreachable(false)\r
{\r
instructions.push_back(new Instruction(id, NoType, OpLabel));\r
}\r
ERROR: 0:126: 'onlyInSwitch' : undeclared identifier \r
WARNING: 0:128: 'switch' : last case/default label not followed by statements \r
ERROR: 0:140: 'nestedX' : undeclared identifier \r
-ERROR: 0:156: 'nestedZ' : undeclared identifier \r
+ERROR: 0:157: 'nestedZ' : undeclared identifier \r
ERROR: 17 compilation errors. No code generated.\r
\r
\r
0:144 3 (const int)\r
0:? Sequence\r
0:146 Branch: Break\r
-0:147 case: with expression\r
-0:147 Constant:\r
-0:147 4 (const int)\r
-0:? Sequence\r
-0:148 Sequence\r
-0:148 move second child to first child (temp mediump int)\r
-0:148 'linearY' (temp mediump int)\r
-0:148 'linearZ' (temp mediump int)\r
-0:149 Branch: Break\r
-0:150 case: with expression\r
-0:150 Constant:\r
-0:150 5 (const int)\r
-0:? Sequence\r
-0:152 Branch: Break\r
-0:153 case: with expression\r
-0:153 Constant:\r
-0:153 6 (const int)\r
-0:? Sequence\r
+0:147 Branch: Break\r
+0:148 case: with expression\r
+0:148 Constant:\r
+0:148 4 (const int)\r
+0:? Sequence\r
+0:149 Sequence\r
+0:149 move second child to first child (temp mediump int)\r
+0:149 'linearY' (temp mediump int)\r
+0:149 'linearZ' (temp mediump int)\r
+0:150 Branch: Break\r
+0:151 case: with expression\r
+0:151 Constant:\r
+0:151 5 (const int)\r
+0:? Sequence\r
+0:153 Branch: Break\r
+0:154 case: with expression\r
0:154 Constant:\r
-0:154 4 (const int)\r
-0:156 'nestedZ' (temp float)\r
+0:154 6 (const int)\r
+0:? Sequence\r
+0:155 Constant:\r
+0:155 4 (const int)\r
+0:157 'nestedZ' (temp float)\r
0:? Linker Objects\r
0:? 'c' (uniform mediump int)\r
0:? 'd' (uniform mediump int)\r
0:144 3 (const int)\r
0:? Sequence\r
0:146 Branch: Break\r
-0:147 case: with expression\r
-0:147 Constant:\r
-0:147 4 (const int)\r
-0:? Sequence\r
-0:148 Sequence\r
-0:148 move second child to first child (temp mediump int)\r
-0:148 'linearY' (temp mediump int)\r
-0:148 'linearZ' (temp mediump int)\r
-0:149 Branch: Break\r
-0:150 case: with expression\r
-0:150 Constant:\r
-0:150 5 (const int)\r
-0:? Sequence\r
-0:152 Branch: Break\r
-0:153 case: with expression\r
-0:153 Constant:\r
-0:153 6 (const int)\r
-0:? Sequence\r
+0:147 Branch: Break\r
+0:148 case: with expression\r
+0:148 Constant:\r
+0:148 4 (const int)\r
+0:? Sequence\r
+0:149 Sequence\r
+0:149 move second child to first child (temp mediump int)\r
+0:149 'linearY' (temp mediump int)\r
+0:149 'linearZ' (temp mediump int)\r
+0:150 Branch: Break\r
+0:151 case: with expression\r
+0:151 Constant:\r
+0:151 5 (const int)\r
+0:? Sequence\r
+0:153 Branch: Break\r
+0:154 case: with expression\r
0:154 Constant:\r
-0:154 4 (const int)\r
-0:156 'nestedZ' (temp float)\r
+0:154 6 (const int)\r
+0:? Sequence\r
+0:155 Constant:\r
+0:155 4 (const int)\r
+0:157 'nestedZ' (temp float)\r
0:? Linker Objects\r
0:? 'c' (uniform mediump int)\r
0:? 'd' (uniform mediump int)\r
case 3:
int linearZ;
break;
+ break;
case 4:
int linearY = linearZ;
break;