All Projects → mmcloughlin → Avo

mmcloughlin / Avo

Licence: bsd-3-clause
Generate x86 Assembly with Go

Programming Languages

go
31211 projects - #10 most used programming language
assembly
5116 projects

Projects that are alternatives of or similar to Avo

Prisma Docs Generator
Prisma generator for automatically generating documentation reference from the Prisma schema.
Stars: ✭ 91 (-95.11%)
Mutual labels:  code-generation
Erika3
ERIKA Enterprise v3 RTOS
Stars: ✭ 98 (-94.74%)
Mutual labels:  x86-64
Cgen
C/C++ source generation from an AST
Stars: ✭ 107 (-94.25%)
Mutual labels:  code-generation
Pyast64
Compile a subset of the Python AST to x64-64 assembler
Stars: ✭ 93 (-95.01%)
Mutual labels:  x86-64
Geco
Simple code generator based on a console project, running on .Net core and using C# interpolated strings
Stars: ✭ 97 (-94.79%)
Mutual labels:  code-generation
Monkos
an experimental 64-bit operating system
Stars: ✭ 100 (-94.63%)
Mutual labels:  x86-64
Evoasm.rb
An AIMGP (Automatic Induction of Machine code by Genetic Programming) engine
Stars: ✭ 91 (-95.11%)
Mutual labels:  x86-64
Snakeware
A free Linux distro with a Python-based userspace
Stars: ✭ 1,514 (-18.69%)
Mutual labels:  x86-64
Predicateflow
Write amazing, strong-typed and easy-to-read NSPredicate.
Stars: ✭ 98 (-94.74%)
Mutual labels:  code-generation
X86 64 Semantics
Semantics of x86-64 in K
Stars: ✭ 108 (-94.2%)
Mutual labels:  x86-64
Laravel Create
Create Laravel projects really fast
Stars: ✭ 1,331 (-28.52%)
Mutual labels:  code-generation
Nextcloudpi
📦 Build code for NextcloudPi: Raspberry Pi, Odroid, Rock64, Docker, curl installer...
Stars: ✭ 1,340 (-28.03%)
Mutual labels:  x86-64
Fcc
Fedjmike's C Compiler
Stars: ✭ 101 (-94.58%)
Mutual labels:  code-generation
Goreuse
Generic Code for Go
Stars: ✭ 93 (-95.01%)
Mutual labels:  code-generation
Shellcode encoder
x64 printable shellcode encoder
Stars: ✭ 109 (-94.15%)
Mutual labels:  x86-64
Ktf
Kernel Test Framework
Stars: ✭ 93 (-95.01%)
Mutual labels:  x86-64
Dingo
Data access in Go - Code Generator
Stars: ✭ 100 (-94.63%)
Mutual labels:  code-generation
Goreadme
Generate readme file from Go doc. Now available with Github actions!
Stars: ✭ 113 (-93.93%)
Mutual labels:  code-generation
Keystone
Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings
Stars: ✭ 1,654 (-11.17%)
Mutual labels:  x86-64
X64dbg
An open-source x64/x32 debugger for windows.
Stars: ✭ 37,825 (+1931.42%)
Mutual labels:  x86-64

avo
Build Status go.dev Go Report Card

Generate x86 Assembly with Go

avo makes high-performance Go assembly easier to write, review and maintain. The avo package presents a familiar assembly-like interface that simplifies development without sacrificing performance:

  • Use Go control structures for assembly generation; avo programs are Go programs
  • Register allocation: write functions with virtual registers and avo assigns physical registers for you
  • Automatically load arguments and store return values: ensure memory offsets are correct for complex structures
  • Generation of stub files to interface with your Go package

For more about avo:

Note: APIs subject to change while avo is still in an experimental phase. You can use it to build real things but we suggest you pin a version with your package manager of choice.

Quick Start

Install avo with go get:

$ go get -u github.com/mmcloughlin/avo

avo assembly generators are pure Go programs. Here's a function that adds two uint64 values:

//go:build ignore
// +build ignore

package main

import . "github.com/mmcloughlin/avo/build"

func main() {
	TEXT("Add", NOSPLIT, "func(x, y uint64) uint64")
	Doc("Add adds x and y.")
	x := Load(Param("x"), GP64())
	y := Load(Param("y"), GP64())
	ADDQ(x, y)
	Store(y, ReturnIndex(0))
	RET()
	Generate()
}

go run this code to see the assembly output. To integrate this into the rest of your Go package we recommend a go:generate line to produce the assembly and the corresponding Go stub file.

//go:generate go run asm.go -out add.s -stubs stub.go

After running go generate the add.s file will contain the Go assembly.

// Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), NOSPLIT, $0-24
	MOVQ x+0(FP), AX
	MOVQ y+8(FP), CX
	ADDQ AX, CX
	MOVQ CX, ret+16(FP)
	RET

The same call will produce the stub file stub.go which will enable the function to be called from your Go code.

// Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT.

package add

// Add adds x and y.
func Add(x uint64, y uint64) uint64

See the examples/add directory for the complete working example.

Examples

See examples for the full suite of examples.

Slice Sum

Sum a slice of uint64s:

func main() {
	TEXT("Sum", NOSPLIT, "func(xs []uint64) uint64")
	Doc("Sum returns the sum of the elements in xs.")
	ptr := Load(Param("xs").Base(), GP64())
	n := Load(Param("xs").Len(), GP64())

	Comment("Initialize sum register to zero.")
	s := GP64()
	XORQ(s, s)

	Label("loop")
	Comment("Loop until zero bytes remain.")
	CMPQ(n, Imm(0))
	JE(LabelRef("done"))

	Comment("Load from pointer and add to running sum.")
	ADDQ(Mem{Base: ptr}, s)

	Comment("Advance pointer, decrement byte count.")
	ADDQ(Imm(8), ptr)
	DECQ(n)
	JMP(LabelRef("loop"))

	Label("done")
	Comment("Store sum to return value.")
	Store(s, ReturnIndex(0))
	RET()
	Generate()
}

The result from this code generator is:

// Code generated by command: go run asm.go -out sum.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Sum(xs []uint64) uint64
TEXT ·Sum(SB), NOSPLIT, $0-32
	MOVQ xs_base+0(FP), AX
	MOVQ xs_len+8(FP), CX

	// Initialize sum register to zero.
	XORQ DX, DX

loop:
	// Loop until zero bytes remain.
	CMPQ CX, $0x00
	JE   done

	// Load from pointer and add to running sum.
	ADDQ (AX), DX

	// Advance pointer, decrement byte count.
	ADDQ $0x08, AX
	DECQ CX
	JMP  loop

done:
	// Store sum to return value.
	MOVQ DX, ret+24(FP)
	RET

Full example at examples/sum.

Features

For demonstrations of avo features:

  • args: Loading function arguments.
  • returns: Building return values.
  • complex: Working with complex{64,128} types.
  • data: Defining DATA sections.
  • ext: Interacting with types from external packages.
  • pragma: Apply compiler directives to generated functions.

Real Examples

Implementations of full algorithms:

Contributing

Contributions to avo are welcome:

Credits

Inspired by the PeachPy and asmjit projects. Thanks to Damian Gryski for advice, and his extensive library of PeachPy Go projects.

License

avo is available under the BSD 3-Clause License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].