예제 #1
1
파일: names.go 프로젝트: 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
}
예제 #2
1
파일: unknown.go 프로젝트: tsavola/wag
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
}
예제 #3
0
파일: copy.go 프로젝트: tsavola/wag
func DiscardUnknownSections(r reader.Reader) (err error) {
	defer func() {
		err = errutil.ErrorOrPanic(recover())
	}()

	copySection(ioutil.Discard, r, sectionids.Unknown)
	return
}
예제 #4
0
파일: copy.go 프로젝트: 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
}
예제 #5
0
파일: module.go 프로젝트: tsavola/wag
// 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
}
예제 #6
0
파일: module.go 프로젝트: tsavola/wag
// 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
}
예제 #7
0
파일: module.go 프로젝트: tsavola/wag
// 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
}