Gyoji Compiler
Loading...
Searching...
No Matches
gyoji-analysis.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#pragma once
16#include <gyoji-mir.hpp>
17#include <gyoji-context.hpp>
18
50namespace Gyoji::analysis {
51
52 // Ultimately, we will want to
53 // define a relation on program points
54 // so that:
55 // pp(x, a) < pp(x, a)
56 // pp(x, a) < pp(x, a+1)
57 // for all a. and pp(x,y) < pp(w,z)
58 // if and only if w is reachable from
59 // x through the control-flow graph.
60
61 class ProgramPoint {
62 public:
63 ProgramPoint(size_t _block_id, size_t _operation_index);
64 ProgramPoint(const ProgramPoint & other);
65 ~ProgramPoint();
66 size_t block_id;
67 size_t operation_index;
68 };
69
82 public:
84 virtual ~AnalysisPass();
85 virtual void check(const Gyoji::mir::MIR & mir) const = 0;
86
87 Gyoji::context::CompilerContext & get_compiler_context() const;
88 const std::string & get_name() const;
89 private:
90 Gyoji::context::CompilerContext & compiler_context;
91 std::string name;
92 };
93
105 public:
108
109 virtual void check(const Gyoji::mir::MIR & mir) const;
110 private:
111 void check_type(const Gyoji::mir::Type & type) const;
112 };
113
132 public:
134 virtual ~AnalysisPassUnreachable();
135
136 virtual void check(const Gyoji::mir::MIR & mir) const;
137 private:
138 void check(const Gyoji::mir::Function & function) const;
139 void check_all_blocks_reachable(
140 const Gyoji::mir::Function & function
141 ) const;
142 };
143
152 public:
155 virtual void check(const Gyoji::mir::MIR & mir) const;
156 private:
157 void check(const Gyoji::mir::Function & function) const;
158 };
159
170 public:
173 virtual void check(const Gyoji::mir::MIR & mir) const;
174 private:
175 void check(const Gyoji::mir::Function & function) const;
176 };
177
189 public:
192 virtual void check(const Gyoji::mir::MIR & mir) const;
193 private:
194 void check(const Gyoji::mir::Function & function) const;
195 };
196
209 public:
212 virtual void check(const Gyoji::mir::MIR & mir) const;
213 private:
214 bool true_at(
215 const Gyoji::mir::Function & function,
216 std::map<size_t, bool> & already_checked,
217 const std::vector<ProgramPoint> & true_points,
218 const ProgramPoint & check_at
219 ) const;
220
221 void check(const Gyoji::mir::Function & function) const;
222 };
223
224};
225
Performs the borrow-checker algorithm.
Definition gyoji-analysis.hpp:151
Performs checks for return-value consistency.
Definition gyoji-analysis.hpp:169
Check that all types have been fully declared before use.
Definition gyoji-analysis.hpp:104
Checks for the existence of unreachable code.
Definition gyoji-analysis.hpp:131
This pass ensures that all values are assigned before they are used.
Definition gyoji-analysis.hpp:208
This pass ensures that every variable that has been declared is also paired with an un-declare.
Definition gyoji-analysis.hpp:188
Abstract interface to analysis passes.
Definition gyoji-analysis.hpp:81
Compiler Context.
Definition gyoji-context.hpp:44
Function inside a translation unit.
Definition functions.hpp:342
The middle-tier intermediate representation (MIR) of a translation unit.
Definition gyoji-mir.hpp:71
This represents a type as declared in a translation unit.
Definition types.hpp:313
Analysis pass performs checks to ensure semantic consistency.
Definition analysis-return-values.cpp:36