@@ -34,13 +34,13 @@ pub fn filter_asm(block: &str) -> String {
34
34
lazy_static ! {
35
35
// Example: mov rax, rdx
36
36
// Always inlude in results
37
- static ref OPCODE_REGEX : Regex = Regex :: new( r"^\s* [a-zA-Z]+.*[^:]$" ) . unwrap( ) ;
37
+ static ref OPCODE_REGEX : Regex = Regex :: new( r"^\s+ [a-zA-Z]+.*[^:]$" ) . unwrap( ) ;
38
38
}
39
39
lazy_static ! {
40
40
// Example:.Lfunc_end7:
41
41
// Finds label declarations
42
42
// Include in results only if it is referenced by an opcode, or is a function
43
- static ref LABEL_DECL_REGEX : Regex = Regex :: new( r"([a-zA-Z_.<][a-zA-Z0-9$&_.,<>\[\]{}:' ]*):$" ) . unwrap( ) ;
43
+ static ref LABEL_DECL_REGEX : Regex = Regex :: new( r"^ ([a-zA-Z_.<][a-zA-Z0-9$&_.,<>\[\]{}:' ]*):(\s+#.*)? $" ) . unwrap( ) ;
44
44
}
45
45
lazy_static ! {
46
46
// Example: mov lea rdi, [rip + str.0] // str.0 is the referenced label
@@ -51,19 +51,19 @@ pub fn filter_asm(block: &str) -> String {
51
51
// Example: .string "Hello, world!"
52
52
// Note: this is a type of directive
53
53
// Include in results if it is part of a used label, may contain label references
54
- static ref DATA_REGEX : Regex = Regex :: new( r"^\s* \.(string|asciz|ascii|[1248]?byte|short|word|long|quad|value|zero)" ) . unwrap( ) ;
54
+ static ref DATA_REGEX : Regex = Regex :: new( r"^\s+ \.(string|asciz|ascii|[1248]?byte|short|word|long|quad|value|zero)" ) . unwrap( ) ;
55
55
}
56
56
lazy_static ! {
57
57
// Example: .type main,@function
58
58
// Note: this is a type of directive
59
59
// Never include in results, but is used to find and include functions
60
- static ref FUNCTION_REGEX : Regex = Regex :: new( r"^\s* \.type\s*(.*),@function$" ) . unwrap( ) ;
60
+ static ref FUNCTION_REGEX : Regex = Regex :: new( r"^\s+ \.type\s*(.*),@function$" ) . unwrap( ) ;
61
61
}
62
62
lazy_static ! {
63
63
// Example: .p2align 4, 0x90
64
64
// Note: this will also match entries found by DATA_REGEX and FUNCTION_REGEX
65
65
// Never include in results
66
- static ref DIRECTIVE_REGEX : Regex = Regex :: new( r"^\s* \..*[^:]$" ) . unwrap( ) ;
66
+ static ref DIRECTIVE_REGEX : Regex = Regex :: new( r"^\s+ \..*[^:]$" ) . unwrap( ) ;
67
67
}
68
68
lazy_static ! {
69
69
// Never include in results
@@ -188,9 +188,8 @@ mod test {
188
188
#[ test]
189
189
fn used_label_kept ( ) {
190
190
assert_eq ! (
191
-
192
- super :: filter_asm( ".Lcfi0:\n callq .Lcfi0\n " ) ,
193
- "\n .Lcfi0:\n callq .Lcfi0\n " ) ;
191
+ super :: filter_asm( ".Lcfi0:\n callq .Lcfi0\n " ) ,
192
+ "\n .Lcfi0:\n callq .Lcfi0\n " ) ;
194
193
}
195
194
196
195
#[ test]
@@ -214,14 +213,14 @@ mod test {
214
213
215
214
#[ test]
216
215
fn blank_lines_removed ( ) {
217
- assert_eq ! ( super :: filter_asm( " mov rbp, rsp\n main :\n jmp core::fmt::Arguments\n \n " ) ,
216
+ assert_eq ! ( super :: filter_asm( " mov rbp, rsp\n main :\n jmp core::fmt::Arguments\n \n " ) ,
218
217
" mov rbp, rsp\n jmp core::fmt::Arguments\n " )
219
218
}
220
219
221
220
#[ test]
222
221
fn functions_kept ( ) {
223
- assert_eq ! ( super :: filter_asm( " .type main,@function\n main :\n pushq %rax\n " ) ,
224
- "\n main :\n pushq %rax\n " ) ;
222
+ assert_eq ! ( super :: filter_asm( " .type main,@function\n main :\n pushq %rax\n " ) ,
223
+ "\n main :\n pushq %rax\n " ) ;
225
224
}
226
225
#[ test]
227
226
fn used_data_ref_label_kept ( ) {
@@ -238,4 +237,14 @@ mod test {
238
237
assert_eq ! ( super :: filter_asm( "main:\n .quad ref.1\n mov main\n ref.1:\n .quad ref.2\n ref.2:\n .quad 1" ) ,
239
238
"\n main:\n .quad ref.1\n mov main\n \n ref.1:\n .quad ref.2\n \n ref.2:\n .quad 1\n " ) ;
240
239
}
240
+ #[ test]
241
+ fn label_with_comment_recognized ( ) {
242
+ assert_eq ! ( super :: filter_asm( ".LBB6_10: # =>Comment\n movq %r15, %rsi\n movq %rbx, %rdx\n ja .LBB6_10\n " ) ,
243
+ "\n .LBB6_10: # =>Comment\n movq %r15, %rsi\n movq %rbx, %rdx\n ja .LBB6_10\n " ) ;
244
+ }
245
+ #[ test]
246
+ fn comment_retained ( ) {
247
+ assert_eq ! ( super :: filter_asm( "# %bb.0:\n subq $24, %rsp\n " ) ,
248
+ "# %bb.0:\n subq $24, %rsp\n " )
249
+ }
241
250
}
0 commit comments