From 50814f8529747694bf530ed3cbd59ec44d7fc993 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Wed, 26 Aug 2020 00:06:13 -0400 Subject: [PATCH 01/17] Add Github Actions and cleanup most test spam --- .github/workflows/linux-workflow.yaml | 26 ++ .gitmodules | 2 +- test.sh | 2 +- test/test_listener_deci2.cpp | 25 +- .../run-clang-format/run-clang-format.py | 404 ++++++++++++++++++ 5 files changed, 444 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/linux-workflow.yaml create mode 100644 third-party/run-clang-format/run-clang-format.py diff --git a/.github/workflows/linux-workflow.yaml b/.github/workflows/linux-workflow.yaml new file mode 100644 index 0000000000..c72db11797 --- /dev/null +++ b/.github/workflows/linux-workflow.yaml @@ -0,0 +1,26 @@ +name: Linux Workflow +on: [push] + +jobs: + build: + name: Build and Test Project (Linux) + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Get Package Dependencies + run: sudo apt install gcc make cmake build-essential g++ nasm clang-format + - name: Initialize Submodules + run: git submodule update --init --recursive + - name: Build Project with CMake + run: | + mkdir build + cd build + cmake .. + make -j + - name: Test Project with gTest + run: ./test.sh + - name: Check Clang-Formatting + run: | + chmod +x ./third-party/run-clang-format/run-clang-format.py + ./third-party/run-clang-format/run-clang-format.py -r common decompiler game goalc test --color always diff --git a/.gitmodules b/.gitmodules index 3f127b847c..522084739f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "third-party/googletest"] path = third-party/googletest - url = https://github.com/google/googletest.git + url = https://github.com/google/googletest.git \ No newline at end of file diff --git a/test.sh b/test.sh index aa21329103..4d275a0f83 100755 --- a/test.sh +++ b/test.sh @@ -4,4 +4,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" export NEXT_DIR=$DIR -$DIR/build/test/goalc-test "$@" \ No newline at end of file +$DIR/build/test/goalc-test --gtest_color=yes --gtest_brief=1 "$@" \ No newline at end of file diff --git a/test/test_listener_deci2.cpp b/test/test_listener_deci2.cpp index 4efa4d5bd9..d5730ded94 100644 --- a/test/test_listener_deci2.cpp +++ b/test/test_listener_deci2.cpp @@ -8,7 +8,7 @@ namespace { bool always_false() { return false; } -} +} // namespace TEST(Listener, ListenerCreation) { listener::Listener l; @@ -23,7 +23,7 @@ TEST(Listener, DeciInit) { EXPECT_TRUE(s.init()); } -//TEST(Listener, TwoDeciServers) { +// TEST(Listener, TwoDeciServers) { // Deci2Server s1, s2; // EXPECT_TRUE(s1.init()); // EXPECT_TRUE(s2.init()); @@ -47,7 +47,7 @@ TEST(Listener, DeciCheckNoListener) { } TEST(Listener, DeciThenListener) { - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { Deci2Server s(always_false); EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); @@ -58,8 +58,8 @@ TEST(Listener, DeciThenListener) { EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); // kind of a hack. - while(!s.check_for_listener()) { - printf("...\n"); + while (!s.check_for_listener()) { + // printf("...\n"); } EXPECT_TRUE(s.check_for_listener()); @@ -67,7 +67,7 @@ TEST(Listener, DeciThenListener) { } TEST(Listener, DeciThenListener2) { - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { Deci2Server s(always_false); EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); @@ -81,14 +81,14 @@ TEST(Listener, DeciThenListener2) { } TEST(Listener, ListenerThenDeci) { - for(int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) { Listener l; EXPECT_FALSE(l.connect_to_target()); Deci2Server s(always_false); EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); - while(!s.check_for_listener()) { + while (!s.check_for_listener()) { printf("...\n"); } } @@ -102,8 +102,8 @@ TEST(Listener, ListenerMultipleDecis) { EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); - while(!s.check_for_listener()) { - printf("...\n"); + while (!s.check_for_listener()) { + // printf("...\n"); } l.disconnect(); } @@ -113,10 +113,9 @@ TEST(Listener, ListenerMultipleDecis) { EXPECT_TRUE(s.init()); EXPECT_FALSE(s.check_for_listener()); EXPECT_TRUE(l.connect_to_target()); - while(!s.check_for_listener()) { - printf("...\n"); + while (!s.check_for_listener()) { + // printf("...\n"); } l.disconnect(); } - } \ No newline at end of file diff --git a/third-party/run-clang-format/run-clang-format.py b/third-party/run-clang-format/run-clang-format.py new file mode 100644 index 0000000000..bbd84071bd --- /dev/null +++ b/third-party/run-clang-format/run-clang-format.py @@ -0,0 +1,404 @@ +#!/usr/bin/env python +"""A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. + +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +See - https://github.com/Sarcasm/run-clang-format + +""" + +from __future__ import print_function, unicode_literals + +import argparse +import codecs +import difflib +import fnmatch +import io +import errno +import multiprocessing +import os +import signal +import subprocess +import sys +import traceback + +from functools import partial + +try: + from subprocess import DEVNULL # py3k +except ImportError: + DEVNULL = open(os.devnull, "wb") + + +DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' +DEFAULT_CLANG_FORMAT_IGNORE = '.clang-format-ignore' + + +class ExitStatus: + SUCCESS = 0 + DIFF = 1 + TROUBLE = 2 + +def excludes_from_file(ignore_file): + excludes = [] + try: + with io.open(ignore_file, 'r', encoding='utf-8') as f: + for line in f: + if line.startswith('#'): + # ignore comments + continue + pattern = line.rstrip() + if not pattern: + # allow empty lines + continue + excludes.append(pattern) + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise + return excludes; + +def list_files(files, recursive=False, extensions=None, exclude=None): + if extensions is None: + extensions = [] + if exclude is None: + exclude = [] + + out = [] + for file in files: + if recursive and os.path.isdir(file): + for dirpath, dnames, fnames in os.walk(file): + fpaths = [os.path.join(dirpath, fname) for fname in fnames] + for pattern in exclude: + # os.walk() supports trimming down the dnames list + # by modifying it in-place, + # to avoid unnecessary directory listings. + dnames[:] = [ + x for x in dnames + if + not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) + ] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern) + ] + for f in fpaths: + ext = os.path.splitext(f)[1][1:] + if ext in extensions: + out.append(f) + else: + out.append(file) + return out + + +def make_diff(file, original, reformatted): + return list( + difflib.unified_diff( + original, + reformatted, + fromfile='{}\t(original)'.format(file), + tofile='{}\t(reformatted)'.format(file), + n=3)) + + +class DiffError(Exception): + def __init__(self, message, errs=None): + super(DiffError, self).__init__(message) + self.errs = errs or [] + + +class UnexpectedError(Exception): + def __init__(self, message, exc=None): + super(UnexpectedError, self).__init__(message) + self.formatted_traceback = traceback.format_exc() + self.exc = exc + + +def run_clang_format_diff_wrapper(args, file): + try: + ret = run_clang_format_diff(args, file) + return ret + except DiffError: + raise + except Exception as e: + raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__, + e), e) + + +def run_clang_format_diff(args, file): + try: + with io.open(file, 'r', encoding='utf-8') as f: + original = f.readlines() + except IOError as exc: + raise DiffError(str(exc)) + + if args.in_place: + invocation = [args.clang_format_executable, '-i', file] + else: + invocation = [args.clang_format_executable, file] + + if args.dry_run: + print(" ".join(invocation)) + return [], [] + + # Use of utf-8 to decode the process output. + # + # Hopefully, this is the correct thing to do. + # + # It's done due to the following assumptions (which may be incorrect): + # - clang-format will returns the bytes read from the files as-is, + # without conversion, and it is already assumed that the files use utf-8. + # - if the diagnostics were internationalized, they would use utf-8: + # > Adding Translations to Clang + # > + # > Not possible yet! + # > Diagnostic strings should be written in UTF-8, + # > the client can translate to the relevant code page if needed. + # > Each translation completely replaces the format string + # > for the diagnostic. + # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation + # + # It's not pretty, due to Python 2 & 3 compatibility. + encoding_py3 = {} + if sys.version_info[0] >= 3: + encoding_py3['encoding'] = 'utf-8' + + try: + proc = subprocess.Popen( + invocation, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + **encoding_py3) + except OSError as exc: + raise DiffError( + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(invocation), exc + ) + ) + proc_stdout = proc.stdout + proc_stderr = proc.stderr + if sys.version_info[0] < 3: + # make the pipes compatible with Python 3, + # reading lines should output unicode + encoding = 'utf-8' + proc_stdout = codecs.getreader(encoding)(proc_stdout) + proc_stderr = codecs.getreader(encoding)(proc_stderr) + # hopefully the stderr pipe won't get full and block the process + outs = list(proc_stdout.readlines()) + errs = list(proc_stderr.readlines()) + proc.wait() + if proc.returncode: + raise DiffError( + "Command '{}' returned non-zero exit status {}".format( + subprocess.list2cmdline(invocation), proc.returncode + ), + errs, + ) + if args.in_place: + return [], errs + return make_diff(file, original, outs), errs + + +def bold_red(s): + return '\x1b[1m\x1b[31m' + s + '\x1b[0m' + + +def colorize(diff_lines): + def bold(s): + return '\x1b[1m' + s + '\x1b[0m' + + def cyan(s): + return '\x1b[36m' + s + '\x1b[0m' + + def green(s): + return '\x1b[32m' + s + '\x1b[0m' + + def red(s): + return '\x1b[31m' + s + '\x1b[0m' + + for line in diff_lines: + if line[:4] in ['--- ', '+++ ']: + yield bold(line) + elif line.startswith('@@ '): + yield cyan(line) + elif line.startswith('+'): + yield green(line) + elif line.startswith('-'): + yield red(line) + else: + yield line + + +def print_diff(diff_lines, use_color): + if use_color: + diff_lines = colorize(diff_lines) + if sys.version_info[0] < 3: + sys.stdout.writelines((l.encode('utf-8') for l in diff_lines)) + else: + sys.stdout.writelines(diff_lines) + + +def print_trouble(prog, message, use_colors): + error_text = 'error:' + if use_colors: + error_text = bold_red(error_text) + print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--clang-format-executable', + metavar='EXECUTABLE', + help='path to the clang-format executable', + default='clang-format') + parser.add_argument( + '--extensions', + help='comma separated list of file extensions (default: {})'.format( + DEFAULT_EXTENSIONS), + default=DEFAULT_EXTENSIONS) + parser.add_argument( + '-r', + '--recursive', + action='store_true', + help='run recursively over directories') + parser.add_argument( + '-d', + '--dry-run', + action='store_true', + help='just print the list of files') + parser.add_argument( + '-i', + '--in-place', + action='store_true', + help='format file instead of printing differences') + parser.add_argument('files', metavar='file', nargs='+') + parser.add_argument( + '-q', + '--quiet', + action='store_true', + help="disable output, useful for the exit code") + parser.add_argument( + '-j', + metavar='N', + type=int, + default=0, + help='run N clang-format jobs in parallel' + ' (default number of cpus + 1)') + parser.add_argument( + '--color', + default='auto', + choices=['auto', 'always', 'never'], + help='show colored diff (default: auto)') + parser.add_argument( + '-e', + '--exclude', + metavar='PATTERN', + action='append', + default=[], + help='exclude paths matching the given glob-like pattern(s)' + ' from recursive search') + + args = parser.parse_args() + + # use default signal handling, like diff return SIGINT value on ^C + # https://bugs.python.org/issue14229#msg156446 + signal.signal(signal.SIGINT, signal.SIG_DFL) + try: + signal.SIGPIPE + except AttributeError: + # compatibility, SIGPIPE does not exist on Windows + pass + else: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + colored_stdout = False + colored_stderr = False + if args.color == 'always': + colored_stdout = True + colored_stderr = True + elif args.color == 'auto': + colored_stdout = sys.stdout.isatty() + colored_stderr = sys.stderr.isatty() + + version_invocation = [args.clang_format_executable, str("--version")] + try: + subprocess.check_call(version_invocation, stdout=DEVNULL) + except subprocess.CalledProcessError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + return ExitStatus.TROUBLE + except OSError as e: + print_trouble( + parser.prog, + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(version_invocation), e + ), + use_colors=colored_stderr, + ) + return ExitStatus.TROUBLE + + retcode = ExitStatus.SUCCESS + + excludes = excludes_from_file(DEFAULT_CLANG_FORMAT_IGNORE) + excludes.extend(args.exclude) + + files = list_files( + args.files, + recursive=args.recursive, + exclude=excludes, + extensions=args.extensions.split(',')) + + if not files: + return + + njobs = args.j + if njobs == 0: + njobs = multiprocessing.cpu_count() + 1 + njobs = min(len(files), njobs) + + if njobs == 1: + # execute directly instead of in a pool, + # less overhead, simpler stacktraces + it = (run_clang_format_diff_wrapper(args, file) for file in files) + pool = None + else: + pool = multiprocessing.Pool(njobs) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) + pool.close() + while True: + try: + outs, errs = next(it) + except StopIteration: + break + except DiffError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + retcode = ExitStatus.TROUBLE + sys.stderr.writelines(e.errs) + except UnexpectedError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + sys.stderr.write(e.formatted_traceback) + retcode = ExitStatus.TROUBLE + # stop at the first unexpected error, + # something could be very wrong, + # don't process all files unnecessarily + if pool: + pool.terminate() + break + else: + sys.stderr.writelines(errs) + if outs == []: + continue + if not args.quiet: + print_diff(outs, use_color=colored_stdout) + if retcode == ExitStatus.SUCCESS: + retcode = ExitStatus.DIFF + if pool: + pool.join() + return retcode + + +if __name__ == '__main__': + sys.exit(main()) From 3c4fcbdd3440a333e8971d33348592876a024bd8 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Wed, 26 Aug 2020 01:21:33 -0400 Subject: [PATCH 02/17] clang-format all the things --- common/goal_constants.h | 8 +- common/symbols.h | 123 +++++------ common/type_system/type_util.h | 4 +- common/versions.h | 2 +- decompiler/Function/Function.h | 20 +- decompiler/ObjectFile/LinkedObjectFile.cpp | 10 +- decompiler/ObjectFile/LinkedObjectFile.h | 25 ++- .../ObjectFile/LinkedObjectFileCreation.cpp | 1 - .../ObjectFile/LinkedObjectFileCreation.h | 2 +- decompiler/ObjectFile/ObjectFileDB.cpp | 73 +++---- decompiler/ObjectFile/ObjectFileDB.h | 10 +- decompiler/TypeSystem/GoalFunction.h | 14 +- decompiler/TypeSystem/GoalSymbol.h | 11 +- decompiler/TypeSystem/GoalType.h | 10 +- decompiler/TypeSystem/TypeInfo.cpp | 13 +- decompiler/TypeSystem/TypeSpec.h | 5 +- decompiler/main.cpp | 4 +- decompiler/util/BinaryReader.h | 28 +-- decompiler/util/FileIO.cpp | 12 +- decompiler/util/FileIO.h | 2 +- decompiler/util/LispPrint.cpp | 194 +++++++++--------- game/kernel/kmemcard.h | 1 - game/main.cpp | 2 +- game/overlord/dma.cpp | 2 +- game/overlord/fake_iso.cpp | 6 +- game/overlord/fake_iso.h | 2 +- game/overlord/iso.cpp | 3 +- game/overlord/iso_api.cpp | 8 +- game/overlord/iso_api.h | 6 +- game/overlord/iso_queue.cpp | 144 ++++++------- game/overlord/iso_queue.h | 14 +- game/overlord/overlord.cpp | 53 +++-- game/overlord/overlord.h | 2 +- game/overlord/sbank.cpp | 4 +- game/overlord/sbank.h | 2 +- game/overlord/soundcommon.cpp | 1 - game/overlord/soundcommon.h | 2 +- game/overlord/srpc.h | 2 +- game/overlord/ssound.cpp | 4 +- game/overlord/ssound.h | 2 +- game/overlord/stream.h | 2 +- game/sce/deci2.h | 1 - game/sce/iop.cpp | 36 ++-- game/sce/iop.h | 55 ++--- game/sce/libcdvd_ee.cpp | 10 +- game/sce/libscf.cpp | 2 +- game/sce/libscf.h | 2 +- game/sce/sif_ee.cpp | 31 +-- game/sce/sif_ee.h | 29 ++- game/sce/stubs.cpp | 10 +- game/sce/stubs.h | 37 ++-- game/system/Deci2Server.h | 3 - game/system/IOP_Kernel.cpp | 109 +++++----- game/system/IOP_Kernel.h | 60 +++--- game/system/SystemThread.h | 23 +-- game/system/Timer.h | 25 +-- game/system/deci_common.h | 2 +- game/system/iop_thread.cpp | 32 +-- game/system/iop_thread.h | 12 +- goalc/emitter/CodeTester.cpp | 7 +- goalc/emitter/CodeTester.h | 3 +- goalc/emitter/IGen.h | 76 +++---- goalc/emitter/Instruction.h | 114 +++++----- goalc/emitter/registers.cpp | 2 +- goalc/listener/Deci2Server.h | 6 +- goalc/listener/Listener.h | 12 +- goalc/main.cpp | 1 - goalc/util/text_util.cpp | 2 +- test/test_CodeTester.cpp | 14 +- test/test_kernel.cpp | 14 +- test/test_reader.cpp | 3 +- test/test_type_system.cpp | 1 - 72 files changed, 772 insertions(+), 795 deletions(-) diff --git a/common/goal_constants.h b/common/goal_constants.h index bf9239e322..bad789b688 100644 --- a/common/goal_constants.h +++ b/common/goal_constants.h @@ -5,12 +5,6 @@ constexpr int POINTER_SIZE = 4; constexpr int BASIC_OFFSET = 4; constexpr int STRUCTURE_ALIGNMENT = 16; -enum class RegKind { - GPR_64, - FLOAT, - INT_128, - FLOAT_4X, - INVALID -}; +enum class RegKind { GPR_64, FLOAT, INT_128, FLOAT_4X, INVALID }; #endif // JAK_GOAL_CONSTANTS_H diff --git a/common/symbols.h b/common/symbols.h index 750e430d87..a16cfcf543 100644 --- a/common/symbols.h +++ b/common/symbols.h @@ -6,75 +6,76 @@ #ifndef JAK1_SYMBOLS_H #define JAK1_SYMBOLS_H -constexpr int FIX_SYM_EMPTY_CAR = -0xc; +constexpr int FIX_SYM_EMPTY_CAR = -0xc; constexpr int FIX_SYM_EMPTY_PAIR = -0xa; -constexpr int FIX_SYM_EMPTY_CDR = -0x8; -constexpr int FIX_SYM_FALSE = 0x0; // GOAL boolean #f (note that this is equal to the $s7 register) -constexpr int FIX_SYM_TRUE = 0x8; // GOAL boolean #t +constexpr int FIX_SYM_EMPTY_CDR = -0x8; +constexpr int FIX_SYM_FALSE = 0x0; // GOAL boolean #f (note that this is equal to the $s7 register) +constexpr int FIX_SYM_TRUE = 0x8; // GOAL boolean #t // types -constexpr int FIX_SYM_FUNCTION_TYPE = 0x10; // GOAL type of function -constexpr int FIX_SYM_BASIC_TYPE = 0x18; // GOAL structure type with type tag -constexpr int FIX_SYM_STRING_TYPE = 0x20; // GOAL string type (gstring) -constexpr int FIX_SYM_SYMBOL_TYPE = 0x28; // GOAL symbol type -constexpr int FIX_SYM_TYPE_TYPE = 0x30; // GOAL type of type -constexpr int FIX_SYM_OBJECT_TYPE = 0x38; // GOAL parent type of all types -constexpr int FIX_SYM_LINK_BLOCK = 0x40; // GOAL type of link-block (used by linker, but seems to be unused by GOAL) -constexpr int FIX_SYM_INTEGER_TYPE = 0x48; // GOAL integer parent type, assumes unboxed -constexpr int FIX_SYM_SINTEGER_TYPE = 0x50; // GOAL signed integer parent type, assumes unboxed -constexpr int FIX_SYM_UINTEGER_TYPE = 0x58; // GOAL unsinged integer parent type, assumes unboxed -constexpr int FIX_SYM_BINTEGER_TYPE = 0x60; // GOAL "boxed integer" type -constexpr int FIX_SYM_INT8_TYPE = 0x68; // GOAL 8-bit signed integer -constexpr int FIX_SYM_INT16_TYPE = 0x70; // ... -constexpr int FIX_SYM_INT32_TYPE = 0x78; // ... -constexpr int FIX_SYM_INT64_TYPE = 0x80; // ... -constexpr int FIX_SYM_INT128_TYPE = 0x88; // GOAL 128-bit integer type, behaves strangely -constexpr int FIX_SYM_UINT8_TYPE = 0x90; // GOAL 8-bit unsigned integer -constexpr int FIX_SYM_UINT16_TYPE = 0x98; // ... -constexpr int FIX_SYM_UINT32_TYPE = 0xA0; // ... -constexpr int FIX_SYM_UINT64_TYPE = 0xA8; // ... -constexpr int FIX_SYM_UINT128_TYPE = 0xB0; // ... -constexpr int FIX_SYM_FLOAT_TYPE = 0xB8; // GOAL 32-bit floating point type -constexpr int FIX_SYM_PROCESS_TREE_TYPE = 0xC0; // GOAL process-tree type. Used in the gkernel -constexpr int FIX_SYM_PROCESS_TYPE = 0xC8; // GOAL process type -constexpr int FIX_SYM_THREAD_TYPE = 0xD0; // GOAL thread type -constexpr int FIX_SYM_STRUCTURE_TYPE = 0xD8; // GOAL structure type. Any type with fields -constexpr int FIX_SYM_PAIR_TYPE = 0xE0; // GOAL pair type -constexpr int FIX_SYM_POINTER_TYPE = 0xE8; // GOAL pointer type (32-bit) -constexpr int FIX_SYM_NUMBER_TYPE = 0xF0; // GOAL number type (parent of integer/float types) -constexpr int FIX_SYM_ARRAY_TYPE = 0xF8; // GOAL array type -constexpr int FIX_SYM_VU_FUNCTION_TYPE = 0x100; // GOAL vu-function type -constexpr int FIX_SYM_CONNECTABLE_TYPE = 0x108; // GOAL connectable -constexpr int FIX_SYM_STACK_FRAME_TYPE = 0x110; // GOAL stack-frame -constexpr int FIX_SYM_FILE_STREAM_TYPE = 0x118; // GOAL file-stream -constexpr int FIX_SYM_KHEAP = 0x120; // GOAL kheap +constexpr int FIX_SYM_FUNCTION_TYPE = 0x10; // GOAL type of function +constexpr int FIX_SYM_BASIC_TYPE = 0x18; // GOAL structure type with type tag +constexpr int FIX_SYM_STRING_TYPE = 0x20; // GOAL string type (gstring) +constexpr int FIX_SYM_SYMBOL_TYPE = 0x28; // GOAL symbol type +constexpr int FIX_SYM_TYPE_TYPE = 0x30; // GOAL type of type +constexpr int FIX_SYM_OBJECT_TYPE = 0x38; // GOAL parent type of all types +constexpr int FIX_SYM_LINK_BLOCK = + 0x40; // GOAL type of link-block (used by linker, but seems to be unused by GOAL) +constexpr int FIX_SYM_INTEGER_TYPE = 0x48; // GOAL integer parent type, assumes unboxed +constexpr int FIX_SYM_SINTEGER_TYPE = 0x50; // GOAL signed integer parent type, assumes unboxed +constexpr int FIX_SYM_UINTEGER_TYPE = 0x58; // GOAL unsinged integer parent type, assumes unboxed +constexpr int FIX_SYM_BINTEGER_TYPE = 0x60; // GOAL "boxed integer" type +constexpr int FIX_SYM_INT8_TYPE = 0x68; // GOAL 8-bit signed integer +constexpr int FIX_SYM_INT16_TYPE = 0x70; // ... +constexpr int FIX_SYM_INT32_TYPE = 0x78; // ... +constexpr int FIX_SYM_INT64_TYPE = 0x80; // ... +constexpr int FIX_SYM_INT128_TYPE = 0x88; // GOAL 128-bit integer type, behaves strangely +constexpr int FIX_SYM_UINT8_TYPE = 0x90; // GOAL 8-bit unsigned integer +constexpr int FIX_SYM_UINT16_TYPE = 0x98; // ... +constexpr int FIX_SYM_UINT32_TYPE = 0xA0; // ... +constexpr int FIX_SYM_UINT64_TYPE = 0xA8; // ... +constexpr int FIX_SYM_UINT128_TYPE = 0xB0; // ... +constexpr int FIX_SYM_FLOAT_TYPE = 0xB8; // GOAL 32-bit floating point type +constexpr int FIX_SYM_PROCESS_TREE_TYPE = 0xC0; // GOAL process-tree type. Used in the gkernel +constexpr int FIX_SYM_PROCESS_TYPE = 0xC8; // GOAL process type +constexpr int FIX_SYM_THREAD_TYPE = 0xD0; // GOAL thread type +constexpr int FIX_SYM_STRUCTURE_TYPE = 0xD8; // GOAL structure type. Any type with fields +constexpr int FIX_SYM_PAIR_TYPE = 0xE0; // GOAL pair type +constexpr int FIX_SYM_POINTER_TYPE = 0xE8; // GOAL pointer type (32-bit) +constexpr int FIX_SYM_NUMBER_TYPE = 0xF0; // GOAL number type (parent of integer/float types) +constexpr int FIX_SYM_ARRAY_TYPE = 0xF8; // GOAL array type +constexpr int FIX_SYM_VU_FUNCTION_TYPE = 0x100; // GOAL vu-function type +constexpr int FIX_SYM_CONNECTABLE_TYPE = 0x108; // GOAL connectable +constexpr int FIX_SYM_STACK_FRAME_TYPE = 0x110; // GOAL stack-frame +constexpr int FIX_SYM_FILE_STREAM_TYPE = 0x118; // GOAL file-stream +constexpr int FIX_SYM_KHEAP = 0x120; // GOAL kheap // GOAL functions -constexpr int FIX_SYM_NOTHING_FUNC = 0x128; // GOAL nothing-func (does nothing) -constexpr int FIX_SYM_DEL_BASIC_FUNC = 0x130; // GOAL delete-basic function +constexpr int FIX_SYM_NOTHING_FUNC = 0x128; // GOAL nothing-func (does nothing) +constexpr int FIX_SYM_DEL_BASIC_FUNC = 0x130; // GOAL delete-basic function // GOAL allocation symbols (?) -constexpr int FIX_SYM_STATIC = 0x138; // GOAL 'static -constexpr int FIX_SYM_GLOBAL_HEAP = 0x140; // GOAL 'global -constexpr int FIX_SYM_DEBUG_HEAP = 0x148; // GOAL 'debug -constexpr int FIX_SYM_LOADING_LEVEL = 0x150; // ?? -constexpr int FIX_SYM_LOADING_PACKAGE = 0x158; // ?? -constexpr int FIX_SYM_PROCESS_LEVEL_HEAP = 0x160; // ?? -constexpr int FIX_SYM_STACK = 0x168; // GOAL 'stack -constexpr int FIX_SYM_SCRATCH = 0x170; // GOAL 'scratch +constexpr int FIX_SYM_STATIC = 0x138; // GOAL 'static +constexpr int FIX_SYM_GLOBAL_HEAP = 0x140; // GOAL 'global +constexpr int FIX_SYM_DEBUG_HEAP = 0x148; // GOAL 'debug +constexpr int FIX_SYM_LOADING_LEVEL = 0x150; // ?? +constexpr int FIX_SYM_LOADING_PACKAGE = 0x158; // ?? +constexpr int FIX_SYM_PROCESS_LEVEL_HEAP = 0x160; // ?? +constexpr int FIX_SYM_STACK = 0x168; // GOAL 'stack +constexpr int FIX_SYM_SCRATCH = 0x170; // GOAL 'scratch // GOAL random stuff -constexpr int FIX_SYM_SCRATCH_TOP = 0x178; // GOAL *scratch-top* -constexpr int FIX_SYM_ZERO_FUNC = 0x180; // GOAL zero-func (returns 0x0 in $v0 register) -constexpr int FIX_SYM_ASIZE_OF_BASIC_FUNC = 0x188; // GOAL asize-of-basic function -constexpr int FIX_SYM_COPY_BASIC_FUNC = 0x190; // GOAL copy-basic function -constexpr int FIX_SYM_LEVEL = 0x198; // ?? -constexpr int FIX_SYM_ART_GROUP = 0x1a0; // ?? -constexpr int FIX_SYM_TX_PAGE_DIR = 0x1a8; // ?? -constexpr int FIX_SYM_TX_PAGE = 0x1b0; // ?? -constexpr int FIX_SYM_SOUND = 0x1b8; // ?? -constexpr int FIX_SYM_DGO = 0x1c0; // ?? -constexpr int FIX_SYM_TOP_LEVEL = 0x1c8; // ?? -constexpr int FIX_FIXED_SYM_END_OFFSET = 0x1d0; +constexpr int FIX_SYM_SCRATCH_TOP = 0x178; // GOAL *scratch-top* +constexpr int FIX_SYM_ZERO_FUNC = 0x180; // GOAL zero-func (returns 0x0 in $v0 register) +constexpr int FIX_SYM_ASIZE_OF_BASIC_FUNC = 0x188; // GOAL asize-of-basic function +constexpr int FIX_SYM_COPY_BASIC_FUNC = 0x190; // GOAL copy-basic function +constexpr int FIX_SYM_LEVEL = 0x198; // ?? +constexpr int FIX_SYM_ART_GROUP = 0x1a0; // ?? +constexpr int FIX_SYM_TX_PAGE_DIR = 0x1a8; // ?? +constexpr int FIX_SYM_TX_PAGE = 0x1b0; // ?? +constexpr int FIX_SYM_SOUND = 0x1b8; // ?? +constexpr int FIX_SYM_DGO = 0x1c0; // ?? +constexpr int FIX_SYM_TOP_LEVEL = 0x1c8; // ?? +constexpr int FIX_FIXED_SYM_END_OFFSET = 0x1d0; #endif // JAK1_SYMBOLS_H diff --git a/common/type_system/type_util.h b/common/type_system/type_util.h index 4e87474578..fcefbdd2ad 100644 --- a/common/type_system/type_util.h +++ b/common/type_system/type_util.h @@ -1,9 +1,9 @@ #ifndef JAK_TYPE_UTIL_H #define JAK_TYPE_UTIL_H -template +template T align(T current, T alignment, T offset = 0) { - while((current % alignment) != 0) { + while ((current % alignment) != 0) { current++; } return current + offset; diff --git a/common/versions.h b/common/versions.h index 74b1ec0169..5ecb742ac8 100644 --- a/common/versions.h +++ b/common/versions.h @@ -12,7 +12,7 @@ namespace versions { // language version constexpr s32 GOAL_VERSION_MAJOR = 2; constexpr s32 GOAL_VERSION_MINOR = 6; -} +} // namespace versions // GOAL kernel version constexpr int KERNEL_VERSION_MAJOR = 2; diff --git a/decompiler/Function/Function.h b/decompiler/Function/Function.h index d8bfeba202..c972496229 100644 --- a/decompiler/Function/Function.h +++ b/decompiler/Function/Function.h @@ -9,18 +9,18 @@ struct FunctionName { enum class FunctionKind { - UNIDENTIFIED, // hasn't been identified yet. - GLOBAL, // global named function + UNIDENTIFIED, // hasn't been identified yet. + GLOBAL, // global named function METHOD, TOP_LEVEL_INIT, } kind = FunctionKind::UNIDENTIFIED; - std::string function_name; // only applicable for GLOBAL - std::string type_name; // only applicable for METHOD - int method_id = -1; // only applicable for METHOD + std::string function_name; // only applicable for GLOBAL + std::string type_name; // only applicable for METHOD + int method_id = -1; // only applicable for METHOD std::string to_string() const { - switch(kind) { + switch (kind) { case FunctionKind::GLOBAL: return function_name; case FunctionKind::METHOD: @@ -34,13 +34,9 @@ struct FunctionName { } } - bool empty() const { - return kind == FunctionKind::UNIDENTIFIED; - } + bool empty() const { return kind == FunctionKind::UNIDENTIFIED; } - void set_as_top_level() { - kind = FunctionKind::TOP_LEVEL_INIT; - } + void set_as_top_level() { kind = FunctionKind::TOP_LEVEL_INIT; } void set_as_global(std::string name) { kind = FunctionKind::GLOBAL; diff --git a/decompiler/ObjectFile/LinkedObjectFile.cpp b/decompiler/ObjectFile/LinkedObjectFile.cpp index d02fc3bf31..be9eaa1de7 100644 --- a/decompiler/ObjectFile/LinkedObjectFile.cpp +++ b/decompiler/ObjectFile/LinkedObjectFile.cpp @@ -90,7 +90,7 @@ Function& LinkedObjectFile::get_function_at_label(int label_id) { } assert(false); - return functions_by_seg.front().front(); // to avoid error + return functions_by_seg.front().front(); // to avoid error } /*! @@ -520,7 +520,7 @@ std::string LinkedObjectFile::print_disassembly() { result += "; .function " + func.guessed_name.to_string() + "\n"; result += ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n"; result += func.prologue.to_string(2) + "\n"; - if(!func.warnings.empty()) { + if (!func.warnings.empty()) { result += "Warnings: " + func.warnings + "\n"; } @@ -581,11 +581,11 @@ std::string LinkedObjectFile::print_disassembly() { // } // hack - if(func.cfg && !func.cfg->is_fully_resolved()) { + if (func.cfg && !func.cfg->is_fully_resolved()) { result += func.cfg->to_dot(); result += "\n"; } - if(func.cfg) { + if (func.cfg) { result += func.cfg->to_form_string() + "\n"; // To debug block stuff. @@ -614,7 +614,6 @@ std::string LinkedObjectFile::print_disassembly() { */ } - result += "\n\n\n"; } @@ -636,7 +635,6 @@ std::string LinkedObjectFile::print_disassembly() { if (word.kind == LinkedWord::TYPE_PTR && word.symbol_name == "string") { result += "; " + get_goal_string(seg, i) + "\n"; - } } } diff --git a/decompiler/ObjectFile/LinkedObjectFile.h b/decompiler/ObjectFile/LinkedObjectFile.h index 4b87dbe345..f897b86475 100644 --- a/decompiler/ObjectFile/LinkedObjectFile.h +++ b/decompiler/ObjectFile/LinkedObjectFile.h @@ -15,7 +15,6 @@ #include "decompiler/Function/Function.h" #include "decompiler/util/LispPrint.h" - /*! * A label to a location in this object file. * Doesn't have to be word aligned. @@ -23,14 +22,14 @@ struct Label { std::string name; int target_segment; - int offset; // in bytes + int offset; // in bytes }; /*! * An object file's data with linking information included. */ class LinkedObjectFile { -public: + public: LinkedObjectFile() = default; void set_segment_count(int n_segs); void push_back_word_to_segment(uint32_t word, int segment); @@ -38,8 +37,15 @@ public: int get_label_at(int seg, int offset) const; bool label_points_to_code(int label_id) const; bool pointer_link_word(int source_segment, int source_offset, int dest_segment, int dest_offset); - void pointer_link_split_word(int source_segment, int source_hi_offset, int source_lo_offset, int dest_segment, int dest_offset); - void symbol_link_word(int source_segment, int source_offset, const char* name, LinkedWord::Kind kind); + void pointer_link_split_word(int source_segment, + int source_hi_offset, + int source_lo_offset, + int dest_segment, + int dest_offset); + void symbol_link_word(int source_segment, + int source_offset, + const char* name, + LinkedWord::Kind kind); void symbol_link_offset(int source_segment, int source_offset, const char* name); Function& get_function_at_label(int label_id); std::string get_label_name(int label_id) const; @@ -83,7 +89,6 @@ public: uint32_t n_fp_reg_use = 0; uint32_t n_fp_reg_use_resolved = 0; - void add(const Stats& other) { total_code_bytes += other.total_code_bytes; total_v2_code_bytes += other.total_v2_code_bytes; @@ -116,9 +121,9 @@ public: std::vector> functions_by_seg; std::vector