UnivesalDisassembler(2003)
|
00001 // symtable.cc 00002 // 00003 // uda - universal disassembler 00004 // Date: 2003-05-04 00005 // 00006 // Copyright (c) 2002-2003 Ales Smrcka 00007 // 00008 // This program is licensed under GNU Library GPL. See the file COPYING. 00009 // 00010 // This module contains implementation of class Symbols - administration of symbols 00011 // 00012 00013 #include "symtable.h" 00014 #include "shared.h" 00015 #include "plugins.h" 00016 #include "udaclasses.h" 00017 #include "instrset.h" //Instruction::Scanner() 00018 #include <string> 00019 #include <iomanip> 00020 #include <iostream> 00021 #include <fstream> 00022 using namespace std; 00023 00024 Symbols *symbols=NULL; 00025 00027 void Symbols::Load(const char *filename) 00028 { 00029 if (filename!=NULL) 00030 { 00031 Scanner scanner(filename); 00032 Scanner::Token t=scanner.Scan(); 00033 Address addr; 00034 while (t) 00035 { 00036 if (t!=tk_number) 00037 throw Exception(string("number expected in ")+filename+" at "+uint2str(scanner.line())); 00038 addr=t.int_value; 00039 t=scanner.Scan(); 00040 if (t!=tk_equal) 00041 throw Exception(string("`=' expected in ")+filename+" at "+uint2str(scanner.line())); 00042 t=scanner.Scan(); 00043 if (t!=tk_text) 00044 throw Exception(string("\"text\" expected in ")+filename+" at "+uint2str(scanner.line())); 00045 symbols[addr]=t.str_value; 00046 t=scanner.Scan(); 00047 if (t!=tk_semicol) 00048 throw Exception(string("`;' expected in ")+filename+" at "+uint2str(scanner.line())); 00049 t=scanner.Scan(); 00050 } 00051 } 00052 else 00053 { 00054 VPlugins::iterator i; 00055 for (i=plugins.begin();i!=plugins.end();i++) 00056 if ((*i)->type&PLUGIN_SYMTABLE) 00057 if ((*i)->IsFileDefined(bfdata.name.c_str())) 00058 { 00059 (*i)->LoadSymbols(*this); 00060 break; 00061 } 00062 } 00063 } 00064 00066 bool Symbols::checkaddress(const Address addr) 00067 { 00068 if (!defined(addr)) 00069 { 00070 symbols[addr]="label"+::uint2str(_counter++); 00071 return false; 00072 } 00073 return true; 00074 } 00075 00077 bool Symbols::defined(const Address addr) 00078 { 00079 return symbols.find(addr)!=symbols.end(); 00080 } 00081 00083 string &Symbols::operator[](const Address addr) 00084 { 00085 return symbols[addr]; 00086 } 00087 00088 00089 // find address corresponding to symbol 00090 Address Symbols::findaddress(const string symbol, bool &defined) 00091 { 00092 MSymbols::iterator i; 00093 for (i=symbols.begin();i!=symbols.end();i++) 00094 if (i->second==symbol) 00095 { 00096 defined=true; 00097 return i->first; 00098 } 00099 defined=false; 00100 return 0; 00101 }