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 | //===----------------------------------------------------------------------===// |
| 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 Schimpf | 5ee234a | 2014-09-12 10:41:40 -0700 | [diff] [blame] | 18 | namespace llvm { |
| 19 | class Module; |
| 20 | } |
| 21 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 22 | namespace Ice { |
| 23 | |
| 24 | class ClFlags; |
| 25 | class Cfg; |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 26 | class VariableDeclaration; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 27 | class GlobalContext; |
| 28 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 29 | // 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 Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 32 | class Translator { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 33 | Translator() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 34 | Translator(const Translator &) = delete; |
| 35 | Translator &operator=(const Translator &) = delete; |
| 36 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 37 | public: |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 38 | explicit Translator(GlobalContext *Ctx); |
Jan Voung | 72984d8 | 2015-01-29 14:42:38 -0800 | [diff] [blame] | 39 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 40 | ~Translator(); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 41 | const ErrorCode &getErrorStatus() const { return ErrorStatus; } |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 42 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 43 | GlobalContext *getContext() const { return Ctx; } |
| 44 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 45 | const ClFlags &getFlags() const { return Ctx->getFlags(); } |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 46 | |
| 47 | /// Translates the constructed ICE function Fcn to machine code. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 48 | /// Takes ownership of Func. |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 49 | void translateFcn(std::unique_ptr<Cfg> Func); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 50 | |
| 51 | /// Emits the constant pool. |
| 52 | void emitConstants(); |
| 53 | |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 54 | /// If there was an error during bitcode reading/parsing, copy the |
| 55 | /// error code into the GlobalContext. |
| 56 | void transferErrorCode() const; |
| 57 | |
Karl Schimpf | 9d98d79 | 2014-10-13 15:01:08 -0700 | [diff] [blame] | 58 | /// Lowers the given list of global addresses to target. Generates |
| 59 | /// list of corresponding variable declarations. |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 60 | void |
| 61 | lowerGlobals(std::unique_ptr<VariableDeclarationList> VariableDeclarations); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 62 | |
| 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 Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 70 | const IceString &Prefix); |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 71 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 72 | uint32_t getNextSequenceNumber() { return NextSequenceNumber++; } |
| 73 | |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 74 | protected: |
| 75 | GlobalContext *Ctx; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 76 | uint32_t NextSequenceNumber; |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 77 | // ErrorCode of the translation. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 78 | ErrorCode ErrorStatus; |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 79 | }; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 80 | |
| 81 | } // end of namespace Ice |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 82 | |
| 83 | #endif // SUBZERO_SRC_ICETRANSLATOR_H |