6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, Joyent Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 */
27
28 /*
29 * DTrace D Language Compiler
30 *
31 * The code in this source file implements the main engine for the D language
32 * compiler. The driver routine for the compiler is dt_compile(), below. The
33 * compiler operates on either stdio FILEs or in-memory strings as its input
34 * and can produce either dtrace_prog_t structures from a D program or a single
35 * dtrace_difo_t structure from a D expression. Multiple entry points are
36 * provided as wrappers around dt_compile() for the various input/output pairs.
37 * The compiler itself is implemented across the following source files:
38 *
39 * dt_lex.l - lex scanner
40 * dt_grammar.y - yacc grammar
41 * dt_parser.c - parse tree creation and semantic checking
42 * dt_decl.c - declaration stack processing
43 * dt_xlator.c - D translator lookup and creation
44 * dt_ident.c - identifier and symbol table routines
45 * dt_pragma.c - #pragma processing and D pragmas
2318 /* Handle /usr/lib/dtrace */
2319 dirp = dt_list_next(&dtp->dt_lib_path);
2320 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) {
2321 dtp->dt_cflags &= ~DTRACE_C_NOLIBS;
2322 return (-1); /* errno is set for us */
2323 }
2324
2325 if (dt_load_libs_sort(dtp) < 0)
2326 return (-1); /* errno is set for us */
2327
2328 return (0);
2329 }
2330
2331 static void *
2332 dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
2333 uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s)
2334 {
2335 dt_node_t *dnp;
2336 dt_decl_t *ddp;
2337 dt_pcb_t pcb;
2338 void *rv;
2339 int err;
2340
2341 if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) {
2342 (void) dt_set_errno(dtp, EINVAL);
2343 return (NULL);
2344 }
2345
2346 if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0)
2347 return (NULL); /* errno is set for us */
2348
2349 if (dtp->dt_globals->dh_nelems != 0)
2350 (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
2351
2352 if (dtp->dt_tls->dh_nelems != 0)
2353 (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
2354
2355 if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
2356 return (NULL); /* errno is set for us */
2357
2358 dt_pcb_push(dtp, &pcb);
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, Joyent Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 * Copyright 2015 Gary Mills
27 */
28
29 /*
30 * DTrace D Language Compiler
31 *
32 * The code in this source file implements the main engine for the D language
33 * compiler. The driver routine for the compiler is dt_compile(), below. The
34 * compiler operates on either stdio FILEs or in-memory strings as its input
35 * and can produce either dtrace_prog_t structures from a D program or a single
36 * dtrace_difo_t structure from a D expression. Multiple entry points are
37 * provided as wrappers around dt_compile() for the various input/output pairs.
38 * The compiler itself is implemented across the following source files:
39 *
40 * dt_lex.l - lex scanner
41 * dt_grammar.y - yacc grammar
42 * dt_parser.c - parse tree creation and semantic checking
43 * dt_decl.c - declaration stack processing
44 * dt_xlator.c - D translator lookup and creation
45 * dt_ident.c - identifier and symbol table routines
46 * dt_pragma.c - #pragma processing and D pragmas
2319 /* Handle /usr/lib/dtrace */
2320 dirp = dt_list_next(&dtp->dt_lib_path);
2321 if (dt_load_libs_dir(dtp, dirp->dir_path) != 0) {
2322 dtp->dt_cflags &= ~DTRACE_C_NOLIBS;
2323 return (-1); /* errno is set for us */
2324 }
2325
2326 if (dt_load_libs_sort(dtp) < 0)
2327 return (-1); /* errno is set for us */
2328
2329 return (0);
2330 }
2331
2332 static void *
2333 dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg,
2334 uint_t cflags, int argc, char *const argv[], FILE *fp, const char *s)
2335 {
2336 dt_node_t *dnp;
2337 dt_decl_t *ddp;
2338 dt_pcb_t pcb;
2339 void *volatile rv;
2340 int err;
2341
2342 if ((fp == NULL && s == NULL) || (cflags & ~DTRACE_C_MASK) != 0) {
2343 (void) dt_set_errno(dtp, EINVAL);
2344 return (NULL);
2345 }
2346
2347 if (dt_list_next(&dtp->dt_lib_path) != NULL && dt_load_libs(dtp) != 0)
2348 return (NULL); /* errno is set for us */
2349
2350 if (dtp->dt_globals->dh_nelems != 0)
2351 (void) dt_idhash_iter(dtp->dt_globals, dt_idreset, NULL);
2352
2353 if (dtp->dt_tls->dh_nelems != 0)
2354 (void) dt_idhash_iter(dtp->dt_tls, dt_idreset, NULL);
2355
2356 if (fp && (cflags & DTRACE_C_CPP) && (fp = dt_preproc(dtp, fp)) == NULL)
2357 return (NULL); /* errno is set for us */
2358
2359 dt_pcb_push(dtp, &pcb);
|