HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Oreo
|
8.0.0_r4
下载
查看原文件
收藏
根目录
external
swiftshader
src
Reactor
Nucleus.cpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "Nucleus.hpp" #include "llvm/Support/IRBuilder.h" #include "llvm/Function.h" #include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/LLVMContext.h" #include "llvm/Constants.h" #include "llvm/Intrinsics.h" #include "llvm/PassManager.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/TargetSelect.h" #include "../lib/ExecutionEngine/JIT/JIT.h" #include "Routine.hpp" #include "RoutineManager.hpp" #include "x86.hpp" #include "CPUID.hpp" #include "Thread.hpp" #include "Memory.hpp" #include
#include
#if defined(__x86_64__) && defined(_WIN32) extern "C" void X86CompilationCallback() { assert(false); // UNIMPLEMENTED } #endif extern "C" { bool (*CodeAnalystInitialize)() = 0; void (*CodeAnalystCompleteJITLog)() = 0; bool (*CodeAnalystLogJITCode)(const void *jitCodeStartAddr, unsigned int jitCodeSize, const wchar_t *functionName) = 0; } namespace llvm { extern bool JITEmitDebugInfo; } namespace sw { Optimization optimization[10] = {InstructionCombining, Disabled}; using namespace llvm; RoutineManager *Nucleus::routineManager = 0; ExecutionEngine *Nucleus::executionEngine = 0; Builder *Nucleus::builder = 0; LLVMContext *Nucleus::context = 0; Module *Nucleus::module = 0; llvm::Function *Nucleus::function = 0; BackoffLock Nucleus::codegenMutex; class Builder : public IRBuilder<> { }; Nucleus::Nucleus() { codegenMutex.lock(); // Reactor and LLVM are currently not thread safe InitializeNativeTarget(); JITEmitDebugInfo = false; if(!context) { context = new LLVMContext(); } module = new Module("", *context); routineManager = new RoutineManager(); #if defined(__x86_64__) const char *architecture = "x86-64"; #else const char *architecture = "x86"; #endif SmallVector
MAttrs; MAttrs.push_back(CPUID::supportsMMX() ? "+mmx" : "-mmx"); MAttrs.push_back(CPUID::supportsCMOV() ? "+cmov" : "-cmov"); MAttrs.push_back(CPUID::supportsSSE() ? "+sse" : "-sse"); MAttrs.push_back(CPUID::supportsSSE2() ? "+sse2" : "-sse2"); MAttrs.push_back(CPUID::supportsSSE3() ? "+sse3" : "-sse3"); MAttrs.push_back(CPUID::supportsSSSE3() ? "+ssse3" : "-ssse3"); MAttrs.push_back(CPUID::supportsSSE4_1() ? "+sse41" : "-sse41"); std::string error; TargetMachine *targetMachine = EngineBuilder::selectTarget(module, architecture, "", MAttrs, Reloc::Default, CodeModel::JITDefault, &error); executionEngine = JIT::createJIT(module, 0, routineManager, CodeGenOpt::Aggressive, true, targetMachine); if(!builder) { builder = static_cast
(new IRBuilder<>(*context)); #if defined(_WIN32) HMODULE CodeAnalyst = LoadLibrary("CAJitNtfyLib.dll"); if(CodeAnalyst) { CodeAnalystInitialize = (bool(*)())GetProcAddress(CodeAnalyst, "CAJIT_Initialize"); CodeAnalystCompleteJITLog = (void(*)())GetProcAddress(CodeAnalyst, "CAJIT_CompleteJITLog"); CodeAnalystLogJITCode = (bool(*)(const void*, unsigned int, const wchar_t*))GetProcAddress(CodeAnalyst, "CAJIT_LogJITCode"); CodeAnalystInitialize(); } #endif } } Nucleus::~Nucleus() { delete executionEngine; executionEngine = 0; routineManager = 0; function = 0; module = 0; codegenMutex.unlock(); } Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) { if(builder->GetInsertBlock()->empty() || !builder->GetInsertBlock()->back().isTerminator()) { Type *type = function->getReturnType(); if(type->isVoidTy()) { createRetVoid(); } else { createRet(UndefValue::get(type)); } } if(false) { std::string error; raw_fd_ostream file("llvm-dump-unopt.txt", error); module->print(file, 0); } if(runOptimizations) { optimize(); } if(false) { std::string error; raw_fd_ostream file("llvm-dump-opt.txt", error); module->print(file, 0); } void *entry = executionEngine->getPointerToFunction(function); Routine *routine = routineManager->acquireRoutine(entry); if(CodeAnalystLogJITCode) { CodeAnalystLogJITCode(routine->getEntry(), routine->getCodeSize(), name); } return routine; } void Nucleus::optimize() { static PassManager *passManager = 0; if(!passManager) { passManager = new PassManager(); UnsafeFPMath = true; // NoInfsFPMath = true; // NoNaNsFPMath = true; passManager->add(new TargetData(*executionEngine->getTargetData())); passManager->add(createScalarReplAggregatesPass()); for(int pass = 0; pass < 10 && optimization[pass] != Disabled; pass++) { switch(optimization[pass]) { case Disabled: break; case CFGSimplification: passManager->add(createCFGSimplificationPass()); break; case LICM: passManager->add(createLICMPass()); break; case AggressiveDCE: passManager->add(createAggressiveDCEPass()); break; case GVN: passManager->add(createGVNPass()); break; case InstructionCombining: passManager->add(createInstructionCombiningPass()); break; case Reassociate: passManager->add(createReassociatePass()); break; case DeadStoreElimination: passManager->add(createDeadStoreEliminationPass()); break; case SCCP: passManager->add(createSCCPPass()); break; case ScalarReplAggregates: passManager->add(createScalarReplAggregatesPass()); break; default: assert(false); } } } passManager->run(*module); } void Nucleus::setFunction(llvm::Function *function) { Nucleus::function = function; builder->SetInsertPoint(BasicBlock::Create(*context, "", function)); } Module *Nucleus::getModule() { return module; } llvm::Function *Nucleus::getFunction() { return function; } llvm::LLVMContext *Nucleus::getContext() { return context; } Value *Nucleus::allocateStackVariable(Type *type, int arraySize) { // Need to allocate it in the entry block for mem2reg to work llvm::Function *function = getFunction(); BasicBlock &entryBlock = function->getEntryBlock(); Instruction *declaration; if(arraySize) { declaration = new AllocaInst(type, Nucleus::createConstantInt(arraySize)); } else { declaration = new AllocaInst(type, (Value*)0); } entryBlock.getInstList().push_front(declaration); return declaration; } BasicBlock *Nucleus::createBasicBlock() { return BasicBlock::Create(*context, "", Nucleus::getFunction()); } BasicBlock *Nucleus::getInsertBlock() { return builder->GetInsertBlock(); } void Nucleus::setInsertBlock(BasicBlock *basicBlock) { // assert(builder->GetInsertBlock()->back().isTerminator()); return builder->SetInsertPoint(basicBlock); } BasicBlock *Nucleus::getPredecessor(BasicBlock *basicBlock) { return *pred_begin(basicBlock); } llvm::Function *Nucleus::createFunction(llvm::Type *ReturnType, std::vector
&Params) { llvm::FunctionType *functionType = llvm::FunctionType::get(ReturnType, Params, false); llvm::Function *function = llvm::Function::Create(functionType, llvm::GlobalValue::InternalLinkage, "", Nucleus::getModule()); function->setCallingConv(llvm::CallingConv::C); return function; } llvm::Value *Nucleus::getArgument(llvm::Function *function, unsigned int index) { llvm::Function::arg_iterator args = function->arg_begin(); while(index) { args++; index--; } return &*args; } Value *Nucleus::createRetVoid() { x86::emms(); return builder->CreateRetVoid(); } Value *Nucleus::createRet(Value *V) { x86::emms(); return builder->CreateRet(V); } Value *Nucleus::createBr(BasicBlock *dest) { return builder->CreateBr(dest); } Value *Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) { return builder->CreateCondBr(cond, ifTrue, ifFalse); } Value *Nucleus::createAdd(Value *lhs, Value *rhs) { return builder->CreateAdd(lhs, rhs); } Value *Nucleus::createSub(Value *lhs, Value *rhs) { return builder->CreateSub(lhs, rhs); } Value *Nucleus::createMul(Value *lhs, Value *rhs) { return builder->CreateMul(lhs, rhs); } Value *Nucleus::createUDiv(Value *lhs, Value *rhs) { return builder->CreateUDiv(lhs, rhs); } Value *Nucleus::createSDiv(Value *lhs, Value *rhs) { return builder->CreateSDiv(lhs, rhs); } Value *Nucleus::createFAdd(Value *lhs, Value *rhs) { return builder->CreateFAdd(lhs, rhs); } Value *Nucleus::createFSub(Value *lhs, Value *rhs) { return builder->CreateFSub(lhs, rhs); } Value *Nucleus::createFMul(Value *lhs, Value *rhs) { return builder->CreateFMul(lhs, rhs); } Value *Nucleus::createFDiv(Value *lhs, Value *rhs) { return builder->CreateFDiv(lhs, rhs); } Value *Nucleus::createURem(Value *lhs, Value *rhs) { return builder->CreateURem(lhs, rhs); } Value *Nucleus::createSRem(Value *lhs, Value *rhs) { return builder->CreateSRem(lhs, rhs); } Value *Nucleus::createFRem(Value *lhs, Value *rhs) { return builder->CreateFRem(lhs, rhs); } Value *Nucleus::createShl(Value *lhs, Value *rhs) { return builder->CreateShl(lhs, rhs); } Value *Nucleus::createLShr(Value *lhs, Value *rhs) { return builder->CreateLShr(lhs, rhs); } Value *Nucleus::createAShr(Value *lhs, Value *rhs) { return builder->CreateAShr(lhs, rhs); } Value *Nucleus::createAnd(Value *lhs, Value *rhs) { return builder->CreateAnd(lhs, rhs); } Value *Nucleus::createOr(Value *lhs, Value *rhs) { return builder->CreateOr(lhs, rhs); } Value *Nucleus::createXor(Value *lhs, Value *rhs) { return builder->CreateXor(lhs, rhs); } Value *Nucleus::createNeg(Value *V) { return builder->CreateNeg(V); } Value *Nucleus::createFNeg(Value *V) { return builder->CreateFNeg(V); } Value *Nucleus::createNot(Value *V) { return builder->CreateNot(V); } Value *Nucleus::createLoad(Value *ptr, bool isVolatile, unsigned int align) { return builder->Insert(new LoadInst(ptr, "", isVolatile, align)); } Value *Nucleus::createStore(Value *value, Value *ptr, bool isVolatile, unsigned int align) { return builder->Insert(new StoreInst(value, ptr, isVolatile, align)); } Value *Nucleus::createGEP(Value *ptr, Value *index) { return builder->CreateGEP(ptr, index); } Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) { return builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, value, SequentiallyConsistent); } Value *Nucleus::createTrunc(Value *V, Type *destType) { return builder->CreateTrunc(V, destType); } Value *Nucleus::createZExt(Value *V, Type *destType) { return builder->CreateZExt(V, destType); } Value *Nucleus::createSExt(Value *V, Type *destType) { return builder->CreateSExt(V, destType); } Value *Nucleus::createFPToUI(Value *V, Type *destType) { return builder->CreateFPToUI(V, destType); } Value *Nucleus::createFPToSI(Value *V, Type *destType) { return builder->CreateFPToSI(V, destType); } Value *Nucleus::createUIToFP(Value *V, Type *destType) { return builder->CreateUIToFP(V, destType); } Value *Nucleus::createSIToFP(Value *V, Type *destType) { return builder->CreateSIToFP(V, destType); } Value *Nucleus::createFPTrunc(Value *V, Type *destType) { return builder->CreateFPTrunc(V, destType); } Value *Nucleus::createFPExt(Value *V, Type *destType) { return builder->CreateFPExt(V, destType); } Value *Nucleus::createPtrToInt(Value *V, Type *destType) { return builder->CreatePtrToInt(V, destType); } Value *Nucleus::createIntToPtr(Value *V, Type *destType) { return builder->CreateIntToPtr(V, destType); } Value *Nucleus::createBitCast(Value *V, Type *destType) { return builder->CreateBitCast(V, destType); } Value *Nucleus::createIntCast(Value *V, Type *destType, bool isSigned) { return builder->CreateIntCast(V, destType, isSigned); } Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) { return builder->CreateICmpEQ(lhs, rhs); } Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) { return builder->CreateICmpNE(lhs, rhs); } Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) { return builder->CreateICmpUGT(lhs, rhs); } Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) { return builder->CreateICmpUGE(lhs, rhs); } Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) { return builder->CreateICmpULT(lhs, rhs); } Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) { return builder->CreateICmpULE(lhs, rhs); } Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) { return builder->CreateICmpSGT(lhs, rhs); } Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) { return builder->CreateICmpSGE(lhs, rhs); } Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) { return builder->CreateICmpSLT(lhs, rhs); } Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) { return builder->CreateICmpSLE(lhs, rhs); } Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) { return builder->CreateFCmpOEQ(lhs, rhs); } Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) { return builder->CreateFCmpOGT(lhs, rhs); } Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) { return builder->CreateFCmpOGE(lhs, rhs); } Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) { return builder->CreateFCmpOLT(lhs, rhs); } Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) { return builder->CreateFCmpOLE(lhs, rhs); } Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) { return builder->CreateFCmpONE(lhs, rhs); } Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) { return builder->CreateFCmpORD(lhs, rhs); } Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) { return builder->CreateFCmpUNO(lhs, rhs); } Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) { return builder->CreateFCmpUEQ(lhs, rhs); } Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) { return builder->CreateFCmpUGT(lhs, rhs); } Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) { return builder->CreateFCmpUGE(lhs, rhs); } Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) { return builder->CreateFCmpULT(lhs, rhs); } Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) { return builder->CreateFCmpULE(lhs, rhs); } Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) { return builder->CreateFCmpULE(lhs, rhs); } Value *Nucleus::createCall(Value *callee) { return builder->CreateCall(callee); } Value *Nucleus::createCall(Value *callee, Value *arg) { return builder->CreateCall(callee, arg); } Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2) { return builder->CreateCall2(callee, arg1, arg2); } Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3) { return builder->CreateCall3(callee, arg1, arg2, arg3); } Value *Nucleus::createCall(Value *callee, Value *arg1, Value *arg2, Value *arg3, Value *arg4) { return builder->CreateCall4(callee, arg1, arg2, arg3, arg4); } Value *Nucleus::createExtractElement(Value *vector, int index) { return builder->CreateExtractElement(vector, createConstantInt(index)); } Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) { return builder->CreateInsertElement(vector, element, createConstantInt(index)); } Value *Nucleus::createShuffleVector(Value *V1, Value *V2, Value *mask) { return builder->CreateShuffleVector(V1, V2, mask); } Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) { return builder->CreateSelect(C, ifTrue, ifFalse); } Value *Nucleus::createSwitch(llvm::Value *V, llvm::BasicBlock *Dest, unsigned NumCases) { return builder->CreateSwitch(V, Dest, NumCases); } void Nucleus::addSwitchCase(llvm::Value *Switch, int Case, llvm::BasicBlock *Branch) { static_cast
(Switch)->addCase(Nucleus::createConstantInt(Case), Branch); } Value *Nucleus::createUnreachable() { return builder->CreateUnreachable(); } Value *Nucleus::createSwizzle(Value *val, unsigned char select) { Constant *swizzle[4]; swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03); swizzle[1] = Nucleus::createConstantInt((select >> 2) & 0x03); swizzle[2] = Nucleus::createConstantInt((select >> 4) & 0x03); swizzle[3] = Nucleus::createConstantInt((select >> 6) & 0x03); Value *shuffle = Nucleus::createShuffleVector(val, UndefValue::get(val->getType()), Nucleus::createConstantVector(swizzle, 4)); return shuffle; } Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select) { bool mask[4] = {false, false, false, false}; mask[(select >> 0) & 0x03] = true; mask[(select >> 2) & 0x03] = true; mask[(select >> 4) & 0x03] = true; mask[(select >> 6) & 0x03] = true; Constant *swizzle[4]; swizzle[0] = Nucleus::createConstantInt(mask[0] ? 4 : 0); swizzle[1] = Nucleus::createConstantInt(mask[1] ? 5 : 1); swizzle[2] = Nucleus::createConstantInt(mask[2] ? 6 : 2); swizzle[3] = Nucleus::createConstantInt(mask[3] ? 7 : 3); Value *shuffle = Nucleus::createShuffleVector(lhs, rhs, Nucleus::createConstantVector(swizzle, 4)); return shuffle; } const llvm::GlobalValue *Nucleus::getGlobalValueAtAddress(void *Addr) { return executionEngine->getGlobalValueAtAddress(Addr); } void Nucleus::addGlobalMapping(const llvm::GlobalValue *GV, void *Addr) { executionEngine->addGlobalMapping(GV, Addr); } llvm::GlobalValue *Nucleus::createGlobalValue(llvm::Type *Ty, bool isConstant, unsigned int Align) { llvm::GlobalValue *global = new llvm::GlobalVariable(*Nucleus::getModule(), Ty, isConstant, llvm::GlobalValue::ExternalLinkage, 0, ""); global->setAlignment(Align); return global; } llvm::Type *Nucleus::getPointerType(llvm::Type *ElementType) { return llvm::PointerType::get(ElementType, 0); } llvm::Constant *Nucleus::createNullValue(llvm::Type *Ty) { return llvm::Constant::getNullValue(Ty); } llvm::ConstantInt *Nucleus::createConstantInt(int64_t i) { return llvm::ConstantInt::get(Type::getInt64Ty(*context), i, true); } llvm::ConstantInt *Nucleus::createConstantInt(int i) { return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, true); } llvm::ConstantInt *Nucleus::createConstantInt(unsigned int i) { return llvm::ConstantInt::get(Type::getInt32Ty(*context), i, false); } llvm::ConstantInt *Nucleus::createConstantBool(bool b) { return llvm::ConstantInt::get(Type::getInt1Ty(*context), b); } llvm::ConstantInt *Nucleus::createConstantByte(signed char i) { return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, true); } llvm::ConstantInt *Nucleus::createConstantByte(unsigned char i) { return llvm::ConstantInt::get(Type::getInt8Ty(*context), i, false); } llvm::ConstantInt *Nucleus::createConstantShort(short i) { return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, true); } llvm::ConstantInt *Nucleus::createConstantShort(unsigned short i) { return llvm::ConstantInt::get(Type::getInt16Ty(*context), i, false); } llvm::Constant *Nucleus::createConstantFloat(float x) { return ConstantFP::get(Float::getType(), x); } llvm::Value *Nucleus::createNullPointer(llvm::Type *Ty) { return llvm::ConstantPointerNull::get(llvm::PointerType::get(Ty, 0)); } llvm::Value *Nucleus::createConstantVector(llvm::Constant *const *Vals, unsigned NumVals) { return llvm::ConstantVector::get(llvm::ArrayRef
(Vals, NumVals)); } Type *Void::getType() { return Type::getVoidTy(*Nucleus::getContext()); } LValue::LValue(llvm::Type *type, int arraySize) { address = Nucleus::allocateStackVariable(type, arraySize); } llvm::Value *LValue::loadValue(unsigned int alignment) const { return Nucleus::createLoad(address, false, alignment); } llvm::Value *LValue::storeValue(llvm::Value *value, unsigned int alignment) const { return Nucleus::createStore(value, address, false, alignment); } llvm::Value *LValue::getAddress(llvm::Value *index) const { return Nucleus::createGEP(address, index); } Type *MMX::getType() { return Type::getX86_MMXTy(*Nucleus::getContext()); } Bool::Bool(Argument
argument) { storeValue(argument.value); } Bool::Bool() { } Bool::Bool(bool x) { storeValue(Nucleus::createConstantBool(x)); } Bool::Bool(RValue
rhs) { storeValue(rhs.value); } Bool::Bool(const Bool &rhs) { Value *value = rhs.loadValue(); storeValue(value); } Bool::Bool(const Reference
&rhs) { Value *value = rhs.loadValue(); storeValue(value); } RValue
Bool::operator=(RValue
rhs) const { storeValue(rhs.value); return rhs; } RValue
Bool::operator=(const Bool &rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
Bool::operator=(const Reference
&rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
operator!(RValue
val) { return RValue
(Nucleus::createNot(val.value)); } RValue
operator&&(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAnd(lhs.value, rhs.value)); } RValue
operator||(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createOr(lhs.value, rhs.value)); } Type *Bool::getType() { return Type::getInt1Ty(*Nucleus::getContext()); } Byte::Byte(Argument
argument) { storeValue(argument.value); } Byte::Byte(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); storeValue(integer); } Byte::Byte(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); storeValue(integer); } Byte::Byte(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); storeValue(integer); } Byte::Byte() { } Byte::Byte(int x) { storeValue(Nucleus::createConstantByte((unsigned char)x)); } Byte::Byte(unsigned char x) { storeValue(Nucleus::createConstantByte(x)); } Byte::Byte(RValue
rhs) { storeValue(rhs.value); } Byte::Byte(const Byte &rhs) { Value *value = rhs.loadValue(); storeValue(value); } Byte::Byte(const Reference
&rhs) { Value *value = rhs.loadValue(); storeValue(value); } RValue
Byte::operator=(RValue
rhs) const { storeValue(rhs.value); return rhs; } RValue
Byte::operator=(const Byte &rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
Byte::operator=(const Reference
&rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
operator+(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAdd(lhs.value, rhs.value)); } RValue
operator-(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createSub(lhs.value, rhs.value)); } RValue
operator*(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createMul(lhs.value, rhs.value)); } RValue
operator/(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createUDiv(lhs.value, rhs.value)); } RValue
operator%(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createURem(lhs.value, rhs.value)); } RValue
operator&(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAnd(lhs.value, rhs.value)); } RValue
operator|(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createOr(lhs.value, rhs.value)); } RValue
operator^(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createXor(lhs.value, rhs.value)); } RValue
operator<<(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createShl(lhs.value, rhs.value)); } RValue
operator>>(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createLShr(lhs.value, rhs.value)); } RValue
operator+=(const Byte &lhs, RValue
rhs) { return lhs = lhs + rhs; } RValue
operator-=(const Byte &lhs, RValue
rhs) { return lhs = lhs - rhs; } RValue
operator*=(const Byte &lhs, RValue
rhs) { return lhs = lhs * rhs; } RValue
operator/=(const Byte &lhs, RValue
rhs) { return lhs = lhs / rhs; } RValue
operator%=(const Byte &lhs, RValue
rhs) { return lhs = lhs % rhs; } RValue
operator&=(const Byte &lhs, RValue
rhs) { return lhs = lhs & rhs; } RValue
operator|=(const Byte &lhs, RValue
rhs) { return lhs = lhs | rhs; } RValue
operator^=(const Byte &lhs, RValue
rhs) { return lhs = lhs ^ rhs; } RValue
operator<<=(const Byte &lhs, RValue
rhs) { return lhs = lhs << rhs; } RValue
operator>>=(const Byte &lhs, RValue
rhs) { return lhs = lhs >> rhs; } RValue
operator+(RValue
val) { return val; } RValue
operator-(RValue
val) { return RValue
(Nucleus::createNeg(val.value)); } RValue
operator~(RValue
val) { return RValue
(Nucleus::createNot(val.value)); } RValue
operator++(const Byte &val, int) // Post-increment { RValue
res = val; Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((unsigned char)1)); val.storeValue(inc); return res; } const Byte &operator++(const Byte &val) // Pre-increment { Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); val.storeValue(inc); return val; } RValue
operator--(const Byte &val, int) // Post-decrement { RValue
res = val; Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((unsigned char)1)); val.storeValue(inc); return res; } const Byte &operator--(const Byte &val) // Pre-decrement { Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); val.storeValue(inc); return val; } RValue
operator<(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpULT(lhs.value, rhs.value)); } RValue
operator<=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpULE(lhs.value, rhs.value)); } RValue
operator>(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpUGT(lhs.value, rhs.value)); } RValue
operator>=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpUGE(lhs.value, rhs.value)); } RValue
operator!=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpNE(lhs.value, rhs.value)); } RValue
operator==(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpEQ(lhs.value, rhs.value)); } Type *Byte::getType() { return Type::getInt8Ty(*Nucleus::getContext()); } SByte::SByte(Argument
argument) { storeValue(argument.value); } SByte::SByte(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); storeValue(integer); } SByte::SByte(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); storeValue(integer); } SByte::SByte() { } SByte::SByte(signed char x) { storeValue(Nucleus::createConstantByte(x)); } SByte::SByte(RValue
rhs) { storeValue(rhs.value); } SByte::SByte(const SByte &rhs) { Value *value = rhs.loadValue(); storeValue(value); } SByte::SByte(const Reference
&rhs) { Value *value = rhs.loadValue(); storeValue(value); } RValue
SByte::operator=(RValue
rhs) const { storeValue(rhs.value); return rhs; } RValue
SByte::operator=(const SByte &rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
SByte::operator=(const Reference
&rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue
operator+(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAdd(lhs.value, rhs.value)); } RValue
operator-(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createSub(lhs.value, rhs.value)); } RValue
operator*(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createMul(lhs.value, rhs.value)); } RValue
operator/(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createSDiv(lhs.value, rhs.value)); } RValue
operator%(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createSRem(lhs.value, rhs.value)); } RValue
operator&(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAnd(lhs.value, rhs.value)); } RValue
operator|(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createOr(lhs.value, rhs.value)); } RValue
operator^(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createXor(lhs.value, rhs.value)); } RValue
operator<<(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createShl(lhs.value, rhs.value)); } RValue
operator>>(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createAShr(lhs.value, rhs.value)); } RValue
operator+=(const SByte &lhs, RValue
rhs) { return lhs = lhs + rhs; } RValue
operator-=(const SByte &lhs, RValue
rhs) { return lhs = lhs - rhs; } RValue
operator*=(const SByte &lhs, RValue
rhs) { return lhs = lhs * rhs; } RValue
operator/=(const SByte &lhs, RValue
rhs) { return lhs = lhs / rhs; } RValue
operator%=(const SByte &lhs, RValue
rhs) { return lhs = lhs % rhs; } RValue
operator&=(const SByte &lhs, RValue
rhs) { return lhs = lhs & rhs; } RValue
operator|=(const SByte &lhs, RValue
rhs) { return lhs = lhs | rhs; } RValue
operator^=(const SByte &lhs, RValue
rhs) { return lhs = lhs ^ rhs; } RValue
operator<<=(const SByte &lhs, RValue
rhs) { return lhs = lhs << rhs; } RValue
operator>>=(const SByte &lhs, RValue
rhs) { return lhs = lhs >> rhs; } RValue
operator+(RValue
val) { return val; } RValue
operator-(RValue
val) { return RValue
(Nucleus::createNeg(val.value)); } RValue
operator~(RValue
val) { return RValue
(Nucleus::createNot(val.value)); } RValue
operator++(const SByte &val, int) // Post-increment { RValue
res = val; Value *inc = Nucleus::createAdd(res.value, Nucleus::createConstantByte((signed char)1)); val.storeValue(inc); return res; } const SByte &operator++(const SByte &val) // Pre-increment { Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1)); val.storeValue(inc); return val; } RValue
operator--(const SByte &val, int) // Post-decrement { RValue
res = val; Value *inc = Nucleus::createSub(res.value, Nucleus::createConstantByte((signed char)1)); val.storeValue(inc); return res; } const SByte &operator--(const SByte &val) // Pre-decrement { Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1)); val.storeValue(inc); return val; } RValue
operator<(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpSLT(lhs.value, rhs.value)); } RValue
operator<=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpSLE(lhs.value, rhs.value)); } RValue
operator>(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpSGT(lhs.value, rhs.value)); } RValue
operator>=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpSGE(lhs.value, rhs.value)); } RValue
operator!=(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpNE(lhs.value, rhs.value)); } RValue
operator==(RValue
lhs, RValue
rhs) { return RValue
(Nucleus::createICmpEQ(lhs.value, rhs.value)); } Type *SByte::getType() { return Type::getInt8Ty(*Nucleus::getContext()); } Short::Short(Argument
argument) { storeValue(argument.value); } Short::Short(RValue
cast) { Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); storeValue(integer); } Short::Short() { } Short::Short(short x) { storeValue(Nucleus::createConstantShort(x)); } Short::Short(RValue
rhs) { storeValue(rhs.value); } Short::Short(const Short &rhs) { Value *value = rhs.loadValue(); storeValue(value); } Short::Short(const Reference
&rhs) { Value *value = rhs.loadValue(); storeValue(value); } RValue
Short::operator=(RValue
rhs) const { storeValue(rhs.value); return rhs; } RValue
Short::operator=(const Short &rhs) const { Value *value = rhs.loadValue(); storeValue(value); return RValue
(value); } RValue