Added file scanner

This commit is contained in:
2023-10-30 16:17:41 +01:00
parent 5fe83543fd
commit 8b19989372
10 changed files with 178 additions and 71 deletions

View File

@ -12,20 +12,17 @@ import (
// Assembler contains a list of instructions.
type Assembler struct {
Instructions []Instruction
// labels map[string]Index
Verbose bool
}
// New creates a new assembler.
func New() *Assembler {
return &Assembler{
Instructions: make([]Instruction, 0, 8),
// labels: map[string]Index{},
}
}
// Finalize generates the final machine code.
func (a *Assembler) Finalize() ([]byte, []byte) {
func (a *Assembler) Finalize(verbose bool) ([]byte, []byte) {
code := make([]byte, 0, len(a.Instructions)*8)
data := make(Data, 0, 16)
pointers := []Pointer{}
@ -46,8 +43,10 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
case SYSCALL:
code = x64.Syscall(code)
}
}
if a.Verbose {
if verbose {
for _, x := range a.Instructions {
log.Info.Println(x.String())
}
}
@ -63,11 +62,6 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
return code, data
}
// AddLabel creates a new label at the current position.
// func (a *Assembler) AddLabel(name string) {
// a.labels[name] = Index(len(a.instructions))
// }
// MoveRegisterData moves a data section address into the given register.
func (a *Assembler) MoveRegisterData(reg register.ID, data []byte) {
a.Instructions = append(a.Instructions, Instruction{