Skip to content

Commit

Permalink
wip: it works?
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Jun 21, 2024
1 parent c74571e commit 05bf702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub struct CodeGen<'ink> {

pub struct GeneratedModule<'ink> {
module: Module<'ink>,
got_layout: Option<HashMap<String, u64>>,
engine: RefCell<Option<ExecutionEngine<'ink>>>,
}

Expand Down Expand Up @@ -301,19 +300,15 @@ impl<'ink> CodeGen<'ink> {
}

#[cfg(not(feature = "verify"))]
Ok(GeneratedModule {
module: self.module,
got_layout: llvm_index.got_layout,
engine: RefCell::new(None),
})
Ok(GeneratedModule { module: self.module, engine: RefCell::new(None) })
}
}

impl<'ink> GeneratedModule<'ink> {
pub fn try_from_bitcode(context: &'ink CodegenContext, path: &Path) -> Result<Self, Diagnostic> {
let module = Module::parse_bitcode_from_path(path, context.deref())
.map_err(|it| Diagnostic::new(it.to_string_lossy()).with_error_code("E071"))?;
Ok(GeneratedModule { module, got_layout: None, engine: RefCell::new(None) })
Ok(GeneratedModule { module, engine: RefCell::new(None) })
}

pub fn try_from_ir(context: &'ink CodegenContext, path: &Path) -> Result<Self, Diagnostic> {
Expand All @@ -325,7 +320,7 @@ impl<'ink> GeneratedModule<'ink> {

log::debug!("{}", module.to_string());

Ok(GeneratedModule { module, got_layout: None, engine: RefCell::new(None) })
Ok(GeneratedModule { module, engine: RefCell::new(None) })
}

pub fn merge(self, other: GeneratedModule<'ink>) -> Result<Self, Diagnostic> {
Expand Down
8 changes: 3 additions & 5 deletions src/codegen/llvm_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ pub struct LlvmTypedIndex<'ink> {
type_associations: FxHashMap<String, BasicTypeEnum<'ink>>,
pou_type_associations: FxHashMap<String, BasicTypeEnum<'ink>>,
global_values: FxHashMap<String, GlobalValue<'ink>>,
// TODO: Should this be an Option?
got_indices: FxHashMap<String, u64>,
initial_value_associations: FxHashMap<String, BasicValueEnum<'ink>>,
loaded_variable_associations: FxHashMap<String, PointerValue<'ink>>,
implementations: FxHashMap<String, FunctionValue<'ink>>,
constants: FxHashMap<String, BasicValueEnum<'ink>>,
utf08_literals: FxHashMap<String, GlobalValue<'ink>>,
utf16_literals: FxHashMap<String, GlobalValue<'ink>>,
// TODO: Okay to have that field public?
pub got_layout: Option<HashMap<String, u64>>,
}

impl<'ink> LlvmTypedIndex<'ink> {
Expand All @@ -40,7 +39,6 @@ impl<'ink> LlvmTypedIndex<'ink> {
constants: FxHashMap::default(),
utf08_literals: FxHashMap::default(),
utf16_literals: FxHashMap::default(),
got_layout: todo!("create child with proper GOT layout: {:?}", parent.got_layout),
}
}

Expand All @@ -59,6 +57,8 @@ impl<'ink> LlvmTypedIndex<'ink> {
}
for (name, index) in other.got_indices.drain() {
self.got_indices.insert(name, index);

dbg!(&self.got_indices);
}
for (name, assocication) in other.initial_value_associations.drain() {
self.initial_value_associations.insert(name, assocication);
Expand All @@ -72,8 +72,6 @@ impl<'ink> LlvmTypedIndex<'ink> {
self.constants.extend(other.constants);
self.utf08_literals.extend(other.utf08_literals);
self.utf16_literals.extend(other.utf16_literals);

todo!("merge two got layouts together: {:?}", other.got_layout);
}

pub fn associate_type(
Expand Down

0 comments on commit 05bf702

Please sign in to comment.