Compare commits

...

3 Commits

Author SHA1 Message Date
David Mak abbaa506ad [standalone] Remove redundant recreation of TargetMachine 2024-09-09 14:27:10 +08:00
David Mak f3dc02d646 [meta] Apply cargo fmt 2024-09-09 14:24:52 +08:00
David Mak ea217eaea1 [meta] Update pre-commit config
Directly invoke cargo using nix develop to avoid using the system cargo.
2024-09-09 14:24:38 +08:00
7 changed files with 25 additions and 34 deletions

View File

@ -8,17 +8,17 @@ repos:
hooks: hooks:
- id: nac3-cargo-fmt - id: nac3-cargo-fmt
name: nac3 cargo format name: nac3 cargo format
entry: cargo entry: nix
language: system language: system
types: [file, rust] types: [file, rust]
pass_filenames: false pass_filenames: false
description: Runs cargo fmt on the codebase. description: Runs cargo fmt on the codebase.
args: [fmt] args: [develop, -c, cargo, fmt, --all]
- id: nac3-cargo-clippy - id: nac3-cargo-clippy
name: nac3 cargo clippy name: nac3 cargo clippy
entry: cargo entry: nix
language: system language: system
types: [file, rust] types: [file, rust]
pass_filenames: false pass_filenames: false
description: Runs cargo clippy on the codebase. description: Runs cargo clippy on the codebase.
args: [clippy, --tests] args: [develop, -c, cargo, clippy, --tests]

View File

@ -32,8 +32,8 @@ use pyo3::{
use crate::{symbol_resolver::InnerResolver, timeline::TimeFns}; use crate::{symbol_resolver::InnerResolver, timeline::TimeFns};
use nac3core::inkwell::values::IntValue;
use itertools::Itertools; use itertools::Itertools;
use nac3core::inkwell::values::IntValue;
use std::{ use std::{
collections::{hash_map::DefaultHasher, HashMap}, collections::{hash_map::DefaultHasher, HashMap},
hash::{Hash, Hasher}, hash::{Hash, Hasher},

View File

@ -23,6 +23,8 @@ use std::process::Command;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use itertools::Itertools;
use nac3core::codegen::{gen_func_impl, CodeGenLLVMOptions, CodeGenTargetMachineOptions};
use nac3core::inkwell::{ use nac3core::inkwell::{
context::Context, context::Context,
memory_buffer::MemoryBuffer, memory_buffer::MemoryBuffer,
@ -32,14 +34,12 @@ use nac3core::inkwell::{
targets::*, targets::*,
OptimizationLevel, OptimizationLevel,
}; };
use itertools::Itertools;
use nac3core::codegen::{gen_func_impl, CodeGenLLVMOptions, CodeGenTargetMachineOptions};
use nac3core::toplevel::builtins::get_exn_constructor;
use nac3core::typecheck::typedef::{into_var_map, TypeEnum, Unifier, VarMap};
use nac3core::nac3parser::{ use nac3core::nac3parser::{
ast::{ExprKind, Stmt, StmtKind, StrRef}, ast::{ExprKind, Stmt, StmtKind, StrRef},
parser::parse_program, parser::parse_program,
}; };
use nac3core::toplevel::builtins::get_exn_constructor;
use nac3core::typecheck::typedef::{into_var_map, TypeEnum, Unifier, VarMap};
use pyo3::create_exception; use pyo3::create_exception;
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::{exceptions, types::PyBytes, types::PyDict, types::PySet}; use pyo3::{exceptions, types::PyBytes, types::PyDict, types::PySet};

View File

@ -1,11 +1,12 @@
use crate::PrimitivePythonId; use crate::PrimitivePythonId;
use itertools::Itertools;
use nac3core::inkwell::{ use nac3core::inkwell::{
module::Linkage, module::Linkage,
types::{BasicType, BasicTypeEnum}, types::{BasicType, BasicTypeEnum},
values::BasicValueEnum, values::BasicValueEnum,
AddressSpace, AddressSpace,
}; };
use itertools::Itertools; use nac3core::nac3parser::ast::{self, StrRef};
use nac3core::{ use nac3core::{
codegen::{ codegen::{
classes::{NDArrayType, ProxyType}, classes::{NDArrayType, ProxyType},
@ -22,7 +23,6 @@ use nac3core::{
typedef::{into_var_map, iter_type_vars, Type, TypeEnum, TypeVar, Unifier, VarMap}, typedef::{into_var_map, iter_type_vars, Type, TypeEnum, TypeVar, Unifier, VarMap},
}, },
}; };
use nac3core::nac3parser::ast::{self, StrRef};
use parking_lot::RwLock; use parking_lot::RwLock;
use pyo3::{ use pyo3::{
types::{PyDict, PyTuple}, types::{PyDict, PyTuple},

View File

@ -1,9 +1,9 @@
use itertools::Either;
use nac3core::codegen::CodeGenContext;
use nac3core::inkwell::{ use nac3core::inkwell::{
values::{BasicValueEnum, CallSiteValue}, values::{BasicValueEnum, CallSiteValue},
AddressSpace, AtomicOrdering, AddressSpace, AtomicOrdering,
}; };
use itertools::Either;
use nac3core::codegen::CodeGenContext;
/// Functions for manipulating the timeline. /// Functions for manipulating the timeline.
pub trait TimeFns { pub trait TimeFns {

View File

@ -1,3 +1,4 @@
use nac3core::nac3parser::ast::{self, StrRef};
use nac3core::{ use nac3core::{
codegen::CodeGenContext, codegen::CodeGenContext,
symbol_resolver::{SymbolResolver, SymbolValue, ValueEnum}, symbol_resolver::{SymbolResolver, SymbolValue, ValueEnum},
@ -7,7 +8,6 @@ use nac3core::{
typedef::{Type, Unifier}, typedef::{Type, Unifier},
}, },
}; };
use nac3core::nac3parser::ast::{self, StrRef};
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use std::collections::HashSet; use std::collections::HashSet;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};

View File

@ -10,8 +10,12 @@
use clap::Parser; use clap::Parser;
use nac3core::inkwell::{ use nac3core::inkwell::{
memory_buffer::MemoryBuffer, passes::PassBuilderOptions, support::is_multithreaded, targets::*, memory_buffer::MemoryBuffer, module::Linkage, passes::PassBuilderOptions,
OptimizationLevel, module::Linkage support::is_multithreaded, targets::*, OptimizationLevel,
};
use nac3core::nac3parser::{
ast::{Constant, Expr, ExprKind, StmtKind, StrRef},
parser,
}; };
use nac3core::{ use nac3core::{
codegen::{ codegen::{
@ -30,10 +34,6 @@ use nac3core::{
typedef::{FunSignature, Type, Unifier, VarMap}, typedef::{FunSignature, Type, Unifier, VarMap},
}, },
}; };
use nac3core::nac3parser::{
ast::{Constant, Expr, ExprKind, StmtKind, StrRef},
parser,
};
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use std::collections::HashSet; use std::collections::HashSet;
use std::num::NonZeroUsize; use std::num::NonZeroUsize;
@ -279,18 +279,14 @@ fn main() {
reloc_mode: RelocMode::PIC, reloc_mode: RelocMode::PIC,
..host_target_machine ..host_target_machine
}; };
let target_machine = target_machine_options
.create_target_machine(opt_level)
.expect("couldn't create target machine");
let context = nac3core::inkwell::context::Context::create(); let context = nac3core::inkwell::context::Context::create();
let size_t = context let size_t =
.ptr_sized_int_type( context.ptr_sized_int_type(&target_machine.get_target_data(), None).get_bit_width();
&target_machine_options
.create_target_machine(opt_level)
.map(|tm| tm.get_target_data())
.unwrap(),
None,
)
.get_bit_width();
let program = match fs::read_to_string(file_name.clone()) { let program = match fs::read_to_string(file_name.clone()) {
Ok(program) => program, Ok(program) => program,
@ -458,11 +454,6 @@ fn main() {
} }
// Optimize `main` // Optimize `main`
let target_machine = llvm_options
.target
.create_target_machine(llvm_options.opt_level)
.expect("couldn't create target machine");
let pass_options = PassBuilderOptions::create(); let pass_options = PassBuilderOptions::create();
pass_options.set_merge_functions(true); pass_options.set_merge_functions(true);
let passes = format!("default<O{}>", opt_level as u32); let passes = format!("default<O{}>", opt_level as u32);