Commit 50e945a7 authored by dcw's avatar dcw
Browse files

added opt flag, meaning: only optimize if -o present

parent 0c7e05e7
......@@ -23,7 +23,7 @@
#include "decs.h"
#define MUSTBE(b) ASSERT(b,("Usage: datadec [-vp] outfile [infile]\n"))
#define MUSTBE(b) ASSERT(b,("Usage: datadec [-vpo] outfile [infile]\n"))
#define NEED_ANOTHER_ARG MUSTBE( IS_ANOTHER_ARG )
#define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg )
......@@ -43,7 +43,7 @@ main( argc, argv ) int argc; char **argv;
arg = 1;
NEED_ANOTHER_ARG;
verbose = FALSE; print = FALSE;
verbose = FALSE; print = FALSE; opt = FALSE;
while( *(s=argv[arg]) == '-' )
{
for( s++; *s; s++ )
......@@ -56,6 +56,9 @@ main( argc, argv ) int argc; char **argv;
case 'p':
print = TRUE;
break;
case 'o':
opt = TRUE;
break;
default:
ABORT( ("datadec: illegal option -%c\n",*s) );
}
......
......@@ -361,76 +361,83 @@ static void optimize( d ) declnlist d;
for( ; d != NULL; d = d->next )
{
count_empty_non( d->shapes, &e, &ne );
t = e+ne;
if( ! opt )
{
d->Defines = d->TagField = d->Struct = d->Union = TRUE;
d->UseNull = FALSE;
} else
{
count_empty_non( d->shapes, &e, &ne );
t = e+ne;
d->Defines = d->TagField = d->Struct =
d->Union = d->UseNull = FALSE;
d->Defines = d->TagField = d->Struct =
d->Union = d->UseNull = FALSE;
/* ONE, EMPTY, eg. 'data x = y' => ERROR */
ASSERT( t!=1 || e!=1,
( "datadec: type %s is empty!\n",d->name) );
ASSERT( t!=1 || e!=1,
( "datadec: type %s is empty!\n",d->name) );
if( t==1 && ne==1 )
if( t==1 && ne==1 )
/* ONE, NON EMPTY, eg. 'data x = fred(string z)' */
{
d->Struct = TRUE;
/* !Defines, !TagField, !Union, !UseNull */
} else if( t>1 && ne==0 )
{
d->Struct = TRUE;
/* !Defines, !TagField, !Union, !UseNull */
} else if( t>1 && ne==0 )
/* >1, ALL EMPTY, eg. 'data x = a | b | c | d | e' */
{
d->Defines = TRUE;
/* !TagField, !Struct, !Union, !UseNull */
} else if( d->shapes->params == NULL ) /* 1st is empty */
{
d->UseNull = d->Struct = TRUE;
if( t==2 && ne==1 )
{
/* TWO, 1ST EMPTY, 2ND NE, eg. 'data x = a | b(char z)' */
d->UseNull = d->Struct = TRUE;
/* !Union, !TagField, !Defines */
} else if( t>2 && ne==1 )
d->Defines = TRUE;
/* !TagField, !Struct, !Union, !UseNull */
} else if( d->shapes->params == NULL ) /* 1st empty */
{
d->UseNull = d->Struct = TRUE;
if( t==2 && ne==1 )
{
/* TWO, 1ST EMPTY, 2ND NE, eg. 'data x = a | b(char z)' */
d->UseNull = d->Struct = TRUE;
/* !Union, !TagField, !Defines */
} else if( t>2 && ne==1 )
{
/* >TWO, 1ST EMPTY, ONLY ONE NE, eg. 'data x = a | b | c(char z) | d | e' */
d->UseNull = d->Struct =
d->Defines = d->TagField = TRUE;
/* !Union */
d->UseNull = d->Struct =
d->Defines = d->TagField = TRUE;
/* !Union */
} else
{
/* >TWO, 1ST EMPTY, >ONE NE, eg. 'data x = a | b(int y) | c(char z) | d | e' */
d->UseNull = d->Struct =
d->Defines = d->TagField =
d->Union = TRUE;
}
} else
/* ELSE */
{
/* >TWO, 1ST EMPTY, >ONE NE, eg. 'data x = a | b(int y) | c(char z) | d | e' */
d->UseNull = d->Struct =
d->Defines = d->TagField =
d->Defines = d->TagField = d->Struct =
d->Union = TRUE;
}
} else
/* ELSE */
{
d->Defines = d->TagField = d->Struct =
d->Union = TRUE;
}
if( verbose )
{
if( verbose )
{
#define XXX(x) ( (x)?' ':'!')
printf( "type %s: %cDefines, %cTagField, ",
d->name, XXX(d->Defines),
XXX(d->TagField) );
printf( "%cStruct, %cUnion, %cUseNull\n",
XXX(d->Struct), XXX(d->Union),
XXX(d->UseNull) );
printf( "type %s: %cDefines, %cTagField, ",
d->name, XXX(d->Defines),
XXX(d->TagField) );
printf( "%cStruct, %cUnion, %cUseNull\n",
XXX(d->Struct), XXX(d->Union),
XXX(d->UseNull) );
#undef XXX
}
}
ASSERT( implies(d->Union,d->TagField),
("optimizer error: type %s has Union&!TagField\n",d->name) );
ASSERT( implies(d->Union,d->Struct),
("optimizer error: type %s has Union&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Struct),
("optimizer error: type %s has TagField&!Struct\n",d->name) );
ASSERT( implies(d->UseNull,d->Struct),
("optimizer error: type %s has UseNull&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Defines),
("optimizer error: type %s has TagField&!Defines\n",d->name) );
ASSERT( implies(d->Union,d->TagField),
("optimizer error: type %s has Union&!TagField\n",d->name) );
ASSERT( implies(d->Union,d->Struct),
("optimizer error: type %s has Union&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Struct),
("optimizer error: type %s has TagField&!Struct\n",d->name) );
ASSERT( implies(d->UseNull,d->Struct),
("optimizer error: type %s has UseNull&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Defines),
("optimizer error: type %s has TagField&!Defines\n",d->name) );
}
}
}
......
......@@ -4,4 +4,4 @@ extern void make_declns( declnlist , FILE * , FILE * , char * );
extern void make_declns();
#endif
extern BOOL print, verbose;
extern BOOL print, verbose, opt;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment