utils/testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 15 Feb 2009 02:25:26 -0500
changeset 628 33da6087aa48
parent 588 ef3d2efa822d
child 901 a9f799b93150
permissions -rw-r--r--
Moved the "public API" comment to what is now, in fact, the real public API. :)
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
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
    62
    pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, 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);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    64
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    65
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    66
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    67
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    68
        {
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    69
            printf("%s:%d: ERROR: %s\n",
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    70
                    pd->errors[i].filename ? pd->errors[i].filename : "???",
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    71
                    pd->errors[i].error_position,
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    72
                    pd->errors[i].error);
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    73
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    74
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    75
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    76
    {
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
    77
        retval = 1;
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    78
        printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    79
        printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    80
        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
    81
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    82
        printf("ATTRIBUTES:");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    83
        if (pd->attribute_count == 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    84
            printf(" (none.)\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    85
        else
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
            int i;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    88
            printf("\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    89
            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
    90
            {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    91
                static const char *usagenames[] = {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    92
                    "position", "blendweight", "blendindices", "normal",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    93
                    "psize", "texcoord", "tangent", "binormal", "tessfactor",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    94
                    "positiont", "color", "fog", "depth", "sample"
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    95
                };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    96
                const MOJOSHADER_attribute *a = &pd->attributes[i];
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    97
                char numstr[16] = { 0 };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    98
                if (a->index != 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    99
                    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
   100
                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
   101
                if (a->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   102
                    printf(" (\"%s\")", a->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   103
                printf("\n");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   104
            } // for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   105
        } // else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   106
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   107
        printf("CONSTANTS:");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   108
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   109
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   110
        else
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
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   113
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   114
            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
   115
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   116
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   117
                const MOJOSHADER_constant *c = &pd->constants[i];
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   118
                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
   119
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   120
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   121
                    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
   122
                                          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
   123
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   124
                else if (c->type == MOJOSHADER_UNIFORM_INT)
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("%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
   127
                                          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
   128
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   129
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   130
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   131
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   132
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   133
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   134
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   135
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   136
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   137
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   138
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   139
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   140
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   141
        printf("UNIFORMS:");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   142
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   143
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   144
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   145
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   146
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   147
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   148
            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
   149
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   150
                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
   151
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   152
                const char *arrayof = "";
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   153
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   154
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   155
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   156
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   157
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   158
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   159
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   160
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   161
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   162
                printf("    * %d: %s%s%s%s", u->index, constant, arrayof,
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   163
                        arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   164
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   165
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   166
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   167
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   168
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   169
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   170
        printf("SAMPLERS:");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   171
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   172
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   173
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   174
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   175
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   176
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   177
            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
   178
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   179
                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
   180
                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
   181
                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
   182
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   183
                    printf(" (\"%s\")", s->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   184
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   185
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   186
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   187
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   188
        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
   189
        {
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
   190
            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
   191
            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
   192
            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
   193
                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
   194
            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
   195
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   196
    } // else
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   197
    printf("\n\n");
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   198
    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
   199
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   200
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   201
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   202
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   203
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   204
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   205
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   206
    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
   207
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   208
    printf("MojoShader testparse\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   209
    printf("Compiled against version %d\n", MOJOSHADER_VERSION);
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   210
    printf("Linked against version %d\n", MOJOSHADER_version());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   211
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   212
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   213
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   214
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   215
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   216
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   217
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   218
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   219
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   220
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   221
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   222
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   223
            printf("FILE: %s\n", argv[i]);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   224
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   225
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   226
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   227
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   228
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   229
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   230
                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
   231
                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
   232
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   233
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   234
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   235
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   236
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   237
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   238
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   239
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   240
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   241
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   242