Exemplo n.º 1
1
Arquivo: names.go Projeto: tsavola/wag
func (ns *NameSection) Load(_ string, r reader.Reader) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	load := loader.L{r}

	count := load.Varuint32()
	ns.FunctionNames = make([]FunctionName, count)

	for i := range ns.FunctionNames {
		fn := &ns.FunctionNames[i]

		funNameLen := load.Varuint32()
		fn.FunName = string(load.Bytes(funNameLen))

		localCount := load.Varuint32()
		fn.LocalNames = make([]string, localCount)

		for j := range fn.LocalNames {
			localNameLen := load.Varuint32()
			fn.LocalNames[j] = string(load.Bytes(localNameLen))
		}
	}

	return
}
Exemplo n.º 2
1
func (uls UnknownLoaders) Load(r reader.Reader, payloadLen uint32) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	load := loader.L{r}

	nameLen := load.Varuint32()
	if nameLen > maxSectionNameLen {
		panic(errors.New("unknown section name is too long"))
	}

	name := string(load.Bytes(nameLen))

	if f := uls[name]; f != nil {
		if err := f(name, load); err != nil {
			panic(err)
		}
	} else {
		if _, err := io.CopyN(ioutil.Discard, load, int64(payloadLen)); err != nil {
			panic(err)
		}
	}

	return
}
Exemplo n.º 3
0
Arquivo: copy.go Projeto: tsavola/wag
func DiscardUnknownSections(r reader.Reader) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	copySection(ioutil.Discard, r, sectionids.Unknown)
	return
}
Exemplo n.º 4
0
Arquivo: copy.go Projeto: tsavola/wag
// CopyCodeSection if there is one.  Unknown sections preceding the code
// section are silently discarded.  If another known section type is found, it
// is left untouched (the reader will be backed up before the section id).
func CopyCodeSection(w io.Writer, r reader.Reader) (ok bool, err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	ok = copySection(w, r, sectionids.Code)
	return
}
Exemplo n.º 5
0
// LoadDataSection, after loading the preliminary sections.
func (m *Module) LoadDataSection(r reader.Reader) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	m.loadDataSection(r)
	return
}
Exemplo n.º 6
0
// LoadCodeSection, after loading the preliminary sections.
func (m *Module) LoadCodeSection(r reader.Reader, textBuf, roDataBuf []byte, roDataAbsAddr int32, startTrigger chan<- struct{}) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	m.loadCodeSection(r, textBuf, roDataBuf, roDataAbsAddr, startTrigger)
	return
}
Exemplo n.º 7
0
// LoadPreliminarySections, excluding the code and data sections.
func (m *Module) LoadPreliminarySections(r reader.Reader, env Environment) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	m.loadPreliminarySections(r, env)
	return
}