Documentation ¶
Overview ¶
Package instructions provides functions for decoding and disassembling Human Resource machine instructions stored in a profile
Index ¶
- Constants
- Variables
- func NextLabel(label string) string
- type Comment
- type CommentLine
- type CommentPoint
- type Comments
- type DisassembleArgInstruction
- type DisassembleComment
- type DisassembleInstruction
- type DisassembleInterface
- type DisassembleJumpInstruction
- type DisassembleJumpTarget
- type Disassembled
- type Instruction
- type Instructions
- type Labels
- type OpCode
- type RawComment
- type RawComments
Constants ¶
const ( OP_INBOX = 0x0 OP_OUTBOX = 0x1 OP_COPY_FROM = 0x2 OP_COPY_TO = 0x3 OP_ADD = 0x4 OP_SUB = 0x5 OP_BUMP_MINUS = 0x6 OP_BUMP_PLUS = 0x7 OP_JUMP = 0x8 OP_JUMP_ZERO = 0x9 OP_JUMP_NEG = 0xA OP_JUMP_TGT = 0xD MODE_DIRECT = 0x1 MODE_INDIRECT = 0x2 )
Variables ¶
var InstructionsWithArg = instructionsWithArg{
OP_COPY_FROM: {},
OP_COPY_TO: {},
OP_ADD: {},
OP_SUB: {},
OP_BUMP_MINUS: {},
OP_BUMP_PLUS: {},
}
A map containing opcodes that take an argument
var InstructionsWithLabel = instructionsWithLabel{
OP_JUMP: {},
OP_JUMP_ZERO: {},
OP_JUMP_NEG: {},
}
A map containing opcodes that have a target label
var InstrunctionMnemonics = instrunctionMnemonics{
OP_INBOX: "INBOX",
OP_OUTBOX: "OUTBOX",
OP_COPY_FROM: "COPYFROM",
OP_COPY_TO: "COPYTO",
OP_ADD: "ADD",
OP_SUB: "SUB",
OP_BUMP_MINUS: "BUMPDN",
OP_BUMP_PLUS: "BUMPUP",
OP_JUMP: "JUMP",
OP_JUMP_ZERO: "JUMPZ",
OP_JUMP_NEG: "JUMPN",
}
A map of mnemonics
Functions ¶
Types ¶
type CommentLine ¶
type CommentLine []CommentPoint
A single unbroken graphical line, however a CommentLine of length one represents a dot
type CommentPoint ¶
A point in a comment, represented by an X and Y coordinate decoded from the RawComment
type Comments ¶
type Comments []Comment
A sequence of comments
func DecodeComments ¶
func DecodeComments(rawComments RawComments) (Comments, error)
Decode a sequence of RawComments into Comments. Comments are useful when, for example, rendering the comments
type DisassembleArgInstruction ¶
type DisassembleArgInstruction struct { DisassembleInstruction Arg uint32 Indirect bool }
An instruction taking one argument (implements DisassembleInterface)
type DisassembleComment ¶
type DisassembleComment struct {
Index uint32
}
A comment (implements DisassembleInterface)
type DisassembleInstruction ¶
An instruction taking no arguments (implements DisassembleInterface)
type DisassembleInterface ¶
type DisassembleInterface interface {
// contains filtered or unexported methods
}
An interface for different kinds of disassembled instructions.
type DisassembleJumpInstruction ¶
type DisassembleJumpInstruction struct { DisassembleInstruction TargetLabel string Target int }
An jump instruction (implements DisassembleInterface)
type DisassembleJumpTarget ¶
A jump target (implements DisassembleInterface)
type Disassembled ¶
type Disassembled []DisassembleInterface
A list of disassembled instructions
func Disassemble ¶
func Disassemble(instructions Instructions) Disassembled
Given a sequence of instructions, return the disassembled instructions
type Instruction ¶
A decoded binary instruction
type Instructions ¶
type Instructions []Instruction
A list of binary instructions
func DecodeInstructions ¶
func DecodeInstructions(reader io.Reader) (Instructions, error)
Decode and return a sequence of instructions read from the passed in reader. The reader must be correctly positioned so that the first word read contains the instruction count
type Labels ¶
A map of instruction indices to label names
func MakeLabels ¶
func MakeLabels(instructions Instructions) Labels
Given a list of instructions, return a map containing the symbolic label names for all jump targets
type RawComments ¶
type RawComments []RawComment
A sequence of raw comments
func DecodeRawComments ¶
func DecodeRawComments(reader io.ReadSeeker) (RawComments, error)
Decode binary comments found in reader into "raw" comments. RawComments are useful when rendering the comments back to a textual Human Resource Machine program representation. The reader must be correctly positioned so that the first word read contains the comment count