docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
src_file_compiler.h
Go to the documentation of this file.
1#pragma once
3
7
8namespace docc::compile {
9
10class SrcFileCompiler;
11
13
15 friend class SrcFileCompiler;
16 SrcFileCompiler& compiler_;
17 const sdfg::codegen::CodeSnippet* snippet_;
18 std::filesystem::path src_path_;
19 std::filesystem::path out_path_;
20 FileCompileOutputType output_type_;
21 std::function<void(std::ostream&)> generator_;
22 int codegen_order_;
23 int compile_min_order_;
24
25 bool src_done_ = false;
26 bool obj_done_ = false;
27
28 std::chrono::duration<std::chrono::milliseconds::rep, std::chrono::milliseconds::period> gen_time_;
29 std::chrono::duration<std::chrono::milliseconds::rep, std::chrono::milliseconds::period> build_time_;
30
31public:
33 SrcFileCompiler& compiler,
34 const sdfg::codegen::CodeSnippet* snippet,
35 const std::filesystem::path& src_path,
36 const std::filesystem::path& obj_path,
37 FileCompileOutputType output_type,
38 int codegen_order,
40 std::function<void(std::ostream&)>& generator
41 );
42
43 [[nodiscard]] CodegenCompiler& creator() const override;
44
45 bool codegen() override;
46
47 bool has_compile_action() override;
48
49 bool compile() override;
50
51 int codegen_order() const override { return codegen_order_; }
52 int compile_min_order() const override { return compile_min_order_; }
53
54 const std::filesystem::path& out_path() const;
55
56 bool has_obj_to_link() const;
57
59};
60
62public:
63 virtual const std::vector<std::string>* get_contributed_link_options() const = 0;
64};
65
67 friend class FileCompileState;
68
69 std::filesystem::path output_dir_;
70 std::optional<std::string> compiler_;
71 std::optional<std::string> linker_;
72 std::string common_args_;
73 std::string compile_args_;
74 std::vector<LibPath> library_paths_;
75 std::vector<std::string> link_options_;
76 std::optional<std::string> main_src_ext_;
77 std::string main_header_ext_;
78 std::string bin_ext_;
79 bool link_immediately_;
80 int codegen_order_;
81 int compile_min_order_;
82 std::unordered_map<std::string, std::unique_ptr<SrcFileCompiler>> redirects_;
83 std::vector<std::string> parent_link_opts_;
84 sdfg::passes::CodegenStatistics* stats_ = nullptr;
85
86 // When set, existing source files on disk are recompiled as-is instead of
87 // being regenerated (allows recompiling possibly hand-edited sources).
88 bool reuse_sources_ = false;
89
90 inline static constexpr auto COMPILE_ONLY_FLAG = "-c";
91 inline static constexpr auto OUTPUT_FILE_ARG = "-o";
92
93public:
95 const std::filesystem::path& output_dir,
96 const std::optional<std::string>& main_src_ext,
97 const std::string& main_header_ext,
98 const std::string& bin_ext,
99 const std::optional<std::string>& compiler,
100 const std::optional<std::string>& linker,
101 const std::string& common_args,
102 const std::string& compile_args,
103 const std::vector<LibPath>& library_paths,
104 const std::vector<std::string>& link_options,
105 bool link_immediately,
106 std::unordered_map<std::string, std::unique_ptr<SrcFileCompiler>>&& redirects,
107 const std::vector<std::string>& parent_link_options,
108 int codegen_order = 0,
109 int compile_min_order = 0
110 );
111
112 std::unique_ptr<CompileState> create_compile(
114 const sdfg::codegen::CodeSnippet* snippet,
115 std::function<void(std::ostream&)> generator
116 ) override;
117
118 std::unique_ptr<CompileState> do_create_compile(
120 const sdfg::codegen::CodeSnippet* snippet,
121 std::function<void(std::ostream&)> generator
122 );
123
124 std::filesystem::path process(
126 CompileExecutor& executor,
127 const std::string& output_file_name,
128 bool reuse_sources = false
129 );
130 std::filesystem::path process(sdfg::codegen::CodeGenerator& generator, CompileExecutor& executor) {
131 return process(generator, executor, generator.sdfg().name());
132 }
133
134 std::shared_ptr<sdfg::codegen::CodeSnippetFactory> create_snippet_factory(const sdfg::StructuredSDFG& sdfg) const;
135
136 const std::vector<std::string>* get_contributed_link_options() const override;
137
138protected:
139 std::filesystem::path generate_header_path(const sdfg::StructuredSDFG& sdfg) const;
140 bool run_compiler(const std::filesystem::path& src, const std::filesystem::path& obj) const;
141
142 void add_link_args(std::stringstream& cmd) const;
143
144 bool run_link(const sdfg::StructuredSDFG& sdfg, CompileExecutor& executor, const std::filesystem::path& bin_file)
145 const;
146 bool run_compile_and_link_single(const std::filesystem::path& src, const std::filesystem::path& bin) const;
147 std::filesystem::path emit_header(const sdfg::StructuredSDFG& sdfg, sdfg::codegen::CodeGenerator& generator);
150 CompileExecutor& executor,
151 std::function<void(const sdfg::codegen::CodeSnippet&)> callback
152 );
153};
154
155} // namespace docc::compile
Definition codegen_compiler.h:27
Definition codegen_build_pool.h:17
Definition codegen_compiler.h:11
CodegenCompiler & creator() const override
void record_stats(const sdfg::StructuredSDFG &sdfg, sdfg::passes::CodegenStatistics &stats)
const std::filesystem::path & out_path() const
int compile_min_order() const override
Definition src_file_compiler.h:52
int codegen_order() const override
Definition src_file_compiler.h:51
FileCompileState(SrcFileCompiler &compiler, const sdfg::codegen::CodeSnippet *snippet, const std::filesystem::path &src_path, const std::filesystem::path &obj_path, FileCompileOutputType output_type, int codegen_order, int compile_min_order, std::function< void(std::ostream &)> &generator)
friend class SrcFileCompiler
Definition src_file_compiler.h:15
bool has_compile_action() override
Definition src_file_compiler.h:61
virtual const std::vector< std::string > * get_contributed_link_options() const =0
Definition src_file_compiler.h:66
std::filesystem::path process(sdfg::codegen::CodeGenerator &generator, CompileExecutor &executor)
Definition src_file_compiler.h:130
SrcFileCompiler(const std::filesystem::path &output_dir, const std::optional< std::string > &main_src_ext, const std::string &main_header_ext, const std::string &bin_ext, const std::optional< std::string > &compiler, const std::optional< std::string > &linker, const std::string &common_args, const std::string &compile_args, const std::vector< LibPath > &library_paths, const std::vector< std::string > &link_options, bool link_immediately, std::unordered_map< std::string, std::unique_ptr< SrcFileCompiler > > &&redirects, const std::vector< std::string > &parent_link_options, int codegen_order=0, int compile_min_order=0)
bool run_link(const sdfg::StructuredSDFG &sdfg, CompileExecutor &executor, const std::filesystem::path &bin_file) const
bool run_compile_and_link_single(const std::filesystem::path &src, const std::filesystem::path &bin) const
bool run_compiler(const std::filesystem::path &src, const std::filesystem::path &obj) const
std::filesystem::path emit_header(const sdfg::StructuredSDFG &sdfg, sdfg::codegen::CodeGenerator &generator)
std::unique_ptr< CompileState > do_create_compile(const sdfg::StructuredSDFG &sdfg, const sdfg::codegen::CodeSnippet *snippet, std::function< void(std::ostream &)> generator)
std::unique_ptr< CompileState > create_compile(const sdfg::StructuredSDFG &sdfg, const sdfg::codegen::CodeSnippet *snippet, std::function< void(std::ostream &)> generator) override
void add_link_args(std::stringstream &cmd) const
friend class FileCompileState
Definition src_file_compiler.h:67
std::shared_ptr< sdfg::codegen::CodeSnippetFactory > create_snippet_factory(const sdfg::StructuredSDFG &sdfg) const
std::filesystem::path generate_header_path(const sdfg::StructuredSDFG &sdfg) const
void for_each_file_snippet(sdfg::codegen::CodeGenerator &generator, CompileExecutor &executor, std::function< void(const sdfg::codegen::CodeSnippet &)> callback)
std::filesystem::path process(sdfg::codegen::CodeGenerator &generator, CompileExecutor &executor, const std::string &output_file_name, bool reuse_sources=false)
const std::vector< std::string > * get_contributed_link_options() const override
const std::string & name() const
Definition structured_sdfg.h:30
Base class for code generators.
Definition code_generator.h:23
const StructuredSDFG & sdfg() const
Definition code_generator.h:69
Definition code_snippet_factory.h:15
Definition statistics.h:222
Definition targets.h:8
FileCompileOutputType
Definition src_file_compiler.h:12
@ LinkedArtifact
Definition src_file_compiler.h:12
@ ObjectFile
Definition src_file_compiler.h:12
@ SrcOnly
Definition src_file_compiler.h:12
Definition analysis.h:7