Ignore requests to use backends that aren't available; fixes #5145
authorIan Lynagh <igloo@earth.li>
Sun, 1 May 2011 15:19:06 +0000 (16:19 +0100)
committerIan Lynagh <igloo@earth.li>
Sun, 1 May 2011 15:19:06 +0000 (16:19 +0100)
Now if you try to use "-fasm" with an unreg compiler, for example,
you just get a warning saying it's being ignored.

compiler/main/CodeOutput.lhs
compiler/main/DynFlags.hs

index 7cfc2e9..f5e3394 100644 (file)
@@ -156,8 +156,7 @@ outputAsm dflags filenm flat_absC
                  nativeCodeGen dflags f ncg_uniqs flat_absC
 
  | otherwise
-  = pprPanic "This compiler was built without a native code generator"
-             (text "Use -fvia-C instead")
+  = panic "This compiler was built without a native code generator"
 \end{code}
 
 
index c7e0465..7e15aa4 100644 (file)
@@ -2039,11 +2039,28 @@ setTarget l = upd set
 -- not from bytecode to object-code.  The idea is that -fasm/-fllvm
 -- can be safely used in an OPTIONS_GHC pragma.
 setObjTarget :: HscTarget -> DynP ()
-setObjTarget l = upd set
+setObjTarget l = updM set
   where
-   set dfs
-     | isObjectTarget (hscTarget dfs) = dfs { hscTarget = l }
-     | otherwise = dfs
+   set dflags
+     | isObjectTarget (hscTarget dflags)
+       = case l of
+         HscC
+          | cGhcUnregisterised /= "YES" ->
+             do addWarn ("Compiler not unregisterised, so ignoring " ++
+                         showHscTargetFlag l)
+                return dflags
+         HscAsm
+          | cGhcWithNativeCodeGen /= "YES" ->
+             do addWarn ("Compiler has no native codegen, so ignoring " ++
+                         showHscTargetFlag l)
+                return dflags
+         HscLlvm
+          | cGhcUnregisterised == "YES" ->
+             do addWarn ("Compiler unregisterised, so ignoring " ++
+                         showHscTargetFlag l)
+                return dflags
+         _ -> return $ dflags { hscTarget = l }
+     | otherwise = return dflags
 
 setOptLevel :: Int -> DynFlags -> DynP DynFlags
 setOptLevel n dflags