commit ff4ec171f405c0712a5c13f2c6ac2651f534e336
parent 92d44660786f4971e6b82db6e383f356cbceaf1f
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date: Thu, 26 Mar 2026 22:03:58 -0300
Cleaned golangci-lint errors.
Diffstat:
14 files changed, 470 insertions(+), 468 deletions(-)
diff --git a/assembler/assembler.go b/assembler/assembler.go
@@ -196,7 +196,9 @@ func Tokenize(fileName string, tokens *[]Token) error {
if err != nil {
return fmt.Errorf(InterCtx.Get("couldn't open file: %v"), err)
}
- defer file.Close()
+ defer func(){
+ _ = file.Close()
+ }()
scanner := bufio.NewScanner(file)
diff --git a/debugger.go b/debugger.go
@@ -31,12 +31,12 @@ func breakpoint2String(breakpoint Breakpoint) string {
var s strings.Builder
if breakpoint.File != nil {
s.WriteString(*breakpoint.File)
- s.WriteString(fmt.Sprintf(":%v ", breakpoint.Line))
+ fmt.Fprintf(&s, ":%v ", breakpoint.Line)
}
if breakpoint.Label != "" {
- s.WriteString(fmt.Sprintf(machine.InterCtx.Get("(Label %v) "), breakpoint.Label))
+ fmt.Fprintf(&s, machine.InterCtx.Get("(Label %v) "), breakpoint.Label)
}
- s.WriteString(fmt.Sprintf("0x%x", breakpoint.Address))
+ fmt.Fprintf(&s, "0x%x", breakpoint.Address)
return s.String()
}
@@ -52,16 +52,16 @@ func tokensToString(sym []assembler.DebuggerToken, info *machine.ArchitectureInf
for i, tok := range sym {
var build strings.Builder
- build.WriteString(fmt.Sprintf("%v:%v: ", *tok.File, tok.Line))
+ fmt.Fprintf(&build, "%v:%v: ", *tok.File, tok.Line)
switch info.WordWidth {
case 8:
- build.WriteString(fmt.Sprintf("0x%02x: ", tok.Address))
+ fmt.Fprintf(&build, "0x%02x: ", tok.Address)
case 16:
- build.WriteString(fmt.Sprintf("0x%04x: ", tok.Address))
+ fmt.Fprintf(&build, "0x%04x: ", tok.Address)
case 32:
- build.WriteString(fmt.Sprintf("0x%08x: ", tok.Address))
+ fmt.Fprintf(&build, "0x%08x: ", tok.Address)
default:
- build.WriteString(fmt.Sprintf("0x%016x: ", tok.Address))
+ fmt.Fprintf(&build, "0x%016x: ", tok.Address)
}
if tok.Label != "" {
build.WriteString(tok.Label)
@@ -289,7 +289,7 @@ func ioCall(m machine.Machine, call *machine.Call, in *bufio.Reader) {
return
}
- m.SetMemoryChunk(addr, []uint8(buf))
+ _ = m.SetMemoryChunk(addr, []uint8(buf))
} else {
addr := call.Arg1
size := call.Arg2
@@ -592,7 +592,7 @@ func debuggerDump(m machine.Machine, args []string, prog []uint8) {
fmt.Printf(machine.InterCtx.Get("Error while writing to %s: %v\n"), file, err)
}
- f.Close()
+ _ = f.Close()
}
func debuggerRewind(m machine.Machine, prog []uint8) {
diff --git a/main.go b/main.go
@@ -12,8 +12,8 @@ import (
"github.com/gboncoffee/egg/machine"
"github.com/gboncoffee/egg/mips"
"github.com/gboncoffee/egg/reduxK"
- "github.com/gboncoffee/egg/reduxv"
"github.com/gboncoffee/egg/reduxPia"
+ "github.com/gboncoffee/egg/reduxv"
"github.com/gboncoffee/egg/riscv"
"github.com/gboncoffee/egg/sagui"
)
@@ -53,8 +53,8 @@ func runMachine(m machine.Machine) {
size := call.Arg2
buf := make([]uint8, size)
reader := bufio.NewReader(os.Stdin)
- io.ReadFull(reader, buf)
- m.SetMemoryChunk(addr, buf)
+ _, _ = io.ReadFull(reader, buf)
+ _ = m.SetMemoryChunk(addr, buf)
case machine.SYS_WRITE:
addr := call.Arg1
size := call.Arg2
@@ -73,8 +73,8 @@ func main() {
var m machine.Machine
machine.InterCtx.Init()
- machine.InterCtx.AddLocale("pt_BR", brazilian)
- machine.InterCtx.AutoSetPreferedLocale()
+ _ = machine.InterCtx.AddLocale("pt_BR", brazilian)
+ _ = machine.InterCtx.AutoSetPreferedLocale()
assembler.InterCtx = &machine.InterCtx
log.SetFlags(0)
diff --git a/mips/mips.go b/mips/mips.go
@@ -208,11 +208,11 @@ func (m *Mips) execSpecial(rs, rt, rd, shamt, funct uint8) {
// div
case 0x18:
res := rsv64 * rtv64
- m.SetRegister(HI, uint64(res>>32))
- m.SetRegister(LO, uint64(res&0x00000000ffffffff))
+ _ = m.SetRegister(HI, uint64(res>>32))
+ _ = m.SetRegister(LO, uint64(res&0x00000000ffffffff))
case 0x1a:
- m.SetRegister(HI, uint64(rsv%rtv))
- m.SetRegister(LO, uint64(rsv/rtv))
+ _ = m.SetRegister(HI, uint64(rsv%rtv))
+ _ = m.SetRegister(LO, uint64(rsv/rtv))
// mfhi
// mflo
// mthi
@@ -224,9 +224,9 @@ func (m *Mips) execSpecial(rs, rt, rd, shamt, funct uint8) {
lo, _ := m.GetRegister(LO)
r = int32(lo)
case 0x11:
- m.SetRegister(HI, uint64(rsv))
+ _ = m.SetRegister(HI, uint64(rsv))
case 0x13:
- m.SetRegister(LO, uint64(rsv))
+ _ = m.SetRegister(LO, uint64(rsv))
// movz
// movn
case 0xa:
@@ -239,7 +239,7 @@ func (m *Mips) execSpecial(rs, rt, rd, shamt, funct uint8) {
}
}
- m.SetRegister(uint64(rd), uint64(r))
+ _ = m.SetRegister(uint64(rd), uint64(r))
}
func (m *Mips) execSpecial2(rs, rd, funct uint8) {
@@ -256,7 +256,7 @@ func (m *Mips) execSpecial2(rs, rd, funct uint8) {
r = int32(bits.LeadingZeros32(uint32(^rsv)))
}
- m.SetRegister(uint64(rd), uint64(r))
+ _ = m.SetRegister(uint64(rd), uint64(r))
}
func (m *Mips) execSpecial3(rs, rd, shamt, funct uint8) {
@@ -282,7 +282,7 @@ func (m *Mips) execSpecial3(rs, rd, shamt, funct uint8) {
}
}
- m.SetRegister(uint64(rd), uint64(r))
+ _ = m.SetRegister(uint64(rd), uint64(r))
}
func (m *Mips) execRegimm(rs, shamt uint8, imm uint32) {
@@ -343,53 +343,53 @@ func (m *Mips) executeBlez(rs uint8, imm uint32) {
func (m *Mips) executeAddi(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
r := int32(rsv64) + int32(imm)
- m.SetRegister(uint64(rt), uint64(r))
+ _ = m.SetRegister(uint64(rt), uint64(r))
}
func (m *Mips) executeAddiu(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
r := uint32(rsv64) + imm
- m.SetRegister(uint64(rt), uint64(r))
+ _ = m.SetRegister(uint64(rt), uint64(r))
}
func (m *Mips) executeAndi(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
r := uint32(rsv64) & imm
- m.SetRegister(uint64(rt), uint64(r))
+ _ = m.SetRegister(uint64(rt), uint64(r))
}
func (m *Mips) executeOri(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
r := uint32(rsv64) | imm
- m.SetRegister(uint64(rt), uint64(r))
+ _ = m.SetRegister(uint64(rt), uint64(r))
}
func (m *Mips) executeXori(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
r := uint32(rsv64) ^ imm
- m.SetRegister(uint64(rt), uint64(r))
+ _ = m.SetRegister(uint64(rt), uint64(r))
}
func (m *Mips) executeSlti(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
if int32(rsv64) < int32(imm) {
- m.SetRegister(uint64(rt), 1)
+ _ = m.SetRegister(uint64(rt), 1)
} else {
- m.SetRegister(uint64(rt), 0)
+ _ = m.SetRegister(uint64(rt), 0)
}
}
func (m *Mips) executeSltiu(rs, rt uint8, imm uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
if uint32(rsv64) < imm {
- m.SetRegister(uint64(rt), 1)
+ _ = m.SetRegister(uint64(rt), 1)
} else {
- m.SetRegister(uint64(rt), 0)
+ _ = m.SetRegister(uint64(rt), 0)
}
}
func (m *Mips) executeLui(rt uint8, imm uint32) {
- m.SetRegister(uint64(rt), uint64(imm<<16))
+ _ = m.SetRegister(uint64(rt), uint64(imm<<16))
}
func (m *Mips) executeJ(imm uint32) {
@@ -399,7 +399,7 @@ func (m *Mips) executeJ(imm uint32) {
}
func (m *Mips) executeJal(imm uint32) {
- m.SetRegister(31, uint64(m.pc+4))
+ _ = m.SetRegister(31, uint64(m.pc+4))
t := (m.pc + 4) & 0xf0000000
t = t | (imm << 2)
m.pc = t - 4
@@ -414,14 +414,14 @@ func (m *Mips) executeLb(rs, rt uint8, off uint32) {
sign = (^(sign - 1)) << 8
r := uint64(memb) | sign
- m.SetRegister(uint64(rt), r)
+ _ = m.SetRegister(uint64(rt), r)
}
func (m *Mips) executeLbu(rs, rt uint8, off uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
mem, _ := m.GetMemory(uint64(uint32(rsv64) + off))
- m.SetRegister(uint64(rt), uint64(mem))
+ _ = m.SetRegister(uint64(rt), uint64(mem))
}
func (m *Mips) executeLh(rs, rt uint8, off uint32) {
@@ -435,7 +435,7 @@ func (m *Mips) executeLh(rs, rt uint8, off uint32) {
sign = (^(sign - 1)) << 16
r := uint64(memb | sign)
- m.SetRegister(uint64(rt), r)
+ _ = m.SetRegister(uint64(rt), r)
}
func (m *Mips) executeLhu(rs, rt uint8, off uint32) {
@@ -444,7 +444,7 @@ func (m *Mips) executeLhu(rs, rt uint8, off uint32) {
mem := memSlice[0]
mem2 := memSlice[1]
- m.SetRegister(uint64(rt), uint64(mem)|(uint64(mem2)<<8))
+ _ = m.SetRegister(uint64(rt), uint64(mem)|(uint64(mem2)<<8))
}
func (m *Mips) executeLw(rs, rt uint8, off uint32) {
@@ -455,7 +455,7 @@ func (m *Mips) executeLw(rs, rt uint8, off uint32) {
mem3 := memSlice[2]
mem4 := memSlice[3]
- m.SetRegister(uint64(rt), uint64(mem)|(uint64(mem2)<<8)|(uint64(mem3)<<16)|(uint64(mem4)<<24))
+ _ = m.SetRegister(uint64(rt), uint64(mem)|(uint64(mem2)<<8)|(uint64(mem3)<<16)|(uint64(mem4)<<24))
}
func (m *Mips) executeLwl(rs, rt uint8, off uint32) {
@@ -465,7 +465,7 @@ func (m *Mips) executeLwl(rs, rt uint8, off uint32) {
mem := memSlice[0]
mem2 := memSlice[1]
- m.SetRegister(uint64(rt), ((uint64(mem)|(uint64(mem2)<<8))<<16)|(rtv64&0xffff))
+ _ = m.SetRegister(uint64(rt), ((uint64(mem)|(uint64(mem2)<<8))<<16)|(rtv64&0xffff))
}
func (m *Mips) executeLwr(rs, rt uint8, off uint32) {
@@ -475,32 +475,32 @@ func (m *Mips) executeLwr(rs, rt uint8, off uint32) {
mem := memSlice[0]
mem2 := memSlice[1]
- m.SetRegister(uint64(rt), (uint64(mem)|(uint64(mem2)<<8))|(rtv64&0xffff0000))
+ _ = m.SetRegister(uint64(rt), (uint64(mem)|(uint64(mem2)<<8))|(rtv64&0xffff0000))
}
func (m *Mips) executeSb(rs, rt uint8, off uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
rtv64, _ := m.GetRegister(uint64(rt))
- m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
}
func (m *Mips) executeSh(rs, rt uint8, off uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
rtv64, _ := m.GetRegister(uint64(rt))
- m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
- m.SetMemory(uint64(uint32(rsv64)+off)+1, uint8((rtv64&0xff00)>>8))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off)+1, uint8((rtv64&0xff00)>>8))
}
func (m *Mips) executeSw(rs, rt uint8, off uint32) {
rsv64, _ := m.GetRegister(uint64(rs))
rtv64, _ := m.GetRegister(uint64(rt))
- m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
- m.SetMemory(uint64(uint32(rsv64)+off)+1, uint8((rtv64&0xff00)>>8))
- m.SetMemory(uint64(uint32(rsv64)+off)+2, uint8((rtv64&0xff0000)>>16))
- m.SetMemory(uint64(uint32(rsv64)+off)+3, uint8((rtv64&0xff000000)>>24))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off), uint8(rtv64&0xff))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off)+1, uint8((rtv64&0xff00)>>8))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off)+2, uint8((rtv64&0xff0000)>>16))
+ _ = m.SetMemory(uint64(uint32(rsv64)+off)+3, uint8((rtv64&0xff000000)>>24))
}
func (m *Mips) execute(i uint32) (*machine.Call, error) {
diff --git a/mips/mips_test.go b/mips/mips_test.go
@@ -13,7 +13,7 @@ func TestIsa(t *testing.T) {
// Assembling will fail if we don't initialize the InterCtx.
machine.InterCtx.Init()
- machine.InterCtx.AutoSetPreferedLocale()
+ _ = machine.InterCtx.AutoSetPreferedLocale()
assembler.InterCtx = &machine.InterCtx
code, _, err := m.Assemble("mips-test.asm")
@@ -21,312 +21,312 @@ func TestIsa(t *testing.T) {
t.Fatalf("Could not assemble file: %v", err)
}
- m.LoadProgram(code)
+ _ = m.LoadProgram(code)
// add t0, t1, t2
- m.SetRegister(1+8, 3)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 3)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ := m.GetRegister(0 + 8)
if v != 5 {
t.Fatalf("add failed: %v", v)
}
// addi t0, t1, 2
- m.SetRegister(1+8, 3)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 3)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 5 {
t.Fatalf("addi failed: %v", v)
}
// addiu t0, t1, 3
- m.SetRegister(1+8, 0xf0_00_00_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xf0_00_00_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xf0000003 {
t.Fatalf("addiu failed: %v", v)
}
// addu t0, t1, t2
- m.SetRegister(1+8, 3)
- m.SetRegister(2+8, 0xf0_00_00_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 3)
+ _ = m.SetRegister(2+8, 0xf0_00_00_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xf0000003 {
t.Fatalf("addu failed: %v", v)
}
// clo t0, t1
- m.SetRegister(1+8, 0xf0_00_00_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xf0_00_00_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 4 {
t.Fatalf("clo failed: %v", v)
}
// clz t0, t1
- m.SetRegister(1+8, 3)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 3)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 30 {
t.Fatalf("clz failed: %v", v)
}
// lui t0, 0xffff
- m.NextInstruction()
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xffff0000 {
t.Fatalf("lui failed: %v", v)
}
// seb t0, t1
- m.SetRegister(1+8, 0xff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xffffffff {
t.Fatalf("seb failed: %v", v)
}
// seh t0, t1
- m.SetRegister(1+8, 0xff_ff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_ff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xffffffff {
t.Fatalf("seh failed: %v", v)
}
// sub t0, t1, t2
- m.SetRegister(1+8, 3)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 3)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 1 {
t.Fatalf("sub failed: %v", v)
}
// subu t0, t1, t2
- m.SetRegister(1+8, 0x80_00_00_03)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x80_00_00_03)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x80_00_00_01 {
t.Fatalf("subu failed: %v", v)
}
// sll t0, t1, 2
- m.SetRegister(1+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 4 {
t.Fatalf("sll failed: %v", v)
}
// sllv t0, t1, t2
- m.SetRegister(1+8, 1)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 4 {
t.Fatalf("sllv failed: %v", v)
}
// sra t0, t1, 2
- m.SetRegister(1+8, 0x80_00_00_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x80_00_00_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xe0_00_00_00 {
t.Fatalf("sra failed: %v", v)
}
// srav t0, t1, t2
- m.SetRegister(1+8, 0x80_00_00_00)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x80_00_00_00)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xe0_00_00_00 {
t.Fatalf("srav failed: %v", v)
}
// srl t0, t1, 2
- m.SetRegister(1+8, 0x80_00_00_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x80_00_00_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x20_00_00_00 {
t.Fatalf("srl failed: %v", v)
}
// srlv t0, t1, t2
- m.SetRegister(1+8, 0x80_00_00_00)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x80_00_00_00)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x20_00_00_00 {
t.Fatalf("srlv failed: %v", v)
}
// and t0, t1, t2
- m.SetRegister(1+8, 0xffff)
- m.SetRegister(2+8, 0xff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xffff)
+ _ = m.SetRegister(2+8, 0xff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff {
t.Fatalf("and failed: %v", v)
}
// andi t0, t1 0xff
- m.SetRegister(1+8, 0xffff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xffff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff {
t.Fatalf("andi failed: %v", v)
}
// nor t0, t1, t2
- m.SetRegister(1+8, 0xff_ff_00_00)
- m.SetRegister(2+8, 0x00_ff_ff_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_ff_00_00)
+ _ = m.SetRegister(2+8, 0x00_ff_ff_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x00_00_00_ff {
t.Fatalf("nor failed: %v", v)
}
// or t0, t1, t2
- m.SetRegister(1+8, 0xff_ff_00_00)
- m.SetRegister(2+8, 0x00_ff_ff_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_ff_00_00)
+ _ = m.SetRegister(2+8, 0x00_ff_ff_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_ff_ff_00 {
t.Fatalf("or failed: %v", v)
}
// ori t0, t1, 0xff
- m.SetRegister(1+8, 0xff_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_ff {
t.Fatalf("ori failed: %v", v)
}
// xor t0, t1, t2
- m.SetRegister(1+8, 0xff_ff_00_00)
- m.SetRegister(2+8, 0x00_ff_ff_00)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_ff_00_00)
+ _ = m.SetRegister(2+8, 0x00_ff_ff_00)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_00_ff_00 {
t.Fatalf("xor failed: %v", v)
}
// xori t0, t1, 0xff
- m.SetRegister(1+8, 0xff_01)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff_01)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_fe {
t.Fatalf("xori failed: %v", v)
}
// movn t0, t1, t2
- m.SetRegister(0+8, 0)
- m.SetRegister(1+8, 0xff)
- m.SetRegister(2+8, 0)
- m.NextInstruction()
+ _ = m.SetRegister(0+8, 0)
+ _ = m.SetRegister(1+8, 0xff)
+ _ = m.SetRegister(2+8, 0)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("movn (not) failed: %v", v)
}
m.pc -= 4
- m.SetRegister(2+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(2+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff {
t.Fatalf("movn (yes) failed: %v", v)
}
// movz t0, t1, t2
- m.SetRegister(0+8, 0)
- m.SetRegister(1+8, 0xff)
- m.SetRegister(2+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(0+8, 0)
+ _ = m.SetRegister(1+8, 0xff)
+ _ = m.SetRegister(2+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("movz (not) failed: %v", v)
}
m.pc -= 4
- m.SetRegister(2+8, 0)
- m.NextInstruction()
+ _ = m.SetRegister(2+8, 0)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff {
t.Fatalf("movz (yes) failed: %v", v)
}
// slt t0, t1, t2
- m.SetRegister(1+8, 1)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 1 {
t.Fatalf("slt failed: %v", v)
}
m.pc -= 4
- m.SetRegister(1+8, 2)
- m.SetRegister(2+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 2)
+ _ = m.SetRegister(2+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("slt failed: %v", v)
}
// slti t0, t1, 0xff
- m.SetRegister(1+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 1 {
t.Fatalf("slti failed: %v", v)
}
m.pc -= 4
- m.SetRegister(1+8, 0xff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("slti failed: %v", v)
}
// sltiu t0, t1, 0xff
- m.SetRegister(1+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 1 {
t.Fatalf("sltiu failed: %v", v)
}
m.pc -= 4
- m.SetRegister(1+8, 0xff)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0xff)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("sltiu failed: %v", v)
}
// sltu t0, t1, t2
- m.SetRegister(1+8, 1)
- m.SetRegister(2+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 1)
+ _ = m.SetRegister(2+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 1 {
t.Fatalf("sltu failed: %v", v)
}
m.pc -= 4
- m.SetRegister(1+8, 2)
- m.SetRegister(2+8, 1)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 2)
+ _ = m.SetRegister(2+8, 1)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0 {
t.Fatalf("sltu failed: %v", v)
}
// div t0, t1
- m.SetRegister(0+8, 10)
- m.SetRegister(1+8, 2)
- m.NextInstruction()
+ _ = m.SetRegister(0+8, 10)
+ _ = m.SetRegister(1+8, 2)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(LO)
if v != 5 {
t.Fatalf("div failed (lo): %v", v)
@@ -337,9 +337,9 @@ func TestIsa(t *testing.T) {
}
// mult t0, t1
- m.SetRegister(0+8, 2)
- m.SetRegister(1+8, 3)
- m.NextInstruction()
+ _ = m.SetRegister(0+8, 2)
+ _ = m.SetRegister(1+8, 3)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(LO)
if v != 6 {
t.Fatalf("mult failed: %v", v)
@@ -350,88 +350,88 @@ func TestIsa(t *testing.T) {
}
// mfhi t0
- m.SetRegister(HI, 0x12345678)
- m.NextInstruction()
+ _ = m.SetRegister(HI, 0x12345678)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x12345678 {
t.Fatalf("mfhi failed: %v", v)
}
// mflo t0
- m.SetRegister(LO, 0x12345678)
- m.NextInstruction()
+ _ = m.SetRegister(LO, 0x12345678)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x12345678 {
t.Fatalf("mflo failed: %v", v)
}
// mthi t0
- m.SetRegister(1+8, 0x12345678)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x12345678)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(HI)
if v != 0x12345678 {
t.Fatalf("mthi failed: %v", v)
}
// mtlo t0
- m.SetRegister(1+8, 0x12345678)
- m.NextInstruction()
+ _ = m.SetRegister(1+8, 0x12345678)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(LO)
if v != 0x12345678 {
t.Fatalf("mtlo failed: %v", v)
}
// beq t0, t1, 8
- m.SetRegister(0+8, 1)
- m.SetRegister(1+8, 1)
+ _ = m.SetRegister(0+8, 1)
+ _ = m.SetRegister(1+8, 1)
savedPC := m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("beq failed: %v to %v", savedPC, m.pc)
}
m.pc = savedPC + 4
// bgez t0, 8
- m.SetRegister(0+8, 1)
+ _ = m.SetRegister(0+8, 1)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("bgez failed: %v to %v", savedPC, m.pc)
}
m.pc = savedPC + 4
// bgtz t0, 8
- m.SetRegister(0+8, 1)
+ _ = m.SetRegister(0+8, 1)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("bgtz failed: %v to %v", savedPC, m.pc)
}
m.pc = savedPC + 4
// blez t0, 8
- m.SetRegister(0+8, 0)
+ _ = m.SetRegister(0+8, 0)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("blez failed: %v to %v", savedPC, m.pc)
}
m.pc = savedPC + 4
// bltz t0, 8
- m.SetRegister(0+8, 0xff_ff_ff_ff)
+ _ = m.SetRegister(0+8, 0xff_ff_ff_ff)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("bltz failed: %v to %v", savedPC, m.pc)
}
m.pc = savedPC + 4
// bne t0, t1, 8
- m.SetRegister(0+8, 1)
- m.SetRegister(1+8, 2)
+ _ = m.SetRegister(0+8, 1)
+ _ = m.SetRegister(1+8, 2)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0 {
t.Fatalf("bne failed: %v to %v", savedPC, m.pc)
}
@@ -444,9 +444,9 @@ func TestIsa(t *testing.T) {
}
// syscall
- m.SetRegister(2, machine.SYS_READ)
- m.SetRegister(4, 1)
- m.SetRegister(5, 2)
+ _ = m.SetRegister(2, machine.SYS_READ)
+ _ = m.SetRegister(4, 1)
+ _ = m.SetRegister(5, 2)
call, _ = m.NextInstruction()
expectedCall := machine.Call{
Number: machine.SYS_READ,
@@ -459,7 +459,7 @@ func TestIsa(t *testing.T) {
// j 8
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != (savedPC&0xf0000000)|8 {
t.Fatalf("j failed: %v", m.pc)
}
@@ -467,7 +467,7 @@ func TestIsa(t *testing.T) {
// jal 8
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != (savedPC&0xf0000000)|8 {
t.Fatalf("jal failed: %v", m.pc)
}
@@ -478,9 +478,9 @@ func TestIsa(t *testing.T) {
m.pc = savedPC + 4
// jalr t0
- m.SetRegister(0+8, 0x12345678)
+ _ = m.SetRegister(0+8, 0x12345678)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0x12345678 {
t.Fatalf("jalr failed: %v", m.pc)
}
@@ -491,84 +491,84 @@ func TestIsa(t *testing.T) {
m.pc = savedPC + 4
// jr t0
- m.SetRegister(0+8, 0x12345678)
+ _ = m.SetRegister(0+8, 0x12345678)
savedPC = m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != 0x12345678 {
t.Fatalf("jr failed: %v", m.pc)
}
m.pc = savedPC + 4
// lb t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 2, 3, 4})
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 2, 3, 4})
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_ff_ff_ff {
t.Fatalf("lb failed: %v", v)
}
// lbu t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 2, 3, 4})
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 2, 3, 4})
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff {
t.Fatalf("lbu failed: %v", v)
}
// lh t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 0xff, 3, 4})
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 0xff, 3, 4})
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_ff_ff_ff {
t.Fatalf("lh failed: %v", v)
}
// lhu t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 0xff, 3, 4})
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0xff, 0xff, 3, 4})
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0xff_ff {
t.Fatalf("lhu failed: %v", v)
}
// lw t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{1, 2, 3, 4})
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{1, 2, 3, 4})
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
v, _ = m.GetRegister(0 + 8)
if v != 0x04_03_02_01 {
t.Fatalf("lw failed: %v", v)
}
// sb t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
- m.SetRegister(0+8, 0xdeadbeef)
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
+ _ = m.SetRegister(0+8, 0xdeadbeef)
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
slice, _ := m.GetMemoryChunk(0xcafebabe, 4)
if !reflect.DeepEqual(slice, []uint8{0xef, 0, 0, 0}) {
t.Fatalf("sb failed: %v", slice)
}
// sh t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
- m.SetRegister(0+8, 0xdeadbeef)
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
+ _ = m.SetRegister(0+8, 0xdeadbeef)
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
slice, _ = m.GetMemoryChunk(0xcafebabe, 4)
if !reflect.DeepEqual(slice, []uint8{0xef, 0xbe, 0, 0}) {
t.Fatalf("sh failed: %v", slice)
}
// sw t0, t1, 0
- m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
- m.SetRegister(0+8, 0xdeadbeef)
- m.SetRegister(1+8, 0xcafebabe)
- m.NextInstruction()
+ _ = m.SetMemoryChunk(0xcafebabe, []uint8{0, 0, 0, 0})
+ _ = m.SetRegister(0+8, 0xdeadbeef)
+ _ = m.SetRegister(1+8, 0xcafebabe)
+ _, _ = m.NextInstruction()
slice, _ = m.GetMemoryChunk(0xcafebabe, 4)
if !reflect.DeepEqual(slice, []uint8{0xef, 0xbe, 0xad, 0xde}) {
t.Fatalf("sw failed: %v", slice)
diff --git a/reduxK/reduxK.go b/reduxK/reduxK.go
@@ -152,11 +152,11 @@ func (m *ReduxK) NextInstruction() (*machine.Call, error) {
m.pc += signExtend8(uint8(imm)) - 1
case 0x2:
mem, _ := m.GetMemory(rbv)
- m.SetRegister(uint64(ra), uint64(mem))
+ _ = m.SetRegister(uint64(ra), uint64(mem))
case 0x3:
- m.SetMemory(rbv, uint8(rav))
+ _ = m.SetMemory(rbv, uint8(rav))
case 0x4:
- m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
+ _ = m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
case 0x5:
for x := int8(0); x < int8(sizev); x++ {
r0v, _ := m.GetRegister(0)
@@ -164,53 +164,53 @@ func (m *ReduxK) NextInstruction() (*machine.Call, error) {
r2v, _ := m.GetRegister(2)
r3v, _ := m.GetRegister(3)
- m.SetMemory(r0v, uint8(r2v))
- m.SetRegister(uint64(2), uint64(uint8(int8(r2v)+int8(r3v))))
- m.SetRegister(uint64(0), uint64(uint8(int8(r0v)+int8(r1v))))
+ _ = m.SetMemory(r0v, uint8(r2v))
+ _ = m.SetRegister(uint64(2), uint64(uint8(int8(r2v)+int8(r3v))))
+ _ = m.SetRegister(uint64(0), uint64(uint8(int8(r0v)+int8(r1v))))
}
case 0x6:
for x := int8(0); x < int8(sizev); x++ {
r0v, _ := m.GetRegister(0)
memr0, _ := m.GetMemory(r0v)
- m.SetAuxRegister(0, uint64(memr0))
+ _ = m.SetAuxRegister(0, uint64(memr0))
r1v, _ := m.GetRegister(1)
memr1, _ := m.GetMemory(r1v)
- m.SetAuxRegister(1, uint64(memr1))
+ _ = m.SetAuxRegister(1, uint64(memr1))
rx, _ := m.GetAuxRegister(0)
ry, _ := m.GetAuxRegister(1)
- m.SetRegister(uint64(3), uint64(uint8(int8(rx)+int8(ry))))
+ _ = m.SetRegister(uint64(3), uint64(uint8(int8(rx)+int8(ry))))
r2v, _ := m.GetRegister(2)
r3v, _ := m.GetRegister(3)
- m.SetMemory(r2v, uint8(r3v))
+ _ = m.SetMemory(r2v, uint8(r3v))
for x := 0; x < 4; x++ {
regv, _ := m.GetRegister(uint64(x))
- m.SetRegister(uint64(x), uint64(uint8(int8(regv)+int8(1))))
+ _ = m.SetRegister(uint64(x), uint64(uint8(int8(regv)+int8(1))))
}
}
case 0x7:
if ra == 0 {
for x := 0; x < 4; x++ {
regv, _ := m.GetRegister(uint64(x))
- m.SetRegister(uint64(x), uint64(uint8(int8(regv)+int8(uimm))))
+ _ = m.SetRegister(uint64(x), uint64(uint8(int8(regv)+int8(uimm))))
}
break
}
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(uimm))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(uimm))))
case 0x8:
if rbv == 0 {
- m.SetRegister(uint64(ra), 1)
+ _ = m.SetRegister(uint64(ra), 1)
} else {
- m.SetRegister(uint64(ra), 0)
+ _ = m.SetRegister(uint64(ra), 0)
}
case 0x9:
- m.SetRegister(uint64(ra), rav&rbv)
+ _ = m.SetRegister(uint64(ra), rav&rbv)
case 0xa:
if rb == 0 && ra == 0 {
m.pc++
@@ -221,7 +221,7 @@ func (m *ReduxK) NextInstruction() (*machine.Call, error) {
}, nil
}
- m.SetRegister(uint64(ra), rav|rbv)
+ _ = m.SetRegister(uint64(ra), rav|rbv)
case 0xb:
if rb == 0 && ra == 0 {
m.pc++
@@ -234,15 +234,15 @@ func (m *ReduxK) NextInstruction() (*machine.Call, error) {
}, nil
}
- m.SetRegister(uint64(ra), rav^rbv)
+ _ = m.SetRegister(uint64(ra), rav^rbv)
case 0xc:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
case 0xd:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
case 0xe:
- m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
+ _ = m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
case 0xf:
- m.SetRegister(uint64(ra), rav>>rbv)
+ _ = m.SetRegister(uint64(ra), rav>>rbv)
}
m.pc++
diff --git a/reduxK/reduxK_test.go b/reduxK/reduxK_test.go
@@ -9,7 +9,7 @@ import (
func TestReduxK(t *testing.T) {
machine.InterCtx.Init()
- machine.InterCtx.AutoSetPreferedLocale()
+ _ = machine.InterCtx.AutoSetPreferedLocale()
assembler.InterCtx = &machine.InterCtx
var m ReduxK
@@ -32,7 +32,7 @@ func TestReduxK(t *testing.T) {
assertBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() == pc+1 {
t.Fatalf("Didn't branched on %v", name)
}
@@ -40,88 +40,88 @@ func TestReduxK(t *testing.T) {
assertDontBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() != pc+1 {
t.Fatalf("Branched on %v", name)
}
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 5, "prepare for jump")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 5, "copy addr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "zero r0 for branching")
assertBranch("brzr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "addi 1 for branching")
assertDontBranch("brzr")
assertBranch("ji")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "not test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 2, "add test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0, "sub for logical test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 1, "not for logical test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 3, "or test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "and test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 2, "sll test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 3, "xor test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "srr test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub r0 for load/store")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0, "sub r1 for load/store")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xff, "addi address")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0xff, "add r1, r0 address")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "zero r0 for value")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xfe, "addi value")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
mem, _ := m.GetMemory(0xff)
if mem != 0xfe {
t.Fatalf("st failed")
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub for load test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xfe, "ld")
call, _ := m.NextInstruction()
@@ -129,31 +129,31 @@ func TestReduxK(t *testing.T) {
t.Fatalf("Break failed: %v", call)
}
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
call, _ = m.NextInstruction()
if call == nil || call.Number != 0 || call.Arg1 != 1 || call.Arg2 != 2 {
t.Fatalf("Call failed: %v", call)
}
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
for x := 0; x < 4; x++ {
assertRegister(uint64(x), 0x1, "inc on r0")
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
for x := 1; x < 4; x++ {
mem, _ := m.GetMemory(uint64(x))
if mem != uint8(x) {
@@ -161,27 +161,27 @@ func TestReduxK(t *testing.T) {
}
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(2, 0x5, "inc")
for x := 4; x < 7; x++ {
- m.NextInstruction()
+ _, _ = m.NextInstruction()
mem, _ := m.GetMemory(uint64(x))
if mem != uint8(x+1) {
t.Fatalf("loadv failed")
}
}
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
mem, _ = m.GetMemory(0x07)
if mem != 6 {
t.Fatalf("loadv failed")
diff --git a/reduxPia/reduxPia.go b/reduxPia/reduxPia.go
@@ -138,43 +138,43 @@ func (m *ReduxPia) NextInstruction() (*machine.Call, error) {
m.pc += signExtend8(uint8(imm)) - 1
case 0x2:
mem, _ := m.GetMemory(rbv)
- m.SetRegister(uint64(ra), uint64(mem))
+ _ = m.SetRegister(uint64(ra), uint64(mem))
case 0x3:
- m.SetMemory(rbv, uint8(rav))
+ _ = m.SetMemory(rbv, uint8(rav))
case 0x4:
- m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
+ _ = m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
case 0x5:
- m.SetRegister(0, uint64((uint8(r0v) & 0xf) | (imm << 4)))
+ _ = m.SetRegister(0, uint64((uint8(r0v)&0xf)|(imm<<4)))
case 0x6:
r3v, _ := m.GetRegister(3)
- r := uint64(r3v-1)
- m.SetRegister(3, r)
+ r := uint64(r3v - 1)
+ _ = m.SetRegister(3, r)
if r != 0 {
m.pc -= imm + 1
return nil, nil
}
case 0x7:
- m.SetRegister(0, uint64(r0v) + rav * rbv)
+ _ = m.SetRegister(0, uint64(r0v)+rav*rbv)
case 0x8:
if rbv == 0 {
- m.SetRegister(uint64(ra), 1)
+ _ = m.SetRegister(uint64(ra), 1)
} else {
- m.SetRegister(uint64(ra), 0)
+ _ = m.SetRegister(uint64(ra), 0)
}
case 0x9:
- m.SetRegister(uint64(ra), rav&rbv)
+ _ = m.SetRegister(uint64(ra), rav&rbv)
case 0xa:
- m.SetRegister(uint64(ra), rav|rbv)
+ _ = m.SetRegister(uint64(ra), rav|rbv)
case 0xb:
- m.SetRegister(uint64(ra), rav^rbv)
+ _ = m.SetRegister(uint64(ra), rav^rbv)
case 0xc:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
case 0xd:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
case 0xe:
- m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
+ _ = m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
case 0xf:
- m.SetRegister(uint64(ra), rav>>rbv)
+ _ = m.SetRegister(uint64(ra), rav>>rbv)
}
m.pc++
diff --git a/reduxv/reduxv.go b/reduxv/reduxv.go
@@ -129,11 +129,11 @@ func (m *ReduxV) NextInstruction() (*machine.Call, error) {
m.pc += signExtend8(uint8(imm)) - 1
case 0x2:
mem, _ := m.GetMemory(rbv)
- m.SetRegister(uint64(ra), uint64(mem))
+ _ = m.SetRegister(uint64(ra), uint64(mem))
case 0x3:
- m.SetMemory(rbv, uint8(rav))
+ _ = m.SetMemory(rbv, uint8(rav))
case 0x4:
- m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
+ _ = m.SetRegister(0, uint64(uint8(r0v)+signExtend8(imm)))
case 0x5:
m.pc++
return &machine.Call{
@@ -153,24 +153,24 @@ func (m *ReduxV) NextInstruction() (*machine.Call, error) {
// 0x7 not implemented.
case 0x8:
if rbv == 0 {
- m.SetRegister(uint64(ra), 1)
+ _ = m.SetRegister(uint64(ra), 1)
} else {
- m.SetRegister(uint64(ra), 0)
+ _ = m.SetRegister(uint64(ra), 0)
}
case 0x9:
- m.SetRegister(uint64(ra), rav&rbv)
+ _ = m.SetRegister(uint64(ra), rav&rbv)
case 0xa:
- m.SetRegister(uint64(ra), rav|rbv)
+ _ = m.SetRegister(uint64(ra), rav|rbv)
case 0xb:
- m.SetRegister(uint64(ra), rav^rbv)
+ _ = m.SetRegister(uint64(ra), rav^rbv)
case 0xc:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)+int8(rbv))))
case 0xd:
- m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
+ _ = m.SetRegister(uint64(ra), uint64(uint8(int8(rav)-int8(rbv))))
case 0xe:
- m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
+ _ = m.SetRegister(uint64(ra), (rav<<rbv)&0xff)
case 0xf:
- m.SetRegister(uint64(ra), rav>>rbv)
+ _ = m.SetRegister(uint64(ra), rav>>rbv)
}
m.pc++
diff --git a/reduxv/reduxv_test.go b/reduxv/reduxv_test.go
@@ -9,7 +9,7 @@ import (
func TestReduxV(t *testing.T) {
machine.InterCtx.Init()
- machine.InterCtx.AutoSetPreferedLocale()
+ _ = machine.InterCtx.AutoSetPreferedLocale()
assembler.InterCtx = &machine.InterCtx
var m ReduxV
@@ -32,7 +32,7 @@ func TestReduxV(t *testing.T) {
assertBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() == pc+1 {
t.Fatalf("Didn't branched on %v", name)
}
@@ -40,88 +40,88 @@ func TestReduxV(t *testing.T) {
assertDontBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() != pc+1 {
t.Fatalf("Branched on %v", name)
}
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 5, "prepare for jump")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 5, "copy addr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "zero r0 for branching")
assertBranch("brzr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "addi 1 for branching")
assertDontBranch("brzr")
assertBranch("ji")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "not test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 2, "add test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0, "sub for logical test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 1, "not for logical test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 3, "or test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "and test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 2, "sll test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 3, "xor test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "srr test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub r0 for load/store")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0, "sub r1 for load/store")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xff, "addi address")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0xff, "add r1, r0 address")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "zero r0 for value")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xfe, "addi value")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
mem, _ := m.GetMemory(0xff)
if mem != 0xfe {
t.Fatalf("st failed")
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "sub for load test")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xfe, "ld")
call, _ := m.NextInstruction()
@@ -129,15 +129,15 @@ func TestReduxV(t *testing.T) {
t.Fatalf("Break failed: %v", call)
}
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
call, _ = m.NextInstruction()
if call == nil || call.Number != 0 || call.Arg1 != 1 || call.Arg2 != 2 {
diff --git a/riscv/riscv.go b/riscv/riscv.go
@@ -220,7 +220,7 @@ func (m *RiscV) execArithmetic(rd uint8, rs1 uint8, rs2 uint8, func3 uint8, func
}
}
- m.SetRegister(uint64(rd), uint64(r))
+ _ = m.SetRegister(uint64(rd), uint64(r))
m.pc += 4
@@ -264,7 +264,7 @@ func (m *RiscV) execImmArithmetic(rd uint8, rs1 uint8, imm uint32, func3 uint8)
r = rs1v & immv
}
- m.SetRegister(uint64(rd), uint64(r))
+ _ = m.SetRegister(uint64(rd), uint64(r))
m.pc += 4
}
@@ -302,7 +302,7 @@ func (m *RiscV) execLoad(rd uint8, rs1 uint8, imm uint32, func3 uint8) {
v = uint32(mem[0]) | (uint32(mem[1]) << 8)
}
- m.SetRegister(uint64(rd), uint64(v))
+ _ = m.SetRegister(uint64(rd), uint64(v))
m.pc += 4
}
@@ -315,10 +315,10 @@ func (m *RiscV) execStore(rs1 uint8, rs2 uint8, imm uint32, func3 uint8) {
switch func3 {
case 0x0:
- m.SetMemory(addr, uint8(rs2v))
+ _ = m.SetMemory(addr, uint8(rs2v))
case 0x1:
v := []uint8{uint8(rs2v), uint8(rs2v >> 8)}
- m.SetMemoryChunk(addr, v)
+ _ = m.SetMemoryChunk(addr, v)
case 0x2:
v := []uint8{
uint8(rs2v),
@@ -326,7 +326,7 @@ func (m *RiscV) execStore(rs1 uint8, rs2 uint8, imm uint32, func3 uint8) {
uint8(rs2v >> 16),
uint8(rs2v >> 24),
}
- m.SetMemoryChunk(addr, v)
+ _ = m.SetMemoryChunk(addr, v)
}
m.pc += 4
@@ -376,25 +376,25 @@ func (m *RiscV) execBranch(rs1 uint8, rs2 uint8, imm uint32, func3 uint8) {
}
func (m *RiscV) execJal(rd uint8, imm uint32) {
- m.SetRegister(uint64(rd), uint64(m.pc+4))
+ _ = m.SetRegister(uint64(rd), uint64(m.pc+4))
r := int32(m.pc) + int32(imm)
m.pc = uint32(r)
}
func (m *RiscV) execJalr(rd uint8, rs1 uint8, imm uint32) {
- m.SetRegister(uint64(rd), uint64(m.pc+4))
+ _ = m.SetRegister(uint64(rd), uint64(m.pc+4))
rs1v, _ := m.GetRegister(uint64(rs1))
m.pc = uint32(rs1v) + imm
}
func (m *RiscV) execLui(rd uint8, imm uint32) {
- m.SetRegister(uint64(rd), uint64(imm))
+ _ = m.SetRegister(uint64(rd), uint64(imm))
m.pc += 4
}
func (m *RiscV) execAuipc(rd uint8, imm uint32) {
- m.SetRegister(uint64(rd), uint64(m.pc)+uint64(imm))
+ _ = m.SetRegister(uint64(rd), uint64(m.pc)+uint64(imm))
m.pc += 4
}
diff --git a/riscv/riscv_test.go b/riscv/riscv_test.go
@@ -11,17 +11,17 @@ import (
func TestRegister(t *testing.T) {
var m RiscV
- m.SetRegister(1, 39)
+ _ = m.SetRegister(1, 39)
v, err := m.GetRegister(1)
if v != 39 || err != nil {
t.Fatalf("Error getting register 1: %d, %v", v, err)
}
- m.SetRegister(0, 39)
+ _ = m.SetRegister(0, 39)
v, err = m.GetRegister(0)
if v != 0 || err != nil {
t.Fatalf("Error getting register 0: %d, %v", v, err)
}
- m.SetRegister(31, 42)
+ _ = m.SetRegister(31, 42)
v, err = m.GetRegister(31)
if v != 42 || err != nil {
t.Fatalf("Error getting register 31: %d, %v", v, err)
@@ -209,7 +209,7 @@ func (m *RiscV) assertRegister(t *testing.T, v string, r uint64, s string) {
func (m *RiscV) ensureBranch(t *testing.T, i string) {
pc := m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if pc == m.pc-4 {
t.Fatalf("%s didn't branch correctly: %d", i, m.pc)
}
@@ -217,7 +217,7 @@ func (m *RiscV) ensureBranch(t *testing.T, i string) {
func (m *RiscV) ensureDontBranch(t *testing.T, i string) {
pc := m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if pc != m.pc-4 {
t.Fatalf("%s didn't pass correctly: %x", i, m.pc)
}
@@ -239,119 +239,119 @@ func TestInstructions(t *testing.T) {
//
// Arithmetic immediate.
//
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 1, "addi t0, zero, 1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 4, "xori t0, t0, 5")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 6, "ori t0, t0, 2")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 2, "andi t0, t0, 3")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 8, "slli t0, t0, 2")
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 536870914, "srli t2, t1, 2")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 3758096386, "srai t2, t1, 2")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t3", 1, "slti t3, t2, t0")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t3", 0, "sltu t3, t2, t0")
//
// Arithmetic.
//
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 3, "add t4, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 1, "sub t4, t2, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 6, "xor t4, t3, t2")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 3, "or t4, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 1, "and t4, t2, t3")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 4, "sll t4, t0, t1")
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 536870914, "srl t4, t5, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 3758096386, "sra t4, t5, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 1, "slt t4, t5, t2")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t4", 0, "sltu t4, t5, t2")
//
// Loads and stores.
//
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t1", 0xaaeeffff, "test value moving")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 0xaaeeffff, "lw t2, t0, 0")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 0xffffffff, "lb t2, t0, 0")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 0x000000ff, "lbu t2, t0, 0")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 0xffffffff, "lh t2, t0, 0")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", 0x0000ffff, "lhu t2, t0, 0")
//
// Jumps.
//
ret := m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc == ret+4 {
t.Fatalf("jal does not jump correctly")
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.pc != ret+4 {
t.Fatalf("jalr does not return correctly")
}
@@ -359,7 +359,7 @@ func TestInstructions(t *testing.T) {
//
// Calls.
//
- m.NextInstruction()
+ _, _ = m.NextInstruction()
call, _ := m.NextInstruction()
if call == nil {
t.Fatalf("call is nil")
@@ -378,8 +378,8 @@ func TestInstructions(t *testing.T) {
//
// Branches.
//
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
m.ensureDontBranch(t, "beq")
m.ensureBranch(t, "beq")
@@ -406,42 +406,42 @@ func TestInstructions(t *testing.T) {
//
// auipc/lui
//
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", 0xaaaaa000, "lui t0, 0xaaaaa")
pc := m.pc
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t0", uint64(0xaaaaa000+pc), "auipc t0, 0xaaaaa")
//
// Multiplication extension.
//
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0x1fffd000), "mul t2, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0x1), "mulh t2, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0x1ffffaaa), "div t2, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0xE0003000), "mul t2, t0, t1 (neg)")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0xFFFFFFFE), "mulh t2, t0, t1 (neg)")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
// -536869545 but without the 4 top bytes.
m.assertRegister(t, "t2", uint64(3758097750), "div t2, t0, t1 (neg)")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(4294965248), "mulsu t2, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0x7FFFF800), "mulu t2, t0, t1")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
m.assertRegister(t, "t2", uint64(0x7FFFF000), "remu t2, t0, t1")
}
diff --git a/sagui/sagui.go b/sagui/sagui.go
@@ -134,33 +134,33 @@ func (m *Sagui) NextInstruction() (*machine.Call, error) {
m.pc = m.pc + signExtend(uint8(imm)) - 1
case 0x4:
mem, _ := m.GetMemory(rbv)
- m.SetRegister(uint64(ra), uint64(mem))
+ _ = m.SetRegister(uint64(ra), uint64(mem))
case 0x5:
- m.SetMemory(rbv, uint8(rav))
+ _ = m.SetMemory(rbv, uint8(rav))
case 0x6:
- m.SetRegister(uint64(ra), rbv)
+ _ = m.SetRegister(uint64(ra), rbv)
case 0x7:
- m.SetRegister(0, uint64(imm<<4)|(r0v&0xf))
+ _ = m.SetRegister(0, uint64(imm<<4)|(r0v&0xf))
case 0x8:
- m.SetRegister(0, uint64(imm)|r0v&0xf0)
+ _ = m.SetRegister(0, uint64(imm)|r0v&0xf0)
case 0x9:
- m.SetRegister(uint64(ra), rav+rbv)
+ _ = m.SetRegister(uint64(ra), rav+rbv)
case 0xA:
- m.SetRegister(uint64(ra), rav-rbv)
+ _ = m.SetRegister(uint64(ra), rav-rbv)
case 0xB:
- m.SetRegister(uint64(ra), rav&rbv)
+ _ = m.SetRegister(uint64(ra), rav&rbv)
case 0xC:
- m.SetRegister(uint64(ra), rav|rbv)
+ _ = m.SetRegister(uint64(ra), rav|rbv)
case 0xD:
if rbv == 0 {
- m.SetRegister(uint64(ra), 1)
+ _ = m.SetRegister(uint64(ra), 1)
} else {
- m.SetRegister(uint64(ra), 0)
+ _ = m.SetRegister(uint64(ra), 0)
}
case 0xE:
- m.SetRegister(uint64(ra), rav<<rbv)
+ _ = m.SetRegister(uint64(ra), rav<<rbv)
case 0xF:
- m.SetRegister(uint64(ra), rav>>rbv)
+ _ = m.SetRegister(uint64(ra), rav>>rbv)
}
m.pc++
diff --git a/sagui/sagui_test.go b/sagui/sagui_test.go
@@ -27,7 +27,7 @@ func TestSagui(t *testing.T) {
assertBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() == pc+1 {
t.Fatalf("Didn't branched on %v", name)
}
@@ -35,74 +35,74 @@ func TestSagui(t *testing.T) {
assertDontBranch := func(name string) {
pc := m.GetCurrentInstructionAddress()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
if m.GetCurrentInstructionAddress() != pc+1 {
t.Fatalf("Branched on %v", name)
}
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 5, "first movl to branch")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 5, "first movr to branch")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "zeroing r0 to branch")
assertBranch("brzr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertBranch("jr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertBranch("brzi")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertDontBranch("brzi")
assertDontBranch("brzr")
assertBranch("ji")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0x1, "movl to arithmetic")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0x1, "movr to arithmetic")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xf0, "movh to arithmetic")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xf1, "add")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xf0, "sub")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0xf1, "or")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0x1, "and")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0, "first not")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 1, "second not")
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0x2, "slr")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(0, 0x1, "srr")
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
- m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
+ _, _ = m.NextInstruction()
mem, _ := m.GetMemory(0xfa)
if mem != 0xa {
t.Fatalf("st failed")
}
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0, "zeroing r1 to be sure")
- m.NextInstruction()
+ _, _ = m.NextInstruction()
assertRegister(1, 0xa, "ld")
call, _ := m.NextInstruction()