use of primal.primitive.adt.Bytes.BytesBuilder in project suite by stupidsing.
the class AsmSl method assemble.
private Bytes assemble(Generalizer generalizer, List<Pair<Reference, Node>> lnis) {
var org = Int.num(generalizer.getVariable(Atom.of(".org")).finalNode());
var out = new BytesBuilder();
for (var isPass2 : new boolean[] { false, true }) {
AssemblePredicates.isPass2 = isPass2;
out.clear();
for (var lni : lnis) {
Bytes bytes = lni.map((reference, instruction) -> {
var address = org + out.size();
if (!isPass2)
reference.bound(Int.of(address));
else if (Int.num(reference.finalNode()) != address)
fail("address varied between passes at " + Integer.toHexString(address) + ": " + instruction);
try {
return asm.assemble(isPass2, address, instruction);
} catch (Exception ex) {
return fail("in " + instruction + " during pass " + (!isPass2 ? "1" : "2"), ex);
}
});
out.append(bytes);
}
if (isPass2)
for (var lni : lnis) lni.k.unbound();
}
return out.toBytes();
}
Aggregations