Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

mmixallib.ch 11 KB
Newer Older
1
2
3
4
5
6
7
This file has been written by Felix Albrecht and was modified by Martin Ruckert.

We start by adding a preprocessor definition to disable warnings
about deprecated functions, like strcpy or sprintf, and 
include mmixlib.h at the start of the sybroutines 
to declare the extern library interface.

8
9
10
11
12
We prepare for the elimination
of the exit() function, which must be replaced by a return from
the subroutine.


13
14
15
16
@x
@<Preprocessor definitions@>=
@y
@<Sub...@>=
17
18
extern void add_line_loc(int file_no, int line_no, octa loc);

19
20

@ @<Global...@>=
21
22
#include <setjmp.h>
jmp_buf mmixal_exit;
23
24

@ @<Preprocessor definitions@>=
25
#ifdef WIN32
26
#pragma warning(disable : 4996)
27
#endif
28
29
30
31
32
33
34
#define _MMIXAL_
@z

We change error messages that handle errors in the command line 
(there is none). Errors are no longer written to stderr.

@x
35
36
37
    fprintf(stderr,
       "(say `-b <number>' to increase the length of my input buffer)\n");
@y
38
    MMXIAL_LINE_TRUNCATED
39
40
@z

41
The filenames in mmixal are considered local.
42
43
44
45

@x
Char *filename[257];
@y
46
static Char *filename[257];
47
48
@z

49
50
The error reporting goes into a separate file, because we might want
to change it.
51
52

@x
53
54
55
56
57
58
59
60
@d err(m) {@+report_error(m);@+if (m[0]!='*') goto bypass;@+}
@d derr(m,p) {@+sprintf(err_buf,m,p);
   report_error(err_buf);@+if (err_buf[0]!='*') goto bypass;@+}
@d dderr(m,p,q) {@+sprintf(err_buf,m,p,q);
   report_error(err_buf);@+if (err_buf[0]!='*') goto bypass;@+}
@d panic(m) {@+sprintf(err_buf,"!%s",m);@+report_error(err_buf);@+}
@d dpanic(m,p) {@+err_buf[0]='!';@+sprintf(err_buf+1,m,p);@+
                                          report_error(err_buf);@+}
61
@y
62
63
64
65
66
67
68
69
@d err(m) {@+report_error(m,filename[cur_file],line_no);@+if (m[0]!='*') goto bypass;@+}
@d derr(m,p) {@+sprintf(err_buf,m,p);
   report_error(err_buf,filename[cur_file],line_no);@+if (err_buf[0]!='*') goto bypass;@+}
@d dderr(m,p,q) {@+sprintf(err_buf,m,p,q);
   report_error(err_buf,filename[cur_file],line_no);@+if (err_buf[0]!='*') goto bypass;@+}
@d panic(m) {@+sprintf(err_buf,"!%s",m);@+report_error(err_buf,filename[cur_file],line_no);@+}
@d dpanic(m,p) {@+err_buf[0]='!';@+sprintf(err_buf+1,m,p);@+
                                          report_error(err_buf,filename[cur_file],line_no);@+}
70
71
72
@z


73
@x
74
75
76
77
78
79
@<Sub...@>=
void report_error @,@,@[ARGS((char*))@];@+@t}\6{@>
void report_error(message)
  char *message;
{
  if (!filename[cur_file]) filename[cur_file]="(nofile)";
80
81
82
83
84
85
86
87
88
89
90
  if (message[0]=='*')
    fprintf(stderr,"\"%s\", line %d warning: %s\n",
                 filename[cur_file],line_no,message+1);
  else if (message[0]=='!')
    fprintf(stderr,"\"%s\", line %d fatal error: %s\n",
                 filename[cur_file],line_no,message+1);
  else {
    fprintf(stderr,"\"%s\", line %d: %s!\n",
                 filename[cur_file],line_no,message);
    err_count++;
  }
91
92
93
94
95
96
97
98
  if (listing_file) {
    if (!line_listed) flush_listing_line("****************** ");
    if (message[0]=='*') fprintf(listing_file,
            "************ warning: %s\n",message+1);
    else if (message[0]=='!') fprintf(listing_file,
            "******** fatal error: %s!\n",message+1);
    else fprintf(listing_file,
            "********** error: %s!\n",message);
99
100
  }
  if (message[0]=='!') exit(-2);
101
}
102
@y
103
104
105
106
@(libalerror.c@>=
#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
107

108
int err_count;
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
extern FILE *listing_file;
extern void flush_listing_line(char*line);
typedef enum{false,true}bool;
extern bool line_listed;
extern jmp_buf mmixal_exit;

void report_error(char *message,char *filename,int line_no)
{
  if (!filename) filename="(nofile)";
  if (message[0]=='*')
    fprintf(stderr,"\"%s\", line %d warning: %s\n",
                 filename,line_no,message+1);
  else if (message[0]=='!')
    fprintf(stderr,"\"%s\", line %d fatal error: %s\n",
                 filename,line_no,message+1);
  else {
    fprintf(stderr,"\"%s\", line %d: %s!\n",
                 filename,line_no,message);
    err_count++;
  }
  if (listing_file) {
    if (!line_listed) flush_listing_line("****************** ");
    if (message[0]=='*') fprintf(listing_file,
            "************ warning: %s\n",message+1);
    else if (message[0]=='!') fprintf(listing_file,
            "******** fatal error: %s!\n",message+1);
    else fprintf(listing_file,
            "********** error: %s!\n",message);
  }
  if (message[0]=='!') longjmp(mmixal_exit,-2);
}
140
141
142
143
144
145
146
@z

In the assemble subroutine, we have the
opportunity to gain some information about
the association of lines and locations.

@x
147
  for (j=0;j<k;j++) {
148
@y
149
 MMIXAL_LINE_LOC(cur_file, line_no, cur_loc);
150
151
152
153
154
155
 for (j=0;j<k;j++) {
@z

We allocate tree nodes node by node so that we can free them again.

@x
156
157
158
159
160
161
162
163
  register trie_node *t=next_trie_node;
  if (t==last_trie_node) {
    t=(trie_node*)calloc(1000,sizeof(trie_node));
    if (!t) panic("Capacity exceeded: Out of trie memory");
@.Capacity exceeded...@>
    last_trie_node=t+1000;
  }
  next_trie_node=t+1;
164
165
  return t;
@y
166
167
  trie_node *t=(trie_node*)calloc(1,sizeof(trie_node));
  if (!t) panic("Capacity exceeded: Out of trie memory");
168
169
170
171
172
173
  return t;
@z

We need extra information in the symbol table.

@x
174
typedef struct sym_tab_struct {
175
@y
176
177
178
typedef struct sym_tab_struct {
  int file_no;
  int line_no;
179
180
181
182
183
@z

We allocat single sym nodes to be able to free them.

@x
184
185
186
187
188
189
190
191
192
193
194
195
    p=next_sym_node;
    if (p==last_sym_node) {
      p=(sym_node*)calloc(1000,sizeof(sym_node));
      if (!p) panic("Capacity exceeded: Out of symbol memory");
@.Capacity exceeded...@>
      last_sym_node=p+1000;
    }
    next_sym_node=p+1;
@y
    p=(sym_node*)calloc(1,sizeof(sym_node));
    if (!p) panic("Capacity exceeded: Out of symbol memory");
@z   
196
197
198
199
200
201
202
203
204
205
206
207

The special names are already defined in mmix-sim.w

@x
Char *special_name[32]={"rB","rD","rE","rH","rJ","rM","rR","rBB",
 "rC","rN","rO","rS","rI","rT","rTT","rK","rQ","rU","rV","rG","rL",
 "rA","rF","rP","rW","rX","rY","rZ","rWW","rXX","rYY","rZZ"};
@y
extern Char *special_name[32];
@z

Errors generated at the end of the assembly should use the
208
normal error reporting function.
209
210

@x
211
212
213
  fprintf(stderr,"undefined symbol: %s\n",sym_buf+1);
@.undefined symbol@>
  err_count++;
214
@y
215
  sprintf(err_buf,"undefined symbol: %s",sym_buf+1);
216
  report_error(err_buf,filename[cur_file],line_no);
217
218
219
220
221
@z

when a sym_node becomes DEFINED, we record file and line.

@x
222
223
224
  @<Find the symbol table node, |pp|@>;
@y
  @<Find the symbol table node, |pp|@>;
225
  pp->file_no=MMIX_FILE_NO(cur_file);
226
  pp->line_no=line_no;  
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
@z




Some global variables need to be static to
avoid name conflicts in the library.

@x
tetra z,y,x,yz,xyz; /* pieces for assembly */
@y
static tetra z,y,x,yz,xyz; /* pieces for assembly */
@z

The main() program becomes mmixal().

@x
244
245
246
247
248
249
250
251
252
253
254
255
@c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
@#
@<Preprocessor definitions@>@;
@<Type definitions@>@;
@<Global variables@>@;
@<Subroutines@>@;
@#
256
257
258
int main(argc,argv)
  int argc;@+
  char *argv[];
259
260
261
{
  register int j,k; /* all-purpose integers */
  @<Local variables@>;
262
  @<Process the command line@>;
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  @<Initialize everything@>;
  while(1) {
    @<Get the next line of input text, or |break| if the input has ended@>;
    while(1) {
      @<Process the next \MMIXAL\ instruction or comment@>;
      if (!*buf_ptr) break;
    }
    if (listing_file) {
      if (listing_bits) listing_clear();
      else if (!line_listed) flush_listing_line("                   ");
    }
  }
  @<Finish the assembly@>;
}
277
@y
278
279
@c
#include <stdlib.h>
280
#include <stdio.h>
281
#include <string.h>
282

283
@#
284
285
286
287
288
289
290
291
extern int expanding;
extern int buf_size;
extern char*src_file_name;
extern char obj_file_name[FILENAME_MAX+1];
extern char listing_name[FILENAME_MAX+1];

extern void report_error(char * message, char *filename, int line_no);
extern int mmixal(char *mms_name, char *mmo_name, char *mml_name, int x_option, int b_option);
292
293
294
295
296
@#
int main(argc,argv)
  int argc;@+
  char *argv[];
{
297
298
  register int j; /* all-purpose integers */

299
  @<Process the command line@>;
300
  return mmixal(src_file_name, obj_file_name, listing_name, expanding, buf_size);
301
302
303
304
305
306
307
}

@ @(libmmixal.c@>=
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
308
#include <time.h> 
309
#include <setjmp.h>
310
#include "libconfig.h"
311
#include "libimport.h"
312
313
314
315
316
@#
@h
@<Preprocessor definitions@>@;
@<Type definitions@>@;
@<Global variables@>@;
317
318

extern void report_error(char * message, char *filename, int line_no);
319
extern jmp_buf mmixal_exit;
320

321
@<Subroutines@>@;
322

323
324
325
326
327
328
@#
int mmixal(char *mms_name, char *mmo_name, char *mml_name, int x_option, int b_option)
{
  register int j,k; /* all-purpose integers */
  @<Local variables@>;
  /* instead of processing the commandline */
329
  err_count=setjmp(mmixal_exit);
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
  if (err_count!=0){
   prune(trie_root);
   goto clean_up;
  }
  if (mms_name==NULL)
    panic("No input file name");
  src_file_name= mms_name;
  if (mmo_name==NULL)
    obj_file_name[0]=0;
  else
    strncpy(obj_file_name,mmo_name,FILENAME_MAX);
  if (mml_name==NULL)
    listing_name[0]=0;
  else
    strncpy(listing_name,mml_name,FILENAME_MAX);
  expanding = x_option;
  buf_size = b_option;
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
    cur_file=0;
  line_no=0;
  long_warning_given=0;
  cur_loc.h=cur_loc.l=0;
  listing_loc.h=listing_loc.l=0;
  spec_mode= 0;
  spec_mode_loc= 0;
  mmo_ptr=0;
  err_count=0;
  serial_number=0;
  filename_count=0;
  for (j=0;j<10;j++)
  { forward_local[j].link=0;
    backward_local[j].link=0;
  }
  greg= 255;
363
  lreg= 32;
364
365
366
367
368
369
370
371
372
373
374
375
376
377
  @<Initialize everything@>;
  while(1) {
    @<Get the next line of input text, or |break| if the input has ended@>;
    while(1) {
      @<Process the next \MMIXAL\ instruction or comment@>;
      if (!*buf_ptr) break;
    }
    if (listing_file) {
      if (listing_bits) listing_clear();
      else if (!line_listed) flush_listing_line("                   ");
    }
  }
  @<Finish the assembly@>;
}
378
379
@z

380
381
We end with return or longjmp instead of exit.

382
@x
383
384
385
386
387
388
389
if (err_count) {
  if (err_count>1) fprintf(stderr,"(%d errors were found.)\n",err_count);
  else fprintf(stderr,"(One error was found.)\n");
}
exit(err_count);
@y
  if (err_count>0){
390
391
392
    if (err_count>1) sprintf(err_buf,"(%d errors were found.)",err_count);
    else sprintf(err_buf,"(One error was found.)");
    report_error(err_buf,filename[cur_file],line_no);
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
  }
clean_up:
  if (listing_file!=NULL) 
  { fclose(listing_file);
    listing_file=NULL;
  }
  if (obj_file!=NULL) 
  { fclose(obj_file);
    obj_file=NULL;
  }
  if (src_file!=NULL) 
  { fclose(src_file);
    src_file=NULL;
  }
  cur_file=0;
  line_no=0;
  long_warning_given=0;
  cur_loc.h=cur_loc.l=0;
  listing_loc.h=listing_loc.l=0;
  spec_mode= 0;
  spec_mode_loc= 0;
  serial_number=0;
  free(buffer); buffer=NULL;
  free(lab_field); lab_field=NULL;
  free(op_field); op_field=NULL;
  free(operand_list); operand_list=NULL;
  free(err_buf);err_buf=NULL;
  free(op_stack); op_stack=NULL;
  free(val_stack);val_stack=NULL;
  filename[0]=NULL;
  filename_passed[0]=0;
  for (j=1;j<filename_count;j++)
  { free(filename[j]);
    filename[j]=NULL;
427
    filename_passed[j]=0;
428
429
430
  }
  filename_count=0;
  
431
432
433
return err_count;
@z

434

435
436
437
438
To report undefined local sysmbols we use the
usual error reporting.

@x
439
440
  err_count++,fprintf(stderr,"undefined local symbol %dF\n",j);
@y
441
442
  { sprintf(err_buf,"undefined local symbol %dF",j);
    report_error(err_buf,filename[cur_file],line_no);
443
444
  }
@z