Add support for building object files from LLVM assembly sources - close #175

This commit is contained in:
josh committed 2024-03-23 22:24:45 -04:00
1 parent 6e7139abb1
commit ba71e8d5e3
10 files changed
+79

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
env do |env|
env["LLVMAS_FLAGS"] += %w[-Wno-override-module]
env.Program("llvmtest.exe", %w[main.c one.ll])
end
+8
View File
@@ -0,0 +1,8 @@
configure do
check_c_compiler "clang"
end
env do |env|
env["LLVMAS_FLAGS"] += %w[-Wno-override-module]
env.Program("llvmtest.exe", %w[one.ll two.ll main2.c], direct: true)
end
+6
View File
@@ -0,0 +1,6 @@
extern int one(void);
int main(int argc, char * argv[])
{
return one();
}
+9
View File
@@ -0,0 +1,9 @@
extern int one(void);
extern int two(void);
int main(int argc, char * argv[])
{
one();
two();
return 0;
}
+9
View File
@@ -0,0 +1,9 @@
@str = private unnamed_addr constant [12 x i8] c"hello world\00"
declare i32 @puts(ptr nocapture) nounwind
define i32 @one()
{
call i32 @puts(ptr @str)
ret i32 0
}
+9
View File
@@ -0,0 +1,9 @@
@str = private unnamed_addr constant [12 x i8] c"hello again\00"
declare i32 @puts(ptr nocapture) nounwind
define i32 @two()
{
call i32 @puts(ptr @str)
ret i32 0
}
+1
View File
@@ -156,6 +156,7 @@ require_relative "rscons/builders/lang/asm"
require_relative "rscons/builders/lang/c"
require_relative "rscons/builders/lang/cxx"
require_relative "rscons/builders/lang/d"
require_relative "rscons/builders/lang/llvm_asm"
# Unbuffer $stdout
$stdout.sync = true
+10
View File
@@ -0,0 +1,10 @@
Rscons::Builders::Object.register(
command: "${LLVMAS_CMD}",
direct_command: "${LLVMAS_CMD:direct}",
suffix: "${LLVMAS_SUFFIX}",
short_description: "Assembling")
Rscons::Builders::SharedObject.register(
command: "${LLVMAS_CMD}",
direct_command: "${LLVMAS_CMD:direct}",
suffix: "${LLVMAS_SUFFIX}",
short_description: "Assembling")
@@ -58,6 +58,11 @@ module Rscons
"LIBPATH" => [],
"LIBS" => [],
"LIBSUFFIX" => ".a",
"LLVMAS" => "clang",
"LLVMAS_CMD" => %w[${LLVMAS} -c -o ${_TARGET} ${LLVMAS_FLAGS} ${_SOURCES}],
"LLVMAS_CMD:direct" => %w[${LLVMAS} -o ${_TARGET} ${LLVMAS_FLAGS} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
"LLVMAS_FLAGS" => [],
"LLVMAS_SUFFIX" => ".ll",
"OBJDUMP" => "objdump",
"OBJSUFFIX" => %w[.o],
"PROGSUFFIX" => on_windows ? ".exe" : "",
+18
View File
@@ -3408,4 +3408,22 @@ EOF
end
end
it "supports building LLVM assembly files with the Program builder" do
test_dir "llvm"
result = run_rscons
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(File.exist?("llvmtest.exe")).to be_truthy
expect(`./llvmtest.exe`).to match /hello world/
end
it "supports building LLVM assembly files with the Program builder in direct mode" do
test_dir "llvm"
result = run_rscons(args: %w[-f direct.rb])
expect(result.stderr).to eq ""
expect(result.status).to eq 0
expect(File.exist?("llvmtest.exe")).to be_truthy
expect(`./llvmtest.exe`).to match /hello again/
end
end