Skip to content

Commit

Permalink
Added support for passing arguments to lambda_wrapper and added corou…
Browse files Browse the repository at this point in the history
…tine_wrapper
  • Loading branch information
AjayBrahmakshatriya committed Dec 18, 2023
1 parent 5d2ffd2 commit ff0b0c1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ all: executables

CHECK_CONFIG=1
CONFIG_STR=DEBUG=$(DEBUG) RECOVER_VAR_NAMES=$(RECOVER_VAR_NAMES) TRACER_USE_LIBUNWIND=$(TRACER_USE_LIBUNWIND)
CONFIG_STR+=EXTRA_CFLAGS=$(EXTRA_CFLAGS)


# Create a scratch directory where the files are stored
$(shell mkdir -p $(BASE_DIR)/scratch)
Expand Down
7 changes: 4 additions & 3 deletions include/builder/builder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class tag_map {
std::unordered_map<std::string, block::stmt_block::Ptr> map;
};

void lambda_wrapper(void);
void lambda_wrapper(std::function<void(void)>);
void lambda_wrapper_close(void);
void lambda_wrapper_impl(void);

void coroutine_wrapper(std::function<void(void)>);
void coroutine_wrapper_close(void);

class builder_context {
public:
static builder_context *current_builder_context;
static int debug_creation_counter;

std::function<void(void)> internal_stored_lambda;
std::function<void(void)> current_function;

std::list<block::block::Ptr> uncommitted_sequence;
block::stmt::Ptr ast;
Expand Down
4 changes: 3 additions & 1 deletion make/setvars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ endif
DEBUG=1
endif

EXTRA_CFLAGS?=""

# Create CFLAGS, LINKER_FLAGS, CFLAGS_INTERNAL and INCLUDE_FLAGS based on config
CFLAGS_INTERNAL=-std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations
CFLAGS_INTERNAL+=-Woverloaded-virtual -Wno-deprecated -Wdelete-non-virtual-dtor -Werror -Wno-vla -pedantic-errors
CFLAGS_INTERNAL+=-Woverloaded-virtual -Wno-deprecated -Wdelete-non-virtual-dtor -Werror -Wno-vla -pedantic-errors
CFLAGS=
LINKER_FLAGS=-L$(BUILD_DIR)/ -l$(LIBRARY_NAME)
INCLUDE_FLAGS=-I$(INCLUDE_DIR) -I$(BUILD_DIR)/gen_headers/
Expand Down Expand Up @@ -49,4 +50,5 @@ endif


LINKER_FLAGS+=-ldl
CFLAGS+=$(EXTRA_CFLAGS)
# --- flags are all ready
5 changes: 1 addition & 4 deletions src/builder/builder_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ block::stmt::Ptr builder_context::extract_ast_from_function_internal(std::vector
try {
current_builder_context = this;
// function();
lambda_wrapper();
lambda_wrapper(internal_stored_lambda);
commit_uncommitted();
ret_ast = ast;
current_builder_context = nullptr;
Expand Down Expand Up @@ -463,8 +463,5 @@ block::stmt::Ptr builder_context::extract_ast_from_function_internal(std::vector
return ret_ast;
}

void lambda_wrapper_impl(void) {
builder_context::current_builder_context->internal_stored_lambda();
}

} // namespace builder
18 changes: 13 additions & 5 deletions src/builder/builder_context_support.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@

#include <functional>
namespace builder {
void lambda_wrapper_impl(void);
void lambda_wrapper(void);
void lambda_wrapper(std::function<void(void)>);
void lambda_wrapper_close(void);
void coroutine_wrapper(std::function<void(void)>);
void coroutine_wrapper_close(void);

int tail_call_guard;

void lambda_wrapper(void) {
lambda_wrapper_impl();
void lambda_wrapper(std::function<void(void)> f) {
f();
tail_call_guard += 1;
}
void lambda_wrapper_close(void) {}


void coroutine_wrapper(std::function<void(void)> f) {
f();
tail_call_guard +=1;
}
void coroutine_wrapper_close(void) {}
} // namespace builder
2 changes: 1 addition & 1 deletion src/util/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

namespace builder {
extern void lambda_wrapper(void);
extern void lambda_wrapper(std::function<void(void)>);
extern void lambda_wrapper_close(void);
} // namespace builder
namespace tracer {
Expand Down

0 comments on commit ff0b0c1

Please sign in to comment.