00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _VM_INPUT_TASM_TASM_FILE_H_
00018 #define _VM_INPUT_TASM_TASM_FILE_H_ 1
00019
00027 #include <vm/vmconfig.h>
00028 #include <vm/input/asmfile.h>
00029 #include <vm/input/tasm/tasm-scanner.h>
00030 #include <lib/tl/tlarrayheap.h>
00031
00032
00033 class StringTreeDump;
00034
00035
00036 namespace VM
00037 {
00038
00039
00040 class ClassInfo;
00041
00042
00052 class AssemblerFile_Plaintext : public AssemblerFile
00053 {
00054 public:
00055 struct RJumpEntry
00056 {
00057 PrgAdr adr;
00058 CodeMark cmark;
00059
00061 static inline PrgAdr ord(const RJumpEntry &e)
00062 { return(e.adr); }
00063
00064 inline RJumpEntry() {}
00065 inline RJumpEntry(PrgAdr _adr,CodeMark _cmark) : adr(_adr),
00066 cmark(_cmark) {}
00067 inline ~RJumpEntry() {}
00068 };
00069
00070 struct RJumpEntry_Operators :
00071 TLDefaultOperators_OrdRel2_Rev<RJumpEntry,RJumpEntry,RJumpEntry,
00072 RJumpEntry>,
00073 TLDefaultOperators_Construct_CDT<RJumpEntry>,
00074 TLDefaultOperators_Index<RJumpEntry>,
00075 TLDefaultOperators_Allocation
00076 {
00077 };
00078
00079 protected:
00081 TextAsmScanner scan;
00083 int n_errors;
00084
00086 IDMapTable<CodeMark,PrgAdr> codemark2prgadr;
00087
00089 TLArrayHeap<RJumpEntry,RJumpEntry_Operators> *prgadr2codemark;
00090
00092 TextAsmScanner::Token *tok;
00093
00095 inline void _LexNextToken()
00096 {
00097
00098 if(tok && tok->str_val) *tok->str_val='\0';
00099 tok=(TextAsmScanner::Token*)scan.LexNextToken();
00100 }
00101
00103 inline TextAsmScanner::TokID _CurrTokID()
00104 { return((TextAsmScanner::TokID)
00105 (tok ? tok->token : TextAsmScanner::T_EOF)); }
00106
00108 void _ExpectError(const char *str);
00110 void _AlreadySetError();
00112 void _LocFirstDefError(const SCLocation &loc);
00113
00115 VarType _ParseVarType(const TextAsmScanner::Token::Type *t);
00117 FuncType _ParseFuncType(char ftype);
00118
00121 void _SkipUntilPop(uint32 num,TextAsmScanner::TokID skip_a,
00122 TextAsmScanner::TokID skip_b=TextAsmScanner::T_EOF);
00123
00125 NamespaceInfo *_CheckNspcNameKnown(NamespaceInfo *parent,
00126 const TLString &name);
00127
00129 void _ParseInfoSection();
00131 void _ParseSymbolSection();
00133 void _ParseLocationSection();
00135 void _ParseProgramSection();
00136
00138 void _ParseSymbols_Namespace(NamespaceInfo *parent);
00140 void _ParseSymbols_Class(NamespaceInfo *parent);
00142 void _ParseSymbols_Symbols(NamespaceInfo *parent);
00144 void _ParseSymbols_Global();
00146 void _ParseSymbols_Class_Base(ClassInfo *parent);
00148 void _ParseSymbols_Class_VTable(ClassInfo *parent);
00150 void _ParseSymbols_Class_Size(ClassInfo *parent);
00151
00153 void _ParseProgram_Label();
00154
00156 void _ParseProgram_FinishFunction();
00157
00159 int _WriteFunctionProgram(FILE *fp,ProgramStorage::Function *pfunc);
00161 int _WriteSymbolSectionContent(FILE *fp);
00163 int _WriteSymbols_Recursive(StringTreeDump &out,NamespaceInfo *ni);
00165 int _WriteSymbols_Global(StringTreeDump &out,_GlobVars *gvar,
00166 char which);
00167
00170 int _MustDumpNamespace(NamespaceInfo *ni);
00171
00172 private:
00174 AssemblerFile_Plaintext(const AssemblerFile_Plaintext &);
00176 void operator=(const AssemblerFile_Plaintext &);
00177 public:
00179 AssemblerFile_Plaintext();
00181 ~AssemblerFile_Plaintext();
00182
00184 int ParseFile(const TLString &fname,SError &error,uint32 file_num);
00185
00187 int WriteFile(const TLString &fname,SError &error);
00188
00190 int WriteFunctionProgram(FILE *fp,ProgramStorage::Function *pfunc)
00191 { return(_WriteFunctionProgram(fp,pfunc)); }
00192 };
00193
00194 }
00195
00196 #endif