blob: 2f1a830eb202d444112911bb8a851a6bd8188436 [file] [log] [blame]
Dan Bornsteind12de172010-12-02 15:21:59 -08001# Copyright (C) 2007 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Dan Bornstein973171b2010-12-03 13:01:06 -080015#
Dan Bornsteind12de172010-12-02 15:21:59 -080016# Awk helper script for opcode-gen.
Dan Bornstein973171b2010-12-03 13:01:06 -080017#
18
19#
20# Initialization.
21#
Dan Bornsteind12de172010-12-02 15:21:59 -080022
23BEGIN {
24 MAX_OPCODE = 65535;
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -080025 MAX_PACKED_OPCODE = 511;
Dan Bornsteind12de172010-12-02 15:21:59 -080026 initIndexTypes();
27 initFlags();
28 if (readBytecodes()) exit 1;
29 deriveOpcodeChains();
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -080030 createPackedTables();
Dan Bornsteind12de172010-12-02 15:21:59 -080031 consumeUntil = "";
Dan Bornstein973171b2010-12-03 13:01:06 -080032 emission = "";
Dan Bornsteind12de172010-12-02 15:21:59 -080033}
34
Dan Bornstein973171b2010-12-03 13:01:06 -080035#
36# General control (must appear above directive handlers).
37#
38
39# Clear out the preexisting output within a directive section.
Dan Bornsteind12de172010-12-02 15:21:59 -080040consumeUntil != "" {
41 if (index($0, consumeUntil) != 0) {
42 consumeUntil = "";
Dan Bornstein973171b2010-12-03 13:01:06 -080043 print;
Dan Bornsteind12de172010-12-02 15:21:59 -080044 }
Dan Bornstein973171b2010-12-03 13:01:06 -080045
46 next;
Dan Bornsteind12de172010-12-02 15:21:59 -080047}
48
Dan Bornstein973171b2010-12-03 13:01:06 -080049# Detect directives.
Dan Bornsteina277f142010-12-03 15:11:55 -080050/BEGIN\([a-z-]*\)/ {
51 i = match($0, /BEGIN\([a-z-]*\)/);
Dan Bornstein973171b2010-12-03 13:01:06 -080052 emission = substr($0, i + 6, RLENGTH - 7);
53 consumeUntil = "END(" emission ")";
54 emissionHandled = 0;
Dan Bornstein9dc57d32010-12-03 17:58:01 -080055}
56
57# Most lines just get copied from the source as-is, including the start
58# comment for directives.
59{
Dan Bornsteind12de172010-12-02 15:21:59 -080060 print;
Dan Bornstein973171b2010-12-03 13:01:06 -080061}
62
63#
64# Handlers for all of the directives.
65#
66
67emission == "opcodes" {
68 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -080069
70 for (i = 0; i <= MAX_OPCODE; i++) {
71 if (isUnused(i) || isOptimized(i)) continue;
72 printf(" public static final int %s = 0x%s;\n",
73 constName[i], hex[i]);
74 }
Dan Bornsteind12de172010-12-02 15:21:59 -080075}
76
Dan Bornstein973171b2010-12-03 13:01:06 -080077emission == "first-opcodes" {
78 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -080079
80 for (i = 0; i <= MAX_OPCODE; i++) {
81 if (isUnused(i) || isOptimized(i)) continue;
82 if (isFirst[i] == "true") {
Dan Bornstein7ba91292011-01-30 14:05:39 -080083 printf(" // Opcodes.%s\n", constName[i]);
Dan Bornsteind12de172010-12-02 15:21:59 -080084 }
85 }
Dan Bornsteind12de172010-12-02 15:21:59 -080086}
87
Dan Bornstein973171b2010-12-03 13:01:06 -080088emission == "dops" {
89 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -080090
91 for (i = 0; i <= MAX_OPCODE; i++) {
92 if (isUnused(i) || isOptimized(i)) continue;
93
94 nextOp = nextOpcode[i];
95 nextOp = (nextOp == -1) ? "NO_NEXT" : constName[nextOp];
96
97 printf(" public static final Dop %s =\n" \
Dan Bornstein7ba91292011-01-30 14:05:39 -080098 " new Dop(Opcodes.%s, Opcodes.%s,\n" \
Dan Bornsteina754fbb2011-02-02 11:45:53 -080099 " Opcodes.%s, Form%s.THE_ONE, %s);\n\n",
Dan Bornsteind12de172010-12-02 15:21:59 -0800100 constName[i], constName[i], family[i], nextOp, format[i],
Dan Bornsteina754fbb2011-02-02 11:45:53 -0800101 hasResult[i]);
Dan Bornsteind12de172010-12-02 15:21:59 -0800102 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800103}
104
Dan Bornstein3c5df372011-01-25 16:39:12 -0800105emission == "opcode-info-defs" {
106 emissionHandled = 1;
107
108 for (i = 0; i <= MAX_OPCODE; i++) {
109 if (isUnused(i) || isOptimized(i)) continue;
110
111 itype = indexType[i];
112 if ((itype == "none") || (itype == "unknown")) {
113 itype = "null";
114 } else {
115 itype = toupper(itype);
116 gsub(/-/, "_", itype);
117 itype = "IndexType." itype;
118 }
119
120 printf(" public static final Info %s =\n" \
Dan Bornsteina754fbb2011-02-02 11:45:53 -0800121 " new Info(Opcodes.%s, \"%s\",\n" \
Dan Bornstein3c5df372011-01-25 16:39:12 -0800122 " InstructionCodec.FORMAT_%s, %s);\n\n", \
Dan Bornsteina754fbb2011-02-02 11:45:53 -0800123 constName[i], constName[i], name[i], toupper(format[i]), itype);
Dan Bornstein3c5df372011-01-25 16:39:12 -0800124 }
125}
126
127emission == "dops-init" || emission == "opcode-info-init" {
Dan Bornstein973171b2010-12-03 13:01:06 -0800128 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800129
130 for (i = 0; i <= MAX_OPCODE; i++) {
131 if (isUnused(i) || isOptimized(i)) continue;
132 printf(" set(%s);\n", constName[i]);
133 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800134}
135
Dan Bornstein973171b2010-12-03 13:01:06 -0800136emission == "libcore-opcodes" {
137 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800138
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800139 for (i = 0; i <= MAX_OPCODE; i++) {
140 if (isUnused(i) || isOptimized(i)) continue;
Dan Bornstein21f322d2010-12-03 13:16:08 -0800141 printf(" int OP_%-28s = 0x%04x;\n", constName[i], i);
Dan Bornsteind12de172010-12-02 15:21:59 -0800142 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800143}
144
Dan Bornstein973171b2010-12-03 13:01:06 -0800145emission == "libcore-maximum-values" {
146 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800147
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800148 printf(" MAXIMUM_VALUE = %d;\n", MAX_OPCODE);
149 printf(" MAXIMUM_PACKED_VALUE = %d;\n", MAX_PACKED_OPCODE);
Dan Bornsteind12de172010-12-02 15:21:59 -0800150}
151
Dan Bornsteinccaab182010-12-03 15:32:40 -0800152emission == "libdex-maximum-values" {
153 emissionHandled = 1;
154
Dan Bornstein29d5b5d2010-12-03 17:48:27 -0800155 printf("#define kMaxOpcodeValue 0x%x\n", MAX_OPCODE);
156 printf("#define kNumPackedOpcodes 0x%x\n", MAX_PACKED_OPCODE + 1);
Dan Bornsteinccaab182010-12-03 15:32:40 -0800157}
158
Dan Bornstein973171b2010-12-03 13:01:06 -0800159emission == "libdex-opcode-enum" {
160 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800161
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800162 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
163 printf(" OP_%-28s = 0x%02x,\n", packedConstName[i], i);
Dan Bornsteind12de172010-12-02 15:21:59 -0800164 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800165}
166
Dan Bornstein973171b2010-12-03 13:01:06 -0800167emission == "libdex-goto-table" {
168 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800169
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800170 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
171 content = sprintf(" H(OP_%s),", packedConstName[i]);
Dan Bornsteind12de172010-12-02 15:21:59 -0800172 printf("%-78s\\\n", content);
173 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800174}
175
Dan Bornstein973171b2010-12-03 13:01:06 -0800176emission == "libdex-opcode-names" {
177 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800178
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800179 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
180 printf(" \"%s\",\n", packedName[i]);
Dan Bornsteind12de172010-12-02 15:21:59 -0800181 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800182}
183
Dan Bornstein973171b2010-12-03 13:01:06 -0800184emission == "libdex-widths" {
185 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800186
187 col = 1;
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800188 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
189 value = sprintf("%d,", packedWidth[i]);
190 col = colPrint(value, (i == MAX_PACKED_OPCODE), col, 16, 2, " ");
Dan Bornsteind12de172010-12-02 15:21:59 -0800191 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800192}
193
Dan Bornstein973171b2010-12-03 13:01:06 -0800194emission == "libdex-flags" {
195 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800196
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800197 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
198 value = flagsToC(packedFlags[i]);
Dan Bornsteind12de172010-12-02 15:21:59 -0800199 printf(" %s,\n", value);
200 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800201}
202
Dan Bornstein973171b2010-12-03 13:01:06 -0800203emission == "libdex-formats" {
204 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800205
206 col = 1;
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800207 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
208 value = sprintf("kFmt%s,", packedFormat[i]);
209 col = colPrint(value, (i == MAX_PACKED_OPCODE), col, 7, 9, " ");
Dan Bornsteind12de172010-12-02 15:21:59 -0800210 }
Dan Bornsteind12de172010-12-02 15:21:59 -0800211}
212
Dan Bornstein973171b2010-12-03 13:01:06 -0800213emission == "libdex-index-types" {
214 emissionHandled = 1;
Dan Bornsteind12de172010-12-02 15:21:59 -0800215
216 col = 1;
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800217 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
218 value = sprintf("%s,", indexTypeValues[packedIndexType[i]]);
219 col = colPrint(value, (i == MAX_PACKED_OPCODE), col, 3, 19, " ");
Dan Bornsteind12de172010-12-02 15:21:59 -0800220 }
Dan Bornstein973171b2010-12-03 13:01:06 -0800221}
Dan Bornsteind12de172010-12-02 15:21:59 -0800222
Dan Bornstein9dc57d32010-12-03 17:58:01 -0800223# Handle the end of directive processing (must appear after the directive
224# clauses).
Dan Bornstein973171b2010-12-03 13:01:06 -0800225emission != "" {
226 if (!emissionHandled) {
227 printf("WARNING: unknown tag \"%s\"\n", emission) >"/dev/stderr";
228 consumeUntil = "";
229 }
230
231 emission = "";
Dan Bornsteind12de172010-12-02 15:21:59 -0800232}
233
Dan Bornstein973171b2010-12-03 13:01:06 -0800234#
235# Helper functions.
236#
237
Dan Bornsteind12de172010-12-02 15:21:59 -0800238# Helper to print out an element in a multi-column fashion. It returns
239# the (one-based) column number that the next element will be printed
240# in.
241function colPrint(value, isLast, col, numCols, colWidth, linePrefix) {
242 isLast = (isLast || (col == numCols));
243 printf("%s%-*s%s",
244 (col == 1) ? linePrefix : " ",
245 isLast ? 1 : colWidth, value,
246 isLast ? "\n" : "");
247
248 return (col % numCols) + 1;
249}
250
251# Read the bytecode description file.
252function readBytecodes(i, parts, line, cmd, status, count) {
253 # locals: parts, line, cmd, status, count
254 for (;;) {
255 # Read a line.
256 status = getline line <bytecodeFile;
257 if (status == 0) break;
258 if (status < 0) {
259 print "trouble reading bytecode file";
260 exit 1;
261 }
262
263 # Clean up the line and extract the command.
264 gsub(/ */, " ", line);
265 sub(/ *#.*$/, "", line);
266 sub(/ $/, "", line);
267 sub(/^ /, "", line);
268 count = split(line, parts);
269 if (count == 0) continue; # Blank or comment line.
270 cmd = parts[1];
271 sub(/^[a-z][a-z]* */, "", line); # Remove the command from line.
272
273 if (cmd == "op") {
274 status = defineOpcode(line);
275 } else if (cmd == "format") {
276 status = defineFormat(line);
277 } else {
278 status = -1;
279 }
280
281 if (status != 0) {
Dan Bornstein973171b2010-12-03 13:01:06 -0800282 printf("syntax error on line: %s\n", line) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800283 return 1;
284 }
285 }
286
287 return 0;
288}
289
290# Define an opcode.
291function defineOpcode(line, count, parts, idx) {
292 # locals: count, parts, idx
293 count = split(line, parts);
294 if (count != 6) return -1;
295 idx = parseHex(parts[1]);
296 if (idx < 0) return -1;
297
298 # Extract directly specified values from the line.
299 hex[idx] = parts[1];
300 name[idx] = parts[2];
301 format[idx] = parts[3];
302 hasResult[idx] = (parts[4] == "n") ? "false" : "true";
303 indexType[idx] = parts[5];
304 flags[idx] = parts[6];
305
306 # Calculate derived values.
307
308 constName[idx] = toupper(name[idx]);
Dan Bornstein9dc57d32010-12-03 17:58:01 -0800309 gsub("[/-]", "_", constName[idx]); # Dash and slash become underscore.
Dan Bornsteind12de172010-12-02 15:21:59 -0800310 gsub("[+^]", "", constName[idx]); # Plus and caret are removed.
311 split(name[idx], parts, "/");
312
313 family[idx] = toupper(parts[1]);
314 gsub("-", "_", family[idx]); # Dash becomes underscore.
315 gsub("[+^]", "", family[idx]); # Plus and caret are removed.
316
317 split(format[idx], parts, ""); # Width is the first format char.
318 width[idx] = parts[1];
319
320 # This association is used when computing "next" opcodes.
321 familyFormat[family[idx],format[idx]] = idx;
322
323 # Verify values.
324
325 if (nextFormat[format[idx]] == "") {
Dan Bornstein973171b2010-12-03 13:01:06 -0800326 printf("unknown format: %s\n", format[idx]) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800327 return 1;
328 }
329
330 if (indexTypeValues[indexType[idx]] == "") {
Dan Bornstein973171b2010-12-03 13:01:06 -0800331 printf("unknown index type: %s\n", indexType[idx]) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800332 return 1;
333 }
334
335 if (flagsToC(flags[idx]) == "") {
Dan Bornstein973171b2010-12-03 13:01:06 -0800336 printf("bogus flags: %s\n", flags[idx]) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800337 return 1;
338 }
339
340 return 0;
341}
342
343# Define a format family.
344function defineFormat(line, count, parts, i) {
345 # locals: count, parts, i
346 count = split(line, parts);
347 if (count < 1) return -1;
348 formats[parts[1]] = line;
349
350 parts[count + 1] = "none";
351 for (i = 1; i <= count; i++) {
352 nextFormat[parts[i]] = parts[i + 1];
353 }
354
355 return 0;
356}
357
358# Produce the nextOpcode and isFirst arrays. The former indicates, for
359# each opcode, which one should be tried next when doing instruction
360# fitting. The latter indicates which opcodes are at the head of an
361# instruction fitting chain.
362function deriveOpcodeChains(i, op) {
363 # locals: i, op
364
365 for (i = 0; i <= MAX_OPCODE; i++) {
366 if (isUnused(i)) continue;
367 isFirst[i] = "true";
368 }
369
370 for (i = 0; i <= MAX_OPCODE; i++) {
371 if (isUnused(i)) continue;
372 op = findNextOpcode(i);
373 nextOpcode[i] = op;
374 if (op != -1) {
375 isFirst[op] = "false";
376 }
377 }
378}
379
380# Given an opcode by index, find the next opcode in the same family
381# (that is, with the same base name) to try when matching instructions
382# to opcodes. This simply walks the nextFormat chain looking for a
383# match. This returns the index of the matching opcode or -1 if there
384# is none.
385function findNextOpcode(idx, fam, fmt, result) {
386 # locals: fam, fmt, result
387 fam = family[idx];
388 fmt = format[idx];
389
390 # Not every opcode has a version with every possible format, so
391 # we have to iterate down the chain until we find one or run out of
392 # formats to try.
393 for (fmt = nextFormat[format[idx]]; fmt != "none"; fmt = nextFormat[fmt]) {
394 result = familyFormat[fam,fmt];
395 if (result != "") {
396 return result;
397 }
398 }
399
400 return -1;
401}
402
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800403# Construct the tables of info indexed by packed opcode. The packed opcode
404# values are in the range 0-0x1ff, whereas the unpacked opcodes sparsely
405# span the range 0-0xffff.
406function createPackedTables(i, op) {
407 # locals: i, op
408 for (i = 0; i <= MAX_PACKED_OPCODE; i++) {
409 op = unpackOpcode(i);
410 if (i == 255) {
411 # Special case: This is the low-opcode slot for a would-be
412 # extended opcode dispatch implementation.
413 packedName[i] = "dispatch-ff";
414 packedConstName[i] = "DISPATCH_FF";
415 packedFormat[i] = "00x";
416 packedFlags[i] = 0;
417 packedWidth[i] = 0;
418 packedIndexType[i] = "unknown";
419 } else if (isUnused(op)) {
420 packedName[i] = unusedName(op);
421 packedConstName[i] = unusedConstName(op);
422 packedFormat[i] = "00x";
423 packedFlags[i] = 0;
424 packedWidth[i] = 0;
425 packedIndexType[i] = "unknown";
426 } else {
427 packedName[i] = name[op];
428 packedConstName[i] = constName[op];
429 packedFormat[i] = format[op];
430 packedFlags[i] = flags[op];
431 packedWidth[i] = width[op];
432 packedIndexType[i] = indexType[op];
433 }
434 }
435}
436
437# Given a packed opcode, returns the raw (unpacked) opcode value.
438function unpackOpcode(idx) {
439 # Note: This must be the inverse of the corresponding code in
440 # libdex/DexOpcodes.h.
441 if (idx <= 255) {
442 return idx;
443 } else {
Dan Bornstein21f322d2010-12-03 13:16:08 -0800444 idx -= 256;
Dan Bornstein3c4dc3b2010-12-02 16:05:51 -0800445 return (idx * 256) + 255;
446 }
447}
448
449# Returns the "unused" name of the given opcode (by index).
450# That is, this is the human-oriented name to use for an opcode
451# definition in cases
452# where the opcode isn't used.
453function unusedName(idx) {
454 if (idx <= 255) {
455 return sprintf("unused-%02x", idx);
456 } else {
457 return sprintf("unused-%04x", idx);
458 }
459}
460
461# Returns the "unused" constant name of the given opcode (by index).
462# That is, this is the name to use for a constant definition in cases
463# where the opcode isn't used.
464function unusedConstName(idx) {
465 if (idx <= 255) {
466 return toupper(sprintf("UNUSED_%02x", idx));
467 } else {
468 return toupper(sprintf("UNUSED_%04x", idx));
469 }
470}
471
Dan Bornsteind12de172010-12-02 15:21:59 -0800472# Convert a hex value to an int.
473function parseHex(hex, result, chars, count, c, i) {
474 # locals: result, chars, count, c, i
475 hex = tolower(hex);
476 count = split(hex, chars, "");
477 result = 0;
478 for (i = 1; i <= count; i++) {
479 c = index("0123456789abcdef", chars[i]);
480 if (c == 0) {
Dan Bornstein973171b2010-12-03 13:01:06 -0800481 printf("bogus hex value: %s\n", hex) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800482 return -1;
483 }
484 result = (result * 16) + c - 1;
485 }
486 return result;
487}
488
489# Initialize the indexTypes data.
490function initIndexTypes() {
491 indexTypeValues["unknown"] = "kIndexUnknown";
492 indexTypeValues["none"] = "kIndexNone";
493 indexTypeValues["varies"] = "kIndexVaries";
494 indexTypeValues["type-ref"] = "kIndexTypeRef";
495 indexTypeValues["string-ref"] = "kIndexStringRef";
496 indexTypeValues["method-ref"] = "kIndexMethodRef";
497 indexTypeValues["field-ref"] = "kIndexFieldRef";
498 indexTypeValues["inline-method"] = "kIndexInlineMethod";
499 indexTypeValues["vtable-offset"] = "kIndexVtableOffset";
500 indexTypeValues["field-offset"] = "kIndexFieldOffset";
501}
502
503# Initialize the flags data.
504function initFlags() {
505 flagValues["branch"] = "kInstrCanBranch";
506 flagValues["continue"] = "kInstrCanContinue";
507 flagValues["switch"] = "kInstrCanSwitch";
508 flagValues["throw"] = "kInstrCanThrow";
509 flagValues["return"] = "kInstrCanReturn";
510 flagValues["invoke"] = "kInstrInvoke";
511 flagValues["optimized"] = "0"; # Not represented in C output
512 flagValues["0"] = "0";
513}
514
515# Translate the given flags into the equivalent C expression. Returns
516# "" on error.
517function flagsToC(f, parts, result, i) {
518 # locals: parts, result, i
519 count = split(f, parts, /\|/); # Split input at pipe characters.
520 result = "0";
521
522 for (i = 1; i <= count; i++) {
523 f = flagValues[parts[i]];
524 if (f == "") {
Dan Bornstein973171b2010-12-03 13:01:06 -0800525 printf("bogus flag: %s\n", f) >"/dev/stderr";
Dan Bornsteind12de172010-12-02 15:21:59 -0800526 return ""; # Bogus flag name.
527 } else if (f == "0") {
528 # Nothing to append for this case.
529 } else if (result == "0") {
530 result = f;
531 } else {
532 result = result "|" f;
533 }
534 }
535
536 return result;
537}
538
Dan Bornsteind12de172010-12-02 15:21:59 -0800539# Returns true if the given opcode (by index) is an "optimized" opcode.
540function isOptimized(idx, parts, f) {
541 # locals: parts, f
542 split(flags[idx], parts, /\|/); # Split flags[idx] at pipes.
543 for (f in parts) {
544 if (parts[f] == "optimized") return 1;
545 }
546 return 0;
547}
548
549# Returns true if there is no definition for the given opcode (by index).
550function isUnused(idx) {
551 return (name[idx] == "");
552}