time_seed
This commit is contained in:
@@ -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
|
||||
foo dana fox
|
||||
|
||||
7
doc/example7.x
Normal file
7
doc/example7.x
Normal file
@@ -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
|
||||
@@ -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_);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <time.h>
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user