From 55c80e763bfd850682b3217fcfc5cdb516eafae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?=
 <respindola@mozilla.com>
Date: Tue, 8 Mar 2011 15:32:42 -0500
Subject: [PATCH] Move the glue asm code to a .o file. This reduces how much
 asm we print in each "translation unit".

---
 src/Makefile             | 23 +++++++++++++++++++----
 src/comp/glue.rc         | 37 +++++++++++++++++++++++++++++++++++++
 src/comp/glue/glue.rs    | 11 +++++++++++
 src/comp/middle/trans.rs |  2 --
 4 files changed, 67 insertions(+), 6 deletions(-)
 create mode 100644 src/comp/glue.rc
 create mode 100644 src/comp/glue/glue.rs

diff --git a/src/Makefile b/src/Makefile
index a239329f4e5..cafd8d18c76 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -90,6 +90,7 @@ ifdef CFG_WINDOWSY
   CFG_EXE_SUFFIX := .exe
   CFG_BOOT := ./rustboot.exe
   CFG_RUSTC := ./rustc.exe
+  CFG_GLUE := ./glue.exe
   CFG_GCC_CFLAGS += -march=i686
   CFG_GCC_LINK_FLAGS += -shared -fPIC
   CFG_RUN_TARG = $(1)
@@ -101,6 +102,7 @@ ifdef CFG_UNIXY
   CFG_INFO := $(info cfg: unix-y environment)
   CFG_BOOT := ./rustboot
   CFG_RUSTC := ./rustc
+  CFG_GLUE := ./glue
   CFG_OBJ_SUFFIX := .o
   CFG_RUN_TARG = LD_LIBRARY_PATH=. $(CFG_VALGRIND) $(1)
   CFG_GCC := 1
@@ -111,6 +113,7 @@ ifdef CFG_UNIXY
     CFG_RUNTIME := rustrt.dll
     CFG_STDLIB := std.dll
     CFG_RUSTC := ./rustc.exe
+    CFG_GLUE := ./glue
     ifdef CFG_VALGRIND
       CFG_VALGRIND += wine
     endif
@@ -308,11 +311,13 @@ RUNTIME_LIBS := $(CFG_RUNTIME_LIBS)
 STDLIB_CRATE := lib/std.rc
 STDLIB_INPUTS := $(wildcard lib/*.rc lib/*.rs lib/*/*.rs)
 COMPILER_CRATE := comp/rustc.rc
-COMPILER_INPUTS := $(wildcard comp/*.rc comp/*.rs comp/*/*.rs)
+COMPILER_INPUTS := $(wildcard comp/rustc.rc comp/*.rs comp/*/*.rs)
+GLUE_CRATE := comp/glue.rc
+GLUE_INPUTS := $(wildcard comp/glue.rc comp/*.rs comp/*/*.rs)
 
 GENERATED := boot/fe/lexer.ml boot/util/version.ml
 
-all: $(CFG_RUSTC) $(MKFILES) $(GENERATED)
+all: $(CFG_RUSTC) $(CFG_GLUE) $(MKFILES) $(GENERATED) glue.o
 
 boot/util/version.ml: Makefile
 	$(CFG_QUIET)git log -1 \
@@ -368,6 +373,16 @@ $(CFG_RUSTC): $(COMPILER_INPUTS) $(CFG_BOOT) $(CFG_RUNTIME) $(CFG_STDLIB)
 	$(BOOT) -minimal -o $@ $<
 	$(CFG_QUIET)chmod 0755 $@
 
+$(CFG_GLUE): $(GLUE_INPUTS) $(CFG_BOOT) $(CFG_RUNTIME) $(CFG_STDLIB)
+	@$(call CFG_ECHO, compile: $<)
+	$(BOOT) -minimal -o $@ $<
+	$(CFG_QUIET)chmod 0755 $@
+
+glue.o: glue.s
+
+glue.s: $(CFG_GLUE)
+	$(CFG_GLUE) > $@
+
 self: $(CFG_RUSTC)
 	@$(call CFG_ECHO, compile: $<)
 	$(RUSTC) $(COMPILER_CRATE)
@@ -763,9 +778,9 @@ test/bench/shootout/%.boot$(CFG_EXE_SUFFIX): \
 	@$(call CFG_ECHO, assemble [llvm]: $<)
 	$(CFG_QUIET)gcc $(CFG_GCC_CFLAGS) -o $@ -c $<
 
-%.rustc$(CFG_EXE_SUFFIX): %.o $(CFG_RUNTIME)
+%.rustc$(CFG_EXE_SUFFIX): %.o $(CFG_RUNTIME) glue.o
 	@$(call CFG_ECHO, link [llvm]: $<)
-	$(CFG_QUIET)gcc $(CFG_GCC_CFLAGS) -o $@ $< -L. -lrustrt
+	$(CFG_QUIET)gcc $(CFG_GCC_CFLAGS) glue.o -o $@ $< -L. -lrustrt
 	@# dsymutil sometimes fails or prints a warning, but the
 	@# program still runs.  Since it simplifies debugging other
 	@# programs, I\'ll live with the noise.
diff --git a/src/comp/glue.rc b/src/comp/glue.rc
new file mode 100644
index 00000000000..1048341ab46
--- /dev/null
+++ b/src/comp/glue.rc
@@ -0,0 +1,37 @@
+// -*- rust -*-
+
+use std;
+
+mod front {
+    mod ast;
+}
+
+mod middle {
+  mod ty;
+}
+
+mod driver {
+  mod session;
+}
+
+mod glue {
+  mod glue;
+}
+
+mod back {
+    mod abi;
+    mod x86;
+}
+
+mod util {
+    mod common;
+}
+
+
+// Local Variables:
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
diff --git a/src/comp/glue/glue.rs b/src/comp/glue/glue.rs
new file mode 100644
index 00000000000..96bdba76a42
--- /dev/null
+++ b/src/comp/glue/glue.rs
@@ -0,0 +1,11 @@
+import back.x86;
+import std._str;
+import std._vec;
+import std.os.libc;
+
+fn main(vec[str] args) {
+  auto module_asm = x86.get_module_asm() + "\n";
+  auto bytes = _str.bytes(module_asm);
+  auto b = _vec.buf[u8](bytes);
+  libc.write(1, b, _vec.len[u8](bytes));
+}
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 7457a5326bd..e4512a47ecc 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -5708,8 +5708,6 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
     let ValueRef crate_ptr =
         llvm.LLVMAddGlobal(llmod, T_crate(tn), _str.buf("rust_crate"));
 
-    llvm.LLVMSetModuleInlineAsm(llmod, _str.buf(x86.get_module_asm()));
-
     auto intrinsics = declare_intrinsics(llmod);
 
     auto glues = make_glues(llmod, tn);