From 7e73e0dd2314527e9b9a79e51fdd5727e6efdad8 Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 18 Oct 2021 22:08:06 +0200 Subject: [PATCH] + support reading of .p2align with op code and/or max. bytes in the gas assembler reader + test --- compiler/aasmtai.pas | 16 ++++++++++++++++ compiler/raatt.pas | 32 +++++++++++++++++++++++++++++++- tests/test/tp2align.pp | 11 +++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/test/tp2align.pp diff --git a/compiler/aasmtai.pas b/compiler/aasmtai.pas index 9fceeaed06..0b4c67c7d3 100644 --- a/compiler/aasmtai.pas +++ b/compiler/aasmtai.pas @@ -949,6 +949,7 @@ interface constructor Create(b:byte);virtual; constructor Create_op(b: byte; _op: byte);virtual; constructor create_max(b: byte; max: byte);virtual; + constructor create_op_max(b: byte; _op: byte; max: byte);virtual; constructor Create_zeros(b:byte); constructor ppuload(t:taitype;ppufile:tcompilerppufile);override; procedure ppuwrite(ppufile:tcompilerppufile);override; @@ -3349,6 +3350,21 @@ implementation end; + constructor tai_align_abstract.create_op_max(b: byte; _op: byte; max: byte); + begin + inherited Create; + typ:=ait_align; + if b in [1,2,4,8,16,32] then + aligntype := b + else + aligntype := 1; + fillop:=_op; + use_op:=true; + maxbytes:=max; + fillsize:=0; + end; + + constructor tai_align_abstract.Create_zeros(b: byte); begin inherited Create; diff --git a/compiler/raatt.pas b/compiler/raatt.pas index 2d1255b8f9..0e22515fda 100644 --- a/compiler/raatt.pas +++ b/compiler/raatt.pas @@ -1071,6 +1071,8 @@ unit raatt; lasTSec : TAsmSectiontype; l1, l2, + l3, + l4, symofs : tcgint; symtyp : TAsmsymtype; section : tai_section; @@ -1255,7 +1257,35 @@ unit raatt; dec(l1); end; l1:=l2; - ConcatAlign(curlist,l1); + if actasmtoken=AS_COMMA then + begin + Consume(AS_COMMA); + if not(actasmtoken in [AS_SEPARATOR,AS_COMMA]) then + begin + l3:=BuildConstExpression(false,false); + if (l3<0) or (l3>255) then + Message(asmr_e_invalid_constant_expression); + if actasmtoken=AS_COMMA then + begin + Consume(AS_COMMA); + l4:=BuildConstExpression(false,false); + if (l4<0) or (l4>l1) then + Message(asmr_e_invalid_constant_expression); + curlist.concat(Tai_align.create_op_max(l1,l3,l4)); + end + end + else if actasmtoken=AS_COMMA then + begin + Consume(AS_COMMA); + l4:=BuildConstExpression(false,false); + if (l4<0) or (l4>l1) then + Message(asmr_e_invalid_constant_expression); + curlist.concat(Tai_align.create_max(l1,l4)); + end + end + else + ConcatAlign(curlist,l1); + if actasmtoken<>AS_SEPARATOR then Consume(AS_SEPARATOR); end; diff --git a/tests/test/tp2align.pp b/tests/test/tp2align.pp new file mode 100644 index 0000000000..bbff4a4656 --- /dev/null +++ b/tests/test/tp2align.pp @@ -0,0 +1,11 @@ +{ %cpu=x86_64,i386 } + +begin + asm + nop + .p2align 3 + .p2align 4,,10 + .p2align 4,0x90 + .p2align 4,0x90,10 + end; +end.