mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
ae65e281f3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
//===- llvm/unittest/Object/Disassembler.cpp ------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#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, X86Test) {
|
|
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);
|
|
}
|
|
|
|
TEST(Disassembler, WebAssemblyTest) {
|
|
llvm::InitializeAllTargetInfos();
|
|
llvm::InitializeAllTargetMCs();
|
|
llvm::InitializeAllDisassemblers();
|
|
|
|
uint8_t Bytes[] = {0x6a, 0x42, 0x7F, 0x35, 0x01, 0x10};
|
|
uint8_t *BytesP = Bytes;
|
|
const char OutStringSize = 100;
|
|
char OutString[OutStringSize];
|
|
LLVMDisasmContextRef DCR = LLVMCreateDisasm("wasm32-unknown-unknown", 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), "\ti32.add ");
|
|
PC += InstSize;
|
|
BytesP += InstSize;
|
|
NumBytes -= InstSize;
|
|
|
|
InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
|
|
OutStringSize);
|
|
EXPECT_EQ(InstSize, 2U);
|
|
EXPECT_EQ(StringRef(OutString), "\ti64.const\t-1");
|
|
|
|
PC += InstSize;
|
|
BytesP += InstSize;
|
|
NumBytes -= InstSize;
|
|
|
|
InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString,
|
|
OutStringSize);
|
|
EXPECT_EQ(InstSize, 3U);
|
|
EXPECT_EQ(StringRef(OutString), "\ti64.load32_u\t16:p2align=1");
|
|
|
|
LLVMDisasmDispose(DCR);
|
|
}
|