Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RBFRegression/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/Disassembler.cs @ 14589

Last change on this file since 14589 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 2.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Text;
23
24namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
25  internal class Disassembler {
26    public static string CodeToString(byte[] code, double[] consts) {
27      var sb = new StringBuilder();
28      int pc = 0;
29      int nextParamIdx = -1;
30      while (code[pc] != (byte)OpCodes.Exit) {
31        var op = code[pc++];
32        switch (op) {
33          case (byte)OpCodes.Add: sb.Append(" + "); break;
34          case (byte)OpCodes.Mul: sb.Append(" * "); break;
35          case (byte)OpCodes.LoadConst1: sb.Append(" 1 "); break;
36          case (byte)OpCodes.LoadConst0: sb.Append(" 0 "); break;
37          case (byte)OpCodes.LoadParamN: sb.AppendFormat(" {0:N3} ", consts[++nextParamIdx]); break;
38          case (byte)OpCodes.LoadVar:
39          {
40              short arg = (short)((code[pc] << 8) | code[pc + 1]);
41              pc += 2;
42            sb.AppendFormat(" var{0} ", arg); break;
43          }
44          case (byte)OpCodes.Exp: sb.Append(" exp "); break;
45          case (byte)OpCodes.Log: sb.Append(" log "); break;
46          case (byte)OpCodes.Inv: sb.Append(" inv "); break;         
47        }
48      }
49      return sb.ToString();
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.