summaryrefslogtreecommitdiffstats
path: root/whichasm-0.01/classifier_ppc.c
blob: dcea4c759ea56fa47852c6bf960407f06c6d46bf (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
54
55
56
57
58
59
60
61
/*
 * Classifier for ppc assembly language
 *
 * Copyright (C) 2012 Red Hat, Inc.
 *
 */

/* PowerPC/POWER opcodes have a form similar to:
 *    nmemonic <Rt>, <Ra>, <Rb>...
 * Register names include the following (32-bit is notional):
 *    32/64-bit GPRS: GPR0-GPR31
 *    32/64-bit SPRS: SPRG4-SPRG7
 *    32-bit Condition register: CR
 *    32/64-bit Link Register: LR
 *    32/64-bit Count Register: CTR
 *    32/64-bit Fixed-Point Exception Register: XER
 *    32-bit VR Save Register: VRSAVE
 *    32/64-bit Floating Point: FPR0-FPR31
 *    32/64-bit Vector registers: VR0-VR31
 *    32-bit Vector Status control: VSCR
 *    32/64-bit Vector scalar registers: VSR0-VSR63
 */

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

#include "classifier.h"

int classifier_ppc(char *token_name)
{
        const struct ppc_opcode *opcode;
        const struct ppc_reg *reg;

        for (opcode=ppc_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=ppc_regs;reg->assembler;reg++) {
		if (strlen(token_name) == strlen(reg->assembler))
			if (0 == strncasecmp(reg->assembler,token_name,
					     strlen(token_name))) {
				//printf("ppc register match\n");
                        	return REGISTER;
			}
        }

        return UNKNOWN;
}