Skip to content

Commit

Permalink
use Instr as GetCost argument for more information
Browse files Browse the repository at this point in the history
  • Loading branch information
hunjixin committed Aug 1, 2019
1 parent 3091ed0 commit a272d77
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func (c *SSAFunctionCompiler) InsertGasCounters(gp GasPolicy) {
blk := &cfg.Blocks[i]
totalCost := int64(1)
for _, ins := range blk.Code {
totalCost += gp.GetCost(ins.Op)
totalCost += gp.GetCost(ins)
if totalCost < 0 {
panic("total cost overflow")
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/gas_policy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package compiler

type GasPolicy interface {
GetCost(key string) int64
GetCost(key Instr) int64
}

type SimpleGasPolicy struct {
GasPerInstruction int64
}

func (p *SimpleGasPolicy) GetCost(key string) int64 {
func (p *SimpleGasPolicy) GetCost(key Instr) int64 {
return p.GasPerInstruction
}

0 comments on commit a272d77

Please sign in to comment.