2
0

dummyas.pp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2007 by Pierre Muller
  4. member of the Free Pascal development team.
  5. Dummy assembler program to be able to easily test
  6. all FPC targets even without cross tools.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. program dummyas;
  14. var
  15. assembler_name : string;
  16. object_name : string;
  17. ofile : text;
  18. function RemoveSuffix(const st : string) : string;
  19. var
  20. i,last : longint;
  21. begin
  22. last:=length(st);
  23. for i:=length(st) downto 1 do
  24. begin
  25. if st[i]='.' then
  26. begin
  27. last:=i-1;
  28. break;
  29. end;
  30. end;
  31. RemoveSuffix:=Copy(st,1,last);
  32. end;
  33. var
  34. i,j : longint;
  35. param : string;
  36. skipnext : boolean;
  37. begin
  38. object_name:='';
  39. skipnext:=false;
  40. for i:=1 to ParamCount do
  41. begin
  42. param:=Paramstr(i);
  43. if skipnext or (length(Param)=0) then
  44. begin
  45. skipnext:=false;
  46. continue;
  47. end;
  48. if Param='-o' then
  49. begin
  50. skipnext:=true;
  51. object_name:=ParamStr(i+1);
  52. end
  53. else if (param='-x') then
  54. begin
  55. // darwin -x assembler for clang
  56. skipnext:=true
  57. end
  58. else if (param='-target') then
  59. begin
  60. // darwin -target x86_64-apple-macosx10.8.0 for clang
  61. skipnext:=true
  62. end
  63. else if (param='--32') then
  64. begin
  65. // Android
  66. // Ignore
  67. end
  68. else if (param='--defsym') then
  69. begin
  70. // Android
  71. skipnext:=true;
  72. end
  73. else if (Param='-f') then
  74. begin
  75. // ignore format in nasm
  76. skipnext:=true;
  77. end
  78. else if copy(param,1,4)='-fo=' then
  79. begin
  80. // Watcom
  81. object_name:=copy(param,5);
  82. end
  83. else if (Param[1]='-') then
  84. begin
  85. { option Param not handled }
  86. { Shouldn't be a real problem }
  87. end
  88. else
  89. begin
  90. if assembler_name='' then
  91. assembler_name:=ParamStr(i)
  92. else
  93. begin
  94. Writeln(stderr,'two non option param found!');
  95. Writeln(stderr,'first non option param =',assembler_name);
  96. Writeln(stderr,'second non option param =',Param);
  97. Writeln(stderr,'Don''t know how to handle this!');
  98. write(stderr,'full command-line was:');
  99. for j:=1 to ParamCount do
  100. Write(' ',paramstr(j));
  101. Writeln;
  102. halt(1);
  103. end;
  104. end;
  105. end;
  106. if assembler_name='' then
  107. begin
  108. Writeln(stderr,'Dummyas, no source file specified');
  109. halt(1);
  110. end;
  111. Assign(ofile,assembler_name);
  112. {$push}{$I-}
  113. Reset(ofile);
  114. if IOResult<>0 then
  115. begin
  116. Writeln(stderr,'Dummyas, source file not found ',assembler_name);
  117. halt(1);
  118. end;
  119. Close(ofile);
  120. if object_name='' then
  121. object_name:=RemoveSuffix(assembler_name)+'.o';
  122. Assign(ofile,object_name);
  123. Rewrite(ofile);
  124. if IOResult<>0 then
  125. begin
  126. Writeln(stderr,'Dummyas, object file not writable ',object_name);
  127. halt(1);
  128. end;
  129. Writeln(ofile,'Dummy as called');
  130. for i:=0 to Paramcount do
  131. Write(ofile,ParamStr(i),' ');
  132. Writeln(ofile);
  133. Writeln(ofile,'assembler file=',assembler_name);
  134. Writeln(ofile,'object file=',object_name);
  135. Close(ofile);
  136. {$pop}
  137. end.