Home | History | Annotate | Download | only in obj
      1 // Derived from Inferno utils/6l/obj.c and utils/6l/span.c
      2 // https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/obj.c
      3 // https://bitbucket.org/inferno-os/inferno-os/src/default/utils/6l/span.c
      4 //
      5 //	Copyright  1994-1999 Lucent Technologies Inc.  All rights reserved.
      6 //	Portions Copyright  1995-1997 C H Forsyth (forsyth (a] terzarima.net)
      7 //	Portions Copyright  1997-1999 Vita Nuova Limited
      8 //	Portions Copyright  2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
      9 //	Portions Copyright  2004,2006 Bruce Ellis
     10 //	Portions Copyright  2005-2007 C H Forsyth (forsyth (a] terzarima.net)
     11 //	Revisions Copyright  2000-2007 Lucent Technologies Inc. and others
     12 //	Portions Copyright  2009 The Go Authors. All rights reserved.
     13 //
     14 // Permission is hereby granted, free of charge, to any person obtaining a copy
     15 // of this software and associated documentation files (the "Software"), to deal
     16 // in the Software without restriction, including without limitation the rights
     17 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     18 // copies of the Software, and to permit persons to whom the Software is
     19 // furnished to do so, subject to the following conditions:
     20 //
     21 // The above copyright notice and this permission notice shall be included in
     22 // all copies or substantial portions of the Software.
     23 //
     24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     30 // THE SOFTWARE.
     31 
     32 package obj
     33 
     34 /*
     35  * add library to library list.
     36  *	srcref: src file referring to package
     37  *	objref: object file referring to package
     38  *	file: object file, e.g., /home/rsc/go/pkg/container/vector.a
     39  *	pkg: package import path, e.g. container/vector
     40  */
     41 
     42 const (
     43 	LOG = 5
     44 )
     45 
     46 func mkfwd(sym *LSym) {
     47 	var dwn [LOG]int32
     48 	var cnt [LOG]int32
     49 	var lst [LOG]*Prog
     50 
     51 	for i := 0; i < LOG; i++ {
     52 		if i == 0 {
     53 			cnt[i] = 1
     54 		} else {
     55 			cnt[i] = LOG * cnt[i-1]
     56 		}
     57 		dwn[i] = 1
     58 		lst[i] = nil
     59 	}
     60 
     61 	i := 0
     62 	for p := sym.Func.Text; p != nil && p.Link != nil; p = p.Link {
     63 		i--
     64 		if i < 0 {
     65 			i = LOG - 1
     66 		}
     67 		p.Forwd = nil
     68 		dwn[i]--
     69 		if dwn[i] <= 0 {
     70 			dwn[i] = cnt[i]
     71 			if lst[i] != nil {
     72 				lst[i].Forwd = p
     73 			}
     74 			lst[i] = p
     75 		}
     76 	}
     77 }
     78 
     79 func Appendp(q *Prog, newprog ProgAlloc) *Prog {
     80 	p := newprog()
     81 	p.Link = q.Link
     82 	q.Link = p
     83 	p.Pos = q.Pos
     84 	return p
     85 }
     86