Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

add plover build functionality, check_qr test #318

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions include/libswiftnav/plover/ambiguity_test.h

This file was deleted.

56 changes: 56 additions & 0 deletions include/libswiftnav/plover/prelude.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef PLOVER_GENERATED_prelude
#define PLOVER_GENERATED_prelude


#include <assert.h>

#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#ifndef COMMON_INT_TYPES
#define COMMON_INT_TYPES
/** \defgroup common_inttypes Integer types
* Specified-width integer type definitions for shorter and nicer code.
*
* These should be used in preference to unspecified width types such as
* `int` which can lead to portability issues between different platforms.
* \{ */

/** Signed 8-bit integer. */
typedef int8_t s8;
/** Signed 16-bit integer. */
typedef int16_t s16;
/** Signed 32-bit integer. */
typedef int32_t s32;
/** Signed 64-bit integer. */
typedef int64_t s64;
/** Unsigned 8-bit integer. */
typedef uint8_t u8;
/** Unsigned 16-bit integer. */
typedef uint16_t u16;
/** Unsigned 32-bit integer. */
typedef uint32_t u32;
/** Unsigned 64-bit integer. */
typedef uint64_t u64;

#endif

/** \} */

#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int ipow(int base, int exp);
double dipow(double base, int exp);
double rand_uniform(void);
double rand_normal (void);
double norm (const s32 n, const double * v);
void normalize (const s32 n, const double * v, double * result);
void print_vec (const s32 n, const double * v);
void print_mat (const s32 n, const s32 m, const double * A);
s32 matrix_inv (const s32 n, const double * A, double * B);
double det (const s32 n, const double * A);


#endif /* PLOVER_GENERATED_prelude */
10 changes: 10 additions & 0 deletions include/libswiftnav/plover/qr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef PLOVER_GENERATED_qr
#define PLOVER_GENERATED_qr

#include "libswiftnav/plover/prelude.h"

s8 qr_solve (const s32 m, const s32 n, double * A, double * b, double * solution, double * const residual);
void qr_update (const s32 m, const s32 n, double * b, double * A);


#endif /* PLOVER_GENERATED_qr */
33 changes: 0 additions & 33 deletions plover/AmbiguityTest.hs

This file was deleted.

83 changes: 56 additions & 27 deletions plover/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,76 @@ set (PLOVER_GENERATED_H_DIR ${CMAKE_SOURCE_DIR}/include/libswiftnav/plover CACHE
file(MAKE_DIRECTORY ${PLOVER_GENERATED_H_DIR})

# Find default cabal
find_program(CMAKE_cabal NAMES cabal)
find_program(CMAKE_CABAL NAMES cabal)
# Find plover executable
find_program(CMAKE_PLOVER NAMES plover)

if (DEFINED ENV{CABAL})
message("Saw cabal flag: $ENV{CABAL}")
set (CMAKE_cabal $ENV{CABAL})
message("Saw CABAL flag: $ENV{CABAL}")
set (CMAKE_CABAL $ENV{CABAL})
else ()
message("Environment variable 'CABAL' not set. Defaulting to ${CMAKE_cabal}.")
message("Environment variable 'CABAL' not set. Defaulting to ${CMAKE_CABAL}.")
endif ()
if (DEFINED ENV{PLOVER})
message("Saw PLOVER flag. Using $ENV{PLOVER}")
set (CMAKE_PLOVER $ENV{PLOVER})
else ()
message("Environment variable 'PLOVER' not set. Defaulting to ${CMAKE_PLOVER}.")
endif ()

set (plover_HS_SRCS
Main.hs
AmbiguityTest.hs
# Haskell files with macro plover definitions
# TODO implement build step
set (PLOVER_HS_SRCS
)

set (plover_SRCS
${PLOVER_GENERATED_C_DIR}/ambiguity_test.c
CACHE INTERNAL ""
# For each unit in PLOVER_UNITS:
# Expects ${unit}.plv in PLOVER_DIR
# Generates ${unit}.c in PLOVER_GENERATED_C_DIR
# and ${unit}.h in PLOVER_GENERATED_H_DIR
set (PLOVER_UNITS
prelude
qr
)

set (plover_HDRS
${PLOVER_GENERATED_H_DIR}/ambiguity_test.h
CACHE INTERNAL ""
)
foreach(unit ${PLOVER_UNITS})
list(APPEND PLOVER_CFILES "${PLOVER_GENERATED_C_DIR}/${unit}.c")
list(APPEND PLOVER_HFILES "${PLOVER_GENERATED_H_DIR}/${unit}.h")
list(APPEND PLOVER_SRC "${PLOVER_DIR}/${unit}.plv")
endforeach(unit)

# Make available to src/ CMakeLists
set(PLOVER_CFILES ${PLOVER_CFILES} PARENT_SCOPE)
set(PLOVER_HFILES ${PLOVER_HFILES} PARENT_SCOPE)

# Main project depends on generate. generate depends on generated files.
add_custom_target(generate DEPENDS ${PLOVER_CFILES} ${PLOVER_HFILES})

if (CMAKE_CABAL AND CMAKE_PLOVER)
message("\nFound Plover tools.")
# Don't add step if no UNITS are specified
if (PLOVER_CFILES OR PLOVER_HFILES)
message("Adding code generation steps, one for each plv unit.\n\
Will run if plover subproject is modified and after make clean or clean-generate.")
foreach(unit ${PLOVER_UNITS})
add_custom_command(
OUTPUT "${PLOVER_GENERATED_C_DIR}/${unit}.c" "${PLOVER_GENERATED_H_DIR}/${unit}.h"
COMMAND ${CMAKE_PLOVER}
-I "${PLOVER_DIR}"
--cdir "${PLOVER_GENERATED_C_DIR}" --hdir "${PLOVER_GENERATED_H_DIR}"
--libprefix "libswiftnav/plover"
"${PLOVER_DIR}/${unit}.plv"
WORKING_DIRECTORY ${PLOVER_DIR}
DEPENDS "${PLOVER_DIR}/${unit}.plv")
endforeach(unit)
endif ()
message("")

if (CMAKE_cabal)
message("\nFound Haskell tools. Adding code generation step (to be run if Haskell subproject is modified).\n")
add_custom_command(
OUTPUT ${plover_SRCS} ${plover_HDRS}
COMMAND ${CMAKE_cabal} run "${PLOVER_GENERATED_C_DIR}" "${PLOVER_GENERATED_H_DIR}"
WORKING_DIRECTORY ${PLOVER_DIR}
DEPENDS ${plover_HS_SRCS})
else ()
message("\nNo Haskell toolchain (cabal) found. Code generation with Plover is disabled.\n")
message("\nNo Plover toolchain found. Code generation is disabled.\n")
endif ()

add_custom_target(clean_generate
add_custom_target(clean-generate
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PLOVER_DIR}/dist
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_C_DIR}/*
COMMAND ${CMAKE_COMMAND} -E remove ${PLOVER_GENERATED_H_DIR}/*
)

# Main project depends on generated code
add_custom_target(generate DEPENDS ${plover_SRCS} ${plover_HDRS})

18 changes: 0 additions & 18 deletions plover/Main.hs

This file was deleted.

2 changes: 2 additions & 0 deletions plover/README
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
requires installation of https://github.com/swift-nav/plover for code generation

new plover files should be added to the local CMakeLists.txt file. see `PLOVER_UNITS`
14 changes: 0 additions & 14 deletions plover/libswiftnav-generate.cabal

This file was deleted.

Loading