blob: 1d2abb77e1cf45f6f2cee9a6fac52d9781b8feff [file] [log] [blame]
Dmitry Skiba01971112015-07-10 14:54:00 -04001//
2// Copyright (c) 2015 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// Cache.h: Implements a cache for various commonly created objects.
8
9#ifndef COMPILER_TRANSLATOR_CACHE_H_
10#define COMPILER_TRANSLATOR_CACHE_H_
11
12#include <stdint.h>
13#include <string.h>
14#include <map>
15
16#include "compiler/translator/Types.h"
17#include "compiler/translator/PoolAlloc.h"
18
19class TCache
20{
21 public:
22
23 static void initialize();
24 static void destroy();
25
26 static const TType *getType(TBasicType basicType,
27 TPrecision precision)
28 {
29 return getType(basicType, precision, EvqTemporary,
30 1, 1);
31 }
32 static const TType *getType(TBasicType basicType,
33 unsigned char primarySize = 1,
34 unsigned char secondarySize = 1)
35 {
36 return getType(basicType, EbpUndefined, EvqGlobal,
37 primarySize, secondarySize);
38 }
39 static const TType *getType(TBasicType basicType,
40 TQualifier qualifier,
41 unsigned char primarySize = 1,
42 unsigned char secondarySize = 1)
43 {
44 return getType(basicType, EbpUndefined, qualifier,
45 primarySize, secondarySize);
46 }
47 static const TType *getType(TBasicType basicType,
48 TPrecision precision,
49 TQualifier qualifier,
50 unsigned char primarySize,
51 unsigned char secondarySize);
52
53 private:
54 TCache()
55 {
56 }
57
58 union TypeKey
59 {
60 TypeKey(TBasicType basicType,
61 TPrecision precision,
62 TQualifier qualifier,
63 unsigned char primarySize,
64 unsigned char secondarySize);
65
66 typedef uint8_t EnumComponentType;
67 struct
68 {
69 EnumComponentType basicType;
70 EnumComponentType precision;
71 EnumComponentType qualifier;
72 unsigned char primarySize;
73 unsigned char secondarySize;
74 } components;
75 uint64_t value;
76
77 bool operator < (const TypeKey &other) const
78 {
79 return value < other.value;
80 }
81 };
82 typedef std::map<TypeKey, const TType*> TypeMap;
83
84 TypeMap mTypes;
85 TPoolAllocator mAllocator;
86
87 static TCache *sCache;
88};
89
90#endif // COMPILER_TRANSLATOR_CACHE_H_