00001 /* 00002 * Copyright (C) 2005, Mike Van Emmerik 00003 * 00004 * See the file "LICENSE.TERMS" for information on usage and 00005 * redistribution of this file, and for a DISCLAIMER OF ALL 00006 * WARRANTIES. 00007 * 00008 */ 00009 00010 /*============================================================================== 00011 * FILE: SymTab.h 00012 * OVERVIEW: This file contains the definition of the class SymTab, a simple class to implement a symbol table 00013 * than can be looked up by address or my name. 00014 * NOTE: Can't readily use operator[] overloaded for address and string parameters. The main problem is 00015 * that when you do symtab[0x100] = "main", the string map doesn't see the string. 00016 * If you have one of the maps be a pointer to the other string and use a special comparison operator, then 00017 * if the strings are ever changed, then the map's internal rb-tree becomes invalid. 00018 *============================================================================*/ 00019 00020 /* 00021 * $Revision: 1.5 $ 00022 * 00023 * 12 Jul 05 - Mike: New implementation with two maps 00024 */ 00025 00026 #ifndef __SYMTAB_H__ 00027 #define __SYMTAB_H__ 00028 00029 #include "types.h" 00030 #include <map> 00031 #include <string> 00032 00033 class SymTab { 00034 // The map indexed by address. 00035 std::map<ADDRESS, std::string> amap; 00036 // The map indexed by string. Note that the strings are stored twice. 00037 std::map<std::string, ADDRESS> smap; 00038 public: 00039 SymTab(); // Constructor 00040 ~SymTab(); // Destructor 00041 void Add(ADDRESS a, char* s); // Add a new entry 00042 const char* find(ADDRESS a); // Find an entry by address; NULL if none 00043 ADDRESS find(const char* s); // Find an entry by name; NO_ADDRESS if none 00044 #if 0 00045 char* FindAfter(ADDRESS& dwAddr); // Find entry with >= given value 00046 char* FindNext(ADDRESS& dwAddr); // Find next entry (after a Find()) 00047 int FindIndex(ADDRESS dwAddr); // Find index for entry 00048 ADDRESS FindSym(char* pName); // Linear search for addr from name 00049 #endif 00050 }; 00051 00052 #ifndef NULL 00053 #define NULL 0 // Normally in stdio.h, it seems! 00054 #endif 00055 00056 #endif // __SYMTAB_H__