Opened 3 years ago

Last modified 25 hours ago

#10869 patch feature request

Option to dump preprocessed source

Reported by: phischu Owned by: RolandSenn
Priority: low Milestone:
Component: Driver Version: 7.10.2
Keywords: easy Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab: D4861
Wiki Page:


It would be awesome if GHC had an option -ddump-preprocessed that dumps the source code for each module after preprocessing. I am not sure what the current definition of "preprocessing" is but I mean the output of at least the following tools: happy, alex, c2hs, hsc2hs and cpp. Additionally even if a module was not subject to any preprocessing it should be dumped anyway.

Use case: I want to parse module files from packages from hackage with haskell-src-exts but find it prohibitively difficult to get the preprocessing right. The idea is that after cabal install with ghc options -ddump-preprocessed -ddump-to-file -dumpdir real_modules you get a complete working set of haskell modules that can be parsed directly without any preprocessing in folder real_modules.

Change History (10)

comment:1 Changed 3 years ago by ezyang

Keywords: easy added

comment:2 Changed 3 years ago by mpickering

I'm fairly sure there is already this option? Maybe it's -E..

comment:3 in reply to:  2 Changed 3 years ago by thomie

Resolution: invalid
Status: newclosed

Replying to mpickering:

I'm fairly sure there is already this option? Maybe it's -E..

Exactly, see:

The option -E runs just the pre-processing passes of the compiler, dumping the result in a file.

GHC doesn't run happy, alex, c2hs or hsc2hs for you, so I don't think there's anything to do here.

comment:4 Changed 3 years ago by thomie

Or maybe you want --make and -E to work together?

comment:5 Changed 3 years ago by phischu

I am sorry that the request was not clear. -E stops ghc after preprocessing. But I want ghc to work normally but in addition dump the preprocessed source files. So, yes, I kinda want --make and -E to work together.

comment:6 Changed 3 years ago by thomie

Resolution: invalid
Status: closednew

comment:7 Changed 4 weeks ago by RolandSenn

Owner: set to RolandSenn

I'll try to implement this:

  • A new compiler flag --ddump-preprocessed will be defined and documented.
  • With the new flag set, GHC will generate the <module>.hspp file with the same content as the one created with the GHC option -E.
  • Opposite to the -E processing, GHC will not stop, but continue its processing normally.
  • If you specify both -E and --ddump-preprocessed, there will be the same processing as with only the GHC option -E: GHC will stop after producing the <module>.hspp file. No error/warning message will be issued.
  • A test case will be added.

As usual, if you disagree, please do holler...

comment:8 Changed 2 weeks ago by RolandSenn

After looking into the code, I decided the following: The requested functionality is not a dump operation. In a dump operation we have information in memory and write (dump) it out to sysout, syserror or to a file. Here, however, we have the information already in a file and we want to keep the file after GHC processing ends. Hence, this is a keep operation, and the flag will be called keep-hspp-file.

comment:9 Changed 2 days ago by RolandSenn

Status: newpatch

comment:10 Changed 25 hours ago by RolandSenn

Differential Rev(s): Phab: D4861
Note: See TracTickets for help on using tickets.