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

/ray/src/vm/input/tasm/tasm-scanner.h

Go to the documentation of this file.
00001 /*
00002  * vm/input/tasm/tasm-scanner.h
00003  * 
00004  * VM plaintext assembly scanner (lexical analysis). 
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_INPUT_TASM_TASM_SCANNER_H_
00018 #define _VM_INPUT_TASM_TASM_SCANNER_H_ 1
00019 
00027 #include <vm/vmconfig.h>    /* MUST be first */
00028 
00029 #include <lib/lex/location.h>
00030 #include <lib/sourcepos/sparchive.h>
00031 #include <vm/input/nspcinfo.h>
00032 #include <vm/program.h>
00033 
00034 #include <stdio.h>      /* because of FILE * (FIXME) */
00035 
00036 #define PREFIX_FlexScannerBase TASM_FlexScannerBase
00037 #include <lib/lex/scannerbase.h>
00038 #undef PREFIX_FlexScannerBase
00039 
00040 
00050 class TextAsmScanner : public TASM_FlexScannerBase
00051 {
00052     friend int TASM_lex(void *);
00053     public:
00056         enum TokID
00057         {
00058             T_EOF=0,           
00059             // skip 0..255 for single char tokens
00060             T_pop=258,         
00061             T_symbols,         
00062             T_locations,       
00063             T_program,         
00064             T_info,            
00065             // For symbols: 
00066             TS_namespace,      
00067             TS_class,          
00068             TS_base,
00069             TS_baseent,
00070             TS_varent,         
00071             TS_size,
00072             TS_virtual,
00073             TS_vtable,         
00074             TS_symref,         
00075             TS_vglobal,        
00076             TS_pglobal,        
00077             TS_symbols,        
00078             TS_funcsym,        
00079             TS_varsym,         
00080             TS_globvar,        
00081             // For locations:
00082             // TL_*  (nothing currently)
00083             // For program:
00084             TP_slabel,         
00085             TP_mlabel,         
00086             TP_rlabel,         
00087             // For info section: 
00088             TI_abivers,        
00089         };
00090         
00092         static const char *TokID2String(TokID t);
00093         
00095         struct Token : TokenEntry
00096         {
00097             struct Type
00098             {
00099                 // Note for TS_varent: 
00100                 //  tid is the TYPEID specified with the pointer when 
00101                 //      used like "p>TYPEID". In this case tchar[1]='>'. 
00102                 //  tchar are the max 2 type chars; 1 normally, 2 for arrays. 
00103                 VM::TypeID tid;
00104                 char tchar[2];
00105             };
00106             
00108             union {
00110                 struct { uint32 size; uint32 num_p,num_v; };
00112                 struct { uint32 num; };
00124                 struct {
00125                     union { Type t; VM::TypeID tid; char ftype; };
00126                     union { VM::Offset off; uint32 codemark; };
00127                     union { VM::SymRef symref; };
00128                 };
00129             };
00131             char *str_val;
00132             
00134             bool MayBeCleared() const;
00136             void clear(bool force);
00137             
00138             Token() : TokenEntry(),str_val(NULL)  { }
00139             ~Token()  { clear(1); }
00140         };
00141         
00142     private:
00144         void reset();
00146         TokenEntry *AllocTokenEntry()
00147             {  return(new Token());  }
00148         
00164         char *_ParseNameStr(const char *str,const char *end);
00165         
00181         template<typename T>const char *_ParseInt(T *ret,const char *str,
00182             char prefix='\0');
00184         template<typename T>const char *_ParseInt0(T *ret,const char *str);
00185         
00191         template<typename T>const char *_ParseFloat(T *ret,const char *str);
00192         
00206         const char *_ParseTypeSpec(Token::Type *ts,const char *str);
00207         
00209         void _CheckInstAllowed_Failed();
00211         inline bool _CheckInstAllowed()
00212         {
00213             if(insn_storage)  return(1);
00214             _CheckInstAllowed_Failed();  return(0);
00215         }
00216         
00218         TextAsmScanner(const TextAsmScanner &);
00220         void operator=(const TextAsmScanner &);
00221     public:
00223         TextAsmScanner();
00225         ~TextAsmScanner();
00226         
00228         int NErrors() const
00229             {  return(n_errors);  }
00230         
00234         VM::ProgramStorage::Function *insn_storage;
00235         
00237         inline VM::InstructionStorage *InsnStorage()
00238             {  return(insn_storage);  }
00239 };
00240 
00241 #endif  /* _VM_INPUT_TASM_TASM_SCANNER_H_ */

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