misc: add more support for different inspect method scenarios (#169)

This commit is contained in:
Tyler Wilding 2022-12-10 23:06:42 -05:00 committed by GitHub
parent fc53651d1f
commit fd92ea84d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -229,9 +229,17 @@ async function genTypeFields() {
let line = lines[i]; let line = lines[i];
// Loop until we find a line with the a field name: // Loop until we find a line with the a field name:
// - `..."~2Tlos:...` // - `..."~2Tlos:...`
if (line.includes('"~2T')) { if (line.includes('"~2T') || line.includes('"~1T')) {
// Get the field name // Get the field name
const fieldName = line.split('"~2T')[1].split(":")[0]; let fieldName = "";
let arraySize = 0;
const fieldString = line.split(/"~\dT/g)[1];
if (fieldString.includes("[")) {
fieldName = fieldString.split("[")[0];
arraySize = parseInt(fieldString.split("[")[1].split("]")[0]);
} else {
fieldName = fieldString.split(":")[0];
}
let skipLine = false; let skipLine = false;
for (const field of fields) { for (const field of fields) {
if (field.name === fieldName) { if (field.name === fieldName) {
@ -250,12 +258,8 @@ async function genTypeFields() {
if (line.includes(": #<")) { if (line.includes(": #<")) {
typeName = line.split(": #<")[1].split(" @")[0]; typeName = line.split(": #<")[1].split(" @")[0];
isStructure = true; isStructure = true;
} else { } else if (arraySize === 0) {
formatString = line formatString = fieldString.split(": ")[1].split("~%")[0].trim();
.split('"~2T')[1]
.split(": ")[1]
.split("~%")[0]
.trim();
} }
// Iterate until we find the offset, a bit fragile but look for the // Iterate until we find the offset, a bit fragile but look for the
// next line with `gp` in it // next line with `gp` in it
@ -285,7 +289,7 @@ async function genTypeFields() {
} }
i++; i++;
} }
// TODO - doesn't support arrays/inline-arrays/pointers yet // TODO - doesn't support inline-arrays/pointers yet
// Figure out the type name if we havn't already from the little information we have // Figure out the type name if we havn't already from the little information we have
if (typeName === "UNKNOWN") { if (typeName === "UNKNOWN") {
if (fieldName.includes("time") && loadInstr === "ld") { if (fieldName.includes("time") && loadInstr === "ld") {
@ -305,6 +309,14 @@ async function genTypeFields() {
typeName = "uint32"; typeName = "uint32";
} else if (loadInstr === "ld") { } else if (loadInstr === "ld") {
typeName = "int64"; typeName = "int64";
} else if (loadInstr === "lbu") {
typeName = "uint8";
} else if (loadInstr === "lb") {
typeName = "int8";
} else if (loadInstr === "lh") {
typeName = "int16";
} else if (loadInstr === "lhu") {
typeName = "uint16";
} }
} }
} }
@ -314,6 +326,8 @@ async function genTypeFields() {
type: typeName, type: typeName,
offset: offset, offset: offset,
isStructure: isStructure, isStructure: isStructure,
arraySize: arraySize,
annotation: "",
}); });
} }
@ -327,11 +341,21 @@ async function genTypeFields() {
const field = fields[f]; const field = fields[f];
// Check if the field should be inlined // Check if the field should be inlined
// TODO - edge-case for the last field (don't know the full size here) // TODO - edge-case for the last field (don't know the full size here)
if (field.isStructure && f + 1 < fields.length) { if (field.arraySize === 0 && field.isStructure && f + 1 < fields.length) {
if (field.offset + 4 !== fields[f + 1].offset) { if (field.offset + 4 !== fields[f + 1].offset) {
// NOTE - this can have false positives without knowing the true size of the struct
field.type += " :inline"; field.type += " :inline";
} }
} }
if (field.arraySize !== 0) {
field.type += ` ${field.arraySize}`;
if (field.offset + 4 !== fields[f + 1].offset) {
field.annotation = ` ;; elt size: ${
(fields[f + 1].offset - field.offset) / field.arraySize
}`;
}
}
if (field.name.length > largestName) { if (field.name.length > largestName) {
largestName = field.name.length; largestName = field.name.length;
} }
@ -345,7 +369,9 @@ async function genTypeFields() {
for (const field of fields) { for (const field of fields) {
let fieldString = ` (${field.name.padEnd(largestName, " ")} `; let fieldString = ` (${field.name.padEnd(largestName, " ")} `;
fieldString += `${field.type.padEnd(largestTypeNameSection, " ")} `; fieldString += `${field.type.padEnd(largestTypeNameSection, " ")} `;
fieldString += `:offset-assert ${field.offset.toString()})`; fieldString += `:offset-assert ${field.offset.toString()})${
field.annotation
}`;
clipboardVal += `${fieldString}\n`; clipboardVal += `${fieldString}\n`;
} }
@ -383,7 +409,7 @@ async function genMethodStubs() {
let foundType = false; let foundType = false;
let parentTypeMethodCount = 0; let parentTypeMethodCount = 0;
for (const line of fileContentsLines) { for (const line of fileContentsLines) {
if (line.includes(`(deftype ${parentType}`)) { if (line.includes(`(deftype ${parentType} `)) {
foundType = true; foundType = true;
} }
if (foundType && line.includes("method-count-assert")) { if (foundType && line.includes("method-count-assert")) {