Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
161a6d3f
Commit
161a6d3f
authored
24 years ago
by
Simon Marlow
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 2000-08-04 09:45:20 by simonmar]
Another attempt at getting the pipeline stuff right. Fixed at least one bug.
parent
fc39db6c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/driver/Main.hs
+58
-49
58 additions, 49 deletions
ghc/driver/Main.hs
with
58 additions
and
49 deletions
ghc/driver/Main.hs
+
58
−
49
View file @
161a6d3f
{-# OPTIONS -W #-}
{-# OPTIONS -W #-}
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- $Id: Main.hs,v 1.4
8
2000/08/04 09:
02:56
simonmar Exp $
-- $Id: Main.hs,v 1.4
9
2000/08/04 09:
45:20
simonmar Exp $
--
--
-- GHC Driver program
-- GHC Driver program
--
--
...
@@ -267,30 +267,6 @@ cleanTempFiles = do
...
@@ -267,30 +267,6 @@ cleanTempFiles = do
(
"warning: can't remove tmp file"
++
f
)))
(
"warning: can't remove tmp file"
++
f
)))
mapM_
blowAway
fs
mapM_
blowAway
fs
-----------------------------------------------------------------------------
-- Which phase to stop at
endPhaseFlag
::
String
->
Maybe
Phase
endPhaseFlag
"-M"
=
Just
MkDependHS
endPhaseFlag
"-E"
=
Just
Cpp
endPhaseFlag
"-C"
=
Just
Hsc
endPhaseFlag
"-S"
=
Just
Mangle
endPhaseFlag
"-c"
=
Just
As
endPhaseFlag
_
=
Nothing
getStopAfter
::
[
String
]
->
IO
(
[
String
]
-- rest of command line
,
Phase
-- stop after phase
,
String
-- "stop after" flag
,
Bool
-- do linking?
)
getStopAfter
flags
=
case
my_partition
endPhaseFlag
flags
of
(
[]
,
rest
)
->
return
(
rest
,
Ln
,
""
,
True
)
-- default is to do linking
([(
flag
,
one
)],
rest
)
->
return
(
rest
,
one
,
flag
,
False
)
(
_
,
_
)
->
throwDyn
(
OtherError
"only one of the flags -M, -E, -C, -S, -c is allowed"
)
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- Global compilation flags
-- Global compilation flags
...
@@ -716,7 +692,7 @@ getPackageImportPath = do
...
@@ -716,7 +692,7 @@ getPackageImportPath = do
getPackageIncludePath
::
IO
[
String
]
getPackageIncludePath
::
IO
[
String
]
getPackageIncludePath
=
do
getPackageIncludePath
=
do
ps
<-
readIORef
packages
ps
<-
readIORef
packages
ps'
<-
getPackageDetails
ps
ps'
<-
getPackageDetails
ps
return
(
nub
(
filter
(
not
.
null
)
(
concatMap
include_dirs
ps'
)))
return
(
nub
(
filter
(
not
.
null
)
(
concatMap
include_dirs
ps'
)))
...
@@ -1152,7 +1128,7 @@ main =
...
@@ -1152,7 +1128,7 @@ main =
writeIORef
package_details
(
read
contents
)
writeIORef
package_details
(
read
contents
)
-- find the phase to stop after (i.e. -E, -C, -c, -S flags)
-- find the phase to stop after (i.e. -E, -C, -c, -S flags)
(
flags2
,
s
to
p_phase
,
stop_flag
,
do_linking
)
<-
getStopAfter
argv'
(
flags2
,
to
do
,
stop_flag
)
<-
getToDo
argv'
-- process all the other arguments, and get the source files
-- process all the other arguments, and get the source files
srcs
<-
processArgs
driver_opts
flags2
[]
srcs
<-
processArgs
driver_opts
flags2
[]
...
@@ -1167,14 +1143,14 @@ main =
...
@@ -1167,14 +1143,14 @@ main =
when
verb
(
hPutStrLn
stderr
(
"Using package config file: "
++
conf_file
))
when
verb
(
hPutStrLn
stderr
(
"Using package config file: "
++
conf_file
))
-- mkdependHS is special
-- mkdependHS is special
when
(
s
to
p_phase
==
MkDependHS
)
beginMkDependHS
when
(
to
do
==
Do
MkDependHS
)
beginMkDependHS
-- for each source file, find which phases to run
-- for each source file, find which phases to run
pipelines
<-
mapM
(
genPipeline
s
to
p_phase
stop_flag
)
srcs
pipelines
<-
mapM
(
genPipeline
to
do
stop_flag
)
srcs
let
src_pipelines
=
zip
srcs
pipelines
let
src_pipelines
=
zip
srcs
pipelines
o_file
<-
readIORef
output_file
o_file
<-
readIORef
output_file
if
isJust
o_file
&&
not
do_linking
&&
length
srcs
>
1
if
isJust
o_file
&&
todo
/=
DoLink
&&
length
srcs
>
1
then
throwDyn
(
UsageError
"can't apply -o option to multiple source files"
)
then
throwDyn
(
UsageError
"can't apply -o option to multiple source files"
)
else
do
else
do
...
@@ -1186,16 +1162,43 @@ main =
...
@@ -1186,16 +1162,43 @@ main =
saved_driver_state
<-
readIORef
driver_state
saved_driver_state
<-
readIORef
driver_state
let
compileFile
(
src
,
phases
)
=
do
let
compileFile
(
src
,
phases
)
=
do
r
<-
run_pipeline
phases
src
do_linking
True
orig_base
orig_suff
r
<-
run_pipeline
phases
src
(
todo
==
DoLink
)
True
orig_base
orig_suff
writeIORef
driver_state
saved_driver_state
writeIORef
driver_state
saved_driver_state
return
r
return
r
where
(
orig_base
,
orig_suff
)
=
splitFilename
src
where
(
orig_base
,
orig_suff
)
=
splitFilename
src
o_files
<-
mapM
compileFile
src_pipelines
o_files
<-
mapM
compileFile
src_pipelines
when
(
stop_phase
==
MkDependHS
)
endMkDependHS
when
(
todo
==
DoMkDependHS
)
endMkDependHS
when
(
todo
==
DoLink
)
(
do_link
o_files
)
when
do_linking
(
do_link
o_files
)
-----------------------------------------------------------------------------
-- Which phase to stop at
data
ToDo
=
DoMkDependHS
|
DoMkDLL
|
StopBefore
Phase
|
DoLink
deriving
(
Eq
)
todoFlag
::
String
->
Maybe
ToDo
todoFlag
"-M"
=
Just
$
DoMkDependHS
todoFlag
"-E"
=
Just
$
StopBefore
Hsc
todoFlag
"-C"
=
Just
$
StopBefore
HCc
todoFlag
"-S"
=
Just
$
StopBefore
As
todoFlag
"-c"
=
Just
$
StopBefore
Ln
todoFlag
_
=
Nothing
getToDo
::
[
String
]
->
IO
(
[
String
]
-- rest of command line
,
ToDo
-- phase to stop at
,
String
-- "stop at" flag
)
getToDo
flags
=
case
my_partition
todoFlag
flags
of
(
[]
,
rest
)
->
return
(
rest
,
DoLink
,
""
)
-- default is to do linking
([(
flag
,
one
)],
rest
)
->
return
(
rest
,
one
,
flag
)
(
_
,
_
)
->
throwDyn
(
OtherError
"only one of the flags -M, -E, -C, -S, -c is allowed"
)
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- genPipeline
-- genPipeline
...
@@ -1242,7 +1245,7 @@ startPhase "o" = Ln
...
@@ -1242,7 +1245,7 @@ startPhase "o" = Ln
startPhase
_
=
Ln
-- all unknown file types
startPhase
_
=
Ln
-- all unknown file types
genPipeline
genPipeline
::
Phase
-- stop after this phase
::
ToDo
-- when to stop
->
String
-- "stop after" flag (for error messages)
->
String
-- "stop after" flag (for error messages)
->
String
-- original filename
->
String
-- original filename
->
IO
[
-- list of phases to run for this file
->
IO
[
-- list of phases to run for this file
...
@@ -1251,7 +1254,7 @@ genPipeline
...
@@ -1251,7 +1254,7 @@ genPipeline
String
)
-- output file suffix
String
)
-- output file suffix
]
]
genPipeline
s
to
p_after
stop_after
_flag
filename
genPipeline
to
do
stop
_flag
filename
=
do
=
do
split
<-
readIORef
split_object_files
split
<-
readIORef
split_object_files
mangle
<-
readIORef
do_asm_mangling
mangle
<-
readIORef
do_asm_mangling
...
@@ -1274,7 +1277,7 @@ genPipeline stop_after stop_after_flag filename
...
@@ -1274,7 +1277,7 @@ genPipeline stop_after stop_after_flag filename
|
otherwise
=
lang
|
otherwise
=
lang
pipeline
pipeline
|
s
to
p_after
==
MkDependHS
=
[
Unlit
,
Cpp
,
MkDependHS
]
|
to
do
==
Do
MkDependHS
=
[
Unlit
,
Cpp
,
MkDependHS
]
|
haskell_ish_file
=
|
haskell_ish_file
=
case
real_lang
of
case
real_lang
of
...
@@ -1304,19 +1307,23 @@ genPipeline stop_after stop_after_flag filename
...
@@ -1304,19 +1307,23 @@ genPipeline stop_after stop_after_flag filename
++
filename
))
++
filename
))
else
do
else
do
-- this might happen, eg. ghc -S Foo.o
-- if we can't find the phase we're supposed to stop before,
if
stop_after
/=
Ln
&&
stop_after
`
notElem
`
pipeline
-- something has gone wrong.
&&
(
stop_after
/=
As
||
SplitAs
`
notElem
`
pipeline
)
case
todo
of
then
throwDyn
(
OtherError
(
"flag "
++
stop_after_flag
StopBefore
phase
->
++
" is incompatible with source file `"
when
(
phase
/=
Ln
++
filename
++
"'"
))
&&
phase
`
notElem
`
pipeline
else
do
&&
not
(
phase
==
As
&&
SplitAs
`
elem
`
pipeline
))
$
throwDyn
(
OtherError
(
"flag "
++
stop_flag
++
" is incompatible with source file `"
++
filename
++
"'"
))
_
->
return
()
let
let
----------- ----- ---- --- -- -- - - -
----------- ----- ---- --- -- -- - - -
annotatePipeline
annotatePipeline
::
[
Phase
]
->
Phase
::
[
Phase
]
-- raw pipeline
->
Phase
-- phase to stop before
->
[(
Phase
,
IntermediateFileType
,
String
{-file extension-}
)]
->
[(
Phase
,
IntermediateFileType
,
String
{-file extension-}
)]
annotatePipeline
[]
_
=
[]
annotatePipeline
[]
_
=
[]
annotatePipeline
(
Ln
:
_
)
_
=
[]
annotatePipeline
(
Ln
:
_
)
_
=
[]
...
@@ -1325,7 +1332,7 @@ genPipeline stop_after stop_after_flag filename
...
@@ -1325,7 +1332,7 @@ genPipeline stop_after stop_after_flag filename
:
annotatePipeline
(
next_phase
:
ps
)
stop
:
annotatePipeline
(
next_phase
:
ps
)
stop
where
where
keep_this_output
keep_this_output
|
phase
==
stop
=
Persistent
|
next_
phase
==
stop
=
Persistent
|
otherwise
=
|
otherwise
=
case
next_phase
of
case
next_phase
of
Ln
->
Persistent
Ln
->
Persistent
...
@@ -1338,14 +1345,16 @@ genPipeline stop_after stop_after_flag filename
...
@@ -1338,14 +1345,16 @@ genPipeline stop_after stop_after_flag filename
-- the suffix on an output file is determined by the next phase
-- the suffix on an output file is determined by the next phase
-- in the pipeline, so we add linking to the end of the pipeline
-- in the pipeline, so we add linking to the end of the pipeline
-- to force the output from the final phase to be a .o file.
-- to force the output from the final phase to be a .o file.
annotated_pipeline
=
annotatePipeline
(
pipeline
++
[
Ln
])
stop_after
stop_phase
=
case
todo
of
StopBefore
phase
->
phase
DoLink
->
Ln
annotated_pipeline
=
annotatePipeline
(
pipeline
++
[
Ln
])
stop_phase
phase_ne
p
(
p1
,
_
,
_
)
=
(
p1
/=
p
)
phase_ne
p
(
p1
,
_
,
_
)
=
(
p1
/=
p
)
----------- ----- ---- --- -- -- - - -
----------- ----- ---- --- -- -- - - -
return
$
return
$
dropWhile
(
phase_ne
start_phase
)
.
dropWhile
(
phase_ne
start_phase
)
.
foldr
(
\
p
ps
->
if
phase_ne
stop_
after
p
then
p
:
ps
else
[
p
])
[]
foldr
(
\
p
ps
->
if
phase_ne
stop_
phase
p
then
p
:
ps
else
[]
)
[]
$
annotated_pipeline
$
annotated_pipeline
...
@@ -1785,7 +1794,7 @@ run_phase Hsc basename _suff input_fn output_fn
...
@@ -1785,7 +1794,7 @@ run_phase Hsc basename _suff input_fn output_fn
])
])
-- compile the _stub.c file w/ gcc
-- compile the _stub.c file w/ gcc
pipeline
<-
genPipeline
As
""
stub_c
pipeline
<-
genPipeline
(
StopBefore
Ln
)
""
stub_c
run_pipeline
pipeline
stub_c
False
{-no linking-}
run_pipeline
pipeline
stub_c
False
{-no linking-}
False
{-no -o option-}
False
{-no -o option-}
(
basename
++
"_stub"
)
"c"
(
basename
++
"_stub"
)
"c"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment