1(* 	$Id: TranslateToX86.Mod,v 1.2 2004/06/03 22:26:32 mva Exp $	 *)
2MODULE OOC:Make:TranslateToX86;
3(*  Translates a module file into an x86 assembler file.
4    Copyright (C) 2004  Michael van Acken
5
6    This file is part of OOC.
7
8    OOC is free software; you can redistribute it and/or modify it
9    under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    OOC is distributed in the hope that it will be useful, but WITHOUT
14    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16    License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with OOC. If not, write to the Free Software Foundation, 59
20    Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*)
22
23
24IMPORT
25  IO, IO:StdChannels,
26  OOC:Config:Pragmas, OOC:Auxiliary:ParseModule,
27  OOC:Auxiliary:WriteSymbolFile, OOC:Error, Rep := OOC:Repository, OOC:AST,
28  OOC:AST:CreateIR, ASTtoXML := OOC:AST:XML,
29  OOC:IR, IRtoXML := OOC:IR:XML, OOC:IR:ConstFold, OOC:IR:CheckUses,
30  Sym := OOC:SymbolTable, OOC:SymbolTable:Exports, OOC:SymbolTable:Uses,
31  OOC:X86:Translate;
32
33PROCEDURE Run*(m: Rep.Module; libraryName: STRING;
34               analysisOnly: BOOLEAN; uses: Uses.Uses;
35               writeAST: BOOLEAN; writeIR: BOOLEAN): Error.List
36RAISES IO.Error;
37(**Compiles a module, creating the symbol file and all relevant C files.  *)
38  VAR
39    ast: AST.Node;
40    symTab: Sym.Module;
41    errList: Error.List;
42    exports: Sym.Exports;
43    module: IR.Module;
44    pragmaHistory: Pragmas.History;
45    ch: IO.ByteChannel;
46  BEGIN
47    ParseModule.ParseModule (m, TRUE, TRUE, FALSE, FALSE, libraryName, uses,
48                             ast, symTab, pragmaHistory, errList);
49    (* note: don't let `ParseModule' write the symbol file; this reduces the
50       data in `symTab' to the view of client modules: declarations private to
51       the module are stripped when writing the symbol file  *)
52
53    IF errList.NoErrors() THEN
54      IF writeAST THEN
55        ASTtoXML.Write (StdChannels.stdout, ast(AST.Module));
56      END;
57      module := CreateIR.CreateIR (ast(AST.Module), symTab,
58                                   IR.NewBuilder (symTab, uses, pragmaHistory,
59                                                  errList,
60                                                  ConstFold.NewConstFold()));
61      IF errList.NoErrors() THEN
62        CheckUses.CheckUses(module, symTab, pragmaHistory, errList);
63      END;
64
65      IF writeIR THEN
66        IRtoXML.Write (StdChannels.stdout, module);
67      END;
68
69      exports := Exports.GetExports (symTab, TRUE);
70
71      IF errList.NoErrors() & ~analysisOnly THEN
72        (* only attempt to produce output if program compiled without errors *)
73        ch := m.GetOutputChannel(Rep.modAssemblerFile, TRUE);
74        Translate.Translate(m, symTab, module, ch);
75
76        IF errList.NoErrors() THEN
77          WriteSymbolFile.WriteSymbolFile (m, symTab, errList);
78        END;
79
80        ch.CloseAndRegister();
81      END;
82      module.Destroy;                    (* cleanup for the sake of the gc *)
83    END;
84
85    RETURN errList;
86  END Run;
87
88END OOC:Make:TranslateToX86.
89