fix(asm): correct RISC-V operand order and complete RVC compression
Assisted-by: DeepSeek V4 Pro
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/asm"
|
||||
@@ -81,11 +82,23 @@ func diffHex(a, b []byte) string {
|
||||
}
|
||||
for i := 0; i < n; i += 4 {
|
||||
ab, bb := "??", "??"
|
||||
if i < len(a) {
|
||||
if i+4 <= len(a) {
|
||||
ab = fmt.Sprintf("%02x%02x%02x%02x", a[i], a[i+1], a[i+2], a[i+3])
|
||||
} else if i < len(a) {
|
||||
var sb strings.Builder
|
||||
for j := i; j < len(a); j++ {
|
||||
fmt.Fprintf(&sb, "%02x", a[j])
|
||||
}
|
||||
ab = sb.String()
|
||||
}
|
||||
if i < len(b) {
|
||||
if i+4 <= len(b) {
|
||||
bb = fmt.Sprintf("%02x%02x%02x%02x", b[i], b[i+1], b[i+2], b[i+3])
|
||||
} else if i < len(b) {
|
||||
var sb strings.Builder
|
||||
for j := i; j < len(b); j++ {
|
||||
fmt.Fprintf(&sb, "%02x", b[j])
|
||||
}
|
||||
bb = sb.String()
|
||||
}
|
||||
mark := " "
|
||||
if ab != bb {
|
||||
|
||||
@@ -17,7 +17,17 @@ import (
|
||||
// relocation fields of static-symbol references are masked before the
|
||||
// comparison, since the toolchain leaves them zero for the linker.
|
||||
func TestGroundTruthRISCV(t *testing.T) {
|
||||
path := "../testdata/verify/basic_riscv64.s"
|
||||
for _, path := range []string{
|
||||
"../testdata/verify/basic_riscv64.s",
|
||||
"../testdata/verify/rvc_riscv64.s",
|
||||
} {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
testGroundTruthRISCVFile(t, path)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testGroundTruthRISCVFile(t *testing.T, path string) {
|
||||
src, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user