minor fixes
[ia32rtools.git] / tools / cvt_hdr.c
CommitLineData
53b50c90 1/*
2 * ia32rtools
3 * header simplification -
4 * output only stack args forced to basic types
5 *
6 * (C) notaz, 2013-2015
7 *
8 * This work is licensed under the terms of 3-clause BSD license.
9 * See COPYING file in the top-level directory.
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include "my_assert.h"
17#include "my_str.h"
18#include "common.h"
19
20#include "protoparse.h"
21
22static const char *output_type(const struct parsed_type *type)
23{
24 if (type->is_float)
25 return "float";
26 else if (type->is_64bit)
27 return "__int64";
28 else if (IS(type->name, "void"))
29 return "void";
30 else
31 return "int";
32}
33
34int main(int argc, char *argv[])
35{
36 const struct parsed_proto *pp;
37 FILE *fhdr, *fout;
38 int i, a, a_out;
39
40 if (argc != 3) {
41 printf("usage:\n%s <hdr_out.h> <hdr_in.h>\n", argv[0]);
42 return 1;
43 }
44
45 hdrfn = argv[2];
46 fhdr = fopen(hdrfn, "r");
47 my_assert_not(fhdr, NULL);
48 fout = fopen(argv[1], "w");
49 my_assert_not(fout, NULL);
50
51 build_caches(fhdr);
52
53 for (i = 0; i < pp_cache_size; i++) {
54 pp = &pp_cache[i];
55 if (!pp->is_func || pp->is_fptr || pp->is_osinc)
56 continue;
57
58 if (pp->argc_reg != 0)
59 fprintf(fout, "// %d reg args\n", pp->argc_reg);
60 fprintf(fout, "%-4s ", output_type(&pp->ret_type));
61 if (!pp->is_stdcall || pp->argc_stack == 0)
62 fprintf(fout, "__cdecl ");
63 else
64 fprintf(fout, "__stdcall ");
65 fprintf(fout, "%s(", pp->name);
66
67 for (a = a_out = 0; a < pp->argc; a++) {
68 if (pp->arg[a].reg != NULL || pp->arg[a].type.is_retreg)
69 continue;
70 if (a_out++ > 0)
71 fprintf(fout, ", ");
72 fprintf(fout, "%s", output_type(&pp->arg[a].type));
73 if (pp->arg[a].type.is_64bit)
74 a++;
75 }
76 if (pp->is_vararg) {
77 if (a_out > 0)
78 fprintf(fout, ", ");
79 fprintf(fout, "...");
80 }
81 fprintf(fout, ");\n");
82 }
83
84 fclose(fhdr);
85 fclose(fout);
86 (void)proto_parse;
87
88 return 0;
89}
90
91// vim:ts=2:shiftwidth=2:expandtab