package org.simantics.scl.compiler.internal.codegen.ssa.exits;
import java.util.ArrayList;
+import java.util.Arrays;
import org.objectweb.asm.Label;
import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
+import gnu.trove.map.hash.TIntObjectHashMap;
+
public class Switch extends SSAExit implements ValRefBinder {
ValRef scrutinee;
int defaultId;
for(defaultId=0;defaultId<branches.length-1&&branches[defaultId].constructor!=null;++defaultId);
int[] values = new int[defaultId];
- Label[] labels = new Label[defaultId];
Cont[] continuations = new Cont[defaultId+1];
+ TIntObjectHashMap<Label> labelMap = new TIntObjectHashMap<Label>(defaultId);
for(int i=0;i<defaultId;++i) {
- values[i] = ((IntegerConstant)branches[i].constructor).getValue();
+ int value = ((IntegerConstant)branches[i].constructor).getValue();
+ values[i] = value;
Cont cont = branches[i].cont.getBinding();
- labels[i] = mb.getLabel(cont);
+ labelMap.put(value, mb.getLabel(cont));
continuations[i] = cont;
}
+ Arrays.sort(values);
+ Label[] labels = new Label[defaultId];
+ for(int i=0;i<defaultId;++i)
+ labels[i] = labelMap.get(values[i]);
Label defaultLabel;
{
Cont cont = branches[defaultId].cont.getBinding();
@Test public void Matching2() { test(); }
@Test public void Matching4() { test(); }
@Test public void Matching5() { test(); }
+ @Test public void Matching6() { test(); }
@Test public void MatchingWithMissingParameter() { test(); }
@Test public void MatchingWithoutTypeAnnotations() { test(); }
@Test public void MaximumBy() { test(); }