github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/core/vm/analysis.go (about) 1 package vm 2 3 type bitvec []byte 4 5 func (bits *bitvec) set(pos uint64) { 6 (*bits)[pos/8] |= 0x80 >> (pos % 8) 7 } 8 func (bits *bitvec) set8(pos uint64) { 9 (*bits)[pos/8] |= 0xFF >> (pos % 8) 10 (*bits)[pos/8+1] |= ^(0xFF >> (pos % 8)) 11 } 12 13 func (bits *bitvec) codeSegment(pos uint64) bool { 14 return ((*bits)[pos/8] & (0x80 >> (pos % 8))) == 0 15 } 16 17 func codeBitmap(code []byte) bitvec { 18 19 bits := make(bitvec, len(code)/8+1+4) 20 for pc := uint64(0); pc < uint64(len(code)); { 21 op := OpCode(code[pc]) 22 23 if op >= PUSH1 && op <= PUSH32 { 24 numbits := op - PUSH1 + 1 25 pc++ 26 for ; numbits >= 8; numbits -= 8 { 27 bits.set8(pc) 28 pc += 8 29 } 30 for ; numbits > 0; numbits-- { 31 bits.set(pc) 32 pc++ 33 } 34 } else { 35 pc++ 36 } 37 } 38 return bits 39 }