Skip to content

Commit

Permalink
Convert asm-raw to typescript (#4647)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt committed Jan 27, 2023
1 parent 4ca9420 commit 784393b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/parsers/asm-raw.js → lib/parsers/asm-raw.ts
Expand Up @@ -22,11 +22,14 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

import {AsmResultLink, ParsedAsmResult, ParsedAsmResultLine} from '../../types/asmresult/asmresult.interfaces';
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';

import {AsmRegex} from './asmregex';

export class AsmRaw extends AsmRegex {
processBinaryAsm(asm, filters) {
const result = [];
processBinaryAsm(asm: string, filters: ParseFiltersAndOutputOptions): ParsedAsmResult {
const result: ParsedAsmResultLine[] = [];
const asmLines = asm.split('\n');
const asmOpcodeRe = /^\s*([\da-f]+):\s*(([\da-f]{2} ?)+)\s*(.*)/;
const labelRe = /^([\da-f]+)\s+<([^>]+)>:$/;
Expand Down Expand Up @@ -55,7 +58,7 @@ export class AsmRaw extends AsmRegex {
const address = parseInt(match[1], 16);
const opcodes = match[2].split(' ').filter(Boolean);
const disassembly = ' ' + AsmRegex.filterAsmLine(match[4], filters);
let links = null;
let links: AsmResultLink[] | undefined;
const destMatch = line.match(destRe);
if (destMatch) {
links = [
Expand Down
5 changes: 3 additions & 2 deletions lib/parsers/asmregex.ts
Expand Up @@ -22,6 +22,7 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import * as utils from '../utils';

const findQuotes = /(.*?)("(?:[^"\\]|\\.)*")(.*)/;
Expand All @@ -33,7 +34,7 @@ export class AsmRegex {
this.labelDef = /^(?:.proc\s+)?([\w$.@]+):/i;
}

static squashHorizontalWhitespace(line, atStart) {
static squashHorizontalWhitespace(line: string, atStart: boolean): string {
const quotes = line.match(findQuotes);
if (quotes) {
return (
Expand All @@ -45,7 +46,7 @@ export class AsmRegex {
return utils.squashHorizontalWhitespace(line, atStart);
}

static filterAsmLine(line, filters) {
static filterAsmLine(line: string, filters: ParseFiltersAndOutputOptions): string {
if (!filters.trim) return line;
return this.squashHorizontalWhitespace(line, true);
}
Expand Down

0 comments on commit 784393b

Please sign in to comment.