daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 6ed8d8a | 2014-06-11 11:25:20 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // |
| 8 | // Build the intermediate representation. |
| 9 | // |
| 10 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 11 | #include <float.h> |
alokp@chromium.org | 1bcc3fd | 2010-05-19 17:08:44 +0000 | [diff] [blame] | 12 | #include <limits.h> |
alokp@chromium.org | 32cfaf4 | 2010-08-23 21:01:13 +0000 | [diff] [blame] | 13 | #include <algorithm> |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 14 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 15 | #include "compiler/translator/Intermediate.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 16 | #include "compiler/translator/SymbolTable.h" |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 17 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 18 | namespace sh |
| 19 | { |
| 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | //////////////////////////////////////////////////////////////////////////// |
| 22 | // |
| 23 | // First set of functions are to help build the intermediate representation. |
| 24 | // These functions are not member functions of the nodes. |
| 25 | // They are called from parser productions. |
| 26 | // |
| 27 | ///////////////////////////////////////////////////////////////////////////// |
| 28 | |
Olli Etuaho | 7d7f8c4 | 2015-05-19 18:38:49 +0300 | [diff] [blame] | 29 | // If the input node is nullptr, return nullptr. |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 30 | // If the input node is a block node, return it. |
| 31 | // If the input node is not a block node, put it inside a block node and return that. |
| 32 | TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node) |
Olli Etuaho | 7d7f8c4 | 2015-05-19 18:38:49 +0300 | [diff] [blame] | 33 | { |
| 34 | if (node == nullptr) |
| 35 | return nullptr; |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 36 | TIntermBlock *blockNode = node->getAsBlock(); |
| 37 | if (blockNode != nullptr) |
| 38 | return blockNode; |
Olli Etuaho | 7d7f8c4 | 2015-05-19 18:38:49 +0300 | [diff] [blame] | 39 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 40 | blockNode = new TIntermBlock(); |
| 41 | blockNode->setLine(node->getLine()); |
Olli Etuaho | 8162926 | 2017-04-19 11:56:01 +0300 | [diff] [blame] | 42 | blockNode->appendStatement(node); |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 43 | return blockNode; |
Olli Etuaho | 7d7f8c4 | 2015-05-19 18:38:49 +0300 | [diff] [blame] | 44 | } |
| 45 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 46 | // |
| 47 | // Constant terminal nodes. Has a union that contains bool, float or int constants |
| 48 | // |
| 49 | // Returns the constant union node created. |
| 50 | // |
| 51 | |
Olli Etuaho | 5c0e023 | 2015-11-11 15:55:59 +0200 | [diff] [blame] | 52 | TIntermConstantUnion *TIntermediate::addConstantUnion(const TConstantUnion *constantUnion, |
| 53 | const TType &type, |
| 54 | const TSourceLoc &line) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 55 | { |
Jamie Madill | b11e248 | 2015-05-04 14:21:22 -0400 | [diff] [blame] | 56 | TIntermConstantUnion *node = new TIntermConstantUnion(constantUnion, type); |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 57 | node->setLine(line); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 58 | |
alokp@chromium.org | 2cf1771 | 2010-03-30 20:33:18 +0000 | [diff] [blame] | 59 | return node; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 62 | } // namespace sh |