Ejemplo n.º 1
0
Archivo: q.c Proyecto: TheProjecter/qvm
static void emit_ident(struct q *q, const struct node *node)
{
    emit_byte(q, OP_PUSH);
    emit_byte(q, TYPE_STR);
    emit(q, &node->vec.len, sizeof(node->vec.len));
    emit(q, node->vec.ptr, node->vec.len);
}
void MacroAssembler::get_thread(Register thread) {

  int segment = NOT_LP64(Assembler::GS_segment) LP64_ONLY(Assembler::FS_segment);
  // Try to emit a Solaris-specific fast TSD/TLS accessor.
  ThreadLocalStorage::pd_tlsAccessMode tlsMode = ThreadLocalStorage::pd_getTlsAccessMode ();
  if (tlsMode == ThreadLocalStorage::pd_tlsAccessIndirect) {            // T1
     // Use thread as a temporary: mov r, gs:[0]; mov r, [r+tlsOffset]
     emit_byte (segment);
     // ExternalAddress doesn't work because it can't take NULL
     AddressLiteral null(0, relocInfo::none);
     movptr (thread, null);
     movptr(thread, Address(thread, ThreadLocalStorage::pd_getTlsOffset())) ;
     return ;
  } else
  if (tlsMode == ThreadLocalStorage::pd_tlsAccessDirect) {              // T2
     // mov r, gs:[tlsOffset]
     emit_byte (segment);
     AddressLiteral tls_off((address)ThreadLocalStorage::pd_getTlsOffset(), relocInfo::none);
     movptr (thread, tls_off);
     return ;
  }

  slow_call_thr_specific(this, thread);

}
Ejemplo n.º 3
0
Archivo: q.c Proyecto: TheProjecter/qvm
static void emit_string_constant(struct q *q, const struct node *node)
{
    char			*dst, *src;
    str_size_t		n = 0;

    /* XXX Must go first, cause expand_code may change q->code pointer */
    if (q->code + q->cc + 2 + sizeof(n) + node->vec.len > q->code + q->cs)
        expand_code(q, node->vec.len + 2 + sizeof(n) + 1);

    dst = q->code + q->cc + 2 + sizeof(n);
    src = node->vec.ptr + 1;

    assert(node->vec.ptr[0] == '"');
    assert(node->vec.ptr[node->vec.len - 1] == '"');
    assert(dst + node->vec.len < q->code + q->cs);

    for (; src < node->vec.ptr + node->vec.len - 1; src++, n++)
        if (*src == '%') {
            dst[n] = hex_ascii_to_int(q,src[1],node->line_no) << 4;
            dst[n] |= hex_ascii_to_int(q, src[2], node->line_no);
            src += 2;
        } else {
            dst[n] = *src;
        }

    emit_byte(q, OP_PUSH);
    emit_byte(q, TYPE_STR);
    emit(q, &n, sizeof(n));
    q->cc += n;
}
Ejemplo n.º 4
0
static void parse_type_assignment()
{
	int local_id = compiler.num_locals++;
	Local *local = &(compiler.locals[local_id]);
	local->name = parser.previous.start;
	local->length = parser.previous.length;

	// Consume the :
	advance();
	consume(TOKEN_IDENTIFIER, "Expected type");

    // Get the identifier
    Type *type = find_type(&parser.previous);
    if (!type)
    {
        error_at(&parser.previous, "Unknown type");
        return;

    }
	// Ignore type for now, otherwise it's not stored in prev

	// Consume the assignment
	consume(TOKEN_ASSIGN, "Expected =");

	advance();
	if (parser.current.type == TOKEN_NO_INIT)
	{
		// No init!
		return;
	}
	expression_after_advance();
    // Conversion here!
	emit_byte(OP_ASSIGN);
	emit_byte((uint8_t)local_id);
}
Ejemplo n.º 5
0
LOCAL void
emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
/* Emit a marker code */
{
  emit_byte(cinfo, 0xFF);
  emit_byte(cinfo, (int) mark);
}
Ejemplo n.º 6
0
void sbitmap_bitmap_show(struct sbitmap *sb, struct seq_file *m)
{
	u8 byte = 0;
	unsigned int byte_bits = 0;
	unsigned int offset = 0;
	int i;

	for (i = 0; i < sb->map_nr; i++) {
		unsigned long word = READ_ONCE(sb->map[i].word);
		unsigned int word_bits = READ_ONCE(sb->map[i].depth);

		while (word_bits > 0) {
			unsigned int bits = min(8 - byte_bits, word_bits);

			byte |= (word & (BIT(bits) - 1)) << byte_bits;
			byte_bits += bits;
			if (byte_bits == 8) {
				emit_byte(m, offset, byte);
				byte = 0;
				byte_bits = 0;
				offset++;
			}
			word >>= bits;
			word_bits -= bits;
		}
	}
	if (byte_bits) {
		emit_byte(m, offset, byte);
		offset++;
	}
	if (offset)
		seq_putc(m, '\n');
}
Ejemplo n.º 7
0
static void and()
{
	// Skip the right argument if the left is true.
	emit_byte(OP_AND);
	int jump = current_chunk()->size;
	emit_byte(0xFF);
	parse_precedence(PREC_AND);
	current_chunk()->code[jump] = (uint8_t)(current_chunk()->size - jump - 1);
}
Ejemplo n.º 8
0
static void emit_modrm_base_offset(int r, int basex86reg, int offset) {
    if (offset == 0) {
        emit_byte(basex86reg | r << 3);
    } else if (offset >= -0x80 && offset < 0x80) {
        emit_byte(0x40 | basex86reg | r << 3);
        emit_byte(offset);
    } else {
        emit_byte(0x80 | basex86reg | r << 3);
        emit_dword(offset);
    }
}
Ejemplo n.º 9
0
LOCAL void
emit_marker (compress_info_ptr cinfo, JPEG_MARKER mark)
#endif	/* XIE_SUPPORTED */
/* Emit a marker code */
{
  emit_byte(cinfo, 0xFF);
  emit_byte(cinfo, mark);
#ifdef XIE_SUPPORTED
  return(0);
#endif	/* XIE_SUPPORTED */
}
Ejemplo n.º 10
0
static void emit_alu_armreg_immediate(int aluop, int armreg, int imm) {
    if (imm >= -0x80 && imm < 0x80) {
        emit_byte(0x83);
        emit_modrm_armreg(aluop, armreg);
        emit_byte(imm);
    } else {
        emit_byte(0x81);
        emit_modrm_armreg(aluop, armreg);
        emit_dword(imm);
    }
}
Ejemplo n.º 11
0
static void emit_alu_x86reg_immediate(int aluop, int x86reg, int imm) {
    if (imm >= -0x80 && imm < 0x80) {
        emit_byte(0x83);
        emit_modrm_x86reg(aluop, x86reg);
        emit_byte(imm);
    } else if (x86reg == EAX) {
        emit_byte(0x05 | aluop << 3);
        emit_dword(imm);
    } else {
        emit_byte(0x81);
        emit_modrm_x86reg(aluop, x86reg);
        emit_dword(imm);
    }
}
Ejemplo n.º 12
0
static void emit_shift_armreg(int shiftop, int armreg, int count) {
    if (count == SHIFT_BY_CL) {
        emit_byte(0xD3);
        emit_modrm_armreg(shiftop, armreg);
    } else if (count == 0) {
        /* no-op */
    } else if (count == 1) {
        emit_byte(0xD1);
        emit_modrm_armreg(shiftop, armreg);
    } else {
        emit_byte(0xC1);
        emit_modrm_armreg(shiftop, armreg);
        emit_byte(count);
    }
}
Ejemplo n.º 13
0
int Plotter::filltype(int level)
{
	emit_byte((int) O_FILLTYPE);
	emit_integer(level);
	emit_terminator();
	return 0;
}
Ejemplo n.º 14
0
double Plotter::ffontsize(double size)
{
	emit_byte(meta_portable_output ? (int) O_FONTSIZE : (int) O_FFONTSIZE);
	emit_float(size);
	emit_terminator();
	return size;
}
Ejemplo n.º 15
0
void emit_dword(int i)
{
	emit_byte(i&0xff);
	emit_byte((i>>8)&0xff);
	emit_byte((i>>16)&0xff);
	emit_byte((i>>24)&0xff);
}
Ejemplo n.º 16
0
static void parse_auto_assignment()
{
	int local_id = compiler.num_locals++;
	Local *local = &(compiler.locals[local_id]);
	local->name = parser.previous.start;
	local->length = parser.previous.length;

	// Consume the :=
	advance();

	// Handle the expression
	expression();
	// Type needed to be deducted here...
	emit_byte(OP_ASSIGN);
	emit_byte((uint8_t)local_id);
}
Ejemplo n.º 17
0
int Plotter::fcont(double x, double y)
{
	emit_byte(meta_portable_output ? (int) O_CONT : (int) O_FCONT);
	emit_float(x);
	emit_float(y);
	emit_terminator();
	return 0;
}
Ejemplo n.º 18
0
int Plotter::flinewidth(double new_line_width)
{
	emit_byte(meta_portable_output ? (int) O_LINEWIDTH : (int)
			  O_FLINEWIDTH);
	emit_float(new_line_width);
	emit_terminator();
	return 0;
}
Ejemplo n.º 19
0
int Plotter::fmove(double x, double y)
{
	emit_byte(meta_portable_output ? (int) O_MOVE : (int) O_FMOVE);
	emit_float(x);
	emit_float(y);
	emit_terminator();
	return 0;
}
Ejemplo n.º 20
0
static inline void emit_jump(uintptr_t target) {
    emit_byte(0xE9);
    int64_t diff = target - ((uintptr_t) out + 4);
    if(diff > INT32_MAX || diff < INT32_MIN)
        assert(false);

    emit_dword(diff);
}
Ejemplo n.º 21
0
/*This is a hack:
 * -regs not saved
 * -stack not aligned */
static inline void emit_call_nosave(uintptr_t target) {
    emit_byte(0xE8);
    int64_t diff = target - ((uintptr_t) out + 4);
    if(diff > INT32_MAX || diff < INT32_MIN)
        assert(false); //Distance doesn't fit into immediate

    emit_dword(diff);
}
Ejemplo n.º 22
0
Archivo: q.c Proyecto: TheProjecter/qvm
static void emit_hash_definition(struct q *q, const struct node *node, int idx)
{
    if (node == NULL) {
        die(q, "%s: line %d: bad hash def", serr, node->line_no);
    } else if (node->tok == ',') {
        emit_hash_definition(q, node->left, idx);
        emit_byte(q, OP_POP);
        emit_hash_definition(q, node->right, idx + 1);
    } else if (node->tok == '=') {
        if (node->left->tok == TOK_IDENT) {
            emit_expr(q, node->right);
            emit_byte(q, OP_DUP);
            emit_byte(q, 1);
            emit_ident(q, node->left);
            emit_byte(q, OP_SET);
        } else {
            die(q, "%s: line %d: bad hash def", serr,node->line_no);
        }
    } else {
        /* Key is the index of the entry in the definition */
        emit_expr(q, node);
        emit_byte(q, OP_DUP);
        emit_byte(q, 1);
        emit_num(q, idx);
        emit_byte(q, OP_SET);
    }
}
Ejemplo n.º 23
0
static void literal()
{
	switch (parser.previous.type)
	{
		case TOKEN_TRUE:
			emit_byte(OP_TRUE);
			break;
		case TOKEN_FALSE:
			emit_byte(OP_FALSE);
			break;
		case TOKEN_NIL:
			emit_byte(OP_NIL);
			break;
		default:
			assert(false && "Can't reach this!");
			return;
	}
}
Ejemplo n.º 24
0
int Plotter::pencolor(int red, int green, int blue)
{
	emit_byte((int) O_PENCOLOR);
	emit_integer(red);
	emit_integer(green);
	emit_integer(blue);
	emit_terminator();
	return 0;
}
Ejemplo n.º 25
0
Archivo: q.c Proyecto: TheProjecter/qvm
static void emit_function_call(struct q *q, const struct node *node)
{
    int	num_params;

    num_params = emit_params(q, node->right, 0);
    emit_num(q, num_params);
    emit_expr(q, node->left);
    emit_byte(q, OP_CALL);
}
Ejemplo n.º 26
0
int Plotter::fbox(double x0, double y0, double x1, double y1)
{
	emit_byte(meta_portable_output ? (int) O_BOX : (int) O_FBOX);
	emit_float(x0);
	emit_float(y0);
	emit_float(x1);
	emit_float(y1);
	emit_terminator();
	return 0;
}
Ejemplo n.º 27
0
int Plotter::fline(double x0, double y0, double x1, double y1)
{
	emit_byte(meta_portable_output ? (int) O_LINE : (int) O_FLINE);
	emit_float(x0);
	emit_float(y0);
	emit_float(x1);
	emit_float(y1);
	emit_terminator();
	return 0;
}
Ejemplo n.º 28
0
int Plotter::fspace(double x0, double y0, double x1, double y1)
{
	emit_byte(meta_portable_output ? (int) O_SPACE : (int) O_FSPACE);
	emit_float(x0);
	emit_float(y0);
	emit_float(x1);
	emit_float(y1);
	emit_terminator();
	return 0;
}
Ejemplo n.º 29
0
static void end_compiler()
{
	emit_byte(OP_RETURN);
#ifdef DEBUG_PRINT_CODE
	if (!parser.had_error)
	{
		disassemble_chunk(current_chunk(), "code");
	}
#endif
}
Ejemplo n.º 30
0
int Plotter::fconcat(double m0, double m1, double m2, double m3, double m4, double m5)
{
	emit_byte((int) O_FCONCAT);
	emit_float(m0);
	emit_float(m1);
	emit_float(m2);
	emit_float(m3);
	emit_float(m4);
	emit_float(m5);
	emit_terminator();
	return 0;
}