+static void pp_copy_arg(struct parsed_proto_arg *d,
+ const struct parsed_proto_arg *s)
+{
+ memcpy(d, s, sizeof(*d));
+
+ if (s->reg != NULL) {
+ d->reg = strdup(s->reg);
+ my_assert_not(d->reg, NULL);
+ }
+ if (s->type.name != NULL) {
+ d->type.name = strdup(s->type.name);
+ my_assert_not(d->type.name, NULL);
+ }
+ if (s->pp != NULL) {
+ d->pp = malloc(sizeof(*d->pp));
+ my_assert_not(d->pp, NULL);
+ memcpy(d->pp, s->pp, sizeof(*d->pp));
+ }
+}
+
+struct parsed_proto *proto_clone(const struct parsed_proto *pp_c)
+{
+ struct parsed_proto *pp;
+ int i;
+
+ pp = malloc(sizeof(*pp));
+ my_assert_not(pp, NULL);
+ memcpy(pp, pp_c, sizeof(*pp)); // lazy..
+
+ // do the actual deep copy..
+ for (i = 0; i < pp_c->argc; i++)
+ pp_copy_arg(&pp->arg[i], &pp_c->arg[i]);
+ if (pp_c->ret_type.name != NULL)
+ pp->ret_type.name = strdup(pp_c->ret_type.name);
+
+ return pp;
+}
+
+
+static inline int pp_cmp_func(const struct parsed_proto *pp1,
+ const struct parsed_proto *pp2)
+{
+ int i;
+
+ if (pp1->argc != pp2->argc || pp1->argc_reg != pp2->argc_reg)
+ return 1;
+ else {
+ for (i = 0; i < pp1->argc; i++) {
+ if ((pp1->arg[i].reg != NULL) != (pp2->arg[i].reg != NULL))
+ return 1;
+
+ if ((pp1->arg[i].reg != NULL)
+ && !IS(pp1->arg[i].reg, pp2->arg[i].reg))
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static inline void pp_print(char *buf, size_t buf_size,
+ const struct parsed_proto *pp)
+{
+ size_t l;
+ int i;
+
+ snprintf(buf, buf_size, "%s %s(", pp->ret_type.name, pp->name);
+ l = strlen(buf);
+
+ for (i = 0; i < pp->argc_reg; i++) {
+ snprintf(buf + l, buf_size - l, "%s%s",
+ i == 0 ? "" : ", ", pp->arg[i].reg);
+ l = strlen(buf);
+ }
+ if (pp->argc_stack > 0) {
+ snprintf(buf + l, buf_size - l, "%s{%d stack}",
+ i == 0 ? "" : ", ", pp->argc_stack);
+ l = strlen(buf);
+ }
+ snprintf(buf + l, buf_size - l, ")");
+}
+
+static inline void proto_release(struct parsed_proto *pp)