Mercurial > hg > Members > menikon > CbC_xv6
view src/gearsTools/lib/Gears/Context/Template/XV6.pm @ 238:e825c247ab24
build success
author | menikon |
---|---|
date | Wed, 29 Jan 2020 22:17:40 +0900 |
parents | 415081e357ec |
children | bc2f3d24faa9 |
line wrap: on
line source
package Gears::Context::Template::XV6; use strict; use warnings; sub emit_top_header { my ($class, $out) = @_; my $str = << 'EOFEOF'; /* Context definition for llrb example */ // #ifdef CBC_CONTEXT_H does not work well #define CBC_CONTEXT_H // #include <stdlib.h> // #include <pthread.h> #ifdef USE_CUDAWorker #include <cuda.h> #include <driver_types.h> #include <cuda_runtime.h> #include "helper_cuda.h" #endif #ifndef NULL # if defined __GNUG__ && \ (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) # define NULL (__null) # else # if !defined(__cplusplus) # define NULL ((void*)0) # else # define NULL (0) # endif # endif #endif #ifdef XV6KERNEL extern void* kmalloc (int order); #define calloc(a,b) kmalloc((a)*(b)) #define free(a) kfree(a) #else extern void* malloc(unsigned int sz); #define calloc(a,b) malloc((a)*(b)) #define free(a) free(a) #endif #define ALLOCATE_SIZE 20000000 #define NEW(type) (type*)(calloc(1, sizeof(type))) #define NEWN(n, type) (type*)(calloc(n, sizeof(type))) #define ALLOC_DATA(cbc_context, dseg) ({\ Meta* meta = (Meta*)cbc_context->heap;\ meta->type = D_##dseg;\ meta->size = sizeof(dseg);\ meta->len = 1;\ cbc_context->heap += sizeof(Meta);\ cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(dseg); (dseg *)cbc_context->data[D_##dseg]; }) #define ALLOC_DATA_TYPE(cbc_context, dseg, t) ({\ Meta* meta = (Meta*)cbc_context->heap;\ meta->type = D_##t;\ meta->size = sizeof(t);\ meta->len = 1;\ cbc_context->heap += sizeof(Meta);\ cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(t); (t *)cbc_context->data[D_##dseg]; }) #define ALLOCATE(cbc_context, t) ({ \ Meta* meta = (Meta*)cbc_context->heap;\ cbc_context->heap += sizeof(Meta);\ union Data* data = cbc_context->heap; \ cbc_context->heap += sizeof(t); \ meta->type = D_##t; \ meta->size = sizeof(t); \ meta->len = 1;\ data; }) #define ALLOCATE_ARRAY(cbc_context, t, length) ({ \ Meta* meta = (Meta*)cbc_context->heap;\ cbc_context->heap += sizeof(Meta);\ union Data* data = cbc_context->heap; \ cbc_context->heap += sizeof(t)*length; \ meta->type = D_##t; \ meta->size = sizeof(t)*length; \ meta->len = length; \ data; }) #define ALLOCATE_PTR_ARRAY(cbc_context, dseg, length) ({\ Meta* meta = (Meta*)cbc_context->heap;\ cbc_context->heap += sizeof(Meta);\ union Data* data = cbc_context->heap; \ cbc_context->heap += sizeof(dseg *)*length; \ meta->type = D_##dseg; \ meta->size = sizeof(dseg *)*length; \ meta->len = length; \ data; }) #define ALLOCATE_DATA_GEAR(cbc_context, t) ({ \ union Data* data = ALLOCATE(cbc_context, t); \ Meta* meta = GET_META(data); \ meta->wait = createSynchronizedQueue(cbc_context); \ data; }) #define ALLOC(cbc_context, t) (&ALLOCATE(cbc_context, t)->t) #define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta))) #define GET_TYPE(dseg) (GET_META(dseg)->type) #define GET_SIZE(dseg) (GET_META(dseg)->size) #define GET_LEN(dseg) (GET_META(dseg)->len) #define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait) #define Gearef(cbc_context, t) (&(cbc_context)->data[D_##t]->t) // (SingleLinkedStack *)cbc_context->data[D_Stack]->Stack.stack->Stack.stack #define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name) #include "c/enumCode.h" #include "types.h" enum Relational { EQ, GT, LT, }; #include "c/enumData.h" #define NDIRECT 12 //fs.h struct Context { enum Code next; struct Worker* worker; struct TaskManager* taskManager; int codeNum; __code (**code) (struct Context*); union Data **data; void* heapStart; void* heap; long heapLimit; int dataNum; // task parameter int idgCount; //number of waiting dataGear int idg; int maxIdg; int odg; int maxOdg; int gpu; // GPU task struct Context* task; struct Element* taskList; #ifdef USE_CUDAWorker int num_exec; CUmodule module; CUfunction function; #endif /* multi dimension parameter */ int iterate; struct Iterator* iterator; enum Code before; }; #include "spinlock.h" typedef int Int; #ifndef USE_CUDAWorker typedef unsigned long long CUdeviceptr; #endif typedef struct proc proc_struct; typedef uint32 pte_t; typedef uint32 pde_t; typedef struct stat stat; typedef struct superblock superblock; EOFEOF print $out $str; } sub emit_data_gears { my ($class, $out, $dgs) = @_; print $out "union Data {\n"; print $out $dgs; print $out <<'EOF'; #ifndef CbC_XV6_CONTEXT struct Context Context; }; // union Data end this is necessary for context generator typedef union Data Data; #endif EOF } sub emit_last_header { my($class, $out) = @_; print $out <<'EOF'; #include "c/typedefData.h" #include "c/extern.h" #define CbC_XV6_CONTEXT 1 extern __code start_code(struct Context* cbc_context); extern __code exit_code(struct Context* cbc_context); extern __code meta(struct Context* cbc_context, enum Code next); //extern __code par_meta(struct Context* cbc_context, enum Code spawns, enum Code next); extern __code parGotoMeta(struct Context* cbc_context, enum Code next); extern void initContext(struct Context* cbc_context); // #endif EOF } 1;