testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 03 May 2008 20:08:46 -0400
branchtrunk
changeset 279 f06f4ea3d751
parent 278 5c432d216078
child 280 61b2abd9c927
permissions -rw-r--r--
Fixed relative addressing in GLSL profile. It was using wrong variable name ("a0" instead of "vs_a0").
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     9
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    10
#include <stdio.h>
9
aea1b254e6a5 [svn] Patched to compile.
icculus
parents: 7
diff changeset
    11
#include <stdlib.h>
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
    12
#include "mojoshader.h"
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    13
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    14
#ifdef _MSC_VER
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    15
#define snprintf _snprintf
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    16
#endif
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    17
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    18
#if MOJOSHADER_DEBUG_MALLOC
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    19
static void *Malloc(int len)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    20
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    21
    void *ptr = malloc(len + sizeof (int));
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    22
    int *store = (int *) ptr;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    23
    printf("malloc() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    24
    if (ptr == NULL) return NULL;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    25
    *store = len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    26
    return (void *) (store + 1);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    27
} // Malloc
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    28
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    29
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    30
static void Free(void *_ptr)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    31
{
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    32
    int *ptr = (((int *) _ptr) - 1);
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    33
    int len = *ptr;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    34
    printf("free() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    35
    free(ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    36
} // Free
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    37
#else
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    38
#define Malloc NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    39
#define Free NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    40
#endif
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    41
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    42
static const char *shader_type(const MOJOSHADER_shaderType s)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    43
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    44
    switch (s)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    45
    {
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    46
        case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    47
        case MOJOSHADER_TYPE_PIXEL: return "pixel";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    48
        case MOJOSHADER_TYPE_VERTEX: return "vertex";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    49
        case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    50
        default: return "(bogus value?)";
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    51
    } // switch
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    52
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    53
    return NULL;  // shouldn't hit this.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    54
} // shader_type
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    55
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    56
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
    57
static int do_parse(const unsigned char *buf, const int len, const char *prof)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    58
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    59
    const MOJOSHADER_parseData *pd;
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
    60
    int retval = 0;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    61
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    62
    pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free, NULL);
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    63
    printf("PROFILE: %s\n", prof);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    64
    if (pd->error != NULL)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    65
        printf("ERROR: %s\n", pd->error);
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    66
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    67
    {
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
    68
        retval = 1;
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    69
        printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    70
        printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    71
        printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    72
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    73
        printf("ATTRIBUTES:");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    74
        if (pd->attribute_count == 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    75
            printf(" (none.)\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    76
        else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    77
        {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    78
            int i;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    79
            printf("\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    80
            for (i = 0; i < pd->attribute_count; i++)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    81
            {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    82
                static const char *usagenames[] = {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    83
                    "position", "blendweight", "blendindices", "normal",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    84
                    "psize", "texcoord", "tangent", "binormal", "tessfactor",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    85
                    "positiont", "color", "fog", "depth", "sample"
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    86
                };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    87
                const MOJOSHADER_attribute *a = &pd->attributes[i];
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    88
                char numstr[16] = { 0 };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    89
                if (a->index != 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    90
                    snprintf(numstr, sizeof (numstr), "%d", a->index);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
    91
                printf("    * %s%s", usagenames[(int) a->usage], numstr);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
    92
                if (a->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
    93
                    printf(" (\"%s\")", a->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
    94
                printf("\n");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    95
            } // for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    96
        } // else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    97
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    98
        printf("CONSTANTS:");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    99
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   100
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   101
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   102
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   103
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   104
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   105
            for (i = 0; i < pd->constant_count; i++)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   106
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   107
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   108
                const MOJOSHADER_constant *c = &pd->constants[i];
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   109
                printf("    * %d: %s (", c->index, typenames[(int) c->type]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   110
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   111
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   112
                    printf("%f %f %f %f", c->value.f[0], c->value.f[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   113
                                          c->value.f[2], c->value.f[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   114
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   115
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   116
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   117
                    printf("%d %d %d %d", c->value.i[0], c->value.i[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   118
                                          c->value.i[2], c->value.i[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   119
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   120
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   121
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   122
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   123
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   124
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   125
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   126
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   127
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   128
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   129
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   130
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   131
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   132
        printf("UNIFORMS:");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   133
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   134
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   135
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   136
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   137
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   138
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   139
            for (i = 0; i < pd->uniform_count; i++)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   140
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   141
                static const char *typenames[] = { "float", "int", "bool" };
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   142
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   143
                printf("    * %d: %s", u->index, typenames[(int) u->type]);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   144
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   145
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   146
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   147
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   148
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   149
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   150
        printf("SAMPLERS:");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   151
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   152
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   153
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   154
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   155
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   156
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   157
            for (i = 0; i < pd->sampler_count; i++)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   158
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   159
                static const char *typenames[] = { "2d", "cube", "volume" };
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   160
                const MOJOSHADER_sampler *s = &pd->samplers[i];
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   161
                printf("    * %d: %s", s->index, typenames[(int) s->type]);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   162
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   163
                    printf(" (\"%s\")", s->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   164
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   165
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   166
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   167
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   168
        if (pd->output != NULL)
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   169
        {
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   170
            int i;
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   171
            printf("OUTPUT:\n");
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   172
            for (i = 0; i < pd->output_len; i++)
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   173
                putchar((int) pd->output[i]);
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   174
            printf("\n");
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   175
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   176
    } // else
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   177
    printf("\n\n");
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   178
    MOJOSHADER_freeParseData(pd);
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   179
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   180
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   181
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   182
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   183
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   184
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   185
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   186
    int retval = 0;
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   187
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   188
    printf("MojoShader testparse\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   189
    printf("Compiled against version %d\n", MOJOSHADER_VERSION);
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   190
    printf("Linked against version %d\n", MOJOSHADER_version());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   191
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   192
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   193
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   194
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   195
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   196
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   197
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   198
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   199
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   200
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   201
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   202
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   203
            printf("FILE: %s\n", argv[i]);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   204
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   205
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   206
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   207
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   208
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   209
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   210
                fclose(io);
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   211
                if (!do_parse(buf, rc, profile))
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   212
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   213
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   214
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   215
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   216
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   217
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   218
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   219
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   220
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   221
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   222