func Compile(objectConfig *Config, r compile.Reader, lib compile.Library) (object *Object, err error) {
	if objectConfig == nil {
		objectConfig = new(Config)
	}
	object = new(Object)
	var debugData section.CustomSections
	var customLoaders = map[string]section.CustomContentLoader{
		section.CustomName: object.Names.Load,
		".debug_abbrev":    debugData.Load,
		".debug_info":      debugData.Load,
		".debug_line":      debugData.Load,
		".debug_pubnames":  debugData.Load,
		".debug_ranges":    debugData.Load,
		".debug_str":       debugData.Load,
	}
	var loadingConfig = compile.Config{
		CustomSectionLoader: section.CustomLoader(customLoaders),
	}
	var moduleConfig = &compile.ModuleConfig{
		Config: loadingConfig,
	}
	module, err := compile.LoadInitialSections(moduleConfig, r)
	object.FuncTypes = module.FuncTypes()
	object.InitialMemorySize = module.InitialMemorySize()
	object.MemorySizeLimit = module.MemorySizeLimit()
	if err != nil {
		return
	}
	if objectConfig.ImportResolver == nil {
		objectConfig.ImportResolver = resolver{lib}
	}
	err = binding.BindImports(&module, objectConfig.ImportResolver)
	if err != nil {
		return
	}
	var codeConfig = &compile.CodeConfig{
		Text:   objectConfig.Text,
		Mapper: &object.InsnMap,
		Config: loadingConfig,
	}
	err = compile.LoadCodeSection(codeConfig, r, module, lib)
	objectConfig.Text = codeConfig.Text
	object.Text = codeConfig.Text.Bytes()
	if err != nil {
		return
	}
	var dataConfig = &compile.DataConfig{
		GlobalsMemory:   objectConfig.GlobalsMemory,
		MemoryAlignment: objectConfig.MemoryAlignment,
		Config:          loadingConfig,
	}
	err = compile.LoadDataSection(dataConfig, r, module)
	objectConfig.GlobalsMemory = dataConfig.GlobalsMemory
	objectConfig.MemoryAlignment = dataConfig.MemoryAlignment
	object.MemoryOffset = alignSize(module.GlobalsSize(), dataConfig.MemoryAlignment)
	object.GlobalsMemory = dataConfig.GlobalsMemory.Bytes()
	if err != nil {
		return
	}
	var startAddr uint32
	if startIndex, defined := module.StartFunc(); defined {
		startAddr = object.FuncAddrs[startIndex]
	}
	var (
		entryIndex uint32
		entryAddr  uint32
	)
	if objectConfig.Entry != "" {
		entryIndex, err = binding.EntryFunc(module, objectConfig.Entry)
		if err != nil {
			return
		}
		entryAddr = object.FuncAddrs[entryIndex]
	}
	object.StackFrame = stack.InitFrame(startAddr, entryAddr)
	err = compile.LoadCustomSections(&loadingConfig, r)
	if err != nil {
		return
	}
	if info := debugData.Sections[".debug_info"]; info != nil {
		var (
			abbrev   = debugData.Sections[".debug_abbrev"]
			line     = debugData.Sections[".debug_line"]
			pubnames = debugData.Sections[".debug_pubnames"]
			ranges   = debugData.Sections[".debug_ranges"]
			str      = debugData.Sections[".debug_str"]
		)
		object.Debug, err = dwarf.New(abbrev, nil, nil, info, line, pubnames, ranges, str)
		if err != nil {
			return
		}
	}
	return
}
Compile a WebAssembly binary module into machine code.  The Object is
constructed incrementally so that populated fields may be inspected on
error.

See the source code for examples of how to use the lower-level APIs.
package wag
import (
	"debug/dwarf"
	"fmt"
	"gate.computer/wag/binding"
	"gate.computer/wag/compile"
	"gate.computer/wag/object/debug"
	"gate.computer/wag/object/stack"
	"gate.computer/wag/section"
	"gate.computer/wag/wa"
)
func CompileLibrary(r compile.Reader, imports binding.LibraryImportResolver) (lib compile.Library, err error) {
	mod, err := compile.LoadInitialSections(nil, r)
	if err != nil {
		return
	}
	lib, err = mod.AsLibrary()
	if err != nil {
		return
	}
	err = binding.BindLibraryImports(&lib, imports)
	if err != nil {
		return
	}
	err = lib.LoadSections(r)
	if err != nil {
		return
	}
	return
}
type Config struct {
	ImportResolver  binding.ImportResolver  
	Text            compile.CodeBuffer      
	GlobalsMemory   compile.DataBuffer      
	MemoryAlignment int                     
	Entry           string                  
}
type Object struct {
	FuncTypes         []wa.FuncType        
	InitialMemorySize int                  
	MemorySizeLimit   int                  
	Text              []byte               
	debug.InsnMap                          
	MemoryOffset      int                  
	GlobalsMemory     []byte               
	StackFrame        []byte               
	Names             section.NameSection  
	Debug             *dwarf.Data          
}