/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Imm, IRNode, IRNodeKind, Label, OperandKind, VReg } from "./irnodes"; import { generateCatchTables } from "./statement/tryStatement"; import { PandaGen } from "./pandagen"; import { isRangeInst, getRangeExplicitVregNums, } from "./base/util"; export class IntrinsicInfo { readonly intrinsicName: string; readonly argsNum: number; readonly returnType: string; constructor(intrinsicName: string, argsNum: number, returnType: string) { this.intrinsicName = intrinsicName; this.argsNum = argsNum; this.returnType = returnType; } } export class AssemblyDumper { private labels: Map // Label.id : Label string name private labelId: number; private pg: PandaGen; readonly labelPrefix = "LABEL_"; static intrinsicRec: Map = new Map(); private output: string; constructor(pg: PandaGen) { this.pg = pg; this.labels = new Map(); this.labelId = 0; this.output = ""; } static writeLanguageTag(out: any): void { out.str += ".language ECMAScript\n"; out.str += "\n"; } writeFunctionHeader(): void { let parametersCount = this.pg.getParametersCount(); this.output += ".function any " + this.pg.internalName + "(" for (let i = 0; i < parametersCount; ++i) { this.output += "any a" + i.toString(); if (i !== parametersCount - 1) { this.output += ", "; } } this.output += ") {\n"; } writeFunctionBody(): void { let irNodes: IRNode[] = this.pg.getInsns(); let parametersCount = this.pg.getParametersCount(); /* the first parametersCount insns are move insn for argument initialization, we can directly dump them into text */ for (let i = 0; i < parametersCount; ++i) { let node = irNodes[i]; this.output += "\t"; this.output += node.getMnemonic() + " v" + (node.operands[0]).num + ", a" + ((node.operands[0]).num) + "\n"; } for (let i = parametersCount; i < irNodes.length; ++i) { let node = irNodes[i]; if (node.kind === IRNodeKind.VREG || node.kind === IRNodeKind.IMM) { continue; } if (node.kind === IRNodeKind.LABEL) { this.writeLabel(