Port the SB128 code to AROS.
[AROS.git] / tools / genmodule / writefd.c
blob04cb29fb30dc518de50a5dc7f0c9874c9415e01d
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Write the functionlist to a FD file for identify.library.
6 */
8 #include "genmodule.h"
10 static void write_fd_func(FILE *out, struct functionhead *funclistit, unsigned int lvo)
12 struct functionarg *arglistit;
13 char *variable;
15 if (funclistit->lvo > lvo + 1)
17 if (funclistit->lvo == lvo + 2)
18 fprintf(out, "private()()\n");
19 else
20 fprintf(out, "##bias %u\n", (funclistit->lvo - 1) * 6);
23 fprintf(out, "%s(", funclistit->name);
25 for (arglistit = funclistit->arguments;
26 arglistit!=NULL;
27 arglistit = arglistit->next)
29 /* Print a , separator when not the first function argument */
30 if (arglistit != funclistit->arguments)
31 fprintf(out, ",");
33 /* Print only variable name */
34 variable = arglistit->arg + strlen(arglistit->arg) - 1;
35 while ((variable >= arglistit->arg) &&
36 (isalnum(*variable) || (*variable == '_')))
38 variable--;
40 fprintf(out, "%s", variable + 1);
42 fprintf(out, ")(");
45 void writefd(struct config *cfg)
47 FILE *out;
48 char line[256];
49 struct functionhead *funclistit;
50 struct functionarg *arglistit;
51 unsigned int lvo;
52 char *lower;
54 if (!cfg->funclist)
55 return;
57 snprintf(line, 255, "%s/%s_lib.fd", cfg->gendir, cfg->modulename);
59 out = fopen(line, "w");
61 if (out == NULL)
63 perror(line);
64 exit(20);
66 else
68 fprintf(out, "##base _%s\n", cfg->libbase);
70 if (cfg->modtype == DEVICE)
72 /* because of BeginIO/EndIO */
73 /* FIXME: do we need special handling for other module types, too? */
74 fprintf(out, "##bias %u\n", (cfg->firstlvo - 2) * 6);
76 else
78 fprintf(out, "##bias %u\n", cfg->firstlvo * 6);
81 fprintf(out, "*\n"
82 "* Automatically generated from '%s'.\n"
83 "* Edits will be lost. This file is supposed to be a support file for identify.library.\n"
84 "*\n",
85 cfg->conffile
88 fprintf(out, "##public\n");
90 for (funclistit = cfg->funclist, lvo = cfg->firstlvo - 1;
91 funclistit != NULL;
92 funclistit = funclistit->next
95 switch (funclistit->libcall)
97 case REGISTERMACRO:
98 write_fd_func(out, funclistit, lvo);
100 for (arglistit = funclistit->arguments;
101 arglistit != NULL;
102 arglistit = arglistit->next
105 /* Print a , separator when not the first function argument */
106 if (arglistit != funclistit->arguments)
107 fprintf(out, ",");
109 /* Print register name in lower case */
110 for (lower = arglistit->reg; *lower != '\0'; lower++)
112 fputc(tolower(*lower), out);
115 fprintf(out, ")\n");
117 lvo = funclistit->lvo;
118 break;
120 case STACK:
121 write_fd_func(out, funclistit, lvo);
122 /* TODO: Currently all SYSV ABI vectors are base-less */
123 fprintf(out, "sysv)\n");
124 lvo = funclistit->lvo;
125 break;
129 fprintf(out, "##end\n");
131 if (ferror(out))
133 perror(line);
134 exit(20);
137 fclose(out);