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

/ray/src/vm/instruction/storage.h

Go to the documentation of this file.
00001 /*
00002  * vm/instruction/storage.h
00003  * 
00004  * VM instruction (program) storage. 
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 #ifndef _VM_INSTRUCTION_STORAGE_H_
00018 #define _VM_INSTRUCTION_STORAGE_H_ 1
00019 
00027 #include <vm/vmconfig.h>    /* MUST be first */
00028 #include <vm/instruction/instruction.h>
00029 #include <lib/tl/tlstring.h>
00030 
00031 
00032 namespace VM
00033 {
00034 
00053 class InstructionStorage
00054 {
00055     private:
00056         char *prg;         
00057         PrgAdr prg_asize;  
00058         PrgAdr prg_len;    
00059         
00062         void _ReallocStore(PrgAdr needlen);
00063         
00065         InstructionStorage(const InstructionStorage &);
00067         void operator=(const InstructionStorage &);
00068     public:
00076         InstructionStorage(PrgAdr prealloc_size=0);
00078         ~InstructionStorage();
00079         
00089         inline PrgAdr length() const
00090             {  return(prg_len);  }
00091         
00093         inline char &index(PrgAdr i)
00094             {  return(prg[i]);  }
00095         
00097         INST::IID InstructionAt(PrgAdr i) const
00098             {  return((INST::IID)(*(uint16*)(prg+i)));  }
00099         
00112         void append(const char *pbuf,PrgAdr plen)
00113         {
00114             PrgAdr idx=prg_len;
00115             prg_len+=plen;
00116             if(prg_len>prg_asize)  _ReallocStore(prg_len);
00117             // Store: 
00118             const uint16 *src=(const uint16*)pbuf;
00119             uint16 *dest=(uint16*)(prg+idx);
00120             uint16 *dend=(uint16*)(prg+prg_len);
00121             while(dest<dend)  *dest++=*src++;
00122             // Done. prg_len already updated. 
00123         }
00124         
00129 
00130         void append(INST::IID inst);
00131         void append(INST::IID inst,uint32 a);
00132         void append(INST::IID inst,int32 a);  // SymRef,TypeID
00133         void append(INST::IID inst,uint8 a,uint8 b);
00134         void append(INST::IID inst,uint16 a,uint8 b);
00135         void append(INST::IID inst,uint32 a,uint8 b);
00136         void append(INST::IID inst,int32 a,uint8 b);  // SymRef,TypeID
00137         void append(INST::IID inst,uint64 a,uint8 b);
00138         void append(INST::IID inst,flt a,uint8 b);
00139         void append(INST::IID inst,flt a,flt b,uint8 z);
00140         void append(INST::IID inst,flt a,flt b,flt c,uint8 z);
00141         void append(INST::IID inst,flt a,flt b,flt c,flt d,uint8 z);
00142         void append(INST::IID inst,dbl a,uint8 b);
00143         void append(INST::IID inst,dbl a,dbl b,uint8 z);
00144         void append(INST::IID inst,dbl a,dbl b,dbl c,uint8 z);
00145         void append(INST::IID inst,dbl a,dbl b,dbl c,dbl d,uint8 z);
00147         
00156 
00157         INST::IID extract(PrgAdr adr) const;
00158         INST::IID extract(PrgAdr adr,uint32 *a) const;
00159         INST::IID extract(PrgAdr adr,int32 *a) const;  // SymRef,TypeID
00160         INST::IID extract(PrgAdr adr,uint8 *a,uint8 *b) const;
00161         INST::IID extract(PrgAdr adr,uint16 *a,uint8 *b) const;
00162         INST::IID extract(PrgAdr adr,uint32 *a,uint8 *b) const;
00163         INST::IID extract(PrgAdr adr,int32 *a,uint8 *b) const;  // SymRef,TypeID
00164         INST::IID extract(PrgAdr adr,uint64 *a,uint8 *b) const;
00165         INST::IID extract(PrgAdr adr,flt *a,uint8 *b) const;
00166         INST::IID extract(PrgAdr adr,flt *a,flt *b,uint8 *z) const;
00167         INST::IID extract(PrgAdr adr,flt *a,flt *b,flt *c,uint8 *z) const;
00168         INST::IID extract(PrgAdr adr,flt *a,flt *b,flt *c,flt *d,uint8 *z)const;
00169         INST::IID extract(PrgAdr adr,dbl *a,uint8 *b) const;
00170         INST::IID extract(PrgAdr adr,dbl *a,dbl *b,uint8 *z) const;
00171         INST::IID extract(PrgAdr adr,dbl *a,dbl *b,dbl *c,uint8 *z) const;
00172         INST::IID extract(PrgAdr adr,dbl *a,dbl *b,dbl *c,dbl *d,uint8 *z)const;
00174         
00182         void TightenSize();
00183         
00191         TLString DumpInstruction(PrgAdr adr) const;
00192 };
00193 
00194 }  // end of namespace VM
00195 
00196 #endif  /* _VM_INSTRUCTION_STORAGE_H_ */

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