예제 #1
0
파일: write.go 프로젝트: 272489711/e8vm
func writeFunc(p *Pkg, f *Func) {
	lfunc := link8.NewFunc()

	for b := f.prologue; b != nil; b = b.next {
		writeBlock(lfunc, b)
	}

	p.lib.DefineFunc(f.name, lfunc)
}
예제 #2
0
// makeFuncObj converts a function AST node f into a function object. It
// resolves the symbols of fillLink, fillHigh and fillLow into <pack, sym>
// index pairs, using the symbol scope and the curPkg context in the
// Builder b.
func makeFuncObj(b *builder, f *funcDecl) *link8.Func {
	ret := link8.NewFunc()
	for _, s := range f.stmts {
		if s.isLabel() {
			continue // skip labels
		}
		ret.AddInst(s.inst.inst)

		if !(s.fill > fillNone && s.fill < fillLabel) {
			continue // only care about fillHigh, fillLow and fillLink
		}

		linkSymbol(b, s, ret)
	}

	if ret.TooLarge() {
		b.Errorf(f.Name.Pos, "too many instructions in func", f.Name.Lit)
	}

	return ret
}