|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 using System.Collections.Generic; |
|
20 using System.Text; |
|
21 using SymbianUtils.Tracer; |
|
22 using SymbianStructuresLib.Arm; |
|
23 using SymbianStructuresLib.Arm.Instructions; |
|
24 using SymbianStackAlgorithmAccurate.CPU; |
|
25 using SymbianStackAlgorithmAccurate.Interfaces; |
|
26 using SymbianStackAlgorithmAccurate.Instructions.Types; |
|
27 |
|
28 namespace SymbianStackAlgorithmAccurate.Instructions |
|
29 { |
|
30 internal class AccInstructionList : IEnumerable<AccInstruction> |
|
31 { |
|
32 #region Constructors |
|
33 public AccInstructionList() |
|
34 { |
|
35 } |
|
36 #endregion |
|
37 |
|
38 #region API |
|
39 public void AddRange( IEnumerable<IArmInstruction> aInstructions ) |
|
40 { |
|
41 foreach ( IArmInstruction bi in aInstructions ) |
|
42 { |
|
43 AccInstruction instruction = null; |
|
44 // |
|
45 switch ( bi.AIGroup ) |
|
46 { |
|
47 case TArmInstructionGroup.EGroupBranch: |
|
48 instruction = new AccInstBranch( bi ); |
|
49 break; |
|
50 case TArmInstructionGroup.EGroupDataProcessing: |
|
51 instruction = new AccInstDataProcessing( bi ); |
|
52 break; |
|
53 case TArmInstructionGroup.EGroupDataTransfer: |
|
54 instruction = new AccInstDataTransfer( bi ); |
|
55 break; |
|
56 default: |
|
57 instruction = new AccInstUnknown( bi ); |
|
58 break; |
|
59 } |
|
60 // |
|
61 iInstructions.Add( instruction ); |
|
62 } |
|
63 } |
|
64 |
|
65 public AccInstruction Deque() |
|
66 { |
|
67 if ( Count == 0 ) |
|
68 { |
|
69 throw new InvalidOperationException( "No instructions to deque" ); |
|
70 } |
|
71 |
|
72 AccInstruction head = iInstructions[ 0 ]; |
|
73 iInstructions.RemoveAt( 0 ); |
|
74 return head; |
|
75 } |
|
76 |
|
77 internal void Prefilter( int aInstructionCountOffsetToPC ) |
|
78 { |
|
79 int count = this.Count; |
|
80 for ( int i = 0; i < count; i++ ) |
|
81 { |
|
82 AccInstruction instruction = iInstructions[ i ]; |
|
83 // |
|
84 if ( instruction.Ignored == false ) |
|
85 { |
|
86 instruction.Prefilter( this, i, aInstructionCountOffsetToPC ); |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 internal void DebugPrint( ITracer aTracer ) |
|
92 { |
|
93 if ( aTracer != null ) |
|
94 { |
|
95 uint address = iInstructions.Count > 0 ? iInstructions[ 0 ].Instruction.AIAddress : uint.MaxValue; |
|
96 // |
|
97 aTracer.Trace( "" ); |
|
98 aTracer.Trace( "INSTRUCTIONS @ 0x{0:x8}", address ); |
|
99 aTracer.Trace( "=========================" ); |
|
100 // |
|
101 foreach ( AccInstruction instruction in this ) |
|
102 { |
|
103 string line = instruction.ToString(); |
|
104 aTracer.Trace( line ); |
|
105 } |
|
106 // |
|
107 aTracer.Trace( "" ); |
|
108 } |
|
109 } |
|
110 #endregion |
|
111 |
|
112 #region Properties |
|
113 public int Count |
|
114 { |
|
115 get { return iInstructions.Count; } |
|
116 } |
|
117 |
|
118 public TArmInstructionSet InstructionSet |
|
119 { |
|
120 get |
|
121 { |
|
122 TArmInstructionSet ret = TArmInstructionSet.EARM; |
|
123 // |
|
124 if ( iInstructions.Count > 0 ) |
|
125 { |
|
126 ret = iInstructions[ 0 ].Instruction.AIType; |
|
127 } |
|
128 // |
|
129 return ret; |
|
130 } |
|
131 } |
|
132 |
|
133 public AccInstruction this[ int aIndex ] |
|
134 { |
|
135 get { return iInstructions[ aIndex ]; } |
|
136 } |
|
137 #endregion |
|
138 |
|
139 #region From IEnumerable<AccInstruction> |
|
140 public IEnumerator<AccInstruction> GetEnumerator() |
|
141 { |
|
142 foreach ( AccInstruction instruction in iInstructions ) |
|
143 { |
|
144 yield return instruction; |
|
145 } |
|
146 } |
|
147 |
|
148 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
149 { |
|
150 foreach ( AccInstruction instruction in iInstructions ) |
|
151 { |
|
152 yield return instruction; |
|
153 } |
|
154 } |
|
155 #endregion |
|
156 |
|
157 #region Data members |
|
158 private List<AccInstruction> iInstructions = new List<AccInstruction>(); |
|
159 #endregion |
|
160 } |
|
161 } |
|
162 |