本文整理汇总了C++中Code类的典型用法代码示例。如果您正苦于以下问题:C++ Code类的具体用法?C++ Code怎么用?C++ Code使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Code类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
wasm::ToggleProfiling(const Code& code, const CallThunk& callThunk, bool enabled)
{
const CodeRange& cr = code.metadata().codeRanges[callThunk.u.codeRangeIndex];
uint32_t calleeOffset = enabled ? cr.funcProfilingEntry() : cr.funcNonProfilingEntry();
MacroAssembler::repatchFarJump(code.segment().base(), callThunk.offset, calleeOffset);
}
示例2: main
int main(int argc, const char * argv[])
{
char* text_buffer = loadFile(argv[1]);
if(!text_buffer) {
cout << "Can't load file: " << argv[1] << endl;
return 1;
}
const std::string text(text_buffer);
Parser parser;
Status *pStatus = parser.parseProgram(text);
if(pStatus && pStatus->isError()) {
cout << pStatus->getError();
return 1;
}
Code* code = new MyCode();
BytecodeFunction * main2 = new BytecodeFunction(parser.top());
code->addFunction(main2);
parser.top()->node()->visit(new ByteCodeVisitor(code, main2->bytecode()));
main2->bytecode()->add(BC_STOP);
//main2->bytecode()->dump(std::cout);
interpreter interp(code);
interp.generate(main2);
return 0;
}
示例3: buildCharMap
void Compressor::compress(const char *filename)
{
buildCharMap();
buildCharTree();
buildCodeTable(charTree);
ofstream out(filename, ios::out | ios::binary);
dumpCharMap(out);
int count = 0, codeSize, i;
char buf = 0;
while (!inputFile.eof())
{
Code code = codeTable[inputFile.get()];
codeSize = (int) code.size();
for(i = 0; i < codeSize; i++)
{
buf |= code[i] << (7 - count);
if (++count == 8)
{
out << buf;
count = buf = NULL;
}
}
}
if(count > 0) {
out << buf;
}
out.close();
}
示例4: validate
bool CodeStack::validate(const Code& cf)
{
TypeFilter tf;
// returns r, i, or j
switch (tf.Get(cf.name))
{
// r requires
// rs, rd, rt
case 'r':
if (cf.rs!="" && cf.rd!="" && cf.rt!="")
return true;
setErr("rs or rt or rd not set");
return false;
// i requires
// rs, rt, imd(or lb)
case 'i':
if (cf.rs!="" && cf.rt!="" && cf.dirt())
return true;
setErr("rs or rt or immediate not set");
return false;
// j requires
// imd
case 'j':
if (cf.dirt())
return true;
setErr("immediate not set");
return false;
default:
// ÕâÊÇɶ
return false;
}
return true;
}
示例5: main
int main()
{
Code code;
void (*f)() = code.getCode<void (*)()>();
dump(code.getCode(), code.getSize());
f();
}
示例6: getLength
// Compares guess to secret code and returns the number of correct digits
// in the incorrect locations.
int Code::checkIncorrect(Code& guess) {
const int secretCodeLength = getLength();
int count = 0; // correct digits in the incorrect location
vector<bool> secretUsed = getUsed();
vector<bool> guessUsed = guess.getUsed();
/// check vector lengths
if (guess.getLength() != secretCodeLength) {
throw InvalidVectSize("Code::checkCorrect - vectors are not the same length!");
}
// compare all unused guess values to current unused secret code value
for (int i = 0; i < secretCodeLength; i++) {
for (int j = 0; j < guess.getLength(); j++) {
if ((!secretUsed[i] && !guessUsed[j]) &&
(getCode()[i] == guess.getCode()[j] )) {
// we have a match, mark these indices as used and
// increase the count before continuing the compare
secretUsed[i] = true;
guessUsed[j] = true;
count++;
break;
}
}
}
return count;
}
示例7: defined
void
wasm::ToggleProfiling(const Code& code, const CallSite& callSite, bool enabled)
{
if (callSite.kind() != CallSite::FuncDef)
return;
uint8_t* callerRetAddr = code.segment().base() + callSite.returnAddressOffset();
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
void* callee = X86Encoding::GetRel32Target(callerRetAddr);
#elif defined(JS_CODEGEN_ARM)
uint8_t* caller = callerRetAddr - 4;
Instruction* callerInsn = reinterpret_cast<Instruction*>(caller);
BOffImm calleeOffset;
callerInsn->as<InstBLImm>()->extractImm(&calleeOffset);
void* callee = calleeOffset.getDest(callerInsn);
#elif defined(JS_CODEGEN_ARM64)
MOZ_CRASH();
void* callee = nullptr;
(void)callerRetAddr;
#elif defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64)
uint8_t* caller = callerRetAddr - 2 * sizeof(uint32_t);
InstImm* callerInsn = reinterpret_cast<InstImm*>(caller);
BOffImm16 calleeOffset;
callerInsn->extractImm16(&calleeOffset);
void* callee = calleeOffset.getDest(reinterpret_cast<Instruction*>(caller));
#elif defined(JS_CODEGEN_NONE)
MOZ_CRASH();
void* callee = nullptr;
#else
# error "Missing architecture"
#endif
const CodeRange* codeRange = code.lookupRange(callee);
if (!codeRange->isFunction())
return;
uint8_t* from = code.segment().base() + codeRange->funcNonProfilingEntry();
uint8_t* to = code.segment().base() + codeRange->funcProfilingEntry();
if (!enabled)
Swap(from, to);
MOZ_ASSERT(callee == from);
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
X86Encoding::SetRel32(callerRetAddr, to);
#elif defined(JS_CODEGEN_ARM)
new (caller) InstBLImm(BOffImm(to - caller), Assembler::Always);
#elif defined(JS_CODEGEN_ARM64)
(void)to;
MOZ_CRASH();
#elif defined(JS_CODEGEN_MIPS32) || defined(JS_CODEGEN_MIPS64)
new (caller) InstImm(op_regimm, zero, rt_bgezal, BOffImm16(to - caller));
#elif defined(JS_CODEGEN_NONE)
MOZ_CRASH();
#else
# error "Missing architecture"
#endif
}
示例8: main
int main(int argc, char** argv) {
const char* script = 0;
std::string mode = INTERPRETE;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-d") {
mode = DISASM;
} else if (string(argv[i]) == "-j") {
mode = JIT;
} else {
script = argv[i];
}
}
if (script == 0) {
cout << "Usage: interpreter [-d | -j] <source_file>" << endl;
return WRONG_ARG_COUNT;
}
const char* expr = loadFile(script);
if (expr == 0) {
cout << "Cannot read file: " << script << endl;
return CANNOT_READ_SOURCE;
}
Translator* translator = new BytecodeTranslatorImpl();
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus == 0) {
//todo
} else if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
cout << "Cannot translate expression: expression at " << line << ", " << offset << "; "
<< "error '" << translateStatus->getError().c_str() << "'" << endl;
} else {
assert(code != 0);
if (mode == DISASM) {
code->disassemble(cout);
} else if (mode == JIT) {
} else {
vector<Var*> t;
code->execute(t);
}
delete code;
}
delete translateStatus;
delete translator;
return 0;
}
示例9: main
int main( int argc, char** argv )
{
std::cout << "Hello World" << std::endl;
Code c;
c.setProperty( "foo", "bar" );
c.setProperty( "hello", "world" );
cout << "Property foo = " << c.getProperty( "foo" ) << endl;
cout << "Property hello = " << c.getProperty( "hello" ) << endl;
}
示例10: main
int main()
{
const int count = 1000;
Xbyak::util::Clock clk;
Code c;
void (*f)() = (void (*)())c.getCode();
for (int i = 0; i < count; i++) {
clk.begin();
f();
clk.end();
}
printf("%.3fclk\n", clk.getClock() / double(N) / clk.getCount());
}
示例11: UpdateEntry
static void
UpdateEntry(const Code& code, bool profilingEnabled, void** entry)
{
const CodeRange& codeRange = *code.lookupRange(*entry);
void* from = code.segment().base() + codeRange.funcNonProfilingEntry();
void* to = code.segment().base() + codeRange.funcProfilingEntry();
if (!profilingEnabled)
Swap(from, to);
MOZ_ASSERT(*entry == from);
*entry = to;
}
示例12: setCorrectNumber
void GuessResponse::setCorrectNumber(const Code &secret, const Code &guess)
{
// iterate through each, marking when a code place is accounted for
for (int i = 0; i < secret.GetLength(); i++)
{
if (secret.GetValue(i) == guess.GetValue(i))
{
_numberCorrect++;
guessCodeMemberAccountedFor[i] = true;
secretCodeMemberAccountedFor[i] = true;
}
}
}
示例13: Code
void CodeEditorWindow::onSave()
{
Code *pNewCode = new Code(m_codeEditor->toHtml(), m_keywordsEditor.text());
if (m_editCode == nullptr) {
pNewCode->setCreateTime(QDateTime::currentMSecsSinceEpoch());
pCodeBase->add(pNewCode);
} else {
pNewCode->copyMembers(m_editCode);
pCodeBase->add(pNewCode, m_editCode->getId());
}
close();
codePaster->save();
}
示例14: step
bool Thread::step()
{
if (state == RUN)
{
Thread::Frame& frame = frames.back();
ThunkPrototype* thunk = frame.thunk->thunkPrototype();
size_t nextInstr = frame.nextInstr;
Code* code = thunk->body[nextInstr];
frame.nextInstr++;
// Uncomment to get *verbose* debug info on scripting
/*cout << thunk;
for (size_t i = 0; i < frames.size(); ++i)
cout << "[" << frames[i].stack.size() << "]";
cout << " " << usl->debug.find(thunk, nextInstr) << ": ";
code->dump(cout);
cout << endl;*/
code->execute(this);
while (true)
{
Thread::Frame& frame = frames.back();
if (frame.nextInstr < frame.thunk->thunkPrototype()->body.size())
break;
Value* retVal = frame.stack.back();
frames.pop_back();
if (!frames.empty())
{
frames.back().stack.push_back(retVal);
}
else
{
#ifdef DEBUG_USL
retVal->dump(cout);
cout << endl;
#endif
state = STOP;
break;
}
}
return true;
}
else
{
return false;
}
}
示例15: brig_container_find_code_module_symbol_offset
HSAIL_C_API brig_code_section_offset brig_container_find_code_module_symbol_offset(brig_container_t handle, const char *symbol_name)
{
BrigContainer& c = ((Api*)handle)->container;
for (Code d = c.code().begin(), e = c.code().end(); d != e; ) {
if (DirectiveExecutable e = d) {
if (e.name().str() == symbol_name) { return e.brigOffset(); }
d = e.nextModuleEntry(); // Skip to next top level directive.
} else if (DirectiveVariable v = d) {
if (v.name().str() == symbol_name) { return v.brigOffset(); }
d = d.next(); // Skip to next directive.
} else {
d = d.next(); // Skip to next directive.
}
}
return 0;
}