Skip to content

Commit

Permalink
bugfix for passing closures, more automated image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
chzchzchz committed Sep 29, 2010
1 parent 2a46e75 commit be6d6aa
Show file tree
Hide file tree
Showing 21 changed files with 347 additions and 40 deletions.
5 changes: 2 additions & 3 deletions fs/ext2.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ u32 indir_count(ext2_indir_block id)
type ext2_indir_block
points_range(
i, 1, indir_count(ext2_indir_block),
disk.blocks[blk_ptr[i] - blocks_off(disk.sb)].data_blk)
disk.blocks[blk_ptr[i-1] - blocks_off(disk.sb)].data_blk)
{
u32 blk_ptr[get_block_size()/4];
}
Expand Down Expand Up @@ -354,7 +354,6 @@ sum(s_free_inodes_c)
set_bytes(1024);
}

/* XXX add points-to here */
type ext2_inode
assert (? is_fast_symlink(ext2_inode) || i_block_direct[0] != 0)
virtual_if(
Expand Down Expand Up @@ -416,7 +415,7 @@ points_if(
}

type ext2_dir_entry
points(ino_by_num(inode))
points_if(? inode > 0, ino_by_num(inode))
{
u32 inode; /* inode number */
u16 rec_len; /* de length */
Expand Down
22 changes: 22 additions & 0 deletions img/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all: ext2.img vfat.img nilfs.img

format: ext2.img vfat.img nilfs.img
./loopback_fs_setup.sh ext2.img ext2 && ./gen_files.sh && ./loopback_fs_teardown.sh
./loopback_fs_setup.sh vfat.img vfat && ./gen_files.sh && ./loopback_fs_teardown.sh
./loopback_fs_setup.sh nilfs.img nilfs2 && ./gen_files.sh && ./loopback_fs_teardown.sh

clean:
rm -f *.img


ext2.img:
dd if=/dev/zero of=ext2.img bs=`expr 1024 \* 1024` count=100
yes | /sbin/mkfs.ext2 ext2.img

vfat.img:
dd if=/dev/zero of=vfat.img bs=`expr 1024 \* 1024` count=100
yes | /usr/sbin/mkfs.vfat vfat.img

nilfs.img:
dd if=/dev/zero of=nilfs.img bs=`expr 1024 \* 1024` count=256
yes | /sbin/mkfs.nilfs2 -L mkfsnilfs -b 4096 nilfs.img
15 changes: 15 additions & 0 deletions img/gen_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash


sudo chmod -R 777 /mnt/FSTEST

for a in `seq 5`; do
echo "A$a" >/mnt/FSTEST/"$a".aaa
done

for b in `seq 5`; do
mkdir -p /mnt/FSTEST/"$b"d
for a in `seq 5`; do
echo "AAA$a" >/mnt/FSTEST/"$b"d/$a.qqq
done
done
35 changes: 35 additions & 0 deletions img/loopback_fs_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# associate image with lo, mount fs image

FS_IMAGE="$1"
FS_TYPE="$2"

if [ -z $FS_IMAGE ]; then
echo "No file given!"
exit -1
fi

sudo /sbin/losetup /dev/loop5 "$FS_IMAGE"

retval=$?
if [ $retval -ne 0 ]; then
exit $retval
fi

FLAGS=""
if [ "$FS_TYPE" = "vfat" ]; then
FLAGS=-oumask=000,uid=1000
echo $FLAGS
fi

sudo /bin/mount -t "$FS_TYPE" /dev/loop5 /mnt/FSTEST $FLAGS
retval=$?

if [ $retval -ne 0 ]; then
echo "Bad mount!"
sudo /sbin/losetup -d /dev/loop5
exit $retval
fi

exit 0
17 changes: 17 additions & 0 deletions img/loopback_fs_teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# unmount fs, deassociate image with lo
sudo /bin/umount /mnt/FSTEST
retval=$?
if [ $retval -ne 0 ]; then
echo "Failed to unmount."
fi

sudo /sbin/losetup -d /dev/loop5
retval=$?

if [ $retval -ne 0 ]; then
echo "Failed to losetup -d"
fi

exit $retval
23 changes: 17 additions & 6 deletions src/code_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,33 @@ void CodeBuilder::copyClosure(
{
llvm::Value *dst_params_ptr;
llvm::Value *src_params_ptr;
llvm::Value* src_loaded;

src_loaded = builder->CreateLoad(src_ptr);

/* copy contents of src into dst */
builder->CreateStore(
builder->CreateInsertValue(
builder->CreateLoad(dst_ptr),
builder->CreateInsertValue(
builder->CreateLoad(dst_ptr),
builder->CreateExtractValue(
src_loaded,
RT_CLO_IDX_OFFSET,
"cb_copy_offset"),
RT_CLO_IDX_OFFSET),
builder->CreateExtractValue(
builder->CreateLoad(src_ptr), 0, "cb_copy_offset"),
0),
src_loaded,
RT_CLO_IDX_XLATE,
"cb_copy_xlate"),
RT_CLO_IDX_XLATE),
dst_ptr);

src_params_ptr = builder->CreateExtractValue(
builder->CreateLoad(src_ptr), 1, "src_params");
src_loaded, RT_CLO_IDX_PARAMS, "src_params");
dst_params_ptr = builder->CreateExtractValue(
builder->CreateLoad(dst_ptr), 1, "dst_params");
builder->CreateLoad(dst_ptr), RT_CLO_IDX_PARAMS, "dst_params");

emitMemcpy64(dst_params_ptr, src_params_ptr,copy_type->getNumArgs());
emitMemcpy64(dst_params_ptr, src_params_ptr, copy_type->getNumArgs());
}

void CodeBuilder::genArgs(
Expand Down
17 changes: 13 additions & 4 deletions src/evalctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ bool EvalCtx::setNewOffsets(
return false;
}



bool EvalCtx::resolveTail(
TypeBase &tb, /* current base */
const IdStruct* ids,
Expand Down Expand Up @@ -470,12 +468,23 @@ const Type* EvalCtx::getTypeId(const Id* id) const
}

if (cur_func != NULL) {
string type_name;
const Type* ret;
string type_name;

/* find inside function arguments */
if (cur_func->getArgs()->lookupType(id->getName(), type_name))
return types_map[type_name];

/* find inside scope blocks */
assert (cur_func_blk != NULL);
if ((ret = cur_func_blk->getVarType(id->getName())) != NULL)
return ret;
}

return types_map[id->getName()];
if (types_map.count(id->getName()) != 0)
return types_map[id->getName()];

return NULL;
}

const Type* EvalCtx::getTypeIdStruct(const IdStruct* ids) const
Expand Down
14 changes: 10 additions & 4 deletions src/fcall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ llvm::Value* FCall::codeGenMkClosure(void) const
builder->CreateInsertValue(
builder->CreateInsertValue(
builder->CreateInsertValue(
closure_loaded, params, 1),
diskoff, 0),
code_builder->getNullPtrI8(), 2),
closure_loaded,
params,
RT_CLO_IDX_PARAMS),
diskoff,
RT_CLO_IDX_OFFSET),
code_builder->getNullPtrI8(),
RT_CLO_IDX_XLATE),
closure);


Expand Down Expand Up @@ -360,7 +364,9 @@ Value* FCall::codeGenClosureRetCall(std::vector<llvm::Value*>& args) const
tmp_params = code_builder->createPrivateTmpI64Array(
param_c, "BURRITOS");
builder->CreateInsertValue(
builder->CreateLoad(tmp_tp), tmp_params, 1);
builder->CreateLoad(tmp_tp),
tmp_params,
RT_CLO_IDX_PARAMS);


args.push_back(tmp_tp);
Expand Down
48 changes: 42 additions & 6 deletions src/func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,47 @@ Value* FuncDecl::codeGen(void) const
return NULL;
}


bool FuncAssign::genDebugAssign(void) const
{
EvalCtx ectx(getOwner());

/* send value to runtime for debugging purposes */
if (scalar->getName() == "DEBUG_WRITE") {
Expr *e;
e = rt_glue.getDebugCall(eval(ectx, expr));
evalAndGen(ectx, e);
delete e;
return true;
}

/* send type data to runtime for debugging purposes */
if (scalar->getName() == "DEBUG_WRITE_TYPE") {
Expr *e;
const ::Type *clo_type;

clo_type = ectx.getType(expr);
if (clo_type == NULL) {
cerr << "Oops: Could not resolve type for expression: ";
expr->print(cerr);
cerr << endl;
exit(-1);
return NULL;
}

e = rt_glue.getDebugCallTypeInstance(
clo_type,
eval(ectx, expr));

evalAndGen(ectx, e);
delete e;
return true;
}

return false;
}


Value* FuncAssign::codeGen(void) const
{

Expand All @@ -129,13 +170,8 @@ Value* FuncAssign::codeGen(void) const

/* send data to runtime for debugging purposes */
/* awful awful syntax abuse */
if (scalar->getName() == "DEBUG_WRITE") {
Expr *e;
e = rt_glue.getDebugCall(eval(ectx, expr));
evalAndGen(ectx, e);
delete e;
if (genDebugAssign())
return NULL;
}

e_v = evalAndGen(ectx, expr);
if (e_v == NULL) {
Expand Down
3 changes: 2 additions & 1 deletion src/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ typedef std::map<std::string, class Func*> func_map;
typedef std::list<class Func*> func_list;
typedef std::map<std::string, struct FuncVar> funcvar_map;


class FuncStmt
{
public:
Expand Down Expand Up @@ -133,6 +132,8 @@ class FuncAssign : public FuncStmt

llvm::Value* codeGen() const;
private:
bool genDebugAssign(void) const;

Id *scalar;
IdArray *array;
Expr *expr;
Expand Down
11 changes: 11 additions & 0 deletions src/runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ void __debugOutcall(uint64_t v)
cur_debug_write_val = v;
}


void __debugClosureOutcall(uint64_t typenum, struct fsl_rt_closure* clo)
{
assert (clo != NULL);

printf("DEBUG_WRITE_TYPE: %s-- off=%"PRIu64". xlate=%p\n",
tt_by_num(typenum)->tt_name,
clo->clo_offset,
clo->clo_xlate);
}

/* TODO FSL_FAILED should have some unique number so we know why we failed */
uint64_t fsl_fail(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ typesize_t __computeArrayBits(

uint64_t __getDynOffset(uint64_t type_num);
void __debugOutcall(uint64_t v);
void __debugClosureOutcall(uint64_t tpenum, struct fsl_rt_closure* clo);
void __getDynClosure(uint64_t typenum, struct fsl_rt_closure* clo);
void __getDynParams(uint64_t typenum, parambuf_t params_out);
void __setDyn(uint64_t type_num, const struct fsl_rt_closure* clo);
Expand Down
28 changes: 19 additions & 9 deletions src/runtime/scantool.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
#include "debug.h"
#include "type_info.h"


#define pt_from_idx(x,y) (&(tt_by_ti(x)->tt_pointsto[y]))

static void print_indent(unsigned int depth);
static void scan_type_pointsto(
const struct type_info* ti,
unsigned int pt_idx);
static void scan_type_pointsto(const struct type_info* ti, unsigned int pt_idx);
static void scan_type_pointsto_all(const struct type_info* ti);
static void scan_type_strongtypes(const struct type_info* ti);
static void scan_type_virt(struct type_info* ti);
Expand Down Expand Up @@ -175,7 +172,6 @@ static void handle_field(

scan_type(new_ti);


typeinfo_free(new_ti);
}
}
Expand All @@ -184,6 +180,7 @@ static void handle_virt(struct type_info* ti, struct fsl_rt_table_virt* vt)
{
unsigned int i;
int err_code;
struct type_info *ti_base;

DEBUG_TOOL_ENTER();

Expand All @@ -194,7 +191,7 @@ static void handle_virt(struct type_info* ti, struct fsl_rt_table_virt* vt)
struct type_info *ti_cur;

DEBUG_TOOL_WRITE("alloc virt[%d] %s", i, vt->vt_name);
FSL_DYN_LOAD(dyn_saved);;
FSL_DYN_LOAD(dyn_saved);
ti_cur = typeinfo_alloc_virt_idx(vt, ti, i, &err_code);
if (ti_cur == NULL) {
DEBUG_TOOL_WRITE(
Expand Down Expand Up @@ -250,15 +247,28 @@ static void scan_type_strongtypes(const struct type_info* ti)

static void scan_type(struct type_info* ti)
{
unsigned int i;
unsigned int i;
typesize_t size;
voff_t voff;
poff_t poff;

DEBUG_TOOL_ENTER();

voff = ti_offset(ti);
poff = ti_phys_offset(ti);
size = ti_size(ti);
printf("scanning: %s (%d usertypes) voff=%"PRIu64" bits. poff=%"PRIu64" bits. xlate=%p\n",
tt_by_ti(ti)->tt_name,
tt_by_ti(ti)->tt_field_c,
ti_offset(ti),
ti_phys_offset(ti),
voff,
poff,
ti_xlate(ti));
printf("{ 'Mode' : 'Scan', 'voff' : %"PRIu64
", 'poff' : %"PRIu64
", 'size': %"PRIu64
", 'name' : '%s' }\n",
voff, poff, size,
tt_by_ti(ti)->tt_name);
scan_type_strongtypes(ti);
DEBUG_TOOL_WRITE("do pointsto_all.");
scan_type_pointsto_all(ti);
Expand Down
Loading

0 comments on commit be6d6aa

Please sign in to comment.