33
34 #include <dt_xlator.h>
35 #include <dt_parser.h>
36 #include <dt_grammar.h>
37 #include <dt_module.h>
38 #include <dt_impl.h>
39
40 /*
41 * Create a member node corresponding to one of the output members of a dynamic
42 * translator. We set the member's dn_membexpr to a DT_NODE_XLATOR node that
43 * has dn_op set to DT_TOK_XLATE and refers back to the translator itself. The
44 * code generator will then use this as the indicator for dynamic translation.
45 */
46 /*ARGSUSED*/
47 static int
48 dt_xlator_create_member(const char *name, ctf_id_t type, ulong_t off, void *arg)
49 {
50 dt_xlator_t *dxp = arg;
51 dtrace_hdl_t *dtp = dxp->dx_hdl;
52 dt_node_t *enp, *mnp;
53
54 if ((enp = dt_node_xalloc(dtp, DT_NODE_XLATOR)) == NULL)
55 return (dt_set_errno(dtp, EDT_NOMEM));
56
57 enp->dn_link = dxp->dx_nodes;
58 dxp->dx_nodes = enp;
59
60 if ((mnp = dt_node_xalloc(dtp, DT_NODE_MEMBER)) == NULL)
61 return (dt_set_errno(dtp, EDT_NOMEM));
62
63 mnp->dn_link = dxp->dx_nodes;
64 dxp->dx_nodes = mnp;
65
66 /*
67 * For the member expression, we use a DT_NODE_XLATOR/TOK_XLATE whose
68 * xlator refers back to the translator and whose dn_xmember refers to
69 * the current member. These refs will be used by dt_cg.c and dt_as.c.
70 */
71 enp->dn_op = DT_TOK_XLATE;
72 enp->dn_xlator = dxp;
73 enp->dn_xmember = mnp;
74 dt_node_type_assign(enp, dxp->dx_dst_ctfp, type, B_FALSE);
75
76 /*
77 * For the member itself, we use a DT_NODE_MEMBER as usual with the
78 * appropriate name, output type, and member expression set to 'enp'.
79 */
80 if (dxp->dx_members != NULL) {
81 assert(enp->dn_link->dn_kind == DT_NODE_MEMBER);
82 enp->dn_link->dn_list = mnp;
83 } else
84 dxp->dx_members = mnp;
85
86 mnp->dn_membname = strdup(name);
87 mnp->dn_membexpr = enp;
88 dt_node_type_assign(mnp, dxp->dx_dst_ctfp, type, B_FALSE);
89
90 if (mnp->dn_membname == NULL)
91 return (dt_set_errno(dtp, EDT_NOMEM));
92
93 return (0);
94 }
|
33
34 #include <dt_xlator.h>
35 #include <dt_parser.h>
36 #include <dt_grammar.h>
37 #include <dt_module.h>
38 #include <dt_impl.h>
39
40 /*
41 * Create a member node corresponding to one of the output members of a dynamic
42 * translator. We set the member's dn_membexpr to a DT_NODE_XLATOR node that
43 * has dn_op set to DT_TOK_XLATE and refers back to the translator itself. The
44 * code generator will then use this as the indicator for dynamic translation.
45 */
46 /*ARGSUSED*/
47 static int
48 dt_xlator_create_member(const char *name, ctf_id_t type, ulong_t off, void *arg)
49 {
50 dt_xlator_t *dxp = arg;
51 dtrace_hdl_t *dtp = dxp->dx_hdl;
52 dt_node_t *enp, *mnp;
53 ctf_file_t *ctfp;
54
55 if ((enp = dt_node_xalloc(dtp, DT_NODE_XLATOR)) == NULL)
56 return (dt_set_errno(dtp, EDT_NOMEM));
57
58 enp->dn_link = dxp->dx_nodes;
59 dxp->dx_nodes = enp;
60
61 if ((mnp = dt_node_xalloc(dtp, DT_NODE_MEMBER)) == NULL)
62 return (dt_set_errno(dtp, EDT_NOMEM));
63
64 mnp->dn_link = dxp->dx_nodes;
65 dxp->dx_nodes = mnp;
66
67 /*
68 * For the member expression, we use a DT_NODE_XLATOR/TOK_XLATE whose
69 * xlator refers back to the translator and whose dn_xmember refers to
70 * the current member. These refs will be used by dt_cg.c and dt_as.c.
71 */
72 enp->dn_op = DT_TOK_XLATE;
73 enp->dn_xlator = dxp;
74 enp->dn_xmember = mnp;
75 /*
76 * XXX: Is it ok for the CTF of the type to not be from the dst ctf?
77 *
78 * I suspect it's actually unnecessary, but I'm also unclear on
79 * dynamic translators
80 */
81 dt_resolve_forward_decl(&ctfp, &type);
82 dt_node_type_assign(enp, ctfp, type, B_FALSE);
83
84 /*
85 * For the member itself, we use a DT_NODE_MEMBER as usual with the
86 * appropriate name, output type, and member expression set to 'enp'.
87 */
88 if (dxp->dx_members != NULL) {
89 assert(enp->dn_link->dn_kind == DT_NODE_MEMBER);
90 enp->dn_link->dn_list = mnp;
91 } else
92 dxp->dx_members = mnp;
93
94 mnp->dn_membname = strdup(name);
95 mnp->dn_membexpr = enp;
96 dt_node_type_assign(mnp, dxp->dx_dst_ctfp, type, B_FALSE);
97
98 if (mnp->dn_membname == NULL)
99 return (dt_set_errno(dtp, EDT_NOMEM));
100
101 return (0);
102 }
|