⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acd.1

📁 操作系统设计与实现源码
💻 1
📖 第 1 页 / 共 2 页
字号:
          shared description file with a different initialization.  Note  that
          descr is only evaluated the first time the include is called.  After
          that the include has been replaced with  the  included  program,  so
          changing its argument won't get you a different file.

     arg string ...
          Arg may be executed in the initialization and scanning phase to post
          an argument scanning rule, that's all the command itself does.  Like
          an if that fails it allows more guards to share the same body.

     transform suffix1 suffix2
          Transform, like arg, only posts a rule to transform a file with  the
          suffix suffix1 into a file with the suffix suffix2.

     prefer suffix1 suffix2
          Tells that the transformation rule from suffix1 to suffix2 is to  be
          preferred when looking for a transformation path to the stop suffix.
          Normally the shortest route to the stop suffix is used.   Prefer  is
          ignored  on  a  combine, because the special nature of combines does
          not allow ambiguity.

          The two suffixes on a transform or prefer may be the same, giving  a
          rule that is only executed when preferred.




                                                                             7



ACD(1)                    Minix Programmer's Manual                     ACD(1)


     combine suffix-list suffix
          Combine is like transform except that it  allows  a  list  of  input
          suffixes to match several types of input files that must be combined
          into one.

     scan The scanning phase may be run early from  the  initialization  phase
          with  the scan command.  Use it if you need to make choices based on
          the  arguments  before  posting  the  transformation  rules.   After
          running this, scan and arg become no-ops.

     compile
          Move on to the compilation phase early, so that you have a chance to
          run  a  few  extra  commands before exiting.  This command implies a
          scan.

     Any other command is seen as a UNIX command.  This is where the <  and  >
     operators  come  into  play.   They  redirect standard input and standard
     output to the file mentioned after them, just like the shell.   Acd  will
     stop with an error if the command is not successful.

  The Initialization Phase
     The driver starts by executing the program once from  top  to  bottom  to
     initialize variables and post argument scanning and transformation rules.

  The Scanning Phase
     In this phase the driver makes a pass over the command line arguments  to
     process  options.   Each  arg  rule is tried one by one in the order they
     were posted against the front of the argument list.  If a match  is  made
     then  the  matched  arguments  are removed from the argument list and the
     arg-body is executed.  If no match can be made then the first argument is
     moved  to  the  list  of  files waiting to be transformed and the scan is
     restarted.

     The match is done as follows: Each of the strings after  arg  must  match
     one  argument at the front of the argument list.  A character in a string
     must match a character in an argument word, a subst in a string may match
     1  to  all  remaining characters in the argument, preferring the shortest
     possible match.  The hyphen in a argument starting with a  hyphen  cannot
     be matched by a subst.  Therefore:

          arg -i

     matches only the argument -i.

          arg -O$n

     matches any argument that starts with -O and is at least three characters
     long.  Lastly,




                                                                             8



ACD(1)                    Minix Programmer's Manual                     ACD(1)


          arg -o $out

     matches -o and the argument following it,  unless  that  argument  starts
     with a hyphen.

     The variable $* is set to all the matched arguments before  the  arg-body
     is executed.  All the substs in the arg strings are set to the characters
     they match.  The variable $> is set to  null.   All  the  values  of  the
     variables are saved and the variables marked local.  All variables except
     $> are marked read-only.  After the arg-body is executed is the value  of
     $>  concatenated  to  the  file list.  This allows one to stuff new files
     into the transformation phase.  These added names are not evaluated until
     the start of the next phase.

  The Compilation Phase
     The files gathered in the  file  list  in  the  scanning  phase  are  now
     transformed  one by one using the transformation rules.  The shortest, or
     preferred route is computed for each file all the way to the stop suffix.
     Each  file  is  transformed  until  it  lands at the stop suffix, or at a
     combine rule.  After a while all files are either fully transformed or at
     a combine rule.

     The driver chooses a combine rule that is not  on  a  path  from  another
     combine  rule and executes it.  The file that results is then transformed
     until it again lands  at  a  combine  rule  or  the  stop  suffix.   This
     continues until all files are at the stop suffix and the program exits.

     The paths through transform rules may be ambiguous and have cycles,  they
     will  be  resolved.   But  paths  through  combines  must be unambiguous,
     because of the many paths from the different files that  meet  there.   A
     description  file will usually have only one combine rule for the loader.
     However if you do have a combine conflict then put a no-op transform rule
     in front of one to resolve the problem.

     If a file matches a long and a short  suffix  then  the  long  suffix  is
     preferred.   By  putting a null input suffix ("") in a rule one can match
     any file that no other rule matches.  You can send unknown files  to  the
     loader this way.

     The variable $* is set to the file to be transformed or the files  to  be
     combined  before the transform or combine-body is executed.  $> is set to
     the output file name, it may  again  be  modified.   $<  is  set  to  the
     original  name  of  the first file of $* with the leading directories and
     the suffix removed.  $* will be made up  of  temporary  files  after  the
     first  rule.  $> will be another temporary file or the name of the target
     file ($< plus the stop suffix), if the stop suffix is reached.

     $> is passed to the next rule; it is imploded and checked to be a  single
     word.   This  driver  does  not  store  intermediate  object files in the
     current directory like most other compilers, but keeps them in /tmp  too.


                                                                             9



ACD(1)                    Minix Programmer's Manual                     ACD(1)


     (Who knows if the current directory can have files created  in?)   As  an
     example, here is how you can express the "normal" method:

          transform .s .o
                  if $> = $<.o
                          # Stop suffix is .o
                  else
                          $> = $<.o
                          temporary $>
                  $AS -o $> $*

     Note that temporary is not called if the target  is  already  the  object
     file,  or  you would lose the intended result!  $> is known to be a word,
     because $< is local.  (Any string whose substs are all  expanded  changes
     to a word.)

  Predefined Variables
     The driver has three variables predefined:  PROGRAM, set to the call name
     of the driver, VERSION, the driver's version number, and ARCH, set to the
     name of the default output architecture.  The  latter  is  optional,  and
     only defined if acd was compiled with -DARCH=\"arch-name\".

EXAMPLE
     As an example a description file for a C compiler is  given.   It  has  a
     front  end (ccom), an intermediate code optimizer (opt), a code generator
     (cg), an assembler (as), and  a  loader  (ld).   The  compiler  can  pre-
     process, but there is also a separate cpp.  If the -D and options like it
     are changed to look like -o then this example  is  even  as  required  by
     POSIX.

          # The compiler support search path.
          C =     /lib /usr/lib /usr/local/lib

          # Compiler passes.
          CPP =   $C/cpp $CPP_F
          CCOM =  $C/ccom $CPP_F
          OPT =   $C/opt
          CG =    $C/cg
          AS =    $C/as
          LD =    $C/ld

          # Predefined symbols.
          CPP_F = -D__EXAMPLE_CC__

          # Library path.
          LIBPATH = $USERLIBPATH $C

          # Default transformation target.
          stop .out



                                                                            10



ACD(1)                    Minix Programmer's Manual                     ACD(1)


          # Preprocessor directives.
          arg -D$name
          arg -U$name
          arg -I$dir
                  CPP_F = $CPP_F $*

          # Stop suffix.
          arg -c
                  stop .o

          arg -E
                  stop .E

          # Optimization.
          arg -O
                  prefer .m .m
                  OPT = $OPT -O1

          arg -O$n
                  numeric $n
                  prefer .m .m
                  OPT = $OPT $*

          # Add debug info to the executable.
          arg -g
                  CCOM = $CCOM -g

          # Add directories to the library path.
          arg -L$dir
                  USERLIBPATH = $USERLIBPATH $dir

          # -llib must be searched in $LIBPATH later.
          arg -l$lib
                  $> = $LIBPATH/lib$lib.a

          # Change output file.
          arg -o$out
          arg -o $out
                  OUT = $out

          # Complain about a missing argument.
          arg -o
                  error "argument expected after '$*'"

          # Any other option (like -s) are for the loader.
          arg -$any
                  LD = $LD $*

          # Preprocess C-source.
          transform .c .i


                                                                            11



ACD(1)                    Minix Programmer's Manual                     ACD(1)


                  $CPP $* > $>

          # Preprocess C-source and send it to standard output or $OUT.
          transform .c .E
                  ifndef OUT
                          $CPP $*
                  else
                          $CPP $* > $OUT

          # Compile C-source to intermediate code.
          transform .c .m
          transform .i .m
                  $CCOM $* $>

          # Intermediate code optimizer.
          transform .m .m
                  $OPT $* > $>

          # Intermediate to assembly.
          transform .m .s
                  $CG $* > $>

          # Assembler to object code.
          transform .s .o
                  if $> = $<.o
                          ifdef OUT
                                  $> = $OUT
                  $AS -o $> $*

          # Combine object files and libraries to an executable.
          combine (.o .a) .out
                  ifndef OUT
                          OUT = a.out
                  $LD -o $OUT $C/crtso.o $* $C/libc.a

FILES

     /usr/lib/descr/descr     - compiler driver description file.

SEE ALSO
     cc(1).

ACKNOWLEDGEMENTS
     Even though the end result doesn't look much like  it,  many  ideas  were
     nevertheless derived from the ACK compiler driver by Ed Keizer.







                                                                            12



ACD(1)                    Minix Programmer's Manual                     ACD(1)


BUGS
     POSIX requires that if compiling one source file to an object file  fails
     then the compiler should continue with the next source file.  There is no
     way acd can do this, it always stops after error.  It doesn't  even  know
     what an object file is!  (The requirement is stupid anyhow.)

     If you don't think that tabs are 8 spaces wide, then don't mix them  with
     spaces for indentation.

AUTHOR
     Kees J. Bot (kjb@cs.vu.nl)









































                                                                            13

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -