├── .gitignore
├── .gitmodules
├── .travis.yml
├── LICENSE
├── Makefile
├── README.md
├── alias.c
├── asmjs.dot
├── asmjs.gp
├── asmjs.jpg
├── asmjs.org
├── asmjs.svg
├── bin
├── caching-interpreter
├── interpolate
├── interpreter
├── interpreter-wasm
├── interpreter-wasm32
├── interpreter-wasm64
├── interpreter-wasm64-native
├── jsexport
├── jsexport-extract
├── multifile-add1
├── prepare
├── prevify
├── stitch
├── wasmify-wasm32
└── wasmify-wasm32-lib
├── binfmt_misc
├── binfmt_misc
├── binfmt_misc-wasm
├── binfmt_misc-wasm32
└── binfmt_misc-wasm64
├── bootstrap
├── asmjs.js
└── interpolate-cache.pl
├── config
└── config.sub
├── dyninfo
└── dyninfo.pl
├── examples
├── 001-graphviz
│ └── example.html
└── 002-perl
│ └── example.html
├── exec_and_unlink
├── exec_and_unlink.c
└── exec_and_unlink_fd3.c
├── foo.js
├── headers
├── wasm32-globals.s
└── wasm32-headers.s
├── hexify
└── hexify.c
├── include
├── js.h
├── js2.h
├── js3.h
├── jsexport.h
└── zeropage.h
├── jsc
├── asm-debug.jsc
├── asm-main.jsc
├── asm-range.jsc
├── asm-thinthin-jsexport.jsc
├── asm-thinthin.jsc
├── asm-vt100.jsc
├── asmjs-system.jsc
├── js2.jsc
├── js3.jsc
├── wasm32-boot.jsc
├── wasm32-forkedworker.jsc
├── wasm32-system.jsc
├── wasm32-worker.jsc
└── wasm64-system.jsc
├── ld.txt
├── lds
├── asmjs-dat.lds
├── asmjs-js1ify.lds
├── asmjs-loose.x
├── asmjs-multifile.x
├── asmjs-tight.x
├── asmjs.lds
├── wasm32-wasmify.lds
└── wasm32.cpp-lds
├── lib
├── 64m.c
├── asmjs.S
├── loop.cc
└── mfinfo.c
├── libdl
├── Makefile
└── libdl.c
├── nexamples
└── 001-dot
│ └── example.html
├── notes
├── binaryen
│ ├── broken.ast
│ ├── broken2.ast
│ ├── broken3.ast
│ ├── broken4.cpp
│ ├── broken5.js
│ ├── broken6.ast
│ ├── broken7.txt
│ └── list.txt
├── build-dot.txt
├── debian.txt
└── secondary.txt
├── perf
├── bestfit.pl
├── measure.pl
├── measure2.pl
├── measure3.pl
└── plottify.pl
├── scripts
└── glibc-generic-diff.bash
├── tests
├── 001-do-nothing
│ └── 001-do-nothing.c
├── 002-hello-world-infloop
│ └── 002-hello-world-infloop.c
├── 003-hello-world-infloop-count
│ └── 003-hello-world-infloop-count.c
├── 004-hello-world-infloop-count
│ └── 004-hello-world-infloop-count.c
├── 005-hello-world-infloop-double
│ └── 005-hello-world-infloop-double.c
├── 006-function-call
│ └── 006-function-call.c
├── 007-argc-argv
│ └── 007-argc-argv.c
├── 008-argi
│ └── 008-argi.c
├── 009-argi
│ └── 009-argi.c
├── 010-argi-printstr
│ └── 010-argi-printstr.c
├── 011-printstr
│ └── 011-printstr.c
├── 012-printf-doubles
│ └── 012-printf-doubles.c
├── 013-asm
│ └── 013-asm.c
├── 014-count
│ └── 014-count.c
├── 015-sscanf-fscanf
│ └── 015-sscanf-fscanf.c
├── 016-double
│ └── 016-double.c
├── 017-fptr
│ └── 017-fptr.c
├── 018-ptr
│ └── 018-ptr.c
├── 019-varargs
│ └── 019-varargs.c
├── 020-int-varargs
│ └── 020-int-varargs.c
├── 021-mixed-varargs
│ └── 021-mixed-varargs.c
├── 022-stack
│ └── 022-stack.c
├── 023-fptr
│ └── 023-fptr.c
├── 024-nofloat
│ └── 024-nofloat.c
├── 025-nofloat
│ └── 025-nofloat.c
├── 026-undefined
│ └── 026-undefined.c
├── 027-intsizes
│ └── 027-intsizes.c
├── 028-twostrings
│ └── 028-twostrings.c
├── 029-flush
│ └── 029-flush.c
├── 030-myprintf
│ └── 030-myprintf.c
├── 031-myprintf-main
│ └── 031-myprintf-main.c
├── 032-myprintf-main-myvalist
│ └── 032-myprintf-main-myvalist.c
├── 033-myprintf-main-myvalist
│ └── 033-myprintf-main-myvalist.c
├── 034-myfprintfi
│ └── 034-myfprintfi.c
├── 035-floor
│ └── 035-floor.c
├── 036-funcall
│ └── 036-funcall.c
├── 037-callbyref
│ └── 037-callbyref.cc
├── 038-hw-terminates
│ └── 038-hw-terminates.c
├── 039-cc-float-double
│ └── 039-cc-float-double.c
├── 040-fdopen-argi
│ └── 040-fdopen-argi.c
├── 041-addrof
│ └── 041-addrof.c
├── 042-putchar
│ └── 042-putchar.c
├── 043-printf
│ └── 043-printf.c
├── 044-printf-fcall
│ └── 044-printf-fcall.c
├── 045-printf-fcall-loop
│ └── 045-printf-fcall-loop.c
├── 046-printf-fcall-loop
│ └── 046-printf-fcall-loop.c
├── 047-printf-fcall-loop
│ └── 047-printf-fcall-loop.c
├── 048-printf-fcall-infloop
│ └── 048-printf-fcall-infloop.c
├── 049-printf-rec
│ └── 049-printf-rec.c
├── 050-exit3
│ └── 050-exit3.c
├── 051-exit
│ └── 051-exit.c
├── 052-signal
│ └── 052-signal.c
├── 053-signal-fcall
│ └── 053-signal-fcall.c
├── 054-signal-fcall
│ └── 054-signal-fcall.c
├── 055-setjmp-longjmp
│ └── 055-setjmp-longjmp.c
├── 056-ldexpf
│ └── 056-ldexpf.c
├── 057-ffsll
│ └── 057-ffsll.c
├── 058-emutls
│ └── 058-emutls.c
├── 059-wrap-write
│ └── 059-wrap-write.c
├── 060-gcvt
│ └── 060-gcvt.c
├── 061-gcvt
│ └── 061-gcvt.c
├── 062-printf-fflush
│ └── 062-printf-fflush.c
├── 063-attribute-cleanup
│ └── 063-attribute-cleanup.c
├── 064-glibc-example
│ └── 064-glibc-example.c
├── 065-glibc-example
│ └── 065-glibc-example.c
├── 066-exp-1
│ └── 066-exp-1.c
├── 067-my-setjmp-longjmp
│ └── 067-my-setjmp-longjmp.c
├── 068-setjmp-longjmp
│ └── 068-setjmp-longjmp.c
├── 069-cc-return
│ └── 069-cc-return.c
├── 070-breakpoint-infloop
│ └── 070-breakpoint-infloop.c
├── 071-breakpoint-infloop-fcall
│ └── 071-breakpoint-infloop-fcall.c
├── 072-infloop
│ └── 072-infloop.c
├── 073-infloop-sprintf
│ └── 073-infloop-sprintf.c
├── 074-malloc
│ └── 074-malloc.c
├── 075-wrap-write
│ └── 075-wrap-write.c
├── 076-wrap-write
│ └── 076-wrap-write.c
├── 077-longloop
│ └── 077-longloop.c
├── 078-delayed
│ └── 078-delayed.c
├── 079-sigaction
│ └── 079-sigaction.c
├── 080-i
│ └── 080-i.c
├── 081-asm-rename
│ └── 081-asm-rename.c
├── 082-breakpoint
│ └── 082-breakpoint.c
├── 083-setjmp-longjmp
│ └── 083-setjmp-longjmp.c
├── 084-unord
│ └── 084-unord.c
├── 085-asm
│ └── 085-asm.c
├── 086-asmjs.js
├── 087-asmjs.js
├── 088-asmjs.js
├── 089-asmjs.js
├── 090-bp1
│ └── 090-bp1.c
├── 091-bra
│ └── 091-bra.c
├── 092-dwarf2eh001
│ └── 092-dwarf2eh001.cpp
├── 093-dwarf2eh002
│ └── 093-dwarf2eh002.c
├── 094-dwarf2eh003
│ └── 094-dwarf2eh003.cpp
├── 095-dwarf2eh004
│ └── 095-dwarf2eh004.cpp
├── 096-f_return
│ └── 096-f_return.c
├── 097-gdb01
│ └── 097-gdb01.c
├── 098-gdb02
│ └── 098-gdb02.c
├── 099-import-macro-c
│ └── 099-import-macro-c.c
├── 100-just-break
│ └── 100-just-break.c
├── 101-just-break
│ └── 101-just-break.c
├── 102-just-write
│ └── 102-just-write.s
├── 103-linkme1
│ └── 103-linkme1.c
├── 104-linkme2
│ └── 104-linkme2.c
├── 105-minidebug
│ └── 105-minidebug.c
├── 106-perl01
│ └── 106-perl01.c
├── 107-qsort
│ └── 107-qsort.c
├── 108-setjmp-new
│ └── 108-setjmp-new.c
├── 109-size_t
│ └── 109-size_t.c
├── 110-stat
│ └── 110-stat.c
├── 111-stdinouterr
│ └── 111-stdinouterr.c
├── 112-testreloc4
│ └── 112-testreloc4.s
├── 113-unorddf2
│ └── 113-unorddf2.c
├── 114-trampoline
│ └── 114-trampoline.c
├── 115-trampoline
│ └── 115-trampoline.c
├── 116-trampoline
│ └── 116-trampoline.c
├── 117-environment
│ └── 117-environment.c
├── 118-fork-exec
│ └── 118-fork-exec.c
├── 119-execve.js
├── 120-builtin-setjmp-longjmp
│ └── 120-builtin-setjmp-longjmp.c
├── 121-dwarf2eh
│ └── 121-dwarf2eh.cpp
├── 122-eh-return
│ └── 122-eh-return.c
├── 123-bra
│ └── 123-bra.c
├── 124-dwarf2eh
│ └── 124-dwarf2eh.cpp
├── 125-mode-di
│ └── 125-mode-di.c
├── 126-broken-link
│ ├── a.cpp
│ └── b.cpp
├── 127-unaligned
│ └── 127-unaligned.cpp
├── 128-pgrps
│ └── 128-pgrps.c
├── 129-pgrps
│ └── 129-pgrps.c
├── 130-link
│ ├── ext.c
│ └── main.c
├── 131-jsexport
│ └── 131-jsexport.c
├── 132-linked-list
│ ├── addlink.sh
│ ├── data.S
│ ├── linked-list-0.lds
│ ├── linked-list-1.lds
│ ├── linked-list.lds
│ └── run.sh
├── 133-multifile
│ ├── README.org
│ ├── data.S
│ ├── multifile-0.lds
│ ├── multifile-more.lds
│ ├── multifile.lds
│ ├── run-executable.sh
│ └── run.sh
├── 134-multifile
│ ├── README.org
│ ├── add1.sh
│ ├── data.S
│ ├── multifile-0.lds
│ ├── multifile-more.lds
│ ├── multifile.lds
│ ├── prevify.sh
│ ├── run-executable.sh
│ └── run.sh
├── 135-multifile
│ └── 135-multifile.c
├── 136-multifile
│ └── 136-multifile.c
├── 137-jsexport-loop
│ └── 137-jsexport-loop.cc
├── 137-log.txt
├── 137-two-functions
│ └── 137-two-functions.c
├── 138-countloop
│ └── 138-countloop.c
├── 139-function-call
│ └── 139-function-call.c
├── 140-extcall
│ └── 140-extcall.c
├── 141-extcall
│ └── 141-extcall.c
├── 142-arith
│ └── 142-arith.c
├── 143-import-macros
│ └── 143-import-macros.s
├── 143-syscall
│ └── 143-syscall.c
├── 144-primes
│ └── 144-primes.c
├── 145-wasm-as
│ └── 145-wasm-as.s
├── 146-b
│ └── 146-b.s
├── 146-wasm-macros
│ └── 146-wasm-macros.s
├── 147-a
│ └── 147-a.s
├── 147-b
│ └── 147-b.s
├── 148-wasm-macros
│ └── 148-wasm-macros.s
├── 149-printloop
│ └── 149-printloop.c
├── 150-divide
│ └── 150-divide.c
├── 151-uhwhat
│ └── 151-uhwhat.c
├── 152-flush
│ └── 152-flush.c
├── 153-constructor
│ └── 153-constructor.cpp
├── 154-dynlink
│ ├── 001-dso.c
│ ├── 002-main.c
│ └── 003-combined.c
├── 155-dlopen
│ └── 155-dlopen.c
├── 156-async
│ └── 156-async.s
├── 156-provide-x
│ └── 156-provide-x.c
├── 157-async
│ └── 157-async.s
├── 157-minimal
│ └── 157-minimal.s
├── 158-async
│ └── 158-async.s
├── 159-async
│ └── 159-async.c
├── 160-dlopen-fun
│ └── 160-dlopen-fun.c
├── 161-libc
│ └── 161-libc.c
├── 162-printf-in-dym
│ └── 162-printf-in-dym.c
├── 163-dlopen-again
│ └── 163-dlopen-again.c
├── 164-hello-world-infloop
│ └── 164-hello-world-infloop.c
├── 165-hello-world-dircall
│ └── 165-hello-world-dircall.c
├── 166-hello-world-dircall
│ └── 166-hello-world-dircall.c
├── 167-hello-world-dircall
│ └── 167-hello-world-dircall.c
├── 168-dynlink
│ ├── 001-main.c
│ └── 002-x.c
├── 169-dynlink
│ ├── 001-main.c
│ └── 002-f.c
├── 170-dlload
│ ├── 001-main.c
│ └── 002-x.c
├── 171-dlload-dep
│ ├── 001-main.c
│ ├── 002-x.c
│ ├── 003-f.c
│ ├── 004-stdmain.c
│ └── Makefile
├── 172-dlload-stdapi
│ ├── 001-main.c
│ ├── 002-x.c
│ ├── 003-f.c
│ ├── 004-stdmain.c
│ └── Makefile
├── 173-libdl
│ ├── 001-main.c
│ ├── 002-x.c
│ ├── 003-f.c
│ ├── 004-stdmain.c
│ ├── 005-libdl.c
│ └── Makefile
├── 174-libdl
│ ├── 001-main.c
│ ├── 002-x.c
│ ├── 003-f.c
│ ├── 004-stdmain.c
│ ├── 005-libdl.c
│ └── Makefile
├── 175-lazyload
│ ├── 001-main.c
│ ├── 002-lazyload.S
│ └── 003-lazyload.c
├── 176-inlinable-import
│ └── 176-inlinable-import.c
├── 177-weak-symbol
│ └── 177-weak-symbol.c
├── 178-strlen
│ └── 178-strlen.c
├── 179-if-else
│ └── 179-if-else.c
├── 180-while
│ └── 180-while.c
├── 181-plt
│ ├── 001-lib.c
│ └── 002-user.c
├── 182-rawcall
│ └── 182-rawcall.c
├── 183-rawcall-nary
│ ├── 001.S
│ └── 002.c
├── 184-static-constructor
│ └── 184-static-constructor.cpp
├── 185-weaksym
│ └── 185-weaksym.c
├── 186-static-constructor
│ └── 186-static-constructor.cpp
├── 187-plt
│ └── 187-plt.c
├── 188-weaksym
│ └── 188-weaksym.c
├── 189-hidden-weaksym
│ └── 189-hidden-weaksym.c
├── 190-weakdef
│ ├── 001.c
│ └── 002.S
├── 191-dircall
│ └── 191-dircall.c
├── 192-hidden-def
│ └── 192-hidden-def.c
├── 193-use-hidden-def
│ └── 193-use-hidden-def.c
├── 194-conftest.c
├── 194-conftest
│ └── 194-conftest.c
├── 195-dropped-symbol
│ ├── 001-define-symbol.c
│ └── 002-reference-symbol.c
├── 196-versions
│ ├── 001-versioned.c
│ └── 002-reference.c
└── test.lds
├── testsuite
├── config
│ └── default.exp
├── features
│ ├── 001-rawcall.c
│ ├── 001-rawcall.d
│ ├── 002-export.c
│ ├── 003-import.c
│ ├── 004-import-var.c
│ ├── 004-import-var.d
│ ├── 005-copyreloc.c
│ ├── 005-copyreloc.d
│ └── features.exp
├── gcc
│ ├── tramp.c
│ └── tramp2.c
├── lib
│ └── lib.exp
├── new
│ ├── 001-fail.c
│ ├── 001-fail.d
│ ├── 002-warning.c
│ ├── 002-warning.d
│ ├── 003-head.c
│ ├── 003-head.d
│ ├── 004-symbols.c
│ ├── 005-stackcall.c
│ ├── 005-stackcall.d
│ ├── 006-idiv.c
│ ├── 007-exception.cpp
│ ├── 007-exception.d
│ ├── 008-exception-class.cpp
│ ├── 008-exception-class.d
│ ├── 008-malloc.c
│ ├── 008-malloc.d
│ ├── 010-weaksym.c
│ ├── 010-weaksym.d
│ ├── 011-weaksym.c
│ ├── 011-weaksym.d
│ └── new.exp
└── old
│ ├── 001-do-nothing.c
│ ├── 001-do-nothing.d
│ ├── 002-hello-world-infloop.c
│ ├── 002-hello-world-infloop.d
│ ├── 003-hello-world-infloop-count.c
│ ├── 003-hello-world-infloop-count.d
│ ├── 004-hello-world-infloop-count.c
│ ├── 004-hello-world-infloop-count.d
│ ├── 005-hello-world-infloop-double.c
│ ├── 005-hello-world-infloop-double.d
│ ├── 006-function-call.c
│ ├── 006-function-call.d
│ ├── 007-argc-argv.c
│ ├── 008-argi.c
│ ├── 009-argi.c
│ ├── 010-argi-printstr.c
│ ├── 011-printstr.c
│ ├── 012-printf-doubles.c
│ ├── 013-asm.c
│ ├── 014-count.c
│ ├── 015-sscanf-fscanf.c
│ ├── 016-double.c
│ ├── 017-fptr.c
│ ├── 017-fptr.d
│ ├── 018-ptr.c
│ ├── 019-varargs.c
│ ├── 020-int-varargs.c
│ ├── 021-mixed-varargs.c
│ ├── 022-stack.c
│ ├── 023-fptr.c
│ ├── 024-nofloat.c
│ ├── 025-nofloat.c
│ ├── 026-undefined.c
│ ├── 027-intsizes.c
│ ├── 028-twostrings.c
│ ├── 029-flush.c
│ ├── 030-myprintf.c
│ ├── 031-myprintf-main.c
│ ├── 032-myprintf-main-myvalist.c
│ ├── 033-myprintf-main-myvalist.c
│ ├── 034-myfprintfi.c
│ ├── 035-floor.c
│ ├── 036-funcall.c
│ ├── 038-hw-terminates.c
│ ├── 039-cc-float-double.c
│ ├── 040-fdopen-argi.c
│ ├── 041-addrof.c
│ ├── 042-putchar.c
│ ├── 043-printf.c
│ ├── 044-printf-fcall.c
│ ├── 045-printf-fcall-loop.c
│ ├── 046-printf-fcall-loop.c
│ ├── 047-printf-fcall-loop.c
│ ├── 048-printf-fcall-infloop.c
│ ├── 049-printf-rec.c
│ ├── 050-exit3.c
│ ├── 051-exit.c
│ ├── 052-signal.c
│ ├── 053-signal-fcall.c
│ ├── 054-signal-fcall.c
│ ├── 055-setjmp-longjmp.c
│ ├── 056-ldexpf.c
│ ├── 057-ffsll.c
│ ├── 058-emutls.c
│ ├── 059-wrap-write.c
│ ├── 060-gcvt.c
│ ├── 061-gcvt.c
│ ├── 062-printf-fflush.c
│ ├── 063-attribute-cleanup.c
│ ├── 064-glibc-example.c
│ ├── 065-glibc-example.c
│ ├── 066-exp-1.c
│ ├── 067-my-setjmp-longjmp.c
│ ├── 068-setjmp-longjmp.c
│ ├── 069-cc-return.c
│ ├── 070-breakpoint-infloop.c
│ ├── 071-breakpoint-infloop-fcall.c
│ ├── 072-infloop.c
│ ├── 073-infloop-sprintf.c
│ ├── 074-malloc.c
│ ├── 075-wrap-write.c
│ ├── 076-wrap-write.c
│ ├── 077-longloop.c
│ ├── 078-delayed.c
│ ├── 079-sigaction.c
│ ├── 080-i.c
│ ├── 081-asm-rename.c
│ ├── 082-breakpoint.c
│ ├── 083-setjmp-longjmp.c
│ ├── 084-unord.c
│ ├── 085-asm.c
│ ├── 090-bp1.c
│ ├── 091-bra.c
│ ├── 092-dwarf2eh001.cpp
│ ├── 092-dwarf2eh001.d
│ ├── 093-dwarf2eh002.cpp
│ ├── 093-dwarf2eh002.d
│ ├── 094-dwarf2eh003.cpp
│ ├── 094-dwarf2eh003.d
│ ├── 095-dwarf2eh004.cpp
│ ├── 095-dwarf2eh004.d
│ ├── 096-f_return.c
│ ├── 097-gdb01.c
│ ├── 098-gdb02.c
│ ├── 099-import-macro-c.c
│ ├── 100-just-break.c
│ ├── 101-just-break.c
│ ├── 103-linkme1.c
│ ├── 104-linkme2.c
│ ├── 105-minidebug.c
│ ├── 106-perl01.c
│ ├── 107-qsort.c
│ ├── 108-setjmp-new.c
│ ├── 109-size_t.c
│ ├── 110-stat.c
│ ├── 111-stdinouterr.c
│ ├── 113-unorddf2.c
│ ├── 114-trampoline.c
│ ├── 115-trampoline.c
│ ├── 116-trampoline.c
│ ├── 117-environment.c
│ ├── 118-fork-exec.c
│ ├── 120-builtin-setjmp-longjmp.c
│ ├── 122-eh-return.c
│ ├── 123-bra.c
│ ├── 125-mode-di.c
│ ├── 128-pgrps.c
│ ├── 129-pgrps.c
│ ├── 131-jsexport.c
│ ├── 135-multifile.c
│ ├── 136-multifile.c
│ ├── 137-two-functions.c
│ ├── 138-countloop.c
│ ├── 139-function-call.c
│ ├── 140-extcall.c
│ ├── 141-extcall.c
│ ├── 142-arith.c
│ ├── 143-syscall.c
│ ├── 144-primes.c
│ ├── 149-printloop.c
│ ├── 150-divide.c
│ ├── 151-uhwhat.c
│ ├── 152-flush.c
│ ├── 155-dlopen.c
│ ├── 156-provide-x.c
│ ├── 159-async.c
│ ├── 160-dlopen-fun.c
│ ├── 161-libc.c
│ ├── 162-printf-in-dym.c
│ ├── 163-dlopen-again.c
│ ├── 164-hello-world-infloop.c
│ ├── 165-hello-world-dircall.c
│ ├── 166-hello-world-dircall.c
│ ├── 167-hello-world-dircall.c
│ ├── 176-inlinable-import.c
│ ├── 177-weak-symbol.c
│ ├── 178-strlen.c
│ ├── 179-if-else.c
│ ├── 180-while.c
│ ├── 182-rawcall.c
│ ├── 182-rawcall.d
│ ├── 183-rawcall-nary.d
│ ├── 183-rawcall-nary
│ ├── 001.S
│ └── 002.c
│ ├── 185-weaksym.c
│ ├── 185-weaksym.d
│ ├── 187-plt.c
│ ├── 187-plt.d
│ ├── 188-weaksym.c
│ ├── 188-weaksym.d
│ ├── 189-hidden-weaksym.c
│ ├── 189-hidden-weaksym.d
│ └── old.exp
├── tramptest.c
├── uintptr.c
├── unsorted-experimentation
├── any.cpp
├── argh.cpp
├── asm-hack.cpp
├── builtin_constant_p.cpp
├── builtin_constant_p_10.cpp
├── builtin_constant_p_2.cpp
├── builtin_constant_p_3.cpp
├── builtin_constant_p_4.cpp
├── builtin_constant_p_5.cpp
├── builtin_constant_p_6.cpp
├── builtin_constant_p_7.cpp
├── builtin_constant_p_8.cpp
├── builtin_constant_p_9.cpp
├── concepts.cpp
├── concepts2.cpp
├── concepts3.cpp
├── const_const_const.cpp
├── const_const_const_2.cpp
├── const_const_const_3.cpp
├── deduce-bw.cpp
├── dlopen.c
├── exceptions-again.cpp
├── extend-deduce-function.cpp
├── foo.c
├── foo2.c
├── foo3.c
├── foo4.c
├── foo5.c
├── foo5.cpp
├── foo6.cpp
├── foo7.cpp
├── huh2.cpp
├── jsexport-extracted.cpp
├── jsexport-generated.cpp
├── jsexport.cpp
├── lift-c-typeinfo.cpp
├── lift-double-2.cpp
├── lift-double-3.cpp
├── lift-double.cpp
├── lift-ice-2.cpp
├── lift-ice-3.cpp
├── lift-ice-4.cpp
├── lift-ice-5.cpp
├── lift-ice-6.cpp
├── lift-ice-7.cpp
├── lift-ice.cpp
├── lift-main.cpp
├── lift-thisshouldwork.cpp
├── lift.cpp
├── lift2.cpp
├── lift3.cpp
├── linkme1.c
├── linkme2.c
├── ptm.cpp
├── runthis.sh
├── runthis2.sh
├── runthis3.sh
├── runthis4.sh
├── signature-header.pl
├── standard-gcc-depends-on-Ox.cpp
├── test.cpp
├── test2.cpp
├── thingy.cpp
├── typeid-test.cpp
├── vartemp.cpp
├── vartemp2.cpp
├── wasm-experimentation
│ ├── as-to-wasm.bash
│ ├── example.pwas
│ ├── hello-world.c
│ ├── ld-bug.lds
│ ├── wasm-dataify.lds
│ ├── wasm-headers.s
│ ├── wasm-macros.s
│ ├── wasm-pwasify.lds
│ ├── wasm-test.s
│ ├── wasm-translate.scm
│ ├── wasm.cpp-lds
│ ├── wasm.h
│ ├── wasm.lds
│ ├── wasm.lds.backup
│ ├── wasm.txt
│ ├── wasm2.lds
│ ├── wasm2gnuc.scm
│ ├── wasm64-translate.scm
│ ├── wasm64lib.html
│ ├── wasm64lib.js
│ ├── wasmglue.js
│ ├── wasmlib.html
│ └── wasmlib.js
├── weaksyms.c
└── weirdhack.cpp
├── unsorted
├── blah.js
├── import.c
├── lazyload.c
└── lazyload2.c
├── wasm.dot
├── wasm.org
├── wasm32-header-macros.s
├── wasm32-test.s
├── wasm32.org
├── wasmparse
└── wasmparse.pl
└── wasmrewrite
├── wasm2s-macros.s
├── wasm2s.c
├── wasmextract.c
├── wasmrewrite.c
└── wasmsect.c
/README.md:
--------------------------------------------------------------------------------
1 | This is pre-release software: feel free to play with it, but be aware that things might not yet be in fully working order and may be subject to change even if they are. Also, it would be great if you could email the author at pipcet@gmail.com with any comments, experiences, bug reports (but feel free to use GitHub instead), and problems.
2 |
3 | Build instructions
4 |
5 | * clone recursively
6 | * `eval $(make env)`
7 | * `make build/binfmt_misc.install` (this will call `sudo`)
8 | * `make all`
9 |
10 | See the [wasm32-specific documentation](https://github.com/pipcet/asmjs/blob/everything/wasm32.org) or the [project documentation](https://github.com/pipcet/asmjs/blob/everything/asmjs.org) for more information.
11 |
--------------------------------------------------------------------------------
/alias.c:
--------------------------------------------------------------------------------
1 | extern int sprintf (char *__s, ...) __attribute__ ((__nothrow__));
2 | extern __typeof (sprintf) sprintf __attribute__ ((visibility ("hidden")));
3 |
4 | int __sprintf(char *s, ...)
5 | {
6 | return 0;
7 | }
8 |
9 | extern __typeof (__sprintf) sprintf __attribute__ ((alias ("__sprintf"))) __attribute__((visibility("default")));
10 |
--------------------------------------------------------------------------------
/asmjs.gp:
--------------------------------------------------------------------------------
1 | digraph G {
2 | "Assembler source" -> "ELF object file";
3 | "ELF object file" -> "ELF library";
4 | "ELF object file" -> "ELF executable";
5 | }
--------------------------------------------------------------------------------
/asmjs.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pipcet/asmjs/7181da13396b01847924455e63ffddf414ec3a2f/asmjs.jpg
--------------------------------------------------------------------------------
/bin/interpreter-wasm:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TMP1=$(mktemp);
3 | TMP2=$(mktemp);
4 | TMP3=$(mktemp);
5 | TMP4=$(mktemp);
6 | TMP5=$(mktemp);
7 | TMP6=$(mktemp);
8 | TMP7=$(mktemp);
9 | TMP8=$(mktemp);
10 | TMP9=$(mktemp);
11 | TMPD=$(mktemp -d);
12 | if [ x"$JS" = x ]; then
13 | JS=$(which js)
14 | fi
15 | if [ x"$WASMDIR" = x ]; then
16 | WASMDIR=$HOME/git/wasm
17 | fi
18 | if [ x"$DELAY" = x ]; then
19 | DELAY=1
20 | fi
21 | (echo "var path = \"$1\";"; cat $WASMDIR/js/wasm32.js) > $TMP7
22 | (sleep $DELAY && rm $TMP6 $TMP7) & disown
23 | chmod u+x $TMP7
24 | # ./wasmrewrite/wasmsect <(echo "console.log('hi')") >> $TMP8
25 | if [ x"$GDB" != x ]; then
26 | mkfifo $TMPD/in
27 | mkfifo $TMPD/out
28 | (dd bs=1 if=$TMPD/out | nc -l -p 7777 | dd bs=1 of=$TMPD/in) &
29 | exec $JS $JSFLAGS $TMP7 "$@" 3<$TMPD/in 4>$TMPD/out
30 | else
31 | exec $JS $JSFLAGS $TMP7 "$@"
32 | fi
33 |
--------------------------------------------------------------------------------
/bin/jsexport:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TMP1=$(mktemp);
3 | TMP2=$(mktemp);
4 | TMP3=$(mktemp);
5 | TMP4=$(mktemp);
6 | TMP5=$(mktemp);
7 | TMP6=$(mktemp);
8 | TMP7=$(mktemp);
9 | TMP8=$(mktemp);
10 | TMPD=$(mktemp -d);
11 | if [ x"$ASMJSDIR" = x ]; then
12 | ASMJSDIR=$HOME/git/asmjs
13 | fi
14 | cat $ASMJSDIR/include/jsexport.h > $TMP1.cc
15 | asmjs-virtual-asmjs-objcopy --dump-section .jsexport=$TMP5 "$1" || exit 1
16 | $ASMJSDIR/bin/jsexport-extract $TMP5 >> $TMP1.cc || exit 1
17 | asmjs-virtual-asmjs-g++ -std=gnu++1z -fno-function-sections -fno-data-sections -fconcepts -c $TMP1.cc -o $TMP2 || exit 1
18 | $ASMJSDIR/bin/prevify "$1" $TMP6
19 | asmjs-virtual-asmjs-ld -T $ASMJSDIR/lds/asmjs-multifile.x $TMP6 $TMP2 $ASMJSDIR/asmjs-virtual-asmjs/asmjs-virtual-asmjs/lib/libstdc++.a $ASMJSDIR/asmjs-virtual-asmjs/asmjs-virtual-asmjs/lib/libc.a $ASMJSDIR/asmjs-virtual-asmjs/lib/gcc/asmjs-virtual-asmjs/7.0.0/libgcc.a -o "$2" || exit 1
20 |
--------------------------------------------------------------------------------
/bin/jsexport-extract:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use English qw(all);
3 | use strict;
4 |
5 | $INPUT_RECORD_SEPARATOR = "\0";
6 |
7 | my %seen;
8 |
9 | while (<>) {
10 | chomp;
11 | next if $seen{$_}++;
12 | print $_;
13 | print "\n";
14 | }
15 |
--------------------------------------------------------------------------------
/bin/multifile-add1:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TMP1=$(mktemp);
3 | TMP2=$(mktemp);
4 | TMP3=$(mktemp);
5 | TMP4=$(mktemp);
6 | TMP5=$(mktemp);
7 | TMP6=$(mktemp);
8 | TMP7=$(mktemp);
9 | TMP8=$(mktemp);
10 | TMPD=$(mktemp -d);
11 | if [ x"$ASMJSDIR" = x ]; then
12 | ASMJSDIR=$HOME/git/asmjs
13 | fi
14 | $ASMJSDIR/bin/prevify "$1" $TMP6
15 | asmjs-virtual-asmjs-ld -T $ASMJSDIR/lds/asmjs-multifile.x $TMP6 "$2" $ASMJSDIR/asmjs-virtual-asmjs/asmjs-virtual-asmjs/lib/libstdc++.a $ASMJSDIR/asmjs-virtual-asmjs/asmjs-virtual-asmjs/lib/libc.a $ASMJSDIR/asmjs-virtual-asmjs/lib/gcc/asmjs-virtual-asmjs/7.0.0/libgcc.a -o "$3" || exit 1
16 |
--------------------------------------------------------------------------------
/bin/prepare:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TMP1=$(mktemp);
3 | TMP2=$(mktemp);
4 | TMP3=$(mktemp);
5 | TMP4=$(mktemp);
6 | TMP5=$(mktemp);
7 | TMP6=$(mktemp);
8 | TMP7=$(mktemp);
9 | TMP8=$(mktemp);
10 | if [ x"$ASMJSDIR" = x ]; then
11 | ASMJSDIR=$HOME/git/asmjs
12 | fi
13 | asmjs-virtual-asmjs-objcopy --dump-section .data=$TMP2 --dump-section .prev.data=$TMP7 --dump-section .asmjs.header=$TMP8 $1 $TMP1
14 | cat $TMP7 $TMP8 $TMP2 | $ASMJSDIR/bin/hexify > $TMP3
15 | asmjs-virtual-asmjs-objcopy --add-section .javascript.data=$TMP3 $1 $TMP4
16 | asmjs-virtual-asmjs-ld -T $ASMJSDIR/lds/asmjs.lds $ASMJSDIR/lib/asmjs.o $TMP4 -o $TMP5
17 | asmjs-virtual-asmjs-ld -T $ASMJSDIR/lds/asmjs-js1ify.lds $ASMJSDIR/lib/asmjs.o $TMP5 -o $TMP6
18 | rm $TMP1 $TMP2 $TMP3 $TMP4 $TMP5
19 | cat $ASMJSDIR/js/asmjs.js $TMP6
20 | rm $TMP6
21 |
--------------------------------------------------------------------------------
/bin/prevify:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | asmjs-virtual-asmjs-objcopy --prefix-sections .prev -N __data_start -N __data_end -N __multifile_init_array_start -N __multifile_init_array_end -N __multifile_preinit_array_start -N __multifile_preinit_array_end -N __multifile_fini_array_start -N __multifile_fini_array_end -N __terminator $1 $2
3 |
--------------------------------------------------------------------------------
/bin/stitch:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | my $off = 0;
3 | my @lines;
4 | while (<>) {
5 | last if (/^########/);
6 | push @lines, [$off, $_];
7 | $off += length $_;
8 | }
9 |
10 | while (<>) {
11 | my ($off, $comment) = /^# ([0-9]*): (.*)$/;
12 | push @lines, [$off-1, "$comment\n"];
13 | }
14 |
15 | @lines = sort { $a->[0] <=> $b->[0] } @lines;
16 |
17 | for my $line (@lines) {
18 | my ($off, $text) = @$line;
19 |
20 | print $text;
21 | }
22 |
--------------------------------------------------------------------------------
/binfmt_misc/binfmt_misc:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | test -x $1 || (echo "argument $1 not present or not executable" > /dev/stderr; exit 1)
3 | mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
4 | echo ':asmjs:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x4a\x53:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:'"$1"':' > /proc/sys/fs/binfmt_misc/register
5 |
--------------------------------------------------------------------------------
/binfmt_misc/binfmt_misc-wasm:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | test -x $1 || (echo "argument $1 not present or not executable" > /dev/stderr; exit 1)
3 | mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
4 | echo ':wasm:M::\x00asm\x01\x00\x00\x00:\xff\xff\xff\xff\xff\xff\xff\xff:'"$1"':' > /proc/sys/fs/binfmt_misc/register
5 |
--------------------------------------------------------------------------------
/binfmt_misc/binfmt_misc-wasm32:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | test -x $1 || (echo "argument $1 not present or not executable" > /dev/stderr; exit 1)
3 | mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
4 | echo ':wasm32:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x57\x41:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:'"$1"':' > /proc/sys/fs/binfmt_misc/register
5 |
--------------------------------------------------------------------------------
/binfmt_misc/binfmt_misc-wasm64:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | test -x $1 || (echo "argument $1 not present or not executable" > /dev/stderr; exit 1)
3 | mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
4 | echo ':wasm64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x57\x41:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:'"$1"':' > /proc/sys/fs/binfmt_misc/register
5 |
--------------------------------------------------------------------------------
/examples/002-perl/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | something 2
4 |
9 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/exec_and_unlink/exec_and_unlink.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main(int argc, char **argv, char **envp)
7 | {
8 | int fd;
9 | fd = open(argv[1], O_RDONLY);
10 |
11 | if (fd < 0)
12 | exit(1);
13 |
14 | unlink(argv[1]);
15 |
16 | if (execveat(fd, "", argv+1, envp, AT_EMPTY_PATH) < 0)
17 | exit(1);
18 |
19 | /* not reached */
20 |
21 | exit(0);
22 | }
23 |
--------------------------------------------------------------------------------
/exec_and_unlink/exec_and_unlink_fd3.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int main(int argc, char **argv, char **envp)
8 | {
9 | int fd;
10 | fd = open(argv[argc-1], O_RDONLY);
11 | if (dup2(fd, 3) < 0)
12 | exit(1);
13 |
14 | if (fd < 0)
15 | exit(1);
16 |
17 | unlink(argv[argc-1]);
18 |
19 | argv[argc-1] = NULL;
20 |
21 | if (execve(argv[1], argv+1, envp) < 0)
22 | exit(1);
23 |
24 | /* not reached */
25 |
26 | exit(0);
27 | }
28 |
--------------------------------------------------------------------------------
/hexify/hexify.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int c;
6 | int i = 0;
7 | while ((c = getchar()) != EOF) {
8 | printf("0x%02x,%s", c, ((i++&31) == 31) ? "\n" : "");
9 | }
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/include/zeropage.h:
--------------------------------------------------------------------------------
1 | typedef struct zeropage {
2 | unsigned long long top_of_memory;
3 | unsigned long long top_of_sbrk;
4 | unsigned long long thread_list;
5 | unsigned long long bottom_of_sbrk;
6 | } zeropage_t;
7 |
8 | typedef struct threadpage {
9 | unsigned long long next;
10 | unsigned long long prev;
11 | unsigned long long id;
12 | unsigned long long bottom_of_stack;
13 | unsigned long long top_of_stack;
14 | unsigned long long stop_reason;
15 | unsigned long long pc;
16 | unsigned long long pc0;
17 | unsigned long long dpc;
18 | unsigned long long sp;
19 | unsigned long long initsp;
20 | unsigned long long rv;
21 | unsigned long long a0;
22 | unsigned long long a1;
23 | unsigned long long a2;
24 | unsigned long long a3;
25 | unsigned long long tp;
26 | } threadpage_t;
27 |
--------------------------------------------------------------------------------
/ld.txt:
--------------------------------------------------------------------------------
1 | * wasm32_create_dynamic_sections
2 | ** creates PPLT, unsized
3 | * _bfd_elf_adjust_dynamic_symbol
4 | ** elf32_wasm32_adjust_dynamic_symbol
5 | *** early-drops PPLT entries
6 | * allocate_pplt
7 | ** alloc-drops PPLT entries
8 | * elf32_wasm32_size_dynamic_sections
9 | ** finalizes PPLT sizes
10 | * finish_pplt_entry
11 | ** finishes PPLT entry
12 | * elf32_wasm32_relocate_section
13 | ** late-drops PPLT entry
14 |
--------------------------------------------------------------------------------
/lds/asmjs-dat.lds:
--------------------------------------------------------------------------------
1 | OUTPUT_FORMAT(binary)
2 | SECTIONS
3 | {
4 | KEEP(*(.data*))
5 | /DISCARD/ (*(*))
6 | }
7 |
--------------------------------------------------------------------------------
/lds/asmjs-js1ify.lds:
--------------------------------------------------------------------------------
1 | OUTPUT_FORMAT("binary")
2 | SECTIONS
3 | {
4 | .text : { *(.javascript.asmjs*) }
5 | /DISCARD/ : { *(*) }
6 | }
7 |
--------------------------------------------------------------------------------
/lds/wasm32-wasmify.lds:
--------------------------------------------------------------------------------
1 | OUTPUT_FORMAT(binary)
2 | SECTIONS
3 | {
4 | .data : SUBALIGN(1) {
5 | *(.output)
6 | *(.asmjs.header)
7 | *(.got*)
8 | *(.data)
9 | *(.bss)
10 | *(.preinit_array)
11 | *(.ctors)
12 | *(.dtors)
13 | *(.output.named)
14 | }
15 | /DISCARD/ : { *(.discard*) *(*) }
16 | }
17 |
--------------------------------------------------------------------------------
/lib/64m.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void* __curbrk;
4 |
5 | static void f(void)
6 | {
7 | __curbrk = 64 * 1024 * 1024;
8 | }
9 |
10 | __attribute__((section(".init_array"))) static void (*f_init)(void) = f;
11 |
--------------------------------------------------------------------------------
/libdl/Makefile:
--------------------------------------------------------------------------------
1 | libdl.so: libdl.c
2 | wasm32-unknown-none-gcc -fPIC -Wl,--shared --shared -o $@ $<
3 | ../bin/wasmify-wasm32 $@ > libdl.wasm
4 |
5 |
--------------------------------------------------------------------------------
/notes/binaryen/broken.ast:
--------------------------------------------------------------------------------
1 | (module (memory 32 32)
2 | (func "f" $f (local $l i32) (return (get_local +))))
--------------------------------------------------------------------------------
/notes/binaryen/broken2.ast:
--------------------------------------------------------------------------------
1 | (module (memory 32 32)
2 | (func "f" $f (local $l i32) (return (i32.const 0xdeadbeef))))
--------------------------------------------------------------------------------
/notes/binaryen/broken3.ast:
--------------------------------------------------------------------------------
1 | (module
2 | (function "f" $f (param $x i32) (param $x i32)))
3 |
--------------------------------------------------------------------------------
/notes/binaryen/broken4.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | std::vector v;
4 |
5 | int main(void)
6 | {
7 | return v[-1];
8 | }
9 |
--------------------------------------------------------------------------------
/notes/binaryen/broken5.js:
--------------------------------------------------------------------------------
1 | function a(heap, foreign)
2 | {
3 | "use asm";
4 |
5 | function f(x,y) {
6 | x = x|0;
7 | y = y|0;
8 |
9 | return (x << y)|0;
10 | };
11 |
12 | return { f: f };
13 | }
14 |
--------------------------------------------------------------------------------
/notes/binaryen/broken6.ast:
--------------------------------------------------------------------------------
1 | (i32.gt (get_local $x) (get_local $y)) compiles to (f64.gt ...)
--------------------------------------------------------------------------------
/notes/binaryen/broken7.txt:
--------------------------------------------------------------------------------
1 | empty file
2 |
--------------------------------------------------------------------------------
/notes/binaryen/list.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pipcet/asmjs/7181da13396b01847924455e63ffddf414ec3a2f/notes/binaryen/list.txt
--------------------------------------------------------------------------------
/notes/build-dot.txt:
--------------------------------------------------------------------------------
1 | make -kj6
2 | cp cmd/dot/dot_static .
3 | ~/git/asmjs/bin/jsexport ./dot_static ./dot-001
4 | ~/git/asmjs/bin/multifile-add1 ./dot-001 ~/git/asmjs/lib/mfinfo.o ./dot-002
5 | ~/git/asmjs/bin/multifile-add1 ./dot-002 ~/git/asmjs/lib/loop.o ./dot-003
6 | ~/git/asmjs/bin/prepare dot-003 > dot-003.js
7 | cp dot-003.js ~/git/ankol/uni/
8 |
--------------------------------------------------------------------------------
/notes/secondary.txt:
--------------------------------------------------------------------------------
1 | asmjs-virtual-asmjs-g++ -c ../bin/jsexport.cpp
2 | asmjs-virtual-asmjs-g++ -c ./linkme1.c
3 | asmjs-virtual-asmjs-g++ -Wl,-T,../lds/asmjs-loose.x ./linkme1.o
4 | asmjs-virtual-asmjs-objcopy --rename-section .init_array=.secondary.init_array --rename-section .data=.secondary.data --rename-section .rodata=.secondary.rodata --rename-section .bss=.secondary.bss jsexport.o jsexport2.o
5 | asmjs-virtual-asmjs-ld -T ../lds/asmjs-tight.x ./a.out ./jsexport2.o ~/git/asmjs/asmjs-virtual-asmjs/asmjs-virtual-asmjs/lib/libstdc++.a -o b.out
6 |
--------------------------------------------------------------------------------
/perf/bestfit.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use POSIX qw(pow);
3 |
4 | while (<>) {
5 | if (/^([\d.]*) ([\d.]*)$/) {
6 | push @dps, [$1, $2]
7 | }
8 | }
9 |
10 | sub badness
11 | {
12 | my ($a, $b) = @_;
13 |
14 | my $sum = 0;
15 |
16 | for my $dp (@dps) {
17 | $sum += pow($a + $b * exp($dp->[0]) - $dp->[1], 2.0);
18 | #print "$sum $a $b " . $dp->[0] . " " . $dp->[1] . "\n";
19 | }
20 |
21 | return $sum;
22 | }
23 |
24 | my $a = 1;
25 | my $b = 0;
26 |
27 | for (my $epsilon = .5; $epsilon > 1e-7; $epsilon *= .9999) {
28 | my $s1 = (rand()-.5);
29 | my $s2 = 1e-6 * (rand()-.5);
30 | if (rand() < .5) {
31 | $s1 = 0;
32 | } else {
33 | $s2 = 0;
34 | }
35 | if (badness($a+$s1*$epsilon, $b+$s2*$epsilon) < badness($a, $b)) {
36 | $a += $s1*$epsilon;
37 | $b += $s2*$epsilon;
38 | }
39 | }
40 |
41 | print "$a + exp($b * x)\n"
42 |
--------------------------------------------------------------------------------
/perf/measure.pl:
--------------------------------------------------------------------------------
1 | use Time::HiRes qw(time);
2 |
3 | my @flags = ("", "--wasm-always-baseline", "--no-threads", "--wasm-always-baseline --no-threads");
4 | my @progs = ("./build/asmjs/perl/miniperl", "./build/wasm32/perl/miniperl");
5 |
6 | while (1)
7 | {
8 | for my $i (0 .. 7) {
9 | my $flags = $flags[$i & 3];
10 | my $prog = $progs[!!($i&4)];
11 |
12 | my $start = time();
13 | `bash -c 'JSFLAGS=\"$flags\" /usr/bin/time --output="log-$i" $prog /dev/null'`;
14 | my $stop = time();
15 |
16 | my $time = $stop - $start;
17 |
18 | warn $time;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/perf/measure2.pl:
--------------------------------------------------------------------------------
1 | use Time::HiRes qw(time);
2 |
3 | my @flags = ("", "--wasm-always-baseline", "--no-threads", "--wasm-always-baseline --no-threads");
4 | my @progs = ("./build/asmjs/perl/miniperl", "./build/wasm32/perl/miniperl", "/usr/bin/perl");
5 |
6 | my @fhs;
7 | for my $i (0 .. 11) {
8 | open $fhs[$i], ">log-$i";
9 | }
10 | while (1)
11 | {
12 | my $e = 16+rand(2)*rand(2);
13 | my $i = int(rand(9));
14 | my $flags = $flags[$i & 3];
15 | my $prog = $progs[int($i/4)];
16 |
17 | my $start = time();
18 | `bash -c 'JSFLAGS=\"$flags\" /usr/bin/time $prog -e "for my \\\$i (0 .. exp($e)) { }"'`;
19 | my $stop = time();
20 |
21 | my $time = $stop - $start;
22 |
23 | warn "$i $e $time";
24 | $fhs[$i]->print("$e $time\n");
25 | $fhs[$i]->flush;
26 | }
27 |
--------------------------------------------------------------------------------
/perf/measure3.pl:
--------------------------------------------------------------------------------
1 | use Time::HiRes qw(time);
2 |
3 | my @flags = ("", "--no-threads");
4 | my @jss = ("./common3/bin/js", "./common3x/bin/js");
5 | my @progs = ("./build/asmjs/perl/miniperl", "./build/wasm32/perl/miniperl", "/usr/bin/perl");
6 |
7 | my @fhs;
8 | for my $i (0 .. 11) {
9 | open $fhs[$i], ">log-$i";
10 | }
11 | while (1)
12 | {
13 | my $e = 16+rand(2)*rand(2);
14 | my $i = int(rand(9));
15 | my $flags = $flags[$i & 1];
16 | my $js = $jss[int($i/2) % 2];
17 | my $prog = $progs[int($i/4)];
18 |
19 | my $start = time();
20 | `bash -c 'JSFLAGS=\"$flags\" JS=\"$js" /usr/bin/time $prog -e "for my \\\$i (0 .. exp($e)) { }"'`;
21 | my $stop = time();
22 |
23 | my $time = $stop - $start;
24 |
25 | warn "$i $e $time";
26 | $fhs[$i]->print("$e $time\n");
27 | $fhs[$i]->flush;
28 | }
29 |
--------------------------------------------------------------------------------
/perf/plottify.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use POSIX qw(pow exp);
3 |
4 | while (<>)
5 | {
6 | if (/^([\d.]*)/) {
7 | push @vs, $1 if ($1 != 0.0);
8 | }
9 | }
10 |
11 | for (my $x = 0.0; $x < 30.0; $x += .01) {
12 | my $y = 0.0;
13 |
14 | for my $v (@vs) {
15 | $y += exp(-pow($x-$v, 2.0));
16 | }
17 |
18 | print "$x $y\n";
19 | }
20 |
--------------------------------------------------------------------------------
/scripts/glibc-generic-diff.bash:
--------------------------------------------------------------------------------
1 | # in glibc/sysdeps/wasm32
2 | find -type f | while read; do diff -uN "../generic/$REPLY" "$REPLY" && echo "YYY $REPLY"; done
3 |
--------------------------------------------------------------------------------
/tests/001-do-nothing/001-do-nothing.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | volatile int x = 1;
6 | if (x != 1) {
7 | printf("hello world\n");
8 | }
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/002-hello-world-infloop/002-hello-world-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | for (;;)
6 | printf("hello world\n");
7 | }
8 |
--------------------------------------------------------------------------------
/tests/003-hello-world-infloop-count/003-hello-world-infloop-count.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | puts("hello world: %d %%f %s %c\n");
9 | ret += printf("hello world: %d %%f %s %c\n", ret,
10 | /* 4.5, */
11 | "string", (int)'x');
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/tests/004-hello-world-infloop-count/004-hello-world-infloop-count.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | extern int breakpoint3();
6 |
7 | int main(void)
8 | {
9 | int ret = 42;
10 |
11 | while (1)
12 | ret += printf("hello world: %d\n", ret);
13 | }
14 |
--------------------------------------------------------------------------------
/tests/005-hello-world-infloop-double/005-hello-world-infloop-double.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1)
8 | ret += printf("hello world: %d %f %s %c\n", ret,
9 | 4.5, "string", 'x');
10 | }
11 |
--------------------------------------------------------------------------------
/tests/006-function-call/006-function-call.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | printf("a %d b %d\n", a, b);
6 | return 7 * a - b;
7 | }
8 |
9 | int main(void)
10 | {
11 | puts("hi");
12 | puts("hi");
13 | printf("%d\n", f(10, 5));
14 | printf("%d\n", f(5, 10));
15 | fprintf(fdopen(1, "w"), "hi there %d\n", 42);
16 |
17 | return 0;
18 | }
19 |
20 | const char *string = "this is a constant string";
21 |
--------------------------------------------------------------------------------
/tests/007-argc-argv/007-argc-argv.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int argc, char **argv)
9 | {
10 | printf("stderr is %p\n", stderr);
11 | fprintf(stderr, "argc: %d\n", argc);
12 | fprintf(stderr, "argv: %p\n", argv);
13 | fprintf(stderr, "arg0: %s\n", argv[0]);
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/008-argi/008-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7)
9 | {
10 | asm("Module.print('in main, sp is ' + sp + ' bp is ' + fp);");
11 | asm("Module.print('' + HEAP32[(sp+32)>>2]);");
12 | asm("Module.print('' + HEAP32[(fp+20)>>2]);");
13 | fprintf(stderr, "arg0: %d\n", arg0);
14 | fprintf(stderr, "arg1: %d\n", arg1);
15 | fprintf(stderr, "arg2: %d\n", arg2);
16 | fprintf(stderr, "arg3: %d\n", arg3);
17 | fprintf(stderr, "arg4: %d\n", arg4);
18 | fprintf(stderr, "arg5: %d\n", arg5);
19 | fprintf(stderr, "arg6: %d\n", arg6);
20 | fprintf(stderr, "arg7: %d\n", arg7);
21 |
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/tests/009-argi/009-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int argc, char **argv)
9 | {
10 | fprintf(stderr, "arg0: %p %s\n", argv+0, argv[0]);
11 | fprintf(stderr, "arg1: %p %s\n", argv+1, argv[1]);
12 | fprintf(stderr, "arg2: %p %s\n", argv+2, argv[2]);
13 | fprintf(stderr, "arg3: %p %s\n", argv+3, argv[3]);
14 | fprintf(stderr, "arg4: %p %s\n", argv+4, argv[4]);
15 | fprintf(stderr, "arg5: %p %s\n", argv+5, argv[5]);
16 | fprintf(stderr, "arg6: %p %s\n", argv+6, argv[6]);
17 | fprintf(stderr, "arg7: %p %s\n", argv+7, argv[7]);
18 | fprintf(stderr, "argc: %d\n", argc);
19 | fprintf(stderr, "argv: %p\n", argv);
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/011-printstr/011-printstr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int printstr(const char *string)
9 | {
10 | asm("Module.print('string should be ' + HEAPU32[($bp + 20 )>>2]);");
11 | return fprintf(stderr, "string: %s\n", string);
12 | }
13 |
14 | int main(int argc, char **argv)
15 | {
16 | int i;
17 |
18 | for(i = 0; i<1024; i++) {
19 | fprintf(stderr, "%d\n", i);
20 | asm("Module.printErr('sp ' + $sp);\n");
21 | }
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/tests/012-printf-doubles/012-printf-doubles.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | double d = 1.2;
6 |
7 | printf("%f\n", 1.2);
8 | printf("%f\n", 1.2);
9 | printf("%f %f\n", 1.2, 3.4);
10 | printf("%f %d %f\n", 1.2, 3, 4.5);
11 | printf("%f %d %d %f\n", 1.2, 3, 4, 5.6);
12 | printf("%f %d %f %d %f %d %f\n", 1.2, 3, 4.5, 6, 7.8, 9, 10.11);
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/tests/013-asm/013-asm.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm("\n\n/* %0 %1 */\n"
4 | :
5 | : "p"(0), "P"(0));
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/014-count/014-count.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | int i;
4 |
5 | for (i=0; i<1024; i++)
6 | printf("%d\n", i);
7 | }
8 |
--------------------------------------------------------------------------------
/tests/015-sscanf-fscanf/015-sscanf-fscanf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int dr_sscanf(const char *, const char *, ...);
4 |
5 | int main(void)
6 | {
7 | int x = 7;
8 | char buf[80];
9 |
10 | //dr_sscanf("3", "%d", &x);
11 | sscanf("3", "%d", &x);
12 | fscanf(stdin, "%d", &x);
13 | fread(buf, 79, 1, stdin);
14 | scanf("%d", &x);
15 |
16 | printf("%d\n", x);
17 |
18 | printf("%p\n", sscanf);
19 |
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/tests/016-double/016-double.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | double d = 1.0;
6 | double e = 1.0 + 1.0;
7 | double f = e - d;
8 |
9 | fprintf(stderr, "d = %f e = %f f = %f\n", d, e, f);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/017-fptr/017-fptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo(void)
4 | {
5 | return 0;
6 | }
7 |
8 | extern int main(void);
9 |
10 | void *mainp = main;
11 |
12 | int main(void)
13 | {
14 | static int (*foop)(void) = foo;
15 | printf("%p\n", mainp);
16 | printf("%p %d\n", foop, foop());
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/tests/018-ptr/018-ptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo[4];
4 | int *foop = foo;
5 |
6 | int main(void)
7 | {
8 | printf("%p\n", foop);
9 | printf("%p\n", foo);
10 | foo[0] = 0;
11 | printf("%p\n", foop);
12 | printf("%p\n", foo);
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/019-varargs/019-varargs.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int f(int count, ...)
5 | {
6 | char buf[1024];
7 | va_list ap;
8 |
9 | va_start(ap,count);
10 | vsprintf(buf, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", ap);
11 |
12 | va_end(ap);
13 |
14 | fprintf(stderr, "%s\n", buf);
15 |
16 | return 0;
17 | }
18 |
19 | int main(void)
20 | {
21 | f(16, 1.0, 2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0);
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/tests/020-int-varargs/020-int-varargs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
6 | 0, 1, 2, 3,
7 | 4, 5, 6, 7,
8 | 8, 9,10,11,
9 | 12,13,14,15);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/022-stack/022-stack.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | volatile int stack1 = 0;
4 |
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/023-fptr/023-fptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo(void)
4 | {
5 | return 0;
6 | }
7 |
8 | int main(void)
9 | {
10 | static int (*foop)(void) = foo;
11 | printf("%p %d\n", foop, foop());
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/tests/024-nofloat/024-nofloat.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | ret += printf("hello world: %d %%f %s %c\n", ret,
9 | /* 4.5, */
10 | "string", (int)'x');
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/tests/025-nofloat/025-nofloat.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | ret += fprintf(stdout, "hello world: %d %%f %s %c\n", ret,
9 | /* 4.5, */
10 | "string", (int)'x');
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/tests/026-undefined/026-undefined.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int thisisanundefinedfunctionsname(void);
4 |
5 | int main(void)
6 | {
7 | return thisisanundefinedfunctionsname();
8 | }
9 |
--------------------------------------------------------------------------------
/tests/027-intsizes/027-intsizes.c:
--------------------------------------------------------------------------------
1 | // from the perl configure script
2 | #include
3 | #define I_STDLIB
4 | #ifdef I_STDLIB
5 | #include
6 | #endif
7 | int main()
8 | {
9 | printf("intsize=%d;\n", (int)sizeof(int));
10 | printf("longsize=%d;\n", (int)sizeof(long));
11 | printf("shortsize=%d;\n", (int)sizeof(short));
12 | exit(0);
13 | }
14 |
--------------------------------------------------------------------------------
/tests/028-twostrings/028-twostrings.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char *string = "this is not the null string\n";
4 | const char *string2 = "this is not the null string either\n";
5 |
6 | int main(void)
7 | {
8 | fprintf(stderr, "%s", string);
9 | }
10 |
--------------------------------------------------------------------------------
/tests/029-flush/029-flush.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm volatile("pc=${label:%=};continue;\n${labeldef:%=}" : : );
4 | }
5 |
--------------------------------------------------------------------------------
/tests/030-myprintf/030-myprintf.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void my_printf(const char *format, ...)
5 | {
6 | __isoc_va_list args;
7 |
8 | va_start(args, format);
9 | printf("args is %p %p\n", args, *(void **)args);
10 | vprintf(format, args);
11 | va_end(args);
12 |
13 | return ;
14 | }
15 |
16 | int main(void)
17 | {
18 | my_printf("hi\n");
19 | my_printf("hi %d\n", 42);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/tests/031-myprintf-main/031-myprintf-main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void my_printf(const char *format, ...)
5 | {
6 | __isoc_va_list args;
7 | void *args2;
8 |
9 | va_start(args, format);
10 | printf("args is %p %p\n", args, *(void **)args);
11 | args2 = (void *)(*(void **)&args);
12 | args2 += 4;
13 | vprintf(format, ((void *)&args2));
14 | va_end(args);
15 |
16 | return ;
17 | }
18 |
19 | int main(void)
20 | {
21 | my_printf("hi\n");
22 | my_printf("hi %p=%s, %s, %s, %d %x %o %p %d %p\n",
23 | main, "hi", "there", "this", 10, 10, 10, main, 10, main);
24 | printf("hi %p=%s, %s, %s, %d %x %o %p %d %p\n",
25 | main, "hi", "there", "this", 10, 10, 10, main, 10, main);
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/tests/035-floor/035-floor.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main(void)
7 | {
8 | double d = 2591024700;
9 | unsigned long l = (unsigned)floor(d+.5)+.5;
10 | fprintf(stderr, "%lu\n", l);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/tests/036-funcall/036-funcall.c:
--------------------------------------------------------------------------------
1 | extern void f(int x);
2 | extern int g(int x);
3 |
4 | int main(void)
5 | {
6 | f(22);
7 | g(42);
8 | }
9 |
--------------------------------------------------------------------------------
/tests/037-callbyref/037-callbyref.cc:
--------------------------------------------------------------------------------
1 | struct s {
2 | int a;
3 | int b;
4 | };
5 |
6 | void g(struct s &x)
7 | {
8 | x.a = 3;
9 | x.b = 4;
10 | }
11 |
12 | int main(void)
13 | {
14 | struct s x;
15 |
16 | g(x);
17 | }
18 |
--------------------------------------------------------------------------------
/tests/038-hw-terminates/038-hw-terminates.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 42;
6 |
7 | while (ret < 10000000)
8 | ret += printf("hello world: %d\n", ret);
9 | }
10 |
--------------------------------------------------------------------------------
/tests/039-cc-float-double/039-cc-float-double.c:
--------------------------------------------------------------------------------
1 | extern void v_f(float);
2 | extern void v_d(double);
3 | extern void v_ff(float, float);
4 | extern void v_fd(float, double);
5 | extern void v_df(double, float);
6 | extern void v_dd(double, double);
7 |
8 | extern int i_f(float);
9 | extern int i_d(double);
10 | extern int i_ff(float, float);
11 | extern int i_fd(float, double);
12 | extern int i_df(double, float);
13 | extern int i_dd(double, double);
14 |
15 |
16 | int main(void)
17 | {
18 | volatile float x = 1.3;
19 | volatile double y = 2.5;
20 | volatile float z = 3.5;
21 | volatile double a = 4.5;
22 |
23 | v_f(x);
24 | v_f(z);
25 | v_d(y);
26 | v_d(a);
27 | v_ff(x, z);
28 | v_fd(x, y);
29 | v_df(a, x);
30 | v_dd(y, a);
31 |
32 | i_f(x);
33 | i_f(z);
34 | i_d(y);
35 | i_d(a);
36 | i_ff(x, z);
37 | i_fd(x, y);
38 | i_df(a, x);
39 | i_dd(y, a);
40 | }
41 |
--------------------------------------------------------------------------------
/tests/040-fdopen-argi/040-fdopen-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv)
4 | {
5 | fprintf(fdopen(1, "w"), "%d %s %s %s %s\n", argc, argv[0], argv[1], argv[2], argv[3]);
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/041-addrof/041-addrof.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int a(void);
4 | extern int b;
5 |
6 | int c(void);
7 | int d;
8 |
9 | void *ap = a;
10 | void *bp = &b;
11 | void *cp = c;
12 | void *dp = &d;
13 |
14 | int main(void)
15 | {
16 | printf("%p %p\n", a, &b);
17 | }
18 |
--------------------------------------------------------------------------------
/tests/042-putchar/042-putchar.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | putchar('h');
6 | putchar('i');
7 | putchar('!');
8 | putchar('\n');
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/043-printf/043-printf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi!\n");
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/044-printf-fcall/044-printf-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | f();
11 | }
12 |
--------------------------------------------------------------------------------
/tests/045-printf-fcall-loop/045-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/tests/046-printf-fcall-loop/046-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/tests/047-printf-fcall-loop/047-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/tests/048-printf-fcall-infloop/048-printf-fcall-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int count)
4 | {
5 | return printf("hi %d\n", count);
6 | }
7 |
8 | int main(void)
9 | {
10 | int x = 0;
11 |
12 | while (1)
13 | x += f(x);
14 | }
15 |
--------------------------------------------------------------------------------
/tests/049-printf-rec/049-printf-rec.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi\n");
6 | main();
7 | }
8 |
--------------------------------------------------------------------------------
/tests/050-exit3/050-exit3.c:
--------------------------------------------------------------------------------
1 | extern void _Noreturn exit(int x);
2 | extern void exit2(int x);
3 | extern int exit3(int x);
4 |
5 | int main(void)
6 | {
7 | volatile int i = 3;
8 |
9 | switch (i) {
10 | case 1:
11 | exit(11);
12 | case 2:
13 | exit2(12);
14 | case 3:
15 | exit3(13);
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/tests/051-exit/051-exit.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | int main()
5 | {
6 | printf("\n");
7 | exit(0);
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/tests/052-signal/052-signal.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 | int main(void)
4 | {
5 | signal(8, 1);
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 |
15 | puts("done");
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/053-signal-fcall/053-signal-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 |
4 | int f(void)
5 | {
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 | signal(8, 1);
15 |
16 | puts("done");
17 | return 0;
18 | }
19 |
20 | int main(void)
21 | {
22 | f();
23 | f();
24 |
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/tests/054-signal-fcall/054-signal-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 |
4 | void f(void)
5 | {
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 | signal(8, 1);
15 |
16 | puts("done");
17 | }
18 |
19 | int main(void)
20 | {
21 | f();
22 | f();
23 |
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/tests/055-setjmp-longjmp/055-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern int __wrap_setjmp(jmp_buf);
5 | extern void __wrap_longjmp(jmp_buf, int);
6 |
7 | int main(void)
8 | {
9 | jmp_buf env;
10 | printf("about to setjmp\n");
11 | fflush(stdout);
12 | printf("fp %p\n", __builtin_frame_address(0));
13 | if (__wrap_setjmp(env)) {
14 | printf("second return\n");
15 | } else {
16 | printf("first return\n");
17 | __wrap_longjmp(env, 1);
18 | printf("notreached\n");
19 | }
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/056-ldexpf/056-ldexpf.c:
--------------------------------------------------------------------------------
1 | extern float ldexpf(float, int);
2 |
3 | #include
4 |
5 | int main(void)
6 | {
7 | printf("%f\n", ldexpf(1.0, 6));
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/057-ffsll/057-ffsll.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | for (int i = 0; i != 0xffffffff; i++) {
7 | printf("%d %d\n", i, __builtin_ffsll(i));
8 | }
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/058-emutls/058-emutls.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* first test linking with glibc */
4 |
5 | int my_errno = 0;
6 |
7 | int *__errno_location(void)
8 | {
9 | return &my_errno;
10 | }
11 |
12 | void *__emutls_get_address(void)
13 | {
14 | return NULL;
15 | }
16 |
17 | int main(void)
18 | {
19 | int ret = 42;
20 |
21 | while (ret == 42)
22 | ret += _IO_printf("hello world: %d %f %f\n", ret, 1.0/0.0, 3.5);
23 |
24 | fflush (stdout);
25 |
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/tests/059-wrap-write/059-wrap-write.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | /* first test linking with glibc */
6 |
7 | int my_errno = 0;
8 |
9 | int *__errno_location(void)
10 | {
11 | return &my_errno;
12 | }
13 |
14 | void *__emutls_get_address(void)
15 | {
16 | return 0xdeadbeef;
17 | }
18 |
19 | extern ssize_t __wrap_write(int, void *, ssize_t);
20 |
21 | int main(void)
22 | {
23 | int ret = 42;
24 | char buf[1024];
25 |
26 | while (ret == 42) {
27 | ret += sprintf(buf, "hello world: %d\n", ret, 1.0/0.0, 3.5);
28 | __wrap_write(1, buf, strlen(buf));
29 | }
30 |
31 | return 0;
32 | }
33 |
--------------------------------------------------------------------------------
/tests/061-gcvt/061-gcvt.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | /* first test linking with glibc */
7 |
8 | int my_errno = 0;
9 |
10 | int *__errno_location(void)
11 | {
12 | return &my_errno;
13 | }
14 |
15 | extern ssize_t __wrap_write(int, void *, ssize_t);
16 | extern void *__wrap_malloc(size_t);
17 |
18 | int __unorddf2(double a, double b)
19 | {
20 | return 0;
21 | }
22 |
23 | int main(void)
24 | {
25 | int ret = 42;
26 | char buf[1024];
27 | char buf2[1024];
28 |
29 | while (ret == 42) {
30 | ret += sprintf(buf, "hello world: %f %s\n", 1.0/3.0, gcvt(3.5, 10, buf2));
31 | __wrap_write(1, buf, strlen(buf));
32 | }
33 |
34 | return 1;
35 | }
36 |
--------------------------------------------------------------------------------
/tests/062-printf-fflush/062-printf-fflush.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi\n");
6 |
7 | fflush(stdout);
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/063-attribute-cleanup/063-attribute-cleanup.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void cu(void**);
4 |
5 | void cu2(void **ptrp)
6 | {
7 | cu(ptrp);
8 | }
9 |
10 | int main(void)
11 | {
12 | void * __attribute__((cleanup(cu2))) ptr = malloc(1024);
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/tests/066-exp-1/066-exp-1.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | printf("%f\n", exp(1.0));
7 | }
8 |
--------------------------------------------------------------------------------
/tests/067-my-setjmp-longjmp/067-my-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern int __my_setjmp(jmp_buf);
5 | extern void __my_longjmp(jmp_buf, int);
6 |
7 | int my_setjmp(jmp_buf env)
8 | {
9 | return __my_setjmp(env);
10 | }
11 |
12 | void my_longjmp(jmp_buf env, int value)
13 | {
14 | __my_longjmp(env, value);
15 | }
16 |
17 | int main(void)
18 | {
19 | jmp_buf env;
20 | printf("about to setjmp\n");
21 | fflush(stdout);
22 | printf("fp %p\n", __builtin_frame_address(0));
23 | if (my_setjmp(env)) {
24 | printf("second return\n");
25 | } else {
26 | printf("first return\n");
27 | fflush(stdout);
28 | my_longjmp(env, 1);
29 | printf("notreached\n");
30 | }
31 |
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/tests/068-setjmp-longjmp/068-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | jmp_buf env;
7 | printf("about to setjmp\n");
8 | fflush(stdout);
9 | printf("fp %p\n", __builtin_frame_address(0));
10 | if (setjmp(env)) {
11 | printf("second return\n");
12 | fflush(stdout);
13 | } else {
14 | printf("first return\n");
15 | fflush(stdout);
16 | longjmp(env, 1);
17 | printf("notreached\n");
18 | fflush(stdout);
19 | }
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/069-cc-return/069-cc-return.c:
--------------------------------------------------------------------------------
1 | extern void v_i(int x);
2 | extern int i_i(int x);
3 | extern double d_i(int x);
4 |
5 | extern void v_d(double x);
6 | extern int i_d(double x);
7 | extern double d_d(double x);
8 |
9 | int main(void)
10 | {
11 | v_i(3);
12 | i_i(4);
13 | d_i(5);
14 |
15 | v_d(6.0);
16 | i_d(7.0);
17 | d_d(8.0);
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/tests/070-breakpoint-infloop/070-breakpoint-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void asmjs_breakpoint(void);
4 | extern int breakpoint3(void);
5 |
6 | int main(void)
7 | {
8 | int ret = 42;
9 |
10 | //asmjs_breakpoint();
11 | breakpoint3();
12 |
13 | while (1) {
14 | ret += printf("hello world: %d\n", ret);
15 | fflush (stdout);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/071-breakpoint-infloop-fcall/071-breakpoint-infloop-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void asmjs_breakpoint(void);
4 | extern int breakpoint3(void);
5 |
6 | void g(void)
7 | {
8 | printf("g\n");
9 | }
10 |
11 | void f(void)
12 | {
13 | printf("f\n");
14 | g();
15 | }
16 |
17 | int main(void)
18 | {
19 | int ret = 42;
20 |
21 | //asmjs_breakpoint();
22 | breakpoint3();
23 |
24 | while (1) {
25 | f();
26 | fflush(stdout);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/072-infloop/072-infloop.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | for(;;);
4 | }
5 |
--------------------------------------------------------------------------------
/tests/073-infloop-sprintf/073-infloop-sprintf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | char buf[1024] = "hi there\n";
6 | for(;;)
7 | sprintf(buf, "%s", buf);
8 | }
9 |
--------------------------------------------------------------------------------
/tests/074-malloc/074-malloc.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | volatile void * volatile p;
4 |
5 | int main(void)
6 | {
7 | p = malloc(2);
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/075-wrap-write/075-wrap-write.c:
--------------------------------------------------------------------------------
1 | extern int __wrap_write(int fd, const char *data, int count);
2 |
3 | int main(void)
4 | {
5 | while(1)
6 | __wrap_write(1, "test\n", 5);
7 | }
8 |
--------------------------------------------------------------------------------
/tests/076-wrap-write/076-wrap-write.c:
--------------------------------------------------------------------------------
1 | extern int __wrap_write(int, const char *, int) __attribute__((stackcall));
2 |
3 | void _start(void)
4 | {
5 | __wrap_write(1, "hi there\n", strlen("hi there\n"));
6 | }
7 |
--------------------------------------------------------------------------------
/tests/077-longloop/077-longloop.c:
--------------------------------------------------------------------------------
1 | void _start(void)
2 | {
3 | int x = 0;
4 | while(++x);
5 | }
6 |
--------------------------------------------------------------------------------
/tests/078-delayed/078-delayed.c:
--------------------------------------------------------------------------------
1 | extern int __wrap_write(int, const char *, int) __attribute__((stackcall));
2 |
3 | void _start(void)
4 | {
5 | volatile int x = 0;
6 | while(++x < 65000);
7 | {
8 | volatile int z1, z2, z3;
9 | z1 += z2 * z3;
10 | }
11 | __wrap_write(1, "hi there\n", strlen("hi there\n"));
12 | for(;;);
13 | }
14 |
--------------------------------------------------------------------------------
/tests/079-sigaction/079-sigaction.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern void f(struct sigaction *);
4 |
5 | int main(void)
6 | {
7 | struct sigaction sa;
8 |
9 | f(&sa);
10 | }
11 |
--------------------------------------------------------------------------------
/tests/080-i/080-i.c:
--------------------------------------------------------------------------------
1 | char str[] = "hi\n";
2 |
3 | int main(void)
4 | {
5 | printf("%c", *(str+1));
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/081-asm-rename/081-asm-rename.c:
--------------------------------------------------------------------------------
1 | int f(int) asm("g");
2 |
3 | int f(int x) {
4 | return x + 1;
5 | }
6 |
--------------------------------------------------------------------------------
/tests/082-breakpoint/082-breakpoint.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | extern int breakpoint3();
6 |
7 | int main(void)
8 | {
9 | volatile struct stat s;
10 | int ret = 42;
11 |
12 | while (1)
13 | ret += printf("hello world: %d\n", ret);
14 | }
15 |
--------------------------------------------------------------------------------
/tests/083-setjmp-longjmp/083-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | jmp_buf env;
5 |
6 | int dummy(void)
7 | {
8 | longjmp(env, 1);
9 | }
10 |
11 | int main(void)
12 | {
13 | printf("about to setjmp\n");
14 | fflush(stdout);
15 | printf("fp %p\n", __builtin_frame_address(0));
16 | if (setjmp(env)) {
17 | printf("second return\n");
18 | } else {
19 | printf("first return\n");
20 | fflush(stdout);
21 | dummy();
22 | printf("notreached\n");
23 | }
24 |
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/tests/084-unord/084-unord.c:
--------------------------------------------------------------------------------
1 | int unorddf2(double x, double y)
2 | {
3 | return (x != x) || (y != y);
4 | }
5 |
--------------------------------------------------------------------------------
/tests/085-asm/085-asm.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm volatile("pc = ${label:%=}; case ${labeldef:%=}:");
4 | }
5 |
--------------------------------------------------------------------------------
/tests/086-asmjs.js:
--------------------------------------------------------------------------------
1 | function AsmModule(stdlib, foreign, heap)
2 | {
3 | "use asm";
4 |
5 | function f0(pc, sp, fp, ap, r0, r1, r2, r3, i0, i1, i2, i3, f0, f1, f2, f3) {
6 | pc = pc|0;
7 | sp = sp|0;
8 | fp = fp|0;
9 | ap = ap|0;
10 | r0 = r0|0;
11 | r1 = r1|0;
12 | r2 = r2|0;
13 | r3 = r3|0;
14 | i0 = i0|0;
15 | i1 = i1|0;
16 | i2 = i2|0;
17 | i3 = i3|0;
18 | f0 = +f0;
19 | f1 = +f1;
20 | f2 = +f2;
21 | f3 = +f3;
22 |
23 | return +f3;
24 | }
25 |
26 | return {
27 | f0: f0,
28 | };
29 | }
30 |
31 | mod = AsmModule(this, {}, new ArrayBuffer(65536));
32 |
33 | print(mod.f0(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4));
34 |
--------------------------------------------------------------------------------
/tests/090-bp1/090-bp1.c:
--------------------------------------------------------------------------------
1 | extern void asmjs_breakpoint(void);
2 | extern int breakpoint2(void *);
3 |
4 | int breakpoint3(void)
5 | {
6 | return breakpoint2(__builtin_frame_address (0));
7 |
8 | asm volatile("pc = $\n\t.codetextlabel .Lbp3\n\t>>4;\n\trp = fp|1; break mainloop;\n\t.codetextlabeldef .Lbp3");
9 |
10 | asmjs_breakpoint();
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/tests/091-bra/091-bra.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | (void)__builtin_return_address (1);
6 |
7 | fprintf(stderr, "ra: %p\n",
8 | __builtin_return_address (0),
9 | __builtin_return_address (1));
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/092-dwarf2eh001/092-dwarf2eh001.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | main() {
4 | fprintf(stderr, "fp %p\n", __builtin_frame_address(0));
5 | try {
6 | throw 1;
7 | }
8 | catch (...) {
9 | printf(" in catch\n");
10 | return 1;
11 | }
12 | printf(" back in main\n");
13 | return 10;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/093-dwarf2eh002/093-dwarf2eh002.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | void f ()
5 | {
6 | printf (" in f()\n");
7 | throw 1;
8 | }
9 |
10 |
11 | main() {
12 | try {
13 | printf(" before throw\n");
14 | f();
15 | }
16 | catch (...) {
17 | printf(" in catch\n");
18 | return 6;
19 | }
20 | printf(" back in main\n");
21 | return 10;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/094-dwarf2eh003/094-dwarf2eh003.cpp:
--------------------------------------------------------------------------------
1 | // Testcase for proper handling of
2 | // c++ type, constructors and destructors.
3 |
4 | #include
5 |
6 | int c, d;
7 |
8 | struct A
9 | {
10 | int i;
11 | A () { i = ++c; fprintf (stderr, "A() %d\n", i); }
12 | A (const A&) { i = ++c; fprintf (stderr, "A(const A&) %d\n", i); }
13 | ~A() { fprintf (stderr, "~A() %d\n", i); ++d; }
14 | };
15 |
16 | void
17 | f()
18 | {
19 | fprintf (stderr, "Throwing 1...\n");
20 | throw A();
21 | }
22 |
23 |
24 | int
25 | main ()
26 | {
27 | A x;
28 | fprintf(stderr, "hi!\n");
29 | try
30 | {
31 | f();
32 | }
33 | catch (A)
34 | {
35 | fprintf (stderr, "Caught.\n");
36 | }
37 | fprintf (stderr, "c == %d, d == %d\n", c, d);
38 | return c != d;
39 | }
40 |
--------------------------------------------------------------------------------
/tests/095-dwarf2eh004/095-dwarf2eh004.cpp:
--------------------------------------------------------------------------------
1 | // Testcase for proper handling of
2 | // c++ type, constructors and destructors.
3 |
4 | #include
5 |
6 | int c, d;
7 |
8 | struct A
9 | {
10 | int i;
11 | A () { i = ++c; fprintf (stderr, "A() %d\n", i); }
12 | A (const A&) { i = ++c; fprintf (stderr, "A(const A&) %d\n", i); }
13 | ~A() { fprintf (stderr, "~A() %d\n", i); ++d; }
14 | };
15 |
16 | void
17 | f()
18 | {
19 | fprintf (stderr, "Throwing 1...\n");
20 | throw A();
21 | }
22 |
23 |
24 | int
25 | main ()
26 | {
27 | fprintf(stderr, "hi!\n");
28 | try
29 | {
30 | f();
31 | }
32 | catch (A)
33 | {
34 | fprintf (stderr, "Caught.\n");
35 | }
36 | fprintf (stderr, "c == %d, d == %d\n", c, d);
37 | return c != d;
38 | }
39 |
--------------------------------------------------------------------------------
/tests/096-f_return/096-f_return.c:
--------------------------------------------------------------------------------
1 | void f_return(void)
2 | {
3 | }
4 |
--------------------------------------------------------------------------------
/tests/099-import-macro-c/099-import-macro-c.c:
--------------------------------------------------------------------------------
1 | int import()
2 | {
3 | asm volatile("return foreign_extcall(0xdeadbeef, pc|0, sp|0);");
4 |
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/100-just-break/100-just-break.c:
--------------------------------------------------------------------------------
1 | extern unsigned long gdbstub_entry(void *sp, unsigned long rv);
2 |
3 | int main(void)
4 | {
5 | return gdbstub_entry(__builtin_frame_address(0), 0);
6 | }
7 |
--------------------------------------------------------------------------------
/tests/101-just-break/101-just-break.c:
--------------------------------------------------------------------------------
1 | extern unsigned long gdbstub_entry(void *sp, unsigned long rv);
2 |
3 | int g(void)
4 | {
5 | return gdbstub_entry(__builtin_frame_address(0), 0);
6 | }
7 |
8 | int f(void)
9 | {
10 | return g();
11 | }
12 |
13 | int main(void)
14 | {
15 | return f();
16 | }
17 |
--------------------------------------------------------------------------------
/tests/102-just-write/102-just-write.s:
--------------------------------------------------------------------------------
1 | #NO_APP
2 | .include "/home/pip/git/fauxsembler/gas-include.s"
3 | .include "/home/pip/git/fauxsembler/tests/import-macro.s"
4 |
5 | .import2 write,__wrap_write
6 | .import2 malloc,__wrap_malloc
7 |
--------------------------------------------------------------------------------
/tests/103-linkme1/103-linkme1.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(void)
4 | {
5 | fprintf(stderr, "I'm f!\n");
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/104-linkme2/104-linkme2.c:
--------------------------------------------------------------------------------
1 | extern int f(void);
2 |
3 | int g(void)
4 | {
5 | return f();
6 | }
7 |
8 | int main(void)
9 | {
10 | while(1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/tests/105-minidebug/105-minidebug.c:
--------------------------------------------------------------------------------
1 | void *malloc(int x)
2 | {
3 | return 0xdeadbeef;
4 | }
5 |
6 | int main(void)
7 |
8 | {
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/106-perl01/106-perl01.c:
--------------------------------------------------------------------------------
1 | #include
2 | int main(void)
3 | {
4 | #ifdef __cplusplus
5 | return 0;
6 | #else
7 | return 1;
8 | #endif
9 | }
10 |
--------------------------------------------------------------------------------
/tests/107-qsort/107-qsort.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int compar(const int *ap, const int *bp)
5 | {
6 | printf("comparing %p/%d and %p/%d\n", ap, *ap, bp, *bp);
7 | //fprintf(stderr, "comparing %p/%d and %p/%d\n", ap, *ap, bp, *bp);
8 |
9 | return *ap - *bp;
10 | }
11 |
12 | int main(void)
13 | {
14 | int array[] = { 5, 1, 13, 14, 12, 13, 9, 0 };
15 | volatile int k = 1;
16 |
17 | if (k)
18 | qsort(array, 8, 4, compar);
19 |
20 | for (int i = 0; i < 8; i++)
21 | printf("el %d: %d\n", i, array[i]);
22 | }
23 |
--------------------------------------------------------------------------------
/tests/108-setjmp-new/108-setjmp-new.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int __dummy(__jmp_buf, int);
4 |
5 | int __my_setjmp(__jmp_buf buf)
6 | {
7 | return __dummy(buf, 0);
8 | }
9 |
10 | void __my_longjmp(__jmp_buf buf, int value)
11 | {
12 | __dummy(buf, value);
13 | return;
14 | }
15 |
--------------------------------------------------------------------------------
/tests/109-size_t/109-size_t.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | __SIZE_TYPE__ s = 0;
6 | size_t s2 = 0;
7 |
8 | fprintf(stderr, "%d\n", sizeof(s));
9 | }
10 |
--------------------------------------------------------------------------------
/tests/110-stat/110-stat.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #define offsetof(haystack, needle) ((unsigned)(&((haystack *)0)->needle))
8 |
9 | #define P(str) printf(#str " %d %d %016llx\n", offsetof(struct stat, str), sizeof(((struct stat *)0)->str), (long long)buf.str);
10 |
11 | int main(int argc, char **argv)
12 | {
13 | struct stat buf;
14 | stat(argv[1], &buf);
15 | P(st_dev);
16 | P(st_ino);
17 | P(st_nlink);
18 | P(st_mode);
19 | P(st_uid);
20 | P(st_gid);
21 | P(st_rdev);
22 | P(st_size);
23 | P(st_blksize);
24 | P(st_blocks);
25 |
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/tests/111-stdinouterr/111-stdinouterr.c:
--------------------------------------------------------------------------------
1 | #define stdin __emscripten_stdin
2 | #define stdout __emscripten_stdout
3 | #define stderr __emscripten_stderr
4 | #include
5 |
6 | FILE *stdin;
7 | FILE *stdout;
8 | FILE *stderr;
9 |
10 | void init_stdinouterr(void)
11 | {
12 | stdin = fdopen(0, "r");
13 | stdout = fdopen(1, "w");
14 | stderr = fdopen(2, "w");
15 | }
16 |
17 | #if 0
18 | int main(void)
19 | {
20 | init_stdinouterr();
21 |
22 | fprintf(stderr, "test\n");
23 | }
24 | #endif
25 |
--------------------------------------------------------------------------------
/tests/112-testreloc4/112-testreloc4.s:
--------------------------------------------------------------------------------
1 | .reloc .+2,R_ASMJS_HEX16R4,b-a
2 | .ascii "0x0000000000000000"
3 | .ascii "HERE HERE HERE"
4 | a:
5 | .long 0xdeadbeef
6 | .long 0xdeadbeef
7 | .long 0xdeadbeef
8 | .long 0xdeadbeef
9 | b:
10 | .globl main
11 | main:
12 |
13 |
--------------------------------------------------------------------------------
/tests/113-unorddf2/113-unorddf2.c:
--------------------------------------------------------------------------------
1 | extern int c(double, double);
2 |
3 | int main(void)
4 | {
5 | return(c(0.0,1.0));
6 | }
7 |
--------------------------------------------------------------------------------
/tests/114-trampoline/114-trampoline.c:
--------------------------------------------------------------------------------
1 | extern int f(int (*)(void));
2 |
3 | int main(void)
4 | {
5 | volatile int x = 7;
6 | volatile int y = 13;
7 | int sum(void) {
8 | return x + y;
9 | }
10 |
11 | f(sum);
12 | }
13 |
--------------------------------------------------------------------------------
/tests/115-trampoline/115-trampoline.c:
--------------------------------------------------------------------------------
1 | int f(int (*sum)(void))
2 | {
3 | return sum();
4 | }
5 |
6 | int main(void)
7 | {
8 | volatile int x = 7;
9 | volatile int y = 13;
10 | int sum(void) {
11 | return x + y;
12 | }
13 |
14 | f(sum);
15 | }
16 |
--------------------------------------------------------------------------------
/tests/116-trampoline/116-trampoline.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int (*sum)(void))
4 | {
5 | return fprintf(stderr, "%d\n", sum());
6 | }
7 |
8 | int main(void)
9 | {
10 | volatile int x = 7;
11 | volatile int y = 13;
12 | int sum(void) {
13 | return x + y;
14 | }
15 |
16 | f(sum);
17 | }
18 |
--------------------------------------------------------------------------------
/tests/117-environment/117-environment.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv, char **envp)
4 | {
5 | while (*envp)
6 | fprintf(stderr, "%s\n", *envp++);
7 |
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/tests/118-fork-exec/118-fork-exec.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | int res;
7 |
8 | res = fork();
9 | if (res > 0)
10 | {
11 | char *argv[] = {
12 | "/bin/echo",
13 | "hello",
14 | "world",
15 | NULL,
16 | };
17 | char *envp[] = {
18 | NULL,
19 | };
20 | fprintf(stderr, "child!\n");
21 | execve("/bin/echo", argv, envp);
22 | }
23 | else
24 | {
25 | fprintf(stderr, "parent: %d\n", res);
26 | }
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/tests/119-execve.js:
--------------------------------------------------------------------------------
1 | os.sys.call64([59, 0, "/bin/echo", ["/bin/echo", "hello", "world", 0, 0], [0, 0]]);
2 |
--------------------------------------------------------------------------------
/tests/120-builtin-setjmp-longjmp/120-builtin-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | jmp_buf env;
7 | printf("about to setjmp\n");
8 | fflush(stdout);
9 | printf("fp %p\n", __builtin_frame_address(0));
10 | if (__builtin_setjmp(env)) {
11 | printf("second return\n");
12 | } else {
13 | printf("first return\n");
14 | fflush(stdout);
15 | __builtin_longjmp(env, 1);
16 | printf("notreached\n");
17 | }
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/tests/121-dwarf2eh/121-dwarf2eh.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | main() {
4 | fprintf(stderr, "fp %p %p\n", __builtin_frame_address(0),
5 | __builtin_frame_address(1));
6 | fprintf(stderr, "cfa %p\n", __builtin_dwarf_cfa());
7 | fprintf(stderr, "rpc %p %p %p\n", __builtin_return_address(0),
8 | __builtin_return_address(1), __builtin_return_address(2));
9 | try {
10 | throw 1;
11 | }
12 | catch (...) {
13 | printf(" in catch\n");
14 | return 1;
15 | }
16 | printf(" back in main\n");
17 | return 10;
18 | }
19 |
--------------------------------------------------------------------------------
/tests/122-eh-return/122-eh-return.c:
--------------------------------------------------------------------------------
1 | void f(void)
2 | {
3 | __builtin_eh_return(0xdeadbeef, 0xc0dec0de);
4 | }
5 |
6 | int main(void)
7 | {
8 | f();
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/123-bra/123-bra.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int g(void)
4 | {
5 | fprintf(stderr, "ra(g): %p %p %p\n",
6 | __builtin_return_address (0),
7 | __builtin_return_address (1),
8 | __builtin_return_address (2));
9 |
10 | return 0;
11 | }
12 |
13 | int f(void)
14 | {
15 | fprintf(stderr, "ra(f): %p %p %p\n",
16 | __builtin_return_address (0),
17 | __builtin_return_address (1),
18 | __builtin_return_address (2));
19 |
20 | g();
21 |
22 | return 0;
23 | }
24 |
25 | int main(void)
26 | {
27 | f();
28 | return 0;
29 | }
30 |
--------------------------------------------------------------------------------
/tests/124-dwarf2eh/124-dwarf2eh.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f() {
4 | throw 1;
5 | }
6 |
7 | main() {
8 | fprintf(stderr, "fp %p %p\n", __builtin_frame_address(0),
9 | __builtin_frame_address(1));
10 | fprintf(stderr, "cfa %p\n", __builtin_dwarf_cfa());
11 | fprintf(stderr, "rpc %p %p %p\n", __builtin_return_address(0),
12 | __builtin_return_address(1), __builtin_return_address(2));
13 | try {
14 | f();
15 | }
16 | catch (...) {
17 | printf(" in catch\n");
18 | return 1;
19 | }
20 | printf(" back in main\n");
21 | return 10;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/125-mode-di/125-mode-di.c:
--------------------------------------------------------------------------------
1 | extern int f(void * __attribute__((mode(DI))) p, unsigned long long x);
2 |
3 | int main(void)
4 | {
5 | f((void *)0xdeadbeef, 0x12345678);
6 |
7 | return 0;
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/tests/126-broken-link/a.cpp:
--------------------------------------------------------------------------------
1 | template
2 | int
3 | s(T x)
4 | {
5 | return sizeof(T) + x;
6 | }
7 |
8 | int f()
9 | {
10 | return s(7);
11 | }
12 |
--------------------------------------------------------------------------------
/tests/126-broken-link/b.cpp:
--------------------------------------------------------------------------------
1 | template
2 | int
3 | s(T x)
4 | {
5 | return sizeof(T) + x;
6 | }
7 |
8 | int g()
9 | {
10 | return s(7);
11 | }
12 |
13 | int f();
14 |
15 | int main()
16 | {
17 | f();
18 | g();
19 | }
20 |
--------------------------------------------------------------------------------
/tests/127-unaligned/127-unaligned.cpp:
--------------------------------------------------------------------------------
1 | struct A {
2 | char c;
3 | int i;
4 | } __attribute__((packed));
5 |
6 | int main()
7 | {
8 | volatile A a;
9 | while(1)
10 | a.i++;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/128-pgrps/128-pgrps.c:
--------------------------------------------------------------------------------
1 | # include
2 | main()
3 | {
4 | # define getpgID() getpgrp()
5 | int pid1, pid2, fds[2];
6 | int status;
7 | char ok;
8 |
9 | switch (pid1 = fork()) {
10 | case -1:
11 | exit(1);
12 | case 0:
13 | setpgid(0, getpid());
14 | exit(0);
15 | }
16 | setpgid(pid1, pid1);
17 |
18 | sleep(2); /* let first child die */
19 |
20 | if (pipe(fds) < 0)
21 | exit(2);
22 |
23 | switch (pid2 = fork()) {
24 | case -1:
25 | exit(3);
26 | case 0:
27 | setpgid(0, pid1);
28 | ok = getpgID() == pid1;
29 | write(fds[1], &ok, 1);
30 | exit(0);
31 | }
32 | setpgid(pid2, pid1);
33 |
34 | close(fds[1]);
35 | if (read(fds[0], &ok, 1) != 1)
36 | exit(4);
37 | wait(&status);
38 | wait(&status);
39 | exit(ok ? 0 : 5);
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/tests/130-link/ext.c:
--------------------------------------------------------------------------------
1 | int bar(void)
2 | {
3 | return 7;
4 | }
5 |
--------------------------------------------------------------------------------
/tests/130-link/main.c:
--------------------------------------------------------------------------------
1 | int foo(void)
2 | {
3 | }
4 |
5 | int main(void)
6 | {
7 | }
8 |
--------------------------------------------------------------------------------
/tests/131-jsexport/131-jsexport.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #if 0
4 | struct __attribute__((jsexport)) {
5 | int x;
6 | int y;
7 | int z;
8 | };
9 |
10 | struct __attribute__((jsexport)) s {
11 | int x;
12 | int y;
13 | int z;
14 | };
15 |
16 | typedef struct __attribute__((jsexport)) s2 {
17 | int x;
18 | int y;
19 | int z;
20 | } s2;
21 | #endif
22 |
23 | __attribute__((jsexport)) int i;
24 | __attribute__((jsexport)) long long ll;
25 | #if 0
26 | __attribute__((jsexport)) struct s s3;
27 | __attribute__((jsexport)) struct s2 s4;
28 | __attribute__((jsexport)) s2 s5;
29 | #endif
30 |
31 | int main(void)
32 | {
33 | printf("main\n");
34 | return 0;
35 | }
36 |
--------------------------------------------------------------------------------
/tests/132-linked-list/addlink.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | TMP1=$(mktemp);
3 | TMP2=$(mktemp);
4 | TMP3=$(mktemp);
5 | TMP4=$(mktemp);
6 | TMP5=$(mktemp);
7 | TMP6=$(mktemp);
8 | TMP7=$(mktemp);
9 | asmjs-virtual-asmjs-objcopy $2 $TMP1 -N __header_start --add-symbol __header_start=.next_header:0
10 | asmjs-virtual-asmjs-ld -T linked-list.lds $1 $TMP1 -o $TMP2
11 | asmjs-virtual-asmjs-ld -T linked-list-1.lds $TMP2 -o $TMP3
12 | cp $TMP3 $1
13 |
--------------------------------------------------------------------------------
/tests/132-linked-list/data.S:
--------------------------------------------------------------------------------
1 | .data
2 | .asciz "A string"
3 |
--------------------------------------------------------------------------------
/tests/132-linked-list/linked-list-0.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .header :
5 | {
6 | __header_start = .;
7 | LONG(0);
8 | LONG(0);
9 | LONG(0);
10 | LONG(0);
11 | }
12 | .data :
13 | {
14 | *(.data)
15 | . = ALIGN(., 16);
16 | }
17 | __next_header_start = .;
18 | }
19 |
--------------------------------------------------------------------------------
/tests/132-linked-list/linked-list-1.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .data :
5 | {
6 | *(.header)
7 | *(.data)
8 | *(.next_header)
9 | *(.next_data)
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/tests/132-linked-list/linked-list.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .header :
5 | {
6 | LONG(__header_start);
7 | LONG(0);
8 | LONG(0);
9 | LONG(0);
10 | }
11 | /DISCARD/ :
12 | {
13 | *(.header)
14 | }
15 | .data :
16 | {
17 | *(.data)
18 | . = ALIGN(., 16);
19 | }
20 | __header_start = .;
21 | .next_header :
22 | {
23 | LONG(0);
24 | LONG(0);
25 | LONG(0);
26 | LONG(0);
27 | }
28 | .next_data :
29 | {
30 | *(.next_data)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/132-linked-list/run.sh:
--------------------------------------------------------------------------------
1 | asmjs-virtual-asmjs-gcc -c data.S
2 | asmjs-virtual-asmjs-ld -T multifile-0.lds data.o -o multifile1a.o
3 | asmjs-virtual-asmjs-objcopy --prefix-sections prev_ -N __data_start -N __data_end multifile1a.o multifile1.o
4 | asmjs-virtual-asmjs-ld -T multifile.lds multifile1.o data.o -o multifile2a.o
5 | asmjs-virtual-asmjs-objcopy --prefix-sections prev_ -N __data_start -N __data_end multifile2a.o multifile2.o
6 | asmjs-virtual-asmjs-ld -T multifile.lds multifile2.o data.o -o multifile3a.o
7 | asmjs-virtual-asmjs-objcopy --prefix-sections prev_ -N __data_start -N __data_end multifile3a.o multifile3.o
8 |
--------------------------------------------------------------------------------
/tests/133-multifile/README.org:
--------------------------------------------------------------------------------
1 | This illustrates how to build a linked list using linker scripts and objcopy. The idea is that this way we'll be able to link a non-relocatable executable plus a relocatable object file into a new non-relocatable executable
2 |
--------------------------------------------------------------------------------
/tests/133-multifile/data.S:
--------------------------------------------------------------------------------
1 | .data
2 | .asciz "A string"
3 |
--------------------------------------------------------------------------------
/tests/133-multifile/multifile-0.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .header :
5 | {
6 | LONG(ABSOLUTE(__data_start));
7 | LONG(ABSOLUTE(__data_end));
8 | LONG(0);
9 | LONG(0);
10 | }
11 | .data :
12 | {
13 | __data_start = .;
14 | *(.data)
15 | . = ALIGN(., 16);
16 | __data_end = .;
17 | }
18 | .term :
19 | {
20 | LONG(0);
21 | LONG(0);
22 | LONG(0);
23 | LONG(0);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/133-multifile/multifile-more.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .prev_header :
5 | {
6 | *(.prev_header)
7 | }
8 | .prev_data :
9 | {
10 | *(.prev_data)
11 | }
12 | .header :
13 | {
14 | LONG(__data_start);
15 | LONG(__data_end);
16 | LONG(0);
17 | LONG(0);
18 | }
19 | .data :
20 | {
21 | __data_start = .;
22 | *(.data)
23 | . = ALIGN(., 16);
24 | __data_end = .;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/133-multifile/multifile.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .prev.data :
5 | {
6 | *(.prev.prev.header)
7 | *(.prev.prev.data)
8 | *(.prev.header)
9 | *(.prev.data)
10 | }
11 | .header :
12 | {
13 | LONG(ABSOLUTE(__data_start));
14 | LONG(ABSOLUTE(__data_end));
15 | LONG(0);
16 | LONG(0);
17 | }
18 | .data :
19 | {
20 | __data_start = .;
21 | *(.data)
22 | . = ALIGN(., 16);
23 | __data_end = .;
24 | }
25 | /DISCARD/ :
26 | {
27 | *(.prev.term)
28 | }
29 | .term :
30 | {
31 | LONG(0);
32 | LONG(0);
33 | LONG(0);
34 | LONG(0);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/134-multifile/README.org:
--------------------------------------------------------------------------------
1 | This illustrates how to build a linked list using linker scripts and objcopy. The idea is that this way we'll be able to link a non-relocatable executable plus a relocatable object file into a new non-relocatable executable
2 |
--------------------------------------------------------------------------------
/tests/134-multifile/add1.sh:
--------------------------------------------------------------------------------
1 | TMP1=$(mktemp)
2 | asmjs-virtual-asmjs-ld -T multifile.lds $1 $2 -o $TMP1
3 | asmjs-virtual-asmjs-objcopy --prefix-sections .prev -N __data_start -N __data_end -N __init_array_start -N __init_array_end -N __terminator $TMP1 $1
4 |
--------------------------------------------------------------------------------
/tests/134-multifile/data.S:
--------------------------------------------------------------------------------
1 | .data
2 | str:
3 | .asciz "A string"
4 | .section .init_array
5 | .long str
6 |
--------------------------------------------------------------------------------
/tests/134-multifile/multifile-0.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .header :
5 | {
6 | LONG(ABSOLUTE(__data_start));
7 | LONG(ABSOLUTE(__terminator));
8 | LONG(0);
9 | LONG(0);
10 | LONG(ABSOLUTE(__init_array_start));
11 | LONG(ABSOLUTE(__init_array_end));
12 | LONG(0);
13 | LONG(0);
14 | }
15 | .data :
16 | {
17 | __data_start = .;
18 | *(.data)
19 | . = ALIGN(., 16);
20 | }
21 | .init_array :
22 | {
23 | __init_array_start = .;
24 | *(.init_array)
25 | __init_array_end = .;
26 | }
27 | . = ALIGN(., 16);
28 | .term :
29 | {
30 | __terminator = .;
31 | LONG(0);
32 | LONG(0);
33 | LONG(0);
34 | LONG(0);
35 | LONG(0);
36 | LONG(0);
37 | LONG(0);
38 | LONG(0);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/134-multifile/multifile-more.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | . = 16384;
4 | .prev_header :
5 | {
6 | *(.prev_header)
7 | }
8 | .prev_data :
9 | {
10 | *(.prev_data)
11 | }
12 | .header :
13 | {
14 | LONG(__data_start);
15 | LONG(__data_end);
16 | LONG(0);
17 | LONG(0);
18 | }
19 | .data :
20 | {
21 | __data_start = .;
22 | *(.data)
23 | . = ALIGN(., 16);
24 | __data_end = .;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/134-multifile/prevify.sh:
--------------------------------------------------------------------------------
1 | TMP1=$(mktemp)
2 | asmjs-virtual-asmjs-objcopy --prefix-sections .prev -N __data_start -N __data_end -N __init_array_start -N __init_array_end -N __terminator $1 $TMP1 && mv $TMP1 $1
3 |
--------------------------------------------------------------------------------
/tests/137-two-functions/137-two-functions.c:
--------------------------------------------------------------------------------
1 | int f(void)
2 | {
3 | volatile int x;
4 |
5 | x++;
6 | x++;
7 | x++;
8 |
9 | return x;
10 | }
11 |
12 | int main(void)
13 | {
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/tests/138-countloop/138-countloop.c:
--------------------------------------------------------------------------------
1 | void _start(void)
2 | {
3 | volatile int x = 0;
4 |
5 | while (++x);
6 | }
7 |
--------------------------------------------------------------------------------
/tests/139-function-call/139-function-call.c:
--------------------------------------------------------------------------------
1 | void loop(void)
2 | {
3 | volatile int i = 1;
4 | while (i++);
5 | }
6 |
7 | int main(void)
8 | {
9 | loop();
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/140-extcall/140-extcall.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | volatile char str[2];
4 |
5 | str[0] = '!';
6 | str[1] = 0;
7 | asm volatile("(call_import $extcall %O0 (i32.const 0) (i32.const 0) (i32.const 0))" : : "r" (str));
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/141-extcall/141-extcall.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | const char *str = "hello world\n";
4 |
5 | asm volatile("(call_import $extcall %O0 (i32.const 0) (i32.const 0) (i32.const 0))" : : "r" (str));
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/142-arith/142-arith.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | volatile int a, b, c;
4 |
5 | c = a + b;
6 | c = a - b;
7 | c = a << b;
8 | c = a >> b;
9 | c = a != b;
10 | c = a == b;
11 | c = a * b;
12 | b = 1;
13 | c = a % b;
14 | c = a / b;
15 |
16 | return c;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/143-syscall/143-syscall.c:
--------------------------------------------------------------------------------
1 | asm(".include \"wasm32-import-macros.s\"");
2 | asm(".import3_pic thinthin,write,__thinthin_write");
3 |
4 | extern __attribute__((stackcall)) int __thinthin_write(int, const char *, int);
5 |
6 | void _start(void)
7 | {
8 | return __thinthin_write(1, "hi there\n", __builtin_strlen("hi there\n"));
9 | }
10 |
11 | int main(void) {}
12 |
--------------------------------------------------------------------------------
/tests/144-primes/144-primes.c:
--------------------------------------------------------------------------------
1 | /* from emscripten */
2 | #include
3 | #include
4 | int main(int argc, char **argv) {
5 | int arg = argc > 1 ? argv[1][0] - '0' : 5;
6 | switch(arg) {
7 | case 0: return 0; break;
8 | case 1: arg = 33000; break;
9 | case 2: arg = 130000; break;
10 | case 3: arg = 220000; break;
11 | case 4: arg = 610000; break;
12 | case 5: arg = 1010000; break;
13 | default: printf("error: %d\\n", arg); return -1;
14 | }
15 |
16 | int primes = 0, curri = 2;
17 | while (primes < arg) {
18 | int ok = 1;
19 | for (int j = 2; j*j < curri; j++) {
20 | if (curri % j == 0) {
21 | ok = 0;
22 | break;
23 | }
24 | }
25 | if (ok) {
26 | primes++;
27 | }
28 | curri++;
29 | }
30 | printf("lastprime: %d.\n", curri-1);
31 | return 0;
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/tests/145-wasm-as/145-wasm-as.s:
--------------------------------------------------------------------------------
1 | .sleb128 end-start
2 | start:
3 | block
4 | end
5 | if
6 | else
7 | end
8 | nop
9 | i32.const 17
10 | end:
11 |
--------------------------------------------------------------------------------
/tests/146-b/146-b.s:
--------------------------------------------------------------------------------
1 | .pushsection .wasm.type
2 | .popsection
3 |
4 | .pushsection .wasm.funchars
5 | .popsection
6 |
7 | .macro defun name, sig:vararg
8 | .pushsection .wasm.sigchars
9 | __sigchar_\name\():
10 | .byte 0
11 | .pushsection .wasm.type
12 | __signature_\name\():
13 | signature \sig
14 | .popsection
15 | .pushsection .wasm.funchars
16 | \name\():
17 | .byte 0
18 | .pushsection .wasm.function
19 | .sleb128 __sigchar_\name\()
20 | .popsection
21 | .pushsection .wasm.code
22 | .endm
23 |
24 | .macro endefun
25 | .popsection
26 | .endm
27 |
28 | .globl h
29 | defun h, i32
30 | nop
31 | endefun
32 |
--------------------------------------------------------------------------------
/tests/149-printloop/149-printloop.c:
--------------------------------------------------------------------------------
1 | void _start(void)
2 | {
3 | volatile char x = 0;
4 |
5 | while (++x)
6 | asm volatile("%0\n\t%0\n\t%0\n\t%0\n\tcall_indirect 0 $extcall"
7 | : : "r" (0xdeadbeef));
8 | }
9 |
--------------------------------------------------------------------------------
/tests/150-divide/150-divide.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | volatile long x = 0x6000000000000000LL;
6 | volatile long y = 0xc000000000000000LL;
7 |
8 | printf("%lx %lx\n",
9 | x / y, x % y);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/151-uhwhat/151-uhwhat.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | volatile unsigned long x = 0x280000000L;
6 | volatile unsigned long y = 0x280000000L;
7 | printf("%d\n", x < y);
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/152-flush/152-flush.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm volatile("local.get $fp\n\t"
4 | "i64.const 1\n\t"
5 | "i64.or\n\t"
6 | "local.set $rp\n\t"
7 | "br __wasm_depth - __wasm_blocks");
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/153-constructor/153-constructor.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | class A {
4 | const char *str;
5 | public:
6 | A(const char *str)
7 | : str(str)
8 | {
9 | printf("%s\n", str);
10 | }
11 | };
12 |
13 | A a("hi there");
14 |
15 | int main()
16 | {
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/tests/154-dynlink/001-dso.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
3 | int g(void)
4 | {
5 | return x;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/154-dynlink/002-main.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int g(void);
4 |
5 | int main(void)
6 | {
7 | printf("%d\n", g());
8 | }
9 |
--------------------------------------------------------------------------------
/tests/154-dynlink/003-combined.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
3 | int g(void)
4 | {
5 | return x;
6 | }
7 | #include
8 |
9 | extern int g(void);
10 |
11 | int main(void)
12 | {
13 | printf("%d\n", g());
14 | }
15 |
--------------------------------------------------------------------------------
/tests/155-dlopen/155-dlopen.c:
--------------------------------------------------------------------------------
1 | asm("\t.include \"wasm32-import-macros.s\"\n"
2 | "\t.import3 thinthin,dlopen,__thinthin_dlopen\n"
3 | "\t.import3 thinthin,dlsym,__thinthin_dlsym\n");
4 |
5 | extern int __thinthin_dlopen(const char *path) __attribute__((stackcall));
6 | extern void *__thinthin_dlsym(const char *sym) __attribute__((stackcall));
7 |
8 | #include
9 |
10 | int main(void)
11 | {
12 | printf("open: %d\n", __thinthin_dlopen("test.wasm"));
13 | printf("dlsym: %p\n", __thinthin_dlsym("x"));
14 | printf("x: %d\n", *(int *)__thinthin_dlsym("x"));
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/156-async/156-async.s:
--------------------------------------------------------------------------------
1 | .include "wasm32-macros.s"
2 | .include "wasm32-import-macros.s"
3 |
4 | .global main
5 | defun main, FiiiiiiiE
6 | nextcase
7 | T 0
8 | T 1
9 | .labeldef_internal .L1
10 | .dpc .L1
11 | local.set $dpc
12 | T 2
13 | jump
14 | end
15 | end
16 | i32.const 0
17 | return
18 | end
19 | endefun main
20 |
--------------------------------------------------------------------------------
/tests/156-provide-x/156-provide-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
3 | void set_x(int nx)
4 | {
5 | x = nx;
6 | }
7 |
8 | int get_x(void)
9 | {
10 | return x;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/157-async/157-async.s:
--------------------------------------------------------------------------------
1 | .include "wasm32-macros.s"
2 | .include "wasm32-import-macros.s"
3 |
4 | .global main
5 | defun main, FiiiiiiiE
6 | T 0
7 | T 1
8 | T 2
9 | br 1
10 | i32.const 0
11 | return
12 | end
13 | endefun main
14 |
--------------------------------------------------------------------------------
/tests/157-minimal/157-minimal.s:
--------------------------------------------------------------------------------
1 | .include "wasm32-macros.s"
2 | .include "wasm32-import-macros.s"
3 |
4 | .global main
5 | defun main, FiiiiiiiE
6 | jump
7 | nextcase
8 | end
9 | i32.const 0
10 | return
11 | end
12 | endefun main
13 |
--------------------------------------------------------------------------------
/tests/158-async/158-async.s:
--------------------------------------------------------------------------------
1 | .include "wasm32-macros.s"
2 | .include "wasm32-import-macros.s"
3 |
4 | .global main
5 | defun main, FiiiiiiiE
6 | jump
7 | nextcase
8 | end
9 | i32.const 0
10 | return
11 | end
12 | endefun main
13 |
--------------------------------------------------------------------------------
/tests/159-async/159-async.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm volatile("nextcase\n\ti32.const 1\n\tget_local $fp\n\ti32.or\n\tset_local $rp\n\tthrow");
4 |
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/160-dlopen-fun/160-dlopen-fun.c:
--------------------------------------------------------------------------------
1 | asm("\t.include \"wasm32-import-macros.s\"\n"
2 | "\t.import3 thinthin,dlopen,__thinthin_dlopen\n"
3 | "\t.import3 thinthin,dlsym,__thinthin_dlsym\n");
4 |
5 | extern int __thinthin_dlopen(const char *path) __attribute__((stackcall));
6 | extern void *__thinthin_dlsym(const char *sym) __attribute__((stackcall));
7 |
8 | #include
9 |
10 | int main(void)
11 | {
12 | printf("open: %d\n", __thinthin_dlopen("test.wasm"));
13 | printf("dlsym: %p\n", __thinthin_dlsym("x"));
14 | printf("x: %d\n", *(int *)__thinthin_dlsym("x"));
15 | printf("get_x: %p\n", __thinthin_dlsym("get_x"));
16 | printf("get_x(): %d\n", ((int (*)(void))__thinthin_dlsym("get_x"))());
17 | ((void (*)(int))__thinthin_dlsym("set_x"))(84);
18 | printf("get_x(): %d\n", ((int (*)(void))__thinthin_dlsym("get_x"))());
19 |
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/tests/161-libc/161-libc.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi\n");
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/162-printf-in-dym/162-printf-in-dym.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(void)
4 | {
5 | printf("hi\n");
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/tests/163-dlopen-again/163-dlopen-again.c:
--------------------------------------------------------------------------------
1 | asm("\t.include \"wasm32-import-macros.s\"\n"
2 | "\t.import3 thinthin,dlopen,__thinthin_dlopen\n"
3 | "\t.import3 thinthin,dlsym,__thinthin_dlsym\n");
4 |
5 | extern int __thinthin_dlopen(const char *path) __attribute__((stackcall));
6 | extern void *__thinthin_dlsym(const char *sym) __attribute__((stackcall));
7 |
8 | #include
9 |
10 | int main(void)
11 | {
12 | printf("open: %d\n", __thinthin_dlopen("162.wasm"));
13 | printf("dlsym: %p\n", __thinthin_dlsym("f"));
14 | printf("x: %d\n", ((int (*)(void))__thinthin_dlsym("f"))());
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/164-hello-world-infloop/164-hello-world-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | asm(".include \"wasm32-import-macros.s\"");
4 |
5 | asm(".import3 thinthin,syscall,__thinthin_syscall");
6 |
7 | extern long __thinthin_syscall(long n, ...) __attribute__((stackcall));
8 |
9 | long long __wasm_syscall(long long n, long long a1, long long a2, long long a3, long long a4, long long a5, long long a6) __attribute__((stackcall));
10 |
11 |
12 | long long __wasm_syscall(long long n, long long a1, long long a2, long long a3, long long a4, long long a5, long long a6) {
13 | return __thinthin_syscall(n, a1, a2, a3, a4, a5, a6);
14 | }
15 | int main(void)
16 | {
17 | int (*p)(const char *) = puts;
18 | for (;;)
19 | p("hello world");
20 | }
21 |
--------------------------------------------------------------------------------
/tests/167-hello-world-dircall/167-hello-world-dircall.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int g(void)
7 | {
8 | fprintf(stderr, "bra: %p\n", __builtin_return_address(0));
9 |
10 | return g();
11 | }
12 |
13 | int main(void)
14 | {
15 | for (;;) {
16 | write(1, "hi\n", 3);
17 | int count = fprintf(stderr, "hey there: %p %p\n", stdout, stderr);
18 | g();
19 | break;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/168-dynlink/001-main.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | #include
4 |
5 | int main(void)
6 | {
7 | printf("%d\n", x);
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/168-dynlink/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/169-dynlink/001-main.c:
--------------------------------------------------------------------------------
1 | extern int f(void);
2 |
3 | #include
4 |
5 | int main(void)
6 | {
7 | printf("%d %p\n", f(), f);
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/tests/169-dynlink/002-f.c:
--------------------------------------------------------------------------------
1 | int f(void)
2 | {
3 | return 42;
4 | }
5 |
--------------------------------------------------------------------------------
/tests/170-dlload/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/171-dlload-dep/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/171-dlload-dep/003-f.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | #include
4 |
5 | int f(void)
6 | {
7 | printf("x: %p\n", &x);
8 | printf("\n");
9 |
10 | return x;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/171-dlload-dep/004-stdmain.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | void *handle = dlopen("003-f.so", RTLD_NOW|RTLD_GLOBAL);
7 | void *sym = dlsym(handle, "x");
8 |
9 | printf("%p\n", sym);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/171-dlload-dep/Makefile:
--------------------------------------------------------------------------------
1 | 001-main: 001-main.c
2 | wasm32-virtual-wasm32-gcc -o $@ $^
3 |
4 | 003-f.so: 003-f.c 002-x.so
5 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
6 | ../../bin/wasmify-wasm32 $@ > 003-f.wasm
7 |
8 | 002-x.so: 002-x.c
9 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
10 | ../../bin/wasmify-wasm32 $@ > 002-x.wasm
11 |
--------------------------------------------------------------------------------
/tests/172-dlload-stdapi/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/172-dlload-stdapi/003-f.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | #include
4 |
5 | int f(void)
6 | {
7 | printf("x: %p\n", &x);
8 | printf("\n");
9 |
10 | return x;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/172-dlload-stdapi/004-stdmain.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | void *handle = dlopen("003-f.so", RTLD_NOW|RTLD_GLOBAL);
7 | void *sym = dlsym(handle, "x");
8 |
9 | printf("%p\n", sym);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/172-dlload-stdapi/Makefile:
--------------------------------------------------------------------------------
1 | 001-main: 001-main.c
2 | wasm32-virtual-wasm32-gcc -o $@ $^
3 |
4 | 003-f.so: 003-f.c 002-x.so
5 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
6 | ../../bin/wasmify-wasm32 $@ > 003-f.wasm
7 |
8 | 002-x.so: 002-x.c
9 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
10 | ../../bin/wasmify-wasm32 $@ > 002-x.wasm
11 |
--------------------------------------------------------------------------------
/tests/173-libdl/001-main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int main(void)
8 | {
9 | printf("%p\n", dlopen);
10 | void *handle = dlopen("003-f.wasm", RTLD_NOW);
11 |
12 | int (*f)(void) = dlsym(handle, "f");
13 |
14 | printf("f: %d\n", f());
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/173-libdl/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/173-libdl/003-f.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | #include
4 |
5 | int f(void)
6 | {
7 | printf("x: %p\n", &x);
8 | printf("\n");
9 |
10 | return x;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/173-libdl/004-stdmain.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | void *handle = dlopen("003-f.so", RTLD_NOW|RTLD_GLOBAL);
7 | void *sym = dlsym(handle, "x");
8 |
9 | printf("%p\n", sym);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/173-libdl/Makefile:
--------------------------------------------------------------------------------
1 | 001-main: 001-main.c 005-libdl.so
2 | wasm32-virtual-wasm32-gcc -o $@ $^
3 |
4 | 003-f.so: 003-f.c 002-x.so
5 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
6 | ../../bin/wasmify-wasm32 $@ > 003-f.wasm
7 |
8 | 002-x.so: 002-x.c
9 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
10 | ../../bin/wasmify-wasm32 $@ > 002-x.wasm
11 |
12 | 005-libdl.so: 005-libdl.c
13 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
14 | ../../bin/wasmify-wasm32 $@ > 005-libdl.wasm
15 |
--------------------------------------------------------------------------------
/tests/174-libdl/001-main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int main(void)
8 | {
9 | printf("%p\n", dlopen);
10 | void *handle = dlopen("003-f.wasm", RTLD_NOW);
11 |
12 | int (*f)(void) = dlsym(handle, "f");
13 |
14 | printf("f: %d\n", f());
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/tests/174-libdl/002-x.c:
--------------------------------------------------------------------------------
1 | int x = 42;
2 |
--------------------------------------------------------------------------------
/tests/174-libdl/003-f.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | #include
4 |
5 | int f(void)
6 | {
7 | printf("x: %p\n", &x);
8 | printf("\n");
9 |
10 | return x;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/174-libdl/004-stdmain.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void)
5 | {
6 | void *handle = dlopen("003-f.so", RTLD_NOW|RTLD_GLOBAL);
7 | void *sym = dlsym(handle, "x");
8 |
9 | printf("%p\n", sym);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/174-libdl/Makefile:
--------------------------------------------------------------------------------
1 | 001-main: 001-main.c 005-libdl.so
2 | wasm32-virtual-wasm32-gcc -o $@ $^
3 |
4 | 003-f.so: 003-f.c 002-x.so
5 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
6 | ../../bin/wasmify-wasm32 $@ > 003-f.wasm
7 |
8 | 002-x.so: 002-x.c
9 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
10 | ../../bin/wasmify-wasm32 $@ > 002-x.wasm
11 |
12 | 005-libdl.so: 005-libdl.c
13 | wasm32-virtual-wasm32-gcc -fPIC -Wl,--shared --shared -o $@ $^
14 | ../../bin/wasmify-wasm32 $@ > 005-libdl.wasm
15 |
--------------------------------------------------------------------------------
/tests/175-lazyload/001-main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern void __wasm_lazyload_stub(void);
5 |
6 | int main(void)
7 | {
8 | *(void **)12416 = (void *)__wasm_lazyload_stub;
9 | printf("hi\n");
10 |
11 | volatile int dodl = 0;
12 |
13 | if (dodl)
14 | dlopen("hi", 0);
15 |
16 | printf("bye\n");
17 |
18 | return 0;
19 | }
20 |
--------------------------------------------------------------------------------
/tests/175-lazyload/003-lazyload.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void __wasm_lazyload(unsigned long index)
4 | {
5 | printf("index is %ld, should be %ld\n", index,
6 | *(long *)12408);
7 |
8 | asm volatile("i32.const 0xdeadbeef\n\t"
9 | "%0\n\t"
10 | "i32.const 0\n\t"
11 | "i32.const 0\n\t"
12 | "i32.const 0\n\t"
13 | "i32.const 0\n\t"
14 | "call $trace\n\t"
15 | "drop" : : "r" (index));
16 | }
17 |
--------------------------------------------------------------------------------
/tests/176-inlinable-import/176-inlinable-import.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int dummy(void) asm("$dummy");
4 |
5 | int main(void)
6 | {
7 | volatile double rootthis = 2.0;
8 | asm volatile("%S0\n\t%1\n\tcall $sqrt\n\t%R0" : "=r" (rootthis) : "r" (rootthis));
9 | fprintf(stderr, "sqrt(2) is %f\n", rootthis);
10 | //printf("%p\n", dummy);
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/tests/177-weak-symbol/177-weak-symbol.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int f(void) __attribute__((weak));
4 |
5 | int main(void)
6 | {
7 | if (f)
8 | fprintf(stderr, "%d\n", f());
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/178-strlen/178-strlen.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(int argc, char **argv)
5 | {
6 | printf("%zd\n", strlen(argv[0]));
7 |
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/tests/179-if-else/179-if-else.c:
--------------------------------------------------------------------------------
1 | extern void f(void);
2 | extern void g(void);
3 |
4 | int main(void)
5 | {
6 | volatile int cond;
7 |
8 | if (cond) {
9 | f();
10 | } else {
11 | g();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tests/180-while/180-while.c:
--------------------------------------------------------------------------------
1 | void f(void)
2 | {
3 | for(;;);
4 | }
5 |
6 | int main(void)
7 | {
8 | volatile int cond;
9 |
10 | while (cond) {
11 | f();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tests/181-plt/001-lib.c:
--------------------------------------------------------------------------------
1 | asm(".text\n\t"
2 | "createsig FiiiiiiiE\n\t"
3 | ".globl plus\n\t"
4 | "defun plus FdddE\n"
5 | "__wasm_body_blocks_plus:\n\t"
6 | "local.get 0\n\t"
7 | "local.get 1\n\t"
8 | "f64.add\n\t"
9 | "return\n\t"
10 | "end\n\t"
11 | "endefun plus");
12 |
--------------------------------------------------------------------------------
/tests/181-plt/002-user.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | double d1 = 3.14;
6 | double d2 = 2.71;
7 | double d;
8 |
9 | asm("createsig FdddE");
10 |
11 | asm("%S0\n\t%1\n\t%2\n\tcall plus@plt{__sigchar_FdddE}\n\t%R0" : "=r" (d) : "r" (d1), "r" (d2));
12 |
13 | printf("%f\n", d);
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/tests/182-rawcall/182-rawcall.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | extern int breakpoint3();
6 |
7 | int f(int) __attribute__((rawcall));
8 | int f(int x) {
9 | return 42;
10 | }
11 |
12 | int main(void)
13 | {
14 | int (*f2)(int) __attribute__((rawcall));
15 | f2 = (volatile void *)f;
16 | int ret = f(41);
17 | ret = f2(43);
18 |
19 | while (1)
20 | ret += printf("hello world: %d\n", ret);
21 | }
22 |
--------------------------------------------------------------------------------
/tests/184-static-constructor/184-static-constructor.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | class A {
4 | public:
5 | A() { printf("hi\n"); }
6 | ~A () { }
7 | };
8 |
9 | A a;
10 |
11 | main () {
12 | }
13 |
--------------------------------------------------------------------------------
/tests/185-weaksym/185-weaksym.c:
--------------------------------------------------------------------------------
1 | extern void f(void) __attribute__((weak));
2 |
3 | int main(void)
4 | {
5 | if (f)
6 | f();
7 | }
8 |
--------------------------------------------------------------------------------
/tests/186-static-constructor/186-static-constructor.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | class A {
4 | public:
5 | A() { for(;;); }
6 | ~A () { }
7 | };
8 |
9 | A a;
10 |
11 | main () {
12 | }
13 |
--------------------------------------------------------------------------------
/tests/187-plt/187-plt.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | void *f = printf;
6 | asm("" : "+r" (f));
7 | if (f)
8 | printf("hi\n");
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/tests/188-weaksym/188-weaksym.c:
--------------------------------------------------------------------------------
1 | asm("createsig FiiE");
2 |
3 | extern int f(int) __attribute__((weak)) __attribute__((rawcall));
4 |
5 | int main(void)
6 | {
7 | if (f)
8 | f(0);
9 | }
10 |
--------------------------------------------------------------------------------
/tests/189-hidden-weaksym/189-hidden-weaksym.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | asm("createsig FiiE");
4 |
5 | //asm(".hidden f");
6 |
7 | extern int f(int) __attribute__((weak)) __attribute__((rawcall));
8 |
9 | int main(void)
10 | {
11 | printf ("%p\n", f);
12 | if (f)
13 | f (42);
14 | }
15 |
--------------------------------------------------------------------------------
/tests/190-weakdef/001.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | asm("createsig FiiE");
4 |
5 | extern int f(int) __attribute__((weak)) __attribute__((rawcall));
6 |
7 | int main(void)
8 | {
9 | if (f)
10 | printf ("%d\n", f(42));
11 | }
12 |
--------------------------------------------------------------------------------
/tests/190-weakdef/002.S:
--------------------------------------------------------------------------------
1 | .include "wasm32-macros.s"
2 | .globl f
3 | defun f FiiE
4 | get_local 0
5 | i32.const 37
6 | i32.add
7 | return
8 | end
9 | endefun f
10 |
--------------------------------------------------------------------------------
/tests/192-hidden-def/192-hidden-def.c:
--------------------------------------------------------------------------------
1 | extern int x __attribute__ ((visibility ("hidden")));
2 | int x __attribute__ ((visibility ("hidden")));
3 |
--------------------------------------------------------------------------------
/tests/193-use-hidden-def/193-use-hidden-def.c:
--------------------------------------------------------------------------------
1 | extern int x __attribute__ ((visibility ("hidden")));
2 |
3 | void _start(void)
4 | {
5 | x++;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/194-conftest.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf ("hello world\n");
6 | }
7 |
--------------------------------------------------------------------------------
/tests/194-conftest/194-conftest.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern FILE _IO_2_1_stdout_;
4 |
5 | int main(void)
6 | {
7 | while (1)
8 | {
9 | //stdout = (void *)(0x7560 + 36864);
10 | puts("boo");
11 | printf ("hello world\n");
12 | char str[128] = {0,};
13 | sprintf (str, "stdout is at %p\n", stdout);
14 | puts (str);
15 | for (int i = 0; i < 1024; i += 4)
16 | {
17 | sprintf (str, "stdout[%d] = %08x\n", i, *(((int *)stdout)+i/4));
18 | puts (str);
19 | }
20 | //fprintf (stdout, "stdout should be at %p\n", stdout);
21 | printf ("%p\n", stdout);
22 | printf ("bye world\n");
23 | read (0, 0, 0);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/195-dropped-symbol/001-define-symbol.c:
--------------------------------------------------------------------------------
1 | int x = 3;
2 |
--------------------------------------------------------------------------------
/tests/195-dropped-symbol/002-reference-symbol.c:
--------------------------------------------------------------------------------
1 | extern int x;
2 |
3 | int main(void)
4 | {
5 | return x;
6 | }
7 |
--------------------------------------------------------------------------------
/tests/196-versions/001-versioned.c:
--------------------------------------------------------------------------------
1 | asm(".symver foo,versioned@@VERS_1.0");
2 |
3 | int foo(void)
4 | {
5 | printf("in foo\n");
6 | }
7 |
--------------------------------------------------------------------------------
/tests/196-versions/002-reference.c:
--------------------------------------------------------------------------------
1 | extern int versioned(void);
2 |
3 | int main(void)
4 | {
5 | return versioned();
6 | }
7 |
--------------------------------------------------------------------------------
/testsuite/features/001-rawcall.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int fi(int) __attribute__((rawcall));
4 | long long fl(long long) __attribute__((rawcall));
5 | float ff(float) __attribute__((rawcall));
6 | double fd(double) __attribute__((rawcall));
7 | void fv(void) __attribute__((rawcall));
8 |
9 | int fi(int x)
10 | {
11 | return x * x;
12 | }
13 |
14 | long long fl(long long x)
15 | {
16 | return x * x;
17 | }
18 |
19 | float ff(float x)
20 | {
21 | return x * x;
22 | }
23 |
24 | double fd(double x)
25 | {
26 | return x * x;
27 | }
28 |
29 | void fv(void)
30 | {
31 | }
32 |
33 | int main(void)
34 | {
35 | printf("%d\n", fi(42));
36 | printf("%lld\n", fl(42));
37 | printf("%f\n", ff(42.5));
38 | printf("%f\n", fd(42.25));
39 |
40 | fv();
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/testsuite/features/001-rawcall.d:
--------------------------------------------------------------------------------
1 | # source: 001-rawcall.c
2 | # gcc:
3 | # wasmify:
4 | # run:
5 | 1764
6 | 1764
7 | 1806.250000
8 | 1785.062500
9 |
--------------------------------------------------------------------------------
/testsuite/features/002-export.c:
--------------------------------------------------------------------------------
1 | int f(int x)
2 | {
3 | return 0;
4 | }
5 |
6 | int f(int) __attribute__((export));
7 |
8 | int x __attribute__((export("y")));
9 |
10 | int main(void)
11 | {
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/features/003-import.c:
--------------------------------------------------------------------------------
1 | //int f(int) __attribute__((import("sys", "g")));
2 | int g(int) __attribute__((import("sys"))) __attribute__((rawcall));
3 |
4 | int main(void)
5 | {
6 | //f(42);
7 |
8 | g(84);
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/testsuite/features/004-import-var.c:
--------------------------------------------------------------------------------
1 | extern int x __attribute__((import("sys")));
2 |
3 | #include
4 |
5 | int main(void)
6 | {
7 | printf("%p\n", &x);
8 | printf("%d\n", x);
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/testsuite/features/004-import-var.d:
--------------------------------------------------------------------------------
1 | #source: 004-import-var.c
2 | #skipcflags: .*-flto.*
3 | #gcc:
4 | #run:
5 | 0x2060
6 | 7
7 |
--------------------------------------------------------------------------------
/testsuite/features/005-copyreloc.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern FILE *stderr;
4 |
5 | int main(void)
6 | {
7 | fprintf (stderr, "hi\n");
8 | stderr = NULL;
9 | fprintf (stderr, "segfault!\n");
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/testsuite/features/005-copyreloc.d:
--------------------------------------------------------------------------------
1 | #source: 005-copyreloc.c
2 | #gcc:
3 | #run:
4 | #error: .*
5 | #stderr: hi
6 |
--------------------------------------------------------------------------------
/testsuite/features/features.exp:
--------------------------------------------------------------------------------
1 | run_dump_test "001-rawcall"
2 | run_dump_test "004-import-var"
3 | run_dump_test "005-copyreloc"
4 |
--------------------------------------------------------------------------------
/testsuite/new/001-fail.c:
--------------------------------------------------------------------------------
1 | int main {}
2 |
--------------------------------------------------------------------------------
/testsuite/new/001-fail.d:
--------------------------------------------------------------------------------
1 | #source: 001-fail.c
2 | #gcc:
3 | #error: .*error: .*
4 |
--------------------------------------------------------------------------------
/testsuite/new/002-warning.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | main() {
4 | printf("hello world\n");
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/testsuite/new/002-warning.d:
--------------------------------------------------------------------------------
1 | #source: 002-warning.c
2 | #gcc: -Wall
3 | #warning: .*
4 | #pass
5 |
--------------------------------------------------------------------------------
/testsuite/new/003-head.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | while (1)
6 | printf("XXX\n");
7 | }
8 |
--------------------------------------------------------------------------------
/testsuite/new/003-head.d:
--------------------------------------------------------------------------------
1 | #source: 003-head.c
2 | #gcc:
3 | #run: | head -10
4 | XXX
5 | XXX
6 | XXX
7 | XXX
8 | XXX
9 | XXX
10 | XXX
11 | XXX
12 | XXX
13 | XXX
14 |
--------------------------------------------------------------------------------
/testsuite/new/004-symbols.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi\n");
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/testsuite/new/005-stackcall.c:
--------------------------------------------------------------------------------
1 | int f(int, long long, int) __attribute__((stackcall));
2 |
3 | int f(int a, long long b, int c)
4 | {
5 | return a / 'a' + b / 'b' + c / 'c';
6 | }
7 |
--------------------------------------------------------------------------------
/testsuite/new/005-stackcall.d:
--------------------------------------------------------------------------------
1 | # source: 005-stackcall.c
2 | # gcc-S:
--------------------------------------------------------------------------------
/testsuite/new/007-exception.cpp:
--------------------------------------------------------------------------------
1 | // Testcase for proper handling of
2 | // c++ type, constructors and destructors.
3 |
4 | #include
5 |
6 | void
7 | f()
8 | {
9 | printf ("Throwing 1...\n");
10 | throw 3;
11 | }
12 |
13 |
14 | int
15 | main ()
16 | {
17 | printf ("hi!\n");
18 | try
19 | {
20 | f ();
21 | }
22 | catch (...)
23 | {
24 | printf ("Caught.\n");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/testsuite/new/007-exception.d:
--------------------------------------------------------------------------------
1 | # source: 007-exception.cpp
2 | # gxx:
3 | # run:
4 | hi!
5 | Throwing 1...
6 | Caught.
7 |
--------------------------------------------------------------------------------
/testsuite/new/008-exception-class.cpp:
--------------------------------------------------------------------------------
1 | // Testcase for proper handling of
2 | // c++ type, constructors and destructors.
3 |
4 | #include
5 |
6 | int c, d;
7 |
8 | struct A
9 | {
10 | int i;
11 | A () { i = ++c; printf("."); }
12 | ~A () { ++d; printf(","); }
13 | };
14 |
15 | void
16 | f()
17 | {
18 | printf ("Throwing 1...\n");
19 | throw A();
20 | }
21 |
22 | int
23 | main ()
24 | {
25 | A x;
26 | printf("hi!\n");
27 | try
28 | {
29 | f();
30 | }
31 | catch (A x)
32 | {
33 | printf ("Caught %d.\n", x.i);
34 | {
35 | A z;
36 | }
37 | printf ("Destroyed.\n");
38 | }
39 | printf ("c == %d, d == %d\n", c, d);
40 | return c != d;
41 | }
42 |
--------------------------------------------------------------------------------
/testsuite/new/008-exception-class.d:
--------------------------------------------------------------------------------
1 | # source: 008-exception-class.cpp
2 | # gxx:
3 | # run:
4 | .hi!
5 | Throwing 1...
6 | .Caught 2.
7 | .,Destroyed.
8 | ,,c == 3, d == 3
9 | #pass
--------------------------------------------------------------------------------
/testsuite/new/008-malloc.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | volatile void *p = malloc(512);
6 |
7 | return p != 0;
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/new/008-malloc.d:
--------------------------------------------------------------------------------
1 | # source: 008-malloc.c
2 | # gcc:
3 | # run:
4 |
--------------------------------------------------------------------------------
/testsuite/new/010-weaksym.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | asm("createsig FiiE");
4 |
5 | extern int f(int) __attribute__((weak));
6 |
7 | int main(void)
8 | {
9 | void (*g)(void) __attribute__((rawcall)) = 0;
10 |
11 | printf("%p\n", f);
12 |
13 | f(0);
14 | }
15 |
--------------------------------------------------------------------------------
/testsuite/new/010-weaksym.d:
--------------------------------------------------------------------------------
1 | #source: 010-weaksym.c
2 | #gcc:
3 | #run:
4 | #stderr: NULL called\!
5 | #pass
--------------------------------------------------------------------------------
/testsuite/new/011-weaksym.c:
--------------------------------------------------------------------------------
1 | extern int f(int) __attribute__((weak));
2 |
3 | int main(void)
4 | {
5 | int (*g)(int) = f;
6 |
7 | g(0);
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/new/011-weaksym.d:
--------------------------------------------------------------------------------
1 | #source: 010-weaksym.c
2 | #gcc:
3 | #run:
4 | #stderr: NULL called\!
5 | #pass
--------------------------------------------------------------------------------
/testsuite/new/new.exp:
--------------------------------------------------------------------------------
1 | run_dump_test "001-fail"
2 | run_dump_test "002-warning"
3 | run_dump_test "003-head"
4 | run_dump_test "007-exception"
5 | run_dump_test "008-exception-class"
6 | run_dump_test "010-weaksym"
7 | run_dump_test "011-weaksym"
8 |
--------------------------------------------------------------------------------
/testsuite/old/001-do-nothing.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | volatile int x = 1;
6 | if (x != 1) {
7 | printf("hello world\n");
8 | }
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/testsuite/old/001-do-nothing.d:
--------------------------------------------------------------------------------
1 | #source: 001-do-nothing.c
2 | #gcc:
3 | #run:
4 |
--------------------------------------------------------------------------------
/testsuite/old/002-hello-world-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | for (;;)
6 | printf("hello world\n");
7 | }
8 |
--------------------------------------------------------------------------------
/testsuite/old/002-hello-world-infloop.d:
--------------------------------------------------------------------------------
1 | #source: 002-hello-world-infloop.c
2 | #gcc:
3 | #warning: .*
4 | #run: | head -10
5 | hello world
6 | hello world
7 | hello world
8 | hello world
9 | hello world
10 | hello world
11 | hello world
12 | hello world
13 | hello world
14 | hello world
15 |
--------------------------------------------------------------------------------
/testsuite/old/003-hello-world-infloop-count.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | puts("hello world: %d %%f %s %c\n");
9 | ret += printf("hello world: %d %%f %s %c\n", ret,
10 | /* 4.5, */
11 | "string", (int)'x');
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/testsuite/old/003-hello-world-infloop-count.d:
--------------------------------------------------------------------------------
1 | #source: 003-hello-world-infloop-count.c
2 | #gcc:
3 | #run: | head -10
4 | hello world: %d %%f %s %c
5 |
6 | hello world: 0 %f string x
7 | hello world: %d %%f %s %c
8 |
9 | hello world: 27 %f string x
10 | hello world: %d %%f %s %c
11 |
12 | hello world: 55 %f string x
13 | hello world: %d %%f %s %c
14 | #pass
--------------------------------------------------------------------------------
/testsuite/old/004-hello-world-infloop-count.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | extern int breakpoint3();
6 |
7 | int main(void)
8 | {
9 | int ret = 42;
10 |
11 | while (1)
12 | ret += printf("hello world: %d\n", ret);
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/004-hello-world-infloop-count.d:
--------------------------------------------------------------------------------
1 | #source: 004-hello-world-infloop-count.c
2 | #gcc:
3 | #warning: .*
4 | #run: | head -10
5 | hello world: 42
6 | hello world: 58
7 | hello world: 74
8 | hello world: 90
9 | hello world: 106
10 | hello world: 123
11 | hello world: 140
12 | hello world: 157
13 | hello world: 174
14 | hello world: 191
15 | #pass
--------------------------------------------------------------------------------
/testsuite/old/005-hello-world-infloop-double.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1)
8 | ret += printf("hello world: %d %f %s %c\n", ret,
9 | 4.5, "string", 'x');
10 | }
11 |
--------------------------------------------------------------------------------
/testsuite/old/005-hello-world-infloop-double.d:
--------------------------------------------------------------------------------
1 | #source: 005-hello-world-infloop-double.c
2 | #gcc:
3 | #warning: .*
4 | #run: | head -10
5 | hello world: 0 4.500000 string x
6 | hello world: 33 4.500000 string x
7 | hello world: 67 4.500000 string x
8 | hello world: 101 4.500000 string x
9 | hello world: 136 4.500000 string x
10 | hello world: 171 4.500000 string x
11 | hello world: 206 4.500000 string x
12 | hello world: 241 4.500000 string x
13 | hello world: 276 4.500000 string x
14 | hello world: 311 4.500000 string x
15 | #pass
--------------------------------------------------------------------------------
/testsuite/old/006-function-call.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | printf("a %d b %d\n", a, b);
6 | return 7 * a - b;
7 | }
8 |
9 | int main(void)
10 | {
11 | puts("hi");
12 | puts("hi");
13 | printf("%d\n", f(10, 5));
14 | printf("%d\n", f(5, 10));
15 | fprintf(fdopen(1, "w"), "hi there %d\n", 42);
16 |
17 | return 0;
18 | }
19 |
20 | const char *string = "this is a constant string";
21 |
--------------------------------------------------------------------------------
/testsuite/old/006-function-call.d:
--------------------------------------------------------------------------------
1 | #source: 006-function-call.c
2 | #gcc:
3 | #warning: .*
4 | #run: | head -10
5 | hi there 42
6 | hi
7 | hi
8 | a 10 b 5
9 | 65
10 | a 5 b 10
11 | 25
12 |
--------------------------------------------------------------------------------
/testsuite/old/007-argc-argv.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int argc, char **argv)
9 | {
10 | printf("stderr is %p\n", stderr);
11 | fprintf(stderr, "argc: %d\n", argc);
12 | fprintf(stderr, "argv: %p\n", argv);
13 | fprintf(stderr, "arg0: %s\n", argv[0]);
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/testsuite/old/008-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7)
9 | {
10 | asm("Module.print('in main, sp is ' + sp + ' bp is ' + fp);");
11 | asm("Module.print('' + HEAP32[(sp+32)>>2]);");
12 | asm("Module.print('' + HEAP32[(fp+20)>>2]);");
13 | fprintf(stderr, "arg0: %d\n", arg0);
14 | fprintf(stderr, "arg1: %d\n", arg1);
15 | fprintf(stderr, "arg2: %d\n", arg2);
16 | fprintf(stderr, "arg3: %d\n", arg3);
17 | fprintf(stderr, "arg4: %d\n", arg4);
18 | fprintf(stderr, "arg5: %d\n", arg5);
19 | fprintf(stderr, "arg6: %d\n", arg6);
20 | fprintf(stderr, "arg7: %d\n", arg7);
21 |
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/testsuite/old/009-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int main(int argc, char **argv)
9 | {
10 | fprintf(stderr, "arg0: %p %s\n", argv+0, argv[0]);
11 | fprintf(stderr, "arg1: %p %s\n", argv+1, argv[1]);
12 | fprintf(stderr, "arg2: %p %s\n", argv+2, argv[2]);
13 | fprintf(stderr, "arg3: %p %s\n", argv+3, argv[3]);
14 | fprintf(stderr, "arg4: %p %s\n", argv+4, argv[4]);
15 | fprintf(stderr, "arg5: %p %s\n", argv+5, argv[5]);
16 | fprintf(stderr, "arg6: %p %s\n", argv+6, argv[6]);
17 | fprintf(stderr, "arg7: %p %s\n", argv+7, argv[7]);
18 | fprintf(stderr, "argc: %d\n", argc);
19 | fprintf(stderr, "argv: %p\n", argv);
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/testsuite/old/011-printstr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int a, int b)
4 | {
5 | return 2 * a - b;
6 | }
7 |
8 | int printstr(const char *string)
9 | {
10 | asm("Module.print('string should be ' + HEAPU32[($bp + 20 )>>2]);");
11 | return fprintf(stderr, "string: %s\n", string);
12 | }
13 |
14 | int main(int argc, char **argv)
15 | {
16 | int i;
17 |
18 | for(i = 0; i<1024; i++) {
19 | fprintf(stderr, "%d\n", i);
20 | asm("Module.printErr('sp ' + $sp);\n");
21 | }
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/testsuite/old/012-printf-doubles.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | double d = 1.2;
6 |
7 | printf("%f\n", 1.2);
8 | printf("%f\n", 1.2);
9 | printf("%f %f\n", 1.2, 3.4);
10 | printf("%f %d %f\n", 1.2, 3, 4.5);
11 | printf("%f %d %d %f\n", 1.2, 3, 4, 5.6);
12 | printf("%f %d %f %d %f %d %f\n", 1.2, 3, 4.5, 6, 7.8, 9, 10.11);
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/testsuite/old/013-asm.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm("\n\n/* %0 %1 */\n"
4 | :
5 | : "p"(0), "P"(0));
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/old/014-count.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | int i;
4 |
5 | for (i=0; i<1024; i++)
6 | printf("%d\n", i);
7 | }
8 |
--------------------------------------------------------------------------------
/testsuite/old/015-sscanf-fscanf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int dr_sscanf(const char *, const char *, ...);
4 |
5 | int main(void)
6 | {
7 | int x = 7;
8 | char buf[80];
9 |
10 | //dr_sscanf("3", "%d", &x);
11 | sscanf("3", "%d", &x);
12 | fscanf(stdin, "%d", &x);
13 | fread(buf, 79, 1, stdin);
14 | scanf("%d", &x);
15 |
16 | printf("%d\n", x);
17 |
18 | printf("%p\n", sscanf);
19 |
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/testsuite/old/016-double.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | double d = 1.0;
6 | double e = 1.0 + 1.0;
7 | double f = e - d;
8 |
9 | fprintf(stderr, "d = %f e = %f f = %f\n", d, e, f);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/testsuite/old/017-fptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo(void)
4 | {
5 | return 0;
6 | }
7 |
8 | extern int main(void);
9 |
10 | void *mainp = main;
11 |
12 | int main(void)
13 | {
14 | static int (*foop)(void) = foo;
15 | printf("%p\n", mainp);
16 | printf("%p %d\n", foop, foop());
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/testsuite/old/017-fptr.d:
--------------------------------------------------------------------------------
1 | # source: 017-fptr.c
2 | # gcc:
3 | # run:
4 | 0x.*
5 | 0x.* 0
6 |
--------------------------------------------------------------------------------
/testsuite/old/018-ptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo[4];
4 | int *foop = foo;
5 |
6 | int main(void)
7 | {
8 | printf("%p\n", foop);
9 | printf("%p\n", foo);
10 | foo[0] = 0;
11 | printf("%p\n", foop);
12 | printf("%p\n", foo);
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/testsuite/old/019-varargs.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int f(int count, ...)
5 | {
6 | char buf[1024];
7 | va_list ap;
8 |
9 | va_start(ap,count);
10 | vsprintf(buf, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n", ap);
11 |
12 | va_end(ap);
13 |
14 | fprintf(stderr, "%s\n", buf);
15 |
16 | return 0;
17 | }
18 |
19 | int main(void)
20 | {
21 | f(16, 1.0, 2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0);
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/testsuite/old/020-int-varargs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
6 | 0, 1, 2, 3,
7 | 4, 5, 6, 7,
8 | 8, 9,10,11,
9 | 12,13,14,15);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/testsuite/old/022-stack.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | volatile int stack1 = 0;
4 |
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/testsuite/old/023-fptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int foo(void)
4 | {
5 | return 0;
6 | }
7 |
8 | int main(void)
9 | {
10 | static int (*foop)(void) = foo;
11 | printf("%p %d\n", foop, foop());
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/024-nofloat.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | ret += printf("hello world: %d %%f %s %c\n", ret,
9 | /* 4.5, */
10 | "string", (int)'x');
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/025-nofloat.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 0;
6 |
7 | while (1) {
8 | ret += fprintf(stdout, "hello world: %d %%f %s %c\n", ret,
9 | /* 4.5, */
10 | "string", (int)'x');
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/026-undefined.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int thisisanundefinedfunctionsname(void);
4 |
5 | int main(void)
6 | {
7 | return thisisanundefinedfunctionsname();
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/old/027-intsizes.c:
--------------------------------------------------------------------------------
1 | // from the perl configure script
2 | #include
3 | #define I_STDLIB
4 | #ifdef I_STDLIB
5 | #include
6 | #endif
7 | int main()
8 | {
9 | printf("intsize=%d;\n", (int)sizeof(int));
10 | printf("longsize=%d;\n", (int)sizeof(long));
11 | printf("shortsize=%d;\n", (int)sizeof(short));
12 | exit(0);
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/028-twostrings.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char *string = "this is not the null string\n";
4 | const char *string2 = "this is not the null string either\n";
5 |
6 | int main(void)
7 | {
8 | fprintf(stderr, "%s", string);
9 | }
10 |
--------------------------------------------------------------------------------
/testsuite/old/029-flush.c:
--------------------------------------------------------------------------------
1 | int main(void)
2 | {
3 | asm volatile("pc=${label:%=};continue;\n${labeldef:%=}" : : );
4 | }
5 |
--------------------------------------------------------------------------------
/testsuite/old/030-myprintf.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void my_printf(const char *format, ...)
5 | {
6 | __isoc_va_list args;
7 |
8 | va_start(args, format);
9 | printf("args is %p %p\n", args, *(void **)args);
10 | vprintf(format, args);
11 | va_end(args);
12 |
13 | return ;
14 | }
15 |
16 | int main(void)
17 | {
18 | my_printf("hi\n");
19 | my_printf("hi %d\n", 42);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/testsuite/old/031-myprintf-main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void my_printf(const char *format, ...)
5 | {
6 | __isoc_va_list args;
7 | void *args2;
8 |
9 | va_start(args, format);
10 | printf("args is %p %p\n", args, *(void **)args);
11 | args2 = (void *)(*(void **)&args);
12 | args2 += 4;
13 | vprintf(format, ((void *)&args2));
14 | va_end(args);
15 |
16 | return ;
17 | }
18 |
19 | int main(void)
20 | {
21 | my_printf("hi\n");
22 | my_printf("hi %p=%s, %s, %s, %d %x %o %p %d %p\n",
23 | main, "hi", "there", "this", 10, 10, 10, main, 10, main);
24 | printf("hi %p=%s, %s, %s, %d %x %o %p %d %p\n",
25 | main, "hi", "there", "this", 10, 10, 10, main, 10, main);
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/testsuite/old/035-floor.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main(void)
7 | {
8 | double d = 2591024700;
9 | unsigned long l = (unsigned)floor(d+.5)+.5;
10 | fprintf(stderr, "%lu\n", l);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/testsuite/old/036-funcall.c:
--------------------------------------------------------------------------------
1 | extern void f(int x);
2 | extern int g(int x);
3 |
4 | int main(void)
5 | {
6 | f(22);
7 | g(42);
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/old/038-hw-terminates.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | int ret = 42;
6 |
7 | while (ret < 10000000)
8 | ret += printf("hello world: %d\n", ret);
9 | }
10 |
--------------------------------------------------------------------------------
/testsuite/old/039-cc-float-double.c:
--------------------------------------------------------------------------------
1 | extern void v_f(float);
2 | extern void v_d(double);
3 | extern void v_ff(float, float);
4 | extern void v_fd(float, double);
5 | extern void v_df(double, float);
6 | extern void v_dd(double, double);
7 |
8 | extern int i_f(float);
9 | extern int i_d(double);
10 | extern int i_ff(float, float);
11 | extern int i_fd(float, double);
12 | extern int i_df(double, float);
13 | extern int i_dd(double, double);
14 |
15 |
16 | int main(void)
17 | {
18 | volatile float x = 1.3;
19 | volatile double y = 2.5;
20 | volatile float z = 3.5;
21 | volatile double a = 4.5;
22 |
23 | v_f(x);
24 | v_f(z);
25 | v_d(y);
26 | v_d(a);
27 | v_ff(x, z);
28 | v_fd(x, y);
29 | v_df(a, x);
30 | v_dd(y, a);
31 |
32 | i_f(x);
33 | i_f(z);
34 | i_d(y);
35 | i_d(a);
36 | i_ff(x, z);
37 | i_fd(x, y);
38 | i_df(a, x);
39 | i_dd(y, a);
40 | }
41 |
--------------------------------------------------------------------------------
/testsuite/old/040-fdopen-argi.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char **argv)
4 | {
5 | fprintf(fdopen(1, "w"), "%d %s %s %s %s\n", argc, argv[0], argv[1], argv[2], argv[3]);
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/old/041-addrof.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int a(void);
4 | extern int b;
5 |
6 | int c(void);
7 | int d;
8 |
9 | void *ap = a;
10 | void *bp = &b;
11 | void *cp = c;
12 | void *dp = &d;
13 |
14 | int main(void)
15 | {
16 | printf("%p %p\n", a, &b);
17 | }
18 |
--------------------------------------------------------------------------------
/testsuite/old/042-putchar.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | putchar('h');
6 | putchar('i');
7 | putchar('!');
8 | putchar('\n');
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/testsuite/old/043-printf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi!\n");
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/testsuite/old/044-printf-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | f();
11 | }
12 |
--------------------------------------------------------------------------------
/testsuite/old/045-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/testsuite/old/046-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/testsuite/old/047-printf-fcall-loop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(void)
4 | {
5 | printf("hi!\n");
6 | }
7 |
8 | int main(void)
9 | {
10 | while (1)
11 | f();
12 | }
13 |
--------------------------------------------------------------------------------
/testsuite/old/048-printf-fcall-infloop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int f(int count)
4 | {
5 | return printf("hi %d\n", count);
6 | }
7 |
8 | int main(void)
9 | {
10 | int x = 0;
11 |
12 | while (1)
13 | x += f(x);
14 | }
15 |
--------------------------------------------------------------------------------
/testsuite/old/049-printf-rec.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(void)
4 | {
5 | printf("hi\n");
6 | main();
7 | }
8 |
--------------------------------------------------------------------------------
/testsuite/old/050-exit3.c:
--------------------------------------------------------------------------------
1 | extern void _Noreturn exit(int x);
2 | extern void exit2(int x);
3 | extern int exit3(int x);
4 |
5 | int main(void)
6 | {
7 | volatile int i = 3;
8 |
9 | switch (i) {
10 | case 1:
11 | exit(11);
12 | case 2:
13 | exit2(12);
14 | case 3:
15 | exit3(13);
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/testsuite/old/051-exit.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | int main()
5 | {
6 | printf("\n");
7 | exit(0);
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/testsuite/old/052-signal.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 | int main(void)
4 | {
5 | signal(8, 1);
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 |
15 | puts("done");
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/testsuite/old/053-signal-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 |
4 | int f(void)
5 | {
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 | signal(8, 1);
15 |
16 | puts("done");
17 | return 0;
18 | }
19 |
20 | int main(void)
21 | {
22 | f();
23 | f();
24 |
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/testsuite/old/054-signal-fcall.c:
--------------------------------------------------------------------------------
1 | #include
2 | extern int signal(int, int);
3 |
4 | void f(void)
5 | {
6 | signal(8, 1);
7 | signal(8, 1);
8 | signal(8, 1);
9 | signal(8, 1);
10 | signal(8, 1);
11 | signal(8, 1);
12 | signal(8, 1);
13 | signal(8, 1);
14 | signal(8, 1);
15 |
16 | puts("done");
17 | }
18 |
19 | int main(void)
20 | {
21 | f();
22 | f();
23 |
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/testsuite/old/055-setjmp-longjmp.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern int __wrap_setjmp(jmp_buf);
5 | extern void __wrap_longjmp(jmp_buf, int);
6 |
7 | int main(void)
8 | {
9 | jmp_buf env;
10 | printf("about to setjmp\n");
11 | fflush(stdout);
12 | printf("fp %p\n", __builtin_frame_address(0));
13 | if (__wrap_setjmp(env)) {
14 | printf("second return\n");
15 | } else {
16 | printf("first return\n");
17 | __wrap_longjmp(env, 1);
18 | printf("notreached\n");
19 | }
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/testsuite/old/056-ldexpf.c:
--------------------------------------------------------------------------------
1 | extern float ldexpf(float, int);
2 |
3 | #include
4 |
5 | int main(void)
6 | {
7 | printf("%f\n", ldexpf(1.0, 6));
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/testsuite/old/057-ffsll.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include