cref.doc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.3 Keywords"
  137. The word \fBvoid\fP is also reserved as a keyword.
  138. .IT "2.4.3 Character constants"
  139. The ASCII-mapping is used when a character is converted to an
  140. integer.
  141. .IT "2.4.4 Floating constants"
  142. To prevent loss of precision the compiler does not perform
  143. floating point constant folding.
  144. .IT "2.6 Hardware characteristics"
  145. The size of objects of the several arithmetic types and
  146. pointers depend on the EM-implementation used.
  147. The ranges of the arithmetic types depend on the size used,
  148. the C-frontend assumes two's complement representation for the
  149. integral types.
  150. All sizes are multiples of bytes.
  151. The calling program \fIack\fP[4] passes information about the
  152. size of the types to the compiler proper.
  153. .br
  154. However, a few general remarks must be made:
  155. .sp 1
  156. .IS
  157. .PT (a)
  158. The size of pointers is a multiple of
  159. (or equal to) the size of an \fIint\fP.
  160. .PT (b)
  161. The following relations exist for the sizes of the types
  162. mentioned:
  163. .br
  164. .ti +5
  165. \fIchar<=short<=int<=long\fP
  166. .PT (c)
  167. Objects of type \fIchar\fP use one 8-bit byte of storage,
  168. although several bytes are allocated sometimes.
  169. .PT (d)
  170. All sizes are in multiples of bytes.
  171. .PT (e)
  172. Most EM implementations use 4 bytes for floats and 8 bytes
  173. for doubles, but exceptions to this rule occur.
  174. .IE
  175. .IT "4 What's in a name"
  176. The type \fIvoid\fP is added.
  177. Objects of type void do not exist.
  178. Functions declared as returning void, do not return a value at all.
  179. .IT "6.1 Characters and integers"
  180. Objects of type \fIchar\fP are unsigned and do not cause
  181. sign-extension when converted to \fIint\fP.
  182. The range of characters values is from 0 to 255.
  183. .IT "6.3 Floating and integral"
  184. Floating point numbers are truncated towards zero when
  185. converted to the integral types.
  186. .IT "6.4 Pointers and integers"
  187. When a \fIlong\fP is added to or subtracted from a pointer and
  188. longs are larger then pointers the \fIlong\fP is converted to an
  189. \fIint\fP before the operation is performed.
  190. .IT "7.2 Unary operators"
  191. It is allowed to cast any expression to the type \fIvoid\fP.
  192. .IT "8.2 Type specifiers"
  193. One type is added to the type-specifiers:
  194. .br
  195. .IS
  196. void
  197. .IE
  198. .IT "8.5 Structure and union declarations"
  199. The only type allowed for fields is \fIint\fP.
  200. Fields with exactly the size of \fIint\fP are signed,
  201. all other fields are unsigned.
  202. .br
  203. The size of any single structure must be less then 4096 bytes.
  204. .IT "8.6 Initialization"
  205. Initialization of structures containing bit fields is not
  206. allowed.
  207. There is one restriction when using an 'address expression' to initialize
  208. an integral variable.
  209. The integral variable must have the same size as a pointer.
  210. Conversions altering the size of the address expression are not allowed.
  211. .IT "9.10 Return statement"
  212. Return statements of the form:
  213. .IS
  214. return ;
  215. .IE
  216. are the only form of return statement allowed in a function of type
  217. function returning void.
  218. .IT "10.1 External function definitions"
  219. The total amount for storage used for parameters
  220. in any function must be less then 4096 bytes.
  221. The same holds for the total amount of storage occupied by the
  222. automatic variables declared inside any function.
  223. .sp
  224. Using formal parameters whose size is smaller the the size of an int
  225. is less efficient on several machines.
  226. At procedure entry these parameters are converted from integer to the
  227. declared type, because the compiler doesn't know where the least
  228. significant bytes are stored in the int.
  229. .IT "11.2 Scope of externals"
  230. Most C compilers are rather lax in enforcing the restriction
  231. that only one external definition without the keyword
  232. \fIextern\fP is allowed in a program.
  233. The Ack-C frontend is very strict in this.
  234. The only exception is that declarations of arrays with a
  235. missing first array bounds expression are regarded to have an
  236. explicit keyword \fIextern\fP.
  237. .IT "14.4 Explicit pointer conversions"
  238. Pointers may be larger the ints, thus assigning a pointer to an
  239. int and back will not always result in the same pointer.
  240. The process mentioned above works with integrals
  241. of the same size or larger as pointers in all EM implementations
  242. having such integrals.
  243. When converting pointers to an integral type or vice-versa,
  244. the pointers is seen as an unsigned int.
  245. .br
  246. EM guarantees that any object can be placed at a word boundary,
  247. this allows the C-programs to use \fIint\fP pointers
  248. as pointers to objects of any type not smaller than an \fIint\fP.
  249. .CH "Frontend options"
  250. The C-frontend has a few options, these are controlled
  251. by flags:
  252. .IS
  253. .PT -V
  254. This flag is followed by a sequence of letters each followed by
  255. positive integers. Each letter indicates a
  256. certain type, the integer following it specifies the size of
  257. objects of that type. One letter indicates the wordsize used.
  258. .IS
  259. .sp 1
  260. .TS
  261. center tab(:);
  262. l l16 l l.
  263. letter:type:letter:type
  264. w:wordsize:i:int
  265. s:short:l:long
  266. f:float:d:double
  267. p:pointer::
  268. .TE
  269. .sp 1
  270. All existing implementations use an integer size equal to the
  271. wordsize.
  272. .IE
  273. The calling program \fIack\fP[4] provides the frontend with
  274. this flag, with values depending on the machine used.
  275. .sp 1
  276. .PT -l
  277. The frontend normally generates code to keep track of the line
  278. number and source file name at runtime for debugging purposes.
  279. Currently a pointer to a
  280. string containing the filename is stored at a fixed place in
  281. memory at each function
  282. entry and the line number at the start of every expression.
  283. At the return from a function these memory locations are not reset to
  284. the values they had before the call.
  285. Most library routines do not use this feature and thus do not
  286. ruin the current line number and filename when called.
  287. However, you are really unlucky when your program crashes due
  288. to a bug in such a library function, because the line number
  289. and filename do not indicate that something went wrong inside
  290. the library function.
  291. .br
  292. Providing the flag -l to the frontend tells it not to generate
  293. the code updating line number and file name.
  294. This is, for example, used when translating the stdio library.
  295. .br
  296. When the \fIack\fP[4] is called with the -L flag it provides
  297. the frontend with this flag.
  298. .sp 1
  299. .PT -Xp
  300. When this flag is present the frontend generates a call to
  301. the function \fBprocentry\fP at each function entry and a
  302. call to \fBprocexit\fP at each function exit.
  303. Both functions are provided with one parameter,
  304. a pointer to a string containing the function name.
  305. .br
  306. When \fIack\fP is called with the -p flag it provides the
  307. frontend with this flag.
  308. .IE
  309. .CH References
  310. .IS
  311. .PT [1]
  312. A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan
  313. Stevenson \fIDescription of a machine architecture for use with
  314. block structured languages\fP Informatica report IR-81.
  315. .sp 1
  316. .PT [2]
  317. B.W. Kernighan and D.M. Ritchie, \fIThe C Programming
  318. language\fP, Prentice-Hall, 1978
  319. .PT [3]
  320. D.M. Ritchie, \fIC Reference Manual\fP
  321. .sp
  322. .PT [4]
  323. UNIX manual ack(I).