Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/andybalholm/leaven

go 1.13

require github.com/llir/llvm v0.3.0-pre7
require (
github.com/llir/llvm v0.3.0
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8
)
45 changes: 26 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inspirer/textmapper v0.0.0-20181224220124-bad2c4921a6b/go.mod h1:SpoIwXu07A3gguovN379QUCTHpUk1lhX2KIjVxpQOas=
github.com/inspirer/textmapper v0.0.0-20190101225825-ae0b38e27780/go.mod h1:SpoIwXu07A3gguovN379QUCTHpUk1lhX2KIjVxpQOas=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/llir/ll v0.0.0-20190101214934-d9b443a40870 h1:DSsVvRMBVpcLvpMrQtPEE7Ld/8601iqtVGv9a9neMCk=
github.com/llir/ll v0.0.0-20190101214934-d9b443a40870/go.mod h1:QSnTUqiZQX2N59KdP8TIEveBZldlGN7ypCN3fiie5WA=
github.com/llir/llvm v0.3.0-pre7 h1:zTzXeXXNVllvHlPS9hIy56A0Nvu2qC4ouh0z8vHvw8g=
github.com/llir/llvm v0.3.0-pre7/go.mod h1:cjDv5v+hXwGbEFpgg/wrrKc3Taq7PLwJUF9RHr/GIDU=
github.com/mewkiz/pkg v0.0.0-20181231041609-5720a0c5985d/go.mod h1:bhmdGJSMX5WCIBFmk27tBnUvBJm5WxXmarBV41qvbNI=
github.com/mewmew/float v0.0.0-20181121163145-c0f786d7da73 h1:bTqCgPsW3TFb9MFtvaOmGFWVhCmN3EmRw02zkchdOHo=
github.com/mewmew/float v0.0.0-20181121163145-c0f786d7da73/go.mod h1:obQBs6O+vjhgOZLkGdALxItKw4xrI49lSBEnAMO6lWI=
github.com/mewspring/tools v0.0.0-20181204020634-6c6637dc82b6/go.mod h1:UAdVbSksr+7Bg+z4mga16OaBg3qAcgdaF3x3AeqJHEs=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rickypai/natsort v0.0.0-20180124032556-f194e6bd5b0c h1:wq5MmT1Whub72MXlR2I5jWTQ3Q5wkNXnVBY21Q3Qzis=
github.com/rickypai/natsort v0.0.0-20180124032556-f194e6bd5b0c/go.mod h1:ECfieXu+EwvGnmpzRZvaAN0U/Jese1LX/BqX3HF1Kl0=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/tools v0.0.0-20190102213336-ca9055ed7d04/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/llir/ll v0.0.0-20191229032745-05be70ade156 h1:tQ3EaDUy4rHvIyvuI2Yf1X2xPMVi4orBwX3H1NSWp74=
github.com/llir/ll v0.0.0-20191229032745-05be70ade156/go.mod h1:8W5HJz80PitAyPZUpOcljQxTu6LD5YKW1URTo+OjVoc=
github.com/llir/llvm v0.3.0 h1:A4lHTPerMXrHYWJZF80XsnerraV8PKEqhBG+4wedSHg=
github.com/llir/llvm v0.3.0/go.mod h1:yjHRZjO9xc1uLUS69qO2qYjS95XFdfd2odSdSnufS10=
github.com/mewmew/float v0.0.0-20191226120903-16bbe2fdd85e h1:KCD7E/8LKwDsC5ymlEWJ3xCiSPaCywrS/psToBMOBH4=
github.com/mewmew/float v0.0.0-20191226120903-16bbe2fdd85e/go.mod h1:O+xb+8ycBNHzJicFVs7GRWtruD4tVZI0huVnw5TM01E=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8 h1:JA8d3MPx/IToSyXZG/RhwYEtfrKO1Fxrqe8KrkiLXKM=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4 h1:Toz2IK7k8rbltAXwNAxKcn9OzqyNfMUhUNjz3sL0NMk=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10 changes: 5 additions & 5 deletions instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ func TranslateInstruction(inst ir.Instruction) (string, error) {
if err != nil {
return "", fmt.Errorf("error translating condition (%v): %v", inst.Cond, err)
}
x, err := FormatValue(inst.X)
valueTrue, err := FormatValue(inst.ValueTrue)
if err != nil {
return "", fmt.Errorf("error translating first operand (%v): %v", inst.X, err)
return "", fmt.Errorf("error translating first operand (%v): %v", inst.ValueTrue, err)
}
y, err := FormatValue(inst.Y)
valueFalse, err := FormatValue(inst.ValueFalse)
if err != nil {
return "", fmt.Errorf("error translating second operand (%v): %v", inst.Y, err)
return "", fmt.Errorf("error translating second operand (%v): %v", inst.ValueFalse, err)
}
name := VariableName(inst)
return fmt.Sprintf("if %s { %s = %s } else { %s = %s }", cond, name, x, name, y), nil
return fmt.Sprintf("if %s { %s = %s } else { %s = %s }", cond, name, valueTrue, name, valueFalse), nil

case *ir.InstSExt:
toType, ok := inst.To.(*types.IntType)
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ func main() {
// PhiAssignments returns an assignment statement expressing the effects of Phi
// nodes on the branch from block a to block b. If block b has no phi nodes,
// it returns the empty string.
func PhiAssignments(a, b *ir.Block) (string, error) {
func PhiAssignments(a, b value.Value) (string, error) {
var dest, src []string
for _, inst := range b.Insts {
for _, inst := range b.(*ir.Block).Insts {
phi, ok := inst.(*ir.InstPhi)
if !ok {
break
Expand Down
7 changes: 4 additions & 3 deletions variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ func VariableName(v value.Named) string {
return name
}

func BlockName(v *ir.Block) string {
name := v.Name()
func BlockName(v value.Value) string {
block := v.(*ir.Block)
name := block.Name()
if name == "" {
return "block" + strings.TrimPrefix(v.Ident(), "%")
return "block" + strings.TrimPrefix(block.Ident(), "%")
}
if c := name[0]; '0' <= c && c <= '9' {
name = "block" + name
Expand Down