From c74571ed34d32c8263267bf0d6d430582058b937 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Thu, 20 Jun 2024 18:47:28 +0200 Subject: [PATCH] wip: almost done with Mutex hashmap NOTE: Reuse got_indices member from LlvmIndex instead --- compiler/plc_driver/src/pipelines.rs | 11 +++++++++-- src/codegen.rs | 7 +++++-- src/codegen/llvm_index.rs | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/compiler/plc_driver/src/pipelines.rs b/compiler/plc_driver/src/pipelines.rs index a15e2f8e49..c11324b276 100644 --- a/compiler/plc_driver/src/pipelines.rs +++ b/compiler/plc_driver/src/pipelines.rs @@ -4,6 +4,7 @@ use std::{ fs::{self, File}, io::Write, path::{Path, PathBuf}, + sync::Mutex, }; use crate::{CompileOptions, LinkOptions}; @@ -320,7 +321,7 @@ impl AnnotatedProject { unit: &CompilationUnit, dependencies: &FxIndexSet, literals: &StringLiterals, - got_layout: Option<&HashMap>, + got_layout: &Mutex>>, ) -> Result, Diagnostic> { let mut code_generator = plc::codegen::CodeGen::new( context, @@ -392,6 +393,8 @@ impl AnnotatedProject { .map(|path| read_got_layout(&path, ConfigFormat::JSON)) .transpose()?; + let got_layout = Mutex::new(got_layout); + let res = targets .par_iter() .map(|target| { @@ -431,7 +434,7 @@ impl AnnotatedProject { unit, dependencies, literals, - got_layout.as_ref(), + &got_layout, )?; module .persist( @@ -451,6 +454,10 @@ impl AnnotatedProject { }) .collect::, Diagnostic>>()?; + compile_options.got_layout_file.as_ref().map(|path| { + write_got_layout(got_layout.into_inner().unwrap().unwrap(), path, ConfigFormat::JSON) + }); + Ok(res) } diff --git a/src/codegen.rs b/src/codegen.rs index af7fde9cef..6432abc95e 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -5,6 +5,7 @@ use std::{ fs, ops::Deref, path::{Path, PathBuf}, + sync::Mutex, }; /// module to generate llvm intermediate representation for a CompilationUnit @@ -111,7 +112,7 @@ impl<'ink> CodeGen<'ink> { literals: &StringLiterals, dependencies: &FxIndexSet, global_index: &Index, - got_layout: Option<&HashMap>, + got_layout: &Mutex>>, ) -> Result, Diagnostic> { let llvm = Llvm::new(context, context.create_builder()); let mut index = LlvmTypedIndex::default(); @@ -159,7 +160,7 @@ impl<'ink> CodeGen<'ink> { let all_names: Vec<_> = all_names.collect(); dbg!(all_names.len()); - if let Some(got_entries) = got_layout { + if let Some(got_entries) = &mut *got_layout.lock().unwrap() { // let got_entries = read_got_layout(location.as_str(), *format)?; let mut new_symbols = Vec::new(); let mut new_got_entries = HashMap::new(); @@ -200,6 +201,8 @@ impl<'ink> CodeGen<'ink> { got_size.try_into().expect("the computed custom GOT size is too large"), )), ); + + *got_entries = new_got_entries; } //Generate opaque functions for implementations and associate them with their types diff --git a/src/codegen/llvm_index.rs b/src/codegen/llvm_index.rs index 16897e87cd..55e270a064 100644 --- a/src/codegen/llvm_index.rs +++ b/src/codegen/llvm_index.rs @@ -73,7 +73,7 @@ impl<'ink> LlvmTypedIndex<'ink> { self.utf08_literals.extend(other.utf08_literals); self.utf16_literals.extend(other.utf16_literals); - todo!("merge two got layouts together") + todo!("merge two got layouts together: {:?}", other.got_layout); } pub fn associate_type(