mirror of
https://github.com/encounter/decomp.me.git
synced 2026-03-30 11:06:27 -07:00
diff.py integration progress
This commit is contained in:
@@ -1,15 +1,62 @@
|
||||
import subprocess
|
||||
from coreapp.models import Assembly, Compilation
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from asm_differ.diff import run_objdump, Display
|
||||
from asm_differ.diff import Config, Display, HtmlFormatter, MIPS_SETTINGS, create_config, restrict_to_function
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class AsmDifferWrapper:
|
||||
def diff(target_assembly: Assembly, compilation: Compilation):
|
||||
# basedump = run_objdump(basecmd, config, project)
|
||||
# mydump = run_objdump(mycmd, config, project)
|
||||
# display = Display(basedump, mydump, config)
|
||||
MAX_FUNC_SIZE_LINES = 5000
|
||||
|
||||
# return display.run_diff()
|
||||
return "meow this is a diff"
|
||||
class AsmDifferWrapper:
|
||||
@staticmethod
|
||||
def create_config(scratch_arch) -> Config:
|
||||
return Config(
|
||||
arch=scratch_arch,
|
||||
# Build/objdump options
|
||||
diff_obj=True,
|
||||
make=False,
|
||||
source=False,
|
||||
source_old_binutils=False,
|
||||
inlines=False,
|
||||
max_function_size_lines=MAX_FUNC_SIZE_LINES,
|
||||
max_function_size_bytes=MAX_FUNC_SIZE_LINES * 4,
|
||||
# Display options
|
||||
formatter=HtmlFormatter(),
|
||||
threeway=False,
|
||||
base_shift=0,
|
||||
skip_lines=0,
|
||||
show_branches=True,
|
||||
stop_jrra=False,
|
||||
ignore_large_imms=False,
|
||||
ignore_addr_diffs=False,
|
||||
algorithm="levenshtein",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def run_objdump(target: Path, config: Config) -> str:
|
||||
flags = ["-drz"]
|
||||
target = target
|
||||
restrict = None # todo maybe restrict
|
||||
|
||||
try:
|
||||
out = subprocess.run(
|
||||
["mips-linux-gnu-objdump"] + config.arch.arch_flags + flags + [target],
|
||||
check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
universal_newlines=True,
|
||||
).stdout
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise e
|
||||
|
||||
if restrict is not None:
|
||||
return restrict_to_function(out, restrict, config)
|
||||
return out
|
||||
|
||||
def diff(target_assembly: Assembly, compilation: Compilation):
|
||||
config = AsmDifferWrapper.create_config(MIPS_SETTINGS) # todo read arch from compiler config of compilation
|
||||
basedump = AsmDifferWrapper.run_objdump(target_assembly.object, config)
|
||||
mydump = AsmDifferWrapper.run_objdump(compilation.object, config)
|
||||
display = Display(basedump, mydump, config)
|
||||
|
||||
return display.run_diff()
|
||||
|
||||
@@ -114,7 +114,6 @@ def scratch(request, slug=None):
|
||||
db_scratch.save()
|
||||
return Response(status=status.HTTP_202_ACCEPTED)
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
def compile(request, slug):
|
||||
required_params = ["compiler_config", "code", "context"]
|
||||
@@ -130,8 +129,9 @@ def compile(request, slug):
|
||||
|
||||
compilation, errors = CompilerWrapper.compile_code(compiler_config, code, context)
|
||||
|
||||
# TODO fix slugless compile (this won't work currently)
|
||||
diff_output = AsmDifferWrapper.diff(scratch.target_assembly, compilation)
|
||||
diff_output = ""
|
||||
if not errors:
|
||||
diff_output = AsmDifferWrapper.diff(scratch.target_assembly, compilation)
|
||||
|
||||
response_obj = {
|
||||
"diff_output": diff_output,
|
||||
|
||||
Reference in New Issue
Block a user