Skip to content

Commit

Permalink
Added target test with already defined register
Browse files Browse the repository at this point in the history
  • Loading branch information
RealA10N committed Dec 2, 2024
1 parent 10c6c89 commit 9b07f14
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions gen/target_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gen_test

import (
"testing"

"alon.kr/x/usm/core"
"alon.kr/x/usm/gen"
"alon.kr/x/usm/parse"
"github.com/stretchr/testify/assert"
)

func TestTargetRegisterAlreadyDefined(t *testing.T) {
src := core.NewSourceView("$32 %a")
unmanaged := src.Unmanaged()
node := parse.TargetNode{
Register: parse.RegisterNode{
UnmanagedSourceView: unmanaged.Subview(4, 6),
},
Type: &parse.TypeNode{
Identifier: unmanaged.Subview(0, 3),
},
}

intType := &gen.TypeInfo{Name: "$32", Size: 4}
types := TypeMap{intType.Name: intType}

registers := RegisterMap{
"%a": &gen.RegisterInfo{Name: "%a", Type: intType},
}

ctx := gen.GenerationContext[Instruction]{
ArchInfo: gen.ArchInfo{PointerSize: 8},
SourceContext: src.Ctx(),
Types: &types,
Registers: &registers,
Instructions: &InstructionMap{},
}

generator := gen.TargetGenerator[Instruction]{}
info, results := generator.Generate(&ctx, node)
assert.True(t, results.IsEmpty())
assert.Equal(t, intType, info)
}

0 comments on commit 9b07f14

Please sign in to comment.