blob: f5878bd6656b2be619b06f82ee7a65eda19d6c1c [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 Madillb1a85f42014-08-19 15:23:24 -040012struct TVectorFields
Zhenyao Moe40d1e92014-07-16 17:40:36 -070013{
Jamie Madillb1a85f42014-08-19 15:23:24 -040014 int offsets[4];
15 int num;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016};
17
Jamie Madillb1a85f42014-08-19 15:23:24 -040018//
Olli Etuahof119a262016-08-19 15:54:22 +030019// Set of helper functions to help build the tree.
Jamie Madillb1a85f42014-08-19 15:23:24 -040020//
Jamie Madillb1a85f42014-08-19 15:23:24 -040021class TIntermediate
Zhenyao Moe40d1e92014-07-16 17:40:36 -070022{
23 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040024 POOL_ALLOCATOR_NEW_DELETE();
Olli Etuahof119a262016-08-19 15:54:22 +030025 TIntermediate() {}
alokp@chromium.org58e54292010-08-24 21:40:03 +000026
Jamie Madillb1a85f42014-08-19 15:23:24 -040027 TIntermSymbol *addSymbol(
28 int id, const TString &, const TType &, const TSourceLoc &);
Olli Etuaho3272a6d2016-08-29 17:54:50 +030029 TIntermTyped *addIndex(TOperator op,
30 TIntermTyped *base,
31 TIntermTyped *index,
32 const TSourceLoc &line,
33 TDiagnostics *diagnostics);
Jamie Madillb1a85f42014-08-19 15:23:24 -040034 TIntermTyped *addUnaryMath(
Olli Etuahof6c694b2015-03-26 14:50:53 +020035 TOperator op, TIntermTyped *child, const TSourceLoc &line, const TType *funcReturnType);
Jamie Madillb1a85f42014-08-19 15:23:24 -040036 TIntermAggregate *growAggregate(
37 TIntermNode *left, TIntermNode *right, const TSourceLoc &);
Olli Etuaho32db19b2016-10-04 14:43:16 +010038 static TIntermAggregate *MakeAggregate(TIntermNode *node, const TSourceLoc &line);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010039 static TIntermBlock *EnsureBlock(TIntermNode *node);
Jamie Madillb1a85f42014-08-19 15:23:24 -040040 TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &);
Olli Etuaho57961272016-09-14 13:57:46 +030041 TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &line);
Olli Etuahod0bad2c2016-09-09 18:01:16 +030042 static TIntermTyped *AddTernarySelection(TIntermTyped *cond,
43 TIntermTyped *trueExpression,
44 TIntermTyped *falseExpression,
45 const TSourceLoc &line);
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010046 TIntermSwitch *addSwitch(TIntermTyped *init,
47 TIntermBlock *statementList,
48 const TSourceLoc &line);
Olli Etuahoa3a36662015-02-17 13:46:51 +020049 TIntermCase *addCase(
50 TIntermTyped *condition, const TSourceLoc &line);
Olli Etuaho15200042015-11-04 16:56:31 +020051 TIntermTyped *addComma(TIntermTyped *left,
52 TIntermTyped *right,
53 const TSourceLoc &line,
54 int shaderVersion);
Olli Etuaho5c0e0232015-11-11 15:55:59 +020055 TIntermConstantUnion *addConstantUnion(const TConstantUnion *constantUnion,
56 const TType &type,
57 const TSourceLoc &line);
Jamie Madillb1a85f42014-08-19 15:23:24 -040058 TIntermNode *addLoop(TLoopType, TIntermNode *, TIntermTyped *, TIntermTyped *,
59 TIntermNode *, const TSourceLoc &);
60 TIntermBranch *addBranch(TOperator, const TSourceLoc &);
61 TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
Olli Etuahob6fa0432016-09-28 16:28:05 +010062 static TIntermTyped *AddSwizzle(TIntermTyped *baseExpression,
63 const TVectorFields &fields,
64 const TSourceLoc &dotLocation);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +020065
66 static void outputTree(TIntermNode *, TInfoSinkBase &);
alokp@chromium.org58e54292010-08-24 21:40:03 +000067
Olli Etuahof119a262016-08-19 15:54:22 +030068 TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate, TDiagnostics *diagnostics);
Arun Patole274f0702015-05-05 13:33:30 +053069
Jamie Madillb1a85f42014-08-19 15:23:24 -040070 private:
71 void operator=(TIntermediate &); // prevent assignments
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072};
73
Geoff Lang0a73dd82014-11-19 16:18:08 -050074#endif // COMPILER_TRANSLATOR_INTERMEDIATE_H_