本文整理匯總了Golang中cmd/internal/obj.Bgetc函數的典型用法代碼示例。如果您正苦於以下問題:Golang Bgetc函數的具體用法?Golang Bgetc怎麽用?Golang Bgetc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Bgetc函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getc
func getc() int {
c := curio.peekc
if c != 0 {
curio.peekc = curio.peekc1
curio.peekc1 = 0
goto check
}
if curio.bin == nil {
if len(curio.cp) == 0 {
c = 0
} else {
c = int(curio.cp[0])
curio.cp = curio.cp[1:]
}
} else {
var c1 int
var c2 int
loop:
c = obj.Bgetc(curio.bin)
if c == 0xef {
c1 = obj.Bgetc(curio.bin)
c2 = obj.Bgetc(curio.bin)
if c1 == 0xbb && c2 == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
goto loop
}
obj.Bungetc(curio.bin)
obj.Bungetc(curio.bin)
}
}
check:
switch c {
case 0:
if curio.bin != nil {
Yyerror("illegal NUL byte")
break
}
fallthrough
// insert \n at EOF
case EOF:
if curio.eofnl != 0 || curio.last == '\n' {
return EOF
}
curio.eofnl = 1
c = '\n'
fallthrough
case '\n':
if pushedio.bin == nil {
lexlineno++
}
}
curio.last = c
return c
}
示例2: ldobjfile
func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
start := obj.Boffset(f)
ctxt.IncVersion()
var buf [8]uint8
obj.Bread(f, buf[:])
if string(buf[:]) != startmagic {
log.Fatalf("%s: invalid file start %x %x %x %x %x %x %x %x", pn, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7])
}
c := obj.Bgetc(f)
if c != 1 {
log.Fatalf("%s: invalid file version number %d", pn, c)
}
var lib string
for {
lib = rdstring(f)
if lib == "" {
break
}
addlib(ctxt, pkg, pn, lib)
}
ctxt.CurRefs = []*LSym{nil} // zeroth ref is nil
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
obj.Bgetc(f)
break
}
readref(ctxt, f, pkg, pn)
}
dataLength := rdint64(f)
data := make([]byte, dataLength)
obj.Bread(f, data)
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, &data, pkg, pn)
}
buf = [8]uint8{}
obj.Bread(f, buf[:])
if string(buf[:]) != endmagic {
log.Fatalf("%s: invalid file end", pn)
}
if obj.Boffset(f) != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(obj.Boffset(f)), int64(start+length))
}
}
示例3: getr
func (l *lexer) getr() rune {
// unread rune != 0 available
if r := l.peekr1; r != 0 {
l.peekr1 = l.peekr2
l.peekr2 = 0
if r == '\n' && importpkg == nil {
lexlineno++
}
return r
}
redo:
// common case: 7bit ASCII
c := obj.Bgetc(l.bin)
if c < utf8.RuneSelf {
if c == 0 {
yyerrorl(int(lexlineno), "illegal NUL byte")
return 0
}
if c == '\n' && importpkg == nil {
lexlineno++
}
return rune(c)
}
// c >= utf8.RuneSelf
// uncommon case: non-ASCII
var buf [utf8.UTFMax]byte
buf[0] = byte(c)
buf[1] = byte(obj.Bgetc(l.bin))
i := 2
for ; i < len(buf) && !utf8.FullRune(buf[:i]); i++ {
buf[i] = byte(obj.Bgetc(l.bin))
}
r, w := utf8.DecodeRune(buf[:i])
if r == utf8.RuneError && w == 1 {
// The string conversion here makes a copy for passing
// to fmt.Printf, so that buf itself does not escape and
// can be allocated on the stack.
yyerrorl(int(lexlineno), "illegal UTF-8 sequence % x", string(buf[:i]))
}
if r == BOM {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
goto redo
}
return r
}
示例4: byte
func (p *importer) byte() byte {
if c := obj.Bgetc(p.in); c >= 0 {
p.read++
return byte(c)
}
Fatalf("read error")
return 0
}
示例5: byte
// byte is the bottleneck interface for reading from p.in.
// It unescapes '|' 'S' to '$' and '|' '|' to '|'.
func (p *importer) byte() byte {
c := obj.Bgetc(p.in)
p.read++
if c < 0 {
Fatalf("read error")
}
if c == '|' {
c = obj.Bgetc(p.in)
p.read++
if c < 0 {
Fatalf("read error")
}
switch c {
case 'S':
c = '$'
case '|':
// nothing to do
default:
Fatalf("unexpected escape sequence in export data")
}
}
return byte(c)
}
示例6: readref
func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
if obj.Bgetc(f) != 0xfe {
log.Fatalf("readsym out of sync")
}
name := rdsymName(f, pkg)
v := rdint(f)
if v != 0 && v != 1 {
log.Fatalf("invalid symbol version %d", v)
}
if v == 1 {
v = ctxt.Version
}
lsym := Linklookup(ctxt, name, v)
ctxt.CurRefs = append(ctxt.CurRefs, lsym)
}
示例7: rdint
func rdint(f *obj.Biobuf) int64 {
var c int
uv := uint64(0)
for shift := 0; ; shift += 7 {
if shift >= 64 {
log.Fatalf("corrupt input")
}
c = obj.Bgetc(f)
uv |= uint64(c&0x7F) << uint(shift)
if c&0x80 == 0 {
break
}
}
return int64(uv>>1) ^ (int64(uint64(uv)<<63) >> 63)
}
示例8: ldobjfile
func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
start := obj.Boffset(f)
ctxt.Version++
var buf [8]uint8
obj.Bread(f, buf[:])
if string(buf[:]) != startmagic {
log.Fatalf("%s: invalid file start %x %x %x %x %x %x %x %x", pn, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7])
}
c := obj.Bgetc(f)
if c != 1 {
log.Fatalf("%s: invalid file version number %d", pn, c)
}
var lib string
for {
lib = rdstring(f)
if lib == "" {
break
}
addlib(ctxt, pkg, pn, lib)
}
for {
c, err := f.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, pkg, pn)
}
buf = [8]uint8{}
obj.Bread(f, buf[:])
if string(buf[:]) != endmagic {
log.Fatalf("%s: invalid file end", pn)
}
if obj.Boffset(f) != start+length {
log.Fatalf("%s: unexpected end at %d, want %d", pn, int64(obj.Boffset(f)), int64(start+length))
}
}
示例9: readref
func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
if obj.Bgetc(f) != 0xfe {
log.Fatalf("readsym out of sync")
}
name := rdsymName(f, pkg)
v := rdint(f)
if v != 0 && v != 1 {
log.Fatalf("invalid symbol version %d", v)
}
if v == 1 {
v = ctxt.Version
}
s := Linklookup(ctxt, name, v)
ctxt.CurRefs = append(ctxt.CurRefs, s)
if s == nil || v != 0 {
return
}
if s.Name[0] == '$' && len(s.Name) > 5 && s.Type == 0 && len(s.P) == 0 {
x, err := strconv.ParseUint(s.Name[5:], 16, 64)
if err != nil {
log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
}
s.Type = obj.SRODATA
s.Attr |= AttrLocal
switch s.Name[:5] {
case "$f32.":
if uint64(uint32(x)) != x {
log.Panicf("$-symbol %s too large: %d", s.Name, x)
}
Adduint32(ctxt, s, uint32(x))
case "$f64.", "$i64.":
Adduint64(ctxt, s, x)
default:
log.Panicf("unrecognized $-symbol: %s", s.Name)
}
s.Attr.Set(AttrReachable, false)
}
if strings.HasPrefix(s.Name, "runtime.gcbits.") {
s.Attr |= AttrLocal
}
}
示例10: importfile
//.........這裏部分代碼省略.........
importpkg.Imported = true
var err error
var imp *obj.Biobuf
imp, err = obj.Bopenr(file)
if err != nil {
Yyerror("can't open import: %q: %v", f.U.(string), err)
errorexit()
}
if strings.HasSuffix(file, ".a") {
if !skiptopkgdef(imp) {
Yyerror("import %s: not a package file", file)
errorexit()
}
}
// check object header
p := obj.Brdstr(imp, '\n', 1)
if p != "empty archive" {
if !strings.HasPrefix(p, "go object ") {
Yyerror("import %s: not a go object file", file)
errorexit()
}
q := fmt.Sprintf("%s %s %s %s", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
if p[10:] != q {
Yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q)
errorexit()
}
}
// assume files move (get installed)
// so don't record the full path.
linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
// In the importfile, if we find:
// $$\n (old format): position the input right after $$\n and return
// $$B\n (new format): import directly, then feed the lexer a dummy statement
// look for $$
var c int
for {
c = obj.Bgetc(imp)
if c < 0 {
break
}
if c == '$' {
c = obj.Bgetc(imp)
if c == '$' || c < 0 {
break
}
}
}
// get character after $$
if c >= 0 {
c = obj.Bgetc(imp)
}
switch c {
case '\n':
// old export format
pushedio = curio
curio.bin = imp
curio.peekc = 0
curio.peekc1 = 0
curio.infile = file
curio.nlsemi = false
typecheckok = true
push_parser()
case 'B':
// new export format
obj.Bgetc(imp) // skip \n after $$B
Import(imp)
// continue as if the package was imported before (see above)
tag := ""
if importpkg.Safe {
tag = "safe"
}
p := fmt.Sprintf("package %s %s\n$$\n", importpkg.Name, tag)
cannedimports(file, p)
// Reset incannedimport flag (we are not truly in a
// canned import) - this will cause importpkg.Direct to
// be set via parser.import_package (was issue #13977).
//
// TODO(gri) Remove this global variable and convoluted
// code in the process of streamlining the import code.
incannedimport = 0
default:
Yyerror("no import in %q", f.U.(string))
}
}
示例11: getc
func getc() int {
c := curio.peekc
if c != 0 {
curio.peekc = curio.peekc1
curio.peekc1 = 0
goto check
}
if curio.bin == nil {
if len(curio.cp) == 0 {
c = 0
} else {
c = int(curio.cp[0])
curio.cp = curio.cp[1:]
}
} else {
loop:
c = obj.Bgetc(curio.bin)
// recognize BOM (U+FEFF): UTF-8 encoding is 0xef 0xbb 0xbf
if c == 0xef {
buf, err := curio.bin.Peek(2)
if err != nil {
yyerrorl(int(lexlineno), "illegal UTF-8 sequence ef % x followed by read error (%v)", string(buf), err)
errorexit()
}
if buf[0] == 0xbb && buf[1] == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
// consume BOM bytes
obj.Bgetc(curio.bin)
obj.Bgetc(curio.bin)
goto loop
}
}
}
check:
switch c {
case 0:
if curio.bin != nil {
Yyerror("illegal NUL byte")
break
}
fallthrough
// insert \n at EOF
case EOF:
if curio.eofnl || curio.last == '\n' {
return EOF
}
curio.eofnl = true
c = '\n'
fallthrough
case '\n':
if pushedio.bin == nil {
lexlineno++
}
}
curio.last = c
return c
}
示例12: importfile
//.........這裏部分代碼省略.........
prefix = localimport
}
path_ = path.Join(prefix, path_)
if isbadimport(path_) {
return
}
}
file, found := findpkg(path_)
if !found {
Yyerror("can't find import: %q", path_)
errorexit()
}
importpkg = mkpkg(path_)
if importpkg.Imported {
return
}
importpkg.Imported = true
imp, err := obj.Bopenr(file)
if err != nil {
Yyerror("can't open import: %q: %v", path_, err)
errorexit()
}
defer obj.Bterm(imp)
if strings.HasSuffix(file, ".a") {
if !skiptopkgdef(imp) {
Yyerror("import %s: not a package file", file)
errorexit()
}
}
// check object header
p := obj.Brdstr(imp, '\n', 1)
if p != "empty archive" {
if !strings.HasPrefix(p, "go object ") {
Yyerror("import %s: not a go object file", file)
errorexit()
}
q := fmt.Sprintf("%s %s %s %s", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
if p[10:] != q {
Yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q)
errorexit()
}
}
// assume files move (get installed)
// so don't record the full path.
linehistpragma(file[len(file)-len(path_)-2:]) // acts as #pragma lib
// In the importfile, if we find:
// $$\n (old format): position the input right after $$\n and return
// $$B\n (new format): import directly, then feed the lexer a dummy statement
// look for $$
var c int
for {
c = obj.Bgetc(imp)
if c < 0 {
break
}
if c == '$' {
c = obj.Bgetc(imp)
if c == '$' || c < 0 {
break
}
}
}
// get character after $$
if c >= 0 {
c = obj.Bgetc(imp)
}
switch c {
case '\n':
// old export format
parse_import(imp, indent)
case 'B':
// new export format
obj.Bgetc(imp) // skip \n after $$B
Import(imp)
default:
Yyerror("no import in %q", path_)
errorexit()
}
if safemode != 0 && !importpkg.Safe {
Yyerror("cannot import unsafe package %q", importpkg.Path)
}
}
示例13: getc
func getc() int {
c := curio.peekc
if c != 0 {
curio.peekc = curio.peekc1
curio.peekc1 = 0
goto check
}
if curio.bin == nil {
if len(curio.cp) == 0 {
c = 0
} else {
c = int(curio.cp[0])
curio.cp = curio.cp[1:]
}
} else {
loop:
c = obj.Bgetc(curio.bin)
if c == 0xef {
buf, err := curio.bin.Peek(2)
if err != nil {
log.Fatalf("getc: peeking: %v", err)
}
if buf[0] == 0xbb && buf[1] == 0xbf {
yyerrorl(int(lexlineno), "Unicode (UTF-8) BOM in middle of file")
// consume BOM bytes
obj.Bgetc(curio.bin)
obj.Bgetc(curio.bin)
goto loop
}
}
}
check:
switch c {
case 0:
if curio.bin != nil {
Yyerror("illegal NUL byte")
break
}
fallthrough
// insert \n at EOF
case EOF:
if curio.eofnl || curio.last == '\n' {
return EOF
}
curio.eofnl = true
c = '\n'
fallthrough
case '\n':
if pushedio.bin == nil {
lexlineno++
}
}
curio.last = c
return c
}
示例14: readsym
func readsym(ctxt *Link, f *obj.Biobuf, buf *[]byte, pkg string, pn string) {
if obj.Bgetc(f) != 0xfe {
log.Fatalf("readsym out of sync")
}
t := rdint(f)
s := rdsym(ctxt, f, pkg)
flags := rdint(f)
dupok := flags&1 != 0
local := flags&2 != 0
size := rdint(f)
typ := rdsym(ctxt, f, pkg)
data := rddata(f, buf)
nreloc := rdint(f)
var dup *LSym
if s.Type != 0 && s.Type != obj.SXREF {
if (t == obj.SDATA || t == obj.SBSS || t == obj.SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
if s.Size < int64(size) {
s.Size = int64(size)
}
if typ != nil && s.Gotype == nil {
s.Gotype = typ
}
return
}
if (s.Type == obj.SDATA || s.Type == obj.SBSS || s.Type == obj.SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 {
goto overwrite
}
if s.Type != obj.SBSS && s.Type != obj.SNOPTRBSS && !dupok && !s.Attr.DuplicateOK() {
log.Fatalf("duplicate symbol %s (types %d and %d) in %s and %s", s.Name, s.Type, t, s.File, pn)
}
if len(s.P) > 0 {
dup = s
s = dupSym
}
}
overwrite:
s.File = pkg
if dupok {
s.Attr |= AttrDuplicateOK
}
if t == obj.SXREF {
log.Fatalf("bad sxref")
}
if t == 0 {
log.Fatalf("missing type for %s in %s", s.Name, pn)
}
if t == obj.SBSS && (s.Type == obj.SRODATA || s.Type == obj.SNOPTRBSS) {
t = int(s.Type)
}
s.Type = int16(t)
if s.Size < int64(size) {
s.Size = int64(size)
}
s.Attr.Set(AttrLocal, local)
if typ != nil {
s.Gotype = typ
}
if dup != nil && typ != nil { // if bss sym defined multiple times, take type from any one def
dup.Gotype = typ
}
s.P = data
if nreloc > 0 {
s.R = make([]Reloc, nreloc)
var r *Reloc
for i := 0; i < nreloc; i++ {
r = &s.R[i]
r.Off = rdint32(f)
r.Siz = rduint8(f)
r.Type = rdint32(f)
r.Add = rdint64(f)
r.Sym = rdsym(ctxt, f, pkg)
}
}
if s.Type == obj.STEXT {
s.Args = rdint32(f)
s.Locals = rdint32(f)
if rduint8(f) != 0 {
s.Attr |= AttrNoSplit
}
flags := rdint(f)
if flags&(1<<2) != 0 {
s.Attr |= AttrReflectMethod
}
n := rdint(f)
s.Autom = make([]Auto, n)
for i := 0; i < n; i++ {
s.Autom[i] = Auto{
Asym: rdsym(ctxt, f, pkg),
Aoffset: rdint32(f),
Name: rdint16(f),
Gotype: rdsym(ctxt, f, pkg),
}
}
s.Pcln = new(Pcln)
pc := s.Pcln
//.........這裏部分代碼省略.........
示例15: readsym
func readsym(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
if obj.Bgetc(f) != 0xfe {
log.Fatalf("readsym out of sync")
}
t := rdint(f)
s := rdsym(ctxt, f, pkg)
flags := rdint(f)
dupok := flags&1 != 0
local := flags&2 != 0
size := rdint(f)
typ := rdsym(ctxt, f, pkg)
data := rddata(f)
nreloc := rdint(f)
var dup *LSym
if s.Type != 0 && s.Type != obj.SXREF {
if (t == obj.SDATA || t == obj.SBSS || t == obj.SNOPTRBSS) && len(data) == 0 && nreloc == 0 {
if s.Size < int64(size) {
s.Size = int64(size)
}
if typ != nil && s.Gotype == nil {
s.Gotype = typ
}
return
}
if (s.Type == obj.SDATA || s.Type == obj.SBSS || s.Type == obj.SNOPTRBSS) && len(s.P) == 0 && len(s.R) == 0 {
goto overwrite
}
if s.Type != obj.SBSS && s.Type != obj.SNOPTRBSS && !dupok && !s.Attr.DuplicateOK() {
log.Fatalf("duplicate symbol %s (types %d and %d) in %s and %s", s.Name, s.Type, t, s.File, pn)
}
if len(s.P) > 0 {
dup = s
s = linknewsym(ctxt, ".dup", -1)
}
}
overwrite:
s.File = pkg
if dupok {
s.Attr |= AttrDuplicateOK
}
if t == obj.SXREF {
log.Fatalf("bad sxref")
}
if t == 0 {
log.Fatalf("missing type for %s in %s", s.Name, pn)
}
if t == obj.SBSS && (s.Type == obj.SRODATA || s.Type == obj.SNOPTRBSS) {
t = int(s.Type)
}
s.Type = int16(t)
if s.Size < int64(size) {
s.Size = int64(size)
}
s.Attr.Set(AttrLocal, local)
if typ != nil { // if bss sym defined multiple times, take type from any one def
s.Gotype = typ
}
if dup != nil && typ != nil {
dup.Gotype = typ
}
s.P = data
s.P = s.P[:len(data)]
if nreloc > 0 {
s.R = make([]Reloc, nreloc)
s.R = s.R[:nreloc]
var r *Reloc
for i := 0; i < nreloc; i++ {
r = &s.R[i]
r.Off = rdint32(f)
r.Siz = rduint8(f)
r.Type = rdint32(f)
r.Add = rdint64(f)
rdint64(f) // Xadd, ignored
r.Sym = rdsym(ctxt, f, pkg)
rdsym(ctxt, f, pkg) // Xsym, ignored
}
}
if len(s.P) > 0 && dup != nil && len(dup.P) > 0 && strings.HasPrefix(s.Name, "gclocals·") {
// content-addressed garbage collection liveness bitmap symbol.
// double check for hash collisions.
if !bytes.Equal(s.P, dup.P) {
log.Fatalf("dupok hash collision for %s in %s and %s", s.Name, s.File, pn)
}
}
if s.Type == obj.STEXT {
s.Args = rdint32(f)
s.Locals = rdint32(f)
if rduint8(f) != 0 {
s.Attr |= AttrNoSplit
}
flags := rdint(f)
if flags&(1<<2) != 0 {
s.Attr |= AttrReflectMethod
}
n := rdint(f)
//.........這裏部分代碼省略.........