Skip to content

ir: add value.User interface implemented by instructions and terminators #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ir/inst_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (inst *InstExtractValue) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstExtractValue) Operands() []*value.Value {
return []*value.Value{&inst.X}
}

// ~~~ [ insertvalue ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstInsertValue is an LLVM IR insertvalue instruction.
Expand Down Expand Up @@ -134,6 +139,11 @@ func (inst *InstInsertValue) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstInsertValue) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Elem}
}

// ### [ Helper functions ] ####################################################

// aggregateElemType returns the element type at the position in the aggregate
Expand Down
60 changes: 60 additions & 0 deletions ir/inst_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (inst *InstAdd) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstAdd) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ fadd ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFAdd is an LLVM IR fadd instruction.
Expand Down Expand Up @@ -129,6 +134,11 @@ func (inst *InstFAdd) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFAdd) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ sub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstSub is an LLVM IR sub instruction.
Expand Down Expand Up @@ -188,6 +198,11 @@ func (inst *InstSub) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstSub) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ fsub ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFSub is an LLVM IR fsub instruction.
Expand Down Expand Up @@ -247,6 +262,11 @@ func (inst *InstFSub) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFSub) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ mul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstMul is an LLVM IR mul instruction.
Expand Down Expand Up @@ -306,6 +326,11 @@ func (inst *InstMul) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstMul) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ fmul ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFMul is an LLVM IR fmul instruction.
Expand Down Expand Up @@ -365,6 +390,11 @@ func (inst *InstFMul) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFMul) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ udiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstUDiv is an LLVM IR udiv instruction.
Expand Down Expand Up @@ -424,6 +454,11 @@ func (inst *InstUDiv) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstUDiv) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ sdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstSDiv is an LLVM IR sdiv instruction.
Expand Down Expand Up @@ -483,6 +518,11 @@ func (inst *InstSDiv) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstSDiv) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ fdiv ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFDiv is an LLVM IR fdiv instruction.
Expand Down Expand Up @@ -542,6 +582,11 @@ func (inst *InstFDiv) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFDiv) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ urem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstURem is an LLVM IR urem instruction.
Expand Down Expand Up @@ -595,6 +640,11 @@ func (inst *InstURem) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstURem) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ srem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstSRem is an LLVM IR srem instruction.
Expand Down Expand Up @@ -648,6 +698,11 @@ func (inst *InstSRem) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstSRem) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ frem ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFRem is an LLVM IR frem instruction.
Expand Down Expand Up @@ -706,3 +761,8 @@ func (inst *InstFRem) LLString() string {
}
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFRem) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}
30 changes: 30 additions & 0 deletions ir/inst_bitwise.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (inst *InstShl) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstShl) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ lshr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstLShr is an LLVM IR lshr instruction.
Expand Down Expand Up @@ -129,6 +134,11 @@ func (inst *InstLShr) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstLShr) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ ashr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstAShr is an LLVM IR ashr instruction.
Expand Down Expand Up @@ -188,6 +198,11 @@ func (inst *InstAShr) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstAShr) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ and ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstAnd is an LLVM IR and instruction.
Expand Down Expand Up @@ -241,6 +256,11 @@ func (inst *InstAnd) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstAnd) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ or ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstOr is an LLVM IR or instruction.
Expand Down Expand Up @@ -294,6 +314,11 @@ func (inst *InstOr) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstOr) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}

// ~~~ [ xor ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstXor is an LLVM IR xor instruction.
Expand Down Expand Up @@ -346,3 +371,8 @@ func (inst *InstXor) LLString() string {
}
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstXor) Operands() []*value.Value {
return []*value.Value{&inst.X, &inst.Y}
}
65 changes: 65 additions & 0 deletions ir/inst_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func (inst *InstTrunc) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstTrunc) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ zext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstZExt is an LLVM IR zext instruction.
Expand Down Expand Up @@ -131,6 +136,11 @@ func (inst *InstZExt) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstZExt) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ sext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstSExt is an LLVM IR sext instruction.
Expand Down Expand Up @@ -178,6 +188,11 @@ func (inst *InstSExt) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstSExt) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ fptrunc ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFPTrunc is an LLVM IR fptrunc instruction.
Expand Down Expand Up @@ -225,6 +240,11 @@ func (inst *InstFPTrunc) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFPTrunc) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ fpext ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFPExt is an LLVM IR fpext instruction.
Expand Down Expand Up @@ -272,6 +292,11 @@ func (inst *InstFPExt) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFPExt) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ fptoui ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFPToUI is an LLVM IR fptoui instruction.
Expand Down Expand Up @@ -319,6 +344,11 @@ func (inst *InstFPToUI) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFPToUI) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ fptosi ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstFPToSI is an LLVM IR fptosi instruction.
Expand Down Expand Up @@ -366,6 +396,11 @@ func (inst *InstFPToSI) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstFPToSI) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ uitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstUIToFP is an LLVM IR uitofp instruction.
Expand Down Expand Up @@ -413,6 +448,11 @@ func (inst *InstUIToFP) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstUIToFP) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ sitofp ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstSIToFP is an LLVM IR sitofp instruction.
Expand Down Expand Up @@ -460,6 +500,11 @@ func (inst *InstSIToFP) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstSIToFP) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ ptrtoint ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstPtrToInt is an LLVM IR ptrtoint instruction.
Expand Down Expand Up @@ -507,6 +552,11 @@ func (inst *InstPtrToInt) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstPtrToInt) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ inttoptr ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstIntToPtr is an LLVM IR inttoptr instruction.
Expand Down Expand Up @@ -554,6 +604,11 @@ func (inst *InstIntToPtr) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstIntToPtr) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ bitcast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstBitCast is an LLVM IR bitcast instruction.
Expand Down Expand Up @@ -601,6 +656,11 @@ func (inst *InstBitCast) LLString() string {
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstBitCast) Operands() []*value.Value {
return []*value.Value{&inst.From}
}

// ~~~ [ addrspacecast ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// InstAddrSpaceCast is an LLVM IR addrspacecast instruction.
Expand Down Expand Up @@ -647,3 +707,8 @@ func (inst *InstAddrSpaceCast) LLString() string {
}
return buf.String()
}

// Operands returns a mutable list of operands of the given instruction.
func (inst *InstAddrSpaceCast) Operands() []*value.Value {
return []*value.Value{&inst.From}
}
Loading