Merge pull request #69 from kernigh/kernigh-stdc

use libc assert, strcmp; declare more functions; fewer clang warnings
This commit is contained in:
David Given 2017-11-19 12:00:40 +01:00 committed by GitHub
commit 6d91bdbbbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
191 changed files with 1433 additions and 1898 deletions

View file

@ -92,8 +92,10 @@ definerule("cppfile",
local hdrpaths = {} local hdrpaths = {}
for _, t in pairs(e.deps) do for _, t in pairs(e.deps) do
if t.dir then
hdrpaths[#hdrpaths+1] = "-I"..t.dir hdrpaths[#hdrpaths+1] = "-I"..t.dir
end end
end
hdrpaths = uniquify(hdrpaths) hdrpaths = uniquify(hdrpaths)
return normalrule { return normalrule {

View file

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __CGG_CG_H_INCLUDED
#define __CGG_CG_H_INCLUDED
/* offsets of interesting fields in EM-pattern */ /* offsets of interesting fields in EM-pattern */
#define PO_HASH 0 #define PO_HASH 0
@ -165,3 +168,5 @@ typedef struct { /* one to one coercions */
if ((a=((*(b)++)&BMASK)) >= 128) {\ if ((a=((*(b)++)&BMASK)) >= 128) {\
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \ a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
} }
#endif /* __CGG_CG_H_INCLUDED */

View file

@ -237,6 +237,7 @@ float_cst(str, sz, buf)
#endif /* USE_FLT */ #endif /* USE_FLT */
#ifdef CODE_GENERATOR #ifdef CODE_GENERATOR
void
con_float() con_float()
{ {
char buf[8]; char buf[8];

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* L E X I C A L A N A L Y Z E R */ /* L E X I C A L A N A L Y Z E R */
#include <assert.h>
#include <alloc.h> #include <alloc.h>
#include "parameters.h" #include "parameters.h"
#include "input.h" #include "input.h"
@ -15,7 +16,6 @@
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
#include "class.h" #include "class.h"
#include "assert.h"
#include "sizes.h" #include "sizes.h"
#include "specials.h" /* registration of special identifiers */ #include "specials.h" /* registration of special identifiers */
@ -61,15 +61,15 @@ void skipcomment();
*/ */
PushLex() PushLex()
{ {
ASSERT(LexSP < MAX_LL_DEPTH); assert(LexSP < MAX_LL_DEPTH);
ASSERT(ASIDE == 0); /* ASIDE = 0; */ assert(ASIDE == 0); /* ASIDE = 0; */
GetToken(&ahead); GetToken(&ahead);
LexStack[LexSP++] = dot; LexStack[LexSP++] = dot;
} }
PopLex() PopLex()
{ {
ASSERT(LexSP > 0); assert(LexSP > 0);
dot = LexStack[--LexSP]; dot = LexStack[--LexSP];
} }
#endif /* NOPP */ #endif /* NOPP */
@ -765,7 +765,7 @@ struct token *ptok;
int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0; int uns_flg = 0, lng_flg = 0, malformed = 0, ovfl = 0;
int fund; int fund;
ASSERT(*cp != '-'); assert(*cp != '-');
if (*cp == '0') { if (*cp == '0') {
cp++; cp++;
if (*cp == 'x' || *cp == 'X') { if (*cp == 'x' || *cp == 'X') {
@ -828,7 +828,7 @@ struct token *ptok;
if (val >= 0) fund = LONG; if (val >= 0) fund = LONG;
else fund = ULONG; else fund = ULONG;
} else { /* sizeof(arith) is greater than long_size */ } else { /* sizeof(arith) is greater than long_size */
ASSERT(arith_size > long_size); assert(arith_size > long_size);
lexwarning("constant too large for target machine"); lexwarning("constant too large for target machine");
/* cut the size to prevent further complaints */ /* cut the size to prevent further complaints */
val &= full_mask[(int)long_size]; val &= full_mask[(int)long_size];

View file

@ -11,6 +11,7 @@
semantics of C is a mess. semantics of C is a mess.
*/ */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#include <alloc.h> #include <alloc.h>
#include <flt_arith.h> #include <flt_arith.h>
@ -23,7 +24,6 @@
#include "Lpars.h" #include "Lpars.h"
#include "field.h" #include "field.h"
#include "mes.h" #include "mes.h"
#include "assert.h"
extern char *symbol2str(); extern char *symbol2str();
extern char options[]; extern char options[];
@ -250,7 +250,7 @@ any2arith(expp, oper)
switch (fund = (*expp)->ex_type->tp_fund) { switch (fund = (*expp)->ex_type->tp_fund) {
case CHAR: case CHAR:
case SHORT: case SHORT:
ASSERT((*expp)->ex_type->tp_size <= int_type->tp_size); assert((*expp)->ex_type->tp_size <= int_type->tp_size);
if ((*expp)->ex_type->tp_unsigned if ((*expp)->ex_type->tp_unsigned
&& (*expp)->ex_type->tp_size == int_type->tp_size) { && (*expp)->ex_type->tp_size == int_type->tp_size) {

View file

@ -1,26 +0,0 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
/* A S S E R T I O N M A C R O D E F I N I T I O N */
/* At some points in the program, it must be sure that some condition
holds true, due to further, successful, processing. As long as
there is no reasonable method to prove that a program is 100%
correct, these assertions are needed in some places.
*/
#include "parameters.h"
#ifdef DEBUG
/* Note: this macro uses parameter substitution inside strings */
#define ASSERT(exp) (exp || crash("in %s, %u: assertion %s failed", \
__FILE__, __LINE__, "exp"))
#define NOTREACHED() crash("in %s, %u: unreachable statement reached", \
__FILE__, __LINE__)
#else
#define ASSERT(exp)
#define NOTREACHED()
#endif /* DEBUG */

View file

@ -138,7 +138,12 @@ cprogram {
matching(filenamesof("+llgen"), "%.c$"), matching(filenamesof("+llgen"), "%.c$"),
}, },
deps = { deps = {
"./*.h", "./LLlex.h", "./align.h", "./arith.h", "./atw.h",
"./class.h", "./decspecs.h", "./file_info.h",
"./input.h", "./interface.h", "./l_class.h",
"./l_comment.h", "./l_em.h", "./l_lint.h",
"./label.h", "./level.h", "./mes.h", "./sizes.h",
"./specials.h", "./tokenname.h",
"+llgen", "+llgen",
"+nextlib", "+nextlib",
"+parameters", "+parameters",

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* S E M A N T I C A N A L Y S I S -- C H A P T E R 3.3 */ /* S E M A N T I C A N A L Y S I S -- C H A P T E R 3.3 */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#include <flt_arith.h> #include <flt_arith.h>
#include "arith.h" #include "arith.h"
@ -16,7 +17,6 @@
#include "expr.h" #include "expr.h"
#include "def.h" #include "def.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.h"
#include "file_info.h" #include "file_info.h"
extern char options[]; extern char options[];
@ -119,7 +119,7 @@ ch3sel(expp, oper, idf)
struct oper *op = &(exp->ex_object.ex_oper); struct oper *op = &(exp->ex_object.ex_oper);
if (op->op_oper == '.' || op->op_oper == ARROW) { if (op->op_oper == '.' || op->op_oper == ARROW) {
ASSERT(is_cp_cst(op->op_right)); assert(is_cp_cst(op->op_right));
op->op_right->VL_VALUE += sd->sd_offset; op->op_right->VL_VALUE += sd->sd_offset;
exp->ex_type = sd->sd_type; exp->ex_type = sd->sd_type;
exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY; exp->ex_lvalue = exp->ex_type->tp_fund != ARRAY;
@ -528,7 +528,7 @@ legal_mixture(tp, otp, diag)
register struct proto *prot; register struct proto *prot;
int fund; int fund;
ASSERT( (pl != 0) ^ (opl != 0)); assert( (pl != 0) ^ (opl != 0));
if (pl) { if (pl) {
prot = pl; prot = pl;
} else { } else {
@ -592,7 +592,7 @@ int qual;
{ {
register struct sdef *sdf; register struct sdef *sdf;
ASSERT(tp); assert(tp);
if (tp->tp_typequal & qual) return 1; if (tp->tp_typequal & qual) return 1;
switch(tp->tp_fund) { switch(tp->tp_fund) {

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* C O D E - G E N E R A T I N G R O U T I N E S */ /* C O D E - G E N E R A T I N G R O U T I N E S */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "parameters.h" #include "parameters.h"
@ -32,7 +33,6 @@
#include "Lpars.h" #include "Lpars.h"
#include "specials.h" #include "specials.h"
#include "atw.h" #include "atw.h"
#include "assert.h"
#include "LLlex.h" #include "LLlex.h"
#include "align.h" #include "align.h"
#ifdef LINT #ifdef LINT
@ -545,7 +545,7 @@ loc_init(expr, id)
static arith tmpoffset = 0; static arith tmpoffset = 0;
static arith unknownsize = 0; static arith unknownsize = 0;
ASSERT(df->df_sc != STATIC); assert(df->df_sc != STATIC);
switch (tp->tp_fund) { switch (tp->tp_fund) {
case ARRAY: case ARRAY:
if (tp->tp_size == (arith) -1) if (tp->tp_size == (arith) -1)

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#include <flt_arith.h> #include <flt_arith.h>
#include "arith.h" #include "arith.h"
@ -13,7 +14,6 @@
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.h"
/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ /* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
arith full_mask[MAXSIZE + 1]; arith full_mask[MAXSIZE + 1];
@ -34,7 +34,7 @@ cstbin(expp, oper, expr)
register arith o2 = expr->VL_VALUE; register arith o2 = expr->VL_VALUE;
int uns = (*expp)->ex_type->tp_unsigned; int uns = (*expp)->ex_type->tp_unsigned;
ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); assert(is_ld_cst(*expp) && is_cp_cst(expr));
switch (oper) { switch (oper) {
case '*': case '*':
o1 *= o2; o1 *= o2;
@ -144,7 +144,7 @@ cut_size(expr)
int uns = expr->ex_type->tp_unsigned; int uns = expr->ex_type->tp_unsigned;
int size = (int) expr->ex_type->tp_size; int size = (int) expr->ex_type->tp_size;
ASSERT(expr->ex_class == Value); assert(expr->ex_class == Value);
if (expr->ex_type->tp_fund == POINTER) { if (expr->ex_type->tp_fund == POINTER) {
/* why warn on "ptr-3" ? /* why warn on "ptr-3" ?
This quick hack fixes it This quick hack fixes it

View file

@ -5,7 +5,7 @@
/* $Id$ */ /* $Id$ */
/* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */ /* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */
#include "assert.h" #include <assert.h>
#include "Lpars.h" #include "Lpars.h"
#include "decspecs.h" #include "decspecs.h"
#include "arith.h" #include "arith.h"
@ -28,7 +28,7 @@ do_decspecs(ds)
*/ */
register struct type *tp = ds->ds_type; register struct type *tp = ds->ds_type;
ASSERT(level != L_FORMAL1); assert(level != L_FORMAL1);
if ( level == L_GLOBAL && if ( level == L_GLOBAL &&
(ds->ds_sc == AUTO || ds->ds_sc == REGISTER) (ds->ds_sc == AUTO || ds->ds_sc == REGISTER)

View file

@ -5,7 +5,9 @@
/* $Id$ */ /* $Id$ */
/* PREPROCESSOR: CONTROLLINE INTERPRETER */ /* PREPROCESSOR: CONTROLLINE INTERPRETER */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "parameters.h" #include "parameters.h"
#include "idf.h" #include "idf.h"
#include "arith.h" #include "arith.h"
@ -15,7 +17,6 @@
#include "replace.h" #include "replace.h"
#ifndef NOPP #ifndef NOPP
#include "assert.h"
#include <alloc.h> #include <alloc.h>
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"
@ -263,7 +264,7 @@ int to_endif;
else SkipToNewLine(); else SkipToNewLine();
break; break;
case K_ENDIF: case K_ENDIF:
ASSERT(nestlevel > nestlow); assert(nestlevel > nestlow);
if (nestlevel == skiplevel) { if (nestlevel == skiplevel) {
if (SkipToNewLine()) { if (SkipToNewLine()) {
if (!options['o']) if (!options['o'])
@ -383,7 +384,7 @@ do_define()
} }
/* read the replacement text if there is any */ /* read the replacement text if there is any */
ch = skipspaces(ch,0); /* find first character of the text */ ch = skipspaces(ch,0); /* find first character of the text */
ASSERT(ch != EOI); assert(ch != EOI);
/* UnGetChar() is not right when replacement starts with a '/' */ /* UnGetChar() is not right when replacement starts with a '/' */
ChPushBack(ch); ChPushBack(ch);
repl_text = get_text((nformals > 0) ? formals : 0, &length); repl_text = get_text((nformals > 0) ? formals : 0, &length);

View file

@ -8,6 +8,7 @@
#ifdef DEBUG #ifdef DEBUG
#include "parameters.h" #include "parameters.h"
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include <flt_arith.h> #include <flt_arith.h>
#include "arith.h" #include "arith.h"
@ -455,8 +456,6 @@ p1_expr(lvl, expr)
break; break;
case String: case String:
{ {
char *bts2str();
print( print(
"\"%s\"\n", "\"%s\"\n",
bts2str(expr->SG_VALUE, expr->SG_LEN-1, bts2str(expr->SG_VALUE, expr->SG_LEN-1,

View file

@ -8,6 +8,8 @@
#include "parameters.h" #include "parameters.h"
#ifndef LINT #ifndef LINT
#include <assert.h>
#include <ack_string.h>
#include <em.h> #include <em.h>
#include <em_reg.h> #include <em_reg.h>
#include <alloc.h> #include <alloc.h>
@ -17,7 +19,6 @@
#include "type.h" #include "type.h"
#include "label.h" #include "label.h"
#include "code.h" #include "code.h"
#include "assert.h"
#include "def.h" #include "def.h"
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
@ -32,7 +33,6 @@
#define CRASH() crash("EVAL: CRASH at line %u", __LINE__) #define CRASH() crash("EVAL: CRASH at line %u", __LINE__)
char *symbol2str(); char *symbol2str();
char *long2str();
arith NewLocal(); /* util.c */ arith NewLocal(); /* util.c */
#define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER) #define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
extern int err_occurred; /* error.c */ extern int err_occurred; /* error.c */
@ -83,7 +83,7 @@ EVAL(expr, val, code, true_label, false_label)
/* can only result from ','-expressions with /* can only result from ','-expressions with
constant right-hand sides ??? constant right-hand sides ???
*/ */
ASSERT(is_cp_cst(expr)); assert(is_cp_cst(expr));
C_bra(expr->VL_VALUE == 0 ? false_label : true_label); C_bra(expr->VL_VALUE == 0 ? false_label : true_label);
} }
else load_val(expr, val); else load_val(expr, val);
@ -254,7 +254,7 @@ EVAL(expr, val, code, true_label, false_label)
break; break;
case '%': case '%':
operands(expr, gencode); operands(expr, gencode);
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); assert(tp->tp_fund==INT || tp->tp_fund==LONG);
if (gencode) if (gencode)
if (tp->tp_unsigned) if (tp->tp_unsigned)
C_rmu(tp->tp_size); C_rmu(tp->tp_size);
@ -554,7 +554,7 @@ EVAL(expr, val, code, true_label, false_label)
fp_used = 1; fp_used = 1;
EVAL(left, oper == '.' ? LVAL : RVAL, gencode, EVAL(left, oper == '.' ? LVAL : RVAL, gencode,
NO_LABEL, NO_LABEL); NO_LABEL, NO_LABEL);
ASSERT(is_cp_cst(right)); assert(is_cp_cst(right));
if (gencode) { if (gencode) {
C_adp(right->VL_VALUE); C_adp(right->VL_VALUE);
} }
@ -877,7 +877,7 @@ store_val(vl, tp)
} }
} }
else { else {
ASSERT(df->df_sc != STATIC); assert(df->df_sc != STATIC);
if (inword || indword) if (inword || indword)
StoreLocal(df->df_address + val, tp->tp_size); StoreLocal(df->df_address + val, tp->tp_size);
else { else {
@ -889,7 +889,7 @@ store_val(vl, tp)
else { else {
label dlb = vl->vl_data.vl_lbl; label dlb = vl->vl_data.vl_lbl;
ASSERT(vl->vl_class == Label); assert(vl->vl_class == Label);
if (inword) if (inword)
C_ste_dlb(dlb, val); C_ste_dlb(dlb, val);
else else
@ -964,12 +964,12 @@ load_val(expr, rlval)
register struct def *df = id->id_def; register struct def *df = id->id_def;
int fund = df->df_type->tp_fund; int fund = df->df_type->tp_fund;
ASSERT(ISNAME(expr)); assert(ISNAME(expr));
if (fund == FUNCTION) { if (fund == FUNCTION) {
/* the previous statement tried to catch a function /* the previous statement tried to catch a function
identifier, which may be cast to a pointer to a identifier, which may be cast to a pointer to a
function. function.
ASSERT(!(rvalue)); ??? assert(!(rvalue)); ???
*/ */
C_lpi(id->id_text); C_lpi(id->id_text);
} }
@ -995,7 +995,7 @@ load_val(expr, rlval)
} }
} }
else { else {
/* ASSERT(df->df_sc != STATIC); */ /* assert(df->df_sc != STATIC); */
if (rvalue) { if (rvalue) {
if (inword || indword) if (inword || indword)
LoadLocal(df->df_address + val, tp->tp_size); LoadLocal(df->df_address + val, tp->tp_size);

View file

@ -5,9 +5,9 @@
/* $Id$ */ /* $Id$ */
/* EXPRESSION TREE HANDLING */ /* EXPRESSION TREE HANDLING */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "parameters.h" #include "parameters.h"
#include "assert.h"
#include <alloc.h> #include <alloc.h>
#include <flt_arith.h> #include <flt_arith.h>
#include "idf.h" #include "idf.h"
@ -251,7 +251,7 @@ float2expr(expr)
expr->ex_class = Float; expr->ex_class = Float;
flt_str2flt(dot.tk_fval, &(expr->FL_ARITH)); flt_str2flt(dot.tk_fval, &(expr->FL_ARITH));
free(dot.tk_fval); free(dot.tk_fval);
ASSERT(flt_status != FLT_NOFLT); assert(flt_status != FLT_NOFLT);
if (flt_status == FLT_OVFL) if (flt_status == FLT_OVFL)
expr_warning(expr,"internal floating point overflow"); expr_warning(expr,"internal floating point overflow");
} }

View file

@ -10,6 +10,7 @@
#ifndef NOBITFIELD #ifndef NOBITFIELD
#include <assert.h>
#include <em.h> #include <em.h>
#include <em_reg.h> #include <em_reg.h>
#include <flt_arith.h> #include <flt_arith.h>
@ -17,7 +18,6 @@
#include "type.h" #include "type.h"
#include "label.h" #include "label.h"
#include "code.h" #include "code.h"
#include "assert.h"
#include "expr.h" #include "expr.h"
#include "sizes.h" #include "sizes.h"
#include "align.h" #include "align.h"
@ -55,12 +55,12 @@ eval_field(expr, code)
: word_type; : word_type;
/* First some assertions to be sure that the rest is legal */ /* First some assertions to be sure that the rest is legal */
ASSERT(atype->tp_size == word_size); /* make sure that C_loc() is legal */ assert(atype->tp_size == word_size); /* make sure that C_loc() is legal */
ASSERT(leftop->ex_type->tp_fund == FIELD); assert(leftop->ex_type->tp_fund == FIELD);
leftop->ex_type = atype; /* this is cheating but it works... */ leftop->ex_type = atype; /* this is cheating but it works... */
if (op == '=') { if (op == '=') {
/* F = E: f = ((E & mask)<<shift) | (~(mask<<shift) & f) */ /* F = E: f = ((E & mask)<<shift) | (~(mask<<shift) & f) */
ASSERT(tp == rightop->ex_type); assert(tp == rightop->ex_type);
EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL);
conversion(tp, atype); conversion(tp, atype);
store_field(fd, tp->tp_unsigned, code, leftop, (arith) 0); store_field(fd, tp->tp_unsigned, code, leftop, (arith) 0);

View file

@ -6,8 +6,8 @@
/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */
/* F O R F L O A T I N G P O I N T N U M B E R S */ /* F O R F L O A T I N G P O I N T N U M B E R S */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#include "assert.h"
#include <alloc.h> #include <alloc.h>
#include <flt_arith.h> #include <flt_arith.h>
#include "arith.h" #include "arith.h"
@ -34,7 +34,7 @@ fltcstbin(expp, oper, expr)
o1 = (*expp)->FL_ARITH; o1 = (*expp)->FL_ARITH;
o2 = expr->FL_ARITH; o2 = expr->FL_ARITH;
ASSERT(is_fp_cst(*expp) && is_fp_cst(expr)); assert(is_fp_cst(*expp) && is_fp_cst(expr));
switch (oper) { switch (oper) {
case '*': case '*':
flt_mul(&o1, &o2, &o1); flt_mul(&o1, &o2, &o1);

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* IDENTIFIER FIDDLING & SYMBOL TABLE HANDLING */ /* IDENTIFIER FIDDLING & SYMBOL TABLE HANDLING */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "parameters.h" #include "parameters.h"
@ -25,7 +26,6 @@
#include "decspecs.h" #include "decspecs.h"
#include "sizes.h" #include "sizes.h"
#include "Lpars.h" #include "Lpars.h"
#include "assert.h"
extern char options[]; extern char options[];
extern arith NewLocal(); extern arith NewLocal();
@ -88,7 +88,7 @@ declare_idf(ds, dc, lvl)
if (ds->ds_type == 0) { if (ds->ds_type == 0) {
/* at the L_FORMAL1 level there is no type specified yet /* at the L_FORMAL1 level there is no type specified yet
*/ */
ASSERT(lvl == L_FORMAL1); assert(lvl == L_FORMAL1);
type = int_type; /* may change at L_FORMAL2 */ type = int_type; /* may change at L_FORMAL2 */
} }
else { else {
@ -224,7 +224,7 @@ declare_idf(ds, dc, lvl)
So here we hand out local addresses only. So here we hand out local addresses only.
*/ */
if (lvl >= L_LOCAL) { if (lvl >= L_LOCAL) {
ASSERT(sc); assert(sc);
switch (sc) { switch (sc) {
case REGISTER: case REGISTER:
case AUTO: case AUTO:
@ -380,7 +380,7 @@ good_formal(def, idf)
error("%s not in parameter list", idf->id_text); error("%s not in parameter list", idf->id_text);
return 0; return 0;
} }
ASSERT(def->df_sc == FORMAL); /* CJ */ assert(def->df_sc == FORMAL); /* CJ */
return 1; return 1;
} }

View file

@ -6,3 +6,11 @@
#define PRIVATE static /* or not */ #define PRIVATE static /* or not */
#define IMPORT extern #define IMPORT extern
#define EXPORT #define EXPORT
/* Here to avoid creating another header "notreached.h" */
#ifndef NDEBUG
#define NOTREACHED() crash("in %s, %u: unreachable statement reached", \
__FILE__, __LINE__)
#else
#define NOTREACHED()
#endif /* NDEBUG */

View file

@ -6,6 +6,7 @@
/* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */ /* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */
{ {
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "parameters.h" #include "parameters.h"
#ifndef LINT #ifndef LINT
@ -14,6 +15,7 @@
#include "l_em.h" #include "l_em.h"
#include "l_lint.h" #include "l_lint.h"
#endif /* LINT */ #endif /* LINT */
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include <assert.h> #include <assert.h>
#include <flt_arith.h> #include <flt_arith.h>
@ -25,7 +27,6 @@
#include "proto.h" #include "proto.h"
#include "struct.h" #include "struct.h"
#include "field.h" #include "field.h"
#include "assert.h"
#include "Lpars.h" #include "Lpars.h"
#include "sizes.h" #include "sizes.h"
#include "align.h" #include "align.h"
@ -38,7 +39,6 @@
#define con_nullbyte() C_con_ucon("0", (arith)1) #define con_nullbyte() C_con_ucon("0", (arith)1)
#define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT) #define aggregate_type(tp) ((tp)->tp_fund == ARRAY || (tp)->tp_fund == STRUCT)
char *long2str();
char *strncpy(); char *strncpy();
extern char options[]; extern char options[];
static int gen_error; static int gen_error;
@ -548,7 +548,7 @@ check_ival(expp, tp)
C_con_dnam(idf->id_text, expr->VL_VALUE); C_con_dnam(idf->id_text, expr->VL_VALUE);
} }
else { else {
ASSERT(expr->VL_CLASS == Label); assert(expr->VL_CLASS == Label);
C_con_dlb(expr->VL_LBL, expr->VL_VALUE); C_con_dlb(expr->VL_LBL, expr->VL_VALUE);
} }
break; break;
@ -625,7 +625,7 @@ ch_array(tpp, ex)
register int length = ex->SG_LEN, i; register int length = ex->SG_LEN, i;
register char *to, *from, *s; register char *to, *from, *s;
ASSERT(ex->ex_class == String); assert(ex->ex_class == String);
if (tp->tp_size == (arith)-1) { if (tp->tp_size == (arith)-1) {
/* set the dimension */ /* set the dimension */
tp = *tpp = construct_type(ARRAY, tp->tp_up, 0, (arith)length, NO_PROTO); tp = *tpp = construct_type(ARRAY, tp->tp_up, 0, (arith)length, NO_PROTO);
@ -696,7 +696,7 @@ put_bf(tp, val)
register struct sdef *sd = fd->fd_sdef; register struct sdef *sd = fd->fd_sdef;
static struct expr exp; static struct expr exp;
ASSERT(sd); assert(sd);
if (offset == (arith)-1) { if (offset == (arith)-1) {
/* first bitfield in this field */ /* first bitfield in this field */
offset = sd->sd_offset; offset = sd->sd_offset;
@ -737,7 +737,7 @@ valid_type(tp, str)
struct type *tp; struct type *tp;
char *str; char *str;
{ {
ASSERT(tp!=(struct type *)0); assert(tp!=(struct type *)0);
if (tp->tp_size < 0) { if (tp->tp_size < 0) {
error("size of %s unknown", str); error("size of %s unknown", str);
return 0; return 0;
@ -750,7 +750,7 @@ con_int(ex)
{ {
register struct type *tp = ex->ex_type; register struct type *tp = ex->ex_type;
ASSERT(is_cp_cst(ex)); assert(is_cp_cst(ex));
if (tp->tp_unsigned) if (tp->tp_unsigned)
C_con_ucon(long2str((long)ex->VL_VALUE, -10), tp->tp_size); C_con_ucon(long2str((long)ex->VL_VALUE, -10), tp->tp_size);
else if (tp->tp_size == word_size) else if (tp->tp_size == word_size)

View file

@ -11,7 +11,6 @@
#include <alloc.h> /* for st_free */ #include <alloc.h> /* for st_free */
#include "interface.h" #include "interface.h"
#include "assert.h"
#ifdef ANSI #ifdef ANSI
#include <flt_arith.h> #include <flt_arith.h>
#endif /* ANSI */ #endif /* ANSI */

View file

@ -9,9 +9,9 @@
#ifdef LINT #ifdef LINT
#include <assert.h>
#include <alloc.h> /* for st_free */ #include <alloc.h> /* for st_free */
#include "interface.h" #include "interface.h"
#include "assert.h"
#ifdef ANSI #ifdef ANSI
#include <flt_arith.h> #include <flt_arith.h>
#endif /* ANSI */ #endif /* ANSI */
@ -365,7 +365,7 @@ add_expr_state(value, to_state, espp)
{ {
register struct expr_state *esp = *espp; register struct expr_state *esp = *espp;
ASSERT(value.vl_class == Name); assert(value.vl_class == Name);
/* try to find the esp */ /* try to find the esp */
while ( esp while ( esp

View file

@ -9,13 +9,14 @@
#ifdef LINT #ifdef LINT
#include <assert.h>
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include "interface.h" #include "interface.h"
#ifdef ANSI #ifdef ANSI
#include <flt_arith.h> #include <flt_arith.h>
#endif /* ANSI */ #endif /* ANSI */
#include "arith.h" #include "arith.h"
#include "assert.h"
#include "type.h" #include "type.h"
#include "proto.h" #include "proto.h"
#include "declar.h" #include "declar.h"
@ -35,7 +36,6 @@
#include "l_outdef.h" #include "l_outdef.h"
#include "l_class.h" #include "l_class.h"
extern char *bts2str();
extern char *symbol2str(); extern char *symbol2str();
int stat_number = 9999; /* static scope number */ int stat_number = 9999; /* static scope number */
@ -384,7 +384,7 @@ outargs(arg, n)
register struct argument *tmp; register struct argument *tmp;
while (n--) { while (n--) {
ASSERT(arg); assert(arg);
outarg(arg); outarg(arg);
tmp = arg; tmp = arg;
arg = arg->next; arg = arg->next;

View file

@ -9,9 +9,9 @@
#ifdef LINT #ifdef LINT
#include <assert.h>
#include <alloc.h> /* for st_free */ #include <alloc.h> /* for st_free */
#include "interface.h" #include "interface.h"
#include "assert.h"
#ifdef ANSI #ifdef ANSI
#include <flt_arith.h> #include <flt_arith.h>
#endif /* ANSI */ #endif /* ANSI */
@ -179,7 +179,7 @@ lint_end_global(stl)
register struct stack_entry *se = stl->sl_entry; register struct stack_entry *se = stl->sl_entry;
dbg_lint_stack("lint_end_global"); dbg_lint_stack("lint_end_global");
ASSERT(level == L_GLOBAL); assert(level == L_GLOBAL);
while (se) { while (se) {
register struct idf *idf = se->se_idf; register struct idf *idf = se->se_idf;
register struct def *def = idf->id_def; register struct def *def = idf->id_def;
@ -275,7 +275,7 @@ change_state(idf, to_state)
register struct def *def = idf->id_def; register struct def *def = idf->id_def;
register struct auto_def *a = top_ls->ls_current->st_auto_list; register struct auto_def *a = top_ls->ls_current->st_auto_list;
ASSERT(def); assert(def);
switch (to_state) { switch (to_state) {
case SET: case SET:
@ -300,7 +300,7 @@ change_state(idf, to_state)
while (br && br->br_count > def->df_firstbrace) { while (br && br->br_count > def->df_firstbrace) {
br = br->next; br = br->next;
} }
ASSERT(br && def->df_minlevel >= br->br_level); assert(br && def->df_minlevel >= br->br_level);
def->df_minlevel = br->br_level; def->df_minlevel = br->br_level;
} }
@ -340,7 +340,7 @@ add_auto(idf) /* to current state on top of lint_stack */
*/ */
register struct def *def = idf->id_def; register struct def *def = idf->id_def;
ASSERT(def); assert(def);
switch (def->df_sc) { switch (def->df_sc) {
register struct auto_def *a; register struct auto_def *a;
@ -369,7 +369,7 @@ check_autos()
*/ */
register struct auto_def *a = top_ls->ls_current->st_auto_list; register struct auto_def *a = top_ls->ls_current->st_auto_list;
ASSERT(!(a && a->ad_def->df_level > level)); assert(!(a && a->ad_def->df_level > level));
while (a && a->ad_def->df_level == level) { while (a && a->ad_def->df_level == level) {
struct idf *idf = a->ad_idf; struct idf *idf = a->ad_idf;
struct def *def = idf->id_def; struct def *def = idf->id_def;
@ -401,7 +401,7 @@ lint_end_formals()
register struct stack_entry *se = local_level->sl_entry; register struct stack_entry *se = local_level->sl_entry;
dbg_lint_stack("lint_end_formals"); dbg_lint_stack("lint_end_formals");
ASSERT(level == L_FORMAL1); assert(level == L_FORMAL1);
while (se) { while (se) {
register struct def *def = se->se_idf->id_def; register struct def *def = se->se_idf->id_def;
@ -581,10 +581,10 @@ merge_autos(a1, a2, lvl, mode)
a = a2; /* pointer to the result */ a = a2; /* pointer to the result */
while (a1) { while (a1) {
ASSERT(a2); assert(a2);
/* merge the auto_defs for one idf */ /* merge the auto_defs for one idf */
ASSERT(a1->ad_idf == a2->ad_idf); assert(a1->ad_idf == a2->ad_idf);
if (a1->ad_used) if (a1->ad_used)
a2->ad_used = 1; a2->ad_used = 1;
@ -605,7 +605,7 @@ merge_autos(a1, a2, lvl, mode)
a1 = a1->next; a1 = a1->next;
a2 = a2->next; a2 = a2->next;
} }
ASSERT(!a2); assert(!a2);
return a; return a;
} }
@ -806,7 +806,7 @@ end_loop_body()
register struct lint_stack_entry *lse = find_wdf(); register struct lint_stack_entry *lse = find_wdf();
dbg_lint_stack("end_loop_body"); dbg_lint_stack("end_loop_body");
ASSERT(lse == top_ls); assert(lse == top_ls);
if (!lse->ls_current->st_notreached) if (!lse->ls_current->st_notreached)
cont_merge(lse); cont_merge(lse);
} }
@ -816,7 +816,7 @@ end_loop_stmt()
register struct lint_stack_entry *lse = find_wdf(); register struct lint_stack_entry *lse = find_wdf();
dbg_lint_stack("end_loop_stmt"); dbg_lint_stack("end_loop_stmt");
ASSERT(lse == top_ls); assert(lse == top_ls);
if (lse->LS_TEST != TEST_TRUE) if (lse->LS_TEST != TEST_TRUE)
break_merge(lse); break_merge(lse);
@ -958,7 +958,7 @@ lint_case_stmt(dflt)
break; break;
case CASE: case CASE:
ASSERT(top_ls->ls_previous->ls_class == SWITCH); assert(top_ls->ls_previous->ls_class == SWITCH);
if (dflt) { if (dflt) {
cs_entry->ls_previous->LS_DEFAULT_MET = 1; cs_entry->ls_previous->LS_DEFAULT_MET = 1;
} }
@ -1079,7 +1079,7 @@ lint_end_function()
* These auto_defs must be freed and the state must be filled * These auto_defs must be freed and the state must be filled
* with zeros. * with zeros.
*/ */
ASSERT(!top_ls->ls_previous); assert(!top_ls->ls_previous);
free_auto_list(top_ls->ls_current->st_auto_list); free_auto_list(top_ls->ls_current->st_auto_list);
top_ls->ls_current->st_auto_list = 0; top_ls->ls_current->st_auto_list = 0;
top_ls->ls_current->st_notreached = 0; top_ls->ls_current->st_notreached = 0;

View file

@ -5,7 +5,9 @@
/* $Id$ */ /* $Id$ */
/* MAIN PROGRAM */ /* MAIN PROGRAM */
#include <string.h>
#include "parameters.h" #include "parameters.h"
#include <ack_string.h>
#include <system.h> #include <system.h>
#include "idf.h" #include "idf.h"
#include "input.h" #include "input.h"
@ -22,7 +24,6 @@
#include "sizes.h" #include "sizes.h"
#include "align.h" #include "align.h"
#include "macro.h" #include "macro.h"
#include "assert.h"
extern struct tokenname tkidf[]; extern struct tokenname tkidf[];
extern char *symbol2str(); extern char *symbol2str();
@ -443,7 +444,6 @@ preprocess()
case STRING: case STRING:
{ {
char sbuf[1024]; /* a transient buffer */ char sbuf[1024]; /* a transient buffer */
char *bts2str();
print("\"%s\" ", bts2str(dot.tk_bts, dot.tk_len - print("\"%s\" ", bts2str(dot.tk_bts, dot.tk_len -
1, sbuf)); 1, sbuf));

View file

@ -5,6 +5,7 @@
/* $Id$ */ /* $Id$ */
/* P R O T O T Y P E F I D D L I N G */ /* P R O T O T Y P E F I D D L I N G */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#include <alloc.h> #include <alloc.h>
#include "idf.h" #include "idf.h"
@ -22,7 +23,6 @@
#include "declar.h" #include "declar.h"
#include "decspecs.h" #include "decspecs.h"
#include "proto.h" #include "proto.h"
#include "assert.h"
extern char options[]; extern char options[];
@ -65,7 +65,7 @@ add_proto(pl, ds, dc, lvl)
register struct type *type; register struct type *type;
char formal_array = 0; char formal_array = 0;
ASSERT(ds->ds_type != (struct type *)0); assert(ds->ds_type != (struct type *)0);
pl->pl_flag = PL_FORMAL; pl->pl_flag = PL_FORMAL;
type = declare_type(ds->ds_type, dc); type = declare_type(ds->ds_type, dc);

View file

@ -5,12 +5,14 @@
/* $Id$ */ /* $Id$ */
/* M A C R O R E P L A C E M E N T */ /* M A C R O R E P L A C E M E N T */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "parameters.h" #include "parameters.h"
#ifndef NOPP #ifndef NOPP
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include "idf.h" #include "idf.h"
#include "input.h" #include "input.h"
@ -18,7 +20,6 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "assert.h"
#include "replace.h" #include "replace.h"
extern struct idf *GetIdentifier(); extern struct idf *GetIdentifier();
@ -85,7 +86,7 @@ EnableMacros()
{ {
register struct repl *r = ReplaceList, *prev = 0; register struct repl *r = ReplaceList, *prev = 0;
ASSERT(Unstacked > 0); assert(Unstacked > 0);
while(r) { while(r) {
struct repl *nxt = r->next; struct repl *nxt = r->next;
@ -131,7 +132,7 @@ expand_macro(repl, idf)
if (mac->mc_nps != -1) { /* with parameter list */ if (mac->mc_nps != -1) { /* with parameter list */
if (mac->mc_flag & FUNC) { if (mac->mc_flag & FUNC) {
/* the following assertion won't compile: /* the following assertion won't compile:
ASSERT(!strcmp("defined", idf->id_text)); assert(!strcmp("defined", idf->id_text));
expand the assert macro by hand (??? dirty, temporary) expand the assert macro by hand (??? dirty, temporary)
*/ */
#ifdef DEBUG #ifdef DEBUG
@ -199,7 +200,7 @@ expand_defined(repl)
} }
ChPushBack(ch); ChPushBack(ch);
id = GetIdentifier(0); id = GetIdentifier(0);
ASSERT(id || class(ch) == STELL); assert(id || class(ch) == STELL);
ch = GetChar(); ch = GetChar();
ch = skipspaces(ch, 0); ch = skipspaces(ch, 0);
if (parens && ch != ')') error(") missing"); if (parens && ch != ')') error(") missing");
@ -514,7 +515,6 @@ macro_func(idef)
*/ */
register struct macro *mac = idef->id_macro; register struct macro *mac = idef->id_macro;
static char FilNamBuf[PATHLENGTH]; static char FilNamBuf[PATHLENGTH];
char *long2str();
switch (idef->id_text[2]) { switch (idef->id_text[2]) {
case 'F': /* __FILE__ */ case 'F': /* __FILE__ */
@ -571,7 +571,7 @@ macro2buffer(repl, idf, args)
int func = idf->id_macro->mc_nps != -1; int func = idf->id_macro->mc_nps != -1;
char *stringify(); char *stringify();
ASSERT(ptr[idf->id_macro->mc_length] == '\0'); assert(ptr[idf->id_macro->mc_length] == '\0');
while (*ptr) { while (*ptr) {
if (*ptr == '\'' || *ptr == '"') { if (*ptr == '\'' || *ptr == '"') {
register int delim = *ptr; register int delim = *ptr;
@ -624,7 +624,7 @@ macro2buffer(repl, idf, args)
register int n = *ptr++ & 0177; register int n = *ptr++ & 0177;
register char *p; register char *p;
ASSERT(n > 0); assert(n > 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
if (p) { /* else macro argument missing */ if (p) { /* else macro argument missing */
while (is_wsp(*p)) p++; while (is_wsp(*p)) p++;
@ -660,7 +660,7 @@ macro2buffer(repl, idf, args)
register int n = *ptr++ & 0177; register int n = *ptr++ & 0177;
register char *p, *q; register char *p, *q;
ASSERT(n > 0); assert(n > 0);
/* This is VERY dirty, we look ahead for the /* This is VERY dirty, we look ahead for the
## operator. If it's found we use the raw ## operator. If it's found we use the raw
@ -718,7 +718,7 @@ stringify(repl, ptr, args)
register int n = *ptr++ & 0177; register int n = *ptr++ & 0177;
register char *p; register char *p;
ASSERT(n != 0); assert(n != 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
add2repl(repl, '"'); add2repl(repl, '"');
while (*p) { while (*p) {
@ -761,7 +761,7 @@ add2repl(repl, ch)
{ {
register int index = repl->r_ptr - repl->r_text; register int index = repl->r_ptr - repl->r_text;
ASSERT(index < repl->r_size); assert(index < repl->r_size);
if (index + 2 >= repl->r_size) { if (index + 2 >= repl->r_size) {
repl->r_text = Realloc(repl->r_text, (unsigned) (repl->r_size <<= 1)); repl->r_text = Realloc(repl->r_text, (unsigned) (repl->r_size <<= 1));
repl->r_ptr = repl->r_text + index; repl->r_ptr = repl->r_text + index;
@ -785,7 +785,7 @@ stash(repl, ch, stashraw)
register int index = args->a_expptr - args->a_expbuf; register int index = args->a_expptr - args->a_expbuf;
if (stashraw >= 0) { if (stashraw >= 0) {
ASSERT(index < args->a_expsize); assert(index < args->a_expsize);
if (index + 1 >= args->a_expsize) { if (index + 1 >= args->a_expsize) {
args->a_expbuf = Realloc(args->a_expbuf, args->a_expbuf = Realloc(args->a_expbuf,
(unsigned) (args->a_expsize <<= 1)); (unsigned) (args->a_expsize <<= 1));
@ -796,7 +796,7 @@ stash(repl, ch, stashraw)
if (stashraw) { if (stashraw) {
index = args->a_rawptr - args->a_rawbuf; index = args->a_rawptr - args->a_rawbuf;
ASSERT(index < args->a_rawsize); assert(index < args->a_rawsize);
if (index + 1 >= args->a_rawsize) { if (index + 1 >= args->a_rawsize) {
args->a_rawbuf = Realloc(args->a_rawbuf, args->a_rawbuf = Realloc(args->a_rawbuf,
(unsigned)(args->a_rawsize <<= 1)); (unsigned)(args->a_rawsize <<= 1));

View file

@ -19,7 +19,6 @@
#include "Lpars.h" #include "Lpars.h"
#include "align.h" #include "align.h"
#include "level.h" #include "level.h"
#include "assert.h"
#include "sizes.h" #include "sizes.h"
/* Type of previous selector declared with a field width specified, /* Type of previous selector declared with a field width specified,

View file

@ -5,12 +5,14 @@
/* $Id$ */ /* $Id$ */
/* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */ /* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */
#include <assert.h>
#include "parameters.h" #include "parameters.h"
#ifndef LINT #ifndef LINT
#include <em.h> #include <em.h>
#else #else
#include "l_em.h" #include "l_em.h"
#endif /* LINT */ #endif /* LINT */
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include "Lpars.h" #include "Lpars.h"
#include "label.h" #include "label.h"
@ -18,7 +20,6 @@
#include "arith.h" #include "arith.h"
#include "switch.h" #include "switch.h"
#include "code.h" #include "code.h"
#include "assert.h"
#include "expr.h" #include "expr.h"
#include "type.h" #include "type.h"
#include "sizes.h" #include "sizes.h"
@ -84,8 +85,6 @@ code_startswitch(expp)
C_bra(l_table); /* goto start of switch_table */ C_bra(l_table); /* goto start of switch_table */
} }
extern char *long2str();
code_endswitch() code_endswitch()
{ {
register struct switch_hdr *sh = switch_stack; register struct switch_hdr *sh = switch_stack;
@ -123,7 +122,7 @@ code_endswitch()
size); size);
ce = sh->sh_entries; ce = sh->sh_entries;
for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) {
ASSERT(ce); assert(ce);
if (val == ce->ce_value) { if (val == ce->ce_value) {
C_rom_ilb(ce->ce_label); C_rom_ilb(ce->ce_label);
ce = ce->next; ce = ce->next;
@ -167,7 +166,7 @@ code_case(expr)
register struct case_entry *ce; register struct case_entry *ce;
register struct switch_hdr *sh = switch_stack; register struct switch_hdr *sh = switch_stack;
ASSERT(is_cp_cst(expr)); assert(is_cp_cst(expr));
if (sh == 0) { if (sh == 0) {
error("case statement not in switch"); error("case statement not in switch");
return; return;
@ -220,7 +219,7 @@ code_case(expr)
} }
} }
else { else {
ASSERT(c2); assert(c2);
ce->next = (struct case_entry *) 0; ce->next = (struct case_entry *) 0;
c2->next = ce; c2->next = ce;
} }

View file

@ -7,6 +7,7 @@
#include "parameters.h" #include "parameters.h"
#include <string.h>
#include <alloc.h> #include <alloc.h>
#include "input.h" #include "input.h"
#include "arith.h" #include "arith.h"

View file

@ -89,6 +89,9 @@ cprogram {
"+tabgen_c" "+tabgen_c"
), ),
deps = { deps = {
"./LLlex.h", "./arith.h", "./bits.h", "./class.h",
"./file_info.h", "./idf.h", "./input.h",
"./parameters.h",
"+llgen", "+llgen",
"+macro_h", "+macro_h",
"+replace_h", "+replace_h",

View file

@ -5,7 +5,9 @@
/* $Id$ */ /* $Id$ */
/* PREPROCESSOR: CONTROLLINE INTERPRETER */ /* PREPROCESSOR: CONTROLLINE INTERPRETER */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
@ -13,7 +15,6 @@
#include "input.h" #include "input.h"
#include "parameters.h" #include "parameters.h"
#include <assert.h>
#include <alloc.h> #include <alloc.h>
#include "class.h" #include "class.h"
#include "macro.h" #include "macro.h"

View file

@ -5,11 +5,12 @@
/* $Id$ */ /* $Id$ */
/* MAIN PROGRAM */ /* MAIN PROGRAM */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "parameters.h" #include "parameters.h"
#include <alloc.h> #include <alloc.h>
#include <assert.h>
#include <system.h> #include <system.h>
#include "arith.h" #include "arith.h"
#include "file_info.h" #include "file_info.h"

View file

@ -5,10 +5,12 @@
/* $Id$ */ /* $Id$ */
/* M A C R O R E P L A C E M E N T */ /* M A C R O R E P L A C E M E N T */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ack_string.h>
#include "parameters.h" #include "parameters.h"
#include "alloc.h" #include "alloc.h"
#include "idf.h" #include "idf.h"
@ -17,7 +19,6 @@
#include "arith.h" #include "arith.h"
#include "LLlex.h" #include "LLlex.h"
#include "class.h" #include "class.h"
#include "assert.h"
#include "replace.h" #include "replace.h"
extern char *GetIdentifier(); extern char *GetIdentifier();
@ -506,7 +507,6 @@ macro_func(idef)
*/ */
register struct macro *mac = idef->id_macro; register struct macro *mac = idef->id_macro;
static char FilNamBuf[PATHLENGTH]; static char FilNamBuf[PATHLENGTH];
char *long2str();
switch (idef->id_text[2]) { switch (idef->id_text[2]) {
case 'F': /* __FILE__ */ case 'F': /* __FILE__ */

View file

@ -17,7 +17,7 @@
#include <em_arith.h> #include <em_arith.h>
#include <em_label.h> #include <em_label.h>
#include <stdlib.h> #include <stdlib.h>
#include <astring.h> #include <string.h>
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
@ -59,15 +59,24 @@ char*
return ""; return "";
} }
STATIC STATIC int
GetFile(name) char* name; GetFile(name) char* name;
{ {
/* Try to find a file with basename "name" and extension ".def", /* Try to find a file with basename "name" and extension ".def",
in the directories mentioned in "DEFPATH". in the directories mentioned in "DEFPATH".
*/ */
char* buf = aprintf("%s.def", name); size_t len;
int found;
char *buf;
len = strlen(name);
buf = Malloc(len + 5);
memcpy(buf, name, len);
memcpy(buf + len, ".def", 5);
DEFPATH[0] = WorkingDir; DEFPATH[0] = WorkingDir;
if (!InsertFile(buf, DEFPATH, &(FileName))) found = InsertFile(buf, DEFPATH, &(FileName));
free(buf);
if (!found)
{ {
error("could not find a DEFINITION MODULE for \"%s\"", name); error("could not find a DEFINITION MODULE for \"%s\"", name);
return 0; return 0;

View file

@ -13,6 +13,7 @@
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include <em_arith.h> #include <em_arith.h>
#include <em_label.h> #include <em_label.h>
@ -455,7 +456,6 @@ genrck(tp)
arith lb, ub; arith lb, ub;
register label ol; register label ol;
arith size = tp->tp_size; arith size = tp->tp_size;
extern char *long2str();
register t_type *btp = BaseType(tp); register t_type *btp = BaseType(tp);
if (size < word_size) size = word_size; if (size < word_size) size = word_size;

View file

@ -5,6 +5,7 @@
#include "parameters.h" #include "parameters.h"
#include "debug.h" #include "debug.h"
#include <ack_string.h>
#include <alloc.h> #include <alloc.h>
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include <em_arith.h>
@ -475,7 +476,7 @@ CutSize(expr)
InitCst() InitCst()
{ {
extern char *long2str(), *Salloc(); extern char *Salloc();
register int i = 0; register int i = 0;
register arith bt = (arith)0; register arith bt = (arith)0;

View file

@ -5,6 +5,7 @@
/* next line DEBUG */ /* next line DEBUG */
#include "debug.h" #include "debug.h"
#include <stddef.h>
#include <alloc.h> #include <alloc.h>
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include <em_arith.h>
@ -21,7 +22,7 @@
#include "scope.h" #include "scope.h"
#include "type.h" #include "type.h"
#define PC_BUFSIZ (sizeof(struct file) - (int)((struct file *)0)->bufadr) #define PC_BUFSIZ (sizeof(struct file) - offsetof(struct file, bufadr))
int proclevel = 0; /* nesting level of procedures */ int proclevel = 0; /* nesting level of procedures */
int parlevel = 0; /* nesting level of parametersections */ int parlevel = 0; /* nesting level of parametersections */

View file

@ -1,5 +1,6 @@
/* H I G H L E V E L S Y M B O L E N T R Y */ /* H I G H L E V E L S Y M B O L E N T R Y */
#include <string.h>
#include <alloc.h> #include <alloc.h>
#include <assert.h> #include <assert.h>
#include <em_arith.h> #include <em_arith.h>

View file

@ -1,5 +1,6 @@
/* S T A T E M E N T S */ /* S T A T E M E N T S */
{ {
#include <string.h>
#include "parameters.h" #include "parameters.h"
#include <alloc.h> #include <alloc.h>
#include <em.h> #include <em.h>

View file

@ -15,6 +15,7 @@ static char rcs_mh[]= ID_MH ;
* machine dependent back end routines for the Intel 80386 * machine dependent back end routines for the Intel 80386
*/ */
void
con_part(sz,w) register sz; word w; { con_part(sz,w) register sz; word w; {
while (part_size % sz) while (part_size % sz)
@ -32,6 +33,7 @@ con_part(sz,w) register sz; word w; {
part_size += sz; part_size += sz;
} }
void
con_mult(sz) word sz; { con_mult(sz) word sz; {
long l; long l;
@ -92,6 +94,7 @@ long si_off;
long di_off; long di_off;
int firstreg; int firstreg;
int
regscore(off, size, typ, score, totyp) regscore(off, size, typ, score, totyp)
long off; long off;
{ {
@ -104,6 +107,7 @@ regscore(off, size, typ, score, totyp)
return score; return score;
} }
void
i_regsave() i_regsave()
{ {
si_off = -1; si_off = -1;
@ -111,6 +115,7 @@ i_regsave()
firstreg = 0; firstreg = 0;
} }
void
f_regsave() f_regsave()
{ {
if (si_off != di_off) { if (si_off != di_off) {
@ -133,8 +138,9 @@ f_regsave()
fprintf(codefile, "mov edi,%ld(ebp)\n", di_off); fprintf(codefile, "mov edi,%ld(ebp)\n", di_off);
} }
void
regsave(regstr, off, size) regsave(regstr, off, size)
char *regstr; const char *regstr;
long off; long off;
{ {
if (strcmp(regstr, "esi") == 0) { if (strcmp(regstr, "esi") == 0) {
@ -147,6 +153,7 @@ regsave(regstr, off, size)
} }
} }
void
regreturn() regreturn()
{ {
if (firstreg == 1) { if (firstreg == 1) {
@ -165,6 +172,7 @@ regreturn()
static int gdb_flag = 0; static int gdb_flag = 0;
static char *fp_hook_nam; static char *fp_hook_nam;
void
mach_option(s) mach_option(s)
char *s; char *s;
{ {

View file

@ -12,6 +12,9 @@ static char rcsid[]= "$Id$" ;
* machine dependent back end routines for the Intel 8080. * machine dependent back end routines for the Intel 8080.
*/ */
#include <stdlib.h> /* atol */
void
con_part(sz,w) register sz; word w; { con_part(sz,w) register sz; word w; {
while (part_size % sz) while (part_size % sz)
@ -30,8 +33,7 @@ con_part(sz,w) register sz; word w; {
part_size += sz; part_size += sz;
} }
long atol(); void
con_mult(sz) word sz; { con_mult(sz) word sz; {
if (argval != 4) if (argval != 4)
@ -39,6 +41,7 @@ con_mult(sz) word sz; {
fprintf(codefile,".data4\t%ld\n",atol(str)); fprintf(codefile,".data4\t%ld\n",atol(str));
} }
void
con_float() { con_float() {
static int warning_given; static int warning_given;
int i = argval; int i = argval;

View file

@ -13,6 +13,7 @@ static char rcs_mh[]= ID_MH ;
* machine dependent back end routines for the Intel 8086 * machine dependent back end routines for the Intel 8086
*/ */
void
con_part(sz,w) register sz; word w; { con_part(sz,w) register sz; word w; {
while (part_size % sz) while (part_size % sz)
@ -31,6 +32,7 @@ con_part(sz,w) register sz; word w; {
part_size += sz; part_size += sz;
} }
void
con_mult(sz) word sz; { con_mult(sz) word sz; {
long l; long l;
@ -83,6 +85,7 @@ long si_off;
long di_off; long di_off;
int firstreg; int firstreg;
int
regscore(off, size, typ, score, totyp) regscore(off, size, typ, score, totyp)
long off; long off;
{ {
@ -95,6 +98,7 @@ regscore(off, size, typ, score, totyp)
return score; return score;
} }
void
i_regsave() i_regsave()
{ {
si_off = -1; si_off = -1;
@ -102,6 +106,7 @@ i_regsave()
firstreg = 0; firstreg = 0;
} }
void
f_regsave() f_regsave()
{ {
if (si_off != di_off) { if (si_off != di_off) {
@ -130,8 +135,9 @@ f_regsave()
fprintf(codefile, "mov si,%ld(bp)\n", si_off); fprintf(codefile, "mov si,%ld(bp)\n", si_off);
} }
void
regsave(regstr, off, size) regsave(regstr, off, size)
char *regstr; const char *regstr;
long off; long off;
{ {
if (strcmp(regstr, "si") == 0) { if (strcmp(regstr, "si") == 0) {
@ -144,6 +150,7 @@ regsave(regstr, off, size)
} }
} }
void
regreturn() regreturn()
{ {
if (firstreg == 1) { if (firstreg == 1) {

View file

@ -17,6 +17,7 @@
#include <stb.h> #include <stb.h>
void
con_part(sz,w) register sz; word w; { con_part(sz,w) register sz; word w; {
while (part_size % sz) while (part_size % sz)
@ -43,6 +44,7 @@ con_part(sz,w) register sz; word w; {
part_size += sz; part_size += sz;
} }
void
con_mult(sz) word sz; { con_mult(sz) word sz; {
if (sz != 4) if (sz != 4)
@ -57,6 +59,7 @@ con_mult(sz) word sz; {
#define FL_MSB_AT_LOW_ADDRESS 1 #define FL_MSB_AT_LOW_ADDRESS 1
#include <con_float> #include <con_float>
int
regscore(off,size,typ,score,totyp) regscore(off,size,typ,score,totyp)
long off; long off;
{ {
@ -93,6 +96,7 @@ struct regsav_t {
int regnr; int regnr;
void
i_regsave() i_regsave()
{ {
regnr = 0; regnr = 0;
@ -100,6 +104,7 @@ i_regsave()
full nlocals; full nlocals;
void
regreturn() regreturn()
{ {
register struct regsav_t *p; register struct regsav_t *p;
@ -127,6 +132,7 @@ regreturn()
fputs("unlk a6\nrts\n", codefile); fputs("unlk a6\nrts\n", codefile);
} }
void
f_regsave() f_regsave()
{ {
register struct regsav_t *p; register struct regsav_t *p;
@ -176,8 +182,9 @@ f_regsave()
} }
} }
void
regsave(s,off,size) regsave(s,off,size)
char *s; const char *s;
long off; long off;
{ {
assert (regnr < 9); assert (regnr < 9);
@ -196,6 +203,7 @@ prolog(n) full n; {
#ifdef MACH_OPTIONS #ifdef MACH_OPTIONS
static int gdb_flag = 0; static int gdb_flag = 0;
void
mach_option(s) mach_option(s)
char *s; char *s;
{ {

View file

@ -13,6 +13,7 @@
static long framesize; static long framesize;
void
con_part(int sz, word w) con_part(int sz, word w)
{ {
while (part_size % sz) while (part_size % sz)
@ -34,6 +35,7 @@ con_part(int sz, word w)
part_size += sz; part_size += sz;
} }
void
con_mult(word sz) con_mult(word sz)
{ {
@ -146,6 +148,7 @@ regscore(long offset, int size, int type, int frequency, int totype)
/* Initialise regvar system for one function. */ /* Initialise regvar system for one function. */
void
i_regsave(void) i_regsave(void)
{ {
int i; int i;
@ -163,6 +166,7 @@ i_regsave(void)
/* Mark a register as being saved. */ /* Mark a register as being saved. */
void
regsave(const char* regname, long offset, int size) regsave(const char* regname, long offset, int size)
{ {
int regnum = atoi(regname + 1); int regnum = atoi(regname + 1);
@ -223,6 +227,7 @@ saveloadregs(const char* ops, const char* opm, const char *opf)
} }
} }
void
f_regsave(void) f_regsave(void)
{ {
int reg; int reg;
@ -248,6 +253,7 @@ f_regsave(void)
/* Restore all saved registers. */ /* Restore all saved registers. */
void
regreturn(void) regreturn(void)
{ {
saveloadregs("lwz", "lmw", "lfd"); saveloadregs("lwz", "lmw", "lfd");

View file

@ -21,6 +21,8 @@ definerule("build_as",
srcs = { "mach/proto/as/comm2.y" }, srcs = { "mach/proto/as/comm2.y" },
outleaf = "comm2.y", outleaf = "comm2.y",
deps = { deps = {
"mach/proto/as/comm0.h",
"mach/proto/as/comm1.h",
"h+emheaders", "h+emheaders",
archlib, archlib,
}, },

View file

@ -105,16 +105,16 @@ _include "out.h"
#include "out.h" #include "out.h"
#endif #endif
#if DEBUG == 0 /*
#define assert(ex) /* nothing */ * Define assert(). Disable assertions if DEBUG == 0.
*/
#if DEBUG == 0 && !defined(NDEBUG)
#define NDEBUG
#endif #endif
#ifdef _include
#if DEBUG == 1 _include <assert.h>
#define assert(ex) {if (!(ex)) assert1();} #else
#endif #include <assert.h>
#if DEBUG == 2
#define assert(ex) {if (!(ex)) assert2(__FILE__, __LINE__);}
#endif #endif
#define CTRL(x) ((x) & 037) #define CTRL(x) ((x) & 037)

View file

@ -104,6 +104,11 @@ extern struct outhead outhead;
extern int curr_token; extern int curr_token;
/* forward function declarations */ /* forward function declarations */
/* comm2.y */
int yyparse(void);
/* comm4.c */
void stop(void);
void newmodule(const char *);
/* comm5.c */ /* comm5.c */
int yylex(void); int yylex(void);
void putval(int); void putval(int);
@ -112,20 +117,52 @@ int nextchar(void);
#ifdef ASLD #ifdef ASLD
char *readident(int); char *readident(int);
#endif #endif
int hash(char *); int hash(const char *);
item_t *item_search(char *); item_t *item_search(const char *);
void item_insert(item_t *, int); void item_insert(item_t *, int);
item_t *item_alloc(int); item_t *item_alloc(int);
item_t *fb_alloc(int); item_t *fb_alloc(int);
item_t *fb_shift(int); item_t *fb_shift(int);
/* comm6.c */
void newequate(item_t *, int);
void newident(item_t *, int);
void newlabel(item_t *);
void newsect(item_t *);
void newbase(valu_t);
void newcomm(item_t *, valu_t);
void switchsect(int);
void align(valu_t);
#ifdef RELOCATION
void newrelo(int, int);
#endif
long new_string(const char *);
void newsymb(const char *, int, int, valu_t);
/* comm7.c */ /* comm7.c */
valu_t load(); valu_t load(const item_t *);
char *remember(); int store(item_t *, valu_t);
FILE *ffcreat(); char *remember(char *);
FILE *fftemp(); int combine(int, int, int);
#ifdef LISTING
int printx(int, valu_t);
void listline(int);
#endif
#ifdef THREE_PASS
int small(int, int);
#endif
void emit1(int);
void emit2(int);
void emit4(long);
void emitx(valu_t, int);
void emitstr(int);
void ffreopen(char *, FILE *);
FILE *ffcreat(char *);
FILE *fftemp(char *, char *);
void yyerror(const char *);
void nosect(void);
void fatal(const char *, ...); void fatal(const char *, ...);
void serror(const char *, ...); void serror(const char *, ...);
void warning(const char *, ...); void warning(const char *, ...);
void nofit(void);
/* ========== Machine dependent C declarations ========== */ /* ========== Machine dependent C declarations ========== */

View file

@ -15,15 +15,23 @@
#include "comm0.h" #include "comm0.h"
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
#include <object.h>
extern YYSTYPE yylval; extern YYSTYPE yylval;
void setupoutput(); static void pass_1(int, char **);
void commfinish(); #ifdef ASLD
static void archive(void);
static int needed(void);
#endif
static void parse(char *);
static void pass_23(int);
static void setupoutput(void);
static void commfinish(void);
/* ========== Machine independent C routines ========== */ /* ========== Machine independent C routines ========== */
void stop() { void stop(void) {
#if DEBUG < 2 #if DEBUG < 2
unlink(temppath); unlink(temppath);
#ifdef LISTING #ifdef LISTING
@ -33,11 +41,11 @@ void stop() {
exit(nerrors != 0); exit(nerrors != 0);
} }
main(argc, argv) int
char **argv; main(int argc, char **argv)
{ {
register char *p; char *p;
register i; int i;
static char sigs[] = { static char sigs[] = {
SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0 SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0
}; };
@ -130,15 +138,15 @@ char **argv;
/* ---------- pass 1: arguments, modules, archives ---------- */ /* ---------- pass 1: arguments, modules, archives ---------- */
pass_1(argc, argv) static void
char **argv; pass_1(int argc, char **argv)
{ {
register char *p; char *p;
register item_t *ip; item_t *ip;
#ifdef ASLD #ifdef ASLD
char armagic[2]; char armagic[2];
#else #else
register nfile = 0; int nfile = 0;
#endif #endif
#ifdef THREE_PASS #ifdef THREE_PASS
@ -198,7 +206,7 @@ char **argv;
machfinish(PASS_1); machfinish(PASS_1);
#ifdef ASLD #ifdef ASLD
if (unresolved) { if (unresolved) {
register int i; int i;
nerrors++; nerrors++;
fflush(stdout); fflush(stdout);
@ -224,8 +232,9 @@ char **argv;
#ifdef ASLD #ifdef ASLD
archive() { static void
register long offset; archive(void) {
long offset;
struct ar_hdr header; struct ar_hdr header;
char getsize[AR_TOTAL]; char getsize[AR_TOTAL];
@ -257,14 +266,15 @@ archive() {
archmode = 0; archmode = 0;
} }
needed() static int
needed(void)
{ {
register c, first; int c, first;
register item_t *ip; item_t *ip;
register need; int need;
#ifdef LISTING #ifdef LISTING
register save; int save;
save = listflag; listflag = 0; save = listflag; listflag = 0;
#endif #endif
@ -309,12 +319,12 @@ needed()
} }
#endif /* ASLD */ #endif /* ASLD */
parse(s) static void
char *s; parse(char *s)
{ {
register i; int i;
register item_t *ip; item_t *ip;
register char *p; char *p;
for (p = s; *p; ) for (p = s; *p; )
if (*p++ == '/') if (*p++ == '/')
@ -374,13 +384,14 @@ char *s;
} }
} }
pass_23(n) static void
pass_23(int n)
{ {
register i; int i;
#ifdef ASLD #ifdef ASLD
register ADDR_T base = 0; ADDR_T base = 0;
#endif #endif
register sect_t *sp; sect_t *sp;
if (nerrors) if (nerrors)
stop(); stop();
@ -433,8 +444,8 @@ pass_23(n)
machfinish(n); machfinish(n);
} }
newmodule(s) void
char *s; newmodule(const char *s)
{ {
static char nmbuf[STRINGMAX]; static char nmbuf[STRINGMAX];
@ -461,13 +472,13 @@ char *s;
#endif #endif
} }
void static void
setupoutput() setupoutput(void)
{ {
register sect_t *sp; sect_t *sp;
register long off; long off;
struct outsect outsect; struct outsect outsect;
register struct outsect *pos = &outsect; struct outsect *pos = &outsect;
if (! wr_open(aoutpath)) { if (! wr_open(aoutpath)) {
fatal("can't create %s", aoutpath); fatal("can't create %s", aoutpath);
@ -497,16 +508,16 @@ setupoutput()
outhead.oh_nchar = off; /* see newsymb() */ outhead.oh_nchar = off; /* see newsymb() */
} }
void static void
commfinish() commfinish(void)
{ {
#ifndef ASLD #ifndef ASLD
register int i; int i;
#endif #endif
register struct common_t *cp; struct common_t *cp;
register item_t *ip; item_t *ip;
register sect_t *sp; sect_t *sp;
register valu_t addr; valu_t addr;
switchsect(S_UND); switchsect(S_UND);
/* /*

View file

@ -17,7 +17,7 @@ static int inident(int);
static int innumber(int); static int innumber(int);
static int instring(int); static int instring(int);
static int inescape(void); static int inescape(void);
static int infbsym(char *); static int infbsym(const char *);
int int
yylex(void) yylex(void)
@ -85,9 +85,9 @@ yylex(void)
void void
putval(int c) putval(int c)
{ {
register valu_t v; valu_t v;
register n = 0; int n = 0;
register char *p = 0; char *p = 0;
assert(c == (c & 0xffff)); assert(c == (c & 0xffff));
switch (c) { switch (c) {
@ -163,9 +163,9 @@ putval(int c)
int int
getval(int c) getval(int c)
{ {
register n = 0; int n = 0;
register valu_t v; valu_t v;
register char *p = 0; char *p = 0;
switch (c) { switch (c) {
case CODE1: case CODE1:
@ -229,7 +229,7 @@ getval(int c)
int int
nextchar(void) nextchar(void)
{ {
register c; int c;
if (peekc != -1) { if (peekc != -1) {
c = peekc; c = peekc;
@ -254,7 +254,7 @@ nextchar(void)
static void static void
readcode(int n) readcode(int n)
{ {
register c; int c;
yylval.y_valu = 0; yylval.y_valu = 0;
do { do {
@ -283,8 +283,9 @@ induo(int c)
('>'<<8) | '>', OP_RR, ('>'<<8) | '>', OP_RR,
('|'<<8) | '|', OP_OO, ('|'<<8) | '|', OP_OO,
('&'<<8) | '&', OP_AA, ('&'<<8) | '&', OP_AA,
0 /* terminates array */
}; };
register short *p; short *p;
c = (c<<8) | nextchar(); c = (c<<8) | nextchar();
for (p = duo; *p; p++) for (p = duo; *p; p++)
@ -299,9 +300,9 @@ static char name[NAMEMAX+1];
static int static int
inident(int c) inident(int c)
{ {
register char *p = name; char *p = name;
register item_t *ip; item_t *ip;
register n = NAMEMAX; int n = NAMEMAX;
do { do {
if (--n >= 0) if (--n >= 0)
@ -330,8 +331,8 @@ inident(int c)
char * char *
readident(int c) readident(int c)
{ {
register n = NAMEMAX; int n = NAMEMAX;
register char *p = name; char *p = name;
do { do {
if (--n >= 0) if (--n >= 0)
@ -347,8 +348,8 @@ readident(int c)
static int static int
innumber(int c) innumber(int c)
{ {
register char *p; char *p;
register radix; int radix;
static char num[20+1]; static char num[20+1];
p = num; p = num;
@ -394,8 +395,8 @@ innumber(int c)
static int static int
instring(int termc) instring(int termc)
{ {
register char *p; char *p;
register c; int c;
static int maxstring = 0; static int maxstring = 0;
if (! maxstring) { if (! maxstring) {
@ -434,7 +435,7 @@ instring(int termc)
static int static int
inescape(void) inescape(void)
{ {
register c, j, r; int c, j, r;
c = nextchar(); c = nextchar();
if (c >= '0' && c <= '7') { if (c >= '0' && c <= '7') {
@ -463,10 +464,10 @@ inescape(void)
} }
static int static int
infbsym(char *p) infbsym(const char *p)
{ {
register lab; int lab;
register item_t *ip; item_t *ip;
lab = *p++ - '0'; lab = *p++ - '0';
if ((unsigned)lab < 10) { if ((unsigned)lab < 10) {
@ -490,10 +491,10 @@ ok:
} }
int int
hash(char *p) hash(const char *p)
{ {
register unsigned short h; unsigned short h;
register c; int c;
h = 0; h = 0;
while (c = *p++) { while (c = *p++) {
@ -504,10 +505,10 @@ hash(char *p)
} }
item_t * item_t *
item_search(char *p) item_search(const char *p)
{ {
register h; int h;
register item_t *ip; item_t *ip;
for (h = hash(p); h < H_TOTAL; h += H_SIZE) { for (h = hash(p); h < H_TOTAL; h += H_SIZE) {
ip = hashtab[h]; ip = hashtab[h];
@ -532,8 +533,8 @@ item_insert(item_t *ip, int h)
item_t * item_t *
item_alloc(int typ) item_alloc(int typ)
{ {
register item_t *ip; item_t *ip;
static nleft = 0; static int nleft = 0;
static item_t *next; static item_t *next;
if (--nleft < 0) { if (--nleft < 0) {
@ -553,7 +554,7 @@ item_alloc(int typ)
item_t * item_t *
fb_alloc(int lab) fb_alloc(int lab)
{ {
register item_t *ip, *p; item_t *ip, *p;
ip = item_alloc(S_UND); ip = item_alloc(S_UND);
p = fb_ptr[FB_TAIL+lab]; p = fb_ptr[FB_TAIL+lab];
@ -568,7 +569,7 @@ fb_alloc(int lab)
item_t * item_t *
fb_shift(int lab) fb_shift(int lab)
{ {
register item_t *ip; item_t *ip;
ip = fb_ptr[FB_FORW+lab]; ip = fb_ptr[FB_FORW+lab];
if (ip == 0) if (ip == 0)

View file

@ -11,14 +11,12 @@
#include "comm0.h" #include "comm0.h"
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
#include <object.h>
void switchsect(); static void new_common(item_t *);
void newsymb();
void newident();
newequate(ip, typ) void
register item_t *ip; newequate(item_t *ip, int typ)
register int typ;
{ {
typ &= ~S_EXT; typ &= ~S_EXT;
if (typ & S_COM) if (typ & S_COM)
@ -39,10 +37,9 @@ register int typ;
} }
void void
newident(ip, typ) newident(item_t *ip, int typ)
register item_t *ip;
{ {
register flag; int flag;
#ifdef GENLAB #ifdef GENLAB
static char genlab[] = GENLAB; static char genlab[] = GENLAB;
#endif /* GENLAB */ #endif /* GENLAB */
@ -80,13 +77,10 @@ register item_t *ip;
} }
void void
newlabel(ip) newlabel(item_t *ip)
register item_t *ip;
{ {
#if DEBUG != 0 #if defined(THREE_PASS) && !defined(NDEBUG)
#ifdef THREE_PASS ADDR_T oldval = ip->i_valu;
register ADDR_T oldval = ip->i_valu;
#endif
#endif #endif
if (DOTSCT == NULL) if (DOTSCT == NULL)
@ -100,11 +94,11 @@ register item_t *ip;
#endif #endif
} }
newsect(ip) void
register item_t *ip; newsect(item_t *ip)
{ {
register int typ; int typ;
register sect_t *sp = NULL; sect_t *sp = NULL;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if (typ == S_UND) { if (typ == S_UND) {
@ -138,11 +132,11 @@ register item_t *ip;
} }
/*ARGSUSED*/ /*ARGSUSED*/
newbase(base) void
valu_t base; newbase(valu_t base)
{ {
#ifdef ASLD #ifdef ASLD
register sect_t *sp; sect_t *sp;
if ((sp = DOTSCT) == NULL) if ((sp = DOTSCT) == NULL)
nosect(); nosect();
@ -166,9 +160,8 @@ valu_t base;
* - maximum length of .comm is recorded in i_valu during PASS_1 * - maximum length of .comm is recorded in i_valu during PASS_1
* - i_valu is used for relocation info during PASS_3 * - i_valu is used for relocation info during PASS_3
*/ */
newcomm(ip, val) void
register item_t *ip; newcomm(item_t *ip, valu_t val)
valu_t val;
{ {
if (pass == PASS_1) { if (pass == PASS_1) {
if (DOTSCT == NULL) if (DOTSCT == NULL)
@ -190,10 +183,9 @@ valu_t val;
} }
void void
switchsect(newtyp) switchsect(int newtyp)
int newtyp;
{ {
register sect_t *sp; sect_t *sp;
if (sp = DOTSCT) if (sp = DOTSCT)
sp->s_size = DOTVAL - sp->s_base; sp->s_size = DOTVAL - sp->s_base;
@ -209,11 +201,11 @@ int newtyp;
DOTTYP = newtyp; DOTTYP = newtyp;
} }
align(bytes) void
valu_t bytes; align(valu_t bytes)
{ {
register valu_t gap; valu_t gap;
register sect_t *sp; sect_t *sp;
if ((sp = DOTSCT) == NULL) if ((sp = DOTSCT) == NULL)
nosect(); nosect();
@ -250,7 +242,7 @@ valu_t bytes;
#ifdef RELOCATION #ifdef RELOCATION
void void
newrelo(s, n) newrelo(int s, int n)
{ {
int iscomm; int iscomm;
struct outrelo outrelo; struct outrelo outrelo;
@ -319,8 +311,7 @@ newrelo(s, n)
#endif #endif
long long
new_string(s) new_string(const char *s)
char *s;
{ {
long r = 0; long r = 0;
@ -335,9 +326,7 @@ new_string(s)
} }
void void
newsymb(name, type, desc, valu) newsymb(const char *name, int type, int desc, valu_t valu)
register char *name;
valu_t valu;
{ {
struct outname outname; struct outname outname;
@ -357,11 +346,11 @@ valu_t valu;
wr_name(&outname, 1); wr_name(&outname, 1);
} }
new_common(ip) static void
item_t *ip; new_common(item_t *ip)
{ {
register struct common_t *cp; struct common_t *cp;
static nleft = 0; static int nleft = 0;
static struct common_t *next; static struct common_t *next;
if (--nleft < 0) { if (--nleft < 0) {

View file

@ -12,13 +12,13 @@
#include "comm1.h" #include "comm1.h"
#include "y.tab.h" #include "y.tab.h"
#include <stdarg.h> #include <stdarg.h>
#include <object.h>
valu_t valu_t
load(ip) load(const item_t *ip)
register item_t *ip;
{ {
#ifdef ASLD #ifdef ASLD
register typ; int typ;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if ((typ -= S_MIN) < 0) /* S_UND or S_ABS */ if ((typ -= S_MIN) < 0) /* S_UND or S_ABS */
@ -37,12 +37,11 @@ register item_t *ip;
#endif #endif
} }
store(ip, val) int
register item_t *ip; store(item_t *ip, valu_t val)
valu_t val;
{ {
#ifdef ASLD #ifdef ASLD
register typ; int typ;
typ = ip->i_type & S_TYP; typ = ip->i_type & S_TYP;
if ((typ -= S_MIN) >= 0) if ((typ -= S_MIN) >= 0)
@ -57,12 +56,11 @@ valu_t val;
} }
char * char *
remember(s) remember(char *s)
register char *s;
{ {
register char *p; char *p;
register n; int n;
static nleft = 0; static int nleft = 0;
static char *next; static char *next;
p = s; p = s;
@ -85,8 +83,8 @@ register char *s;
return(s); return(s);
} }
combine(typ1, typ2, op) int
register typ1, typ2; combine(int typ1, int typ2, int op)
{ {
switch (op) { switch (op) {
case '+': case '+':
@ -122,12 +120,12 @@ register typ1, typ2;
} }
#ifdef LISTING #ifdef LISTING
printx(ndig, val) int
valu_t val; printx(int ndig, valu_t val)
{ {
static char buf[8]; static char buf[8];
register char *p; char *p;
register c, n; int c, n;
p = buf; n = ndig; p = buf; n = ndig;
do { do {
@ -140,12 +138,11 @@ valu_t val;
} while (p > buf); } while (p > buf);
return(ndig); return(ndig);
} }
#endif
#ifdef LISTING void
listline(textline) listline(int textline)
{ {
register c; int c;
if ((listflag & 4) && (c = getc(listfile)) != '\n' && textline) { if ((listflag & 4) && (c = getc(listfile)) != '\n' && textline) {
if (listcolm >= 24) if (listcolm >= 24)
@ -176,10 +173,11 @@ listline(textline)
#define PBITTABSZ 128 #define PBITTABSZ 128
static char *pbittab[PBITTABSZ]; static char *pbittab[PBITTABSZ];
small(fitsmall, gain) int
small(int fitsmall, int gain)
{ {
register bit; int bit;
register char *p; char *p;
if (DOTSCT == NULL) if (DOTSCT == NULL)
nosect(); nosect();
@ -231,7 +229,8 @@ small(fitsmall, gain)
/* ---------- output ---------- */ /* ---------- output ---------- */
emit1(arg) void
emit1(int arg)
{ {
static int olddottyp = -1; static int olddottyp = -1;
#ifdef LISTING #ifdef LISTING
@ -269,8 +268,8 @@ emit1(arg)
DOTVAL++; DOTVAL++;
} }
emit2(arg) void
int arg; emit2(int arg)
{ {
#ifdef BYTES_REVERSED #ifdef BYTES_REVERSED
emit1((arg>>8)); emit1(arg); emit1((arg>>8)); emit1(arg);
@ -279,8 +278,8 @@ int arg;
#endif #endif
} }
emit4(arg) void
long arg; emit4(long arg)
{ {
#ifdef WORDS_REVERSED #ifdef WORDS_REVERSED
emit2((int)(arg>>16)); emit2((int)(arg)); emit2((int)(arg>>16)); emit2((int)(arg));
@ -289,9 +288,8 @@ long arg;
#endif #endif
} }
emitx(val, n) void
valu_t val; emitx(valu_t val, int n)
int n;
{ {
switch (n) { switch (n) {
case RELO1: case RELO1:
@ -315,10 +313,11 @@ int n;
} }
} }
emitstr(zero) void
emitstr(int zero)
{ {
register i; int i;
register char *p; char *p;
p = stringbuf; p = stringbuf;
i = stringlen; i = stringlen;
@ -330,17 +329,15 @@ emitstr(zero)
/* ---------- Error checked file I/O ---------- */ /* ---------- Error checked file I/O ---------- */
ffreopen(s, f) void
char *s; ffreopen(char *s, FILE *f)
FILE *f;
{ {
if (freopen(s, "r", f) == NULL) if (freopen(s, "r", f) == NULL)
fatal("can't reopen %s", s); fatal("can't reopen %s", s);
} }
FILE * FILE *
ffcreat(s) ffcreat(char *s)
char *s;
{ {
FILE *f; FILE *f;
@ -355,10 +352,9 @@ char *s;
char *tmp_dir = TMPDIR; char *tmp_dir = TMPDIR;
FILE * FILE *
fftemp(path, tail) fftemp(char *path, char *tail)
char *path, *tail;
{ {
register char *dir; char *dir;
if ((dir = getenv("TMPDIR")) == NULL) if ((dir = getenv("TMPDIR")) == NULL)
dir = tmp_dir; dir = tmp_dir;
@ -369,20 +365,24 @@ char *path, *tail;
/* ---------- Error handling ---------- */ /* ---------- Error handling ---------- */
/*VARARGS*/ /* ARGSUSED */
yyerror(){} /* we will do our own error printing */ void
yyerror(const char *message)
{} /* we will do our own error printing */
nosect() void
nosect(void)
{ {
fatal("no sections"); fatal("no sections");
} }
wr_fatal() void
wr_fatal(void)
{ {
fatal("write error"); fatal("write error");
} }
void diag(const char* tail, const char* s, va_list ap) static void diag(const char* tail, const char* s, va_list ap)
{ {
fflush(stdout); fflush(stdout);
if (modulename) if (modulename)
@ -406,22 +406,7 @@ void fatal(const char* s, ...)
va_end(ap); va_end(ap);
} }
#if DEBUG == 2 /* VARARGS1 */
assert2(file, line)
char *file;
{
fatal("assertion failed (%s, %d)", file, line);
}
#endif
#if DEBUG == 1
assert1()
{
fatal("assertion failed");
abort();
}
#endif
void serror(const char* s, ...) void serror(const char* s, ...)
{ {
va_list ap; va_list ap;
@ -447,7 +432,8 @@ void warning(const char* s, ...)
va_end(ap); va_end(ap);
} }
nofit() void
nofit(void)
{ {
if (pass == PASS_3) if (pass == PASS_3)
warning("too big"); warning("too big");

View file

@ -1,12 +0,0 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#undef NDEBUG
#ifndef NDEBUG
#define assert(x) if(!(x)) badassertion("x",__FILE__,__LINE__)
#else
#define assert(x) /* nothing */
#endif

View file

@ -11,7 +11,15 @@ definerule("build_ncg",
name = e.name.."/headers", name = e.name.."/headers",
srcs = {}, srcs = {},
hdrs = { hdrs = {
"mach/proto/ncg/*.h", "mach/proto/ncg/data.h",
"mach/proto/ncg/equiv.h",
"mach/proto/ncg/glosym.h",
"mach/proto/ncg/label.h",
"mach/proto/ncg/param.h",
"mach/proto/ncg/regvar.h",
"mach/proto/ncg/result.h",
"mach/proto/ncg/state.h",
"mach/proto/ncg/types.h",
"mach/"..e.arch.."/ncg/mach.c", "mach/"..e.arch.."/ncg/mach.c",
"mach/"..e.arch.."/ncg/*.h", "mach/"..e.arch.."/ncg/*.h",
} }

View file

@ -2,9 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -14,6 +14,9 @@ static char rcsid[] = "$Id$";
#include "state.h" #include "state.h"
#include "equiv.h" #include "equiv.h"
#include "extern.h" #include "extern.h"
#ifdef REGVARS
#include "regvar.h" /* regreturn */
#endif
/* /*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
@ -27,13 +30,6 @@ static char rcsid[] = "$Id$";
byte startupcode[] = { DO_NEXTEM }; byte startupcode[] = { DO_NEXTEM };
byte* nextem();
unsigned costcalc();
unsigned docoerc();
unsigned stackupto();
string tostring();
string ad2str();
#ifdef NDEBUG #ifdef NDEBUG
#define DEBUG(string) #define DEBUG(string)
#else #else
@ -124,7 +120,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
byte* bp; byte* bp;
int n; int n;
unsigned mindistance, dist; unsigned mindistance, dist;
register i; int i;
int cindex; int cindex;
int npos, pos[MAXRULE]; int npos, pos[MAXRULE];
unsigned mincost, t; unsigned mincost, t;
@ -295,8 +291,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
DEBUG("XXMATCH"); DEBUG("XXMATCH");
case DO_XMATCH: case DO_XMATCH:
{ {
register i; int i, temp;
int temp;
DEBUG("XMATCH"); DEBUG("XMATCH");
tokpatlen = (codep[-1] >> 5) & 07; tokpatlen = (codep[-1] >> 5) & 07;
@ -306,8 +301,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_MATCH: case DO_MATCH:
{ {
register i; int i, j;
int j;
unsigned mincost, t; unsigned mincost, t;
token_p tp; token_p tp;
int size, lsize; int size, lsize;
@ -603,8 +597,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
case DO_KILLREG: case DO_KILLREG:
case DO_RREMOVE: case DO_RREMOVE:
{ /* register remove */ { /* register remove */
register i; int i, nodeno;
int nodeno;
token_p tp; token_p tp;
tkdef_p tdp; tkdef_p tdp;
result_t result; result_t result;
@ -650,7 +643,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_DEALLOCATE: case DO_DEALLOCATE:
{ {
register i; int i;
tkdef_p tdp; tkdef_p tdp;
int tinstno; int tinstno;
token_t token; token_t token;
@ -684,8 +677,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_ALLOCATE: case DO_ALLOCATE:
{ {
register i; int i, j;
int j;
int tinstno; int tinstno;
int npos, npos2, pos[NREGS], pos2[NREGS]; int npos, npos2, pos[NREGS], pos2[NREGS];
unsigned mincost, t; unsigned mincost, t;
@ -844,8 +836,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_INSTR: case DO_INSTR:
{ {
register i; int i, n;
int n;
int tinstno; int tinstno;
token_t token; token_t token;
int stringno; int stringno;
@ -933,7 +924,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_TOKREPLACE: case DO_TOKREPLACE:
{ {
register i; int i;
int tinstno; int tinstno;
int repllen; int repllen;
token_t reptoken[MAXREPLLEN]; token_t reptoken[MAXREPLLEN];
@ -969,8 +960,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
} }
case DO_EMREPLACE: case DO_EMREPLACE:
{ {
register i; int i, j;
int j;
int nodeno; int nodeno;
result_t result[MAXEMREPLLEN]; result_t result[MAXEMREPLLEN];
int emrepllen, eminstr; int emrepllen, eminstr;
@ -1093,10 +1083,10 @@ doreturn:
return (totalcost); return (totalcost);
} }
readcodebytes() void readcodebytes(void)
{ {
#ifndef CODEINC #ifndef CODEINC
register fd; int fd;
extern int ncodebytes; extern int ncodebytes;
if ((fd = open("code", 0)) < 0) if ((fd = open("code", 0)) < 0)
@ -1108,13 +1098,12 @@ readcodebytes()
error("Short read from code"); error("Short read from code");
} }
close(fd); close(fd);
#endif #endif /* CODEINC */
} }
#ifdef TABLEDEBUG #ifdef TABLEDEBUG
initlset(f) char* f; void initlset(char *f)
{ {
extern char* myalloc();
set_flag = f; set_flag = f;
if ((set_fd = open(f + 1, 2)) < 0) if ((set_fd = open(f + 1, 2)) < 0)
@ -1124,7 +1113,7 @@ initlset(f) char* f;
read(set_fd, set_val, set_size); read(set_fd, set_val, set_size);
} }
termlset() void termlset(void)
{ {
if (set_fd) if (set_fd)
@ -1134,7 +1123,7 @@ termlset()
close(set_fd); close(set_fd);
if (set_flag[0] == 'u') if (set_flag[0] == 'u')
{ {
register i; int i;
fprintf(stderr, "Unused code rules:\n\n"); fprintf(stderr, "Unused code rules:\n\n");
for (i = 0; i < 8 * set_size; i++) for (i = 0; i < 8 * set_size; i++)
@ -1143,4 +1132,4 @@ termlset()
} }
} }
} }
#endif #endif /* TABLEDEBUG */

View file

@ -2,10 +2,10 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -35,7 +35,7 @@ static char rcsid[] = "$Id$";
#define LLDEF LLEAF|LDEF #define LLDEF LLEAF|LDEF
#define RLDEF RLEAF|RDEF #define RLDEF RLEAF|RDEF
char opdesc[] = { static const char opdesc[] = {
0, /* EX_TOKFIELD */ 0, /* EX_TOKFIELD */
0, /* EX_ARG */ 0, /* EX_ARG */
0, /* EX_CON */ 0, /* EX_CON */
@ -87,10 +87,8 @@ char opdesc[] = {
#endif #endif
}; };
string salloc(),strcpy(),strcat(); static string mycat(string s1, string s2) {
string s;
string mycat(s1,s2) register string s1,s2; {
register string s;
if (s1==0 || *s1=='\0') return(s2); if (s1==0 || *s1=='\0') return(s2);
if (s2==0 || *s2=='\0') return(s1); if (s2==0 || *s2=='\0') return(s1);
@ -101,7 +99,7 @@ string mycat(s1,s2) register string s1,s2; {
return(s); return(s);
} }
string mystrcpy(s) register string s; { string mystrcpy(string s) {
register string r; register string r;
r=salloc(strlen(s)); r=salloc(strlen(s));
@ -109,9 +107,9 @@ string mystrcpy(s) register string s; {
return(r); return(r);
} }
char digstr[21][15]; static char digstr[21][15];
string tostring(n) register word n; { string tostring(word n) {
char buf[25]; char buf[25];
if (n>=-20 && n<=20 && (n&1)==0) { if (n>=-20 && n<=20 && (n&1)==0) {
@ -123,10 +121,9 @@ string tostring(n) register word n; {
return(mystrcpy(buf)); return(mystrcpy(buf));
} }
void void compute(node_p node, result_t *presult) {
compute(node, presult) register node_p node; register result_t *presult; {
result_t leaf1,leaf2; result_t leaf1,leaf2;
register token_p tp; token_p tp;
int desc; int desc;
long mask,tmp; long mask,tmp;
int i,tmpreg; int i,tmpreg;

View file

@ -4,6 +4,8 @@
*/ */
/* $Id$ */ /* $Id$ */
#include <cgg_cg.h> /* set_p, c3_p */
typedef struct cost { typedef struct cost {
short ct_space; short ct_space;
short ct_time; short ct_time;
@ -69,3 +71,32 @@ typedef struct {
int rl_n; /* number in list */ int rl_n; /* number in list */
int rl_list[NREGS]; int rl_list[NREGS];
} rl_t,*rl_p; } rl_t,*rl_p;
/* gencode.c */
void genstr(int);
string ad2str(address_t);
void gennl(void);
void prtoken(token_p, int);
#ifdef USE_TES
void printlabel(int);
#endif
/* move.c */
int move(token_p, token_p, int, int, unsigned);
void setcc(token_p);
int test(token_p, int, int, unsigned);
/* subr.c */
int match(token_p, set_p, int);
void instance(int, token_p);
int eqtoken(token_p, token_p);
int distance(int);
unsigned costcalc(cost_t);
int ssize(int);
int tsize(token_p);
void tref(token_p, int);
int in_stack(int);
#ifdef MAXSPLIT
int split(token_p, int *, int, int);
#endif
unsigned docoerc(token_p, c3_p, int, int, int);
unsigned stackupto(token_p, int, int);
c3_p findcoerc(token_p, set_p);

View file

@ -2,15 +2,15 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "equiv.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
#include <cgg_cg.h> #include <cgg_cg.h>
#include "data.h" #include "data.h"
#include "equiv.h"
#include "result.h" #include "result.h"
#include "extern.h" #include "extern.h"
@ -21,21 +21,18 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
extern string myalloc(); static int rar[MAXCREG];
static rl_p *lar;
static int maxindex;
static int regclass[NREGS];
static struct perm *perms;
int rar[MAXCREG]; static void permute(int);
rl_p *lar;
int maxindex;
int regclass[NREGS];
struct perm *perms;
void permute(); struct perm *tuples(rl_p *regls, int nregneeded) {
struct perm *
tuples(regls,nregneeded) rl_p *regls; {
int class=0; int class=0;
register i,j; int i,j;
register struct reginfo *rp; struct reginfo *rp;
/* /*
* First compute equivalence classes of registers. * First compute equivalence classes of registers.
@ -66,11 +63,10 @@ tuples(regls,nregneeded) rl_p *regls; {
return(perms); return(perms);
} }
void static void permute(int index) {
permute(index) { struct perm *pp;
register struct perm *pp; rl_p rlp;
register rl_p rlp; int i,j;
register i,j;
if (index == maxindex) { if (index == maxindex) {
for (pp=perms; pp != 0; pp=pp->p_next) { for (pp=perms; pp != 0; pp=pp->p_next) {

View file

@ -10,3 +10,5 @@ struct perm {
struct perm *p_next; struct perm *p_next;
int p_rar[MAXCREG]; int p_rar[MAXCREG];
}; };
struct perm *tuples(rl_p *, int);

View file

@ -54,6 +54,3 @@ extern int *rvnumbers[]; /* lists of numbers */
#endif #endif
extern FILE *codefile; extern FILE *codefile;
extern void error(const char *s, ...);
extern void fatal(const char *s, ...);

View file

@ -2,10 +2,10 @@
static char rcsid2[] = "$Id$"; static char rcsid2[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "assert.h"
#include <em_spec.h> #include <em_spec.h>
#include <em_pseu.h> #include <em_pseu.h>
#include <em_flag.h> #include <em_flag.h>
@ -17,6 +17,7 @@ static char rcsid2[] = "$Id$";
#include "types.h" #include "types.h"
#include <cgg_cg.h> #include <cgg_cg.h>
#include "data.h" #include "data.h"
#include "glosym.h"
#include "result.h" #include "result.h"
#ifdef REGVARS #ifdef REGVARS
#include "regvar.h" #include "regvar.h"
@ -55,50 +56,60 @@ Read the documentation.
#define SEGROM 2 #define SEGROM 2
#define SEGBSS 3 #define SEGBSS 3
long con();
#define get8() getc(emfile) #define get8() getc(emfile)
FILE *emfile; static FILE *emfile;
int nextispseu,savetab1; static int nextispseu,savetab1;
int opcode; static int opcode;
int offtyp; static int offtyp;
long argval; static long argval;
int dlbval; static int dlbval;
char *str,argstr[128],labstr[128]; static char *str,argstr[128],labstr[128];
unsigned int maxstrsiz; static unsigned int maxstrsiz;
int strsiz; static int strsiz;
int holno=0; static int holno=0;
int procno=0; static int procno=0;
int curseg= -1; static int curseg= -1;
int part_size=0; static int part_size=0;
word part_word=0; static word part_word=0;
#ifdef REGVARS #ifdef REGVARS
int regallowed=0; static int regallowed=0;
#endif #endif
extern char em_flag[]; extern char em_flag[];
extern short em_ptyp[]; extern short em_ptyp[];
extern double atof();
/* machine dependent */
void con_part(int, word);
void con_mult(word);
void con_float(void);
void prolog(full nlocals); void prolog(full nlocals);
void mes(); void mes(word);
void bss();
void savelab(); static int getarg(int);
void dumplab(); static int table1(void);
void part_flush(); static int table2(void);
void xdumplab(); static int table3(int);
void switchseg(); static int get16(void);
static long get32(void);
static void getstring(void);
static string strarg(int);
static void bss(full, int, int);
static long con(int);
static void switchseg(int);
static void savelab(void);
static void dumplab(void);
static void xdumplab(void);
static void part_flush(void);
static string holstr(word);
/* Own version of atol that continues computing on overflow. /* Own version of atol that continues computing on overflow.
We don't know that about the ANSI C one. We don't know that about the ANSI C one.
*/ */
long our_atol(s) static long our_atol(char *s) {
register char *s; long total = 0;
{ unsigned digit;
register long total = 0;
register unsigned digit;
int minus = 0; int minus = 0;
while (*s == ' ' || *s == '\t') s++; while (*s == ' ' || *s == '\t') s++;
@ -117,14 +128,7 @@ register char *s;
#define sp_cstx sp_cst2 #define sp_cstx sp_cst2
string tostring(); void in_init(char *filename) {
string holstr();
string strarg();
string mystrcpy();
string myalloc();
long get32();
in_init(filename) char *filename; {
emfile = stdin; emfile = stdin;
if (filename && (emfile=freopen(filename,"r",stdin))==NULL) if (filename && (emfile=freopen(filename,"r",stdin))==NULL)
@ -134,19 +138,18 @@ in_init(filename) char *filename; {
str = myalloc(maxstrsiz=256); str = myalloc(maxstrsiz=256);
} }
in_start() { void in_start(void) {
#ifdef modhead #ifdef modhead
fprintf(codefile,"%s",modhead) ; fprintf(codefile,"%s",modhead) ;
#endif #endif
} }
in_finish() { static void in_finish(void) {
} }
void void fillemlines(void) {
fillemlines() { int t,i;
register int t,i; struct emline *lp;
register struct emline *lp;
while ((emlines+nemlines)-emp<MAXEMLINES-5) { while ((emlines+nemlines)-emp<MAXEMLINES-5) {
assert(nemlines<MAXEMLINES); assert(nemlines<MAXEMLINES);
@ -236,13 +239,12 @@ fillemlines() {
void void
dopseudo() { dopseudo() {
register b,t; int b,t;
register full n; full n;
register long save; long save;
word romcont[MAXROM+1]; word romcont[MAXROM+1];
int nromwords; int nromwords;
int rombit,rommask; int rombit,rommask;
unsigned stackupto();
if (nextispseu==0 || nemlines>0) if (nextispseu==0 || nemlines>0)
error("No table entry for %d",emlines[0].em_instr); error("No table entry for %d",emlines[0].em_instr);
@ -439,8 +441,8 @@ dopseudo() {
/* ----- input ----- */ /* ----- input ----- */
int getarg(typset) { static int getarg(int typset) {
register t,argtyp; int t,argtyp;
argtyp = t = table2(); argtyp = t = table2();
if (t == EOF) if (t == EOF)
@ -452,8 +454,8 @@ int getarg(typset) {
return(argtyp); return(argtyp);
} }
int table1() { static int table1(void) {
register i; int i;
i = get8(); i = get8();
if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) { if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
@ -471,8 +473,8 @@ int table1() {
return(table3(i)); return(table3(i));
} }
int table2() { static int table2(void) {
register i; int i;
i = get8(); i = get8();
if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) { if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
@ -482,7 +484,7 @@ int table2() {
return(table3(i)); return(table3(i));
} }
int table3(i) { static int table3(int i) {
word consiz; word consiz;
switch(i) { switch(i) {
@ -525,8 +527,8 @@ int table3(i) {
return(i); return(i);
} }
int get16() { static int get16(void) {
register int l_byte, h_byte; int l_byte, h_byte;
l_byte = get8(); l_byte = get8();
h_byte = get8(); h_byte = get8();
@ -534,9 +536,9 @@ int get16() {
return l_byte | (h_byte*256) ; return l_byte | (h_byte*256) ;
} }
long get32() { static long get32(void) {
register long l; long l;
register int h_byte; int h_byte;
l = get8(); l = get8();
l |= ((unsigned) get8())*256 ; l |= ((unsigned) get8())*256 ;
@ -546,9 +548,9 @@ long get32() {
return l | (h_byte*256L*256*256L) ; return l | (h_byte*256L*256*256L) ;
} }
getstring() { static void getstring(void) {
register char *p; char *p;
register n; int n;
getarg(cst_ptyp); getarg(cst_ptyp);
if (argval < 0) if (argval < 0)
@ -565,8 +567,8 @@ getstring() {
*p++ = '\0'; *p++ = '\0';
} }
char *strarg(t) { static string strarg(int t) {
register char *p; char *p;
switch (t) { switch (t) {
case sp_ilb1: case sp_ilb1:
@ -613,9 +615,8 @@ char *strarg(t) {
return(mystrcpy(argstr)); return(mystrcpy(argstr));
} }
void static void bss(full n, int t, int b) {
bss(n,t,b) full n; { long s = 0;
register long s = 0;
if (n % TEM_WSIZE) if (n % TEM_WSIZE)
fatal("bad BSS size"); fatal("bad BSS size");
@ -637,8 +638,8 @@ bss(n,t,b) full n; {
fatal("bad BSS initializer"); fatal("bad BSS initializer");
} }
long con(t) { static long con(int t) {
register i; int i;
strarg(t); strarg(t);
switch (t) { switch (t) {
@ -682,12 +683,11 @@ long con(t) {
extern char *segname[]; extern char *segname[];
swtxt() { void swtxt(void) {
switchseg(SEGTXT); switchseg(SEGTXT);
} }
void static void switchseg(int s) {
switchseg(s) {
if (s == curseg) if (s == curseg)
return; return;
@ -696,8 +696,7 @@ switchseg(s) {
fprintf(codefile,"%s\n",segname[s]); fprintf(codefile,"%s\n",segname[s]);
} }
void static void savelab(void) {
savelab() {
register char *p,*q; register char *p,*q;
part_flush(); part_flush();
@ -711,8 +710,7 @@ savelab() {
; ;
} }
void static void dumplab(void) {
dumplab() {
if (labstr[0] == 0) if (labstr[0] == 0)
return; return;
@ -721,8 +719,7 @@ dumplab() {
labstr[0] = 0; labstr[0] = 0;
} }
void static void xdumplab(void) {
xdumplab() {
if (labstr[0] == 0) if (labstr[0] == 0)
return; return;
@ -730,8 +727,7 @@ xdumplab() {
newdlb(labstr); newdlb(labstr);
} }
void static void part_flush(void) {
part_flush() {
/* /*
* Each new data fragment and each data label starts at * Each new data fragment and each data label starts at
@ -744,7 +740,7 @@ part_flush() {
part_word = 0; part_word = 0;
} }
string holstr(n) word n; { static string holstr(word n) {
sprintf(str,hol_off,n,holno); sprintf(str,hol_off,n,holno);
return(mystrcpy(str)); return(mystrcpy(str));

View file

@ -2,8 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include "assert.h" #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> /* isatty */
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -22,12 +23,9 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
string mystrcpy();
FILE *codefile; FILE *codefile;
extern FILE *freopen();
out_init(filename) char *filename; { void out_init(char *filename) {
#ifndef NDEBUG #ifndef NDEBUG
static char stderrbuff[BUFSIZ]; static char stderrbuff[BUFSIZ];
@ -48,7 +46,7 @@ out_init(filename) char *filename; {
#endif #endif
} }
out_finish() { void out_finish(void) {
#ifndef NDEBUG #ifndef NDEBUG
if (Debug) if (Debug)
@ -61,18 +59,18 @@ out_finish() {
#endif #endif
} }
tstoutput() { void tstoutput(void) {
if (ferror(codefile)) if (ferror(codefile))
error("Write error on output"); error("Write error on output");
} }
genstr(stringno) { void genstr(int stringno) {
fputs(codestrings[stringno],codefile); fputs(codestrings[stringno],codefile);
} }
string ad2str(ad) address_t ad; { string ad2str(address_t ad) {
static char buf[100]; static char buf[100];
if (ad.ea_str==0) if (ad.ea_str==0)
@ -87,7 +85,7 @@ string ad2str(ad) address_t ad; {
return(mystrcpy(buf)); return(mystrcpy(buf));
} }
praddr(ad) address_t ad; { static void praddr(address_t ad) {
if (ad.ea_str==0 || *(ad.ea_str) == '\0') if (ad.ea_str==0 || *(ad.ea_str) == '\0')
fprintf(codefile,WRD_FMT,ad.ea_off); fprintf(codefile,WRD_FMT,ad.ea_off);
@ -104,15 +102,14 @@ praddr(ad) address_t ad; {
} }
} }
gennl() { void gennl(void) {
putc('\n',codefile); putc('\n',codefile);
} }
void void prtoken(token_p tp, int leadingchar) {
prtoken(tp,leadingchar) token_p tp; { int c;
register c; char *code;
register char *code; tkdef_p tdp;
register tkdef_p tdp;
putc(leadingchar,codefile); putc(leadingchar,codefile);
if (tp->t_token == -1) { if (tp->t_token == -1) {
@ -145,9 +142,7 @@ prtoken(tp,leadingchar) token_p tp; {
} }
#ifdef USE_TES #ifdef USE_TES
printlabel(labnum) void printlabel(int labnum) {
int labnum;
{
newilb(dollar[labnum].e_v.e_addr.ea_str); newilb(dollar[labnum].e_v.e_addr.ea_str);
} }
#endif #endif

View file

@ -16,13 +16,11 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
extern string myalloc(); static glosym_p glolist= (glosym_p) 0;
glosym_p glolist= (glosym_p) 0; void enterglo(string name, word *romp) {
glosym_p gp;
enterglo(name,romp) string name; word *romp; { int i;
register glosym_p gp;
register i;
gp = (glosym_p) myalloc(sizeof *gp); gp = (glosym_p) myalloc(sizeof *gp);
gp->gl_next = glolist; gp->gl_next = glolist;
@ -33,8 +31,8 @@ enterglo(name,romp) string name; word *romp; {
glolist = gp; glolist = gp;
} }
glosym_p lookglo(name) string name; { glosym_p lookglo(string name) {
register glosym_p gp; glosym_p gp;
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next) for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
if (strcmp(gp->gl_name,name)==0) if (strcmp(gp->gl_name,name)==0)

View file

@ -10,4 +10,5 @@ typedef struct glosym {
word gl_rom[MAXROM+1]; word gl_rom[MAXROM+1];
} glosym_t,*glosym_p; } glosym_t,*glosym_p;
glosym_p lookglo(); void enterglo(string, word *);
glosym_p lookglo(string);

View file

@ -5,12 +5,10 @@
#include "label.h" #include "label.h"
static label_p label_list = (label_p)0; static label_p label_list = (label_p)0;
extern char *myalloc();
void void add_label(num, height, flth)
add_label(num, height, flth)
{ {
register label_p lbl = (label_p)0; label_p lbl = (label_p)0;
if (height <= 0) return; if (height <= 0) return;
if (flth != TRUE && flth != FALSE) if (flth != TRUE && flth != FALSE)
@ -24,10 +22,9 @@ add_label(num, height, flth)
label_list = lbl; label_list = lbl;
} }
label_p get_label(num) label_p get_label(word num)
register word num;
{ {
register label_p tmp = label_list; label_p tmp = label_list;
while (tmp != (label_p)0) { while (tmp != (label_p)0) {
if (tmp->lb_number == num) return tmp; if (tmp->lb_number == num) return tmp;
@ -36,7 +33,7 @@ register word num;
return (label_p)0; return (label_p)0;
} }
kill_labels() void kill_labels(void)
{ {
label_p tmp; label_p tmp;

View file

@ -14,4 +14,6 @@ struct label {
short lb_fallthrough; short lb_fallthrough;
}; };
extern label_p get_label(); void add_label(int, int, int);
label_p get_label(word);
void kill_labels(void);

View file

@ -2,8 +2,10 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <stdlib.h> /* atoi */
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h"
#include "mach.h" #include "mach.h"
/* /*
@ -14,18 +16,18 @@ static char rcsid[] = "$Id$";
*/ */
char *progname; char *progname;
extern char startupcode[]; extern byte startupcode[]; /* codegen.c */
extern unsigned codegen();
int maxply=1; int maxply=1;
#ifndef NDEBUG #ifndef NDEBUG
int Debug=0; int Debug=0;
char *strtdebug=""; char *strtdebug="";
#endif #endif
main(argc,argv) char **argv; { static unsigned ggd(unsigned, unsigned);
register unsigned n;
extern unsigned cc1,cc2,cc3,cc4; int main(int argc, char **argv) {
unsigned ggd(); unsigned n;
extern unsigned cc1,cc2,cc3,cc4; /* tables.c */
progname = argv[0]; progname = argv[0];
while (--argc && **++argv == '-') { while (--argc && **++argv == '-') {
@ -84,8 +86,8 @@ main(argc,argv) char **argv; {
error("Bombed out of codegen"); error("Bombed out of codegen");
} }
unsigned ggd(a,b) register unsigned a,b; { unsigned ggd(unsigned a, unsigned b) {
register unsigned c; unsigned c;
do { do {
c = a%b; a=b; b=c; c = a%b; a=b; b=c;

View file

@ -2,9 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -20,13 +20,12 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; { int move(token_p tp1, token_p tp2, int ply, int toplevel, unsigned maxcost) {
register move_p mp; move_p mp;
unsigned t; unsigned t;
register struct reginfo *rp; struct reginfo *rp;
register byte *tdpb; byte *tdpb;
int i; int i;
unsigned codegen();
if (eqtoken(tp1,tp2)) if (eqtoken(tp1,tp2))
return(0); return(0);
@ -97,15 +96,14 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
#define cocoreg machregs[0].r_contents #define cocoreg machregs[0].r_contents
setcc(tp) token_p tp; { void setcc(token_p tp) {
cocoreg = *tp; cocoreg = *tp;
} }
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; { int test(token_p tp, int ply, int toplevel, unsigned maxcost) {
register test_p mp; test_p mp;
unsigned t; unsigned t;
unsigned codegen();
if (cocoreg.t_token!=0) { if (cocoreg.t_token!=0) {
if (eqtoken(tp,&cocoreg)) if (eqtoken(tp,&cocoreg))

View file

@ -2,11 +2,11 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <em_spec.h> #include <em_spec.h>
#include <em_flag.h> #include <em_flag.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -27,8 +27,10 @@ static char rcsid[] = "$Id$";
extern char em_mnem[][4]; extern char em_mnem[][4];
#endif #endif
byte *trypat(bp,len) register byte *bp; { static int argtyp(int);
register patlen,i;
static byte *trypat(byte *bp, int len) {
int patlen,i;
result_t result; result_t result;
getint(patlen,bp); getint(patlen,bp);
@ -85,7 +87,7 @@ byte *trypat(bp,len) register byte *bp; {
extern char em_flag[]; extern char em_flag[];
argtyp(mn) { static int argtyp(int mn) {
/* op_lab is a special opcode which represents a label definition. It's /* op_lab is a special opcode which represents a label definition. It's
* not actually a real EM instruction. Therefore if we try to look it * not actually a real EM instruction. Therefore if we try to look it
@ -110,13 +112,13 @@ argtyp(mn) {
} }
} }
byte *nextem(toplevel) { byte *nextem(int toplevel) {
register i; int i;
short hash[3]; short hash[3];
register byte *bp; byte *bp;
byte *cp; byte *cp;
int index; int index;
register struct emline *ep; struct emline *ep;
if (toplevel) { if (toplevel) {
if (nemlines && emp>emlines) { if (nemlines && emp>emlines) {

View file

@ -2,9 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -20,10 +20,10 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
chrefcount(regno,amount,tflag) { void chrefcount(int regno, int amount, int tflag) {
register struct reginfo *rp; struct reginfo *rp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
register i, tmp; int i, tmp;
#endif #endif
rp= &machregs[regno]; rp= &machregs[regno];
@ -42,10 +42,10 @@ chrefcount(regno,amount,tflag) {
#endif #endif
} }
getrefcount(regno, tflag) { int getrefcount(int regno, int tflag) {
register struct reginfo *rp; struct reginfo *rp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
register i,maxcount, tmp; int i,maxcount, tmp;
#endif #endif
rp= &machregs[regno]; rp= &machregs[regno];
@ -66,10 +66,10 @@ getrefcount(regno, tflag) {
#endif #endif
} }
erasereg(regno) { void erasereg(int regno) {
register struct reginfo *rp = &machregs[regno]; struct reginfo *rp = &machregs[regno];
register int i; int i;
register byte *tdpb; byte *tdpb;
#if MAXMEMBERS==0 #if MAXMEMBERS==0
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
@ -108,7 +108,7 @@ erasereg(regno) {
} }
#else #else
extern short clashlist[]; extern short clashlist[];
register short *sp = &clashlist[rp->r_iclash]; short *sp = &clashlist[rp->r_iclash];
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
while (*sp) { while (*sp) {
@ -151,9 +151,9 @@ erasereg(regno) {
#endif #endif
} }
cleanregs() { void cleanregs(void) {
register struct reginfo *rp; struct reginfo *rp;
register i; int i;
for (rp=machregs;rp<machregs+NREGS;rp++) { for (rp=machregs;rp<machregs+NREGS;rp++) {
rp->r_contents.t_token = 0; rp->r_contents.t_token = 0;
@ -163,9 +163,9 @@ cleanregs() {
} }
#ifndef NDEBUG #ifndef NDEBUG
inctcount(regno) { static void inctcount(int regno) {
register struct reginfo *rp; struct reginfo *rp;
register i; int i;
rp = &machregs[regno]; rp = &machregs[regno];
#if MAXMEMBERS!=0 #if MAXMEMBERS!=0
@ -181,10 +181,10 @@ inctcount(regno) {
#endif #endif
} }
chkregs() { void chkregs(void) {
register struct reginfo *rp; struct reginfo *rp;
register token_p tp; token_p tp;
register byte *tdpb; byte *tdpb;
int i; int i;
for (rp=machregs+1;rp<machregs+NREGS;rp++) { for (rp=machregs+1;rp<machregs+NREGS;rp++) {

View file

@ -1,6 +1,6 @@
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
@ -24,12 +24,10 @@ static char rcsid[] = "$Id$";
* *
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
extern string myalloc(); static struct regvar *rvlist;
struct regvar *rvlist;
struct regvar * struct regvar *linkreg(long of, int sz, int tp, int sc) {
linkreg(long of, int sz, int tp, int sc) { struct regvar *rvlp;
register struct regvar *rvlp;
rvlp= (struct regvar *) myalloc(sizeof *rvlp); rvlp= (struct regvar *) myalloc(sizeof *rvlp);
rvlp->rv_next = rvlist; rvlp->rv_next = rvlist;
@ -42,11 +40,10 @@ linkreg(long of, int sz, int tp, int sc) {
return(rvlp); return(rvlp);
} }
void void tryreg(struct regvar *rvlp, int typ) {
tryreg(struct regvar *rvlp, int typ) {
int score; int score;
register i; int i;
register struct regassigned *ra; struct regassigned *ra;
struct regvar *save; struct regvar *save;
if (typ != reg_any && nregvar[typ]!=0) { if (typ != reg_any && nregvar[typ]!=0) {
@ -100,8 +97,7 @@ tryreg(struct regvar *rvlp, int typ) {
} }
} }
void void fixregvars(int saveall) {
fixregvars(int saveall) {
struct reginfo *rp, *rp2; struct reginfo *rp, *rp2;
struct regvar *rv; struct regvar *rv;
int i, regno, rvtyp; int i, regno, rvtyp;
@ -146,9 +142,8 @@ fixregvars(int saveall) {
f_regsave(); f_regsave();
} }
int int isregvar(long off) {
isregvar(long off) { struct regvar *rvlp;
register struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off) if(rvlp->rv_off == off)
@ -157,8 +152,7 @@ isregvar(long off) {
} }
#ifdef REGLAP #ifdef REGLAP
int int isregvar_size(long off, int size) {
isregvar_size(long off, int size) {
int regno = isregvar(off); int regno = isregvar(off);
/* /*
* A reg_float may have two sizes. If this register has the * A reg_float may have two sizes. If this register has the
@ -176,9 +170,8 @@ isregvar_size(long off, int size) {
} }
#endif /* REGLAP */ #endif /* REGLAP */
int int isregtyp(long off) {
isregtyp(long off) { struct regvar *rvlp;
register struct regvar *rvlp;
for (rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) for (rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if (rvlp->rv_off == off) if (rvlp->rv_off == off)
@ -186,10 +179,9 @@ isregtyp(long off) {
return(-1); return(-1);
} }
void void unlinkregs(void) {
unlinkregs(void) { struct regvar *rvlp,*t;
register struct regvar *rvlp,*t; struct regassigned *ra;
register struct regassigned *ra;
int rvtyp,i; int rvtyp,i;
for (rvlp=rvlist;rvlp!=0;rvlp=t) { for (rvlp=rvlist;rvlp!=0;rvlp=t) {

View file

@ -18,7 +18,6 @@ struct regassigned {
int ra_score; int ra_score;
}; };
extern struct regvar *rvlist;
extern int nregvar[]; extern int nregvar[];
extern struct regassigned *regassigned[]; extern struct regassigned *regassigned[];
@ -37,3 +36,10 @@ void unlinkregs(void);
#else #else
#define PICK_REGVAR(off, size) isregvar(off) #define PICK_REGVAR(off, size) isregvar(off)
#endif #endif
/* machine dependent */
int regscore(long, int, int, int, int);
void i_regsave(void);
void regsave(const char *, long, int);
void f_regsave(void);
void regreturn(void);

View file

@ -19,3 +19,6 @@ struct result {
#define EV_ADDR 3 #define EV_ADDR 3
typedef struct result result_t; typedef struct result result_t;
/* compute.c */
void compute(node_p, result_t *);

View file

@ -2,9 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -32,10 +32,10 @@ static char rcsid[] = "$Id$";
char *stab[MAXSTAB]; char *stab[MAXSTAB];
int nstab=0; int nstab=0;
void chkstr(); static void chkstr(string, char *);
string myalloc(size) { string myalloc(size) {
register string p; string p;
p = (string) calloc((unsigned)size, 1); p = (string) calloc((unsigned)size, 1);
if (p==0) if (p==0)
@ -43,21 +43,21 @@ string myalloc(size) {
return(p); return(p);
} }
myfree(p) string p; { void myfree(string p) {
free(p); free(p);
} }
popstr(nnstab) { void popstr(int nnstab) {
register i; int i;
for (i=nnstab;i<nstab;i++) for (i=nnstab;i<nstab;i++)
myfree(stab[i]); myfree(stab[i]);
nstab = nnstab; nstab = nnstab;
} }
char *salloc(size) { char *salloc(int size) {
register char *p; char *p;
if (nstab==MAXSTAB) if (nstab==MAXSTAB)
fatal("String table overflow"); fatal("String table overflow");
@ -66,7 +66,9 @@ char *salloc(size) {
return(p); return(p);
} }
compar(p1,p2) char **p1,**p2; { static int compar(const void *v1, const void *v2) {
char *const *p1 = v1;
char *const *p2 = v2;
assert(*p1 != *p2); assert(*p1 != *p2);
if (*p1 < *p2) if (*p1 < *p2)
@ -74,14 +76,13 @@ compar(p1,p2) char **p1,**p2; {
return(1); return(1);
} }
void void garbage_collect(void) {
garbage_collect() { int i;
register i;
struct emline *emlp; struct emline *emlp;
token_p tp; token_p tp;
tkdef_p tdp; tkdef_p tdp;
struct reginfo *rp; struct reginfo *rp;
register char **fillp,**scanp; char **fillp,**scanp;
char used[MAXSTAB]; /* could be bitarray */ char used[MAXSTAB]; /* could be bitarray */
if (nstab<THRESHOLD) if (nstab<THRESHOLD)
@ -119,9 +120,9 @@ garbage_collect() {
nstab = fillp-stab; nstab = fillp-stab;
} }
void static void
chkstr(str,used) string str; char used[]; { chkstr(string str, char *used) {
register low,middle,high; int low,middle,high;
low=0; high=nstab-1; low=0; high=nstab-1;
while (high>low) { while (high>low) {

View file

@ -2,9 +2,9 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "assert.h"
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -23,9 +23,9 @@ static char rcsid[] = "$Id$";
extern int nstab; /* salloc.c */ extern int nstab; /* salloc.c */
void bmove(); static void bmove(short *, short *, int);
savestatus(sp) register state_p sp; { void savestatus(state_p sp) {
sp->st_sh = stackheight; sp->st_sh = stackheight;
bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t)); bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
@ -42,7 +42,7 @@ savestatus(sp) register state_p sp; {
sp->st_ns = nstab; sp->st_ns = nstab;
} }
restorestatus(sp) register state_p sp; { void restorestatus(state_p sp) {
stackheight = sp->st_sh; stackheight = sp->st_sh;
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t)); bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
@ -59,8 +59,7 @@ restorestatus(sp) register state_p sp; {
popstr(sp->st_ns); popstr(sp->st_ns);
} }
void static void bmove(short *from, short *to, int nbytes) {
bmove(from,to,nbytes) register short *from,*to; register nbytes; {
if (nbytes<=0) if (nbytes<=0)
return; return;

View file

@ -20,3 +20,7 @@ typedef struct state {
int st_tl; /* tokpatlen */ int st_tl; /* tokpatlen */
int st_ns; /* nstab */ int st_ns; /* nstab */
} state_t,*state_p; } state_t,*state_p;
/* state.c */
void savestatus(state_p);
void restorestatus(state_p);

View file

@ -2,10 +2,11 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "assert.h" #include <string.h> /* strcmp */
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -24,11 +25,13 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren * Author: Hans van Staveren
*/ */
string myalloc(); static int from_stack(set_p);
unsigned codegen(); #ifdef TABLEDEBUG
static void ruletrace(void);
#endif
match(tp,tep,optexp) register token_p tp; register set_p tep; { int match(token_p tp, set_p tep, int optexp) {
register bitno; int bitno;
token_p ct; token_p ct;
result_t result; result_t result;
@ -53,11 +56,10 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; {
return(result.e_v.e_con); return(result.e_v.e_con);
} }
void void instance(int instno, token_p token) {
instance(instno,token) register token_p token; { inst_p inp;
register inst_p inp;
int i; int i;
register token_p tp; token_p tp;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
struct reginfo *rp; struct reginfo *rp;
#endif #endif
@ -152,9 +154,8 @@ instance(instno,token) register token_p token; {
} }
} }
void static void cinstance(int instno, token_p token, token_p tp, int regno) {
cinstance(instno,token,tp,regno) register token_p token,tp; { inst_p inp;
register inst_p inp;
int i; int i;
#if MAXMEMBERS != 0 #if MAXMEMBERS != 0
struct reginfo *rp; struct reginfo *rp;
@ -250,9 +251,9 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
} }
} }
eqtoken(tp1,tp2) token_p tp1,tp2; { int eqtoken(token_p tp1, token_p tp2) {
register i; int i;
register tkdef_p tdp; tkdef_p tdp;
if (tp1->t_token!=tp2->t_token) if (tp1->t_token!=tp2->t_token)
return(0); return(0);
@ -286,10 +287,10 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
return(1); return(1);
} }
distance(cindex) { int distance(int cindex) {
register char *bp; char *bp;
register i; int i;
register token_p tp; token_p tp;
int tokexp,tpl; int tokexp,tpl;
int expsize,toksize,exact; int expsize,toksize,exact;
int xsekt=0; int xsekt=0;
@ -363,31 +364,29 @@ distance(cindex) {
return(20-2*exact+fromstackneeded); return(20-2*exact+fromstackneeded);
} }
extern set_t unstackset; extern set_t unstackset; /* tables.c */
int from_stack(s1) static int from_stack(set_p s1) {
register set_p s1; set_p s2 = &unstackset;
{ int i;
register set_p s2 = &unstackset;
register int i;
for (i = 0; i < SETSIZE; i++) { for (i = 0; i < SETSIZE; i++) {
if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1; if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1;
} }
return 0; return 0;
} }
unsigned costcalc(cost) cost_t cost; { unsigned costcalc(cost_t cost) {
extern unsigned cc1,cc2,cc3,cc4; extern unsigned cc1,cc2,cc3,cc4; /* tables.c */
return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4); return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4);
} }
ssize(tokexpno) { int ssize(int tokexpno) {
return(machsets[tokexpno].set_size); return(machsets[tokexpno].set_size);
} }
tsize(tp) register token_p tp; { int tsize(token_p tp) {
if (tp->t_token==-1) if (tp->t_token==-1)
return(machregs[tp->t_att[0].ar].r_size); return(machregs[tp->t_att[0].ar].r_size);
@ -395,7 +394,7 @@ tsize(tp) register token_p tp; {
} }
#ifdef MAXSPLIT #ifdef MAXSPLIT
instsize(tinstno,tp) token_p tp; { static int instsize(int tinstno, token_p tp) {
inst_p inp; inst_p inp;
struct reginfo *rp; struct reginfo *rp;
@ -428,9 +427,9 @@ instsize(tinstno,tp) token_p tp; {
} }
#endif /* MAXSPLIT */ #endif /* MAXSPLIT */
tref(tp,amount) register token_p tp; { void tref(token_p tp, int amount) {
register i; int i;
register byte *tdpb; byte *tdpb;
if (tp->t_token==-1) if (tp->t_token==-1)
chrefcount(tp->t_att[0].ar,amount,FALSE); chrefcount(tp->t_att[0].ar,amount,FALSE);
@ -447,10 +446,10 @@ tref(tp,amount) register token_p tp; {
restore it and check whether a certain register is present in the restore it and check whether a certain register is present in the
saved stack saved stack
*/ */
token_t aside[MAXSAVE] ; static token_t aside[MAXSAVE] ;
int aside_length = -1 ; static int aside_length = -1 ;
save_stack(tp) register token_p tp ; { static void save_stack(token_p tp) {
int i ; int i ;
token_p tmp = &fakestack[stackheight - 1]; token_p tmp = &fakestack[stackheight - 1];
@ -468,10 +467,10 @@ save_stack(tp) register token_p tp ; {
stackheight -= aside_length; stackheight -= aside_length;
} }
in_stack(reg) { int in_stack(int reg) {
register token_p tp ; token_p tp ;
register i ; int i ;
register tkdef_p tdp ; tkdef_p tdp ;
for ( i=0, tp=aside ; i<aside_length ; i++, tp++ ) for ( i=0, tp=aside ; i<aside_length ; i++, tp++ )
if (tp->t_token==-1) { if (tp->t_token==-1) {
@ -494,8 +493,8 @@ gotone:
return 1 ; return 1 ;
} }
rest_stack() { static void rest_stack(void) {
register int i ; int i ;
assert(aside_length!= -1); assert(aside_length!= -1);
#ifndef NDEBUG #ifndef NDEBUG
@ -509,11 +508,11 @@ rest_stack() {
} }
#ifdef MAXSPLIT #ifdef MAXSPLIT
split(tp,ip,ply,toplevel) token_p tp; register int *ip; { int split(token_p tp, int *ip, int ply, int toplevel) {
register c2_p cp; c2_p cp;
token_t savestack[MAXSAVE]; token_t savestack[MAXSAVE];
int ok; int ok;
register i; int i;
int diff; int diff;
token_p stp; token_p stp;
int tpl; int tpl;
@ -543,7 +542,7 @@ found:
} }
#endif /* MAXSPLIT */ #endif /* MAXSPLIT */
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; { unsigned docoerc(token_p tp, c3_p cp, int ply, int toplevel, int forced) {
unsigned cost; unsigned cost;
int tpl; /* saved tokpatlen */ int tpl; /* saved tokpatlen */
@ -557,15 +556,15 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
return(cost); return(cost);
} }
unsigned stackupto(limit,ply,toplevel) token_p limit; { unsigned stackupto(token_p limit, int ply, int toplevel) {
token_t savestack[MAXFSTACK]; token_t savestack[MAXFSTACK];
token_p stp; token_p stp;
int i,diff; int i,diff;
int tpl; /* saved tokpatlen */ int tpl; /* saved tokpatlen */
int nareg; /* saved nareg */ int nareg; /* saved nareg */
int areg[MAXALLREG]; int areg[MAXALLREG];
register c1_p cp; c1_p cp;
register token_p tp; token_p tp;
unsigned totalcost=0; unsigned totalcost=0;
struct reginfo *rp,**rpp; struct reginfo *rp,**rpp;
@ -621,11 +620,11 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; {
return(totalcost); return(totalcost);
} }
c3_p findcoerc(tp,tep) token_p tp; set_p tep; { c3_p findcoerc(token_p tp, set_p tep) {
register c3_p cp; c3_p cp;
token_t rtoken; token_t rtoken;
register i; int i;
register struct reginfo **rpp; struct reginfo **rpp;
for (cp=c3coercs;cp->c3_texpno>=0; cp++) { for (cp=c3coercs;cp->c3_texpno>=0; cp++) {
if (tp!=(token_p) 0) { if (tp!=(token_p) 0) {
@ -658,8 +657,8 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
return(0); /* nothing found */ return(0); /* nothing found */
} }
itokcost() { void itokcost(void) {
register tkdef_p tdp; tkdef_p tdp;
for(tdp=tokens+1;tdp->t_size!=0;tdp++) for(tdp=tokens+1;tdp->t_size!=0;tdp++)
tdp->t_cost.ct_space = costcalc(tdp->t_cost); tdp->t_cost.ct_space = costcalc(tdp->t_cost);
@ -696,8 +695,8 @@ void fatal(const char *s, ...) {
#ifdef TABLEDEBUG #ifdef TABLEDEBUG
ruletrace() { static void ruletrace(void) {
register i; int i;
extern int tablelines[MAXTDBUG]; extern int tablelines[MAXTDBUG];
extern int ntableline; extern int ntableline;
extern char *tablename; extern char *tablename;
@ -712,11 +711,4 @@ ruletrace() {
i--; i--;
} }
} }
#endif #endif /* TABLEDEBUG */
#ifndef NDEBUG
badassertion(asstr,file,line) char *asstr, *file; {
fatal("\"%s\", line %d:Assertion \"%s\" failed",file,line,asstr);
}
#endif

View file

@ -28,3 +28,45 @@ typedef char * string;
#ifndef WRD_FMT #ifndef WRD_FMT
#define WRD_FMT "%ld" #define WRD_FMT "%ld"
#endif /* WRD_FMT */ #endif /* WRD_FMT */
/* codegen.c */
unsigned codegen(byte *, int, int, unsigned, int);
void readcodebytes(void);
#ifdef TABLEDEBUG
void initlset(char *);
void termlset(void);
#endif
/* compute.c */
string mystrcpy(string);
string tostring(word);
/* fillem.c */
void in_init(char *);
void in_start(void);
void fillemlines(void);
void swtxt(void);
/* gencode.c */
void out_init(char *);
void out_finish(void);
void tstoutput(void);
/* nextem.c */
byte *nextem(int);
/* reg.c */
void chrefcount(int, int, int);
int getrefcount(int, int);
void erasereg(int);
void cleanregs(void);
void chkregs(void);
/* salloc.c */
string myalloc(int);
void myfree(string);
void popstr(int);
char *salloc(int);
void garbage_collect(void);
/* subr.c */
void itokcost(void);
void error(const char *s, ...);
void fatal(const char *s, ...);
#ifdef MACH_OPTIONS
void mach_option(char *); /* machine dependent */
#endif

View file

@ -12,7 +12,7 @@ int framesize;
/* Write out a constant data section. */ /* Write out a constant data section. */
con_part(int sz, word w) void con_part(int sz, word w)
{ {
while (part_size % sz) while (part_size % sz)
part_size++; part_size++;
@ -29,7 +29,7 @@ con_part(int sz, word w)
part_size += sz; part_size += sz;
} }
con_mult(word sz) void con_mult(word sz)
{ {
if (argval != 4) if (argval != 4)
fatal("bad icon/ucon size"); fatal("bad icon/ucon size");
@ -49,7 +49,7 @@ void prolog(full nlocals)
fprintf(codefile, "push fp, lr\n"); fprintf(codefile, "push fp, lr\n");
fprintf(codefile, "mov fp, sp\n"); fprintf(codefile, "mov fp, sp\n");
if (nlocals > 0) if (nlocals > 0)
fprintf(codefile, "sub sp, #%d\n", nlocals); fprintf(codefile, "sub sp, #%ld\n", nlocals);
framesize = nlocals; framesize = nlocals;
} }

View file

@ -1,42 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* _BadAssertion: used for debugging purposes. It should give an error message
indicated by the parameters, and then give a core dump
*/
#include <string.h>
#include <system.h>
static
wr_num(fd, n)
File *fd;
int n;
{
char s[2];
s[1] = '\0';
if (n >= 10) {
wr_num(fd, n/10);
}
s[0] = (n % 10) + '0';
sys_write(fd, s, 1);
}
int
_BadAssertion(file, lineno, assertion)
char *file, *assertion;
int lineno;
{
sys_write(STDERR, file, strlen(file));
sys_write(STDERR, ", line ", 7);
wr_num(STDERR, lineno);
sys_write(STDERR, ": assertion \"", 13);
sys_write(STDERR, assertion, strlen(assertion));
sys_write(STDERR, "\" failed\n", 9);
sys_stop(S_ABORT);
return 0;
}

View file

@ -1,61 +0,0 @@
.TH ASSERT 3 "$Revision$"
.ad
.SH NAME
assert \- program verification
.SH SYNOPSIS
.B #include <assert.h>
.PP
.B assert(expression)
.PP
.B _BadAssertion(fn, lino, ass)
.br
char *fn, *ass;
.br
unsigned int lino;
.SH DESCRIPTION
.PP
.I Assert
is a macro that indicates
.I expression
is expected to be true at this point in the program.
It causes a call to
.I _BadAssertion
when
.I expression
is false (0).
.PP
The routine
.I_BadAssertion
accepts three parameters:
a filename, a linenumber,
and a string representing a failed assertion.
It causes a
.IR sys_stop (S_ABORT)
with a diagnostic comment on standard error.
.PP
The assertions are disabled by defining the preprocessor constant NDEBUG.
.SH DIAGNOSTICS
.IR fn ,
line
.IR lino :
assertion
.I ass
failed.
.br
.I fn
is the source file,
.I lino
is the source line number,
and
.I ass
is the assertion
of the
.I assert
statement.
.SH MODULES
system(3)
.SH FILES
.nf
~em/modules/h/assert.h
~em/modules/lib/libassert.a
.fi

View file

@ -1,24 +0,0 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
/* A S S E R T I O N M A C R O D E F I N I T I O N */
/* This 'assert' definition can be used in a ,-expression. */
#ifndef NDEBUG
#if __STDC__
int _BadAssertion(char *, int, char *);
#define assert(exp) ((void)((exp) || _BadAssertion(__FILE__, __LINE__, #exp)))
#else
/* Note: this macro uses parameter substitution inside strings */
#define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, "exp"))
#endif
#else
#if __STDC__
#define assert(exp) ((void)0)
#else
#define assert(exp) (0)
#endif
#endif /* NDEBUG */

View file

@ -1,7 +0,0 @@
clibrary {
name = "lib",
srcs = { "./*.c" },
hdrs = { "./assert.h" },
}

View file

@ -13,22 +13,22 @@ struct outrelo;
struct outsect; struct outsect;
struct ranlib; struct ranlib;
int wr_open(char *f); int wr_open(const char *f);
void wr_close(void); void wr_close(void);
void wr_ohead(struct outhead *h); void wr_ohead(const struct outhead *h);
void wr_sect(struct outsect *s, unsigned int c); void wr_sect(const struct outsect *s, unsigned int c);
void wr_outsect(int sectno); void wr_outsect(int sectno);
void wr_emit(char *b, long c); void wr_emit(const char *b, long c);
void wr_putc(int c); void wr_putc(int c);
void wr_relo(struct outrelo *r, unsigned int c); void wr_relo(const struct outrelo *r, unsigned int c);
void wr_name(struct outname *n, unsigned int c); void wr_name(const struct outname *n, unsigned int c);
void wr_string(char *s, long c); void wr_string(const char *s, long c);
void wr_arhdr(int fd, struct ar_hdr *a); void wr_arhdr(int fd, struct ar_hdr *a);
void wr_ranlib(int fd, struct ranlib *r, long cnt); void wr_ranlib(int fd, struct ranlib *r, long cnt);
void wr_int2(int fd, int i); void wr_int2(int fd, int i);
void wr_long(int fd, long l); void wr_long(int fd, long l);
void wr_bytes(int fd, char *buf, long l); void wr_bytes(int fd, const char *buf, long l);
int rd_open(char *f); int rd_open(const char *f);
int rd_fdopen(int f); int rd_fdopen(int f);
void rd_close(void); void rd_close(void);
void rd_ohead(struct outhead *h); void rd_ohead(struct outhead *h);

View file

@ -3,6 +3,7 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#include <fcntl.h>
#include "obj.h" #include "obj.h"
/* /*
@ -57,7 +58,7 @@ OUTREAD(int p, char* b, long n)
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
*/ */
int int
rd_open(char* f) rd_open(const char* f)
{ {
if ((outfile = open(f, 0)) < 0) if ((outfile = open(f, 0)) < 0)

View file

@ -11,6 +11,7 @@
* part. In this case #define OUTSEEK. * part. In this case #define OUTSEEK.
*/ */
#include <fcntl.h>
#include "obj.h" #include "obj.h"
/* /*
@ -28,8 +29,7 @@ int __sectionnr;
static int offcnt; static int offcnt;
void void
__wr_flush(ptr) __wr_flush(struct fil *ptr)
register struct fil *ptr;
{ {
#ifdef OUTSEEK #ifdef OUTSEEK
/* seek to correct position even if we aren't going to write now */ /* seek to correct position even if we aren't going to write now */
@ -53,14 +53,12 @@ __wr_flush(ptr)
} }
static void static void
OUTWRITE(p, b, n) OUTWRITE(int p, const char *b, long n)
int p; /* part number */ /* p = part number, b = buffer pointer, n = write count */
register char *b; /* buffer pointer */
long n; /* write count */
{ {
register struct fil *ptr = &__parts[p]; struct fil *ptr = &__parts[p];
register char *pn = ptr->pnow; char *pn = ptr->pnow;
register int i; int i;
long m; long m;
i = ptr->cnt; i = ptr->cnt;
@ -119,11 +117,10 @@ OUTWRITE(p, b, n)
} }
static void static void
BEGINSEEK(p, o) BEGINSEEK(int p, long o)
int p; /* part number */ /* p = part number, o = offset in file */
long o; /* offset in file */
{ {
register struct fil *ptr = &__parts[p]; struct fil *ptr = &__parts[p];
#ifdef OUTSEEK #ifdef OUTSEEK
ptr->fd = outfile; ptr->fd = outfile;
@ -143,10 +140,9 @@ BEGINSEEK(p, o)
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
*/ */
int int
wr_open(f) wr_open(const char *f)
char *f;
{ {
register struct fil *fdp; struct fil *fdp;
close(creat(f, 0666)); close(creat(f, 0666));
#ifdef OUTSEEK #ifdef OUTSEEK
@ -165,7 +161,7 @@ wr_open(f)
void void
wr_close() wr_close()
{ {
register struct fil *ptr; struct fil *ptr;
for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) { for (ptr = &__parts[PARTEMIT]; ptr < &__parts[NPARTS]; ptr++) {
__wr_flush(ptr); __wr_flush(ptr);
@ -181,11 +177,10 @@ wr_close()
} }
void void
wr_ohead(head) wr_ohead(const struct outhead *head)
register struct outhead *head;
{ {
{ {
register long off = OFF_RELO(*head); long off = OFF_RELO(*head);
BEGINSEEK(PARTEMIT, 0L); BEGINSEEK(PARTEMIT, 0L);
BEGINSEEK(PARTRELO, off); BEGINSEEK(PARTRELO, off);
@ -202,7 +197,7 @@ wr_ohead(head)
{ {
char buf[SZ_HEAD]; char buf[SZ_HEAD];
register char *c = &buf[0]; char *c = &buf[0];
put2(head->oh_magic, c); c += 2; put2(head->oh_magic, c); c += 2;
put2(head->oh_stamp, c); c += 2; put2(head->oh_stamp, c); c += 2;
@ -217,11 +212,9 @@ wr_ohead(head)
} }
void void
wr_sect(sect, cnt) wr_sect(const struct outsect *sect, unsigned int cnt)
register struct outsect *sect;
register unsigned int cnt;
{ {
{ register unsigned int i = cnt; { unsigned int i = cnt;
while (i--) { while (i--) {
if (offcnt >= 1 && offcnt < SECTCNT) { if (offcnt >= 1 && offcnt < SECTCNT) {
@ -234,8 +227,8 @@ wr_sect(sect, cnt)
} }
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTEMIT].cnt/SZ_SECT; i = __parts[PARTEMIT].cnt/SZ_SECT;
c = __parts[PARTEMIT].pnow; c = __parts[PARTEMIT].pnow;
@ -258,10 +251,10 @@ wr_sect(sect, cnt)
} }
void void
wr_outsect(s) wr_outsect(int s)
int s; /* section number */ /* s = section number */
{ {
register struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)]; struct fil *ptr = &__parts[PARTEMIT + getsect(sectionnr)];
if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) { if (s != sectionnr && s >= (SECTCNT-1) && sectionnr >= (SECTCNT-1)) {
#ifdef OUTSEEK #ifdef OUTSEEK
@ -291,23 +284,19 @@ wr_outsect(s)
* We don't have to worry about byte order here. * We don't have to worry about byte order here.
*/ */
void void
wr_emit(emit, cnt) wr_emit(const char *emit, long cnt)
char *emit;
long cnt;
{ {
OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt); OUTWRITE(PARTEMIT + getsect(sectionnr) , emit, cnt);
} }
void void
wr_relo(relo, cnt) wr_relo(const struct outrelo *relo, unsigned int cnt)
register struct outrelo *relo;
unsigned int cnt;
{ {
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTRELO].cnt/SZ_RELO; i = __parts[PARTRELO].cnt/SZ_RELO;
c = __parts[PARTRELO].pnow; c = __parts[PARTRELO].pnow;
@ -329,14 +318,12 @@ wr_relo(relo, cnt)
} }
void void
wr_name(name, cnt) wr_name(const struct outname *name, unsigned int cnt)
register struct outname *name;
unsigned int cnt;
{ {
while (cnt) while (cnt)
{ {
register char *c; char *c;
register unsigned int i; unsigned int i;
i = __parts[PARTNAME].cnt/SZ_NAME; i = __parts[PARTNAME].cnt/SZ_NAME;
c = __parts[PARTNAME].pnow; c = __parts[PARTNAME].pnow;
@ -356,11 +343,8 @@ wr_name(name, cnt)
} }
void void
wr_string(addr, len) wr_string(const char *addr, long len)
char *addr;
long len;
{ {
OUTWRITE(PARTCHAR, addr, len); OUTWRITE(PARTCHAR, addr, len);
} }

View file

@ -12,19 +12,17 @@
You have to put it in an int! You have to put it in an int!
*/ */
static int maxchunk = MAXCHUNK; static const int maxchunk = MAXCHUNK;
/* /*
* Just write "cnt" bytes to file-descriptor "fd". * Just write "cnt" bytes to file-descriptor "fd".
*/ */
void void
wr_bytes(fd, string, cnt) wr_bytes(int fd, const char *string, long cnt)
register char *string;
register long cnt;
{ {
while (cnt) { while (cnt) {
register int n = cnt >= maxchunk ? maxchunk : cnt; int n = cnt >= maxchunk ? maxchunk : cnt;
if (write(fd, string, n) != n) if (write(fd, string, n) != n)
wr_fatal(); wr_fatal();

View file

@ -6,11 +6,12 @@
#include "obj.h" #include "obj.h"
extern int __sectionnr; extern int __sectionnr;
void __wr_flush(struct fil *);
void void
wr_putc(ch) wr_putc(int ch)
{ {
register struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)]; struct fil *ptr = &__parts[PARTEMIT+getsect(__sectionnr)];
if (ptr->cnt == 0) __wr_flush(ptr); if (ptr->cnt == 0) __wr_flush(ptr);
ptr->cnt--; *ptr->pnow++ = ch; ptr->cnt--; *ptr->pnow++ = ch;

View file

@ -1,12 +1,13 @@
clibrary { clibrary {
name = "lib", name = "lib",
srcs = { "./*.c" }, srcs = {
"./doprnt.c", "./format.c", "./fprint.c", "./print.c",
"./sprint.c",
},
hdrs = { "./print.h" }, hdrs = { "./print.h" },
deps = { deps = {
"modules+headers", "./param.h",
"modules/src/string+lib",
"modules/src/system+lib", "modules/src/system+lib",
"./*.h"
} }
} }

View file

@ -16,10 +16,7 @@
%d = int %d = int
$ */ $ */
void void
doprnt(fp, fmt, argp) doprnt(File *fp, char *fmt, va_list argp)
File *fp;
char *fmt;
va_list argp;
{ {
char buf[SSIZE]; char buf[SSIZE];

View file

@ -5,13 +5,12 @@
/* $Id$ */ /* $Id$ */
#include <string.h> #include <string.h>
#include <ack_string.h>
#include <system.h> #include <system.h>
#include "print.h" #include "print.h"
extern char *long2str();
static int static int
integral(c) integral(int c)
{ {
switch (c) { switch (c) {
case 'b': case 'b':
@ -36,9 +35,7 @@ integral(c)
%d = int %d = int
$ */ $ */
int int
_format(buf, fmt, argp) _format(char *buf, char *fmt, va_list argp)
char *buf, *fmt;
register va_list argp;
{ {
register char *pf = fmt; register char *pf = fmt;
register char *pb = buf; register char *pb = buf;

View file

@ -17,27 +17,12 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
void void
fprint fprint(File *fp, char *fmt, ...)
#if __STDC__
(File *fp, char *fmt, ...)
{ {
#else
(va_alist)
va_dcl
{
File *fp;
char *fmt;
#endif
va_list args; va_list args;
char buf[SSIZE]; char buf[SSIZE];
#if __STDC__
va_start(args, fmt); va_start(args, fmt);
#else
va_start(args);
fp = va_arg(args, File *);
fmt = va_arg(args, char *);
#endif
sys_write(fp, buf, _format(buf, fmt, args)); sys_write(fp, buf, _format(buf, fmt, args));
va_end(args); va_end(args);
} }

View file

@ -17,25 +17,12 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
void void
print print(char *fmt, ...)
#if __STDC__
(char *fmt, ...)
{ {
#else
(va_alist)
va_dcl
{
char *fmt;
#endif
va_list args; va_list args;
char buf[SSIZE]; char buf[SSIZE];
#if __STDC__
va_start(args, fmt); va_start(args, fmt);
#else
va_start(args);
fmt = va_arg(args, char *);
#endif
sys_write(STDOUT, buf, _format(buf, fmt, args)); sys_write(STDOUT, buf, _format(buf, fmt, args));
va_end(args); va_end(args);
} }

View file

@ -7,17 +7,12 @@
#ifndef __PRINT_INCLUDED__ #ifndef __PRINT_INCLUDED__
#define __PRINT_INCLUDED__ #define __PRINT_INCLUDED__
#include <ansi.h>
#if __STDC__
#include <stdarg.h> #include <stdarg.h>
#else
#include <varargs.h>
#endif
_PROTOTYPE(void print, (char *fmt, ...)); void print(char *fmt, ...);
_PROTOTYPE(void fprint, (File *f, char *fmt, ...)); void fprint(File *f, char *fmt, ...);
_PROTOTYPE(void doprnt, (File *f, char *fmt, va_list ap)); void doprnt(File *f, char *fmt, va_list ap);
_PROTOTYPE(int _format, (char *buf, char *fmt, va_list ap)); int _format(char *buf, char *fmt, va_list ap);
_PROTOTYPE(char *sprint, (char *buf, char *fmt, ...)); char *sprint(char *buf, char *fmt, ...);
#endif /* __PRINT_INCLUDED__ */ #endif /* __PRINT_INCLUDED__ */

View file

@ -17,25 +17,11 @@
$ */ $ */
/*VARARGS*/ /*VARARGS*/
char * char *
sprint sprint(char *buf, char *fmt, ...)
#if __STDC__
(char *buf, char *fmt, ...)
{ {
#else
(va_alist)
va_dcl
{
char *buf, *fmt;
#endif
va_list args; va_list args;
#if __STDC__
va_start(args, fmt); va_start(args, fmt);
#else
va_start(args);
buf = va_arg(args, char *);
fmt = va_arg(args, char *);
#endif
buf[_format(buf, fmt, args)] = '\0'; buf[_format(buf, fmt, args)] = '\0';
va_end(args); va_end(args);
return buf; return buf;

View file

@ -1,4 +1,3 @@
normalrule { normalrule {
name = "c_mnem_narg_h", name = "c_mnem_narg_h",
ins = { ins = {
@ -53,6 +52,7 @@ local function variant(name, cflags)
"modules/src/alloc+lib", "modules/src/alloc+lib",
"modules/src/em_code+headers", "modules/src/em_code+headers",
"modules/src/em_data+lib", "modules/src/em_data+lib",
"modules/src/string+lib",
"modules/src/system+lib", "modules/src/system+lib",
"./*.h", "./*.h",
} }
@ -61,4 +61,3 @@ end
variant("lib_ev", {}) variant("lib_ev", {})
variant("lib_kv", { "-DCOMPACT" }) variant("lib_kv", { "-DCOMPACT" })

View file

@ -10,6 +10,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <ack_string.h>
/* #define XXX_YYY /* only for early debugging */ /* #define XXX_YYY /* only for early debugging */
@ -283,7 +284,6 @@ getnumber(c, ap)
register char *p = str; register char *p = str;
int n; int n;
int expsign; int expsign;
long str2long();
ap->ema_argtype = cst_ptyp; ap->ema_argtype = cst_ptyp;
expsign = 0; expsign = 0;

View file

@ -7,25 +7,16 @@
#ifndef __ACK_STRING_INCLUDED__ #ifndef __ACK_STRING_INCLUDED__
#define __ACK_STRING_INCLUDED__ #define __ACK_STRING_INCLUDED__
#include <ansi.h> char *strindex(char *s, int c);
char *strrindex(char *s, int c);
_PROTOTYPE(char *strcpy, (char *s1, const char *s2)); char *strzero(char *s);
_PROTOTYPE(char *strncpy, (char *s1, const char *s2, size_t n)); char *str2bts(char *s, char *b, int *n);
_PROTOTYPE(char *strcat, (char *s1, const char *s2)); char *long2str(long l, int b);
_PROTOTYPE(char *strncat, (char *s1, const char *s2, size_t n)); long str2long(char *s, int b);
_PROTOTYPE(int strcmp, (const char *s1, const char *s2)); char *btscpy(char *s1, char *s2, int n);
_PROTOTYPE(int strncmp, (const char *s1, const char *s2, size_t n)); char *btscat(char *s1, int n1, char *s2, int n2);
_PROTOTYPE(_SIZET strlen, (const char *s)); int btscmp(char *s1, int n1, char *s2, int n2);
_PROTOTYPE(char *strindex, (char *s, int c)); char *btszero(char *b, int n);
_PROTOTYPE(char *strrindex, (char *s, int c)); char *bts2str(char *b, int n, char *s);
_PROTOTYPE(char *strzero, (char *s));
_PROTOTYPE(char *str2bts, (char *s, char *b, int *n));
_PROTOTYPE(char *long2str, (long l, int b));
_PROTOTYPE(long str2long, (char *s, int b));
_PROTOTYPE(char *btscpy, (char *s1, char *s2, int n));
_PROTOTYPE(char *btscat, (char *s1, int n1, char *s2, int n2));
_PROTOTYPE(int btscmp, (char *s1, int n1, char *s2, int n2));
_PROTOTYPE(char *btszero, (char *b, int n));
_PROTOTYPE(char *bts2str, (char *b, int n, char *s));
#endif /* __ACK_STRING_INCLUDED__ */ #endif /* __ACK_STRING_INCLUDED__ */

View file

@ -1,10 +1,10 @@
clibrary { clibrary {
name = "lib", name = "lib",
srcs = { "./*.c" }, srcs = {
deps = { "./bts2str.c", "./btscat.c", "./btscmp.c",
"modules+headers", "./btscpy.c", "./btszero.c", "./long2str.c",
"./*.h" "./str2bts.c", "./str2long.c", "./strindex.c",
"./strrindex.c", "./strzero.c",
}, },
hdrs = { "./ack_string.h", },
} }

View file

@ -1,24 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* append t to s
*/
#include "ack_string.h"
char *
strcat(s, t)
register char *s;
register _CONST char *t;
{
register char *b = s;
while (*s++)
;
s--;
while (*s++ = *t++)
;
return b;
}

Some files were not shown because too many files have changed in this diff Show more