summaryrefslogtreecommitdiffstats
path: root/whichasm-0.01/classifier_s390x.c
blob: 2ce9d9346ed04cec27d0313d304fe1f03413b1b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Classifier for s390x assembly language
 *
 * Copyright (C) 2012 Red Hat, Inc.
 *
 */

/* s390x opcodes have 26 different formats but mostly match this:
 *    nmemonic <param1>, <param2>, <param3>...
 * Register names include the following:
 *    32/64-bit GPRS: R0-R15 (GPR0-GPR15)
 *    32/64-bit control registers: CR0-CR15
 *    32-bit access registers: AR0-AR15
 *    64-bit floating point: FP0-FP15
 *    64/128-bit status reg: PSW
 */

#include "s390x.h"
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
#include <stdlib.h>
#include <string.h>

#include "classifier.h"

int classifier_s390x(char *token_name)
{
        const struct s390x_opcode *opcode;
        const struct s390x_reg *reg;

        for (opcode=s390x_opcodes;opcode->assembler;opcode++) {
		// TODO - catch variants of assembly language mnemonics
		// previously limited to opcode->assembler length
		// need to catch assembly that has appended letters
		if (strlen(token_name) == strlen(opcode->assembler))
			if (0 == strncasecmp(token_name, opcode->assembler,
					     strlen(opcode->assembler))) {
				//printf("opcode: %s\n", opcode->assembler);
                        	return MNEMONIC;
			}
        }

        for (reg=s390x_regs;reg->assembler;reg++) {
		if (strlen(token_name) == strlen(reg->assembler))
			if (0 == strncasecmp(reg->assembler,token_name,
					     strlen(token_name)))
                        return REGISTER;
        }

        return UNKNOWN;
}