/** * Write the Java code required for error checking and calling the emit method represented by a * singleton EmitterSet. A singleton EmiiterSet will typically be the result of a series of * splits of bigger sets, where the splits represent emitted queries of operand types and sizes. * (See emitSet) However, there may be cases when some operand has only one possible options, so * the splitting will not have generated any tests for it. In this case, we will emit assertions * that guarantee the operand is of the expected type. Note that the answers to queries * alrrready performed by splitting are known to be fine, so no additional error checking is * needed for cases they cover. * * @see #emitSet * @param opcode the IA32 opcode to generate * @param testsPerformed the set of queries already performed by splitting. * @param level level of indentation for prett printing */ private void emitSingleton(String opcode, boolean[][] testsPerformed, int level) { EmitterDescriptor ed = (EmitterDescriptor) emitters.iterator().next(); ArgumentType[] args = ed.getArgs(); int count = ed.getCount(); for (int i = 0; i < count; i++) if (!testsPerformed[i][args[i].ordinal()]) emitVerify(i, args[i], level); ArgumentType size = ed.getSize(); if (size != null) { boolean needed = true; for (int i = 0; i < count; i++) if (testsPerformed[i][size.ordinal()]) needed = false; if (needed) emitVerify(0, size, level); if (size == ArgumentType.Byte) for (int i = 0; i < count; i++) if (args[i] == ArgumentType.GPRegister) if (currentOpcode.indexOf("MOVZX") == -1 && currentOpcode.indexOf("MOVSX") == -1) { emitTab(level); emit("if (VM.VerifyAssertions) opt_assert("); emitArgs(i, ArgumentType.GPRegister); emit(".isValidAs8bitRegister());\n"); } } emitEmitCall(opcode, args, count, level, ed.getSize()); }
/** * This method uses a SplitRecord as the criertion to partition the given EmitterSet into two * subsets. * * @param split the plit record dicatating how to split */ private EmitterSet[] makeSplit(SplitRecord split) { int arg = split.argument; ArgumentType test = split.test; EmitterSet yes = new EmitterSet(); EmitterSet no = new EmitterSet(); Iterator<EmitterDescriptor> i = emitters.iterator(); while (i.hasNext()) { EmitterDescriptor ed = (EmitterDescriptor) i.next(); if (ed.argMatchesEncoding(arg, test)) { yes.add(ed); } else { no.add(ed); } } return new EmitterSet[] {yes, no}; }