#include #include #include #include #include #include "Debug.h" #include "symbol.h" /** @file symbol.c * @brief You will modify this file and implement the symbol.h interface * @details Your implementation of the functions defined in symbol.h. * You may add other functions if you find it helpful. Added functions * should be declared static to indicate they are only used * within this file. *

* @author Your name goes here */ /** size of LC3 memory */ #define LC3_MEMORY_SIZE (1 << 16) /** Provide prototype for strdup() */ char *strdup(const char *s); /** Defines the data structure used to store nodes in the hash table */ typedef struct node { struct node* next; /**< linked list of symbols at same index */ int hash; /**< hash value - makes searching faster */ symbol_t symbol; /**< the data the user is interested in */ } node_t; /** Defines the data structure for the symbol table */ struct sym_table { int size; /**< size of hash table */ node_t** hash_table; /**< array of node_t pointers */ char** addr_table; /**< array of character pointers */ }; /** djb hash - found at http://www.cse.yorku.ca/~oz/hash.html * tolower() call to make case insensitive. */ static int symbol_hash (const char* name) { unsigned char* str = (unsigned char*) name; unsigned long hash = 5381; int c; while ((c = *str++)) hash = ((hash << 5) + hash) + tolower(c); /* hash * 33 + c */ c = hash & 0x7FFFFFFF; /* keep 31 bits - avoid negative values */ return c; } /** @todo Implement this function */ sym_table_t* symbol_init (int table_size) { debug("symbol_init was called with table_size = %d", table_size); return NULL; } /** @todo Implement this function */ void symbol_add_unique (sym_table_t* symTab, const char* name, int addr) { } /** @todo Implement this function */ char* symbol_find_by_addr (sym_table_t* symTab, int addr) { return NULL; } /** @todo Implement this function */ void symbol_iterate (sym_table_t* symTab, iterate_fnc_t fnc, void* data) { } /** @todo Implement this function */ struct node* symbol_search (sym_table_t* symTab, const char* name, int* ptrToHash, int* ptrToIndex) { *ptrToHash = symbol_hash(name); return NULL; } /** @todo Implement this function */ int symbol_add (sym_table_t* symTab, const char* name, int addr) { return 0; } /** @todo Implement this function */ symbol_t* symbol_find_by_name (sym_table_t* symTab, const char* name) { return NULL; } /** @todo Implement this function */ void symbol_reset(sym_table_t* symTab) { } /** @todo Implement this function */ void symbol_term (sym_table_t* symTab) { }