41 #define out(...) fprintf(thefile, __VA_ARGS__) 45 static const char ruler[] =
"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
50 #define TOK(tok) (int)(tok)->ft_len, (int)(tok)->ft_len, (tok)->ft_val 51 #define T(term) TOK(&(term)->fn_tok) 57 if (
f->f_decl !=
NULL) {
62 out(
" %s",
f->f_name);
64 if (
f->f_parent->t_array)
65 out(
"[%s]",
f->f_tag);
74 out(
"%s {\n",
t->t_c_name);
82 for (;
f !=
NULL;
f =
f->f_next)
100 out(
"/* This file is automatically generated from %s.ff */\n\n",
102 out(
"#pragma once\n\n");
105 out(
"#ifndef __KERNEL__\n");
106 out(
"#include <sys/types.h>\n");
107 out(
"#endif /* __KERNEL__ */\n\n");
108 out(
"#include \"xcode/xcode.h\"\n\n");
110 for (
r =
ff->ff_require.l_head;
r !=
NULL;
r =
r->r_next)
111 out(
"#include %s\n",
r->r_path);
113 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next) {
120 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next) {
122 out(
"extern struct m0_xcode_type *%s;\n",
t->t_xc_name);
125 "M0_INTERNAL void m0_xc_%s_init(void);\n" 126 "M0_INTERNAL void m0_xc_%s_fini(void);\n\n", opt->
go_basename,
136 out(
"\t_%s._child[%i] = (struct m0_xcode_field) {\n" 137 "\t\t.xf_name = \"%s\",\n" 138 "\t\t.xf_type = %s,\n" 139 "\t\t.xf_tag = %s,\n" 140 "\t\t.xf_opaque = %s,\n" 141 "\t\t.xf_offset = offsetof(%s, %s)\n" 143 t->t_name,
i,
f->f_name,
f->f_xc_type,
145 f->f_escape ?:
"NULL",
146 t->t_c_name,
f->f_c_name);
154 for (
i = 0,
f =
t->t_field.l_head;
f !=
NULL;
f =
f->f_next,
i++)
160 out(
"%sstruct m0_xcode_type *%s",
161 t->t_public ?
"" :
"static ",
t->t_xc_name);
166 static const char *caggr[] = {
177 out(
"static struct _%s_s {\n" 178 "\tstruct m0_xcode_type _type;\n" 179 "\tstruct m0_xcode_field _child[%i];\n" 182 "\t\t.xct_aggr = %s,\n" 183 "\t\t.xct_name = \"%s\",\n" 184 "\t\t.xct_sizeof = sizeof (%s),\n" 188 t->t_name,
t->t_nr,
t->t_name,
189 caggr[
t->t_term->fn_head->fn_tok.ft_type],
190 t->t_name,
t->t_c_name,
t->t_nr);
192 out(
" = &_%s._type;\n" 193 "M0_BASSERT(offsetof(struct _%s_s, _child[0]) ==\n" 194 "\toffsetof(struct m0_xcode_type, xct_child[0]));\n\n",
195 t->t_name,
t->t_name);
205 out(
"/* This file is automatically generated from %s.ff */\n\n",
208 out(
"#include \"lib/misc.h\" /* offsetof */\n");
209 out(
"#include \"lib/assert.h\"\n");
210 out(
"#include \"xcode/xcode.h\"\n\n");
213 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next) {
220 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next) {
227 for (e =
ff->ff_escape.l_head; e !=
NULL; e = e->
e_next) {
228 out(
"int %s(const struct m0_xcode_obj *par,\n" 229 "\t\tconst struct m0_xcode_type **out);\n", e->
e_escape);
232 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next)
236 "M0_INTERNAL void m0_xc_%s_init(void)\n" 239 for (
t =
ff->ff_type.l_head;
t !=
NULL;
t =
t->t_next) {
244 "M0_INTERNAL void m0_xc_%s_fini(void)\n{}\n", opt->
go_basename);
static void field_def(const struct ff2c_type *t, const struct ff2c_field *f, int i)
static void type_decl(const struct ff2c_type *t)
const char * go_guardname
static int ff(struct ff2c_context *ctx, struct ff2c_term *term)
int ff2c_c_gen(const struct ff2c_ff *ff, const struct ff2c_gen_opt *opt)
static struct m0_thread t[8]
int ff2c_h_gen(const struct ff2c_ff *ff, const struct ff2c_gen_opt *opt)
static void indent(int depth)
static void type_def(const struct ff2c_type *t)
static void field_h(const struct ff2c_field *f, int depth)
static void type_h(const struct ff2c_type *t, int depth)
static void type_fields(const struct ff2c_type *t)
struct ff2c_escape * e_next