| 1060 | ) -> Result<AssembledOutput, LinkerError> { |
| 1061 | let mut out = ObjectLinker::link(modules)?; |
| 1062 | let layout = self.effective_link_layout(); |
| 1063 | if layout.emit_layout_symbols { |
| 1064 | out.inject_layout_symbols(&layout); |
| 1065 | } |
| 1066 | out.mark_entry_global(self.effective_entry_point()); |
| 1067 | let stem = sanitize_artifact_component(stem); |
| 1068 | *self.last_artifact_stem.borrow_mut() = Some(stem.clone()); |
| 1069 | self.write_bytes_artifact( |
| 1070 | "elf", |
| 1071 | &format!("total_{stem}"), |
| 1072 | ".elf", |
| 1073 | &out.to_elf_with_entry(self.effective_load_base(), self.effective_entry_point()), |
| 1074 | ); |
| 1075 | Ok(out) |
| 1076 | } |
| 1077 | |
| 1078 | /// Compile multiple named modules independently, producing one `.o` per module. |
| 1079 | /// |
| 1080 | /// Returns assembled objects in input order, or the diagnostics from the first failed module. |
| 1081 | #[track_caller] |
| 1082 | pub fn compile_modules( |
| 1083 | &mut self, |
| 1084 | modules: &[(&str, &str)], |
| 1085 | ) -> Result<Vec<AssembledOutput>, CompilationError> { |
| 1086 | let mut result = Vec::with_capacity(modules.len()); |
| 1087 | |
| 1088 | for (module_name, source) in modules { |
| 1089 | self.set_artifact_stem(Some(module_name.to_string())); |
| 1090 | |
| 1091 | let compile_result = self.compile(source)?; |
| 1092 | |
| 1093 | let (_, tokens) = self.compile_ir_to_assembly_with_tokens(&compile_result.ir_program); |
| 1094 | |
| 1095 | let assembled = self |
| 1096 | .assemble_named(module_name, &tokens) |
| 1097 | .map_err(|e| CompilationError::FreestandingErrors(vec![e.message]))?; |
| 1098 | |
| 1099 | result.push(assembled); |
| 1100 | } |
| 1101 | |
| 1102 | Ok(result) |
| 1103 | } |
| 1104 | |
| 1105 | /// Compile a primary unit plus every module reachable through its qualified `import("path")` |
| 1106 | /// declarations (the link closure) into per-module objects, deps first, cycles rejected. |
| 1107 | #[track_caller] |
| 1108 | pub fn compile_program_closure( |
| 1109 | &mut self, |
| 1110 | primary_name: &str, |
| 1111 | primary_src: &str, |