Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Feb 16, 2024
1 parent 64a4665 commit 4dabaf0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
34 changes: 34 additions & 0 deletions lib/edlang_codegen_llvm/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/edlang_driver/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
borrow::Cow,
fmt,
path::{Path, PathBuf},
process::Output,
process::Child,
};

use ariadne::Source;
Expand Down Expand Up @@ -80,9 +80,6 @@ pub fn compile_program(
})
}

pub fn run_program(program: &Path, args: &[&str]) -> Result<Output, std::io::Error> {
std::process::Command::new(program)
.args(args)
.spawn()?
.wait_with_output()
pub fn run_program(program: &Path, args: &[&str]) -> Result<Child, std::io::Error> {
std::process::Command::new(dbg!(program)).args(args).spawn()
}
7 changes: 4 additions & 3 deletions lib/edlang_driver/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/edlang_driver/tests/programs/factorial.ed
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4dabaf0

Please sign in to comment.