Ejemplo n.º 1
0
func visitMakeChan(instr *ssa.MakeChan, infer *TypeInfer, ctx *Context) {
	newch := &Value{instr, ctx.F.InstanceID(), ctx.L.Index}
	ctx.F.locals[instr] = newch
	chType, ok := instr.Type().(*types.Chan)
	if !ok {
		infer.Logger.Fatal(ErrMakeChanNonChan)
	}
	bufSz, ok := instr.Size.(*ssa.Const)
	if !ok {
		infer.Logger.Fatal(ErrNonConstChanBuf)
	}
	infer.Logger.Printf(ctx.F.Sprintf(ChanSymbol+"%s = %s {t:%s, buf:%d} @ %s",
		newch,
		fmtChan("chan"),
		chType.Elem(),
		bufSz.Int64(),
		fmtPos(infer.SSA.FSet.Position(instr.Pos()).String())))
	ctx.F.FuncDef.AddStmts(&migo.NewChanStatement{Name: instr, Chan: newch.String(), Size: bufSz.Int64()})
	// Make sure it is not a duplicated extraargs
	var found bool
	for _, ea := range ctx.F.extraargs {
		if phi, ok := ea.(*ssa.Phi); ok {
			if instr.Block().Index < len(phi.Edges) {
				if phi.Edges[instr.Block().Index].Name() == instr.Name() {
					found = true
				}
			}
		}
	}
	if !found {
		ctx.F.extraargs = append(ctx.F.extraargs, instr)
	}
}
Ejemplo n.º 2
0
func visitMakeChan(inst *ssa.MakeChan, caller *frame) {
	locn := loc(caller, inst.Pos())
	role := caller.gortn.role

	vd := utils.NewDef(inst) // Unique identifier for inst
	ch := caller.env.session.MakeChan(vd, role)

	caller.env.chans[vd] = &ch
	caller.gortn.AddNode(sesstype.NewNewChanNode(ch))
	caller.locals[inst] = vd
	fmt.Fprintf(os.Stderr, "   New channel %s { type: %s } by %s at %s\n", green(ch.Name()), ch.Type(), vd.String(), locn)
	fmt.Fprintf(os.Stderr, "               ^ in role %s\n", role.Name())
}