Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
xsmith
WebAssembly Sandbox
Commits
038c1511
Commit
038c1511
authored
Jun 15, 2020
by
Guy Watson
Browse files
Add different printing for main vs other functions
parent
bf42b79d
Changes
1
Show whitespace changes
Inline
Side-by-side
wasmlike/wasmlike.rkt
View file @
038c1511
...
...
@@ -47,10 +47,11 @@
;; This defines the layout of the grammar.
(
add-to-grammar
wasm-like
[
Program
#f
(
Func
;;[main
: Func]
[
Program
#f
(
[
main
:
Func
]
[
functions
:
Func
*
]
[
globals
:
GlobalDeclaration
*
])]
[
Func
#f
([
root
:
Expr
]
[
name
]
[
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
)
n
(
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
)))]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment