Parameterize object_unittest to work for whatever target types are
[platform/upstream/binutils.git] / gold / target-select.h
1 // target-select.h -- select a target for an object file  -*- C++ -*-
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #ifndef GOLD_TARGET_SELECT_H
24 #define GOLD_TARGET_SELECT_H
25
26 namespace gold
27 {
28
29 class Target;
30
31 // We want to avoid a master list of targets, which implies using a
32 // global constructor.  And we also want the program to start up as
33 // quickly as possible, which implies avoiding global constructors.
34 // We compromise on a very simple global constructor.  We use a target
35 // selector, which specifies an ELF machine number and a recognition
36 // function.  We use global constructors to build a linked list of
37 // target selectors--a simple pointer list, not a std::list.
38
39 class Target_selector
40 {
41  public:
42   // Create a target selector for a specific machine number, size (32
43   // or 64), and endianness.  The machine number can be EM_NONE to
44   // test for any machine number.
45   Target_selector(int machine, int size, bool is_big_endian);
46
47   virtual ~Target_selector()
48   { }
49
50   // If we can handle this target, return a pointer to a target
51   // structure.  The size and endianness are known.
52   virtual Target* recognize(int machine, int osabi, int abiversion) = 0;
53
54   // Return the next Target_selector in the linked list.
55   Target_selector*
56   next() const
57   { return this->next_; }
58
59   // Return the machine number this selector is looking for, which can
60   // be EM_NONE to match any machine number.
61   int
62   machine() const
63   { return this->machine_; }
64
65   // Return the size this is looking for (32 or 64).
66   int
67   get_size() const
68   { return this->size_; }
69
70   // Return the endianness this is looking for.
71   bool
72   is_big_endian() const
73   { return this->is_big_endian_; }
74
75  private:
76   int machine_;
77   int size_;
78   bool is_big_endian_;
79   Target_selector* next_;
80 };
81
82 // Select the target for an ELF file.
83
84 extern Target* select_target(int machine, int size, bool big_endian,
85                              int osabi, int abiversion);
86
87 } // End namespace gold.
88
89 #endif // !defined(GOLD_TARGET_SELECT_H)