remove %option align_xxx (block level alignment, as we now have better alternatives)

This commit is contained in:
Irmen de Jong 2024-10-26 21:18:34 +02:00
parent c9535049c8
commit 1f2d46628e
12 changed files with 9 additions and 72 deletions

View File

@ -80,18 +80,11 @@ class PtBlock(name: String,
val options: Options,
position: Position
) : PtNamedNode(name, position), IPtStatementContainer {
enum class BlockAlignment {
NONE,
WORD,
PAGE
}
class Options(val address: UInt? = null,
val forceOutput: Boolean = false,
val noSymbolPrefixing: Boolean = false,
val veraFxMuls: Boolean = false,
val ignoreUnused: Boolean = false,
val alignment: BlockAlignment = BlockAlignment.NONE)
val ignoreUnused: Boolean = false)
}

View File

@ -97,8 +97,7 @@ fun printAst(root: PtNode, skipLibraries: Boolean, output: (text: String) -> Uni
}
is PtBlock -> {
val addr = if(node.options.address==null) "" else "@${node.options.address.toHex()}"
val align = if(node.options.alignment==PtBlock.BlockAlignment.NONE) "" else "align=${node.options.alignment}"
"\nblock '${node.name}' $addr $align"
"\nblock '${node.name}' $addr"
}
is PtConstant -> {
val value = when(node.type) {

View File

@ -291,12 +291,6 @@ internal class ProgramAndVarsGen(
asmgen.out("; ---- block: '${block.name}' ----")
if(block.options.address!=null)
asmgen.out("* = ${block.options.address!!.toHex()}")
else {
if(block.options.alignment==PtBlock.BlockAlignment.WORD)
asmgen.out("\t.align 2")
else if(block.options.alignment==PtBlock.BlockAlignment.PAGE)
asmgen.out("\t.align $100")
}
asmgen.out("${block.name}\t" + (if(block.options.forceOutput) ".block" else ".proc"))
asmgen.outputSourceLine(block)

View File

@ -1668,8 +1668,7 @@ class IRCodeGen(
block.options.forceOutput,
block.options.noSymbolPrefixing,
block.options.veraFxMuls,
block.options.ignoreUnused,
translate(block.options.alignment)
block.options.ignoreUnused
), block.position)
for (child in block.children) {
when(child) {
@ -1734,14 +1733,6 @@ class IRCodeGen(
IRSubroutine.IRParam(flattenedName, orig.dt)
}
private fun translate(alignment: PtBlock.BlockAlignment): IRBlock.BlockAlignment {
return when(alignment) {
PtBlock.BlockAlignment.NONE -> IRBlock.BlockAlignment.NONE
PtBlock.BlockAlignment.WORD -> IRBlock.BlockAlignment.WORD
PtBlock.BlockAlignment.PAGE -> IRBlock.BlockAlignment.PAGE
}
}
private var labelSequenceNumber = 0
internal fun createLabelName(): String {
labelSequenceNumber++

View File

@ -987,12 +987,10 @@ internal class AstChecker(private val program: Program,
err("this directive may only occur in a block or at module level")
if(directive.args.isEmpty())
err("missing option directive argument(s)")
else if(directive.args.map{it.name in arrayOf("enable_floats", "force_output", "no_sysinit", "align_word", "align_page", "merge", "verafxmuls", "splitarrays", "no_symbol_prefixing", "ignore_unused")}.any { !it })
else if(directive.args.map{it.name in arrayOf("enable_floats", "force_output", "no_sysinit", "merge", "verafxmuls", "splitarrays", "no_symbol_prefixing", "ignore_unused")}.any { !it })
err("invalid option directive argument(s)")
if(directive.args.any {it.name=="align_word"} && directive.args.any { it.name=="align_page"})
err("conflicting alignment options")
if(directive.parent is Block) {
if(directive.args.any {it.name !in arrayOf("align_word", "align_page", "force_output", "merge", "verafxmuls", "splitarrays", "no_symbol_prefixing", "ignore_unused")})
if(directive.args.any {it.name !in arrayOf("force_output", "merge", "verafxmuls", "splitarrays", "no_symbol_prefixing", "ignore_unused")})
err("using an option that is not valid for blocks")
}
if(directive.parent is Module) {

View File

@ -185,7 +185,6 @@ class IntermediateAstMaker(private val program: Program, private val errors: IEr
}
private fun transform(srcBlock: Block): PtBlock {
var alignment = PtBlock.BlockAlignment.NONE
var forceOutput = false
var veraFxMuls = false
var noSymbolPrefixing = false
@ -194,8 +193,6 @@ class IntermediateAstMaker(private val program: Program, private val errors: IEr
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
"no_symbol_prefixing" -> noSymbolPrefixing = true
"ignore_unused" -> ignoreUnused = true
"force_output" -> forceOutput = true
@ -208,7 +205,7 @@ class IntermediateAstMaker(private val program: Program, private val errors: IEr
val (vardecls, statements) = srcBlock.statements.partition { it is VarDecl }
val src = srcBlock.definingModule.source
val block = PtBlock(srcBlock.name, srcBlock.isInLibrary, src,
PtBlock.Options(srcBlock.address, forceOutput, noSymbolPrefixing, veraFxMuls, ignoreUnused, alignment),
PtBlock.Options(srcBlock.address, forceOutput, noSymbolPrefixing, veraFxMuls, ignoreUnused),
srcBlock.position)
makeScopeVarsDecls(vardecls).forEach { block.add(it) }
for (stmt in statements)
@ -526,27 +523,6 @@ class IntermediateAstMaker(private val program: Program, private val errors: IEr
when(srcVar.type) {
VarDeclType.VAR -> {
val value = if(srcVar.value!=null) transformExpression(srcVar.value!!) else null
if(srcVar.isArray) {
if(value==null) {
val blockOptions = srcVar.definingBlock.options()
if("align_page" in blockOptions || "align_word" in blockOptions) {
errors.info("converting uninitialized array to explicit zeros because of block alignment option", srcVar.position)
val zeros = PtArray(srcVar.datatype, srcVar.position)
repeat(srcVar.arraysize!!.constIndex()!!) {
zeros.children.add(PtNumber(ArrayToElementTypes.getValue(srcVar.datatype), 0.0, srcVar.position))
}
return PtVariable(
srcVar.name,
srcVar.datatype,
srcVar.zeropage,
srcVar.alignment,
zeros,
srcVar.arraysize?.constIndex()?.toUInt(),
srcVar.position
)
}
}
}
return PtVariable(
srcVar.name,
srcVar.datatype,

View File

@ -139,10 +139,6 @@ Directives
program was launched.
- ``force_output`` (in a block) will force the block to be outputted in the final program.
Can be useful to make sure some data is generated that would otherwise be discarded because the compiler thinks it's not referenced (such as sprite data)
- ``align_word`` (in a block) will make the assembler align the start address of this block on a word boundary in memory (so, an even memory address).
Warning: if you use this to align array variables in the block, these have to be initialized with a value to make them stay in the block and get aligned properly. Otherwise they'll end up at a random spot in the BSS section and the alignment doesn't apply there.
- ``align_page`` (in a block) will make the assembler align the start address of this block on a page boundary in memory (so, the LSB of the address is 0).
Warning: if you use this to align array variables in the block, these have to be initialized with a value to make them stay in the block and get aligned properly. Otherwise they'll end up at a random spot in the BSS section and the alignment doesn't apply there.
- ``merge`` (in a block) will merge this block's contents into an already existing block with the same name. Useful in library scenarios. Can result in a bunch of unused symbol warnings, this depends on the import order.
- ``splitarrays`` (block or module) makes all word-arrays in this scope lsb/msb split arrays (as if they all have the @split tag). See Arrays.
- ``no_symbol_prefixing`` (block or module) makes the compiler *not* use symbol-prefixing when translating prog8 code into assembly.

View File

@ -2,7 +2,6 @@ TODO
====
- rewrite c64 sprite examples to use the new @align64
- remove %option align_xxx (block level alignment, as we now have individual variable alignments) if all uses can be replaced by the new ones
- add docs for @alignxxx. Note: uninitialized (bss) variables are also correctly aligned (%option align docs say they're not, but that is fixed)
- add docs for %align. Note: the directive doesn't modify variable declarations that may follow it!

View File

@ -315,7 +315,7 @@ stereo {
}
wavdata {
%option align_page
wav_data:
%asmbinary "small-adpcm-mono.wav"
wav_data_end:

View File

@ -369,8 +369,7 @@ class IRFileReader {
attrs.getOrDefault("FORCEOUTPUT", "false").toBoolean(),
attrs.getOrDefault("NOPREFIXING", "false").toBoolean(),
attrs.getOrDefault("VERAFXMULS", "false").toBoolean(),
attrs.getOrDefault("IGNOREUNUSED", "false").toBoolean(),
IRBlock.BlockAlignment.valueOf(attrs.getValue("ALIGN"))
attrs.getOrDefault("IGNOREUNUSED", "false").toBoolean()
),
parsePosition(attrs.getValue("POS")))
skipText(reader)

View File

@ -62,7 +62,6 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
if(block.options.noSymbolPrefixing) xml.writeAttribute("NOPREFIXING", "true")
if(block.options.veraFxMuls) xml.writeAttribute("VERAFXMULS", "true")
if(block.options.ignoreUnused) xml.writeAttribute("IGNOREUNUSED", "true")
xml.writeAttribute("ALIGN", block.options.alignment.toString())
xml.writeAttribute("LIBRARY", block.library.toString())
xml.writeAttribute("POS", block.position.toString())
xml.writeCharacters("\n")

View File

@ -368,18 +368,11 @@ class IRBlock(
) {
val children = mutableListOf<IIRBlockElement>()
enum class BlockAlignment {
NONE,
WORD,
PAGE
}
class Options(val address: UInt? = null,
val forceOutput: Boolean = false,
val noSymbolPrefixing: Boolean = false,
val veraFxMuls: Boolean = false,
val ignoreUnused: Boolean = false,
val alignment: BlockAlignment = BlockAlignment.NONE)
val ignoreUnused: Boolean = false)
operator fun plusAssign(sub: IRSubroutine) { children += sub }
operator fun plusAssign(sub: IRAsmSubroutine) { children += sub }