blob: 7931424da02a186610f1f96b5b5eeeab95fa18a4 [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//
19// Set of helper functions to help parse and build the tree.
20//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021class TInfoSink;
Jamie Madillb1a85f42014-08-19 15:23:24 -040022class TIntermediate
Zhenyao Moe40d1e92014-07-16 17:40:36 -070023{
24 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040025 POOL_ALLOCATOR_NEW_DELETE();
Jamie Madillb1a85f42014-08-19 15:23:24 -040026 TIntermediate(TInfoSink &i)
27 : mInfoSink(i) { }
alokp@chromium.org58e54292010-08-24 21:40:03 +000028
Jamie Madillb1a85f42014-08-19 15:23:24 -040029 TIntermSymbol *addSymbol(
30 int id, const TString &, const TType &, const TSourceLoc &);
31 TIntermTyped *addBinaryMath(
32 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &);
33 TIntermTyped *addAssign(
34 TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &);
35 TIntermTyped *addIndex(
36 TOperator op, TIntermTyped *base, TIntermTyped *index, const TSourceLoc &);
37 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 &);
41 TIntermAggregate *makeAggregate(TIntermNode *node, const TSourceLoc &);
Olli Etuaho7d7f8c42015-05-19 18:38:49 +030042 TIntermAggregate *ensureSequence(TIntermNode *node);
Jamie Madillb1a85f42014-08-19 15:23:24 -040043 TIntermAggregate *setAggregateOperator(TIntermNode *, TOperator, const TSourceLoc &);
44 TIntermNode *addSelection(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &);
Olli Etuaho52901742015-04-15 13:42:45 +030045 TIntermTyped *addSelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock,
46 const TSourceLoc &line);
Olli Etuahoa3a36662015-02-17 13:46:51 +020047 TIntermSwitch *addSwitch(
48 TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &line);
49 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);
Jamie Madillb11e2482015-05-04 14:21:22 -040055 TIntermConstantUnion *addConstantUnion(
56 TConstantUnion *constantUnion, const TType &type, const TSourceLoc &line);
Jamie Madillb1a85f42014-08-19 15:23:24 -040057 // TODO(zmo): Get rid of default value.
Jamie Madill6ba6ead2015-05-04 14:21:21 -040058 bool parseConstTree(const TSourceLoc &, TIntermNode *, TConstantUnion *,
Jamie Madillb1a85f42014-08-19 15:23:24 -040059 TOperator, TType, bool singleConstantParam = false);
60 TIntermNode *addLoop(TLoopType, TIntermNode *, TIntermTyped *, TIntermTyped *,
61 TIntermNode *, const TSourceLoc &);
62 TIntermBranch *addBranch(TOperator, const TSourceLoc &);
63 TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
64 TIntermTyped *addSwizzle(TVectorFields &, const TSourceLoc &);
Olli Etuaho43613b02015-08-04 11:02:21 +030065 TIntermAggregate *postProcess(TIntermNode *root);
Olli Etuahoa3a5cc62015-02-13 13:12:22 +020066
67 static void outputTree(TIntermNode *, TInfoSinkBase &);
alokp@chromium.org58e54292010-08-24 21:40:03 +000068
Olli Etuahob43846e2015-06-02 18:18:57 +030069 TIntermTyped *foldAggregateBuiltIn(TIntermAggregate *aggregate);
Arun Patole274f0702015-05-05 13:33:30 +053070
Jamie Madillb1a85f42014-08-19 15:23:24 -040071 private:
72 void operator=(TIntermediate &); // prevent assignments
alokp@chromium.org58e54292010-08-24 21:40:03 +000073
Jamie Madillb1a85f42014-08-19 15:23:24 -040074 TInfoSink & mInfoSink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075};
76
Geoff Lang0a73dd82014-11-19 16:18:08 -050077#endif // COMPILER_TRANSLATOR_INTERMEDIATE_H_