Various fixes
This commit is contained in:
parent
7690f683a4
commit
3b9ed0c35f
|
@ -10,7 +10,6 @@ type blockManager struct {
|
|||
declarations map[*entity.Declaration] llvm.Value
|
||||
}
|
||||
|
||||
// TODO make it a stackkkk
|
||||
func (this *generator) pushBlockManager (function *llvm.Function) *blockManager {
|
||||
manager := new(blockManager)
|
||||
this.managerStack = append(this.managerStack, manager)
|
||||
|
|
|
@ -173,9 +173,7 @@ func (this *generator) generateLiteralArray (literal *entity.LiteralArray) (llvm
|
|||
ty := ty.(*entity.TypePointer)
|
||||
array, err := makeData(ty.Referenced)
|
||||
if err != nil { return nil, err }
|
||||
pointer := this.blockManager.NewAlloca(llvm.Pointer)
|
||||
this.blockManager.NewStore(array, pointer)
|
||||
return pointer, nil
|
||||
return array, nil
|
||||
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintln("array can't be used as ", ty))
|
||||
|
|
|
@ -8,8 +8,10 @@ testString (test,
|
|||
`,
|
||||
`
|
||||
[puts string:*Byte]:I32
|
||||
[main] = {
|
||||
[puts (* 72 101 101 101 111 101 100 0)]
|
||||
[main argc:I32 argv:**Byte]:I32 = {
|
||||
[puts [. argv]]
|
||||
0
|
||||
}
|
||||
`)
|
||||
}
|
||||
// [write 1 (* 72 101 108 108 111 114 108 100 0) 7]
|
||||
|
|
|
@ -24,9 +24,10 @@ type ConstArray struct {
|
|||
func (*ConstArray) IsConstant () { }
|
||||
func (this *ConstArray) Type () Type { return this.Ty }
|
||||
func (this *ConstArray) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstArray) Name () string {
|
||||
func (this *ConstArray) Name () string { return this.Identifier() }
|
||||
func (this *ConstArray) Identifier () string {
|
||||
buf := &strings.Builder{}
|
||||
buf.WriteString("[")
|
||||
for i, elem := range this.Elements {
|
||||
|
@ -46,9 +47,10 @@ type ConstBlockAddress struct {
|
|||
func (*ConstBlockAddress) IsConstant ( ) { }
|
||||
func (this *ConstBlockAddress) Type () Type { return &TypePointer { } }
|
||||
func (this *ConstBlockAddress) String () string {
|
||||
return fmt.Sprintf("%v %v", &TypePointer { }, this.Name())
|
||||
return fmt.Sprintf("%v %v", &TypePointer { }, this.Identifier())
|
||||
}
|
||||
func (this *ConstBlockAddress) Name () string {
|
||||
func (this *ConstBlockAddress) Name () string { return this.Identifier() }
|
||||
func (this *ConstBlockAddress) Identifier () string {
|
||||
return fmt.Sprintf("blockaddress(%s, %s)", this.Function.Name(), this.Block.Name())
|
||||
}
|
||||
|
||||
|
@ -59,9 +61,10 @@ type ConstCharArray struct {
|
|||
func (*ConstCharArray) IsConstant () { }
|
||||
func (this *ConstCharArray) Type () Type { return this.Ty }
|
||||
func (this *ConstCharArray) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstCharArray) Name () string {
|
||||
func (this *ConstCharArray) Name () string { return this.Identifier() }
|
||||
func (this *ConstCharArray) Identifier () string {
|
||||
return "c" + EscapeQuoteString(this.Elements)
|
||||
}
|
||||
|
||||
|
@ -71,9 +74,10 @@ type ConstDSOLocalEquivalent struct {
|
|||
func (*ConstDSOLocalEquivalent) IsConstant () { }
|
||||
func (this *ConstDSOLocalEquivalent) Type () Type { return this.Function.Type() }
|
||||
func (this *ConstDSOLocalEquivalent) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstDSOLocalEquivalent) Name () string {
|
||||
func (this *ConstDSOLocalEquivalent) Name () string { return this.Identifier() }
|
||||
func (this *ConstDSOLocalEquivalent) Identifier () string {
|
||||
return fmt.Sprintf("dso_local_equivalent %s", this.Function.Name())
|
||||
}
|
||||
|
||||
|
@ -98,10 +102,11 @@ func NewConstFloat (ty *TypeFloat, value float64) *ConstFloat {
|
|||
}
|
||||
func (*ConstFloat) IsConstant () { }
|
||||
func (this *ConstFloat) Type () Type { return this.Ty }
|
||||
func (this *ConstFloat) Name () string { return this.Identifier() }
|
||||
func (this *ConstFloat) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstFloat) Name () string {
|
||||
func (this *ConstFloat) Identifier () string {
|
||||
// FloatLit
|
||||
//
|
||||
// Print hexadecimal representation of floating-point literal if NaN, Inf,
|
||||
|
@ -267,7 +272,8 @@ type ConstIndex struct {
|
|||
Const
|
||||
InRange bool
|
||||
}
|
||||
func (this *ConstIndex) String () string {
|
||||
func (this *ConstIndex) Name () string { return this.Identifier() }
|
||||
func (this *ConstIndex) Identifier () string {
|
||||
// OptInrange Type Constant
|
||||
if this.InRange {
|
||||
return fmt.Sprintf("inrange %s", this.Const)
|
||||
|
@ -293,9 +299,10 @@ func NewConstBool (value bool) *ConstInt {
|
|||
func (*ConstInt) IsConstant () { }
|
||||
func (this *ConstInt) Type () Type { return this.Ty }
|
||||
func (this *ConstInt) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstInt) Name () string {
|
||||
func (this *ConstInt) Name () string { return this.Identifier() }
|
||||
func (this *ConstInt) Identifier () string {
|
||||
// IntLit
|
||||
if this.Ty.BitSize == 1 {
|
||||
// "true"
|
||||
|
@ -413,19 +420,21 @@ type ConstNoCFI struct {
|
|||
func (*ConstNoCFI) IsConstant () { }
|
||||
func (this *ConstNoCFI) Type () Type { return this.Function.Type() }
|
||||
func (this *ConstNoCFI) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstNoCFI) Name () string {
|
||||
return fmt.Sprintf("no_cfi %s", this.Function.Name())
|
||||
func (this *ConstNoCFI) Name () string { return this.Identifier() }
|
||||
func (this *ConstNoCFI) Identifier () string {
|
||||
return fmt.Sprintf("no_cfi %s", this.Function.Identifier())
|
||||
}
|
||||
|
||||
type ConstNull struct { }
|
||||
func (*ConstNull) IsConstant () { }
|
||||
func (*ConstNull) Type () Type { return &TypePointer { } }
|
||||
func (this *ConstNull) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstNull) Name () string { return "null" }
|
||||
func (this *ConstNull) Name () string { return this.Identifier() }
|
||||
func (this *ConstNull) Identifier () string { return "null" }
|
||||
|
||||
type ConstPoison struct {
|
||||
Ty Type
|
||||
|
@ -433,9 +442,10 @@ type ConstPoison struct {
|
|||
func (*ConstPoison) IsConstant () { }
|
||||
func (this *ConstPoison) Type () Type { return this.Ty }
|
||||
func (this *ConstPoison) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstPoison) Name () string { return "poison" }
|
||||
func (this *ConstPoison) Name () string { return this.Identifier() }
|
||||
func (this *ConstPoison) Identifier () string { return "poison" }
|
||||
|
||||
type ConstStruct struct {
|
||||
Ty *TypeStruct
|
||||
|
@ -444,9 +454,10 @@ type ConstStruct struct {
|
|||
func (*ConstStruct) IsConstant () { }
|
||||
func (this *ConstStruct) Type () Type { return this.Ty }
|
||||
func (this *ConstStruct) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstStruct) Name () string {
|
||||
func (this *ConstStruct) Name () string { return this.Identifier() }
|
||||
func (this *ConstStruct) Identifier () string {
|
||||
buf := &strings.Builder{}
|
||||
if this.Ty.Packed {
|
||||
buf.WriteString("<")
|
||||
|
@ -471,9 +482,10 @@ type ConstUndef struct {
|
|||
func (*ConstUndef) IsConstant () { }
|
||||
func (this *ConstUndef) Type () Type { return this.Ty }
|
||||
func (this *ConstUndef) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstUndef) Name () string { return "undef" }
|
||||
func (this *ConstUndef) Name () string { return this.Identifier() }
|
||||
func (this *ConstUndef) Identifier () string { return "undef" }
|
||||
|
||||
type ConstVector struct {
|
||||
Ty *TypeVector
|
||||
|
@ -482,9 +494,10 @@ type ConstVector struct {
|
|||
func (*ConstVector) IsConstant () { }
|
||||
func (this *ConstVector) Type () Type { return this.Ty }
|
||||
func (this *ConstVector) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstVector) Name () string {
|
||||
func (this *ConstVector) Name () string { return this.Identifier() }
|
||||
func (this *ConstVector) Identifier () string {
|
||||
buf := &strings.Builder{}
|
||||
buf.WriteString("<")
|
||||
for i, elem := range this.Elements {
|
||||
|
@ -503,6 +516,7 @@ type ConstZeroInitializer struct {
|
|||
func (*ConstZeroInitializer) IsConstant () { }
|
||||
func (this *ConstZeroInitializer) Type () Type { return this.Ty }
|
||||
func (this *ConstZeroInitializer) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Type(), this.Identifier())
|
||||
}
|
||||
func (this *ConstZeroInitializer) Name () string { return "zeroinitializer" }
|
||||
func (this *ConstZeroInitializer) Name () string { return this.Identifier() }
|
||||
func (this *ConstZeroInitializer) Identifier () string { return "zeroinitializer" }
|
||||
|
|
|
@ -73,18 +73,22 @@ func (this *Function) Name () string {
|
|||
return this.FunctionName
|
||||
}
|
||||
|
||||
func (this *Function) Identifier () string {
|
||||
return EncodeFunctionName(this.Name())
|
||||
}
|
||||
|
||||
func (this *Function) SetName (name string) {
|
||||
this.FunctionName = name
|
||||
}
|
||||
|
||||
func (this *Function) String () string {
|
||||
return fmt.Sprintf("ptr %v", EncodeFunctionName(this.Name()))
|
||||
return fmt.Sprintf("ptr %v", this.Identifier())
|
||||
}
|
||||
|
||||
func (this *Function) headerString () string {
|
||||
buffer := &strings.Builder { }
|
||||
fmt.Fprintf(buffer, " %v", this.Signature.Return)
|
||||
fmt.Fprintf(buffer, " %v(", EncodeFunctionName(this.Name()))
|
||||
fmt.Fprintf(buffer, " %v(", this.Identifier())
|
||||
for index, param := range this.Parameters {
|
||||
if index > 0 { buffer.WriteString(", ") }
|
||||
buffer.WriteString(param.LLString())
|
||||
|
@ -123,13 +127,17 @@ type Block struct {
|
|||
|
||||
func (this *Block) LLString () string {
|
||||
buffer := &strings.Builder { }
|
||||
fmt.Fprintf(buffer, "%s\n", EncodeLabelName(this.Name))
|
||||
fmt.Fprintf(buffer, "%s:\n", this.Name)
|
||||
for _, instruction := range this.Instructions {
|
||||
fmt.Fprintf(buffer, "\t%s\n", instruction.LLString())
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
func (this *Block) Identifier () string {
|
||||
return EncodeRegisterName(this.Name)
|
||||
}
|
||||
|
||||
func (this *Block) AddInstruction (instruction Instruction) {
|
||||
if instruction, ok := instruction.(ValueInstruction); ok {
|
||||
instruction.SetName(this.Parent.newIdent())
|
||||
|
|
|
@ -25,7 +25,7 @@ type AbstractInstructionBinary struct {
|
|||
func (this *AbstractInstructionBinary) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.Named () {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString(this.Token)
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y)
|
||||
|
@ -39,7 +39,7 @@ type AbstractInstructionBinaryFP struct {
|
|||
|
||||
func (this *AbstractInstructionBinaryFP) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString(this.Token)
|
||||
for _, flag := range this.FastMathFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
|
@ -58,7 +58,7 @@ type AbstractInstructionCast struct {
|
|||
func (this *AbstractInstructionCast) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.Named () {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString(this.Token)
|
||||
fmt.Fprintf(buf, " %s to %s", this.From, this.To)
|
||||
|
@ -73,7 +73,7 @@ type AbstractInstructionBinaryExact struct {
|
|||
func (this *AbstractInstructionBinaryExact) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.Named () {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString(this.Token)
|
||||
if this.Exact { buf.WriteString(" exact") }
|
||||
|
@ -145,7 +145,7 @@ func (this *Block) NewAlloca (element Type) *InstructionAlloca {
|
|||
|
||||
func (this *InstructionAlloca) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("alloca")
|
||||
if this.InAlloca {
|
||||
buf.WriteString(" inalloca")
|
||||
|
@ -261,7 +261,7 @@ func (this *Block) NewAtomicRMW (op AtomicOp, destination, x Value, ordering Ato
|
|||
|
||||
func (this *InstructionAtomicRMW) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("atomicrmw")
|
||||
if this.Volatile {
|
||||
buf.WriteString(" volatile")
|
||||
|
@ -283,7 +283,7 @@ type InstructionBitCast struct {
|
|||
func (this *InstructionBitCast) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.Named () {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString("bitcast")
|
||||
fmt.Fprintf(buf, " %s to %s", this.From, this.To)
|
||||
|
@ -310,7 +310,7 @@ type InstructionCall struct {
|
|||
func (this *InstructionCall) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
if _, ok := this.Type().(*TypeVoid); !ok {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString("call")
|
||||
// (optional) Address space.
|
||||
|
@ -322,7 +322,7 @@ func (this *InstructionCall) LLString () string {
|
|||
if sig := this.Signature; sig.Variadic {
|
||||
calleeType = sig
|
||||
}
|
||||
fmt.Fprintf(buf, " %s %s(", calleeType, this.Callee)
|
||||
fmt.Fprintf(buf, " %s %s(", calleeType, this.Callee.Identifier())
|
||||
for index, arg := range this.Arguments {
|
||||
if index > 0 {
|
||||
buf.WriteString(", ")
|
||||
|
@ -356,7 +356,7 @@ type InstructionCatchPad struct {
|
|||
|
||||
func (this *InstructionCatchPad) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "catchpad within %s [", this.CatchSwitch)
|
||||
for index, arg := range this.Arguments {
|
||||
if index > 0 {
|
||||
|
@ -386,7 +386,7 @@ type InstructionCleanupPad struct {
|
|||
|
||||
func (this *InstructionCleanupPad) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "cleanuppad within %s [", this.ParentPad)
|
||||
for index, arg := range this.Arguments {
|
||||
if index > 0 {
|
||||
|
@ -422,7 +422,7 @@ type InstructionCmpXchg struct {
|
|||
|
||||
func (this *InstructionCmpXchg) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("cmpxchg")
|
||||
if this.Weak {
|
||||
buf.WriteString(" weak")
|
||||
|
@ -463,7 +463,7 @@ type InstructionExtractElement struct {
|
|||
|
||||
func (this *InstructionExtractElement) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "extractelement %s, %s", this.X, this.Index)
|
||||
return buf.String()
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ type InstructionExtractValue struct {
|
|||
|
||||
func (this *InstructionExtractValue) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "extractvalue %s", this.X)
|
||||
for _, index := range this.Indices {
|
||||
fmt.Fprintf(buf, ", %d", index)
|
||||
|
@ -588,12 +588,12 @@ type InstructionFCmp struct {
|
|||
|
||||
func (this *InstructionFCmp) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("fcmp")
|
||||
for _, flag := range this.FastMathFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
}
|
||||
fmt.Fprintf(buf, " %s %s, %s", this.Predicate, this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s %s, %s", this.Predicate, this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -653,7 +653,7 @@ type InstructionFNeg struct {
|
|||
|
||||
func (this *InstructionFNeg) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("fneg")
|
||||
for _, flag := range this.FastMathFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
|
@ -782,7 +782,7 @@ type InstructionFreeze struct {
|
|||
|
||||
func (this *InstructionFreeze) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "freeze %s", this.X)
|
||||
return buf.String()
|
||||
}
|
||||
|
@ -804,7 +804,7 @@ type InstructionGetElementPtr struct {
|
|||
|
||||
func (this *InstructionGetElementPtr) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("getelementptr")
|
||||
if this.InBounds {
|
||||
buf.WriteString(" inbounds")
|
||||
|
@ -863,9 +863,9 @@ type InstructionICmp struct {
|
|||
|
||||
func (this *InstructionICmp) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("icmp")
|
||||
fmt.Fprintf(buf, " %s %s, %s", this.Predicate, this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s %s, %s", this.Predicate, this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -898,7 +898,7 @@ type InstructionInsertElement struct {
|
|||
|
||||
func (this *InstructionInsertElement) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "insertelement %s, %s, %s", this.X, this.Element, this.Index)
|
||||
return buf.String()
|
||||
}
|
||||
|
@ -926,7 +926,7 @@ type InstructionInsertValue struct {
|
|||
|
||||
func (this *InstructionInsertValue) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "insertvalue %s, %s", this.X, this.Element)
|
||||
for _, index := range this.Indices {
|
||||
fmt.Fprintf(buf, ", %d", index)
|
||||
|
@ -1003,7 +1003,7 @@ type InstructionLandingPad struct {
|
|||
|
||||
func (this *InstructionLandingPad) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "landingpad %s", this.Type())
|
||||
if this.Cleanup {
|
||||
buf.WriteString("\n\t\tcleanup")
|
||||
|
@ -1033,7 +1033,7 @@ type InstructionLoad struct {
|
|||
|
||||
func (this *InstructionLoad) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("load")
|
||||
if this.Atomic {
|
||||
buf.WriteString(" atomic")
|
||||
|
@ -1081,12 +1081,12 @@ type InstructionMul struct {
|
|||
|
||||
func (this *InstructionMul) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("mul")
|
||||
for _, flag := range this.OverflowFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
}
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -1120,7 +1120,7 @@ type Incoming struct {
|
|||
}
|
||||
|
||||
func (this *Incoming) String () string {
|
||||
return fmt.Sprintf("[ %s, %s ]", this.X.Name(), this.Predecessor.Name())
|
||||
return fmt.Sprintf("[ %s, %s ]", this.X.Identifier(), this.Predecessor.Identifier())
|
||||
}
|
||||
|
||||
type InstructionPhi struct {
|
||||
|
@ -1131,7 +1131,7 @@ type InstructionPhi struct {
|
|||
|
||||
func (this *InstructionPhi) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("phi ")
|
||||
for _, flag := range this.FastMathFlags {
|
||||
buf.WriteString(flag.String())
|
||||
|
@ -1179,11 +1179,11 @@ type InstructionSDiv struct {
|
|||
func (this *InstructionSDiv) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.Named () {
|
||||
fmt.Fprintf(buf, "%s = ", this.Register.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
}
|
||||
buf.WriteString("sdiv")
|
||||
if this.Exact { buf.WriteString(" exact") }
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -1249,7 +1249,7 @@ type InstructionSelect struct {
|
|||
|
||||
func (this *InstructionSelect) LLString() string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("select")
|
||||
for _, flag := range this.FastMathFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
|
@ -1275,12 +1275,12 @@ type InstructionShl struct {
|
|||
|
||||
func (this *InstructionShl) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("shl")
|
||||
for _, flag := range this.OverflowFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
}
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -1302,7 +1302,7 @@ type InstructionShuffleVector struct {
|
|||
|
||||
func (this *InstructionShuffleVector) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "shufflevector %s, %s, %s", this.X, this.Y, this.Mask)
|
||||
return buf.String()
|
||||
}
|
||||
|
@ -1375,12 +1375,12 @@ type InstructionSub struct {
|
|||
|
||||
func (this *InstructionSub) LLString () string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
buf.WriteString("sub")
|
||||
for _, flag := range this.OverflowFlags {
|
||||
fmt.Fprintf(buf, " %s", flag)
|
||||
}
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Name())
|
||||
fmt.Fprintf(buf, " %s, %s", this.X, this.Y.Identifier())
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
|
@ -1457,7 +1457,7 @@ type InstructionVAArg struct {
|
|||
|
||||
func (this *InstructionVAArg) LLString() string {
|
||||
buf := &strings.Builder{}
|
||||
fmt.Fprintf(buf, "%s = ", this.Name())
|
||||
fmt.Fprintf(buf, "%s = ", this.Identifier())
|
||||
fmt.Fprintf(buf, "va_arg %s, %s", this.List, this.Type())
|
||||
return buf.String()
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ type TerminatorRet struct {
|
|||
func (this *TerminatorRet) LLString () string {
|
||||
buf := &strings.Builder { }
|
||||
if this.X == nil {
|
||||
fmt.Fprintf(buf, "ret")
|
||||
fmt.Fprintf(buf, "ret void")
|
||||
} else {
|
||||
fmt.Fprintf(buf, "ret %s", this.X)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ type Value interface {
|
|||
fmt.Stringer
|
||||
Type () Type
|
||||
Name () string
|
||||
Identifier () string
|
||||
}
|
||||
|
||||
type Register struct {
|
||||
|
@ -22,7 +23,11 @@ func (this *Register) Named () bool {
|
|||
}
|
||||
|
||||
func (this *Register) Name () string {
|
||||
return EncodeRegisterName(this.RegisterName)
|
||||
return this.RegisterName
|
||||
}
|
||||
|
||||
func (this *Register) Identifier () string {
|
||||
return EncodeRegisterName(this.Name())
|
||||
}
|
||||
|
||||
func (this *Register) SetName (name string) {
|
||||
|
@ -30,5 +35,5 @@ func (this *Register) SetName (name string) {
|
|||
}
|
||||
|
||||
func (this *Register) String () string {
|
||||
return fmt.Sprintf("%v %v", this.Ty, this.Name())
|
||||
return fmt.Sprintf("%v %v", this.Ty, this.Identifier())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue