blob: 3b79a92641196e44453c534d759d2f30166be662 [file] [log] [blame]
Jan Voung8acded02014-09-22 18:02:25 -07001//===- subzero/src/IceFixups.h - Assembler fixup kinds ----------*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
11/// This file declares generic fixup types.
12///
Jan Voung8acded02014-09-22 18:02:25 -070013//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICEFIXUPS_H
16#define SUBZERO_SRC_ICEFIXUPS_H
17
Jan Voungec270732015-01-12 17:00:22 -080018#include "IceDefs.h"
Jan Voung8acded02014-09-22 18:02:25 -070019
20namespace Ice {
21
Andrew Scull9612d322015-07-06 14:53:25 -070022/// Each target and container format has a different namespace of relocations.
23/// This holds the specific target+container format's relocation number.
Jan Voungec270732015-01-12 17:00:22 -080024typedef uint32_t FixupKind;
Jan Voung8acded02014-09-22 18:02:25 -070025
Andrew Scull9612d322015-07-06 14:53:25 -070026/// Assembler fixups are positions in generated code/data that hold relocation
27/// information that needs to be processed before finalizing the code/data.
Jan Voungec270732015-01-12 17:00:22 -080028struct AssemblerFixup {
Jim Stichnothc6ead202015-02-24 09:30:30 -080029 AssemblerFixup &operator=(const AssemblerFixup &) = delete;
30
Jan Voungec270732015-01-12 17:00:22 -080031public:
Jim Stichnotheafb56c2015-06-22 10:35:22 -070032 AssemblerFixup() = default;
Jim Stichnothc6ead202015-02-24 09:30:30 -080033 AssemblerFixup(const AssemblerFixup &) = default;
Jan Voungec270732015-01-12 17:00:22 -080034 intptr_t position() const { return position_; }
35 void set_position(intptr_t Position) { position_ = Position; }
36
37 FixupKind kind() const { return kind_; }
38 void set_kind(FixupKind Kind) { kind_ = Kind; }
39
40 RelocOffsetT offset() const;
41 IceString symbol(const GlobalContext *Ctx) const;
Jan Voungf644a4b2015-03-19 11:57:52 -070042
43 static const Constant *NullSymbol;
44 bool isNullSymbol() const { return value_ == NullSymbol; }
45
Jan Voungec270732015-01-12 17:00:22 -080046 void set_value(const Constant *Value) { value_ = Value; }
47
Jan Voungb7db1a52015-07-21 09:39:01 -070048 void emit(GlobalContext *Ctx, RelocOffsetT OverrideOffset) const;
Jan Voungec270732015-01-12 17:00:22 -080049
50private:
Jim Stichnotheafb56c2015-06-22 10:35:22 -070051 intptr_t position_ = 0;
52 FixupKind kind_ = 0;
53 const Constant *value_ = nullptr;
Jan Voung8acded02014-09-22 18:02:25 -070054};
55
Jan Voungec270732015-01-12 17:00:22 -080056typedef std::vector<AssemblerFixup> FixupList;
57typedef std::vector<AssemblerFixup *> FixupRefList;
58
Jan Voung8acded02014-09-22 18:02:25 -070059} // end of namespace Ice
60
61#endif // SUBZERO_SRC_ICEFIXUPS_H