Преглед изворни кода

+ support exporting labels from asm blocks in intel syntax asm blocks via the
'public' directive

git-svn-id: trunk@37530 -

nickysn пре 7 година
родитељ
комит
29558a74cd
8 измењених фајлова са 402 додато и 317 уклоњено
  1. 1 0
      .gitattributes
  2. 1 0
      compiler/aasmbase.pas
  3. 3 1
      compiler/msg/errore.msg
  4. 4 2
      compiler/msgidx.inc
  5. 309 309
      compiler/msgtxt.inc
  6. 5 1
      compiler/raatt.pas
  7. 47 4
      compiler/x86/rax86int.pas
  8. 32 0
      tests/test/tasmpublic1.pp

+ 1 - 0
.gitattributes

@@ -12423,6 +12423,7 @@ tests/test/tasm6.pp svneol=native#text/plain
 tests/test/tasm7.pp svneol=native#text/pascal
 tests/test/tasm8.pp svneol=native#text/plain
 tests/test/tasm9.pp svneol=native#text/pascal
+tests/test/tasmpublic1.pp svneol=native#text/pascal
 tests/test/tasmread.pp svneol=native#text/plain
 tests/test/tasout.pp svneol=native#text/plain
 tests/test/tassignmentoperator1.pp svneol=native#text/pascal

+ 1 - 0
compiler/aasmbase.pas

@@ -219,6 +219,7 @@ interface
          labelnr   : longint;
          labeltype : TAsmLabelType;
          is_set    : boolean;
+         is_public : boolean;
          constructor Createlocal(AList: TFPHashObjectList; nr: longint; ltyp: TAsmLabelType);
          constructor Createstatic(AList: TFPHashObjectList; nr: longint; ltyp: TAsmLabelType);
          constructor Createglobal(AList: TFPHashObjectList; const modulename: TSymStr; nr: longint; ltyp: TAsmLabelType);

+ 3 - 1
compiler/msg/errore.msg

@@ -2483,7 +2483,7 @@ cg_f_max_units_reached=06057_F_Maximum number of units ($1) reached for the curr
 #
 # Assembler reader
 #
-# 07136 is the last used one
+# 07137 is the last used one
 #
 asmr_d_start_reading=07000_DL_Starting $1 styled assembler parsing
 % This informs you that an assembler block is being parsed
@@ -2817,6 +2817,8 @@ asmr_e_pop_cs_not_valid=07135_E_Instruction "POP CS" is not valid for the curren
 % supported on the i386 or x86_64 targets.
 asmr_w_pop_cs_not_portable=07136_W_Instruction "POP CS" is not portable (it only works on 8086 and 8088 CPUs)
 % The 'pop cs' instruction doesn't work on any CPU, except 8086 and 8088.
+asmr_e_public_must_be_used_before_label_definition=07137_E_Label $1 can only be declared public before it's defined
+asmr_e_local_label_cannot_be_declared_public=07138_E_Local label $1 cannot be declared public
 #
 # Assembler/binary writers
 #

+ 4 - 2
compiler/msgidx.inc

@@ -818,6 +818,8 @@ const
   asmr_e_address_sizes_do_not_match=07134;
   asmr_e_pop_cs_not_valid=07135;
   asmr_w_pop_cs_not_portable=07136;
+  asmr_e_public_must_be_used_before_label_definition=07137;
+  asmr_e_local_label_cannot_be_declared_public=07138;
   asmw_f_too_many_asm_files=08000;
   asmw_f_assembler_output_not_supported=08001;
   asmw_f_comp_not_supported=08002;
@@ -1088,9 +1090,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 80799;
+  MsgTxtSize = 80913;
 
   MsgIdxMax : array[1..20] of longint=(
-    27,105,347,124,96,58,137,33,221,67,
+    27,105,347,124,96,58,139,33,221,67,
     60,20,30,1,1,1,1,1,1,1
   );

Разлика између датотеке није приказан због своје велике величине
+ 309 - 309
compiler/msgtxt.inc


+ 5 - 1
compiler/raatt.pas

@@ -1065,7 +1065,11 @@ unit raatt;
            AS_LABEL:
              Begin
                if SearchLabel(upper(actasmpattern),hl,true) then
-                ConcatLabel(curlist,hl)
+                 begin
+                   if hl.is_public then
+                     ConcatPublic(curlist,actasmpattern);
+                   ConcatLabel(curlist,hl);
+                 end
                else
                 Message1(asmr_e_unknown_label_identifier,actasmpattern);
                Consume(AS_LABEL);

+ 47 - 4
compiler/x86/rax86int.pas

@@ -40,7 +40,7 @@ Unit Rax86int;
       AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
       AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,
        {------------------ Assembler directives --------------------}
-      AS_ALIGN,AS_DB,AS_DW,AS_DD,AS_DQ,AS_END,
+      AS_ALIGN,AS_DB,AS_DW,AS_DD,AS_DQ,AS_PUBLIC,AS_END,
        {------------------ Assembler Operators  --------------------}
       AS_BYTE,AS_WORD,AS_DWORD,AS_QWORD,AS_TBYTE,AS_DQWORD,AS_OWORD,AS_XMMWORD,AS_YWORD,AS_YMMWORD,AS_NEAR,AS_FAR,
       AS_HIGH,AS_LOW,AS_OFFSET,AS_SIZEOF,AS_VMTOFFSET,AS_SEG,AS_TYPE,AS_PTR,AS_MOD,AS_SHL,AS_SHR,AS_NOT,
@@ -48,6 +48,7 @@ Unit Rax86int;
 
     type
        tx86intreader = class(tasmreader)
+         actasmpattern_origcase : string;
          actasmtoken : tasmtoken;
          prevasmtoken : tasmtoken;
          ActOpsize : topsize;
@@ -116,7 +117,7 @@ Unit Rax86int;
        _count_asmoperators  = longint(lastoperator)-longint(firstoperator);
 
        _asmdirectives : array[0.._count_asmdirectives] of tasmkeyword =
-       ('ALIGN','DB','DW','DD','DQ','END');
+       ('ALIGN','DB','DW','DD','DQ','PUBLIC','END');
 
        { problems with shl,shr,not,and,or and xor, they are }
        { context sensitive.                                 }
@@ -130,7 +131,7 @@ Unit Rax86int;
         ',',',',',',',',',','[',']','(',
         ')',':','.','+','-','*',
         ';','identifier','register','opcode','/',
-        '','','','','','END',
+        '','','','','','','END',
         '','','','','','','','','',
         '','','sizeof','vmtoffset','','type','ptr','mod','shl','shr','not',
         'and','or','xor','wrt','..gotpcrel'
@@ -284,6 +285,7 @@ Unit Rax86int;
               c:=current_scanner.asmgetchar;
             end;
            actasmpattern[0]:=chr(len);
+           actasmpattern_origcase:=actasmpattern;
            uppervar(actasmpattern);
            { allow spaces }
            while (c in [' ',#9]) do
@@ -331,6 +333,7 @@ Unit Rax86int;
                     actasmpattern:=actasmpattern + c;
                     c:=current_scanner.asmgetchar;
                   end;
+                 actasmpattern_origcase:=actasmpattern;
                  uppervar(actasmpattern);
                  actasmtoken:=AS_ID;
                  exit;
@@ -345,6 +348,7 @@ Unit Rax86int;
                     actasmpattern:=actasmpattern + c;
                     c:=current_scanner.asmgetchar;
                   end;
+                 actasmpattern_origcase:=actasmpattern;
                  uppervar(actasmpattern);
                  { after prefix (or segment override) we allow also a new opcode }
                  If (is_prefix(actopcode) or is_override(actopcode)) and is_asmopcode(actasmpattern) then
@@ -533,6 +537,7 @@ Unit Rax86int;
                     actasmpattern:=actasmpattern + c;
                     c:=current_scanner.asmgetchar;
                   end;
+                 actasmpattern_origcase:=actasmpattern;
                  uppervar(actasmpattern);
                  actasmtoken:=AS_ID;
                  exit;
@@ -656,6 +661,7 @@ Unit Rax86int;
                     c:=current_scanner.asmgetchar;
                   end;
                  { Get ending character }
+                 actasmpattern_origcase:=actasmpattern;
                  uppervar(actasmpattern);
                  c:=upcase(c);
                  { possibly a binary number. }
@@ -2495,6 +2501,8 @@ Unit Rax86int;
     Var
       hl : tasmlabel;
       instr : Tx86Instruction;
+      tmpsym: tsym;
+      tmpsrsymtable: TSymtable;
     Begin
       Message1(asmr_d_start_reading,'intel');
       inexpression:=FALSE;
@@ -2526,7 +2534,11 @@ Unit Rax86int;
           AS_LABEL:
             Begin
               if SearchLabel(upper(actasmpattern),hl,true) then
-               ConcatLabel(curlist,hl)
+                begin
+                  if hl.is_public then
+                    ConcatPublic(curlist,actasmpattern_origcase);
+                  ConcatLabel(curlist,hl);
+                end
               else
                Message1(asmr_e_unknown_label_identifier,actasmpattern);
               Consume(AS_LABEL);
@@ -2566,6 +2578,37 @@ Unit Rax86int;
             end;
 {$endif cpu64bitaddr}
 
+          AS_PUBLIC:
+            Begin
+              Consume(AS_PUBLIC);
+              repeat
+                if actasmtoken=AS_ID then
+                  begin
+                    if (actasmpattern<>'') and (actasmpattern[1]='@') then
+                      Message1(asmr_e_local_label_cannot_be_declared_public,actasmpattern)
+                    else if SearchLabel(upper(actasmpattern),hl,false) then
+                      begin
+                        if not hl.is_public then
+                          begin
+                            hl.is_public:=true;
+                            asmsearchsym(upper(actasmpattern),tmpsym,tmpsrsymtable);
+                            if tlabelsym(tmpsym).defined then
+                              Message1(asmr_e_public_must_be_used_before_label_definition,actasmpattern);
+                          end;
+                      end
+                    else
+                      Message1(asmr_e_unknown_label_identifier,actasmpattern);
+                  end;
+                Consume(AS_ID);
+                if actasmtoken=AS_COMMA then
+                  begin
+                    Consume(AS_COMMA);
+                    if actasmtoken<>AS_ID then
+                      Consume(AS_ID);
+                  end;
+              until actasmtoken=AS_SEPARATOR;
+            end;
+
           AS_ALIGN:
             Begin
               Consume(AS_ALIGN);

+ 32 - 0
tests/test/tasmpublic1.pp

@@ -0,0 +1,32 @@
+{ %CPU=i386,x86_64 }
+program tasmpublic1;
+
+{$goto on}
+{$asmmode intel}
+
+label
+  test_gLoBaL_label;
+
+var
+  codeseg_var: LongWord; external name 'test_gLoBaL_label';
+
+begin
+  asm
+    public test_gLoBaL_label
+    jmp @@skip
+    db 'some garbage here'
+test_gLoBaL_label:
+    nop
+    nop
+    nop
+    nop
+@@skip:
+  end;
+  if codeseg_var<>$90909090 then
+  begin
+    Writeln('Error!');
+    Halt(1);
+  end
+  else
+    Writeln('Ok!');
+end.

Неке датотеке нису приказане због велике количине промена