当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Printf方法代码示例

本文整理汇总了Golang中sevki/org/build.Context.Printf方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Printf方法的具体用法?Golang Context.Printf怎么用?Golang Context.Printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sevki/org/build.Context的用法示例。


在下文中一共展示了Context.Printf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Build

func (etc *ElfToC) Build(c *build.Context) error {
	fileName := ""

	if xf, err := c.Open(etc.Elf); err != nil {
		return fmt.Errorf("open :%s", err.Error())
	} else {
		fileName = xf.Name()
		xf.Close()
	}

	f, err := elf.Open(fileName)
	if err != nil {
		return err
	}
	var dataend, codeend, end uint64
	var datastart, codestart, start uint64
	datastart, codestart, start = math.MaxUint64, math.MaxUint64, math.MaxUint64
	mem := []byte{}
	for _, v := range f.Progs {
		if v.Type != elf.PT_LOAD {
			continue
		}
		c.Printf("processing %v\n", v)
		// MUST alignt to 2M page boundary.
		// then MUST allocate a []byte that
		// is the right size. And MUST
		// see if by some off chance it
		// joins to a pre-existing segment.
		// It's easier than it seems. We produce ONE text
		// array and ONE data array. So it's a matter of creating
		// a virtual memory space with an assumed starting point of
		// 0x200000, and filling it. We just grow that as needed.

		curstart := v.Vaddr & ^uint64(0xfff) // 0x1fffff)
		curend := v.Vaddr + v.Memsz
		c.Printf("s %x e %x\n", curstart, curend)
		if curend > end {
			nmem := make([]byte, curend)
			copy(nmem, mem)
			mem = nmem
		}
		if curstart < start {
			start = curstart
		}

		if v.Flags&elf.PF_X == elf.PF_X {
			if curstart < codestart {
				codestart = curstart
			}
			if curend > codeend {
				codeend = curend
			}
			c.Printf("code s %v e %v\n", codestart, codeend)
		} else {
			if curstart < datastart {
				datastart = curstart
			}
			if curend > dataend {
				dataend = curend
			}
			c.Printf("data s %v e %v\n", datastart, dataend)
		}
		for i := uint64(0); i < v.Filesz; i++ {
			if amt, err := v.ReadAt(mem[v.Vaddr+i:], int64(i)); err != nil && err != io.EOF {
				err := fmt.Errorf("%v: %v\n", amt, err)
				c.Println(err)
				return err
			} else if amt == 0 {
				if i < v.Filesz {
					err := fmt.Errorf("%v: Short read: %v of %v\n", v, i, v.Filesz)
					c.Println(err)
					return err
				}
				break
			} else {
				i = i + uint64(amt)
				c.Printf("i now %d\n", i)
			}
		}
		c.Printf("Processed %v\n", v)
	}
	c.Printf("gencode\n")
	// Gen code to stdout. For each file, create an array, a start, and an end variable.
	outfile, err := c.Create(fmt.Sprintf("%s.h", etc.Name))
	if err != nil {
		return err
	}

	_, file := path.Split(etc.Elf)

	gencode(outfile, file, "code", mem, codestart, codeend)
	gencode(outfile, file, "data", mem, datastart, dataend)

	return nil
}
开发者ID:ftrvxmtrx,项目名称:build,代码行数:95,代码来源:elf2c.go


注:本文中的sevki/org/build.Context.Printf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。