[svn] Enabled -Wall, found some bugs. trunk
authoricculus
Thu, 27 Mar 2008 22:52:20 -0400
branchtrunk
changeset 48 86dc2c772d26
parent 47 49953c7cb142
child 49 780cd8790dff
[svn] Enabled -Wall, found some bugs.
CMakeLists.txt
mojoshader.c
testparse.c
--- a/CMakeLists.txt	Thu Mar 27 22:43:36 2008 -0400
+++ b/CMakeLists.txt	Thu Mar 27 22:52:20 2008 -0400
@@ -1,5 +1,13 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
 PROJECT(MojoShader)
+
+IF(CMAKE_COMPILER_IS_GNUCC)
+    ADD_DEFINITIONS(-Wall -ggdb3)
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+# testparse uses this.
+ADD_DEFINITIONS(-DMOJOSHADER_DEBUG_MALLOC=1)
+
 ADD_EXECUTABLE(testparse testparse.c mojoshader.c)
 
 # End of CMakeLists.txt ...
--- a/mojoshader.c	Thu Mar 27 22:43:36 2008 -0400
+++ b/mojoshader.c	Thu Mar 27 22:52:20 2008 -0400
@@ -310,7 +310,7 @@
 #define NOFAIL (-2)
 #define END_OF_STREAM (-3)
 
-static inline isfail(const Context *ctx)
+static inline int isfail(const Context *ctx)
 {
     return (ctx->failstr != NULL);
 } // isfail
@@ -542,7 +542,10 @@
             break;
 
         // !!! FIXME: don't know what the asm string is for this..
-        // case REGISTER_TYPE_TEMPFLOAT16:
+        case REGISTER_TYPE_TEMPFLOAT16:
+            retval = "???";
+            has_number = 0;
+            break;
 
         case REGISTER_TYPE_MISCTYPE:
             switch ((MiscTypeType) regnum)
@@ -690,6 +693,10 @@
         case SRCMOD_NOT:
             premod_str = "!";
             break;
+
+        case SRCMOD_NONE:
+        case SRCMOD_TOTAL:
+             break;  // stop compiler whining.
     } // switch
 
 
@@ -1921,7 +1928,6 @@
 {
     int unsupported = 0;
     const uint32 token = SWAP32(*(ctx->tokens));
-    const DeclUsageType usage = (DeclUsageType)(token & 0xF);
     const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
     uint32 reserved_mask = 0x00000000;
 
@@ -2299,6 +2305,9 @@
     if (coissue)  // !!! FIXME: I'm not sure what this means, yet.
         return fail(ctx, "coissue instructions unsupported");
 
+    if (predicated)  // !!! FIXME: I'm not sure what this means, yet.
+        return fail(ctx, "predicated instructions unsupported");
+
     if (ctx->major_ver < 2)
     {
         if (insttoks != 0)  // this is a reserved field in shaders < 2.0 ...
@@ -2357,6 +2366,9 @@
 
 static int parse_version_token(Context *ctx)
 {
+    if (isfail(ctx))  // catch preexisting errors here.
+        return FAIL;
+
     if (ctx->tokencount == 0)
         return fail(ctx, "Expected version token, got none at all.");
 
@@ -2519,6 +2531,8 @@
         ctx->profile = &profiles[profileid];
     else
         failf(ctx, "Profile '%s' is unknown or unsupported", profile);
+
+    return ctx;
 } // build_context
 
 
@@ -2574,7 +2588,6 @@
 static MOJOSHADER_parseData *build_parsedata(Context *ctx)
 {
     char *output = NULL;
-    int len = 0;
     MOJOSHADER_parseData *retval;
 
     if ((retval = ctx->malloc(sizeof (MOJOSHADER_parseData))) == NULL)
@@ -2627,19 +2640,16 @@
     if ((ctx = build_context(profile, tokenbuf, bufsize, m, f)) == NULL)
         return &out_of_mem_data;
 
-    if (!isfail(ctx))
+    // Version token always comes first.
+    rc = parse_version_token(ctx);
+
+    // parse out the rest of the tokens after the version token...
+    while ( (rc > 0) && (!isfail(ctx)) )
     {
-        // Version token always comes first.
-        rc = parse_version_token(ctx);
-
-        // parse out the rest of the tokens after the version token...
-        while (rc > 0)
-        {
-            ctx->tokens += rc;
-            ctx->tokencount -= rc;
-            rc = parse_token(ctx);
-        } // while
-    } // if
+        ctx->tokens += rc;
+        ctx->tokencount -= rc;
+        rc = parse_token(ctx);
+    } // while
 
     retval = build_parsedata(ctx);
     destroy_context(ctx);
--- a/testparse.c	Thu Mar 27 22:43:36 2008 -0400
+++ b/testparse.c	Thu Mar 27 22:52:20 2008 -0400
@@ -28,7 +28,7 @@
 #define Free NULL
 #endif
 
-static const char *shader_type(MOJOSHADER_shaderType s)
+static const char *shader_type(const MOJOSHADER_shaderType s)
 {
     switch (s)
     {
@@ -36,9 +36,10 @@
         case MOJOSHADER_TYPE_PIXEL: return "pixel";
         case MOJOSHADER_TYPE_VERTEX: return "vertex";
         case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
+        default: return "(bogus value?)";
     } // switch
 
-    return "(bogus value?)";
+    return NULL;  // shouldn't hit this.
 } // shader_type