aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/MC
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-12-01 14:51:49 -0800
committerStephen Hines <srhines@google.com>2014-12-02 16:08:10 -0800
commit37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch)
tree8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /unittests/MC
parentd2327b22152ced7bc46dc629fc908959e8a52d03 (diff)
downloadexternal_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz
external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'unittests/MC')
-rw-r--r--unittests/MC/CMakeLists.txt13
-rw-r--r--unittests/MC/Disassembler.cpp64
-rw-r--r--unittests/MC/Hexagon/CMakeLists.txt14
-rw-r--r--unittests/MC/Hexagon/HexagonMCCodeEmitterTest.cpp53
-rw-r--r--unittests/MC/MCAtomTest.cpp31
-rw-r--r--unittests/MC/Makefile2
-rw-r--r--unittests/MC/StringTableBuilderTest.cpp35
7 files changed, 176 insertions, 36 deletions
diff --git a/unittests/MC/CMakeLists.txt b/unittests/MC/CMakeLists.txt
index e2beab2..c82bcde 100644
--- a/unittests/MC/CMakeLists.txt
+++ b/unittests/MC/CMakeLists.txt
@@ -1,9 +1,18 @@
set(LLVM_LINK_COMPONENTS
- MCAnalysis
+ ${LLVM_TARGETS_TO_BUILD}
+ MC
+ MCDisassembler
+ Support
)
add_llvm_unittest(MCTests
- MCAtomTest.cpp
+ Disassembler.cpp
StringTableBuilderTest.cpp
YAMLTest.cpp
)
+
+foreach(t ${LLVM_TARGETS_TO_BUILD})
+ if (IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${t}")
+ add_subdirectory(${t})
+ endif (IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${t}")
+endforeach()
diff --git a/unittests/MC/Disassembler.cpp b/unittests/MC/Disassembler.cpp
new file mode 100644
index 0000000..dd0f1ef
--- /dev/null
+++ b/unittests/MC/Disassembler.cpp
@@ -0,0 +1,64 @@
+//===- llvm/unittest/Object/Disassembler.cpp ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-c/Disassembler.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+static const char *symbolLookupCallback(void *DisInfo, uint64_t ReferenceValue,
+ uint64_t *ReferenceType,
+ uint64_t ReferencePC,
+ const char **ReferenceName) {
+ *ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
+ return nullptr;
+}
+
+TEST(Disassembler, Test1) {
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargetMCs();
+ llvm::InitializeAllDisassemblers();
+
+ uint8_t Bytes[] = {0x90, 0x90, 0xeb, 0xfd};
+ uint8_t *BytesP = Bytes;
+ const char OutStringSize = 100;
+ char OutString[OutStringSize];
+ LLVMDisasmContextRef DCR = LLVMCreateDisasm("x86_64-pc-linux", nullptr, 0,
+ nullptr, symbolLookupCallback);
+ if (!DCR)
+ return;
+
+ size_t InstSize;
+ unsigned NumBytes = sizeof(Bytes);
+ unsigned PC = 0;
+
+ InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
+ OutStringSize);
+ EXPECT_EQ(InstSize, 1U);
+ EXPECT_EQ(StringRef(OutString), "\tnop");
+ PC += InstSize;
+ BytesP += InstSize;
+ NumBytes -= InstSize;
+
+ InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
+ OutStringSize);
+ EXPECT_EQ(InstSize, 1U);
+ EXPECT_EQ(StringRef(OutString), "\tnop");
+ PC += InstSize;
+ BytesP += InstSize;
+ NumBytes -= InstSize;
+
+ InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
+ OutStringSize);
+ EXPECT_EQ(InstSize, 2U);
+ EXPECT_EQ(StringRef(OutString), "\tjmp\t0x1");
+
+ LLVMDisasmDispose(DCR);
+}
diff --git a/unittests/MC/Hexagon/CMakeLists.txt b/unittests/MC/Hexagon/CMakeLists.txt
new file mode 100644
index 0000000..6d4ee93
--- /dev/null
+++ b/unittests/MC/Hexagon/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS
+ HexagonCodeGen
+ HexagonDesc
+ HexagonInfo
+ MC
+ Support
+ )
+
+include_directories (${LLVM_MAIN_SRC_DIR}/lib/Target/Hexagon)
+include_directories (${LLVM_BINARY_DIR}/lib/Target/Hexagon)
+
+add_llvm_unittest(HexagonTests
+ HexagonMCCodeEmitterTest.cpp
+ )
diff --git a/unittests/MC/Hexagon/HexagonMCCodeEmitterTest.cpp b/unittests/MC/Hexagon/HexagonMCCodeEmitterTest.cpp
new file mode 100644
index 0000000..958a21f
--- /dev/null
+++ b/unittests/MC/Hexagon/HexagonMCCodeEmitterTest.cpp
@@ -0,0 +1,53 @@
+#include "gtest/gtest.h"
+
+#include <memory>
+
+#include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include "MCTargetDesc/HexagonMCInst.h"
+#include "MCTargetDesc/HexagonMCTargetDesc.h"
+
+namespace {
+class TestEmitter {
+public:
+ TestEmitter() : Triple("hexagon-unknown-elf") {
+ LLVMInitializeHexagonTargetInfo();
+ LLVMInitializeHexagonTarget();
+ LLVMInitializeHexagonTargetMC();
+ std::string error;
+ Target = llvm::TargetRegistry::lookupTarget("hexagon", error);
+ assert(Target != nullptr && "Expected to find target");
+ assert(error.empty() && "Error should be empty if we have a target");
+ RegisterInfo = Target->createMCRegInfo(Triple);
+ assert(RegisterInfo != nullptr && "Expecting to find register info");
+ AsmInfo = Target->createMCAsmInfo(*RegisterInfo, Triple);
+ assert(AsmInfo != nullptr && "Expecting to find asm info");
+ Context = new llvm::MCContext(AsmInfo, RegisterInfo, nullptr);
+ assert(Context != nullptr && "Expecting to create a context");
+ Subtarget = Target->createMCSubtargetInfo(Triple, "hexagonv4", "");
+ assert(Subtarget != nullptr && "Expecting to find a subtarget");
+ InstrInfo = Target->createMCInstrInfo();
+ assert(InstrInfo != nullptr && "Expecting to find instr info");
+ Emitter = Target->createMCCodeEmitter(*InstrInfo, *RegisterInfo, *Subtarget,
+ *Context);
+ assert(Emitter != nullptr);
+ }
+ std::string Triple;
+ llvm::Target const *Target;
+ llvm::MCRegisterInfo *RegisterInfo;
+ llvm::MCAsmInfo *AsmInfo;
+ llvm::MCContext *Context;
+ llvm::MCSubtargetInfo *Subtarget;
+ llvm::MCInstrInfo *InstrInfo;
+ llvm::MCCodeEmitter *Emitter;
+};
+TestEmitter Emitter;
+}
+
+TEST(HexagonMCCodeEmitter, emitter_creation) {
+ ASSERT_NE(nullptr, Emitter.Emitter);
+}
diff --git a/unittests/MC/MCAtomTest.cpp b/unittests/MC/MCAtomTest.cpp
deleted file mode 100644
index 16228b5..0000000
--- a/unittests/MC/MCAtomTest.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- llvm/unittest/MC/MCAtomTest.cpp - Instructions 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/MC/MCAnalysis/MCAtom.h"
-#include "llvm/MC/MCAnalysis/MCModule.h"
-#include "gtest/gtest.h"
-
-namespace llvm {
-namespace {
-
-TEST(MCAtomTest, MCDataSize) {
- MCModule M;
- MCDataAtom *Atom = M.createDataAtom(0, 0);
- EXPECT_EQ(uint64_t(0), Atom->getEndAddr());
- Atom->addData(0);
- EXPECT_EQ(uint64_t(0), Atom->getEndAddr());
- Atom->addData(1);
- EXPECT_EQ(uint64_t(1), Atom->getEndAddr());
- Atom->addData(2);
- EXPECT_EQ(uint64_t(2), Atom->getEndAddr());
- EXPECT_EQ(size_t(3), Atom->getData().size());
-}
-
-} // end anonymous namespace
-} // end namespace llvm
diff --git a/unittests/MC/Makefile b/unittests/MC/Makefile
index 07a608e..3f8d1ef 100644
--- a/unittests/MC/Makefile
+++ b/unittests/MC/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../..
TESTNAME = MC
-LINK_COMPONENTS := MCAnalysis
+LINK_COMPONENTS := all-targets MCDisassembler Object
include $(LEVEL)/Makefile.config
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/unittests/MC/StringTableBuilderTest.cpp b/unittests/MC/StringTableBuilderTest.cpp
index d30dc62..6b5185c 100644
--- a/unittests/MC/StringTableBuilderTest.cpp
+++ b/unittests/MC/StringTableBuilderTest.cpp
@@ -9,20 +9,21 @@
#include "llvm/MC/StringTableBuilder.h"
#include "gtest/gtest.h"
+#include "llvm/Support/Endian.h"
#include <string>
using namespace llvm;
namespace {
-TEST(StringTableBuilderTest, Basic) {
+TEST(StringTableBuilderTest, BasicELF) {
StringTableBuilder B;
B.add("foo");
B.add("bar");
B.add("foobar");
- B.finalize();
+ B.finalize(StringTableBuilder::ELF);
std::string Expected;
Expected += '\x00';
@@ -37,4 +38,34 @@ TEST(StringTableBuilderTest, Basic) {
EXPECT_EQ(8U, B.getOffset("foo"));
}
+TEST(StringTableBuilderTest, BasicWinCOFF) {
+ StringTableBuilder B;
+
+ // Strings must be 9 chars or longer to go in the table.
+ B.add("hippopotamus");
+ B.add("pygmy hippopotamus");
+ B.add("river horse");
+
+ B.finalize(StringTableBuilder::WinCOFF);
+
+ // size_field + "pygmy hippopotamus\0" + "river horse\0"
+ uint32_t ExpectedSize = 4 + 19 + 12;
+ EXPECT_EQ(ExpectedSize, B.data().size());
+
+ std::string Expected;
+
+ ExpectedSize =
+ support::endian::byte_swap<uint32_t, support::little>(ExpectedSize);
+ Expected.append((const char*)&ExpectedSize, 4);
+ Expected += "pygmy hippopotamus";
+ Expected += '\x00';
+ Expected += "river horse";
+ Expected += '\x00';
+
+ EXPECT_EQ(Expected, B.data());
+ EXPECT_EQ(4U, B.getOffset("pygmy hippopotamus"));
+ EXPECT_EQ(10U, B.getOffset("hippopotamus"));
+ EXPECT_EQ(23U, B.getOffset("river horse"));
+}
+
}