|
@ -21,18 +21,41 @@ export const realizeUnary = (dest: Loc, op: UnaryOp | BinaryOp, source: Operand) |
|
|
throw new Error("unexpected form for unary operation") |
|
|
throw new Error("unexpected form for unary operation") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let output: Array<SM83Insn> = [] |
|
|
|
|
|
|
|
|
switch (op) { |
|
|
switch (op) { |
|
|
case "add": |
|
|
case "add": |
|
|
return [`ADD ${getSourceName(source)}`] |
|
|
return [`ADD ${getSourceName(source)}`] |
|
|
|
|
|
|
|
|
|
|
|
case "subtract": |
|
|
|
|
|
return [`SUB ${getSourceName(source)}`] |
|
|
|
|
|
|
|
|
|
|
|
case "bit_and": |
|
|
|
|
|
return [`AND ${getSourceName(source)}`] |
|
|
|
|
|
|
|
|
|
|
|
case "bit_or": |
|
|
|
|
|
return [`OR ${getSourceName(source)}`] |
|
|
|
|
|
|
|
|
|
|
|
case "bit_xor": |
|
|
|
|
|
return [`XOR ${getSourceName(source)}`] |
|
|
|
|
|
|
|
|
|
|
|
case "shift_left": |
|
|
|
|
|
for (let i = 0; i < source; ++i) { |
|
|
|
|
|
output.push("SLA A") |
|
|
|
|
|
} |
|
|
|
|
|
return output |
|
|
|
|
|
|
|
|
|
|
|
case "shift_right": |
|
|
|
|
|
for (let i = 0; i < source; ++i) { |
|
|
|
|
|
output.push("SRL A") |
|
|
|
|
|
} |
|
|
|
|
|
return output |
|
|
|
|
|
|
|
|
case "arith_negate": |
|
|
case "arith_negate": |
|
|
return ["CPL", "INC A"] |
|
|
return ["CPL", "INC A"] |
|
|
|
|
|
|
|
|
case "bit_negate": |
|
|
case "bit_negate": |
|
|
return ["CPL"] |
|
|
return ["CPL"] |
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
throw new Error(`unsupported unary op \`${op}'`) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|