This commit is contained in:
Edgar 2024-02-16 12:49:12 +01:00
parent 4dabaf070b
commit ebfb0ef34c
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
2 changed files with 18 additions and 6 deletions

View file

@ -11,6 +11,7 @@ use inkwell::{
AsDIScope, DICompileUnit, DIFlagsConstants, DILocation, DIScope, DIType, DebugInfoBuilder, AsDIScope, DICompileUnit, DIFlagsConstants, DILocation, DIScope, DIType, DebugInfoBuilder,
}, },
module::Module, module::Module,
passes::PassBuilderOptions,
targets::{InitializationConfig, Target, TargetData, TargetMachine}, targets::{InitializationConfig, Target, TargetData, TargetMachine},
types::{AnyType, BasicMetadataTypeEnum, BasicType}, types::{AnyType, BasicMetadataTypeEnum, BasicType},
values::{BasicValue, BasicValueEnum, PointerValue}, values::{BasicValue, BasicValueEnum, PointerValue},
@ -94,6 +95,7 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result<PathBuf, Box<
) )
.unwrap(); .unwrap();
machine.set_asm_verbosity(true); machine.set_asm_verbosity(true);
info!("compiling for: {:?}", target.get_description()); info!("compiling for: {:?}", target.get_description());
let filename = session.file_path.file_name().unwrap().to_string_lossy(); let filename = session.file_path.file_name().unwrap().to_string_lossy();
@ -142,6 +144,18 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result<PathBuf, Box<
module_ctx.di_builder.finalize(); module_ctx.di_builder.finalize();
module_ctx.module.verify()?; module_ctx.module.verify()?;
let opt = match session.optlevel {
edlang_session::OptLevel::None => "0",
edlang_session::OptLevel::Less => "1",
edlang_session::OptLevel::Default => "2",
edlang_session::OptLevel::Aggressive => "3",
};
let passopt = PassBuilderOptions::create();
module_ctx
.module
.run_passes(&format!("default<O{}>", opt), &machine, passopt)?;
if session.output_llvm { if session.output_llvm {
module_ctx module_ctx
.module .module
@ -233,6 +247,7 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) {
preallocated sret align 0 allockind(\"\") allocsize(0,0) dereferenceable(0) dereferenceable_or_null(0 preallocated sret align 0 allockind(\"\") allocsize(0,0) dereferenceable(0) dereferenceable_or_null(0
*/ */
/*
// nounwind // nounwind
fn_value.add_attribute( fn_value.add_attribute(
inkwell::attributes::AttributeLoc::Function, inkwell::attributes::AttributeLoc::Function,
@ -250,12 +265,9 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) {
inkwell::attributes::AttributeLoc::Function, inkwell::attributes::AttributeLoc::Function,
ctx.ctx.context.create_enum_attribute(66, 0), ctx.ctx.context.create_enum_attribute(66, 0),
); );
*/
if body.name == "main" { fn_value.set_call_conventions(0);
fn_value.set_call_conventions(0);
} else {
fn_value.set_call_conventions(1);
}
let (_, line, _col) = ctx let (_, line, _col) = ctx
.ctx .ctx

View file

@ -4,7 +4,7 @@ mod Main {
return b; return b;
} }
fn factorial(n: i32) -> i32 { pub fn factorial(n: i32) -> i32 {
if n == 1 { if n == 1 {
return n; return n;
} else { } else {