Refactored code structure
This commit is contained in:
parent
9e52e2dd1c
commit
fd6e874b44
54 changed files with 583 additions and 450 deletions
|
@ -63,6 +63,9 @@ func (a Assembler) Finalize() ([]byte, []byte) {
|
|||
},
|
||||
})
|
||||
|
||||
case COMMENT:
|
||||
continue
|
||||
|
||||
case JUMP:
|
||||
code = x64.Jump8(code, 0x00)
|
||||
size := 1
|
||||
|
|
|
@ -44,6 +44,16 @@ func (a *Assembler) Label(name string) {
|
|||
})
|
||||
}
|
||||
|
||||
// Comment adds a comment at the current position.
|
||||
func (a *Assembler) Comment(text string) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
Mnemonic: COMMENT,
|
||||
Data: &Label{
|
||||
Name: text,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Call calls a function whose position is identified by a label.
|
||||
func (a *Assembler) Call(name string) {
|
||||
a.Instructions = append(a.Instructions, Instruction{
|
||||
|
|
|
@ -6,6 +6,7 @@ const (
|
|||
NONE Mnemonic = iota
|
||||
ADD
|
||||
CALL
|
||||
COMMENT
|
||||
DIV
|
||||
JUMP
|
||||
MUL
|
||||
|
@ -23,40 +24,31 @@ func (m Mnemonic) String() string {
|
|||
switch m {
|
||||
case ADD:
|
||||
return "add"
|
||||
|
||||
case CALL:
|
||||
return "call"
|
||||
|
||||
case COMMENT:
|
||||
return "comment"
|
||||
case DIV:
|
||||
return "div"
|
||||
|
||||
case JUMP:
|
||||
return "jump"
|
||||
|
||||
case LABEL:
|
||||
return "label"
|
||||
|
||||
case MOVE:
|
||||
return "move"
|
||||
|
||||
case MUL:
|
||||
return "mul"
|
||||
|
||||
case POP:
|
||||
return "pop"
|
||||
|
||||
case PUSH:
|
||||
return "push"
|
||||
|
||||
case RETURN:
|
||||
return "return"
|
||||
|
||||
case SUB:
|
||||
return "sub"
|
||||
|
||||
case SYSCALL:
|
||||
return "syscall"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
return "NONE"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue