Implement emission of all Win64 exception tables. Make the COFF streamer emit
[oota-llvm.git] / lib / MC / MCWin64EH.cpp
index 9884f66e5fb549c2e629609ec9265b27150b5d9d..fc394504bfb768530fab240a756705a807f36dfe 100644 (file)
@@ -110,7 +110,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
 }
 
 static void EmitRuntimeFunction(MCStreamer &streamer,
-                                MCWin64EHUnwindInfo *info) {
+                                const MCWin64EHUnwindInfo *info) {
   MCContext &context = streamer.getContext();
 
   streamer.EmitValue(MCSymbolRefExpr::Create(info->Begin, context), 4);
@@ -185,5 +185,20 @@ void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
   llvm::EmitUnwindInfo(streamer, info);
 }
 
+void MCWin64EHUnwindEmitter::Emit(MCStreamer &streamer) {
+  MCContext &context = streamer.getContext();
+  // Emit the unwind info structs first.
+  const TargetAsmInfo &asmInfo = context.getTargetAsmInfo();
+  const MCSection *xdataSect = asmInfo.getWin64EHTableSection();
+  streamer.SwitchSection(xdataSect);
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i)
+    llvm::EmitUnwindInfo(streamer, &streamer.getW64UnwindInfo(i));
+  // Now emit RUNTIME_FUNCTION entries.
+  const MCSection *pdataSect = asmInfo.getWin64EHFuncTableSection();
+  streamer.SwitchSection(pdataSect);
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i)
+    EmitRuntimeFunction(streamer, &streamer.getW64UnwindInfo(i));
+}
+
 } // End of namespace llvm