Allow build with original radio driver using $make RF230BB=0
[contiki-2.x.git] / tools / mknmlist-ansi
blob7a8234686edcbe66468f9564497f6aa4eb245685
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--) { 
13       tmp = V[j];
14       V[j] = V[j - 1];
15       V[j - 1] = tmp;
16     }
17   return;
20 BEGIN {
21  ndata = ntext = 0;
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)";
37  builtin[""] =  "";
40 # DATA or TEXT (ignored)
41 /^[0123456789abcdef]+ [AVWw] / { 
42   print "/* " $1 " " $2 " " $3 " */";
45 # DATA
46 /^[0123456789abcdef]+ [BCDGRS] / { 
47   if ($3 != "sym_obj" && $3 != "sym_obj_nelts" &&
48       $3 != "sym_func" && $3 != "sym_func_nelts") {
49     data[ndata++] = $3;
50   }
53 # TEXT
54 /^[0123456789abcdef]+ [T] / { 
55   if ($3 != "sym_obj" && $3 != "sym_obj_nelts" &&
56       $3 != "sym_func" && $3 != "sym_func_nelts") {
57     text[ntext++] = $3;
58   }
61 END {
62   sort(data, ndata);
63   sort(text, ntext);
65   print "#ifdef __AVR__"
66   print "#define PROGMEM __attribute__((__progmem__))"
67   print "#else"
68   print "#define PROGMEM"
69   print "#endif"
70   print "#include \"loader/sym.h\"";
72   print "";
73   for (x = 0; x < ndata; x++) {
74     print "static const PROGMEM char __D"x"[] = \""data[x]"\";";
75   }
77   # Extern decls. Must deal with compiler builtins etc.
78   print "";
79   for (x = 0; x < ndata; x++) {
80     if (builtin[data[x]] != "")
81       print builtin[data[x]] ";";
82     else
83       print "extern int " data[x]";";
84   }
86   print "";
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] " } },";
91   print "};";
93   print "";
94   for (x = 0; x < ntext; x++) {
95     print "static const PROGMEM char __T"x"[] = \""text[x]"\";";
96   }
98   # Extern decls. Must deal with compiler builtins etc.
99   print "";
100   for (x = 0; x < ntext; x++) {
101     if (builtin[text[x]] != "")
102       print builtin[text[x]] ";";
103     else
104       print "extern int " text[x]"();";
105   }
107   print "";
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] " } },";
112   print "};";