-- AMModelBridgeImpl.Mesa -- last modified on July 14, 1983 10:25 am by Paul Rovner DIRECTORY AMBridge USING[ IsRemote, TVToRemoteProc, TVToProc, GetWorld, GetWorldIncarnation, RemoteGFHFromTV, RemoteGlobalFrameHandle, nilRemoteGlobalFrameHandle, TVForRemoteProc, TVForProc, GFHFromTV], AMModel USING[Context, Section, ContextSection], AMModelBridge USING[LoadedSection, ContextForFrame, FrameFromContext], AMModelPrivate USING[SectionRec, ProgPCToFGI], AMTypes USING[GlobalParent, TV], PrincOps USING[BytePC, ControlLink, EPRange, GlobalFrameHandle, ProcDesc], PrincOpsUtils USING[GlobalFrameAndEntryPoint], RemotePrincOpsUtils USING[RemoteGlobalFrameAndEntryPoint], RTTypesPrivate USING[GetPc], RTTypesRemotePrivate USING[GetRemotePc, GetRemoteGFHeader], WorldVM USING[World, CurrentIncarnation]; AMModelBridgeImpl: PROGRAM IMPORTS AMBridge, AMModel, AMModelBridge, AMModelPrivate, AMTypes, PrincOpsUtils, RemotePrincOpsUtils, RTTypesPrivate, RTTypesRemotePrivate, WorldVM EXPORTS AMModel, AMModelBridge = BEGIN OPEN AMModel, AMModelBridge, PrincOps, RTTypesPrivate, RTTypesRemotePrivate; -- TYPEs -- either binder output bundle for a config, or compiler output bundle -- for a prog module, DEFs module, proc, or statement Section: TYPE = REF SectionObj; SectionObj: PUBLIC TYPE = AMModelPrivate.SectionRec; LoadedSection: TYPE = AMModelBridge.LoadedSection; -- A LoadedSection is a convenience for clients of AMModelBridge. Each represents one of: -- loaded compiler output bundle for a prog module [prog, prog] -- loaded compiler output bundle for a proc [proc, prog] -- loaded compiler output bundle for a statement [statement, prog] LoadedSectionForProc: PUBLIC PROC[tv: AMTypes.TV--proc--] RETURNS[ans: LoadedSection _ [NIL, NIL, [0]]] = { c: Context; s: Section; ep: CARDINAL; gf: AMTypes.TV _ AMTypes.GlobalParent[tv]; ans.context _ AMModelBridge.ContextForFrame[gf]; c _ ans.context; s _ ContextSection[c]; IF AMBridge.IsRemote[tv] THEN { world: WorldVM.World = AMBridge.GetWorld[tv]; rgfh: AMBridge.RemoteGlobalFrameHandle _ AMBridge.nilRemoteGlobalFrameHandle; gfh: PrincOps.GlobalFrameHandle; [gfh, ep] _ RemotePrincOpsUtils.RemoteGlobalFrameAndEntryPoint [world, AMBridge.TVToRemoteProc[tv].pd]; rgfh _ [world, WorldVM.CurrentIncarnation[world], LOOPHOLE[gfh]]; ans.pc _ RTTypesRemotePrivate.GetRemotePc[rgfh, ep]; } ELSE { gfh: PrincOps.GlobalFrameHandle; [gfh, ep] _ PrincOpsUtils.GlobalFrameAndEntryPoint[AMBridge.TVToProc[tv]]; ans.pc _ RTTypesPrivate.GetPc[gfh, ep]; }; ans.section _ NEW[SectionObj _ [proc[prog: NARROW[s], entryPointIndex: ep, procTV: NARROW[tv]]]]; }; LoadedSectionForProgPC: PUBLIC PROC[prog: Context, pc: BytePC] RETURNS[ans: LoadedSection _ [NIL, NIL, [0]]] = { s: Section = ContextSection[prog]; ans.context _ prog; ans.section _ NEW[SectionObj _ [statement [prog: NARROW[s], fgtIndex: AMModelPrivate.ProgPCToFGI[FrameFromContext[prog], pc]]]]; ans.pc _ pc; }; ProcFromLoadedSection: PUBLIC PROC[proc: LoadedSection] RETURNS[AMTypes.TV--proc--] = {s: Section = proc.section; sr: REF proc SectionObj _ NARROW[s]; IF sr.procTV # NIL THEN RETURN[sr.procTV] ELSE {IF AMBridge.IsRemote[FrameFromContext[proc.context]] THEN {pd: PrincOps.ProcDesc _ PrincOps.ControlLink[procedure[gfi: 0, ep: 0, tag: TRUE]]; pd.gfi _ GetRemoteGFHeader [AMBridge.RemoteGFHFromTV[FrameFromContext[proc.context]]].gfi + sr.entryPointIndex/PrincOps.EPRange; pd.ep _ sr.entryPointIndex MOD PrincOps.EPRange; RETURN[AMBridge.TVForRemoteProc [[world: AMBridge.GetWorld[FrameFromContext[proc.context]], worldIncarnation: AMBridge.GetWorldIncarnation [FrameFromContext[proc.context]], pd: pd]]]} ELSE {pd: PrincOps.ProcDesc _ PrincOps.ControlLink[procedure[gfi: 0, ep: 0, tag: TRUE]]; pd.gfi _ AMBridge.GFHFromTV[FrameFromContext[proc.context]].gfi + sr.entryPointIndex/PrincOps.EPRange; pd.ep _ sr.entryPointIndex MOD PrincOps.EPRange; RETURN[AMBridge.TVForProc[LOOPHOLE[pd]]]} }; }; END.