arnetheduck / nlvm

LLVM-based compiler for the Nim language
Other
712 stars 41 forks source link

WebAssembly target compilation error #9

Closed darkmusic closed 5 years ago

darkmusic commented 6 years ago

Hi,

While attempting to compile an example Nim script using NLVM with the wasm32 target, I received the error "Several-byte opcodes not supported yet".

nlvm commit: e91863c92f9e1f171e7896d8b55b4f62e5b38808

Nim commit: https://github.com/nim-lang/Nim/commit/fedd695d76e621bfbbaca4bbc8f66996a0a732a4

System: Linux x86_64

[thomas@callisto examples]$ cat hallo.nim
# Hello world program

echo "Hello World"
[thomas@callisto examples]$ ../../nlvm/nlvm c --nlvm.target=wasm32 hallo.nim
Hint: used config file '/home/thomas/code/nlvm/Nim/config/nim.cfg' [Conf]
nlvm: ../lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp:67: virtual void {anonymous}::WebAssemblyMCCodeEmitter::encodeInstruction(const llvm::MCInst&, llvm::raw_ostream&, llvm::SmallVectorImpl<llvm::MCFixup>&, const llvm::MCSubtargetInfo&) const: Assertion `Binary <= UINT16_MAX && "Several-byte opcodes not supported yet"' failed.
Traceback (most recent call last)
nlvm.nim(161)            nlvm
nlvm.nim(150)            handleCmdLine
nlvm.nim(77)             mainCommand
nlvm.nim(52)             commandLL
modules.nim(126)         compileProject
modules.nim(71)          compileModule
passes.nim(197)          processModule
passes.nim(95)           closePasses
llgen.nim(5857)          myClose
llgen.nim(5785)          writeOutput
SIGABRT: Abnormal termination.

For the relevant location in the LLVM code, see: https://github.com/llvm-mirror/llvm/blob/57aa4fc38b0878c6328ab565a128bb79805e29bd/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp#L69

I understand this may just be an LLVM WebAssembly implementation issue and have nothing to do with NLVM, but thought it might be of interest here.

arnetheduck commented 5 years ago

yeah, I've seen this before, but not sure what's causing it.. gonna try to update to llvm 7 and see if it's still there.. next step is actually fixing nlvm so it supports 32-bit targets - right now, int in nlvm is fixed to 64 bits which is wrong, and could be related to this

arnetheduck commented 5 years ago

fixed - related to that wasm32 is 32-bits and nlvm was using 64-bit types too freely