Compare commits

..

3 Commits

Author SHA1 Message Date
f1581299fc core: Minor changes to IRRT
Add missing documentation, remove redundant lifetime variables, and fix
typos.
2024-01-25 15:50:53 +08:00
af95ba5012 standalone: Add debug flag to run_demo.sh
Allows running demos using the debug build instead of the (default)
release build.
2024-01-25 15:50:53 +08:00
9c9756be33 standalone: Use size_t in demo.c 2024-01-25 15:50:53 +08:00
3 changed files with 27 additions and 23 deletions

View File

@ -552,9 +552,9 @@ pub fn call_j0<'ctx>(
/// ///
/// * `num_dims` - An [IntValue] containing the number of dimensions. /// * `num_dims` - An [IntValue] containing the number of dimensions.
/// * `dims` - A [PointerValue] to an array containing the size of each dimensions. /// * `dims` - A [PointerValue] to an array containing the size of each dimensions.
pub fn call_ndarray_calc_size<'ctx, 'a>( pub fn call_ndarray_calc_size<'ctx>(
generator: &mut dyn CodeGenerator, generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, 'a>, ctx: &mut CodeGenContext<'ctx, '_>,
num_dims: IntValue<'ctx>, num_dims: IntValue<'ctx>,
dims: PointerValue<'ctx>, dims: PointerValue<'ctx>,
) -> IntValue<'ctx> { ) -> IntValue<'ctx> {
@ -563,7 +563,7 @@ pub fn call_ndarray_calc_size<'ctx, 'a>(
let llvm_pi64 = llvm_i64.ptr_type(AddressSpace::default()); let llvm_pi64 = llvm_i64.ptr_type(AddressSpace::default());
let ndarray_calc_size_fn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_calc_size_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_calc_size", 32 => "__nac3_ndarray_calc_size",
64 => "__nac3_ndarray_calc_size64", 64 => "__nac3_ndarray_calc_size64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
@ -600,9 +600,9 @@ pub fn call_ndarray_calc_size<'ctx, 'a>(
/// `NDArray`. /// `NDArray`.
/// * `shape` - LLVM pointer to the `shape` of the NDArray. This value must be the LLVM /// * `shape` - LLVM pointer to the `shape` of the NDArray. This value must be the LLVM
/// representation of a `list`. /// representation of a `list`.
pub fn call_ndarray_init_dims<'ctx, 'a>( pub fn call_ndarray_init_dims<'ctx>(
generator: &mut dyn CodeGenerator, generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, 'a>, ctx: &mut CodeGenContext<'ctx, '_>,
ndarray: PointerValue<'ctx>, ndarray: PointerValue<'ctx>,
shape: PointerValue<'ctx>, shape: PointerValue<'ctx>,
) { ) {
@ -616,7 +616,7 @@ pub fn call_ndarray_init_dims<'ctx, 'a>(
let llvm_pi32 = llvm_i32.ptr_type(AddressSpace::default()); let llvm_pi32 = llvm_i32.ptr_type(AddressSpace::default());
let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default()); let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default());
let ndarray_init_dims_fn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_init_dims_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_init_dims", 32 => "__nac3_ndarray_init_dims",
64 => "__nac3_ndarray_init_dims64", 64 => "__nac3_ndarray_init_dims64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
@ -661,9 +661,14 @@ pub fn call_ndarray_init_dims<'ctx, 'a>(
); );
} }
pub fn call_ndarray_calc_nd_indices<'ctx, 'a>( /// Generates a call to `__nac3_ndarray_calc_nd_indices`.
generator: &mut dyn CodeGenerator, ///
ctx: &mut CodeGenContext<'ctx, 'a>, /// * `index` - The index to compute the multidimensional index for.
/// * `ndarray` - LLVM pointer to the NDArray. This value must be the LLVM representation of an
/// `NDArray`.
pub fn call_ndarray_calc_nd_indices<'ctx>(
generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, '_>,
index: IntValue<'ctx>, index: IntValue<'ctx>,
ndarray: PointerValue<'ctx>, ndarray: PointerValue<'ctx>,
) -> Result<PointerValue<'ctx>, String> { ) -> Result<PointerValue<'ctx>, String> {
@ -675,12 +680,12 @@ pub fn call_ndarray_calc_nd_indices<'ctx, 'a>(
let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default()); let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default());
let ndarray_calc_nd_indices_dn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_calc_nd_indices_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_calc_nd_indices", 32 => "__nac3_ndarray_calc_nd_indices",
64 => "__nac3_ndarray_calc_nd_indices64", 64 => "__nac3_ndarray_calc_nd_indices64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
}; };
let ndarray_calc_nd_indices_fn = ctx.module.get_function(ndarray_calc_nd_indices_dn_name).unwrap_or_else(|| { let ndarray_calc_nd_indices_fn = ctx.module.get_function(ndarray_calc_nd_indices_fn_name).unwrap_or_else(|| {
let fn_type = llvm_void.fn_type( let fn_type = llvm_void.fn_type(
&[ &[
llvm_usize.into(), llvm_usize.into(),
@ -691,7 +696,7 @@ pub fn call_ndarray_calc_nd_indices<'ctx, 'a>(
false, false,
); );
ctx.module.add_function(ndarray_calc_nd_indices_dn_name, fn_type, None) ctx.module.add_function(ndarray_calc_nd_indices_fn_name, fn_type, None)
}); });
let ndarray_num_dims = ctx.build_gep_and_load( let ndarray_num_dims = ctx.build_gep_and_load(

View File

@ -1,18 +1,12 @@
#include <inttypes.h>
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#if __SIZEOF_POINTER__ == 8 #define usize size_t
#define usize uint64_t
#elif __SIZEOF_POINTER__ == 4
#define usize uint32_t
#else
#error "Unsupported platform - Platform is not 32-bit or 64-bit"
#endif
double dbl_nan(void) { double dbl_nan(void) {
return NAN; return NAN;

View File

@ -17,6 +17,9 @@ while [ $# -ge 1 ]; do
--lli) --lli)
use_lli=1 use_lli=1
;; ;;
--debug)
debug=1
;;
*) *)
nac3args+=("$1") nac3args+=("$1")
;; ;;
@ -24,7 +27,9 @@ while [ $# -ge 1 ]; do
shift shift
done done
if [ -e ../../target/release/nac3standalone ]; then if [ -n "$debug" ] && [ -e ../../target/debug/nac3standalone ]; then
nac3standalone=../../target/debug/nac3standalone
elif [ -e ../../target/release/nac3standalone ]; then
nac3standalone=../../target/release/nac3standalone nac3standalone=../../target/release/nac3standalone
else else
# used by Nix builds # used by Nix builds