Mercurial > hg-old > index.cgi
diff lwasm/symbol.c @ 342:7b4123dce741
Added basic symbol registration
author | lost@starbug |
---|---|
date | Wed, 24 Mar 2010 21:30:31 -0600 |
parents | |
children | 0215a0fbf61b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/symbol.c Wed Mar 24 21:30:31 2010 -0600 @@ -0,0 +1,87 @@ +/* +symbol.c + +Copyright © 2010 William Astle + +This file is part of LWTOOLS. + +LWTOOLS is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +#include <stdlib.h> +#include <string.h> + +#include <lw_alloc.h> +#include <lw_expr.h> + +#include "lwasm.h" + +struct symtabe *register_symbol(asmstate_t *as, char *sym, lw_expr_t val, int flags) +{ + struct symtabe *se; + int islocal = 0; + int context = -1; + int version = -1; + + if (strchr(sym, '@') || strchr(sym, '?')) + islocal = 1; + if (!(as -> pragmas & PRAGMA_DOLLARNOTLOCAL) && strchr(sym, '$')) + islocal = 1; + + if (islocal) + context = as -> context; + + // first, look up symbol to see if it is already defined + for (se = as -> symtab.head; se; se = se -> next) + { + if (!strcmp(sym, se -> symbol)) + { + if (se -> context != context) + continue; + if ((flags & symbol_flag_set) && (se -> flags & symbol_flag_set)) + { + if (version < se -> version) + version = se -> version; + continue; + } + break; + } + } + if (se) + { + // multiply defined symbol + return NULL; + } + + if (flags & symbol_flag_set) + { + version++; + } + + se = lw_alloc(sizeof(struct symtabe)); + se -> next = as -> symtab.head; + as -> symtab.head = se; + se -> context = context; + se -> version = version; + se -> flags = flags; + se -> value = lw_expr_copy(val); + return se; +} + +struct symtabe * lookup_symbol(asmstate_t *as, char *sym, int context, int version) +{ + return NULL; +}