MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / compile_program

Method compile_program

crates/hll-to-ir/src/compiler/compiler.rs:151–261  ·  view source on GitHub ↗
(&mut self, program: &Program)

Source from the content-addressed store, hash-verified

149 source_lines: Vec::new(),
150 }
151 }
152
153 pub fn set_type_prelude(&mut self, types: Vec<(String, IrType)>) {
154 self.prelude_types = types;
155 }
156
157 /// Import aliases that resolve to the string module's format runtime.
158 pub fn set_format_aliases(&mut self, aliases: std::collections::HashSet<String>) {
159 self.format_aliases = aliases;
160 }
161
162 /// Name attributed to pc-to-source line markers emitted while lowering.
163 pub fn set_source_file(&mut self, file: &str) {
164 self.source_file = file.to_owned();
165 }
166
167 /// Lines added by the source prelude, subtracted from marker line numbers so
168 /// they index into the user's file (prelude statements are dropped).
169 pub fn set_source_line_offset(&mut self, lines: u32) {
170 self.source_line_offset = lines;
171 }
172
173 /// The user source (prelude-free), so lowering diagnostics can quote the
174 /// offending line. Line N of `source` backs a diagnostic on line N.
175 pub fn set_source_lines(&mut self, source: &str) {
176 self.source_lines = source.lines().map(str::to_owned).collect();
177 }
178}
179
180impl Default for HighLevelCompiler {
181 fn default() -> Self {
182 Self::new()
183 }
184}
185
186impl HighLevelCompiler {
187 pub fn compile_program(&mut self, program: &Program) -> Result<IrProgram, CompilerError> {
188 log::info!(
189 "Starting IR compilation for {} declarations",
190 program.declarations.len()
191 );
192
193 let mut semantic_analyzer = SemanticAnalyzer::new();
194 if semantic_analyzer.analyze_program(program).is_err() {
195 // Collect semantic diagnostics whole, keeping their spans and levels
196 for diagnostic in semantic_analyzer.diagnostics() {
197 self.context.diagnostics.push(diagnostic.clone());
198 }
199 log::warn!(
200 "Semantic analysis found errors, continuing with compilation for diagnostics"
201 );
202 }
203
204 self.context.reset_for_program();
205 self.context.types.register_types(&self.prelude_types);
206 self.next_temp = 0;
207 self.next_label = 0;
208 self.pending_global_strings.clear();

Calls 15

analyze_programMethod · 0.80
reset_for_programMethod · 0.80
register_typesMethod · 0.80
push_type_aliasMethod · 0.80
lower_typeMethod · 0.80
register_typeMethod · 0.80
register_enumMethod · 0.80
lower_return_typeMethod · 0.80
lower_declarationMethod · 0.80
push_global_stringMethod · 0.80
diagnosticsMethod · 0.45
errorMethod · 0.45