cref.doc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. .\" $Header$
  2. .ll 72
  3. .nr ID 4
  4. .de hd
  5. 'sp 2
  6. 'tl ''-%-''
  7. 'sp 3
  8. ..
  9. .de fo
  10. 'bp
  11. ..
  12. .tr ~
  13. . TITLE
  14. .de TL
  15. .sp 15
  16. .ce
  17. \\fB\\$1\\fR
  18. ..
  19. . AUTHOR
  20. .de AU
  21. .sp 15
  22. .ce
  23. by
  24. .sp 2
  25. .ce
  26. \\$1
  27. ..
  28. . DATE
  29. .de DA
  30. .sp 3
  31. .ce
  32. ( Dated \\$1 )
  33. ..
  34. . INSTITUTE
  35. .de VU
  36. .sp 3
  37. .ce 4
  38. Wiskundig Seminarium
  39. Vrije Universteit
  40. De Boelelaan 1081
  41. Amsterdam
  42. ..
  43. . PARAGRAPH
  44. .de PP
  45. .sp
  46. .ti +\n(ID
  47. ..
  48. .nr CH 0 1
  49. . CHAPTER
  50. .de CH
  51. .nr SH 0 1
  52. .bp
  53. .in 0
  54. \\fB\\n+(CH.~\\$1\\fR
  55. .PP
  56. ..
  57. . SUBCHAPTER
  58. .de SH
  59. .sp 3
  60. .in 0
  61. \\fB\\n(CH.\\n+(SH.~\\$1\\fR
  62. .PP
  63. ..
  64. . INDENT START
  65. .de IS
  66. .sp
  67. .in +\n(ID
  68. ..
  69. . INDENT END
  70. .de IE
  71. .in -\n(ID
  72. .sp
  73. ..
  74. .de PT
  75. .ti -\n(ID
  76. .ta \n(ID
  77. .fc " @
  78. "\\$1@"\c
  79. .fc
  80. ..
  81. . DOUBLE INDENT START
  82. .de DS
  83. .sp
  84. .in +\n(ID
  85. .ll -\n(ID
  86. ..
  87. . DOUBLE INDENT END
  88. .de DE
  89. .ll +\n(ID
  90. .in -\n(ID
  91. .sp
  92. ..
  93. . EQUATION START
  94. .de EQ
  95. .sp
  96. .nf
  97. ..
  98. . EQUATION END
  99. .de EN
  100. .fi
  101. .sp
  102. ..
  103. . ITEM
  104. .de IT
  105. .sp
  106. .in 0
  107. \\fB~\\$1\\fR
  108. .ti +5
  109. ..
  110. .de CS
  111. .br
  112. ~-~\\
  113. ..
  114. .br
  115. .fi
  116. .TL "Ack-C reference manual"
  117. .AU "Ed Keizer"
  118. .DA "September 12, 1983"
  119. .VU
  120. .wh 0 hd
  121. .wh 60 fo
  122. .CH "Introduction"
  123. The C frontend included in the Amsterdam Compiler Kit
  124. translates UNIX-V7 C into compact EM code [1].
  125. The language accepted is described in [2] and [3].
  126. This document describes which implementation dependent choices were
  127. made in the Ack-C frontend and
  128. some restrictions and additions.
  129. .CH "The language"
  130. .PP
  131. Under the same heading as used in [2] we describe the
  132. properties of the Ack-C frontend.
  133. .IT "2.2 Identifiers"
  134. External identifiers are unique up to 7 characters and allow
  135. both upper and lower case.
  136. .IT "2.4.3 Character constants"
  137. The ASCII-mapping is used when a character is converted to an
  138. integer.
  139. .IT "2.4.4 Floating constants"
  140. To prevent loss of precision the compiler does not perform
  141. floating point constant folding.
  142. .IT "2.6 Hardware characteristics"
  143. The size of objects of the several arithmetic types and the two
  144. pointer types depend on the EM-implementation used.
  145. The ranges of the arithmetic types depend on the size used,
  146. the C-frontend assumes two's complement representation for the
  147. integral types. All sizes are multiples of bytes.
  148. The calling program \fIack\fP[4] passes information about the
  149. size of the types to the compiler proper.
  150. .br
  151. However, a few general remarks must be made:
  152. .sp 1
  153. .IS
  154. .PT (a)
  155. Two different pointer types exist: pointers to data and
  156. pointers to functions.
  157. The latter type is twice as large as the former.
  158. Pointers to functions use the same format as Pascal procedure
  159. parameters, thereby allowing C to use Pascal procedure
  160. parameters and vice-versa.
  161. The extra information passed indicates the scope level of the
  162. procedure.
  163. .PT (b)
  164. The size of pointers to data is a multiple of
  165. (or equal to) the size of an \fIint\fP.
  166. .PT (c)
  167. The following relations exist for the sizes of the types
  168. mentioned:
  169. .br
  170. .ti +5
  171. \fIchar<=short<=int<=long\fP
  172. .PT (d)
  173. Objects of type \fIchar\fP use one 8-bit byte of storage,
  174. although several bytes are allocated sometimes.
  175. .PT (e)
  176. All sizes are in multiples of bytes.
  177. .PT (f)
  178. Most EM implementations use 4 bytes for floats and 8 bytes
  179. for doubles, but exceptions to this rule occur.
  180. .IE
  181. .IT "6.1 Characters and integers"
  182. Objects of type \fIchar\fP are unsigned and do not cause
  183. sign-extension when converted to \fIint\fP.
  184. The range of characters values is from 0 to 255.
  185. .IT "6.3 Floating and integral"
  186. Floating point numbers are truncated towards zero when
  187. converted to the integral types.
  188. .IT "6.4 Pointers and integers"
  189. When a \fIlong\fP is added to or subtracted from a pointer and
  190. longs are larger then data pointers the \fIlong\fP is converted to an
  191. \fIint\fP before the operation is performed.
  192. .IT "8.5 Structure and union declarations"
  193. The only type allowed for fields is \fIint\fP.
  194. Fields with exactly the size of \fIint\fP are signed,
  195. all other fields are unsigned.
  196. .br
  197. The size of any single structure must be less then 4096 bytes.
  198. .IT "8.6 Initialization"
  199. Initialization of structures containing bit fields is not
  200. allowed.
  201. There is one restriction when using an 'address expression' to initialize
  202. an integral variable.
  203. The integral variable must have the size of a data pointer.
  204. Conversions altering the size of the address expression are not allowed.
  205. .IT "10.1 External function definitions"
  206. The total amount for storage used for parameters
  207. in any function must be less then 4096 bytes.
  208. The same holds for the total amount of storage occupied by the
  209. automatic variables declared inside any function.
  210. .sp
  211. Using formal parameters whose size is smaller the the size of an int
  212. is less efficient on several machines.
  213. At procedure entry these parameters are converted from integer to the
  214. declared type, because the compiler doesn't know where the least
  215. significant bytes are stored in the int.
  216. .IT "11.2 Scope of externals"
  217. Most C compilers are rather lax in enforcing the restriction
  218. that only one external definition without the keyword
  219. \fIextern\fP is allowed in a program.
  220. The Ack-C frontend is very strict in this.
  221. The only exception is that declarations of arrays with a
  222. missing first array bounds expression are regarded to have an
  223. explicit keyword \fIextern\fP.
  224. .IT "14.4 Explicit pointer conversions"
  225. Pointers may be larger the ints, thus assigning a pointer to an
  226. int and back will not always result in the same pointer.
  227. The process mentioned above works with integrals
  228. of the same size or larger as pointers in all EM implementations
  229. having such integrals.
  230. Note that pointers to functions have
  231. twice the size of pointers to data.
  232. When converting data pointers to an integral type or vice-versa,
  233. the pointers is seen as an unsigned with the same size a data-pointer.
  234. When converting function pointers to anything else the static link part
  235. of the pointer is discarded,
  236. the resulting value is treated as if it were a data pointer.
  237. When converting a data pointer or object of integral type to a function pointer
  238. a static link with the value 0 is added to complete the function pointer.
  239. .br
  240. EM guarantees that any object can be placed at a word boundary,
  241. this allows the C-programs to use \fIint\fP pointers
  242. as pointers to objects of any type not smaller than an \fIint\fP.
  243. .CH "Frontend options"
  244. The C-frontend has a few options, these are controlled
  245. by flags:
  246. .IS
  247. .PT -V
  248. This flag is followed by a sequence of letters each followed by
  249. positive integers. Each letter indicates a
  250. certain type, the integer following it specifies the size of
  251. objects of that type. One letter indicates the wordsize used.
  252. .IS
  253. .sp 1
  254. .TS
  255. center tab(:);
  256. l l16 l l.
  257. letter:type:letter:type
  258. w:wordsize:i:int
  259. s:short:l:long
  260. f:float:d:double
  261. p:pointer::
  262. .TE
  263. .sp 1
  264. All existing implementations use an integer size equal to the
  265. wordsize.
  266. .IE
  267. The calling program \fIack\fP[4] provides the frontend with
  268. this flag, with values depending on the machine used.
  269. .sp 1
  270. .PT -l
  271. The frontend normally generates code to keep track of the line
  272. number and source file name at runtime for debugging purposes.
  273. Currently a pointer to a
  274. string containing the filename is stored at a fixed place in
  275. memory at each function
  276. entry and the line number at the start of every expression.
  277. At the return from a function these memory locations are not reset to
  278. the values they had before the call.
  279. Most library routines do not use this feature and thus do not
  280. ruin the current line number and filename when called.
  281. However, you are really unlucky when your program crashes due
  282. to a bug in such a library function, because the line number
  283. and filename do not indicate that something went wrong inside
  284. the library function.
  285. .br
  286. Providing the flag -l to the frontend tells it not to generate
  287. the code updating line number and file name.
  288. This is, for example, used when translating the stdio library.
  289. .br
  290. When the \fIack\fP[4] is called with the -L flag it provides
  291. the frontend with this flag.
  292. .sp 1
  293. .PT -Xp
  294. When this flag is present the frontend generates a call to
  295. the function \fBprocentry\fP at each function entry and a
  296. call to \fBprocexit\fP at each function exit.
  297. Both functions are provided with one parameter,
  298. a pointer to a string containing the function name.
  299. .br
  300. When \fIack\fP is called with the -p flag it provides the
  301. frontend with this flag.
  302. .IE
  303. .CH References
  304. .IS
  305. .PT [1]
  306. A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan
  307. Stevenson \fIDescription of a machine architecture for use with
  308. block structured languages\fP Informatica report IR-81.
  309. .sp 1
  310. .PT [2]
  311. B.W. Kernighan and D.M. Ritchie, \fIThe C Programming
  312. language\fP, Prentice-Hall, 1978
  313. .PT [3]
  314. D.M. Ritchie, \fIC Reference Manual\fP
  315. .sp
  316. .PT [4]
  317. UNIX manual ack(I).