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