Skip to content

Commit bb5221f

Browse files
committed
prepare alignment removal for dbg
1 parent e0d9623 commit bb5221f

File tree

5 files changed

+87
-69
lines changed

5 files changed

+87
-69
lines changed

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__multi_files__multiple_files_in_different_locations_with_debug_info.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4343
!11 = !DIFile(filename: "file1.st", directory: "app")
4444
!12 = !DISubroutineType(flags: DIFlagPublic, types: !13)
4545
!13 = !{null}
46-
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15, align: 16)
46+
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15)
4747
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
4848
!16 = !DILocation(line: 2, column: 13, scope: !10)
4949
!17 = !DILocation(line: 10, column: 4, scope: !10)

compiler/plc_driver/src/tests/snapshots/plc_driver__tests__multi_files__multiple_files_with_debug_info.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
4343
!11 = !DIFile(filename: "file1.st", directory: "")
4444
!12 = !DISubroutineType(flags: DIFlagPublic, types: !13)
4545
!13 = !{null}
46-
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15, align: 16)
46+
!14 = !DILocalVariable(name: "main", scope: !10, file: !11, line: 2, type: !15)
4747
!15 = !DIBasicType(name: "INT", size: 16, encoding: DW_ATE_signed, flags: DIFlagPublic)
4848
!16 = !DILocation(line: 2, column: 13, scope: !10)
4949
!17 = !DILocation(line: 10, column: 4, scope: !10)

src/codegen/debug.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ impl<'ink> DebugBuilder<'ink> {
298298

299299
//Adjust the offset based on the field alignment
300300
let type_info = dt.get_type_information();
301-
let alignment = type_info.get_alignment(index);
301+
// let alignment = type_info.get_alignment(index);
302302
let size = type_info.get_size(index).unwrap();
303-
running_offset = running_offset.align_to(alignment);
303+
// TODO: alignment
304+
// running_offset = running_offset.align_to(alignment);
304305

305306
types.push(
306307
self.debug_info
@@ -310,7 +311,9 @@ impl<'ink> DebugBuilder<'ink> {
310311
file,
311312
location.get_line_plus_one() as u32,
312313
size.bits().into(),
313-
alignment.bits(),
314+
// TODO: alignment
315+
// alignment.bits(),
316+
0, // no alignment for now
314317
running_offset.bits().into(),
315318
DIFlags::PUBLIC,
316319
di_type.into(),
@@ -320,7 +323,8 @@ impl<'ink> DebugBuilder<'ink> {
320323
running_offset += size;
321324
}
322325

323-
let struct_dt = index.get_type_information_or_void(name);
326+
// TODO: alignment
327+
// let struct_dt = index.get_type_information_or_void(name);
324328

325329
//Create a struct type
326330
let struct_type = self.debug_info.create_struct_type(
@@ -329,7 +333,9 @@ impl<'ink> DebugBuilder<'ink> {
329333
file,
330334
location.get_line_plus_one() as u32,
331335
running_offset.bits().into(),
332-
struct_dt.get_alignment(index).bits(),
336+
// TODO: alignment
337+
0, // no alignment for now
338+
// struct_dt.get_alignment(index).bits(),
333339
DIFlags::PUBLIC,
334340
None,
335341
types.as_slice(),
@@ -458,7 +464,9 @@ impl<'ink> DebugBuilder<'ink> {
458464
file,
459465
location.get_line_plus_one() as u32,
460466
file.as_debug_info_scope(),
461-
inner_dt.get_type_information().get_alignment(index).bits(),
467+
// TODO: alignment
468+
0, // no alignment for now
469+
// inner_dt.get_type_information().get_alignment(index).bits(),
462470
);
463471
self.register_concrete_type(name, DebugType::Derived(typedef));
464472

@@ -542,11 +550,12 @@ impl<'ink> DebugBuilder<'ink> {
542550
.iter()
543551
.filter(|it| it.is_local() || it.is_temp() || it.is_return())
544552
{
545-
let var_type = index
546-
.find_effective_type_by_name(variable.get_type_name())
547-
.expect("Type should exist at this stage");
548-
let alignment = var_type.get_type_information().get_alignment(index).bits();
549-
self.register_local_variable(variable, alignment, func);
553+
// TODO: alignment
554+
// let var_type = index
555+
// .find_effective_type_by_name(variable.get_type_name())
556+
// .expect("Type should exist at this stage");
557+
// let alignment = var_type.get_type_information().get_alignment(index).bits();
558+
self.register_local_variable(variable, 0, func);
550559
}
551560

552561
let implementation = pou.find_implementation(index).expect("A POU will have an impl at this stage");
@@ -639,17 +648,18 @@ impl<'ink> Debug<'ink> for DebugBuilder<'ink> {
639648
if !self.types.contains_key(&name.to_lowercase()) {
640649
let type_info = datatype.get_type_information();
641650
let size = type_info.get_size(index).unwrap();
642-
let alignment = type_info.get_alignment(index);
651+
// TODO: alignment
652+
// let alignment = type_info.get_alignment(index);
643653
let location = &datatype.location;
644654
match type_info {
645655
DataTypeInformation::Struct { members, .. } => {
646656
self.create_struct_type(name, members.as_slice(), index, location)
647657
}
648658
DataTypeInformation::Array { name, inner_type_name, dimensions, .. } => {
649-
self.create_array_type(name, inner_type_name, dimensions, size, alignment, index)
659+
self.create_array_type(name, inner_type_name, dimensions, size, Bytes::new(0), index)
650660
}
651661
DataTypeInformation::Pointer { name, inner_type_name, .. } => {
652-
self.create_pointer_type(name, inner_type_name, size, alignment, index)
662+
self.create_pointer_type(name, inner_type_name, size, Bytes::new(0), index)
653663
}
654664
DataTypeInformation::Integer { signed, size, .. } => {
655665
let encoding = if type_info.is_bool() {
@@ -671,7 +681,9 @@ impl<'ink> Debug<'ink> for DebugBuilder<'ink> {
671681
let length = string_size
672682
.as_int_value(index)
673683
.map_err(|err| Diagnostic::codegen_error(err, SourceLocation::undefined()))?;
674-
self.create_string_type(name, length, *encoding, size, alignment, index)
684+
// TODO: alignment
685+
// TODO does this break strings?
686+
self.create_string_type(name, length, *encoding, size, Bytes::new(0), index)
675687
}
676688
DataTypeInformation::Alias { name, referenced_type }
677689
| DataTypeInformation::Enum { name, referenced_type, .. } => {

src/datalayout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ mod tests {
187187
let struct_type = index.get_effective_type_by_name("MyStruct").unwrap().get_type_information();
188188
// And the struct size takes the alignment into account
189189
assert_eq!(struct_type.get_size(&index).unwrap().bits(), 192);
190-
assert_eq!(struct_type.get_alignment(&index), Bytes::new(8)) //Struct alignment is 64 by default
190+
// TODO: alignment
191+
// assert_eq!(struct_type.get_alignment(&index), Bytes::new(8)) //Struct alignment is 64 by default
191192
}
192193
}

src/typesystem.rs

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,13 @@ impl DataTypeInformation {
642642
DataTypeInformation::Struct { members, .. } => members
643643
.iter()
644644
.map(|it| it.get_type_name())
645-
.try_fold(MemoryLocation::new(0), |prev, it| {
645+
.try_fold(MemoryLocation::new(0), |_, it| {
646646
let type_info: &DataTypeInformation = index.get_type_information_or_void(it);
647647
let size = type_info.get_size_recursive(index, seen)?.value();
648-
let after_align = prev.align_to(type_info.get_alignment(index)).value();
649-
let res = after_align + size;
650-
Ok(MemoryLocation::new(res))
648+
// TODO: alignment
649+
// let after_align = prev.align_to(type_info.get_alignment(index)).value();
650+
// let res = after_align + size;
651+
Ok(MemoryLocation::new(size))
651652
})
652653
.map(Into::into),
653654
DataTypeInformation::Array { inner_type_name, dimensions, .. } => {
@@ -683,53 +684,57 @@ impl DataTypeInformation {
683684
}
684685
}
685686

686-
pub fn get_alignment(&self, index: &Index) -> Bytes {
687-
if self.get_size(index).unwrap_or_default().value() == 0 {
688-
return Bytes::new(0);
689-
}
690-
691-
let type_layout = index.get_type_layout();
692-
match self {
693-
DataTypeInformation::Array { inner_type_name, .. } => {
694-
index.get_type_information_or_void(inner_type_name).get_alignment(index)
695-
}
696-
DataTypeInformation::Struct { .. } => type_layout.aggregate,
697-
DataTypeInformation::String { encoding, .. } => match encoding {
698-
StringEncoding::Utf8 => Bytes::new(1),
699-
StringEncoding::Utf16 => Bytes::new(2),
700-
},
701-
DataTypeInformation::Pointer { .. } => type_layout.p64,
702-
DataTypeInformation::Integer { size, semantic_size, .. } => {
703-
if let Some(1) = semantic_size {
704-
type_layout.i1
705-
} else {
706-
match size {
707-
8 => type_layout.i8,
708-
16 => type_layout.i16,
709-
32 => type_layout.i32,
710-
64 => type_layout.i64,
711-
_ => type_layout.p64,
712-
}
713-
}
714-
}
715-
DataTypeInformation::Enum { referenced_type, .. } => {
716-
index.get_type_information_or_void(referenced_type).get_alignment(index)
717-
}
718-
DataTypeInformation::Float { size, .. } => match size {
719-
32 => type_layout.f32,
720-
64 => type_layout.f64,
721-
_ => type_layout.p64,
722-
},
723-
DataTypeInformation::SubRange { referenced_type, .. } => {
724-
index.get_type_information_or_void(referenced_type).get_alignment(index)
725-
}
726-
DataTypeInformation::Alias { referenced_type, .. } => {
727-
index.get_type_information_or_void(referenced_type).get_alignment(index)
728-
}
729-
_ => type_layout.i8,
730-
}
731-
}
732-
687+
// TODO: alignment
688+
// pub fn get_alignment(&self, index: &Index) -> Bytes {
689+
// if true {
690+
// return Bytes::new(0);
691+
// }
692+
// if self.get_size(index).unwrap_or_default().value() == 0 {
693+
// return Bytes::new(0);
694+
// }
695+
//
696+
// let type_layout = index.get_type_layout();
697+
// match self {
698+
// DataTypeInformation::Array { inner_type_name, .. } => {
699+
// index.get_type_information_or_void(inner_type_name).get_alignment(index)
700+
// }
701+
// DataTypeInformation::Struct { .. } => type_layout.aggregate,
702+
// DataTypeInformation::String { encoding, .. } => match encoding {
703+
// StringEncoding::Utf8 => Bytes::new(1),
704+
// StringEncoding::Utf16 => Bytes::new(2),
705+
// },
706+
// DataTypeInformation::Pointer { .. } => type_layout.p64,
707+
// DataTypeInformation::Integer { size, semantic_size, .. } => {
708+
// if let Some(1) = semantic_size {
709+
// type_layout.i1
710+
// } else {
711+
// match size {
712+
// 8 => type_layout.i8,
713+
// 16 => type_layout.i16,
714+
// 32 => type_layout.i32,
715+
// 64 => type_layout.i64,
716+
// _ => type_layout.p64,
717+
// }
718+
// }
719+
// }
720+
// DataTypeInformation::Enum { referenced_type, .. } => {
721+
// index.get_type_information_or_void(referenced_type).get_alignment(index)
722+
// }
723+
// DataTypeInformation::Float { size, .. } => match size {
724+
// 32 => type_layout.f32,
725+
// 64 => type_layout.f64,
726+
// _ => type_layout.p64,
727+
// },
728+
// DataTypeInformation::SubRange { referenced_type, .. } => {
729+
// index.get_type_information_or_void(referenced_type).get_alignment(index)
730+
// }
731+
// DataTypeInformation::Alias { referenced_type, .. } => {
732+
// index.get_type_information_or_void(referenced_type).get_alignment(index)
733+
// }
734+
// _ => type_layout.i8,
735+
// }
736+
// }
737+
//
733738
pub fn get_inner_array_type_name(&self) -> Option<&str> {
734739
match self {
735740
DataTypeInformation::Array { inner_type_name, .. } => Some(inner_type_name),

0 commit comments

Comments
 (0)