Skip to content

Commit

Permalink
Feat compiler option verboseScope (for debug)
Browse files Browse the repository at this point in the history
  • Loading branch information
deleterium committed Feb 17, 2024
1 parent 8f105c4 commit 156e0c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/codeGenerator/codeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function codeGenerator (Program: CONTRACT) {
},
startScope: function (scopeName: string) {
this.scopedRegisters.push(scopeName)
if (Program.Config.verboseAssembly) {
if (Program.Config.verboseScope) {
this.printFreeRegisters()
}
},
Expand All @@ -68,7 +68,7 @@ export default function codeGenerator (Program: CONTRACT) {
motherMemory.asmName = ''
}
} while (liberationNeeded !== scopeName)
if (Program.Config.verboseAssembly) {
if (Program.Config.verboseScope) {
this.printFreeRegisters()
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/shaper/shaper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export default function shaper (Program: CONTRACT, tokenAST: TOKEN[]): void {
case 'verboseAssembly':
Program.Config.verboseAssembly = bool
return true
case 'verboseScope':
Program.Config.verboseScope = bool
return true
default:
throw new Error(`At line: ${MacroToken.line}.` +
` Unknow macro property: '#${MacroToken.type} ${MacroToken.property}'.` +
Expand Down Expand Up @@ -531,6 +534,10 @@ export default function shaper (Program: CONTRACT, tokenAST: TOKEN[]): void {
default:
if (CurrMem.toBeRegister) {
// do not allocate variables modified as register
if (Program.Config.verboseAssembly) {
// It will be needed by Simulator
Program.Config.verboseScope = true
}
return
}
CurrMem.address = memoryAddress
Expand Down
3 changes: 2 additions & 1 deletion src/smartc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class SmartC {
PUserStackPages: 0,
PCodeStackPages: 0,
PCodeHashId: '',
verboseAssembly: false
verboseAssembly: false,
verboseScope: false
},
warnings: []
}
Expand Down
2 changes: 2 additions & 0 deletions src/typings/contractTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type SC_CONFIG = {
PCodeHashId: string,
/** Adds a comment in generated assembly code with source code line number and content */
verboseAssembly: boolean,
/** Adds a comment when new scope start/ends with the free registers, and warns when one register is locked */
verboseScope: boolean,
}

export type SC_MACRO = {
Expand Down

0 comments on commit 156e0c1

Please sign in to comment.