Skip to content

Commit 369686c

Browse files
Sonicadvance1Stefanos Kornilios Mitsis Poiitidis
authored andcommitted
Initial Commit
1 parent e9ea4cb commit 369686c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+8820
-4
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
21
compile_commands.json
32
vim_rc
3+
Config.json
4+
5+
[Bb]uild*/
6+
.vscode/

.gitmodules

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
[submodule "External/SonicUtils"]
2-
path = External/SonicUtils
3-
url = https://github.com/Sonicadvance1/SonicUtils.git
41
[submodule "External/vixl"]
52
path = External/vixl
63
url = https://github.com/Sonicadvance1/vixl.git
4+
[submodule "External/cpp-optparse"]
5+
path = External/cpp-optparse
6+
url = https://github.com/Sonicadvance1/cpp-optparse
7+
[submodule "External/imgui"]
8+
path = External/imgui
9+
url = https://github.com/Sonicadvance1/imgui.git
10+
[submodule "External/json-maker"]
11+
path = External/json-maker
12+
url = https://github.com/Sonicadvance1/json-maker.git
13+
[submodule "External/tiny-json"]
14+
path = External/tiny-json
15+
url = https://github.com/Sonicadvance1/tiny-json.git

CMakeLists.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(FEX)
3+
4+
option(BUILD_TESTS "Build unit tests to ensure sanity" TRUE)
5+
option(ENABLE_CLANG_FORMAT "Run clang format over the source" FALSE)
6+
option(ENABLE_LTO "Enable LTO with compilation" TRUE)
7+
option(ENABLE_XRAY "Enable building with LLVM X-Ray" FALSE)
8+
option(ENABLE_LLD "Enable linking with LLD" FALSE)
9+
option(ENABLE_ASAN "Enables Clang ASAN" FALSE)
10+
option(ENABLE_TSAN "Enables Clang TSAN" FALSE)
11+
12+
set(CMAKE_CXX_STANDARD 17)
13+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
14+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Bin)
15+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
16+
17+
if (ENABLE_LTO)
18+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
19+
endif()
20+
21+
if (ENABLE_XRAY)
22+
add_compile_options(-fxray-instrument)
23+
link_libraries(-fxray-instrument)
24+
endif()
25+
26+
if (ENABLE_LLD)
27+
link_libraries(-fuse-ld=lld)
28+
endif()
29+
30+
if (ENABLE_ASAN)
31+
add_compile_options(-fno-omit-frame-pointer -fsanitize=address)
32+
link_libraries(-fno-omit-frame-pointer -fsanitize=address)
33+
endif()
34+
35+
if (ENABLE_TSAN)
36+
add_compile_options(-fno-omit-frame-pointer -fsanitize=thread)
37+
link_libraries(-fno-omit-frame-pointer -fsanitize=thread)
38+
endif()
39+
40+
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
41+
set (CMAKE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_LINKER_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer")
42+
43+
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
44+
set (CMAKE_LINKER_FLAGS_RELEASE "${CMAKE_LINKER_FLAGS_RELEASE} -fomit-frame-pointer")
45+
46+
add_definitions(-Wno-trigraphs)
47+
48+
# add_subdirectory(External/SonicUtils/)
49+
include_directories(External/SonicUtils/)
50+
51+
add_subdirectory(External/cpp-optparse/)
52+
include_directories(External/cpp-optparse/)
53+
54+
add_subdirectory(External/imgui/)
55+
include_directories(External/imgui/)
56+
57+
add_subdirectory(External/json-maker/)
58+
include_directories(External/json-maker/)
59+
60+
add_subdirectory(External/tiny-json/)
61+
include_directories(External/tiny-json/)
62+
63+
include_directories(Source/)
64+
include_directories("${CMAKE_BINARY_DIR}/Source/")
65+
66+
add_subdirectory(External/FEXCore)
67+
68+
find_package(LLVM CONFIG QUIET)
69+
if(LLVM_FOUND AND TARGET LLVM)
70+
message(STATUS "LLVM found!")
71+
include_directories(${LLVM_INCLUDE_DIRS})
72+
endif()
73+
74+
include(CheckCXXCompilerFlag)
75+
76+
# Add in diagnostic colours if the option is available.
77+
# Ninja code generator will kill colours if this isn't here
78+
check_cxx_compiler_flag(-fdiagnostics-color=always GCC_COLOR)
79+
check_cxx_compiler_flag(-fcolor-diagnostics CLANG_COLOR)
80+
81+
if (GCC_COLOR)
82+
add_compile_options(-fdiagnostics-color=always)
83+
endif()
84+
if (CLANG_COLOR)
85+
add_compile_options(-fcolor-diagnostics)
86+
endif()
87+
88+
check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
89+
if(COMPILER_SUPPORTS_MARCH_NATIVE)
90+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
91+
endif()
92+
93+
add_compile_options(-Wall)
94+
95+
add_subdirectory(Source/)
96+
97+
if (BUILD_TESTS)
98+
enable_testing()
99+
message(STATUS "Unit tests are enabled")
100+
add_subdirectory(unittests/)
101+
endif()

External/cpp-optparse

Submodule cpp-optparse added at 5d46ee5

External/imgui

Submodule imgui added at 6ad3730

External/json-maker

Submodule json-maker added at 8ecb8ec

External/tiny-json

Submodule tiny-json added at 9d09127

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Ryan Houdek <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# FEX - Fast x86 emulation frontend
2+
This is the frontend application and tooling used for development and debugging of the FEXCore library.
3+
4+
### Dependencies
5+
* [SonicUtils](https://github.com/Sonicadvance1/SonicUtils)
6+
* FEXCore
7+
* cpp-optparse
8+
* imgui
9+
* json-maker
10+
* tiny-json
11+
* boost interprocess (sadly)
12+
* A C++17 compliant compiler (There are assumptions made about using Clang and LTO)
13+
* clang-tidy if you want the code cleaned up
14+
* cmake
15+
16+
![FEX diagram](docs/Diagram.svg)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/python3
2+
from enum import Flag
3+
import json
4+
import os
5+
import struct
6+
import sys
7+
import glob
8+
from threading import Thread
9+
import subprocess
10+
import time
11+
import multiprocessing
12+
13+
if sys.version_info[0] < 3:
14+
raise Exception("Python 3 or a more recent version is required.")
15+
16+
if (len(sys.argv) < 3):
17+
sys.exit("We need two arguments. Location of LockStepRunner and folder containing the tests")
18+
19+
# Remove our SHM regions if they still exist
20+
SHM_Files = glob.glob("/dev/shm/*_Lockstep")
21+
for file in SHM_Files:
22+
os.remove(file)
23+
24+
UnitTests = sorted(glob.glob(sys.argv[2] + "*"))
25+
UnitTestsSize = len(UnitTests)
26+
Threads = [None] * UnitTestsSize
27+
Results = [None] * UnitTestsSize
28+
ThreadResults = [[None] * 2] * UnitTestsSize
29+
MaxFileNameStringLen = 0
30+
31+
def Threaded_Runner(Args, ID, Client):
32+
Log = open("Log_" + str(ID) + "_" + str(Client), "w")
33+
Log.write("Args: %s\n" % " ".join(Args))
34+
Log.flush()
35+
Process = subprocess.Popen(Args, stdout=Log, stderr=Log)
36+
Process.wait()
37+
Log.flush()
38+
ThreadResults[ID][Client] = Process.returncode
39+
40+
def Threaded_Manager(Runner, ID, File):
41+
ServerArgs = ["catchsegv", Runner, "-c", "vm", "-n", "1", "-I", "R" + str(ID), File]
42+
ClientArgs = ["catchsegv", Runner, "-c", "vm", "-n", "1", "-I", "R" + str(ID), "-C"]
43+
44+
ServerThread = Thread(target = Threaded_Runner, args = (ServerArgs, ID, 0))
45+
ClientThread = Thread(target = Threaded_Runner, args = (ClientArgs, ID, 1))
46+
47+
ServerThread.start()
48+
ClientThread.start()
49+
50+
ClientThread.join()
51+
ServerThread.join()
52+
53+
# The server is the one we should listen to for results
54+
if (ThreadResults[ID][1] != 0 and ThreadResults[ID][0] == 0):
55+
# If the client died for some reason but server thought we were fine then take client data
56+
Results[ID] = ThreadResults[ID][1]
57+
else:
58+
# Else just take the server data
59+
Results[ID] = ThreadResults[ID][0]
60+
61+
DupLen = MaxFileNameStringLen - len(UnitTests[ID])
62+
63+
if (Results[ID] == 0):
64+
print("\t'%s'%s - PASSED ID: %d - 0" % (UnitTests[ID], " "*DupLen, ID))
65+
else:
66+
print("\t'%s'%s - FAILED ID: %d - %s" % (UnitTests[ID], " "*DupLen, ID, hex(Results[ID])))
67+
68+
RunnerSlot = 0
69+
MaxRunnerSlots = min(32, multiprocessing.cpu_count() / 2)
70+
RunnerSlots = [None] * MaxRunnerSlots
71+
for RunnerID in range(UnitTestsSize):
72+
File = UnitTests[RunnerID]
73+
print("'%s' Running Test" % File)
74+
MaxFileNameStringLen = max(MaxFileNameStringLen, len(File))
75+
Threads[RunnerID] = Thread(target = Threaded_Manager, args = (sys.argv[1], RunnerID, File))
76+
Threads[RunnerID].start()
77+
if (MaxRunnerSlots != 0):
78+
RunnerSlots[RunnerSlot] = Threads[RunnerID]
79+
RunnerSlot += 1
80+
if (RunnerSlot == MaxRunnerSlots):
81+
for i in range(MaxRunnerSlots):
82+
RunnerSlots[i].join()
83+
RunnerSlot = 0
84+
85+
for i in range(UnitTestsSize):
86+
Threads[i].join()
87+
88+
print("====== PASSED RESULTS ======")
89+
for i in range(UnitTestsSize):
90+
DupLen = MaxFileNameStringLen - len(UnitTests[i])
91+
if (Results[i] == 0):
92+
print("\t'%s'%s - PASSED ID: %d - 0" % (UnitTests[i], " "*DupLen, i))
93+
94+
print("====== FAILED RESULTS ======")
95+
for i in range(UnitTestsSize):
96+
DupLen = MaxFileNameStringLen - len(UnitTests[i])
97+
if (Results[i] != 0):
98+
print("\t'%s'%s - FAILED ID: %d - %s" % (UnitTests[i], " "*DupLen, i, hex(Results[i])))

0 commit comments

Comments
 (0)