00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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>
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>
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
00060 T_pop=258,
00061 T_symbols,
00062 T_locations,
00063 T_program,
00064 T_info,
00065
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
00082
00083
00084 TP_slabel,
00085 TP_mlabel,
00086 TP_rlabel,
00087
00088 TI_abivers,
00089 };
00090
00092 static const char *TokID2String(TokID t);
00093
00095 struct Token : TokenEntry
00096 {
00097 struct Type
00098 {
00099
00100
00101
00102
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