forked from TrueCloudLab/neoneo-go
compiler: make toShortForm
accept an opcode
This commit is contained in:
parent
1be1b8de9e
commit
4d04c56efb
1 changed files with 14 additions and 14 deletions
|
@ -1699,13 +1699,13 @@ func shortenJumps(b []byte, offsets []int) []byte {
|
||||||
// 2. Convert instructions.
|
// 2. Convert instructions.
|
||||||
copyOffset := 0
|
copyOffset := 0
|
||||||
l := len(offsets)
|
l := len(offsets)
|
||||||
b[offsets[0]] = toShortForm(b[offsets[0]])
|
b[offsets[0]] = byte(toShortForm(opcode.Opcode(b[offsets[0]])))
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
start := offsets[i] + 2
|
start := offsets[i] + 2
|
||||||
end := len(b)
|
end := len(b)
|
||||||
if i != l-1 {
|
if i != l-1 {
|
||||||
end = offsets[i+1] + 2
|
end = offsets[i+1] + 2
|
||||||
b[offsets[i+1]] = toShortForm(b[offsets[i+1]])
|
b[offsets[i+1]] = byte(toShortForm(opcode.Opcode(b[offsets[i+1]])))
|
||||||
}
|
}
|
||||||
copy(b[start-copyOffset:], b[start+3:end])
|
copy(b[start-copyOffset:], b[start+3:end])
|
||||||
copyOffset += longToShortRemoveCount
|
copyOffset += longToShortRemoveCount
|
||||||
|
@ -1731,28 +1731,28 @@ func calcOffsetCorrection(ip, target int, offsets []int) int {
|
||||||
return cnt
|
return cnt
|
||||||
}
|
}
|
||||||
|
|
||||||
func toShortForm(b byte) byte {
|
func toShortForm(op opcode.Opcode) opcode.Opcode {
|
||||||
switch op := opcode.Opcode(b); op {
|
switch op {
|
||||||
case opcode.JMPL:
|
case opcode.JMPL:
|
||||||
return byte(opcode.JMP)
|
return opcode.JMP
|
||||||
case opcode.JMPIFL:
|
case opcode.JMPIFL:
|
||||||
return byte(opcode.JMPIF)
|
return opcode.JMPIF
|
||||||
case opcode.JMPIFNOTL:
|
case opcode.JMPIFNOTL:
|
||||||
return byte(opcode.JMPIFNOT)
|
return opcode.JMPIFNOT
|
||||||
case opcode.JMPEQL:
|
case opcode.JMPEQL:
|
||||||
return byte(opcode.JMPEQ)
|
return opcode.JMPEQ
|
||||||
case opcode.JMPNEL:
|
case opcode.JMPNEL:
|
||||||
return byte(opcode.JMPNE)
|
return opcode.JMPNE
|
||||||
case opcode.JMPGTL:
|
case opcode.JMPGTL:
|
||||||
return byte(opcode.JMPGT)
|
return opcode.JMPGT
|
||||||
case opcode.JMPGEL:
|
case opcode.JMPGEL:
|
||||||
return byte(opcode.JMPGE)
|
return opcode.JMPGE
|
||||||
case opcode.JMPLEL:
|
case opcode.JMPLEL:
|
||||||
return byte(opcode.JMPLE)
|
return opcode.JMPLE
|
||||||
case opcode.JMPLTL:
|
case opcode.JMPLTL:
|
||||||
return byte(opcode.JMPLT)
|
return opcode.JMPLT
|
||||||
case opcode.CALLL:
|
case opcode.CALLL:
|
||||||
return byte(opcode.CALL)
|
return opcode.CALL
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("invalid opcode: %s", op))
|
panic(fmt.Errorf("invalid opcode: %s", op))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue