add block directive options to PtBlock

This commit is contained in:
Irmen de Jong 2022-04-10 21:37:47 +02:00
parent c960246eee
commit c25d07259a
3 changed files with 28 additions and 3 deletions

View File

@ -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
}
}

View File

@ -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<Directive>()
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)
}
}

View File

@ -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