📄 cdoc1
字号:
.SHThe Intermediate Language.PP.FS\(dgUNIX is a Trademark of Bell Laboratories..FECommunication between the two phases of the compiler properis carried out by means of a pair of intermediate files.These files are treated as having identical structure,although the second file contains only the code generated for strings.It is convenient to write strings out separately to reduce theneed for multiple location counters in a later assemblyphase..PPThe intermediate language is not machine-independent;its structure in a number of ways reflectsthe fact that C was originally a one-pass compilerchopped in two to reduce the maximum memoryrequirement.In fact, only the latest versionof the compiler has a completeintermediate language at all.Until recently, the first phase of the compiler generatedassembly code for those constructions it could deal with,and passed expression parse trees, in absolute binaryform,to the second phase for code generation.Now, at least, all inter-phase informationis passed in a describable form, and there areno absolute pointers involved, so the coupling betweenthe phases is not so strong..PPThe areas in which the machine(and system) dependencies are most noticeable are.IP 1.Storage allocation for automatic variables and argumentshas already been performed,and nodes for such variables refer to them by offsetfrom a display pointer.Type conversion(for example, from integer to pointer)has already occurred using the assumption ofbyte addressing and 2-byte words..IP 2.Data representations suitable to the PDP-11 are assumed;in particular, floating point constants are passed asfour words in the machine representation..PPAs it happens, each intermediate file is represented as a sequenceof binary numbers without any explicit demarcations.It consists of a sequence ofconceptual lines, each headed by an operator, and possibly containingvarious operands.The operators are small numbers;to assist in recognizing failure in synchronization,the high-order byte of each operator word is always theoctal number 376.Operands areeither 16-bit binary numbers or strings of characters representing names.Each name is terminated by a null character.There is no alignment requirement for numericaloperands and so there is no paddingafter a name string..PPThe binary representation was chosen to avoid the necessityof converting to and from character formand to minimize the size of the files.It would be very easy to makeeach operator-operand `line' in the file bea genuine, printable line, with the numbers in octal or decimal;this in fact was the representation originally used..PPThe operators fall naturally into two classes:those which represent part of an expression, and all others.Expressions are transmitted in a reverse-Polish notation;as they are being read, a tree is built which is isomorphicto the tree constructed in the first phase.Expressions are passed as a whole, with no non-expression operatorsintervening.The reader maintains a stack; each leaf of the expression tree (name, constant)is pushed on the stack;each unary operator replaces the top of the stack by a node whoseoperand is the old top-of-stack;each binary operator replaces the top pair on the stack witha single entry.When the expression is complete there is exactly one item on thestack.Following each expressionis a special operator which passes the unique previous expressionto the `optimizer' described below and then to the codegenerator..PPHere is the list of operators not themselves part of expressions..LP.Op EOFmarks the end of an input file..Op BDATA "flag data ..."specifies a sequence of bytes to be assembledas static data.It is followed by pairs of words; the first memberof the pair is non-zero to indicate that the data continue;a zero flag is not followed by data and terminatesthe operator.The data bytes occupy the low-order part of a word..Op WDATA "flag data ..."specifies a sequence of words to be assembled asstatic data; it is identical to the BDATA operatorexcept that entire words, not just bytes, are passed..Op PROGmeans that subsequent information is to be compiled as program text..Op DATAmeans that subsequent information is to be compiled as static data..Op BSSmeans that subsequent information is to be compiled as unitializedstatic data..Op SYMDEF namemeans thatthe symbol.Iname.Ris an external name defined in the current program.It is produced for each external data or function definition..Op CSPACE "name size"indicates that the name refers to a data area whose size is thespecified number of bytes.It is produced for external data definitions without explicit initialization..Op SSPACE sizeindicates that.Isize.Rbytes should be set aside for data storage.It is used to pad out short initializations of external dataand to reserve space for static (internal) data.It will be preceded by an appropriate label..Op EVENis produced after eachexternal data definition whose size is notan integral number of words.It is not produced after strings except when they initializea character array..Op NLABEL nameis produced just before a BDATA or WDATA initializingexternal data, and serves as a label for the data..Op RLABEL nameis produced just before each function definition,and labels its entry point..Op SNAME "name number"is produced at the start of each function for each static variableor labeldeclared therein.Subsequent uses of the variable will be in terms of the given number.The code generator uses this only to produce a debugging symbol table..Op ANAME "name number"Likewise, each automatic variable's name and stack offsetis specified by this operator.Arguments count as automatics..Op RNAME "name number"Each register variable is similarly named, with its register number..Op SAVE numberproduces a register-save sequence at the start of each function,just after its label (RLABEL)..Op SETREG numberis used to indicate the number of registers usedfor register variables.It actually gives the register number of the lowestfree register; it is redundant because the RNAME operators could becounted instead..Op PROFILis produced before the save sequence for functionswhen the profile option is turned on.It produces code to count the numberof times the function is called..Op SWIT "deflab line label value ..."is produced for switches.When control flows into it,the value being switched on is in the registerforced by RFORCE (below).The switch statement occurred on the indicated lineof the source, and the label number of the default locationis.Ideflab..RThen the operator is followed by a sequence of label-number and value pairs;the list is terminated by a 0 label..Op LABEL numbergenerates an internal label.It is referred to elsewhere using the given number..Op BRANCH numberindicates an unconditional transfer to the internal label numbergiven..Op RETRNproduces the return sequence for a function.It occurs only once, at the end of each function..Op EXPR linecauses the expression just preceding to be compiled.The argument is the line number in the source where theexpression occurred..Op NAME "class type name".Op NAME "class type number"indicates a name occurring in an expression.The first form is used when the name is external;the second when the name is automatic, static, or a register.Then the number indicates the stack offset, the label number,or the register number as appropriate.Class and type encoding is described elsewhere..Op CON "type value"transmits an integer constant.This and the next two operators occur as part of expressions..Op FCON "type 4-word-value"transmits a floating constant asfour words in PDP-11 notation..Op SFCON "type value"transmits a floating-point constantwhose value is correctly represented by its high-order wordin PDP-11 notation..Op NULLindicates a null argument list of a function call in an expression;call is a binary operator whose second operand is the argument list..Op CBRANCH "label cond"produces a conditional branch.It is an expression operator, and will be followedby an EXPR.The branch to the label number takes place if the expression'struth value is the same as that of.Icond..RThat is, if.Icond=1.Rand the expression evaluates to true, the branch is taken..Op binary-operator typeThere are binary operators correspondingto each such source-language operator;the type of the result of each is passed as well.Some perhaps-unexpected ones are:COMMA, which is a right-associative operator designedto simplify right-to-left evaluationof function arguments;prefix and postfix ++ and \-\-, whose second operandis the increment amount, as a CON;QUEST and COLON, to express the conditionalexpression as `a?(b:c)';and a sequence of special operators for expressingrelations between pointers, in case pointer comparisonis different from integer comparison(e.g. unsigned)..Op unary-operator typeThere are also numerous unary operators.These include ITOF, FTOI, FTOL, LTOF, ITOL, LTOIwhich convert among floating, long, and integer;JUMP which branches indirectly through a label expression;INIT, which compiles the value of a constant expressionused as an initializer;RFORCE, which is used before a return sequence ora switch to place a value in an agreed-upon register.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -