📄 ops-to-gp
字号:
MCC = '$MCC' GCC = '$GCC' i = 0; COUNT = i++ OPTIMIZE = i++ CONSTRAINTS = i++ INSN_CODE = i++ PREDICATE = i++ TRANSFORM = i++ VOLATILE_PTR_OK = i++ CONST_PTR_OK = i++ INSTRUCTION = i++ ADDRESSIBLE = i++ CONFIGURED = i++ WHEN = i++ SPECIFIC = i++ RESULT = i++ EQ = i++ OPN = i++ NARGS = i++ if (MCC) { print "%{"; print "/* Command-line: '"$gperf"' */"; MAXARGS = 5 } if (GCC) MAXARGS = 3 } function write_test(tree, type, num) { if (type == "PTR") { printf "\n && TY_kind(%s) == KIND_POINTER", tree; } else if (type == "I5") { printf "\n && is_integer_type(%s)", tree; printf "\n && Is_Const(ND_kid0(ND_kid(t,%d)), &tc)", num; printf "\n && ((UINT32)Targ_To_Host(tc) + 16) < 32"; } else if (type == "U5") { printf "\n && is_integer_type(%s)", tree; printf "\n && Is_Const(ND_kid0(ND_kid(t,%d)), &tc)", num; printf "\n && (UINT32)Targ_To_Host(tc) < 32"; } else if (type == "U4") { printf "\n && is_integer_type(%s)", tree; printf "\n && Is_Const(ND_kid0(ND_kid(t,%d)), &tc)", num; printf "\n && (UINT32)Targ_To_Host(tc) < 16"; } else if (type == "U2") { printf "\n && is_integer_type(%s)", tree; printf "\n && Is_Const(ND_kid0(ND_kid(t,%d)), &tc)", num; printf "\n && (UINT32)Targ_To_Host(tc) < 4"; } else if (type == "BETYPE_U4" || type == "BETYPE_I4") { printf "\n && is_integer_type(%s)", tree; } else { printf "\n && Similar_Types(%s,", tree; printf "\n\t\t Be_Type_Tbl(%s), IGNORE_QUALIFIERS)", type; } } $1 == "@" { if (MCC) { if ($2 == "@1") { # Write the predicate function from the given parameters. # The format is: # @ @1 transform_ifii Make_3tree(OP_IASMII, ND_kid(t,1), ND_kid(t,2) print ""; print "/*ARGSUSED*/"; print "static void"; print $3 "(ND *func, ND *parent, ND *t, struct builtin *self)"; print "{"; printf " *t = *%s", $4; for (i = 5; i <= NF; i++) printf " %s", $i; print ","; if (split($3,jmp,"_") == 5 && jmp[2] == "j") printf "\t\t MK_I4CONST_ND((self->data << 5) + %d));\n", \ jmp[3]; else print "\t\t MK_I4CONST_ND(self->data));"; print " Is_True(self->data > 0, (\"No implementation for %s\", self->name));"; print "}"; } else if ($2 == "@2") { # Write the transform function from the given parameters. # The format is: # @ @2 2 is_int_func_int_int BETYPE_I4 BETYPE_I4 BETYPE_I4 # (int (*)(int, int)) print ""; print "/*ARGSUSED*/"; print "static BOOL"; print $4 "(ND *func, ND *parent, ND *t, struct builtin *self)"; print "{"; print " TCON tc;"; printf " if (ND_nkids(t) == %d", $3+1; write_test("ST_type(ND_dec(func))", $5, ""); for (i = 1; i <= $3; i++) { printf "\n && ND_name(ND_kid(t,%d)) == TO_VAL", i; write_test(sprintf("The_Tree_Type(ND_kid(t,%d))", i), $(i+5), i); } print ")"; print " return TRUE;"; print " Error_Prt_Line (ND_linenum(t), ec_builtin_function_type, self->name,"; i = $3+6; printf "\t\t \"%s", $i; while (++i <= NF) printf " %s", $i; print "\");"; print " return FALSE;"; print "}"; } else if ($2 == "@3") { if (once++ == 0) printf "\n#ifndef HAVE_ALTIVEC\n"; printf "#define %s -1\n", $3; } else { if (once && twice++ == 0) printf "#endif /* HAVE_ALTIVEC */\n\n"; printf "extern struct a_type *T_%s;\n", $2; } } next; } $1 == "%" { print $0; status = 1; exit; } { # Compute the signature of the generic function. signature=$1; for (i = 2; i <= NF-OPN; i++) { if ($i != "...") signature=(signature " " $i); } # Ensure that the signature is unique. if (signature_line[signature]) { print "Ambiguous signatures:"; print $0; print line[signature_line[signature]]; } signature_line[signature] = n_lines; # Require that overloaded functions have the same attributes: # number of arguments, when, configured, and addressible. if (same_arg_count[$1] && same_arg_count[$1] != NF) printf "%% number of arguments for %s varies: %d and %d\n", \ $1, NF-NARGS, same_arg_count[$1]-NARGS; same_arg_count[$1] = NF; if (same_when[$1] && same_when[$1] != $(NF-WHEN)) printf "%% when for %s varies: %s and %s\n", \ $1, $(NF-WHEN), same_when[$1]; same_when[$1] = $(NF-WHEN); if (same_configured[$1] && same_configured[$1] != $(NF-CONFIGURED)) printf "%% configured for %s varies: %s and %s\n", \ $1, $(NF-CONFIGURED), same_configured[$1]; same_configured[$1] = $(NF-CONFIGURED); if (same_addressible[$1] && same_addressible[$1] != $(NF-ADDRESSIBLE)) printf "%% addressible for %s varies: %s and %s\n", \ $1, $(NF-ADDRESSIBLE), same_addressible[$1]; else if (same_addressible[$1] && same_addressible[$1] != "FALSE") printf "%% Overloaded function %s is addressible\n", $1 same_addressible[$1] = $(NF-ADDRESSIBLE); # Record the line. line[n_lines++] = $0; } function push(fcn, n) { if (last) printf "};\n"; # Gcc3: declare as arrays of const pointers if (fcn) printf "static const struct builtin *const O_%s[%d] = {\n", fcn, n; last = fcn; } function mangle(name) { if (split(name, names, ":") == 1) return ("B_" names[1]); return ("B" names[2] "_" names[1]); } END { if (status) exit; # Gcc3: Mark file as Apple local printf "/* APPLE LOCAL file AltiVec */\n"; printf "/* This file is generated by ops-to-gp. Do not edit. */\n\n"; printf "/* To regenerate execute:\n"; printf " ops-to-gp -gcc vec.ops builtin.ops\n"; printf " with the current directory being gcc/config/rs6000. */\n\n"; # Output the description of each specific function. uid = 0; if (MCC) print ""; for (i = 0; i < n_lines; i++) { nf = split(line[i], part); fcn = part[nf-SPECIFIC]; if (!done[fcn]) { printf "static const struct builtin %s = {", mangle(fcn); if (GCC) printf " {"; ellipsis = 1; for (j = 2; j <= nf-OPN; j++) if (part[j] != "...") { printf " &T_%s,", part[j]; } else { ellipsis = -1; printf " NULL,"; } while (j++ <= MAXARGS+1) printf " NULL,"; instruction = part[nf-INSTRUCTION]; if (substr(instruction, 1, 4) == "MOP_") instruction = substr(instruction, 5); if (substr(instruction, length(instruction)) == "D") instruction = (substr(instruction, 1, length(instruction) - 1) "."); # Gcc3: Prefix each specific instruction with a "*" if (match (instruction, "^[a-zA-Z]") > 0) instruction = "*" instruction; if (GCC) printf " },"; if (GCC) printf " \"%s\",", substr(part[nf-CONSTRAINTS], 1, length(part[nf-CONSTRAINTS]) - 1); printf " &T_%s,", part[nf-RESULT]; if (MCC) printf " \"%s\",", part[nf-SPECIFIC]; printf " %d,", ellipsis * (nf - NARGS); if (MCC) { printf " %s,", part[nf-WHEN]; printf " %s,", part[nf-ADDRESSIBLE]; printf " %s,", part[nf-CONST_PTR_OK]; printf " %s,", part[nf-VOLATILE_PTR_OK]; printf " %s,", part[nf-CONFIGURED]; printf " %s,", part[nf-INSTRUCTION]; printf " %s,", part[nf-TRANSFORM]; printf " %s", part[nf-PREDICATE]; } else if (GCC) { printf " %s,", part[nf-CONST_PTR_OK]; printf " %s,", part[nf-VOLATILE_PTR_OK]; printf " %s,", part[nf-OPTIMIZE]; printf " \"%s\",", part[nf-SPECIFIC]; printf " \"%s\",", instruction; printf " %s,", part[nf-INSN_CODE]; printf " B_UID(%d)", uid++; } printf " };\n"; } done[fcn] = 1; } if (GCC) printf "#define LAST_B_UID B_UID(%d)\n", uid; if (GCC) { # Output the description of each specific function. print ""; uid = 0; for (i in done) done[i] = ""; print "const struct builtin * const Builtin[] = {" for (i = 0; i < n_lines; i++) { nf = split(line[i], part); fcn = part[nf-SPECIFIC]; if (!done[fcn]) { printf " &%s,\n", mangle(fcn); } done[fcn] = 1; } print "};" } # Output the overload tables for each generic function. print ""; for (i = 0; i < n_lines; i++) { nf = split(line[i], part); fcn = part[1]; if (last != fcn) push(fcn, part[nf]); printf " &%s,\n", mangle(part[nf-SPECIFIC]); } push("", 0); # Output the builtin function structure. print ""; if (MCC) { print "%}"; print "struct overloadx {"; print " char *name;"; print " int fcns;"; print " int args;"; print " struct builtin **functions;"; print "};"; print "%%"; } else if (GCC) { print "const struct overloadx Overload[] = {"; } # Output the builtin function list and data. uid = 0; for (i = 0; i < n_lines; i++) { nf = split(line[i], part); fcn = part[1]; args = nf - NARGS; if (part[nf-OPN] == "...") args = -args; if (last != fcn) { if (MCC) printf "%s, %d, %d, O_%s\n", fcn, part[nf], args, fcn; if (GCC) printf " { \"%s\", %d, %d, O_%s, O_UID(%d) },\n", \ fcn, part[nf], args, fcn, uid++; } last = fcn; } if (GCC) { print " { NULL, 0, 0, NULL, 0 }" print "};"; printf "#define LAST_O_UID O_UID(%d)\n", uid; } }' > $output.$suffixif [ "$MCC" = "1" ] ; then $gperf > $output.hfi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -