forked from M-Labs/nac3
add NAC3 refcount to IRRT
This commit is contained in:
@@ -7,10 +7,10 @@ device_db = {
|
||||
"module": "artiq.coredevice.core",
|
||||
"class": "Core",
|
||||
"arguments": {
|
||||
"host": "kc705",
|
||||
"host": "host",
|
||||
"ref_period": 1e-9,
|
||||
"ref_multiplier": 8,
|
||||
"target": "rv32g"
|
||||
"target": "host"
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -141,6 +141,10 @@ def compile(cls):
|
||||
return cls
|
||||
|
||||
|
||||
def staticmethod(function):
|
||||
pass
|
||||
|
||||
|
||||
import device_db
|
||||
core_arguments = device_db.device_db["core"]["arguments"]
|
||||
|
||||
@@ -148,6 +152,7 @@ builtins = {
|
||||
"int": int,
|
||||
"float": float,
|
||||
"bool": bool,
|
||||
"staticmethod": staticmethod,
|
||||
"str": str,
|
||||
"list": list,
|
||||
"tuple": tuple,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "irrt/exception.hpp"
|
||||
#include "irrt/list.hpp"
|
||||
#include "irrt/math.hpp"
|
||||
#include "irrt/mem.hpp"
|
||||
#include "irrt/range.hpp"
|
||||
#include "irrt/slice.hpp"
|
||||
#include "irrt/string.hpp"
|
||||
|
||||
42
nac3core/irrt/irrt/mem.hpp
Normal file
42
nac3core/irrt/irrt/mem.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "irrt/int_types.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
extern "C" void nac3_free(void *ptr);
|
||||
|
||||
template<typename SizeT>
|
||||
void __nac3_rc_incr_impl(void *obj) {
|
||||
SizeT *p = (SizeT *) ptr;
|
||||
*(p - 1) += 1;
|
||||
}
|
||||
|
||||
template<typename SizeT>
|
||||
void __nac3_rc_decr_impl(void *obj) {
|
||||
SizeT *p = (SizeT *) ptr;
|
||||
*(p - 1) -= 1;
|
||||
|
||||
if (!*(p - 1))
|
||||
nac3_free(p - 2);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define DEF_nac3_rc_incr_(T) \
|
||||
void __nac3_rc_incr_##T(void *ptr) { \
|
||||
return __nac3_rc_incr_impl<T>(ptr); \
|
||||
}
|
||||
#define DEF_nac3_rc_decr_(T) \
|
||||
void __nac3_rc_decr_##T(void *ptr) { \
|
||||
return __nac3_rc_incr_impl<T>(ptr); \
|
||||
}
|
||||
|
||||
DEF_nac3_rc_decr_(uint32_t);
|
||||
DEF_nac3_rc_decr_(uint64_t);
|
||||
DEF_nac3_rc_incr_(uint32_t);
|
||||
DEF_nac3_rc_incr_(uint64_t);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -618,6 +618,7 @@ pub fn gen_constructor<'ctx, 'a, G: CodeGenerator>(
|
||||
.build_bit_cast(zelf_intptr, zelf_ty.ptr_type(AddressSpace::default()), "malloc")
|
||||
.unwrap();
|
||||
|
||||
// TODO(HTGAzureX1212): size_t
|
||||
let void = ctx.ctx.void_type();
|
||||
call_extern!(ctx: void _ = "nac3_rc_incr"(zelf_intptr));
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ pub extern "C" fn delay_mu(dt: i64) {
|
||||
unsafe { NOW += dt }
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn rpc_send_async(_: u32, _: &[u8], _: *const *const ()) {}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn rtio_init() {
|
||||
println!("rtio_init");
|
||||
@@ -50,6 +53,11 @@ pub extern "C" fn __nac3_personality(_state: u32, _exception_object: u32, _conte
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn __nac3_resume() -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let filename = env::args().nth(1).unwrap();
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user