How to use get method of proggen Package

Best Syzkaller code snippet using proggen.get

reflect.go

Source:reflect.go Github

copy

Full Screen

...245 d.Type = receiver246 in = list(in, d)247 }248 var d *Node249 for t := getinargx(f).Type; t != nil; t = t.Down {250 d = Nod(ODCLFIELD, nil, nil)251 d.Type = t.Type252 d.Isddd = t.Isddd253 in = list(in, d)254 }255 var out *NodeList256 for t := getoutargx(f).Type; t != nil; t = t.Down {257 d = Nod(ODCLFIELD, nil, nil)258 d.Type = t.Type259 out = list(out, d)260 }261 t := functype(nil, in, out)262 if f.Nname != nil {263 // Link to name of original method function.264 t.Nname = f.Nname265 }266 return t267}268/*269 * return methods of non-interface type t, sorted by name.270 * generates stub functions as needed.271 */272func methods(t *Type) *Sig {273 // method type274 mt := methtype(t, 0)275 if mt == nil {276 return nil277 }278 expandmeth(mt)279 // type stored in interface word280 it := t281 if !isdirectiface(it) {282 it = Ptrto(t)283 }284 // make list of methods for t,285 // generating code if necessary.286 var a *Sig287 var this *Type288 var b *Sig289 var method *Sym290 for f := mt.Xmethod; f != nil; f = f.Down {291 if f.Etype != TFIELD {292 Fatal("methods: not field %v", Tconv(f, 0))293 }294 if f.Type.Etype != TFUNC || f.Type.Thistuple == 0 {295 Fatal("non-method on %v method %v %v\n", Tconv(mt, 0), Sconv(f.Sym, 0), Tconv(f, 0))296 }297 if getthisx(f.Type).Type == nil {298 Fatal("receiver with no type on %v method %v %v\n", Tconv(mt, 0), Sconv(f.Sym, 0), Tconv(f, 0))299 }300 if f.Nointerface {301 continue302 }303 method = f.Sym304 if method == nil {305 continue306 }307 // get receiver type for this particular method.308 // if pointer receiver but non-pointer t and309 // this is not an embedded pointer inside a struct,310 // method does not apply.311 this = getthisx(f.Type).Type.Type312 if Isptr[this.Etype] && this.Type == t {313 continue314 }315 if Isptr[this.Etype] && !Isptr[t.Etype] && f.Embedded != 2 && !isifacemethod(f.Type) {316 continue317 }318 b = new(Sig)319 b.link = a320 a = b321 a.name = method.Name322 if !exportname(method.Name) {323 if method.Pkg == nil {324 Fatal("methods: missing package")325 }326 a.pkg = method.Pkg327 }328 a.isym = methodsym(method, it, 1)329 a.tsym = methodsym(method, t, 0)330 a.type_ = methodfunc(f.Type, t)331 a.mtype = methodfunc(f.Type, nil)332 if a.isym.Flags&SymSiggen == 0 {333 a.isym.Flags |= SymSiggen334 if !Eqtype(this, it) || this.Width < Types[Tptr].Width {335 compiling_wrappers = 1336 genwrapper(it, f, a.isym, 1)337 compiling_wrappers = 0338 }339 }340 if a.tsym.Flags&SymSiggen == 0 {341 a.tsym.Flags |= SymSiggen342 if !Eqtype(this, t) {343 compiling_wrappers = 1344 genwrapper(t, f, a.tsym, 0)345 compiling_wrappers = 0346 }347 }348 }349 return lsort(a, sigcmp)350}351/*352 * return methods of interface type t, sorted by name.353 */354func imethods(t *Type) *Sig {355 var a *Sig356 var method *Sym357 var isym *Sym358 var all *Sig359 var last *Sig360 for f := t.Type; f != nil; f = f.Down {361 if f.Etype != TFIELD {362 Fatal("imethods: not field")363 }364 if f.Type.Etype != TFUNC || f.Sym == nil {365 continue366 }367 method = f.Sym368 a = new(Sig)369 a.name = method.Name370 if !exportname(method.Name) {371 if method.Pkg == nil {372 Fatal("imethods: missing package")373 }374 a.pkg = method.Pkg375 }376 a.mtype = f.Type377 a.offset = 0378 a.type_ = methodfunc(f.Type, nil)379 if last != nil && sigcmp(last, a) >= 0 {380 Fatal("sigcmp vs sortinter %s %s", last.name, a.name)381 }382 if last == nil {383 all = a384 } else {385 last.link = a386 }387 last = a388 // Compiler can only refer to wrappers for non-blank methods.389 if isblanksym(method) {390 continue391 }392 // NOTE(rsc): Perhaps an oversight that393 // IfaceType.Method is not in the reflect data.394 // Generate the method body, so that compiled395 // code can refer to it.396 isym = methodsym(method, t, 0)397 if isym.Flags&SymSiggen == 0 {398 isym.Flags |= SymSiggen399 genwrapper(t, f, isym, 0)400 }401 }402 return all403}404var dimportpath_gopkg *Pkg405func dimportpath(p *Pkg) {406 if p.Pathsym != nil {407 return408 }409 if dimportpath_gopkg == nil {410 dimportpath_gopkg = mkpkg("go")411 dimportpath_gopkg.Name = "go"412 }413 nam := "importpath." + p.Prefix + "."414 n := Nod(ONAME, nil, nil)415 n.Sym = Pkglookup(nam, dimportpath_gopkg)416 n.Class = PEXTERN417 n.Xoffset = 0418 p.Pathsym = n.Sym419 gdatastring(n, p.Path)420 ggloblsym(n.Sym, int32(Types[TSTRING].Width), obj.DUPOK|obj.RODATA)421}422func dgopkgpath(s *Sym, ot int, pkg *Pkg) int {423 if pkg == nil {424 return dgostringptr(s, ot, "")425 }426 // Emit reference to go.importpath.""., which 6l will427 // rewrite using the correct import path. Every package428 // that imports this one directly defines the symbol.429 if pkg == localpkg {430 var ns *Sym431 if ns == nil {432 ns = Pkglookup("importpath.\"\".", mkpkg("go"))433 }434 return dsymptr(s, ot, ns, 0)435 }436 dimportpath(pkg)437 return dsymptr(s, ot, pkg.Pathsym, 0)438}439/*440 * uncommonType441 * ../../run_time/type.go:/uncommonType442 */443func dextratype(sym *Sym, off int, t *Type, ptroff int) int {444 m := methods(t)445 if t.Sym == nil && m == nil {446 return off447 }448 // fill in *extraType pointer in header449 off = int(Rnd(int64(off), int64(Widthptr)))450 dsymptr(sym, ptroff, sym, off)451 n := 0452 for a := m; a != nil; a = a.link {453 dtypesym(a.type_)454 n++455 }456 ot := off457 s := sym458 if t.Sym != nil {459 ot = dgostringptr(s, ot, t.Sym.Name)460 if t != Types[t.Etype] && t != errortype {461 ot = dgopkgpath(s, ot, t.Sym.Pkg)462 } else {463 ot = dgostringptr(s, ot, "")464 }465 } else {466 ot = dgostringptr(s, ot, "")467 ot = dgostringptr(s, ot, "")468 }469 // slice header470 ot = dsymptr(s, ot, s, ot+Widthptr+2*Widthint)471 ot = duintxx(s, ot, uint64(n), Widthint)472 ot = duintxx(s, ot, uint64(n), Widthint)473 // methods474 for a := m; a != nil; a = a.link {475 // method476 // ../../run_time/type.go:/method477 ot = dgostringptr(s, ot, a.name)478 ot = dgopkgpath(s, ot, a.pkg)479 ot = dsymptr(s, ot, dtypesym(a.mtype), 0)480 ot = dsymptr(s, ot, dtypesym(a.type_), 0)481 if a.isym != nil {482 ot = dsymptr(s, ot, a.isym, 0)483 } else {484 ot = duintptr(s, ot, 0)485 }486 if a.tsym != nil {487 ot = dsymptr(s, ot, a.tsym, 0)488 } else {489 ot = duintptr(s, ot, 0)490 }491 }492 return ot493}494var kinds = []int{495 TINT: obj.KindInt,496 TUINT: obj.KindUint,497 TINT8: obj.KindInt8,498 TUINT8: obj.KindUint8,499 TINT16: obj.KindInt16,500 TUINT16: obj.KindUint16,501 TINT32: obj.KindInt32,502 TUINT32: obj.KindUint32,503 TINT64: obj.KindInt64,504 TUINT64: obj.KindUint64,505 TUINTPTR: obj.KindUintptr,506 TFLOAT32: obj.KindFloat32,507 TFLOAT64: obj.KindFloat64,508 TBOOL: obj.KindBool,509 TSTRING: obj.KindString,510 TPTR32: obj.KindPtr,511 TPTR64: obj.KindPtr,512 TSTRUCT: obj.KindStruct,513 TINTER: obj.KindInterface,514 TCHAN: obj.KindChan,515 TMAP: obj.KindMap,516 TARRAY: obj.KindArray,517 TFUNC: obj.KindFunc,518 TCOMPLEX64: obj.KindComplex64,519 TCOMPLEX128: obj.KindComplex128,520 TUNSAFEPTR: obj.KindUnsafePointer,521}522func haspointers(t *Type) bool {523 if t.Haspointers != 0 {524 return t.Haspointers-1 != 0525 }526 var ret bool527 switch t.Etype {528 case TINT,529 TUINT,530 TINT8,531 TUINT8,532 TINT16,533 TUINT16,534 TINT32,535 TUINT32,536 TINT64,537 TUINT64,538 TUINTPTR,539 TFLOAT32,540 TFLOAT64,541 TCOMPLEX64,542 TCOMPLEX128,543 TBOOL:544 ret = false545 case TARRAY:546 if t.Bound < 0 { // slice547 ret = true548 break549 }550 if t.Bound == 0 { // empty array551 ret = false552 break553 }554 ret = haspointers(t.Type)555 case TSTRUCT:556 ret = false557 for t1 := t.Type; t1 != nil; t1 = t1.Down {558 if haspointers(t1.Type) {559 ret = true560 break561 }562 }563 case TSTRING,564 TPTR32,565 TPTR64,566 TUNSAFEPTR,567 TINTER,568 TCHAN,569 TMAP,570 TFUNC:571 fallthrough572 default:573 ret = true574 }575 t.Haspointers = 1 + uint8(bool2int(ret))576 return ret577}578/*579 * commonType580 * ../../run_time/type.go:/commonType581 */582var dcommontype_algarray *Sym583func dcommontype(s *Sym, ot int, t *Type) int {584 if ot != 0 {585 Fatal("dcommontype %d", ot)586 }587 sizeofAlg := 2 * Widthptr588 if dcommontype_algarray == nil {589 dcommontype_algarray = Pkglookup("algarray", Runtimepkg)590 }591 dowidth(t)592 alg := algtype(t)593 var algsym *Sym594 if alg < 0 || alg == AMEM {595 algsym = dalgsym(t)596 }597 var sptr *Sym598 if t.Sym != nil && !Isptr[t.Etype] {599 sptr = dtypesym(Ptrto(t))600 } else {601 sptr = weaktypesym(Ptrto(t))602 }603 // All (non-reflect-allocated) Types share the same zero object.604 // Each place in the compiler where a pointer to the zero object605 // might be returned by a run_time call (map access return value,606 // 2-arg type cast) declares the size of the zerovalue it needs.607 // The linker magically takes the max of all the sizes.608 zero := Pkglookup("zerovalue", Runtimepkg)609 // We use size 0 here so we get the pointer to the zero value,610 // but don't allocate space for the zero value unless we need it.611 // TODO: how do we get this symbol into bss? We really want612 // a read-only bss, but I don't think such a thing exists.613 // ../../pkg/reflect/type.go:/^type.commonType614 // actual type structure615 // type commonType struct {616 // size uintptr617 // hash uint32618 // _ uint8619 // align uint8620 // fieldAlign uint8621 // kind uint8622 // alg unsafe.Pointer623 // gc unsafe.Pointer624 // string *string625 // *extraType626 // ptrToThis *Type627 // zero unsafe.Pointer628 // }629 ot = duintptr(s, ot, uint64(t.Width))630 ot = duint32(s, ot, typehash(t))631 ot = duint8(s, ot, 0) // unused632 // run_time (and common sense) expects alignment to be a power of two.633 i := int(t.Align)634 if i == 0 {635 i = 1636 }637 if i&(i-1) != 0 {638 Fatal("invalid alignment %d for %v", t.Align, Tconv(t, 0))639 }640 ot = duint8(s, ot, t.Align) // align641 ot = duint8(s, ot, t.Align) // fieldAlign642 gcprog := usegcprog(t)643 i = kinds[t.Etype]644 if t.Etype == TARRAY && t.Bound < 0 {645 i = obj.KindSlice646 }647 if !haspointers(t) {648 i |= obj.KindNoPointers649 }650 if isdirectiface(t) {651 i |= obj.KindDirectIface652 }653 if gcprog {654 i |= obj.KindGCProg655 }656 ot = duint8(s, ot, uint8(i)) // kind657 if algsym == nil {658 ot = dsymptr(s, ot, dcommontype_algarray, alg*sizeofAlg)659 } else {660 ot = dsymptr(s, ot, algsym, 0)661 }662 // gc663 if gcprog {664 var gcprog1 *Sym665 var gcprog0 *Sym666 gengcprog(t, &gcprog0, &gcprog1)667 if gcprog0 != nil {668 ot = dsymptr(s, ot, gcprog0, 0)669 } else {670 ot = duintptr(s, ot, 0)671 }672 ot = dsymptr(s, ot, gcprog1, 0)673 } else {674 var gcmask [16]uint8675 gengcmask(t, gcmask[:])676 x1 := uint64(0)677 for i := 0; i < 8; i++ {678 x1 = x1<<8 | uint64(gcmask[i])679 }680 var p string681 if Widthptr == 4 {682 p = fmt.Sprintf("gcbits.0x%016x", x1)683 } else {684 x2 := uint64(0)685 for i := 0; i < 8; i++ {686 x2 = x2<<8 | uint64(gcmask[i+8])687 }688 p = fmt.Sprintf("gcbits.0x%016x%016x", x1, x2)689 }690 sbits := Pkglookup(p, Runtimepkg)691 if sbits.Flags&SymUniq == 0 {692 sbits.Flags |= SymUniq693 for i := 0; i < 2*Widthptr; i++ {694 duint8(sbits, i, gcmask[i])695 }696 ggloblsym(sbits, 2*int32(Widthptr), obj.DUPOK|obj.RODATA)697 }698 ot = dsymptr(s, ot, sbits, 0)699 ot = duintptr(s, ot, 0)700 }701 p := Tconv(t, obj.FmtLeft|obj.FmtUnsigned)702 //print("dcommontype: %s\n", p);703 ot = dgostringptr(s, ot, p) // string704 // skip pointer to extraType,705 // which follows the rest of this type structure.706 // caller will fill in if needed.707 // otherwise linker will assume 0.708 ot += Widthptr709 ot = dsymptr(s, ot, sptr, 0) // ptrto type710 ot = dsymptr(s, ot, zero, 0) // ptr to zero value711 return ot712}713func typesym(t *Type) *Sym {714 return Pkglookup(Tconv(t, obj.FmtLeft), typepkg)715}716func tracksym(t *Type) *Sym {717 return Pkglookup(Tconv(t.Outer, obj.FmtLeft)+"."+t.Sym.Name, trackpkg)718}719func typelinksym(t *Type) *Sym {720 // %-uT is what the generated Type's string field says.721 // It uses (ambiguous) package names instead of import paths.722 // %-T is the complete, unambiguous type name.723 // We want the types to end up sorted by string field,724 // so use that first in the name, and then add :%-T to725 // disambiguate. The names are a little long but they are726 // discarded by the linker and do not end up in the symbol727 // table of the final binary.728 p := Tconv(t, obj.FmtLeft|obj.FmtUnsigned) + "/" + Tconv(t, obj.FmtLeft)729 s := Pkglookup(p, typelinkpkg)730 //print("typelinksym: %s -> %+S\n", p, s);731 return s732}733func typesymprefix(prefix string, t *Type) *Sym {734 p := prefix + "." + Tconv(t, obj.FmtLeft)735 s := Pkglookup(p, typepkg)736 //print("algsym: %s -> %+S\n", p, s);737 return s738}739func typenamesym(t *Type) *Sym {740 if t == nil || (Isptr[t.Etype] && t.Type == nil) || isideal(t) {741 Fatal("typename %v", Tconv(t, 0))742 }743 s := typesym(t)744 if s.Def == nil {745 n := Nod(ONAME, nil, nil)746 n.Sym = s747 n.Type = Types[TUINT8]748 n.Addable = 1749 n.Ullman = 1750 n.Class = PEXTERN751 n.Xoffset = 0752 n.Typecheck = 1753 s.Def = n754 signatlist = list(signatlist, typenod(t))755 }756 return s.Def.Sym757}758func typename(t *Type) *Node {759 s := typenamesym(t)760 n := Nod(OADDR, s.Def, nil)761 n.Type = Ptrto(s.Def.Type)762 n.Addable = 1763 n.Ullman = 2764 n.Typecheck = 1765 return n766}767func weaktypesym(t *Type) *Sym {768 p := Tconv(t, obj.FmtLeft)769 s := Pkglookup(p, weaktypepkg)770 //print("weaktypesym: %s -> %+S\n", p, s);771 return s772}773/*774 * Returns 1 if t has a reflexive equality operator.775 * That is, if x==x for all x of type t.776 */777func isreflexive(t *Type) bool {778 switch t.Etype {779 case TBOOL,780 TINT,781 TUINT,782 TINT8,783 TUINT8,784 TINT16,785 TUINT16,786 TINT32,787 TUINT32,788 TINT64,789 TUINT64,790 TUINTPTR,791 TPTR32,792 TPTR64,793 TUNSAFEPTR,794 TSTRING,795 TCHAN:796 return true797 case TFLOAT32,798 TFLOAT64,799 TCOMPLEX64,800 TCOMPLEX128,801 TINTER:802 return false803 case TARRAY:804 if Isslice(t) {805 Fatal("slice can't be a map key: %v", Tconv(t, 0))806 }807 return isreflexive(t.Type)808 case TSTRUCT:809 for t1 := t.Type; t1 != nil; t1 = t1.Down {810 if !isreflexive(t1.Type) {811 return false812 }813 }814 return true815 default:816 Fatal("bad type for map key: %v", Tconv(t, 0))817 return false818 }819}820func dtypesym(t *Type) *Sym {821 // Replace byte, rune aliases with real type.822 // They've been separate internally to make error messages823 // better, but we have to merge them in the reflect tables.824 if t == bytetype || t == runetype {825 t = Types[t.Etype]826 }827 if isideal(t) {828 Fatal("dtypesym %v", Tconv(t, 0))829 }830 s := typesym(t)831 if s.Flags&SymSiggen != 0 {832 return s833 }834 s.Flags |= SymSiggen835 // special case (look for run_time below):836 // when compiling package run_time,837 // emit the type structures for int, float, etc.838 tbase := t839 if Isptr[t.Etype] && t.Sym == nil && t.Type.Sym != nil {840 tbase = t.Type841 }842 dupok := 0843 if tbase.Sym == nil {844 dupok = obj.DUPOK845 }846 if compiling_run_time != 0 && (tbase == Types[tbase.Etype] || tbase == bytetype || tbase == runetype || tbase == errortype) { // int, float, etc847 goto ok848 }849 // named types from other files are defined only by those files850 if tbase.Sym != nil && !tbase.Local {851 return s852 }853 if isforw[tbase.Etype] {854 return s855 }856ok:857 ot := 0858 xt := 0859 switch t.Etype {860 default:861 ot = dcommontype(s, ot, t)862 xt = ot - 3*Widthptr863 case TARRAY:864 if t.Bound >= 0 {865 // ../../run_time/type.go:/ArrayType866 s1 := dtypesym(t.Type)867 t2 := typ(TARRAY)868 t2.Type = t.Type869 t2.Bound = -1 // slice870 s2 := dtypesym(t2)871 ot = dcommontype(s, ot, t)872 xt = ot - 3*Widthptr873 ot = dsymptr(s, ot, s1, 0)874 ot = dsymptr(s, ot, s2, 0)875 ot = duintptr(s, ot, uint64(t.Bound))876 } else {877 // ../../run_time/type.go:/SliceType878 s1 := dtypesym(t.Type)879 ot = dcommontype(s, ot, t)880 xt = ot - 3*Widthptr881 ot = dsymptr(s, ot, s1, 0)882 }883 // ../../run_time/type.go:/ChanType884 case TCHAN:885 s1 := dtypesym(t.Type)886 ot = dcommontype(s, ot, t)887 xt = ot - 3*Widthptr888 ot = dsymptr(s, ot, s1, 0)889 ot = duintptr(s, ot, uint64(t.Chan))890 case TFUNC:891 for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {892 dtypesym(t1.Type)893 }894 isddd := false895 for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {896 isddd = t1.Isddd897 dtypesym(t1.Type)898 }899 for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {900 dtypesym(t1.Type)901 }902 ot = dcommontype(s, ot, t)903 xt = ot - 3*Widthptr904 ot = duint8(s, ot, uint8(bool2int(isddd)))905 // two slice headers: in and out.906 ot = int(Rnd(int64(ot), int64(Widthptr)))907 ot = dsymptr(s, ot, s, ot+2*(Widthptr+2*Widthint))908 n := t.Thistuple + t.Intuple909 ot = duintxx(s, ot, uint64(n), Widthint)910 ot = duintxx(s, ot, uint64(n), Widthint)911 ot = dsymptr(s, ot, s, ot+1*(Widthptr+2*Widthint)+n*Widthptr)912 ot = duintxx(s, ot, uint64(t.Outtuple), Widthint)913 ot = duintxx(s, ot, uint64(t.Outtuple), Widthint)914 // slice data915 for t1 := getthisx(t).Type; t1 != nil; t1 = t1.Down {916 ot = dsymptr(s, ot, dtypesym(t1.Type), 0)917 n++918 }919 for t1 := getinargx(t).Type; t1 != nil; t1 = t1.Down {920 ot = dsymptr(s, ot, dtypesym(t1.Type), 0)921 n++922 }923 for t1 := getoutargx(t).Type; t1 != nil; t1 = t1.Down {924 ot = dsymptr(s, ot, dtypesym(t1.Type), 0)925 n++926 }927 case TINTER:928 m := imethods(t)929 n := 0930 for a := m; a != nil; a = a.link {931 dtypesym(a.type_)932 n++933 }934 // ../../run_time/type.go:/InterfaceType935 ot = dcommontype(s, ot, t)936 xt = ot - 3*Widthptr937 ot = dsymptr(s, ot, s, ot+Widthptr+2*Widthint)938 ot = duintxx(s, ot, uint64(n), Widthint)939 ot = duintxx(s, ot, uint64(n), Widthint)940 for a := m; a != nil; a = a.link {941 // ../../run_time/type.go:/imethod942 ot = dgostringptr(s, ot, a.name)943 ot = dgopkgpath(s, ot, a.pkg)944 ot = dsymptr(s, ot, dtypesym(a.type_), 0)945 }946 // ../../run_time/type.go:/MapType947 case TMAP:948 s1 := dtypesym(t.Down)949 s2 := dtypesym(t.Type)950 s3 := dtypesym(mapbucket(t))951 s4 := dtypesym(hmap(t))952 ot = dcommontype(s, ot, t)953 xt = ot - 3*Widthptr954 ot = dsymptr(s, ot, s1, 0)955 ot = dsymptr(s, ot, s2, 0)956 ot = dsymptr(s, ot, s3, 0)957 ot = dsymptr(s, ot, s4, 0)958 if t.Down.Width > MAXKEYSIZE {959 ot = duint8(s, ot, uint8(Widthptr))960 ot = duint8(s, ot, 1) // indirect961 } else {962 ot = duint8(s, ot, uint8(t.Down.Width))963 ot = duint8(s, ot, 0) // not indirect964 }965 if t.Type.Width > MAXVALSIZE {966 ot = duint8(s, ot, uint8(Widthptr))967 ot = duint8(s, ot, 1) // indirect968 } else {969 ot = duint8(s, ot, uint8(t.Type.Width))970 ot = duint8(s, ot, 0) // not indirect971 }972 ot = duint16(s, ot, uint16(mapbucket(t).Width))973 ot = duint8(s, ot, uint8(bool2int(isreflexive(t.Down))))974 case TPTR32,975 TPTR64:976 if t.Type.Etype == TANY {977 // ../../run_time/type.go:/UnsafePointerType978 ot = dcommontype(s, ot, t)979 break980 }981 // ../../run_time/type.go:/PtrType982 s1 := dtypesym(t.Type)983 ot = dcommontype(s, ot, t)984 xt = ot - 3*Widthptr985 ot = dsymptr(s, ot, s1, 0)986 // ../../run_time/type.go:/StructType987 // for security, only the exported fields.988 case TSTRUCT:989 n := 0990 for t1 := t.Type; t1 != nil; t1 = t1.Down {991 dtypesym(t1.Type)992 n++993 }994 ot = dcommontype(s, ot, t)995 xt = ot - 3*Widthptr996 ot = dsymptr(s, ot, s, ot+Widthptr+2*Widthint)997 ot = duintxx(s, ot, uint64(n), Widthint)998 ot = duintxx(s, ot, uint64(n), Widthint)999 for t1 := t.Type; t1 != nil; t1 = t1.Down {1000 // ../../run_time/type.go:/structField1001 if t1.Sym != nil && t1.Embedded == 0 {1002 ot = dgostringptr(s, ot, t1.Sym.Name)1003 if exportname(t1.Sym.Name) {1004 ot = dgostringptr(s, ot, "")1005 } else {1006 ot = dgopkgpath(s, ot, t1.Sym.Pkg)1007 }1008 } else {1009 ot = dgostringptr(s, ot, "")1010 if t1.Type.Sym != nil && t1.Type.Sym.Pkg == builtinpkg {1011 ot = dgopkgpath(s, ot, localpkg)1012 } else {1013 ot = dgostringptr(s, ot, "")1014 }1015 }1016 ot = dsymptr(s, ot, dtypesym(t1.Type), 0)1017 ot = dgostrlitptr(s, ot, t1.Note)1018 ot = duintptr(s, ot, uint64(t1.Width)) // field offset1019 }1020 }1021 ot = dextratype(s, ot, t, xt)1022 ggloblsym(s, int32(ot), int8(dupok|obj.RODATA))1023 // generate typelink.foo pointing at s = type.foo.1024 // The linker will leave a table of all the typelinks for1025 // types in the binary, so reflect can find them.1026 // We only need the link for unnamed composites that1027 // we want be able to find.1028 if t.Sym == nil {1029 switch t.Etype {1030 case TARRAY,1031 TCHAN,1032 TMAP:1033 slink := typelinksym(t)1034 dsymptr(slink, 0, s, 0)1035 ggloblsym(slink, int32(Widthptr), int8(dupok|obj.RODATA))1036 }1037 }1038 return s1039}1040func dumptypestructs() {1041 var n *Node1042 // copy types from externdcl list to signatlist1043 for l := externdcl; l != nil; l = l.Next {1044 n = l.N1045 if n.Op != OTYPE {1046 continue1047 }1048 signatlist = list(signatlist, n)1049 }1050 // process signatlist1051 var t *Type1052 for l := signatlist; l != nil; l = l.Next {1053 n = l.N1054 if n.Op != OTYPE {1055 continue1056 }1057 t = n.Type1058 dtypesym(t)1059 if t.Sym != nil {1060 dtypesym(Ptrto(t))1061 }1062 }1063 // generate import strings for imported packages1064 for _, p := range pkgs {1065 if p.Direct != 0 {1066 dimportpath(p)1067 }1068 }1069 // do basic types if compiling package run_time.1070 // they have to be in at least one package,1071 // and run_time is always loaded implicitly,1072 // so this is as good as any.1073 // another possible choice would be package main,1074 // but using run_time means fewer copies in .6 files.1075 if compiling_run_time != 0 {1076 for i := 1; i <= TBOOL; i++ {1077 dtypesym(Ptrto(Types[i]))1078 }1079 dtypesym(Ptrto(Types[TSTRING]))1080 dtypesym(Ptrto(Types[TUNSAFEPTR]))1081 // emit type structs for error and func(error) string.1082 // The latter is the type of an auto-generated wrapper.1083 dtypesym(Ptrto(errortype))1084 dtypesym(functype(nil, list1(Nod(ODCLFIELD, nil, typenod(errortype))), list1(Nod(ODCLFIELD, nil, typenod(Types[TSTRING])))))1085 // add paths for run_time and main, which 6l imports implicitly.1086 dimportpath(Runtimepkg)1087 if flag_race != 0 {1088 dimportpath(racepkg)1089 }1090 dimportpath(mkpkg("main"))1091 }1092}1093func dalgsym(t *Type) *Sym {1094 var s *Sym1095 var hashfunc *Sym1096 var eqfunc *Sym1097 // dalgsym is only called for a type that needs an algorithm table,1098 // which implies that the type is comparable (or else it would use ANOEQ).1099 if algtype(t) == AMEM {1100 // we use one algorithm table for all AMEM types of a given size1101 p := fmt.Sprintf(".alg%d", t.Width)1102 s = Pkglookup(p, typepkg)1103 if s.Flags&SymAlgGen != 0 {1104 return s1105 }1106 s.Flags |= SymAlgGen1107 // make hash closure1108 p = fmt.Sprintf(".hashfunc%d", t.Width)1109 hashfunc = Pkglookup(p, typepkg)1110 ot := 01111 ot = dsymptr(hashfunc, ot, Pkglookup("memhash_varlen", Runtimepkg), 0)1112 ot = duintxx(hashfunc, ot, uint64(t.Width), Widthptr) // size encoded in closure1113 ggloblsym(hashfunc, int32(ot), obj.DUPOK|obj.RODATA)1114 // make equality closure1115 p = fmt.Sprintf(".eqfunc%d", t.Width)1116 eqfunc = Pkglookup(p, typepkg)1117 ot = 01118 ot = dsymptr(eqfunc, ot, Pkglookup("memequal_varlen", Runtimepkg), 0)1119 ot = duintxx(eqfunc, ot, uint64(t.Width), Widthptr)1120 ggloblsym(eqfunc, int32(ot), obj.DUPOK|obj.RODATA)1121 } else {1122 // generate an alg table specific to this type1123 s = typesymprefix(".alg", t)1124 hash := typesymprefix(".hash", t)1125 eq := typesymprefix(".eq", t)1126 hashfunc = typesymprefix(".hashfunc", t)1127 eqfunc = typesymprefix(".eqfunc", t)1128 genhash(hash, t)1129 geneq(eq, t)1130 // make Go funcs (closures) for calling hash and equal from Go1131 dsymptr(hashfunc, 0, hash, 0)1132 ggloblsym(hashfunc, int32(Widthptr), obj.DUPOK|obj.RODATA)1133 dsymptr(eqfunc, 0, eq, 0)1134 ggloblsym(eqfunc, int32(Widthptr), obj.DUPOK|obj.RODATA)1135 }1136 // ../../run_time/alg.go:/typeAlg1137 ot := 01138 ot = dsymptr(s, ot, hashfunc, 0)1139 ot = dsymptr(s, ot, eqfunc, 0)1140 ggloblsym(s, int32(ot), obj.DUPOK|obj.RODATA)1141 return s1142}1143func usegcprog(t *Type) bool {1144 if !haspointers(t) {1145 return false1146 }1147 if t.Width == BADWIDTH {1148 dowidth(t)1149 }1150 // Calculate size of the unrolled GC mask.1151 nptr := (t.Width + int64(Widthptr) - 1) / int64(Widthptr)1152 size := nptr1153 if size%2 != 0 {1154 size *= 2 // repeated1155 }1156 size = size * obj.GcBits / 8 // 4 bits per word1157 // Decide whether to use unrolled GC mask or GC program.1158 // We could use a more elaborate condition, but this seems to work well in practice.1159 // For small objects GC program can't give significant reduction.1160 // While large objects usually contain arrays; and even if it don't1161 // the program uses 2-bits per word while mask uses 4-bits per word,1162 // so the program is still smaller.1163 return size > int64(2*Widthptr)1164}1165// Generates sparse GC bitmask (4 bits per word).1166func gengcmask(t *Type, gcmask []byte) {1167 for i := int64(0); i < 16; i++ {1168 gcmask[i] = 01169 }1170 if !haspointers(t) {1171 return1172 }1173 // Generate compact mask as stacks use.1174 xoffset := int64(0)1175 vec := bvalloc(2 * int32(Widthptr) * 8)1176 twobitwalktype1(t, &xoffset, vec)1177 // Unfold the mask for the GC bitmap format:1178 // 4 bits per word, 2 high bits encode pointer info.1179 pos := gcmask1180 nptr := (t.Width + int64(Widthptr) - 1) / int64(Widthptr)1181 half := false1182 // If number of words is odd, repeat the mask.1183 // This makes simpler handling of arrays in run_time.1184 var i int641185 var bits uint81186 for j := int64(0); j <= (nptr % 2); j++ {1187 for i = 0; i < nptr; i++ {1188 bits = uint8(bvget(vec, int32(i*obj.BitsPerPointer)) | bvget(vec, int32(i*obj.BitsPerPointer+1))<<1)1189 // Some fake types (e.g. Hmap) has missing fileds.1190 // twobitwalktype1 generates BitsDead for that holes,1191 // replace BitsDead with BitsScalar.1192 if bits == obj.BitsDead {1193 bits = obj.BitsScalar1194 }1195 bits <<= 21196 if half {1197 bits <<= 41198 }1199 pos[0] |= byte(bits)1200 half = !half1201 if !half {1202 pos = pos[1:]...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...19 flagDir = flag.String("dir", "", "directory to parse")20 variantMap = proggen.NewCall2VariantMap()21)22const (23 goos = "linux" // Target OS24 arch = "amd64" // Target architecture25 currentDBVersion = 3 // Marked as minimized26)27func main() {28 flag.Parse()29 target, err := prog.GetTarget(goos, arch)30 if err != nil {31 log.Fatalf("Failed to load target: %s", err)32 }33 variantMap.Build(target)34 parseTraces(target)35 log.Logf(0, "Successfully converted traces. Generating corpus.db")36 pack("deserialized", "corpus.db")37}38func parseTraces(target *prog.Target) []*proggen.Context {39 var ret []*proggen.Context40 var names []string41 if *flagFile != "" {42 names = append(names, *flagFile)43 } else if *flagDir != "" {44 names = getTraceFiles(*flagDir)45 } else {46 log.Fatalf("Flag or FlagDir required")47 }48 totalFiles := len(names)49 log.Logf(0, "Parsing %d traces", totalFiles)50 for i, file := range names {51 log.Logf(1, "Parsing File %d/%d: %s", i+1, totalFiles, filepath.Base(names[i]))52 tree := parser.Parse(file)53 if tree == nil {54 log.Logf(1, "File: %s is empty", filepath.Base(file))55 continue56 }57 ctxs := parseTree(tree, tree.RootPid, target)58 ret = append(ret, ctxs...)59 for i, ctx := range ctxs {60 ctx.Prog.Target = ctx.Target61 err := ctx.FillOutMemory()62 if err != nil {63 log.Logf(1, "Failed to fill out memory. Error: %s", err)64 continue65 }66 if err := ctx.Prog.Validate(); err != nil {67 log.Fatalf("Error validating program: %s", err)68 }69 if progIsTooLarge(ctx.Prog) {70 log.Logf(1, "Prog is too large")71 continue72 }73 progName := "deserialized/" + filepath.Base(file) + strconv.Itoa(i)74 if err := ioutil.WriteFile(progName, ctx.Prog.Serialize(), 0640); err != nil {75 log.Fatalf("failed to output file: %v", err)76 }77 }78 }79 return ret80}81func progIsTooLarge(p *prog.Prog) bool {82 buff := make([]byte, prog.ExecBufferSize)83 if _, err := p.SerializeForExec(buff); err != nil {84 return true85 }86 return false87}88func getTraceFiles(dir string) []string {89 var names []string90 infos, err := ioutil.ReadDir(dir)91 if err != nil {92 log.Fatalf("Failed to read dir: %s", err.Error())93 }94 for _, info := range infos {95 name := filepath.Join(dir, info.Name())96 names = append(names, name)97 }98 return names99}100// parseTree groups system calls in the trace by process id.101// The tree preserves process hierarchy i.e. parent->[]child102func parseTree(tree *parser.TraceTree, pid int64, target *prog.Target) []*proggen.Context {103 log.Logf(2, "Parsing trace: %s", tree.Filename)104 var ctxs []*proggen.Context105 ctx := proggen.GenSyzProg(tree.TraceMap[pid], target, variantMap)106 ctxs = append(ctxs, ctx)107 for _, childPid := range tree.Ptree[pid] {108 if tree.TraceMap[childPid] != nil {109 ctxs = append(ctxs, parseTree(tree, childPid, target)...)110 }111 }112 return ctxs113}114func pack(dir, file string) {115 log.Logf(0, "Converted traces...Generating corpus.db")116 files, err := ioutil.ReadDir(dir)117 if err != nil {118 log.Fatalf("failed to read dir: %v", err)119 }120 os.Remove(file)121 syzDb, err := db.Open(file)122 if err != nil {123 log.Fatalf("failed to open database file: %v", err)...

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(proggen.Get())4}5import (6func main() {7 fmt.Println(proggen.Get())8}9import (10func main() {11 fmt.Println(proggen.Get())12}13import (14func main() {15 fmt.Println(proggen.Get())16}17import (18func main() {19 fmt.Println(proggen.Get())20}21import (22func main() {23 fmt.Println(proggen.Get())24}25import (26func main() {27 fmt.Println(proggen.Get())28}29import (30func main() {31 fmt.Println(proggen.Get())32}33import (34func main() {35 fmt.Println(proggen.Get())36}37import (38func main() {39 fmt.Println(proggen.Get())40}41import (42func main() {43 fmt.Println(proggen.Get())44}45import (46func main() {47 fmt.Println(proggen.Get())48}

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := proggen.Get()4 fmt.Println(p)5}6func Get() string {7}

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(proggen.Get(1))4}5import (6func main() {7 fmt.Println(proggen.Get(2))8}9import (10func main() {11 fmt.Println(proggen.Get(3))12}13import (14func main() {15 fmt.Println(proggen.Get(4))16}17import (18func main() {19 fmt.Println(proggen.Get(5))20}21import (22func main() {23 fmt.Println(proggen.Get(6))24}25import (26func main() {27 fmt.Println(proggen.Get(7))28}29import (30func main() {31 fmt.Println(proggen.Get(8))32}33import (34func main() {35 fmt.Println(proggen.Get(9))36}

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(proggen.Get("Hello World"))4}5import (6func main() {7 fmt.Println(proggen.Get("Hello World"))8}9import (10func main() {11 fmt.Println(proggen.Get("Hello World"))12}13import (14func main() {15 fmt.Println(proggen.Get("Hello World"))16}17import (18func main() {19 fmt.Println(proggen.Get("Hello World"))20}21import (22func main() {23 fmt.Println(proggen.Get("Hello World"))24}25import (26func main() {27 fmt.Println(proggen.Get("Hello World"))28}29import (30func main() {31 fmt.Println(proggen.Get("Hello World"))32}33import (

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(proggen.Get())4}5func Get() string {6}7I am new to golang and I am trying to create a package with a function in it. I am trying to use the get method of the proggen class. I am using the following code. Path: 2.go code to use get method of proggen class package main import ( "fmt" "proggen" ) func main() { fmt.Println(proggen.Get()) } package proggen func Get() string { return "Hello World" } I am using the following command to run the code go run 2.go But I am getting the following error proggen\proggen.go:1:1: expected 'package', found 'EOF' I am not sure what I am doing wrong here. Can anyone help me with t

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var a = Proggen.Get(1, 1)4 fmt.Println(a)5}6import (7func Get(a int, b int) int {8}9 /usr/lib/go-1.6/src/github.com/Proggen/Proggen (from $GOROOT)10 /home/username/go/src/github.com/Proggen/Proggen (from $GOPATH)11 /usr/lib/go-1.6/src/github.com/Proggen/Proggen (from $GOROOT)12 /home/username/go/src/github.com/Proggen/Proggen (from $GOPATH)

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c = proggen.Get(a, b)4 fmt.Println(c)5}6Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. It is a statically typed language with syntax inspired by C, adding garbage collection, type safety, some dynamic-typing capabilities, additional built-in types (e.g. variable-length arrays and key-value maps), and a large standard library. Go is a compiled language and there is no interpreter for Go. The Go compiler compiles the source code into machine code. The Go compiler also generates an executable file. Go has a garbage collector that frees the memory of unused variables. Go is a concurrent language. It means that we can run multiple tasks in parallel. Go has a special keyword called go to run a function concurrently. Go is a statically typed language. It means that the type of a variable is known at compile time. Go has a special keyword called defer that is used to execute a function at the end of the main function. Go has a special keyword called panic that is used to raise an exception. Go has a special keyword called recover that is used to handle the exception. Go supports multiple return values from a function. Go supports pointers. Go supports arrays. Go supports slices. Go supports maps. Go supports structs. Go supports interfaces. Go supports goroutines. Go supports channels. Go supports select. Go supports packages. Go supports modules. Go supports command line arguments. Go supports file handling. Go supports JSON. Go supports XML. Go supports regular expressions. Go supports web applications. Go supports web services. Go supports database connectivity. Go supports unit testing. Go supports benchmarking. Go supports profiling. Go supports reflection. Go supports code generation. Go supports template. Go supports concurrency. Go supports concurrency using channels. Go supports concurrency using select. Go supports concurrency using goroutines. Go

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 proggen.Get()4 fmt.Println("Hello World")5}6import (7func main() {8 proggen.Get()9 fmt.Println("Hello World")10}11import (12func main() {13 proggen.Get()14 fmt.Println("Hello World")15}16import (17func main() {18 proggen.Get()19 fmt.Println("Hello World")20}21import (22func main() {23 proggen.Get()24 fmt.Println("Hello World")25}26import (27func main() {28 proggen.Get()29 fmt.Println("Hello World")30}31import (32func main() {33 proggen.Get()34 fmt.Println("Hello World")35}36import (37func main() {38 proggen.Get()39 fmt.Println("Hello World")40}

Full Screen

Full Screen

get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a.Get()4 fmt.Println(a)5}6{Go Computer Science BHU 2}7{Java Computer Science IIT 3}8{Go Computer Science BHU 2}9{Go Computer Science BHU 2}10{Java Computer Science IIT 3}11{Python Computer Science IIT 2}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful