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 @@ ...@@ -23,7 +23,7 @@
#include "decs.h" #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 NEED_ANOTHER_ARG MUSTBE( IS_ANOTHER_ARG )
#define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg ) #define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg )
...@@ -43,7 +43,7 @@ main( argc, argv ) int argc; char **argv; ...@@ -43,7 +43,7 @@ main( argc, argv ) int argc; char **argv;
arg = 1; arg = 1;
NEED_ANOTHER_ARG; NEED_ANOTHER_ARG;
verbose = FALSE; print = FALSE; verbose = FALSE; print = FALSE; opt = FALSE;
while( *(s=argv[arg]) == '-' ) while( *(s=argv[arg]) == '-' )
{ {
for( s++; *s; s++ ) for( s++; *s; s++ )
...@@ -56,6 +56,9 @@ main( argc, argv ) int argc; char **argv; ...@@ -56,6 +56,9 @@ main( argc, argv ) int argc; char **argv;
case 'p': case 'p':
print = TRUE; print = TRUE;
break; break;
case 'o':
opt = TRUE;
break;
default: default:
ABORT( ("datadec: illegal option -%c\n",*s) ); ABORT( ("datadec: illegal option -%c\n",*s) );
} }
......
...@@ -361,76 +361,83 @@ static void optimize( d ) declnlist d; ...@@ -361,76 +361,83 @@ static void optimize( d ) declnlist d;
for( ; d != NULL; d = d->next ) for( ; d != NULL; d = d->next )
{ {
count_empty_non( d->shapes, &e, &ne ); if( ! opt )
t = e+ne; {
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->Defines = d->TagField = d->Struct =
d->Union = d->UseNull = FALSE; d->Union = d->UseNull = FALSE;
/* ONE, EMPTY, eg. 'data x = y' => ERROR */ /* ONE, EMPTY, eg. 'data x = y' => ERROR */
ASSERT( t!=1 || e!=1, ASSERT( t!=1 || e!=1,
( "datadec: type %s is empty!\n",d->name) ); ( "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)' */ /* ONE, NON EMPTY, eg. 'data x = fred(string z)' */
{ {
d->Struct = TRUE; d->Struct = TRUE;
/* !Defines, !TagField, !Union, !UseNull */ /* !Defines, !TagField, !Union, !UseNull */
} else if( t>1 && ne==0 ) } else if( t>1 && ne==0 )
/* >1, ALL EMPTY, eg. 'data x = a | b | c | d | e' */ /* >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->Defines = TRUE;
d->UseNull = d->Struct = TRUE; /* !TagField, !Struct, !Union, !UseNull */
/* !Union, !TagField, !Defines */ } else if( d->shapes->params == NULL ) /* 1st empty */
} else if( t>2 && ne==1 )
{ {
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' */ /* >TWO, 1ST EMPTY, ONLY ONE NE, eg. 'data x = a | b | c(char z) | d | e' */
d->UseNull = d->Struct = d->UseNull = d->Struct =
d->Defines = d->TagField = TRUE; d->Defines = d->TagField = TRUE;
/* !Union */ /* !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
/* ELSE */
{ {
/* >TWO, 1ST EMPTY, >ONE NE, eg. 'data x = a | b(int y) | c(char z) | d | e' */ d->Defines = d->TagField = d->Struct =
d->UseNull = d->Struct =
d->Defines = d->TagField =
d->Union = TRUE; d->Union = TRUE;
} }
} else
/* ELSE */
{
d->Defines = d->TagField = d->Struct =
d->Union = TRUE;
}
if( verbose ) if( verbose )
{ {
#define XXX(x) ( (x)?' ':'!') #define XXX(x) ( (x)?' ':'!')
printf( "type %s: %cDefines, %cTagField, ", printf( "type %s: %cDefines, %cTagField, ",
d->name, XXX(d->Defines), d->name, XXX(d->Defines),
XXX(d->TagField) ); XXX(d->TagField) );
printf( "%cStruct, %cUnion, %cUseNull\n", printf( "%cStruct, %cUnion, %cUseNull\n",
XXX(d->Struct), XXX(d->Union), XXX(d->Struct), XXX(d->Union),
XXX(d->UseNull) ); XXX(d->UseNull) );
#undef XXX #undef XXX
} }
ASSERT( implies(d->Union,d->TagField), ASSERT( implies(d->Union,d->TagField),
("optimizer error: type %s has Union&!TagField\n",d->name) ); ("optimizer error: type %s has Union&!TagField\n",d->name) );
ASSERT( implies(d->Union,d->Struct), ASSERT( implies(d->Union,d->Struct),
("optimizer error: type %s has Union&!Struct\n",d->name) ); ("optimizer error: type %s has Union&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Struct), ASSERT( implies(d->TagField,d->Struct),
("optimizer error: type %s has TagField&!Struct\n",d->name) ); ("optimizer error: type %s has TagField&!Struct\n",d->name) );
ASSERT( implies(d->UseNull,d->Struct), ASSERT( implies(d->UseNull,d->Struct),
("optimizer error: type %s has UseNull&!Struct\n",d->name) ); ("optimizer error: type %s has UseNull&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Defines), ASSERT( implies(d->TagField,d->Defines),
("optimizer error: type %s has TagField&!Defines\n",d->name) ); ("optimizer error: type %s has TagField&!Defines\n",d->name) );
}
} }
} }
......
...@@ -4,4 +4,4 @@ extern void make_declns( declnlist , FILE * , FILE * , char * ); ...@@ -4,4 +4,4 @@ extern void make_declns( declnlist , FILE * , FILE * , char * );
extern void make_declns(); extern void make_declns();
#endif #endif
extern BOOL print, verbose; extern BOOL print, verbose, opt;
Supports Markdown
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