Fix std.out issues with eofparse

* In stdin mode ack good code with OK
* remove or feature flag stray printlns.
* use reader to accept potentially larget contracts
This commit is contained in:
Danno Ferrin 2024-08-02 07:43:52 -06:00 committed by Marius van der Wijden
parent 9edd35cefe
commit 24c56f2a4f
3 changed files with 23 additions and 10 deletions

View file

@ -91,7 +91,7 @@ func eofParser(ctx *cli.Context) error {
}
return fmt.Errorf("err(%d): %w", errorMap[err.Error()], err)
}
fmt.Println("ok.")
fmt.Println("OK")
return nil
}
@ -138,19 +138,28 @@ func eofParser(ctx *cli.Context) error {
}
// If neither are passed in, read input from stdin.
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
t := strings.TrimSpace(scanner.Text())
if len(t) == 0 || t[0] == '#' {
reader := bufio.NewReaderSize(os.Stdin, 1024*1024)
t, err := reader.ReadString('\n')
for err == nil {
l := len(t)
if l == 0 || t[0] == '#' {
continue
}
if _, err := parseAndValidate(t, false); err != nil {
if t[l-1] == '\n' {
t = t[:l-1] // remove newline
}
_, err := parseAndValidate(t, false)
if err != nil {
if err2 := errors.Unwrap(err); err2 != nil {
err = err2
}
fmt.Fprintf(os.Stderr, "err(%d): %v\n", errorMap[err.Error()], err)
fmt.Printf("err(%d): %v\n", errorMap[err.Error()], err)
} else {
fmt.Println("OK")
}
t, err = reader.ReadString('\n')
}
println(err.Error())
return nil
}

View file

@ -180,7 +180,7 @@ func validateCode(code []byte, section int, container *Container, jt *JumpTable,
if paths, err := validateControlFlow2(code, section, container.Types, jt); err != nil {
return nil, err
} else if paths != count {
fmt.Printf("Paths: %v Count: %v\n", paths, count)
//fmt.Printf("Paths: %v Count: %v\n", paths, count)
// TODO(matt): return actual position of unreachable code
return nil, ErrUnreachableCode
}

View file

@ -30,7 +30,9 @@ func validateControlFlow2(code []byte, section int, metadata []*FunctionMetadata
op := OpCode(code[pos])
currentBounds := stackBounds[pos]
if currentBounds == nil {
if debugging {
fmt.Printf("Stack bounds not set: %v at %v \n", op, pos)
}
return 0, ErrUnreachableCode
}
@ -196,7 +198,9 @@ func validateControlFlow2(code []byte, section int, metadata []*FunctionMetadata
return 0, ErrStackOverflow{maxStackHeight, int(params.StackLimit)}
}
if maxStackHeight != int(metadata[section].MaxStackHeight) {
if debugging {
fmt.Print(maxStackHeight, metadata[section].MaxStackHeight)
}
return 0, fmt.Errorf("%w in code section %d: have %d, want %d", ErrInvalidMaxStackHeight, section, maxStackHeight, metadata[section].MaxStackHeight)
}
return len(stackBounds), nil