Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonicadvance1 authored and Stefanos Kornilios Mitsis Poiitidis committed Mar 6, 2020
1 parent e9ea4cb commit 369686c
Show file tree
Hide file tree
Showing 73 changed files with 8,820 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

compile_commands.json
vim_rc
Config.json

[Bb]uild*/
.vscode/
15 changes: 12 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
[submodule "External/SonicUtils"]
path = External/SonicUtils
url = https://github.com/Sonicadvance1/SonicUtils.git
[submodule "External/vixl"]
path = External/vixl
url = https://github.com/Sonicadvance1/vixl.git
[submodule "External/cpp-optparse"]
path = External/cpp-optparse
url = https://github.com/Sonicadvance1/cpp-optparse
[submodule "External/imgui"]
path = External/imgui
url = https://github.com/Sonicadvance1/imgui.git
[submodule "External/json-maker"]
path = External/json-maker
url = https://github.com/Sonicadvance1/json-maker.git
[submodule "External/tiny-json"]
path = External/tiny-json
url = https://github.com/Sonicadvance1/tiny-json.git
101 changes: 101 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
cmake_minimum_required(VERSION 3.10)
project(FEX)

option(BUILD_TESTS "Build unit tests to ensure sanity" TRUE)
option(ENABLE_CLANG_FORMAT "Run clang format over the source" FALSE)
option(ENABLE_LTO "Enable LTO with compilation" TRUE)
option(ENABLE_XRAY "Enable building with LLVM X-Ray" FALSE)
option(ENABLE_LLD "Enable linking with LLD" FALSE)
option(ENABLE_ASAN "Enables Clang ASAN" FALSE)
option(ENABLE_TSAN "Enables Clang TSAN" FALSE)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

if (ENABLE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

if (ENABLE_XRAY)
add_compile_options(-fxray-instrument)
link_libraries(-fxray-instrument)
endif()

if (ENABLE_LLD)
link_libraries(-fuse-ld=lld)
endif()

if (ENABLE_ASAN)
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
link_libraries(-fno-omit-frame-pointer -fsanitize=address)
endif()

if (ENABLE_TSAN)
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread)
link_libraries(-fno-omit-frame-pointer -fsanitize=thread)
endif()

set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
set (CMAKE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")

set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
set (CMAKE_LINKER_FLAGS_RELEASE "${CMAKE_LINKER_FLAGS_RELEASE} -fomit-frame-pointer")

add_definitions(-Wno-trigraphs)

# add_subdirectory(External/SonicUtils/)
include_directories(External/SonicUtils/)

add_subdirectory(External/cpp-optparse/)
include_directories(External/cpp-optparse/)

add_subdirectory(External/imgui/)
include_directories(External/imgui/)

add_subdirectory(External/json-maker/)
include_directories(External/json-maker/)

add_subdirectory(External/tiny-json/)
include_directories(External/tiny-json/)

include_directories(Source/)
include_directories("${CMAKE_BINARY_DIR}/Source/")

add_subdirectory(External/FEXCore)

find_package(LLVM CONFIG QUIET)
if(LLVM_FOUND AND TARGET LLVM)
message(STATUS "LLVM found!")
include_directories(${LLVM_INCLUDE_DIRS})
endif()

include(CheckCXXCompilerFlag)

# Add in diagnostic colours if the option is available.
# Ninja code generator will kill colours if this isn't here
check_cxx_compiler_flag(-fdiagnostics-color=always GCC_COLOR)
check_cxx_compiler_flag(-fcolor-diagnostics CLANG_COLOR)

if (GCC_COLOR)
add_compile_options(-fdiagnostics-color=always)
endif()
if (CLANG_COLOR)
add_compile_options(-fcolor-diagnostics)
endif()

check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()

add_compile_options(-Wall)

add_subdirectory(Source/)

if (BUILD_TESTS)
enable_testing()
message(STATUS "Unit tests are enabled")
add_subdirectory(unittests/)
endif()
1 change: 1 addition & 0 deletions External/cpp-optparse
Submodule cpp-optparse added at 5d46ee
1 change: 1 addition & 0 deletions External/imgui
Submodule imgui added at 6ad373
1 change: 1 addition & 0 deletions External/json-maker
Submodule json-maker added at 8ecb8e
1 change: 1 addition & 0 deletions External/tiny-json
Submodule tiny-json added at 9d0912
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Ryan Houdek <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# FEX - Fast x86 emulation frontend
This is the frontend application and tooling used for development and debugging of the FEXCore library.

### Dependencies
* [SonicUtils](https://github.com/Sonicadvance1/SonicUtils)
* FEXCore
* cpp-optparse
* imgui
* json-maker
* tiny-json
* boost interprocess (sadly)
* A C++17 compliant compiler (There are assumptions made about using Clang and LTO)
* clang-tidy if you want the code cleaned up
* cmake

![FEX diagram](docs/Diagram.svg)
98 changes: 98 additions & 0 deletions Scripts/Threaded_Lockstep_Runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/python3
from enum import Flag
import json
import os
import struct
import sys
import glob
from threading import Thread
import subprocess
import time
import multiprocessing

if sys.version_info[0] < 3:
raise Exception("Python 3 or a more recent version is required.")

if (len(sys.argv) < 3):
sys.exit("We need two arguments. Location of LockStepRunner and folder containing the tests")

# Remove our SHM regions if they still exist
SHM_Files = glob.glob("/dev/shm/*_Lockstep")
for file in SHM_Files:
os.remove(file)

UnitTests = sorted(glob.glob(sys.argv[2] + "*"))
UnitTestsSize = len(UnitTests)
Threads = [None] * UnitTestsSize
Results = [None] * UnitTestsSize
ThreadResults = [[None] * 2] * UnitTestsSize
MaxFileNameStringLen = 0

def Threaded_Runner(Args, ID, Client):
Log = open("Log_" + str(ID) + "_" + str(Client), "w")
Log.write("Args: %s\n" % " ".join(Args))
Log.flush()
Process = subprocess.Popen(Args, stdout=Log, stderr=Log)
Process.wait()
Log.flush()
ThreadResults[ID][Client] = Process.returncode

def Threaded_Manager(Runner, ID, File):
ServerArgs = ["catchsegv", Runner, "-c", "vm", "-n", "1", "-I", "R" + str(ID), File]
ClientArgs = ["catchsegv", Runner, "-c", "vm", "-n", "1", "-I", "R" + str(ID), "-C"]

ServerThread = Thread(target = Threaded_Runner, args = (ServerArgs, ID, 0))
ClientThread = Thread(target = Threaded_Runner, args = (ClientArgs, ID, 1))

ServerThread.start()
ClientThread.start()

ClientThread.join()
ServerThread.join()

# The server is the one we should listen to for results
if (ThreadResults[ID][1] != 0 and ThreadResults[ID][0] == 0):
# If the client died for some reason but server thought we were fine then take client data
Results[ID] = ThreadResults[ID][1]
else:
# Else just take the server data
Results[ID] = ThreadResults[ID][0]

DupLen = MaxFileNameStringLen - len(UnitTests[ID])

if (Results[ID] == 0):
print("\t'%s'%s - PASSED ID: %d - 0" % (UnitTests[ID], " "*DupLen, ID))
else:
print("\t'%s'%s - FAILED ID: %d - %s" % (UnitTests[ID], " "*DupLen, ID, hex(Results[ID])))

RunnerSlot = 0
MaxRunnerSlots = min(32, multiprocessing.cpu_count() / 2)
RunnerSlots = [None] * MaxRunnerSlots
for RunnerID in range(UnitTestsSize):
File = UnitTests[RunnerID]
print("'%s' Running Test" % File)
MaxFileNameStringLen = max(MaxFileNameStringLen, len(File))
Threads[RunnerID] = Thread(target = Threaded_Manager, args = (sys.argv[1], RunnerID, File))
Threads[RunnerID].start()
if (MaxRunnerSlots != 0):
RunnerSlots[RunnerSlot] = Threads[RunnerID]
RunnerSlot += 1
if (RunnerSlot == MaxRunnerSlots):
for i in range(MaxRunnerSlots):
RunnerSlots[i].join()
RunnerSlot = 0

for i in range(UnitTestsSize):
Threads[i].join()

print("====== PASSED RESULTS ======")
for i in range(UnitTestsSize):
DupLen = MaxFileNameStringLen - len(UnitTests[i])
if (Results[i] == 0):
print("\t'%s'%s - PASSED ID: %d - 0" % (UnitTests[i], " "*DupLen, i))

print("====== FAILED RESULTS ======")
for i in range(UnitTestsSize):
DupLen = MaxFileNameStringLen - len(UnitTests[i])
if (Results[i] != 0):
print("\t'%s'%s - FAILED ID: %d - %s" % (UnitTests[i], " "*DupLen, i, hex(Results[i])))
Loading

0 comments on commit 369686c

Please sign in to comment.