add columns to debug information (#362)

- Add column numbers to debug information.
- Do not build allocas at entry for now.

---------

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-07-17 09:53:54 +02:00
committed by GitHub
parent a0396dd6d0
commit c285a6ec3d
17 changed files with 75 additions and 34 deletions
@@ -119,7 +119,7 @@ where
mut self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let value = match self.initializer.into_llvm(context)? {
Some(value) => value,
@@ -149,7 +149,7 @@ where
context.build_store(tuple_pointer, value)?;
for (index, binding) in self.bindings.into_iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let field_pointer = context.build_gep(
tuple_pointer,
+10 -3
View File
@@ -155,7 +155,10 @@ where
function.into_llvm(context)?;
}
context.set_current_function(current_function.as_str(), Some(self.location.line))?;
context.set_current_function(
current_function.as_str(),
Some((self.location.line, self.location.column)),
)?;
if let Some(debug_info) = context.debug_info() {
let di_builder = debug_info.builder();
@@ -169,12 +172,16 @@ where
)
.as_debug_info_scope();
context.push_debug_scope(di_block_scope);
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
}
context.set_basic_block(current_block);
for statement in local_statements.into_iter() {
context.set_debug_location(statement.location().line, 0, None)?;
context.set_debug_location(
statement.location().line,
statement.location().column,
None,
)?;
if context.basic_block().get_terminator().is_some() {
break;
}
@@ -123,7 +123,7 @@ impl FunctionCall {
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let location = self.location;
context.set_debug_location(location.line, 0, None)?;
context.set_debug_location(location.line, location.column, None)?;
match self.name {
Name::UserDefined(name) => {
@@ -72,6 +72,7 @@ where
let increment_block = context.append_basic_block("for_increment");
let join_block = context.append_basic_block("for_join");
context.set_debug_location(self.location.line, self.location.column, None)?;
context.build_unconditional_branch(condition_block);
context.set_basic_block(condition_block);
let condition = self
@@ -80,6 +81,7 @@ where
.expect("Always exists")
.access(context)?
.into_int_value();
context.set_debug_location(self.location.line, self.location.column, None)?;
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.word_type(),
@@ -98,10 +100,12 @@ where
context.set_basic_block(body_block);
self.body.into_llvm(context)?;
context.build_unconditional_branch(increment_block);
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(increment_block);
self.finalizer.into_llvm(context)?;
context.build_unconditional_branch(condition_block);
context.set_debug_location(self.location.line, self.location.column, None)?;
context.pop_loop();
context.set_basic_block(join_block);
@@ -212,6 +212,7 @@ where
function_type,
self.result.len(),
Some(inkwell::module::Linkage::External),
Some((self.location.line, self.location.column)),
)?;
revive_llvm_context::PolkaVMFunction::set_attributes(
context.llvm(),
@@ -230,7 +231,10 @@ where
mut self,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_current_function(self.identifier.as_str(), Some(self.location.line))?;
context.set_current_function(
self.identifier.as_str(),
Some((self.location.line, self.location.column)),
)?;
context.set_basic_block(context.current_function().borrow().entry_block());
let r#return = context.current_function().borrow().r#return();
@@ -290,7 +294,7 @@ where
}
self.body.into_llvm(context)?;
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
match context
.basic_block()
@@ -53,13 +53,13 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, 0, None)?;
let condition = self
.condition
.into_llvm(context)?
.expect("Always exists")
.access(context)?
.into_int_value();
context.set_debug_location(self.location.line, self.location.column, None)?;
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.word_type(),
+2 -2
View File
@@ -279,17 +279,17 @@ where
context.push_debug_scope(object_scope.as_debug_info_scope());
}
context.set_debug_location(self.location.line, self.location.column, None)?;
if self.identifier.ends_with("_deployed") {
revive_llvm_context::PolkaVMRuntimeCodeFunction::new(self.code).into_llvm(context)?;
} else {
revive_llvm_context::PolkaVMDeployCodeFunction::new(self.code).into_llvm(context)?;
}
context.set_debug_location(self.location.line, 0, None)?;
if let Some(object) = self.inner_object {
object.into_llvm(context)?;
}
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.pop_debug_scope();
@@ -123,6 +123,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, self.location.column, None)?;
let scrutinee = self.expression.into_llvm(context)?;
if self.cases.is_empty() {
@@ -143,6 +144,7 @@ where
.append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str());
context.set_basic_block(expression_block);
case.block.into_llvm(context)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.build_unconditional_branch(join_block);
branches.push((constant.into_int_value(), expression_block));
@@ -159,6 +161,7 @@ where
None => join_block,
};
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(current_block);
context.builder().build_switch(
scrutinee
@@ -169,6 +172,7 @@ where
branches.as_slice(),
)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
context.set_basic_block(join_block);
Ok(())
@@ -101,7 +101,7 @@ where
) -> anyhow::Result<()> {
if self.bindings.len() == 1 {
let identifier = self.bindings.remove(0);
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let identifier_type = identifier.r#type.clone().unwrap_or_default();
let r#type = identifier_type.into_llvm(context);
let pointer = context.build_alloca(r#type, identifier.inner.as_str());
@@ -133,7 +133,7 @@ where
}
for (index, binding) in self.bindings.iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?;
context.set_debug_location(self.location.line, self.location.column, None)?;
let yul_type = binding
.r#type