Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions rules/builtin/ir_refcount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"f10": {
"body": [
{
"text": "let (val, ovf) = "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".overflowing_mul("
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
]
}
},
{
"text": ";\n "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 2,
"access": "read"
}
}
],
"body": [
{
"text": ".write(val)"
}
]
}
},
{
"text": ";\n ovf"
}
],
"multi_statement": true,
"params": {
"a0": {
"type": "i64"
},
"a1": {
"type": "i64"
},
"a2": {
"type": "Ptr<i64>",
"is_refcount_pointer": true
}
},
"return_type": {
"type": "bool"
}
},
"f9": {
"body": [
{
"text": "let (val, ovf) = "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".overflowing_mul("
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
]
}
},
{
"text": ";\n "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 2,
"access": "read"
}
}
],
"body": [
{
"text": ".write(val)"
}
]
}
},
{
"text": ";\n ovf"
}
],
"multi_statement": true,
"params": {
"a0": {
"type": "i64"
},
"a1": {
"type": "i64"
},
"a2": {
"type": "Ptr<i64>",
"is_refcount_pointer": true
}
},
"return_type": {
"type": "bool"
}
}
}
186 changes: 186 additions & 0 deletions rules/builtin/ir_unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,67 @@
"type": "usize"
}
},
"f10": {
"body": [
{
"text": "let (val, ovf) = "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".overflowing_mul("
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
]
}
},
{
"text": ";\n *"
},
{
"placeholder": {
"arg": 2,
"access": "write"
}
},
{
"text": " = val;\n ovf"
}
],
"multi_statement": true,
"params": {
"a0": {
"type": "i64"
},
"a1": {
"type": "i64"
},
"a2": {
"type": "*mut i64",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "bool"
}
},
"f2": {
"body": [
{
Expand Down Expand Up @@ -170,5 +231,130 @@
"return_type": {
"type": "u64"
}
},
"f7": {
"body": [
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".trailing_zeros()"
}
]
}
},
{
"text": " as i32"
}
],
"params": {
"a0": {
"type": "u64"
}
},
"return_type": {
"type": "i32"
}
},
"f8": {
"body": [
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".count_ones()"
}
]
}
},
{
"text": " as i32"
}
],
"params": {
"a0": {
"type": "u64"
}
},
"return_type": {
"type": "i32"
}
},
"f9": {
"body": [
{
"text": "let (val, ovf) = "
},
{
"method_call": {
"receiver": [
{
"placeholder": {
"arg": 0,
"access": "read"
}
}
],
"body": [
{
"text": ".overflowing_mul("
},
{
"placeholder": {
"arg": 1,
"access": "read"
}
},
{
"text": ")"
}
]
}
},
{
"text": ";\n *"
},
{
"placeholder": {
"arg": 2,
"access": "write"
}
},
{
"text": " = val;\n ovf"
}
],
"multi_statement": true,
"params": {
"a0": {
"type": "i64"
},
"a1": {
"type": "i64"
},
"a2": {
"type": "*mut i64",
"is_unsafe_pointer": true
}
},
"return_type": {
"type": "bool"
}
}
}
4 changes: 4 additions & 0 deletions rules/builtin/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ unsigned short f4(unsigned short x) { return __builtin_bswap16(x); }
unsigned int f5(unsigned int x) { return __builtin_bswap32(x); }
unsigned long long f6(unsigned long long x) { return __builtin_bswap64(x); }
#endif
int f7(unsigned long x) { return __builtin_ctzl(x); }
int f8(unsigned long x) { return __builtin_popcountl(x); }
bool f9(long a, long b, long *r) { return __builtin_mul_overflow(a, b, r); }
bool f10(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); }
15 changes: 15 additions & 0 deletions rules/builtin/tgt_refcount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

use libcc2rs::*;

fn f9(a0: i64, a1: i64, a2: Ptr<i64>) -> bool {
let (val, ovf) = a0.overflowing_mul(a1);
a2.write(val);
ovf
}
fn f10(a0: i64, a1: i64, a2: Ptr<i64>) -> bool {
let (val, ovf) = a0.overflowing_mul(a1);
a2.write(val);
ovf
}
16 changes: 16 additions & 0 deletions rules/builtin/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ unsafe fn f5(a0: u32) -> u32 {
unsafe fn f6(a0: u64) -> u64 {
a0.swap_bytes()
}
unsafe fn f7(a0: u64) -> i32 {
a0.trailing_zeros() as i32
}
unsafe fn f8(a0: u64) -> i32 {
a0.count_ones() as i32
}
unsafe fn f9(a0: i64, a1: i64, a2: *mut i64) -> bool {
let (val, ovf) = a0.overflowing_mul(a1);
*a2 = val;
ovf
}
unsafe fn f10(a0: i64, a1: i64, a2: *mut i64) -> bool {
let (val, ovf) = a0.overflowing_mul(a1);
*a2 = val;
ovf
}
2 changes: 2 additions & 0 deletions rules/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod assert_tgt_unsafe;
pub mod brotli_tgt_refcount;
#[path = r#"../brotli/tgt_unsafe.rs"#]
pub mod brotli_tgt_unsafe;
#[path = r#"../builtin/tgt_refcount.rs"#]
pub mod builtin_tgt_refcount;
#[path = r#"../builtin/tgt_unsafe.rs"#]
pub mod builtin_tgt_unsafe;
#[path = r#"../carray/tgt_refcount.rs"#]
Expand Down
Loading
Loading