mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-23 16:34:06 +00:00
reccmp: diff bugfixes (#583)
This commit is contained in:
@@ -34,6 +34,10 @@ def combined_diff(
|
|||||||
orig_addrs = set()
|
orig_addrs = set()
|
||||||
recomp_addrs = set()
|
recomp_addrs = set()
|
||||||
|
|
||||||
|
first, last = group[0], group[-1]
|
||||||
|
orig_range = len(orig_combined[first[1] : last[2]])
|
||||||
|
recomp_range = len(recomp_combined[first[3] : last[4]])
|
||||||
|
|
||||||
for code, i1, i2, j1, j2 in group:
|
for code, i1, i2, j1, j2 in group:
|
||||||
if code == "equal":
|
if code == "equal":
|
||||||
# The sections are equal, so the list slices are guaranteed
|
# The sections are equal, so the list slices are guaranteed
|
||||||
@@ -74,7 +78,20 @@ def combined_diff(
|
|||||||
orig_sorted = sorted(orig_addrs)
|
orig_sorted = sorted(orig_addrs)
|
||||||
recomp_sorted = sorted(recomp_addrs)
|
recomp_sorted = sorted(recomp_addrs)
|
||||||
|
|
||||||
diff_slug = f"@@ -{orig_sorted[0]},{orig_sorted[-1]} +{recomp_sorted[0]},{recomp_sorted[-1]} @@"
|
# We could get a diff group that has no original addresses.
|
||||||
|
# This might happen for a stub function where we are not able to
|
||||||
|
# produce even a single instruction from the original.
|
||||||
|
# In that case, show the best slug line that we can.
|
||||||
|
def peek_front(list_, default=""):
|
||||||
|
try:
|
||||||
|
return list_[0]
|
||||||
|
except IndexError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
orig_first = peek_front(orig_sorted)
|
||||||
|
recomp_first = peek_front(recomp_sorted)
|
||||||
|
|
||||||
|
diff_slug = f"@@ -{orig_first},{orig_range} +{recomp_first},{recomp_range} @@"
|
||||||
|
|
||||||
unified_diff.append((diff_slug, subgroups))
|
unified_diff.append((diff_slug, subgroups))
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ def print_combined_diff(udiff, plain: bool = False, show_both: bool = False):
|
|||||||
addr_prefix = (
|
addr_prefix = (
|
||||||
f"{'':{padding_size}} / {recomp_addr}"
|
f"{'':{padding_size}} / {recomp_addr}"
|
||||||
if show_both
|
if show_both
|
||||||
else recomp_addr
|
else " " * padding_size
|
||||||
)
|
)
|
||||||
|
|
||||||
if plain:
|
if plain:
|
||||||
|
@@ -418,26 +418,26 @@ class DiffDisplay extends window.HTMLElement {
|
|||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
const obj = getDataByAddr(this.address);
|
const obj = getDataByAddr(this.address);
|
||||||
|
|
||||||
const createSingleCellRow = (text, className) => {
|
const createHeaderLine = (text, className) => {
|
||||||
const tr = document.createElement('tr');
|
const div = document.createElement('div');
|
||||||
const td = document.createElement('td');
|
div.textContent = text;
|
||||||
td.setAttribute('colspan', 3);
|
div.className = className;
|
||||||
td.textContent = text;
|
return div;
|
||||||
td.className = className;
|
|
||||||
tr.appendChild(td);
|
|
||||||
return tr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const groups = obj.diff;
|
const groups = obj.diff;
|
||||||
groups.forEach(([slug, subgroups]) => {
|
groups.forEach(([slug, subgroups]) => {
|
||||||
const secondTable = document.createElement('table');
|
const secondTable = document.createElement('table');
|
||||||
secondTable.classList.add('diffTable', 'showOrig');
|
secondTable.classList.add('diffTable');
|
||||||
|
|
||||||
|
const hdr = document.createElement('div');
|
||||||
|
hdr.appendChild(createHeaderLine('---', 'diffneg'));
|
||||||
|
hdr.appendChild(createHeaderLine('+++', 'diffpos'));
|
||||||
|
hdr.appendChild(createHeaderLine(slug, 'diffslug'));
|
||||||
|
div.appendChild(hdr);
|
||||||
|
|
||||||
const tbody = document.createElement('tbody');
|
const tbody = document.createElement('tbody');
|
||||||
secondTable.appendChild(tbody);
|
secondTable.appendChild(tbody);
|
||||||
tbody.appendChild(createSingleCellRow('---', 'diffneg'));
|
|
||||||
tbody.appendChild(createSingleCellRow('+++', 'diffpos'));
|
|
||||||
tbody.appendChild(createSingleCellRow(slug, 'diffslug'));
|
|
||||||
|
|
||||||
const diffs = formatAsm(subgroups, this.option);
|
const diffs = formatAsm(subgroups, this.option);
|
||||||
for (const el of diffs) {
|
for (const el of diffs) {
|
||||||
|
Reference in New Issue
Block a user