Adding a target type

Hi all,

I've been away for a while fixing LLVM backend bugs in AVR, which was quite difficult. :slight_smile:

I'm back now and attempting to pick up where I left off. I have slightly sleepy memory these days so I'm trying to remember how to get back to where I was!

I had this patch (see the end of the post), which was for me to add the experimental avr llvm back end as a target architecture to the front end.

Can anyone tell me a) if anything major is missing from the patch, I thought it was working before and b) what command line to use with utils/build-script?

This is what I was using but it wasn't working.

utils/build-script --reconfigure -c -R --debug-llvm --debug-swift --extra-cmake-options="-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR" --build-swift-static-stdlib TRUE

A swift compiler is built but when run with swiftc -target avr-atmel-linux-gnueabihf it says <unknown>:0: error: unsupported target architecture: 'avr'

The patch:

diff --git a/.gitignore b/.gitignore
index 05e03732a5..25394c79d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+worktree
+
 #==============================================================================#
 # This file specifies intentionally untracked files that git should ignore.
 # See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e1cfb1f35..814e483981 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -86,7 +86,7 @@ option(SWIFT_INCLUDE_TESTS "Create targets for building/running tests." TRUE)
 
 option(SWIFT_INCLUDE_DOCS
     "Create targets for building docs."
-    TRUE)
+    FALSE)
 
 #
 # Miscellaneous User-configurable options.
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index 75fc706702..f1e147535c 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -1,10 +1,10 @@
 add_subdirectory(tools)
 
-find_program(SPHINX_EXECUTABLE
-  NAMES sphinx-build
-  HINTS $ENV{SPHINX_DIR}
-  PATH_SUFFIXES bin
-  DOC "Sphinx documentation generator")
+#find_program(SPHINX_EXECUTABLE
+#  NAMES sphinx-build
+#  HINTS $ENV{SPHINX_DIR}
+#  PATH_SUFFIXES bin
+#  DOC "Sphinx documentation generator")
 
 SET(SWIFT_SPHINX_PAPER_SIZE "letter"
   CACHE STRING "Paper size for generated documentation")

 
diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp
index 146bee5e5b..6491413b8f 100644
--- a/lib/Basic/LangOptions.cpp
+++ b/lib/Basic/LangOptions.cpp
@@ -48,7 +48,8 @@ static const StringRef SupportedConditionalCompilationArches[] = {
   "x86_64",
   "powerpc64",
   "powerpc64le",
-  "s390x"
+  "s390x",
+  "avr"
 };
 
 static const StringRef SupportedConditionalCompilationEndianness[] = {
@@ -221,7 +222,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
   case llvm::Triple::ArchType::systemz:
     addPlatformConditionValue(PlatformConditionKind::Arch, "s390x");
     break;
-  default:
+  case llvm::Triple::ArchType::avr:
+    addPlatformConditionValue(PlatformConditionKind::Arch, "avr");
+    break;  default:
     UnsupportedArch = true;
   }
 
@@ -252,6 +255,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
   case llvm::Triple::ArchType::systemz:
     addPlatformConditionValue(PlatformConditionKind::Endianness, "big");
     break;
+  case llvm::Triple::ArchType::avr:
+    addPlatformConditionValue(PlatformConditionKind::Endianness, "little");
+    break;
   default:
     llvm_unreachable("undefined architecture endianness");
   }

diff --git a/utils/swift_build_support/swift_build_support/targets.py b/utils/swift_build_support/swift_build_support/targets.py
index f4b5bb0d48..7fa4ef422a 100644
--- a/utils/swift_build_support/swift_build_support/targets.py
+++ b/utils/swift_build_support/swift_build_support/targets.py
@@ -118,7 +118,8 @@ class StdlibDeploymentTarget(object):
         "aarch64",
         "powerpc64",
         "powerpc64le",
-        "s390x"])
+        "s390x",
+        "avr"])
 
     FreeBSD = Platform("freebsd", archs=["x86_64"])
 
@@ -174,6 +175,8 @@ class StdlibDeploymentTarget(object):
                 return StdlibDeploymentTarget.Linux.powerpc64le
             elif machine == 's390x':
                 return StdlibDeploymentTarget.Linux.s390x
+            elif machine == 'avr':
+                return StdlibDeploymentTarget.Linux.avr
 
         elif system == 'Darwin':
             if machine == 'x86_64':

Thanks for any advice/help you can offer!

Carl