dummyas.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 (Param[1]='-') then
  79. begin
  80. { option Param not handled }
  81. { Shouldn't be a real problem }
  82. end
  83. else
  84. begin
  85. if assembler_name='' then
  86. assembler_name:=ParamStr(i)
  87. else
  88. begin
  89. Writeln(stderr,'two non option param found!');
  90. Writeln(stderr,'first non option param =',assembler_name);
  91. Writeln(stderr,'second non option param =',Param);
  92. Writeln(stderr,'Don''t know how to handle this!');
  93. write(stderr,'full command-line was:');
  94. for j:=1 to ParamCount do
  95. Write(' ',paramstr(j));
  96. Writeln;
  97. halt(1);
  98. end;
  99. end;
  100. end;
  101. if assembler_name='' then
  102. begin
  103. Writeln(stderr,'Dummyas, no source file specified');
  104. halt(1);
  105. end;
  106. Assign(ofile,assembler_name);
  107. {$push}{$I-}
  108. Reset(ofile);
  109. if IOResult<>0 then
  110. begin
  111. Writeln(stderr,'Dummyas, source file not found ',assembler_name);
  112. halt(1);
  113. end;
  114. Close(ofile);
  115. if object_name='' then
  116. object_name:=RemoveSuffix(assembler_name)+'.o';
  117. Assign(ofile,object_name);
  118. Rewrite(ofile);
  119. if IOResult<>0 then
  120. begin
  121. Writeln(stderr,'Dummyas, object file not writable ',object_name);
  122. halt(1);
  123. end;
  124. Writeln(ofile,'Dummy as called');
  125. for i:=0 to Paramcount do
  126. Write(ofile,ParamStr(i),' ');
  127. Writeln(ofile);
  128. Writeln(ofile,'assembler file=',assembler_name);
  129. Writeln(ofile,'object file=',object_name);
  130. Close(ofile);
  131. {$pop}
  132. end.