Print this page
7085 add support for "if" and "else" statements in dtrace
*** 19,30 ****
* CDDL HEADER END
*/
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, Joyent Inc. All rights reserved.
- * Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2015 Gary Mills
*/
/*
* DTrace D Language Compiler
--- 19,30 ----
* CDDL HEADER END
*/
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014 by Delphix. All rights reserved.
* Copyright (c) 2013, Joyent Inc. All rights reserved.
* Copyright 2015 Gary Mills
*/
/*
* DTrace D Language Compiler
*** 117,127 ****
};
static void *dt_compile(dtrace_hdl_t *, int, dtrace_probespec_t, void *,
uint_t, int, char *const[], FILE *, const char *);
-
/*ARGSUSED*/
static int
dt_idreset(dt_idhash_t *dhp, dt_ident_t *idp, void *ignored)
{
idp->di_flags &= ~(DT_IDFLG_REF | DT_IDFLG_MOD |
--- 117,126 ----
*** 2417,2426 ****
--- 2416,2447 ----
xyerror(D_MACRO_UNUSED, "extraneous argument '%s' ($%d is "
"not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1);
}
/*
+ * Perform sugar transformations (for "if" / "else") and replace the
+ * existing clause chain with the new one.
+ */
+ if (context == DT_CTX_DPROG) {
+ dt_node_t *dnp, *next_dnp;
+ dt_node_t *new_list = NULL;
+
+ for (dnp = yypcb->pcb_root->dn_list;
+ dnp != NULL; dnp = next_dnp) {
+ /* remove this node from the list */
+ next_dnp = dnp->dn_list;
+ dnp->dn_list = NULL;
+
+ if (dnp->dn_kind == DT_NODE_CLAUSE)
+ dnp = dt_compile_sugar(dtp, dnp);
+ /* append node to the new list */
+ new_list = dt_node_link(new_list, dnp);
+ }
+ yypcb->pcb_root->dn_list = new_list;
+ }
+
+ /*
* If we have successfully created a parse tree for a D program, loop
* over the clauses and actions and instantiate the corresponding
* libdtrace program. If we are parsing a D expression, then we
* simply run the code generator and assembler on the resulting tree.
*/
*** 2436,2445 ****
--- 2457,2468 ----
longjmp(yypcb->pcb_jmpbuf, dtrace_errno(dtp));
for (; dnp != NULL; dnp = dnp->dn_list) {
switch (dnp->dn_kind) {
case DT_NODE_CLAUSE:
+ if (DT_TREEDUMP_PASS(dtp, 4))
+ dt_printd(dnp, stderr, 0);
dt_compile_clause(dtp, dnp);
break;
case DT_NODE_XLATOR:
if (dtp->dt_xlatemode == DT_XL_DYNAMIC)
dt_compile_xlator(dnp);