testoutput.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 03 Jul 2008 12:09:26 -0400
branchtrunk
changeset 421 bfd3d95273ec
parent 390 4effa7e6b49c
child 450 6a9faf398c1d
permissions -rw-r--r--
First piece of work on nv3 profile.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
390
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/**
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *  Direct3D shaders.
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 *
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
 */
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdio.h>
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <stdlib.h>
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "mojoshader.h"
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
static int do_parse(const unsigned char *buf, const int len, const char *prof)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
{
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    const MOJOSHADER_parseData *pd;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    int retval = 0;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    pd = MOJOSHADER_parse(prof, buf, len, NULL, NULL, NULL);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    if (pd->error != NULL)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
        printf("ERROR: %s\n", pd->error);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    {
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
        retval = 1;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
        if (pd->output != NULL)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
        {
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
            int i;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
            for (i = 0; i < pd->output_len; i++)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
                putchar((int) pd->output[i]);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
            printf("\n");
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        } // if
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
    } // else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    printf("\n\n");
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    MOJOSHADER_freeParseData(pd);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    return retval;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
} // do_parse
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
int main(int argc, char **argv)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
{
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    int retval = 0;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    if (argc <= 2)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    {
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        const char *profile = argv[1];
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        int i;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        for (i = 2; i < argc; i++)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        {
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
            FILE *io = fopen(argv[i], "rb");
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
            if (io == NULL)
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
                printf(" ... fopen('%s') failed.\n", argv[i]);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
            else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
            {
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
                unsigned char *buf = (unsigned char *) malloc(1000000);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
                int rc = fread(buf, 1, 1000000, io);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
                fclose(io);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
                if (!do_parse(buf, rc, profile))
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
                    retval = 1;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
                free(buf);
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            } // else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        } // for
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    } // else
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    return retval;
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
} // main
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
// end of testoutput.c ...
4effa7e6b49c Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72