Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move C convenience functions to own file

  • Loading branch information...
commit 5f4d8aeec360333962460637c6acc7f6645b3e4e 1 parent ac92d14
@pkhuong authored
Showing with 164 additions and 155 deletions.
  1. +164 −0 vlbdb_convenience.c
  2. +0 −155 vlbdb_impl.cpp
View
164 vlbdb_convenience.c
@@ -0,0 +1,164 @@
+#include "vlbdb.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <limits.h>
+
+void * vlbdb_specializef (vlbdb_unit_t * unit, void * function,
+ const char * format, ...)
+{
+ va_list values;
+ va_start(values, format);
+ return vlbdb_vspecializef(unit, function, format, values);
+}
+
+void * vlbdb_block_specializef (vlbdb_unit_t * unit, void * block,
+ const char * format, ...)
+{
+ va_list values;
+ va_start(values, format);
+ return vlbdb_vblock_specializef(unit, block, format, values);
+}
+
+void * vlbdb_vspecializef (vlbdb_unit_t * unit, void * function,
+ const char * format, va_list values)
+{
+ vlbdb_binder_t * binder = vlbdb_binder_create(unit, function);
+ vlbdb_vbindf(binder, format, values);
+ return vlbdb_specialize(binder);
+}
+
+void * vlbdb_vblock_specializef (vlbdb_unit_t * unit, void * block,
+ const char * format, va_list values)
+{
+ vlbdb_binder_t * binder = vlbdb_binder_create_block(unit, block);
+ vlbdb_vbindf(binder, format, values);
+ return vlbdb_specialize(binder);
+}
+
+void * vlbdb_block_specialize(vlbdb_unit_t * unit, void * block)
+{
+ vlbdb_binder_t * binder = vlbdb_binder_create_block(unit, block);
+ return vlbdb_specialize(binder);
+}
+
+void vlbdb_bindf (vlbdb_binder_t * binder, const char * format, ...)
+{
+ va_list values;
+ va_start(values, format);
+ return vlbdb_vbindf(binder, format, values);
+}
+
+static const char *
+bind_one_argf (vlbdb_binder_t * binder, const char * format, va_list values)
+{
+ int have_width = 0;
+ long width = 0;
+ enum {normal, l, z, ll} modifier = normal;
+ int after_point = 0;
+
+ for (; *format != '\0'; format++) {
+ switch(*format) {
+ case '*':
+ case '-': case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ {
+ int value = 0;
+ have_width = 1;
+ if (*format == '*') {
+ value = va_arg(values, int);
+ } else {
+ value = strtol(format, (char**)&format, 10);
+ format--;
+ }
+ if (!after_point)
+ width = value;
+ break;
+ }
+ case '.':
+ after_point = 1;
+ break;
+ case 'h': break;
+ case 'l':
+ if (modifier == normal)
+ modifier = l;
+ else modifier = ll;
+ break;
+ case 'j':
+ modifier = ll;
+ break;
+ case 'z':
+ case 't':
+ modifier = z;
+ break;
+ case 'd': case 'i':
+ {
+ long long i = 0;
+ if (modifier == normal)
+ i = va_arg(values, int);
+ else if (modifier < ll)
+ i = va_arg(values, long);
+ else i = va_arg(values, long long);
+ vlbdb_bind_int(binder, i);
+ return format;
+ }
+ case 'c':
+ assert(modifier == normal);
+ case 'o': case 'u': case 'x': case 'X':
+ {
+ unsigned long long u = 0;
+ if (modifier == normal)
+ u = va_arg(values, unsigned);
+ else if (modifier < ll)
+ u = va_arg(values, unsigned long);
+ else u = va_arg(values, unsigned long long);
+ vlbdb_bind_uint(binder, u);
+ return format+1;
+ }
+ case 'f': case 'F': case 'e': case 'E':
+ case 'g': case 'G': case 'a': case 'A':
+ {
+ double fp = va_arg(values, double);
+ vlbdb_bind_fp(binder, fp);
+ return format;
+ }
+ case 'p':
+ {
+ void * ptr = va_arg(values, void*);
+ if ((!have_width) || (width == 0)) {
+ vlbdb_bind_ptr(binder, ptr);
+ } else if (width < 0) {
+ assert (0);
+ /* vlbdb_register_range(binder->unit, */
+ /* ptr, -width); */
+ /* vlbdb_bind_ptr(binder, ptr); */
+ } else if (width > 0) {
+ vlbdb_bind_range(binder, ptr, width);
+ } else {
+ assert(0);
+ }
+ return format;
+ }
+ case '%': break;
+ default:
+ assert(0);
+ break;
+ }
+ }
+ return format;
+}
+
+void vlbdb_vbindf (vlbdb_binder_t * binder, const char * format, va_list values)
+{
+ for (; *format != '\0'; format++) {
+ if (*format == '%')
+ format = bind_one_argf(binder, format+1, values);
+ }
+ va_end(values);
+}
+
+void * vlbdb_specialize (vlbdb_binder_t * binder)
+{
+ void * ret = vlbdb_specialize_retain(binder);
+ vlbdb_binder_destroy(binder);
+ return ret;
+}
View
155 vlbdb_impl.cpp
@@ -223,44 +223,6 @@ vlbdb_register_block (vlbdb_unit_t * unit, void * ptr, size_t nspecialize)
return vlbdb_register_function(unit, block->invoke, nspecialize+1, NULL);
}
-void * vlbdb_specializef (vlbdb_unit_t * unit, void * function,
- const char * format, ...)
-{
- va_list values;
- va_start(values, format);
- return vlbdb_vspecializef(unit, function, format, values);
-}
-
-void * vlbdb_block_specializef (vlbdb_unit_t * unit, void * block,
- const char * format, ...)
-{
- va_list values;
- va_start(values, format);
- return vlbdb_vblock_specializef(unit, block, format, values);
-}
-
-void * vlbdb_vspecializef (vlbdb_unit_t * unit, void * function,
- const char * format, va_list values)
-{
- vlbdb_binder_t * binder = vlbdb_binder_create(unit, function);
- vlbdb_vbindf(binder, format, values);
- return vlbdb_specialize(binder);
-}
-
-void * vlbdb_vblock_specializef (vlbdb_unit_t * unit, void * block,
- const char * format, va_list values)
-{
- vlbdb_binder_t * binder = vlbdb_binder_create_block(unit, block);
- vlbdb_vbindf(binder, format, values);
- return vlbdb_specialize(binder);
-}
-
-void * vlbdb_block_specialize(vlbdb_unit_t * unit, void * block)
-{
- vlbdb_binder_t * binder = vlbdb_binder_create_block(unit, block);
- return vlbdb_specialize(binder);
-}
-
std::pair<GlobalVariable *, bool>
find_intern_range (vlbdb_unit_t * unit, void * ptr, size_t size)
{
@@ -362,116 +324,6 @@ void vlbdb_bind_range(vlbdb_binder_t * binder, void * address, size_t size)
binder->args.push_back(ConstantExpr::getBitCast(var, ptr));
}
-void vlbdb_bindf (vlbdb_binder_t * binder, const char * format, ...)
-{
- va_list values;
- va_start(values, format);
- return vlbdb_vbindf(binder, format, values);
-}
-
-static const char *
-bind_one_argf (vlbdb_binder_t * binder, const char * format, va_list values)
-{
- bool have_width = false;
- long width = 0;
- enum {normal, l, z, ll} modifier = normal;
- bool after_point = false;
-
- for (; *format != '\0'; format++) {
- switch(*format) {
- case '*':
- case '-': case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- if (after_point) break;
- have_width = true;
- if (*format == '*') {
- width = va_arg(values, int);
- } else {
- width = strtol(format, (char**)&format, 10);
- format--;
- }
- break;
- case '.':
- after_point = true;
- break;
- case 'h': break;
- case 'l':
- if (modifier == normal)
- modifier = l;
- else modifier = ll;
- break;
- case 'j':
- modifier = ll;
- break;
- case 'z':
- case 't':
- modifier = z;
- break;
- case 'd': case 'i':
- {
- long long i = 0;
- if (modifier == normal)
- i = va_arg(values, int);
- else if (modifier < ll)
- i = va_arg(values, long);
- else i = va_arg(values, long long);
- vlbdb_bind_int(binder, i);
- return format;
- }
- case 'c':
- assert(modifier == normal);
- case 'o': case 'u': case 'x': case 'X':
- {
- unsigned long long u = 0;
- if (modifier == normal)
- u = va_arg(values, unsigned);
- else if (modifier < ll)
- u = va_arg(values, unsigned long);
- else u = va_arg(values, unsigned long long);
- vlbdb_bind_uint(binder, u);
- return format+1;
- }
- case 'f': case 'F': case 'e': case 'E':
- case 'g': case 'G': case 'a': case 'A':
- {
- double fp = va_arg(values, double);
- vlbdb_bind_fp(binder, fp);
- return format;
- }
- case 'p':
- {
- void * ptr = va_arg(values, void*);
- if (!have_width) {
- vlbdb_bind_ptr(binder, ptr);
- } else if (width < 0) {
- vlbdb_register_range(binder->unit,
- ptr, -width);
- vlbdb_bind_ptr(binder, ptr);
- } else if (width > 0) {
- vlbdb_bind_range(binder, ptr, width);
- } else {
- assert(0);
- }
- return format;
- }
- case '%': break;
- default:
- assert(0);
- break;
- }
- }
- return format;
-}
-
-void vlbdb_vbindf (vlbdb_binder_t * binder, const char * format, va_list values)
-{
- for (; *format != '\0'; format++) {
- if (*format == '%')
- format = bind_one_argf(binder, format+1, values);
- }
- va_end(values);
-}
-
void * vlbdb_specialize_retain (vlbdb_binder_t * binder)
{
vlbdb_unit_t * unit = binder->unit;
@@ -480,10 +332,3 @@ void * vlbdb_specialize_retain (vlbdb_binder_t * binder)
unit->ptr_to_function[binary] = specialized;
return binary;
}
-
-void * vlbdb_specialize (vlbdb_binder_t * binder)
-{
- void * ret = vlbdb_specialize_retain(binder);
- vlbdb_binder_destroy(binder);
- return ret;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.