bool WebCLAction::initialize(clang::CompilerInstance &instance)
{
    reporter_ = new WebCLReporter(instance);
    if (!reporter_) {
        llvm::errs() << "Internal error. Can't report errors.\n";
        return false;
    }

    preprocessor_ = new WebCLPreprocessor(instance, extensions_, usedExtensions_);
    if (!preprocessor_) {
        reporter_->fatal("Internal error. Can't create preprocessor callbacks.\n");
        return false;
    }
    clang::Preprocessor &preprocessor = instance.getPreprocessor();
    preprocessor.addPPCallbacks(preprocessor_);

    if (output_) {
        // see clang::PrintPreprocessedAction
        instance.getFrontendOpts().OutputFile = output_;
        out_ = instance.createDefaultOutputFile(true, getCurrentFile());
        if (!out_) {
            reporter_->fatal("Internal error. Can't create output stream.");
            return false;
        }
    }

    const clang::FrontendInputFile &file = getCurrentInput();
    if (file.getKind() != clang::IK_OpenCL) {
        static const char *format =
            "Source file '%0' isn't treated as OpenCL code. Make sure that you "
            "give the '-x cl' option or that the file has a '.cl' extension.\n";
        reporter_->fatal(format) << file.getFile();
        return false;
    }

    return true;
}
Esempio n. 2
0
void Game::updateInput() {
	int currentInput = getCurrentInput();
	uint8_t inputKey0 = _inputsTable[currentInput].inputKey0;

	if (inp.dirMask & kInputDirRight) {
		_inputDirKeyPressed[inputKey0] |= 1;
	} else {
		_inputDirKeyPressed[inputKey0] &= ~1;
		if (inp.dirMaskPrev & kInputDirRight) {
			_inputDirKeyReleased[inputKey0] |= 1;
		}
	}
	if (inp.dirMask & kInputDirLeft) {
		_inputDirKeyPressed[inputKey0] |= 2;
	} else {
		_inputDirKeyPressed[inputKey0] &= ~2;
		if (inp.dirMaskPrev & kInputDirLeft) {
			_inputDirKeyReleased[inputKey0] |= 2;
		}
	}
	if (inp.dirMask & kInputDirDown) {
		_inputDirKeyPressed[inputKey0] |= 4;
	} else {
		_inputDirKeyPressed[inputKey0] &= ~4;
		if (inp.dirMaskPrev & kInputDirDown) {
			_inputDirKeyReleased[inputKey0] |= 4;
		}
	}
	if (inp.dirMask & kInputDirUp) {
		_inputDirKeyPressed[inputKey0] |= 8;
	} else {
		_inputDirKeyPressed[inputKey0] &= ~8;
		if (inp.dirMaskPrev & kInputDirUp) {
			_inputDirKeyReleased[inputKey0] |= 8;
		}
	}
	if (inp.altKey) {
		_inputButtonKey[inputKey0] |= 1;
	} else {
		_inputButtonKey[inputKey0] &= ~1;
	}
	if (inp.shiftKey) {
		_inputButtonKey[inputKey0] |= 2;
	} else {
		_inputButtonKey[inputKey0] &= ~2;
	}
	if (inp.enterKey) {
		_inputButtonKey[inputKey0] |= 4;
	} else {
		_inputButtonKey[inputKey0] &= ~4;
	}
	if (inp.ctrlKey) {
		_inputButtonKey[inputKey0] |= 8;
	} else {
		_inputButtonKey[inputKey0] &= ~8;
	}
	inp.dirMaskPrev = inp.dirMask;

	_inputKeyAction = inp.spaceKey;
	inp.spaceKey = false;
	_inputKeyUse = inp.useKey;
	inp.useKey = false;
	_inputKeyJump = inp.jumpKey;
	inp.jumpKey = false;

	for (int i = 0; i < _inputsCount; ++i) {
		_inputsTable[i].sysmaskPrev = _inputsTable[i].sysmask;
		if (currentInput == i) {
			_inputsTable[i].sysmask = _inputButtonKey[0] | (_inputDirKeyPressed[0] << 4) | (_inputButtonKey[1] << 8) | (_inputDirKeyPressed[1] << 12);
//			_inputsTable[i].sysmask |= _inputButtonMouse | (_inputDirMouse << 4);
			updateInputKeyMask(i);
		} else {
			_inputsTable[i].sysmask = 0;
			_inputsTable[i].keymask = 0;
			_inputsTable[i].keymaskToggle = 0;
		}
	}
	readInputEvents();
}