tvm

package
v0.0.0-...-4262487 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2018 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KEY_LENGTH int = 64
	HTAB_SIZE  int = 4096
)
View Source
const (
	NUM_REGISTERS int = 17

	MIN_MEMORY_SIZE int = 64 * 1024 * 1024 /* 64 MB */
)
View Source
const (
	TOK_INCLUDE string = "%include"
	TOK_DEFINE  string = "%define"
)
View Source
const (
	MAX_ARGS int = 2
)

Variables

View Source
var (
	ErrorHtabCtxKeyAlreadyExists error = errors.New("htab: key already exists")
	ErrorHtabCtxKeyNotFound      error = errors.New("htab: key not found")
)
View Source
var (
	ErrorLabelParseLabelDefineTwice error = errors.New("parser: label defined twice")

	ErrorProgParseInstrNotExists error = errors.New("parser: no instruction exists")
)
View Source
var (
	ErrorPreprocessDefineMissArgs       error = errors.New("preprocess: define missing arguments")
	ErrorPreprocessDefineWrongArgs      error = errors.New("preprocess: define wrong arguments")
	ErrorPreprocessDefineMultipleDefine error = errors.New("preprocess: multiple define")
)

Functions

func NewHtabCtx

func NewHtabCtx() *htabCtx

func NewLexerCtx

func NewLexerCtx() *lexerCtx

func ParseValue

func ParseValue(token []byte) int

utils

func ReadFile

func ReadFile(filename string, extension string) ([]byte, error)

utils

Types

type Ctx

type Ctx struct {
	Prog *Prog
	Mem  *Mem
}

func NewCtx

func NewCtx() *Ctx

func (*Ctx) End

func (ctx *Ctx) End() bool

func (*Ctx) Interpret

func (ctx *Ctx) Interpret(filename string) error

func (*Ctx) ParseLabels

func (ctx *Ctx) ParseLabels(lexer *lexerCtx) error

func (*Ctx) ParseProgram

func (ctx *Ctx) ParseProgram(lexer *lexerCtx) error

func (*Ctx) Run

func (ctx *Ctx) Run() error

func (*Ctx) Step

func (ctx *Ctx) Step(instrIdx *int) error

type Line

type Line []byte

type Mem

type Mem struct {
	FLAGS int
	// contains filtered or unexported fields
}

func NewMem

func NewMem(size int) *Mem

func (*Mem) AllRegisterInfos

func (m *Mem) AllRegisterInfos() string

func (*Mem) GetFLAGS

func (m *Mem) GetFLAGS() int

func (*Mem) GetRegisterI32

func (m *Mem) GetRegisterI32(reg Register) *int

func (*Mem) GetRegisterI32Ptr

func (m *Mem) GetRegisterI32Ptr(reg Register) *int

func (*Mem) GetRemainder

func (m *Mem) GetRemainder() int

func (*Mem) SetRegisterI32

func (m *Mem) SetRegisterI32(reg Register, v int)

func (*Mem) SetRegisterI32Ptr

func (m *Mem) SetRegisterI32Ptr(reg Register, v *int)

func (*Mem) StackCreate

func (m *Mem) StackCreate(size int)

Initialize our stack by setting the base pointer and stack pointer

func (*Mem) StackPop

func (m *Mem) StackPop() *int

func (*Mem) StackPush

func (m *Mem) StackPush(item *int)

type Opcode

type Opcode int

tvm opcode map

const (
	NOP Opcode = iota
	INT
	MOV

	PUSH
	POP
	PUSHF
	POPF

	INC
	DEC
	ADD
	SUB
	MUL
	DIV
	MOD
	REM

	NOT
	XOR
	OR
	AND
	SHL
	SHR

	CMP
	JMP
	CALL
	RET

	JE
	JNE
	JG
	JGE
	JL
	JLE

	PRN
)

func (Opcode) String

func (o Opcode) String() string

type Prog

type Prog struct {
	// contains filtered or unexported fields
}

func NewProg

func NewProg() *Prog

func (*Prog) Args

func (prog *Prog) Args(instrIdx int) []*int

func (*Prog) NumInstr

func (prog *Prog) NumInstr() int

func (*Prog) OpCode

func (prog *Prog) OpCode(instrIdx int) Opcode

func (*Prog) Start

func (prog *Prog) Start() int

func (*Prog) Tokens

func (prog *Prog) Tokens(instrIdx int) [][]byte

type Register

type Register int
const (
	EAX Register = iota
	EBX
	ECX
	EDX

	ESI
	EDI
	ESP
	EBP

	EIP

	R08
	R09
	R10
	R11

	R12
	R13
	R14
	R15
)

func (Register) String

func (r Register) String() string

type Token

type Token []byte

Jump to

Keyboard shortcuts

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