Skip to content

Commit

Permalink
A ton of changes, especially to the build system, structure and suppo…
Browse files Browse the repository at this point in the history
…rt functions
  • Loading branch information
rsms committed Oct 11, 2012
1 parent 1ccd67a commit 39a11af
Show file tree
Hide file tree
Showing 21 changed files with 566 additions and 152 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.DS_Store
build
test/map

lab
36 changes: 24 additions & 12 deletions Make.common
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,55 @@ OS = $(shell uname -s)
# Dependencies
DEPS_PREFIX := $(SRCROOT)/deps

# Build target type
ifeq ($(strip $(DEBUG)),1)
BUILD_TARGET_TYPE = debug
else
BUILD_TARGET_TYPE = release
endif

# Build directories
BUILD_PREFIX := $(SRCROOT)/build
INCLUDE_BUILD_PREFIX := $(BUILD_PREFIX)/include
BUILD_TARGET_PREFIX := $(BUILD_PREFIX)/$(BUILD_TARGET_TYPE)
TESTS_BUILD_PREFIX := $(BUILD_PREFIX)/test
LIB_BUILD_PREFIX := $(BUILD_PREFIX)/lib
BIN_BUILD_PREFIX := $(BUILD_PREFIX)/bin
INCLUDE_BUILD_PREFIX := $(BUILD_TARGET_PREFIX)/include
LIB_BUILD_PREFIX := $(BUILD_TARGET_PREFIX)/lib
BIN_BUILD_PREFIX := $(BUILD_TARGET_PREFIX)/bin
DEBUG_BUILD_PREFIX := $(BUILD_TARGET_PREFIX)/debug

OBJECT_DIR := $(BUILD_PREFIX)/.objs
OBJECT_DIR := $(BUILD_TARGET_PREFIX)/.objs

# Tools
CC = clang
CXXC = clang++
LD = clang
AR = ar

# $(call UpperCase,foo_bar) -> FOO_BAR
UpperCase = $(shell echo $(1) | tr a-z A-Z)

# Compiler and Linker flags for all targets
CFLAGS += -Wall -g -MMD -I$(INCLUDE_BUILD_PREFIX)
CFLAGS += -Wall -g -std=c99 -MMD -I$(INCLUDE_BUILD_PREFIX) -arch $(TARGETARCH)
CXXFLAGS += -std=c++11 -fno-rtti
#LDFLAGS +=
LDFLAGS += -arch $(TARGETARCH)
XXLDFLAGS += -lc++ -lstdc++

# Compiler and Linker flags for release and debug targets (e.g. make DEBUG=1)
ifneq ($(DEBUG),)
CFLAGS += -O0 -DFB_DEBUG=1 #-gdwarf2
ifeq ($(strip $(DEBUG)),1)
CFLAGS += -O0 -DS_DEBUG=1
#LDFLAGS +=
else
CFLAGS += -O3 -DNDEBUG
CFLAGS += -O3 -DS_DEBUG=0 -DNDEBUG
#LDFLAGS +=
endif

# Functions

# (call PubHeaderNames,<header_pub_dir>,<list of header files>) -> <list of pub header files>
# $(call PubHeaderNames,<header_pub_dir>,<list of header files>) -> <list of pub header files>
PubHeaderNames = $(patsubst %,$(1)/%,$(2))

# (call FileDirs,<list of files>) -> <unique list of dirs>
# $(call FileDirs,<list of files>) -> <unique list of dirs>
FileDirs = $(sort $(foreach fn,$(1),$(dir $(fn))))

# (call SrcToObjects,<objdir>,<list of source files>) -> <list of objects>
# $(call SrcToObjects,<objdir>,<list of source files>) -> <list of objects>
SrcToObjects = $(patsubst %,$(1)/%,$(2))
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Sol

A sunny little programming language on a register-based virtual machine.


## VM design

Each scheduler has one run queue in which tasks are queued for execution

VM
Scheduler N
Run queue
Tasks
(Task migration)

When more than one scheduler is running, tasks might migrate from one scheduler
to another.


## Building

Build Sol and run tests (when in the same directory as this README file):

make

Build Sol in debug mode

make DEBUG=1 sol

Run the debug version of Sol

./build/debug/bin/sol

Run tests and potentially build Sol and affected tests:

make test


# MIT License

Copyright (c) 2012 Rasmus Andersson <http://rsms.me/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
49 changes: 42 additions & 7 deletions sol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ include ../Make.common
# Sources
cxx_sources :=

c_sources := main.c vm.c sched.c task.c
c_sources := main.c \
log.c host.c \
sched.c task.c

headers_pub := sol.h common.h debug.h stdint.h \
instr.h vm.h sched.h task.h
headers_pub := sol.h \
common.h common_target.h common_stdint.h \
debug.h log.h host.h \
instr.h vm.h sched.h runq.h task.h

# --- conf ---------------------------------------------------------------------

Expand All @@ -18,11 +22,21 @@ objects = $(call SrcToObjects,$(object_dir),${cxx_sources:.cc=.o} ${c_sources:.c
object_dirs = $(call FileDirs,$(objects))
-include ${objects:.o=.d} # header dependencies

# For LLVM IR and Assembly output
asmout_dir = $(DEBUG_BUILD_PREFIX)/$(project_id)-asm
asmout_ll = $(call SrcToObjects,$(asmout_dir),${cxx_sources:.cc=.ll} ${c_sources:.c=.ll})
asmout_ll_dirs = $(call FileDirs,$(asmout_ll))
asmout_s = $(call SrcToObjects,$(asmout_dir),${cxx_sources:.cc=.s} ${c_sources:.c=.s})
asmout_s_dirs = $(call FileDirs,$(asmout_s))

# Public headers
headers_pub_dir = $(INCLUDE_BUILD_PREFIX)/$(project_id)
headers_pub_export = $(call PubHeaderNames,$(headers_pub_dir),$(headers_pub))
headers_pub_export_dirs = $(call FileDirs,$(headers_pub_export))

# Sol program
main_program = $(BIN_BUILD_PREFIX)/$(project_id)

# Compiler and linker flags
c_flags := $(CFLAGS)
cxx_flags := $(CXXFLAGS)
Expand All @@ -36,12 +50,15 @@ all: $(project_id)
clean:
rm -rf $(object_dir)
rm -rf $(headers_pub_export)
rm -rf $(asmout_dir)
rm -f $(main_program)
# rm -rf $(LIB_BUILD_PREFIX)/lib$(project_id).a

common_prebuild:
@mkdir -p $(LIB_BUILD_PREFIX)
@mkdir -p $(dir $(main_program))
@mkdir -p $(object_dirs)
@mkdir -p $(headers_pub_export_dirs)
# @mkdir -p $(LIB_BUILD_PREFIX)

$(project_id): common_prebuild $(headers_pub_export)
#$(LIB_BUILD_PREFIX)/lib$(project_id).a
Expand All @@ -51,12 +68,22 @@ $(project_id): common_prebuild $(headers_pub_export)
# $(AR) -rcL $@ $^

# Create program
$(project_id): common_prebuild $(BIN_BUILD_PREFIX)/$(project_id)
#$(BIN_BUILD_PREFIX)/$(project_id): $(LIB_BUILD_PREFIX)/lib$(project_id).a
$(BIN_BUILD_PREFIX)/$(project_id): $(objects)
$(project_id): common_prebuild $(main_program)
#$(main_program): $(LIB_BUILD_PREFIX)/lib$(project_id).a
$(main_program): $(objects)
$(LD) $(ld_flags) -o $@ $^
# $(LD) $(xxld_flags) $(ld_flags) -o $@ $^

# Generate LLVM IS code (.ll files)
llvm_ir_prebuild: common_prebuild
@mkdir -p $(asmout_ll_dirs)
llvm_ir: llvm_ir_prebuild $(asmout_ll)

# Generate target assembly code (.s files)
asm_prebuild: common_prebuild
@mkdir -p $(asmout_s_dirs)
asm: asm_prebuild $(asmout_s)

# C++ source -> object
$(object_dir)/%.o: %.cc
$(CXXC) $(c_flags) $(cxx_flags) -c -o $@ $<
Expand All @@ -65,6 +92,14 @@ $(object_dir)/%.o: %.cc
$(object_dir)/%.o: %.c
$(CC) $(c_flags) -c -o $@ $<

# C source -> LLVM IR
$(asmout_dir)/%.ll: %.c
clang $(CFLAGS) -S -emit-llvm -DS_CODEGEN_ASM=1 -DS_CODEGEN_LLVMIR=1 -o $@ $<

# C source -> target assembly
$(asmout_dir)/%.s: %.c
$(CC) $(CFLAGS) -S -DS_CODEGEN_ASM=1 -o $@ $<

# Copy headers into $headers_pub_dir
$(headers_pub_dir)/%: %
@cp $^ $@
Expand Down
43 changes: 30 additions & 13 deletions sol/common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
#ifndef S_COMMON_H_
#define S_COMMON_H_
#define S_COMMON_H_INSIDE_

#define S_STR1(str) #str
#define S_STR(str) S_STR1(str)

#define S_VERSION_MAJOR 0
#define S_VERSION_MINOR 1
#define S_VERSION_BUILD 0
#define S_VERSION_STRING \
S_STR(S_VERSION_MAJOR) "." S_STR(S_VERSION_MINOR) "." S_STR(S_VERSION_BUILD)

#ifndef S_DEBUG
#define S_DEBUG 0
#endif

#include <sol/common_target.h>

#ifdef __BASE_FILE__
#define S_FILENAME __BASE_FILE__
#else
#define S_FILENAME ((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)
#endif

#define S_countof(a) (sizeof(a)/sizeof(*(a)))

// Attributes
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
Expand All @@ -13,11 +38,6 @@
#else
#define S_ALWAYS_INLINE
#endif
#if __has_attribute(deprecated)
#define S_DEPRECATED __attribute__((deprecated))
#else
#define S_DEPRECATED
#endif
#if __has_attribute(deprecated)
#define S_UNUSED __attribute__((unused))
#else
Expand All @@ -33,7 +53,6 @@
#else
#define S_WUNUSEDR
#endif

#if __has_builtin(__builtin_unreachable)
#define S_UNREACHABLE do { \
assert(!"UNREACHABLE"); \
Expand All @@ -44,17 +63,15 @@
assert(!"UNREACHABLE")
#endif

#define S_countof(a) (sizeof(a)/sizeof(*(a)))

#define S_STR1(str) #str
#define S_STR(str) S_STR1(str)

#include <sol/stdint.h> // .. include <std{io,int,def,bool}>
#include <sol/common_stdint.h> // .. include <std{io,int,def,bool}>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#define SNil 0
#if S_HOST_OS_POSIX
#include <unistd.h>
#endif

#undef S_COMMON_H_INSIDE_
#endif // S_COMMON_H_
9 changes: 4 additions & 5 deletions sol/stdint.h → sol/common_stdint.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef SOL_STDINT_H
#define SOL_STDINT_H
#ifndef S_COMMON_H_INSIDE_
#error "This file should not be included directly"
#endif

#include <stddef.h>
#include <stdio.h>
#include <stdio.h> // size_t, ssize_t, off_t

#if defined(_WIN32) && !defined(__MINGW32__)
typedef signed char int8_t;
Expand All @@ -19,5 +20,3 @@
#include <stdint.h>
#include <stdbool.h>
#endif

#endif
Loading

0 comments on commit 39a11af

Please sign in to comment.