From c25d07259ab592bd8b032c65eafe1541352032ad Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 10 Apr 2022 21:37:47 +0200 Subject: [PATCH] add block directive options to PtBlock --- codeAst/src/prog8/code/ast/AstBase.kt | 10 +++++++++- .../src/prog8/compiler/IntermediateAstMaker.kt | 17 +++++++++++++++-- examples/test.p8 | 4 ++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/codeAst/src/prog8/code/ast/AstBase.kt b/codeAst/src/prog8/code/ast/AstBase.kt index b68b85572..1f48beb6b 100644 --- a/codeAst/src/prog8/code/ast/AstBase.kt +++ b/codeAst/src/prog8/code/ast/AstBase.kt @@ -80,10 +80,18 @@ class PtProgram( class PtBlock(name: String, val address: UInt?, val library: Boolean, + val forceOutput: Boolean, + val alignment: BlockAlignment, position: Position ) : PtNamedNode(name, position) { override fun printProperties() { - print("$name addr=$address library=$library") + print("$name addr=$address library=$library forceOutput=$forceOutput alignment=$alignment") + } + + enum class BlockAlignment { + NONE, + WORD, + PAGE } } diff --git a/compiler/src/prog8/compiler/IntermediateAstMaker.kt b/compiler/src/prog8/compiler/IntermediateAstMaker.kt index 265874ec6..6eb29fdf3 100644 --- a/compiler/src/prog8/compiler/IntermediateAstMaker.kt +++ b/compiler/src/prog8/compiler/IntermediateAstMaker.kt @@ -131,8 +131,21 @@ class IntermediateAstMaker(val program: Program) { } private fun transform(srcBlock: Block): PtBlock { + var alignment = PtBlock.BlockAlignment.NONE + var forceOutput = false + val directives = srcBlock.statements.filterIsInstance() + for (directive in directives.filter { it.directive == "%option" }) { + for (arg in directive.args) { + when (arg.name) { + "align_word" -> alignment = PtBlock.BlockAlignment.WORD + "align_page" -> alignment = PtBlock.BlockAlignment.PAGE + "force_output" -> forceOutput=true + else -> throw FatalAstException("weird directive option: ${arg.name}") + } + } + } val (vardecls, statements) = srcBlock.statements.partition { it is VarDecl } - val block = PtBlock(srcBlock.name, srcBlock.address, srcBlock.isInLibrary, srcBlock.position) + val block = PtBlock(srcBlock.name, srcBlock.address, srcBlock.isInLibrary, forceOutput, alignment, srcBlock.position) if(vardecls.isNotEmpty()) block.add(makeScopeVarsDecls(vardecls, srcBlock.position)) for (stmt in statements) block.add(transformStatement(stmt)) @@ -185,7 +198,7 @@ class IntermediateAstMaker(val program: Program) { PtInlineAssembly(assembly, directive.position) } else -> { - // other directives don't output any code + // other directives don't output any code (but could end up in option flags somewhere else) PtNop(directive.position) } } diff --git a/examples/test.p8 b/examples/test.p8 index 06cf40567..f467b2437 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,7 +5,11 @@ ; NOTE: meant to test to virtual machine output target (use -target vitual) main { + %option align_word + %option force_output + sub start() { + ; a "pixelshader": void syscall1(8, 0) ; enable lo res creen ubyte shifter