Skip to content

Commit

Permalink
fix: output 10 ADD as correct 10 ADDCONST, -1 ADD as DEC, `-1…
Browse files Browse the repository at this point in the history
… MUL` as `NEGATE` (#29)

Fixes #25
  • Loading branch information
i582 authored Jan 17, 2025
1 parent 3948087 commit a2939ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
56 changes: 28 additions & 28 deletions src/decompiler/__snapshots__/decompileAll.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
SUB
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -752,14 +752,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
ADD
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -817,7 +817,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
<{
1 RSHIFT
s0 s2 XCHG
-1 ADD
DEC
s0 s2 XCHG
}> PUSHCONT
IF
Expand Down Expand Up @@ -858,7 +858,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
AND
<{
s0 s1 XCHG
-1 MULCONST
NEGATE
}> PUSHCONT
REPEAT
}>
Expand All @@ -883,7 +883,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
?fun_ref_1b1ae470b4614553 PROCREF:<{
s0 PUSH
UBITSIZE
-1 ADD
DEC
8 PUSHPOW2DEC
s1 PUSH
SUB
Expand All @@ -900,7 +900,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
ADD
s1 s2 XCHG
true 0 false 1 1 0 DIV
11 ADD
11 ADDCONST
s0 PUSH
5 PUSHINT
false 0 false 3 0 0 DIV
Expand Down Expand Up @@ -1001,7 +1001,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
s1 s3 XCHG
SUB
s0 s2 XCHG
-2 ADD
-2 ADDCONST
}> PUSHCONT
REPEAT
s0 POP
Expand Down Expand Up @@ -1220,7 +1220,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
s0 s1 XCHG
SUB
true 2 true 1 1 255 DIV
-1 MULCONST
NEGATE
?fun_ref_5c788425937a7d28 INLINECALLDICT
}>
?fun_ref_5a712c8e35fef248 PROCREF:<{
Expand Down Expand Up @@ -1277,7 +1277,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
s6 s6 PUSH2
true 1 true 1 1 255 DIV
false 1 true 1 1 1 DIV
-1 MULCONST
NEGATE
?fun_ref_eabdf5efadfce810 INLINECALLDICT
4 LSHIFT
GREATER
Expand Down Expand Up @@ -1350,14 +1350,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
ADD
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -1417,14 +1417,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
ADD
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -1482,14 +1482,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 245 DIV
s1 s1 PUXC
ADD
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand All @@ -1513,7 +1513,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
true 1 true 1 1 254 DIV
s1 PUSH
1 LSHIFT
5 ADD
5 ADDCONST
250 LSHIFT
s0 PUSH
251 PUSHPOW2
Expand Down Expand Up @@ -1588,7 +1588,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
<{
2 1 BLKDROP2
0 EQINT
-1 MULCONST
NEGATE
}> PUSHCONT
IFJMP
?fun_ref_2051d9d821c3f770 INLINECALLDICT
Expand Down Expand Up @@ -1674,7 +1674,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
128 LSHIFT
ADD
true 2 true 1 1 58 DIV
13 ADD
13 ADDCONST
33226912 PUSHINT
5232641 PUSHINT
s2 PUSH
Expand Down Expand Up @@ -1734,7 +1734,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
AND
<{
s0 s1 XCHG
-1 MULCONST
NEGATE
}> PUSHCONT
IF
true 2 true 1 1 247 DIV
Expand All @@ -1752,14 +1752,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
SUB
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -1853,14 +1853,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 241 DIV
s1 s1 PUXC
ADD
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down Expand Up @@ -1995,7 +1995,7 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
1 PUSHINT
AND
<{
-1 MULCONST
NEGATE
s0 s1 XCHG
}> PUSHCONT
IF
Expand Down Expand Up @@ -2064,14 +2064,14 @@ exports[`decompileAll should decompile mathlib.fc 1`] = `
255 PUSHPOW2
ADD
s3 PUSH
-1 ADD
DEC
<{
s2 s1 PUXC
true 2 true 1 1 247 DIV
s1 s1 PUXC
SUB
s3 PUSH
-1 ADD
DEC
s4 s4 XCPU
true 0 false 1 1 0 DIV
s1 PUSH
Expand Down
9 changes: 8 additions & 1 deletion src/printer/AssemblerWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ export class AssemblerWriter {
if (firstArg === 1) {
return 'INC';
}
if (firstArg === -1) {
return 'DEC';
}
}

return `${firstArg} ADD`;
if (node.opcode === 'MULCONST') {
if (firstArg === -1) {
return 'NEGATE';
}
}

// Debug
Expand Down

0 comments on commit a2939ea

Please sign in to comment.