blob: 00ce20544181538f8de49640900b10cc842e0e6d [file] [log] [blame]
Ben Murdoch61f157c2016-09-16 13:49:30 +01001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5"use strict";
6
7class ScheduleView extends TextView {
8 constructor(id, broker, nodePositionMap) {
9 super(id, broker, null, false);
10 let view = this;
11 let BLOCK_STYLE = {
12 css: 'tag'
13 };
14 const BLOCK_HEADER_STYLE = {
15 css: 'com',
16 block_id: -1,
17 location: function(text) {
18 let matches = /\d+/.exec(text);
19 if (!matches) return undefined;
20 BLOCK_HEADER_STYLE.block_id = Number(matches[0]);
21 return {
22 block_id: BLOCK_HEADER_STYLE.block_id
23 };
24 },
25 };
26 const BLOCK_LINK_STYLE = {
27 css: 'tag',
28 link: function(text) {
29 let id = Number(text.substr(1));
30 view.select(function(location) { return location.block_id == id; }, true, true);
31 }
32 };
33 const ID_STYLE = {
34 css: 'tag',
35 location: function(text) {
36 let matches = /\d+/.exec(text);
37 return {
38 node_id: Number(matches[0]),
39 block_id: BLOCK_HEADER_STYLE.block_id
40 };
41 },
42 };
43 const ID_LINK_STYLE = {
44 css: 'tag',
45 link: function(text) {
46 let id = Number(text);
47 view.select(function(location) { return location.node_id == id; }, true, true);
48 }
49 };
50 const NODE_STYLE = { css: 'kwd' };
51 const GOTO_STYLE = { css: 'kwd',
52 goto_id: -2,
53 location: function(text) {
54 return {
55 node_id: GOTO_STYLE.goto_id--,
56 block_id: BLOCK_HEADER_STYLE.block_id
57 };
58 }
59 }
60 const ARROW_STYLE = { css: 'kwd' };
61 let patterns = [
62 [
63 [/^--- BLOCK B\d+/, BLOCK_HEADER_STYLE, 1],
64 [/^\s+\d+: /, ID_STYLE, 2],
65 [/^\s+Goto/, GOTO_STYLE, 6],
66 [/^.*/, null, -1]
67 ],
68 [
69 [/^ +/, null],
70 [/^\(deferred\)/, BLOCK_HEADER_STYLE],
71 [/^B\d+/, BLOCK_LINK_STYLE],
72 [/^<-/, ARROW_STYLE],
73 [/^->/, ARROW_STYLE],
74 [/^,/, null],
75 [/^---/, BLOCK_HEADER_STYLE, -1]
76 ],
77 // Parse opcode including []
78 [
79 [/^[A-Za-z0-9_]+(\[.*\])?$/, NODE_STYLE, -1],
80 [/^[A-Za-z0-9_]+(\[.*\])?/, NODE_STYLE, 3]
81 ],
82 // Parse optional parameters
83 [
84 [/^ /, null, 4],
85 [/^\(/, null],
86 [/^\d+/, ID_LINK_STYLE],
87 [/^, /, null],
88 [/^\)$/, null, -1],
89 [/^\)/, null, 4],
90 ],
91 [
92 [/^ -> /, ARROW_STYLE, 5],
93 [/^.*/, null, -1]
94 ],
95 [
96 [/^B\d+$/, BLOCK_LINK_STYLE, -1],
97 [/^B\d+/, BLOCK_LINK_STYLE],
98 [/^, /, null]
99 ],
100 [
101 [/^ -> /, ARROW_STYLE],
102 [/^B\d+$/, BLOCK_LINK_STYLE, -1]
103 ]
104 ];
105 this.setPatterns(patterns);
106 this.setNodePositionMap(nodePositionMap);
107 }
108
109 initializeContent(data, rememberedSelection) {
110 super.initializeContent(data, rememberedSelection);
111 var graph = this;
112 var locations = [];
113 for (var id of rememberedSelection) {
114 locations.push({ node_id : id });
115 }
116 this.selectLocations(locations, true, false);
117 }
118
119 detachSelection() {
120 var selection = this.selection.detachSelection();
121 var s = new Set();
122 for (var i of selection) {
123 s.add(i.location.node_id);
124 };
125 return s;
126 }
127}