blob: bc9a933dd22b7063bd19a9698d2fa5368e01d8e0 [file] [log] [blame]
Karl Schimpf8d7abae2014-07-07 14:50:30 -07001//===- subzero/src/IceTranslator.h - ICE to machine code --------*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the general driver class for translating ICE to
11// machine code.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef SUBZERO_SRC_ICETRANSLATOR_H
16#define SUBZERO_SRC_ICETRANSLATOR_H
17
Karl Schimpf5ee234a2014-09-12 10:41:40 -070018namespace llvm {
19class Module;
20}
21
Karl Schimpf8d7abae2014-07-07 14:50:30 -070022namespace Ice {
23
24class ClFlags;
25class Cfg;
Karl Schimpf9d98d792014-10-13 15:01:08 -070026class VariableDeclaration;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070027class GlobalContext;
28
Karl Schimpf9d98d792014-10-13 15:01:08 -070029// Base class for translating ICE to machine code. Derived classes convert
30// other intermediate representations down to ICE, and then call the appropriate
31// (inherited) methods to convert ICE into machine instructions.
Karl Schimpf8d7abae2014-07-07 14:50:30 -070032class Translator {
Jim Stichnoth7b451a92014-10-15 14:39:23 -070033 Translator(const Translator &) = delete;
34 Translator &operator=(const Translator &) = delete;
35
Karl Schimpf8d7abae2014-07-07 14:50:30 -070036public:
Jim Stichnothbbca7542015-02-11 16:08:31 -080037 Translator(GlobalContext *Ctx);
Jan Voung72984d82015-01-29 14:42:38 -080038
Karl Schimpf8d7abae2014-07-07 14:50:30 -070039 ~Translator();
Jim Stichnothfa4efea2015-01-27 05:06:03 -080040 const ErrorCode &getErrorStatus() const { return ErrorStatus; }
Karl Schimpf8d7abae2014-07-07 14:50:30 -070041
Karl Schimpfd6064a12014-08-27 15:34:58 -070042 GlobalContext *getContext() const { return Ctx; }
43
Jim Stichnothbbca7542015-02-11 16:08:31 -080044 const ClFlags &getFlags() const { return Ctx->getFlags(); }
Karl Schimpfd6064a12014-08-27 15:34:58 -070045
46 /// Translates the constructed ICE function Fcn to machine code.
Jim Stichnothfa4efea2015-01-27 05:06:03 -080047 /// Takes ownership of Func.
Jim Stichnoth8e928382015-02-02 17:03:08 -080048 void translateFcn(std::unique_ptr<Cfg> Func);
Karl Schimpfd6064a12014-08-27 15:34:58 -070049
50 /// Emits the constant pool.
51 void emitConstants();
52
Jim Stichnothfa4efea2015-01-27 05:06:03 -080053 /// If there was an error during bitcode reading/parsing, copy the
54 /// error code into the GlobalContext.
55 void transferErrorCode() const;
56
Karl Schimpf9d98d792014-10-13 15:01:08 -070057 /// Lowers the given list of global addresses to target. Generates
58 /// list of corresponding variable declarations.
Jim Stichnothbbca7542015-02-11 16:08:31 -080059 void
60 lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070061
62 /// Creates a name using the given prefix and corresponding index.
63 std::string createUnnamedName(const IceString &Prefix, SizeT Index);
64
65 /// Reports if there is a (potential) conflict between Name, and using
66 /// Prefix to name unnamed names. Errors are put on Ostream.
67 /// Returns true if there isn't a potential conflict.
68 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
Jim Stichnothe4a8f402015-01-20 12:52:51 -080069 const IceString &Prefix);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070070
Jim Stichnothbbca7542015-02-11 16:08:31 -080071 uint32_t getNextSequenceNumber() { return NextSequenceNumber++; }
72
Karl Schimpf8d7abae2014-07-07 14:50:30 -070073protected:
74 GlobalContext *Ctx;
Jim Stichnothbbca7542015-02-11 16:08:31 -080075 uint32_t NextSequenceNumber;
Jim Stichnothfa4efea2015-01-27 05:06:03 -080076 // Exit status of the translation. False is successful. True otherwise.
77 ErrorCode ErrorStatus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070078};
Jim Stichnoth7b451a92014-10-15 14:39:23 -070079
80} // end of namespace Ice
Karl Schimpf8d7abae2014-07-07 14:50:30 -070081
82#endif // SUBZERO_SRC_ICETRANSLATOR_H