Skip to content

Commit

Permalink
Fixed instruction test
Browse files Browse the repository at this point in the history
  • Loading branch information
RealA10N committed Dec 2, 2024
1 parent 95f9c25 commit 7c99df3
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions gen/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type Instruction struct{}

type AddInstructionDefinition struct{}

func (AddInstructionDefinition) Names() []string {
return []string{"ADD"}
}

func (AddInstructionDefinition) BuildInstruction(
targets []*gen.RegisterInfo,
arguments []*gen.ArgumentInfo,
Expand Down Expand Up @@ -55,10 +51,25 @@ func (AddInstructionDefinition) InferTargetTypes(
return []*gen.TypeInfo{arguments[0]}, core.ResultList{}
}

type InstructionMap map[string]gen.InstructionDefinition[Instruction]

func (m *InstructionMap) GetInstructionDefinition(
name string,
) (gen.InstructionDefinition[Instruction], core.ResultList) {
instDef, ok := (*m)[name]
if !ok {
return nil, list.FromSingle(core.Result{{
Type: core.ErrorResult,
Message: "undefined instruction",
}})
}
return instDef, core.ResultList{}
}

func TestInstructionCreateTarget(t *testing.T) {
isa := gen.NewInstructionSet([]gen.InstructionDefinition[Instruction]{
&AddInstructionDefinition{},
})
instructions := InstructionMap{
"ADD": &AddInstructionDefinition{},
}

src := core.NewSourceView("%c = ADD %a %b")
tkns, err := lex.NewTokenizer().Tokenize(src)
Expand All @@ -82,9 +93,11 @@ func TestInstructionCreateTarget(t *testing.T) {
SourceContext: src.Ctx(),
Types: &types,
Registers: &registers,
Instructions: &instructions,
}

_, results := isa.Build(ctx, node)
generator := gen.InstructionGenerator[Instruction]{}
_, results := generator.Generate(ctx, node)
assert.True(t, results.IsEmpty())

target := registers.GetRegister("%c")
Expand Down

0 comments on commit 7c99df3

Please sign in to comment.