blob: adddc32c8d0b428bbd22d4824d9d0c49284d3c1c [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 Stichnothc6ead202015-02-24 09:30:30 -080033 Translator() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070034 Translator(const Translator &) = delete;
35 Translator &operator=(const Translator &) = delete;
36
Karl Schimpf8d7abae2014-07-07 14:50:30 -070037public:
Jim Stichnothc6ead202015-02-24 09:30:30 -080038 explicit Translator(GlobalContext *Ctx);
Jan Voung72984d82015-01-29 14:42:38 -080039
Karl Schimpf8d7abae2014-07-07 14:50:30 -070040 ~Translator();
Jim Stichnothfa4efea2015-01-27 05:06:03 -080041 const ErrorCode &getErrorStatus() const { return ErrorStatus; }
Karl Schimpf8d7abae2014-07-07 14:50:30 -070042
Karl Schimpfd6064a12014-08-27 15:34:58 -070043 GlobalContext *getContext() const { return Ctx; }
44
Jim Stichnothbbca7542015-02-11 16:08:31 -080045 const ClFlags &getFlags() const { return Ctx->getFlags(); }
Karl Schimpfd6064a12014-08-27 15:34:58 -070046
47 /// Translates the constructed ICE function Fcn to machine code.
Jim Stichnothfa4efea2015-01-27 05:06:03 -080048 /// Takes ownership of Func.
Jim Stichnoth8e928382015-02-02 17:03:08 -080049 void translateFcn(std::unique_ptr<Cfg> Func);
Karl Schimpfd6064a12014-08-27 15:34:58 -070050
51 /// Emits the constant pool.
52 void emitConstants();
53
Jim Stichnothfa4efea2015-01-27 05:06:03 -080054 /// If there was an error during bitcode reading/parsing, copy the
55 /// error code into the GlobalContext.
56 void transferErrorCode() const;
57
Karl Schimpf9d98d792014-10-13 15:01:08 -070058 /// Lowers the given list of global addresses to target. Generates
59 /// list of corresponding variable declarations.
Jim Stichnothbbca7542015-02-11 16:08:31 -080060 void
61 lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070062
63 /// Creates a name using the given prefix and corresponding index.
64 std::string createUnnamedName(const IceString &Prefix, SizeT Index);
65
66 /// Reports if there is a (potential) conflict between Name, and using
67 /// Prefix to name unnamed names. Errors are put on Ostream.
68 /// Returns true if there isn't a potential conflict.
69 bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind,
Jim Stichnothe4a8f402015-01-20 12:52:51 -080070 const IceString &Prefix);
Karl Schimpfe3f64d02014-10-07 10:38:22 -070071
Jim Stichnothbbca7542015-02-11 16:08:31 -080072 uint32_t getNextSequenceNumber() { return NextSequenceNumber++; }
73
Karl Schimpf8d7abae2014-07-07 14:50:30 -070074protected:
75 GlobalContext *Ctx;
Jim Stichnothbbca7542015-02-11 16:08:31 -080076 uint32_t NextSequenceNumber;
Jan Voung44c3a802015-03-27 16:29:08 -070077 // ErrorCode of the translation.
Jim Stichnothfa4efea2015-01-27 05:06:03 -080078 ErrorCode ErrorStatus;
Karl Schimpf8d7abae2014-07-07 14:50:30 -070079};
Jim Stichnoth7b451a92014-10-15 14:39:23 -070080
81} // end of namespace Ice
Karl Schimpf8d7abae2014-07-07 14:50:30 -070082
83#endif // SUBZERO_SRC_ICETRANSLATOR_H