clean up the CBE output a bit
authorChris Lattner <sabre@nondot.org>
Fri, 6 May 2005 06:58:42 +0000 (06:58 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 6 May 2005 06:58:42 +0000 (06:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21740 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index be124b0501ef9a765e863d6300781eb1c58338c3..282d013047c1bf1b7d7692ec5ced318ed584cfcb 100644 (file)
@@ -215,7 +215,6 @@ namespace {
                             unsigned Indent);
     void printIndexingExpression(Value *Ptr, gep_type_iterator I,
                                  gep_type_iterator E);
-    void printCodeForMain();
   };
 }
 
@@ -815,8 +814,20 @@ static void generateCompilerSpecificCode(std::ostream& Out) {
       << "#define LLVM_NANSF(NanStr) 0.0F                    /* Float */\n"
       << "#define LLVM_INF           ((double)0.0)           /* Double */\n"
       << "#define LLVM_INFF          0.0F                    /* Float */\n"
-      << "#define LLVM_PREFETCH(addr,rw,locality)          \n"
-      << "#endif\n";
+      << "#define LLVM_PREFETCH(addr,rw,locality)            /* PREFETCH */\n"
+      << "#endif\n\n";
+
+  // Output target-specific code that should be inserted into main.
+  Out << "#define CODE_FOR_MAIN() /* Any target-specific code for main()*/\n";
+  // On X86, set the FP control word to 64-bits of precision instead of 80 bits.
+  Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
+      << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
+      << "#undef CODE_FOR_MAIN\n"
+      << "#define CODE_FOR_MAIN() \\\n"
+      << "  {short F;__asm__ (\"fnstcw %0\" : \"=m\" (*&F)); \\\n"
+      << "  F=(F&~0x300)|0x200;__asm__(\"fldcw %0\"::\"m\"(*&F));}\n"
+      << "#endif\n#endif\n";
+
 }
 
 bool CWriter::doInitialization(Module &M) {
@@ -1140,7 +1151,7 @@ void CWriter::printFunction(Function &F) {
   Out << '\n';
 
   if (F.hasExternalLinkage() && F.getName() == "main")
-    printCodeForMain();
+    Out << "  CODE_FOR_MAIN();\n";
 
   // print the basic blocks
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
@@ -1155,15 +1166,6 @@ void CWriter::printFunction(Function &F) {
   Out << "}\n\n";
 }
 
-void CWriter::printCodeForMain() {
-  // On X86, set the FP control word to 64-bits of precision instead of 80 bits.
-  Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
-      << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
-      << "{short FPCW;__asm__ (\"fnstcw %0\" : \"=m\" (*&FPCW));\n"
-      << "FPCW=(FPCW&~0x300)|0x200;__asm__(\"fldcw %0\" :: \"m\" (*&FPCW));}\n"
-      << "#endif\n#endif\n";
-}
-
 void CWriter::printLoop(Loop *L) {
   Out << "  do {     /* Syntactic loop '" << L->getHeader()->getName()
       << "' to make GCC happy */\n";
index be124b0501ef9a765e863d6300781eb1c58338c3..282d013047c1bf1b7d7692ec5ced318ed584cfcb 100644 (file)
@@ -215,7 +215,6 @@ namespace {
                             unsigned Indent);
     void printIndexingExpression(Value *Ptr, gep_type_iterator I,
                                  gep_type_iterator E);
-    void printCodeForMain();
   };
 }
 
@@ -815,8 +814,20 @@ static void generateCompilerSpecificCode(std::ostream& Out) {
       << "#define LLVM_NANSF(NanStr) 0.0F                    /* Float */\n"
       << "#define LLVM_INF           ((double)0.0)           /* Double */\n"
       << "#define LLVM_INFF          0.0F                    /* Float */\n"
-      << "#define LLVM_PREFETCH(addr,rw,locality)          \n"
-      << "#endif\n";
+      << "#define LLVM_PREFETCH(addr,rw,locality)            /* PREFETCH */\n"
+      << "#endif\n\n";
+
+  // Output target-specific code that should be inserted into main.
+  Out << "#define CODE_FOR_MAIN() /* Any target-specific code for main()*/\n";
+  // On X86, set the FP control word to 64-bits of precision instead of 80 bits.
+  Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
+      << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
+      << "#undef CODE_FOR_MAIN\n"
+      << "#define CODE_FOR_MAIN() \\\n"
+      << "  {short F;__asm__ (\"fnstcw %0\" : \"=m\" (*&F)); \\\n"
+      << "  F=(F&~0x300)|0x200;__asm__(\"fldcw %0\"::\"m\"(*&F));}\n"
+      << "#endif\n#endif\n";
+
 }
 
 bool CWriter::doInitialization(Module &M) {
@@ -1140,7 +1151,7 @@ void CWriter::printFunction(Function &F) {
   Out << '\n';
 
   if (F.hasExternalLinkage() && F.getName() == "main")
-    printCodeForMain();
+    Out << "  CODE_FOR_MAIN();\n";
 
   // print the basic blocks
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
@@ -1155,15 +1166,6 @@ void CWriter::printFunction(Function &F) {
   Out << "}\n\n";
 }
 
-void CWriter::printCodeForMain() {
-  // On X86, set the FP control word to 64-bits of precision instead of 80 bits.
-  Out << "#if defined(__GNUC__) && !defined(__llvm__)\n"
-      << "#if defined(i386) || defined(__i386__) || defined(__i386)\n"
-      << "{short FPCW;__asm__ (\"fnstcw %0\" : \"=m\" (*&FPCW));\n"
-      << "FPCW=(FPCW&~0x300)|0x200;__asm__(\"fldcw %0\" :: \"m\" (*&FPCW));}\n"
-      << "#endif\n#endif\n";
-}
-
 void CWriter::printLoop(Loop *L) {
   Out << "  do {     /* Syntactic loop '" << L->getHeader()->getName()
       << "' to make GCC happy */\n";