From 6e19bb560d474736d45f5be011ff0830c7019991 Mon Sep 17 00:00:00 2001 From: Dimitar Trendafilov Date: Mon, 5 Nov 2018 23:34:00 +0200 Subject: Squashed 'spasm/' content from commit 08ee95d git-subtree-dir: spasm git-subtree-split: 08ee95d89054ba0d33697d613799a0a013aedf89 --- src/asm/symbol.hpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/asm/symbol.hpp (limited to 'src/asm/symbol.hpp') diff --git a/src/asm/symbol.hpp b/src/asm/symbol.hpp new file mode 100644 index 0000000..6ce4dbf --- /dev/null +++ b/src/asm/symbol.hpp @@ -0,0 +1,69 @@ +#ifndef SYMBOL_HPP +#define SYMBOL_HPP + +#include +#include +#include + +namespace SpasmImpl +{ +namespace ASM +{ +//! Represents symbol table entry for the assembler +class Symbol +{ + public: + typedef std::list Positions_t; + static const size_t notdefined; + Symbol(); + Symbol(const std::string&, size_t = 0); + + const std::string& identifier() const; + size_t definition() const; + + void define(size_t); + + size_t add_position(size_t); + + Positions_t::const_iterator positions_begin() const; + Positions_t::const_iterator positions_end() const; + + private: + //! identifier of the symbol + std::string _identifier; + + //! position of definition of the identifier + size_t _definition; + + //! list of uses of the identifier (positions) + Positions_t _positions; +}; + +//! This is the symbol table of the assembler +class Symbol_Table +{ + private: + typedef std::map Table_t; + typedef Table_t::iterator iterator; + + public: + Symbol_Table(); + typedef Table_t::const_iterator const_iterator; + + Symbol* find(const std::string&) const; + Symbol* insert(const std::string&, size_t); + Symbol* define(const std::string&, size_t); + + const_iterator begin() const; + const_iterator end() const; + + private: + Symbol_Table(const Symbol_Table&); + Symbol_Table& operator=(const Symbol_Table&); + + Table_t _table; +}; +} // namespace ASM +} // namespace SpasmImpl + +#endif // SYMBOL_HPP -- cgit v1.3.1-26-gb76a