// Helper function for managing labels and their target addresses. // Returns a sensible address, and if it is not the label's final // address, notes the dependency (at 'branch_pc') on the label. address CodeSection::target(Label& L, address branch_pc) { if (L.is_bound()) { int loc = L.loc(); if (index() == CodeBuffer::locator_sect(loc)) { return start() + CodeBuffer::locator_pos(loc); } else { return outer()->locator_address(loc); } } else { assert(allocates2(branch_pc), "sanity"); address base = start(); int patch_loc = CodeBuffer::locator(branch_pc - base, index()); L.add_patch_at(outer(), patch_loc); // Need to return a pc, doesn't matter what it is since it will be // replaced during resolution later. // Don't return NULL or badAddress, since branches shouldn't overflow. // Don't return base either because that could overflow displacements // for shorter branches. It will get checked when bound. return branch_pc; } }