File: mkopcode.awk

package info (click to toggle)
xcache 2.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,724 kB
  • sloc: ansic: 8,175; php: 4,557; awk: 285; sh: 135; makefile: 75
file content (77 lines) | stat: -rwxr-xr-x 1,375 bytes parent folder | download | duplicates (3)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/awk -f
# vim:ts=4:sw=4
# process zend_vm_def.h or zend_compile.h
BEGIN {
	FS=" "
	max = 0;
}

/^ZEND_VM_HANDLER\(/ {
	# regex from php5.1+/Zend/zend_vm_gen.php
	gsub(/ +/, "");
	if (!match($0, /^ZEND_VM_HANDLER\(([0-9]+),([A-Z_]+),([A-Z|]+),([A-Z|]+)\)/)) {
		print "error unmatch $0";
		exit;
	}
	# life is hard without 3rd argument of match()
	sub(/^ZEND_VM_HANDLER\(/, "");
	id = $0;
	sub(/,.*/, "", id); # chop
	id = 0 + id;
	sub(/^([0-9]+),/, "");
	sub(/,.*/, ""); # chop
	name = $0;
	if (max < id) {
		max = id;
	}
	opcodes[id] = name;
	next;
}

/^#define +ZEND_[A-Z_]+[\t ]+[[:digit:]]+$/ {
	id = 0 + $3;
	name = $2;
	if (max < id) {
		max = id;
	}
	opcodes[id] = name;
	next;
}

/end of block/ {
	exit;
}

END {
	mymax = 112;
	if (max < mymax) {
		for (i = max + 1; i <= mymax; i ++) {
			opcodes[i] = "UNDEF";
		}
		max = mymax;
		opcodes[110] = "ZEND_DO_FCALL_BY_FUNC";
		opcodes[111] = "ZEND_INIT_FCALL_BY_FUNC";
		opcodes[112] = "UNDEF";
	}
	printf "/* size = %d */\n", max + 1;
	print "static const char *const xc_opcode_names[] = {";
	for (i = 0; i <= max; i ++) {
		if (i != 0) {
			print ",";
		}
		printf "/* %d */\t", i
		if (i in opcodes) {
			name = opcodes[i];
			sub(/^ZEND_/, "", name);
			printf "\"%s\"", name;
		}
		else if (i == 137) {
			printf "\"%s\"", "OP_DATA";
		}
		else {
			printf "\"UNDEF\"";
		}
	}
	print "";
	print "};";
}