1 .TH EM_CODE 3 "$Revision: 1.14 $"
4 emcode \- EM code interface for compilers
9 .B void C_init(wsize, psize)
10 .B arith wsize, psize;
12 .B int C_open(filename)
38 .BI "void C_bss_" cstp ()
39 .BI "void C_hol_" cstp ()
40 .BI "void C_con_" cstp ()
41 .BI "void C_rom_" cstp ()
43 .B #include <em_mes.h>
44 .B void C_mes_begin(ms)
53 .BI "void C_" mnem _dlb()
54 .BI "void C_" mnem _dnam()
55 .BI "void C_" mnem _narg()
57 .B void C_insertpart(id)
60 .B void C_beginpart(id)
78 This package provides a procedural EM code interface to be used in
79 compilers and other EM code producing programs.
80 The basic idea behind this package is to simplify the program writer's task
81 of producing EM code in any form, either compact or human-readable
82 EM assembly code or a sequence of procedure calls.
88 refer to types on the local
89 machine that are suitable for doing arithmetics and storing EM numeric labels
91 Common definitions are
102 should be called to initialize the module.
106 the pointer size on the target machine.
107 Checking implementations of this module use these values to check
108 whether arguments of an instruction are legal.
110 .BI C_open( filename )
111 should be invoked as initialiser for
112 a sequence of calls that produce EM code on file
116 is a null pointer, the code is produced on standard output.
117 Some implementations, such as fast back ends, may ignore the parameter.
119 causes some internal buffers to be flushed and the output file to be closed.
120 All subsequent routines, except for
122 must be invoked between the calls to
128 can be invoked in order
129 to detect whether EM code is currently being generated, i.e. whether
131 is invoked without a corresponding
138 produces the EM magic word.
140 Two routines can be used to generate code for the definitions of global data
147 for alphanumeric labels
151 produces EM code for instruction label
154 The routines for producing the EM procedure delimiters are:
162 \&\fBC_pro(\fP\fIs\fP\fB,\ \fP\fIl\fP\fB)\fP \fBpro\ \fP\fIs\fP\fB,\ \fP\fIl\fP
164 \&\fBC_pro_narg(\fP\fIs\fP\fB)\fP \fBpro\ \fP\fIs\fP\fB,\ ?\fP
166 \&\fBC_end(\fP\fIl\fP\fB)\fP \fBend\ \fP\fIl\fP
168 \&\fBC_end_narg()\fP \fBend\ ?\fP
172 A set of routines, concerning the scope definition pseudo instructions, is:
180 \&\fBC_exa_dnam(\fP\fIs\fP\fB)\fP \fBexa \fP\fIs\fP
182 \&\fBC_exa_dlb(\fP\fIl\fP\fB)\fP \fBexa .\fP\fIl\fP
184 \&\fBC_exp(\fP\fIs\fP\fB)\fP \fBexp $\fP\fIs\fP
186 \&\fBC_ina_dnam(\fP\fIs\fP\fB)\fP \fBina \fP\fIs\fP
188 \&\fBC_ina_dlb(\fP\fIl\fP\fB)\fP \fBina .\fP\fIl\fP
190 \&\fBC_inp(\fP\fIs\fP\fB)\fP \fBinp $\fP\fIs\fP
195 .B storage-declaration
196 pseudo instructions, we can
197 distinguish four groups, one for each type of storage declaration:
206 instructions are generated by
211 The type of the initialization value and the number and type of the parameters
214 according to the following table:
222 \&\fIcstp\fP number of type of description
223 parameters parameters
225 \&\fBcst\fP 1 \fBarith\fP word-sized integer of \fBarith\fP-type
227 \&\fBicon\fP 2 \fBchar *\fP integer in string representation
228 \fBarith\fP number of bytes on target machine
230 \&\fBucon\fP 2 \fBchar *\fP unsigned integer in string representation
231 \fBarith\fP number of bytes on target machine
233 \&\fBfcon\fP 2 \fBchar *\fP floating in string representation
234 \fBarith\fP number of bytes on target machine
236 \&\fBscon\fP 2 \fBchar *\fP row of bytes
237 \fBarith\fP length of the row of bytes
239 \&\fBdnam\fP 2 \fBchar *\fP alphanumeric global data label
240 \fBarith\fP offset (possibly 0)
242 \&\fBdlb\fP 2 \fBlabel\fP numeric global data label
243 \fBarith\fP offset (possibly 0)
245 \&\fBilb\fP 1 \fBlabel\fP instruction label
247 \&\fBpnam\fP 1 \fBchar *\fP procedure identifier
251 As an example of the use of the
253 routines, consider the
258 con 23I4, "hello world", .12, table + 12, *33
260 A sequence of calls to get this, is
263 C_con_icon("23", (arith)4);
264 C_con_scon("hello world", (arith) 11);
265 C_con_dlb((label)12, (arith)0);
266 C_con_dnam("table", (arith)12);
267 C_con_ilb((label)33);
275 instruction is produced by invoking
281 indicates the type of value that is used at initialisation.
282 The parameter list of
286 is similar to that of the corresponding
288 except that it is preceeded by an
297 indicates the number of bytes to reserve for the data;
299 has value 1 if the initialization is strictly necessary and 0 if not.
300 Note that, according to the EM definition, an initialisation type of
302 is not allowed in the
306 Another set of routines is that of the EM
309 As there is an undefined number of messages and each type of message has
310 its own number of parameters and each parameter its own type,
311 the user is responsible for building his own message lists.
312 Such a list consists of a list of
314 routine calls enclosed
316 .BI C_mes_begin( ms )
319 is the message number,
328 The use of this function may cause trouble in some implementations of this
330 A fast back end, for instance, may refuse to implement
332 The use of this function is therefore not recommended.
334 The final class of routines is that of the EM machine-instruction generating
341 The best way to describe them is according to section 11.3 of [EM].
342 Depending on the class of the argument (as indicated by a letter), one
343 or more routines are available for each machine instruction.
344 The following table gives an overview of the available routines for
345 the EM machine instruction
354 class routine(s) number of type of
355 parameters parameter(s)
357 [\fBcdflnorsz\fP] \fBC_\fP\fImnem\fP 1 \fBarith\fP
359 \&\fBw\fP \fBC_\fP\fImnem\fP 1 \fBarith\fP
360 \fBC_\fP\fImnem\fP\fB_narg\fP 0
362 \&\fBg\fP \fBC_\fP\fImnem\fP 1 \fBarith\fP
363 \fBC_\fP\fImnem\fP\fB_dnam\fP 2 \fBchar *\fP
365 \fBC_\fP\fImnem\fP\fB_dlb\fP 2 \fBlabel\fP
368 \&\fBp\fP \fBC_\fP\fImnem\fP 1 \fBchar *\fP
370 \&\fBb\fP \fBC_\fP\fImnem\fP 1 \fBlabel\fP
372 \&\fB\-\fP \fBC_\fP\fImnem\fP 0
376 The available routines for, for example, the EM machine instruction
384 with a given argument, and
388 with an argument on top of the stack.
389 Likewise are the available routines for
391 (which instruction has argument class
397 .BI C_loe_dnam( g , o )
400 is an alphanumeric label, and
401 .BI C_loe_dlb( g , o )
405 The latter two routines have the (possibly zero) offset
414 routines together implement a mechanism for re-arranging the generated code.
419 is to be inserted at the current position.
424 indicate begin and end of part
426 The order in which the parts are defined is not significant.
429 is called, all parts that have been inserted, must also be defined.
430 Parts may themselves again have sub-parts.
434 can be used to obtain a valid and unique part
437 On implementations with limited memory, the mechanism is implemented with a
439 The directory in which this file resides is indicated by
441 The default is the #define TMP_DIR from ~em/h/em_path.h.
442 The user can change this by just changing
448 accepts a structure as delivered by the
450 module, and produces code for it. It returns 1 if it succeeds, 0 if it fails
451 for some reason. The reason can then be found in \fIC_error\fP. The
453 routine replaces the EM_mkcalls routine.
457 ~em/modules/lib/libemk.a: library for generating compact EM code
458 ~em/modules/lib/libeme.a: library for generating human-readable EM code
459 ~em/lib.bin/em_data.a: library needed when using libeme.a
463 libemk.a: alloc(3), system(3), string(3)
464 libeme.a: alloc(3), print(3), system(3), string(3)
467 read_em(3), em_mes(3)
470 Andrew S. Tanenbaum, Hans van Staveren, Ed G. Keizer, Johan W. Stevenson,
472 "Description of a Machine Architecture for use with Block Structured Languages",
473 Informatica Rapport IR-81, Vrije Universiteit, Amsterdam, 1983.
477 returns 1 if the open is successful and 0 if not.
479 When a read, write or open fails, the routine
481 is called. The user can override its default definition by supplying his
482 own. The default just gives an error message and quits.
484 When an error occurs with the
486 mechanism, the routine
488 is called. Again, the user can override its default definition by supplying his
489 own. Such errors, however, are caused by a programming error of the user.
491 Some of the routines in this module may be implemented as macros. So,
492 do not try to take the address of these functions.
494 It is not possible to indicate that the argument of
496 must be seen as an unsigned value.