comparison lwasm/symbol.c @ 344:0215a0fbf61b

Added assembly error system and additional checks for symbol syntax
author lost@starbug
date Thu, 25 Mar 2010 22:06:50 -0600
parents 7b4123dce741
children a82c55070624
comparison
equal deleted inserted replaced
343:b4157778d354 344:0215a0fbf61b
27 #include <lw_alloc.h> 27 #include <lw_alloc.h>
28 #include <lw_expr.h> 28 #include <lw_expr.h>
29 29
30 #include "lwasm.h" 30 #include "lwasm.h"
31 31
32 struct symtabe *register_symbol(asmstate_t *as, char *sym, lw_expr_t val, int flags) 32 // these are allowed chars BELOW 0x80
33 #define SSYMCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@$"
34 #define SYMCHARS SSYMCHARS ".?0123456789"
35
36 struct symtabe *register_symbol(asmstate_t *as, line_t *cl, char *sym, lw_expr_t val, int flags)
33 { 37 {
34 struct symtabe *se; 38 struct symtabe *se;
35 int islocal = 0; 39 int islocal = 0;
36 int context = -1; 40 int context = -1;
37 int version = -1; 41 int version = -1;
42 char *cp;
38 43
39 if (strchr(sym, '@') || strchr(sym, '?')) 44 if (*sym < 0x80 && !strchr(SSYMCHARS, *sym))
40 islocal = 1; 45 {
41 if (!(as -> pragmas & PRAGMA_DOLLARNOTLOCAL) && strchr(sym, '$')) 46 lwasm_register_error(as, cl, "Bad symbol (%s)", sym);
42 islocal = 1; 47 return NULL;
48 }
49
50 if ((*sym == '$' || *sym == '@') && (sym[1] >= '0' && sym[1] <= '9'))
51 {
52 lwasm_register_error(as, cl, "Bad symbol (%s)", sym);
53 return NULL;
54 }
55
56 for (cp = sym; *cp; cp++)
57 {
58 if (*cp == '@' || *cp == '?')
59 islocal = 1;
60 if (*cp == '$' && !(as -> pragmas & PRAGMA_DOLLARNOTLOCAL))
61 islocal = 1;
62
63 // bad symbol
64 if (*cp < 0x80 && !strchr(SYMCHARS, *cp))
65 {
66 lwasm_register_error(as, cl, "Bad symbol (%s)", sym);
67 return NULL;
68 }
69 }
43 70
44 if (islocal) 71 if (islocal)
45 context = as -> context; 72 context = as -> context;
46 73
47 // first, look up symbol to see if it is already defined 74 // first, look up symbol to see if it is already defined
61 } 88 }
62 } 89 }
63 if (se) 90 if (se)
64 { 91 {
65 // multiply defined symbol 92 // multiply defined symbol
93 lwasm_register_error(as, cl, "Multiply defined symbol (%s)", sym);
66 return NULL; 94 return NULL;
67 } 95 }
68 96
69 if (flags & symbol_flag_set) 97 if (flags & symbol_flag_set)
70 { 98 {
79 se -> flags = flags; 107 se -> flags = flags;
80 se -> value = lw_expr_copy(val); 108 se -> value = lw_expr_copy(val);
81 return se; 109 return se;
82 } 110 }
83 111
84 struct symtabe * lookup_symbol(asmstate_t *as, char *sym, int context, int version) 112 struct symtabe * lookup_symbol(asmstate_t *as, line_t *cl, char *sym, int context, int version)
85 { 113 {
86 return NULL; 114 return NULL;
87 } 115 }