Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major: minimaze error #4

Merged
merged 1 commit into from
Dec 21, 2018
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
125 changes: 66 additions & 59 deletions fortran/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
goast "go/ast"
goparser "go/parser"
"go/token"
"os"
"strconv"
"strings"
)
Expand Down Expand Up @@ -393,7 +394,7 @@ func (p *parser) parseNodes() (decls []goast.Decl) {
p.ns = comb
p.ident--

p.addError(fmt.Sprintf("Add fake PROGRAM MAIN in pos : %v", p.ns[p.ident].pos))
fmt.Fprintf(os.Stdout, "Add fake PROGRAM MAIN in pos : %v", p.ns[p.ident].pos)
}

return
Expand Down Expand Up @@ -1582,24 +1583,53 @@ func (p *parser) parseData() (stmts []goast.Stmt) {
// LL - value
// LL - vector fully
// LL - matrix fully
if v, ok := p.initVars.get(nodesToString(name)); ok {
lenArray := p.getArrayLen(v.name)
isByte := v.typ.getBaseType() == "byte"
switch lenArray {
case 0:
v, ok := p.initVars.get(nodesToString(name))
if !ok {
p.initVars.add(nodesToString(name), goType{
baseType: "float64",
})
v, _ = p.initVars.get(nodesToString(name))
}
lenArray := p.getArrayLen(v.name)
isByte := v.typ.getBaseType() == "byte"
switch lenArray {
case 0:
nameExpr = append(nameExpr, tExpr{
expr: p.parseExprNodes(name),
isByte: isByte,
})
case 1: // vector
size, ok := p.getSize(v.name, 0)
if !ok {
panic("Not ok : " + v.name)
}
for i := 0; i < size; i++ {
nameExpr = append(nameExpr, tExpr{
expr: p.parseExprNodes(name),
isByte: isByte,
})
case 1: // vector
size, ok := p.getSize(v.name, 0)
if !ok {
panic("Not ok : " + v.name)
}
for i := 0; i < size; i++ {
expr: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(i),
},
},
isByte: isByte})
}
case 2: // matrix
size0, _ := p.getSize(v.name, 0)
size1, _ := p.getSize(v.name, 1)
for i := 0; i < size0; i++ {
for j := 0; j < size1; j++ {
nameExpr = append(nameExpr, tExpr{
expr: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
X: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(j),
},
},
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Expand All @@ -1608,15 +1638,25 @@ func (p *parser) parseData() (stmts []goast.Stmt) {
},
isByte: isByte})
}
case 2: // matrix
size0, _ := p.getSize(v.name, 0)
size1, _ := p.getSize(v.name, 1)
for i := 0; i < size0; i++ {
for j := 0; j < size1; j++ {
}
case 3: //matrix ()()()
size0, _ := p.getSize(v.name, 0)
size1, _ := p.getSize(v.name, 1)
size2, _ := p.getSize(v.name, 2)
for k := 0; k < size2; k++ {
for j := 0; j < size1; j++ {
for i := 0; i < size0; i++ {
nameExpr = append(nameExpr, tExpr{
expr: &goast.IndexExpr{
X: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
X: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(i),
},
},
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Expand All @@ -1626,50 +1666,17 @@ func (p *parser) parseData() (stmts []goast.Stmt) {
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(i),
Value: strconv.Itoa(k),
},
},
isByte: isByte})
}
}
case 3: //matrix ()()()
size0, _ := p.getSize(v.name, 0)
size1, _ := p.getSize(v.name, 1)
size2, _ := p.getSize(v.name, 2)
for k := 0; k < size2; k++ {
for j := 0; j < size1; j++ {
for i := 0; i < size0; i++ {
nameExpr = append(nameExpr, tExpr{
expr: &goast.IndexExpr{
X: &goast.IndexExpr{
X: &goast.IndexExpr{
X: goast.NewIdent(nodesToString(name)),
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(i),
},
},
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(j),
},
},
Lbrack: 1,
Index: &goast.BasicLit{
Kind: token.INT,
Value: strconv.Itoa(k),
},
},
isByte: isByte})
}
}
}
default:
panic("Not acceptable type : " + nodesToString(name))
}
default:
panic("Not acceptable type : " + nodesToString(name))
}

continue
}
if v, ok := p.initVars.get(string(name[0].b)); ok {
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"go/format"
"go/token"
"io/ioutil"
"os/exec"
"runtime"
"strings"

Expand All @@ -25,8 +26,9 @@ func main() {
func run() {
flag.Parse()

if flag.NFlag() == 0 {
flag.PrintDefaults()
if flag.NArg() < 1 {
flag.Usage()
return
}

if packageFlag == nil {
Expand Down Expand Up @@ -87,11 +89,19 @@ func parse(filename, packageName, goFilename string) []errorRow {
}
}

fmt.Println("\n\ngenerate : ", goFilename)

// save go source
if err = ioutil.WriteFile(goFilename, buf.Bytes(), 0644); err != nil {
return []errorRow{{err: fmt.Errorf("Cannot write Go source: %v", err), filename: filename}}
}

// gofmt simplification
_, _ = exec.Command("gofmt", "-s", "-w", goFilename).CombinedOutput()

// goimports
_, _ = exec.Command("goimport", "-w", goFilename).CombinedOutput()

return nil
}

Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func TestIntegration(t *testing.T) {
}

if !bytes.Equal(fortranOutput, goOutput) {
// t.Errorf("Results is not same: `%v` != `%v`",
// string(fortranOutput),
// string(goOutput))
t.Errorf("Results is not same :\n`%v`\n`%v`",
string(fortranOutput),
string(goOutput))
fortLines := bytes.Split(fortranOutput, []byte("\n"))
goLines := bytes.Split(goOutput, []byte("\n"))
if len(fortLines) != len(goLines) {
Expand All @@ -72,7 +72,7 @@ func TestIntegration(t *testing.T) {
}
for i := 0; i < length; i++ {
if !bytes.Equal(fortLines[i], goLines[i]) {
t.Errorf("Results is not same in line %d: `%v` != `%v`",
t.Errorf("Results is not same in line %d: `%v`\n`%v`",
i,
string(fortLines[i]),
string(goLines[i]))
Expand Down
1 change: 1 addition & 0 deletions testdata/blas/blas/caxpy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package main

//*> \brief \b CAXPY
//*
//* =========== DOCUMENTATION ===========
Expand Down
1 change: 1 addition & 0 deletions testdata/blas/blas/ccopy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package main

//*> \brief \b CCOPY
//*
//* =========== DOCUMENTATION ===========
Expand Down
1 change: 1 addition & 0 deletions testdata/blas/blas/cdotc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import "github.com/Konstantin8105/f4go/intrinsic"

//*> \brief \b CDOTC
//*
//* =========== DOCUMENTATION ===========
Expand Down
1 change: 1 addition & 0 deletions testdata/blas/blas/cdotu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package main

//*> \brief \b CDOTU
//*
//* =========== DOCUMENTATION ===========
Expand Down
11 changes: 6 additions & 5 deletions testdata/blas/blas/cgbmv.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import "github.com/Konstantin8105/f4go/intrinsic"

//*> \brief \b CGBMV
//*
//* =========== DOCUMENTATION ===========
Expand Down Expand Up @@ -233,7 +234,7 @@ func CGBMV(TRANS *byte, M *int, N *int, KL *int, KU *int, ALPHA *complex64, A *[
//* Test the input parameters.
//*
INFO = 0
if !LSAME(TRANS, func()*byte{y:=byte('N');return &y}()) && !LSAME(TRANS, func()*byte{y:=byte('T');return &y}()) && !LSAME(TRANS, func()*byte{y:=byte('C');return &y}()) {
if !LSAME(TRANS, func() *byte { y := byte('N'); return &y }()) && !LSAME(TRANS, func() *byte { y := byte('T'); return &y }()) && !LSAME(TRANS, func() *byte { y := byte('C'); return &y }()) {
INFO = 1
} else if (*M) < 0 {
INFO = 2
Expand All @@ -251,7 +252,7 @@ func CGBMV(TRANS *byte, M *int, N *int, KL *int, KU *int, ALPHA *complex64, A *[
INFO = 13
}
if INFO != 0 {
XERBLA(func()*[]byte{y:=[]byte("CGBMV ");return &y}(), &(INFO))
XERBLA(func() *[]byte { y := []byte("CGBMV "); return &y }(), &(INFO))
return
}
//*
Expand All @@ -261,12 +262,12 @@ func CGBMV(TRANS *byte, M *int, N *int, KL *int, KU *int, ALPHA *complex64, A *[
return
}
//*
NOCONJ = LSAME(TRANS, func()*byte{y:=byte('T');return &y}())
NOCONJ = LSAME(TRANS, func() *byte { y := byte('T'); return &y }())
//*
//* Set LENX and LENY, the lengths of the vectors x and y, and set
//* up the start points in X and Y.
//*
if LSAME(TRANS, func()*byte{y:=byte('N');return &y}()) {
if LSAME(TRANS, func() *byte { y := byte('N'); return &y }()) {
LENX = (*N)
LENY = (*M)
} else {
Expand Down Expand Up @@ -319,7 +320,7 @@ func CGBMV(TRANS *byte, M *int, N *int, KL *int, KU *int, ALPHA *complex64, A *[
return
}
KUP1 = (*KU) + 1
if LSAME(TRANS, func()*byte{y:=byte('N');return &y}()) {
if LSAME(TRANS, func() *byte { y := byte('N'); return &y }()) {
//*
//* Form y := alpha*A*x + y.
//*
Expand Down
15 changes: 8 additions & 7 deletions testdata/blas/blas/cgemm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import "github.com/Konstantin8105/f4go/intrinsic"

//*> \brief \b CGEMM
//*
//* =========== DOCUMENTATION ===========
Expand Down Expand Up @@ -233,10 +234,10 @@ func CGEMM(TRANSA *byte, TRANSB *byte, M *int, N *int, K *int, ALPHA *complex64,
//* NROWA, NCOLA and NROWB as the number of rows and columns of A
//* and the number of rows of B respectively.
//*
NOTA = LSAME(TRANSA, func()*byte{y:=byte('N');return &y}())
NOTB = LSAME(TRANSB, func()*byte{y:=byte('N');return &y}())
CONJA = LSAME(TRANSA, func()*byte{y:=byte('C');return &y}())
CONJB = LSAME(TRANSB, func()*byte{y:=byte('C');return &y}())
NOTA = LSAME(TRANSA, func() *byte { y := byte('N'); return &y }())
NOTB = LSAME(TRANSB, func() *byte { y := byte('N'); return &y }())
CONJA = LSAME(TRANSA, func() *byte { y := byte('C'); return &y }())
CONJB = LSAME(TRANSB, func() *byte { y := byte('C'); return &y }())
if NOTA {
NROWA = (*M)
NCOLA = (*K)
Expand All @@ -253,9 +254,9 @@ func CGEMM(TRANSA *byte, TRANSB *byte, M *int, N *int, K *int, ALPHA *complex64,
//* Test the input parameters.
//*
INFO = 0
if (!NOTA) && (!CONJA) && (!LSAME(TRANSA, func()*byte{y:=byte('T');return &y}())) {
if (!NOTA) && (!CONJA) && (!LSAME(TRANSA, func() *byte { y := byte('T'); return &y }())) {
INFO = 1
} else if (!NOTB) && (!CONJB) && (!LSAME(TRANSB, func()*byte{y:=byte('T');return &y}())) {
} else if (!NOTB) && (!CONJB) && (!LSAME(TRANSB, func() *byte { y := byte('T'); return &y }())) {
INFO = 2
} else if (*M) < 0 {
INFO = 3
Expand All @@ -271,7 +272,7 @@ func CGEMM(TRANSA *byte, TRANSB *byte, M *int, N *int, K *int, ALPHA *complex64,
INFO = 13
}
if INFO != 0 {
XERBLA(func()*[]byte{y:=[]byte("CGEMM ");return &y}(), &(INFO))
XERBLA(func() *[]byte { y := []byte("CGEMM "); return &y }(), &(INFO))
return
}
//*
Expand Down
Loading