emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.59k stars 3.28k forks source link

code generation issue? #855

Closed iansmith closed 5 years ago

iansmith commented 11 years ago

After running emcc I got this line in my resulting a.out.js

var $9$0={_i8bitcast$0___llgo_type_float64_toi8i8null}$0;

Here is the traceback, although it's not surprising:

/Users/iansmith/oder/emscripten/a.out.js:1381 var $9$0={_i8bitcast$0___llgo_type_float64_toi8i8null}$0; ^ SyntaxError: Unexpected token } at Module._compile (module.js:437:25) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I can give you the source code but I don't know how to attach it here. The input file was a tiny bit of portable byte code (.bc file) for llvm:

file ../samples/ex1.bc ../samples/ex1.bc: LLVM bit-code object x86_64

The human readable version (courtesy of llgo) is at the end of this report.

Happy to help any way I can, ian

; ModuleID = 'main' target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-darwin"

%0 = type { i8, i8 } %1 = type { %0, i32, i32 } %2 = type { i8, i8, { i8, i32 } (i8) }

@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00" @__llgo.type.float64 = common global %0 zeroinitializer

define void @main.main() { entry: %x = alloca double store double 3.000000e+00, double* %x %y = alloca double store double 4.000000e+00, double* %y %0 = load double* %x %1 = call double @math.Pow(double %0, double 2.000000e+00) %2 = load double* %y %3 = call double @math.Pow(double %2, double 2.000000e+00) %4 = fadd double %1, %3 %5 = call double @math.Sqrt(double %4) %z = alloca double store double %5, double* %z %6 = load double* %z %7 = bitcast double %6 to i64 %8 = inttoptr i64 %7 to i8 %9 = insertvalue %0 { i8* bitcast (%0* @_llgo.type.float64 to i8), i8_ null }, i8* %8, 1 %10 = call i64 @runtime.malloc(i64 mul nuw (i64 ptrtoint (i1* getelementptr (i1* null, i32 1) to i64), i64 2)) %11 = inttoptr i64 %10 to %0 %12 = getelementptr %0* %11, i32 0 store %0 %9, %0* %12 %13 = insertvalue %1 undef, %0* %11, 0 %14 = insertvalue %1 %13, i32 1, 1 %15 = insertvalue %1 %14, i32 1, 2 %16 = call { i32, %2 } @fmt.Printf({ i8, i32 } { i8 getelementptr inbounds ([4 x i8]* @0, i32 0, i32 0), i32 3 }, %1 %15) ret void }

declare double @math.Sqrt(double)

declare double @math.Pow(double, double)

declare { i32, %2 } @fmt.Printf({ i8*, i32 }, %1)

declare i64 @runtime.malloc(i64)

declare i32 @runtime.main(i32, i8, i8, void ()*)

define i32 @main(i32, i8, i8) { entry: %3 = call i32 @runtime.main(i32 %0, i8* %1, i8* %2, void ()* @main.main) ret i32 %3 }

kripken commented 11 years ago

I guess this was generated by llgo? I'm concerned about it being portable enough. It is marked 64-bit, which is not good for emscripten, and the platform is darwin (emscripten standardized on linux on all platforms).

Aside from that, looks like we need to handle nested function calls in insertvalue. That's a rare instruction for clang to emit so we probably never noticed this issue because of that. But before looking into that, let's make sure we can even compile at all - can llgo be told to emit 32-bit code?

iansmith commented 11 years ago

Ok, I'm going to try to get llgo (yes, that's the source) to generate 32 bit code and maybe I can convince it to emit code for linux as well. I'll advise sometime tomorrow west-coast time about this.

Thanks for your prompt response! ian

tobia commented 10 years ago

@iansmith did you ever manage to get llgo and Emscripten to generate working js code?

iansmith commented 10 years ago

No, I switched to gopherjs. I'd be happy to try it again if folks feel that this should work. Also, llgo might be another way to get the bit code representation, then switch to emscripten for bit code->asm.js.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.