From c911cc365fd5a52f845777c09533118a975bb0e3 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sun, 5 Nov 2023 13:28:04 +0100 Subject: [PATCH 1/3] Multiplier: use enhanced switch --- java/se/sics/mspsim/core/Multiplier.java | 45 ++++++++++++------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/java/se/sics/mspsim/core/Multiplier.java b/java/se/sics/mspsim/core/Multiplier.java index 40128933e..120769846 100644 --- a/java/se/sics/mspsim/core/Multiplier.java +++ b/java/se/sics/mspsim/core/Multiplier.java @@ -78,30 +78,29 @@ public Multiplier(MSP430Core cpu, int[] memory, int offset) { @Override public int read(int address, boolean word, long cycles) { - switch (address) { - case MPY: - return mpy; - case MPYS: - return mpys; - case MAC: - return mac; - case MACS: - return macs; - case OP2: - return op2; - case RESHI: - if (DEBUG) log("read res hi: " + resHi ); - return resHi; - case RESLO: - if (DEBUG) log("read res lo: " + resLo ); - return resLo; - case SUMEXT: - if (DEBUG) log("read sumext: " + sumext); - return sumext; - default: + return switch (address) { + case MPY -> mpy; + case MPYS -> mpys; + case MAC -> mac; + case MACS -> macs; + case OP2 -> op2; + case RESHI -> { + if (DEBUG) log("read res hi: " + resHi); + yield resHi; + } + case RESLO -> { + if (DEBUG) log("read res lo: " + resLo); + yield resLo; + } + case SUMEXT -> { + if (DEBUG) log("read sumext: " + sumext); + yield sumext; + } + default -> { logw(WarningType.EMULATION_ERROR, "read unhandled address: 0x" + Utils.hex(address, 4)); - return 0; - } + yield 0; + } + }; } @Override From af6eed82ea0faeb7d6d46e936b6e3dd1db442dec Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sun, 5 Nov 2023 13:29:54 +0100 Subject: [PATCH 2/3] Multiplier32: use enhanced switch --- java/se/sics/mspsim/core/Multiplier32.java | 90 +++++++++------------- 1 file changed, 37 insertions(+), 53 deletions(-) diff --git a/java/se/sics/mspsim/core/Multiplier32.java b/java/se/sics/mspsim/core/Multiplier32.java index 1ea767761..0a7447b0c 100644 --- a/java/se/sics/mspsim/core/Multiplier32.java +++ b/java/se/sics/mspsim/core/Multiplier32.java @@ -109,60 +109,44 @@ public Multiplier32(MSP430Core cpu, int[] memory, int offset) { @Override public int read(int address, boolean word, long cycles) { address = address - offset; - switch (address) { - case MPY: - return mpy; - case MPYS: - return mpys; - case MAC: - return mac; - case MACS: - return macs; - case OP2: - return op2; - case RESHI: - if (DEBUG) log("read res hi: " + resHi ); - return resHi; - case RESLO: - if (DEBUG) log("read res lo: " + resLo ); - return resLo; - case SUMEXT: - if (DEBUG) log("read sumext: " + sumext); - return sumext; - case MPY32L: - return mpy32L; - case MPY32H: - return mpy32H; - case MPYS32L: - return mpys32L; - case MPYS32H: - return mpys32H; - case MAC32L: - return mac32L; - case MAC32H: - return mac32H; - case MACS32L: - return macs32L; - case MACS32H: - return macs32H; - case OP2L: - return op2L; - case OP2H: - return op2H; - case RES0: - return res0; - case RES1: - return res1; - case RES2: - return res2; - case RES3: - return res3; - case MPY32CTL0: - return mpy32ctl0; - default: - logw(WarningType.EMULATION_ERROR, "read unhandled address: 0x" + Utils.hex(address, 4)); - return 0; + return switch (address) { + case MPY -> mpy; + case MPYS -> mpys; + case MAC -> mac; + case MACS -> macs; + case OP2 -> op2; + case RESHI -> { + if (DEBUG) log("read res hi: " + resHi); + yield resHi; + } + case RESLO -> { + if (DEBUG) log("read res lo: " + resLo); + yield resLo; + } + case SUMEXT -> { + if (DEBUG) log("read sumext: " + sumext); + yield sumext; + } + case MPY32L -> mpy32L; + case MPY32H -> mpy32H; + case MPYS32L -> mpys32L; + case MPYS32H -> mpys32H; + case MAC32L -> mac32L; + case MAC32H -> mac32H; + case MACS32L -> macs32L; + case MACS32H -> macs32H; + case OP2L -> op2L; + case OP2H -> op2H; + case RES0 -> res0; + case RES1 -> res1; + case RES2 -> res2; + case RES3 -> res3; + case MPY32CTL0 -> mpy32ctl0; + default -> { + logw(WarningType.EMULATION_ERROR, "read unhandled address: 0x" + Utils.hex(address, 4)); + yield 0; } + }; } @Override From 4fcea0df4bb41f40be318f41861700cecfa682da Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Sun, 5 Nov 2023 13:31:10 +0100 Subject: [PATCH 3/3] IPHCPacketAnalyzer: use enhanced switch --- .../cooja/plugins/analyzers/IPHCPacketAnalyzer.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java index 437e41d1c..b9536a3b5 100644 --- a/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java +++ b/java/org/contikios/cooja/plugins/analyzers/IPHCPacketAnalyzer.java @@ -82,14 +82,11 @@ public int analyzePacket(Packet packet, StringBuilder brief, int tf = (packet.get(0) >> 3) & 0x03; boolean nhc = (packet.get(0) & SICSLOWPAN_IPHC_NH_C) > 0; int hlim = (packet.get(0) & 0x03); - switch (hlim) { - case 0x02: - hlim = 64; - break; - case 0x03: - hlim = 255; - break; - } + hlim = switch (hlim) { + case 0x02 -> 64; + case 0x03 -> 255; + default -> hlim; + }; int cid = (packet.get(1) >> 7) & 0x01; int sac = (packet.get(1) >> 6) & 0x01; int sam = (packet.get(1) >> 4) & 0x03;