1/* 2 * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef VALUE_LOCATION_H 6#define VALUE_LOCATION_H 7 8 9#include <Array.h> 10#include <Referenceable.h> 11 12#include "Types.h" 13 14 15enum value_piece_location_type { 16 VALUE_PIECE_LOCATION_INVALID, // structure is invalid 17 VALUE_PIECE_LOCATION_UNKNOWN, // location unknown, but size is valid 18 VALUE_PIECE_LOCATION_MEMORY, // piece is in memory 19 VALUE_PIECE_LOCATION_REGISTER // piece is in a register 20}; 21 22 23struct ValuePieceLocation { 24 union { 25 target_addr_t address; // memory address 26 uint32 reg; // register number 27 }; 28 target_size_t size; // size in bytes (including 29 // incomplete ones) 30 uint64 bitSize; // total size in bits 31 uint64 bitOffset; // bit offset (to the most 32 // significant bit) 33 value_piece_location_type type; 34 35 ValuePieceLocation() 36 : 37 type(VALUE_PIECE_LOCATION_INVALID) 38 { 39 } 40 41 bool IsValid() const 42 { 43 return type != VALUE_PIECE_LOCATION_INVALID; 44 } 45 46 void SetToUnknown() 47 { 48 type = VALUE_PIECE_LOCATION_UNKNOWN; 49 } 50 51 void SetToMemory(target_addr_t address) 52 { 53 type = VALUE_PIECE_LOCATION_MEMORY; 54 this->address = address; 55 } 56 57 void SetToRegister(uint32 reg) 58 { 59 type = VALUE_PIECE_LOCATION_REGISTER; 60 this->reg = reg; 61 } 62 63 void SetSize(target_size_t size) 64 { 65 this->size = size; 66 this->bitSize = size * 8; 67 this->bitOffset = 0; 68 } 69 70 void SetSize(uint64 bitSize, uint64 bitOffset) 71 { 72 this->size = (bitOffset + bitSize + 7) / 8; 73 this->bitSize = bitSize; 74 this->bitOffset = bitOffset; 75 } 76 77 ValuePieceLocation& Normalize(bool bigEndian); 78}; 79 80 81class ValueLocation : public BReferenceable { 82public: 83 ValueLocation(); 84 ValueLocation(bool bigEndian); 85 ValueLocation(bool bigEndian, 86 const ValuePieceLocation& piece); 87 ValueLocation(const ValueLocation& other); 88 89 bool SetTo(const ValueLocation& other, 90 uint64 bitOffset, uint64 bitSize); 91 92 void Clear(); 93 94 bool IsBigEndian() const { return fBigEndian; } 95 96 bool AddPiece(const ValuePieceLocation& piece); 97 98 int32 CountPieces() const; 99 ValuePieceLocation PieceAt(int32 index) const; 100 void SetPieceAt(int32 index, 101 const ValuePieceLocation& piece); 102 103 ValueLocation& operator=(const ValueLocation& other); 104 105 void Dump() const; 106 107private: 108 typedef Array<ValuePieceLocation> PieceArray; 109 110private: 111 PieceArray fPieces; 112 bool fBigEndian; 113}; 114 115 116#endif // VALUE_LOCATION_H 117