forget difference between big and small commands - obsolete with vm.
[minix.git] / commands / i386 / gas2ack / asm86.c
blob29c5b7ba9510c2481fada358afda2f348aa5e04e
1 /* asm86.c - 80X86 assembly intermediate Author: Kees J. Bot
2 * 24 Dec 1993
3 */
4 #define nil 0
5 #include <stddef.h>
6 #include <string.h>
7 #include <assert.h>
8 #include "asm86.h"
9 #include "asmconv.h"
10 #include "token.h"
12 expression_t *new_expr(void)
13 /* Make a new cell to build an expression. */
15 expression_t *e;
17 e= allocate(nil, sizeof(*e));
18 e->operator= -1;
19 e->left= e->middle= e->right= nil;
20 e->name= nil;
21 e->magic= 31624;
22 return e;
25 void del_expr(expression_t *e)
26 /* Delete an expression tree. */
28 if (e != nil) {
29 assert(e->magic == 31624);
30 e->magic= 0;
31 deallocate(e->name);
32 del_expr(e->left);
33 del_expr(e->middle);
34 del_expr(e->right);
35 deallocate(e);
39 asm86_t *new_asm86(void)
40 /* Make a new cell to hold an 80X86 instruction. */
42 asm86_t *a;
44 a= allocate(nil, sizeof(*a));
45 a->opcode= -1;
46 get_file(&a->file, &a->line);
47 a->optype= NONE;
48 a->oaz= 0;
49 a->rep= ONCE;
50 a->seg= DEFSEG;
51 a->args= nil;
52 a->magic= 37937;
53 a->raw_string = NULL;
54 return a;
57 void del_asm86(asm86_t *a)
58 /* Delete an 80X86 instruction. */
60 assert(a != nil);
61 assert(a->magic == 37937);
62 a->magic= 0;
63 del_expr(a->args);
64 deallocate(a->raw_string);
65 a->raw_string = NULL;
66 deallocate(a);
69 int isregister(const char *name)
70 /* True if the string is a register name. Return its size. */
72 static char *regs[] = {
73 "al", "bl", "cl", "dl", "ah", "bh", "ch", "dh",
74 "ax", "bx", "cx", "dx", "si", "di", "bp", "sp",
75 "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp", "esp",
76 "cs", "ds", "es", "fs", "gs", "ss",
77 "cr0", "cr1", "cr2", "cr3", "cr4",
78 "st",
80 int reg;
82 for (reg= 0; reg < arraysize(regs); reg++) {
83 if (strcmp(name, regs[reg]) == 0)
84 return reg+1;
86 return 0;