Mercurial > hg > Members > Moririn
changeset 4:cd262e34ac1a
allocate example
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Mar 2015 12:41:39 +0900 |
parents | e95bf956f853 |
children | b8066055e295 |
files | src/CMakeLists.txt src/Makefile src/allocate.c src/allocate.h |
diffstat | 4 files changed, 251 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/CMakeLists.txt Wed Mar 18 12:41:39 2015 +0900 @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8) +add_definitions("-Wall -g -O0") +add_executable(allocate allocate.c) +set(CMAKE_C_COMPILER /Users/e105744/Desktop/CbC_llvm/Release+Asserts/bin/clang)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Makefile Wed Mar 18 12:41:39 2015 +0900 @@ -0,0 +1,167 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.1 + +# Default target executed when no arguments are given to make. +default_target: all +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: +.PHONY : .NOTPARALLEL + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + +# A target that is always out of date. +cmake_force: +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/local/Cellar/cmake/3.1.3/bin/cmake + +# The command to remove a file. +RM = /usr/local/Cellar/cmake/3.1.3/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /Users/e105744/Desktop/Gears/src + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /Users/e105744/Desktop/Gears/src + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." + /usr/local/Cellar/cmake/3.1.3/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache +.PHONY : edit_cache/fast + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/local/Cellar/cmake/3.1.3/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache +.PHONY : rebuild_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /Users/e105744/Desktop/Gears/src/CMakeFiles /Users/e105744/Desktop/Gears/src/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /Users/e105744/Desktop/Gears/src/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named allocate + +# Build rule for target. +allocate: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 allocate +.PHONY : allocate + +# fast build rule for target. +allocate/fast: + $(MAKE) -f CMakeFiles/allocate.dir/build.make CMakeFiles/allocate.dir/build +.PHONY : allocate/fast + +allocate.o: allocate.c.o +.PHONY : allocate.o + +# target to build an object file +allocate.c.o: + $(MAKE) -f CMakeFiles/allocate.dir/build.make CMakeFiles/allocate.dir/allocate.c.o +.PHONY : allocate.c.o + +allocate.i: allocate.c.i +.PHONY : allocate.i + +# target to preprocess a source file +allocate.c.i: + $(MAKE) -f CMakeFiles/allocate.dir/build.make CMakeFiles/allocate.dir/allocate.c.i +.PHONY : allocate.c.i + +allocate.s: allocate.c.s +.PHONY : allocate.s + +# target to generate assembly for a file +allocate.c.s: + $(MAKE) -f CMakeFiles/allocate.dir/build.make CMakeFiles/allocate.dir/allocate.c.s +.PHONY : allocate.c.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... edit_cache" + @echo "... rebuild_cache" + @echo "... allocate" + @echo "... allocate.o" + @echo "... allocate.i" + @echo "... allocate.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system +
--- a/src/allocate.c Tue Mar 17 11:29:17 2015 +0900 +++ b/src/allocate.c Wed Mar 18 12:41:39 2015 +0900 @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "allocate.h" + +#ifdef CLANG +#define _CbC_retrun __return +#define _CbC_environment __environment +#endif + +typedef struct DataSegment1 { + int i; // 4 byte + char c; // 1 byte + // padding 3 byte +} ds, *dsptr; // 8 byte + +typedef struct metaDataSegment1 { + size_t size; // 8 byte + dsptr ds; // 8 byte +} mds, *mdsptr; // 16 byte + +typedef struct Context { + dsptr ds; + mdsptr mds; + dsptr ds_heap; + mdsptr mds_heap; +} context, *contextptr; + +__code start_code(contextptr context) { + goto meta_start_code(context); +} + +__code meta_start_code(contextptr context) { + goto code1(context); +} + +__code code1(contextptr context) { + goto meta_code1(context); +} + +__code meta_code1(contextptr context) { + goto allocate(context, 10); +} + +__code allocate(contextptr context, int size) { + dsptr in = context->ds; + context->ds += size; + context->mds->ds = in; + context->mds->size = context->ds - in; + context->mds++; + goto meta_allocate(context, in); +} + +__code meta_allocate(contextptr context, dsptr in) { + goto exit_code(context, in, 0); +} + +__code exit_code(contextptr context, dsptr in, int i) { + in[i].i = i; + printf("%d\n", in[i].i); + if (i == 10) + goto exit(0); + goto exit_code(context, in, ++i); +} + +int main() { + contextptr context = (contextptr)malloc(sizeof(contextptr)); + context->ds_heap = (dsptr)malloc(sizeof(ds)*1024); + context->mds_heap = (mdsptr)malloc(sizeof(mds)*1024); + context->ds = context->ds_heap; + context->mds = context->mds_heap; + goto start_code(context); +}