14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License, Version 1.0 only
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (the "License"). You may not use this file except in compliance
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#pragma ident "%Z%%M% %I% %E% SMI"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * DTrace Parsing Control Block
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * A DTrace Parsing Control Block (PCB) contains all of the state that is used
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * by a single pass of the D compiler, other than the global variables used by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * lex and yacc. The routines in this file are used to set up and tear down
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * PCBs, which are kept on a stack pointed to by the libdtrace global 'yypcb'.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The main engine of the compiler, dt_compile(), is located in dt_cc.c and is
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * responsible for calling these routines to begin and end a compilation pass.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Sun's lex/yacc are not MT-safe or re-entrant, but we permit limited nested
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * use of dt_compile() once the entire parse tree has been constructed but has
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * not yet executed the "cooking" pass (see dt_cc.c for more information). The
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * PCB design also makes it easier to debug (since all global state is kept in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * one place) and could permit us to make the D compiler MT-safe or re-entrant
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * in the future by adding locks to libdtrace or switching to Flex and Bison.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Initialize the specified PCB by zeroing it and filling in a few default
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * members, and then pushing it on to the top of the PCB stack and setting
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * yypcb to point to it. Increment the current handle's generation count.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Since lex/yacc are not re-entrant and we don't implement state save,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * assert that if another PCB is active, it is from the same handle and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * has completed execution of yyparse(). If the first assertion fires,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the caller is calling libdtrace without proper MT locking. If the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * second assertion fires, dt_compile() is being called recursively
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * from an illegal location in libdtrace, or a dt_pcb_pop() is missing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dt_idstack_push(&pcb->pcb_globals, dtp->dt_globals);
2fc831009973ba4f02b68bfccfd69fa85d8f522bvboxsync#ifndef USING_FLEX /* In case flex starts work too early. Moved to dt_compile. */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncdt_pcb_pop_ident(dt_idhash_t *dhp, dt_ident_t *idp, void *arg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Pop the topmost PCB from the PCB stack and destroy any data structures that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * are associated with it. If 'err' is non-zero, destroy any intermediate
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * state that is left behind as part of a compilation that has failed.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (err != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (dxp = dt_list_next(&dtp->dt_xlators); dxp; dxp = nxp) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (pvp = dt_list_next(&dtp->dt_provlist); pvp; pvp = nvp) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_aggs, dt_pcb_pop_ident, dtp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) dt_idhash_iter(dtp->dt_globals, dt_pcb_pop_ident, dtp);