Open
Description
Should we rethink sumtypes to allow for user-defined types?
For instance, ir.Instruction
currently requires the unexported isInstruction
method, but there are valid use cases where users may wish to define their own instructions to put in basic blocks.
One such use case seen in the wild is a comment pseudo-instruction which prints itself as ; data...
, e.g.
// Comment is a pseudo-instruction that may be used for adding LLVM IR comments
// to basic blocks.
type Comment struct {
// Line-comment contents.
Data string
}
// IsInstruction implements the ir.Instruction interface for Comment.
func (inst *Comment) IsInstruction() {}
// LLString returns the LLVM syntax representation of the comment.
func (inst *Comment) LLString() string {
return fmt.Sprintf("; %s", inst.Data)
}