1 package edu.berkeley.fleet.loops;
2 import edu.berkeley.fleet.api.*;
7 * A program is a collection of CodeBags resident in a particular Memory.
11 private Ship memoryShip;
13 private long leastUnallocatedAddress;
14 private long startAddress;
16 private HashSet<CodeBag> codeBags = new HashSet<CodeBag>();
18 public Program(Ship memoryShip) { this(memoryShip, 0); }
19 public Program(Ship memoryShip, long startAddress) {
20 this.fleet = memoryShip.getFleet();
21 this.memoryShip = memoryShip;
22 this.startAddress = startAddress;
23 this.leastUnallocatedAddress = startAddress;
26 public void run(FleetProcess fp, CodeBag run) {
27 System.out.println("invoking...");
28 Context ctx = new Context(fleet);
30 lf = new LoopFactory(ctx, memoryShip.getDock("inCBD"), 1);
31 lf.literal( (run.baseAddress<<6) | run.instructions.length );
34 System.out.println("invoked.");
37 public void install(FleetProcess fp) {
38 BitVector[] bvs = new BitVector[(int)(leastUnallocatedAddress-startAddress)];
40 for(CodeBag cb : codeBags)
41 for(int i=0; i<cb.instructions.length; i++)
42 bvs[j++] = fleet.encodeInstruction(cb.instructions[i], memoryShip.getDock("out"));
43 System.out.println("writing... ("+bvs.length+" words)");
44 MemoryUtils.writeMem(fp, memoryShip, startAddress, bvs);
45 System.out.println("written.");
48 public CodeBag makeCodeBag(Context ctx) {
49 Instruction[] instructions = ctx.emit();
50 CodeBag codeBag = new CodeBag(this, instructions, leastUnallocatedAddress);
51 System.out.println("instructions.length="+instructions.length);
52 leastUnallocatedAddress += instructions.length;
53 codeBags.add(codeBag);