Skip to content

Commit 4537360

Browse files
committed
Implement m_dbg_line and m_dbg_column matchers
1 parent 033bba7 commit 4537360

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed

docs/matchers/debug.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Constants Instructions Matchers functions
2+
3+
| Function | Parameters | Return | Description |
4+
| :----------: | :--------: | :---------: | :----------------------------------------------------: |
5+
| m_dbg_line | (Int) | InstMatcher | Build Inst Matcher that match debug into line number |
6+
| m_dbg_column | (Int) | InstMatcher | Build Inst Matcher that match debug into column number |

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ nav:
9999
- Cast: matchers/cast.md
100100
- Combine: matchers/combine.md
101101
- Types: matchers/types.md
102+
- Debug: matchers/debug.md
102103

103104
extra:
104105
social:

src/functions/matchers/debug.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use std::collections::HashMap;
2+
3+
use crate::ir::types::InstMatcherType;
4+
use crate::ir::values::InstMatcherValue;
5+
use crate::matchers::debug::DebugInfoColumnMatcher;
6+
use crate::matchers::debug::DebugInfoLineMatcher;
7+
8+
use gitql_ast::types::integer::IntType;
9+
use gitql_core::signature::Signature;
10+
use gitql_core::signature::StandardFunction;
11+
use gitql_core::values::Value;
12+
13+
#[inline(always)]
14+
pub fn register_debug_inst_matchers_functions(map: &mut HashMap<&'static str, StandardFunction>) {
15+
map.insert("m_dbg_line", match_debug_info_line);
16+
map.insert("m_dbg_column", match_debug_info_column);
17+
}
18+
19+
#[inline(always)]
20+
pub fn register_debug_inst_matchers_function_signatures(
21+
map: &mut HashMap<&'static str, Signature>,
22+
) {
23+
map.insert(
24+
"m_dbg_line",
25+
Signature {
26+
parameters: vec![Box::new(IntType)],
27+
return_type: Box::new(InstMatcherType),
28+
},
29+
);
30+
31+
map.insert(
32+
"m_dbg_column",
33+
Signature {
34+
parameters: vec![Box::new(IntType)],
35+
return_type: Box::new(InstMatcherType),
36+
},
37+
);
38+
}
39+
40+
fn match_debug_info_line(values: &[Box<dyn Value>]) -> Box<dyn Value> {
41+
let line = values[0].as_int().unwrap() as u32;
42+
let matcher = Box::new(DebugInfoLineMatcher { line });
43+
Box::new(InstMatcherValue { matcher })
44+
}
45+
46+
fn match_debug_info_column(values: &[Box<dyn Value>]) -> Box<dyn Value> {
47+
let column = values[0].as_int().unwrap() as u32;
48+
let matcher = Box::new(DebugInfoColumnMatcher { column });
49+
Box::new(InstMatcherValue { matcher })
50+
}

src/functions/matchers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod call;
44
pub mod cast;
55
pub mod combine;
66
pub mod constants;
7+
pub mod debug;
78
pub mod exception;
89
pub mod fcmp;
910
pub mod icmp;

src/functions/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use matchers::combine::register_combine_matchers_function;
2121
use matchers::combine::register_combine_matchers_function_signatures;
2222
use matchers::constants::register_constants_matchers_function_signatures;
2323
use matchers::constants::register_constants_matchers_functions;
24+
use matchers::debug::register_debug_inst_matchers_function_signatures;
25+
use matchers::debug::register_debug_inst_matchers_functions;
2426
use matchers::exception::register_exception_inst_matchers_function_signatures;
2527
use matchers::exception::register_exception_inst_matchers_functions;
2628
use matchers::fcmp::register_float_comparisons_matchers_function_signatures;
@@ -61,6 +63,7 @@ pub fn llvm_ir_functions() -> &'static HashMap<&'static str, StandardFunction> {
6163
register_combine_matchers_function(&mut map);
6264
register_call_inst_matchers_functions(&mut map);
6365
register_cast_matchers_function(&mut map);
66+
register_debug_inst_matchers_functions(&mut map);
6467
map
6568
})
6669
}
@@ -81,6 +84,7 @@ pub fn llvm_ir_function_signatures() -> HashMap<&'static str, Signature> {
8184
register_combine_matchers_function_signatures(&mut map);
8285
register_call_inst_matchers_function_signatures(&mut map);
8386
register_cast_matchers_function_signatures(&mut map);
87+
register_debug_inst_matchers_function_signatures(&mut map);
8488
map
8589
}
8690

src/matchers/debug.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use inkwell::llvm_sys::core::LLVMGetDebugLocColumn;
2+
use inkwell::llvm_sys::core::LLVMGetDebugLocLine;
3+
use inkwell::llvm_sys::prelude::LLVMValueRef;
4+
5+
use super::Matcher;
6+
7+
#[derive(Clone)]
8+
pub struct DebugInfoLineMatcher {
9+
pub line: u32,
10+
}
11+
12+
impl Matcher<LLVMValueRef> for DebugInfoLineMatcher {
13+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
14+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
15+
unsafe { self.line == LLVMGetDebugLocLine(*instruction) }
16+
}
17+
}
18+
19+
#[derive(Clone)]
20+
pub struct DebugInfoColumnMatcher {
21+
pub column: u32,
22+
}
23+
24+
impl Matcher<LLVMValueRef> for DebugInfoColumnMatcher {
25+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
26+
fn is_match(&self, instruction: &LLVMValueRef) -> bool {
27+
unsafe { self.column == LLVMGetDebugLocColumn(*instruction) }
28+
}
29+
}

src/matchers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod call;
55
pub mod cast;
66
pub mod combine;
77
pub mod constants;
8+
pub mod debug;
89
pub mod exception;
910
pub mod fcmp;
1011
pub mod icmp;

0 commit comments

Comments
 (0)