Browse Source

+ support reading of .p2align with op code and/or max. bytes in the gas assembler reader
+ test

florian 3 years ago
parent
commit
7e73e0dd23
3 changed files with 58 additions and 1 deletions
  1. 16 0
      compiler/aasmtai.pas
  2. 31 1
      compiler/raatt.pas
  3. 11 0
      tests/test/tp2align.pp

+ 16 - 0
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;

+ 31 - 1
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;

+ 11 - 0
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.