Skip to content

Commit cd729e4

Browse files
Remove null action warning + adjust table printing
Null actions don't seem to cause issues that wouldn't be catchable by the other errors, so the warning has been removed. Also, table printing has been adjusted so each line includes a newline for cleanliness, and so the end bit property instead prints a message.
1 parent 83558ea commit cd729e4

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ description = "CodeWarrior Exception Table decoder (binary)"
1010
rust-version = "1.58"
1111

1212
[dependencies]
13-
cwextab = { path = "../lib", version = "1.0.2" }
13+
cwextab = { path = "../lib", version = "1.0" }

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cwextab"
3-
version = "1.0.2"
3+
version = "1.0.3"
44
edition = "2021"
55
authors = ["Amber Brault <[email protected]>"]
66
license = "MIT OR Apache-2.0"

lib/src/lib.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,8 @@ impl ExceptionAction {
221221
/// Returns whether this action has a destuctor reference or not.
222222
pub fn has_dtor_ref(&self) -> bool {
223223
match self.action_type {
224-
ExAction::EndOfList => {
225-
println!("Warning: null action passed");
226-
false
227-
}
228-
ExAction::Branch
224+
ExAction::EndOfList
225+
| ExAction::Branch
229226
| ExAction::CatchBlock
230227
| ExAction::ActiveCatchBlock
231228
| ExAction::Terminate
@@ -626,37 +623,37 @@ impl ExceptionTableData {
626623
match exaction_data {
627624
ExActionData::EndOfList => {}
628625
ExActionData::Branch { target_offset } => {
629-
line += format!("Action: {target_offset:06X}").as_str();
626+
line += format!("Action: {target_offset:06X}\n").as_str();
630627
}
631628
ExActionData::DestroyLocal { local_offset, .. } => {
632-
line += format!("Local: {local_offset:#X}({local_reg_string})").as_str();
629+
line += format!("Local: {local_offset:#X}({local_reg_string})\n").as_str();
633630
}
634631
ExActionData::DestroyLocalCond {
635632
condition,
636633
local_offset,
637634
..
638635
} => {
639-
line += format!("Local: {local_offset:#X}({local_reg_string})").as_str();
636+
line += format!("Local: {local_offset:#X}({local_reg_string})\n").as_str();
640637

641638
//The action param is used to determine the type of reference for the condition (0: local offset, 1: register)
642639
if action.action_param == 0 {
643640
//Local offset
644-
line += format!("\nCond: {condition:#X}({local_reg_string})").as_str();
641+
line += format!("Cond: {condition:#X}({local_reg_string})\n").as_str();
645642
} else {
646643
//Register
647644
//In this case, the local offset param is actually the register number
648-
line += format!("\nCond: r{condition}").as_str();
645+
line += format!("Cond: r{condition}\n").as_str();
649646
}
650647
}
651648
ExActionData::DestroyLocalPointer { local_pointer, .. } => {
652649
let mode = action.action_param >> 7;
653650
if mode == 0 {
654651
//Local offset
655652
line +=
656-
format!("Pointer: {local_pointer:#X}({local_reg_string})").as_str();
653+
format!("Pointer: {local_pointer:#X}({local_reg_string})\n").as_str();
657654
} else {
658655
//Register
659-
line += format!("Pointer: r{local_pointer}").as_str();
656+
line += format!("Pointer: r{local_pointer}\n").as_str();
660657
}
661658
}
662659
ExActionData::DestroyLocalArray {
@@ -665,7 +662,7 @@ impl ExceptionTableData {
665662
element_size,
666663
..
667664
} => {
668-
line += format!("Array: {local_array:#X}({local_reg_string})\nElements: {elements}\nSize: {element_size}").as_str();
665+
line += format!("Array: {local_array:#X}({local_reg_string})\nElements: {elements}\nSize: {element_size}\n").as_str();
669666
}
670667
ExActionData::DestroyBase {
671668
object_pointer,
@@ -674,10 +671,10 @@ impl ExceptionTableData {
674671
} => {
675672
let mode = action.action_param >> 7;
676673
if mode == 0 {
677-
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}").as_str();
674+
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}\n").as_str();
678675
} else {
679676
line +=
680-
format!("Member: {member_offset:#X}(r{object_pointer})").as_str();
677+
format!("Member: {member_offset:#X}(r{object_pointer})\n").as_str();
681678
}
682679
}
683680
ExActionData::DestroyMember {
@@ -687,10 +684,10 @@ impl ExceptionTableData {
687684
} => {
688685
let mode = action.action_param >> 7;
689686
if mode == 0 {
690-
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}").as_str();
687+
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}\n").as_str();
691688
} else {
692689
line +=
693-
format!("Member: {member_offset:#X}(r{object_pointer})").as_str();
690+
format!("Member: {member_offset:#X}(r{object_pointer})\n").as_str();
694691
}
695692
}
696693
ExActionData::DestroyMemberCond {
@@ -701,19 +698,19 @@ impl ExceptionTableData {
701698
} => {
702699
let mode = (action.action_param >> 6) & 1;
703700
if mode == 0 {
704-
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}").as_str();
701+
line += format!("Member: {object_pointer:#X}({local_reg_string})+{member_offset:#X}\n").as_str();
705702
} else {
706703
//Register
707704
line +=
708-
format!("Member: {member_offset:#X}(r{object_pointer})").as_str();
705+
format!("Member: {member_offset:#X}(r{object_pointer})\n").as_str();
709706
}
710707
let condition_mode = action.action_param >> 7;
711708
if condition_mode == 0 {
712709
//Local offset
713-
line += format!("\nCond: {condition:#X}({local_reg_string})").as_str();
710+
line += format!("Cond: {condition:#X}({local_reg_string})\n").as_str();
714711
} else {
715712
//Register
716-
line += format!("\nCond: r{condition}").as_str();
713+
line += format!("Cond: r{condition}\n").as_str();
717714
}
718715
}
719716
ExActionData::DestroyMemberArray {
@@ -727,25 +724,25 @@ impl ExceptionTableData {
727724
if mode == 0 {
728725
//Local offset
729726
line += format!(
730-
"Member: {object_pointer:#X}({local_reg_string})+0x{member_offset}"
727+
"Member: {object_pointer:#X}({local_reg_string})+0x{member_offset}\n"
731728
)
732729
.as_str();
733730
} else {
734731
//Register
735732
line +=
736-
format!("Member: {member_offset:#X}(r{object_pointer})").as_str();
733+
format!("Member: {member_offset:#X}(r{object_pointer})\n").as_str();
737734
}
738-
line += format!("\nElements: {elements}\nSize: {element_size}").as_str();
735+
line += format!("Elements: {elements}\nSize: {element_size}\n").as_str();
739736
}
740737
ExActionData::DeletePointer { object_pointer, .. } => {
741738
let mode = action.action_param >> 7;
742739
if mode == 0 {
743740
//Local offset
744-
line += format!("Pointer: {object_pointer:#X}({local_reg_string})")
741+
line += format!("Pointer: {object_pointer:#X}({local_reg_string})\n")
745742
.as_str();
746743
} else {
747744
//Register
748-
line += format!("Pointer: r{object_pointer})").as_str();
745+
line += format!("Pointer: r{object_pointer})\n").as_str();
749746
}
750747
}
751748
ExActionData::DeletePointerCond {
@@ -756,19 +753,19 @@ impl ExceptionTableData {
756753
let mode = (action.action_param >> 6) & 1;
757754
if mode == 0 {
758755
//Local offset
759-
line += format!("Pointer: {object_pointer:#X}({local_reg_string})")
756+
line += format!("Pointer: {object_pointer:#X}({local_reg_string})\n")
760757
.as_str();
761758
} else {
762759
//Register
763-
line += format!("Pointer: r{object_pointer})").as_str();
760+
line += format!("Pointer: r{object_pointer})\n").as_str();
764761
}
765762
let condition_mode = action.action_param >> 7;
766763
if condition_mode == 0 {
767764
//Local offset
768-
line += format!("\nCond: {condition:#X}({local_reg_string})").as_str();
765+
line += format!("Cond: {condition:#X}({local_reg_string})\n").as_str();
769766
} else {
770767
//Register
771-
line += format!("\nCond: r{condition}").as_str();
768+
line += format!("Cond: r{condition}\n").as_str();
772769
}
773770
}
774771
ExActionData::CatchBlock {
@@ -777,10 +774,10 @@ impl ExceptionTableData {
777774
cinfo_ref,
778775
..
779776
} => {
780-
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {catch_pc_offset:08X}\ncatch_type_addr: {catch_type:08X}").as_str();
777+
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {catch_pc_offset:08X}\ncatch_type_addr: {catch_type:08X}\n").as_str();
781778
}
782779
ExActionData::ActiveCatchBlock { cinfo_ref } => {
783-
line += format!("Local: {cinfo_ref:#X}({local_reg_string})").as_str();
780+
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\n").as_str();
784781
}
785782
ExActionData::Terminate => {}
786783
ExActionData::Specification {
@@ -789,15 +786,15 @@ impl ExceptionTableData {
789786
cinfo_ref,
790787
..
791788
} => {
792-
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {pc_offset:08X}\nTypes: {specs}").as_str();
789+
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {pc_offset:08X}\nTypes: {specs}\n").as_str();
793790
}
794791
ExActionData::CatchBlock32 {
795792
catch_type,
796793
catch_pc_offset,
797794
cinfo_ref,
798795
..
799796
} => {
800-
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {catch_pc_offset:08X}\ncatch_type_addr: {catch_type:08X}").as_str();
797+
line += format!("Local: {cinfo_ref:#X}({local_reg_string})\nPC: {catch_pc_offset:08X}\ncatch_type_addr: {catch_type:08X}\n").as_str();
801798
}
802799
}
803800

@@ -808,14 +805,13 @@ impl ExceptionTableData {
808805
return None;
809806
}
810807
let func_name = func_names[func_index].as_str();
811-
line += format!("\nDtor: \"{func_name}\"").as_str();
808+
line += format!("Dtor: \"{func_name}\"\n").as_str();
812809
func_index += 1;
813810
}
814811

815812
if action.has_end_bit {
816-
line += "."
817-
}; //Add a dot to the end if the has end bit flag is set
818-
line += "\n";
813+
line += "Has end bit\n"
814+
};
819815
sb += line.as_str(); //Print the line
820816
}
821817
}

0 commit comments

Comments
 (0)