Skip to content

Commit 56d835b

Browse files
committed
more hacks
1 parent a501648 commit 56d835b

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

src/codegen.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,37 @@ impl<'ink> CodeGen<'ink> {
139139
// functions and assign them indices in the GOT, taking into account prior indices.
140140
let program_globals =
141141
global_index.get_program_instances().into_iter().fold(Vec::new(), |mut acc, p| {
142-
acc.push(p.get_name());
143-
acc.push(p.get_qualified_name());
142+
acc.push(p.get_name().to_owned());
143+
acc.push(p.get_qualified_name().to_owned());
144+
acc.push(format!("{}_instance", p.get_name()));
144145
acc
145146
});
147+
let test: Vec<_> =
148+
program_globals.clone().into_iter().map(|s| crate::index::get_initializer_name(&s)).collect();
149+
146150
let functions = global_index.get_pous().values().filter_map(|p| match p {
147151
PouIndexEntry::Function { name, linkage: LinkageType::Internal, is_generated: false, .. }
148152
| PouIndexEntry::FunctionBlock { name, linkage: LinkageType::Internal, .. } => {
149-
Some(name.as_ref())
153+
Some(String::from(name))
150154
}
151155
_ => None,
152156
});
153157
let all_names = global_index
154158
.get_globals()
155159
.values()
156160
.map(VariableIndexEntry::get_qualified_name)
161+
.map(String::from)
157162
.chain(program_globals)
158163
.chain(functions)
159-
.map(str::to_lowercase);
164+
.map(|s| s.to_lowercase())
165+
.map(|s| (crate::index::get_initializer_name(&s), s))
166+
.fold(Vec::new(), |mut acc, (s, s1)| {
167+
acc.push(s);
168+
acc.push(s1);
169+
acc
170+
});
160171

161-
let all_names: Vec<_> = all_names.collect();
162-
dbg!(all_names.len());
172+
// let all_names: Vec<_> = all_names.collect();
163173

164174
if let Some(got_entries) = &mut *got_layout.lock().unwrap() {
165175
// let got_entries = read_got_layout(location.as_str(), *format)?;

src/codegen/generators/pou_generator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub fn generate_global_constants_for_pou_members<'ink>(
133133
.make_constant()
134134
.set_initial_value(Some(value), variable_type);
135135
local_llvm_index.associate_global(&name, global_value)?;
136+
local_llvm_index.insert_new_got_index(&name)?;
136137
}
137138
}
138139
}
@@ -154,7 +155,7 @@ impl<'ink, 'cg> PouGenerator<'ink, 'cg> {
154155
}
155156

156157
fn mangle_function(&self, implementation: &ImplementationIndexEntry) -> Result<String, Diagnostic> {
157-
let ctx = SectionMangler::function(implementation.get_call_name());
158+
let ctx = SectionMangler::function(implementation.get_call_name().to_lowercase());
158159

159160
let params = self.index.get_declared_parameters(implementation.get_call_name());
160161

src/codegen/generators/variable_generator.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use indexmap::IndexSet;
1010
use inkwell::{module::Module, values::GlobalValue};
1111
use plc_ast::ast::LinkageType;
1212
use plc_diagnostics::diagnostics::Diagnostic;
13+
use section_mangler::SectionMangler;
1314

1415
use super::{
1516
data_type_generator::get_default_for,
@@ -171,8 +172,15 @@ impl<'ctx, 'b> VariableGenerator<'ctx, 'b> {
171172
}
172173
}
173174

174-
let section = section_mangler::SectionMangler::variable(
175-
global_variable.get_qualified_name(),
175+
let global_name = if global_variable.get_name().ends_with("instance") {
176+
global_variable.get_name()
177+
} else {
178+
global_variable.get_qualified_name()
179+
};
180+
let global_name = global_name.to_lowercase();
181+
182+
let section = SectionMangler::variable(
183+
global_name,
176184
section_names::mangle_type(
177185
self.global_index,
178186
self.global_index.get_effective_type_by_name(global_variable.get_type_name())?,

src/codegen/llvm_index.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ impl<'ink> LlvmTypedIndex<'ink> {
166166
self.global_values.insert(variable_name.to_lowercase(), global_variable);
167167
self.initial_value_associations
168168
.insert(variable_name.to_lowercase(), global_variable.as_pointer_value().into());
169+
170+
// FIXME: Do we want to call .insert_new_got_index() here?
171+
169172
Ok(())
170173
}
171174

@@ -174,6 +177,16 @@ impl<'ink> LlvmTypedIndex<'ink> {
174177
Ok(())
175178
}
176179

180+
pub fn insert_new_got_index(&mut self, variable_name: &str) -> Result<(), Diagnostic> {
181+
eprintln!("llvm_index: inserting {variable_name}");
182+
// FIXME: Does that start at 0 or 1?
183+
let idx = self.got_indices.values().max().copied().unwrap_or(0);
184+
185+
self.got_indices.insert(variable_name.to_lowercase(), idx);
186+
187+
Ok(())
188+
}
189+
177190
pub fn associate_implementation(
178191
&mut self,
179192
callable_name: &str,

0 commit comments

Comments
 (0)