mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Add conditional compilation to syscall autogeneration
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3452 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+45
-16
@@ -57,8 +57,9 @@
|
||||
#define MAX_PARMSIZE 128
|
||||
#define NAME_INDEX 0
|
||||
#define HEADER_INDEX 1
|
||||
#define RETTYPE_INDEX 2
|
||||
#define PARM1_INDEX 3
|
||||
#define COND_INDEX 2
|
||||
#define RETTYPE_INDEX 3
|
||||
#define PARM1_INDEX 4
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -69,6 +70,7 @@ static bool g_inline;
|
||||
static char g_line[LINESIZE+1];
|
||||
static char g_parm[MAX_FIELDS][MAX_PARMSIZE];
|
||||
static FILE *g_stubstream;
|
||||
static int g_lineno;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@@ -93,6 +95,7 @@ static char *read_line(FILE *stream)
|
||||
}
|
||||
else
|
||||
{
|
||||
g_lineno++;
|
||||
if (g_debug)
|
||||
{
|
||||
printf("Line: %s\n", g_line);
|
||||
@@ -121,7 +124,7 @@ static char *copy_parm(char *src, char *dest)
|
||||
}
|
||||
else if (*src == '\n' || *src == '\0')
|
||||
{
|
||||
fprintf(stderr, "Unexpected end of line: \"%s\"\n", start);
|
||||
fprintf(stderr, "%d: Unexpected end of line: \"%s\"\n", g_lineno, start);
|
||||
exit(4);
|
||||
}
|
||||
else
|
||||
@@ -130,7 +133,7 @@ static char *copy_parm(char *src, char *dest)
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Parameter too long: \"%s\"\n", start);
|
||||
fprintf(stderr, "%d: Parameter too long: \"%s\"\n", g_lineno, start);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
@@ -140,7 +143,7 @@ static char *find_parm(char *ptr)
|
||||
|
||||
if (*ptr != '"')
|
||||
{
|
||||
fprintf(stderr, "I'm confused: \"%s\"\n", start);
|
||||
fprintf(stderr, "%d: I'm confused: \"%s\"\n", g_lineno, start);
|
||||
exit(5);
|
||||
}
|
||||
ptr++;
|
||||
@@ -152,7 +155,7 @@ static char *find_parm(char *ptr)
|
||||
}
|
||||
else if (*ptr != ',')
|
||||
{
|
||||
fprintf(stderr, "Expected ',': \"%s\"\n", start);
|
||||
fprintf(stderr, "%d: Expected ',': \"%s\"\n", g_lineno, start);
|
||||
exit(6);
|
||||
}
|
||||
ptr++;
|
||||
@@ -160,7 +163,7 @@ static char *find_parm(char *ptr)
|
||||
ptr = skip_space(ptr);
|
||||
if (*ptr != '"')
|
||||
{
|
||||
fprintf(stderr, "Expected \": \"%s\"\n", start);
|
||||
fprintf(stderr, "%d: Expected \": \"%s\"\n", g_lineno, start);
|
||||
exit(7);
|
||||
}
|
||||
ptr++;
|
||||
@@ -180,7 +183,7 @@ static int parse_csvline(char *ptr)
|
||||
|
||||
if (*ptr != '"')
|
||||
{
|
||||
fprintf(stderr, "Bad line: \"%s\"\n", g_line);
|
||||
fprintf(stderr, "%d: Bad line: \"%s\"\n", g_lineno, g_line);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
@@ -212,7 +215,7 @@ static bool is_vararg(const char *type, int index, int nparms)
|
||||
{
|
||||
if (index != (nparms-1))
|
||||
{
|
||||
fprintf(stderr, "... is not the last in the argument list\n");
|
||||
fprintf(stderr, "%d: ... is not the last in the argument list\n", g_lineno);
|
||||
exit(11);
|
||||
}
|
||||
return true;
|
||||
@@ -323,9 +326,15 @@ static void generate_proxy(int nparms)
|
||||
/* Generate "up-front" information, include correct header files */
|
||||
|
||||
fprintf(stream, "/* Auto-generated %s proxy file -- do not edit */\n\n", g_parm[NAME_INDEX]);
|
||||
fprintf(stream, "#include <nuttx/config.h>\n");
|
||||
fprintf(stream, "#include <%s>\n", g_parm[HEADER_INDEX]);
|
||||
fprintf(stream, "#include <syscall.h>\n\n");
|
||||
|
||||
if (g_parm[COND_INDEX][0] != '\0')
|
||||
{
|
||||
fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]);
|
||||
}
|
||||
|
||||
/* Generate the function definition that matches standard function prototype */
|
||||
|
||||
fprintf(stream, "%s %s(", g_parm[RETTYPE_INDEX], g_parm[NAME_INDEX]);
|
||||
@@ -370,7 +379,12 @@ static void generate_proxy(int nparms)
|
||||
|
||||
/* Handle the tail end of the function. */
|
||||
|
||||
fprintf(stream, ");\n}\n");
|
||||
fprintf(stream, ");\n}\n\n");
|
||||
if (g_parm[COND_INDEX][0] != '\0')
|
||||
{
|
||||
fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]);
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
}
|
||||
|
||||
@@ -386,6 +400,9 @@ static FILE *open_stub(void)
|
||||
fprintf(stderr, "Failed to open STUB.h: %s\n", strerror(errno));
|
||||
exit(9);
|
||||
}
|
||||
fprintf(g_stubstream, "/* Autogenerated STUB header file */\n\n");
|
||||
fprintf(g_stubstream, "#ifndef __STUB_H\n");
|
||||
fprintf(g_stubstream, "#define __STUB_H\n\n");
|
||||
}
|
||||
|
||||
return g_stubstream;
|
||||
@@ -427,9 +444,15 @@ static void generate_stub(int nparms)
|
||||
/* Generate "up-front" information, include correct header files */
|
||||
|
||||
fprintf(stream, "/* Auto-generated %s stub file -- do not edit */\n\n", g_parm[0]);
|
||||
fprintf(stream, "#include <nuttx/config.h>\n");
|
||||
fprintf(stream, "#include <stdint.h>\n");
|
||||
fprintf(stream, "#include <%s>\n\n", g_parm[HEADER_INDEX]);
|
||||
|
||||
if (g_parm[COND_INDEX][0] != '\0')
|
||||
{
|
||||
fprintf(stream, "#if %s\n\n", g_parm[COND_INDEX]);
|
||||
}
|
||||
|
||||
/* Generate the function definition that matches standard function prototype */
|
||||
|
||||
fprintf(stream, "uintptr_t STUB_%s(", g_parm[NAME_INDEX]);
|
||||
@@ -545,17 +568,22 @@ static void generate_stub(int nparms)
|
||||
}
|
||||
}
|
||||
|
||||
/* Tail end of the function. The the proxied function has no return
|
||||
/* Tail end of the function. If the proxied function has no return
|
||||
* value, just return zero (OK).
|
||||
*/
|
||||
|
||||
if (strcmp(g_parm[RETTYPE_INDEX], "void") == 0)
|
||||
{
|
||||
fprintf(stream, ");\n return 0;\n}\n");
|
||||
fprintf(stream, ");\n return 0;\n}\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stream, ");\n}\n");
|
||||
fprintf(stream, ");\n}\n\n");
|
||||
}
|
||||
|
||||
if (g_parm[COND_INDEX][0] != '\0')
|
||||
{
|
||||
fprintf(stream, "#endif /* %s */\n", g_parm[COND_INDEX]);
|
||||
}
|
||||
stub_close(stream);
|
||||
}
|
||||
@@ -650,7 +678,7 @@ int main(int argc, char **argv, char **envp)
|
||||
/* Parse the line from the CVS file */
|
||||
|
||||
int nargs = parse_csvline(ptr);
|
||||
if (nargs < 3)
|
||||
if (nargs < PARM1_INDEX)
|
||||
{
|
||||
fprintf(stderr, "Only %d arguments found: %s\n", nargs, g_line);
|
||||
exit(8);
|
||||
@@ -658,14 +686,15 @@ int main(int argc, char **argv, char **envp)
|
||||
|
||||
if (proxies)
|
||||
{
|
||||
generate_proxy(nargs-3);
|
||||
generate_proxy(nargs - PARM1_INDEX);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_stubstream = NULL;
|
||||
generate_stub(nargs-3);
|
||||
generate_stub(nargs - PARM1_INDEX);
|
||||
if (g_stubstream != NULL)
|
||||
{
|
||||
fprintf(g_stubstream, "\n#endif /* __STUB_H */\n");
|
||||
fclose(g_stubstream);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user