- Instruction[] instructions = ctx.emit();
- CodeBag codeBag = new CodeBag(this, instructions, leastUnallocatedAddress);
- System.out.println("instructions.length="+instructions.length);
- leastUnallocatedAddress += instructions.length;
- codeBags.add(codeBag);
- return codeBag;
+ return makeCodeBag(ctx.emit());
+ }
+
+ public CodeBag makeCodeBag(Instruction[] instructions) {
+ int MAX_BAG_SIZE = (1<<7)-1;
+ if (instructions.length > MAX_BAG_SIZE) {
+ System.out.println("warning: code bag size is "+instructions.length+
+ ", which exceeds maximum of "+MAX_BAG_SIZE+
+ "; breaking into multiple bags");
+ ArrayList<CodeBag> subBags = new ArrayList<CodeBag>();
+ for(int block=0; block<instructions.length; block+=MAX_BAG_SIZE) {
+ Instruction[] inst = new Instruction[Math.min(instructions.length-block, MAX_BAG_SIZE)];
+ System.arraycopy(instructions, block, inst, 0, inst.length);
+ subBags.add(makeCodeBag(inst));
+ }
+ throw new RuntimeException("FIXME: not done");
+
+ } else {
+ CodeBag codeBag = new CodeBag(this, instructions, leastUnallocatedAddress);
+ System.out.println("instructions.length="+instructions.length);
+ leastUnallocatedAddress += instructions.length;
+ codeBags.add(codeBag);
+ return codeBag;
+ }