本文整理匯總了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)
}
}
}
示例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
}
示例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)
}
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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")
}
}
示例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
}