?login_element?

Subversion Repositories NedoOS

Rev

Rev 129 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. /*
  2.  
  3.   SjASMPlus Z80 Cross Compiler
  4.  
  5.   This is modified sources of SjASM by Aprisobal - aprisobal@tut.by
  6.  
  7.   Copyright (c) 2006 Sjoerd Mastijn
  8.  
  9.   This software is provided 'as-is', without any express or implied warranty.
  10.   In no event will the authors be held liable for any damages arising from the
  11.   use of this software.
  12.  
  13.   Permission is granted to anyone to use this software for any purpose,
  14.   including commercial applications, and to alter it and redistribute it freely,
  15.   subject to the following restrictions:
  16.  
  17.   1. The origin of this software must not be misrepresented; you must not claim
  18.          that you wrote the original software. If you use this software in a product,
  19.          an acknowledgment in the product documentation would be appreciated but is
  20.          not required.
  21.  
  22.   2. Altered source versions must be plainly marked as such, and must not be
  23.          misrepresented as being the original software.
  24.  
  25.   3. This notice may not be removed or altered from any source distribution.
  26.  
  27. */
  28.  
  29. // tables.h
  30.  
  31. struct TextFilePos {
  32.         const char*             filename;
  33.         uint32_t                line;                           // line numbering start at 1 (human way) 0 = invalid/init value
  34.         uint32_t                colBegin, colEnd;       // columns coordinates are unused at this moment
  35.  
  36.         TextFilePos();
  37.         void newFile(const char* fileNamePtr);  // requires stable immutable pointer (until sjasmplus exits)
  38.  
  39.         // advanceColumns are valid only when true == endsWithColon (else advanceColumns == 0)
  40.         // default arguments are basically "next line"
  41.         void nextSegment(bool endsWithColon = false, size_t advanceColumns = 0);
  42. };
  43.  
  44. enum EStructureMembers { SMEMBUNKNOWN, SMEMBALIGN, SMEMBBYTE, SMEMBWORD, SMEMBBLOCK, SMEMBDWORD, SMEMBD24, SMEMBPARENOPEN, SMEMBPARENCLOSE };
  45.  
  46. char* ValidateLabel(const char* naam, bool setNameSpace);
  47. extern char* PreviousIsLabel;
  48. bool GetLabelPage(char*& p, aint& val);
  49. bool GetLabelValue(char*& p, aint& val);
  50. int GetLocalLabelValue(char*& op, aint& val);
  51.  
  52. constexpr int LABEL_PAGE_UNDEFINED = -1;
  53. constexpr int LABEL_PAGE_ROM = 0x7F00;                  // must be minimum of special values (but positive)
  54. constexpr int LABEL_PAGE_OUT_OF_BOUNDS = 0x7F01;        // label is defined, but not within Z80 address space
  55.  
  56. class CLabelTableEntry {
  57. public:
  58.         char*   name;
  59.         aint    value;
  60.         int             updatePass;     // last update was in pass
  61.         short   page;
  62.         bool    IsDEFL;
  63.         bool    IsEQU;
  64.         bool    used;
  65.         CLabelTableEntry();
  66.         void ClearData();
  67. };
  68.  
  69. class CLabelTable {
  70. public:
  71.         CLabelTable();
  72.         int Insert(const char* nname, aint nvalue, bool undefined = false, bool IsDEFL = false, bool IsEQU = false);
  73.         int Update(char*, aint);
  74.         CLabelTableEntry* Find(const char* name, bool onlyDefined = false);
  75.         bool Remove(const char* name);
  76.         bool IsUsed(const char* name);
  77.         void RemoveAll();
  78.         void Dump();
  79.         void DumpForUnreal();
  80.         void DumpForCSpect();
  81.         void DumpSymbols();
  82. private:
  83.         int HashTable[LABTABSIZE], NextLocation;
  84.         CLabelTableEntry LabelTable[LABTABSIZE];
  85.         int Hash(const char*);
  86. };
  87.  
  88. class CFunctionTableEntry {
  89. public:
  90.         char* name;
  91.         void (*funp)(void);
  92. };
  93.  
  94. class CFunctionTable {
  95. public:
  96.         CFunctionTable();
  97.         int Insert(const char*, void(*) (void));
  98.         int insertd(const char*, void(*) (void));
  99.         int zoek(const char*);
  100.         int Find(char*);
  101. private:
  102.         int HashTable[FUNTABSIZE], NextLocation;
  103.         CFunctionTableEntry funtab[FUNTABSIZE];
  104.         int Hash(const char*);
  105. };
  106.  
  107. class CLocalLabelTableEntry {
  108. public:
  109.         aint nummer, value;
  110.         CLocalLabelTableEntry* next, * prev;
  111.         CLocalLabelTableEntry(aint number, aint address, CLocalLabelTableEntry* previous);
  112. };
  113.  
  114. class CLocalLabelTable {
  115. public:
  116.         CLocalLabelTable();
  117.         ~CLocalLabelTable();
  118.         void InitPass();
  119.         aint seekForward(const aint labelNumber) const;
  120.         aint seekBack(const aint labelNumber) const;
  121.         bool InsertRefresh(const aint labelNumber);
  122. private:
  123.         bool insertImpl(const aint labelNumber);
  124.         bool refreshImpl(const aint labelNumber);
  125.         CLocalLabelTableEntry* first, * last, * refresh;
  126. };
  127.  
  128. class CStringsList {
  129. public:
  130.         char* string;
  131.         CStringsList* next;
  132.         TextFilePos source;
  133.         TextFilePos definition;
  134.         CStringsList();
  135.         ~CStringsList();
  136.         CStringsList(const char* stringSource, CStringsList* next = NULL);
  137. };
  138.  
  139. class CDefineTableEntry {
  140. public:
  141.         char* name, * value;
  142.         CStringsList* nss;
  143.         CDefineTableEntry* next;
  144.         CDefineTableEntry(const char*, const char*, CStringsList*, CDefineTableEntry*);
  145.         ~CDefineTableEntry();
  146. };
  147.  
  148. class CMacroDefineTable {
  149. public:
  150.         void ReInit();
  151.         void AddMacro(char*, char*);
  152.         CDefineTableEntry* getdefs();
  153.         void setdefs(CDefineTableEntry*);
  154.         char* getverv(char*);
  155.         int FindDuplicate(char*);
  156.         CMacroDefineTable();
  157.         CMacroDefineTable(const CMacroDefineTable&) = delete;
  158.         CMacroDefineTable& operator=(CMacroDefineTable const&) = delete;
  159.         ~CMacroDefineTable();
  160. private:
  161.         bool used[128];
  162.         CDefineTableEntry* defs;
  163. };
  164.  
  165. class CDefineTable {
  166. public:
  167.         CStringsList* DefArrayList;
  168.         void Init();
  169.         void Add(const char*, const char*, CStringsList*);
  170.         char* Get(const char*);
  171.         int FindDuplicate(const char*);
  172.         int Replace(const char*, const char*);
  173.         int Replace(const char*, const int);
  174.         int Remove(const char*);
  175.         void RemoveAll();
  176.         CDefineTable() {
  177.                 Init();
  178.         }
  179.         ~CDefineTable();
  180.         CDefineTable(const CDefineTable&) = delete;
  181.         CDefineTable& operator=(CDefineTable const & defTable);
  182. private:
  183.         CDefineTableEntry* defs[128];
  184. };
  185.  
  186. class CMacroTableEntry {
  187. public:
  188.         char* naam;
  189.         CStringsList* args, * body;
  190.         CMacroTableEntry* next;
  191.         CMacroTableEntry(char*, CMacroTableEntry*);
  192.         ~CMacroTableEntry();
  193. };
  194.  
  195. class CMacroTable {
  196. public:
  197.         void Add(char*, char*&);
  198.         int Emit(char*, char*&);
  199.         int FindDuplicate(char*);
  200.         void ReInit();
  201.         CMacroTable();
  202.         ~CMacroTable();
  203. private:
  204.         bool used[128];
  205.         CMacroTableEntry* macs;
  206. };
  207.  
  208. class CStructureEntry1 {
  209. public:
  210.         char* naam;
  211.         aint offset;
  212.         CStructureEntry1* next;
  213.         CStructureEntry1(char*, aint);
  214.         ~CStructureEntry1();
  215. };
  216.  
  217. class CStructureEntry2 {
  218. public:
  219.         aint offset, len, def;
  220.         EStructureMembers type;
  221.         CStructureEntry2* next;
  222.         CStructureEntry2(aint noffset, aint nlen, aint ndef, EStructureMembers ntype);
  223.         ~CStructureEntry2();
  224.         aint ParseValue(char* & p);
  225. };
  226.  
  227. class CStructure {
  228. public:
  229.         char* naam, * id;
  230.         int global;
  231.         int maxAlignment;
  232.         aint noffset;
  233.         void AddLabel(char*);
  234.         void AddMember(CStructureEntry2*);
  235.         void CopyLabel(char*, aint);
  236.         void CopyLabels(CStructure*);
  237.         void CopyMember(CStructureEntry2*, aint);
  238.         void CopyMembers(CStructure*, char*&);
  239.         void deflab();
  240.         void emitlab(char* iid, aint address);
  241.         void emitmembs(char*&);
  242.         CStructure* next;
  243.         CStructure(const char* nnaam, char* nid, int no, int ngl, CStructure* p);
  244.         ~CStructure();
  245. private:
  246.         CStructureEntry1* mnf, * mnl;
  247.         CStructureEntry2* mbf, * mbl;
  248. };
  249.  
  250. class CStructureTable {
  251. public:
  252.         CStructure* Add(char* naam, int no, int gl);
  253.         void ReInit();
  254.         CStructureTable();
  255.         ~CStructureTable();
  256.         CStructure* zoek(const char*, int);
  257.         int FindDuplicate(char*);
  258.         int Emit(char*, char*, char*&, int);
  259. private:
  260.         static aint ParseDesignedAddress(char* &p);
  261.         CStructure* strs[128];
  262. };
  263.  
  264. struct SRepeatStack {
  265.         int RepeatCount;
  266.         TextFilePos sourcePos;
  267.         aint CurrentSourceLine;
  268.         CStringsList* Lines;
  269.         CStringsList* Pointer;
  270.         bool IsInWork;
  271.         int Level;
  272. };
  273.  
  274. struct SConditionalStack {
  275.         aint CurrentSourceLine;
  276.         CStringsList* Lines;
  277.         CStringsList* Pointer;
  278.         bool IsInWork;
  279.         int Level;
  280. };
  281.  
  282. int LuaGetLabel(char *name);
  283.  
  284. //eof tables.h
  285.  
  286.