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