blob: c0facf3d56bc0c1749ef34e0fab1824d51384d2d [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens6ed8d8a2014-06-11 11:25:20 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// 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.com4f39fd92010-03-08 20:26:45 +000011#include <float.h>
alokp@chromium.org1bcc3fd2010-05-19 17:08:44 +000012#include <limits.h>
alokp@chromium.org32cfaf42010-08-23 21:01:13 +000013#include <algorithm>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000014
Jamie Madillb1a85f42014-08-19 15:23:24 -040015#include "compiler/translator/Intermediate.h"
Geoff Lang17732822013-08-29 13:46:49 -040016#include "compiler/translator/SymbolTable.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000017
Jamie Madill45bcc782016-11-07 13:58:48 -050018namespace sh
19{
20
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021////////////////////////////////////////////////////////////////////////////
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 Etuaho7d7f8c42015-05-19 18:38:49 +030029// If the input node is nullptr, return nullptr.
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010030// 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.
32TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node)
Olli Etuaho7d7f8c42015-05-19 18:38:49 +030033{
34 if (node == nullptr)
35 return nullptr;
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010036 TIntermBlock *blockNode = node->getAsBlock();
37 if (blockNode != nullptr)
38 return blockNode;
Olli Etuaho7d7f8c42015-05-19 18:38:49 +030039
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010040 blockNode = new TIntermBlock();
41 blockNode->setLine(node->getLine());
Olli Etuaho81629262017-04-19 11:56:01 +030042 blockNode->appendStatement(node);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010043 return blockNode;
Olli Etuaho7d7f8c42015-05-19 18:38:49 +030044}
45
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046//
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 Etuaho5c0e0232015-11-11 15:55:59 +020052TIntermConstantUnion *TIntermediate::addConstantUnion(const TConstantUnion *constantUnion,
53 const TType &type,
54 const TSourceLoc &line)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000055{
Jamie Madillb11e2482015-05-04 14:21:22 -040056 TIntermConstantUnion *node = new TIntermConstantUnion(constantUnion, type);
alokp@chromium.org2cf17712010-03-30 20:33:18 +000057 node->setLine(line);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000058
alokp@chromium.org2cf17712010-03-30 20:33:18 +000059 return node;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060}
61
Jamie Madill45bcc782016-11-07 13:58:48 -050062} // namespace sh