Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
scout119 committed Apr 15, 2018
1 parent fa0a12d commit 33dd011
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 177 deletions.
18 changes: 1 addition & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "BEAMdasm",
"description": "BEAM file disassembler",
"license": "SEE LICENSE IN LICENSE.md",
"version": "0.0.2",
"version": "1.0.0",
"publisher": "Valentin",
"engines": {
"vscode": "^1.21.0"
Expand All @@ -26,7 +26,6 @@
"color": "#1E1E1E",
"theme": "dark"
},
"preview": true,
"activationEvents": [
"onView:beamdasm.beamFilesTree",
"onCommand:beamdasm.disassemble"
Expand Down Expand Up @@ -86,21 +85,6 @@
"group": "navigation"
}
]
},
"configuration": {
"type": "object",
"title": "BEAMDasm extension configuration",
"properties": {
"beamdasm.formatter" : {
"type": "string",
"default": "beamdasm",
"description": "Bytecode formatter to use",
"enum": [
"beamdasm",
"erlang"
]
}
}
}
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions resources/dark/attr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 1 addition & 29 deletions resources/dark/code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/dark/litt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/dark/strt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/light/attr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 1 addition & 29 deletions resources/light/code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/light/litt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/light/strt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions src/beam/beamFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import * as fs from 'fs';
import * as zlib from 'zlib';
import List from './terms/list';
import Tuple from './terms/tuple';
import Map from './terms/map';

import { opcodes } from './opcodes';

import * as Tags from './tags';
/// <reference path="interface.ts"/>

export default class BeamFile implements beamdasm.IBeamFile {
export default class BeamFile implements beamdasm.Beam {

readonly code: any[] = [];
_codeNumberOfFunctions: number = 0;
Expand Down Expand Up @@ -550,23 +551,23 @@ export default class BeamFile implements beamdasm.IBeamFile {

readMap(buffer: Buffer, offset: number): any {
let arity = buffer.readUInt32BE(offset); offset += 4;

let map = new Map();

while (arity-- > 0) {
let keyTag = buffer.readUInt8(offset++);
let keyObj = this.readObject(keyTag, buffer, offset);
offset = keyObj.offset;

//console.log(`${keyObj.data}`);

let valTag = buffer.readUInt8(offset++);
let valObj = this.readObject(valTag, buffer, offset);
offset = valObj.offset;

//console.log(`${valObj.data}`);

//Add object to the map
map.add(keyObj.data, valObj.data);
}

return { data: "Map", offset: offset };
return { data: map, offset: offset };
}

readAtom(buffer: Buffer, offset: number): any {
Expand Down
6 changes: 3 additions & 3 deletions src/beam/beamFileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class BeamCacheSingleton
}

beamFilePath: string = '';
beamFile: beamdasm.IBeamFile | undefined = undefined;
beamFile: beamdasm.Beam | undefined = undefined;

public getBeamFile(path: string): beamdasm.IBeamFile {
public getBeamFile(path: string): beamdasm.Beam {
if( this.beamFilePath === path ){
return this.beamFile as beamdasm.IBeamFile;
return this.beamFile as beamdasm.Beam;
}

this.beamFilePath = path;
Expand Down
89 changes: 31 additions & 58 deletions src/beam/beamdasmFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as Tags from './tags';

let lbl: (val: number) => string;

function instructionToString(beamFile: beamdasm.IBeamFile, obj: any, func: number): string {
function instructionToString(beamFile: beamdasm.Beam, obj: any, func: number): string {
let name = opcodes[obj.op].nm;
let str = ` ${name}` + ' '.repeat(20 - name.length);

Expand All @@ -37,7 +37,7 @@ function instructionToString(beamFile: beamdasm.IBeamFile, obj: any, func: numbe
return str;
}

function termToString(beamFile: beamdasm.IBeamFile, obj: any): string {
function termToString(beamFile: beamdasm.Beam, obj: any): string {
if (obj.tag === Tags.TAG_LABEL) {
return lbl(obj.data);
}
Expand Down Expand Up @@ -75,9 +75,9 @@ function termToString(beamFile: beamdasm.IBeamFile, obj: any): string {
return `.`;
}

export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
export class BeamdasmFormatter implements beamdasm.BeamFormatter {

formatModuleInfo(beamFile: beamdasm.IBeamFile): string {
formatModuleInfo(beamFile: beamdasm.Beam): string {
let str = `Module: ${beamFile.atoms[1]}\n`;
str += '\n';
str += `Attributes: ${beamFile.attributes}\n`;
Expand All @@ -87,7 +87,7 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatcode(beamFile: beamdasm.IBeamFile): string {
formatcode(beamFile: beamdasm.Beam): string {

let str = '';

Expand Down Expand Up @@ -142,65 +142,31 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatlitt(beamFile: beamdasm.IBeamFile): string {
let str = 'Literals: ';
str += `${beamFile.literals}\n`;
formatlitt(beamFile: beamdasm.Beam): string {
let str = 'Literals: \n';

for( let i = 0; i < beamFile.literals.length; i++ ){
str += `\t${beamFile.literals[i]}\n`;
}

str += '\n';
return str;
}

// formatatu8(beamFile: beamdasm.IBeamFile): string {
// let str = 'Atoms: ';
// let offset = str.length;

// for (let i = 0; i < beamFile.atoms.length; i++) {
// str += (i !== 0) ? ' '.repeat(offset) : '';
// str += `${i}\t${beamFile.atoms[i]}\n`;
// }
// str += '\n';

// return str;
// }

formatatu8(beamFile: beamdasm.IBeamFile):string {
let str = `
<head>
<style>
table, td, th {
border: 1px solid white;
}
table {
margin-left: auto;
margin-right: auto;
border-collapse: collapse;
width: 50%;
}
th {
height: 50px;
}
td {
text-align: center;
}
</style>
</head>
<table style="margin-left:auto;margin-right:auto;width=50%">
<tr><th>Index</th><th>Atom</th></tr>
${this.insertAtoms(beamFile)}
</table>`;

return str;
}
formatatu8(beamFile: beamdasm.Beam): string {
let str = 'Atoms: ';
let offset = str.length;

insertAtoms(beamFile: beamdasm.IBeamFile):string {
let str = '';
for(let i = 0; i< beamFile.atoms.length; i++){
str+=`<tr><td>${i}</td><td>${beamFile.atoms[i]}</td></tr>`;
for (let i = 0; i < beamFile.atoms.length; i++) {
str += (i !== 0) ? ' '.repeat(offset) : '';
str += `${i}\t${beamFile.atoms[i]}\n`;
}
str += '\n';

return str;
}

formatimpt(beamFile: beamdasm.IBeamFile): string {
formatimpt(beamFile: beamdasm.Beam): string {
let str = 'Imports: ';
let offset = str.length;

Expand All @@ -215,7 +181,7 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatexpt(beamFile: beamdasm.IBeamFile): string {
formatexpt(beamFile: beamdasm.Beam): string {

if (!lbl) {
let lblLength = beamFile.codeNumberOfLabels.toString().length;
Expand All @@ -235,7 +201,7 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatloct(beamFile: beamdasm.IBeamFile): string {
formatloct(beamFile: beamdasm.Beam): string {

if (!lbl) {
let lblLength = beamFile.codeNumberOfLabels.toString().length;
Expand All @@ -256,7 +222,7 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

formatstrt(beamFile: beamdasm.IBeamFile): string {
formatstrt(beamFile: beamdasm.Beam): string {
let str = 'Strings: ';

str += `\"${beamFile.StrT}\"\n`;
Expand All @@ -265,5 +231,12 @@ export class BeamdasmFormatter implements beamdasm.BeamBytecodeFormatter {
return str;
}

[func: string]: (beamFile: beamdasm.IBeamFile) => string;
formatattr(beamFile: beamdasm.Beam): string {
let str = 'Attributes:\n';

str += `${beamFile.attributes}`;
return str;
}

[func: string]: (beamFile: beamdasm.Beam) => string;
}
Loading

0 comments on commit 33dd011

Please sign in to comment.