@@ -32,10 +32,10 @@ pub fn split_prog_into_segs(
32
32
instrumented_state. split_segment ( false , seg_path, new_writer) ;
33
33
let new_writer = |name : & str | -> Option < std:: fs:: File > { File :: create ( name) . ok ( ) } ;
34
34
loop {
35
+ let cycles = instrumented_state. step ( ) ;
35
36
if instrumented_state. state . exited {
36
37
break ;
37
38
}
38
- let cycles = instrumented_state. step ( ) ;
39
39
if cycles > ( seg_size as isize - 1 ) as u64 {
40
40
instrumented_state. split_segment ( true , seg_path, new_writer) ;
41
41
}
@@ -54,3 +54,51 @@ pub fn split_prog_into_segs(
54
54
instrumented_state. state ,
55
55
)
56
56
}
57
+
58
+ pub fn load_segment ( seg_file : & str ) -> ( Box < State > , u64 ) {
59
+ State :: load_seg ( seg_file)
60
+ }
61
+
62
+ pub fn split_seg_into_segs (
63
+ seg_file : & str ,
64
+ seg_path : & str ,
65
+ block_path : & str ,
66
+ seg_size : usize ,
67
+ ) -> ( usize , usize , Box < State > ) {
68
+ let ( state, final_step) = load_segment ( seg_file) ;
69
+ let mut instrumented_state = InstrumentedState :: new ( state, block_path. to_string ( ) ) ;
70
+ log:: debug!( "start pc: {:X} {}" , instrumented_state. state. pc, final_step) ;
71
+ std:: fs:: create_dir_all ( seg_path) . unwrap ( ) ;
72
+ let new_writer = |_: & str | -> Option < std:: fs:: File > { None } ;
73
+ instrumented_state. split_segment ( false , seg_path, new_writer) ;
74
+ let new_writer = |name : & str | -> Option < std:: fs:: File > { File :: create ( name) . ok ( ) } ;
75
+ loop {
76
+ let cycles = instrumented_state. step ( ) ;
77
+ if instrumented_state. state . total_step + instrumented_state. state . step == final_step {
78
+ break ;
79
+ }
80
+ if cycles > ( seg_size as isize - 1 ) as u64 {
81
+ instrumented_state. split_segment ( true , seg_path, new_writer) ;
82
+ log:: debug!(
83
+ "Split at {} : {} into {}" ,
84
+ instrumented_state. state. total_step,
85
+ instrumented_state. state. total_cycle,
86
+ instrumented_state. pre_segment_id
87
+ ) ;
88
+ }
89
+ }
90
+ instrumented_state. split_segment ( true , seg_path, new_writer) ;
91
+ log:: info!(
92
+ "Split done {} : {} into {}" ,
93
+ instrumented_state. state. total_step,
94
+ instrumented_state. state. total_cycle,
95
+ instrumented_state. pre_segment_id
96
+ ) ;
97
+
98
+ instrumented_state. dump_memory ( ) ;
99
+ (
100
+ instrumented_state. state . total_step as usize ,
101
+ instrumented_state. pre_segment_id as usize ,
102
+ instrumented_state. state ,
103
+ )
104
+ }
0 commit comments