3 # Create tables so that we can lookup ANSI C objects and functions in
4 # an object file (by reading nm output from stdin).
6 # This tool makes assumptions compatible with ANSI C. Unfortunately
7 # this implies that we need to rely on ANSI C features.
9 function sort(V, N, tmp, i, j) {
10 V[-1] = ""; # Used as a sentinel before V[0].
11 for (i = 1; i < N; i++)
12 for (j = i; V[j - 1] > V[j]; j--) {
22 builtin["sym_function"] = "sym_func_t sym_function(const char *)";
23 builtin["sym_object"] = "void *sym_object(const char *)";
25 builtin["printf"] = "int printf(const char *, ...)";
26 builtin["sprintf"] = "int sprintf(char *, const char *, ...)";
27 builtin["malloc"] = "void *malloc()";
28 builtin["memcpy"] = "void *memcpy()";
29 builtin["memset"] = "void *memset()";
30 builtin["memmove"] = "void *memmove()";
31 builtin["strcpy"] = "char *strcpy()";
33 builtin["sin"] = "double sin()";
34 builtin["cos"] = "double cos()";
35 builtin["sinf"] = "float sinf(float)";
36 builtin["cosf"] = "float cosf(float)";
40 # DATA or TEXT (ignored)
41 /^[0123456789abcdef]+ [AVWw] / {
42 print "/* " $1 " " $2 " " $3 " */";
46 /^[0123456789abcdef]+ [BCDGRS] / {
47 if ($3 != "sym_obj" && $3 != "sym_obj_nelts" &&
48 $3 != "sym_func" && $3 != "sym_func_nelts") {
54 /^[0123456789abcdef]+ [T] / {
55 if ($3 != "sym_obj" && $3 != "sym_obj_nelts" &&
56 $3 != "sym_func" && $3 != "sym_func_nelts") {
65 print "#ifdef __AVR__"
66 print "#define PROGMEM __attribute__((__progmem__))"
68 print "#define PROGMEM"
70 print "#include \"loader/sym.h\"";
73 for (x = 0; x < ndata; x++) {
74 print "static const PROGMEM char __D"x"[] = \""data[x]"\";";
77 # Extern decls. Must deal with compiler builtins etc.
79 for (x = 0; x < ndata; x++) {
80 if (builtin[data[x]] != "")
81 print builtin[data[x]] ";";
83 print "extern int " data[x]";";
87 print "const int sym_obj_nelts = " ndata ";";
88 print "PROGMEM const struct sym_bol sym_obj[" ndata "] = {";
89 for (x = 0; x < ndata; x++)
90 print " { (const char *)__D"x", { .obj = (void *)&" data[x] " } },";
94 for (x = 0; x < ntext; x++) {
95 print "static const PROGMEM char __T"x"[] = \""text[x]"\";";
98 # Extern decls. Must deal with compiler builtins etc.
100 for (x = 0; x < ntext; x++) {
101 if (builtin[text[x]] != "")
102 print builtin[text[x]] ";";
104 print "extern int " text[x]"();";
108 print "const int sym_func_nelts = " ntext ";";
109 print "PROGMEM const struct sym_bol sym_func[" ntext "] = {";
110 for (x = 0; x < ntext; x++)
111 print " { (const char *)__T"x", { .func = (sym_func_t)&" text[x] " } },";