@jhlagado/azm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +649 -0
- package/README.md +142 -0
- package/dist/src/analysis.d.ts +11 -0
- package/dist/src/analysis.js +41 -0
- package/dist/src/api-compile.d.ts +8 -0
- package/dist/src/api-compile.js +3 -0
- package/dist/src/api-tooling.d.ts +25 -0
- package/dist/src/api-tooling.js +21 -0
- package/dist/src/cli.d.ts +30 -0
- package/dist/src/cli.js +523 -0
- package/dist/src/compile.d.ts +10 -0
- package/dist/src/compile.js +175 -0
- package/dist/src/compileShared.d.ts +3 -0
- package/dist/src/compileShared.js +7 -0
- package/dist/src/diagnosticTypes.d.ts +77 -0
- package/dist/src/diagnosticTypes.js +53 -0
- package/dist/src/formats/index.d.ts +7 -0
- package/dist/src/formats/index.js +17 -0
- package/dist/src/formats/range.d.ts +17 -0
- package/dist/src/formats/range.js +45 -0
- package/dist/src/formats/types.d.ts +208 -0
- package/dist/src/formats/types.js +1 -0
- package/dist/src/formats/writeAsm80.d.ts +6 -0
- package/dist/src/formats/writeAsm80.js +86 -0
- package/dist/src/formats/writeBin.d.ts +7 -0
- package/dist/src/formats/writeBin.js +23 -0
- package/dist/src/formats/writeD8m.d.ts +9 -0
- package/dist/src/formats/writeD8m.js +239 -0
- package/dist/src/formats/writeHex.d.ts +9 -0
- package/dist/src/formats/writeHex.js +39 -0
- package/dist/src/formats/writeListing.d.ts +8 -0
- package/dist/src/formats/writeListing.js +83 -0
- package/dist/src/frontend/asm80/asmLine.d.ts +39 -0
- package/dist/src/frontend/asm80/asmLine.js +89 -0
- package/dist/src/frontend/asm80/parseAsmRawValues.d.ts +4 -0
- package/dist/src/frontend/asm80/parseAsmRawValues.js +94 -0
- package/dist/src/frontend/asm80/quoteScan.d.ts +10 -0
- package/dist/src/frontend/asm80/quoteScan.js +25 -0
- package/dist/src/frontend/ast.d.ts +376 -0
- package/dist/src/frontend/ast.js +1 -0
- package/dist/src/frontend/directiveAliases.d.ts +14 -0
- package/dist/src/frontend/directiveAliases.js +189 -0
- package/dist/src/frontend/grammarData.d.ts +14 -0
- package/dist/src/frontend/grammarData.js +65 -0
- package/dist/src/frontend/immExprUtils.d.ts +2 -0
- package/dist/src/frontend/immExprUtils.js +12 -0
- package/dist/src/frontend/parseAsmFlatDirectiveLine.d.ts +17 -0
- package/dist/src/frontend/parseAsmFlatDirectiveLine.js +187 -0
- package/dist/src/frontend/parseAsmInstruction.d.ts +3 -0
- package/dist/src/frontend/parseAsmInstruction.js +73 -0
- package/dist/src/frontend/parseAsmStatements.d.ts +6 -0
- package/dist/src/frontend/parseAsmStatements.js +16 -0
- package/dist/src/frontend/parseAsmStream.d.ts +10 -0
- package/dist/src/frontend/parseAsmStream.js +33 -0
- package/dist/src/frontend/parseAsmTopLevel.d.ts +18 -0
- package/dist/src/frontend/parseAsmTopLevel.js +34 -0
- package/dist/src/frontend/parseDiagnostics.d.ts +9 -0
- package/dist/src/frontend/parseDiagnostics.js +16 -0
- package/dist/src/frontend/parseEnum.d.ts +12 -0
- package/dist/src/frontend/parseEnum.js +70 -0
- package/dist/src/frontend/parseImm.d.ts +10 -0
- package/dist/src/frontend/parseImm.js +397 -0
- package/dist/src/frontend/parseLogicalLines.d.ts +11 -0
- package/dist/src/frontend/parseLogicalLines.js +94 -0
- package/dist/src/frontend/parseOp.d.ts +25 -0
- package/dist/src/frontend/parseOp.js +120 -0
- package/dist/src/frontend/parseOpHeader.d.ts +20 -0
- package/dist/src/frontend/parseOpHeader.js +32 -0
- package/dist/src/frontend/parseOperands.d.ts +4 -0
- package/dist/src/frontend/parseOperands.js +290 -0
- package/dist/src/frontend/parseParams.d.ts +6 -0
- package/dist/src/frontend/parseParams.js +62 -0
- package/dist/src/frontend/parseParserRecovery.d.ts +12 -0
- package/dist/src/frontend/parseParserRecovery.js +17 -0
- package/dist/src/frontend/parseParserShared.d.ts +2 -0
- package/dist/src/frontend/parseParserShared.js +8 -0
- package/dist/src/frontend/parseRawDataDirectiveStart.d.ts +1 -0
- package/dist/src/frontend/parseRawDataDirectiveStart.js +3 -0
- package/dist/src/frontend/parseRawDataDirectives.d.ts +7 -0
- package/dist/src/frontend/parseRawDataDirectives.js +142 -0
- package/dist/src/frontend/parseRecordFieldDecl.d.ts +34 -0
- package/dist/src/frontend/parseRecordFieldDecl.js +177 -0
- package/dist/src/frontend/parseSourceItemDispatch.d.ts +46 -0
- package/dist/src/frontend/parseSourceItemDispatch.js +53 -0
- package/dist/src/frontend/parseSourceItemTable.d.ts +16 -0
- package/dist/src/frontend/parseSourceItemTable.js +68 -0
- package/dist/src/frontend/parseTopLevelCommon.d.ts +11 -0
- package/dist/src/frontend/parseTopLevelCommon.js +50 -0
- package/dist/src/frontend/parseTypes.d.ts +24 -0
- package/dist/src/frontend/parseTypes.js +77 -0
- package/dist/src/frontend/parser.d.ts +11 -0
- package/dist/src/frontend/parser.js +88 -0
- package/dist/src/frontend/source.d.ts +28 -0
- package/dist/src/frontend/source.js +58 -0
- package/dist/src/frontend/sourceExtensions.d.ts +2 -0
- package/dist/src/frontend/sourceExtensions.js +6 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +2 -0
- package/dist/src/lintCaseStyle.d.ts +4 -0
- package/dist/src/lintCaseStyle.js +129 -0
- package/dist/src/lowering/asmDirectiveLowering.d.ts +4 -0
- package/dist/src/lowering/asmDirectiveLowering.js +229 -0
- package/dist/src/lowering/asmDirectiveTraversal.d.ts +47 -0
- package/dist/src/lowering/asmDirectiveTraversal.js +52 -0
- package/dist/src/lowering/asmEquResolution.d.ts +8 -0
- package/dist/src/lowering/asmEquResolution.js +69 -0
- package/dist/src/lowering/asmInstructionLdHelpers.d.ts +15 -0
- package/dist/src/lowering/asmInstructionLdHelpers.js +102 -0
- package/dist/src/lowering/asmInstructionLowering.d.ts +5 -0
- package/dist/src/lowering/asmInstructionLowering.js +54 -0
- package/dist/src/lowering/asmInstructionStream.d.ts +46 -0
- package/dist/src/lowering/asmInstructionStream.js +51 -0
- package/dist/src/lowering/asmLoweringBranchCall.d.ts +43 -0
- package/dist/src/lowering/asmLoweringBranchCall.js +254 -0
- package/dist/src/lowering/asmLoweringHost.d.ts +23 -0
- package/dist/src/lowering/asmLoweringHost.js +1 -0
- package/dist/src/lowering/asmLoweringLd.d.ts +28 -0
- package/dist/src/lowering/asmLoweringLd.js +144 -0
- package/dist/src/lowering/asmRangeLowering.d.ts +17 -0
- package/dist/src/lowering/asmRangeLowering.js +39 -0
- package/dist/src/lowering/asmRawDataLowering.d.ts +16 -0
- package/dist/src/lowering/asmRawDataLowering.js +209 -0
- package/dist/src/lowering/asmSourceEmitter.d.ts +4 -0
- package/dist/src/lowering/asmSourceEmitter.js +9 -0
- package/dist/src/lowering/asmSourceInstructionLowering.d.ts +4 -0
- package/dist/src/lowering/asmSourceInstructionLowering.js +14 -0
- package/dist/src/lowering/asmUtils.d.ts +13 -0
- package/dist/src/lowering/asmUtils.js +105 -0
- package/dist/src/lowering/assemblerFlowSetup.d.ts +54 -0
- package/dist/src/lowering/assemblerFlowSetup.js +128 -0
- package/dist/src/lowering/assemblerLoweringContext.d.ts +151 -0
- package/dist/src/lowering/assemblerLoweringContext.js +16 -0
- package/dist/src/lowering/assemblerLoweringContextSplit.d.ts +7 -0
- package/dist/src/lowering/assemblerLoweringContextSplit.js +75 -0
- package/dist/src/lowering/assemblerLoweringPhases.d.ts +66 -0
- package/dist/src/lowering/assemblerLoweringPhases.js +166 -0
- package/dist/src/lowering/bytePlacement.d.ts +7 -0
- package/dist/src/lowering/bytePlacement.js +37 -0
- package/dist/src/lowering/capabilities.d.ts +67 -0
- package/dist/src/lowering/capabilities.js +1 -0
- package/dist/src/lowering/eaResolution.d.ts +58 -0
- package/dist/src/lowering/eaResolution.js +159 -0
- package/dist/src/lowering/emissionCore.d.ts +17 -0
- package/dist/src/lowering/emissionCore.js +21 -0
- package/dist/src/lowering/emit.d.ts +17 -0
- package/dist/src/lowering/emit.js +46 -0
- package/dist/src/lowering/emitContextBuilder.d.ts +63 -0
- package/dist/src/lowering/emitContextBuilder.js +41 -0
- package/dist/src/lowering/emitFinalization.d.ts +61 -0
- package/dist/src/lowering/emitFinalization.js +66 -0
- package/dist/src/lowering/emitFinalizationSetup.d.ts +19 -0
- package/dist/src/lowering/emitFinalizationSetup.js +26 -0
- package/dist/src/lowering/emitPhase1BuildProgramLoweringContext.d.ts +7 -0
- package/dist/src/lowering/emitPhase1BuildProgramLoweringContext.js +119 -0
- package/dist/src/lowering/emitPhase1Helpers.d.ts +4 -0
- package/dist/src/lowering/emitPhase1Helpers.js +12 -0
- package/dist/src/lowering/emitPhase1Types.d.ts +21 -0
- package/dist/src/lowering/emitPhase1Types.js +1 -0
- package/dist/src/lowering/emitPhase1WirePipeline.d.ts +70 -0
- package/dist/src/lowering/emitPhase1WirePipeline.js +203 -0
- package/dist/src/lowering/emitPhase1Workspace.d.ts +82 -0
- package/dist/src/lowering/emitPhase1Workspace.js +55 -0
- package/dist/src/lowering/emitPipeline.d.ts +121 -0
- package/dist/src/lowering/emitPipeline.js +57 -0
- package/dist/src/lowering/emitProgramContext.d.ts +39 -0
- package/dist/src/lowering/emitProgramContext.js +29 -0
- package/dist/src/lowering/emitState.d.ts +90 -0
- package/dist/src/lowering/emitState.js +124 -0
- package/dist/src/lowering/fixupBaseResolution.d.ts +7 -0
- package/dist/src/lowering/fixupBaseResolution.js +23 -0
- package/dist/src/lowering/fixupEmission.d.ts +64 -0
- package/dist/src/lowering/fixupEmission.js +199 -0
- package/dist/src/lowering/immMath.d.ts +2 -0
- package/dist/src/lowering/immMath.js +34 -0
- package/dist/src/lowering/inputAssets.d.ts +7 -0
- package/dist/src/lowering/inputAssets.js +106 -0
- package/dist/src/lowering/ldEncoding.d.ts +15 -0
- package/dist/src/lowering/ldEncoding.js +12 -0
- package/dist/src/lowering/ldEncodingRegMemHelpers.d.ts +5 -0
- package/dist/src/lowering/ldEncodingRegMemHelpers.js +124 -0
- package/dist/src/lowering/ldFormSelection.d.ts +26 -0
- package/dist/src/lowering/ldFormSelection.js +92 -0
- package/dist/src/lowering/ldLowering.d.ts +7 -0
- package/dist/src/lowering/ldLowering.js +13 -0
- package/dist/src/lowering/loweredAsmByteEmission.d.ts +23 -0
- package/dist/src/lowering/loweredAsmByteEmission.js +185 -0
- package/dist/src/lowering/loweredAsmPlacement.d.ts +13 -0
- package/dist/src/lowering/loweredAsmPlacement.js +86 -0
- package/dist/src/lowering/loweredAsmStreamRecording.d.ts +27 -0
- package/dist/src/lowering/loweredAsmStreamRecording.js +215 -0
- package/dist/src/lowering/loweredAsmTypes.d.ts +202 -0
- package/dist/src/lowering/loweredAsmTypes.js +1 -0
- package/dist/src/lowering/loweredFormat.d.ts +3 -0
- package/dist/src/lowering/loweredFormat.js +26 -0
- package/dist/src/lowering/loweredItemSize.d.ts +4 -0
- package/dist/src/lowering/loweredItemSize.js +17 -0
- package/dist/src/lowering/loweringDiagnostics.d.ts +9 -0
- package/dist/src/lowering/loweringDiagnostics.js +55 -0
- package/dist/src/lowering/loweringTypes.d.ts +27 -0
- package/dist/src/lowering/loweringTypes.js +1 -0
- package/dist/src/lowering/opCandidateRegistry.d.ts +9 -0
- package/dist/src/lowering/opCandidateRegistry.js +9 -0
- package/dist/src/lowering/opExpansionExecution.d.ts +15 -0
- package/dist/src/lowering/opExpansionExecution.js +45 -0
- package/dist/src/lowering/opExpansionOrchestration.d.ts +15 -0
- package/dist/src/lowering/opExpansionOrchestration.js +88 -0
- package/dist/src/lowering/opExpansionStream.d.ts +12 -0
- package/dist/src/lowering/opExpansionStream.js +176 -0
- package/dist/src/lowering/opMatching.d.ts +52 -0
- package/dist/src/lowering/opMatching.js +355 -0
- package/dist/src/lowering/opSubstitution.d.ts +13 -0
- package/dist/src/lowering/opSubstitution.js +175 -0
- package/dist/src/lowering/prescanTypes.d.ts +7 -0
- package/dist/src/lowering/prescanTypes.js +1 -0
- package/dist/src/lowering/programLowering.d.ts +144 -0
- package/dist/src/lowering/programLowering.js +2 -0
- package/dist/src/lowering/programLoweringDeclarations.d.ts +5 -0
- package/dist/src/lowering/programLoweringDeclarations.js +5 -0
- package/dist/src/lowering/programLoweringFinalize.d.ts +18 -0
- package/dist/src/lowering/programLoweringFinalize.js +115 -0
- package/dist/src/lowering/programLoweringTraversal.d.ts +2 -0
- package/dist/src/lowering/programLoweringTraversal.js +93 -0
- package/dist/src/lowering/programPrescan.d.ts +3 -0
- package/dist/src/lowering/programPrescan.js +37 -0
- package/dist/src/lowering/traceFormat.d.ts +13 -0
- package/dist/src/lowering/traceFormat.js +211 -0
- package/dist/src/pathCompare.d.ts +3 -0
- package/dist/src/pathCompare.js +26 -0
- package/dist/src/pipeline.d.ts +78 -0
- package/dist/src/pipeline.js +1 -0
- package/dist/src/registerCare/analyze.d.ts +24 -0
- package/dist/src/registerCare/analyze.js +327 -0
- package/dist/src/registerCare/annotate.d.ts +11 -0
- package/dist/src/registerCare/annotate.js +76 -0
- package/dist/src/registerCare/boundaryHints.d.ts +2 -0
- package/dist/src/registerCare/boundaryHints.js +10 -0
- package/dist/src/registerCare/carriers.d.ts +4 -0
- package/dist/src/registerCare/carriers.js +78 -0
- package/dist/src/registerCare/controlFlow.d.ts +5 -0
- package/dist/src/registerCare/controlFlow.js +35 -0
- package/dist/src/registerCare/fix.d.ts +11 -0
- package/dist/src/registerCare/fix.js +119 -0
- package/dist/src/registerCare/liveness.d.ts +7 -0
- package/dist/src/registerCare/liveness.js +227 -0
- package/dist/src/registerCare/profiles.d.ts +11 -0
- package/dist/src/registerCare/profiles.js +45 -0
- package/dist/src/registerCare/programModel.d.ts +3 -0
- package/dist/src/registerCare/programModel.js +181 -0
- package/dist/src/registerCare/report.d.ts +5 -0
- package/dist/src/registerCare/report.js +139 -0
- package/dist/src/registerCare/smartComments.d.ts +5 -0
- package/dist/src/registerCare/smartComments.js +247 -0
- package/dist/src/registerCare/sourceText.d.ts +8 -0
- package/dist/src/registerCare/sourceText.js +15 -0
- package/dist/src/registerCare/summary.d.ts +3 -0
- package/dist/src/registerCare/summary.js +492 -0
- package/dist/src/registerCare/tooling.d.ts +42 -0
- package/dist/src/registerCare/tooling.js +50 -0
- package/dist/src/registerCare/types.d.ts +154 -0
- package/dist/src/registerCare/types.js +1 -0
- package/dist/src/semantics/declVisitor.d.ts +5 -0
- package/dist/src/semantics/declVisitor.js +11 -0
- package/dist/src/semantics/env.d.ts +28 -0
- package/dist/src/semantics/env.js +432 -0
- package/dist/src/semantics/layout.d.ts +21 -0
- package/dist/src/semantics/layout.js +226 -0
- package/dist/src/semantics/layoutCastFold.d.ts +22 -0
- package/dist/src/semantics/layoutCastFold.js +118 -0
- package/dist/src/semantics/semanticsDiagnostics.d.ts +2 -0
- package/dist/src/semantics/semanticsDiagnostics.js +4 -0
- package/dist/src/semantics/typeQueries.d.ts +31 -0
- package/dist/src/semantics/typeQueries.js +124 -0
- package/dist/src/sourceIncludeExpansion.d.ts +17 -0
- package/dist/src/sourceIncludeExpansion.js +124 -0
- package/dist/src/sourceIncludePaths.d.ts +1 -0
- package/dist/src/sourceIncludePaths.js +12 -0
- package/dist/src/sourceLoader.d.ts +15 -0
- package/dist/src/sourceLoader.js +118 -0
- package/dist/src/z80/effects.d.ts +3 -0
- package/dist/src/z80/effects.js +516 -0
- package/dist/src/z80/encode.d.ts +10 -0
- package/dist/src/z80/encode.js +412 -0
- package/dist/src/z80/encodeAlu.d.ts +7 -0
- package/dist/src/z80/encodeAlu.js +219 -0
- package/dist/src/z80/encodeBitOps.d.ts +7 -0
- package/dist/src/z80/encodeBitOps.js +123 -0
- package/dist/src/z80/encodeContext.d.ts +29 -0
- package/dist/src/z80/encodeContext.js +1 -0
- package/dist/src/z80/encodeControl.d.ts +26 -0
- package/dist/src/z80/encodeControl.js +180 -0
- package/dist/src/z80/encodeCoreOps.d.ts +7 -0
- package/dist/src/z80/encodeCoreOps.js +131 -0
- package/dist/src/z80/encodeIo.d.ts +9 -0
- package/dist/src/z80/encodeIo.js +128 -0
- package/dist/src/z80/encodeLd.d.ts +13 -0
- package/dist/src/z80/encodeLd.js +273 -0
- package/dist/src/z80/encoderRegistry.d.ts +13 -0
- package/dist/src/z80/encoderRegistry.js +169 -0
- package/docs/reference/cli.md +134 -0
- package/docs/reference/tooling-api.md +248 -0
- package/package.json +98 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Diagnostic } from './diagnosticTypes.js';
|
|
2
|
+
import type { ProgramNode } from './frontend/ast.js';
|
|
3
|
+
import type { DirectiveAliasPolicy } from './frontend/directiveAliases.js';
|
|
4
|
+
import type { CompilerOptions } from './pipeline.js';
|
|
5
|
+
export type LoadedProgram = {
|
|
6
|
+
program: ProgramNode;
|
|
7
|
+
sourceTexts: Map<string, string>;
|
|
8
|
+
sourceLineComments: Map<string, Map<number, string>>;
|
|
9
|
+
};
|
|
10
|
+
export interface LoadProgramOptions extends Pick<CompilerOptions, 'includeDirs'> {
|
|
11
|
+
directiveAliasPolicy?: DirectiveAliasPolicy;
|
|
12
|
+
preloadedText?: string;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
export declare function loadProgram(entryFile: string, diagnostics: Diagnostic[], options: LoadProgramOptions): Promise<LoadedProgram | undefined>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { hasErrors, normalizePath } from './compileShared.js';
|
|
3
|
+
import { DiagnosticIds } from './diagnosticTypes.js';
|
|
4
|
+
import { buildDirectiveAliasPolicy, defaultDirectiveAliasProfileName, } from './frontend/directiveAliases.js';
|
|
5
|
+
import { parseSourceFile } from './frontend/parser.js';
|
|
6
|
+
import { makeSourceFile } from './frontend/source.js';
|
|
7
|
+
import { isSupportedSourcePath } from './frontend/sourceExtensions.js';
|
|
8
|
+
import { expandTextIncludesForFile } from './sourceIncludeExpansion.js';
|
|
9
|
+
function throwIfAborted(signal) {
|
|
10
|
+
signal?.throwIfAborted();
|
|
11
|
+
}
|
|
12
|
+
async function readSourceFileText(sourcePath, diagnostics, importer, preloadedText, signal) {
|
|
13
|
+
throwIfAborted(signal);
|
|
14
|
+
try {
|
|
15
|
+
return preloadedText ?? (await readFile(sourcePath, 'utf8'));
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
diagnostics.push({
|
|
19
|
+
id: DiagnosticIds.IoReadFailed,
|
|
20
|
+
severity: 'error',
|
|
21
|
+
message: importer
|
|
22
|
+
? `Failed to read included source file "${sourcePath}" (included by "${importer}"): ${String(err)}`
|
|
23
|
+
: `Failed to read entry file: ${String(err)}`,
|
|
24
|
+
file: importer ?? sourcePath,
|
|
25
|
+
});
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function recordSourceLineComments(sourceLineComments, expanded) {
|
|
30
|
+
const lines = expanded.text.split(/\r?\n/);
|
|
31
|
+
for (let i = 0; i < lines.length; i++) {
|
|
32
|
+
const line = lines[i] ?? '';
|
|
33
|
+
const semi = line.indexOf(';');
|
|
34
|
+
if (semi < 0)
|
|
35
|
+
continue;
|
|
36
|
+
const commentText = line.slice(semi + 1).trim();
|
|
37
|
+
if (!commentText)
|
|
38
|
+
continue;
|
|
39
|
+
const fileRaw = expanded.lineFiles[i];
|
|
40
|
+
if (!fileRaw)
|
|
41
|
+
continue;
|
|
42
|
+
const file = normalizePath(fileRaw);
|
|
43
|
+
const lineNo = expanded.lineBaseLines[i] ?? i + 1;
|
|
44
|
+
let lineMap = sourceLineComments.get(file);
|
|
45
|
+
if (!lineMap) {
|
|
46
|
+
lineMap = new Map();
|
|
47
|
+
sourceLineComments.set(file, lineMap);
|
|
48
|
+
}
|
|
49
|
+
lineMap.set(lineNo, commentText);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function parseExpandedSourceFile(sourcePath, expanded, diagnostics, aliasPolicy) {
|
|
53
|
+
try {
|
|
54
|
+
const sourceFile = makeSourceFile(sourcePath, expanded.text);
|
|
55
|
+
sourceFile.lineFiles = expanded.lineFiles;
|
|
56
|
+
sourceFile.lineBaseLines = expanded.lineBaseLines;
|
|
57
|
+
return parseSourceFile(sourcePath, expanded.text, diagnostics, sourceFile, aliasPolicy);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
diagnostics.push({
|
|
61
|
+
id: DiagnosticIds.InternalParseError,
|
|
62
|
+
severity: 'error',
|
|
63
|
+
message: `Internal error during parse: ${String(err)}`,
|
|
64
|
+
file: sourcePath,
|
|
65
|
+
});
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export async function loadProgram(entryFile, diagnostics, options) {
|
|
70
|
+
const entryPath = normalizePath(entryFile);
|
|
71
|
+
const sourceTexts = new Map();
|
|
72
|
+
const sourceLineComments = new Map();
|
|
73
|
+
const includeDirs = (options.includeDirs ?? []).map(normalizePath);
|
|
74
|
+
const aliasPolicy = options.directiveAliasPolicy ?? buildDirectiveAliasPolicy(defaultDirectiveAliasProfileName());
|
|
75
|
+
const signal = options.signal;
|
|
76
|
+
throwIfAborted(signal);
|
|
77
|
+
const sourceText = await readSourceFileText(entryPath, diagnostics, undefined, options.preloadedText, signal);
|
|
78
|
+
if (sourceText === undefined)
|
|
79
|
+
return undefined;
|
|
80
|
+
sourceTexts.set(entryPath, sourceText);
|
|
81
|
+
if (!isSupportedSourcePath(entryPath)) {
|
|
82
|
+
diagnostics.push({
|
|
83
|
+
id: DiagnosticIds.Unknown,
|
|
84
|
+
severity: 'error',
|
|
85
|
+
message: 'Unsupported source file extension (expected .asm or .z80)',
|
|
86
|
+
file: entryPath,
|
|
87
|
+
});
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const expanded = await expandTextIncludesForFile({
|
|
91
|
+
sourcePath: entryPath,
|
|
92
|
+
sourceText,
|
|
93
|
+
includeDirs,
|
|
94
|
+
diagnostics,
|
|
95
|
+
sourceTexts,
|
|
96
|
+
includeStack: [entryPath],
|
|
97
|
+
...(aliasPolicy ? { aliasPolicy } : {}),
|
|
98
|
+
...(signal ? { signal } : {}),
|
|
99
|
+
});
|
|
100
|
+
if (expanded === undefined)
|
|
101
|
+
return undefined;
|
|
102
|
+
if (hasErrors(diagnostics))
|
|
103
|
+
return undefined;
|
|
104
|
+
const entrySource = parseExpandedSourceFile(entryPath, expanded, diagnostics, aliasPolicy);
|
|
105
|
+
if (!entrySource)
|
|
106
|
+
return undefined;
|
|
107
|
+
recordSourceLineComments(sourceLineComments, expanded);
|
|
108
|
+
return {
|
|
109
|
+
program: {
|
|
110
|
+
kind: 'Program',
|
|
111
|
+
span: entrySource.span,
|
|
112
|
+
entryFile: entryPath,
|
|
113
|
+
files: [entrySource],
|
|
114
|
+
},
|
|
115
|
+
sourceTexts,
|
|
116
|
+
sourceLineComments,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { expandCarrier } from '../registerCare/carriers.js';
|
|
2
|
+
const FLAG_WRITES = ['sign', 'zero', 'halfCarry', 'parity', 'carry'];
|
|
3
|
+
const INC_DEC_FLAG_WRITES = ['sign', 'zero', 'halfCarry', 'parity'];
|
|
4
|
+
const ROTATE_SHIFT_FLAG_WRITES = [
|
|
5
|
+
'sign',
|
|
6
|
+
'zero',
|
|
7
|
+
'halfCarry',
|
|
8
|
+
'parity',
|
|
9
|
+
'carry',
|
|
10
|
+
];
|
|
11
|
+
const BIT_FLAG_WRITES = ['sign', 'zero', 'halfCarry', 'parity'];
|
|
12
|
+
const STACK_POINTER_UNITS = ['SPH', 'SPL'];
|
|
13
|
+
const UNKNOWN_UNITS = [
|
|
14
|
+
'A',
|
|
15
|
+
'B',
|
|
16
|
+
'C',
|
|
17
|
+
'D',
|
|
18
|
+
'E',
|
|
19
|
+
'H',
|
|
20
|
+
'L',
|
|
21
|
+
'IXH',
|
|
22
|
+
'IXL',
|
|
23
|
+
'IYH',
|
|
24
|
+
'IYL',
|
|
25
|
+
'SPH',
|
|
26
|
+
'SPL',
|
|
27
|
+
'carry',
|
|
28
|
+
'zero',
|
|
29
|
+
'sign',
|
|
30
|
+
'parity',
|
|
31
|
+
'halfCarry',
|
|
32
|
+
];
|
|
33
|
+
function baseEffect() {
|
|
34
|
+
return {
|
|
35
|
+
reads: [],
|
|
36
|
+
writes: [],
|
|
37
|
+
stack: { kind: 'none' },
|
|
38
|
+
control: { kind: 'fallthrough' },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function unknownEffect() {
|
|
42
|
+
return {
|
|
43
|
+
reads: UNKNOWN_UNITS,
|
|
44
|
+
writes: UNKNOWN_UNITS,
|
|
45
|
+
stack: { kind: 'unknown' },
|
|
46
|
+
control: { kind: 'unknown' },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function appendUnique(out, units) {
|
|
50
|
+
for (const unit of units) {
|
|
51
|
+
if (!out.includes(unit))
|
|
52
|
+
out.push(unit);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function concatUnique(...groups) {
|
|
56
|
+
const out = [];
|
|
57
|
+
for (const group of groups)
|
|
58
|
+
appendUnique(out, group);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function registerUnits(op) {
|
|
62
|
+
if (!op || op.kind !== 'Reg')
|
|
63
|
+
return undefined;
|
|
64
|
+
return expandCarrier(op.name);
|
|
65
|
+
}
|
|
66
|
+
function immName(op) {
|
|
67
|
+
return op?.kind === 'Imm' && op.expr.kind === 'ImmName' ? op.expr.name : undefined;
|
|
68
|
+
}
|
|
69
|
+
function immLiteral(op) {
|
|
70
|
+
return op?.kind === 'Imm' && op.expr.kind === 'ImmLiteral' ? op.expr.value : undefined;
|
|
71
|
+
}
|
|
72
|
+
function operandTokenName(op) {
|
|
73
|
+
if (op?.kind === 'Reg')
|
|
74
|
+
return op.name.toUpperCase();
|
|
75
|
+
if (op?.kind === 'Imm' && op.expr.kind === 'ImmName')
|
|
76
|
+
return op.expr.name.toUpperCase();
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
function conditionFlagRead(op) {
|
|
80
|
+
switch (operandTokenName(op)) {
|
|
81
|
+
case 'Z':
|
|
82
|
+
case 'NZ':
|
|
83
|
+
return ['zero'];
|
|
84
|
+
case 'C':
|
|
85
|
+
case 'NC':
|
|
86
|
+
return ['carry'];
|
|
87
|
+
case 'M':
|
|
88
|
+
case 'P':
|
|
89
|
+
return ['sign'];
|
|
90
|
+
case 'PE':
|
|
91
|
+
case 'PO':
|
|
92
|
+
return ['parity'];
|
|
93
|
+
default:
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function eaReads(ea) {
|
|
98
|
+
switch (ea.kind) {
|
|
99
|
+
case 'EaName':
|
|
100
|
+
return expandCarrier(ea.name) ?? [];
|
|
101
|
+
case 'EaImm':
|
|
102
|
+
return [];
|
|
103
|
+
case 'EaLayoutCast':
|
|
104
|
+
case 'EaField':
|
|
105
|
+
return eaReads(ea.base);
|
|
106
|
+
case 'EaAdd':
|
|
107
|
+
case 'EaSub':
|
|
108
|
+
return eaReads(ea.base);
|
|
109
|
+
case 'EaIndex': {
|
|
110
|
+
const base = eaReads(ea.base);
|
|
111
|
+
const index = indexReads(ea.index);
|
|
112
|
+
if (!base || !index)
|
|
113
|
+
return undefined;
|
|
114
|
+
return concatUnique(base, index);
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function indexReads(index) {
|
|
121
|
+
switch (index.kind) {
|
|
122
|
+
case 'IndexImm':
|
|
123
|
+
return [];
|
|
124
|
+
case 'IndexReg8':
|
|
125
|
+
case 'IndexReg16':
|
|
126
|
+
return expandCarrier(index.reg);
|
|
127
|
+
case 'IndexMemHL':
|
|
128
|
+
return expandCarrier('HL');
|
|
129
|
+
case 'IndexMemIxIy':
|
|
130
|
+
return expandCarrier(index.base);
|
|
131
|
+
case 'IndexEa':
|
|
132
|
+
return eaReads(index.expr);
|
|
133
|
+
default:
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function operandReads(op) {
|
|
138
|
+
if (!op)
|
|
139
|
+
return undefined;
|
|
140
|
+
switch (op.kind) {
|
|
141
|
+
case 'Reg':
|
|
142
|
+
return expandCarrier(op.name);
|
|
143
|
+
case 'Imm':
|
|
144
|
+
return immReads(op.expr);
|
|
145
|
+
case 'Ea':
|
|
146
|
+
case 'Mem':
|
|
147
|
+
return eaReads(op.expr);
|
|
148
|
+
case 'PortC':
|
|
149
|
+
return expandCarrier('C');
|
|
150
|
+
case 'PortImm8':
|
|
151
|
+
return immReads(op.expr);
|
|
152
|
+
default:
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function immReads(expr) {
|
|
157
|
+
switch (expr.kind) {
|
|
158
|
+
case 'ImmBinary':
|
|
159
|
+
return concatUnique(immReads(expr.left), immReads(expr.right));
|
|
160
|
+
case 'ImmUnary':
|
|
161
|
+
return immReads(expr.expr);
|
|
162
|
+
default:
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function targetName(operands) {
|
|
167
|
+
if (operands.length === 0)
|
|
168
|
+
return undefined;
|
|
169
|
+
return immName(operands[operands.length - 1]);
|
|
170
|
+
}
|
|
171
|
+
function callControl(target, conditional) {
|
|
172
|
+
return target === undefined
|
|
173
|
+
? { kind: 'call', conditional }
|
|
174
|
+
: { kind: 'call', target, conditional };
|
|
175
|
+
}
|
|
176
|
+
function rstControl(vector) {
|
|
177
|
+
return vector === undefined ? { kind: 'rst' } : { kind: 'rst', vector };
|
|
178
|
+
}
|
|
179
|
+
function jumpControl(target, conditional) {
|
|
180
|
+
return target === undefined
|
|
181
|
+
? { kind: 'jump', conditional }
|
|
182
|
+
: { kind: 'jump', target, conditional };
|
|
183
|
+
}
|
|
184
|
+
function isConditionalControl(operands) {
|
|
185
|
+
return operands.length > 1;
|
|
186
|
+
}
|
|
187
|
+
function ldEffect(inst) {
|
|
188
|
+
if (inst.operands.length !== 2)
|
|
189
|
+
return unknownEffect();
|
|
190
|
+
const dst = inst.operands[0];
|
|
191
|
+
const src = inst.operands[1];
|
|
192
|
+
if (!dst || !src)
|
|
193
|
+
return unknownEffect();
|
|
194
|
+
const effect = baseEffect();
|
|
195
|
+
const srcReads = operandReads(src);
|
|
196
|
+
if (!srcReads)
|
|
197
|
+
return unknownEffect();
|
|
198
|
+
if (dst.kind === 'Reg') {
|
|
199
|
+
const dstWrites = expandCarrier(dst.name);
|
|
200
|
+
if (!dstWrites)
|
|
201
|
+
return unknownEffect();
|
|
202
|
+
effect.reads = srcReads;
|
|
203
|
+
effect.writes = dstWrites;
|
|
204
|
+
return effect;
|
|
205
|
+
}
|
|
206
|
+
if (dst.kind === 'Mem') {
|
|
207
|
+
const dstReads = operandReads(dst);
|
|
208
|
+
if (!dstReads)
|
|
209
|
+
return unknownEffect();
|
|
210
|
+
effect.reads = concatUnique(dstReads, srcReads);
|
|
211
|
+
return effect;
|
|
212
|
+
}
|
|
213
|
+
return unknownEffect();
|
|
214
|
+
}
|
|
215
|
+
function unaryOperandEffect(inst, flagWrites) {
|
|
216
|
+
if (inst.operands.length !== 1)
|
|
217
|
+
return unknownEffect();
|
|
218
|
+
const op = inst.operands[0];
|
|
219
|
+
if (!op)
|
|
220
|
+
return unknownEffect();
|
|
221
|
+
const reads = operandReads(op);
|
|
222
|
+
if (!reads)
|
|
223
|
+
return unknownEffect();
|
|
224
|
+
const writes = op.kind === 'Reg' ? registerUnits(op) : [];
|
|
225
|
+
if (!writes)
|
|
226
|
+
return unknownEffect();
|
|
227
|
+
return {
|
|
228
|
+
...baseEffect(),
|
|
229
|
+
reads,
|
|
230
|
+
writes: concatUnique(writes, flagWrites),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function incDecEffect(inst) {
|
|
234
|
+
return unaryOperandEffect(inst, INC_DEC_FLAG_WRITES);
|
|
235
|
+
}
|
|
236
|
+
function aluEffect(inst) {
|
|
237
|
+
if (inst.operands.length < 1 || inst.operands.length > 2)
|
|
238
|
+
return unknownEffect();
|
|
239
|
+
const first = inst.operands[0];
|
|
240
|
+
const second = inst.operands[1];
|
|
241
|
+
const xorSelfZero = inst.head === 'xor' &&
|
|
242
|
+
second === undefined &&
|
|
243
|
+
first?.kind === 'Reg' &&
|
|
244
|
+
first.name.toUpperCase() === 'A';
|
|
245
|
+
const firstReads = operandReads(first);
|
|
246
|
+
if (!firstReads)
|
|
247
|
+
return unknownEffect();
|
|
248
|
+
let reads;
|
|
249
|
+
let writes = [];
|
|
250
|
+
if (second) {
|
|
251
|
+
const secondReads = operandReads(second);
|
|
252
|
+
if (!secondReads)
|
|
253
|
+
return unknownEffect();
|
|
254
|
+
reads = concatUnique(firstReads, secondReads);
|
|
255
|
+
if (inst.head !== 'cp' && first?.kind === 'Reg') {
|
|
256
|
+
const firstWrites = registerUnits(first);
|
|
257
|
+
if (!firstWrites)
|
|
258
|
+
return unknownEffect();
|
|
259
|
+
writes = firstWrites;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const aReads = expandCarrier('A');
|
|
264
|
+
if (!aReads)
|
|
265
|
+
return unknownEffect();
|
|
266
|
+
reads = xorSelfZero ? [] : concatUnique(aReads, firstReads);
|
|
267
|
+
if (inst.head !== 'cp')
|
|
268
|
+
writes = aReads;
|
|
269
|
+
}
|
|
270
|
+
const carryReads = inst.head === 'adc' || inst.head === 'sbc' ? ['carry'] : [];
|
|
271
|
+
return {
|
|
272
|
+
...baseEffect(),
|
|
273
|
+
reads: concatUnique(reads, carryReads),
|
|
274
|
+
writes: concatUnique(writes, FLAG_WRITES),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function pushEffect(inst) {
|
|
278
|
+
if (inst.operands.length !== 1)
|
|
279
|
+
return unknownEffect();
|
|
280
|
+
const units = registerUnits(inst.operands[0]);
|
|
281
|
+
if (!units)
|
|
282
|
+
return unknownEffect();
|
|
283
|
+
return {
|
|
284
|
+
...baseEffect(),
|
|
285
|
+
reads: units,
|
|
286
|
+
writes: STACK_POINTER_UNITS,
|
|
287
|
+
stack: { kind: 'push', units },
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function popEffect(inst) {
|
|
291
|
+
if (inst.operands.length !== 1)
|
|
292
|
+
return unknownEffect();
|
|
293
|
+
const units = registerUnits(inst.operands[0]);
|
|
294
|
+
if (!units)
|
|
295
|
+
return unknownEffect();
|
|
296
|
+
return {
|
|
297
|
+
...baseEffect(),
|
|
298
|
+
writes: concatUnique(units, STACK_POINTER_UNITS),
|
|
299
|
+
stack: { kind: 'pop', units },
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function controlEffect(control, reads = []) {
|
|
303
|
+
return {
|
|
304
|
+
...baseEffect(),
|
|
305
|
+
reads,
|
|
306
|
+
control,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function stackControlEffect(control, reads = []) {
|
|
310
|
+
return {
|
|
311
|
+
...controlEffect(control, reads),
|
|
312
|
+
writes: STACK_POINTER_UNITS,
|
|
313
|
+
stack: { kind: 'unknown' },
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function jumpEffect(inst) {
|
|
317
|
+
const conditional = isConditionalControl(inst.operands);
|
|
318
|
+
const reads = conditional
|
|
319
|
+
? conditionFlagRead(inst.operands[0])
|
|
320
|
+
: operandReads(inst.operands[inst.operands.length - 1]);
|
|
321
|
+
if (!reads)
|
|
322
|
+
return unknownEffect();
|
|
323
|
+
const effect = controlEffect(jumpControl(targetName(inst.operands), conditional));
|
|
324
|
+
effect.reads = reads;
|
|
325
|
+
return effect;
|
|
326
|
+
}
|
|
327
|
+
function callEffect(inst) {
|
|
328
|
+
const conditional = isConditionalControl(inst.operands);
|
|
329
|
+
const reads = conditional ? conditionFlagRead(inst.operands[0]) : [];
|
|
330
|
+
if (!reads)
|
|
331
|
+
return unknownEffect();
|
|
332
|
+
return stackControlEffect(callControl(targetName(inst.operands), conditional), reads);
|
|
333
|
+
}
|
|
334
|
+
function retEffect(inst) {
|
|
335
|
+
const reads = inst.operands.length > 0 ? conditionFlagRead(inst.operands[0]) : [];
|
|
336
|
+
if (!reads)
|
|
337
|
+
return unknownEffect();
|
|
338
|
+
return stackControlEffect({ kind: 'return' }, reads);
|
|
339
|
+
}
|
|
340
|
+
function djnzEffect(inst) {
|
|
341
|
+
return {
|
|
342
|
+
...baseEffect(),
|
|
343
|
+
reads: ['B'],
|
|
344
|
+
writes: ['B'],
|
|
345
|
+
control: jumpControl(targetName(inst.operands), true),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function rotateShiftEffect(inst) {
|
|
349
|
+
return unaryOperandEffect(inst, ROTATE_SHIFT_FLAG_WRITES);
|
|
350
|
+
}
|
|
351
|
+
function accumulatorRotateEffect(head) {
|
|
352
|
+
const reads = head === 'rla' || head === 'rra' ? ['A', 'carry'] : ['A'];
|
|
353
|
+
return {
|
|
354
|
+
...baseEffect(),
|
|
355
|
+
reads,
|
|
356
|
+
writes: ['A', 'carry', 'halfCarry'],
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function bitEffect(inst) {
|
|
360
|
+
if (inst.operands.length !== 2)
|
|
361
|
+
return unknownEffect();
|
|
362
|
+
const target = inst.operands[1];
|
|
363
|
+
if (!target)
|
|
364
|
+
return unknownEffect();
|
|
365
|
+
const reads = operandReads(target);
|
|
366
|
+
if (!reads)
|
|
367
|
+
return unknownEffect();
|
|
368
|
+
return {
|
|
369
|
+
...baseEffect(),
|
|
370
|
+
reads,
|
|
371
|
+
writes: BIT_FLAG_WRITES,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function outEffect(inst) {
|
|
375
|
+
if (inst.operands.length !== 2)
|
|
376
|
+
return unknownEffect();
|
|
377
|
+
const portReads = operandReads(inst.operands[0]);
|
|
378
|
+
const valueReads = operandReads(inst.operands[1]);
|
|
379
|
+
if (!portReads || !valueReads)
|
|
380
|
+
return unknownEffect();
|
|
381
|
+
return {
|
|
382
|
+
...baseEffect(),
|
|
383
|
+
reads: concatUnique(portReads, valueReads),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function inEffect(inst) {
|
|
387
|
+
if (inst.operands.length !== 2)
|
|
388
|
+
return unknownEffect();
|
|
389
|
+
const target = inst.operands[0];
|
|
390
|
+
const port = inst.operands[1];
|
|
391
|
+
if (target?.kind !== 'Reg')
|
|
392
|
+
return unknownEffect();
|
|
393
|
+
const writes = registerUnits(target);
|
|
394
|
+
if (!writes)
|
|
395
|
+
return unknownEffect();
|
|
396
|
+
if (port?.kind === 'PortImm8') {
|
|
397
|
+
return {
|
|
398
|
+
...baseEffect(),
|
|
399
|
+
reads: concatUnique(['A'], operandReads(port) ?? []),
|
|
400
|
+
writes,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
if (port?.kind === 'PortC') {
|
|
404
|
+
return {
|
|
405
|
+
...baseEffect(),
|
|
406
|
+
reads: ['C'],
|
|
407
|
+
writes: concatUnique(writes, BIT_FLAG_WRITES),
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return unknownEffect();
|
|
411
|
+
}
|
|
412
|
+
function blockTransferEffect(inst) {
|
|
413
|
+
if (inst.operands.length !== 0)
|
|
414
|
+
return unknownEffect();
|
|
415
|
+
return {
|
|
416
|
+
...baseEffect(),
|
|
417
|
+
reads: ['H', 'L', 'D', 'E', 'B', 'C'],
|
|
418
|
+
writes: ['H', 'L', 'D', 'E', 'B', 'C', 'halfCarry', 'parity'],
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function exEffect(inst) {
|
|
422
|
+
if (inst.operands.length !== 2)
|
|
423
|
+
return unknownEffect();
|
|
424
|
+
const left = inst.operands[0];
|
|
425
|
+
const right = inst.operands[1];
|
|
426
|
+
const leftUnits = registerUnits(left);
|
|
427
|
+
const rightUnits = registerUnits(right);
|
|
428
|
+
if (!leftUnits || !rightUnits)
|
|
429
|
+
return unknownEffect();
|
|
430
|
+
const leftName = left?.kind === 'Reg' ? left.name.toUpperCase() : '';
|
|
431
|
+
const rightName = right?.kind === 'Reg' ? right.name.toUpperCase() : '';
|
|
432
|
+
const isDeHl = (leftName === 'DE' && rightName === 'HL') || (leftName === 'HL' && rightName === 'DE');
|
|
433
|
+
if (!isDeHl)
|
|
434
|
+
return unknownEffect();
|
|
435
|
+
return {
|
|
436
|
+
...baseEffect(),
|
|
437
|
+
reads: concatUnique(leftUnits, rightUnits),
|
|
438
|
+
writes: concatUnique(leftUnits, rightUnits),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
export function getZ80InstructionEffect(inst) {
|
|
442
|
+
switch (inst.head.toLowerCase()) {
|
|
443
|
+
case 'nop':
|
|
444
|
+
case 'halt':
|
|
445
|
+
case 'di':
|
|
446
|
+
case 'ei':
|
|
447
|
+
return baseEffect();
|
|
448
|
+
case 'ld':
|
|
449
|
+
return ldEffect(inst);
|
|
450
|
+
case 'inc':
|
|
451
|
+
case 'dec':
|
|
452
|
+
return incDecEffect(inst);
|
|
453
|
+
case 'add':
|
|
454
|
+
case 'adc':
|
|
455
|
+
case 'sbc':
|
|
456
|
+
case 'sub':
|
|
457
|
+
case 'and':
|
|
458
|
+
case 'or':
|
|
459
|
+
case 'xor':
|
|
460
|
+
case 'cp':
|
|
461
|
+
return aluEffect(inst);
|
|
462
|
+
case 'push':
|
|
463
|
+
return pushEffect(inst);
|
|
464
|
+
case 'pop':
|
|
465
|
+
return popEffect(inst);
|
|
466
|
+
case 'call':
|
|
467
|
+
return callEffect(inst);
|
|
468
|
+
case 'rst':
|
|
469
|
+
return stackControlEffect(rstControl(immLiteral(inst.operands[0])));
|
|
470
|
+
case 'ret':
|
|
471
|
+
case 'retn':
|
|
472
|
+
case 'reti':
|
|
473
|
+
return retEffect(inst);
|
|
474
|
+
case 'jp':
|
|
475
|
+
case 'jr':
|
|
476
|
+
return jumpEffect(inst);
|
|
477
|
+
case 'djnz':
|
|
478
|
+
return djnzEffect(inst);
|
|
479
|
+
case 'rlc':
|
|
480
|
+
case 'rrc':
|
|
481
|
+
case 'rl':
|
|
482
|
+
case 'rr':
|
|
483
|
+
case 'sla':
|
|
484
|
+
case 'sra':
|
|
485
|
+
case 'srl':
|
|
486
|
+
return rotateShiftEffect(inst);
|
|
487
|
+
case 'rlca':
|
|
488
|
+
case 'rrca':
|
|
489
|
+
case 'rla':
|
|
490
|
+
case 'rra':
|
|
491
|
+
return accumulatorRotateEffect(inst.head.toLowerCase());
|
|
492
|
+
case 'bit':
|
|
493
|
+
return bitEffect(inst);
|
|
494
|
+
case 'scf':
|
|
495
|
+
return { ...baseEffect(), writes: ['carry', 'halfCarry'] };
|
|
496
|
+
case 'ccf':
|
|
497
|
+
return { ...baseEffect(), reads: ['carry'], writes: ['carry', 'halfCarry'] };
|
|
498
|
+
case 'cpl':
|
|
499
|
+
return { ...baseEffect(), reads: ['A'], writes: ['A', 'halfCarry'] };
|
|
500
|
+
case 'neg':
|
|
501
|
+
return { ...baseEffect(), reads: ['A'], writes: concatUnique(['A'], FLAG_WRITES) };
|
|
502
|
+
case 'out':
|
|
503
|
+
return outEffect(inst);
|
|
504
|
+
case 'in':
|
|
505
|
+
return inEffect(inst);
|
|
506
|
+
case 'ldi':
|
|
507
|
+
case 'ldir':
|
|
508
|
+
case 'ldd':
|
|
509
|
+
case 'lddr':
|
|
510
|
+
return blockTransferEffect(inst);
|
|
511
|
+
case 'ex':
|
|
512
|
+
return exEffect(inst);
|
|
513
|
+
default:
|
|
514
|
+
return unknownEffect();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Diagnostic } from '../diagnosticTypes.js';
|
|
2
|
+
import type { AsmInstructionNode } from '../frontend/ast.js';
|
|
3
|
+
import type { CompileEnv } from '../semantics/env.js';
|
|
4
|
+
/**
|
|
5
|
+
* Encode a single `asm` instruction node into Z80 machine-code bytes.
|
|
6
|
+
*
|
|
7
|
+
* - Immediate operands may be `imm` expressions (const/enum names and operators), evaluated via the env.
|
|
8
|
+
* - Unsupported forms append an error diagnostic and return `undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeInstruction(node: AsmInstructionNode, env: CompileEnv, diagnostics: Diagnostic[]): Uint8Array | undefined;
|