Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HaskellでLLVM Frontend

yagi
May 11, 2014

HaskellでLLVM Frontend

parsecサイコー。llvm-general難しい

yagi

May 11, 2014
Tweet

More Decks by yagi

Other Decks in Technology

Transcript

  1. ΍ͬͨࣄ • ʮ48࣌ؒͰSchemeΛॻ͜͏ʯͰSchemeͷΠϯλϓϦ λΛREPLลΓ·Ͱ࣮૷ • Implementing a JIT Compiled Language

    with Haskell and LLVMͰṖݴޠΛLLVM IRʹίϯύΠϧ͢ΔౕΛ৮Δ • SchemeΛίϯύΠϧͯ͠LLVM IRʹు͘Α͏ʹͨ͠(ͱ ͍ͬͯ΋਺஋ܭࢉ෦෼ͷΈ) • LLVM IRΛemscriptenͰjsʹ͢Δ http://ja.wikibooks.org/wiki/48%E6%99%82%E9%96%93%E3%81%A7Scheme%E3%82%92%E6%9B%B8%E3%81%93%E3%81%86 http://www.stephendiehl.com/llvm/
  2. Environment • Mac Book Pro OSX 10.9.2 • GHC 7.6.3

    • Cabal 1.20.0.1 • Sublime Text 2
  3. Parsec • ੜ࢈ੑ͕ߴ͘ϞφσΟοΫͳύʔαίϯϏωʔλɻ ඪ४ϥΠϒϥϦɻBNFΆ͍هड़Ͱॻ͚Δ • <|> : ࣈ۟ղੳΛ͢ΔύʔαΛͭͳ͛Δ ex: var

    | val • many : ࢦఆͨ͠ύλʔϯʹ0ճҎ্Ϛον͢Δɻ ex:{ args } • many1 : ࢦఆͨ͠ύλʔϯʹ1ճҎ্Ϛον͢Δ ex:{ Uppercase }+ • optional : ࢦఆͨ͠ύλʔϯ͕1ճ͋ͬͯ΋ͳͯ͘΋Մ ex: [ args ] • try : ࢦఆͨ͠ύλʔϯʹϚον͠ͳ͍৔߹όοϑΝΛר͖໭ͯ࣍͠ͷύλʔϯ ͷϚονΛࢼΈΔ
  4. LLVM • http://www.stephendiehl.com/llvm/ Λࢀߟʹɻ • LLVM3.4ΛίϯύΠϧͯ͠Πϯετʔϧ • llvm-general, llvm-general-pureͱ͍͏packageΛ࢖͏ •

    ࡞ͬͨASTΛḷͬͯLLVM IRΛు͔ͤΔ • emscriptenΛΠϯετʔϧɺemscriptenଆ͸fastcomp ͱ͍͏LLVM࣮૷Λ࢖͏
  5. શମ૾ Main.hs Syntax.hs Lexer.hs Codegen.hs Emit.hs source file(scheme) input AST

    LLVM Assembly ࠓճ࡞ͬͨൣғ llvm-ac emcc LLVM Bitcode hoge.js