comparison keiko/oblink.h @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 /*
2 * oblink.h
3 *
4 * This file is part of the Oxford Oberon-2 compiler
5 * Copyright (c) 2006--2016 J. M. Spivey
6 * All rights reserved
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <stdarg.h>
36 #include <assert.h>
37 #include "obcommon.h"
38 #include "exec.h"
39
40 #ifdef DEBUG
41 /* Small tables to help test auto-growth */
42 #define INIT_PMEM 8 /* Init space for procedures */
43 #define INIT_XMEM 128 /* Same for data buffer */
44 #define INIT_LMEM 16 /* Same for local labels */
45 #define INIT_SMEM 16 /* Same for symbol table */
46 #define INIT_MODS 10 /* Init space for modules */
47 #else
48 #define INIT_PMEM 256 /* Init space for procedures */
49 #define INIT_XMEM 2048 /* Same for data buffer */
50 #define INIT_LMEM 1024 /* Same for local labels */
51 #define INIT_SMEM 1024 /* Same for symbol table */
52 #define INIT_MODS 100 /* Init space for modules */
53 #endif
54
55 #define STACK_SIZE (1024 * 1024 - 32)
56 /* Default stack size (bytes) */
57 #define MIN_STACK 4096 /* Min stack size (bytes) */
58
59 typedef enum { ABS, DATA, BSS, CODE, UNDEFINED } segment;
60
61 typedef struct _phrase *phrase;
62
63 #ifdef __cplusplus
64 #define template xyzzy
65 #endif
66
67 typedef struct _template *template;
68
69 #define MAXMAC 6
70
71 struct _template { /* An encoding of an instruction */
72 const char *t_name; /* The instruction */
73 const char *t_pattern; /* Argument formats */
74 int t_lo, t_hi, t_step; /* Pattern of values for 'N' format */
75 int t_size; /* Total length of instruction */
76 int t_oplen; /* Length of opcode */
77 uchar t_op; /* Opcode */
78 const char *t_macro[MAXMAC]; /* Macro expansion */
79 };
80
81 #define put1(buf, x) put_int(1, buf, x)
82 #define put2(buf, x) put_int(2, buf, x)
83 #define put4(buf, x) put_int(4, buf, x)
84
85 EXTERN int dflag;
86 EXTERN int zflag; /* Whether to compress the bytecode */
87 EXTERN mybool sflag; /* Whether to suppress symbol table */
88 EXTERN mybool gflag; /* Whether to output extra debugging info */
89 EXTERN mybool custom; /* Whether to output a primitive table */
90 EXTERN mybool linecount;
91 EXTERN int stack_size;
92
93 /* template.c */
94 extern struct _template templates[];
95 extern short templ_trie[];
96 extern uchar templ_check[];
97
98 /* symtab.c */
99 typedef struct _symbol *symbol;
100
101 symbol make_symbol(const char *name);
102 symbol find_symbol(const char *name);
103 const char *sym_name(symbol s);
104 void def_global(symbol s, segment seg, int off, int kind);
105 void use_global(symbol s, uchar *base, int offset);
106 int sym_value(symbol s);
107 mybool known(const char *name);
108 void fix_data(uchar *base, int bss);
109 int write_symtab(void);
110 void module_data(symbol s, unsigned checksum, int nlines);
111
112 void init_labels(void);
113 int make_label(symbol s);
114 const char *label_name(int n);
115 void def_label(symbol s, phrase val);
116 phrase find_label(int n);
117
118 /* linker.c */
119 void init_linker(char *outname, char *interp);
120 void put_inst(const char *name, char *rands[], unsigned nrands);
121 void gen_inst(const char *fmt, ...);
122 void save_string(const char *label, char *string);
123 void open_output(char *name, char *interp);
124 void end_linking(void);
125 void dump_prims(void);
126
127 void relocate(int loc, int bits);
128
129 void put_int(int n, uchar *buf, int x);
130 int get4(uchar *buf);
131 void write_string(const char *s);
132 void write_int(int n, int x);
133
134 /* util.c */
135 #include "util.h"