mirror of
https://github.com/decompme/decomp.me.git
synced 2026-02-13 17:18:45 -06:00
* Switch to subprocess.run for timeouts * [experiment] Set CI TIMEOUT_SCALE_FACTOR to 1 * supress parameterized.expand error in event of no compilers, change TIMEOUT_SCALE_FACTOR in CI to 2 * Exempt dummy compilers from nsjail bind mounts, disable nsjail time limits * Don't run timeout test on windows * Decouple test_compiler_timeout's timeout from global timeout settings, reset TIMEOUT_SCALE_FACTOR to 10 * Have DummyLongRunningCompiler subclass DummyCompiler * Have a timeout of zero disable timeouts entirely * Skip test_zero_timeout on windows * black Co-authored-by: ConorBobbleHat <c.github@firstpartners.net>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import logging
|
|
|
|
from coreapp import compilers
|
|
|
|
from coreapp.compilers import Compiler
|
|
|
|
from coreapp.m2c_wrapper import M2CError, M2CWrapper
|
|
from coreapp.platforms import Platform
|
|
from django.conf import settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
MAX_M2C_ASM_LINES = 15000
|
|
|
|
|
|
class DecompilerWrapper:
|
|
@staticmethod
|
|
def decompile(
|
|
default_source_code: str,
|
|
platform: Platform,
|
|
asm: str,
|
|
context: str,
|
|
compiler: Compiler,
|
|
) -> str:
|
|
if compiler == compilers.DUMMY:
|
|
return f"decompiled({asm})"
|
|
|
|
ret = default_source_code
|
|
if platform.arch in ["mips", "mipsel", "ppc"]:
|
|
if len(asm.splitlines()) > MAX_M2C_ASM_LINES:
|
|
return "/* Too many lines to decompile; please run m2c manually */"
|
|
try:
|
|
ret = M2CWrapper.decompile(asm, context, compiler, platform.arch)
|
|
except M2CError as e:
|
|
ret = f"{e}\n{default_source_code}"
|
|
except Exception:
|
|
logger.exception("Error running m2c")
|
|
ret = f"/* Internal error while running m2c */\n{default_source_code}"
|
|
else:
|
|
ret = f"/* No decompiler yet implemented for {platform.arch} */\n{default_source_code}"
|
|
|
|
return ret
|