home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.parl.clemson.edu
/
2015-02-07.ftp.parl.clemson.edu.tar
/
ftp.parl.clemson.edu
/
pub
/
coven
/
coven-utils-1.1.tgz
/
coven-utils-1.1.tar
/
utils
/
coven-module-parser
/
module_parser.y
< prev
next >
Wrap
Text File
|
2003-01-28
|
8KB
|
317 lines
/*
* (C) 2001 Clemson University
*
* See COPYING in top-level directory.
*/
%{
#include <module_lang.h>
#include <symbol.h>
#include <stringtbl.h>
char module_name[256];
extern FILE *yyout;
%}
%union{
int i;
double f;
char *c;
sym_ent *s;
argument_ent *a;
}
%token <i> COVEN_MODULE
%token <c> IDENTIFIER
%token <i> CONST
%token <i> INPUT
%token <i> OUTPUT
%token <i> INOUT
%token <i> STATIC
%token <i> BUFFER
%token <i> UNSIGNED
%token <i> ASTERIX
%token <i> COMMA
%token <i> LPAREN
%token <i> RPAREN
%token <i> LSBRACE
%token <c> ARRAY_END_STRING
%type <i> mod_static, mod_direction, mod_buffer, mod_unsigned, mod_star
%type <f>
%type <c> identifier, mod_type, mod_varname, mod_array
%type <s>
%type <a>
%start coven_module
%%
identifier : IDENTIFIER
{
$$ = enter_string($1);
}
;
coven_module : coven_mod_section
;
/* --------------------------------------------------------------------------*/
/* BEGIN: Coven_Module section */
/* --------------------------------------------------------------------------*/
coven_mod_section : COVEN_MODULE identifier LPAREN
{
char outstr[512];
/* save the module name for later in cleanup */
strcpy(module_name, $2);
if(header_flag) {
snprintf(outstr, 512, "module %s {",
$2);
}
else {
snprintf(outstr, 512, "COVEN_MODULE(%s, "
"_default_tph, _const_tph, _static_tph)\n{", $2);
fprintf(yyout,"/* COVEN MODULE: BEGIN */\n");
}
fprintf(yyout, "%s\n", outstr);
}
inside_mod RPAREN
{
if(header_flag) {
fprintf(yyout,"}\n");
}
}
;
inside_mod : /* empty */
| mod_decl list_of_mod_decls
;
list_of_mod_decls : /* empty */
| COMMA mod_decl list_of_mod_decls
;
mod_decl : mod_static mod_direction mod_buffer mod_unsigned
mod_type mod_star mod_varname mod_array
{
char outstr[512];
char ctype[64];
char tph[64];
int _static = $1;
int _direction = $2;
int _buffer = $3;
int _unsigned = $4;
char * _type = $5;
int _asterix = $6;
char * _varname = $7;
char * _array = $8;
int unknown_type = 0;
if(header_flag) {
fprintf(yyout,"\t");
if(_static == STATIC) fprintf(yyout,"static ");
if(_static != STATIC ||
(_static == STATIC && _buffer == BUFFER)) {
if(_direction == CONST) fprintf(yyout,"const ");
else if(_direction == INPUT)
fprintf(yyout,"input ");
else if(_direction == OUTPUT)
fprintf(yyout,"output ");
else if(_direction == INOUT)
fprintf(yyout,"inout ");
}
if(_buffer == BUFFER) fprintf(yyout,"buffer ");
else fprintf(yyout,"parameter ");
fprintf(yyout,"%s %s,\n", _type, _varname);
/* this does a "return" :) */
break;
}
/* imagine there's an else if(!header_flag) here */
if(_static == STATIC)
strcpy(tph, "_static_tph");
else
strcpy(tph, "_default_tph");
if(strcmp(_type, "int")==0) {
if(_unsigned == UNSIGNED)
strcpy(ctype, "UINT");
else
strcpy(ctype, "INT");
}
else if(strcmp(_type, "char")==0) {
if(_unsigned == UNSIGNED)
strcpy(ctype, "UCHAR");
else
strcpy(ctype, "CHAR");
}
else if(strcmp(_type, "short")==0) {
if(_unsigned == UNSIGNED)
strcpy(ctype, "USHORT");
else
strcpy(ctype, "SHORT");
}
else if(strcmp(_type, "string")==0) {
strcpy(ctype, "STRING");
strcpy(_type, "char *");
}
else if(strcmp(_type, "float")==0)
strcpy(ctype, "FLOAT");
else if(strcmp(_type, "double")==0)
strcpy(ctype, "DOUBLE");
else {
strcpy(ctype, _type);
unknown_type = 1;
}
if(_buffer == BUFFER) {
char dtype[64], bctype[128];
if(unknown_type) {
strcpy(bctype, ctype);
}
else {
snprintf(bctype, 128, "COVEN_%s_BUFFER",
ctype);
}
if(_direction == INPUT) strcpy(dtype, "INPUT");
else if(_direction == OUTPUT) strcpy(dtype,
"OUTPUT");
else if(_direction == INOUT) strcpy(dtype,
"INOUT");
if(_direction == OUTPUT) {
/* error, if it's an output buffer we
* require a size specified in the array
* field! */
if(_array == NULL) {
yyerror("output buffers require a "
"size of the buffer specified "
"with the array [ ] functionality.");
}
snprintf(outstr, 512, "%s_TYPE"
" %s = "
"COVEN_%s(%s, %s, %s, "
"\"%s\");",
bctype, _varname, dtype, tph, bctype,
_array, _varname);
fprintf(yyout," %s\n", outstr);
}
else {
snprintf(outstr, 512, "%s_TYPE"
" %s = "
"COVEN_%s(%s, %s, \"%s\");",
bctype, _varname, dtype, tph,
bctype, _varname);
fprintf(yyout," %s\n", outstr);
if(_array != NULL) {
snprintf(outstr, 512, "int %s = "
"COVEN_COUNT(%s);", _array, _varname);
fprintf(yyout," %s\n", outstr);
}
}
}
else {
if(_direction == CONST) {
snprintf(outstr, 512, "%s %s = COVEN_%s_"
"CONST(\"%s\");", _type, _varname, ctype,
_varname);
fprintf(yyout," %s\n", outstr);
}
else if(_direction == INPUT) {
snprintf(outstr, 512, "%s %s = COVEN_%s_"
"ATTRIB_GET(%s, \"%s\");", _type,
_varname, ctype, tph, _varname);
fprintf(yyout," %s\n", outstr);
}
else if(_direction == OUTPUT) {
if(_asterix != ASTERIX) {
yyerror("output types require pointer "
"'*' type.");
}
else {
snprintf(outstr, 512, "%s * %s = COVEN_"
"%s_ATTRIB_PUT(%s, \"%s\");",
_type, _varname, ctype, tph, _varname);
fprintf(yyout," %s\n", outstr);
}
}
else if(_direction == INOUT) {
if(_asterix != ASTERIX) {
yyerror("inout types require pointer "
"'*' type.");
}
else {
snprintf(outstr, 512, "%s * %s = COVEN_"
"%s_ATTRIB_GET_PTR(%s, \"%s\");",
_type, _varname, ctype, tph, _varname);
fprintf(yyout," %s\n", outstr);
}
}
}
}
;
mod_static : /* empty */ { $$ = -1; }
| STATIC
;
mod_direction : CONST
| INPUT
| OUTPUT
| INOUT
;
mod_buffer : /* empty */ { $$ = -1; }
| BUFFER
;
mod_unsigned : /* empty */ { $$ = -1; }
| UNSIGNED;
;
mod_type : identifier
;
mod_star : /* empty */ { $$ = -1; }
| ASTERIX;
;
mod_varname : identifier
;
mod_array : /* empty */ { $$ = NULL; }
| LSBRACE ARRAY_END_STRING
{
$$ = enter_string($2);
}
;
%%
yywrap()
{
return 1;
}
module_parser_done()
{
char outstr[512];
if(!header_flag) {
fprintf(yyout,"\n}\n/* COVEN MODULE: END */\n");
fprintf(yyout,"\n/* COVEN INTERFACE: BEGIN */\n");
snprintf(outstr, 512, "struct COVEN_Interface _module_interface = "
"{%s};", module_name);
fprintf(yyout,"%s\n", outstr);
fprintf(yyout,"/* COVEN INTERFACE: END*/\n");
}
}