LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Godefs takes as input a host-compilable C file that includes | 5 // Godefs takes as input a host-compilable C file that includes |
6 // standard system headers. From that input file, it generates | 6 // standard system headers. From that input file, it generates |
7 // a standalone (no #includes) C or Go file containing equivalent | 7 // a standalone (no #includes) C or Go file containing equivalent |
8 // definitions. | 8 // definitions. |
9 // | 9 // |
10 // The input C file is expected to define new types and enumerated | 10 // The input C file is expected to define new types and enumerated |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 waitpid(); | 174 waitpid(); |
175 } | 175 } |
176 | 176 |
177 void | 177 void |
178 main(int argc, char **argv) | 178 main(int argc, char **argv) |
179 { | 179 { |
180 int p[2], pid, i, j, n, off, npad, prefix; | 180 int p[2], pid, i, j, n, off, npad, prefix; |
181 char **av, *q, *r, *tofree, *name; | 181 char **av, *q, *r, *tofree, *name; |
182 char nambuf[100]; | 182 char nambuf[100]; |
183 Biobuf *bin, *bout; | 183 Biobuf *bin, *bout; |
184 » Type *t; | 184 » Type *t, *tt; |
185 Field *f; | 185 Field *f; |
186 int orig_output_fd; | 186 int orig_output_fd; |
187 | 187 |
188 quotefmtinstall(); | 188 quotefmtinstall(); |
189 | 189 |
190 oargc = argc; | 190 oargc = argc; |
191 oargv = argv; | 191 oargv = argv; |
192 av = emalloc((30+argc)*sizeof av[0]); | 192 av = emalloc((30+argc)*sizeof av[0]); |
193 atexit(waitforgcc); | 193 atexit(waitforgcc); |
194 | 194 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 Bprint(bout, lang->unionbegin, name, name, name); | 366 Bprint(bout, lang->unionbegin, name, name, name); |
367 goto StructBody; | 367 goto StructBody; |
368 case Struct: | 368 case Struct: |
369 Bprint(bout, lang->structbegin, name, name, name); | 369 Bprint(bout, lang->structbegin, name, name, name); |
370 StructBody: | 370 StructBody: |
371 prefix = 0; | 371 prefix = 0; |
372 if(lang == &go) | 372 if(lang == &go) |
373 prefix = prefixlen(t); | 373 prefix = prefixlen(t); |
374 for(j=0; j<t->nf; j++) { | 374 for(j=0; j<t->nf; j++) { |
375 f = &t->f[j]; | 375 f = &t->f[j]; |
376 » » » » if(f->type->kind == 0) | 376 » » » » if(f->type->kind == 0 && f->size <= 64 && (f->si
ze&(f->size-1)) == 0) { |
377 » » » » » continue; | 377 » » » » » // unknown type but <= 64 bits and bit s
ize is a power of two. |
| 378 » » » » » // could be enum - make Uint64 and then
let it reduce |
| 379 » » » » » tt = emalloc(sizeof *tt); |
| 380 » » » » » *tt = *f->type; |
| 381 » » » » » f->type = tt; |
| 382 » » » » » tt->kind = Uint64; |
| 383 » » » » » while(tt->kind > Uint8 && kindsize[tt->k
ind] > f->size) |
| 384 » » » » » » tt->kind -= 2; |
| 385 » » » » } |
378 // padding | 386 // padding |
379 if(t->kind == Struct || lang == &go) { | 387 if(t->kind == Struct || lang == &go) { |
380 if(f->offset%8 != 0 || f->size%8 != 0) { | 388 if(f->offset%8 != 0 || f->size%8 != 0) { |
381 fprint(2, "ignoring bitfield %s.
%s\n", t->name, f->name); | 389 fprint(2, "ignoring bitfield %s.
%s\n", t->name, f->name); |
382 continue; | 390 continue; |
383 } | 391 } |
384 if(f->offset < off) | 392 if(f->offset < off) |
385 sysfatal("%s: struct fields went
backward", t->name); | 393 sysfatal("%s: struct fields went
backward", t->name); |
386 if(off < f->offset) { | 394 if(off < f->offset) { |
387 Bprint(bout, lang->structpadfmt,
npad++, (f->offset - off) / 8); | 395 Bprint(bout, lang->structpadfmt,
npad++, (f->offset - off) / 8); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return 0; | 597 return 0; |
590 if(name == nil) { | 598 if(name == nil) { |
591 name = f->name; | 599 name = f->name; |
592 len = p+1 - name; | 600 len = p+1 - name; |
593 } | 601 } |
594 else if(strncmp(f->name, name, len) != 0) | 602 else if(strncmp(f->name, name, len) != 0) |
595 return 0; | 603 return 0; |
596 } | 604 } |
597 return len; | 605 return len; |
598 } | 606 } |
LEFT | RIGHT |