|
4 | 4 | (require "../utils/common.rkt" |
5 | 5 | "../utils/errors.rkt" |
6 | 6 | "../config.rkt" |
7 | | - "../core/rules.rkt" |
8 | 7 | "matcher.rkt" |
9 | 8 | "types.rkt" |
10 | 9 | "syntax.rkt" |
|
29 | 28 | (fprintf port "#<platform>"))]) |
30 | 29 |
|
31 | 30 | (provide *active-platform* |
32 | | - platform-lifting-rules |
33 | | - platform-lowering-rules |
34 | 31 | platform-copy |
35 | | - validate-platform! |
36 | 32 | repr-exists? |
37 | 33 | get-representation |
38 | 34 | impl-exists? |
|
68 | 64 | (define impls (make-hash)) |
69 | 65 | (create-platform reprs impls repr-costs)) |
70 | 66 |
|
71 | | -(define (validate-platform! platform) |
72 | | - (when (empty? (platform-implementations platform)) |
73 | | - (raise-herbie-error "Platform contains no operations")) |
74 | | - (for ([(name impl) (in-hash (platform-implementations platform))]) |
75 | | - (define ctx (operator-impl-ctx impl)) |
76 | | - (for ([repr (in-list (cons (context-repr ctx) (context-var-reprs ctx)))]) |
77 | | - (unless (equal? (hash-ref (platform-representations platform) (representation-name repr) #f) |
78 | | - repr) |
79 | | - (raise-herbie-error "Representation ~a not defined" (representation-name repr)))))) |
80 | | - |
81 | 67 | ;; Returns the representation associated with `name` |
82 | 68 | ;; attempts to generate the repr if not initially found |
83 | 69 | (define (get-representation name) |
|
181 | 167 | (define itypes (impl-info impl 'itype)) |
182 | 168 | (apply cost-proc (map loop args itypes))])))) |
183 | 169 |
|
184 | | -;; Rules from impl to spec (fixed for a particular platform) |
185 | | -(define/reset *lifting-rules* (make-hash)) |
186 | | - |
187 | | -;; Rules from spec to impl (fixed for a particular platform) |
188 | | -(define/reset *lowering-rules* (make-hash)) |
189 | | - |
190 | | -;; Synthesizes the LHS and RHS of lifting/lowering rules. |
191 | | -(define (impl->rule-parts impl) |
192 | | - (define vars (impl-info impl 'vars)) |
193 | | - (define spec (impl-info impl 'spec)) |
194 | | - (values vars spec (cons impl vars))) |
195 | | - |
196 | | -;; Synthesizes lifting rules for a platform platform. |
197 | | -(define (platform-lifting-rules [pform (*active-platform*)]) |
198 | | - (define impls (platform-impls pform)) |
199 | | - (for/list ([impl (in-list impls)]) |
200 | | - (hash-ref! (*lifting-rules*) |
201 | | - (cons impl pform) |
202 | | - (lambda () |
203 | | - (define name (sym-append 'lift- impl)) |
204 | | - (define-values (vars spec-expr impl-expr) (impl->rule-parts impl)) |
205 | | - (rule name impl-expr spec-expr '(lifting)))))) |
206 | | - |
207 | | -;; Synthesizes lowering rules for a given platform. |
208 | | -(define (platform-lowering-rules [pform (*active-platform*)]) |
209 | | - (define impls (platform-impls pform)) |
210 | | - (append* (for/list ([impl (in-list impls)]) |
211 | | - (hash-ref! (*lowering-rules*) |
212 | | - (cons impl pform) |
213 | | - (lambda () |
214 | | - (define name (sym-append 'lower- impl)) |
215 | | - (define-values (vars spec-expr impl-expr) (impl->rule-parts impl)) |
216 | | - (list (rule name spec-expr impl-expr '(lowering)) |
217 | | - (rule (sym-append 'lower-unsound- impl) |
218 | | - (add-unsound spec-expr) |
219 | | - impl-expr |
220 | | - '(lowering)))))))) |
221 | | - |
222 | 170 | ;; Extracts the `fpcore` field of an operator implementation |
223 | 171 | ;; as a property dictionary and expression. |
224 | 172 | (define (impl->fpcore impl) |
|
0 commit comments