Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 1 | //===- 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// This file declares the general driver class for translating ICE to |
| 12 | /// machine code. |
| 13 | /// |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETRANSLATOR_H |
| 17 | #define SUBZERO_SRC_ICETRANSLATOR_H |
| 18 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 19 | #include "IceDefs.h" |
| 20 | #include "IceGlobalContext.h" |
| 21 | |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 22 | namespace llvm { |
| 23 | class Module; |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 24 | } // end of namespace llvm |
Karl Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 25 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 26 | namespace Ice { |
| 27 | |
| 28 | class ClFlags; |
| 29 | class Cfg; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 30 | class VariableDeclaration; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 31 | class GlobalContext; |
| 32 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 33 | /// Base class for translating ICE to machine code. Derived classes convert |
| 34 | /// other intermediate representations down to ICE, and then call the |
| 35 | /// appropriate (inherited) methods to convert ICE into machine instructions. |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 36 | class Translator { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 37 | Translator() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 38 | Translator(const Translator &) = delete; |
| 39 | Translator &operator=(const Translator &) = delete; |
| 40 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 41 | public: |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 42 | explicit Translator(GlobalContext *Ctx); |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 43 | |
Jim Stichnoth | f4fbf7f | 2015-08-08 08:37:02 -0700 | [diff] [blame] | 44 | virtual ~Translator() = default; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 45 | const ErrorCode &getErrorStatus() const { return ErrorStatus; } |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 46 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 47 | GlobalContext *getContext() const { return Ctx; } |
| 48 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 49 | const ClFlags &getFlags() const { return Ctx->getFlags(); } |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 50 | |
| 51 | /// Translates the constructed ICE function Fcn to machine code. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 52 | /// Takes ownership of Func. |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 53 | void translateFcn(std::unique_ptr<Cfg> Func); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 54 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 55 | /// Lowers the given list of global addresses to target. Generates |
| 56 | /// list of corresponding variable declarations. |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 57 | void |
| 58 | lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 59 | |
| 60 | /// Creates a name using the given prefix and corresponding index. |
| 61 | std::string createUnnamedName(const IceString &Prefix, SizeT Index); |
| 62 | |
| 63 | /// Reports if there is a (potential) conflict between Name, and using |
| 64 | /// Prefix to name unnamed names. Errors are put on Ostream. |
| 65 | /// Returns true if there isn't a potential conflict. |
| 66 | bool checkIfUnnamedNameSafe(const IceString &Name, const char *Kind, |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 67 | const IceString &Prefix); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 68 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 69 | uint32_t getNextSequenceNumber() { return NextSequenceNumber++; } |
| 70 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 71 | protected: |
| 72 | GlobalContext *Ctx; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 73 | uint32_t NextSequenceNumber; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 74 | /// ErrorCode of the translation. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 75 | ErrorCode ErrorStatus; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 76 | }; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 77 | |
| 78 | } // end of namespace Ice |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 79 | |
| 80 | #endif // SUBZERO_SRC_ICETRANSLATOR_H |