From f5f878ed888b93a576b76dc05a6e274c5111aa22 Mon Sep 17 00:00:00 2001 From: rina Date: Fri, 22 Mar 2024 00:04:00 +1000 Subject: [PATCH] update stubs with new interface --- offlineASL-cpp/aslp_lifter_base.cpp | 84 ------------------------ offlineASL-cpp/llvm_interface.cpp | 99 +++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 84 deletions(-) delete mode 100644 offlineASL-cpp/aslp_lifter_base.cpp create mode 100644 offlineASL-cpp/llvm_interface.cpp diff --git a/offlineASL-cpp/aslp_lifter_base.cpp b/offlineASL-cpp/aslp_lifter_base.cpp deleted file mode 100644 index 2171bbd7..00000000 --- a/offlineASL-cpp/aslp_lifter_base.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "aslp_lifter_base.hpp" - -namespace aslp { - -bits extract_bits(const bits &val, bigint lo, bigint wd) { - return val.extractBits(wd, lo); -} - -bool f_eq_bits(bits x, bits y) { - return x == y; -} -bool f_ne_bits(bits x, bits y) { - return x != y; -} -bits f_add_bits(bits x, bits y) { - return x + y; -} -bits f_sub_bits(bits x, bits y) { - return x - y; -} -bits f_mul_bits(bits x, bits y) { - return x * y; -} -bits f_and_bits(bits x, bits y) { - return x & y; -} -bits f_or_bits(bits x, bits y) { - return x | y; -} -bits f_eor_bits(bits x, bits y) { - return x ^ y; -} -bits f_not_bits(bits x) { - return ~x; -} -bool f_slt_bits(bits x, bits y) { - return x.slt(y); -} -bool f_sle_bits(bits x, bits y) { - return x.sle(y); -} -bits f_zeros_bits(bigint n) { - return llvm::APInt::getZero(n); -} -bits f_ones_bits(bigint n) { - return llvm::APInt::getAllOnes(n); -} -bits f_replicate_bits(bits x, bigint n) { - assert(n >= 1); - bits original = x; - unsigned wd = x.getBitWidth(); - x = x.zextOrTrunc(wd * n); - for (unsigned i = 1; i < n; i++) { - x <<= wd; - x |= original; - } - return x; -} -bits f_append_bits(bits x, bits y) { - x = x.zext(x.getBitWidth() + y.getBitWidth()); - x <<= y.getBitWidth(); - x |= y; - return x; -} -bits f_ZeroExtend(bits x, bigint wd) { - return x.zextOrTrunc(wd); -} -bits f_SignExtend(bits x, bigint wd) { - return x.sextOrTrunc(wd); -} -bits f_lsl_bits(bits x, bits y) { - return x << y; -} -bits f_lsr_bits(bits x, bits y) { - return x.lshr(y); -} -bits f_asr_bits(bits x, bits y) { - return x.ashr(y); -} -bigint f_cvt_bits_uint(bits x) { - return x.getZExtValue(); -} - -} // namespace aslp \ No newline at end of file diff --git a/offlineASL-cpp/llvm_interface.cpp b/offlineASL-cpp/llvm_interface.cpp new file mode 100644 index 00000000..4be04583 --- /dev/null +++ b/offlineASL-cpp/llvm_interface.cpp @@ -0,0 +1,99 @@ +#include + +#include "aslp_lifter_base.hpp" +#include "interface.hpp" + +namespace aslp { + +using __lifter_interface_llvm = lifter_interface; + +class llvm_lifter_interface : public __lifter_interface_llvm { + + using super = __lifter_interface_llvm; + using typename super::bits; + using typename super::bigint; + using typename super::rt_expr; + using typename super::rt_lexpr; + using typename super::rt_label; + + virtual bits extract_bits(const bits &val, bigint lo, bigint wd) override { + return val.extractBits(wd, lo); + } + bool f_eq_bits(const bits &x, const bits &y) override { + return x == y; + } + bool f_ne_bits(const bits &x, const bits &y) override { + return x != y; + } + virtual bits f_add_bits(const bits &x, const bits &y) override { + return x + y; + } + virtual bits f_sub_bits(const bits &x, const bits &y) override { + return x - y; + } + virtual bits f_mul_bits(const bits &x, const bits &y) override { + return x * y; + } + virtual bits f_and_bits(const bits &x, const bits &y) override { + return x & y; + } + virtual bits f_or_bits(const bits &x, const bits &y) override { + return x | y; + } + virtual bits f_eor_bits(const bits &x, const bits &y) override { + return x ^ y; + } + virtual bits f_not_bits(const bits &x) override { + return ~x; + } + bool f_slt_bits(const bits &x, const bits &y) override { + return x.slt(y); + } + bool f_sle_bits(const bits &x, const bits &y) override { + return x.sle(y); + } + virtual bits f_zeros_bits(bigint n) override { + return llvm::APInt::getZero(n); + } + virtual bits f_ones_bits(bigint n) override { + return llvm::APInt::getAllOnes(n); + } + virtual bits f_replicate_bits(const bits &x, bigint n) override { + assert(n >= 1); + bits original = x; + unsigned wd = x.getBitWidth(); + auto ret = x.zextOrTrunc(wd * n); + for (unsigned i = 1; i < n; i++) { + ret <<= wd; + ret |= original; + } + return ret; + } + virtual bits f_append_bits(const bits &x, const bits &y) override { + auto ret = x.zext(x.getBitWidth() + y.getBitWidth()); + ret <<= y.getBitWidth(); + ret |= y; + return ret; + } + virtual bits f_ZeroExtend(const bits &x, bigint wd) override { + return x.zextOrTrunc(wd); + } + virtual bits f_SignExtend(const bits &x, bigint wd) override { + return x.sextOrTrunc(wd); + } + virtual bits f_lsl_bits(const bits &x, const bits &y) override { + return x << y; + } + virtual bits f_lsr_bits(const bits &x, const bits &y) override { + return x.lshr(y); + } + virtual bits f_asr_bits(const bits &x, const bits &y) override { + return x.ashr(y); + } + bigint f_cvt_bits_uint(const bits &x) override { + return x.getZExtValue(); + } + +}; + +} // namespace aslp