parent
e917cb8d8f
commit
4f9278d4b7
@ -1 +1,74 @@
|
||||
PROJECT=sm
|
||||
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
|
||||
|
||||
SRC_C = $(wildcard src/*.c)
|
||||
SRC_CXX = $(wildcard src/*.cpp)
|
||||
|
||||
INCLUDE=include
|
||||
|
||||
COMMON_FLAGS= -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE))
|
||||
|
||||
OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \
|
||||
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
|
||||
-fno-stack-check
|
||||
|
||||
CXX_OPT_FLAGS?= $(OPT_FLAGS) -felide-constructors
|
||||
|
||||
CFLAGS += $(COMMON_FLAGS) --std=gnu11
|
||||
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -fno-exceptions
|
||||
LDFLAGS +=
|
||||
|
||||
STRIP=strip
|
||||
|
||||
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
|
||||
RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS)
|
||||
RELEASE_LDFLAGS?= -O3 -flto
|
||||
|
||||
DEBUG_CFLAGS?= -O0 -g -DDEBUG
|
||||
DEBUG_CXXFLAGS?= $(DEBUG_CFLAGS)
|
||||
DEBUG_LDFLAGS?=
|
||||
|
||||
# Objects
|
||||
|
||||
OBJ_C = $(addprefix obj/c/,$(SRC_C:.c=.o))
|
||||
OBJ_CXX = $(addprefix obj/cxx/,$(SRC_CXX:.cpp=.o))
|
||||
OBJ = $(OBJ_C) $(OBJ_CXX)
|
||||
|
||||
# Phonies
|
||||
|
||||
.PHONY: release
|
||||
release: | dirs $(PROJECT)-release
|
||||
|
||||
.PHONY: debug
|
||||
debug: | dirs $(PROJECT)-debug
|
||||
|
||||
# Targets
|
||||
|
||||
dirs:
|
||||
@mkdir -p obj/c{,xx}/src
|
||||
|
||||
obj/c/%.o: %.c
|
||||
$(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS)
|
||||
|
||||
obj/cxx/%.o: %.cpp
|
||||
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
|
||||
|
||||
$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS)
|
||||
$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS)
|
||||
$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS)
|
||||
$(PROJECT)-release: $(OBJ)
|
||||
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
||||
$(STRIP) $@
|
||||
|
||||
$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS)
|
||||
$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS)
|
||||
$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS)
|
||||
$(PROJECT)-debug: $(OBJ)
|
||||
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
||||
|
||||
clean-rebuild:
|
||||
rm -rf obj
|
||||
|
||||
clean: clean-rebuild
|
||||
rm -f $(PROJECT)-{release,debug,pgo}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "frame.h"
|
||||
|
||||
typedef void* (*sm_yield)(sm_state* state); //NOTE: This `void*` is a stand-in for this function returning itself.
|
||||
|
||||
template<typename T, typename U>
|
||||
inline T* _sm_var(sm_state* state, U name, T init)
|
||||
{
|
||||
auto val = &state->current->user.data[name];
|
||||
bool set = val->set;
|
||||
val->set = true;
|
||||
val->free = false;
|
||||
return ( ! set ) ?
|
||||
_sm_init<T>(val, init) :
|
||||
_sm_get<T>(val);
|
||||
}
|
||||
template<uint64_t name, typename T>
|
||||
inline T* _sm_var(sm_state* state, T init)
|
||||
{
|
||||
static_assert(name < _SM_STACK_SIZE, "Line pseudo-hashmap not yet implemented");
|
||||
return _sm_var(state, name, init);
|
||||
}
|
||||
|
||||
// Pop the current stack frame, and re-set the pointer to the previous one.
|
||||
void _sm_pop_stack(sm_state* state);
|
||||
|
||||
sm_yield _sm_noop(sm_state*);
|
||||
|
||||
inline sm_yield sm_end() { return (sm_yield)nullptr; }
|
||||
inline sm_yield sm_continue() { return (sm_yield)_sm_noop; }
|
||||
|
||||
#define SM_VAR_EX(name, init) _sm_var(state, (name), (init)) //TODO: Replace `name' with (__LINE__ % _SM_STACK_SIZE) pseudo-hashmap
|
||||
#define SM_VAR(init) _sm_var<__LINE__, decltype(init)>(state, (init))
|
||||
|
||||
#define SM_BEGIN switch(state->current->pc) { case 0:
|
||||
#define SM_END } _sm_pop_stack(state); return sm_end()
|
||||
|
||||
#define SM_YIELD(v) do { state->current->pc = __LINE__; return (sm_yield)(v); case __LINE__:; } while(0)
|
||||
|
@ -0,0 +1,6 @@
|
||||
#include <state.h>
|
||||
|
||||
sm_yield _sm_noop(sm_state*)
|
||||
{
|
||||
return (sm_yield)nullptr;
|
||||
}
|
Loading…
Reference in new issue