MachineLocation.h revision 0a4371a2073d8841768cf3e8cf65601a8d7cc4fc
1//===-- llvm/MC/MachineLocation.h -------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// The MachineLocation class is used to represent a simple location in a machine 10// frame. Locations will be one of two forms; a register or an address formed 11// from a base address plus an offset. Register indirection can be specified by 12// explicitly passing an offset to the constructor. 13//===----------------------------------------------------------------------===// 14 15 16#ifndef LLVM_MC_MACHINELOCATION_H 17#define LLVM_MC_MACHINELOCATION_H 18 19namespace llvm { 20 class MCSymbol; 21 22class MachineLocation { 23private: 24 bool IsRegister; // True if location is a register. 25 unsigned Register; // gcc/gdb register number. 26 int Offset; // Displacement if not register. 27public: 28 enum { 29 // The target register number for an abstract frame pointer. The value is 30 // an arbitrary value that doesn't collide with any real target register. 31 VirtualFP = ~0U 32 }; 33 MachineLocation() 34 : IsRegister(false), Register(0), Offset(0) {} 35 /// Create a direct register location. 36 explicit MachineLocation(unsigned R) 37 : IsRegister(true), Register(R), Offset(0) {} 38 /// Create a register-indirect location with an offset. 39 MachineLocation(unsigned R, int O) 40 : IsRegister(false), Register(R), Offset(O) {} 41 42 bool operator==(const MachineLocation &Other) const { 43 return IsRegister == Other.IsRegister && Register == Other.Register && 44 Offset == Other.Offset; 45 } 46 47 // Accessors. 48 /// \return true iff this is a register-indirect location. 49 bool isIndirect() const { return !IsRegister; } 50 bool isReg() const { return IsRegister; } 51 unsigned getReg() const { return Register; } 52 int getOffset() const { return Offset; } 53 void setIsRegister(bool Is) { IsRegister = Is; } 54 void setRegister(unsigned R) { Register = R; } 55 void setOffset(int O) { Offset = O; } 56 /// Make this location a direct register location. 57 void set(unsigned R) { 58 IsRegister = true; 59 Register = R; 60 Offset = 0; 61 } 62 /// Make this location a register-indirect+offset location. 63 void set(unsigned R, int O) { 64 IsRegister = false; 65 Register = R; 66 Offset = O; 67 } 68 69#ifndef NDEBUG 70 void dump(); 71#endif 72}; 73} // End llvm namespace 74 75#endif 76