v6502
The MOS 6502 Virtual Machine and Toolchain Infrastructure
symbols.h
Go to the documentation of this file.
1 
4 /*
5  * Copyright (c) 2013 Daniel Loffgren
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to
9  * deal in the Software without restriction, including without limitation the
10  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25 
26 #ifndef as6502_symbols_h
27 #define as6502_symbols_h
28 
29 #include <stdint.h>
30 
31 #include <as6502/token.h>
32 
36 #define as6502_symbolTypeIsLinked(_type) (_type == as6502_symbol_type_label || _type == as6502_symbol_type_variable)
37 
38 #define as6502_symbolTypeIsLabel(_type) (_type == as6502_symbol_type_label || _type == as6502_symbol_type_label_unlinked)
39 
40 #define as6502_symbolTypeIsVariable(_type) (_type == as6502_symbol_type_variable || _type == as6502_symbol_type_variable_unlinked)
41 
46 typedef enum {
47  as6502_symbol_type_unknown = 0,
48  as6502_symbol_type_label = 2,
49  as6502_symbol_type_variable = 3,
50  as6502_symbol_type_label_unlinked = 4,
51  as6502_symbol_type_variable_unlinked = 5
53 
56 typedef struct _as6502_symbol {
58  struct _as6502_symbol *next;
60  unsigned long line;
62  char *name;
64  uint16_t address;
68 
71 typedef struct {
75 
85 void as6502_printSymbolScript(as6502_symbol_table *table, FILE *out);
95 uint16_t as6502_addressForSymbolByName(as6502_symbol_table *table, const char *name);
97 void as6502_addSymbolToTable(as6502_symbol_table *table, unsigned long line, const char *name, uint16_t address, as6502_symbol_type type);
101 void as6502_truncateTableToAddressSpace(as6502_symbol_table *table, uint16_t start, uint16_t len);
114 as6502_token *as6502_desymbolicateExpression(as6502_symbol_table *table, as6502_token *head, uint16_t offset, int caseSensitive);
115 
122 void as6502_symbolicateLine(as6502_symbol_table *table, char *line, size_t len, uint16_t offset);
128 void as6502_replaceSymbolInLineAtLocationWithText(char *line, size_t len, char *loc, const char * restrict symbol, const char * restrict text);
133 #endif
void as6502_printSymbolScript(as6502_symbol_table *table, FILE *out)
Generates a debugger script containing all of the commands necessary for loading the symbol table gen...
Definition: symbols.c:63
void as6502_replaceSymbolInLineAtLocationWithText(char *line, size_t len, char *loc, const char *restrict symbol, const char *restrict text)
Convenience function to replace a given string in another string, with its location already specified...
Definition: symbols.c:242
An individual token which will often be a part of a linked list of tokens.
Definition: token.h:41
void as6502_printSymbolTable(as6502_symbol_table *table)
Prints a human readable representation of a as6502_symbol_table for debugging.
Definition: symbols.c:82
as6502_token * as6502_desymbolicateExpression(as6502_symbol_table *table, as6502_token *head, uint16_t offset, int caseSensitive)
Automatically detects symbols in a given line, then dereferences them and replaces them with their ac...
Definition: symbols.c:281
void as6502_destroySymbolTable(as6502_symbol_table *table)
Destroys a symbol table object.
Definition: symbols.c:48
void as6502_symbolicateLine(as6502_symbol_table *table, char *line, size_t len, uint16_t offset)
Searches for addresses in a given line and replaces them with their symbols in a given symbol table...
Definition: symbols.c:371
An individual symbol in a symbol table.
Definition: symbols.h:56
as6502_symbol_table * as6502_createSymbolTable(void)
Creates a new symbol table object.
Definition: symbols.c:44
void as6502_truncateTableToAddressSpace(as6502_symbol_table *table, uint16_t start, uint16_t len)
Remove all as6502_symbol&#39;s that lie outside the address region specified.
Definition: symbols.c:219
as6502_symbol * as6502_symbolForString(as6502_symbol_table *table, const char *name)
Finds a as6502_symbol in a given as6502_symbol_table by name.
Definition: symbols.c:118
as6502_symbol_type type
The symbol type.
Definition: symbols.h:66
void as6502_addSymbolToTable(as6502_symbol_table *table, unsigned long line, const char *name, uint16_t address, as6502_symbol_type type)
Creates and adds a as6502_symbol to a as6502_symbol_table.
Definition: symbols.c:154
as6502_symbol * as6502_symbolForAddress(as6502_symbol_table *table, uint16_t address)
Finds a as6502_symbol in a given as6502_symbol_table by address.
Definition: symbols.c:130
uint16_t address
The symbol&#39;s address.
Definition: symbols.h:64
char * name
The symbol name.
Definition: symbols.h:62
int as6502_symbolShouldBeReplacedDoubleWidth(as6502_token *instruction)
This indicates if a symbol following an instruction should be replaced with a relative or absolute ad...
Definition: symbols.c:270
The assembler&#39;s per-object symbol table structure, which holds all symbols.
Definition: symbols.h:71
struct _as6502_symbol * next
The next variable in the linked list.
Definition: symbols.h:58
void as6502_removeSymbolFromTable(as6502_symbol_table *table, as6502_symbol *symbol)
Removes a as6502_symbol from a as6502_symbol_table.
Definition: symbols.c:205
uint16_t as6502_addressForSymbolByName(as6502_symbol_table *table, const char *name)
Looks up a symbol by name to retrieve its address.
Definition: symbols.c:142
as6502_symbol * first_symbol
The head of the linked list of labels.
Definition: symbols.h:73
Tokenization functionality.
unsigned long line
The line number of the symbol in the source file.
Definition: symbols.h:60
as6502_symbol_type
as6502_symbol Type
Definition: symbols.h:46