Skip to content

Commit 183270b

Browse files
committed
Move dump file creation into subprocess file
1 parent 43d67e7 commit 183270b

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/core/egglog-herbie.rkt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,6 @@
7777
(define insert-brfs (egglog-runner-brfs runner))
7878
(define curr-program (make-egglog-program))
7979

80-
;; Dump-file
81-
(define dump-file
82-
(cond
83-
[(flag-set? 'dump 'egglog)
84-
(define dump-dir "dump-egglog")
85-
(unless (directory-exists? dump-dir)
86-
(make-directory dump-dir))
87-
(define name
88-
(for/first ([i (in-naturals)]
89-
#:unless
90-
(file-exists? (build-path dump-dir (format "~a~a.egg" (if label label "") i))))
91-
(build-path dump-dir (format "~a~a.egg" (if label label "") i))))
92-
93-
(open-output-file name #:exists 'replace)]
94-
95-
[else #f]))
96-
9780
;; 1. Add the Prelude
9881
(prelude curr-program #:mixed-egraph? #t)
9982

@@ -166,7 +149,7 @@
166149
(egglog-program-add! `(run-schedule (repeat 1 run-extract-commands)) curr-program)
167150

168151
;;;; SUBPROCESS START ;;;;
169-
(define subproc (create-new-egglog-subprocess dump-file))
152+
(define subproc (create-new-egglog-subprocess label))
170153

171154
(thread (lambda ()
172155
(with-handlers ([exn:fail? (lambda (_) (void))])

src/core/egglog-subprocess.rkt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@
2222

2323
;; High-level function that writes the program to a file, runs it then returns output
2424
;;
25-
;; If the flag is set to dump the egglog file, since a new subprocess is starting, we can
26-
;; create a new file to dump the egglog program is and set it
27-
(define (create-new-egglog-subprocess dump-file)
25+
;; If the flag is set to dump the egglog file, creates a new dump file in dump-egglog/ directory
26+
(define (create-new-egglog-subprocess [label #f])
2827
(define egglog-path
2928
(or (find-executable-path "egglog") (error "egglog executable not found in PATH")))
3029

3130
; TODO : "RUST_BACKTRACE=1"
3231
(define-values (egglog-process egglog-output egglog-in err) (subprocess #f #f #f egglog-path))
3332

33+
;; Create dump file if flag is set
34+
(define dump-file
35+
(cond
36+
[(flag-set? 'dump 'egglog)
37+
(define dump-dir "dump-egglog")
38+
(unless (directory-exists? dump-dir)
39+
(make-directory dump-dir))
40+
(define name
41+
(for/first ([i (in-naturals)]
42+
#:unless
43+
(file-exists? (build-path dump-dir (format "~a~a.egg" (if label label "") i))))
44+
(build-path dump-dir (format "~a~a.egg" (if label label "") i))))
45+
(open-output-file name #:exists 'replace)]
46+
[else #f]))
47+
3448
(egglog-subprocess egglog-process egglog-output egglog-in err dump-file))
3549

3650
(define (send-to-egglog commands subproc #:num-extracts [num-extracts 0])

0 commit comments

Comments
 (0)