Skip to content

Commit

Permalink
ir: remove isVoidType in favour of types.Equal(n.Type(), types.Void)
Browse files Browse the repository at this point in the history
This is one small step towards allowing user-defined instructions.
Note, this commit is not perfect though, since we may want to allow
user-defined types too, and this commit relies on types.Void instead
of some to-be-defined IsVoidType interface (or something along those
lines).

Updates #59.
  • Loading branch information
mewmew committed Feb 17, 2020
1 parent f24b815 commit 1c91f30
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions ir/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func (f *Func) AssignIDs() error {
if !ok {
continue
}
// Skip void instructions.
if isVoidValue(n) {
// Skip void instructions (call with void return).
if types.Equal(n.Type(), types.Void) {
continue
}
// Assign local IDs to unnamed local variables.
Expand All @@ -198,7 +198,8 @@ func (f *Func) AssignIDs() error {
if !ok {
continue
}
if isVoidValue(n) {
// Skip void terminators (invoke, callbr with void return).
if types.Equal(n.Type(), types.Void) {
continue
}
if err := setName(n); err != nil {
Expand Down Expand Up @@ -305,16 +306,6 @@ func bodyString(body *Func) string {
return buf.String()
}

// isVoidValue reports whether the given named value is a non-value (i.e. a call
// instruction or invoke terminator with void-return type).
func isVoidValue(n value.Named) bool {
switch n.(type) {
case *InstCall, *TermInvoke, *TermCallBr:
return n.Type().Equal(types.Void)
}
return false
}

// local is a local variable.
type local interface {
value.Named
Expand Down

0 comments on commit 1c91f30

Please sign in to comment.