Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2701_MemPRAlgorithm/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/CodeGenerator.cs @ 16752

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

#2526: Updated year of copyrights in license headers

File size: 1.8 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.Diagnostics.Contracts;
23
24namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
25  internal class CodeGenerator {
26
27    public const int MaxCodeLength = 10000;
28    public const int MaxConstants = 100;
29
30    private readonly byte[] codeArray = new byte[MaxCodeLength];
31    private int pc;
32    private int nParams;
33
34    public void Reset() {
35      pc = 0;
36      nParams = 0;
37    }
38
39    public void Emit1(OpCodes code) {
40      codeArray[pc++] = (byte)code;
41      if (code == OpCodes.LoadParamN) nParams++;
42    }
43
44    public void Emit2(OpCodes code, short arg) {
45      Contract.Assert(code == OpCodes.LoadVar); // only loadVar opcode has params
46      Emit1(code);
47      codeArray[pc++] = (byte)(arg >> 8);
48      codeArray[pc++] = (byte)(arg & 0xFF);
49    }
50
51    public void GetCode(out byte[] code, out int nParams) {
52      code = codeArray;
53      nParams = this.nParams;
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.