/*
* 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 forthdebug macros as requested by the input
* template, the format of which is given below.
*
* These templates have the following elements:
*
* 1. Macro creation
*
* Given the name of a structure, union, or enum type, a forthdebug macro
* is created that will dump the members of the type. The type can be
* specified as a standalone structure, union, or enum, or it can be
* described relative to another structure or union as "type.member".
*
* By default, all struct members, union members, or enum values, as
* appropriate, will be printed. An alternate form allows specific members
* of struct or union types to be printed. Both forms must be followed by a
* blank line. In the specific-member case, an optional format specifier can
* be provided that will be used to dump the contents of the member.
* Builtins `d' and `x' can be used to dump the member in decimal or
* hexadecimal, respectively. Alternatively, a custom formatter can be
* specified.
*
* 2. Model-specific sections
*
* `model_start' / `model_end' pairs function as an #ifdef for the ctfstabs
* tool. They take, as an argument, either `ilp32' or `lp64'. If a 64-bit
* macro is being generated (if a 64-bit object file is being used), lines
* between `lp64' model pairs will be processed, but lines between `ilp32'
* pairs will be omitted. The reverse is true for 32-bit macros.
*
* 3. Literal sections
*
* Portions of the input template file enclosed within `forth_start' /
* `forth_end' pairs and between `verbatim_begin' / `verbatim_end' pairs
* will be copied as-is to the output file.
*
* 4. Comments
*
* Lines beginning with backslashes are ignored.
*
* Example:
*
* \ dump the `foo' structure
* foo
*
* \ dump the `a' and `b' members of the `bar' structure. dump member `b'
* \ in hexadecimal
* bar
* a
* b x
*
* \ dump the `big' member of the `baz' structure in 64-bit macros, and
* \ the `small' member in 32-bit macros.
* baz
* model_start lp64
* big
* model_end
* model_start ilp32
* small
* model_end
*
* \ copy `literal 1' and `literal 2' to the output file
* verbatim_begin
* literal 1
* verbatim_end
* forth_start
* literal 2
* forth_end
*
* For a more complex example, see common.fdbg.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ctf_headers.h"
#include "ctfstabs.h"
#include "forth.h"
#include "utils.h"
#include "memory.h"
static int
{
return (0);
}
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static int
{
return (0);
}
static int
fth_null_trailer(void)
{
return (0);
}
};
/*ARGSUSED2*/
static int
{
return (tid);
return (0);
}
/* find the tid of a specified member */
static ctf_id_t
{
}
/*
* Begin a macro.
*
* Once we figure out the type of the thing that we're supposed to dump (struct,
* union, or enum), we select the proper type-specific ops-vector for dumping.
*/
static int
{
/*
* First figure out what sort of type we're looking at. Life would be
* simple if we were only going to get type names, but it's not - we
* could also get `type.member'. In that case, we need to figure out
* (and dump) the type of `member' instead.
*/
for (;;) {
/* First part - the struct name */
return (parse_warn("Couldn't find %s: %s",
}
} else {
/* Second (or more) part - the member name */
return (parse_warn("%s isn't a struct/union",
lpart));
}
return (parse_warn("%s isn't a member of %s",
}
return (parse_warn("Can't get kind for %s",
part));
}
}
/*
* Stop if there aren't any more parts. We use `npart' here
* because we don't want to clobber part - we need it later.
*/
break;
}
/*
* Pick the right ops vector for dumping.
*/
switch (kind) {
case CTF_K_STRUCT:
case CTF_K_UNION:
break;
case CTF_K_ENUM:
break;
default:
}
}
static int
{
if (fth_curtype == NULL)
return (fth_section_init(name));
return (-1);
return (0);
}
static int
fth_section_end(void)
{
if (fth_curtype == NULL)
return (0);
if (fth_type_ops->fto_trailer() < 0)
return (-1);
fth_curtype = NULL;
return (0);
}
static int
{
int nblank = 0;
int n;
if (fth_section_end() < 0)
return (-1);
return (0);
} else
nblank = 0;
/* skip comments */
if (line[0] == '\\')
return (0);
fth_ignoring = 0;
return (0);
}
if (fth_ignoring == 1)
return (0);
word = "model_start ";
/* EMPTY - match */;
else
fth_ignoring = 1;
return (0);
}
"verbatim_begin" : "forth_start");
if (fth_copying == 0) {
(void) parse_warn("Found %s without matching %s",
if (fth_curtype != NULL)
(void) fth_section_end();
return (-1);
}
fth_copying = 0;
return (0);
}
if (fth_copying == 1) {
return (0);
}
if (fth_curtype != NULL) {
(void) parse_warn("Expected blank line between %s "
return (fth_section_end());
}
fth_copying = 1;
return (0);
}
if (n == 1)
else if (n == 2)
else
(void) parse_warn("Too many words");
}
}
static int
fth_fini(void)
{
return (fth_section_end());
}
};