Esempio n. 1
0
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)
		}
	}
}
Esempio n. 2
0
File: global.go Progetto: 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())
}
Esempio n. 3
0
File: other.go Progetto: 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)
}
Esempio n. 4
0
func BenchmarkGlobalReplace(b *testing.B) {
	for i := 0; i < b.N; i++ {
		enc.Global("$foo bar#baz")
	}
}
Esempio n. 5
0
File: global.go Progetto: llir/llvm
// ValueString returns a string representation of the value.
func (d *GlobalDecl) ValueString() string {
	return enc.Global(d.Name())
}
Esempio n. 6
0
// ValueString returns a string representation of the value.
func (f *Function) ValueString() string {
	return enc.Global(f.Name())
}
Esempio n. 7
0
File: basic.go Progetto: llir/llvm
// String returns a string representation of the pointer constant; e.g.
//
//    @printf
func (v *Pointer) String() string {
	return enc.Global(v.name)
}