Skip to content

Commit 3d2ee13

Browse files
committed
Expanding statistics
1 parent f896a7d commit 3d2ee13

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

src/app/bytecode-reader/bytecode-reader.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ import { faFolderOpen } from '@fortawesome/free-solid-svg-icons';
2828
})
2929
export class BytecodeReaderComponent implements OnInit {
3030

31-
file: any;
32-
@Output("bytecode") bytecodeEmitter: EventEmitter<ArrayBuffer> = new EventEmitter();
33-
uploadedFileName: string = "simple_calculator.obj";
34-
folderOpenIcon: IconDefinition = faFolderOpen;
31+
private file: any;
32+
@Output("bytecode") public bytecodeEmitter: EventEmitter<ArrayBuffer> = new EventEmitter();
33+
public uploadedFileName: string = "simple_calculator.obj";
34+
public folderOpenIcon: IconDefinition = faFolderOpen;
3535

3636
constructor() { }
3737

3838
ngOnInit() {
3939
}
4040

4141
fileChanged(event: Event) {
42-
if ((event.target as HTMLInputElement).files.length > 0) {
43-
this.file = (event.target as HTMLInputElement).files[0];
42+
let eventTarget = event.target as HTMLInputElement;
43+
if (eventTarget.files.length > 0) {
44+
this.file = eventTarget.files[0];
4445
this.emitBytes();
4546
} else {
4647
this.bytecodeEmitter.emit(null);

src/app/shared/disassembler.shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ export class Disassembler {
121121
public static readonly ARRAYLENGTH: Instruction = {mnemonic: "arraylength", opcode: 38};
122122

123123
public static readonly POP: Instruction = {mnemonic: "pop", opcode: 39};
124-
public static readonly DUP: Instruction = {mnemonic: "dup_x1", opcode: 40};
125-
public static readonly DUP2: Instruction = {mnemonic: "dup_x2", opcode: 41};
124+
public static readonly DUP: Instruction = {mnemonic: "dup", opcode: 40};
125+
public static readonly DUP2: Instruction = {mnemonic: "dup2", opcode: 41};
126126

127127
public static readonly JMP: Instruction = {mnemonic: "jmp", opcode: 42};
128128
public static readonly JEQ: Instruction = {mnemonic: "jeq", opcode: 43};

src/app/stats/stats.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ <h3>General</h3>
6969
</table>
7070
<h3>Instructions</h3>
7171
<hr />
72+
<p>
73+
This object file contains {{this.instructionCountArray.length}} out of {{this.totalNumInstructions}} available instructions, which is {{((this.instructionCountArray.length / this.totalNumInstructions) * 100).toFixed(2)}}% of the instruction set.
74+
<span *ngIf="this.leftOutInstructions.length">Instructions that do not appear in this object file are:</span>
75+
</p>
76+
<ol *ngIf="this.leftOutInstructions.length">
77+
<li *ngFor="let leftOutInstruction of this.leftOutInstructions">
78+
<code>{{leftOutInstruction.mnemonic}}</code>
79+
</li>
80+
</ol>
81+
<p>Instructions that do appear in this object file are:</p>
7282
<div class="table-responsive">
7383
<table class="table table-bordered table-hover">
7484
<thead>

src/app/stats/stats.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export class StatsComponent implements OnInit {
3737
private instructionCount = {};
3838
public instructionCountArray = [];
3939

40+
public totalNumInstructions = Disassembler.INSTRUCTIONS.length;
41+
public leftOutInstructions = Object.assign([], Disassembler.INSTRUCTIONS);
42+
4043
constructor() { }
4144

4245
ngOnInit() {
@@ -77,6 +80,9 @@ export class StatsComponent implements OnInit {
7780
mnemonic: key,
7881
count: this.instructionCount[key]
7982
});
83+
this.leftOutInstructions.splice(this.leftOutInstructions.findIndex((instruction) => {
84+
return instruction.mnemonic === key;
85+
}), 1);
8086
}
8187
this.instructionCountArray.sort((ic1, ic2) => {
8288
return ic2.count - ic1.count;

0 commit comments

Comments
 (0)