Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions core/iwasm/compilation/aot_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,6 @@ aot_compile_wasm(AOTCompContext *comp_ctx);
bool
aot_emit_llvm_file(AOTCompContext *comp_ctx, const char *file_name);

bool
aot_emit_aot_file(AOTCompContext *comp_ctx, AOTCompData *comp_data,
const char *file_name);

uint8 *
aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
uint32 *p_aot_file_size);

bool
aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name);

Expand Down
61 changes: 37 additions & 24 deletions core/iwasm/compilation/aot_emit_aot_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#include "aot_compiler.h"
#include "aot_emit_aot_file.h"
#include "../aot/aot_runtime.h"

#define PUT_U64_TO_ADDR(addr, value) \
Expand Down Expand Up @@ -1189,9 +1189,9 @@ get_string_literal_section_size(AOTCompContext *comp_ctx,
static uint32
get_custom_sections_size(AOTCompContext *comp_ctx, AOTCompData *comp_data);

static uint32
get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data)
uint32
aot_get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data)
{
uint32 size = 0;
uint32 size_custom_section = 0;
Expand Down Expand Up @@ -4228,7 +4228,7 @@ destroy_relocation_symbol_list(AOTSymbolList *symbol_list)
}
}

static void
void
aot_obj_data_destroy(AOTObjectData *obj_data)
{
if (obj_data->binary)
Expand Down Expand Up @@ -4261,7 +4261,7 @@ aot_obj_data_destroy(AOTObjectData *obj_data)
wasm_runtime_free(obj_data);
}

static AOTObjectData *
AOTObjectData *
aot_obj_data_create(AOTCompContext *comp_ctx)
{
char *err = NULL;
Expand Down Expand Up @@ -4443,25 +4443,48 @@ aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
uint32 *p_aot_file_size)
{
AOTObjectData *obj_data = aot_obj_data_create(comp_ctx);
uint8 *aot_file_buf, *buf, *buf_end;
uint32 aot_file_size, offset = 0;
uint8 *aot_file_buf;
uint32 aot_file_size;

if (!obj_data)
return NULL;

aot_file_size = get_aot_file_size(comp_ctx, comp_data, obj_data);
aot_file_size = aot_get_aot_file_size(comp_ctx, comp_data, obj_data);
if (aot_file_size == 0) {
aot_set_last_error("get aot file size failed");
goto fail1;
}

if (!(buf = aot_file_buf = wasm_runtime_malloc(aot_file_size))) {
if (!(aot_file_buf = wasm_runtime_malloc(aot_file_size))) {
aot_set_last_error("allocate memory failed.");
goto fail1;
}

memset(aot_file_buf, 0, aot_file_size);
buf_end = buf + aot_file_size;
if (!aot_emit_aot_file_buf_ex(comp_ctx, comp_data, obj_data, aot_file_buf,
aot_file_size))
goto fail2;

*p_aot_file_size = aot_file_size;

aot_obj_data_destroy(obj_data);
return aot_file_buf;

fail2:
wasm_runtime_free(aot_file_buf);

fail1:
aot_obj_data_destroy(obj_data);
return NULL;
}

bool
aot_emit_aot_file_buf_ex(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data, uint8 *buf,
uint32 aot_file_size)
{
uint8 *buf_end = buf + aot_file_size;
uint32 offset = 0;

if (!aot_emit_file_header(buf, buf_end, &offset, comp_data, obj_data)
|| !aot_emit_target_info_section(buf, buf_end, &offset, comp_data,
Expand All @@ -4482,28 +4505,18 @@ aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
comp_ctx)
#endif
)
goto fail2;
return false;

#if 0
dump_buf(buf, offset, "sections");
#endif

if (offset != aot_file_size) {
aot_set_last_error("emit aot file failed.");
goto fail2;
return false;
}

*p_aot_file_size = aot_file_size;

aot_obj_data_destroy(obj_data);
return aot_file_buf;

fail2:
wasm_runtime_free(aot_file_buf);

fail1:
aot_obj_data_destroy(obj_data);
return NULL;
return true;
}

bool
Expand Down
44 changes: 44 additions & 0 deletions core/iwasm/compilation/aot_emit_aot_file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

#ifndef _AOT_EMIT_AOT_FILE_H_
#define _AOT_EMIT_AOT_FILE_H_

#include "aot_compiler.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct AOTObjectData AOTObjectData;

AOTObjectData *
aot_obj_data_create(AOTCompContext *comp_ctx);

void
aot_obj_data_destroy(AOTObjectData *obj_data);

uint32
aot_get_aot_file_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data);

bool
aot_emit_aot_file(AOTCompContext *comp_ctx, AOTCompData *comp_data,
const char *file_name);

uint8 *
aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
uint32 *p_aot_file_size);

bool
aot_emit_aot_file_buf_ex(AOTCompContext *comp_ctx, AOTCompData *comp_data,
AOTObjectData *obj_data, uint8 *aot_file_buf,
uint32 aot_file_size);

#ifdef __cplusplus
} /* end of extern "C" */
#endif

#endif /* end of _AOT_EMIT_AOT_FILE_H_ */
22 changes: 22 additions & 0 deletions core/iwasm/include/aot_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ typedef struct AOTCompData *aot_comp_data_t;
struct AOTCompContext;
typedef struct AOTCompContext *aot_comp_context_t;

struct AOTObjectData;
typedef struct AOTObjectData *aot_obj_data_t;

aot_comp_data_t
aot_create_comp_data(void *wasm_module, const char *target_arch,
bool gc_enabled);
Expand Down Expand Up @@ -62,6 +65,25 @@ aot_destroy_comp_context(aot_comp_context_t comp_ctx);
bool
aot_compile_wasm(aot_comp_context_t comp_ctx);

aot_obj_data_t
aot_obj_data_create(aot_comp_context_t comp_ctx);

void
aot_obj_data_destroy(aot_obj_data_t obj_data);

uint32_t
aot_get_aot_file_size(aot_comp_context_t comp_ctx, aot_comp_data_t comp_data,
aot_obj_data_t obj_data);

uint8_t *
aot_emit_aot_file_buf(aot_comp_context_t comp_ctx, aot_comp_data_t comp_data,
uint32_t *p_aot_file_size);

bool
aot_emit_aot_file_buf_ex(aot_comp_context_t comp_ctx, aot_comp_data_t comp_data,
aot_obj_data_t obj_data, uint8_t *aot_file_buf,
uint32_t aot_file_size);

bool
aot_emit_llvm_file(aot_comp_context_t comp_ctx, const char *file_name);

Expand Down