Compare commits
7 Commits
fc93fc2f0e
...
8bef0ab8f2
Author | SHA1 | Date |
---|---|---|
David Mak | 8bef0ab8f2 | |
David Mak | 806f65815f | |
David Mak | 2e6a64a1de | |
David Mak | 20aa094b1f | |
David Mak | 5ab8d751ed | |
David Mak | c7d5d75014 | |
David Mak | 72570fbb16 |
|
@ -64,8 +64,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
|||
index: &[IntValue<'ctx>],
|
||||
name: Option<&str>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let gep = unsafe { self.builder.build_gep(ptr, index, "") };
|
||||
self.builder.build_load(gep, name.unwrap_or_default())
|
||||
unsafe { self.builder.build_load(self.builder.build_gep(ptr, index, ""), name.unwrap_or_default()) }
|
||||
}
|
||||
|
||||
fn get_subst_key(
|
||||
|
|
|
@ -13,10 +13,7 @@ use crate::{
|
|||
},
|
||||
};
|
||||
use indoc::indoc;
|
||||
use inkwell::{
|
||||
targets::{InitializationConfig, Target},
|
||||
OptimizationLevel
|
||||
};
|
||||
use inkwell::OptimizationLevel;
|
||||
use nac3parser::{
|
||||
ast::{fold::Fold, StrRef},
|
||||
parser::parse_program,
|
||||
|
@ -24,6 +21,7 @@ use nac3parser::{
|
|||
use parking_lot::RwLock;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use inkwell::targets::{InitializationConfig, Target};
|
||||
|
||||
struct Resolver {
|
||||
id_to_type: HashMap<StrRef, Type>,
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define min(a, b) \
|
||||
({ \
|
||||
__typeof__(a) _a = (a); \
|
||||
__typeof__(b) _b = (b); \
|
||||
_a < _b ? _a : _b; \
|
||||
})
|
||||
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
#define usize uint64_t
|
||||
#elif __SIZEOF_POINTER__ == 4
|
||||
#define usize uint32_t
|
||||
#elif __SIZEOF_POINTER__ == 2
|
||||
#define usize uint16_t
|
||||
#endif
|
||||
|
||||
void output_int32(const int32_t x) {
|
||||
printf("%d\n", x);
|
||||
}
|
||||
|
||||
void output_int64(const int64_t x) {
|
||||
printf("%ld\n", x);
|
||||
}
|
||||
|
||||
void output_uint32(const uint32_t x) {
|
||||
printf("%d\n", x);
|
||||
}
|
||||
|
||||
void output_uint64(const uint64_t x) {
|
||||
printf("%ld\n", x);
|
||||
}
|
||||
|
||||
void output_asciiart(const int32_t x) {
|
||||
const char* chars = " .,-:;i+hHM$*#@ ";
|
||||
if (x < 0) {
|
||||
fputc('\n', stdout);
|
||||
} else {
|
||||
fputc(chars[x], stdout);
|
||||
}
|
||||
}
|
||||
|
||||
struct cslice_int32 {
|
||||
const int32_t* data;
|
||||
usize len;
|
||||
};
|
||||
|
||||
void output_int32_list(struct cslice_int32* slice) {
|
||||
fputc('[', stdout);
|
||||
for (usize i = 0; i < slice->len; ++i) {
|
||||
if (i == slice->len - 1) {
|
||||
printf("%d", slice->data[i]);
|
||||
} else {
|
||||
printf("%d, ", slice->data[i]);
|
||||
}
|
||||
}
|
||||
puts("]");
|
||||
}
|
||||
|
||||
uint32_t __nac3_personality(
|
||||
__attribute__((unused)) uint32_t state,
|
||||
__attribute__((unused)) uint32_t exception_object,
|
||||
__attribute__((unused)) uint32_t context) {
|
||||
assert(false && "__nac3_personality not implemented");
|
||||
exit(101);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
uint32_t __nac3_raise(uint32_t state, uint32_t exception_object, uint32_t context) {
|
||||
printf("__nac3_raise(state: %x, exception_object: %x, context: %x\n", state, exception_object, context);
|
||||
exit(101);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
extern int32_t run();
|
||||
|
||||
int main() {
|
||||
run();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "No argument supplied"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -e ../../target/release/nac3standalone ]; then
|
||||
nac3standalone=../../target/release/nac3standalone
|
||||
else
|
||||
# used by Nix builds
|
||||
nac3standalone=../../target/x86_64-unknown-linux-gnu/release/nac3standalone
|
||||
fi
|
||||
|
||||
rm -f *.o *.bc
|
||||
$nac3standalone --emit-llvm "$@"
|
||||
gcc -c -std=c11 -Wall -Wextra -pedantic-errors -Werror=pedantic -O3 -o demo.o demo.c
|
||||
clang -S -Wall -Wextra -O3 -emit-llvm -o irrt.bc ../../nac3core/src/codegen/irrt/irrt.c
|
||||
lli --extra-object demo.o --extra-module irrt.bc main.bc
|
Loading…
Reference in New Issue