// // This file is part of Mipsy, a tiny MIPS simulator // Copyright (C) 2003 Benoit Perrot // // Mipsy is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // Mipsy is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // #ifndef INST_SECTION_HH # define INST_SECTION_HH # include # include # include "misc/contract.hh" # include "inst/label.hh" namespace inst { class Section { protected: typedef std::list label_list_t; typedef std::map offset_label_t; typedef std::map label_offset_t; public: Section() { } virtual ~Section() { } protected: void add_label(Label& label, int offset) { // FIXME: check that this label has not already been added. offsets[label] = offset; labels[offset].push_back(&label); } public: bool has_label(const Label& label) const { label_offset_t::const_iterator it = offsets.find(label); return it != offsets.end(); } int get_offset(const Label& label) const { label_offset_t::const_iterator it = offsets.find(label); assertion(it != offsets.end()); return (*it).second; } const label_offset_t& get_offsets() const { return offsets; } public: virtual void print(std::ostream& ostr) const = 0; protected: // FIXME: Might be static, to avoid multi-definition of labels. offset_label_t labels; label_offset_t offsets; }; inline std::ostream& operator<<(std::ostream& ostr, const Section& s) { s.print(ostr); return ostr; } } // namespace inst #endif // !INST_SECTION_HH