| | 107 | |
| | 108 | All backends are given the final Cmm programs in the form of the `RawCmm` datatype. |
| | 109 | |
| | 110 | Possible interface: extend `Plugin` with a new constructor, which can have a Cmm backend (TODO: should `DynFlags` argument to plugin be replaced with type `[CommandLineOption]` that is already in use?) |
| | 111 | |
| | 112 | {{{ |
| | 113 | type CmmBackendPlugin = Maybe (String,(DynFlags -> FilePath -> [RawCmm] -> IO ())) |
| | 114 | |
| | 115 | data Plugin = Plugin { |
| | 116 | ... |
| | 117 | installCmmBackend :: CmmBackendPlugin |
| | 118 | ... |
| | 119 | } |
| | 120 | |
| | 121 | defaultPlugin = Plugin { |
| | 122 | ... |
| | 123 | installCmmBackend = Nothing |
| | 124 | } |
| | 125 | |
| | 126 | }}} |
| | 127 | |
| | 128 | Then, to use: |
| | 129 | |
| | 130 | {{{ |
| | 131 | module Some.Cmm.Plugin (plugin) where |
| | 132 | import GHCPlugins |
| | 133 | |
| | 134 | plugin :: Plugin |
| | 135 | plugin = defaultPlugin { |
| | 136 | installCmmBackend = Just ("Wharble code generator backend", backend) |
| | 137 | } |
| | 138 | |
| | 139 | backend :: DynFlags -> FilePath -> [RawCmm] -> IO () |
| | 140 | backend dflags filenm flat_absC = do |
| | 141 | ... |
| | 142 | }}} |
| | 143 | |
| | 144 | Modifications to compiler pipeline: |
| | 145 | |
| | 146 | * Dynamic code loading can be provided by the same code that works for Core plugins, so this is DONE |
| | 147 | * Extending `HscTarget` to recognize the new compilation output case |
| | 148 | * Might not be necessary. We can load plugins whenever, and scrutinize the 'installCmmField' to see if there is `Nothing` and if there is, |
| | 149 | invoke the normal pipeline, otherwise call our own backend and exit. |
| | 150 | * Modify `compiler/main/CodeOutput.lhs` to invoke the plugin callback. |
| | 151 | * Plugin-based backends should automatically prioritize over built-in backends? |