mirror of
https://github.com/irmen/prog8.git
synced 2025-09-26 01:16:46 +00:00
fix mistakes
This commit is contained in:
@@ -211,7 +211,10 @@ internal class BeforeAsmAstChanger(val program: Program, private val options: Co
|
|||||||
val structsize = expr.left.inferType(program).getOrUndef().size(program.memsizer)
|
val structsize = expr.left.inferType(program).getOrUndef().size(program.memsizer)
|
||||||
// pointer + byte -> (pointer as uword) + (byte as uword * structsize) (yields better code on 6502 than the plain pointer arithmetic)
|
// pointer + byte -> (pointer as uword) + (byte as uword * structsize) (yields better code on 6502 than the plain pointer arithmetic)
|
||||||
val ptrCast = TypecastExpression(expr.left, DataType.UWORD, true, expr.left.position)
|
val ptrCast = TypecastExpression(expr.left, DataType.UWORD, true, expr.left.position)
|
||||||
val multiply = BinaryExpression(expr.right, "*", NumericLiteral(BaseDataType.UWORD, structsize.toDouble(), expr.right.position), expr.right.position)
|
val multiply = if(structsize>1)
|
||||||
|
BinaryExpression(expr.right, "*", NumericLiteral(BaseDataType.UWORD, structsize.toDouble(), expr.right.position), expr.right.position)
|
||||||
|
else
|
||||||
|
expr.right
|
||||||
val replacement = BinaryExpression(ptrCast, expr.operator, multiply, expr.position)
|
val replacement = BinaryExpression(ptrCast, expr.operator, multiply, expr.position)
|
||||||
return listOf(IAstModification.ReplaceNode(expr, replacement, parent))
|
return listOf(IAstModification.ReplaceNode(expr, replacement, parent))
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,14 @@ internal class BeforeAsmTypecastCleaner(val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(typecast.type.isUnsignedWord && sourceDt.isPointer) {
|
||||||
|
// remove all typecasts of pointers to unsigned words if they're not part of a pointer arithmetic expression.
|
||||||
|
val expr = typecast.parent as? BinaryExpression
|
||||||
|
if(expr==null || (expr.operator!="+" && expr.operator!="-")) {
|
||||||
|
return listOf(IAstModification.ReplaceNode(typecast, typecast.expression, parent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -872,13 +872,13 @@ main {
|
|||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
val result = compileText(Cx16Target(), true, src, outputDir)!!
|
val result = compileText(VMTarget(), true, src, outputDir)!!
|
||||||
val st = result.codegenAst!!.entrypoint()!!.children
|
val st = result.codegenAst!!.allBlocks().first { it.name=="main" }.children
|
||||||
st.size shouldBe 12
|
st.size shouldBe 5
|
||||||
val add1 = (st[8] as PtSub).children
|
val add1 = (st[1] as PtSub).children
|
||||||
val add2 = (st[9] as PtSub).children
|
val add2 = (st[2] as PtSub).children
|
||||||
val sub1 = (st[10] as PtSub).children
|
val sub1 = (st[3] as PtSub).children
|
||||||
val sub2 = (st[11] as PtSub).children
|
val sub2 = (st[4] as PtSub).children
|
||||||
add1.size shouldBe 5
|
add1.size shouldBe 5
|
||||||
add2.size shouldBe 5
|
add2.size shouldBe 5
|
||||||
sub1.size shouldBe 5
|
sub1.size shouldBe 5
|
||||||
|
@@ -56,8 +56,6 @@ main {
|
|||||||
STRUCTS and TYPED POINTERS (6502 codegen specific)
|
STRUCTS and TYPED POINTERS (6502 codegen specific)
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
- SIZE REGRESSION: binarytree incresed with a dozen bytes or so, fountain-cx16 with a few, sortedlist with 20 or so
|
|
||||||
|
|
||||||
- implement the remaining TODO's in PointerAssignmentsGen.
|
- implement the remaining TODO's in PointerAssignmentsGen.
|
||||||
- fix code size regressions (if any left)
|
- fix code size regressions (if any left)
|
||||||
- update structpointers.rst docs with 6502 specific things?
|
- update structpointers.rst docs with 6502 specific things?
|
||||||
|
Reference in New Issue
Block a user