+/* Current output file. */
+extern const char *output_filename;
+
+/* Current output mode. */
+enum output_mode {
+ output_c = 0,
+ output_h = 1,
+};
+extern enum output_mode output_mode;
+
+/* Abstract syntax tree types. */
+enum type_enum {
+ type_char, type_short, type_int, type_hyper,
+ type_double,
+ type_string, type_opaque, type_bool,
+ type_ident,
+};
+
+struct type {
+ enum type_enum type;
+ int sgn; /* true if signed, false if unsigned */
+ char *ident;
+ char *len; /* length (only for strings) */
+};
+
+extern struct type *new_type (enum type_enum, int, char *, char *);
+extern void free_type (struct type *);
+
+enum decl_type {
+ decl_type_simple, /* type ident; */
+ decl_type_fixed_array, /* type ident[len]; */
+ decl_type_variable_array, /* type ident<len>; (len is optional) */
+ decl_type_pointer, /* type *ident; */
+};
+
+struct decl {
+ enum decl_type decl_type;
+ struct type *type;
+ char *ident;
+ char *len;
+};
+
+extern struct decl *new_decl (enum decl_type, struct type *, char *, char *);
+extern void free_decl (struct decl *);
+
+struct enum_value {
+ char *ident;
+ char *value;
+};
+
+extern struct enum_value *new_enum_value (char *, char *);
+extern void free_enum_value (struct enum_value *);
+
+enum union_case_type {
+ union_case_normal, /* case const: decl; */
+ union_case_default_void, /* default: void; */
+ union_case_default_decl, /* default: decl; */
+};
+
+struct union_case {
+ enum union_case_type type;
+ char *const_;
+ struct decl *decl;
+};
+
+extern struct union_case *new_union_case (enum union_case_type, char *, struct decl *);
+extern void free_union_case (struct union_case *);
+
+typedef void (*free_fn) (void *);
+
+struct cons {
+ struct cons *next; /* cdr/tail */
+ void *ptr; /* car/head */
+ free_fn free; /* free the head element */
+};
+
+extern struct cons *new_cons (struct cons *, void *, free_fn);
+extern struct cons *list_rev (struct cons *);
+extern void list_free (struct cons *);
+
+/* Code generator functions. */
+extern void gen_prologue (const char *filename);
+extern void gen_epilogue (void);
+extern void gen_const (const char *name, const char *value);
+extern void gen_enum (const char *name, const struct cons *enum_values);
+extern void gen_struct (const char *name, const struct cons *decls);
+extern void gen_union (const char *name, const struct decl *discrim, const struct cons *union_cases);
+extern void gen_typedef (const struct decl *decl);
+