/* 
 *------------------------------------------------------------------
 * node.c - the api generator's semantic back-end
 *
 * Copyright (c) 2004-2009 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <vppinfra/vec.h>
#include <vppinfra/hash.h>

#include "lex.h"
#include "node.h"

#define YYSTYPE void *

FILE *ofp;
FILE *javafp;
FILE *jnifp;
FILE *pythonfp;
char *java_class;
time_t starttime;
char *vlib_app_name;
char *input_filename;
node_vft_t *the_vft[NODE_N_TYPES];
static int indent;
static int dont_output_version;
int dump_tree;
static char *fixed_name;
static char tmpbuf [MAXNAME];
static char *current_def_name;
static char *current_union_name;
static char *current_type_fmt;
static char *current_type_cast;
static char current_id;
static char current_is_complex;
static char *current_endianfun;
static char *current_type_name;
static int current_java_parameter_number;
static int current_java_emitted_parameter;
static int current_java_parameter_need_comma_space;
void *current_java_methodfun;
void *current_java_jnifun;

void indent_me(FILE *ofp)
{
    int i;

    for (i = 0; i < indent; i++)
        putc(' ', ofp);
}

char *uppercase (char *s)
{
    char *cp;

    cp = tmpbuf;

    while (*s && (cp < tmpbuf + (sizeof(tmpbuf)-1))) {
        if (*s >= 'a' && *s <= 'z')
            *cp++ = *s++ - ('a' - 'A');
        else
            *cp++ = *s++;
    }
    *cp = 0;
    return(tmpbuf);
}

char *lowercase (char *s)
{
    char *cp;

    cp = tmpbuf;

    while (*s && (cp < tmpbuf + (sizeof(tmpbuf)-1))) {
        if (*s >= 'A' && *s <= 'Z')
            *cp++ = *s++ + ('a' - 'A');
        else
            *cp++ = *s++;
    }
    *cp = 0;
    return(tmpbuf);
}

/* 
 * javah maps foo_bar to foo_1bar for whatever freakin' reason
 * So, adjust java names accordingly.
 */
char *java_name_mangle (void * name_arg)
{
    char * name = name_arg;
    static u8 * s;
    int i;

    vec_reset_length (s);

    s = format (s, "%s%c", name, 0);

    for (i = 0; i < vec_len(s); i++)
        if (s[i] == '_') {
            vec_delete (s, 1, i);
            if (s[i] >= 'a' && s[i] <= 'z')
                s[i] -= ('a' - 'A');
        }
    vec_add1 (s, 0);
    
    return ((char *) s);
}

void primtype_recursive_print(node_t *this, i8 *fmt)
{
    fputs((char *)fmt, stdout);

    if (this->deeper) {
        node_vft_t *vftp = the_vft[this->deeper->type];
        vftp->print(this->deeper);
    }
}

void primtype_recursive_generate(node_t *this, enum passid which, FILE *ofp,
                                 i8 *type_name, i8 *type_fmt, i8 *type_cast)
{
    node_vft_t *vftp;

    current_type_name = (char *)type_name;
    current_type_cast = (char *)type_cast;

    switch(which) {
    case TYPEDEF_PASS:
        fputs((char *)type_name, ofp);
        fputs(" ", ofp);
        break;

    case PRINTFUN_PASS:
        current_type_fmt = (char *)type_fmt;
        break;

    case ENDIANFUN_PASS:
        vftp = the_vft[this->type];
        current_endianfun = vftp->endian_converter;
        break;

    case JAVA_METHOD_PASS:
        vftp = the_vft[this->type];
        current_java_methodfun = vftp->java_method_function;
        break;

    case PYTHON_PASS:
        fputs("('", pythonfp);
        fputs((char *)type_name, pythonfp);
        fputs("', ", pythonfp);
        break;

    default:
        fprintf(stderr, "primtype_recursive_generate: unimp pass %d\n", which);
        break;
    }

    if (this->deeper) {
        vftp = the_vft[this->deeper->type];
        vftp->generate(this->deeper, which, ofp);
    }
}

static int hidden_from_java(const node_t * deeper)
{
    if (current_java_parameter_number++ < 3) {
        if (!strncmp ((char *)(deeper->data[0]), "client_index", 12))
            return 1;
        else if (!strncmp ((char *)(deeper->data[0]), "context", 7))
            return 1;
        else if (!strncmp ((char *)(deeper->data[0]), "_vl_msg_id", 10))
            return 1;
    }

    return 0;
}

void primtype_java_method (node_t * this, enum passid which, FILE *ofp, 
                           char *java_type_name)
{
    node_t * deeper;

    deeper = this->deeper;

    /* We'll take care of _msg_id, client_index, and context ourselves */
    if (hidden_from_java(deeper)) {
        return;
    }

    if (deeper->type == NODE_SCALAR)
        fprintf (ofp, "%s %s", java_type_name, 
                 java_name_mangle(deeper->data[0]));
    else
        fprintf (ofp, "%s [] %s", java_type_name, 
                 java_name_mangle(deeper->data[0]));

    current_java_emitted_parameter = 1;
}

void primtype_java_parameter (node_t * this, enum passid which, FILE *ofp, 
                              char *java_type_name)
{
    node_t * deeper;

    deeper = this->deeper;

    /* We'll take care of _msg_id, client_index, and context ourselves */
    if (hidden_from_java(deeper)) {
        return;
    }
    if (current_java_parameter_need_comma_space) {
        current_java_parameter_need_comma_space = 0;
        fputs (", ", ofp);
    }

    if (deeper->type == NODE_SCALAR)
        fprintf (ofp, "%s %s", java_type_name, (char *)(deeper->data[0]));
    else
        fprintf (ofp, "%sArray %s", java_type_name, (char *)(deeper->data[0]));

    current_java_emitted_parameter = 1;
}

void primtype_java_setup (node_t * this, enum passid which, FILE *ofp, 
                          char *java_type_name, char *array_element_name)
{
    node_t * deeper;

    deeper = this->deeper;

    /* We'll take care of _msg_id, client_index, and context ourselves */
    if (hidden_from_java(deeper)) {
        return;
    }

    if (deeper->type == NODE_VECTOR) {
        indent_me(ofp);
        fprintf (ofp, 
                 "%s * %sP = (*env)->Get%sArrayElements (env, %s, NULL);\n",
                 java_type_name, (char *)(deeper->data[0]),
                 array_element_name, (char *)(deeper->data[0]));
    }
                 
    current_java_emitted_parameter = 1;
}

void primtype_java_code (node_t * this, enum passid which, FILE *ofp, 
                         char *java_type_name, char * swapper)
{
    node_t * deeper;
    char * s;

    deeper = this->deeper;

    /* We'll take care of _msg_id, client_index, and context ourselves */
    if (hidden_from_java(deeper)) {
        return;
    }

    indent_me(ofp);

    s = (char *)(deeper->data[0]);

    if (swapper == 0) {
        if (deeper->type == NODE_VECTOR)
            fprintf (ofp, "memcpy (mp->%s, %sP, sizeof (mp->%s));\n",
                     s, s, s);
        else
            fprintf (ofp, "mp->%s = %s;\n", s, s);
    } else {
        if (deeper->type == NODE_VECTOR) {
            fprintf(ofp, "{\n");
            indent += 4;
            indent_me(ofp);
            fprintf(ofp, "int _i;\n");
            indent_me(ofp);
            fprintf(ofp, "for (_i = 0; _i < %lu; _i++) {\n",
                    (u64)(deeper->data[1]));
            indent += 4;
            indent_me(ofp);
            fprintf(ofp, "mp->%s[_i] = %s(%sP[_i]);\n",
                    s, swapper, s);
            indent -= 4;
            indent_me(ofp);
            fprintf(ofp, "}\n");
            indent -= 4;
            indent_me(ofp);
            fprintf(ofp, "}\n");
        } else {
            fprintf (ofp, "mp->%s = %s(%s);\n", s, swapper, s);
        }
    }

    current_java_emitted_parameter = 1;
}

void primtype_java_teardown (node_t * this, enum passid which, FILE *ofp, 
                             char * array_element_name)
{
    node_t * deeper;

    deeper = this->deeper;

    /* We'll take care of _msg_id, client_index, and context ourselves */
    if (hidden_from_java(deeper)) {
        return;
    }

    if (deeper->type == NODE_VECTOR) {
        indent_me(ofp);
        fprintf (ofp, 
                 "(*env)->Release%sArrayElements (env, %s, %sP, 0);\n",
                 array_element_name, 
                 (char *)(deeper->data[0]), 
                 (char *)(deeper->data[0]));
    }

    current_java_emitted_parameter = 1;
}

void node_illegal_print (node_t *this)
{
    fprintf(stderr, "node_illegal_print called\n");
    exit(0);
}

void node_illegal_generate (node_t *this, enum passid notused, FILE *ofp)
{
    fprintf(stderr, "node_illegal_generate called\n");
    exit(0);
}

void node_illegal_java_method (node_t *this, enum passid notused, FILE *ofp)
{
    fprintf(stderr, "node_illegal_java_method called\n");
    exit(0);
}

void node_illegal_java_jni (node_t *this, enum passid notused, FILE *ofp)
{
    fprintf(stderr, "node_illegal_java_jni called\n");
    exit(0);
}

node_vft_t node_illegal_vft = {
    node_illegal_print,
    node_illegal_generate,
    "illegal",
    node_illegal_java_method,
    node_illegal_java_jni,
};

void node_u8_print (node_t *this)
{
    primtype_recursive_print(this, "u8 ");
}

void node_u8_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "u8", "%u", "(unsigned)");
}

void node_u8_java_method (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_method (this, which, ofp, "byte");
}

void node_u8_java_parameter (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_parameter (this, which, ofp, "jbyte");
}

void node_u8_java_setup (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_setup (this, which, ofp, "jbyte", "Byte");
}

void node_u8_java_code (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_code (this, which, ofp, "jbyte", 0 /* swapper */);
}

void node_u8_java_teardown (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_teardown (this, which, ofp, "Byte");
}

node_vft_t node_u8_vft = {
    node_u8_print,
    node_u8_generate,
    "", 
    node_u8_java_method,
    node_u8_java_parameter,
    node_u8_java_setup,
    node_u8_java_code,
    node_u8_java_teardown,
};

void node_u16_print (node_t *this)
{
    primtype_recursive_print(this, "u16 ");
}

void node_u16_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "u16", "%u", "(unsigned)");
}

void node_u16_java_method (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_method (this, which, ofp, "short");
}

void node_u16_java_parameter (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_parameter (this, which, ofp, "jshort");
}

void node_u16_java_setup (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_setup (this, which, ofp, "jshort", "Short");
}

void node_u16_java_code (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_code (this, which, ofp, "jshort", "clib_host_to_net_u16");
}

void node_u16_java_teardown (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_teardown (this, which, ofp, "Short");
}

node_vft_t node_u16_vft = {
    node_u16_print,
    node_u16_generate,
    "clib_net_to_host_u16",
    node_u16_java_method,
    node_u16_java_parameter,
    node_u16_java_setup,
    node_u16_java_code,
    node_u16_java_teardown,
};

void node_u32_print (node_t *this)
{
    primtype_recursive_print(this, "u32 ");
}

void node_u32_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "u32", "%u", "(unsigned)");
}

void node_u32_java_method (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_method (this, which, ofp, "int");
}

void node_u32_java_parameter (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_parameter (this, which, ofp, "jint");
}

void node_u32_java_setup (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_setup (this, which, ofp, "jint", "Int");
}

void node_u32_java_code (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_code (this, which, ofp, "jint", "clib_host_to_net_u32");
}

void node_u32_java_teardown (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_teardown (this, which, ofp, "Int");
}

node_vft_t node_u32_vft = {
    node_u32_print,
    node_u32_generate,
    "clib_net_to_host_u32",
    node_u32_java_method,
    node_u32_java_parameter,
    node_u32_java_setup,
    node_u32_java_code,
    node_u32_java_teardown,
};

void node_u64_print (node_t *this)
{
    primtype_recursive_print(this, "u64 ");
}

void node_u64_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "u64", "%llu", 
                                "(long long)");
}

void node_u64_java_method (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_method (this, which, ofp, "long");
}

void node_u64_java_parameter (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_parameter (this, which, ofp, "jlong");
}

void node_u64_java_setup (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_setup (this, which, ofp, "jlong", "Long");
}

void node_u64_java_code (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_code (this, which, ofp, "jlong", "clib_host_to_net_u64");
}

void node_u64_java_teardown (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_teardown (this, which, ofp, "Long");
}

node_vft_t node_u64_vft = {
    node_u64_print,
    node_u64_generate,
    "clib_net_to_host_u64",
    node_u64_java_method,
    node_u64_java_parameter,
    node_u64_java_setup,
    node_u64_java_code,
    node_u64_java_teardown,
};

void node_i8_print (node_t *this)
{
    primtype_recursive_print(this, "i8 ");
}

void node_i8_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "i8", "%d", "(int)");
}

node_vft_t node_i8_vft = {
    node_i8_print,
    node_i8_generate,
    "",
    node_u8_java_method,
    node_u8_java_parameter,
    node_u8_java_setup,
    node_u8_java_code,
    node_u8_java_teardown,
};

void node_i16_print (node_t *this)
{
    primtype_recursive_print(this, "i16 ");
}

void node_i16_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "i16", "%d", "(int)");
}

node_vft_t node_i16_vft = {
    node_i16_print,
    node_i16_generate,
    "clib_net_to_host_u16",
    node_u16_java_method,
    node_u16_java_parameter,
    node_u16_java_setup,
    node_u16_java_code,
    node_u16_java_teardown,
};

void node_i32_print (node_t *this)
{
    primtype_recursive_print(this, "i32 ");
}

void node_i32_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "i32", "%ld", "(long)");
}

node_vft_t node_i32_vft = {
    node_i32_print,
    node_i32_generate,
    "clib_net_to_host_u32",
    node_u32_java_method,
    node_u32_java_parameter,
    node_u32_java_setup,
    node_u32_java_code,
    node_u32_java_teardown,
};

void node_i64_print (node_t *this)
{
    primtype_recursive_print(this, "i64 ");
}

void node_i64_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "i64", "%lld", 
                                "(long long)");
}

node_vft_t node_i64_vft = {
    node_i64_print,
    node_i64_generate,
    "clib_net_to_host_u64",
    node_u64_java_method,
    node_u64_java_parameter,
    node_u64_java_setup,
    node_u64_java_code,
    node_u64_java_teardown,
};

void node_f64_print (node_t *this)
{
    primtype_recursive_print(this, "f64 ");
}

void node_f64_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "f64", "%.2f", 
                                "(double)");
}
void node_f64_java_method (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_method (this, which, ofp, "double");
}

void node_f64_java_parameter (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_parameter (this, which, ofp, "jdouble");
}

void node_f64_java_setup (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_setup (this, which, ofp, "jdouble", "Double");
}

void node_f64_java_code (node_t *this, enum passid which, FILE *ofp)
{
    /* 
     * Current API code doesn't try to endian-swap doubles
     * FP formats aren't portable yadda yadda yadda
     */
    primtype_java_code (this, which, ofp, "jdouble", 0 /* $$$ */);
}

void node_f64_java_teardown (node_t *this, enum passid which, FILE *ofp)
{
    primtype_java_teardown (this, which, ofp, "Double");
}

node_vft_t node_f64_vft = {
    node_f64_print,
    node_f64_generate,
    " ",                        /* FP numbers are sent in host byte order */
    node_f64_java_method,
    node_f64_java_parameter,
    node_f64_java_setup,
    node_f64_java_code,
    node_f64_java_teardown,
};


void node_packed_print (node_t *this)
{
    primtype_recursive_print (this, "packed ");
}

void node_packed_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "PACKED", "", "");
}

node_vft_t node_packed_vft = {
    node_packed_print,
    node_packed_generate,
    0,
};

void node_define_print (node_t *this)
{
    fprintf(stdout, "define %s {\n", CDATA0);
    if (this->deeper) {
        node_vft_t *vftp = the_vft[this->deeper->type];
        fprintf(stdout, "    ");
        vftp->print(this->deeper);
    }
    fprintf(stdout, "};\n");
}

static void emit_java_arg_declaration(node_t *child, FILE *fp) {
    current_java_parameter_number = 0;
    while (child) {
        node_vft_t *vftp = the_vft[child->type];
        current_java_emitted_parameter = 0;
        vftp->java_method_function(child, JAVA_METHOD_PASS, fp);
        child = child->peer;
        if (child && current_java_emitted_parameter)
            fputs (", ", fp);
    }
}

void node_define_generate (node_t *this, enum passid which, FILE *fp)
{
    node_t *child, *save_child;

    switch(which) {
    case TYPEDEF_PASS:
        fprintf(fp, "typedef VL_API_PACKED(struct _vl_api_%s {\n", CDATA0);
        child = this->deeper;
        indent += 4;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            indent_me(fp);
            vftp->generate(child, which, fp);
            child = child->peer;
        }
        indent -= 4;
        fprintf(fp, "}) vl_api_%s_t;\n\n", CDATA0);
        break;

    case ENDIANFUN_PASS:
    case PRINTFUN_PASS:
        child = this->deeper;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            vftp->generate(child, which, fp);
            child = child->peer;
        }
        break;

    case JAVA_METHOD_PASS:
        indent += 4;
        indent_me(fp);

        /* Generate private native declaration */
        fprintf (fp, "private static native int %s0(", java_name_mangle(CDATA0));
        emit_java_arg_declaration(this->deeper, fp);
        fputs (");\n", fp);

        /* Generate public Java method */
        indent_me(fp);
        fprintf (fp, "public final int %s(", java_name_mangle(CDATA0));
        emit_java_arg_declaration(this->deeper, fp);
        fputs (") {\n", fp);

        indent += 4;
        indent_me(fp);
        fputs ("checkConnected();\n", fp);
        indent_me(fp);
        fprintf (fp, "return %s.%s0(", java_class, java_name_mangle(CDATA0));

        child = this->deeper;
        current_java_parameter_number = 0;
        while (child && hidden_from_java(child->deeper)) {
            child = child->peer;
        }
        while (child) {
            fputs(java_name_mangle((char *)(child->deeper->data[0])), fp);
            child = child->peer;
            if (child)
                fputs (", ", fp);
        }

        fputs (");\n", fp);
        indent -= 4;
        indent_me(fp);
        fputs ("}\n\n", fp);
        indent -= 4;
        break;

    case JAVA_JNI_PASS:
        /* Generate function prototype */
        fprintf (fp, "JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_%s_%s0\n", 
                 java_class, java_name_mangle(CDATA0));

        fprintf (fp, "(JNIEnv * env, jclass clazz");
        current_java_parameter_need_comma_space = 1;
        child = this->deeper;
        save_child = child;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            current_java_emitted_parameter = 0;
            vftp->java_jni_parameter(child, which, fp);
            child = child->peer;
            if (child && current_java_emitted_parameter)
                fputs (", ", fp);
        }
        fprintf (fp, ")\n{\n");
        indent += 4;

        /* define the api message pointer */
        indent_me(fp);
        fprintf (fp, "vppjni_main_t *jm = &vppjni_main;\n");
        indent_me(fp);
        fprintf (fp, "vl_api_%s_t * mp;\n", current_def_name);
        indent_me(fp);
        fprintf (fp, "u32 my_context_id;\n");
        indent_me(fp);
        fprintf (fp, "int rv;\n");

        indent_me(fp);
        fprintf (fp, "rv = vppjni_sanity_check (jm);\n");
        indent_me(fp);
        fprintf (fp, "if (rv) return rv;\n");

        indent_me(fp);
        fprintf (fp, "my_context_id = vppjni_get_context_id (jm);\n");

        /* Generate array setups, if any */
        child = save_child;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            current_java_parameter_number = 0;
            current_java_emitted_parameter = 0;
            vftp->java_jni_setup(child, which, fp);
            child = child->peer;
        }

        /* Setup the API message */
        indent_me(fp);
        fprintf (fp, "M(%s, %s);\n", uppercase(current_def_name),
                 current_def_name);
        indent_me(fp);
        fprintf (fp, "mp->context = clib_host_to_net_u32 (my_context_id);\n");
        /* $$$ Set up context hash table or some such... */

        /* Generate code */
        child = save_child;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            current_java_parameter_number = 0;
            current_java_emitted_parameter = 0;
            vftp->java_jni_code(child, which, fp);
            child = child->peer;
        }

        /* Generate array teardowns */
        child = save_child;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            current_java_parameter_number = 0;
            current_java_emitted_parameter = 0;
            vftp->java_jni_teardown(child, which, fp);
            child = child->peer;
        }

        /* Send the message, return context_id */
        indent_me (fp);
        fprintf (fp, "S;\n");
        indent_me (fp);
        fprintf (fp, "return my_context_id;\n");
        
        indent -= 4;
        fprintf (fp, "}\n\n");
        break;

    case PYTHON_PASS:
      fprintf(fp, "('%s',\n", CDATA0);
        child = this->deeper;
        indent += 4;
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            indent_me(fp);
            vftp->generate(child, which, fp);
            child = child->peer;
        }
        indent -= 4;
        fprintf(fp, "),\n\n");
        break;

    default:
        fprintf(stderr, "node_define_generate: unimp pass %d\n", which);
        break;
    }
}

node_vft_t node_define_vft = {
    node_define_print,
    node_define_generate,
    0,
};

void node_union_print (node_t *this)
{
    primtype_recursive_print (this, "union ");
}

void node_union_generate (node_t *this, enum passid which, FILE *fp)
{
    node_t *child;
    node_t *uelem;
    int case_id=1;

    switch(which) {
    case TYPEDEF_PASS:
        fprintf(fp, "u8 _%s_which;\n", CDATA0);
        indent_me(fp);
        fprintf(fp, "union _%s {\n", CDATA0);
        child = this->deeper;
        indent += 4;
    
        while (child) {
            node_vft_t *vftp = the_vft[child->type];
            indent_me(fp);
            vftp->generate(child, which, fp);
            child = child->peer;
        }
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "} %s;\n", CDATA0);
        break;

    case PRINTFUN_PASS:
    case ENDIANFUN_PASS:
        uelem = this->deeper;
        
        indent_me(fp);
        fprintf(fp, "switch(a->_%s_which) {\n",
                CDATA0);
        indent += 4;
        current_union_name = CDATA0;

        /* Walk the list of objects in this union */
        while (uelem) {
            node_vft_t *vftp = the_vft[uelem->type];
            indent -= 4;
            indent_me(fp);
            fprintf(fp, "case %d:\n", case_id);
            case_id++;
            indent += 4;
            /* Drill down on each element */
            vftp->generate(uelem, which, fp);
            indent_me(fp);
            fprintf(fp, "break;\n");
            uelem = uelem->peer;
        }
        current_union_name = 0;
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "default:\n");
        indent += 4;
        indent_me(fp);                 
        if (which == PRINTFUN_PASS) {
            fprintf(fp, 
                    "vl_print(handle, \"WARNING: _%s_which not set.\\n\");\n",
                    CDATA0);
        }
        indent_me(fp);
        fprintf(fp, "break;\n");
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "}\n");
        break;

    default:
        fprintf(stderr, "node_union_generate: unimp pass %d\n", which);
        break;
    }
}


node_vft_t node_union_vft = {
    node_union_print,
    node_union_generate,
    0,
};

void node_scalar_print (node_t *this)
{
    fprintf(stdout, "%s", CDATA0);
    primtype_recursive_print (this, "");
}

void node_scalar_generate (node_t *this, enum passid which, FILE *fp)
{
    char *union_prefix = "";

    if (current_union_name) {
        sprintf(tmpbuf, "%s.", current_union_name);
        union_prefix = tmpbuf;
    }

    switch(which) {
    case TYPEDEF_PASS:
        fprintf(fp, "%s;\n", CDATA0);
        break;

    case PRINTFUN_PASS:
        indent_me(fp);
        if (current_is_complex) {
            fprintf(fp, "vl_api_%s_t_print(a->%s%s, handle);\n", 
                    current_type_name, union_prefix, CDATA0);
        } else {
            if (!strcmp(current_type_fmt, "uword")) {
                fprintf(fp, 
           "vl_print(handle, \"%s%s: \" _uword_fmt \"\\n\", %s a->%s%s);\n", 
                        union_prefix, CDATA0, "(_uword_cast)",
                        union_prefix, CDATA0);
            } else {
                fprintf(fp, 
                        "vl_print(handle, \"%s%s: %s\\n\", %s a->%s%s);\n", 
                        union_prefix, CDATA0, 
                        current_type_fmt, current_type_cast,
                        union_prefix, CDATA0);
            }
        }
        break;

    case ENDIANFUN_PASS:
        indent_me(fp);
        if (current_is_complex) {
            fprintf(fp, "vl_api%s_t_endian(a->%s%s);\n", 
                    current_type_name, union_prefix, CDATA0);
        } else {
            /* Current_endianfun == NULL means e.g. it's a u8... */
            if (current_endianfun) {
                fprintf(fp, "a->%s%s = %s(a->%s%s);\n", union_prefix,
                        CDATA0, current_endianfun, 
                        union_prefix, CDATA0);
            } else {
                fprintf(fp, "/* a->%s%s = a->%s%s */\n",
                        union_prefix, CDATA0, 
                        union_prefix, CDATA0);
            }
        }
        break;
    case PYTHON_PASS:
        fprintf(fp, "'%s'),\n", CDATA0);
        break;

    default:
        fprintf(stderr, "node_scalar_generate: unimp pass %d\n", which);
    }
    if (this->deeper) {
        fprintf(stderr, "broken recursion in node_scalar_generate\n");
    }
}


node_vft_t node_scalar_vft = {
    node_scalar_print,
    node_scalar_generate,
    0,
};

void node_vector_print (node_t *this)
{
    primtype_recursive_print (this, "vector ");
}

void node_vector_generate (node_t *this, enum passid which, FILE *fp)
{
    char *union_prefix = "";

    if (current_union_name) {
        sprintf(tmpbuf, "%s.", current_union_name);
        union_prefix = tmpbuf;
    }

    switch(which) {
    case TYPEDEF_PASS:
        fprintf(fp, "%s[%d];\n", CDATA0, IDATA1);
        break;

    case PRINTFUN_PASS:
        /* Don't bother about "u8 data [0];" et al. */
        if (IDATA1 == 0)
            break;

        indent_me(fp);
        fprintf(fp, "{\n");
        indent += 4;
        indent_me(fp);
        fprintf(fp, "int _i;\n");
        indent_me(fp);
        fprintf(fp, "for (_i = 0; _i < %d; _i++) {\n", 
                IDATA1);
        indent += 4;
        indent_me(fp);
        if (current_is_complex) {
            fprintf(fp, "vl_print(handle, \"%s%s[%%d]: ",
                    union_prefix, CDATA0);
            fprintf(fp, 
                    "vl_print_%s (handle, a->%s%s[_i]);\n", 
                    CDATA0, union_prefix, CDATA0);
        } else {
            fprintf(fp, 
         "vl_print(handle, \"%s%s[%%d]: %s\\n\", _i, a->%s%s[_i]);\n",
                    union_prefix, CDATA0, 
                    current_type_fmt, 
                    union_prefix, CDATA0);
        }
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "}\n");
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "}\n");
        break;

    case ENDIANFUN_PASS:
        /* Don't bother about "u8 data [0];" et al. */
        if (IDATA1 == 0)
            break;

        indent_me(fp);
        fprintf(fp, "{\n");
        indent += 4;
        indent_me(fp);
        fprintf(fp, "int _i;\n");
        indent_me(fp);
        fprintf(fp, "for (_i = 0; _i < %d; _i++) {\n", 
                IDATA1);
        indent += 4;
        indent_me(fp);
        if (current_is_complex) {
            fprintf(fp, 
                    "vl_api_%s_t_endian (a->%s%s[_i]);\n", 
                    current_type_name, union_prefix, CDATA0);
        } else {
            fprintf(fp, 
                    "a->%s%s[_i] = %s(a->%s%s[_i]);\n", 
                    union_prefix, CDATA0, 
                    current_endianfun, 
                    union_prefix, CDATA0);
        }
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "}\n");
        indent -= 4;
        indent_me(fp);
        fprintf(fp, "}\n");
        break;
    case PYTHON_PASS:
        fprintf(fp, "'%s', '%d'),\n", CDATA0, IDATA1);
        break;

    default:
        fprintf(stderr, "node_vector_generate: unimp pass %d\n", which);
    }
    if (this->deeper) {
        fprintf(stderr, "broken recursion in node_vector_generate\n");
    }
}

node_vft_t node_vector_vft = {
    node_vector_print,
    node_vector_generate,
    0,
};

void node_complex_print (node_t *this)
{
    primtype_recursive_print (this, "complex ");
}

void node_complex_generate (node_t *this, enum passid which, FILE *fp)
{
    node_t *deeper;
    node_vft_t *vftp;
    char *member_name = "broken!";
    char *union_prefix = "";

    if (current_union_name) {
        sprintf(tmpbuf, "%s.", current_union_name);
        union_prefix = tmpbuf;
    }

    current_is_complex++;
    
    switch(which) {
    case TYPEDEF_PASS:
        fprintf(fp, "%s ", CDATA0);
        deeper = this->deeper;
        if (deeper) {
            vftp = the_vft[deeper->type];
            vftp->generate(deeper, which, fp);
        }
        break;

    case PRINTFUN_PASS:
        deeper = this->deeper;
        while (deeper) {
            if (deeper->type == NODE_SCALAR ||
                deeper->type == NODE_VECTOR) {
                member_name = deeper->data[0];
                break;
            }
            deeper = deeper->deeper;
        }
        indent_me(fp);
        fprintf(fp, "vl_print(handle, \"%s%s ----- \\n\");\n", 
                union_prefix, member_name);
        indent_me(fp);
        fprintf(fp, "%s_print(&a->%s%s, handle);\n", 
                CDATA0, union_prefix, member_name);
        indent_me(fp);
        fprintf(fp, "vl_print(handle, \"%s%s ----- END \\n\");\n", 
                union_prefix, member_name);
        break;

    case ENDIANFUN_PASS:
        deeper = this->deeper;
        while (deeper) {
            if (deeper->type == NODE_SCALAR ||
                deeper->type == NODE_VECTOR) {
                member_name = deeper->data[0];
                break;
            }
            deeper = deeper->deeper;
        }

        indent_me(fp);
        fprintf(fp, "%s_endian(&a->%s%s);\n", 
                CDATA0, union_prefix, member_name);
        break;
    case PYTHON_PASS:
        fprintf(fp, "('%s',", CDATA0);
        deeper = this->deeper;
        if (deeper) {
            vftp = the_vft[deeper->type];
            vftp->generate(deeper, which, fp);
        }
        break;

    default:
        fprintf(stderr, "node_complex_generate unimp pass %d...\n", which);
        break;
    }
    current_is_complex--;
}

node_vft_t node_complex_vft = {
    node_complex_print,
    node_complex_generate,
    0,
};

void node_noversion_print (node_t *this)
{
    primtype_recursive_print (this, "noversion ");
}

void node_noversion_generate (node_t *this, enum passid which, FILE *ofp)
{
    fprintf(stderr, "node_noversion_generate called...\n");
}

node_vft_t node_noversion_vft = {
    node_noversion_print,
    node_noversion_generate,
    0,
};

void node_uword_print (node_t *this)
{
    primtype_recursive_print(this, "uword ");
}

void node_uword_generate (node_t *this, enum passid which, FILE *ofp)
{
    primtype_recursive_generate(this, which, ofp, "uword", "uword", "");
}

node_vft_t node_uword_vft = {
    node_uword_print,
    node_uword_generate,
    "clib_net_to_host_uword",
};

node_vft_t *the_vft[NODE_N_TYPES] = {
    &node_illegal_vft,
    &node_u8_vft,
    &node_u16_vft,
    &node_u32_vft,
    &node_u64_vft,
    &node_i8_vft,
    &node_i16_vft,
    &node_i32_vft,
    &node_i64_vft,
    &node_f64_vft,
    &node_packed_vft,
    &node_define_vft,
    &node_union_vft,
    &node_scalar_vft,
    &node_vector_vft,
    &node_complex_vft,
    &node_noversion_vft,
    &node_uword_vft,
};

void *make_node (enum node_subclass type)
{
    node_t *rv;

    rv = (node_t *) malloc (sizeof (*rv));
    if (rv == 0) {
        fprintf (stderr, "fatal: make_node out of memory\n");
        exit (1);
    }
    bzero (rv, sizeof (*rv));
    rv->type = type;
    return ((void *) rv);
}

YYSTYPE deeper (YYSTYPE arg1, YYSTYPE arg2)
{
    node_t *np1 = (node_t *) arg1;
    node_t *np2 = (node_t *) arg2;
    node_t *hook_point;
    
    hook_point = np1;

    while (hook_point->deeper)
        hook_point = hook_point->deeper;

    hook_point->deeper = np2;
    return (arg1);
}

YYSTYPE addpeer (YYSTYPE arg1, YYSTYPE arg2)
{
    node_t *np1 = (node_t *) arg1;
    node_t *np2 = (node_t *) arg2;
    node_t *hook_point;
    
    hook_point = np1;

    while (hook_point->peer)
        hook_point = hook_point->peer;

    hook_point->peer = np2;
    return (arg1);
}

/*
 * add_slist (stmt_list, stmt)
 */

YYSTYPE add_slist (YYSTYPE a1, YYSTYPE a2)
{
    if (a1 && a2)
        return (addpeer(a1, a2));
    else if(a1)
        return(a1);
    else 
        return(a2);
}

/*
 * add_define (char *name, defn_list);
 */
YYSTYPE add_define (YYSTYPE a1, YYSTYPE a2)
{
    node_t *np;

    np = make_node(NODE_DEFINE);
    np->data[0] = a1;
    deeper((YYSTYPE)np, a2);
    return ((YYSTYPE) np);
}

/*
 * add_defbody (defn_list, new_defn)
 */
YYSTYPE add_defbody (YYSTYPE a1, YYSTYPE a2)
{
    return (addpeer(a1, a2));
}

/*
 * add_primtype ([packed], primitive type, instance)
 */ 

YYSTYPE add_primtype (YYSTYPE a1, YYSTYPE a2, YYSTYPE a3)
{
    node_t *np1;

    np1 = (node_t *)a1;
    
    /* Hook instance to type node */
    deeper (a1, a2);
    if (a3) {
        deeper(a1, a3);
    }
    return (a1);
}

/*
 * add_complex(char *type_name, instance)
 */

YYSTYPE add_complex (YYSTYPE a1, YYSTYPE a2)
{
    node_t *np;

    np = make_node(NODE_COMPLEX);
    np->data[0] = (void *) a1;

    deeper((YYSTYPE)np, a2);
    return ((YYSTYPE) np);
}

/*
 * add_union(char *type_name, definition)
 */

YYSTYPE add_union (YYSTYPE a1, YYSTYPE a2)
{
    node_t *np;

    np = make_node(NODE_UNION);
    np->data[0] = (void *) a1;

    deeper((YYSTYPE)np, a2);
    return ((YYSTYPE) np);
}


/*
 * add_vector_vbl (node_t *variable, YYSTYPE size)
 */

YYSTYPE add_vector_vbl (YYSTYPE a1, YYSTYPE a2)
{
    node_t *np;

    np = make_node(NODE_VECTOR);
    np->data[0] = (void *) a1;
    np->data[1] = (void *) a2;
    return ((YYSTYPE) np);
}

/*
 * add_scalar_vbl (char *name)
 */
YYSTYPE add_scalar_vbl (YYSTYPE a1)
{
    node_t *np;

    np = make_node(NODE_SCALAR);
    np->data[0] = (void *) a1;
    return ((YYSTYPE) np);
}

/*
 * set_flags (int flags, msg(=0?))
 */ 
YYSTYPE set_flags(YYSTYPE a1, YYSTYPE a2)
{
    node_t *np;
    int flags;

    np = (node_t *)a2;
    if (!np)
        return(0);

    flags = (int)(uword) a1;

    np->flags |= flags;
    return (a2);
}
/*
 * suppress_version
 */
YYSTYPE suppress_version (void)
{
    dont_output_version = 1;
    return (0);
}

void dump(node_t *np)
{
    node_vft_t *vftp;

    while (np) {
        vftp = the_vft[np->type];
        vftp->print(np);
        np = np->peer;
    }
}

char *fixup_input_filename(void)
{
    char *cp;

    cp = (char *)input_filename;

    while (*cp)
        cp++;

    cp--;

    while (cp > input_filename && *cp != '/')
        cp--;
    if (*cp == '/')
        cp++;

    strcpy (tmpbuf, cp);

    cp = tmpbuf;

    while (*cp)
        cp++;

    cp--;

    while (cp > tmpbuf && *cp != '.')
        cp--;
    
    if (*cp == '.')
        *cp = 0;

    return (sxerox(tmpbuf));
}

void generate_top_boilerplate(FILE *fp)

{
    char *datestring = ctime(&starttime);
    fixed_name = fixup_input_filename();

    datestring[24] = 0;

    fprintf (fp, "/*\n");
    fprintf (fp, " * VLIB API definitions %s\n", datestring);
    fprintf (fp, " * Input file: %s\n", input_filename);
    fprintf (fp, " * Automatically generated: please edit the input file ");
    fprintf (fp, "NOT this file!\n");

    /* Moron Acme trigger workaround */
    fprintf (fp, " * %syright (c) %s by Cisco Systems, Inc.\n", "Cop", 
             &datestring[20]);
    fprintf (fp, " */\n\n");
    fprintf (fp, "#if defined(vl_msg_id)||defined(vl_union_id)||");
    fprintf (fp, "defined(vl_printfun) \\\n ||defined(vl_endianfun)||");
    fprintf (fp, " defined(vl_api_version)||defined(vl_typedefs) \\\n");
    fprintf (fp, " ||defined(vl_msg_name)\n");
    fprintf (fp, "/* ok, something was selected */\n");
    fprintf (fp, "#else\n");
    fprintf (fp, "#warning no content included from %s\n", input_filename);
    fprintf (fp, "#endif\n\n");
    fprintf (fp, "#define VL_API_PACKED(x) x __attribute__ ((packed))\n\n");
}

void generate_bottom_boilerplate(FILE *fp)

{
    fprintf (fp, "\n#ifdef vl_api_version\n");

    if (dont_output_version) {
        fprintf (fp, "/* WARNING: API FILE VERSION CHECK DISABLED */\n");
        input_crc = 0;
    }

    fprintf (fp, "vl_api_version(%s, 0x%08x)\n\n", 
             fixed_name, (unsigned int)input_crc);
    fprintf (fp, "#endif\n\n");
}

void generate_msg_ids(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;

    fprintf (fp, "\n/****** Message ID / handler enum ******/\n\n");
    fprintf (fp, "#ifdef vl_msg_id\n");

    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & NODE_FLAG_TYPEONLY)) {
                fprintf (fp, "vl_msg_id(VL_API_%s, vl_api_%s_t_handler)\n", 
                         uppercase(np->data[0]), (i8 *)np->data[0]);
            } else {
                fprintf (fp, "/* typeonly: %s */\n", (i8 *)np->data[0]);
            }
        }
        np = np->peer;
    }
    fprintf (fp, "#endif\n");

}

void generate_msg_names(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;

    fprintf (fp, "\n/****** Message names ******/\n\n");

    fprintf (fp, "#ifdef vl_msg_name\n");

    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & NODE_FLAG_TYPEONLY)) {
                fprintf (fp, "vl_msg_name(vl_api_%s_t, %d)\n",
                         (i8 *) np->data[0], 
                         (np->flags & NODE_FLAG_DONT_TRACE ? 0 : 1));
            } else {
                fprintf (fp, "/* typeonly: %s */\n", (i8 *)np->data[0]);
            }
        }
        np = np->peer;
    }
    fprintf (fp, "#endif\n\n");
}

void generate_typedefs(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    fprintf(fp, "\n/****** Typedefs *****/\n\n");
    fprintf(fp, "#ifdef vl_typedefs\n\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            /* Yeah, this is pedantic */
            vftp = the_vft[np->type];
            vftp->generate(np, TYPEDEF_PASS, fp);
        }
        np = np->peer;
    }
    fprintf(fp, "#endif /* vl_typedefs */\n\n");
}

void union_walk_one_defn(node_t *np, FILE *fp)
{
    node_t *vblp;
    node_t *uelem;

    /* Walk the list of typed objects in this msg def */
    while (np) {
        if (np->type == NODE_UNION) {
            current_union_name = np->data[0];
            uelem = np->deeper;

            /* Walk the list of objects in this union */
            while (uelem) {
                vblp = uelem->deeper;
                /* Drill down on each element, find the variable name */
                while(vblp) {
                    if (vblp->type == NODE_SCALAR ||
                        vblp->type == NODE_VECTOR ||
                        vblp->type == NODE_COMPLEX) {
                        fprintf(ofp, "#define %s_", 
                                uppercase(current_def_name));
                        fprintf(ofp, "%s_", uppercase(current_union_name));
                        fprintf(ofp, "%s %d\n",uppercase(vblp->data[0]),
                                current_id);
                        current_id++;
                        break;
                    }
                    vblp = vblp->deeper;
                }
                uelem = uelem->peer;
            }
            current_union_name = 0;
            current_id = 1;
        }
        np = np->peer;
    }
}

void generate_uniondefs(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;

    fprintf(fp, "/****** Discriminated Union Definitions *****/\n\n");
    fprintf(fp, "#ifdef vl_union_id\n\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            current_id = 1;
            current_def_name = np->data[0];
            union_walk_one_defn(np->deeper, fp);
        }
        np = np->peer;
    }
    fprintf(fp, "\n#endif /* vl_union_id */\n\n");
}

void generate_printfun(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    fprintf(fp, "/****** Print functions *****/\n\n");
    fprintf(fp, "#ifdef vl_printfun\n\n");

    fprintf(fp, "#ifdef LP64\n");
    fputs ("#define _uword_fmt \"%lld\"\n", fp);
    fputs ("#define _uword_cast (long long)\n", fp);
    fprintf(fp, "#else\n");
    fputs("#define _uword_fmt \"%ld\"\n", fp);
    fputs ("#define _uword_cast long\n", fp);
    fprintf(fp, "#endif\n\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & NODE_FLAG_MANUAL_PRINT)) {
                fprintf(fp, 
       "static inline void *vl_api_%s_t_print (vl_api_%s_t *a,",
                        (i8 *)np->data[0], (i8 *) np->data[0]);
                fprintf(fp, "void *handle)\n{\n");
                /* output the message name */
                fprintf(fp, 
                    "    vl_print(handle, \"vl_api_%s_t:\\n\");\n",
                        (i8 *)np->data[0]);

                indent += 4;
                /* Yeah, this is pedantic */
                vftp = the_vft[np->type];
                vftp->generate(np, PRINTFUN_PASS, fp);
                fprintf(fp, "    return handle;\n");
                fprintf(fp, "}\n\n");
                indent -= 4;
            } else {
                fprintf(fp, "/***** manual: vl_api_%s_t_print  *****/\n\n",
                        (i8 *) np->data[0]);
            }
        }
        np = np->peer;
    }
    fprintf(fp, "#endif /* vl_printfun */\n\n");
}

void generate_endianfun(YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    fprintf(fp, "\n/****** Endian swap functions *****/\n\n");
    fprintf(fp, "#ifdef vl_endianfun\n\n");
    fprintf(fp, "#undef clib_net_to_host_uword\n");
    fprintf(fp, "#ifdef LP64\n");
    fprintf(fp, "#define clib_net_to_host_uword clib_net_to_host_u64\n");
    fprintf(fp, "#else\n");
    fprintf(fp, "#define clib_net_to_host_uword clib_net_to_host_u32\n");
    fprintf(fp, "#endif\n\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & NODE_FLAG_MANUAL_ENDIAN)) {
                fprintf(fp, 
               "static inline void vl_api_%s_t_endian (vl_api_%s_t *a)\n{\n",
                        (i8 *) np->data[0], (i8 *) np->data[0]);
                indent += 4;
                /* Yeah, this is pedantic */
                vftp = the_vft[np->type];
                vftp->generate(np, ENDIANFUN_PASS, fp);
                fprintf(fp, "}\n\n");
                indent -= 4;
            } else {
                fprintf(fp, "/***** manual: vl_api_%s_t_endian  *****/\n\n",
                        (i8 *) np->data[0]);
            }
        }
        np = np->peer;
    }
    fprintf(fp, "#endif /* vl_endianfun */\n\n");
}

void add_msg_ids(YYSTYPE a1)
{
    node_t *np = (node_t *)a1;
    node_t *new_u16;
    node_t *new_vbl;

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & NODE_FLAG_TYPEONLY)) {
	        /* add the parse tree for "u16 _vl_msg_id" */
                new_u16 = make_node(NODE_U16);
                new_u16->peer = np->deeper;
                np->deeper = new_u16;
                new_vbl = make_node(NODE_SCALAR);
                new_vbl->data[0] = sxerox("_vl_msg_id");
                new_u16->deeper = new_vbl;
	    }
        }
        np = np->peer;
    }
}

void generate_java_top_boilerplate(FILE *fp)

{
    char *datestring = ctime(&starttime);
    fixed_name = fixup_input_filename();

    datestring[24] = 0;

    fprintf (fp, "/*\n");
    fprintf (fp, " * VLIB API java binding %s\n", datestring);
    fprintf (fp, " * Input file: %s\n", input_filename);
    fprintf (fp, " * Automatically generated: please edit the input file ");
    fprintf (fp, "NOT this file!\n");
    fprintf (fp, " */\n\n");

    fprintf (fp, "package org.openvpp.vppjapi;\n\n");
    fprintf (fp, "import java.io.IOException;\n\n");
    fprintf (fp, "public class %s extends vppConn {\n",
             java_class);
    fprintf (fp, "    public %s(String clientName) throws IOException {\n", java_class);
    fprintf (fp, "        super(clientName);\n");
    fprintf (fp, "    }\n\n");
}

void generate_java_bottom_boilerplate(FILE *fp)
{
    fprintf (fp, "}\n");
}


void generate_java_class_definition (YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    fprintf(fp, "/****** API methods *****/\n\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & (NODE_FLAG_MANUAL_JAVA | NODE_FLAG_TYPEONLY))) {
                /* Suppress messages named "xyz_reply" */
                char * cp = (char *) np->data[0];
                while (*cp)
                    cp++;
                cp -= 6;
                if (strncmp (cp, "_reply", 6)) {
                    current_java_parameter_number = 0;
                    vftp = the_vft[np->type];
                    vftp->generate(np, JAVA_METHOD_PASS, fp);
                }
            }
        }
        np = np->peer;
    }

    fprintf(fp, "\n/****** end of API methods *****/\n");
}

void generate_jni_reply_handler_list (YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    fprintf (fp, "#define foreach_api_reply_handler \\\n");

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & (NODE_FLAG_MANUAL_JAVA | NODE_FLAG_TYPEONLY))) {
                /* emit messages named "xyz_reply" */
                char * cp = (char *) np->data[0];
                while (*cp)
                    cp++;
                cp -= 6;
                if (!strncmp (cp, "_reply", 6)) {
                    fprintf (fp, "_(%s, %s) \\\n", 
                             uppercase(np->data[0]), (char *)(np->data[0]));
                }
            }
        }
        np = np->peer;
    }

    fprintf (fp, "\n\n");
}

char * m_macro_boilerplate =     
"#define M(T,t)                                      \\\n"
"do {                                                \\\n"
"    api_result_ready = 0;                           \\\n"
"    mp = vl_msg_api_alloc(sizeof(*mp));             \\\n"
"    memset (mp, 0, sizeof (*mp));                   \\\n"
"    mp->_vl_msg_id = ntohs (VL_API_##T);            \\\n"
"    mp->client_index = api_main.my_client_index;    \\\n"
"} while(0);\n\n"
"#define M2(T,t,n)                                   \\\n"
"do {                                                \\\n"
"    api_result_ready = 0;                           \\\n"
"    mp = vl_msg_api_alloc(sizeof(*mp)+(n));         \\\n"
"    memset (mp, 0, sizeof (*mp));                   \\\n"
"    mp->_vl_msg_id = ntohs (VL_API_##T);            \\\n"
"    mp->client_index = api_main.my_client_index;    \\\n"
"} while(0);\n\n";

char * s_macro_boilerplate = 
"#define S (vl_msg_api_send_shmem (api_main.shmem_hdr->vl_input_queue, \\\n"
"(u8 *)&mp));\n\n";

char * w_macro_boilerplate = 
"#define W                                               \\\n"
"do {                                                    \\\n"
"    timeout = clib_time_now (&clib_time) + 1.0;         \\\n"
"                                                        \\\n"
"    while (clib_time_now (&clib_time) < timeout) {      \\\n"
"        if (api_result_ready == 1) {                    \\\n"
"            return ((jint) api_result);                 \\\n"    
"        }                                               \\\n"
"    }                                                   \\\n"
"    return -99;                                         \\\n"   
"} while(0);\n\n";

void generate_jni_top_boilerplate(FILE *fp)

{
    char *datestring = ctime(&starttime);
    fixed_name = fixup_input_filename();

    datestring[24] = 0;

    fprintf (fp, "/*\n");
    fprintf (fp, " * VLIB Java native code %s\n", datestring);
    fprintf (fp, " * Input file: %s\n", input_filename);
    fprintf (fp, " * Automatically generated: please edit the input file ");
    fprintf (fp, "NOT this file!\n");
    fprintf (fp, " */\n\n");

    fprintf (fp, "#include <japi/vppjni.h>\n");

    fprintf (fp, 
             "#define vl_api_version(n,v) static u32 %s_api_version %s = v;\n",
	     vlib_app_name, "__attribute__((unused))");
    fprintf (fp, "#include <api/%s.api.h>\n", vlib_app_name);
    fprintf (fp, "#undef vl_api_version\n\n");

    fprintf (fp, "#include <japi/org_openvpp_vppjapi_vppConn.h>\n");
    fprintf (fp, "#include <japi/org_openvpp_vppjapi_%s.h>\n\n", java_class);

    fprintf (fp, "#include <api/%s_msg_enum.h>\n", vlib_app_name);
    fprintf (fp, "#define vl_typedefs /* define message structures */\n");
    fprintf (fp, "#include <api/%s_all_api_h.h> \n", vlib_app_name);
    fprintf (fp, "#undef vl_typedefs\n\n");

    fprintf (fp, "#define vl_endianfun \n");
    fprintf (fp, "#include <api/%s_all_api_h.h> \n", vlib_app_name);
    fprintf (fp, "#undef vl_endianfun\n\n");

    fprintf (fp, "#define vl_print(handle, ...)\n");
    fprintf (fp, "#define vl_printfun\n");
    fprintf (fp, "#include <api/%s_all_api_h.h>\n", vlib_app_name);
    fprintf (fp, "#undef vl_printfun\n\n");
}

void generate_jni_code (YYSTYPE a1, FILE *fp)
{
    node_t *np = (node_t *)a1;
    node_vft_t *vftp;

    /* Walk the top-level node-list */
    while (np) {
        if (np->type == NODE_DEFINE) {
            if (!(np->flags & (NODE_FLAG_MANUAL_JAVA | NODE_FLAG_TYPEONLY))) {
                /* Suppress messages named "xyz_reply" */
                char * cp = (char *) np->data[0];
                while (*cp)
                    cp++;
                cp -= 6;
                if (strncmp (cp, "_reply", 6)) {
                    current_def_name = np->data[0];
                    current_java_parameter_number = 0;
                    vftp = the_vft[np->type];
                    vftp->generate(np, JAVA_JNI_PASS, fp);
                }
            }
        }
        np = np->peer;
    }
}

char *hookup_boilerplate = 
"void vl_msg_reply_handler_hookup (void)\n"
"{\n"
"#define _(N,n)	\\\n"
"    vl_msg_api_set_handlers (VL_API_##N, #n, \\\n"
"        vl_api_generic_reply_handler, \\\n"
"        vl_noop_handler, \\\n"
"        vl_api_##n##_t_endian, \\\n"
"        vl_api_##n##_t_print, \\\n"
"        sizeof(vl_api_##n##_t), 1); \n"
"    foreach_api_reply_handler;\n"
"#undef _\n\n"
"}\n\n";
    
void generate_jni_bottom_boilerplate(FILE *fp)
{
    fputs (hookup_boilerplate, fp);
}

void generate_python (YYSTYPE a1, FILE *fp)
{
  node_t *np = (node_t *)a1;
  node_vft_t *vftp;
  fprintf (fp, "vppapidef = [\n");
  /* Walk the top-level node-list */
  while (np) {
    if (np->type == NODE_DEFINE && !(np->flags & NODE_FLAG_TYPEONLY)) {
      /* Yeah, this is pedantic */
      vftp = the_vft[np->type];
      vftp->generate(np, PYTHON_PASS, fp);
    }
    np = np->peer;
  }
  fprintf (fp, "\n]\n");
}

void generate(YYSTYPE a1)
{
    if (dump_tree) {
        dump((node_t *)a1);
    }

    add_msg_ids(a1);

    if (ofp) {
        generate_top_boilerplate(ofp);

        generate_msg_ids(a1, ofp);
        generate_msg_names(a1, ofp);
        generate_typedefs(a1, ofp);
        generate_uniondefs(a1, ofp);
        generate_printfun(a1, ofp);
        generate_endianfun(a1, ofp);
        
        generate_bottom_boilerplate(ofp);
    }

    if (javafp) {
        generate_java_top_boilerplate(javafp);
        generate_java_class_definition(a1, javafp);
        generate_java_bottom_boilerplate(javafp);
    }
    if (jnifp) {
        generate_jni_top_boilerplate(jnifp);
        generate_jni_reply_handler_list (a1, jnifp);
        generate_jni_code(a1, jnifp);
        generate_jni_bottom_boilerplate(jnifp);
    }
    if (pythonfp) {
      generate_python(a1, pythonfp);
    }
}
