genassym.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* In this mode, we generate header files containg various #defines which can
* be used to access members of various structures, and to walk through arrays.
* The input template specifies the structures and members for whom #defines
* are to be generated.
*
* The template has the following elements
*
* 1. Given the name of a structure or union, #defines can be generated that
* describe the type. If requested, #defines that give the size and the
* log2 (shift) of the structure will be generated. The latter can only
* be requested for structures whose size is a power of two.
*
* Per-member #defines are also generated. The value of these defines will
* be the offsets necessary to access the members they describe. By
* default, the name of the #define will be the name of the member, in upper
* case, but a user-supplied version can be used instead. If the member is
* an array, an extra #define will be generated that will give the increment
* needed to access individual array elements. The name of the increment
* #define will be identical to that of the member #define, but with an
* "_INCR" suffix.
*
* 2. Literal cpp directives
*
* Lines beginning with "\#" are copied directly to the output file.
*
* 3. Comments
*
* Lines beginning with backslashes (excluding the literal cpp directives
* described above) are ignored.
*
* Example input:
*
* \ Dump the `foo' structure, creating a size #define called FOO_SIZE, and a
* \ shift #define called FOO_SHIFT. `foo' has one member called `mem'.
* foo FOO_SIZE FOO_SHIFT
*
* \ Dump the `a' and `b' members of the `bar' structure. the offset
* \ #defines for these members should be `FRED' and `BOB', respectively.
* \ Both members are of type `char'
* bar
* a FRED
* b BOB
*
* Example output:
*
* #define FOO_SIZE 0x4
* #define FOO_SHIFT 0x2
* #define FRED 0x0
* #define FRED_INCR 0x1
* #define BOB 0x4
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "ctf_headers.h"
#include "utils.h"
#include "ctfstabs.h"
static int
{
char *c = line;
char *word;
int n;
while (isspace(*c))
c++;
if (n > max)
return (-1);
}
return (n - 1);
}
static int
{
char **wret[3];
int nread;
return (-1);
return (nread);
}
/*
* Valid format: typename [sizedefname [shiftdefname]]
*/
static int
{
}
/*
* Valid format: memname [offdefname]
*/
static int
{
}
/*
* and optional shift constants.
*/
static int
ga_process_name(char *line)
{
return (parse_warn("Couldn't parse name"));
return (parse_warn("Couldn't get size for type %s",
curname));
} else if (sz == 0) {
return (parse_warn("Invalid type size 0 for %s",
curname));
}
}
return (parse_warn("Can't make shift #define: %s size "
}
}
return (curtype);
}
/*
* ga_process_member() and ga_member_cb() are used to print the offset and
* possibly array increment values for a given structure member. A specific
* member is requested via ga_process_member(), and ga_member_cb() is used
* to iterate through the members of the current structure type, looking for
* that member. This is not the most efficient way to do things, but the
* lists involved are generally short.
*/
typedef struct ga_member_cb_data {
char *gmcb_memname;
char *gmcb_submem;
char *gmcb_offdef;
static int
{
char *label;
return (0);
/*
* The user requested foo.bar. We've found foo, and now need to
* recurse down to bar.
*/
}
int i;
} else
/* offsets are in bits - we need bytes */
return (parse_warn("Couldn't get array elem size"));
}
return (1);
}
static int
{
char *c;
int rc;
*c++ = NULL;
md->gmcb_submem = c;
return (parse_warn("Couldn't find member named %s",
md->gmcb_memname));
} else if (rc != 1)
return (parse_warn("Can't parse"));
return (1);
}
static int
{
ga_member_cb_data_t md = { 0 };
return (parse_warn("Couldn't parse member"));
}
static int
ga_process_line(char *line)
{
static int curtype = -1;
int nblank = 0;
curtype = -1;
if (nblank++ == 1)
return (1);
} else
nblank = 0;
if (line[0] == '\\') {
/* dump, verbatim, lines that begin with "\#" */
}
return (1);
} else if (line[0] == '#') {
return (1);
}
if (curtype == -1)
else
}
proc_ops_t ga_ops = {
NULL,
};