1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef FUNCTION_INSTANCE_H
6#define FUNCTION_INSTANCE_H
7
8#include <util/DoublyLinkedList.h>
9
10#include "FunctionDebugInfo.h"
11
12
13enum function_source_state {
14	FUNCTION_SOURCE_NOT_LOADED,
15	FUNCTION_SOURCE_LOADING,
16	FUNCTION_SOURCE_LOADED,
17	FUNCTION_SOURCE_UNAVAILABLE
18};
19
20
21class DisassembledCode;
22class Function;
23class FunctionDebugInfo;
24class FunctionID;
25class ImageDebugInfo;
26
27
28class FunctionInstance : public BReferenceable,
29	public DoublyLinkedListLinkImpl<FunctionInstance> {
30public:
31								FunctionInstance(ImageDebugInfo* imageDebugInfo,
32									FunctionDebugInfo* functionDebugInfo);
33								~FunctionInstance();
34
35			ImageDebugInfo*		GetImageDebugInfo() const
36									{ return fImageDebugInfo; }
37			Function*			GetFunction() const
38									{ return fFunction; }
39			FunctionDebugInfo*	GetFunctionDebugInfo() const
40									{ return fFunctionDebugInfo; }
41
42			target_addr_t		Address() const
43									{ return fFunctionDebugInfo->Address(); }
44			target_size_t		Size() const
45									{ return fFunctionDebugInfo->Size(); }
46			const BString&		Name() const
47									{ return fFunctionDebugInfo->Name(); }
48			const BString&		PrettyName() const
49									{ return fFunctionDebugInfo->PrettyName(); }
50			LocatableFile*		SourceFile() const
51									{ return fFunctionDebugInfo->SourceFile(); }
52			SourceLocation		GetSourceLocation() const
53									{ return fFunctionDebugInfo
54										->SourceStartLocation(); }
55
56			FunctionID*			GetFunctionID() const;
57									// returns a reference
58
59			void				SetFunction(Function* function);
60									// package private
61
62			// mutable attributes follow (locking required)
63			DisassembledCode*	GetSourceCode() const
64									{ return fSourceCode; }
65			function_source_state SourceCodeState() const
66									{ return fSourceCodeState; }
67			void				SetSourceCode(DisassembledCode* source,
68									function_source_state state);
69
70private:
71			ImageDebugInfo*		fImageDebugInfo;
72			Function*			fFunction;
73			FunctionDebugInfo*	fFunctionDebugInfo;
74			DisassembledCode*	fSourceCode;
75			function_source_state fSourceCodeState;
76};
77
78
79typedef DoublyLinkedList<FunctionInstance> FunctionInstanceList;
80
81
82#endif	// FUNCTION_INSTANCE_H
83