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 19 namespace llvm { 20 class MCSymbol; 21 22 class MachineLocation { 23 private: 24 bool IsRegister; // True if location is a register. 25 unsigned Register; // gcc/gdb register number. 26 int Offset; // Displacement if not register. 27 public: 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 bool isIndirect() const { return !IsRegister; } 49 bool isReg() const { return IsRegister; } 50 unsigned getReg() const { return Register; } 51 int getOffset() const { return Offset; } 52 void setIsRegister(bool Is) { IsRegister = Is; } 53 void setRegister(unsigned R) { Register = R; } 54 void setOffset(int O) { Offset = O; } 55 /// Make this location a direct register location. 56 void set(unsigned R) { 57 IsRegister = true; 58 Register = R; 59 Offset = 0; 60 } 61 /// Make this location a register-indirect+offset location. 62 void set(unsigned R, int O) { 63 IsRegister = false; 64 Register = R; 65 Offset = O; 66 } 67 68 #ifndef NDEBUG 69 void dump(); 70 #endif 71 }; 72 } // End llvm namespace 73 74 #endif 75