diff --git a/flang/test/Driver/asm-code-gen-x86.s b/flang/test/Driver/asm-code-gen-x86.s new file mode 100644 --- /dev/null +++ b/flang/test/Driver/asm-code-gen-x86.s @@ -0,0 +1,12 @@ +// Test -emit-obj (X86) + +// RUN: %flang -c %s -o - \ +// RUN: | llvm-objdump -d - | FileCheck %s +// RUN: %flang_cc1as -triple x86_64-pc-linux-gnu -filetype obj %s -o - \ +// RUN: | llvm-objdump -d - | FileCheck %s + +// CHECK: retq + +.globl main +main: + ret diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -28,7 +28,7 @@ config.suffixes = ['.c', '.cpp', '.f', '.F', '.ff', '.FOR', '.for', '.f77', '.f90', '.F90', '.ff90', '.f95', '.F95', '.ff95', '.fpp', '.FPP', '.cuf' '.CUF', '.f18', '.F18', '.f03', '.F03', '.f08', '.F08', - '.ll', '.fir', '.mlir'] + '.ll', '.fir', '.mlir', '.s', '.S'] config.substitutions.append(('%PATH%', config.environment['PATH'])) config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir)) @@ -90,9 +90,11 @@ # For each occurrence of a flang tool name, replace it with the full path to # the build directory holding that tool. tools = [ - ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'), + ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'), ToolSubst('%flang_fc1', command=FindTool('flang-new'), extra_args=['-fc1'], - unresolved='fatal')] + unresolved='fatal'), + ToolSubst('%flang_cc1as', command=FindTool('flang-new'), extra_args=['-cc1as'], + unresolved='fatal')] # Flang has several unimplemented features. TODO messages are used to mark and fail if these # features are exercised. TODOs exit with an error in non-assert builds but in assert builds diff --git a/flang/tools/flang-driver/CMakeLists.txt b/flang/tools/flang-driver/CMakeLists.txt --- a/flang/tools/flang-driver/CMakeLists.txt +++ b/flang/tools/flang-driver/CMakeLists.txt @@ -14,6 +14,7 @@ add_flang_tool(flang-new driver.cpp fc1_main.cpp + ../../../clang/tools/driver/cc1as_main.cpp DEPENDS # These libraries are used in the linker invocation generated by the driver @@ -32,8 +33,7 @@ clang_target_link_libraries(flang-new PRIVATE - clangDriver - clangBasic + clangFrontend ) option(FLANG_PLUGIN_SUPPORT "Build Flang with plugin support." ON) diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp --- a/flang/tools/flang-driver/driver.cpp +++ b/flang/tools/flang-driver/driver.cpp @@ -35,6 +35,9 @@ // main frontend method. Lives inside fc1_main.cpp extern int fc1_main(llvm::ArrayRef argv, const char *argv0); +extern int cc1as_main(llvm::ArrayRef Argv, const char *Argv0, + void *MainAddr); + std::string getExecutablePath(const char *argv0) { // This just needs to be some symbol in the binary void *p = (void *)(intptr_t)getExecutablePath; @@ -64,6 +67,8 @@ llvm::StringRef tool = argV[1]; if (tool == "-fc1") return fc1_main(llvm::ArrayRef(argV).slice(2), argV[0]); + if (tool == "-cc1as") + return cc1as_main(llvm::ArrayRef(argV).slice(2), argV[0], nullptr); // Reject unknown tools. // ATM it only supports fc1. Any fc1[*] is rejected. @@ -99,6 +104,10 @@ auto firstArg = std::find_if(args.begin() + 1, args.end(), [](const char *a) { return a != nullptr; }); if (firstArg != args.end()) { + // Call flang -cc1as frontend + if (llvm::StringRef(args[1]).startswith("-cc1as")) { + return executeFC1Tool(args); + } if (llvm::StringRef(args[1]).startswith("-cc1")) { llvm::errs() << "error: unknown integrated tool '" << args[1] << "'. " << "Valid tools include '-fc1'.\n";