Commit 93b36a9a authored by Duncan White's avatar Duncan White

split meta-data generation out, separate -m mode generating meta-data to...

split meta-data generation out, separate -m mode generating meta-data to stdout, no .dd file, much nicely
parent f994b8fd
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
* *
* The output produced is placed in pair of files (eg. x.c and x.h ) * The output produced is placed in pair of files (eg. x.c and x.h )
* which together form a module provided the relevant data types. * which together form a module provided the relevant data types.
* NEW in 2018: in addition, we write a useful summary of types, *
* shapes and the types of the shape parameters into a .x.dd file, * NEW in 2018: new "-m" (meta-data only) mode, which causes datadec to
* this can be used by experimental client-side tools such as "CPM.perl". * ONLY write a useful summary of types, shapes and the types of the shape
* parameters to stdout.
* This can be used by experimental client-side tools such as my "C with
* shaped pattern matching tool", CPM.
*/ */
#include <stdio.h> #include <stdio.h>
...@@ -32,7 +35,9 @@ ...@@ -32,7 +35,9 @@
#include "optimize.h" #include "optimize.h"
#define MUSTBE(b) {if(!(b)){fprintf(stderr,"Usage: datadec [-vnof] outfile [infile]\n");exit(1);}} #define USAGEMSG "Usage: datadec [-vnof] outfile infile\nOr: datadec -m infile\n"
#define MUSTBE(b) {if(!(b)){fprintf(stderr, USAGEMSG);exit(1);}}
#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 )
...@@ -57,6 +62,7 @@ int main( int argc, char **argv ) ...@@ -57,6 +62,7 @@ int main( int argc, char **argv )
NEED_ANOTHER_ARG; NEED_ANOTHER_ARG;
verbose = false; opt = true; verbose = false; opt = true;
metaonly = false;
while( *(s=argv[arg]) == '-' ) while( *(s=argv[arg]) == '-' )
{ {
for( s++; *s; s++ ) for( s++; *s; s++ )
...@@ -75,9 +81,13 @@ int main( int argc, char **argv ) ...@@ -75,9 +81,13 @@ int main( int argc, char **argv )
case 'o': case 'o':
opt = true; opt = true;
break; break;
case 'm':
metaonly = true;
break;
default: default:
fprintf( stderr, fprintf( stderr,
"datadec: illegal option -%c\n", *s ); "datadec: illegal option -%c\n", *s );
MUSTBE(false);
exit(1); exit(1);
} }
} }
...@@ -85,14 +95,18 @@ int main( int argc, char **argv ) ...@@ -85,14 +95,18 @@ int main( int argc, char **argv )
NEED_ANOTHER_ARG; NEED_ANOTHER_ARG;
} }
basename = argv[arg++]; if( ! metaonly )
len = strlen( basename );
if( !strcmp( basename+len-2, ".c" ) )
{ {
basename[len-2] = '\0'; basename = argv[arg++];
len = strlen( basename );
if( !strcmp( basename+len-2, ".c" ) )
{
basename[len-2] = '\0';
}
} }
if( IS_ANOTHER_ARG ) { NEED_ANOTHER_ARG;
//if( IS_ANOTHER_ARG ) {
lexfile = fopen( argv[arg], "r" ); lexfile = fopen( argv[arg], "r" );
if( lexfile == NULL ) if( lexfile == NULL )
{ {
...@@ -101,9 +115,9 @@ int main( int argc, char **argv ) ...@@ -101,9 +115,9 @@ int main( int argc, char **argv )
exit(1); exit(1);
} }
arg++; arg++;
} else { //} else {
lexfile = stdin; // lexfile = stdin;
} //}
REQUIRE_NO_MORE_ARGS; REQUIRE_NO_MORE_ARGS;
...@@ -121,7 +135,13 @@ int main( int argc, char **argv ) ...@@ -121,7 +135,13 @@ int main( int argc, char **argv )
printf( "begin = {%s}\n", begin ); printf( "begin = {%s}\n", begin );
} }
optimize( declns ); optimize( declns );
make_declns( exports, globals, begin, declns, basename ); if( ! metaonly )
{
make_declns( exports, globals, begin, declns, basename );
} else
{
make_metadata( declns );
}
exit(0); exit(0);
/*NOTREACHED*/ /*NOTREACHED*/
} }
...@@ -12,7 +12,6 @@ bool makefree = false; ...@@ -12,7 +12,6 @@ bool makefree = false;
static void literalline( char * mesg ); static void literalline( char * mesg );
static void h_declns( char * base, char * exports, bool init, declnlist d ); static void h_declns( char * base, char * exports, bool init, declnlist d );
static void c_declns( char * base, char * globals, char * begin, declnlist d ); static void c_declns( char * base, char * globals, char * begin, declnlist d );
static void dd_declns( char * base, declnlist d );
static void ddtypes( declnlist d ); static void ddtypes( declnlist d );
static void ddoneshape( decln d, shapelist s ); static void ddoneshape( decln d, shapelist s );
static void data_decls( declnlist decs ); static void data_decls( declnlist decs );
...@@ -81,7 +80,6 @@ void make_declns( char *exports, char *globals, char *begin, declnlist d, char * ...@@ -81,7 +80,6 @@ void make_declns( char *exports, char *globals, char *begin, declnlist d, char *
printf( "datadec: Making data declarations in %s.[ch]\n", base ); printf( "datadec: Making data declarations in %s.[ch]\n", base );
h_declns( base, exports, *begin != '\0', d ); h_declns( base, exports, *begin != '\0', d );
c_declns( base, globals, begin, d ); c_declns( base, globals, begin, d );
dd_declns( base, d );
} }
...@@ -220,24 +218,10 @@ static void c_declns( char *base, char *globals, char *begin, declnlist d ) ...@@ -220,24 +218,10 @@ static void c_declns( char *base, char *globals, char *begin, declnlist d )
} }
static void dd_declns( char *base, declnlist d ) void make_metadata( declnlist d )
{ {
char tempname[256]; usefile( stdout );
FILE *file;
sprintf( tempname, ".%s.dd", base );
file = fopen( tempname, "w" );
if( file == NULL )
{
fprintf( stderr, "datadec: can't create '%s'\n", tempname );
exit(1);
}
usefile( file );
ddtypes( d ); ddtypes( d );
fclose( file );
} }
......
extern bool makefree; extern bool makefree;
extern void make_declns( char * , char * , char * , declnlist , char * ); extern void make_declns( char * exports, char * globals, char * begin, declnlist d, char * base );
extern void make_metadata( declnlist d );
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include "optimize.h" #include "optimize.h"
bool opt; /* opt == perform optimizations */ bool opt; /* opt == perform optimizations */
bool verbose; /* verbose == be verbose - diagnostics */ bool verbose; /* verbose == be verbose - diagnostics */
bool metaonly; /* metaonly == ONLY generate the meta-data on output */
static void optimize_decln( decln ); static void optimize_decln( decln );
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
extern bool opt; /* perform optimizations */ extern bool opt; /* perform optimizations */
extern bool verbose; /* be verbose */ extern bool verbose; /* be verbose */
extern bool metaonly; /* ONLY generate the meta-data on output */
extern void optimize( declnlist ); extern void optimize( declnlist );
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