Skip to content
Snippets Groups Projects
Commit 36d9d427 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[region] visualize current marker

parent 64ce3b86
No related branches found
No related tags found
No related merge requests found
...@@ -166,34 +166,26 @@ const regions_internal: Server.GetRequest<decl,region[]> = { ...@@ -166,34 +166,26 @@ const regions_internal: Server.GetRequest<decl,region[]> = {
/** Returns computed regions for the given declaration */ /** Returns computed regions for the given declaration */
export const regions: Server.GetRequest<decl,region[]>= regions_internal; export const regions: Server.GetRequest<decl,region[]>= regions_internal;
const regionsAt_internal: Server.GetRequest<[ marker, boolean ],region[]> = { const regionsAt_internal: Server.GetRequest<marker,region[]> = {
kind: Server.RqKind.GET, kind: Server.RqKind.GET,
name: 'plugins.region.regionsAt', name: 'plugins.region.regionsAt',
input: Json.jPair( jMarker, Json.jBoolean,), input: jMarker,
output: Json.jArray(jRegion), output: Json.jArray(jRegion),
fallback: [], fallback: [],
signals: [ { name: 'plugins.region.updated' } ], signals: [ { name: 'plugins.region.updated' } ],
}; };
/** Compute regions at the given marker */ /** Compute regions at the given marker program point */
export const regionsAt: Server.GetRequest<[ marker, boolean ],region[]>= regionsAt_internal; export const regionsAt: Server.GetRequest<marker,region[]>= regionsAt_internal;
const localize_internal: Server.GetRequest< const localize_internal: Server.GetRequest<marker,node | undefined> = {
[ marker, boolean ],
node |
undefined
> = {
kind: Server.RqKind.GET, kind: Server.RqKind.GET,
name: 'plugins.region.localize', name: 'plugins.region.localize',
input: Json.jPair( jMarker, Json.jBoolean,), input: jMarker,
output: Json.jOption(jNode), output: Json.jOption(jNode),
fallback: undefined, fallback: undefined,
signals: [ { name: 'plugins.region.updated' } ], signals: [ { name: 'plugins.region.updated' } ],
}; };
/** Localize in the local (true) or global map (false) */ /** Localize the marker in its map */
export const localize: Server.GetRequest< export const localize: Server.GetRequest<marker,node | undefined>= localize_internal;
[ marker, boolean ],
node |
undefined
>= localize_internal;
/* ------------------------------------- */ /* ------------------------------------- */
...@@ -43,9 +43,11 @@ function RegionAnalys(): JSX.Element { ...@@ -43,9 +43,11 @@ function RegionAnalys(): JSX.Element {
const [pinned, setPinned] = React.useState(false); const [pinned, setPinned] = React.useState(false);
const [running, setRunning] = React.useState(false); const [running, setRunning] = React.useState(false);
const setComputing = Dome.useProtected(setRunning); const setComputing = Dome.useProtected(setRunning);
const scope = States.useCurrentScope(); const { scope, marker } = States.useCurrentLocation();
const { kind, name } = States.useDeclaration(scope); const { kind, name } = States.useDeclaration(scope);
const regions = States.useRequestStable(Region.regions, kf); const regions = States.useRequestStable(Region.regions, kf);
const node = States.useRequestStable(Region.localize, marker);
const { descr: label } = States.useMarker(marker);
React.useEffect(() => { React.useEffect(() => {
if (!pinned && kind === 'FUNCTION' && scope !== kf) { if (!pinned && kind === 'FUNCTION' && scope !== kf) {
setKf(scope); setKf(scope);
...@@ -84,7 +86,7 @@ function RegionAnalys(): JSX.Element { ...@@ -84,7 +86,7 @@ function RegionAnalys(): JSX.Element {
onClick={() => setPinned(!pinned)} onClick={() => setPinned(!pinned)}
/> />
</Tools.ToolBar> </Tools.ToolBar>
<MemoryView regions={regions} /> <MemoryView regions={regions} node={node} label={label} />
</> </>
); );
} }
......
...@@ -58,8 +58,8 @@ function makeRecord( ...@@ -58,8 +58,8 @@ function makeRecord(
} }
interface Diagram { interface Diagram {
nodes: Dot.Node[]; nodes: readonly Dot.Node[];
edges: Dot.Edge[]; edges: readonly Dot.Edge[];
} }
function makeDiagram(regions: readonly Region.region[]): Diagram { function makeDiagram(regions: readonly Region.region[]): Diagram {
...@@ -110,11 +110,23 @@ function makeDiagram(regions: readonly Region.region[]): Diagram { ...@@ -110,11 +110,23 @@ function makeDiagram(regions: readonly Region.region[]): Diagram {
return { nodes, edges }; return { nodes, edges };
} }
function addSelected(d: Diagram, label: string, node: Region.node): void { function addSelected(
d.nodes.push({ diag: Diagram,
id: 'Selected', label, title: "Selected Marker", shape: 'note' node: Region.node | undefined,
}); label: string | undefined
d.edges.push({ source: 'Selected', target: `n${node}` }); ): Diagram {
if (node && label) {
const nodes = diag.nodes.concat({
id: 'Selected', label, title: "Selected Marker",
shape: 'note', color: 'selected'
});
const edges = diag.edges.concat({
source: 'Selected', target: `n${node}`, aligned: true,
headAnchor: 's', tailAnchor: 'n',
});
return { nodes, edges };
} else
return diag;
} }
export interface MemoryViewProps { export interface MemoryViewProps {
...@@ -125,9 +137,12 @@ export interface MemoryViewProps { ...@@ -125,9 +137,12 @@ export interface MemoryViewProps {
export function MemoryView(props: MemoryViewProps): JSX.Element { export function MemoryView(props: MemoryViewProps): JSX.Element {
const { regions = [], label, node } = props; const { regions = [], label, node } = props;
const diagram = React.useMemo(() => makeDiagram(regions), [regions]); const baseDiagram = React.useMemo(() => makeDiagram(regions), [regions]);
if (label && node) addSelected(diagram, label, node); const fullDiagram = React.useMemo(
return <Dot.Diagram {...diagram} />; () => addSelected(baseDiagram, node, label),
[baseDiagram, node, label]
);
return <Dot.Diagram {...fullDiagram} />;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -181,13 +181,13 @@ module Regions = Data.Jlist(Region) ...@@ -181,13 +181,13 @@ module Regions = Data.Jlist(Region)
(* --- Server API --- *) (* --- Server API --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
let map_of_localizable ~local (loc : Printer_tag.localizable) = let map_of_localizable ?(atStmt=false) (loc : Printer_tag.localizable) =
let open Printer_tag in let open Printer_tag in
match kf_of_localizable loc with match kf_of_localizable loc with
| None -> raise Not_found | None -> raise Not_found
| Some kf -> | Some kf ->
let domain = Analysis.find kf in let domain = Analysis.find kf in
if local then if atStmt then
match ki_of_localizable loc with match ki_of_localizable loc with
| Kglobal -> domain.map | Kglobal -> domain.map
| Kstmt s -> Stmt.Map.find s domain.body | Kstmt s -> Stmt.Map.find s domain.body
...@@ -236,25 +236,25 @@ let () = ...@@ -236,25 +236,25 @@ let () =
let () = let () =
Request.register Request.register
~package ~kind:`GET ~name:"regionsAt" ~package ~kind:`GET ~name:"regionsAt"
~descr:(Md.plain "Compute regions at the given marker") ~descr:(Md.plain "Compute regions at the given marker program point")
~input:(module Data.Jpair(Kernel_ast.Marker)(Data.Jbool)) ~input:(module Kernel_ast.Marker)
~output:(module Regions) ~output:(module Regions)
~signals:[signal] ~signals:[signal]
begin fun (loc,local) -> begin fun loc ->
try Memory.regions @@ map_of_localizable ~local loc try Memory.regions @@ map_of_localizable ~atStmt:true loc
with Not_found -> [] with Not_found -> []
end end
let () = let () =
Request.register Request.register
~package ~kind:`GET ~name:"localize" ~package ~kind:`GET ~name:"localize"
~descr:(Md.plain "Localize in the local (true) or global map (false)") ~descr:(Md.plain "Localize the marker in its map")
~input:(module Data.Jpair(Kernel_ast.Marker)(Data.Jbool)) ~input:(module Kernel_ast.Marker)
~output:(module NodeOpt) ~output:(module NodeOpt)
~signals:[signal] ~signals:[signal]
begin fun (loc,local) -> begin fun loc ->
try try
let map = map_of_localizable ~local loc in let map = map_of_localizable loc in
region_of_localizable map loc region_of_localizable map loc
with Not_found -> None with Not_found -> None
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment