LLVM API Documentation

MachineLocation.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MachineLocation.h -------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 // The MachineLocation class is used to represent a simple location in a machine
00010 // frame.  Locations will be one of two forms; a register or an address formed
00011 // from a base address plus an offset.  Register indirection can be specified by
00012 // explicitly passing an offset to the constructor.
00013 //===----------------------------------------------------------------------===//
00014 
00015 
00016 #ifndef LLVM_MC_MACHINELOCATION_H
00017 #define LLVM_MC_MACHINELOCATION_H
00018 
00019 namespace llvm {
00020   class MCSymbol;
00021 
00022 class MachineLocation {
00023 private:
00024   bool IsRegister;                      // True if location is a register.
00025   unsigned Register;                    // gcc/gdb register number.
00026   int Offset;                           // Displacement if not register.
00027 public:
00028   enum {
00029     // The target register number for an abstract frame pointer. The value is
00030     // an arbitrary value that doesn't collide with any real target register.
00031     VirtualFP = ~0U
00032   };
00033   MachineLocation()
00034     : IsRegister(false), Register(0), Offset(0) {}
00035   /// Create a direct register location.
00036   explicit MachineLocation(unsigned R)
00037     : IsRegister(true), Register(R), Offset(0) {}
00038   /// Create a register-indirect location with an offset.
00039   MachineLocation(unsigned R, int O)
00040     : IsRegister(false), Register(R), Offset(O) {}
00041 
00042   bool operator==(const MachineLocation &Other) const {
00043       return IsRegister == Other.IsRegister && Register == Other.Register &&
00044         Offset == Other.Offset;
00045   }
00046 
00047   // Accessors
00048   bool isIndirect()      const { return !IsRegister; }
00049   bool isReg()           const { return IsRegister; }
00050   unsigned getReg()      const { return Register; }
00051   int getOffset()        const { return Offset; }
00052   void setIsRegister(bool Is)  { IsRegister = Is; }
00053   void setRegister(unsigned R) { Register = R; }
00054   void setOffset(int O)        { Offset = O; }
00055   /// Make this location a direct register location.
00056   void set(unsigned R) {
00057     IsRegister = true;
00058     Register = R;
00059     Offset = 0;
00060   }
00061   /// Make this location a register-indirect+offset location.
00062   void set(unsigned R, int O) {
00063     IsRegister = false;
00064     Register = R;
00065     Offset = O;
00066   }
00067 
00068 #ifndef NDEBUG
00069   void dump();
00070 #endif
00071 };
00072 } // End llvm namespace
00073 
00074 #endif