blob: 01e9d4a66726cbea4c2d3be165a9721c7917dddf [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
2// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
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#ifndef CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
8#define CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
9
10#include <set>
11
12#include "compiler/ForLoopUnroll.h"
13#include "compiler/intermediate.h"
14#include "compiler/ParseHelper.h"
15
16class TOutputGLSLBase : public TIntermTraverser
17{
18public:
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000019 TOutputGLSLBase(TInfoSinkBase& objSink,
20 ShHashFunction64 hashFunction,
21 NameMap& nameMap,
22 TSymbolTable& symbolTable);
zmo@google.com5601ea02011-06-10 18:23:25 +000023
24protected:
25 TInfoSinkBase& objSink() { return mObjSink; }
26 void writeTriplet(Visit visit, const char* preStr, const char* inStr, const char* postStr);
27 void writeVariableType(const TType& type);
28 virtual bool writeVariablePrecision(TPrecision precision) = 0;
29 void writeFunctionParameters(const TIntermSequence& args);
30 const ConstantUnion* writeConstantUnion(const TType& type, const ConstantUnion* pConstUnion);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000031 TString getTypeName(const TType& type);
zmo@google.com5601ea02011-06-10 18:23:25 +000032
33 virtual void visitSymbol(TIntermSymbol* node);
34 virtual void visitConstantUnion(TIntermConstantUnion* node);
35 virtual bool visitBinary(Visit visit, TIntermBinary* node);
36 virtual bool visitUnary(Visit visit, TIntermUnary* node);
37 virtual bool visitSelection(Visit visit, TIntermSelection* node);
38 virtual bool visitAggregate(Visit visit, TIntermAggregate* node);
39 virtual bool visitLoop(Visit visit, TIntermLoop* node);
40 virtual bool visitBranch(Visit visit, TIntermBranch* node);
41
42 void visitCodeBlock(TIntermNode* node);
43
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000044
45 // Return the original name if hash function pointer is NULL;
46 // otherwise return the hashed name.
47 TString hashName(const TString& name);
48 // Same as hashName(), but without hashing built-in variables.
49 TString hashVariableName(const TString& name);
50 // Same as hashName(), but without hashing built-in functions.
51 TString hashFunctionName(const TString& mangled_name);
52
zmo@google.com5601ea02011-06-10 18:23:25 +000053private:
54 TInfoSinkBase& mObjSink;
55 bool mDeclaringVariables;
56
57 // Structs are declared as the tree is traversed. This set contains all
58 // the structs already declared. It is maintained so that a struct is
59 // declared only once.
60 typedef std::set<TString> DeclaredStructs;
61 DeclaredStructs mDeclaredStructs;
62
63 ForLoopUnroll mLoopUnroll;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000064
65 // name hashing.
66 ShHashFunction64 mHashFunction;
67 NameMap& mNameMap;
68
69 TSymbolTable& mSymbolTable;
zmo@google.com5601ea02011-06-10 18:23:25 +000070};
71
72#endif // CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_