section.hh 2.22 KB
Newer Older
Benoit Perrot's avatar
Benoit Perrot committed
1
//
Benoit Perrot's avatar
Benoit Perrot committed
2
// This file is part of Nolimips, a MIPS simulator with unlimited registers
Benoit Perrot's avatar
Benoit Perrot committed
3
// Copyright (C) 2003, 2004, 2005 Benoit Perrot <benoit@lrde.epita.fr>
Benoit Perrot's avatar
Benoit Perrot committed
4
//
Benoit Perrot's avatar
Benoit Perrot committed
5
// Nolimips is free software; you can redistribute it and/or modify
Benoit Perrot's avatar
Benoit Perrot committed
6
7
8
9
// 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.
// 
Benoit Perrot's avatar
Benoit Perrot committed
10
// Nolimips is distributed in the hope that it will be useful,
Benoit Perrot's avatar
Benoit Perrot committed
11
12
13
14
15
16
17
18
19
20
21
// 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

22
# include <set>
Benoit Perrot's avatar
Benoit Perrot committed
23
24

# include "misc/contract.hh"
Benoit Perrot's avatar
Benoit Perrot committed
25
# include "misc/unique_string.hh"
Benoit Perrot's avatar
Benoit Perrot committed
26
27
28
29
30
31

# include "inst/label.hh"

namespace inst
{
  
Benoit Perrot's avatar
Benoit Perrot committed
32
  /// Abstract an assembly section
Benoit Perrot's avatar
Benoit Perrot committed
33
34
35
  class Section
  {
  protected:
36
    typedef std::set<const Label*, Label::deref_ptr_less> label_set_type;
37

Benoit Perrot's avatar
Benoit Perrot committed
38
  public:
Benoit Perrot's avatar
Benoit Perrot committed
39
40
    /// Construct an abstract section `\a name'
    Section(const std::string &name):
41
      name_(name)
Benoit Perrot's avatar
Benoit Perrot committed
42
    {}
43
    virtual ~Section();
Benoit Perrot's avatar
Benoit Perrot committed
44
45
    
  protected:
46
47
48
49
    /** Return false if the label already exists in this section, true
	otherwise */
    bool register_label(Label *label);

Benoit Perrot's avatar
Benoit Perrot committed
50
  public:
51
    bool	has_label(const misc::unique_string &label) const
Benoit Perrot's avatar
Benoit Perrot committed
52
    {
53
      Label dummy(label, 0);
Benoit Perrot's avatar
Benoit Perrot committed
54

55
56
      label_set_type::const_iterator it = sorted_labels_.find(&dummy);
      return it != sorted_labels_.end();
Benoit Perrot's avatar
Benoit Perrot committed
57
    }
58
    int		get_offset(const misc::unique_string &label) const
59
    {
60
61
62
63
64
      Label dummy(label, 0);

      label_set_type::const_iterator it = sorted_labels_.find(&dummy);
      assertion(it != sorted_labels_.end());
      return (*it)->get_offset();
65
66
    }

Benoit Perrot's avatar
Benoit Perrot committed
67
68
69
70
  public:
    virtual void	print(std::ostream& ostr) const = 0;

  protected:
71
    const misc::unique_string name_;
Benoit Perrot's avatar
Benoit Perrot committed
72

73
    label_set_type	sorted_labels_;
Benoit Perrot's avatar
Benoit Perrot committed
74
75
76
77
78
79
80
81
82
83
84
85
  };

  inline std::ostream&
  operator<<(std::ostream& ostr, const Section& s)
  {
    s.print(ostr);
    return ostr;
  }

} // namespace inst

#endif // !INST_SECTION_HH