summaryrefslogtreecommitdiff
path: root/compiler/utils/dummyas.pp
blob: 922acc3091f615f3f0e38b2061114b31f0af946b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 2007 by Pierre Muller
    member of the Free Pascal development team.

    Dummy assembler program to be able to easily test
    all FPC targets even without cross tools.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

program dummyas;

var
  assembler_name : string;
  object_name : string;
  ofile : text;

function RemoveSuffix(const st : string) : string;
var
  i,last : longint;
begin
  last:=length(st);
  for i:=length(st) downto 1 do
    begin
      if st[i]='.' then
        begin
          last:=i-1;
          break;
        end;
    end;
  RemoveSuffix:=Copy(st,1,last);
end;

var
  i : longint;
  param : string;
  skipnext : boolean;
begin
  object_name:='';
  skipnext:=false;
  for i:=1 to ParamCount do
    begin
      param:=Paramstr(i);
      if skipnext or (length(Param)=0) then
        begin
          skipnext:=false;
          continue;
        end;
      if Param='-o' then
        begin
          skipnext:=true;
          object_name:=ParamStr(i+1);
        end
      else if (Param[1]='-') then
        begin
          { option Param not handled }
          { Shouldn't be a real problem }
        end
      else
        begin
          if assembler_name='' then
            assembler_name:=ParamStr(i)
          else
            begin
              Writeln(stderr,'two non option param found!');
              Writeln(stderr,'first non option param =',assembler_name);
              Writeln(stderr,'second non option param =',Param);
              Writeln(stderr,'Don''t know how to handle this!');
              halt(1);
            end;
        end;
    end;

  if assembler_name='' then
    begin
      Writeln(stderr,'Dummyas, no source file specified');
      halt(1);
    end;
  Assign(ofile,assembler_name);
{$push}{$I-}
  Reset(ofile);
  if IOResult<>0 then
    begin
      Writeln(stderr,'Dummyas, source file not found ',assembler_name);
      halt(1);
    end;
  Close(ofile);
  if object_name='' then
    object_name:=RemoveSuffix(assembler_name)+'.o';
  Assign(ofile,object_name);
  Rewrite(ofile);
  if IOResult<>0 then
    begin
      Writeln(stderr,'Dummyas, object file not writable ',object_name);
      halt(1);
    end;
  Writeln(ofile,'Dummy as called');
  for i:=0 to Paramcount do
    Write(ofile,ParamStr(i),' ');
  Writeln(ofile);
  Writeln(ofile,'assembler file=',assembler_name);
  Writeln(ofile,'object file=',object_name);
  Close(ofile);
{$pop}
end.