mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-28 09:00:52 +01:00
Merge pull request #52 from Sonicadvance1/remove_old_code
Removes old test code from FEXCore
This commit is contained in:
commit
43df66de29
9 files changed
-350
No files matched your search
Vendored
-1
@@ -48,7 +48,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/External/SonicUtils/include/SonicUtils)
|
||||
|
||||
add_subdirectory(Source/)
|
||||
add_subdirectory(Examples/)
|
||||
|
||||
install (DIRECTORY include/FEXCore ${CMAKE_BINARY_DIR}/include/FEXCore
|
||||
DESTINATION include
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
set (SRCS
|
||||
SimpleCodeLoader.cpp)
|
||||
|
||||
set (ExampleName SimpleCodeLoader)
|
||||
|
||||
add_executable(${ExampleName} ${SRCS})
|
||||
target_link_libraries(${ExampleName} PRIVATE ${PROJECT_NAME} SonicUtils)
|
||||
|
||||
set (SRCS
|
||||
SimplePrint.cpp)
|
||||
|
||||
set (ExampleName SimplePrint)
|
||||
|
||||
add_executable(${ExampleName} ${SRCS})
|
||||
target_link_libraries(${ExampleName} PRIVATE ${PROJECT_NAME} SonicUtils)
|
||||
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
#include "LogManager.h"
|
||||
#include "SimpleCodeLoader.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
#include <FEXCore/Core/Context.h>
|
||||
#include <FEXCore/Memory/SharedMem.h>
|
||||
#include <cstdio>
|
||||
|
||||
void MsgHandler(LogMan::DebugLevels Level, const char *Message) {
|
||||
const char *CharLevel{nullptr};
|
||||
|
||||
switch (Level) {
|
||||
case LogMan::NONE:
|
||||
CharLevel = "NONE";
|
||||
break;
|
||||
case LogMan::ASSERT:
|
||||
CharLevel = "ASSERT";
|
||||
break;
|
||||
case LogMan::ERROR:
|
||||
CharLevel = "ERROR";
|
||||
break;
|
||||
case LogMan::DEBUG:
|
||||
CharLevel = "DEBUG";
|
||||
break;
|
||||
case LogMan::INFO:
|
||||
CharLevel = "Info";
|
||||
break;
|
||||
default:
|
||||
CharLevel = "???";
|
||||
break;
|
||||
}
|
||||
printf("[%s] %s\n", CharLevel, Message);
|
||||
}
|
||||
|
||||
void AssertHandler(const char *Message) {
|
||||
printf("[ASSERT] %s\n", Message);
|
||||
}
|
||||
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
|
||||
LogMan::Throw::InstallHandler(AssertHandler);
|
||||
LogMan::Msg::InstallHandler(MsgHandler);
|
||||
|
||||
static constexpr uint8_t RawCode[] = {
|
||||
0x90, // NOP
|
||||
0xF4 // HLT
|
||||
};
|
||||
|
||||
TestCode Test(RawCode, sizeof(RawCode));
|
||||
FEXCore::Context::InitializeStaticTables();
|
||||
auto SHM = FEXCore::SHM::AllocateSHMRegion(1ULL << 36);
|
||||
auto CTX = FEXCore::Context::CreateNewContext();
|
||||
|
||||
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MAXBLOCKINST, 1);
|
||||
FEXCore::Context::AddGuestMemoryRegion(CTX, SHM);
|
||||
FEXCore::Context::InitCore(CTX, &Test);
|
||||
|
||||
auto ShutdownReason = FEXCore::Context::RunUntilExit(CTX);
|
||||
LogMan::Msg::D("Reason we left VM: %d", ShutdownReason);
|
||||
|
||||
FEXCore::Context::DestroyContext(CTX);
|
||||
FEXCore::SHM::DestroyRegion(SHM);
|
||||
return 0;
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <FEXCore/Core/CodeLoader.h>
|
||||
|
||||
class TestCode final : public FEXCore::CodeLoader {
|
||||
public:
|
||||
|
||||
TestCode(uint8_t const *Code, size_t Size)
|
||||
: CodePtr {Code}
|
||||
, CodeSize {Size} {
|
||||
}
|
||||
|
||||
uint64_t StackSize() const override {
|
||||
return STACK_SIZE;
|
||||
}
|
||||
|
||||
uint64_t SetupStack([[maybe_unused]] void *HostPtr, uint64_t GuestPtr) const override {
|
||||
return GuestPtr + STACK_SIZE - 16;
|
||||
}
|
||||
|
||||
uint64_t DefaultRIP() const override {
|
||||
return RIP;
|
||||
}
|
||||
|
||||
FEXCore::CodeLoader::MemoryLayout GetLayout() const override {
|
||||
// Needs to be page aligned
|
||||
constexpr uint64_t ConstCodeSize = 0x1000;
|
||||
return std::make_tuple(CODE_START_RANGE, CODE_START_RANGE + ConstCodeSize, ConstCodeSize);
|
||||
}
|
||||
|
||||
void MapMemoryRegion(std::function<void* (uint64_t, uint64_t)> Mapper) override {
|
||||
}
|
||||
|
||||
void LoadMemory(MemoryWriter Writer) override {
|
||||
Writer(reinterpret_cast<void const*>(CodePtr), 0, CodeSize);
|
||||
}
|
||||
|
||||
uint64_t GetFinalRIP() override { return CODE_START_RANGE + CodeSize; }
|
||||
|
||||
private:
|
||||
static constexpr uint64_t STACK_SIZE = 0x1000;
|
||||
static constexpr uint64_t CODE_START_RANGE = 0x0;
|
||||
static constexpr uint64_t RIP = 0;
|
||||
|
||||
uint8_t const *CodePtr;
|
||||
size_t CodeSize;
|
||||
|
||||
};
|
||||
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
#include "LogManager.h"
|
||||
#include "SimpleCodeLoader.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
#include <FEXCore/Core/Context.h>
|
||||
#include <FEXCore/Memory/SharedMem.h>
|
||||
#include <cstdio>
|
||||
|
||||
void MsgHandler(LogMan::DebugLevels Level, char const *Message) {
|
||||
const char *CharLevel{nullptr};
|
||||
|
||||
switch (Level) {
|
||||
case LogMan::NONE:
|
||||
CharLevel = "NONE";
|
||||
break;
|
||||
case LogMan::ASSERT:
|
||||
CharLevel = "ASSERT";
|
||||
break;
|
||||
case LogMan::ERROR:
|
||||
CharLevel = "ERROR";
|
||||
break;
|
||||
case LogMan::DEBUG:
|
||||
CharLevel = "DEBUG";
|
||||
break;
|
||||
case LogMan::INFO:
|
||||
CharLevel = "Info";
|
||||
break;
|
||||
case LogMan::STDERR:
|
||||
CharLevel = "STDERR";
|
||||
break;
|
||||
case LogMan::STDOUT:
|
||||
CharLevel = "STDOUT";
|
||||
break;
|
||||
default:
|
||||
CharLevel = "???";
|
||||
break;
|
||||
}
|
||||
printf("[%s] %s\n", CharLevel, Message);
|
||||
}
|
||||
|
||||
void AssertHandler(char const *Message) {
|
||||
printf("[ASSERT] %s\n", Message);
|
||||
}
|
||||
|
||||
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
|
||||
LogMan::Throw::InstallHandler(AssertHandler);
|
||||
LogMan::Msg::InstallHandler(MsgHandler);
|
||||
|
||||
// Set up a syscall to do a syscall WRITE to stdout
|
||||
// Syscall handler catches writes to stdout/stderr and pumps it through LogManager
|
||||
static constexpr uint8_t RawCode[] = {
|
||||
0X48,
|
||||
0XC7,
|
||||
0XC0,
|
||||
0X01,
|
||||
0X00,
|
||||
0X00,
|
||||
0X00, // MOV RAX, 0x1
|
||||
|
||||
0X48,
|
||||
0XC7,
|
||||
0XC7,
|
||||
0X01,
|
||||
0X00,
|
||||
0X00,
|
||||
0X00, // MOV RDI, 0x1
|
||||
|
||||
0X48,
|
||||
0XC7,
|
||||
0XC6,
|
||||
0X1F,
|
||||
0X00,
|
||||
0X00,
|
||||
0X00, // MOV RSI, 0x1F
|
||||
|
||||
0X48,
|
||||
0XC7,
|
||||
0XC2,
|
||||
0X01,
|
||||
0X00,
|
||||
0X00,
|
||||
0X00, // MOV RDX, 1
|
||||
|
||||
0X0F,
|
||||
0X05, // SYSCALL
|
||||
|
||||
0XF4, // HLT
|
||||
|
||||
0X54,
|
||||
0X65,
|
||||
0X73,
|
||||
0X74,
|
||||
0X65,
|
||||
0X72,
|
||||
0X00, // 'Tester\0'
|
||||
};
|
||||
|
||||
TestCode Test(RawCode, sizeof(RawCode));
|
||||
FEXCore::Context::InitializeStaticTables();
|
||||
auto SHM = FEXCore::SHM::AllocateSHMRegion(1ULL << 36);
|
||||
auto CTX = FEXCore::Context::CreateNewContext();
|
||||
|
||||
// FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MAXBLOCKINST, 1);
|
||||
FEXCore::Context::AddGuestMemoryRegion(CTX, SHM);
|
||||
FEXCore::Context::InitCore(CTX, &Test);
|
||||
|
||||
auto ShutdownReason = FEXCore::Context::RunUntilExit(CTX);
|
||||
LogMan::Msg::D("Reason we left VM: %d", ShutdownReason);
|
||||
|
||||
FEXCore::Context::DestroyContext(CTX);
|
||||
FEXCore::SHM::DestroyRegion(SHM);
|
||||
return 0;
|
||||
}
|
||||
-2
@@ -180,5 +180,3 @@ install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_shared
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
COMPONENT Libraries)
|
||||
|
||||
add_subdirectory(Test/)
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
set (NAME IRTest)
|
||||
set (SRCS IRTest.cpp)
|
||||
|
||||
add_executable(${NAME} ${SRCS})
|
||||
add_dependencies(${NAME} IR_INC)
|
||||
|
||||
target_link_libraries(${NAME} ${PROJECT_NAME} SonicUtils)
|
||||
|
||||
set (NAME LLVMIRTest)
|
||||
set (SRCS LLVMIRTest.cpp)
|
||||
|
||||
add_executable(${NAME} ${SRCS})
|
||||
add_dependencies(${NAME} IR_INC)
|
||||
|
||||
target_link_libraries(${NAME} ${PROJECT_NAME} SonicUtils)
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
#include <FEXCore/IR/IntrusiveIRList.h>
|
||||
|
||||
#include "LogManager.h"
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("IR Test\n");
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
#include <llvm-c/Core.h>
|
||||
#include <llvm/ExecutionEngine/ExecutionEngine.h>
|
||||
#include <llvm/InitializePasses.h>
|
||||
#include <llvm/IR/IRBuilder.h>
|
||||
#include <llvm/IR/IRPrintingPasses.h>
|
||||
#include <llvm/IR/LLVMContext.h>
|
||||
#include <llvm/IR/LegacyPassManager.h>
|
||||
#include <llvm/IR/Verifier.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
#include <llvm/Support/TargetSelect.h>
|
||||
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
|
||||
#include <llvm/Transforms/Scalar.h>
|
||||
#include <llvm/Transforms/Vectorize.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("LLVM Test\n");
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
|
||||
auto ContextRef = LLVMContextCreate();
|
||||
auto Con = *llvm::unwrap(&ContextRef);
|
||||
auto MainModule = new llvm::Module("Main Module", *Con);
|
||||
auto IRBuilder = new llvm::IRBuilder<>(*Con);
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
Type *i64 = Type::getInt64Ty(*Con);
|
||||
auto FunctionType = FunctionType::get(Type::getVoidTy(*Con),
|
||||
{
|
||||
i64,
|
||||
}, false);
|
||||
|
||||
|
||||
legacy::PassManager PM;
|
||||
PassManagerBuilder PMBuilder;
|
||||
PMBuilder.OptLevel = 3;
|
||||
PMBuilder.populateModulePassManager(PM);
|
||||
|
||||
std::string Empty;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
|
||||
auto Func = Function::Create(FunctionType,
|
||||
Function::ExternalLinkage,
|
||||
Empty,
|
||||
MainModule);
|
||||
Func->setCallingConv(CallingConv::C);
|
||||
|
||||
{
|
||||
auto Entry = BasicBlock::Create(*Con, Empty, Func);
|
||||
IRBuilder->SetInsertPoint(Entry);
|
||||
|
||||
auto ExitBlock = BasicBlock::Create(*Con, Empty, Func);
|
||||
|
||||
IRBuilder->SetInsertPoint(ExitBlock);
|
||||
IRBuilder->CreateRetVoid();
|
||||
|
||||
IRBuilder->SetInsertPoint(Entry);
|
||||
IRBuilder->CreateBr(ExitBlock);
|
||||
}
|
||||
|
||||
//printf("i: %d\n", i);
|
||||
PM.run(*MainModule);
|
||||
|
||||
auto FunctionList = &MainModule->getFunctionList();
|
||||
FunctionList->clear();
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto diff = end - start;
|
||||
|
||||
printf("Took %ld(%ldms) nanoseconds\n", diff.count(), std::chrono::duration_cast<std::chrono::milliseconds>(diff).count());
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user