github.com/annchain/OG@v0.0.9/vm/common/bitvec.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package common 15 16 // Bitvec is a bit vector which maps bytes in a program. 17 // An unset bit means the byte is an opcode, a set bit means 18 // it's data (i.e. argument of PUSHxx). 19 type Bitvec []byte 20 21 func (bits *Bitvec) Set(pos uint64) { 22 (*bits)[pos/8] |= 0x80 >> (pos % 8) 23 } 24 func (bits *Bitvec) Set8(pos uint64) { 25 (*bits)[pos/8] |= 0xFF >> (pos % 8) 26 (*bits)[pos/8+1] |= ^(0xFF >> (pos % 8)) 27 } 28 29 // codeSegment checks if the position is in a code segment. 30 func (bits *Bitvec) CodeSegment(pos uint64) bool { 31 return ((*bits)[pos/8] & (0x80 >> (pos % 8))) == 0 32 }