summarylogtreecommitdiffstats
path: root/commit-4de44cb
blob: 4c1c63ecbe83b9d3bbdc2cd96ff4c15221c5f217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
commit 4de44cb67e9e36966fb1993c0be35659a47182ef
Author: Zhenyao Mo <zmo@chromium.org>
Date:   Wed Oct 29 18:03:46 2014 -0700

    Change ShaderLang APIs from c style to c++ style.
    
    BUG=angle:816
    TEST=gpu_unittests,angle_unittests,webgl_conformance
    
    Change-Id: I0b46c11f6055a82511bb946a6dc491360835526e
    Reviewed-on: https://chromium-review.googlesource.com/226410
    Reviewed-by: Zhenyao Mo <zmo@chromium.org>
    Tested-by: Zhenyao Mo <zmo@chromium.org>

diff --git a/include/GLSLANG/ShaderLang.h b/include/GLSLANG/ShaderLang.h
index 0c1f8a0..647fed6 100644
--- a/include/GLSLANG/ShaderLang.h
+++ b/include/GLSLANG/ShaderLang.h
@@ -27,6 +27,10 @@
 
 #include "KHR/khrplatform.h"
 
+#include <map>
+#include <string>
+#include <vector>
+
 //
 // This is the platform independent interface between an OGL driver
 // and the shading language compiler.
@@ -42,13 +46,9 @@ typedef unsigned int GLenum;
 // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
 #include "ShaderVars.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 // Version number for shader translation API.
 // It is incremented every time the API changes.
-#define ANGLE_SH_VERSION 131
+#define ANGLE_SH_VERSION 132
 
 typedef enum {
   SH_GLES2_SPEC = 0x8B40,
@@ -88,18 +88,6 @@ typedef enum {
   SH_HLSL11_OUTPUT = 0x8B48
 } ShShaderOutput;
 
-typedef enum {
-  SH_INFO_LOG_LENGTH                = 0x8B84,
-  SH_OBJECT_CODE_LENGTH             = 0x8B88,  // GL_SHADER_SOURCE_LENGTH
-  SH_MAPPED_NAME_MAX_LENGTH         = 0x6000,
-  SH_NAME_MAX_LENGTH                = 0x6001,
-  SH_HASHED_NAME_MAX_LENGTH         = 0x6002,
-  SH_HASHED_NAMES_COUNT             = 0x6003,
-  SH_SHADER_VERSION                 = 0x6004,
-  SH_RESOURCES_STRING_LENGTH        = 0x6005,
-  SH_OUTPUT_TYPE                    = 0x6006
-} ShShaderInfo;
-
 // Compile options.
 typedef enum {
   SH_VALIDATE                = 0,
@@ -198,14 +186,14 @@ typedef enum {
 //
 // Driver must call this first, once, before doing any other
 // compiler operations.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
 //
-COMPILER_EXPORT int ShInitialize();
+COMPILER_EXPORT bool ShInitialize();
 //
 // Driver should call this at shutdown.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
 //
-COMPILER_EXPORT int ShFinalize();
+COMPILER_EXPORT bool ShFinalize();
 
 // The 64 bits hash function. The first parameter is the input string; the
 // second parameter is the string length.
@@ -273,7 +261,7 @@ typedef struct
 // Parameters:
 // resources: The object to initialize. Will be comparable with memcmp.
 //
-COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
+COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
 
 //
 // ShHandle held by but opaque to the driver.  It is allocated,
@@ -282,18 +270,15 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
 //
 // If handle creation fails, 0 will be returned.
 //
-typedef void* ShHandle;
+typedef void *ShHandle;
 
 //
-// Returns the a concatenated list of the items in ShBuiltInResources as a string.
+// Returns the a concatenated list of the items in ShBuiltInResources as a
+// null-terminated string.
 // This function must be updated whenever ShBuiltInResources is changed.
 // Parameters:
 // handle: Specifies the handle of the compiler to be used.
-// outStringLen: Specifies the size of the buffer, in number of characters. The size
-//               of the buffer required to store the resources string can be obtained
-//               by calling ShGetInfo with SH_RESOURCES_STRING_LENGTH.
-// outStr: Returns a null-terminated string representing all the built-in resources.
-COMPILER_EXPORT void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outStr);
+COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle handle);
 
 //
 // Driver calls these to create and destroy compiler objects.
@@ -311,12 +296,12 @@ COMPILER_EXPORT ShHandle ShConstructCompiler(
     sh::GLenum type,
     ShShaderSpec spec,
     ShShaderOutput output,
-    const ShBuiltInResources* resources);
+    const ShBuiltInResources *resources);
 COMPILER_EXPORT void ShDestruct(ShHandle handle);
 
 //
 // Compiles the given shader source.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
 // Parameters:
 // handle: Specifies the handle of compiler to be used.
 // shaderStrings: Specifies an array of pointers to null-terminated strings
@@ -338,74 +323,36 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
 // SH_VARIABLES: Extracts attributes, uniforms, and varyings.
 //               Can be queried by calling ShGetVariableInfo().
 //
-COMPILER_EXPORT int ShCompile(
+COMPILER_EXPORT bool ShCompile(
     const ShHandle handle,
-    const char* const shaderStrings[],
+    const char * const shaderStrings[],
     size_t numStrings,
-    int compileOptions
-    );
+    int compileOptions);
 
-// Returns a parameter from a compiled shader.
-// Parameters:
-// handle: Specifies the compiler
-// pname: Specifies the parameter to query.
-// The following parameters are defined:
-// SH_INFO_LOG_LENGTH: the number of characters in the information log
-//                     including the null termination character.
-// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
-//                        including the null termination character.
-// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
-//                            the null termination character.
-// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the
-//                     null termination character.
-// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
-//                            null termination character.
-// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
-// SH_SHADER_VERSION: the version of the shader language
-// SH_OUTPUT_TYPE: the currently set language output type
-//
-// params: Requested parameter
-COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
-                               ShShaderInfo pname,
-                               size_t* params);
+// Return the version of the shader language.
+COMPILER_EXPORT int ShGetShaderVersion(const ShHandle handle);
+
+// Return the currently set language output type.
+COMPILER_EXPORT ShShaderOutput ShGetShaderOutputType(
+    const ShHandle handle);
 
-// Returns nul-terminated information log for a compiled shader.
+// Returns null-terminated information log for a compiled shader.
 // Parameters:
 // handle: Specifies the compiler
-// infoLog: Specifies an array of characters that is used to return
-//          the information log. It is assumed that infoLog has enough memory
-//          to accomodate the information log. The size of the buffer required
-//          to store the returned information log can be obtained by calling
-//          ShGetInfo with SH_INFO_LOG_LENGTH.
-COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
+COMPILER_EXPORT const std::string &ShGetInfoLog(const ShHandle handle);
 
 // Returns null-terminated object code for a compiled shader.
 // Parameters:
 // handle: Specifies the compiler
-// infoLog: Specifies an array of characters that is used to return
-//          the object code. It is assumed that infoLog has enough memory to
-//          accomodate the object code. The size of the buffer required to
-//          store the returned object code can be obtained by calling
-//          ShGetInfo with SH_OBJECT_CODE_LENGTH.
-COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
-
-// Returns information about a name hashing entry from the latest compile.
+COMPILER_EXPORT const std::string &ShGetObjectCode(const ShHandle handle);
+
+// Returns a (original_name, hash) map containing all the user defined
+// names in the shader, including variable names, function names, struct
+// names, and struct field names.
 // Parameters:
 // handle: Specifies the compiler
-// index: Specifies the index of the name hashing entry to be queried.
-// name: Returns a null terminated string containing the user defined name.
-//       It is assumed that name has enough memory to accomodate the name.
-//       The size of the buffer required to store the user defined name can
-//       be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH.
-// hashedName: Returns a null terminated string containing the hashed name of
-//             the uniform variable, It is assumed that hashedName has enough
-//             memory to accomodate the name. The size of the buffer required
-//             to store the name can be obtained by calling ShGetInfo with
-//             SH_HASHED_NAME_MAX_LENGTH.
-COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle,
-                                           int index,
-                                           char* name,
-                                           char* hashedName);
+COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap(
+    const ShHandle handle);
 
 // Shader variable inspection.
 // Returns a pointer to a list of variables of the designated type.
@@ -425,17 +372,17 @@ typedef struct
     int size;
 } ShVariableInfo;
 
-// Returns 1 if the passed in variables pack in maxVectors following
+// Returns true if the passed in variables pack in maxVectors following
 // the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
-// Returns 0 otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
+// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
 // flag above.
 // Parameters:
 // maxVectors: the available rows of registers.
 // varInfoArray: an array of variable info (types and sizes).
 // varInfoArraySize: the size of the variable array.
-COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
+COMPILER_EXPORT bool ShCheckVariablesWithinPackingLimits(
     int maxVectors,
-    ShVariableInfo* varInfoArray,
+    ShVariableInfo *varInfoArray,
     size_t varInfoArraySize);
 
 // Gives the compiler-assigned register for an interface block.
@@ -446,7 +393,7 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
 // interfaceBlockName: Specifies the interface block
 // indexOut: output variable that stores the assigned register
 COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
-                                                 const char *interfaceBlockName,
+                                                 const std::string &interfaceBlockName,
                                                  unsigned int *indexOut);
 
 // Gives the compiler-assigned register for uniforms in the default
@@ -458,11 +405,7 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
 // interfaceBlockName: Specifies the uniform
 // indexOut: output variable that stores the assigned register
 COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle,
-                                          const char *uniformName,
+                                          const std::string &uniformName,
                                           unsigned int *indexOut);
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif // _COMPILER_INTERFACE_INCLUDED_
diff --git a/src/compiler/translator/Compiler.h b/src/compiler/translator/Compiler.h
index 145ecb4..b6c9d13 100644
--- a/src/compiler/translator/Compiler.h
+++ b/src/compiler/translator/Compiler.h
@@ -80,7 +80,7 @@ class TCompiler : public TShHandleBase
     TSymbolTable& getSymbolTable() { return symbolTable; }
     ShShaderSpec getShaderSpec() const { return shaderSpec; }
     ShShaderOutput getOutputType() const { return outputType; }
-    std::string getBuiltInResourcesString() const { return builtInResourcesString; }
+    const std::string &getBuiltInResourcesString() const { return builtInResourcesString; }
 
     // Get the resources set by InitBuiltInSymbolTable
     const ShBuiltInResources& getResources() const;
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index 35dac5f..0d6a1d6 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -84,32 +84,48 @@ const std::vector<VarT> *GetShaderVariables(const ShHandle handle, ShaderVariabl
     return GetVariableList<VarT>(compiler, variableType);
 }
 
+TCompiler *GetCompilerFromHandle(ShHandle handle)
+{
+    if (!handle)
+        return NULL;
+    TShHandleBase *base = static_cast<TShHandleBase *>(handle);
+    return base->getAsCompiler();
 }
 
+TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
+{
+    if (!handle)
+        return NULL;
+    TShHandleBase *base = static_cast<TShHandleBase *>(handle);
+    return base->getAsTranslatorHLSL();
+}
+
+}  // namespace anonymous
+
 //
 // Driver must call this first, once, before doing any other compiler operations.
 // Subsequent calls to this function are no-op.
 //
-int ShInitialize()
+bool ShInitialize()
 {
     if (!isInitialized)
     {
         isInitialized = InitProcess();
     }
-    return isInitialized ? 1 : 0;
+    return isInitialized;
 }
 
 //
 // Cleanup symbol tables
 //
-int ShFinalize()
+bool ShFinalize()
 {
     if (isInitialized)
     {
         DetachProcess();
         isInitialized = false;
     }
-    return 1;
+    return true;
 }
 
 //
@@ -190,23 +206,13 @@ void ShDestruct(ShHandle handle)
         DeleteCompiler(base->getAsCompiler());
 }
 
-void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outString)
+const std::string &ShGetBuiltInResourcesString(const ShHandle handle)
 {
-    if (!handle || !outString)
-    {
-        return;
-    }
-
-    TShHandleBase *base = static_cast<TShHandleBase*>(handle);
-    TCompiler *compiler = base->getAsCompiler();
-    if (!compiler)
-    {
-        return;
-    }
-
-    strncpy(outString, compiler->getBuiltInResourcesString().c_str(), outStringLen);
-    outString[outStringLen - 1] = '\0';
+    TCompiler *compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
+    return compiler->getBuiltInResourcesString();
 }
+
 //
 // Do an actual compile on the given strings.  The result is left
 // in the given compile object.
@@ -214,149 +220,62 @@ void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, cha
 // Return:  The return value of ShCompile is really boolean, indicating
 // success or failure.
 //
-int ShCompile(
+bool ShCompile(
     const ShHandle handle,
-    const char* const shaderStrings[],
+    const char *const shaderStrings[],
     size_t numStrings,
     int compileOptions)
 {
-    if (handle == 0)
-        return 0;
-
-    TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
-    TCompiler* compiler = base->getAsCompiler();
-    if (compiler == 0)
-        return 0;
+    TCompiler *compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
 
-    bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
-    return success ? 1 : 0;
+    return compiler->compile(shaderStrings, numStrings, compileOptions);
 }
 
-void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
+int ShGetShaderVersion(const ShHandle handle)
 {
-    if (!handle || !params)
-        return;
-
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TCompiler* compiler = base->getAsCompiler();
-    if (!compiler) return;
+    TCompiler* compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
+    return compiler->getShaderVersion();
+}
 
-    switch(pname)
-    {
-    case SH_INFO_LOG_LENGTH:
-        *params = compiler->getInfoSink().info.size() + 1;
-        break;
-    case SH_OBJECT_CODE_LENGTH:
-        *params = compiler->getInfoSink().obj.size() + 1;
-        break;
-    case SH_MAPPED_NAME_MAX_LENGTH:
-        // Use longer length than MAX_SHORTENED_IDENTIFIER_SIZE to
-        // handle array and struct dereferences.
-        *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
-        break;
-    case SH_NAME_MAX_LENGTH:
-        *params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
-        break;
-    case SH_HASHED_NAME_MAX_LENGTH:
-        if (compiler->getHashFunction() == NULL) {
-            *params = 0;
-        } else {
-            // 64 bits hashing output requires 16 bytes for hex 
-            // representation.
-            const char HashedNamePrefix[] = HASHED_NAME_PREFIX;
-            (void)HashedNamePrefix;
-            *params = 16 + sizeof(HashedNamePrefix);
-        }
-        break;
-    case SH_HASHED_NAMES_COUNT:
-        *params = compiler->getNameMap().size();
-        break;
-    case SH_SHADER_VERSION:
-        *params = compiler->getShaderVersion();
-        break;
-    case SH_RESOURCES_STRING_LENGTH:
-        *params = compiler->getBuiltInResourcesString().length() + 1;
-        break;
-    case SH_OUTPUT_TYPE:
-        *params = compiler->getOutputType();
-        break;
-    default: UNREACHABLE();
-    }
+ShShaderOutput ShGetShaderOutputType(const ShHandle handle)
+{
+    TCompiler* compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
+    return compiler->getOutputType();
 }
 
 //
 // Return any compiler log of messages for the application.
 //
-void ShGetInfoLog(const ShHandle handle, char* infoLog)
+const std::string &ShGetInfoLog(const ShHandle handle)
 {
-    if (!handle || !infoLog)
-        return;
+    TCompiler *compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
 
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TCompiler* compiler = base->getAsCompiler();
-    if (!compiler) return;
-
-    TInfoSink& infoSink = compiler->getInfoSink();
-    strcpy(infoLog, infoSink.info.c_str());
+    TInfoSink &infoSink = compiler->getInfoSink();
+    return infoSink.info.str();
 }
 
 //
 // Return any object code.
 //
-void ShGetObjectCode(const ShHandle handle, char* objCode)
+const std::string &ShGetObjectCode(const ShHandle handle)
 {
-    if (!handle || !objCode)
-        return;
+    TCompiler *compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
 
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TCompiler* compiler = base->getAsCompiler();
-    if (!compiler) return;
-
-    TInfoSink& infoSink = compiler->getInfoSink();
-    strcpy(objCode, infoSink.obj.c_str());
+    TInfoSink &infoSink = compiler->getInfoSink();
+    return infoSink.obj.str();
 }
 
-void ShGetNameHashingEntry(const ShHandle handle,
-                           int index,
-                           char* name,
-                           char* hashedName)
+const std::map<std::string, std::string> *ShGetNameHashingMap(
+    const ShHandle handle)
 {
-    if (!handle || !name || !hashedName || index < 0)
-        return;
-
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TCompiler* compiler = base->getAsCompiler();
-    if (!compiler) return;
-
-    const NameMap& nameMap = compiler->getNameMap();
-    if (index >= static_cast<int>(nameMap.size()))
-        return;
-
-    NameMap::const_iterator it = nameMap.begin();
-    for (int i = 0; i < index; ++i)
-        ++it;
-
-    size_t len = it->first.length() + 1;
-    size_t max_len = 0;
-    ShGetInfo(handle, SH_NAME_MAX_LENGTH, &max_len);
-    if (len > max_len) {
-        ASSERT(false);
-        len = max_len;
-    }
-    strncpy(name, it->first.c_str(), len);
-    // To be on the safe side in case the source is longer than expected.
-    name[len - 1] = '\0';
-
-    len = it->second.length() + 1;
-    max_len = 0;
-    ShGetInfo(handle, SH_HASHED_NAME_MAX_LENGTH, &max_len);
-    if (len > max_len) {
-        ASSERT(false);
-        len = max_len;
-    }
-    strncpy(hashedName, it->second.c_str(), len);
-    // To be on the safe side in case the source is longer than expected.
-    hashedName[len - 1] = '\0';
+    TCompiler *compiler = GetCompilerFromHandle(handle);
+    ASSERT(compiler);
+    return &(compiler->getNameMap());
 }
 
 const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle)
@@ -384,11 +303,11 @@ const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handl
     return GetShaderVariables<sh::InterfaceBlock>(handle, SHADERVAR_INTERFACEBLOCK);
 }
 
-int ShCheckVariablesWithinPackingLimits(
-    int maxVectors, ShVariableInfo* varInfoArray, size_t varInfoArraySize)
+bool ShCheckVariablesWithinPackingLimits(
+    int maxVectors, ShVariableInfo *varInfoArray, size_t varInfoArraySize)
 {
     if (varInfoArraySize == 0)
-        return 1;
+        return true;
     ASSERT(varInfoArray);
     std::vector<sh::ShaderVariable> variables;
     for (size_t ii = 0; ii < varInfoArraySize; ++ii)
@@ -397,24 +316,17 @@ int ShCheckVariablesWithinPackingLimits(
         variables.push_back(var);
     }
     VariablePacker packer;
-    return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0;
+    return packer.CheckVariablesWithinPackingLimits(maxVectors, variables);
 }
 
 bool ShGetInterfaceBlockRegister(const ShHandle handle,
-                                 const char *interfaceBlockName,
+                                 const std::string &interfaceBlockName,
                                  unsigned int *indexOut)
 {
-    if (!handle || !interfaceBlockName || !indexOut)
-    {
-        return false;
-    }
+    ASSERT(indexOut);
 
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TranslatorHLSL* translator = base->getAsTranslatorHLSL();
-    if (!translator)
-    {
-        return false;
-    }
+    TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
+    ASSERT(translator);
 
     if (!translator->hasInterfaceBlock(interfaceBlockName))
     {
@@ -426,20 +338,12 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle,
 }
 
 bool ShGetUniformRegister(const ShHandle handle,
-                          const char *uniformName,
+                          const std::string &uniformName,
                           unsigned int *indexOut)
 {
-    if (!handle || !uniformName || !indexOut)
-    {
-        return false;
-    }
-
-    TShHandleBase* base = static_cast<TShHandleBase*>(handle);
-    TranslatorHLSL* translator = base->getAsTranslatorHLSL();
-    if (!translator)
-    {
-        return false;
-    }
+    ASSERT(indexOut);
+    TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
+    ASSERT(translator);
 
     if (!translator->hasUniform(uniformName))
     {
diff --git a/src/libGLESv2/renderer/d3d/ShaderD3D.cpp b/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
index d08a81d..44e73e5 100644
--- a/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
+++ b/src/libGLESv2/renderer/d3d/ShaderD3D.cpp
@@ -102,7 +102,7 @@ void ShaderD3D::initializeCompiler()
 {
     if (!mFragmentCompiler)
     {
-        int result = ShInitialize();
+        bool result = ShInitialize();
 
         if (result)
         {
@@ -252,23 +252,16 @@
         result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH);
     }
 
-    size_t shaderVersion = 100;
-    ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
+    mShaderVersion = ShGetShaderVersion(compiler);
 
-    mShaderVersion = static_cast<int>(shaderVersion);
-
-    if (shaderVersion == 300 && data.clientVersion < 3)
+    if (mShaderVersion == 300 && data.clientVersion < 3)
     {
         mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
         TRACE("\n%s", mInfoLog.c_str());
     }
     else if (result)
     {
-        size_t objCodeLen = 0;
-        ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
-
-        std::vector<char> outputHLSL(objCodeLen);
-        ShGetObjectCode(compiler, outputHLSL.data());
+        mHlsl = ShGetObjectCode(compiler);
 
 #ifdef _DEBUG
         // Prefix hlsl shader with commented out glsl shader
@@ -288,10 +281,8 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
             curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
         }
         hlslStream << "\n\n";
-        hlslStream << outputHLSL.data();
+        hlslStream << mHlsl;
         mHlsl = hlslStream.str();
-#else
-        mHlsl = outputHLSL.data();
 #endif
 
         mUniforms = *GetShaderVariables(ShGetUniforms(compiler));
@@ -303,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
             if (uniform.staticUse)
             {
                 unsigned int index = -1;
-                bool result = ShGetUniformRegister(compiler, uniform.name.c_str(), &index);
+                bool result = ShGetUniformRegister(compiler, uniform.name, &index);
                 UNUSED_ASSERTION_VARIABLE(result);
                 ASSERT(result);
 
@@ -320,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
             if (interfaceBlock.staticUse)
             {
                 unsigned int index = -1;
-                bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index);
+                bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name, &index);
                 UNUSED_ASSERTION_VARIABLE(result);
                 ASSERT(result);
 
@@ -330,14 +321,9 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
     }
     else
     {
-        size_t infoLogLen = 0;
-        ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
+        mInfoLog = ShGetInfoLog(compiler);
 
-        std::vector<char> infoLog(infoLogLen);
-        ShGetInfoLog(compiler, infoLog.data());
-        mInfoLog = infoLog.data();
-
-        TRACE("\n%s", infoLog.data());
+        TRACE("\n%s", mInfoLog.c_str());
     }
 }
 
@@ -419,10 +405,7 @@
       default: UNREACHABLE();  return SH_HLSL9_OUTPUT;
     }
 
-    size_t outputType = 0;
-    ShGetInfo(compiler, SH_OUTPUT_TYPE, &outputType);
-
-    return static_cast<ShShaderOutput>(outputType);
+    return ShGetShaderOutputType(compiler);
 }
 
 bool ShaderD3D::compile(const gl::Data &data, const std::string &source)
diff --git a/tests/compiler_tests/ExpressionLimit_test.cpp b/tests/compiler_tests/ExpressionLimit_test.cpp
index 0236064..1dc2be6 100644
--- a/tests/compiler_tests/ExpressionLimit_test.cpp
+++ b/tests/compiler_tests/ExpressionLimit_test.cpp
@@ -144,19 +144,18 @@ protected:
     // substring in the error log. This way we know the error is specific
     // to the issue we are testing.
     bool CheckShaderCompilation(ShHandle compiler,
-                                const char* source,
+                                const char *source,
                                 int compileOptions,
-                                const char* expected_error) {
+                                const char *expected_error)
+    {
         bool success = ShCompile(compiler, &source, 1, compileOptions) != 0;
-        if (success) {
+        if (success)
+        {
             success = !expected_error;
-        } else {
-            size_t bufferLen = 0;
-            ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen);
-            char* buffer(new char [bufferLen]);
-            ShGetInfoLog(compiler, buffer);
-            std::string log(buffer, buffer + bufferLen);
-            delete [] buffer;
+        }
+        else
+        {
+            std::string log = ShGetInfoLog(compiler);
             if (expected_error)
                 success = log.find(expected_error) != std::string::npos;