Add a put_char function so we can print characters ...

This commit is contained in:
Markus Hauschild
2013-06-02 01:17:57 +02:00
parent 1ed3c1fe26
commit fd3ade68df
2 changed files with 11 additions and 3 deletions

View File

@@ -11,9 +11,13 @@ CodeGenVisitor::CodeGenVisitor(llvm::Module* module, llvm::FunctionPassManager *
scope_ = 0;
namedValues_.push_back(std::map<std::string, llvm::Value*>());
// create external for random_if
// create external for putchar
std::vector<llvm::Type*> argt(1, typeToLLVMType(Type::INT));
llvm::FunctionType* ft = llvm::FunctionType::get(typeToLLVMType(Type::BOOL), argt, false);
llvm::FunctionType* ft = llvm::FunctionType::get(typeToLLVMType(Type::INT), argt, false);
llvm::Function::Create(ft, llvm::Function::ExternalLinkage, "put_char", 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_);
}

View File

@@ -3,9 +3,13 @@
#include <stdbool.h>
#include <stdio.h>
int put_char(int c) {
printf("%c", c);
return 0;
}
bool random_if(int p) {
//srand(time(NULL));
int r = rand() % 100;
//printf("Value of r:%d\n",r);
return (r < p);
}