assembler

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package egg/assembler implements a set of usefull functions and structs for creating assemblers.

Index

Constants

View Source
const (
	TOKEN_LABEL = iota
	TOKEN_INSTRUCTION
	TOKEN_ARG
	TOKEN_LITERAL
)

Variables

This section is empty.

Functions

func ParseLiteral

func ParseLiteral(lit string) string

Parses everything cleanly excepts that any % followed by a two-digit hex number (e.g., %FA) in substituted by it's own value. Use %% for a literal %.

Types

type ArgTranslateFunction

type ArgTranslateFunction func(string) (uint64, error)

Function to pass to ResolveTokensFixedSize.

type DebuggerToken

type DebuggerToken struct {
	Instruction string
	Args        string
	Address     uint64
	Label       string
}

Token only for instructions. An array of DebuggerToken is passed to the debugger.

func CreateDebugTokensFixedSize

func CreateDebugTokensFixedSize(tokens []Token, size uint64) []DebuggerToken

Creates an array of DebuggerToken when instructions have always a fixed size.

type ResolvedToken

type ResolvedToken struct {
	Type  uint8
	Size  uint64
	Value string
	Args  []uint64
}

Token with resolved labels and arguments (only instructions have arguments). Can only be instruction or literal.

func ResolveTokensFixedSize

func ResolveTokensFixedSize(tokens []Token, size uint64, arg ArgTranslateFunction) ([]ResolvedToken, error)

Resolves labels and arguments for fixed-size instructions with size bytes. ArgTranslateFunction translates arguments into numbers. The arguments are translating first resolving the labels, and them, if the argument is not a label, calling ArgTranslateFunction with it. Labels are always changed by their address, so the architeture-side should change it to an offset when needed.

type Token

type Token struct {
	Type  uint8
	Value string
}

Can be label, instruction, arg or literal.

func Tokenize

func Tokenize(asm string) []Token

Tokenize uses a very standard Assembly syntax to create a token array: - Define labels with : - Arguments are separated by , - Comments start with ; and go to the end of the line - Literals must be placed in lines beggining with # and are parsed by ParseLiteral

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL