1/*
2 * Copyright 2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef TYPE_UNIT_H
6#define TYPE_UNIT_H
7
8
9#include <ObjectList.h>
10#include <String.h>
11
12#include "BaseUnit.h"
13
14
15class DIETypeUnit;
16
17
18class TypeUnit : public BaseUnit {
19public:
20								TypeUnit(off_t headerOffset,
21									off_t contentOffset,
22									off_t totalSize,
23									off_t abbreviationOffset,
24									off_t typeOffset,
25									uint8 addressSize,
26									bool isBigEndian,
27									uint64 typeSignature,
28									bool isDwarf64);
29								~TypeUnit();
30
31			uint64				Signature() const	{ return fSignature; }
32
33			off_t				TypeOffset() const	{ return fTypeOffset; }
34
35
36			DIETypeUnit*		UnitEntry() const	{ return fUnitEntry; }
37			void				SetUnitEntry(DIETypeUnit* entry);
38
39			DebugInfoEntry*		TypeEntry() const;
40			void				SetTypeEntry(DebugInfoEntry* entry);
41
42	virtual	dwarf_unit_kind		Kind() const;
43
44private:
45			DIETypeUnit*		fUnitEntry;
46			DebugInfoEntry*		fTypeEntry;
47			uint64				fSignature;
48			off_t				fTypeOffset;
49};
50
51
52struct TypeUnitTableEntry {
53	uint64					signature;
54	TypeUnit*				unit;
55	TypeUnitTableEntry*		next;
56
57	TypeUnitTableEntry(uint64 signature, TypeUnit* unit)
58		:
59		signature(signature),
60		unit(unit)
61	{
62	}
63};
64
65
66struct TypeUnitTableHashDefinition {
67	typedef uint64					KeyType;
68	typedef	TypeUnitTableEntry		ValueType;
69
70	size_t HashKey(uint64 key) const
71	{
72		return (size_t)key;
73	}
74
75	size_t Hash(TypeUnitTableEntry* value) const
76	{
77		return HashKey(value->signature);
78	}
79
80	bool Compare(uint64 key, TypeUnitTableEntry* value) const
81	{
82		return value->signature == key;
83	}
84
85	TypeUnitTableEntry*& GetLink(TypeUnitTableEntry* value) const
86	{
87		return value->next;
88	}
89};
90
91
92#endif	// TYPE_UNIT_H
93