1 //===- llvm/unittest/Object/Disassembler.cpp ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm-c/Disassembler.h"
11 #include "llvm/Support/TargetSelect.h"
12 #include "gtest/gtest.h"
16 static const char *symbolLookupCallback(void *DisInfo, uint64_t ReferenceValue,
17 uint64_t *ReferenceType,
19 const char **ReferenceName) {
20 *ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
24 TEST(Disassembler, Test1) {
25 llvm::InitializeAllTargetInfos();
26 llvm::InitializeAllTargetMCs();
27 llvm::InitializeAllDisassemblers();
29 uint8_t Bytes[] = {0x90, 0x90, 0xeb, 0xfd};
30 uint8_t *BytesP = Bytes;
31 const char OutStringSize = 100;
32 char OutString[OutStringSize];
33 LLVMDisasmContextRef DCR = LLVMCreateDisasm("x86_64-pc-linux", nullptr, 0,
34 nullptr, symbolLookupCallback);
39 unsigned NumBytes = sizeof(Bytes);
42 InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
44 EXPECT_EQ(InstSize, 1U);
45 EXPECT_EQ(StringRef(OutString), "\tnop");
50 InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
52 EXPECT_EQ(InstSize, 1U);
53 EXPECT_EQ(StringRef(OutString), "\tnop");
58 InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
60 EXPECT_EQ(InstSize, 2U);
61 EXPECT_EQ(StringRef(OutString), "\tjmp\t0x1");
63 LLVMDisasmDispose(DCR);