Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/vm/instruction/inst2str.cc

Go to the documentation of this file.
00001 /*
00002  * vm/instruction/inst2str.cc
00003  * 
00004  * VM instruction to string conversion. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "storage.h"
00018 #include <lib/lex/fastval2str.h>
00019 
00020 
00021 namespace VM
00022 {
00023 
00024 // Copy src to dest with trailing NUL and return pointer to NUL. 
00025 // This allows to continue with the string at the return value. 
00026 static inline char *_strpcp(char *dest,const char *src)
00027 {
00028     while((*dest=*src))
00029     {  ++dest;  ++src;  }
00030     return(dest);
00031 }
00032 
00033 
00034 TLString InstructionStorage::DumpInstruction(PrgAdr adr) const
00035 {
00036     INST::IID inst=InstructionAt(adr);
00037     const INST::DescEntry *desc=INST::Desc(inst);
00038     if(!desc)
00039     {  return("illegal instruction");  }
00040     
00041     const int FLTLEN=16; // 14
00042     const int DBLLEN=24; // 22
00043     
00044     TLString tmp;
00045     
00046     // FIXME: Should speed-improve this by directly using TLSTring::SData with 
00047     //     correct length pre-allocated. Also, avoid strlen(). 
00048     
00049     // NOTE: We assume that no instruction ID (ala "incsd") has more than 
00050     //       8 chars. 
00051     
00052     switch(desc->argcomb)
00053     {
00054         case INST::AC_void:
00055             tmp=desc->name;
00056             break;
00057         case INST::AC_i:
00058         {
00059             uint32 a;
00060             extract(adr,&a);
00061             
00062             Assert(!desc->symref_off && !desc->typeid_off);
00063             
00064             char buf[8+2+10],*e=buf;
00065             e=_strpcp(e,desc->name);  *e++=' ';
00066             if(desc->codemark_off)  *e++='&';
00067             e=FastInt2String(e,a);
00068             
00069             tmp.assign(buf,e-buf);
00070         }   break;
00071         case INST::AC_S:
00072         {
00073             int32 a;
00074             extract(adr,&a);
00075             
00076             Assert(desc->symref_off || desc->typeid_off);
00077             Assert(!desc->codemark_off);
00078             
00079             char buf[8+2+11],*e=buf;
00080             e=_strpcp(e,desc->name);  *e++=' ';
00081             if(desc->symref_off)  *e++='$';
00082             e=FastInt2String(e,a,10);
00083             
00084             tmp.assign(buf,e-buf);
00085         }   break;
00086         case INST::AC_bb:
00087         {
00088             uint8 a,b;
00089             extract(adr,&a,&b);
00090             
00091             if(inst==INST::ANEW)
00092             {
00093                 char buf[8],*e=buf;
00094                 const char *postfix=" bsilpafd";
00095                 e=_strpcp(e,desc->name);
00096                 if(a>0 && a<=8)  // ">0" CORRECT
00097                 {  *e++=postfix[a];  }
00098                 else
00099                 {  *e++='?';  }
00100                 tmp.assign(buf,e-buf);
00101                 break;
00102             }
00103             
00104             char buf[8+1+4+1+4],*e=buf;
00105             e=_strpcp(e,desc->name);  *e++=' ';
00106             e=FastInt2String(e,a);    *e++=' ';
00107             e=FastInt2String(e,b);
00108             
00109             tmp.assign(buf,e-buf);
00110         }   break;
00111         case INST::AC_sb:
00112         {
00113             uint16 a;
00114             uint8 b;
00115             extract(adr,&a,&b);
00116             
00117             char buf[8+1+4+1+6],*e=buf;
00118             e=_strpcp(e,desc->name);  *e++=' ';
00119             e=FastInt2String(e,a);    *e++=' ';
00120             e=FastInt2String(e,b);
00121             
00122             tmp.assign(buf,e-buf);
00123         }   break;
00124         case INST::AC_ib:
00125         {
00126             uint32 a;
00127             uint8 b;
00128             extract(adr,&a,&b);
00129             
00130             Assert(!desc->symref_off && !desc->typeid_off);
00131             
00132             char buf[8+1+4+1+10],*e=buf;
00133             e=_strpcp(e,desc->name);  *e++=' ';
00134             if(desc->codemark_off)  *e++='&';
00135             e=FastInt2String(e,a);  *e++=' ';
00136             e=FastInt2String(e,b);
00137             
00138             tmp.assign(buf,e-buf);
00139         }   break;
00140         case INST::AC_Sb:
00141         {
00142             int32 a;
00143             uint8 b;
00144             extract(adr,&a,&b);
00145             
00146             Assert(desc->symref_off || desc->typeid_off);
00147             Assert(!desc->codemark_off);
00148             
00149             char buf[8+1+4+1+11],*e=buf;
00150             e=_strpcp(e,desc->name);  *e++=' ';
00151             if(desc->symref_off)  *e++='$';
00152             e=FastInt2String(e,a,10);    *e++=' ';
00153             e=FastInt2String(e,b);
00154             
00155             tmp.assign(buf,e-buf);
00156         }   break;
00157         case INST::AC_lb:
00158         {
00159             uint64 a;
00160             uint8 b;
00161             extract(adr,&a,&b);
00162             
00163             char buf[8+1+4+1+18],*e=buf;
00164             e=_strpcp(e,desc->name);  *e++=' ';
00165             e=FastInt2String(e,a);    *e++=' ';
00166             e=FastInt2String(e,b);
00167             
00168             tmp.assign(buf,e-buf);
00169         }   break;
00170         case INST::AC_fb:
00171         {
00172             flt a;
00173             uint8 z;
00174             extract(adr,&a,&z);
00175             
00176             char buf[8+1+4+1+FLTLEN],*e=buf;
00177             e=_strpcp(e,desc->name);  *e++=' ';
00178             e=FastFloat2String(e,a);  *e++=' ';
00179             e=FastInt2String(e,z);
00180             
00181             tmp.assign(buf,e-buf);
00182         }   break;
00183         case INST::AC_ffb:
00184         {
00185             flt a,b;
00186             uint8 z;
00187             extract(adr,&a,&b,&z);
00188             
00189             char buf[8+1+4+(1+FLTLEN)*2],*e=buf;
00190             e=_strpcp(e,desc->name);  *e++=' ';
00191             e=FastFloat2String(e,a);  *e++=' ';
00192             e=FastFloat2String(e,b);  *e++=' ';
00193             e=FastInt2String(e,z);
00194             
00195             tmp.assign(buf,e-buf);
00196         }   break;
00197         case INST::AC_fffb:
00198         {
00199             flt a,b,c;
00200             uint8 z;
00201             extract(adr,&a,&b,&c,&z);
00202             
00203             char buf[8+1+4+(1+FLTLEN)*3],*e=buf;
00204             e=_strpcp(e,desc->name);  *e++=' ';
00205             e=FastFloat2String(e,a);  *e++=' ';
00206             e=FastFloat2String(e,b);  *e++=' ';
00207             e=FastFloat2String(e,c);  *e++=' ';
00208             e=FastInt2String(e,z);
00209             
00210             tmp.assign(buf,e-buf);
00211         }   break;
00212         case INST::AC_ffffb:
00213         {
00214             flt a,b,c,d;
00215             uint8 z;
00216             extract(adr,&a,&b,&c,&d,&z);
00217             
00218             char buf[8+1+4+(1+FLTLEN)*4],*e=buf;
00219             e=_strpcp(e,desc->name);  *e++=' ';
00220             e=FastFloat2String(e,a);  *e++=' ';
00221             e=FastFloat2String(e,b);  *e++=' ';
00222             e=FastFloat2String(e,c);  *e++=' ';
00223             e=FastFloat2String(e,d);  *e++=' ';
00224             e=FastInt2String(e,z);
00225             
00226             tmp.assign(buf,e-buf);
00227         }   break;
00228         case INST::AC_db:
00229         {
00230             dbl a;
00231             uint8 z;
00232             extract(adr,&a,&z);
00233             
00234             char buf[8+1+4+1+DBLLEN],*e=buf;
00235             e=_strpcp(e,desc->name);  *e++=' ';
00236             e=FastFloat2String(e,a);  *e++=' ';
00237             e=FastInt2String(e,z);
00238             
00239             tmp.assign(buf,e-buf);
00240         }   break;
00241         case INST::AC_ddb:
00242         {
00243             dbl a,b;
00244             uint8 z;
00245             extract(adr,&a,&b,&z);
00246             
00247             char buf[8+1+4+(1+DBLLEN)*2],*e=buf;
00248             e=_strpcp(e,desc->name);  *e++=' ';
00249             e=FastFloat2String(e,a);  *e++=' ';
00250             e=FastFloat2String(e,b);  *e++=' ';
00251             e=FastInt2String(e,z);
00252             
00253             tmp.assign(buf,e-buf);
00254         }   break;
00255         case INST::AC_dddb:
00256         {
00257             dbl a,b,c;
00258             uint8 z;
00259             extract(adr,&a,&b,&c,&z);
00260             
00261             char buf[8+1+4+(1+DBLLEN)*3],*e=buf;
00262             e=_strpcp(e,desc->name);  *e++=' ';
00263             e=FastFloat2String(e,a);  *e++=' ';
00264             e=FastFloat2String(e,b);  *e++=' ';
00265             e=FastFloat2String(e,c);  *e++=' ';
00266             e=FastInt2String(e,z);
00267             
00268             tmp.assign(buf,e-buf);
00269         }   break;
00270         case INST::AC_ddddb:
00271         {
00272             dbl a,b,c,d;
00273             uint8 z;
00274             extract(adr,&a,&b,&c,&d,&z);
00275             
00276             char buf[8+1+4+(1+DBLLEN)*4],*e=buf;
00277             e=_strpcp(e,desc->name);  *e++=' ';
00278             e=FastFloat2String(e,a);  *e++=' ';
00279             e=FastFloat2String(e,b);  *e++=' ';
00280             e=FastFloat2String(e,c);  *e++=' ';
00281             e=FastFloat2String(e,d);  *e++=' ';
00282             e=FastInt2String(e,z);
00283             
00284             tmp.assign(buf,e-buf);
00285         }   break;
00286         default: Assert(0);
00287     }
00288     
00289     return(tmp);
00290 }
00291 
00292 }  // end of namespace VM

Generated on Sat Feb 19 22:33:47 2005 for Ray by doxygen 1.3.5