cmd/mbf: dump IR of artifact presets

This exposes IR outside test cases, useful for verifying correctness of alternative IR emitters.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-02-07 17:21:43 +09:00
parent ffd2f979fb
commit 096a25ad3a

View File

@@ -150,6 +150,10 @@ func main() {
}, },
) )
{
var (
flagDump string
)
c.NewCommand( c.NewCommand(
"cure", "cure",
"Cure the named artifact and show its path", "Cure the named artifact and show its path",
@@ -159,15 +163,37 @@ func main() {
} }
if p, ok := rosa.ResolveName(args[0]); !ok { if p, ok := rosa.ResolveName(args[0]); !ok {
return fmt.Errorf("unsupported artifact %q", args[0]) return fmt.Errorf("unsupported artifact %q", args[0])
} else { } else if flagDump == "" {
pathname, _, err := cache.Cure(rosa.Std.Load(p)) pathname, _, err := cache.Cure(rosa.Std.Load(p))
if err == nil { if err == nil {
log.Println(pathname) log.Println(pathname)
} }
return err return err
} else {
f, err := os.OpenFile(
flagDump,
os.O_WRONLY|os.O_CREATE|os.O_EXCL,
0644,
)
if err != nil {
return err
}
if err = cache.EncodeAll(f, rosa.Std.Load(p)); err != nil {
_ = f.Close()
return err
}
return f.Close()
} }
}, },
).
Flag(
&flagDump,
"dump", command.StringFlag(""),
"Write IR to specified pathname and terminate",
) )
}
c.MustParse(os.Args[1:], func(err error) { c.MustParse(os.Args[1:], func(err error) {
if cache != nil { if cache != nil {