1 ;; ---------------------------------------------------------------------------
2 ;; Time-stamp: <Tue Jun 11 1996 18:01:28 Stardate: [-31]7643.54 hwloidl>
4 ;; Mode for GrAnSim profiles
5 ;; ---------------------------------------------------------------------------
7 (defvar gransim-auto-hilit t
8 "Automagically invoke hilit19.")
10 (defvar grandir (getenv "GRANDIR")
11 "Root of the GrAnSim installation. Executables should be in grandir/bin")
13 (defvar hwl-hi-node-face 'highlight
14 "Face to be used for specific highlighting of a node")
16 (defvar hwl-hi-thread-face 'holiday-face
17 "Face to be used for specific highlighting of a thread")
19 ;; ---------------------------------------------------------------------------
21 (setq exec-path (cons (concat grandir "/bin") exec-path))
23 ;; Requires hilit19 for highlighting parts of a GrAnSim profile
25 (setq hilit-mode-enable-list '(not text-mode)
26 hilit-background-mode 'light
27 hilit-inhibit-hooks nil
28 hilit-inhibit-rebinding nil);
35 (append '(("\\.gr" . gr-mode))
38 (defvar gr-mode-map (make-keymap "GrAnSim Profile Mode SetUp")
39 "Keymap for GrAnSim profiles.")
41 ; (fset 'GrAnSim-mode-fiddly gr-mode-map)
43 ;(define-key gr-mode-map [wrap]
44 ; '("Wrap lines" . hwl-wrap))
46 ;(define-key gr-mode-map [truncate]
47 ; '("Truncate lines" . hwl-truncate))
49 ;(define-key global-map [C-S-down-mouse-1] 'GrAnSim-mode-fiddly)
51 ;(modify-frame-parameters (selected-frame)
52 ; '((menu-bar-lines . 2)))
54 ;(define-key-after gr-mode-map [menu-bar GrAnSim]
55 ; '("GrAnSim" . (make-sparse-keymap "GrAnSim")) 'edit)
57 ;(defvar GrAnSim-menu-map (make-sparse-keymap "GrAnSim"))
59 (define-key gr-mode-map [menu-bar GrAnSim]
60 (cons "GrAnSim" (make-sparse-keymap "GrAnSim"))) ; 'edit)
62 (define-key gr-mode-map [menu-bar GrAnSim wrap]
63 '("Wrap lines" . hwl-wrap))
65 (define-key gr-mode-map [menu-bar GrAnSim truncate]
66 '("Truncate lines" . hwl-truncate))
68 (define-key gr-mode-map [menu-bar GrAnSim toggle-truncate]
69 '("Toggle truncate/wrap" . hwl-toggle-truncate-wrap) )
71 (define-key gr-mode-map [menu-bar GrAnSim hi-clear]
72 '("Clear highlights" . hwl-hi-clear))
74 (define-key gr-mode-map [menu-bar GrAnSim hi-thread]
75 '("Highlight specific Thread" . hwl-hi-thread))
77 (define-key gr-mode-map [menu-bar GrAnSim hi-node]
78 '("Highlight specific Node" . hwl-hi-node))
80 (define-key gr-mode-map [menu-bar GrAnSim highlight]
81 '("Highlight buffer" . hilit-rehighlight-buffer))
83 (define-key gr-mode-map [menu-bar GrAnSim narrow-event]
84 '("Narrow to Event" . hwl-narrow-to-event))
86 (define-key gr-mode-map [menu-bar GrAnSim narrow-thread]
87 '("Narrow to Thread" . hwl-narrow-to-thread))
89 (define-key gr-mode-map [menu-bar GrAnSim narrow-pe]
90 '("Narrow to PE" . hwl-narrow-to-pe))
94 ; (define-key global-map [C-S-down-mouse-1] 'GrAnSim-mode-fiddly)
97 (defvar gr-mode-hook nil
98 "Invoked in gr mode.")
101 ;;; Ensure new buffers won't get this mode if default-major-mode is nil.
102 ;(put 'gr-mode 'mode-class 'special)
105 "Major mode for GrAnSim profiles."
107 (kill-all-local-variables)
108 ;(use-local-map gr-mode-map)
109 (use-local-map gr-mode-map) ; This provides the local keymap.
110 (setq major-mode 'gr-mode)
111 (setq mode-name "GrAnSim Profile Mode")
112 (setq local-abbrev-table text-mode-abbrev-table)
113 (set-syntax-table text-mode-syntax-table)
114 (setq truncate-lines t) ; do not wrap lines (truncates END lines!)
116 ;(setq buffer-offer-save t)
117 (run-hooks 'gr-mode-hook))
119 ;; same as mh-make-local-vars
120 (defun gr-make-local-vars (&rest pairs)
121 ;; Take VARIABLE-VALUE pairs and make local variables initialized to the
124 (make-variable-buffer-local (car pairs))
125 (set (car pairs) (car (cdr pairs)))
126 (setq pairs (cdr (cdr pairs)))))
128 ;; ----------------------------------------------------------------------
129 ;; Highlighting stuff (currently either hilit19 or fontlock is used)
130 ;; ----------------------------------------------------------------------
132 (hilit-set-mode-patterns
135 ("--.*$" nil comment)
136 ("\\+\\+.*$" nil comment)
137 ;; hilight important bits in the header
138 ("^Granularity Simulation for \\(.*\\)$" 1 glob-struct)
139 ("^PEs[ \t]+\\([0-9]+\\)" 1 decl)
140 ("^Latency[ \t]+\\([0-9]+\\)" 1 decl)
141 ("Arith[ \t]+\\([0-9]+\\)" 1 decl)
142 ("Branch[ \t]+\\([0-9]+\\)" 1 decl)
143 ("Load[ \t]+\\([0-9]+\\)" 1 decl)
144 ("Store[ \t]+\\([0-9]+\\)" 1 decl)
145 ("Float[ \t]+\\([0-9]+\\)" 1 decl)
146 ("Alloc[ \t]+\\([0-9]+\\)" 1 decl)
147 ;; hilight PE number and time in each line
148 ("^PE[ \t]+\\([0-9]+\\)" 1 glob-struct)
149 (" \\[\\([0-9]+\\)\\]:" 1 define)
150 ;; in this case the events are the keyword
151 ; ("\\(FETCH\\|REPLY\\|RESUME\\|RESUME(Q)\\|SCHEDULE\\|SCHEDULE(Q)\\|BLOCK\\|STEALING\\|STOLEN\\|STOLEN(Q)\\)[ \t]" 1 keyword)
152 ("\\(FETCH\\|BLOCK\\)[ \t]" 1 label)
153 ("\\(REPLY\\|RESUME(Q)\\|SCHEDULE(Q)\\|STOLEN(Q)\\)[ \t]" 1 named-param)
154 ("\\(RESUME\\|SCHEDULE\\|STOLEN\\)[ \t]" 1 msg-quote)
155 ("\\(STEALING\\)[ \t]" 1 keyword)
156 ("\\(START\\|END\\)[ \t]" 1 defun)
157 ("\\(SPARK\\|SPARKAT\\|USED\\|PRUNED\\)[ \t]" 1 crossref)
158 ("\\(EXPORTED\\|ACQUIRED\\)[ \t]" 1 string)
159 ;; especially interesting are END events; hightlight runtime etc
160 (",[ \t]+RT[ \t]+\\([0-9]+\\)" 1 define)
161 ;; currently unused but why not?
162 ("\"" ".*\"" string))
165 ;; --------------------------------------------------------------------------
166 ;; Own fcts for selective highlighting
167 ;; --------------------------------------------------------------------------
169 (defun hwl-hi-node (node)
170 "Highlight node in GrAnSim profile."
171 (interactive "sNode (hex): ")
173 (let* ( (here (point))
174 (len (length node)) )
175 (goto-char (point-min))
176 (while (search-forward node nil t)
177 (let* ( (end (point))
178 (start (- end len)) )
179 (add-text-properties start end `(face ,hwl-hi-node-face))
185 (defun hwl-hi-thread (task)
186 "Highlight task in GrAnSim profile."
187 (interactive "sTask: ")
189 (let* ( (here (point))
191 (se-str (format "[A-Z)]\\s-+%s\\(\\s-\\|,\\)" task))
193 (goto-char (point-min))
194 (while (re-search-forward se-str nil t)
195 (let ( (c (current-column)) )
196 (if (and (> c 10) (< c 70))
197 (let* ( (end (1- (point)))
198 (start (- end len)) )
199 (add-text-properties start end `(face ,hwl-hi-thread-face))
205 (defun hwl-hi-line ()
206 "Highlight the current line."
210 (let ( (beg (point)) )
212 (add-text-properties beg (point) '(face highlight))
217 (defun hwl-unhi-line ()
218 "Unhighlight the current line."
222 (let ( (beg (point)) )
224 (add-text-properties beg (point) '(face nil))
230 (defun hwl-hi-from-to (from to)
231 "Highlight region between two timestamps."
232 (interactive "nFrom: \nnTo:")
234 (let* ( (here (point))
239 (goto-char (point-min))
240 ; (re-search-forward REGEXP)
241 (search-forward separator nil t)
249 (setq time-str (buffer-substring beg (- (point) 2)))
250 (setq now (string-to-number time-str))
261 (setq time-str (buffer-substring beg (- (point) 2)))
262 (setq now (string-to-number time-str))
267 (add-text-properties start end '(face paren-match-face))
274 (defun hwl-hi-clear ()
276 (let ( (start (point-min) )
278 (remove-text-properties start end '(face nil))
282 ;; --------------------------------------------------------------------------
283 ;; Misc Elisp functions
284 ;; --------------------------------------------------------------------------
288 (setq truncate-lines nil)
292 (defun hwl-truncate ()
294 (setq truncate-lines t)
298 (defun hwl-toggle-truncate-wrap ()
300 (if truncate-lines (setq truncate-lines nil)
301 (setq truncate-lines t))
305 (defun hwl-narrow-to-pe (pe)
306 (interactive "nPE: ")
310 (defun hwl-narrow-to-thread (thread)
311 (interactive "sThread: ")
312 (hwl-narrow 2 thread "")
315 (defun hwl-narrow-to-event (event)
316 (interactive "sEvent: ")
317 (hwl-narrow 3 0 event)
320 (defun hwl-narrow (mode id str)
321 ( let* ((outbuffer (get-buffer-create "*GrAnSim Narrowed*"))
322 ;(from (beginning-of-buffer))
323 ;(to (end-of-buffer))
324 ;(to (point)) ; (region-end))
325 ;(text (buffer-substring from to)) ; contains text in region
326 (w (selected-window))
327 ;(nh 5) ; height of new window
328 ;(h (window-height w)) ; height of selcted window
329 ;(h1 (if (<= h nh) (- h 1) (- h nh))) ; height of old window
330 (w1 (get-buffer-window outbuffer 'visible))
332 (infile (buffer-file-name)) ; or
333 (inbuffer (current-buffer))
335 ;(mode_opt (cond ((eq mode 1) "-p")
340 (if w1 (message "Window *GrAnSim Narrowed* already visible")
341 (split-window w nil nil))
342 (switch-to-buffer-other-window outbuffer)
344 (setq truncate-lines t)
346 ;(beginning-of-buffer)
349 ;(delete-region region-beginning region-end)
351 ;(message (format "Narrowing to Processor %d" id))
352 (call-process command nil outbuffer t "-p" (format "%d" id) infile ))
354 ;(message (format "Narrowing to Thread %d" id))
355 (call-process command nil outbuffer t "-t" (format "%s" id) infile ))
357 ;(message (format "Narrowing to Event %s" str))
358 (call-process command nil outbuffer t "-e" str infile ))
363 (defun hwl-command-on-buffer (prg opts file)
364 (interactice "CProgram:\nsOptions:\nfFile:")
365 ( let* ((outbuffer (get-buffer-create "*GrAnSim Command*"))
366 (from (beginning-of-buffer))
368 ;(to (point)) ; (region-end))
369 ;(text (buffer-substring from to)) ; contains text in region
370 (w (selected-window))
371 ;(nh 5) ; height of new window
372 ;(h (window-height w)) ; height of selcted window
373 ;(h1 (if (<= h nh) (- h 1) (- h nh))) ; height of old window
374 (w1 (get-buffer-window outbuffer 'visible))
376 (infile (buffer-file-name)) ; or
377 (inbuffer (current-buffer))
379 ;(mode_opt (cond ((eq mode 1) "-p")
384 (if w1 (message "Window *GrAnSim Command* already visible")
385 (split-window w nil nil))
386 (switch-to-buffer-other-window outbuffer)
388 (setq truncate-lines t)
390 (call-process prg nil outbuffer opts file)
394 ;; ToDo: Elisp Fcts for calling scripts like gr3ps etc
396 (define-key gr-mode-map "\C-ct" 'hwl-truncate)
397 (define-key gr-mode-map "\C-cw" 'hwl-wrap)
398 (define-key gr-mode-map "\C-ch" 'hilit-rehighlight-buffer)
399 (define-key gr-mode-map "\C-cp" 'hwl-narrow-to-pe)
400 (define-key gr-mode-map "\C-ct" 'hwl-narrow-to-thread)
401 (define-key gr-mode-map "\C-ce" 'hwl-narrow-to-event)
402 (define-key gr-mode-map "\C-c\C-e" '(lambda () (hwl-narrow-to-event "END")))
403 (define-key gr-mode-map "\C-c " 'hwl-toggle-truncate-wrap)
404 (define-key gr-mode-map "\C-cN" 'hwl-hi-node)
405 (define-key gr-mode-map "\C-cT" 'hwl-hi-thread)
406 (define-key gr-mode-map "\C-c\C-c" 'hwl-hi-clear)
408 ;; ---------------------------------------------------------------------------
409 ;; Mode for threaded C files
410 ;; ---------------------------------------------------------------------------
412 (setq auto-mode-alist
413 (append '(("\\.hc" . hc-mode))
416 (define-derived-mode hc-mode c-mode "hc Mode"
417 "Derived mode for Haskell C files."
420 (hilit-set-mode-patterns
423 ("\\(GRAN_FETCH\\|GRAN_RESCHEDULE\\|GRAN_FETCH_AND_RESCHEDULE\\|GRAN_EXEC\\|GRAN_YIELD\\)" 1 keyword)
426 ("__STG_SPLIT_MARKER" nil msg-note)
427 ("^.*_ITBL.*$" nil defun)
428 ("^\\(I\\|E\\|\\)FN.*$" nil define)
432 ; (define-key global-map [S-pause] 'hc-mode)