From 5d55c8c863ea9909064ee847f25163bf02e5e8f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Fri, 12 May 2017 13:22:50 +0300 Subject: [PATCH] (refs #7218) Sort labels by integer values when generating switch Change-Id: Ic6acb6241151f3d178e4c5bdf9c4fac5424b6100 --- .../internal/codegen/ssa/exits/Switch.java | 14 +++++++++++--- .../scl/compiler/tests/ModuleRegressionTests.java | 1 + .../simantics/scl/compiler/tests/scl/Matching6.scl | 9 +++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Matching6.scl diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java index 27f853e02..386199d83 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Switch.java @@ -1,6 +1,7 @@ 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; @@ -26,6 +27,8 @@ import org.simantics.scl.compiler.types.TVar; 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; @@ -60,14 +63,19 @@ public class Switch extends SSAExit implements ValRefBinder { int defaultId; for(defaultId=0;defaultId labelMap = new TIntObjectHashMap