Added label type
This commit is contained in:
@ -2,12 +2,12 @@ package asm
|
||||
|
||||
// Comment adds a comment at the current position.
|
||||
func (a *Assembler) Comment(text string) {
|
||||
a.Label(COMMENT, text)
|
||||
a.Label(COMMENT, Label{Name: text, Type: CommentLabel})
|
||||
}
|
||||
|
||||
// DLLCall calls a function in a DLL file.
|
||||
func (a *Assembler) DLLCall(name string) {
|
||||
a.Label(DLLCALL, name)
|
||||
a.Label(DLLCALL, Label{Name: name, Type: ExternLabel})
|
||||
}
|
||||
|
||||
// Return returns back to the caller.
|
||||
|
@ -3,6 +3,7 @@ package asm
|
||||
// Label represents a jump label.
|
||||
type Label struct {
|
||||
Name string
|
||||
Type LabelType
|
||||
}
|
||||
|
||||
// String returns a human readable version.
|
||||
@ -11,14 +12,12 @@ func (data *Label) String() string {
|
||||
}
|
||||
|
||||
// Label adds an instruction using a label.
|
||||
func (a *Assembler) Label(mnemonic Mnemonic, name string) {
|
||||
func (a *Assembler) Label(mnemonic Mnemonic, label Label) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: mnemonic,
|
||||
Type: TypeLabel,
|
||||
Index: Index(len(a.Param.Label)),
|
||||
})
|
||||
|
||||
a.Param.Label = append(a.Param.Label, Label{
|
||||
Name: name,
|
||||
})
|
||||
a.Param.Label = append(a.Param.Label, label)
|
||||
}
|
||||
|
13
src/asm/LabelType.go
Normal file
13
src/asm/LabelType.go
Normal file
@ -0,0 +1,13 @@
|
||||
package asm
|
||||
|
||||
// LabelType shows what the label was used for.
|
||||
type LabelType uint8
|
||||
|
||||
const (
|
||||
UnknownLabel LabelType = iota
|
||||
CommentLabel
|
||||
ControlLabel
|
||||
DataLabel
|
||||
FunctionLabel
|
||||
ExternLabel
|
||||
)
|
@ -2,17 +2,17 @@ package asm
|
||||
|
||||
// MemoryLabel operates with a memory address and a number.
|
||||
type MemoryLabel struct {
|
||||
Label string
|
||||
Label Label
|
||||
Address Memory
|
||||
}
|
||||
|
||||
// String returns a human readable version.
|
||||
func (data *MemoryLabel) String() string {
|
||||
return data.Address.Format(data.Label)
|
||||
return data.Address.Format(data.Label.Name)
|
||||
}
|
||||
|
||||
// MemoryLabel adds an instruction with a memory address and a label.
|
||||
func (a *Assembler) MemoryLabel(mnemonic Mnemonic, address Memory, label string) {
|
||||
func (a *Assembler) MemoryLabel(mnemonic Mnemonic, address Memory, label Label) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: mnemonic,
|
||||
Type: TypeMemoryLabel,
|
||||
|
@ -8,17 +8,17 @@ import (
|
||||
|
||||
// RegisterLabel operates with a register and a label.
|
||||
type RegisterLabel struct {
|
||||
Label string
|
||||
Label Label
|
||||
Register cpu.Register
|
||||
}
|
||||
|
||||
// String returns a human readable version.
|
||||
func (data *RegisterLabel) String() string {
|
||||
return fmt.Sprintf("%s, %s", data.Register, data.Label)
|
||||
return fmt.Sprintf("%s, %s", data.Register, data.Label.Name)
|
||||
}
|
||||
|
||||
// RegisterLabel adds an instruction with a register and a label.
|
||||
func (a *Assembler) RegisterLabel(mnemonic Mnemonic, register cpu.Register, label string) {
|
||||
func (a *Assembler) RegisterLabel(mnemonic Mnemonic, register cpu.Register, label Label) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: mnemonic,
|
||||
Type: TypeRegisterLabel,
|
||||
|
Reference in New Issue
Block a user