Motr  M0
sample.ff
Go to the documentation of this file.
1 /* ff2c input file. */
2 
3 /*
4  * The following command generates ./xcode/ff2c/sample.{c,h}
5  *
6  * $ ./xcode/ff2c/ff2c ./xcode/ff2c/sample.ff
7  *
8  */
9 
10 /*
11  * C-style comments are used, blank-spaces between tokens are ignored.
12  *
13  * Semicolon is used as a _separator_, not a _terminator_. That is, various
14  * lists (fields, declarations) have a form E0 ; E1 ; ... ; EN.
15  */
16 
17 /*
18  * "require" statement introduces a dependency on other source file. For each
19  * "require", an #include directive is produced, which includes corresponding
20  * header file, "lib/vec.h" in this case
21  */
22 require "lib/vec";
23 require "fop/fop";
24 
25 /*
26  * Following in this file are type declaration statements, which all have form
27  * "type-declaration type-name".
28  */
29 
30 /* define "fid" as a RECORD type, having two U64 fields. */
31 record {
32  u64 f_container;
33  u64 f_offset
34 } fid;
35 /*
36  * Produced C declaration is:
37  * struct fid {
38  * uint64_t f_container;
39  * uint64_t f_offset;
40  * };
41  */
42 
43 /*
44  * Define "optfid" as a UNION containing a byte discriminator field (o_flag),
45  * followed either by a fid (provided o_flag's value is 1) or a U32 value
46  * o_short (provided o_flag's value is 3).
47  */
48 union {
49  u8 o_flag;
50  fid o_fid :1;
51  u32 o_short :3
52 } optfid;
53 /*
54  * Produced C declaration is:
55  *
56  * struct optfid {
57  * uint8_t o_flag;
58  * union {
59  * struct fid o_fid;
60  * uint32_t o_short;
61  * } u;
62  * };
63  */
64 
65 /* define optfidarray as a counted array of optfid instances. */
66 sequence {
67  u64 ofa_nr;
68  optfid ofa_data
69 } optfidarray;
70 /*
71  * Produced C declaration is:
72  *
73  * struct optfidarray {
74  * uint64_t ofa_nr;
75  * struct optfid *ofa_data;
76  * };
77  */
78 
79 /*
80  * define fixarray as a fixed-size array of optfids. Array size is NR, which
81  * must be defined in one of "require"-d files.
82  */
83 sequence {
84  void fa_none :NR;
85  optfid fa_data
86 } fixarray;
87 /*
88  * Produced C declaration is:
89  *
90  * struct fixarray {
91  * m0_void_t fa_none;
92  * struct optfid *fa_data;
93  * };
94  */
95 
96 /* demonstrate declaration of a more complex structure. */
97 record {
98  fid p_fid;
99 
100  /*
101  * "p_cred" is opaque field. It is represented as a pointer to struct
102  * m0_cred. The actual type of pointed object is returned by
103  * m0_package_cred_get() function.
104  */
105  *m0_cred p_cred [m0_package_cred_get];
106 
107  /*
108  * field's type can be defined in-place. ff2c generates a name of the
109  * form "parent_type"_"field_name" for such anonymous type.
110  */
111  sequence {
112  u32 s_nr;
113  record {
114  u8 e_flag;
115  fixarray e_payload;
116  record {
117  u64 d_0;
118  u64 d_1
119  } e_datum
120  } s_el
121  } p_name
122 } package;
123 /*
124  * Produced C declaration is:
125  *
126  * struct package {
127  * struct fid p_fid;
128  * struct m0_cred *p_cred;
129  * struct package_p_name {
130  * uint32_t s_nr;
131  * struct p_name_s_el {
132  * uint8_t e_flag;
133  * struct fixarray e_payload;
134  * struct s_el_e_datum {
135  * uint64_t d_0;
136  * uint64_t d_1;
137  * } e_datum;
138  * } s_el;
139  * } p_name;
140  * };
141  *
142  * And (in sample.c):
143  *
144  * int m0_package_cred_get(const struct m0_xcode_obj *par,
145  * const struct m0_xcode_type **out);
146  *
147  */
148 
149 array {
150  fid quad : NR
151 } fixfid
152 /*
153  * Produced C declaration is:
154  *
155  * struct fixfid {
156  * struct fid[NR];
157  * };
158  */