From a986fc4419864c3025c8f37740140f89b7c512fe Mon Sep 17 00:00:00 2001 From: Peter Dahlberg Date: Sun, 2 Jun 2013 01:51:19 +0200 Subject: [PATCH] time_seed --- doc/example6.x | 2 +- doc/example7.x | 7 +++++++ src/AST/CodeGenVisitor.cpp | 5 +++++ src/libscully.c | 7 ++++++- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 doc/example7.x diff --git a/doc/example6.x b/doc/example6.x index 24314e7..00e0deb 100644 --- a/doc/example6.x +++ b/doc/example6.x @@ -3,4 +3,4 @@ int foo dana fox mulder int i; rfor dana i = 0; 90; i = i + 1; fox bar dana fox; foo dana fox foo dana fox foo dana fox -foo dana fox \ No newline at end of file +foo dana fox diff --git a/doc/example7.x b/doc/example7.x new file mode 100644 index 0000000..79e0504 --- /dev/null +++ b/doc/example7.x @@ -0,0 +1,7 @@ +time_seed dana fox +int bar dana fox mulder int i; rfor dana i = 65; 70; i = i + 1; fox put_char dana i fox; return 0; scully +int foo dana fox mulder int i; rfor dana i = 0; 90; i = i + 1; fox bar dana fox; return 0; scully +foo dana fox +foo dana fox +foo dana fox +foo dana fox diff --git a/src/AST/CodeGenVisitor.cpp b/src/AST/CodeGenVisitor.cpp index aba72ee..2d23219 100644 --- a/src/AST/CodeGenVisitor.cpp +++ b/src/AST/CodeGenVisitor.cpp @@ -16,6 +16,11 @@ CodeGenVisitor::CodeGenVisitor(llvm::Module* module, llvm::FunctionPassManager * llvm::FunctionType* ft = llvm::FunctionType::get(typeToLLVMType(Type::INT), argt, false); llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "put_char", module_); + + // create external for time_seed + ft = llvm::FunctionType::get(typeToLLVMType(Type::INT), false); + llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "time_seed", module_); + // create external for random_if ft = llvm::FunctionType::get(typeToLLVMType(Type::BOOL), argt, false); llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "random_if", module_); diff --git a/src/libscully.c b/src/libscully.c index eb8da57..b1d5e9d 100644 --- a/src/libscully.c +++ b/src/libscully.c @@ -2,7 +2,7 @@ #include #include #include - +#include int put_char(int c) { printf("%c", c); return 0; @@ -13,3 +13,8 @@ bool random_if(int p) { int r = rand() % 100; return (r < p); } + +int time_seed() { + srand(time(NULL)); + return 0; +}