xref: /aosp_15_r20/external/swiftshader/src/Vulkan/Debug/File.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1*03ce13f7SAndroid Build Coastguard Worker // Copyright 2019 The SwiftShader Authors. All Rights Reserved.
2*03ce13f7SAndroid Build Coastguard Worker //
3*03ce13f7SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*03ce13f7SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*03ce13f7SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*03ce13f7SAndroid Build Coastguard Worker //
7*03ce13f7SAndroid Build Coastguard Worker //    http://www.apache.org/licenses/LICENSE-2.0
8*03ce13f7SAndroid Build Coastguard Worker //
9*03ce13f7SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*03ce13f7SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*03ce13f7SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*03ce13f7SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*03ce13f7SAndroid Build Coastguard Worker // limitations under the License.
14*03ce13f7SAndroid Build Coastguard Worker 
15*03ce13f7SAndroid Build Coastguard Worker #ifndef VK_DEBUG_FILE_HPP_
16*03ce13f7SAndroid Build Coastguard Worker #define VK_DEBUG_FILE_HPP_
17*03ce13f7SAndroid Build Coastguard Worker 
18*03ce13f7SAndroid Build Coastguard Worker #include "ID.hpp"
19*03ce13f7SAndroid Build Coastguard Worker 
20*03ce13f7SAndroid Build Coastguard Worker #include <memory>
21*03ce13f7SAndroid Build Coastguard Worker #include <string>
22*03ce13f7SAndroid Build Coastguard Worker #include <unordered_set>
23*03ce13f7SAndroid Build Coastguard Worker 
24*03ce13f7SAndroid Build Coastguard Worker namespace vk {
25*03ce13f7SAndroid Build Coastguard Worker namespace dbg {
26*03ce13f7SAndroid Build Coastguard Worker 
27*03ce13f7SAndroid Build Coastguard Worker class File
28*03ce13f7SAndroid Build Coastguard Worker {
29*03ce13f7SAndroid Build Coastguard Worker public:
30*03ce13f7SAndroid Build Coastguard Worker 	using ID = dbg::ID<File>;
31*03ce13f7SAndroid Build Coastguard Worker 
32*03ce13f7SAndroid Build Coastguard Worker 	// createVirtual() returns a new file that is not backed by the filesystem.
33*03ce13f7SAndroid Build Coastguard Worker 	// name is the name of the file.
34*03ce13f7SAndroid Build Coastguard Worker 	// source is the content of the file.
35*03ce13f7SAndroid Build Coastguard Worker 	static std::shared_ptr<File> createVirtual(ID id, std::string name, std::string source);
36*03ce13f7SAndroid Build Coastguard Worker 
37*03ce13f7SAndroid Build Coastguard Worker 	// createPhysical() returns a new file that is backed by the file at path.
38*03ce13f7SAndroid Build Coastguard Worker 	static std::shared_ptr<File> createPhysical(ID id, std::string path);
39*03ce13f7SAndroid Build Coastguard Worker 
40*03ce13f7SAndroid Build Coastguard Worker 	// clearBreakpoints() removes all the breakpoints set on the file.
41*03ce13f7SAndroid Build Coastguard Worker 	// This function and addBreakpoint() is safe to call concurrently on
42*03ce13f7SAndroid Build Coastguard Worker 	// multiple threads.
43*03ce13f7SAndroid Build Coastguard Worker 	virtual void clearBreakpoints() = 0;
44*03ce13f7SAndroid Build Coastguard Worker 
45*03ce13f7SAndroid Build Coastguard Worker 	// addBreakpoint() adds a new line breakpoint at the line with the given
46*03ce13f7SAndroid Build Coastguard Worker 	// index.
47*03ce13f7SAndroid Build Coastguard Worker 	// This function and clearBreakpoints() is safe to call concurrently on
48*03ce13f7SAndroid Build Coastguard Worker 	// multiple threads.
49*03ce13f7SAndroid Build Coastguard Worker 	virtual void addBreakpoint(int line) = 0;
50*03ce13f7SAndroid Build Coastguard Worker 
51*03ce13f7SAndroid Build Coastguard Worker 	// hasBreakpoint() returns true iff the file has a breakpoint set at the
52*03ce13f7SAndroid Build Coastguard Worker 	// line with the given index.
53*03ce13f7SAndroid Build Coastguard Worker 	virtual bool hasBreakpoint(int line) const = 0;
54*03ce13f7SAndroid Build Coastguard Worker 
55*03ce13f7SAndroid Build Coastguard Worker 	// getBreakpoints() returns all the breakpoints set in the file.
56*03ce13f7SAndroid Build Coastguard Worker 	virtual std::unordered_set<int> getBreakpoints() const = 0;
57*03ce13f7SAndroid Build Coastguard Worker 
58*03ce13f7SAndroid Build Coastguard Worker 	// isVirtual() returns true iff the file is not backed by the filesystem.
59*03ce13f7SAndroid Build Coastguard Worker 	virtual bool isVirtual() const = 0;
60*03ce13f7SAndroid Build Coastguard Worker 
61*03ce13f7SAndroid Build Coastguard Worker 	// path() returns the path to the file, if backed by the filesystem,
62*03ce13f7SAndroid Build Coastguard Worker 	// otherwise and empty string.
63*03ce13f7SAndroid Build Coastguard Worker 	inline std::string path() const;
64*03ce13f7SAndroid Build Coastguard Worker 
65*03ce13f7SAndroid Build Coastguard Worker 	// The unique identifier of the file.
66*03ce13f7SAndroid Build Coastguard Worker 	const ID id;
67*03ce13f7SAndroid Build Coastguard Worker 
68*03ce13f7SAndroid Build Coastguard Worker 	// The directory of file if backed by the filesystem, otherwise an empty string.
69*03ce13f7SAndroid Build Coastguard Worker 	const std::string dir;
70*03ce13f7SAndroid Build Coastguard Worker 
71*03ce13f7SAndroid Build Coastguard Worker 	// The name of the file.
72*03ce13f7SAndroid Build Coastguard Worker 	const std::string name;
73*03ce13f7SAndroid Build Coastguard Worker 
74*03ce13f7SAndroid Build Coastguard Worker 	// The source of the file if not backed by the filesystem, otherwise an empty string.
75*03ce13f7SAndroid Build Coastguard Worker 	const std::string source;
76*03ce13f7SAndroid Build Coastguard Worker 
77*03ce13f7SAndroid Build Coastguard Worker 	virtual ~File() = default;
78*03ce13f7SAndroid Build Coastguard Worker 
79*03ce13f7SAndroid Build Coastguard Worker protected:
80*03ce13f7SAndroid Build Coastguard Worker 	inline File(ID id, std::string dir, std::string name, std::string source);
81*03ce13f7SAndroid Build Coastguard Worker };
82*03ce13f7SAndroid Build Coastguard Worker 
File(ID id,std::string dir,std::string name,std::string source)83*03ce13f7SAndroid Build Coastguard Worker File::File(ID id, std::string dir, std::string name, std::string source)
84*03ce13f7SAndroid Build Coastguard Worker     : id(std::move(id))
85*03ce13f7SAndroid Build Coastguard Worker     , dir(std::move(dir))
86*03ce13f7SAndroid Build Coastguard Worker     , name(std::move(name))
87*03ce13f7SAndroid Build Coastguard Worker     , source(source)
88*03ce13f7SAndroid Build Coastguard Worker {}
89*03ce13f7SAndroid Build Coastguard Worker 
path() const90*03ce13f7SAndroid Build Coastguard Worker std::string File::path() const
91*03ce13f7SAndroid Build Coastguard Worker {
92*03ce13f7SAndroid Build Coastguard Worker 	return (dir.size() > 0) ? (dir + "/" + name) : name;
93*03ce13f7SAndroid Build Coastguard Worker }
94*03ce13f7SAndroid Build Coastguard Worker 
95*03ce13f7SAndroid Build Coastguard Worker }  // namespace dbg
96*03ce13f7SAndroid Build Coastguard Worker }  // namespace vk
97*03ce13f7SAndroid Build Coastguard Worker 
98*03ce13f7SAndroid Build Coastguard Worker #endif  // VK_DEBUG_FILE_HPP_
99