Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1449)

Unified Diff: src/IceFixups.cpp

Issue 828873002: Subzero: Start writing out some relocation sections (text) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: review fixes Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceFixups.h ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceFixups.cpp
diff --git a/src/IceFixups.cpp b/src/IceFixups.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..52bb0dd1c1de4fad4be4e5d588aaed33a8a667f1
--- /dev/null
+++ b/src/IceFixups.cpp
@@ -0,0 +1,52 @@
+//===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the AssemblerFixup class, a very basic
+// target-independent representation of a fixup or relocation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceFixups.h"
+#include "IceOperand.h"
+
+namespace Ice {
+
+RelocOffsetT AssemblerFixup::offset() const {
+ if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_))
+ return CR->getOffset();
+ return 0;
+}
+
+IceString AssemblerFixup::symbol(const GlobalContext *Ctx) const {
+ std::string Buffer;
+ llvm::raw_string_ostream Str(Buffer);
+ const Constant *C = value_;
+ if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(C)) {
+ if (CR->getSuppressMangling())
+ Str << CR->getName();
+ else
+ Str << Ctx->mangleName(CR->getName());
+ } else {
+ // NOTE: currently only float/doubles are put into constant pools.
+ // In the future we may put integers as well.
+ assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C));
+ C->emitPoolLabel(Str);
+ }
+ return Str.str();
+}
+
+void AssemblerFixup::emit(GlobalContext *Ctx) const {
+ Ostream &Str = Ctx->getStrEmit();
+ Str << symbol(Ctx);
+ RelocOffsetT Offset = offset();
+ if (Offset)
+ Str << " + " << Offset;
+}
+
+} // end of namespace Ice
« no previous file with comments | « src/IceFixups.h ('k') | src/IceGlobalContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698