www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - [[bad mustMatch:]]: error while compiling to wasm

reply =?UTF-8?B?SMO8c2V5aW4gQWtiYcWf?= <huskb.code gmail.com> writes:
Hi I was trying to build wasm code via ldc and binaryen. I saw 
how to do it in a c++ tutorial.

My source code is:

import std.stdio;

extern(C) int main()
{
	writeln("Edit source/app.d to start your project.");
   return 0;
}


I compile with the following:
ldc2 app.d -output-s
s2wasm app.s > app.wast

While compiling to s, everyhing is fine but s2wasm it gives this 
error:
<< set >>
[[bad mustMatch:]]:
==========
_main:
	.cfi_startproc
	pushq	%rbp
Lcfi0:
	.cfi_def_cfa_offs
==========

It is something related to the D structure? How can I fix this?

Thanks
Jul 07 2018
next sibling parent Seb <seb wilzba.ch> writes:
On Saturday, 7 July 2018 at 07:55:59 UTC, Hüseyin Akbaş wrote:
 Hi I was trying to build wasm code via ldc and binaryen. I saw 
 how to do it in a c++ tutorial.

 My source code is:

 import std.stdio;

 extern(C) int main()
 {
 	writeln("Edit source/app.d to start your project.");
   return 0;
 }


 I compile with the following:
 ldc2 app.d -output-s
 s2wasm app.s > app.wast

 While compiling to s, everyhing is fine but s2wasm it gives 
 this error:
 << set >>
 [[bad mustMatch:]]:
 ==========
 _main:
 	.cfi_startproc
 	pushq	%rbp
 Lcfi0:
 	.cfi_def_cfa_offs
 ==========

 It is something related to the D structure? How can I fix this?

 Thanks
Did you try -betterC? IIRC the full druntime doesn't work with wasm yet.
Jul 07 2018
prev sibling parent reply kinke <noone nowhere.com> writes:
On Saturday, 7 July 2018 at 07:55:59 UTC, Hüseyin Akbaş wrote:
 Hi I was trying to build wasm code via ldc and binaryen. I saw 
 how to do it in a c++ tutorial.

 My source code is:

 import std.stdio;

 extern(C) int main()
 {
 	writeln("Edit source/app.d to start your project.");
   return 0;
 }


 I compile with the following:
 ldc2 app.d -output-s
 s2wasm app.s > app.wast
LDC will soon be able to compile & link some trivial D code directly to WebAssembly, without any external tools. Don't expect a seamingly simple `writeln()` to work soon though [you don't even have access to the console in WebAssembly and must interop with a JavaScript function to do so AFAIK]. See https://github.com/ldc-developers/ldc/pull/2766#issuecomment-403222908 for how to get started.
Jul 07 2018
parent reply =?UTF-8?B?SMO8c2V5aW4gQWtiYcWf?= <huskb.code gmail.com> writes:
On Saturday, 7 July 2018 at 18:01:46 UTC, kinke wrote:
 On Saturday, 7 July 2018 at 07:55:59 UTC, Hüseyin Akbaş wrote:
 Hi I was trying to build wasm code via ldc and binaryen. I saw 
 how to do it in a c++ tutorial.

 My source code is:

 import std.stdio;

 extern(C) int main()
 {
 	writeln("Edit source/app.d to start your project.");
   return 0;
 }


 I compile with the following:
 ldc2 app.d -output-s
 s2wasm app.s > app.wast
LDC will soon be able to compile & link some trivial D code directly to WebAssembly, without any external tools. Don't expect a seamingly simple `writeln()` to work soon though [you don't even have access to the console in WebAssembly and must interop with a JavaScript function to do so AFAIK]. See https://github.com/ldc-developers/ldc/pull/2766#issuecomment-403222908 for how to get started.
Some guy has created a toolchain like emscripten in order to compile a few libraries for webasm with the D code. However, I couldn't make it work. Here is the link: https://github.com/CyberShadow/dscripten-tools What do you think? Is it useful?
Jul 08 2018
parent kinke <noone nowhere.com> writes:
On Sunday, 8 July 2018 at 09:01:09 UTC, Hüseyin Akbaş wrote:
 Some guy has created a toolchain like emscripten in order to 
 compile a few libraries for webasm  with the D code. However, I 
 couldn't make it work. Here is the link: 
 https://github.com/CyberShadow/dscripten-tools What do you 
 think? Is it useful?
I had a quick look. dscripten compiles to asm.js, a JavaScript subset auto-generated from code in statically typed languages and which most modern JS engines are supposed to generate efficient code for. 'Compiling' to JavaScript isn't supported by official LLVM and seems to require changes to LLVM itself, not just an additional LLVM target, hence it isn't supported by LDC either, and that why there's the dscripten fork using emscripten's LLVM. WebAssembly is an official LLVM target and AFAICT supposed to replace the ugly and inefficient asm.js layer (that's still source code after all, human-readable for masochists). The first version apparently doesn't give you access to the JS garbage collector or the DOM though. Even passing strings between JS and WebAssembly seems to be a PITA (never seen that much code needed to print a 'hello world' to a console [1]). DOM and GC access is planned for WebAssembly v2 AFAIK, and only then things start getting interesting IMO, allowing for front-ends fully written in D or interoperating with other JS/WebAssembly libs. [1] https://medium.com/ mbebenita/hello-world-in-webassembly-83951757775
Jul 09 2018