GP-3211: Refactored pcodetest scripts

This commit is contained in:
ghidorahrex 2023-08-15 15:53:42 +00:00
parent 8936bf9d55
commit 8004108681
7 changed files with 95 additions and 35 deletions

View File

@ -13,14 +13,39 @@ from pcodetest import *
# set default properties first, then update values from the command
# line before they are instantiated.
def test_action(action_class, deprecate=False):
class pcodeTestAction(action_class):
def __call__(self, parser, namespace, values, option_string=None):
c = getattr(namespace, 'command_count', 0)
setattr(namespace, 'command_count', c+1)
if deprecate:
print('Deprecated pcodetest command\n\tuse --%s' % (self.dest))
action_class.__call__(self, parser, namespace, values, option_string)
return pcodeTestAction
exec(compile(open('defaults.py', "rb").read(), 'defaults.py', 'exec'))
parser = argparse.ArgumentParser(description='''Build pcodetests.
One and only one of the following options must be given:
[--pcodetest, --pcodetest-all, --pcodetest-list]''',
[--test, --all, --list]''',
epilog='(*) default properties for pcodetest instances',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# required alternates
required_group = parser.add_argument_group('Pcodetest Commands')
required_group.add_argument('-t', '--test', dest='test', action=test_action(argparse._StoreAction), help='the pcode test to build')
required_group.add_argument('-a', '--all', dest='all', action=test_action(argparse._StoreTrueAction), help='build all pcode tests')
required_group.add_argument('-l', '--list', dest='list', action=test_action(argparse._StoreTrueAction), help='list available pcode tests')
#Deprecated
required_group.add_argument('--pcodetest', dest='test', action=test_action(argparse._StoreAction, True), help=argparse.SUPPRESS)
required_group.add_argument('--pcodetest-all',dest='all', action=test_action(argparse._StoreTrueAction, True), help=argparse.SUPPRESS)
required_group.add_argument('--pcodetest-list', dest='list', action=test_action(argparse._StoreTrueAction, True), help=argparse.SUPPRESS)
# all-applicable arguments
parser.add_argument('-f', '--force', action='store_true', help='force a build')
@ -29,16 +54,10 @@ parser.add_argument('--toolchain-root', default=PCodeTest.defaults.toolchain_roo
parser.add_argument('--build-root', default=PCodeTest.defaults.build_root, help='temporary directory to hold build files (*)')
parser.add_argument('--gcc-version', default=PCodeTest.defaults.gcc_version, help='default version of gcc (*)')
# required alternates
required_group = parser.add_mutually_exclusive_group(required=True)
required_group.add_argument('--pcodetest', help='the pcode test to build')
required_group.add_argument('--pcodetest-all', action='store_true', help='build all pcode tests')
required_group.add_argument('--pcodetest-list', action='store_true', help='list available pcode tests')
# pcodetest arguments
pcodetest_group = parser.add_argument_group('pcodetest', 'pcodetest options')
pcodetest_group = parser.add_argument_group('Pcodetest Options')
pcodetest_group.add_argument('--no-publish', action='store_true', help='do not publish pcode test binaries to pcode test root')
pcodetest_group.add_argument('--pcodetest-root', default=PCodeTest.defaults.pcodetest_root, help='location to publish pcode tests binaries (*)')
pcodetest_group.add_argument('--pcodetest-src', default=PCodeTest.defaults.pcodetest_src, help='location of pcode test .c and .h source files (*)')
@ -49,6 +68,7 @@ pcodetest_group.add_argument('--add-info', action='store_true', help='add data t
pcodetest_group.add_argument('--build-exe', action='store_true', help='build a guest executable binary (exe)')
pcodetest_group.add_argument('--variants', default=json.dumps(PCodeTest.defaults.variants, sort_keys=True, separators=(',',':')), type=json.loads, help='build the (optimization) variants, encoded as a json dict')
sys.argv.pop(0)
args = parser.parse_args(sys.argv)
@ -73,9 +93,21 @@ exec(compile(open('pcode_defs.py', "rb").read(), 'pcode_defs.py', 'exec'))
cwd = os.getcwd()
if args.pcodetest_list:
if not hasattr(args, 'command_count'):
print('ERROR: One of [--test, --all, --list] must be given\n')
parser.print_help()
exit()
if args.command_count > 1:
print('ERROR: Two many commands given. Only one of [--test, --all, --list] must be given\n')
parser.print_help()
exit()
if args.list:
PCodeTest.print_all()
elif args.pcodetest_all:
elif args.all:
for n,pct in sorted(PCodeTest.list.items(), key=lambda x: x[0].lower()):
if pct.config.build_all:
try: PCodeTestBuild.factory(pct).main()
@ -83,12 +115,13 @@ elif args.pcodetest_all:
print('unhandled exception while building %s' % n)
traceback.print_exc(file=sys.stdout)
os.chdir(cwd)
elif args.pcodetest:
if args.pcodetest in PCodeTest.list:
PCodeTest = PCodeTest.list[args.pcodetest]
elif args.test:
if args.test in PCodeTest.list:
PCodeTest = PCodeTest.list[args.test]
PCodeTestBuild.factory(PCodeTest).main()
else:
print('the pcode test %s is not in the list' % args.pcodetest)
print('the pcode test %s is not in the list' % args.test)
else:
parser.print_help()

View File

@ -16,6 +16,19 @@
#include "pcode_test.h"
#ifdef HAS_DOUBLE
f8 f8_compareLogic(f8 lhs, f8 rhs)
{
if (lhs < 0)
lhs += 2;
if (lhs > 0)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
/* Comparison operators */
f8 f8_greaterThan(f8 lhs, f8 rhs)
{

View File

@ -29,19 +29,6 @@ f4 f4_compareLogic(f4 lhs, f4 rhs)
return lhs;
}
f8 f8_compareLogic(f8 lhs, f8 rhs)
{
if (lhs < 0)
lhs += 2;
if (lhs > 0)
lhs += 4;
if (lhs == 0)
lhs += 8;
if (lhs != rhs)
lhs += 16;
return lhs;
}
/* Comparison operators */
f4 f4_greaterThan(f4 lhs, f4 rhs)
{

View File

@ -107,6 +107,8 @@ typedef unsigned int u4;
typedef signed int i4;
#ifdef HAS_LONGLONG
typedef long long i8;
#endif
#if defined(HAS_LONGLONG) || defined(HAS__DOUBLE)
typedef unsigned long long u8;
#endif
#ifdef HAS_FLOAT
@ -132,6 +134,8 @@ typedef signed int i4;
#endif
#ifdef HAS_LONGLONG
typedef long long i8;
#endif
#if defined(HAS_LONGLONG) || defined(HAS__DOUBLE)
typedef unsigned long long u8;
#endif
#ifdef HAS_FLOAT
@ -197,10 +201,8 @@ typedef __UINT8_TYPE__ u1;
typedef __UINT16_TYPE__ u2;
typedef __UINT32_TYPE__ u4;
#if defined(__UINT64_TYPE__)
#ifdef HAS_LONGLONG
typedef __UINT64_TYPE__ u8;
#endif
#endif
#ifdef __SIZEOF_FLOAT__
#ifdef HAS_FLOAT

View File

@ -20,19 +20,17 @@
PCodeTest.defaults.toolchain_root = '/local/ToolChains'
PCodeTest.defaults.build_root = '/local/build-pcodetest'
PCodeTest.defaults.gcc_version = '7.3.0'
PCodeTest.defaults.gcc_version = '9.2.0'
PCodeTest.defaults.skip_files = []
PCodeTest.defaults.export_root = os.getcwd() + '/../../../../../ghidra.bin/Ghidra/Test/TestResources/data/pcodetests/'
PCodeTest.defaults.pcodetest_src = os.getcwd() + '/c_src'
# PCodeTest.defaults that cannot be overridden on the command line
# These are set by processor test definitions in the pcode_defs.py file
PCodeTest.defaults.build_all = 0
PCodeTest.defaults.ccflags = ''
PCodeTest.defaults.has_decimal128 = 0
PCodeTest.defaults.has_decimal32 = 0
PCodeTest.defaults.has_decimal64 = 0
PCodeTest.defaults.has_double = 1
PCodeTest.defaults.has_float = 1

View File

@ -219,6 +219,32 @@ PCodeTest({
'architecture_test': 'PARISC',
})
PCodeTest({
'name': 'Loongarch64',
'build_all': 1,
'build_exe': 0,
'gcc_version': '12.3.0',
'qemu_command': 'qemu-loongarch64',
'target': 'loongson-linux',
'toolchain': '%(name)s/%(target)s', #%(toolchain_dir)s/lib/gcc/loongarch64-linux/%(gcc_version)s
'ccflags': '-march=loongarch64 -mabi=lp64d -L /local/cross/lib/gcc/loongarch64-linux/12.3.0/ -lgcc',
'language_id': 'Loongarch:LE:64:default',
#'has_longlong': 0,
})
PCodeTest({
'name': 'Loongarch64f',
'build_all': 1,
'build_exe': 0,
'gcc_version': '12.3.0',
'qemu_command': 'qemu-loongarch64',
'target': 'loongson-linux',
'toolchain': 'Loongarch64/%(target)s', #%(toolchain_dir)s/lib/gcc/loongarch64-linux/%(gcc_version)s
'ccflags': '-march=loongarch64 -mabi=lp64f -mfpu=32 -L /local/cross/lib/gcc/loongarch64-linux/12.3.0/ -lgcc',
'language_id': 'Loongarch:LE:64:lp64f',
'has_double': 0,
})
# Note that libgcc.a was built for m68020 which has a different function calling convention from pre-68020

View File

@ -400,9 +400,10 @@ class PCodeBuildGCC(PCodeTestBuild):
# can pass this if weak symbols aren't defined
# f += ['-Xlinker', '--unresolved-symbols=ignore-all']
f += self.config.ccflags.split()
f += self.config.add_ccflags.split()
f +=[self.config.format(g) for g in self.config.ccflags.split()]
f += [self.config.format(g) for g in self.config.add_ccflags.split()]
self.log_info('Compiler flags: %s' % f)
return f
def compile(self, input_files, opt_cflag, output_base):