Skip to content

Commit

Permalink
[svn] Enabled -Wall, found some bugs.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Mar 28, 2008
1 parent d49cd8b commit 2286829
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
@@ -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 ...
Expand Down
42 changes: 26 additions & 16 deletions mojoshader.c
Expand Up @@ -310,7 +310,7 @@ static inline char *get_scratch_buffer(Context *ctx)
#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
Expand Down Expand Up @@ -542,7 +542,10 @@ static const char *get_D3D_register_string(Context *ctx,
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)
Expand Down Expand Up @@ -690,6 +693,10 @@ static char *make_D3D_sourcearg_string(Context *ctx, const int idx)
case SRCMOD_NOT:
premod_str = "!";
break;

case SRCMOD_NONE:
case SRCMOD_TOTAL:
break; // stop compiler whining.
} // switch


Expand Down Expand Up @@ -1921,7 +1928,6 @@ static int parse_args_DCL(Context *ctx)
{
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;

Expand Down Expand Up @@ -2299,6 +2305,9 @@ static int parse_instruction_token(Context *ctx)
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 ...
Expand Down Expand Up @@ -2357,6 +2366,9 @@ static int parse_instruction_token(Context *ctx)

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.");

Expand Down Expand Up @@ -2519,6 +2531,8 @@ static Context *build_context(const char *profile,
ctx->profile = &profiles[profileid];
else
failf(ctx, "Profile '%s' is unknown or unsupported", profile);

return ctx;
} // build_context


Expand Down Expand Up @@ -2574,7 +2588,6 @@ static char *build_output(Context *ctx)
static MOJOSHADER_parseData *build_parsedata(Context *ctx)
{
char *output = NULL;
int len = 0;
MOJOSHADER_parseData *retval;

if ((retval = ctx->malloc(sizeof (MOJOSHADER_parseData))) == NULL)
Expand Down Expand Up @@ -2627,19 +2640,16 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
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);
// 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
// parse out the rest of the tokens after the version token...
while ( (rc > 0) && (!isfail(ctx)) )
{
ctx->tokens += rc;
ctx->tokencount -= rc;
rc = parse_token(ctx);
} // while

retval = build_parsedata(ctx);
destroy_context(ctx);
Expand Down
5 changes: 3 additions & 2 deletions testparse.c
Expand Up @@ -28,17 +28,18 @@ static void Free(void *_ptr)
#define Free NULL
#endif

static const char *shader_type(MOJOSHADER_shaderType s)
static const char *shader_type(const MOJOSHADER_shaderType s)
{
switch (s)
{
case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
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


Expand Down

0 comments on commit 2286829

Please sign in to comment.