17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26*a386cc11SRobert Mustacchi /*
27*a386cc11SRobert Mustacchi  * Copyright (c) 2013 by Delphix. All rights reserved.
28*a386cc11SRobert Mustacchi  * Copyright (c) 2013 Joyent, Inc. All rights reserved.
29*a386cc11SRobert Mustacchi  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef	_DT_DECL_H
327c478bd9Sstevel@tonic-gate #define	_DT_DECL_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <libctf.h>
367c478bd9Sstevel@tonic-gate #include <dtrace.h>
377c478bd9Sstevel@tonic-gate #include <stdio.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate struct dt_node;				/* forward declaration of dt_node_t */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef struct dt_decl {
467c478bd9Sstevel@tonic-gate 	ushort_t dd_kind;		/* declaration kind (CTF_K_* kind) */
477c478bd9Sstevel@tonic-gate 	ushort_t dd_attr;		/* attributes (DT_DA_* flags) */
487c478bd9Sstevel@tonic-gate 	ctf_file_t *dd_ctfp;		/* CTF container for decl's type */
497c478bd9Sstevel@tonic-gate 	ctf_id_t dd_type;		/* CTF identifier for decl's type */
507c478bd9Sstevel@tonic-gate 	char *dd_name;			/* string name of this decl (or NULL) */
517c478bd9Sstevel@tonic-gate 	struct dt_node *dd_node;	/* node for array size or parm list */
527c478bd9Sstevel@tonic-gate 	struct dt_decl *dd_next;	/* next declaration in list */
537c478bd9Sstevel@tonic-gate } dt_decl_t;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	DT_DA_SIGNED	0x0001		/* signed integer value */
567c478bd9Sstevel@tonic-gate #define	DT_DA_UNSIGNED	0x0002		/* unsigned integer value */
577c478bd9Sstevel@tonic-gate #define	DT_DA_SHORT	0x0004		/* short integer value */
587c478bd9Sstevel@tonic-gate #define	DT_DA_LONG	0x0008		/* long integer or double */
597c478bd9Sstevel@tonic-gate #define	DT_DA_LONGLONG	0x0010		/* long long integer value */
607c478bd9Sstevel@tonic-gate #define	DT_DA_CONST	0x0020		/* qualify type as const */
617c478bd9Sstevel@tonic-gate #define	DT_DA_RESTRICT	0x0040		/* qualify type as restrict */
627c478bd9Sstevel@tonic-gate #define	DT_DA_VOLATILE	0x0080		/* qualify type as volatile */
637c478bd9Sstevel@tonic-gate #define	DT_DA_PAREN	0x0100		/* parenthesis tag */
64*a386cc11SRobert Mustacchi #define	DT_DA_USER	0x0200		/* user-land type specifier */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate typedef enum dt_dclass {
677c478bd9Sstevel@tonic-gate 	DT_DC_DEFAULT,			/* no storage class specified */
687c478bd9Sstevel@tonic-gate 	DT_DC_AUTO,			/* automatic storage */
697c478bd9Sstevel@tonic-gate 	DT_DC_REGISTER,			/* register storage */
707c478bd9Sstevel@tonic-gate 	DT_DC_STATIC,			/* static storage */
717c478bd9Sstevel@tonic-gate 	DT_DC_EXTERN,			/* extern storage */
727c478bd9Sstevel@tonic-gate 	DT_DC_TYPEDEF,			/* type definition */
737c478bd9Sstevel@tonic-gate 	DT_DC_SELF,			/* thread-local storage */
747c478bd9Sstevel@tonic-gate 	DT_DC_THIS			/* clause-local storage */
757c478bd9Sstevel@tonic-gate } dt_dclass_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate typedef struct dt_scope {
787c478bd9Sstevel@tonic-gate 	dt_decl_t *ds_decl;		/* pointer to top of decl stack */
797c478bd9Sstevel@tonic-gate 	struct dt_scope *ds_next;	/* pointer to next scope */
807c478bd9Sstevel@tonic-gate 	char *ds_ident;			/* identifier for this scope (if any) */
817c478bd9Sstevel@tonic-gate 	ctf_file_t *ds_ctfp;		/* CTF container for this scope */
827c478bd9Sstevel@tonic-gate 	ctf_id_t ds_type;		/* CTF id of enclosing type */
837c478bd9Sstevel@tonic-gate 	dt_dclass_t ds_class;		/* declaration class for this scope */
847c478bd9Sstevel@tonic-gate 	int ds_enumval;			/* most recent enumerator value */
857c478bd9Sstevel@tonic-gate } dt_scope_t;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_alloc(ushort_t, char *);
887c478bd9Sstevel@tonic-gate extern void dt_decl_free(dt_decl_t *);
897c478bd9Sstevel@tonic-gate extern void dt_decl_reset(void);
907c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_push(dt_decl_t *);
917c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_pop(void);
927c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_pop_param(char **);
937c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_top(void);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_ident(char *);
967c478bd9Sstevel@tonic-gate extern void dt_decl_class(dt_dclass_t);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	DT_DP_VARARGS	0x1		/* permit varargs in prototype */
997c478bd9Sstevel@tonic-gate #define	DT_DP_DYNAMIC	0x2		/* permit dynamic type in prototype */
1007c478bd9Sstevel@tonic-gate #define	DT_DP_VOID	0x4		/* permit void type in prototype */
1017c478bd9Sstevel@tonic-gate #define	DT_DP_ANON	0x8		/* permit anonymous parameters */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate extern int dt_decl_prototype(struct dt_node *, struct dt_node *,
1047c478bd9Sstevel@tonic-gate     const char *, uint_t);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_spec(ushort_t, char *);
1077c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_attr(ushort_t);
1087c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_array(struct dt_node *);
1097c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_func(dt_decl_t *, struct dt_node *);
1107c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_ptr(void);
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_sou(uint_t, char *);
1137c478bd9Sstevel@tonic-gate extern void dt_decl_member(struct dt_node *);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_decl_enum(char *);
1167c478bd9Sstevel@tonic-gate extern void dt_decl_enumerator(char *, struct dt_node *);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate extern int dt_decl_type(dt_decl_t *, dtrace_typeinfo_t *);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate extern void dt_scope_create(dt_scope_t *);
1217c478bd9Sstevel@tonic-gate extern void dt_scope_destroy(dt_scope_t *);
1227c478bd9Sstevel@tonic-gate extern void dt_scope_push(ctf_file_t *, ctf_id_t);
1237c478bd9Sstevel@tonic-gate extern dt_decl_t *dt_scope_pop(void);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate #endif
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #endif	/* _DT_DECL_H */
130