如何以人类可读的形式转储GHC简化输出? [英] How to dump GHC simplifier output in human-readable form?

查看:141
本文介绍了如何以人类可读的形式转储GHC简化输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下程序:

  Succ Peano派生(显示)

add零b = b
add(Succ a)b = add a(Succ b)

mul Zero b = Zero
mul(Succ a)b = add b(mul ab)

four x = let two = Succ(Succ Zero)in mul two two



我想从GHC获得类似的结果:

  add = 
\ ds b - >
case ds of
Zero - >
b
Succ a - >
add
a
(Succ b)

mul =
\ ds b - >
case ds of
Zero - >
Zero
Succ a - >
add
b
(mul ab)

four =
let
two =
Succ

in
mul two two

/ p>

  ghci -ddump-simpl -dsuppress-module-prefixes -dsuppress- uniques foo.hs 

但是它的钢需要大量手动删除GHC生成的东西来获取上面的代码。是否有GHC或第三方脚本的清除切换?



有一种方法至少摆脱 case {tick (main:Main,8)} @(State#RealWorld)of _ {__DEFAULT - >

解决方案>

你很幸运!有一个工作: ghc-core



ghc-core使用命令行包装器覆盖ghc,在寻呼机中以可读,可变颜色的方式显示GHC的优化核心和程序集输出。



只需用 ghc-core 替换 ghc

  ghc-core A.hs 

ghc-core -fvia-C -optc-O3 A.hs


I have the following program:

data Peano = Zero | Succ Peano deriving (Show)

add Zero     b = b
add (Succ a) b = add a (Succ b)

mul Zero     b = Zero
mul (Succ a) b = add b (mul a b)

four x = let two = Succ (Succ Zero) in mul two two

I want to get something like this from GHC:

add =
  \ ds b ->
    case ds of
      Zero ->
        b
      Succ a ->
        add
          a
          (Succ b)

mul =
  \ ds b ->
    case ds of 
      Zero ->
        Zero
      Succ a ->
        add
          b
          (mul a b)

four =
    let
      two =
        Succ
           (Succ Zero)
    in
    mul two two

The best I managed to get is

ghci -ddump-simpl -dsuppress-module-prefixes -dsuppress-uniques foo.hs

but it steel required a lot of manual removal of GHC generated stuff to get the code above. Is there a switch for GHC or a third party script that does the cleanup?

Is there a way at least to get rid of case {tick (main:Main, 8)} @ (State# RealWorld) of _ { __DEFAULT ->?

解决方案

You're in luck! There is a tool for the job: ghc-core.

ghc-core wraps ghc with a command line wrapper that displays GHC's optimised core and assembly output in a human readable, colourised manner, in a pager.

Usage - just replace ghc with ghc-core:

   ghc-core A.hs  

   ghc-core -fvia-C -optc-O3 A.hs

这篇关于如何以人类可读的形式转储GHC简化输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆