utils/testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 17 Apr 2012 00:07:33 -0400
changeset 1090 636ffcd3f14a
parent 1055 3295380ce6fc
child 1104 9147482e1ec7
permissions -rw-r--r--
First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
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
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    42
static inline void do_indent(const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    43
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    44
    unsigned int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    45
    for (i = 0; i < indent; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    46
        printf("    ");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    47
}
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    48
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    49
#define INDENT() do { if (indent) { do_indent(indent); } } while (0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    50
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    51
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    52
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
    53
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    54
    switch (s)
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
        case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    57
        case MOJOSHADER_TYPE_PIXEL: return "pixel";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    58
        case MOJOSHADER_TYPE_VERTEX: return "vertex";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    59
        case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    60
        default: return "(bogus value?)";
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    61
    } // switch
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    62
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    63
    return NULL;  // shouldn't hit this.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    64
} // shader_type
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    65
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    66
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    67
static void print_typeinfo(const MOJOSHADER_symbolTypeInfo *info,
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    68
                           unsigned int indent)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    69
{
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    70
    static const char *symclasses[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    71
        "scalar", "vector", "row-major matrix",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    72
        "column-major matrix", "object", "struct"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    73
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    74
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    75
    static const char *symtypes[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    76
        "void", "bool", "int", "float", "string", "texture",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    77
        "texture1d", "texture2d", "texture3d", "texturecube",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    78
        "sampler", "sampler1d", "sampler2d", "sampler3d",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    79
        "samplercube", "pixelshader", "vertexshader", "unsupported"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    80
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    81
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    82
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    83
    printf("      symbol class %s\n", symclasses[info->parameter_class]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    84
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    85
    printf("      symbol type %s\n", symtypes[info->parameter_type]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    86
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    87
    printf("      rows %u\n", info->rows);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    88
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    89
    printf("      columns %u\n", info->columns);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    90
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    91
    printf("      elements %u\n", info->elements);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    92
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    93
    if (info->member_count > 0)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    94
    {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    95
        int i;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    96
        INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    97
        for (i = 0; i < info->member_count; i++)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    98
        {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    99
            const MOJOSHADER_symbolStructMember *member = &info->members[i];
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   100
            INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   101
            indent++;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   102
            INDENT(); printf("      * %d: \"%s\"\n", i, member->name);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   103
            print_typeinfo(&member->info, indent);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   104
            indent--;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   105
        } // for
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   106
    } // if
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   107
} // print_typeinfo
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   108
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   109
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   110
static void print_symbols(const MOJOSHADER_symbol *sym,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   111
                          const unsigned int symbol_count,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   112
                          const unsigned int indent)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   113
{
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   114
    INDENT(); printf("SYMBOLS:");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   115
    if (symbol_count == 0)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   116
        printf(" (none.)\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   117
    else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   118
    {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   119
        int i;
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   120
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   121
        for (i = 0; i < symbol_count; i++, sym++)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   122
        {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   123
            static const char *regsets[] = {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   124
                "bool", "int4", "float4", "sampler"
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   125
            };
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   126
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   127
            INDENT(); printf("    * %d: \"%s\"\n", i, sym->name);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   128
            INDENT(); printf("      register set %s\n", regsets[sym->register_set]);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   129
            INDENT(); printf("      register index %u\n", sym->register_index);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   130
            INDENT(); printf("      register count %u\n", sym->register_count);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   131
            print_typeinfo(&sym->info, indent);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   132
        } // for
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   133
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   134
    } // else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   135
} // print_symbols
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   136
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   137
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   138
static void print_preshader_operand(const MOJOSHADER_preshader *preshader,
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   139
                                    const int instidx, const int opidx)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   140
{
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   141
    static char mask[] = { 'x', 'y', 'z', 'w' };
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   142
    const MOJOSHADER_preshaderInstruction *inst = &preshader->instructions[instidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   143
    const MOJOSHADER_preshaderOperand *operand = &inst->operands[opidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   144
    const int elems = inst->element_count;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   145
    const int isscalarop = (inst->opcode >= MOJOSHADER_PRESHADEROP_SCALAR_OPS);
1051
96a838f4e680 Fixed off-by-one error in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1046
diff changeset
   146
    const int isscalar = ((isscalarop) && (opidx == 0)); // probably wrong.
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   147
    int i;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   148
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   149
    switch (operand->type)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   150
    {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   151
        case MOJOSHADER_PRESHADEROPERAND_LITERAL:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   152
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   153
            const double *lit = &preshader->literals[operand->index];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   154
            printf("(");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   155
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   156
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   157
                const double val = *lit;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   158
                for (i = 0; i < elems-1; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   159
                    printf("%g, ", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   160
                printf("%g)", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   161
            } // if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   162
            else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   163
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   164
                for (i = 0; i < elems-1; i++, lit++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   165
                    printf("%g, ", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   166
                printf("%g)", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   167
            } // else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   168
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   169
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   170
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   171
        case MOJOSHADER_PRESHADEROPERAND_INPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   172
        case MOJOSHADER_PRESHADEROPERAND_OUTPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   173
        case MOJOSHADER_PRESHADEROPERAND_TEMP:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   174
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   175
            int idx = operand->index % 4;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   176
            char regch = 'c';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   177
            if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   178
                regch = 'r';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   179
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   180
            printf("%c%d", regch, operand->index / 4);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   181
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   182
                printf(".%c", mask[idx]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   183
            else if (elems != 4)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   184
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   185
                printf(".");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   186
                for (i = 0; i < elems; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   187
                    printf("%c", mask[idx++]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   188
            } // else if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   189
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   190
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   191
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   192
        default:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   193
            printf("[???{%d, %u}???]", (int) operand->type, operand->index);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   194
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   195
    } // switch
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   196
} // print_preshader_operand
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   197
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   198
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   199
static void print_preshader(const MOJOSHADER_preshader *preshader,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   200
                            const int indent)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   201
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   202
    MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   203
    int i, j;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   204
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   205
    static const char *opcodestr[] = {
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   206
        "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos",
1034
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   207
        "asin", "acos", "atan", "min", "max", "lt", "ge", "add", "mul",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   208
        "atan2", "div", "cmp", "movc", "dot", "noise", "min", "max", "lt",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   209
        "ge", "add", "mul", "atan2", "div", "dot", "noise"
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   210
    };
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   211
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   212
    INDENT(); printf("PRESHADER:\n");
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   213
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   214
    print_symbols(preshader->symbols, preshader->symbol_count, indent + 1);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   215
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   216
    for (i = 0; i < preshader->instruction_count; i++, inst++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   217
    {
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   218
        INDENT(); printf("    %s ", opcodestr[inst->opcode]);
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   219
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   220
        // print dest register first...
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   221
        print_preshader_operand(preshader, i, inst->operand_count - 1);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   222
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   223
        // ...then the source registers.
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   224
        for (j = 0; j < inst->operand_count - 1; j++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   225
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   226
            printf(", ");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   227
            print_preshader_operand(preshader, i, j);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   228
        } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   229
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   230
        printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   231
    } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   232
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   233
    printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   234
} // print_preshader
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   235
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   236
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   237
static void print_attrs(const char *category, const int count,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   238
                        const MOJOSHADER_attribute *attributes,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   239
                        const int indent)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   240
{
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   241
    INDENT(); printf("%s:", category);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   242
    if (count == 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   243
        printf(" (none.)\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   244
    else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   245
    {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   246
        int i;
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   247
        printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   248
        for (i = 0; i < count; i++)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   249
        {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   250
            static const char *usagenames[] = {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   251
                "position", "blendweight", "blendindices", "normal",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   252
                "psize", "texcoord", "tangent", "binormal", "tessfactor",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   253
                "positiont", "color", "fog", "depth", "sample"
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   254
            };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   255
            const MOJOSHADER_attribute *a = &attributes[i];
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   256
            char numstr[16] = { 0 };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   257
            if (a->index != 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   258
                snprintf(numstr, sizeof (numstr), "%d", a->index);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   259
            INDENT();
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   260
            printf("    * %s%s", usagenames[(int) a->usage], numstr);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   261
            if (a->name != NULL)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   262
                printf(" (\"%s\")", a->name);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   263
            printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   264
        } // for
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   265
    } // else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   266
} // print_attrs
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   267
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   268
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   269
static void print_shader(const char *fname, const MOJOSHADER_parseData *pd,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   270
                         unsigned int indent)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   271
{
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   272
    INDENT(); printf("PROFILE: %s\n", pd->profile);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   273
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   274
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   275
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   276
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   277
        {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   278
            const MOJOSHADER_error *err = &pd->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   279
            INDENT();
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
   280
            printf("%s:%d: ERROR: %s\n",
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   281
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   282
                    err->error_position, err->error);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   283
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   284
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   285
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   286
    {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   287
        INDENT(); printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   288
        INDENT(); printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   289
        INDENT(); printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   290
        print_attrs("INPUTS", pd->attribute_count, pd->attributes, indent);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   291
        print_attrs("OUTPUTS", pd->output_count, pd->outputs, indent);
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   292
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   293
        INDENT(); printf("CONSTANTS:");
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   294
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   295
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   296
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   297
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   298
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   299
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   300
            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
   301
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   302
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   303
                const MOJOSHADER_constant *c = &pd->constants[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   304
                INDENT(); 
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   305
                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
   306
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   307
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   308
                    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
   309
                                          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
   310
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   311
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   312
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   313
                    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
   314
                                          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
   315
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   316
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   317
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   318
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   319
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   320
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   321
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   322
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   323
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   324
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   325
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   326
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   327
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   328
        INDENT(); printf("UNIFORMS:");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   329
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   330
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   331
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   332
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   333
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   334
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   335
            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
   336
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   337
                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
   338
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   339
                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
   340
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   341
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   342
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   343
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   344
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   345
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   346
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   347
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   348
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   349
                INDENT();
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
   350
                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
   351
                        arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   352
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   353
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   354
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   355
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   356
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   357
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   358
        INDENT(); printf("SAMPLERS:");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   359
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   360
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   361
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   362
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   363
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   364
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   365
            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
   366
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   367
                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
   368
                const MOJOSHADER_sampler *s = &pd->samplers[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   369
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   370
                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
   371
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   372
                    printf(" (\"%s\")", s->name);
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   373
                if (s->texbem)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   374
                    printf(" [TEXBEM]");
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   375
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   376
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   377
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   378
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   379
        print_symbols(pd->symbols, pd->symbol_count, indent);
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   380
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   381
        if (pd->preshader != NULL)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   382
            print_preshader(pd->preshader, indent);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   383
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   384
        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
   385
        {
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
   386
            int i;
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   387
            INDENT();
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
   388
            printf("OUTPUT:\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   389
            indent++;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   390
            INDENT();
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
   391
            for (i = 0; i < pd->output_len; i++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   392
            {
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
   393
                putchar((int) pd->output[i]);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   394
                if (pd->output[i] == '\n')
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   395
                    INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   396
            } // for
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
   397
            printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   398
            indent--;
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
   399
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   400
    } // else
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   401
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   402
    printf("\n\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   403
} // print_shader
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   404
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   405
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   406
static void print_effect(const char *fname, const MOJOSHADER_effect *effect,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   407
                         const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   408
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   409
    INDENT(); printf("PROFILE: %s\n", effect->profile);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   410
    printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   411
    if (effect->error_count > 0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   412
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   413
        int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   414
        for (i = 0; i < effect->error_count; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   415
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   416
            const MOJOSHADER_error *err = &effect->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   417
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   418
            printf("%s:%d: ERROR: %s\n",
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   419
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   420
                    err->error_position, err->error);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   421
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   422
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   423
    else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   424
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   425
        int i, j, k;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   426
        const MOJOSHADER_effectTechnique *technique = effect->techniques;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   427
        const MOJOSHADER_effectTexture *texture = effect->textures;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   428
        const MOJOSHADER_effectShader *shader = effect->shaders;
1037
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   429
        const MOJOSHADER_effectParam *param = effect->params;
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   430
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   431
        for (i = 0; i < effect->param_count; i++, param++)
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   432
        {
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   433
            INDENT();
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   434
            printf("PARAM #%d '%s' -> '%s'\n", i, param->name, param->semantic);
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   435
        } // for
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   436
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   437
        printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   438
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   439
        for (i = 0; i < effect->technique_count; i++, technique++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   440
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   441
            const MOJOSHADER_effectPass *pass = technique->passes;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   442
            INDENT(); printf("TECHNIQUE #%d ('%s'):\n", i, technique->name);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   443
            for (j = 0; j < technique->pass_count; j++, pass++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   444
            {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   445
                const MOJOSHADER_effectState *state = pass->states;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   446
                INDENT(); printf("    PASS #%d ('%s'):\n", j, pass->name);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   447
                for (k = 0; k < pass->state_count; k++, state++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   448
                {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   449
                    INDENT(); printf("        STATE 0x%X\n", state->type);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   450
                } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   451
            } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   452
            printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   453
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   454
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   455
        for (i = 0; i < effect->texture_count; i++, texture++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   456
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   457
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   458
            printf("TEXTURE #%d ('%s'): %u\n", i,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   459
                    texture->name, texture->param);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   460
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   461
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   462
        printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   463
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   464
        for (i = 0; i < effect->shader_count; i++, shader++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   465
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   466
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   467
            printf("SHADER #%d: technique %u, pass %u\n", i,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   468
                    shader->technique, shader->pass);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   469
            print_shader(fname, shader->shader, indent + 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   470
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   471
    } // else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   472
} // print_effect
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   473
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   474
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   475
static int do_parse(const char *fname, const unsigned char *buf,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   476
                    const int len, const char *prof)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   477
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   478
    int retval = 0;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   479
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   480
    // magic for an effects file (!!! FIXME: I _think_).
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   481
    if ( (buf[0] == 0x01) && (buf[1] == 0x09) &&
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   482
         (buf[2] == 0xFF) && (buf[3] == 0xFE) )
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   483
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   484
        const MOJOSHADER_effect *effect;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   485
        effect = MOJOSHADER_parseEffect(prof, buf, len, 0, 0, Malloc, Free, 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   486
        retval = (effect->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   487
        printf("EFFECT: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   488
        print_effect(fname, effect, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   489
        MOJOSHADER_freeEffect(effect);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   490
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   491
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   492
    else  // do it as a regular compiled shader.
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   493
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   494
        const MOJOSHADER_parseData *pd;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   495
        pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, Malloc, Free, NULL);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   496
        retval = (pd->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   497
        printf("SHADER: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   498
        print_shader(fname, pd, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   499
        MOJOSHADER_freeParseData(pd);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   500
    } // else
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   501
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   502
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   503
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   504
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   505
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   506
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   507
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   508
    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
   509
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   510
    printf("MojoShader testparse\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   511
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   512
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   513
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   514
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   515
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   516
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   517
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   518
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   519
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   520
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   521
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   522
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   523
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   524
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   525
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   526
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   527
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   528
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   529
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   530
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   531
                fclose(io);
902
cff5841d29e7 Report actual filename in errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   532
                if (!do_parse(argv[i], buf, rc, profile))
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   533
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   534
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   535
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   536
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   537
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   538
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   539
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   540
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   541
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   542
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   543