Skip to content

Commit

Permalink
wip: almost done with Mutex hashmap
Browse files Browse the repository at this point in the history
NOTE: Reuse got_indices member from LlvmIndex instead
  • Loading branch information
CohenArthur committed Jun 20, 2024
1 parent 6ec6d7f commit c74571e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions compiler/plc_driver/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
fs::{self, File},
io::Write,
path::{Path, PathBuf},
sync::Mutex,
};

use crate::{CompileOptions, LinkOptions};
Expand Down Expand Up @@ -320,7 +321,7 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
unit: &CompilationUnit,
dependencies: &FxIndexSet<Dependency>,
literals: &StringLiterals,
got_layout: Option<&HashMap<String, u64>>,
got_layout: &Mutex<Option<HashMap<String, u64>>>,
) -> Result<GeneratedModule<'ctx>, Diagnostic> {
let mut code_generator = plc::codegen::CodeGen::new(
context,
Expand Down Expand Up @@ -392,6 +393,8 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
.map(|path| read_got_layout(&path, ConfigFormat::JSON))
.transpose()?;

let got_layout = Mutex::new(got_layout);

let res = targets
.par_iter()
.map(|target| {
Expand Down Expand Up @@ -431,7 +434,7 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
unit,
dependencies,
literals,
got_layout.as_ref(),
&got_layout,
)?;
module
.persist(
Expand All @@ -451,6 +454,10 @@ impl<T: SourceContainer + Sync> AnnotatedProject<T> {
})
.collect::<Result<Vec<_>, Diagnostic>>()?;

compile_options.got_layout_file.as_ref().map(|path| {
write_got_layout(got_layout.into_inner().unwrap().unwrap(), path, ConfigFormat::JSON)
});

Ok(res)
}

Expand Down
7 changes: 5 additions & 2 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
fs,
ops::Deref,
path::{Path, PathBuf},
sync::Mutex,
};

/// module to generate llvm intermediate representation for a CompilationUnit
Expand Down Expand Up @@ -111,7 +112,7 @@ impl<'ink> CodeGen<'ink> {
literals: &StringLiterals,
dependencies: &FxIndexSet<Dependency>,
global_index: &Index,
got_layout: Option<&HashMap<String, u64>>,
got_layout: &Mutex<Option<HashMap<String, u64>>>,
) -> Result<LlvmTypedIndex<'ink>, Diagnostic> {
let llvm = Llvm::new(context, context.create_builder());
let mut index = LlvmTypedIndex::default();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/llvm_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c74571e

Please sign in to comment.