當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Module.Functions方法代碼示例

本文整理匯總了Golang中github.com/MovingtoMars/nnvm/ssa.Module.Functions方法的典型用法代碼示例。如果您正苦於以下問題:Golang Module.Functions方法的具體用法?Golang Module.Functions怎麽用?Golang Module.Functions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/MovingtoMars/nnvm/ssa.Module的用法示例。


在下文中一共展示了Module.Functions方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: VisitBlocks

func VisitBlocks(mod *ssa.Module, visitFn func(*ssa.Block)) {
	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			visitFn(block)
		}
	}
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:7,代碼來源:validate.go

示例2: checkBranchToEntry

func checkBranchToEntry(mod *ssa.Module) error {
	makeError := func(i ssa.Instruction) error {
		return &InstrError{
			Instr:   i,
			Message: fmt.Sprintf("Branch to entry block `%%%s`", i.Block().Name()),
		}
	}

	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			lastInstr := block.LastInstr()

			switch i := lastInstr.(type) {
			case *ssa.Br:
				if block := ssa.GetOperands(i)[0].(*ssa.Block); block.IsEntry() {
					return makeError(i)
				}

			case *ssa.CondBr:
				for _, op := range ssa.GetOperands(i)[1:3] {
					if op.(*ssa.Block).IsEntry() {
						return makeError(i)
					}
				}

			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:31,代碼來源:branchtoentry.go

示例3: VisitInstrs

func VisitInstrs(mod *ssa.Module, visitFn func(ssa.Instruction)) {
	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			for _, instr := range block.Instrs() {
				visitFn(instr)
			}
		}
	}
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:9,代碼來源:validate.go

示例4: checkEmptyBlock

func checkEmptyBlock(mod *ssa.Module) error {
	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			if len(block.Instrs()) == 0 {
				return &BlockError{
					Block:   block,
					Message: "Empty block",
				}
			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:14,代碼來源:emptyblock.go

示例5: checkBlockDoesNotTerminate

func checkBlockDoesNotTerminate(mod *ssa.Module) error {
	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			lastInstr := block.LastInstr()
			if lastInstr == nil || !lastInstr.IsTerminating() {
				return &BlockError{
					Block:   block,
					Message: "Non-terminating block",
				}
			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:15,代碼來源:blockdoesnotterminate.go

示例6: checkIllegalTerminate

func checkIllegalTerminate(mod *ssa.Module) error {
	for _, fn := range mod.Functions() {
		for _, block := range fn.Blocks() {
			instrs := block.Instrs()
			for _, instr := range instrs[:len(instrs)-1] {
				if instr.IsTerminating() {
					return &InstrError{
						Instr:   instr,
						Message: "Terminating instruction in middle of block",
					}
				}
			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:17,代碼來源:illegalterminate.go

示例7: checkEntryPhi

func checkEntryPhi(mod *ssa.Module) error {
	for _, fn := range mod.Functions() {
		if !fn.IsPrototype() {
			for _, instr := range fn.EntryBlock().Instrs() {
				_, ok := instr.(*ssa.Phi)
				if ok {
					return InstrError{
						Instr:   instr,
						Message: "Phi node in entry block",
					}
				}
			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:17,代碼來源:entryphi.go

示例8: checkInstrs

func checkInstrs(mod *ssa.Module) error {
	for _, fn := range mod.Functions() {
		var blockDomTree *analysis.DominatorTree
		if !fn.IsPrototype() {
			blockDomTree = analysis.NewBlockDominatorTree(analysis.NewBlockCFG(fn))
		}

		for _, block := range fn.Blocks() {
			for _, instr := range block.Instrs() {
				if err := checkInstr(instr, blockDomTree); err != nil {
					return err
				}
			}
		}
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:18,代碼來源:instr.go

示例9: PrintValues

func PrintValues(mod *ssa.Module, out io.Writer) {
	printf := func(val string, stuff ...interface{}) {
		fmt.Fprintf(out, val, stuff...)
	}

	printf("Values in module `%s`\n", mod.Name())
	printf("\n")

	printf("Globals:\n")
	for _, glob := range mod.Globals() {
		printf("  %s (references: %d)\n", ssa.ValueString(glob), len(glob.References()))
	}
	printf("\n")

	printf("Functions:\n")
	for _, fn := range mod.Functions() {
		printf("  %s (references: %d)\n", ssa.ValueString(fn), len(fn.References()))
		if fn.IsPrototype() {
			printf("\n")
			continue
		}

		printf("    Parameters:\n")

		for _, par := range fn.Parameters() {
			printf("      %s (references: %d)\n", ssa.ValueString(par), len(par.References()))
		}

		printf("    Instruction values:\n")

		for _, block := range fn.Blocks() {
			for _, instr := range block.Instrs() {
				if val, ok := instr.(ssa.Value); ok {
					printf("      %s (references: %d)\n", ssa.ValueString(val), len(val.References()))
				}
			}
		}

		printf("\n")
	}
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:41,代碼來源:printvalues.go

示例10: checkFunctionNames

func checkFunctionNames(mod *ssa.Module) error {
	seenNames := make(map[string]bool, len(mod.Functions()))

	for _, fn := range mod.Functions() {
		if fn.Name() == "" {
			return &FunctionError{
				Function: fn,
				Message:  "Empty function name",
			}
		}

		if seenNames[fn.Name()] {
			return &FunctionError{
				Function: fn,
				Message:  "Duplicate function name `" + fn.Name() + "`",
			}
		}

		seenNames[fn.Name()] = true
	}

	return nil
}
開發者ID:MovingtoMars,項目名稱:nnvm,代碼行數:23,代碼來源:functionname.go


注:本文中的github.com/MovingtoMars/nnvm/ssa.Module.Functions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。