示例#1
0
文件: enc_test.go 项目: llir/llvm
func TestGlobal(t *testing.T) {
	golden := []struct {
		s    string
		want string
	}{
		// i=0
		{s: "foo", want: "@foo"},
		// i=1
		{s: "a b", want: `@a\20b`},
		// i=2
		{s: "$a", want: "@$a"},
		// i=3
		{s: "-a", want: "@-a"},
		// i=4
		{s: ".a", want: "@.a"},
		// i=5
		{s: "_a", want: "@_a"},
		// i=6
		{s: "#a", want: `@\23a`},
		// i=7
		{s: "a b#c", want: `@a\20b\23c`},
		// i=8
		{s: "2", want: "@2"},
		// i=9
		{s: "foo世bar", want: `@foo\E4\B8\96bar`},
	}

	for i, g := range golden {
		got := enc.Global(g.s)
		if got != g.want {
			t.Errorf("i=%d: name mismatch; expected %q, got %q", i, g.want, got)
		}
	}
}
示例#2
0
文件: global.go 项目: llir/llvm
// String returns the string representation of the global variable declaration.
func (d *GlobalDecl) String() string {
	immutableSpec := "global"
	if d.Immutable() {
		immutableSpec = "constant"
	}

	// External global variable declaration; e.g.
	//    @y = external global i32
	if d.val == nil {
		return fmt.Sprintf("%s = external %s %s", enc.Global(d.Name()), immutableSpec, d.Underlying())
	}

	// Global variable definition; e.g.
	//     @x = global i32 42
	//     @s = constant [13 x i8] c"hello world\0A\00"
	return fmt.Sprintf("%s = %s %s %s", enc.Global(d.Name()), immutableSpec, d.Underlying(), d.Value().ValueString())
}
示例#3
0
文件: other.go 项目: llir/llvm
// String returns the string representation of the instruction.
func (inst *Call) String() string {
	argsBuf := new(bytes.Buffer)
	for i, arg := range inst.args {
		if i > 0 {
			argsBuf.WriteString(", ")
		}
		fmt.Fprintf(argsBuf, "%s %s", arg.Type(), arg.ValueString())
	}
	// TODO: Use inst.callee.ValueString() rather than enc.Global(inst.callee),
	// once the type of callee is changed to NamedValue or *ir.Function.
	return fmt.Sprintf("call %s %s(%s)", inst.result, enc.Global(inst.callee), argsBuf)
}
示例#4
0
文件: enc_test.go 项目: llir/llvm
func BenchmarkGlobalReplace(b *testing.B) {
	for i := 0; i < b.N; i++ {
		enc.Global("$foo bar#baz")
	}
}
示例#5
0
文件: global.go 项目: llir/llvm
// ValueString returns a string representation of the value.
func (d *GlobalDecl) ValueString() string {
	return enc.Global(d.Name())
}
示例#6
0
文件: function.go 项目: llir/llvm
// ValueString returns a string representation of the value.
func (f *Function) ValueString() string {
	return enc.Global(f.Name())
}
示例#7
0
文件: basic.go 项目: llir/llvm
// String returns a string representation of the pointer constant; e.g.
//
//    @printf
func (v *Pointer) String() string {
	return enc.Global(v.name)
}