Commit 894a07f1 authored by Etienne Renault's avatar Etienne Renault
Browse files

Bug fix when -rers option is not available

* boilerplate/main.go, main.go: Here.
parent 710ca455
......@@ -81,7 +81,7 @@ func G2PEntry(src G2PStateType) []G2PStateType {
// Build the result by considering eventually RERS inputs
var final2 []G2PStateType = []G2PStateType{}
for i, _ := range result {
if src[G2PRersPos] != result[i][G2PRersPos] {
if G2PRersActive != 0 && src[G2PRersPos] != result[i][G2PRersPos] {
for _, e := range G2PRersValues {
result[i][G2PRersPos] = e
final2 = append(final, result[i])
......
......@@ -51,7 +51,7 @@ func variableNamesToC(variableNames []string) []ast.Expr {
// Compiles the input file `(path, src)` and writes it to `file`.
func compileTo(path string, src []byte, file *os.File,
goroutines []*goroutine.Goroutine, rers []string) (string, error) {
goroutines []*goroutine.Goroutine, rers *string) (string, error) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, src, 0)
......@@ -221,18 +221,26 @@ func compileTo(path string, src []byte, file *os.File,
// Produce array of values for RERS
var rers_values = []int{}
for _, i := range rers {
j, err := strconv.Atoi(i)
if err != nil {
panic(err)
var rers_position = 0
var rers_active = 0
if *rers != "" {
rers_active = 1
var unspacify = regexp.MustCompile(` *`)
s := strings.Split(unspacify.ReplaceAllString(*rers, ""), ";")
for _, i := range s {
j, err := strconv.Atoi(i)
if err != nil {
panic(err)
}
rers_values = append(rers_values, j)
}
rers_values = append(rers_values, j)
}
var rers_position = -1
for i, e := range meta.GetVariables() {
if strings.Contains(e, "__RERS__") {
rers_position = i
break
for i, e := range meta.GetVariables() {
if strings.Contains(e, "__RERS__") {
rers_position = i
break
}
}
}
......@@ -243,6 +251,7 @@ func compileTo(path string, src []byte, file *os.File,
res.(*ast.File),
[]ast.Decl{
// Do we want a support for RERS?
decl.Int(token.CONST, "G2PRersActive", rers_active),
decl.Int(token.CONST, "G2PRersPos", rers_position),
decl.IntArray("G2PRersValues", rers_values),
......@@ -528,9 +537,7 @@ func main() {
}
// Compile and write the package to the output file.
var unspacify = regexp.MustCompile(` *`)
s := unspacify.ReplaceAllString(*rers, "")
packageName, err := compileTo(basePackagePath, src, f, goroutines, strings.Split(s, ";"))
packageName, err := compileTo(basePackagePath, src, f, goroutines, rers)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment