
Hello, I would like to use nativeCodeGen outside of GHC to generate code from an IR. The IR would be produced by a third party program, not the GHC frontend. Looking at CVS HEAD I can see that GHC.hs exports plenty of things (for the GHC API I presume), but I can't find anything that lets me input some sort of IR and have ASM in return. Am I missing it somewhere or is there no way to input IR and get ASM in return? If there isn't, is such a feature planned/wanted? If such a feature isn't planned, I would appreciate any ideas on how to to accomplish the same thing. I have no problems with having a build tree of GHC laying around if that makes things easier. It would be a nice bonus if it made my maintenance burden low. / Peter

pj:
Hello,
I would like to use nativeCodeGen outside of GHC to generate code from an IR. The IR would be produced by a third party program, not the GHC frontend.
Looking at CVS HEAD I can see that GHC.hs exports plenty of things (for the GHC API I presume), but I can't find anything that lets me input some sort of IR and have ASM in return. Am I missing it somewhere or is there no way to input IR and get ASM in return? If there isn't, is such a feature planned/wanted?
If such a feature isn't planned, I would appreciate any ideas on how to to accomplish the same thing. I have no problems with having a build tree of GHC laying around if that makes things easier. It would be a nice bonus if it made my maintenance burden low.
You could use External Core with GHC, couldn't you?

dons:
pj:
Hello,
I would like to use nativeCodeGen outside of GHC to generate code from an IR. The IR would be produced by a third party program, not the GHC frontend.
Looking at CVS HEAD I can see that GHC.hs exports plenty of things (for the GHC API I presume), but I can't find anything that lets me input some sort of IR and have ASM in return. Am I missing it somewhere or is there no way to input IR and get ASM in return? If there isn't, is such a feature planned/wanted?
If such a feature isn't planned, I would appreciate any ideas on how to to accomplish the same thing. I have no problems with having a build tree of GHC laying around if that makes things easier. It would be a nice bonus if it made my maintenance burden low.
You could use External Core with GHC, couldn't you?
For example: Your src: $ cat M.hs module M where f = "foo" Compile to Core: $ ghc -fno-code -fext-core M.hs Now edit M.hcr. And compile that to assembly: $ ghc -fasm -c -keep-tmp-files M.hcr And inspect your piping-hot asm ... $ cat ghc17508.s .data .align 4 _module_registered: .long 0 .text .align 4,0x90 .globl __stginit_M_ __stginit_M_: cmpl $0,_module_registered jne .Lc5Y .Lc5Z: movl $1,_module_registered .Lc5Y: addl $4,%ebp jmp *-4(%ebp) .text .align 4,0x90 .globl __stginit_M __stginit_M: jmp __stginit_M_ -- Don

dons@cse.unsw.edu.au (Donald Bruce Stewart) writes:
pj:
I would like to use nativeCodeGen outside of GHC to generate code from an IR. The IR would be produced by a third party program, not the GHC frontend.
Looking at CVS HEAD I can see that GHC.hs exports plenty of things (for the GHC API I presume), but I can't find anything that lets me input some sort of IR and have ASM in return. Am I missing it somewhere or is there no way to input IR and get ASM in return? If there isn't, is such a feature planned/wanted?
If such a feature isn't planned, I would appreciate any ideas on how to to accomplish the same thing. I have no problems with having a build tree of GHC laying around if that makes things easier. It would be a nice bonus if it made my maintenance burden low.
You could use External Core with GHC, couldn't you?
Thanks for the quick answer! Maybe it's my lack of understanding of the inner workings of GHC but reading "An External Representation for the GHC Core Language" I get the impression that the dumping of Core Language is basically targeted at researchers writing their own optimization passes or backends for Haskell/GHC so they can use the existing infrastructure of GHC. My request is the other way around - I want to throw out the frontend but use* ("low-level") parts of the backend of GHC. The Core Language seems to be translated into STG-machine code, which according to my understanding is an abstract machine desinged to support non-strict higher-order functional languages. I was hoping that the laziness was in the STG-syntax, not in Cmm. Looking at output of -ddump-cmm it resembles C-- quite closely (also implied by comments in PprCmm.hs), which makes me believe that is the "correct" level of abstraction for me. *) The reasons are two-fold, one is that it is written in Haskell, the other is that it generates code for more than one architecture today. / Peter
participants (2)
-
dons@cse.unsw.edu.au
-
Peter A Jonsson