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 @@
;; This defines the layout of the grammar.
[Program #f (Func
;;[main : Func]
[Program #f ([main : Func]
[functions : Func *]
[globals : GlobalDeclaration *])]
[Func #f ([root : Expr]
[localcount = (random 1 10)])]
[Expr #f ()
#:prop may-be-generated #f]
......@@ -424,7 +425,7 @@
[index (random (length targets))])
(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)
(get-func-node (parent-node n))))
......@@ -475,9 +476,16 @@
(list (string->symbol (format "$~a" (ast-child 'name global))))
'(call $addToCrc)))
(reverse (ast-children (ast-child 'globals n))))))))]
[Func (λ (n) `(func (export "_func") (result i32)
(local ,@(make-list (ast-child 'localcount n) 'i32)) ;;todo convert to new method
,@($xsmith_render-node (ast-child 'root n))))]
[Func (λ (n) ;; The main function is printed a little differently
(if (eqv? (ast-child 'name n) "main")
`(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)))]
[LiteralIntSixtyFour (λ (n) (list 'i64.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