From 4dabaf070bc812a584e5a3a8e353dadc267bb981 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Fri, 16 Feb 2024 11:48:15 +0100 Subject: [PATCH] fixes --- lib/edlang_codegen_llvm/src/codegen.rs | 34 +++++++++++++++++++ lib/edlang_driver/tests/common.rs | 9 ++--- lib/edlang_driver/tests/programs.rs | 7 ++-- lib/edlang_driver/tests/programs/factorial.ed | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/edlang_codegen_llvm/src/codegen.rs b/lib/edlang_codegen_llvm/src/codegen.rs index b2b9f69a9..0f90fa172 100644 --- a/lib/edlang_codegen_llvm/src/codegen.rs +++ b/lib/edlang_codegen_llvm/src/codegen.rs @@ -218,11 +218,45 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) { }), ); + // https://llvm.org/doxygen/group__LLVMCCoreTypes.html + + /* starting from 1 to 80 + allocalign allocptr alwaysinline builtin cold convergent disable_sanitizer_instrumentation fn_ret_thunk_extern hot + immarg inreg inlinehint jumptable minsize mustprogress naked nest noalias + nobuiltin nocallback nocapture nocf_check noduplicate nofree noimplicitfloat + noinline nomerge noprofile norecurse noredzone noreturn nosanitize_bounds + nosanitize_coverage nosync noundef nounwind nonlazybind nonnull null_pointer_is_valid + optforfuzzing optsize optnone presplitcoroutine readnone readonly returned returns_twice + signext safestack sanitize_address sanitize_hwaddress sanitize_memtag sanitize_memory + sanitize_thread shadowcallstack skipprofile speculatable speculative_load_hardening ssp + sspreq sspstrong strictfp swiftasync swifterror swiftself willreturn writeonly (67) zeroext byref byval elementtype inalloca + preallocated sret align 0 allockind(\"\") allocsize(0,0) dereferenceable(0) dereferenceable_or_null(0 + */ + + // nounwind + fn_value.add_attribute( + inkwell::attributes::AttributeLoc::Function, + ctx.ctx.context.create_enum_attribute(36, 0), + ); + // nonlazybind fn_value.add_attribute( inkwell::attributes::AttributeLoc::Function, ctx.ctx.context.create_enum_attribute(37, 0), ); + + // willreturn + fn_value.add_attribute( + inkwell::attributes::AttributeLoc::Function, + ctx.ctx.context.create_enum_attribute(66, 0), + ); + + if body.name == "main" { + fn_value.set_call_conventions(0); + } else { + fn_value.set_call_conventions(1); + } + let (_, line, _col) = ctx .ctx .session diff --git a/lib/edlang_driver/tests/common.rs b/lib/edlang_driver/tests/common.rs index b4865bb6a..03396b960 100644 --- a/lib/edlang_driver/tests/common.rs +++ b/lib/edlang_driver/tests/common.rs @@ -2,7 +2,7 @@ use std::{ borrow::Cow, fmt, path::{Path, PathBuf}, - process::Output, + process::Child, }; use ariadne::Source; @@ -80,9 +80,6 @@ pub fn compile_program( }) } -pub fn run_program(program: &Path, args: &[&str]) -> Result { - std::process::Command::new(program) - .args(args) - .spawn()? - .wait_with_output() +pub fn run_program(program: &Path, args: &[&str]) -> Result { + std::process::Command::new(dbg!(program)).args(args).spawn() } diff --git a/lib/edlang_driver/tests/programs.rs b/lib/edlang_driver/tests/programs.rs index 75080be9e..4f040ee13 100644 --- a/lib/edlang_driver/tests/programs.rs +++ b/lib/edlang_driver/tests/programs.rs @@ -18,13 +18,14 @@ mod common; #[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 1, &[] ; "TEST_IF_NO_ELSE")] #[test_case(TEST_IF_NO_ELSE, "TEST_IF_NO_ELSE", false, 2, &["a"] ; "TEST_IF_NO_ELSE args")] fn example_tests(source: &str, name: &str, is_library: bool, status_code: i32, args: &[&str]) { + dbg!(source); let program = compile_program(source, name, is_library).unwrap(); assert!(program.binary_file.exists(), "program not compiled"); - - let result = run_program(&program.binary_file, args).unwrap(); + let mut result = run_program(&program.binary_file, args).unwrap(); + let status = result.wait().unwrap(); assert_eq!( - result.status.code().unwrap(), + status.code().unwrap(), status_code, "Program {} returned a unexpected status code", name diff --git a/lib/edlang_driver/tests/programs/factorial.ed b/lib/edlang_driver/tests/programs/factorial.ed index 28a8e6772..7123369fb 100644 --- a/lib/edlang_driver/tests/programs/factorial.ed +++ b/lib/edlang_driver/tests/programs/factorial.ed @@ -5,7 +5,7 @@ mod Main { } fn factorial(n: i32) -> i32 { - if n == 0 { + if n == 1 { return n; } else { return n * factorial(n - 1);