-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathOperationsFunctions.hpp
More file actions
101 lines (85 loc) · 3.7 KB
/
Copy pathOperationsFunctions.hpp
File metadata and controls
101 lines (85 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright (C) 2014 - 2020 Map2Check tool
* This file is part of the Map2Check tool, and is made available under
* the terms of the GNU General Public License version 2.
*
* LLVM -> NCSA
*
* SPDX-License-Identifier: (GPL-2.0 AND NCSA)
**/
#ifndef MODULES_BACKEND_PASS_OPERATIONSFUNCTIONS_HPP_
#define MODULES_BACKEND_PASS_OPERATIONSFUNCTIONS_HPP_
#include <llvm/IR/Constants.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/PassManager.h>
#include <llvm/Support/raw_ostream.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
// using namespace llvm;
using llvm::Function;
using llvm::FunctionCallee;
using llvm::LLVMContext;
using llvm::PointerType;
using llvm::Type;
class OperationsFunctions {
FunctionCallee OverflowAdd;
FunctionCallee OverflowAddUint;
FunctionCallee OverflowSub;
FunctionCallee OverflowSubUint;
FunctionCallee OverflowMul;
FunctionCallee OverflowMulUint;
FunctionCallee OverflowSDiv;
FunctionCallee OverflowError;
public:
FunctionCallee getOverflowAdd() { return this->OverflowAdd; }
FunctionCallee getOverflowAddUint() { return this->OverflowAddUint; }
FunctionCallee getOverflowSub() { return this->OverflowSub; }
FunctionCallee getOverflowSubUint() { return this->OverflowSubUint; }
FunctionCallee getOverflowMul() { return this->OverflowMul; }
FunctionCallee getOverflowMulUint() { return this->OverflowMulUint; }
FunctionCallee getOverflowSDiv() { return this->OverflowSDiv; }
FunctionCallee getOverflowError() { return this->OverflowError; }
OperationsFunctions(Function *F, LLVMContext *Ctx) {
// LLVM 16: opaque pointers — use PointerType::get(*Ctx, 0) instead of PointerType::get(, 0)
auto *PtrTy = PointerType::get(*Ctx, 0);
this->OverflowAdd = F->getParent()->getOrInsertFunction(
"map2check_binop_add", Type::getVoidTy(*Ctx), Type::getInt64Ty(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
PtrTy);
this->OverflowAddUint = F->getParent()->getOrInsertFunction(
"map2check_binop_add_uint", Type::getVoidTy(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
Type::getInt64Ty(*Ctx), PtrTy);
this->OverflowSub = F->getParent()->getOrInsertFunction(
"map2check_binop_sub", Type::getVoidTy(*Ctx), Type::getInt64Ty(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
PtrTy);
this->OverflowSubUint = F->getParent()->getOrInsertFunction(
"map2check_binop_sub_uint", Type::getVoidTy(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
Type::getInt64Ty(*Ctx), PtrTy);
this->OverflowMul = F->getParent()->getOrInsertFunction(
"map2check_binop_mul", Type::getVoidTy(*Ctx), Type::getInt64Ty(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
PtrTy);
this->OverflowMulUint = F->getParent()->getOrInsertFunction(
"map2check_binop_mul_uint", Type::getVoidTy(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
Type::getInt64Ty(*Ctx), PtrTy);
this->OverflowSDiv = F->getParent()->getOrInsertFunction(
"map2check_binop_sdiv", Type::getVoidTy(*Ctx), Type::getInt64Ty(*Ctx),
Type::getInt64Ty(*Ctx), Type::getInt32Ty(*Ctx), Type::getInt32Ty(*Ctx),
PtrTy);
this->OverflowError = F->getParent()->getOrInsertFunction(
"overflowError", Type::getVoidTy(*Ctx), Type::getInt32Ty(*Ctx),
PtrTy);
}
};
#endif // MODULES_BACKEND_PASS_OPERATIONSFUNCTIONS_HPP_