Skip to content
Snippets Groups Projects
Select Git revision
  • 4d7be7df9d41f769a4c783604dc15d88c7dcddaa
  • master default protected
  • reboot-to-bootloader
  • fix-off-by-one
  • genofire/ble-personal_state
  • ios-workarounds
  • schneider/maxim-sdk-update
  • rahix/simple_menu
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • renze/hatchery_apps
  • schneider/fundamental-test
  • koalo/factory-reset
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
29 results

init.gdb

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    emitbc.c 26.16 KiB
    #include <unistd.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <stdio.h>
    #include <string.h>
    #include <assert.h>
    
    #include "misc.h"
    #include "mpconfig.h"
    #include "qstr.h"
    #include "lexer.h"
    #include "parse.h"
    #include "scope.h"
    #include "runtime0.h"
    #include "emit.h"
    #include "bc0.h"
    
    struct _emit_t {
        pass_kind_t pass;
        int stack_size;
        bool last_emit_was_return_value;
    
        scope_t *scope;
    
        uint last_source_line_offset;
        uint last_source_line;
    
        uint max_num_labels;
        uint *label_offsets;
    
        uint code_info_offset;
        uint code_info_size;
        uint byte_code_offset;
        uint byte_code_size;
        byte *code_base; // stores both byte code and code info
        byte dummy_data[8];
    };
    
    emit_t *emit_bc_new(uint max_num_labels) {
        emit_t *emit = m_new0(emit_t, 1);
        emit->max_num_labels = max_num_labels;
        emit->label_offsets = m_new(uint, emit->max_num_labels);
        return emit;
    }
    
    void emit_bc_free(emit_t *emit) {
        m_del(uint, emit->label_offsets, emit->max_num_labels);
        m_del_obj(emit_t, emit);
    }
    
    // all functions must go through this one to emit code info
    static byte* emit_get_cur_to_write_code_info(emit_t* emit, int num_bytes_to_write) {
        //printf("emit %d\n", num_bytes_to_write);
        if (emit->pass < PASS_3) {
            emit->code_info_offset += num_bytes_to_write;
            return emit->dummy_data;
        } else {
            assert(emit->code_info_offset + num_bytes_to_write <= emit->code_info_size);
            byte *c = emit->code_base + emit->code_info_offset;
            emit->code_info_offset += num_bytes_to_write;
            return c;
        }
    }
    
    static void emit_write_code_info_qstr(emit_t* emit, qstr qstr) {
        byte* c = emit_get_cur_to_write_code_info(emit, 4);
        // TODO variable length encoding for qstr
        c[0] = qstr & 0xff;
        c[1] = (qstr >> 8) & 0xff;
        c[2] = (qstr >> 16) & 0xff;