本文整理匯總了C++中EmitLn函數的典型用法代碼示例。如果您正苦於以下問題:C++ EmitLn函數的具體用法?C++ EmitLn怎麽用?C++ EmitLn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EmitLn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Add
void Add()
{
Match('+');
Term();
EmitLn("addl (%esp), %eax");
EmitLn("addl $4, %esp");
}
示例2: DoFor
void DoFor() {
char L1[100];
char L2[100];
Match('f');
strcpy(L1, NewLabel());
strcpy(L2, NewLabel());
char Name = GetName();
Match('=');
Expression();
EmitLn("dec rax");
sprintf(tmp, "mov qword [%c], rax", Name);
EmitLn(tmp);
Expression();
EmitLn("push rax");
PostLabel(L1);
sprintf(tmp, "mov rax, qword [%c]", Name);
EmitLn(tmp);
EmitLn("inc rax");
sprintf(tmp, "mov qword [%c], rax", Name);
EmitLn(tmp);
EmitLn("cmp rax, qword [rsp]");
sprintf(tmp, "jg %s", L2);
EmitLn(tmp);
Block();
Match('e');
sprintf(tmp, "jmp %s", L1);
EmitLn(tmp);
PostLabel(L2);
EmitLn("add rsp, 8");
}
示例3: DoWhile
void DoWhile(void)
{
char code[MAXMSG];
char l1[MAXLBL];
char l2[MAXLBL];
Match('w');
NewLabel();
strncpy(l1, label, MAXLBL);
NewLabel();
strncpy(l2, label, MAXLBL);
PostLabel(l1);
BoolExpression();
snprintf(code, MAXMSG, "je .%s", l2);
EmitLn(code);
Block(l2);
Match('e'); // ENDWHILE
printf("#ENDWHILE\n");
snprintf(code, MAXMSG, "jmp .%s", l1);
EmitLn(code);
PostLabel(l2);
}
示例4: DoIf
void DoIf()
{
Condition();
char L1[MAX_BUF];
char L2[MAX_BUF];
strcpy(L1, NewLabel());
strcpy(L2, L1);
sprintf(tmp, "jz %s", L1);
EmitLn(tmp);
Block();
if (Token == 'l') {
/* match *else* statement */
strcpy(L2, NewLabel());
sprintf(tmp, "jmp %s", L2);
EmitLn(tmp);
PostLabel(L1);
Block();
}
PostLabel(L2);
MatchString("ENDIF");
}
示例5: Subtract
void Subtract() {
Match('-');
Term();
EmitLn("pop rbx");
EmitLn("sub rax, rbx");
EmitLn("neg rax");
}
示例6: BoolXor
void BoolXor()
{
Match('~');
BoolTerm();
EmitLn("xor (%esp), %eax");
EmitLn("addl $4, %esp"); /* recover the stack */
}
示例7: DoDo
void DoDo(void)
{
char code[MAXMSG];
char l1[MAXLBL];
char l2[MAXLBL];
Match('d');
NewLabel();
strncpy(l1, label, MAXLBL);
NewLabel();
strncpy(l2, label, MAXLBL); // exit point
printf("# DO\n");
Expression(); // expr1 = repeat count
EmitLn("pushl %eax\t\t# repeat count");
PostLabel(l1);
Block(l2);
EmitLn("popl %ecx");
EmitLn("dec %ecx");
EmitLn("pushl %ecx");
// test
snprintf(code, MAXMSG, "jnz .%s", l1);
EmitLn(code);
Match('e'); // ENDWHILE
printf("#ENDDO\n");
PostLabel(l2);
}
示例8: Greater
void Greater() {
Match('>');
Expression();
EmitLn("cmp rax, [rsp]");
EmitLn("setle al");
}
示例9: DoIf
void DoIf(char *exit_label)
{
char code[MAXMSG];
char l1[MAXLBL];
char l2[MAXLBL];
Match('i');
printf("# IF\n");
NewLabel();
strncpy(l1, label, MAXLBL);
strncpy(l2, label, MAXLBL);
BoolExpression();
snprintf(code, MAXMSG, "je .%s", l1);
EmitLn(code);
printf("# TRUE\n");
// here, tutorial 05 only matches 'e' once, after the if statement
// this doesn't seem to work unless i add Look=='l' to the test in
// Blocks().
Block(exit_label);
if (Look=='l') {
Match('l');
printf("#ELSE\n");
NewLabel();
strncpy(l2, label, MAXLBL);
snprintf(code, MAXMSG, "jmp .%s", l2);
EmitLn(code);
PostLabel(l1);
Block(exit_label);
}
Match('e'); // ENDIF
printf("#ENDIF\n");
PostLabel(l2);
}
示例10: Subtract
void Subtract()
{
Match('-');
Term();
EmitLn("subl (%esp), %eax");
EmitLn("negl %eax");
EmitLn("addl $4, %esp");
}
示例11: Multiply
void Multiply()
{
Match('*');
Factor();
EmitLn("imull (%esp), %eax");
/* push of the stack */
EmitLn("addl $4, %esp");
}
示例12: Greater
void Greater()
{
Match('>');
Expression();
EmitLn("cmp %eax, (%esp)");
EmitLn("setg %al");
EmitLn("addl $4, %esp"); /* recover the stack */
}
示例13: NotEquals
void NotEquals()
{
Match('#');
Expression();
EmitLn("cmp (%esp), %eax");
EmitLn("setne %al");
EmitLn("addl $4, %esp"); /* recover the stack */
}
示例14: Divide
void Divide() {
Match('/');
Factor();
EmitLn("mov rbx, rax");
EmitLn("pop rax");
EmitLn("cqo");
EmitLn("idiv rbx");
}
示例15: Less
void Less()
{
Match('<');
Expression();
EmitLn("cmp %eax, (%esp)");
EmitLn("setl %al");
EmitLn("addl $4, %esp"); /* recover the stack */
}