2008-02-18 H.J. Lu <hongjiu.lu@intel.com>
[binutils.git] / gold / target-select.h
blob5757d5b5d7f077fec784acb1153cf07948c35c28
1 // target-select.h -- select a target for an object file -*- C++ -*-
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_TARGET_SELECT_H
24 #define GOLD_TARGET_SELECT_H
26 namespace gold
29 class Target;
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.
39 class Target_selector
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);
47 virtual ~Target_selector()
48 { }
50 // If we can handle this target, return a pointer to a target
51 // structure. The size and endianness are known.
52 virtual Target*
53 recognize(int machine, int osabi, int abiversion) = 0;
55 // If NAME matches the target, return a pointer to a target
56 // structure.
57 virtual Target*
58 recognize_by_name(const char* name) = 0;
60 // Return the next Target_selector in the linked list.
61 Target_selector*
62 next() const
63 { return this->next_; }
65 // Return the machine number this selector is looking for, which can
66 // be EM_NONE to match any machine number.
67 int
68 machine() const
69 { return this->machine_; }
71 // Return the size this is looking for (32 or 64).
72 int
73 get_size() const
74 { return this->size_; }
76 // Return the endianness this is looking for.
77 bool
78 is_big_endian() const
79 { return this->is_big_endian_; }
81 private:
82 int machine_;
83 int size_;
84 bool is_big_endian_;
85 Target_selector* next_;
88 // Select the target for an ELF file.
90 extern Target* select_target(int machine, int size, bool big_endian,
91 int osabi, int abiversion);
93 // Select a target using a BFD name.
95 extern Target* select_target_by_name(const char* name);
97 } // End namespace gold.
99 #endif // !defined(GOLD_TARGET_SELECT_H)