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

Method resolve_modules

src/compilation_pipeline.rs:455–555  ·  view source on GitHub ↗

Resolve `source`'s module imports. Each `alias := import("path")` adds its exported interface to the prelude and yields an export set for qualified access.

(&self, source: &str)

Source from the content-addressed store, hash-verified

453 Ok(assembled) => (Some(BinaryOutput { assembled }), None),
454 Err(e) => (None, Some(PipelineFailure::Linker(e))),
455 };
456
457 PipelineResult {
458 diagnostics,
459 lex,
460 parse,
461 ir,
462 asm,
463 binary,
464 failure,
465 }
466 }
467
468 /// Compile an IR program to RISC-V assembly text.
469 #[track_caller]
470 pub fn compile_ir_to_assembly(&self, ir: &IrProgram) -> Result<String, CodegenError> {
471 self.compile_ir_to_assembly_with_tokens(ir)
472 .map(|(assembly, _)| assembly)
473 }
474
475 /// Compile an IR program to assembly text and the structured token stream.
476 #[track_caller]
477 pub fn compile_ir_to_assembly_with_tokens(
478 &self,
479 ir: &IrProgram,
480 ) -> Result<(String, Vec<RvInstruction>), CodegenError> {
481 let mut compiler = CompilerRv64::new();
482 compiler.set_peephole(self.peephole);
483 compiler.set_register_allocation(self.register_allocation);
484 compiler.set_omit_frame_pointer(self.omit_frame_pointer);
485 let (asm, tokens) = compiler.compile_with_tokens(ir)?;
486 let stem = if let Some(existing) = self.current_artifact_stem() {
487 existing
488 } else {
489 let stem = self.default_artifact_stem(Location::caller(), "asm", &asm);
490 *self.last_artifact_stem.borrow_mut() = Some(stem.clone());
491 stem
492 };
493 self.write_text_artifact("asm", &stem, ".s", &asm);
494 Ok((asm, tokens))
495 }
496
497 /// Assemble a token stream into machine code.
498 #[track_caller]
499 pub fn assemble(&self, tokens: &[RvInstruction]) -> Result<AssembledOutput, AssemblerError> {
500 let stem = self.current_artifact_stem().unwrap_or_else(|| {
501 self.default_artifact_stem(Location::caller(), "obj", &format!("{}", tokens.len()))
502 });
503 self.assemble_named(&stem, tokens)
504 }
505
506 #[track_caller]
507 pub fn assemble_named(
508 &self,
509 stem: &str,
510 tokens: &[RvInstruction],
511 ) -> Result<AssembledOutput, AssemblerError> {
512 let mut assembled = Assembler::assemble(tokens)?;

Callers 2

compileMethod · 0.80
run_fullMethod · 0.80

Calls 9

collect_module_importsFunction · 0.85
module_keyFunction · 0.85
collect_exportsFunction · 0.85
resolve_module_sourceMethod · 0.80
module_member_aliasesFunction · 0.70
insertMethod · 0.45

Tested by

no test coverage detected