On Thu, 29 Oct 2020 19:08:28 -0500
Taylor Simpson <tsimp...@quicinc.com> wrote:

> +if __name__ == '__main__':
> +    f = io.StringIO()
> +    print_tree(f, dectree_normal)
> +    print_tree(f, dectree_16bit)
> +    if subinsn_groupings:
> +        print_tree(f, dectree_subinsn_groupings)
> +    for (name, dectree_subinsn) in sorted(dectree_subinsns.items()):
> +        print_tree(f, dectree_subinsn)
> +    for (name, dectree_ext) in sorted(dectree_extensions.items()):
> +        print_tree(f, dectree_ext)
> +    print_match_info(f)
> +    print_op_info(f)
> +    open(sys.argv[1], 'w').write(f.getvalue())

Is there any specific reason why (here and elsewhere) you use
`StringIO` instead of writing to the file directly?

I'd expect something like:

```
if __name__ == '__main__':
    with open(sys.argv[1], 'w') as f:
        print_tree(f, dectree_normal)
        print_tree(f, dectree_16bit)
        if subinsn_groupings:
            print_tree(f, dectree_subinsn_groupings)
        for (name, dectree_subinsn) in sorted(dectree_subinsns.items()):
            print_tree(f, dectree_subinsn)
        for (name, dectree_ext) in sorted(dectree_extensions.items()):
            print_tree(f, dectree_ext)
        print_match_info(f)
        print_op_info(f)
```

Maybe you're trying to avoid leaving a corrupted file in case of error,
but I guess that's more of a concern for the build system.

Elsewhere, you invoke `.close()`. I'd suggest to use a `with`-statement
there too.

-- 
Alessandro Di Federico
rev.ng

Reply via email to