Skip to content

Commit

Permalink
Buffer I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
smoynes committed Oct 8, 2023
1 parent cb51005 commit 4386b54
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/cli/cmd/asm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bufio"
"context"
"flag"
"fmt"
Expand Down Expand Up @@ -76,6 +77,7 @@ func (a *assembler) Run(ctx context.Context, args []string, stdout io.Writer, lo
// Second pass: generate code.
symbols := parser.Symbols()
syntax := parser.Syntax()
generator := asm.NewGenerator(symbols, syntax)

out, err := os.Create(a.output)
if err != nil {
Expand All @@ -85,15 +87,20 @@ func (a *assembler) Run(ctx context.Context, args []string, stdout io.Writer, lo

logger.Debug("Writing object", "file", a.output)

generator := asm.NewGenerator(symbols, syntax)

wrote, err := generator.WriteTo(out)
buf := bufio.NewWriter(out)
wrote, err := generator.WriteTo(buf)
if err != nil {

Check failure on line 92 in internal/cli/cmd/asm.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)
logger.Error("Compile error", "out", "a.o", "err", err)
logger.Error("Compile error", "out", a.output, "err", err)
return -1
}

if err = buf.Flush(); err != nil {
logger.Error("I/O error", "out", a.output, "err", err)
return -1
}

logger.Debug("Compiled object",
"out", a.output,
"size", wrote,
"symbols", symbols.Count(),
"syntax", syntax.Size(),
Expand Down

0 comments on commit 4386b54

Please sign in to comment.