cref.doc 8.2 KB

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