Commit 038c1511 authored by Guy Watson's avatar Guy Watson
Browse files

Add different printing for main vs other functions

parent bf42b79d
...@@ -47,10 +47,11 @@ ...@@ -47,10 +47,11 @@
;; This defines the layout of the grammar. ;; This defines the layout of the grammar.
(add-to-grammar (add-to-grammar
wasm-like wasm-like
[Program #f (Func [Program #f ([main : Func]
;;[main : Func] [functions : Func *]
[globals : GlobalDeclaration *])] [globals : GlobalDeclaration *])]
[Func #f ([root : Expr] [Func #f ([root : Expr]
[name]
[localcount = (random 1 10)])] [localcount = (random 1 10)])]
[Expr #f () [Expr #f ()
#:prop may-be-generated #f] #:prop may-be-generated #f]
...@@ -424,7 +425,7 @@ ...@@ -424,7 +425,7 @@
[index (random (length targets))]) [index (random (length targets))])
(cons index (list-ref targets index)))) (cons index (list-ref targets index))))
(define (get-func-node n) (define (get-func-node n);; todo - With the addition of more functions, this is possibly broken
(if (eq? (node-type n) 'Func) (if (eq? (node-type n) 'Func)
n n
(get-func-node (parent-node n)))) (get-func-node (parent-node n))))
...@@ -475,9 +476,16 @@ ...@@ -475,9 +476,16 @@
(list (string->symbol (format "$~a" (ast-child 'name global)))) (list (string->symbol (format "$~a" (ast-child 'name global))))
'(call $addToCrc))) '(call $addToCrc)))
(reverse (ast-children (ast-child 'globals n))))))))] (reverse (ast-children (ast-child 'globals n))))))))]
[Func (λ (n) `(func (export "_func") (result i32) [Func (λ (n) ;; The main function is printed a little differently
(local ,@(make-list (ast-child 'localcount n) 'i32)) ;;todo convert to new method (if (eqv? (ast-child 'name n) "main")
,@($xsmith_render-node (ast-child 'root n))))] `(func $main (export "_main") (result i32)
(local ,@(make-list (ast-child 'localcount n) 'i32)) ;;todo convert locals to reference lifting
;;todo - allow other types than i32
,@($xsmith_render-node (ast-child 'root n)))
'(func ,(string->symbol (format "~a~a" "$" (ast-child 'name n)))
(result ,(get-base-type-name n))
(local ,@(make-list (ast-child 'localcount n) 'i32))
,@($xsmith_render-node (ast-child 'root n)))))]
[LiteralIntThirtyTwo (λ (n) (list 'i32.const (ast-child 'v n)))] [LiteralIntThirtyTwo (λ (n) (list 'i32.const (ast-child 'v n)))]
[LiteralIntSixtyFour (λ (n) (list 'i64.const (ast-child 'v n)))] [LiteralIntSixtyFour (λ (n) (list 'i64.const (ast-child 'v n)))]
[LiteralFloatThirtyTwo (λ (n) (list 'f32.const (ast-child 'v n)))] [LiteralFloatThirtyTwo (λ (n) (list 'f32.const (ast-child 'v n)))]
......
Markdown is supported
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