fspl/llvm/global.go

68 lines
1.4 KiB
Go

package llvm
import "fmt"
import "strings"
type Global struct {
Ty Type
GlobalName string
Constant bool
Initial Const
AddressSpace AddressSpace
// TODO complete this
}
func (this *Global) IsConstant () {
// FIXME globals are not always constant... perhaps there is a better
// way of doing this? maybe making a separate type ConstGlobal that
// embeds Global? would have to do away with Constant member.
}
func (this *Global) Type () Type {
return &TypePointer {
AddressSpace: this.AddressSpace,
}
}
func (this *Global) Named () bool {
return this.GlobalName != ""
}
func (this *Global) Name () string {
return this.GlobalName
}
func (this *Global) Identifier () string {
return EncodeGlobalName(this.Name())
}
func (this *Global) SetName (name string) {
this.GlobalName = name
}
func (this *Global) String () string {
return fmt.Sprintf("%v %v", this.Ty, this.Identifier())
}
func (this *Global) LLString () string {
buffer := &strings.Builder { }
buffer.WriteString(this.Name())
buffer.WriteString(" = ")
if this.AddressSpace != 0 {
fmt.Fprintf(buffer, " %v", this.AddressSpace)
}
if this.Constant {
buffer.WriteString(" constant")
} else {
buffer.WriteString(" global")
}
fmt.Fprintf(buffer, " %v", this.Ty)
if this.Initial != nil {
fmt.Fprintf(buffer, " %v", this.Initial)
}
buffer.WriteString("\n")
return buffer.String()
}