blob: fb5308759e3172f6708e6082f22a12c41cdf8049 [file] [log] [blame]
daniel@transgaming.com91ed1492010-10-29 03:11:43 +00001//
2// Copyright (c) 2002-2010 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 COMPILER_UTIL_H
8#define COMPILER_UTIL_H
9
Jamie Madill77f74852014-07-08 15:02:34 -040010#include <stack>
11
Jamie Madillf51639a2014-06-25 16:04:57 -040012#include "angle_gl.h"
Jamie Madille294bb82014-07-17 14:16:26 -040013#include <GLSLANG/ShaderLang.h>
Jamie Madill13cfd272014-07-17 14:16:28 -040014
15#include "compiler/translator/Types.h"
Jamie Madill033dae62014-06-18 12:56:28 -040016
Zhenyao Mof1d723c2013-09-23 14:57:07 -040017// atof_clamp is like atof but
18// 1. it forces C locale, i.e. forcing '.' as decimal point.
19// 2. it clamps the value to -FLT_MAX or FLT_MAX if overflow happens.
20// Return false if overflow happens.
21extern bool atof_clamp(const char *str, float *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000022
Zhenyao Mof1d723c2013-09-23 14:57:07 -040023// If overflow happens, clamp the value to INT_MIN or INT_MAX.
24// Return false if overflow happens.
25extern bool atoi_clamp(const char *str, int *value);
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000026
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070027class TSymbolTable;
28
Jamie Madill033dae62014-06-18 12:56:28 -040029namespace sh
30{
31
32GLenum GLVariableType(const TType &type);
33GLenum GLVariablePrecision(const TType &type);
34bool IsVaryingIn(TQualifier qualifier);
35bool IsVaryingOut(TQualifier qualifier);
36bool IsVarying(TQualifier qualifier);
Jamie Madillf2575982014-06-25 16:04:54 -040037InterpolationType GetInterpolationType(TQualifier qualifier);
Jamie Madill033dae62014-06-18 12:56:28 -040038TString ArrayString(const TType &type);
39
Jamie Madill77f74852014-07-08 15:02:34 -040040class GetVariableTraverser
41{
42 public:
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070043 GetVariableTraverser(const TSymbolTable &symbolTable);
Jamie Madill42bcf322014-08-25 16:20:46 -040044
45 template <typename VarT>
46 void traverse(const TType &type, const TString &name, std::vector<VarT> *output);
Jamie Madill77f74852014-07-08 15:02:34 -040047
48 protected:
Jamie Madill28f70c32014-07-18 10:33:10 -040049 // May be overloaded
Jamie Madill42bcf322014-08-25 16:20:46 -040050 virtual void visitVariable(ShaderVariable *newVar) {}
Jamie Madill77f74852014-07-08 15:02:34 -040051
52 private:
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070053 // Helper function called by traverse() to fill specific fields
54 // for attributes/varyings/uniforms.
55 template <typename VarT>
56 void setTypeSpecificInfo(
57 const TType &type, const TString &name, VarT *variable) {}
58
59 const TSymbolTable &mSymbolTable;
60
Jamie Madill42bcf322014-08-25 16:20:46 -040061 DISALLOW_COPY_AND_ASSIGN(GetVariableTraverser);
Jamie Madill77f74852014-07-08 15:02:34 -040062};
63
Jamie Madill033dae62014-06-18 12:56:28 -040064}
65
daniel@transgaming.com91ed1492010-10-29 03:11:43 +000066#endif // COMPILER_UTIL_H