aicasm.c (7532) | aicasm.c (7857) |
---|---|
1/* 2 * Adaptec 274x device driver for Linux. 3 * Copyright (c) 1994 The University of Calgary Department of Computer Science. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 1/*+M************************************************************************* 2 * Adaptec AIC7770/AIC7870 sequencer code assembler. |
18 * | 3 * |
19 * Comments are started by `#' and continue to the end of the line; lines 20 * may be of the form: | 4 * Copyright (c) 1994 John Aycock 5 * The University of Calgary Department of Computer Science. 6 * All rights reserved. |
21 * | 7 * |
22 * <label>* 23 * <label>* <undef-sym> = <value> 24 * <label>* <opcode> <operand>* | 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions, and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of Calgary 19 * Department of Computer Science and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. |
25 * | 23 * |
26 * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas 27 * are token separators. 28 * 29 * $Id: aic7xxx.c,v 1.6 1995/03/17 23:54:16 gibbs Exp $ 30 */ 31 32/* #define _POSIX_SOURCE 1 */ 33#define _POSIX_C_SOURCE 2 34 | 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * Comments are started by `#' and continue to the end of the line; lines 37 * may be of the form: 38 * <label>* 39 * <label>* <undef-sym> = <value> 40 * <label>* <opcode> <operand>* 41 * 42 * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas 43 * are token separators. 44 * 45 *-M*************************************************************************/ 46static char id[] = "$Id$"; |
35#include <ctype.h> 36#include <stdio.h> 37#include <string.h> 38#include <stdlib.h> 39#include <unistd.h> 40 41#define MEMORY 448 42#define MAXLINE 1024 43#define MAXTOKEN 32 44#define ADOTOUT "a.out" 45#define NOVALUE -1 46 47/* | 47#include <ctype.h> 48#include <stdio.h> 49#include <string.h> 50#include <stdlib.h> 51#include <unistd.h> 52 53#define MEMORY 448 54#define MAXLINE 1024 55#define MAXTOKEN 32 56#define ADOTOUT "a.out" 57#define NOVALUE -1 58 59/* |
48 * AIC-7770 register definitions | 60 * AIC-7770/AIC-7870 register definitions |
49 */ 50#define R_SINDEX 0x65 51#define R_ALLONES 0x69 52#define R_ALLZEROS 0x6a 53#define R_NONE 0x6a 54 | 61 */ 62#define R_SINDEX 0x65 63#define R_ALLONES 0x69 64#define R_ALLZEROS 0x6a 65#define R_NONE 0x6a 66 |
55static 56char sccsid[] = 57 "@(#)aic7770.c 1.10 94/07/22 jda"; 58 | |
59int debug; 60int lineno, LC; 61char *filename; 62FILE *ifp, *ofp; 63unsigned char M[MEMORY][4]; 64 | 67int debug; 68int lineno, LC; 69char *filename; 70FILE *ifp, *ofp; 71unsigned char M[MEMORY][4]; 72 |
65void error(char *s) | 73void 74error(char *s) |
66{ 67 fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno); 68 exit(EXIT_FAILURE); 69} 70 | 75{ 76 fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno); 77 exit(EXIT_FAILURE); 78} 79 |
71void *Malloc(size_t size) | 80void * 81Malloc(size_t size) |
72{ 73 void *p = malloc(size); 74 if (!p) 75 error("out of memory"); 76 return(p); 77} 78 | 82{ 83 void *p = malloc(size); 84 if (!p) 85 error("out of memory"); 86 return(p); 87} 88 |
79void *Realloc(void *ptr, size_t size) | 89void * 90Realloc(void *ptr, size_t size) |
80{ 81 void *p = realloc(ptr, size); 82 if (!p) 83 error("out of memory"); 84 return(p); 85} 86 | 91{ 92 void *p = realloc(ptr, size); 93 if (!p) 94 error("out of memory"); 95 return(p); 96} 97 |
87char *Strdup(char *s) | 98char * 99Strdup(char *s) |
88{ 89 char *p = (char *)Malloc(strlen(s) + 1); 90 strcpy(p, s); 91 return(p); 92} 93 94typedef struct sym_t { | 100{ 101 char *p = (char *)Malloc(strlen(s) + 1); 102 strcpy(p, s); 103 return(p); 104} 105 106typedef struct sym_t { |
95 struct sym_t *next; /* MUST BE FIRST */ 96 char *name; 97 int value; 98 int npatch, *patch; | 107 struct sym_t *next; /* MUST BE FIRST */ 108 char *name; 109 int value; 110 int npatch; 111 int *patch; |
99} sym_t; 100 101sym_t *head; 102 | 112} sym_t; 113 114sym_t *head; 115 |
103void define(char *name, int value) | 116void 117define(char *name, int value) |
104{ 105 sym_t *p, *q; 106 107 for (p = head, q = (sym_t *)&head; p; p = p->next) { 108 if (!strcmp(p->name, name)) 109 error("redefined symbol"); 110 q = p; 111 } --- 9 unchanged lines hidden (view full) --- 121 fprintf(stderr, "\"%s\" ", p->name); 122 if (p->value != NOVALUE) 123 fprintf(stderr, "defined as 0x%x\n", p->value); 124 else 125 fprintf(stderr, "undefined\n"); 126 } 127} 128 | 118{ 119 sym_t *p, *q; 120 121 for (p = head, q = (sym_t *)&head; p; p = p->next) { 122 if (!strcmp(p->name, name)) 123 error("redefined symbol"); 124 q = p; 125 } --- 9 unchanged lines hidden (view full) --- 135 fprintf(stderr, "\"%s\" ", p->name); 136 if (p->value != NOVALUE) 137 fprintf(stderr, "defined as 0x%x\n", p->value); 138 else 139 fprintf(stderr, "undefined\n"); 140 } 141} 142 |
129sym_t *lookup(char *name) | 143sym_t * 144lookup(char *name) |
130{ 131 sym_t *p; 132 133 for (p = head; p; p = p->next) 134 if (!strcmp(p->name, name)) 135 return(p); 136 return(NULL); 137} 138 | 145{ 146 sym_t *p; 147 148 for (p = head; p; p = p->next) 149 if (!strcmp(p->name, name)) 150 return(p); 151 return(NULL); 152} 153 |
139void patch(sym_t *p, int location) | 154void 155patch(sym_t *p, int location) |
140{ 141 p->npatch += 1; 142 p->patch = (int *)Realloc(p->patch, p->npatch * sizeof(int *)); 143 144 p->patch[p->npatch - 1] = location; 145} 146 147void backpatch(void) --- 30 unchanged lines hidden (view full) --- 178 } 179 } 180} 181 182/* 183 * Output words in byte-reversed order (least significant first) 184 * since the sequencer RAM is loaded that way. 185 */ | 156{ 157 p->npatch += 1; 158 p->patch = (int *)Realloc(p->patch, p->npatch * sizeof(int *)); 159 160 p->patch[p->npatch - 1] = location; 161} 162 163void backpatch(void) --- 30 unchanged lines hidden (view full) --- 194 } 195 } 196} 197 198/* 199 * Output words in byte-reversed order (least significant first) 200 * since the sequencer RAM is loaded that way. 201 */ |
186void output(FILE *fp) | 202void 203output(FILE *fp) |
187{ 188 int i; 189 190 for (i = 0; i < LC; i++) 191 fprintf(fp, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", 192 M[i][3], 193 M[i][2], 194 M[i][1], 195 M[i][0]); 196 printf("%d out of %d instructions used.\n", LC, MEMORY); 197} 198 | 204{ 205 int i; 206 207 for (i = 0; i < LC; i++) 208 fprintf(fp, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", 209 M[i][3], 210 M[i][2], 211 M[i][1], 212 M[i][0]); 213 printf("%d out of %d instructions used.\n", LC, MEMORY); 214} 215 |
199char **getl(int *n) | 216char ** 217getl(int *n) |
200{ 201 int i; 202 char *p, *quote; 203 static char buf[MAXLINE]; 204 static char *a[MAXTOKEN]; 205 206 i = 0; 207 --- 56 unchanged lines hidden (view full) --- 264 unsigned int op; /* immediate or L?|pos_from_0 */ 265 unsigned int dest; /* NA, pos_from_0, or I|immediate */ 266 unsigned int src; /* NA, pos_from_0, or I|immediate */ 267 unsigned int imm; /* pos_from_0, A|pos_from_0, or I|immediate */ 268 unsigned int addr; /* NA or pos_from_0 */ 269 int fmt; /* instruction format - 1, 2, or 3 */ 270} instr[] = { 271/* | 218{ 219 int i; 220 char *p, *quote; 221 static char buf[MAXLINE]; 222 static char *a[MAXTOKEN]; 223 224 i = 0; 225 --- 56 unchanged lines hidden (view full) --- 282 unsigned int op; /* immediate or L?|pos_from_0 */ 283 unsigned int dest; /* NA, pos_from_0, or I|immediate */ 284 unsigned int src; /* NA, pos_from_0, or I|immediate */ 285 unsigned int imm; /* pos_from_0, A|pos_from_0, or I|immediate */ 286 unsigned int addr; /* NA or pos_from_0 */ 287 int fmt; /* instruction format - 1, 2, or 3 */ 288} instr[] = { 289/* |
272 * N OP DEST SRC IMM ADDR FMT | 290 * N OP DEST SRC IMM ADDR FMT |
273 */ | 291 */ |
274 "mov", 3, 1, 1, 2, I|0xff, NA, 1, 275 "mov", 4, LO|2, NA, 1, I|0, 3, 3, 276 "mvi", 3, 0, 1, I|R_ALLZEROS, A|2, NA, 1, 277 "mvi", 4, LO|2, NA, I|R_ALLZEROS, 1, 3, 3, 278 "not", 2, 2, 1, 1, I|0xff, NA, 1, 279 "not", 3, 2, 1, 2, I|0xff, NA, 1, 280 "and", 3, 1, 1, 1, A|2, NA, 1, 281 "and", 4, 1, 1, 3, A|2, NA, 1, 282 "or", 3, 0, 1, 1, A|2, NA, 1, 283 "or", 4, 0, 1, 3, A|2, NA, 1, 284 "or", 5, LO|3, NA, 1, 2, 4, 3, 285 "xor", 3, 2, 1, 1, A|2, NA, 1, 286 "xor", 4, 2, 1, 3, A|2, NA, 1, 287 "nop", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, 288 "inc", 2, 3, 1, 1, I|1, NA, 1, 289 "inc", 3, 3, 1, 2, I|1, NA, 1, 290 "dec", 2, 3, 1, 1, I|0xff, NA, 1, 291 "dec", 3, 3, 1, 2, I|0xff, NA, 1, 292 "jmp", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, 293 "jc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, 294 "jnc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, 295 "call", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, 296 "test", 5, LA|3, NA, 1, A|2, 4, 3, 297 "cmp", 5, LX|3, NA, 1, A|2, 4, 3, 298 "ret", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, 299 "clc", 1, 3, I|R_NONE, I|R_ALLZEROS, I|1, NA, 1, 300 "clc", 4, 3, 2, I|R_ALLZEROS, A|3, NA, 1, 301 "stc", 1, 3, I|R_NONE, I|R_ALLONES, I|1, NA, 1, 302 "stc", 2, 3, 1, I|R_ALLONES, I|1, NA, 1, 303 "add", 3, 3, 1, 1, A|2, NA, 1, 304 "add", 4, 3, 1, 3, A|2, NA, 1, 305 "adc", 3, 4, 1, 1, A|2, NA, 1, 306 "adc", 4, 4, 1, 3, A|2, NA, 1, 307 "shl", 3, 5, 1, 1, SL|2, NA, 2, 308 "shl", 4, 5, 1, 2, SL|3, NA, 2, 309 "shr", 3, 5, 1, 1, SR|2, NA, 2, 310 "shr", 4, 5, 1, 2, SR|3, NA, 2, 311 "rol", 3, 5, 1, 1, RL|2, NA, 2, 312 "rol", 4, 5, 1, 2, RL|3, NA, 2, 313 "ror", 3, 5, 1, 1, RR|2, NA, 2, 314 "ror", 4, 5, 1, 2, RR|3, NA, 2, | 292 { "mov", 3, 1, 1, 2, I|0xff, NA, 1 }, 293 { "mov", 4, LO|2, NA, 1, I|0, 3, 3 }, 294 { "mvi", 3, 0, 1, I|R_ALLZEROS, A|2, NA, 1 }, 295 { "mvi", 4, LO|2, NA, I|R_ALLZEROS, 1, 3, 3 }, 296 { "not", 2, 2, 1, 1, I|0xff, NA, 1 }, 297 { "and", 3, 1, 1, 1, A|2, NA, 1 }, 298 { "and", 4, 1, 1, 3, A|2, NA, 1 }, 299 { "or", 3, 0, 1, 1, A|2, NA, 1 }, 300 { "or", 4, 0, 1, 3, A|2, NA, 1 }, 301 { "or", 5, LO|3, NA, 1, 2, 4, 3 }, 302 { "xor", 3, 2, 1, 1, A|2, NA, 1 }, 303 { "xor", 4, 2, 1, 3, A|2, NA, 1 }, 304 { "nop", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1 }, 305 { "inc", 2, 3, 1, 1, I|1, NA, 1 }, 306 { "inc", 3, 3, 1, 2, I|1, NA, 1 }, 307 { "dec", 2, 3, 1, 1, I|0xff, NA, 1 }, 308 { "dec", 3, 3, 1, 2, I|0xff, NA, 1 }, 309 { "jmp", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3 }, 310 { "jc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3 }, 311 { "jnc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3 }, 312 { "call", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3 }, 313 { "test", 5, LA|3, NA, 1, A|2, 4, 3 }, 314 { "cmp", 5, LX|3, NA, 1, A|2, 4, 3 }, 315 { "ret", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1 }, 316 { "ret", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1 }, 317 { "clc", 1, 3, I|R_NONE, I|R_ALLZEROS, I|1, NA, 1 }, 318 { "clc", 4, 3, 2, I|R_ALLZEROS, A|3, NA, 1 }, 319 { "stc", 2, 3, 1, I|R_ALLONES, I|1, NA, 1 }, 320 { "add", 3, 3, 1, 1, A|2, NA, 1 }, 321 { "add", 4, 3, 1, 3, A|2, NA, 1 }, 322 { "adc", 3, 4, 1, 1, A|2, NA, 1 }, 323 { "adc", 4, 4, 1, 3, A|2, NA, 1 }, 324 { "shl", 3, 5, 1, 1, SL|2, NA, 2 }, 325 { "shl", 4, 5, 1, 2, SL|3, NA, 2 }, 326 { "shr", 3, 5, 1, 1, SR|2, NA, 2 }, 327 { "shr", 4, 5, 1, 2, SR|3, NA, 2 }, 328 { "rol", 3, 5, 1, 1, RL|2, NA, 2 }, 329 { "rol", 4, 5, 1, 2, RL|3, NA, 2 }, 330 { "ror", 3, 5, 1, 1, RR|2, NA, 2 }, 331 { "ror", 4, 5, 1, 2, RR|3, NA, 2 }, |
315 /* 316 * Extensions (note also that mvi allows A) 317 */ | 332 /* 333 * Extensions (note also that mvi allows A) 334 */ |
318 "clr", 2, 1, 1, I|R_ALLZEROS, I|0xff, NA, 1, 319 0 | 335 { "clr", 2, 1, 1, I|R_ALLZEROS, I|0xff, NA, 1 }, 336 { 0, 0, 0, 0, 0, 0, 0, 0 } |
320}; 321 | 337}; 338 |
322int eval_operand(char **a, int spec) | 339int 340eval_operand(char **a, int spec) |
323{ 324 int i; 325 unsigned int want = spec & (LO|LA|LX); 326 327 static struct { 328 unsigned int what; 329 char *name; 330 int value; 331 } jmptab[] = { | 341{ 342 int i; 343 unsigned int want = spec & (LO|LA|LX); 344 345 static struct { 346 unsigned int what; 347 char *name; 348 int value; 349 } jmptab[] = { |
332 LO, "jmp", 8, 333 LO, "jc", 9, 334 LO, "jnc", 10, 335 LO, "call", 11, 336 LA, "jz", 15, 337 LA, "jnz", 13, 338 LX, "je", 14, 339 LX, "jne", 12, | 350 { LO, "jmp", 8 }, 351 { LO, "jc", 9 }, 352 { LO, "jnc", 10 }, 353 { LO, "call", 11 }, 354 { LA, "jz", 15 }, 355 { LA, "jnz", 13 }, 356 { LX, "je", 14 }, 357 { LX, "jne", 12 }, |
340 }; 341 342 spec &= ~(LO|LA|LX); 343 344 for (i = 0; i < sizeof(jmptab)/sizeof(jmptab[0]); i++) 345 if (jmptab[i].what == want && 346 !strcmp(jmptab[i].name, a[spec])) 347 { 348 return(jmptab[i].value); 349 } 350 351 if (want) 352 error("invalid jump"); 353 354 return(spec); /* "case 0" - no flags set */ 355} 356 | 358 }; 359 360 spec &= ~(LO|LA|LX); 361 362 for (i = 0; i < sizeof(jmptab)/sizeof(jmptab[0]); i++) 363 if (jmptab[i].what == want && 364 !strcmp(jmptab[i].name, a[spec])) 365 { 366 return(jmptab[i].value); 367 } 368 369 if (want) 370 error("invalid jump"); 371 372 return(spec); /* "case 0" - no flags set */ 373} 374 |
357int eval_sdi(char **a, int spec) | 375int 376eval_sdi(char **a, int spec) |
358{ 359 sym_t *p; 360 unsigned val; 361 362 if (spec == NA) 363 return(NA); 364 365 switch (spec & (A|I|SL|SR|RL|RR)) { --- 52 unchanged lines hidden (view full) --- 418 if (p) 419 return(p->value); 420 error("undefined symbol used"); 421 } 422 423 return(NA); /* shut the compiler up */ 424} 425 | 377{ 378 sym_t *p; 379 unsigned val; 380 381 if (spec == NA) 382 return(NA); 383 384 switch (spec & (A|I|SL|SR|RL|RR)) { --- 52 unchanged lines hidden (view full) --- 437 if (p) 438 return(p->value); 439 error("undefined symbol used"); 440 } 441 442 return(NA); /* shut the compiler up */ 443} 444 |
426int eval_addr(char **a, int spec) | 445int 446eval_addr(char **a, int spec) |
427{ 428 sym_t *p; 429 430 if (spec == NA) 431 return(NA); 432 if (isdigit(*a[spec])) 433 return(strtol(a[spec], NULL, 0)); 434 --- 7 unchanged lines hidden (view full) --- 442 define(a[spec], NOVALUE); 443 p = lookup(a[spec]); 444 patch(p, LC); 445 } 446 447 return(NA); /* will be patched in later */ 448} 449 | 447{ 448 sym_t *p; 449 450 if (spec == NA) 451 return(NA); 452 if (isdigit(*a[spec])) 453 return(strtol(a[spec], NULL, 0)); 454 --- 7 unchanged lines hidden (view full) --- 462 define(a[spec], NOVALUE); 463 p = lookup(a[spec]); 464 patch(p, LC); 465 } 466 467 return(NA); /* will be patched in later */ 468} 469 |
450int crack(char **a, int n) | 470int 471crack(char **a, int n) |
451{ 452 int i; 453 int I_imm, I_addr; 454 int I_op, I_dest, I_src, I_ret; 455 456 /* 457 * Check for "ret" at the end of the line; remove 458 * it unless it's "ret" alone - we still want to --- 37 unchanged lines hidden (view full) --- 496 error("illegal use of \"ret\""); 497 M[LC][0] = (I_op << 1) | ((I_addr >> 8) & 1); 498 M[LC][1] = I_addr & 0xff; 499 M[LC][2] = I_src; 500 M[LC][3] = I_imm; 501 break; 502 } 503 | 472{ 473 int i; 474 int I_imm, I_addr; 475 int I_op, I_dest, I_src, I_ret; 476 477 /* 478 * Check for "ret" at the end of the line; remove 479 * it unless it's "ret" alone - we still want to --- 37 unchanged lines hidden (view full) --- 517 error("illegal use of \"ret\""); 518 M[LC][0] = (I_op << 1) | ((I_addr >> 8) & 1); 519 M[LC][1] = I_addr & 0xff; 520 M[LC][2] = I_src; 521 M[LC][3] = I_imm; 522 break; 523 } 524 |
504 return(1); /* no two-byte instructions yet */ | 525 return (1); /* no two-byte instructions yet */ |
505} 506 507#undef SL 508#undef SR 509#undef RL 510#undef RR 511#undef LX 512#undef LA 513#undef LO 514#undef I 515#undef A 516 | 526} 527 528#undef SL 529#undef SR 530#undef RL 531#undef RR 532#undef LX 533#undef LA 534#undef LO 535#undef I 536#undef A 537 |
517void assemble(void) | 538void 539assemble(void) |
518{ 519 int n; 520 char **a; 521 sym_t *p; 522 523 while ((a = getl(&n))) { 524 525 while (a[0][strlen(*a)-1] == ':') { --- 22 unchanged lines hidden (view full) --- 548 549 backpatch(); 550 output(ofp); 551 552 if (debug) 553 output(stderr); 554} 555 | 540{ 541 int n; 542 char **a; 543 sym_t *p; 544 545 while ((a = getl(&n))) { 546 547 while (a[0][strlen(*a)-1] == ':') { --- 22 unchanged lines hidden (view full) --- 570 571 backpatch(); 572 output(ofp); 573 574 if (debug) 575 output(stderr); 576} 577 |
556int main(int argc, char **argv) | 578int 579main(int argc, char **argv) |
557{ 558 int c; 559 | 580{ 581 int c; 582 |
560 while ((c = getopt(argc, argv, "dho:")) != EOF) { | 583 while ((c = getopt(argc, argv, "dho:vD")) != EOF) { |
561 switch (c) { 562 case 'd': 563 debug = !0; 564 break; | 584 switch (c) { 585 case 'd': 586 debug = !0; 587 break; |
588 case 'D': 589 { 590 char *p; 591 if ((p = strchr(optarg, '=')) != NULL) { 592 *p = '\0'; 593 define(optarg, strtol(p + 1, NULL, 0)); 594 } 595 else 596 define(optarg, 1); 597 break; 598 } |
|
565 case 'o': 566 ofp = fopen(optarg, "w"); 567 if (!ofp) { 568 perror(optarg); 569 exit(EXIT_FAILURE); 570 } 571 break; 572 case 'h': | 599 case 'o': 600 ofp = fopen(optarg, "w"); 601 if (!ofp) { 602 perror(optarg); 603 exit(EXIT_FAILURE); 604 } 605 break; 606 case 'h': |
573 printf("usage: %s [-d] [-ooutput] input\n", *argv); | 607 printf("usage: %s [-d] [-Dname] [-ooutput] input\n", 608 *argv); |
574 exit(EXIT_SUCCESS); | 609 exit(EXIT_SUCCESS); |
575 case NULL: 576 /* 577 * An impossible option to shut the compiler 578 * up about sccsid[]. 579 */ 580 exit((int)sccsid); | 610 break; 611 case 'v': 612 printf("%s\n", id); 613 exit(EXIT_SUCCESS); 614 break; |
581 default: 582 exit(EXIT_FAILURE); | 615 default: 616 exit(EXIT_FAILURE); |
617 break; |
|
583 } 584 } 585 586 if (argc - optind != 1) { 587 fprintf(stderr, "%s: must have one input file\n", *argv); 588 exit(EXIT_FAILURE); 589 } 590 filename = argv[optind]; --- 18 unchanged lines hidden --- | 618 } 619 } 620 621 if (argc - optind != 1) { 622 fprintf(stderr, "%s: must have one input file\n", *argv); 623 exit(EXIT_FAILURE); 624 } 625 filename = argv[optind]; --- 18 unchanged lines hidden --- |