mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
Converted a1.ll to unittests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67652 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
abc061c088
commit
2e734269e3
@ -1,25 +0,0 @@
|
||||
; RUN: llvm-as %s -o - | llvm-dis > %t.ll
|
||||
; RUN: diff %t.ll %s.out
|
||||
|
||||
; test 1 bit
|
||||
;
|
||||
@b = constant i1 add(i1 1 , i1 1)
|
||||
@c = constant i1 add(i1 -1, i1 1)
|
||||
@d = constant i1 add(i1 -1, i1 -1)
|
||||
@e = constant i1 sub(i1 -1, i1 1)
|
||||
@f = constant i1 sub(i1 1 , i1 -1)
|
||||
@g = constant i1 sub(i1 1 , i1 1)
|
||||
|
||||
@h = constant i1 shl(i1 1 , i1 1) ; undefined
|
||||
@i = constant i1 shl(i1 1 , i1 0)
|
||||
@j = constant i1 lshr(i1 1, i1 1) ; undefined
|
||||
@m = constant i1 ashr(i1 1, i1 1) ; undefined
|
||||
|
||||
@n = constant i1 mul(i1 -1, i1 1)
|
||||
@o = constant i1 sdiv(i1 -1, i1 1) ; overflow
|
||||
@p = constant i1 sdiv(i1 1 , i1 -1); overflow
|
||||
@q = constant i1 udiv(i1 -1, i1 1)
|
||||
@r = constant i1 udiv(i1 1, i1 -1)
|
||||
@s = constant i1 srem(i1 -1, i1 1) ; overflow
|
||||
@t = constant i1 urem(i1 -1, i1 1)
|
||||
@u = constant i1 srem(i1 1, i1 -1) ; overflow
|
@ -1,19 +0,0 @@
|
||||
; ModuleID = '<stdin>'
|
||||
@b = constant i1 false ; <i1*> [#uses=0]
|
||||
@c = constant i1 false ; <i1*> [#uses=0]
|
||||
@d = constant i1 false ; <i1*> [#uses=0]
|
||||
@e = constant i1 false ; <i1*> [#uses=0]
|
||||
@f = constant i1 false ; <i1*> [#uses=0]
|
||||
@g = constant i1 false ; <i1*> [#uses=0]
|
||||
@h = constant i1 undef ; <i1*> [#uses=0]
|
||||
@i = constant i1 true ; <i1*> [#uses=0]
|
||||
@j = constant i1 undef ; <i1*> [#uses=0]
|
||||
@m = constant i1 undef ; <i1*> [#uses=0]
|
||||
@n = constant i1 true ; <i1*> [#uses=0]
|
||||
@o = constant i1 true ; <i1*> [#uses=0]
|
||||
@p = constant i1 true ; <i1*> [#uses=0]
|
||||
@q = constant i1 true ; <i1*> [#uses=0]
|
||||
@r = constant i1 true ; <i1*> [#uses=0]
|
||||
@s = constant i1 false ; <i1*> [#uses=0]
|
||||
@t = constant i1 false ; <i1*> [#uses=0]
|
||||
@u = constant i1 false ; <i1*> [#uses=0]
|
@ -7,13 +7,29 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <ostream>
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
// Make the Google Test failure output equivalent to APInt::dump()
|
||||
std::ostream& operator<<(std::ostream &OS, const llvm::APInt& I) {
|
||||
llvm::raw_os_ostream raw_os(OS);
|
||||
|
||||
SmallString<40> S, U;
|
||||
I.toStringUnsigned(U);
|
||||
I.toStringSigned(S);
|
||||
raw_os << "APInt(" << I.getBitWidth()<< "b, "
|
||||
<< U.c_str() << "u " << S.c_str() << "s)";
|
||||
raw_os.flush();
|
||||
return OS;
|
||||
}
|
||||
|
||||
// Test that APInt shift left works when bitwidth > 64 and shiftamt == 0
|
||||
TEST(APIntTest, ShiftLeftByZero) {
|
||||
APInt One = APInt::getNullValue(65) + 1;
|
||||
@ -22,7 +38,7 @@ TEST(APIntTest, ShiftLeftByZero) {
|
||||
EXPECT_EQ(false, Shl[1]);
|
||||
}
|
||||
|
||||
TEST(APIntTest, I128NegativeCount) {
|
||||
TEST(APIntTest, i128_NegativeCount) {
|
||||
APInt Minus3(128, (uint64_t)-3, true);
|
||||
EXPECT_EQ(126u, Minus3.countLeadingOnes());
|
||||
EXPECT_EQ(-3, Minus3.getSExtValue());
|
||||
@ -37,7 +53,7 @@ TEST(APIntTest, I128NegativeCount) {
|
||||
EXPECT_EQ(-1, Minus1.getSExtValue());
|
||||
}
|
||||
|
||||
TEST(APIntTest, I33Count) {
|
||||
TEST(APIntTest, i33_Count) {
|
||||
APInt i33minus2(33, -2, true);
|
||||
EXPECT_EQ(0u, i33minus2.countLeadingZeros());
|
||||
EXPECT_EQ(32u, i33minus2.countLeadingOnes());
|
||||
@ -48,7 +64,7 @@ TEST(APIntTest, I33Count) {
|
||||
EXPECT_EQ(((uint64_t)-2)&((1ull<<33) -1), i33minus2.getZExtValue());
|
||||
}
|
||||
|
||||
TEST(APIntTest, I65Count) {
|
||||
TEST(APIntTest, i65_Count) {
|
||||
APInt i65minus(65, 0, true);
|
||||
i65minus.set(64);
|
||||
EXPECT_EQ(0u, i65minus.countLeadingZeros());
|
||||
@ -58,7 +74,7 @@ TEST(APIntTest, I65Count) {
|
||||
EXPECT_EQ(1u, i65minus.countPopulation());
|
||||
}
|
||||
|
||||
TEST(APIntTest, I128PositiveCount) {
|
||||
TEST(APIntTest, i128_PositiveCount) {
|
||||
APInt u128max = APInt::getAllOnesValue(128);
|
||||
EXPECT_EQ(128u, u128max.countLeadingOnes());
|
||||
EXPECT_EQ(0u, u128max.countLeadingZeros());
|
||||
@ -97,4 +113,67 @@ TEST(APIntTest, I128PositiveCount) {
|
||||
EXPECT_EQ(1u, one.getZExtValue());
|
||||
}
|
||||
|
||||
TEST(APIntTest, i1) {
|
||||
const APInt neg_two(1, -2, true);
|
||||
const APInt neg_one(1, -1, true);
|
||||
const APInt zero(1, 0);
|
||||
const APInt one(1, 1);
|
||||
const APInt two(1, 2);
|
||||
|
||||
EXPECT_EQ(0, neg_two.getSExtValue());
|
||||
EXPECT_EQ(-1, neg_one.getSExtValue());
|
||||
EXPECT_EQ(1u, neg_one.getZExtValue());
|
||||
EXPECT_EQ(0u, zero.getZExtValue());
|
||||
EXPECT_EQ(-1, one.getSExtValue());
|
||||
EXPECT_EQ(1u, one.getZExtValue());
|
||||
EXPECT_EQ(0u, two.getZExtValue());
|
||||
EXPECT_EQ(0, two.getSExtValue());
|
||||
|
||||
// Basic equalities for 1-bit values.
|
||||
EXPECT_EQ(zero, two);
|
||||
EXPECT_EQ(zero, neg_two);
|
||||
EXPECT_EQ(one, neg_one);
|
||||
EXPECT_EQ(two, neg_two);
|
||||
|
||||
// Additions.
|
||||
EXPECT_EQ(two, one + one);
|
||||
EXPECT_EQ(zero, neg_one + one);
|
||||
EXPECT_EQ(neg_two, neg_one + neg_one);
|
||||
|
||||
// Subtractions.
|
||||
EXPECT_EQ(neg_two, neg_one - one);
|
||||
EXPECT_EQ(two, one - neg_one);
|
||||
EXPECT_EQ(zero, one - one);
|
||||
|
||||
// Shifts.
|
||||
EXPECT_EQ(zero, one << one);
|
||||
EXPECT_EQ(one, one << zero);
|
||||
EXPECT_EQ(zero, one.shl(1));
|
||||
EXPECT_EQ(one, one.shl(0));
|
||||
EXPECT_EQ(zero, one.lshr(1));
|
||||
EXPECT_EQ(zero, one.ashr(1));
|
||||
|
||||
// Multiplies.
|
||||
EXPECT_EQ(neg_one, neg_one * one);
|
||||
EXPECT_EQ(neg_one, one * neg_one);
|
||||
EXPECT_EQ(one, neg_one * neg_one);
|
||||
EXPECT_EQ(one, one * one);
|
||||
|
||||
// Divides.
|
||||
EXPECT_EQ(neg_one, one.sdiv(neg_one));
|
||||
EXPECT_EQ(neg_one, neg_one.sdiv(one));
|
||||
EXPECT_EQ(one, neg_one.sdiv(neg_one));
|
||||
EXPECT_EQ(one, one.sdiv(one));
|
||||
|
||||
EXPECT_EQ(neg_one, one.udiv(neg_one));
|
||||
EXPECT_EQ(neg_one, neg_one.udiv(one));
|
||||
EXPECT_EQ(one, neg_one.udiv(neg_one));
|
||||
EXPECT_EQ(one, one.udiv(one));
|
||||
|
||||
// Remainders.
|
||||
EXPECT_EQ(zero, neg_one.srem(one));
|
||||
EXPECT_EQ(zero, neg_one.urem(one));
|
||||
EXPECT_EQ(zero, one.srem(neg_one));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ BUILD_ARCHIVE = 1
|
||||
CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include/
|
||||
CPP.Flags += -Wno-variadic-macros
|
||||
|
||||
PARALLEL_DIRS = ADT Support
|
||||
PARALLEL_DIRS = ADT Support VMCore
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
|
98
unittests/VMCore/ConstantsTest.cpp
Normal file
98
unittests/VMCore/ConstantsTest.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
//===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants unit tests ------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace {
|
||||
|
||||
TEST(ConstantsTest, Integer_i1) {
|
||||
const IntegerType* Int1 = IntegerType::get(1);
|
||||
Constant* One = ConstantInt::get(Int1, 1, true);
|
||||
Constant* Zero = ConstantInt::get(Int1, 0);
|
||||
Constant* NegOne = ConstantInt::get(Int1, -1, true);
|
||||
Constant* Undef = UndefValue::get(Int1);
|
||||
|
||||
// Input: @b = constant i1 add(i1 1 , i1 1)
|
||||
// Output: @b = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One));
|
||||
|
||||
// @c = constant i1 add(i1 -1, i1 1)
|
||||
// @c = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One));
|
||||
|
||||
// @d = constant i1 add(i1 -1, i1 -1)
|
||||
// @d = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne));
|
||||
|
||||
// @e = constant i1 sub(i1 -1, i1 1)
|
||||
// @e = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One));
|
||||
|
||||
// @f = constant i1 sub(i1 1 , i1 -1)
|
||||
// @f = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne));
|
||||
|
||||
// @g = constant i1 sub(i1 1 , i1 1)
|
||||
// @g = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getSub(One, One));
|
||||
|
||||
// @h = constant i1 shl(i1 1 , i1 1) ; undefined
|
||||
// @h = constant i1 undef
|
||||
EXPECT_EQ(Undef, ConstantExpr::getShl(One, One));
|
||||
|
||||
// @i = constant i1 shl(i1 1 , i1 0)
|
||||
// @i = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getShl(One, Zero));
|
||||
|
||||
// @j = constant i1 lshr(i1 1, i1 1) ; undefined
|
||||
// @j = constant i1 undef
|
||||
EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One));
|
||||
|
||||
// @m = constant i1 ashr(i1 1, i1 1) ; undefined
|
||||
// @m = constant i1 undef
|
||||
EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One));
|
||||
|
||||
// @n = constant i1 mul(i1 -1, i1 1)
|
||||
// @n = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One));
|
||||
|
||||
// @o = constant i1 sdiv(i1 -1, i1 1) ; overflow
|
||||
// @o = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One));
|
||||
|
||||
// @p = constant i1 sdiv(i1 1 , i1 -1); overflow
|
||||
// @p = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne));
|
||||
|
||||
// @q = constant i1 udiv(i1 -1, i1 1)
|
||||
// @q = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One));
|
||||
|
||||
// @r = constant i1 udiv(i1 1, i1 -1)
|
||||
// @r = constant i1 true
|
||||
EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne));
|
||||
|
||||
// @s = constant i1 srem(i1 -1, i1 1) ; overflow
|
||||
// @s = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One));
|
||||
|
||||
// @t = constant i1 urem(i1 -1, i1 1)
|
||||
// @t = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One));
|
||||
|
||||
// @u = constant i1 srem(i1 1, i1 -1) ; overflow
|
||||
// @u = constant i1 false
|
||||
EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne));
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
} // end namespace llvm
|
15
unittests/VMCore/Makefile
Normal file
15
unittests/VMCore/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
##===- unittests/VMCore/Makefile ---------------------------*- Makefile -*-===##
|
||||
#
|
||||
# The LLVM Compiler Infrastructure
|
||||
#
|
||||
# This file is distributed under the University of Illinois Open Source
|
||||
# License. See LICENSE.TXT for details.
|
||||
#
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
LEVEL = ../..
|
||||
TESTNAME = VMCore
|
||||
LINK_COMPONENTS := core support
|
||||
|
||||
include $(LEVEL)/Makefile.config
|
||||
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
|
Loading…
Reference in New Issue
Block a user