+ break;
+
+ /* #pragma code [symbol] [location] */
+ case P_CODE:
+ {
+ absSym *absS;
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_STR != token.type)
+ goto code_err;
+
+ absS = Safe_calloc(1, sizeof(absSym));
+ sprintf(absS->name, "_%s", get_pragma_string(&token));
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_INT != token.type)
+ {
+ code_err:
+ //fprintf (stderr, "%s:%d: #pragma code [symbol] [location] -- symbol or location missing\n", filename, lineno);
+ err = 1;
+ break;
+ }
+ absS->address = token.val.int_val;
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_EOL != token.type)
+ {
+ err = 1;
+ break;
+ }
+
+ if ((absS->address % 2) != 0) {
+ absS->address--;
+ fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
+ filename, lineno, absS->address);
+ }
+
+ addSet(&absSymSet, absS);
+// fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
+// __FILE__, __LINE__, symname, absS->address);
+ }
+ break;
+
+ /* #pragma udata [section-name] [symbol] */
+ case P_UDATA:
+ {
+ char *sectname;
+ const char *symname;
+ symbol *nsym;
+ sectSym *ssym;
+ sectName *snam;
+ int found = 0;
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_STR == token.type)
+ sectname = Safe_strdup(get_pragma_string(&token));
+ else
+ {
+ err = 1;
+ break;
+ }
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_STR == token.type)
+ symname = get_pragma_string(&token);
+ else
+ {
+ //fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno);
+ err = 1;
+ symname = NULL;
+ }
+
+ while (symname)
+ {
+ ssym = Safe_calloc(1, sizeof(sectSym));
+ ssym->name = Safe_calloc(1, strlen(symname) + 2);
+ sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
+ ssym->reg = NULL;
+
+ addSet(§Syms, ssym);
+
+ nsym = newSymbol((char *)symname, 0);
+ strcpy(nsym->rname, ssym->name);
+
+#if 0
+ checkAddSym(&publics, nsym);
+#endif
+
+ found = 0;
+ for (snam = setFirstItem(sectNames);snam;snam=setNextItem(sectNames))
+ {
+ if (!strcmp(sectname, snam->name))
+ {
+ found=1;
+ break;
+ }
+ }
+
+ if(!found)
+ {
+ snam = Safe_calloc(1, sizeof(sectName));
+ snam->name = Safe_strdup(sectname);
+ snam->regsSet = NULL;
+
+ addSet(§Names, snam);
+ }
+
+ ssym->section = snam;
+
+#if 0
+ fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
+ ssym->name, snam->name, snam);
+#endif
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_STR == token.type)
+ symname = get_pragma_string(&token);
+ else if (TOKEN_EOL == token.type)
+ symname = NULL;
+ else
+ {
+ err = 1;
+ symname = NULL;
+ }
+ }
+
+ Safe_free(sectname);
+ }
+ break;
+
+ /* #pragma library library_module */
+ case P_LIBRARY:
+ {
+ const char *lmodule;
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_EOL != token.type)
+ {
+ lmodule = get_pragma_string(&token);
+
+ /* lmodule can be:
+ * c link the C library
+ * math link the math library
+ * io link the IO library
+ * debug link the debug libary
+ * anything else, will link as-is */
+
+ if(!strcmp(lmodule, "c"))
+ libflags.want_libc = 1;
+ else if(!strcmp(lmodule, "math"))
+ libflags.want_libm = 1;
+ else if(!strcmp(lmodule, "io"))
+ libflags.want_libio = 1;
+ else if(!strcmp(lmodule, "debug"))
+ libflags.want_libdebug = 1;
+ else if(!strcmp(lmodule, "ignore"))
+ libflags.ignore = 1;
+ else
+ {
+ if(!libflags.ignore)
+ {
+ fprintf(stderr, "link library %s\n", lmodule);
+ addSetHead(&libFilesSet, (char *)lmodule);
+ }
+ }
+ }
+ else
+ {
+ err = 1;
+ break;
+ }
+
+ cp = get_pragma_token(cp, &token);
+ if (TOKEN_EOL != token.type)
+ {
+ err = 1;
+ break;
+ }
+ }
+ break;
+
+#if 0
+ /* This is an experimental code for #pragma inline
+ and is temporarily disabled for 2.5.0 release */
+ case P_INLINE:
+ {
+ char *tmp = strtok((char *)NULL, WHITECOMMA);
+
+ while(tmp) {
+ addSet(&asmInlineMap, Safe_strdup( tmp ));
+ tmp = strtok((char *)NULL, WHITECOMMA);
+ }
+
+ {
+ char *s;
+
+ for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
+ debugf("inline asm: `%s'\n", s);
+ }
+ }
+ }
+ break;
+#endif /* 0 */
+
+ default:
+ processed = 0;
+ break;
+ }
+
+ get_pragma_token(cp, &token);
+
+ if (1 == err)
+ werror(W_BAD_PRAGMA_ARGUMENTS, name);
+
+ free_pragma_token(&token);
+ return processed;
+}
+
+static struct pragma_s pragma_tbl[] = {
+ { "maxram", P_MAXRAM, 0, do_pragma },
+ { "stack", P_STACK, 0, do_pragma },
+ { "code", P_CODE, 0, do_pragma },
+ { "udata", P_UDATA, 0, do_pragma },
+ { "library", P_LIBRARY, 0, do_pragma },
+/*{ "inline", P_INLINE, 0, do_pragma }, */
+ { NULL, 0, 0, NULL },
+ };
+
+static int
+_process_pragma(const char *s)
+{
+ return process_pragma_tbl(pragma_tbl, s);