当前位置: 首页>>代码示例>>C++>>正文


C++ AsmCode类代码示例

本文整理汇总了C++中AsmCode的典型用法代码示例。如果您正苦于以下问题:C++ AsmCode类的具体用法?C++ AsmCode怎么用?C++ AsmCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsmCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: deleteUselessMovs

void Optimizer::deleteUselessMovs(AsmCode& code){
	for (int i = 0; i < code.size(); i++){
		if (*code[i] != cmdMOV || !code[i]->usedRegister(EAX))
			continue;
		AsmCmd2* cmd = dynamic_cast<AsmCmd2*>(code[i]);
		if (cmd->secondArg()->usedRegister(EAX))
			continue;
		if (*cmd->firstArg() != EAX)
			continue;
		int idx = i + 1;
		bool deletingNedeed = true;
		while (idx < code.size() && deletingNedeed){
			if (code[idx]->usedRegister(EAX))
				if (*code[idx] != cmdMOV)
					deletingNedeed = false;
				else {
					AsmCmd2* tmp = dynamic_cast<AsmCmd2*>(code[idx]);
					if (tmp->secondArg()->usedRegister(EAX)	|| dynamic_cast<AsmIndirectArg*>(tmp->firstArg()))
						deletingNedeed = false;
					else
						break;
				}
			idx++;
		}
		if (deletingNedeed)
			code.deleteRange(i, i);
	}
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:28,代码来源:l_optimizer.cpp

示例2: generateLvalue

void BinOpNode::generateLvalue(AsmCode& code){
	string value = token->Value;
	if (value == "+"){
		
			SymbolType *type = left->getType();
		if (dynamic_cast<ArraySymbol*>(type))
			left->generateLvalue(code);
		else if (dynamic_cast<PointerSymbol*>(type))
			left->generate(code);
		SymbolType *t = type->upType();
			right->generate(code);
		
			code.add(_POP, _EAX)
				.add(_MOV, _EBX, to_string(t->byteSize()))
				.add(_IMUL, _EAX, _EBX)
				.add(_POP, _EBX)
				.add(_ADD, _EAX, _EBX)
				.add(_PUSH, _EAX);
			t = t->upType();
		
		
	}
	else	if (isAssing(token)){ 
		generate(code);
		code.add(_POP, _EAX);
		left->generateLvalue(code);
	}
	else
		throw MyException("Compiler error");
}
开发者ID:Deniallugo,项目名称:compiler,代码行数:30,代码来源:node_generation+-+копия.cpp

示例3: generate

void FuncCallNode::generate(AsmCode& code){
	code.add(_SUB, _ESP, to_string(symbol->value->byteSize()));
	for (int i = args.size() - 1; i > -1; i--)
		args[i]->generate(code);
	code.add(_CALL, new AsmLabelArg("f_" + name->token->Value))
		.add(_ADD, _ESP, to_string(symbol->params->byteSize()));
}
开发者ID:Deniallugo,项目名称:compiler,代码行数:7,代码来源:node_generation+-+копия.cpp

示例4: Generate

void SymVarGlobal::Generate(AsmCode& asmCode, unsigned) const
{
   if (type->GetSize() > 4) {
      GenerateLValue(asmCode, 0);
      asmCode.PushMemory(type->GetSize());
   } else {
      asmCode.AddCmd(PUSH, AsmMemory(varLabel, 0, szDWORD));
   }
}
开发者ID:koninka,项目名称:pascal-complier,代码行数:9,代码来源:symbols.cpp

示例5: generateLvalue

void IdentifierNode::generateLvalue(AsmCode &code) {
	if(var->global)
		code.add(cmdPUSH, makeArgMemory("var_" + var->name, true));
	else
		code.add(cmdMOV, EAX, EBP)
			.add(cmdMOV, EBX, var->offset)
			.add(cmdADD, EAX, EBX)
			.add(cmdPUSH, EAX);
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:9,代码来源:nodes.cpp

示例6:

bool PushPop2MovOptimization::optimize(AsmCode& code, int index){
	if(	prepare(code[index], code[index + 1]) && *cmd1 == cmdPUSH && *cmd2 == cmdPOP 
		&& !(cmd1->argument()->isMemory() && cmd2->argument()->isMemory())){
		AsmCmd* optCmd = new AsmCmd2(cmdMOV, cmd2->argument(), cmd1->argument());
		code.deleteRange(index, index + 1);
		code.insert(optCmd, index);	
		return true;
	} 
	return false;
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:10,代码来源:l_optimizer.cpp

示例7: generate

void IdentifierNode::generate(AsmCode &code) {
	int size = var->byteSize();
	int steps = size / 4 + (size % 4 != 0);
	if (var->global)
		for (int i = 0; i < steps; i++)
			code.add(cmdPUSH, makeArgMemory("dword ptr [var_" + var->name + " + " + to_string(4 * (steps - i - 1)) +"]"));
	else
		for (int i = 0; i < steps; i++)
			code.add(cmdPUSH, makeIndirectArg(EBP, var->offset + 4 * (steps - i - 1)));
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:10,代码来源:nodes.cpp

示例8: generateOperationAssing

static void generateOperationAssing(SymbolType * type, AsmCode & code, Commands cmd, Registers reg = _EAX) {
	code.add(_POP, _EBX)
		.add(_POP, _ECX);

	if (type->getType() == CharType) {
		code.add(_XOR, _EAX, _EAX)
			.add(_MOV, new AsmRegArg(_AL), new AsmIndirectArg(_ECX));

	}
	else {
		code.add(_MOV, new AsmRegArg(_EAX), new AsmIndirectArg(_ECX));
	}

	code.add(_XOR, _EDX, _EDX);

	if (cmd == _IDIV || cmd == _IMUL) code.add(cmd, _EBX);
	else code.add(cmd, _EAX, _EBX);
	if (type->getType() == CharType) {
	Registers byteReg = reg == _EAX ? _AL : _DL;
		code.add(_MOV, new AsmIndirectArg(_ECX), new AsmRegArg(byteReg))
			.add(_XOR, reg, reg)
			.add(_MOV, new AsmRegArg(byteReg), new AsmIndirectArg(_ECX));

	}
	else {
		code.add(_MOV, new AsmIndirectArg(_ECX), new AsmRegArg(reg));
	}

	code.add(_PUSH, reg);
}
开发者ID:Deniallugo,项目名称:compiler,代码行数:30,代码来源:node_generation+-+копия.cpp

示例9: generateOperation

static void generateOperation(AsmCode & code, Commands cmd, Registers reg = _EAX) {
	code.add(_POP, _EBX)
		.add(_POP, _EAX)

		.add(_XOR, _EDX, _EDX);

	if (cmd == _IDIV || cmd == _IMUL) code.add(cmd, _EBX);
	else code.add(cmd, _EAX, _EBX);

	code.add(_PUSH, reg);
}
开发者ID:Deniallugo,项目名称:compiler,代码行数:11,代码来源:node_generation+-+копия.cpp

示例10: optimize

bool CompactAdditionOptimization::optimize(AsmCode& code, int index){
	if(	prepare(code[index], code[index + 1], code[index + 2])
		&& *cmd1 == cmdMOV && *cmd2 == cmdMOV && *cmd1->firstArg() == EBX 
		&& *cmd1->secondArg() == cmd2->firstArg() && *cmd3 == cmdADD 
		&& *cmd3->firstArg() == cmd2->firstArg() && *cmd3->secondArg() == cmd1->firstArg()){
			AsmCmd2* optCmd = new AsmCmd2(cmdMOV, makeArg(EBX), cmd2->secondArg());
			code.deleteRange(index, index + 1);
			code.insert(optCmd, index);
			return true;
	} 
	return false;
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:12,代码来源:l_optimizer.cpp

示例11: Action

bool PopToUpPushToDown::Action(AsmCode& code, AsmCmd1* cmd, int i, int inc)
{
    int j = i;
    while (0 < j && j + 1 < code.Size()
        && !UsesStack(code[j + inc])
        && !IsArgument(cmd->GetArgument(), code[j + inc]))
    {
        j += inc;
    }
    code.Move(i, j);
    return j != i;
}
开发者ID:GuraYaroslava,项目名称:c-compiler,代码行数:12,代码来源:asm_optimizer.cpp

示例12: makeArg

bool Neg2MovOppositeOptimization::optimize(AsmCode& code, int index){
	if (prepare(code[index], code[index + 1]) 
		&& *cmd1 == cmdMOV && *cmd1->firstArg() == EAX
		&& *cmd2 == cmdNEG && *cmd2->argument() == EAX
		&& dynamic_cast<AsmImmediateArg*>(cmd1->secondArg())){
			int val = dynamic_cast<AsmImmediateArg*>(cmd1->secondArg())->value;
			AsmCmd2* optCmd = new AsmCmd2(cmdMOV, makeArg(EAX), makeArg(-val));
			code.deleteRange(index, index + 1);
			code.insert(optCmd, index);
			return true;
	}
	return false;
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:13,代码来源:l_optimizer.cpp

示例13: pushDownPopUp

void Optimizer::pushDownPopUp(AsmCode& code){
	for (int i = 0; i < code.size(); i++){
		AsmCmd1* cmd = dynamic_cast<AsmCmd1*>(code[i]);
		int j = i;
		if (cmd && *cmd == cmdPUSH){			
			while (j + 1 < code.size() && !code[j + 1]->changeStack() && !code[j + 1]->operateWith(cmd->argument()))
				j++;
			code.move(i, j);
		} else if (cmd && *cmd == cmdPOP) {
			while (j - 1 > -1 && !code[j - 1]->changeStack() && !code[j - 1]->operateWith(cmd->argument()))
				j--;
			code.move(i, j);
		}
	}
}
开发者ID:Alex-ttt,项目名称:C-Compoiler,代码行数:15,代码来源:l_optimizer.cpp

示例14: GenerateValue

void SymVarConst::GenerateValue(AsmCode& asm_code) const
{
    if (value.GetType() == INT_CONST)
    {
        asm_code.AddCmd(ASM_PUSH, value.GetIntValue());
    }
    else if (value.GetType() == REAL_CONST)
    {
        stringstream s;
        s << value.GetName();
        float f;
        int* p = (int*)&f;
        s >> f;
        asm_code.AddCmd(ASM_PUSH, *p);
    }
开发者ID:bencz,项目名称:Compiler-study,代码行数:15,代码来源:sym_table.cpp

示例15: Optimize

//-----------------------------------------------------------------------------
bool AddSubZero::Optimize(AsmCode& code, int index)
{
    if (index == code.Size())
    {
        return false;
    }

    AsmCmd2* cmd = dynamic_cast<AsmCmd2*>(code[index]);
    if (cmd && (*cmd == cmdSUB || *cmd == cmdADD) && *cmd->GetSecond() == "0")
    {
        code.Delete(index);
        return true;
    }

    return false;
}
开发者ID:GuraYaroslava,项目名称:c-compiler,代码行数:17,代码来源:asm_optimizer.cpp


注:本文中的AsmCode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。