Skip to content

Commit 010f6c3

Browse files
committed
Add Pushf, Popf, and move symbol->label into a86.
1 parent c6e7670 commit 010f6c3

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

langs/a86/ast.rkt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@
238238
(instruct Sal (dst i) check:shift)
239239
(instruct Sar (dst i) check:shift)
240240
(instruct Push (a1) check:push)
241+
(instruct Pushf () check:none)
242+
(instruct Popf () check:none)
241243
(instruct Pop (a1) check:register)
242244
(instruct Lea (dst x) check:lea)
243245
(instruct Not (x) check:register)
@@ -385,3 +387,27 @@
385387
(define (check-has-initial-label asm)
386388
(unless (findf Label? asm)
387389
(error 'prog "no initial label found")))
390+
391+
392+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
393+
;; Symbol to Label
394+
395+
;; Symbol -> Label
396+
;; Produce a symbol that is a valid Nasm label
397+
;; Guarantees that (eq? s1 s2) <=> (eq? (symbol->label s1) (symbol->label s1))
398+
(provide symbol->label)
399+
(define (symbol->label s)
400+
(string->symbol
401+
(string-append
402+
"label_"
403+
(list->string
404+
(map (λ (c)
405+
(if (or (char<=? #\a c #\z)
406+
(char<=? #\A c #\Z)
407+
(char<=? #\0 c #\9)
408+
(memq c '(#\_ #\$ #\# #\@ #\~ #\. #\?)))
409+
c
410+
#\_))
411+
(string->list (symbol->string s))))
412+
"_"
413+
(number->string (eq-hash-code s) 16))))

langs/a86/printer.rkt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@
211211
[(Push a)
212212
(string-append tab "push "
213213
(arg->string a))]
214+
[(Pushf)
215+
(string-append tab "pushf")]
216+
[(Popf)
217+
(string-append tab "popf")]
214218
[(Pop r)
215219
(string-append tab "pop "
216220
(reg->string r))]
@@ -234,6 +238,8 @@
234238
" equ "
235239
(number->string c))]
236240

241+
[(Db (? bytes? bs))
242+
(apply string-append tab "db " (add-between (map number->string (bytes->list bs)) ", "))]
237243
[(Db x)
238244
(string-append tab "db " (arg->string x))]
239245
[(Dw x)

0 commit comments

Comments
 (0)