blob: d712bf9532e3a7bcce84253a1a3d13cefd18b787 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens16004fc2014-06-11 11:29:11 -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
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_INTERMEDIATE_H_
8#define COMPILER_TRANSLATOR_INTERMEDIATE_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
Jamie Madillb1a85f42014-08-19 15:23:24 -040010#include "compiler/translator/IntermNode.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
Jamie Madill45bcc782016-11-07 13:58:48 -050012namespace sh
13{
14
Jamie Madillb1a85f42014-08-19 15:23:24 -040015struct TVectorFields
Zhenyao Moe40d1e92014-07-16 17:40:36 -070016{
Jamie Madillb1a85f42014-08-19 15:23:24 -040017 int offsets[4];
18 int num;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019};
20
Jamie Madillb1a85f42014-08-19 15:23:24 -040021//
Olli Etuahof119a262016-08-19 15:54:22 +030022// Set of helper functions to help build the tree.
Jamie Madillb1a85f42014-08-19 15:23:24 -040023//
Jamie Madillb1a85f42014-08-19 15:23:24 -040024class TIntermediate
Zhenyao Moe40d1e92014-07-16 17:40:36 -070025{
26 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040027 POOL_ALLOCATOR_NEW_DELETE();
Olli Etuahof119a262016-08-19 15:54:22 +030028 TIntermediate() {}
alokp@chromium.org58e54292010-08-24 21:40:03 +000029
Jamie Madillb1a85f42014-08-19 15:23:24 -040030 TIntermSymbol *addSymbol(
31 int id, const TString &, const TType &, const TSourceLoc &);
Olli Etuaho3272a6d2016-08-29 17:54:50 +030032 TIntermTyped *addIndex(TOperator op,
33 TIntermTyped *base,
34 TIntermTyped *index,
35 const TSourceLoc &line,
36 TDiagnostics *diagnostics);
Jamie Madillb1a85f42014-08-19 15:23:24 -040037 TIntermTyped *addUnaryMath(
Olli Etuahof6c694b2015-03-26 14:50:53 +020038 TOperator op, TIntermTyped *child, const TSourceLoc &line, const TType *funcReturnType);
Jamie Madillb1a85f42014-08-19 15:23:24 -040039 TIntermAggregate *growAggregate(
40 TIntermNode *left, TIntermNode *right, const TSourceLoc &);
Olli Etuaho32db19b2016-10-04 14:43:16 +010041 static TIntermAggregate *MakeAggregate(TIntermNode *node, const TSourceLoc &line);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010042 static TIntermBlock *EnsureBlock(TIntermNode *node);
Jamie Madillb1a85f42014-08-19 15:23:24 -040043 TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &);
Olli Etuaho57961272016-09-14 13:57:46 +030044 TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &line);
Olli Etuahod0bad2c2016-09-09 18:01:16 +030045 static TIntermTyped *AddTernarySelection(TIntermTyped *cond,
46 TIntermTyped *trueExpression,
47 TIntermTyped *falseExpression,
48 const TSourceLoc &line);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010049 TIntermSwitch *addSwitch(TIntermTyped *init,
50 TIntermBlock *statementList,
51 const TSourceLoc &line);
Olli Etuahoa3a36662015-02-17 13:46:51 +020052 TIntermCase *addCase(
53 TIntermTyped *condition, const TSourceLoc &line);
Olli Etuaho4db7ded2016-10-13 12:23:11 +010054 static TIntermTyped *AddComma(TIntermTyped *left,
55 TIntermTyped *right,
56 const TSourceLoc &line,
57 int shaderVersion);
Olli Etuaho5c0e0232015-11-11 15:55:59 +020058 TIntermConstantUnion *addConstantUnion(const TConstantUnion *constantUnion,
59 const TType &type,
60 const TSourceLoc &line);
Jamie Madillb1a85f42014-08-19 15:23:24 -040061 TIntermNode *addLoop(TLoopType, TIntermNode *, TIntermTyped *, TIntermTyped *,
62 TIntermNode *, const TSourceLoc &);
63 TIntermBranch *addBranch(TOperator, const TSourceLoc &);
64 TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
Olli Etuahob6fa0432016-09-28 16:28:05 +010065 static TIntermTyped *AddSwizzle(TIntermTyped *baseExpression,
66 const TVectorFields &fields,
67 const TSourceLoc &dotLocation);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +020068
69 static void outputTree(TIntermNode *, TInfoSinkBase &);
alokp@chromium.org58e54292010-08-24 21:40:03 +000070
Olli Etuahof119a262016-08-19 15:54:22 +030071 TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate, TDiagnostics *diagnostics);
Arun Patole274f0702015-05-05 13:33:30 +053072
Jamie Madillb1a85f42014-08-19 15:23:24 -040073 private:
74 void operator=(TIntermediate &); // prevent assignments
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075};
76
Jamie Madill45bcc782016-11-07 13:58:48 -050077} // namespace sh
78
Geoff Lang0a73dd82014-11-19 16:18:08 -050079#endif // COMPILER_TRANSLATOR_INTERMEDIATE_H_