/** * This method updates the source attributes for all statements in a block. This is typically done * in conjunction with a substitution, when we're inlining constraints from e.g. pre- and * post-conditions. * * @param block * @param nsrc * @return */ public static Block resource(Block block, Attribute.Source nsrc) { if (block == null) { return null; } Block nblock = new Block(block.numInputs()); for (Entry e : block) { nblock.append(e.code, nsrc); } return nblock; }
public Block relabel() { HashMap<String, String> labels = new HashMap<String, String>(); for (Entry s : this) { if (s.code instanceof Code.Label) { Code.Label l = (Code.Label) s.code; labels.put(l.label, freshLabel()); } } Block block = new Block(numInputs); // Finally, apply the binding and relabel any labels as well. for (Entry s : this) { Code ncode = s.code.relabel(labels); block.append(ncode, s.attributes()); } return block; }
private Block readCodeBlock(int numInputs) throws IOException { Block block = new Block(numInputs); int nCodes = input.read_uv(); HashMap<Integer, Code.Label> labels = new HashMap<Integer, Code.Label>(); for (int i = 0; i != nCodes; ++i) { Code code = readCode(i, labels); block.append(code); } // NOTE: we must go up to nCodes+1 because of the possibility of a label // occurring after the very last bytecode instruction. for (int i = 0, j = 0; i != nCodes + 1; ++i, ++j) { Code.Label label = labels.get(i); if (label != null) { block.insert(j++, label); } } input.pad_u8(); // necessary return block; }