* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: reggen.l
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* ident "@(#)reggen.l 1.5 05/01/12 SMI"
#include <sys/param.h> /* for MAXPATHLEN */
#include <string.h> /* for strchr */
#include <ctype.h> /* for islower / toupper */
void strcasecpy(char * top, char * fromp);
sprintf(aliasname, "Reg_%s_%s", structnamep, yytext);
fprintf(doth,"\t%s = %d, \n", aliasname, enumidx);
fprintf(dotc,"\t{ \"%s\", Reg_%s_%s },\n", yytext, structnamep, yytext);
fprintf(doth,"\t\tReg_%s_%s = %s,\n",
structnamep, yytext, aliasname);
fprintf(dotc,"\t{ \"%s\", %s },\n", yytext, aliasname);
#.* { /* swallow comments */ }
fatal("Illegal spec text %s", yytext);
int main(int argc, char ** argv)
if (argc != 3) fatal("usage: %s <basefilename> <basestructname>\n",
if (strlen(structnamep)>MAXBUF-100) fatal("basestructname is too long!");
/* Initialise the .h and .c files */
sprintf(bufp, "%s.c", basenamep);
if (dotc == NULL) fatal("creating %s", bufp);
sprintf(bufp, "%s.h", basenamep);
if (doth == NULL) fatal("creating %s", bufp);
/* remove any earlier path ... */
bnamep = strrchr(basenamep, '/');
strcasecpy(caps, bnamep);
/* Autogenerated file - DO NOT EDIT */\n\
#include \"simcore.h\"\n\
reg_map_t %s_reg_map[]={\n",
typedef enum {\n", caps, caps);
#endif\n", structnamep, enumidx, structnamep);
return 0; /* compiler joy */
void fatal(char* fmt, ...)
if (errno!=0) perror("FATAL: "); else fprintf(stderr,"FATAL: ");
(void)vfprintf(stderr, fmt, args);
void strcasecpy(char * top, char * fromp)
*top++ = islower((unsigned)*fromp) ? toupper((unsigned)*fromp) : *fromp;
} while (*fromp++ != '\0');