directive really needs to be listed out in the parser otherwise it confuses it with % modulo :-(

Also fix missing const fold pass in optimizer
This commit is contained in:
Irmen de Jong 2023-12-29 03:39:12 +01:00
parent 5d88717f32
commit d28c994ecd
4 changed files with 12 additions and 6 deletions

View File

@ -386,13 +386,18 @@ private fun optimizeAst(program: Program, compilerOptions: CompilationOptions, e
val optsDone2 = program.optimizeStatements(errors, functions, compilerOptions)
val optsDone3 = program.inlineSubroutines(compilerOptions)
program.constantFold(errors, compTarget) // because simplified statements and expressions can result in more constants that can be folded away
errors.report()
if(!errors.noErrors()) {
errors.report()
break
}
if (optsDone1 + optsDone2 + optsDone3 == 0)
break
}
val remover2 = UnusedCodeRemover(program, errors, compTarget)
remover2.visit(program)
remover2.applyModifications()
if(errors.noErrors())
program.constantFold(errors, compTarget) // because simplified statements and expressions can result in more constants that can be folded away
errors.report()
}

View File

@ -361,7 +361,7 @@ private fun ArrayindexContext.toAst() : ArrayIndex =
ArrayIndex(expression().toAst(), toPosition())
internal fun DirectiveContext.toAst() : Directive =
Directive(DIRECTIVE().text, directivearg().map { it.toAst() }, toPosition())
Directive(directivename.text, directivearg().map { it.toAst() }, toPosition())
private fun DirectiveargContext.toAst() : DirectiveArg {
val str = stringliteral()

View File

@ -2,7 +2,6 @@
TODO
====
- fix a1%a2 being parsed as directive
- fix bitshift.p8
- add crc8 and crc16 and crc32 to math
- fix crc* bench routines to no longer depend on the kernal rom version (use a bin file)

View File

@ -34,8 +34,6 @@ INVALID_AND_COMPOSITE: '&&' ;
fragment HEX_DIGIT: ('a'..'f') | ('A'..'F') | ('0'..'9') ;
fragment BIN_DIGIT: ('0' | '1') ;
fragment DEC_DIGIT: ('0'..'9') ;
fragment LOWERCASE: ('a'..'z') ;
DIRECTIVE: '%' LOWERCASE+ ;
FLOAT_NUMBER : FNUMBER (('E'|'e') ('+' | '-')? DEC_INTEGER)? ; // sign comes later from unary expression
FNUMBER : FDOTNUMBER | FNUMDOTNUMBER ;
@ -130,7 +128,11 @@ labeldef : identifier ':' ;
unconditionaljump : 'goto' (integerliteral | scoped_identifier) ;
directive : DIRECTIVE (directivearg? | directivearg (',' directivearg)*) ;
directive :
directivename=('%output' | '%launcher' | '%zeropage' | '%zpreserved' | '%zpallowed' | '%address' | '%import' |
'%breakpoint' | '%asminclude' | '%asmbinary' | '%option' | '%encoding' )
(directivearg? | directivearg (',' directivearg)*)
;
directivearg : stringliteral | identifier | integerliteral ;