Commit 7e76e749 authored by Guy Watson's avatar Guy Watson
Browse files

Add a more concise type prefix function to the renderer

parent dbc6701c
......@@ -383,14 +383,20 @@
(let ([type (att-value 'xsmith_type n)])
(if (concrete-type? type)
(base-type-name (concretize-type type))
(eprintf "Non-concrete type encountered in renderer"))))
(begin
(eprintf (format "Non-concrete type encountered in renderer\n"))
(eprintf (format "Node: ~a Types: ~a\n\n" (node-type n) (att-value 'xsmith_type n)))
'NON-CONCRETE))))
;;Combines symbols: useful for printing things like 'i32.add'
(define (combine-symbols a b)
(let* ([a-string (symbol->string a)]
[b-string (symbol->string b)])
(string->symbol (format "~a~a" a-string b-string))))
;; Combines an node's base type and a given string. Returns a symbol.
;; This is useful for constructing symbols like i32.add
;; Usage: (prefix-type <some node> ".add")
;; Return: 'i32.add
(define (prefix-type node instruction)
(let ([type (get-base-type-name node)])
(string->symbol (format "~a~a" type instruction))))
(add-prop
wasm-like
......@@ -490,18 +496,14 @@
(append
($xsmith_render-node (ast-child 'address n))
($xsmith_render-node (ast-child 'value n))
`(,(combine-symbols
(get-base-type-name n)
'.store)
`(,(prefix-type n '.store)
,(string->symbol (format "offset=~a" (ast-child 'offset n)))
,(string->symbol (format "align=~a" (expt 2 (ast-child 'alignment n)))))
($xsmith_render-node (ast-child 'expr n))))]
[MemLoad (λ (n)
(append
($xsmith_render-node (ast-child 'address n))
`(,(combine-symbols
(get-base-type-name n)
'.load)
`(,(prefix-type n '.load)
,(string->symbol (format "offset=~a" (ast-child 'offset n)))
,(string->symbol (format "align=~a" (expt 2 (ast-child 'alignment n)))))))]
[LocalGet (λ (n)
......@@ -569,35 +571,35 @@
(add-att-rule
wasm-like math-op
[Equal (λ (n) (combine-symbols (get-base-type-name) '.eq))]
[NotEqual (λ (n) (combine-symbols (get-base-type-name n) '.ne))]
[EqualZero (λ (n) (combine-symbols (get-base-type-name n) '.eqz))]
[Addition (λ (n) (combine-symbols (get-base-type-name n) '.add))]
[Subtraction (λ (n) (combine-symbols (get-base-type-name n) '.sub))]
[Multiplication (λ (n) (combine-symbols (get-base-type-name n) '.mul))]
[DivisionSigned (λ (n) (combine-symbols (get-base-type-name n) '.div_s))]
[DivisionUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.div_u))]
[LessThanSigned (λ (n) (combine-symbols (get-base-type-name n) '.lt_s))]
[LessThanUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.lt_u))]
[GreaterThanSigned (λ (n) (combine-symbols (get-base-type-name n) '.gt_s))]
[GreaterThanUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.gt_u))]
[LessThanOrEqualSigned (λ (n) (combine-symbols (get-base-type-name n) '.le_s))]
[LessThanOrEqualUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.le_u))]
[GreaterThanOrEqualSigned (λ (n) (combine-symbols (get-base-type-name n) '.ge_s))]
[GreaterThanOrEqualUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.ge_u))]
[CountLeadingZero (λ (n) (combine-symbols (get-base-type-name n) '.clz))]
[CountTrailingZero (λ (n) (combine-symbols (get-base-type-name n) '.ctz))]
[NonZeroBits (λ (n) (combine-symbols (get-base-type-name n) '.popcnt))]
[RemainderSigned (λ (n) (combine-symbols (get-base-type-name n) '.rem_s))]
[RemainderUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.rem_u))]
[And (λ (n) (combine-symbols (get-base-type-name n) '.and))]
[Or (λ (n) (combine-symbols (get-base-type-name n) '.or))]
[Xor (λ (n) (combine-symbols (get-base-type-name n) '.xor))]
[ShiftLeft (λ (n) (combine-symbols (get-base-type-name n) '.shl))]
[ShiftRightSigned (λ (n) (combine-symbols (get-base-type-name n) '.shr_s))]
[ShiftRightUnsigned (λ (n) (combine-symbols (get-base-type-name n) '.shr_u))]
[RotateLeft (λ (n) (combine-symbols (get-base-type-name n) '.rotl))]
[RotateRight (λ (n) (combine-symbols (get-base-type-name n) '.rotr))]
[Equal (λ (n) (prefix-type n '.eq))]
[NotEqual (λ (n) (prefix-type n '.ne))]
[EqualZero (λ (n) (prefix-type n '.eqz))]
[Addition (λ (n) (prefix-type n '.add))]
[Subtraction (λ (n) (prefix-type n '.sub))]
[Multiplication (λ (n) (prefix-type n '.mul))]
[DivisionSigned (λ (n) (prefix-type n '.div_s))]
[DivisionUnsigned (λ (n) (prefix-type n '.div_u))]
[LessThanSigned (λ (n) (prefix-type n '.lt_s))]
[LessThanUnsigned (λ (n) (prefix-type n '.lt_u))]
[GreaterThanSigned (λ (n) (prefix-type n '.gt_s))]
[GreaterThanUnsigned (λ (n) (prefix-type n '.gt_u))]
[LessThanOrEqualSigned (λ (n) (prefix-type n '.le_s))]
[LessThanOrEqualUnsigned (λ (n) (prefix-type n '.le_u))]
[GreaterThanOrEqualSigned (λ (n) (prefix-type n '.ge_s))]
[GreaterThanOrEqualUnsigned (λ (n) (prefix-type n '.ge_u))]
[CountLeadingZero (λ (n) (prefix-type n '.clz))]
[CountTrailingZero (λ (n) (prefix-type n '.ctz))]
[NonZeroBits (λ (n) (prefix-type n '.popcnt))]
[RemainderSigned (λ (n) (prefix-type n '.rem_s))]
[RemainderUnsigned (λ (n) (prefix-type n '.rem_u))]
[And (λ (n) (prefix-type n '.and))]
[Or (λ (n) (prefix-type n '.or))]
[Xor (λ (n) (prefix-type n '.xor))]
[ShiftLeft (λ (n) (prefix-type n '.shl))]
[ShiftRightSigned (λ (n) (prefix-type n '.shr_s))]
[ShiftRightUnsigned (λ (n) (prefix-type n '.shr_u))]
[RotateLeft (λ (n) (prefix-type n '.rotl))]
[RotateRight (λ (n) (prefix-type n '.rotr))]
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment