Add dex_lang as common frontend to lir and LLVM. dex_lang + bc2lir =
Greenland

First commit of Greenland compiler: It's working in the sense of oat
tests. E.g., mm test-art-host-oat-Fibonacci. It shows the correct
bitcode before lir.

Change-Id: I91cbb02188325eb1fa605ed71ec7108fd2b0dbb9
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 9af92da..33c33af 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -22,7 +22,23 @@
 ART_USE_LLVM_COMPILER := false
 endif
 
-ifeq ($(ART_USE_LLVM_COMPILER),true)
+ifneq ($(wildcard art/USE_GREENLAND_COMPILER),)
+ART_USE_GREENLAND_COMPILER := true
+else
+ART_USE_GREENLAND_COMPILER := false
+endif
+
+ifeq ($(filter-out true,$(ART_USE_LLVM_COMPILER) $(ART_USE_GREENLAND_COMPILER)),)
+$(error Cannot enable art-greenland and art-llvm compiler simultaneously!)
+endif
+
+ifeq ($(filter true,$(ART_USE_LLVM_COMPILER) $(ART_USE_GREENLAND_COMPILER)),true)
+ART_REQUIRE_LLVM := true
+else
+ART_REQUIRE_LLVM := false
+endif
+
+ifeq ($(ART_REQUIRE_LLVM),true)
 LLVM_ROOT_PATH := external/llvm
 include $(LLVM_ROOT_PATH)/llvm.mk
 endif
@@ -209,6 +225,11 @@
 	src/compiler_llvm/runtime_support_llvm.cc
 endif
 
+ifeq ($(ART_USE_GREENLAND_COMPILER),true)
+LIBART_COMMON_SRC_FILES += \
+       src/greenland/inferred_reg_category_map.cc
+endif
+
 LIBART_COMMON_SRC_FILES += \
 	src/oat/runtime/context.cc \
 	src/oat/runtime/support_alloc.cc \
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 5f139ee..9305d4d 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -22,6 +22,10 @@
   ART_EXECUTABLES_CFLAGS += -DART_USE_LLVM_COMPILER=1
 endif
 
+ifeq ($(ART_USE_GREENLAND_COMPILER),true)
+  ART_EXECUTABLES_CFLAGS += -DART_USE_GREENLAND_COMPILER=1
+endif
+
 # $(1): executable ("d" will be appended for debug version)
 # $(2): source
 # $(3): target or host
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 3405e7e..63c4b60 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -24,6 +24,10 @@
   ART_TEST_CFLAGS += -DART_USE_LLVM_COMPILER=1
 endif
 
+ifeq ($(ART_USE_GREENLAND_COMPILER),true)
+  ART_TEST_CFLAGS += -DART_USE_GREENLAND_COMPILER=1
+endif
+
 # $(1): target or host
 # $(2): file name
 define build-art-test
diff --git a/build/Android.libart-compiler-greenland.mk b/build/Android.libart-compiler-greenland.mk
new file mode 100644
index 0000000..04eec5e
--- /dev/null
+++ b/build/Android.libart-compiler-greenland.mk
@@ -0,0 +1,179 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+LIBART_COMPILER_GREENLAND_CFLAGS := -DART_USE_GREENLAND_COMPILER=1
+
+LIBART_COMPILER_GREENLAND_SRC_FILES += \
+	src/greenland/dalvik_reg.cc \
+	src/greenland/dex_lang.cc \
+	src/greenland/greenland.cc \
+	src/greenland/lir.cc \
+	src/greenland/lir_function.cc \
+	src/greenland/inferred_reg_category_map.cc \
+	src/greenland/intrinsic_helper.cc \
+	src/greenland/ir_builder.cc \
+	src/greenland/target_codegen_machine.cc \
+	src/greenland/target_lir_emitter.cc \
+	src/greenland/target_registry.cc \
+	src/oat/jni/calling_convention.cc \
+	src/oat/jni/jni_compiler.cc \
+	src/oat/jni/arm/calling_convention_arm.cc \
+	src/oat/jni/x86/calling_convention_x86.cc
+
+LIBART_COMPILER_GREENLAND_ARM_SRC_FILES += \
+  src/greenland/arm/arm_codegen_machine.cc \
+	src/greenland/arm/arm_invoke_stub_compiler.cc
+
+LIBART_COMPILER_GREENLAND_MIPS_SRC_FILES += \
+  src/greenland/mips/mips_codegen_machine.cc \
+  src/greenland/mips/mips_invoke_stub_compiler.cc
+
+LIBART_COMPILER_GREENLAND_X86_SRC_FILES += \
+  src/greenland/x86/x86_codegen_machine.cc \
+  src/greenland/x86/x86_lir_emitter.cc \
+  src/greenland/x86/x86_lir_info.cc \
+  src/greenland/x86/x86_invoke_stub_compiler.cc
+
+# $(1): target or host
+# $(2): ndebug or debug
+define build-libart-compiler-greenland
+  ifneq ($(1),target)
+    ifneq ($(1),host)
+      $$(error expected target or host for argument 1, received $(1))
+    endif
+  endif
+  ifneq ($(2),ndebug)
+    ifneq ($(2),debug)
+      $$(error expected ndebug or debug for argument 2, received $(2))
+    endif
+  endif
+
+  art_target_or_host := $(1)
+  art_ndebug_or_debug := $(2)
+
+  include $(CLEAR_VARS)
+  ifeq ($$(art_target_or_host),target)
+    include external/stlport/libstlport.mk
+  endif
+  LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
+  ifeq ($$(art_ndebug_or_debug),ndebug)
+    LOCAL_MODULE := libart-compiler-greenland
+  else # debug
+    LOCAL_MODULE := libartd-compiler-greenland
+  endif
+
+  LOCAL_MODULE_TAGS := optional
+  LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+  LOCAL_SRC_FILES := $(LIBART_COMPILER_GREENLAND_SRC_FILES)
+  LOCAL_CFLAGS := $(LIBART_COMPILER_GREENLAND_CFLAGS)
+  ifeq ($$(art_target_or_host),target)
+    LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
+  else # host
+    LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
+  endif
+
+  LOCAL_C_INCLUDES += $(ART_C_INCLUDES)
+
+  ifeq ($$(art_target_or_host),target)
+    LOCAL_SRC_FILES += \
+      $(LIBART_COMPILER_GREENLAND_ARM_SRC_FILES)
+  else
+    LOCAL_SRC_FILES += \
+      $(LIBART_COMPILER_GREENLAND_ARM_SRC_FILES) \
+      $(LIBART_COMPILER_GREENLAND_MIPS_SRC_FILES) \
+      $(LIBART_COMPILER_GREENLAND_X86_SRC_FILES)
+  endif
+
+  LOCAL_STATIC_LIBRARIES += \
+    libLLVMBitWriter \
+    libLLVMBitReader \
+    libLLVMScalarOpts \
+    libLLVMInstCombine \
+    libLLVMTransformUtils \
+    libLLVMAnalysis \
+    libLLVMTarget \
+    libLLVMCore \
+    libLLVMSupport
+  LOCAL_SHARED_LIBRARIES := liblog libnativehelper
+  ifeq ($$(art_target_or_host),target)
+    LOCAL_SHARED_LIBRARIES += libcutils libstlport libz libdl
+    LOCAL_SHARED_LIBRARIES += libdynamic_annotations # tsan support
+#    LOCAL_SHARED_LIBRARIES += libcorkscrew # native stack trace support
+  else # host
+    LOCAL_STATIC_LIBRARIES += libcutils
+    LOCAL_SHARED_LIBRARIES += libz-host
+    LOCAL_SHARED_LIBRARIES += libdynamic_annotations-host # tsan support
+    LOCAL_LDLIBS := -ldl -lpthread
+    ifeq ($(HOST_OS),linux)
+      LOCAL_LDLIBS += -lrt
+    endif
+  endif
+  ifeq ($$(art_ndebug_or_debug),debug)
+    ifeq ($$(art_target_or_host),target)
+      LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
+    else # host
+      LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
+    endif
+    LOCAL_SHARED_LIBRARIES += libartd
+  else
+    ifeq ($$(art_target_or_host),target)
+      LOCAL_CFLAGS += $(ART_TARGET_NON_DEBUG_CFLAGS)
+    else # host
+      LOCAL_CFLAGS += $(ART_HOST_NON_DEBUG_CFLAGS)
+    endif
+    LOCAL_SHARED_LIBRARIES += libart
+  endif
+  ifeq ($$(art_target_or_host),target)
+    include $(LLVM_GEN_INTRINSICS_MK)
+    include $(LLVM_DEVICE_BUILD_MK)
+    include $(BUILD_SHARED_LIBRARY)
+  else # host
+    LOCAL_IS_HOST_MODULE := true
+    include $(LLVM_GEN_INTRINSICS_MK)
+    include $(LLVM_HOST_BUILD_MK)
+    include $(BUILD_HOST_SHARED_LIBRARY)
+  endif
+
+  ifeq ($$(art_target_or_host),target)
+    ifeq ($$(art_ndebug_or_debug),debug)
+      $(TARGET_OUT_EXECUTABLES)/dex2oatd: $$(LOCAL_INSTALLED_MODULE)
+    else
+      $(TARGET_OUT_EXECUTABLES)/dex2oat: $$(LOCAL_INSTALLED_MODULE)
+    endif
+  else # host
+    ifeq ($$(art_ndebug_or_debug),debug)
+      $(HOST_OUT_EXECUTABLES)/dex2oatd: $$(LOCAL_INSTALLED_MODULE)
+    else
+      $(HOST_OUT_EXECUTABLES)/dex2oat: $$(LOCAL_INSTALLED_MODULE)
+    endif
+  endif
+
+endef
+
+ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
+  $(eval $(call build-libart-compiler-greenland,target,ndebug))
+endif
+ifeq ($(ART_BUILD_TARGET_DEBUG),true)
+  $(eval $(call build-libart-compiler-greenland,target,debug))
+endif
+ifeq ($(ART_BUILD_HOST_NDEBUG),true)
+  $(eval $(call build-libart-compiler-greenland,host,ndebug))
+endif
+ifeq ($(ART_BUILD_HOST_DEBUG),true)
+  $(eval $(call build-libart-compiler-greenland,host,debug))
+endif
diff --git a/build/Android.libart.mk b/build/Android.libart.mk
index c7a85ef..2683f14 100644
--- a/build/Android.libart.mk
+++ b/build/Android.libart.mk
@@ -19,6 +19,10 @@
   LIBART_CFLAGS += -DART_USE_LLVM_COMPILER=1
 endif
 
+ifeq ($(ART_USE_GREENLAND_COMPILER),true)
+  LIBART_CFLAGS += -DART_USE_GREENLAND_COMPILER=1
+endif
+
 # $(1): target or host
 # $(2): ndebug or debug
 define build-libart
@@ -91,7 +95,10 @@
   LOCAL_C_INCLUDES += $(ART_C_INCLUDES)
   ifeq ($(ART_USE_LLVM_COMPILER),true)
     LOCAL_C_INCLUDES += frameworks/compile/linkloader
-    LOCAL_STATIC_LIBRARIES += librsloader libLLVMSupport
+    LOCAL_STATIC_LIBRARIES += librsloader
+  endif
+  ifeq ($(ART_REQUIRE_LLVM),true)
+    LOCAL_STATIC_LIBRARIES += libLLVMSupport
   endif
   LOCAL_SHARED_LIBRARIES := liblog libnativehelper
   ifeq ($$(art_target_or_host),target)
@@ -108,13 +115,13 @@
     endif
   endif
   ifeq ($$(art_target_or_host),target)
-    ifeq ($(ART_USE_LLVM_COMPILER),true)
+    ifeq ($(ART_REQUIRE_LLVM),true)
       include $(LLVM_GEN_INTRINSICS_MK)
       include $(LLVM_DEVICE_BUILD_MK)
     endif
     include $(BUILD_SHARED_LIBRARY)
   else # host
-    ifeq ($(ART_USE_LLVM_COMPILER),true)
+    ifeq ($(ART_REQUIRE_LLVM),true)
       include $(LLVM_GEN_INTRINSICS_MK)
       include $(LLVM_HOST_BUILD_MK)
     endif
diff --git a/build/Android.oattest.mk b/build/Android.oattest.mk
index 9a215e0..c9540e8 100644
--- a/build/Android.oattest.mk
+++ b/build/Android.oattest.mk
@@ -45,8 +45,9 @@
   include $(BUILD_HOST_JAVA_LIBRARY)
   ART_TEST_HOST_DEX_FILES += $$(LOCAL_MODULE_PATH)/$$(LOCAL_MODULE).jar
 endef
-$(foreach dir,$(TEST_DEX_DIRECTORIES), $(eval $(call build-art-test-dex,art-test-dex,$(dir),$(ART_NATIVETEST_OUT))))
-$(foreach dir,$(TEST_OAT_DIRECTORIES), $(eval $(call build-art-test-dex,oat-test-dex,$(dir),$(ART_TEST_OUT))))
+#$(foreach dir,$(TEST_DEX_DIRECTORIES), $(eval $(call build-art-test-dex,art-test-dex,$(dir),$(ART_NATIVETEST_OUT))))
+#$(foreach dir,$(TEST_OAT_DIRECTORIES), $(eval $(call build-art-test-dex,oat-test-dex,$(dir),$(ART_TEST_OUT))))
+$(foreach dir,HelloWorld, $(eval $(call build-art-test-dex,oat-test-dex,$(dir),$(ART_TEST_OUT))))
 
 ########################################################################