Skip to content

Commit

Permalink
Initial block support
Browse files Browse the repository at this point in the history
  • Loading branch information
pkhuong committed Oct 18, 2011
1 parent cb51cdc commit 5151341
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 3 additions & 3 deletions vlbdb.h
Expand Up @@ -16,14 +16,14 @@ vlbdb_unit_t * vlbdb_unit_from_bitcode (const char *, void * context);
void vlbdb_unit_destroy (vlbdb_unit_t *);

vlbdb_binder_t * vlbdb_binder_create (vlbdb_unit_t *, void *);
vlbdb_binder_t * vlbdb_binder_create_block (vlbdb_unit_t *, void *); /* TODO */
vlbdb_binder_t * vlbdb_binder_create_block (vlbdb_unit_t *, void *);
vlbdb_binder_t * vlbdb_binder_copy (vlbdb_binder_t *);
void vlbdb_binder_destroy (vlbdb_binder_t *);

void vlbdb_register_function (vlbdb_unit_t *, void *, size_t, const char *);
void vlbdb_register_function_name (vlbdb_unit_t *, const char *, size_t);

void vlbdb_register_block (vlbdb_unit_t *, void *, size_t); /* TODO */
void vlbdb_register_block (vlbdb_unit_t *, void *, size_t);

/* TODO */
void * vlbdb_specializef(vlbdb_unit_t *, void * function, const char *, ...);
Expand All @@ -32,7 +32,7 @@ void * vlbdb_block_specializef(vlbdb_unit_t *, void * function, const char *, ..
void * vlbdb_vblock_specializef(vlbdb_unit_t *, void * function, const char *, va_list);

int vlbdb_intern_range (vlbdb_unit_t *, void *, size_t);
int vlbdb_register_range (vlbdb_unit_t *, void *, size_t); /* TODO */
int vlbdb_register_range (vlbdb_unit_t *, void *, size_t);

void vlbdb_bind_uint(vlbdb_binder_t *, unsigned long long);
void vlbdb_bind_int(vlbdb_binder_t *, long long);
Expand Down
19 changes: 17 additions & 2 deletions vlbdb_impl.cpp
Expand Up @@ -89,6 +89,15 @@ vlbdb_binder_create (vlbdb_unit_t * unit, void * base)
return new vlbdb_binder_t(unit, base);
}

vlbdb_binder_t *
vlbdb_binder_create_block (vlbdb_unit_t * unit, void * ptr)
{
Block_literal * block = (Block_literal*)ptr;
vlbdb_binder_t * binder = vlbdb_binder_create(unit, block->invoke);
vlbdb_bind_range(binder, ptr, block->descriptor->size);
return binder;
}

vlbdb_binder_t *
vlbdb_binder_copy (vlbdb_binder_t * binder)
{
Expand Down Expand Up @@ -153,6 +162,12 @@ vlbdb_register_function_name (vlbdb_unit_t * unit, const char * name,
return vlbdb_register_function(unit, NULL, nspecialize, name);
}

void
vlbdb_register_block (vlbdb_unit_t * unit, void * ptr, size_t nspecialize)
{
Block_literal * block = (Block_literal*)ptr;
return vlbdb_register_function(unit, block->invoke, nspecialize+1, NULL);
}

static std::pair<GlobalVariable *, bool>
find_intern_range (vlbdb_unit_t * unit, void * ptr, size_t size)
Expand Down Expand Up @@ -639,10 +654,10 @@ process_call (vlbdb_unit_t * unit, CallInst * call)
if (ConstantExpr * expr = dyn_cast<ConstantExpr>(con)) {
if (Constant * optimized
= (ConstantFoldConstantExpression
(expr, info->target_data)))
(expr, unit->target_data)))
con = optimized;
}
constants.push_back();
constants.push_back(con);
} else {
constant_prefix = false;
}
Expand Down
19 changes: 19 additions & 0 deletions vlbdb_impl.hpp
Expand Up @@ -107,6 +107,25 @@ struct binder_impl
}
};

// see http://clang.llvm.org/docs/Block-ABI-Apple.txt

struct Block_literal {
void *isa; // initialized to &_NSConcreteStackBlock or &_NSConcreteGlobalBlock
int flags;
int reserved;
void *invoke;
struct Block_descriptor {
unsigned long int reserved; // NULL
unsigned long int size; // sizeof(struct Block_literal)
// optional helper functions
void (*copy_helper)(void *dst, void *src); // IFF (1<<25)
void (*dispose_helper)(void *src); // IFF (1<<25)
// required ABI.2010.3.16
const char *signature; // IFF (1<<30)
} *descriptor;
// tail
};

template <typename Map, typename Key>
static bool exists (const Map &map, const Key &key)
{
Expand Down

0 comments on commit 5151341

Please sign in to comment.