Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / symbol.hpp
diff options
context:
space:
mode:
Commitc3252e63c296d1133254f4973fe7e3bf52cc6c1a (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-11-05 23:34:00 +0200
Files67c6bfc067696562aded70f66d25899f3f70a1c8 /spasm/src/asm/symbol.hpp
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.tar.gz
IPL-c3252e63c296d1133254f4973fe7e3bf52cc6c1a.zip
Parentc9912fdb174e1580629e00cacab6bc4ed480e643 (diff)
Parent6e19bb560d474736d45f5be011ff0830c7019991 (diff)
Merge commit '6e19bb560d474736d45f5be011ff0830c7019991' as 'spasm'
1 files changed, 69 insertions, 0 deletions
-rw-r--r--spasm/src/asm/symbol.hpp69
diff --git a/spasm/src/asm/symbol.hpp b/spasm/src/asm/symbol.hpp
new file mode 100644
index 0000000..6ce4dbf
--- /dev/null
+++ b/spasm/src/asm/symbol.hpp
@@ -0,0 +1,69 @@
+#ifndef SYMBOL_HPP
+#define SYMBOL_HPP
+
+#include <list>
+#include <map>
+#include <string>
+
+namespace SpasmImpl
+{
+namespace ASM
+{
+//! Represents symbol table entry for the assembler
+class Symbol
+{
+ public:
+ typedef std::list<size_t> 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<std::string, Symbol*> 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