Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

registers.cpp

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2002 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 -----
00020 
00021 INFORMATION
00022   www: https://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #include "global.h"
00026 #ifdef HAVE_HDRSTOP
00027 #pragma hdrstop
00028 #endif
00029 
00030 #include <set>
00031 #include <algorithm>
00032 #include <string>
00033 #include "registers.h"
00034 
00035 using namespace std;
00036 
00037 // costruisci la tabelle con tutti i dati
00038 #define DEFINE_REG(size,type,name,string,complete,mask) \
00039  { reg_info::size, reg_info::type, string, complete, mask },
00040 reg_info regs[] =
00041 {
00042 #include "x86regs.h"
00043 };
00044 #undef DEFINE_REG
00045 #define NUM_REG (sizeof(regs)/sizeof(regs[0]))
00046 
00047 struct __find_reg: public unary_function<const reg_info&,bool>
00048 {
00049   __find_reg(const char* _p):p(_p) {};
00050   bool operator()(const reg_info& info)
00051   { return strcmp(info.name,p) == 0; };
00052   const char* p;
00053 };
00054 
00055 reg_t find_reg(const char *reg)
00056 {
00057   int n = find_if(regs,regs+NUM_REG,__find_reg(reg)) - regs;
00058   if (n == NUM_REG)
00059     return null_reg;
00060   return static_cast<reg_t>(n);
00061 }
00062 
00063 const reg_info* RegistryInfo::GetInfo(const char* name)
00064 {
00065   reg_info *p = find_if(regs,regs+NUM_REG,__find_reg(name));
00066   if ( p == (regs+NUM_REG) )
00067     return NULL;
00068   return p;
00069 }
00070 
00071 const reg_info* RegistryInfo::GetInfo(reg_t i)
00072 {
00073   if ( unsigned(i) >= NUM_REG )
00074     return NULL;
00075   return &regs[i];
00076 }
00077 
00078 reg_t RegistryInfo::GetIndex(const char* name)
00079 {
00080   return find_reg(name);
00081 }
00082 

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15