Extract shared IO/parse/decode/run utilities
add artifact/ref IO, format parse, opreg formatting, PEL decode/run modules refactor PEL/ASL CLIs and pel_run/seed to use shared helpers update build to include new sources and headers
This commit is contained in:
parent
74eed45a5a
commit
bdbe9cd6fc
|
|
@ -61,8 +61,10 @@ set(AMDUAT_UTIL_SRCS
|
||||||
|
|
||||||
set(AMDUAT_ASL_SRCS
|
set(AMDUAT_ASL_SRCS
|
||||||
src/kernel/asl/core.c
|
src/kernel/asl/core.c
|
||||||
|
src/near_core/asl/artifact_io.c
|
||||||
src/near_core/asl/io.c
|
src/near_core/asl/io.c
|
||||||
src/near_core/asl/parse.c
|
src/near_core/asl/parse.c
|
||||||
|
src/near_core/asl/ref_io.c
|
||||||
src/near_core/asl/store.c
|
src/near_core/asl/store.c
|
||||||
src/near_core/asl/ref_text.c
|
src/near_core/asl/ref_text.c
|
||||||
src/near_core/asl/registry.c
|
src/near_core/asl/registry.c
|
||||||
|
|
@ -84,15 +86,19 @@ set(AMDUAT_ENC_SRCS
|
||||||
|
|
||||||
set(AMDUAT_FORMAT_SRCS
|
set(AMDUAT_FORMAT_SRCS
|
||||||
src/near_core/format/json.c
|
src/near_core/format/json.c
|
||||||
|
src/near_core/format/opreg_util.c
|
||||||
|
src/near_core/format/parse.c
|
||||||
src/near_core/format/ref.c
|
src/near_core/format/ref.c
|
||||||
src/near_core/format/pel.c
|
src/near_core/format/pel.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set(AMDUAT_PEL_SRCS
|
set(AMDUAT_PEL_SRCS
|
||||||
src/kernel/pel/core.c
|
src/kernel/pel/core.c
|
||||||
|
src/pel_stack/decode.c
|
||||||
src/pel_stack/surf/surf.c
|
src/pel_stack/surf/surf.c
|
||||||
src/pel_stack/program_dag/program_dag.c
|
src/pel_stack/program_dag/program_dag.c
|
||||||
src/pel_stack/program_dag/program_dag_desc.c
|
src/pel_stack/program_dag/program_dag_desc.c
|
||||||
|
src/pel_stack/run.c
|
||||||
src/pel_stack/trace_dag/trace_dag.c
|
src/pel_stack/trace_dag/trace_dag.c
|
||||||
src/pel_stack/opreg/kernel.c
|
src/pel_stack/opreg/kernel.c
|
||||||
src/pel_stack/opreg/kernel_params.c
|
src/pel_stack/opreg/kernel_params.c
|
||||||
|
|
|
||||||
33
include/amduat/asl/artifact_io.h
Normal file
33
include/amduat/asl/artifact_io.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#ifndef AMDUAT_ASL_ARTIFACT_IO_H
|
||||||
|
#define AMDUAT_ASL_ARTIFACT_IO_H
|
||||||
|
|
||||||
|
#include "amduat/asl/core.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
AMDUAT_ASL_IO_RAW = 0,
|
||||||
|
AMDUAT_ASL_IO_ARTIFACT = 1
|
||||||
|
} amduat_asl_io_format_t;
|
||||||
|
|
||||||
|
/* For AMDUAT_ASL_IO_RAW, out_artifact takes ownership of input bytes. */
|
||||||
|
bool amduat_asl_artifact_from_bytes(amduat_octets_t input,
|
||||||
|
amduat_asl_io_format_t format,
|
||||||
|
bool has_type_tag,
|
||||||
|
amduat_type_tag_t type_tag,
|
||||||
|
amduat_artifact_t *out_artifact);
|
||||||
|
|
||||||
|
bool amduat_asl_artifact_expect_type_tag(const amduat_artifact_t *artifact,
|
||||||
|
amduat_type_tag_t expected);
|
||||||
|
|
||||||
|
void amduat_asl_artifact_free(amduat_artifact_t *artifact);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_ASL_ARTIFACT_IO_H */
|
||||||
29
include/amduat/asl/ref_io.h
Normal file
29
include/amduat/asl/ref_io.h
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef AMDUAT_ASL_REF_IO_H
|
||||||
|
#define AMDUAT_ASL_REF_IO_H
|
||||||
|
|
||||||
|
#include "amduat/asl/core.h"
|
||||||
|
#include "amduat/format/ref.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool amduat_asl_ref_decode_format(amduat_format_ref_format_t fmt,
|
||||||
|
amduat_octets_t input,
|
||||||
|
amduat_reference_t *out_ref);
|
||||||
|
|
||||||
|
bool amduat_asl_ref_list_parse(amduat_octets_t input,
|
||||||
|
amduat_format_ref_format_t fmt,
|
||||||
|
amduat_reference_t **out_refs,
|
||||||
|
size_t *out_len);
|
||||||
|
|
||||||
|
void amduat_asl_ref_list_free(amduat_reference_t *refs, size_t len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_ASL_REF_IO_H */
|
||||||
37
include/amduat/format/opreg_util.h
Normal file
37
include/amduat/format/opreg_util.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef AMDUAT_FORMAT_OPREG_UTIL_H
|
||||||
|
#define AMDUAT_FORMAT_OPREG_UTIL_H
|
||||||
|
|
||||||
|
#include "amduat/asl/core.h"
|
||||||
|
#include "amduat/format/output.h"
|
||||||
|
#include "amduat/pel/opreg_kernel.h"
|
||||||
|
#include "amduat/pel/opreg_kernel_params.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool amduat_pel_op_parse_name(const char *text,
|
||||||
|
amduat_octets_t *out_name,
|
||||||
|
uint32_t *out_version);
|
||||||
|
|
||||||
|
bool amduat_format_pel_op_desc(FILE *stream,
|
||||||
|
const amduat_pel_kernel_op_desc_t *desc,
|
||||||
|
amduat_octets_t op_name,
|
||||||
|
uint32_t version,
|
||||||
|
amduat_format_output_t format);
|
||||||
|
|
||||||
|
bool amduat_format_pel_op_params(FILE *stream,
|
||||||
|
const amduat_pel_kernel_params_t *params,
|
||||||
|
amduat_octets_t op_name,
|
||||||
|
uint32_t version,
|
||||||
|
amduat_format_output_t format);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_FORMAT_OPREG_UTIL_H */
|
||||||
27
include/amduat/format/parse.h
Normal file
27
include/amduat/format/parse.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef AMDUAT_FORMAT_PARSE_H
|
||||||
|
#define AMDUAT_FORMAT_PARSE_H
|
||||||
|
|
||||||
|
#include "amduat/asl/artifact_io.h"
|
||||||
|
#include "amduat/format/output.h"
|
||||||
|
#include "amduat/format/ref.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool amduat_format_ref_parse(const char *text,
|
||||||
|
amduat_format_ref_format_t *out_fmt);
|
||||||
|
|
||||||
|
bool amduat_format_output_parse(const char *text,
|
||||||
|
amduat_format_output_t *out_fmt);
|
||||||
|
|
||||||
|
bool amduat_asl_io_format_parse(const char *text,
|
||||||
|
amduat_asl_io_format_t *out_fmt);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_FORMAT_PARSE_H */
|
||||||
32
include/amduat/pel/decode.h
Normal file
32
include/amduat/pel/decode.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef AMDUAT_PEL_DECODE_H
|
||||||
|
#define AMDUAT_PEL_DECODE_H
|
||||||
|
|
||||||
|
#include "amduat/asl/core.h"
|
||||||
|
#include "amduat/pel/program_dag.h"
|
||||||
|
#include "amduat/pel/surf.h"
|
||||||
|
#include "amduat/pel/trace_dag.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool amduat_pel_program_decode_artifact(const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_program_t *out_program);
|
||||||
|
|
||||||
|
bool amduat_pel_trace_decode_artifact(const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_trace_dag_value_t *out_trace);
|
||||||
|
|
||||||
|
bool amduat_pel_result_decode_artifact(
|
||||||
|
const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_surface_execution_result_t *out_result);
|
||||||
|
|
||||||
|
bool amduat_pel_program_validate_artifact(const amduat_artifact_t *artifact,
|
||||||
|
bool *out_valid);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_PEL_DECODE_H */
|
||||||
44
include/amduat/pel/run.h
Normal file
44
include/amduat/pel/run.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef AMDUAT_PEL_RUN_H
|
||||||
|
#define AMDUAT_PEL_RUN_H
|
||||||
|
|
||||||
|
#include "amduat/asl/core.h"
|
||||||
|
#include "amduat/asl/store.h"
|
||||||
|
#include "amduat/pel/core.h"
|
||||||
|
#include "amduat/pel/surf.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
amduat_reference_t result_ref;
|
||||||
|
amduat_reference_t *output_refs;
|
||||||
|
size_t output_refs_len;
|
||||||
|
bool has_result_value;
|
||||||
|
amduat_pel_surface_execution_result_t result_value;
|
||||||
|
} amduat_pel_run_result_t;
|
||||||
|
|
||||||
|
bool amduat_pel_surf_run_with_result(amduat_asl_store_t *store,
|
||||||
|
amduat_reference_t scheme_ref,
|
||||||
|
amduat_reference_t program_ref,
|
||||||
|
const amduat_reference_t *input_refs,
|
||||||
|
size_t input_refs_len,
|
||||||
|
bool has_params_ref,
|
||||||
|
amduat_reference_t params_ref,
|
||||||
|
amduat_pel_run_result_t *out_run);
|
||||||
|
|
||||||
|
bool amduat_pel_exec_program_bytes(amduat_octets_t program_bytes,
|
||||||
|
const amduat_artifact_t *inputs,
|
||||||
|
size_t inputs_len,
|
||||||
|
amduat_artifact_t **out_outputs,
|
||||||
|
size_t *out_outputs_len,
|
||||||
|
amduat_pel_execution_result_value_t *out_result);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* AMDUAT_PEL_RUN_H */
|
||||||
49
src/near_core/asl/artifact_io.c
Normal file
49
src/near_core/asl/artifact_io.c
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "amduat/asl/artifact_io.h"
|
||||||
|
|
||||||
|
#include "amduat/enc/asl1_core_codec.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool amduat_asl_artifact_from_bytes(amduat_octets_t input,
|
||||||
|
amduat_asl_io_format_t format,
|
||||||
|
bool has_type_tag,
|
||||||
|
amduat_type_tag_t type_tag,
|
||||||
|
amduat_artifact_t *out_artifact) {
|
||||||
|
if (out_artifact == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (input.len != 0 && input.data == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out_artifact, 0, sizeof(*out_artifact));
|
||||||
|
if (format == AMDUAT_ASL_IO_RAW) {
|
||||||
|
*out_artifact = has_type_tag ? amduat_artifact_with_type(input, type_tag)
|
||||||
|
: amduat_artifact(input);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (format == AMDUAT_ASL_IO_ARTIFACT) {
|
||||||
|
return amduat_enc_asl1_core_decode_artifact_v1(input, out_artifact);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_asl_artifact_expect_type_tag(const amduat_artifact_t *artifact,
|
||||||
|
amduat_type_tag_t expected) {
|
||||||
|
if (artifact == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return artifact->has_type_tag && artifact->type_tag.tag_id == expected.tag_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void amduat_asl_artifact_free(amduat_artifact_t *artifact) {
|
||||||
|
if (artifact == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free((void *)artifact->bytes.data);
|
||||||
|
artifact->bytes.data = NULL;
|
||||||
|
artifact->bytes.len = 0u;
|
||||||
|
artifact->has_type_tag = false;
|
||||||
|
artifact->type_tag = amduat_type_tag(0u);
|
||||||
|
}
|
||||||
192
src/near_core/asl/ref_io.c
Normal file
192
src/near_core/asl/ref_io.c
Normal file
|
|
@ -0,0 +1,192 @@
|
||||||
|
#include "amduat/asl/ref_io.h"
|
||||||
|
|
||||||
|
#include "amduat/asl/ref_text.h"
|
||||||
|
#include "amduat/hash/asl1.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void amduat_asl_ref_free(amduat_reference_t *ref) {
|
||||||
|
if (ref == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free((void *)ref->digest.data);
|
||||||
|
ref->digest.data = NULL;
|
||||||
|
ref->digest.len = 0u;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool amduat_asl_ref_decode_hex_bytes(const uint8_t *data,
|
||||||
|
size_t len,
|
||||||
|
amduat_reference_t *out_ref) {
|
||||||
|
size_t start = 0;
|
||||||
|
size_t end = len;
|
||||||
|
char *text;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (data == NULL || out_ref == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (start < end && isspace((unsigned char)data[start])) {
|
||||||
|
++start;
|
||||||
|
}
|
||||||
|
while (end > start && isspace((unsigned char)data[end - 1])) {
|
||||||
|
--end;
|
||||||
|
}
|
||||||
|
if (end <= start) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
text = (char *)malloc(end - start + 1u);
|
||||||
|
if (text == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memcpy(text, data + start, end - start);
|
||||||
|
text[end - start] = '\0';
|
||||||
|
ok = amduat_asl_ref_decode_hex(text, out_ref);
|
||||||
|
free(text);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_asl_ref_decode_format(amduat_format_ref_format_t fmt,
|
||||||
|
amduat_octets_t input,
|
||||||
|
amduat_reference_t *out_ref) {
|
||||||
|
if (out_ref == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (input.len != 0 && input.data == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fmt == AMDUAT_FORMAT_REF_HEX) {
|
||||||
|
return amduat_asl_ref_decode_hex_bytes(input.data, input.len, out_ref);
|
||||||
|
}
|
||||||
|
if (fmt == AMDUAT_FORMAT_REF_BYTES) {
|
||||||
|
return amduat_asl_ref_decode_bytes(input.data, input.len, out_ref);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_asl_ref_list_parse(amduat_octets_t input,
|
||||||
|
amduat_format_ref_format_t fmt,
|
||||||
|
amduat_reference_t **out_refs,
|
||||||
|
size_t *out_len) {
|
||||||
|
amduat_reference_t *refs = NULL;
|
||||||
|
size_t refs_len = 0;
|
||||||
|
|
||||||
|
if (out_refs == NULL || out_len == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*out_refs = NULL;
|
||||||
|
*out_len = 0;
|
||||||
|
if (input.len != 0 && input.data == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fmt == AMDUAT_FORMAT_REF_BYTES) {
|
||||||
|
size_t offset = 0;
|
||||||
|
while (offset < input.len) {
|
||||||
|
amduat_hash_id_t hash_id;
|
||||||
|
const amduat_hash_asl1_desc_t *hash_desc;
|
||||||
|
size_t digest_len;
|
||||||
|
size_t total_len;
|
||||||
|
amduat_reference_t ref;
|
||||||
|
amduat_reference_t *next;
|
||||||
|
|
||||||
|
if (input.len - offset < sizeof(uint16_t)) {
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hash_id = (amduat_hash_id_t)((input.data[offset] << 8u) |
|
||||||
|
input.data[offset + 1u]);
|
||||||
|
hash_desc = amduat_hash_asl1_desc_lookup(hash_id);
|
||||||
|
if (hash_desc == NULL || hash_desc->digest_len == 0) {
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
digest_len = hash_desc->digest_len;
|
||||||
|
total_len = sizeof(uint16_t) + digest_len;
|
||||||
|
if (offset + total_len > input.len) {
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!amduat_asl_ref_decode_bytes(input.data + offset,
|
||||||
|
total_len,
|
||||||
|
&ref)) {
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
next = (amduat_reference_t *)realloc(
|
||||||
|
refs, (refs_len + 1u) * sizeof(*refs));
|
||||||
|
if (next == NULL) {
|
||||||
|
amduat_asl_ref_free(&ref);
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
refs = next;
|
||||||
|
refs[refs_len++] = ref;
|
||||||
|
offset += total_len;
|
||||||
|
}
|
||||||
|
*out_refs = refs;
|
||||||
|
*out_len = refs_len;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < input.len) {
|
||||||
|
size_t start;
|
||||||
|
size_t token_len;
|
||||||
|
amduat_reference_t ref;
|
||||||
|
amduat_reference_t *next;
|
||||||
|
|
||||||
|
while (i < input.len && isspace((unsigned char)input.data[i])) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (i >= input.len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
start = i;
|
||||||
|
while (i < input.len && !isspace((unsigned char)input.data[i])) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
token_len = i - start;
|
||||||
|
|
||||||
|
if (!amduat_asl_ref_decode_hex_bytes(input.data + start,
|
||||||
|
token_len,
|
||||||
|
&ref)) {
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
next = (amduat_reference_t *)realloc(
|
||||||
|
refs, (refs_len + 1u) * sizeof(*refs));
|
||||||
|
if (next == NULL) {
|
||||||
|
amduat_asl_ref_free(&ref);
|
||||||
|
amduat_asl_ref_list_free(refs, refs_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
refs = next;
|
||||||
|
refs[refs_len++] = ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_refs = refs;
|
||||||
|
*out_len = refs_len;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void amduat_asl_ref_list_free(amduat_reference_t *refs, size_t len) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (refs == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i = 0; i < len; ++i) {
|
||||||
|
amduat_asl_ref_free(&refs[i]);
|
||||||
|
}
|
||||||
|
free(refs);
|
||||||
|
}
|
||||||
192
src/near_core/format/opreg_util.c
Normal file
192
src/near_core/format/opreg_util.c
Normal file
|
|
@ -0,0 +1,192 @@
|
||||||
|
#include "amduat/format/opreg_util.h"
|
||||||
|
|
||||||
|
#include "amduat/asl/parse.h"
|
||||||
|
#include "amduat/format/json.h"
|
||||||
|
#include "amduat/format/pel.h"
|
||||||
|
#include "amduat/hash/asl1.h"
|
||||||
|
#include "amduat/util/hex.h"
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool amduat_pel_op_parse_name(const char *text,
|
||||||
|
amduat_octets_t *out_name,
|
||||||
|
uint32_t *out_version) {
|
||||||
|
const char *eq;
|
||||||
|
uint32_t version;
|
||||||
|
|
||||||
|
if (text == NULL || out_name == NULL || out_version == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
eq = strchr(text, '=');
|
||||||
|
if (eq == NULL) {
|
||||||
|
*out_name = amduat_octets(text, strlen(text));
|
||||||
|
*out_version = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eq == text) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!amduat_asl_parse_u32(eq + 1, &version)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_name = amduat_octets(text, (size_t)(eq - text));
|
||||||
|
*out_version = version;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_format_pel_op_desc(FILE *stream,
|
||||||
|
const amduat_pel_kernel_op_desc_t *desc,
|
||||||
|
amduat_octets_t op_name,
|
||||||
|
uint32_t version,
|
||||||
|
amduat_format_output_t format) {
|
||||||
|
if (stream == NULL || desc == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == AMDUAT_FORMAT_OUTPUT_TEXT) {
|
||||||
|
fprintf(stream, "name=%.*s\n", (int)op_name.len, (const char *)op_name.data);
|
||||||
|
fprintf(stream, "version=%u\n", version);
|
||||||
|
fprintf(stream, "kind=%s\n",
|
||||||
|
amduat_format_pel_kernel_kind_name(desc->kind));
|
||||||
|
fprintf(stream, "kernel_op_code=0x%04x\n", desc->kernel_op_code);
|
||||||
|
fprintf(stream, "min_inputs=%zu\n", desc->min_inputs);
|
||||||
|
fprintf(stream, "max_inputs=%zu\n", desc->max_inputs);
|
||||||
|
fprintf(stream, "outputs_len=%zu\n", desc->outputs_len);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs("{\"name\":", stream);
|
||||||
|
amduat_format_json_escape(stream, op_name);
|
||||||
|
fprintf(stream, ",\"version\":%u", version);
|
||||||
|
fputs(",\"kind\":", stream);
|
||||||
|
amduat_format_json_escape(
|
||||||
|
stream,
|
||||||
|
amduat_octets(amduat_format_pel_kernel_kind_name(desc->kind),
|
||||||
|
strlen(amduat_format_pel_kernel_kind_name(desc->kind))));
|
||||||
|
fprintf(stream, ",\"kernel_op_code\":%u", desc->kernel_op_code);
|
||||||
|
fprintf(stream, ",\"min_inputs\":%zu", desc->min_inputs);
|
||||||
|
fprintf(stream, ",\"max_inputs\":%zu", desc->max_inputs);
|
||||||
|
fprintf(stream, ",\"outputs_len\":%zu}\n", desc->outputs_len);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_format_pel_op_params(FILE *stream,
|
||||||
|
const amduat_pel_kernel_params_t *params,
|
||||||
|
amduat_octets_t op_name,
|
||||||
|
uint32_t version,
|
||||||
|
amduat_format_output_t format) {
|
||||||
|
if (stream == NULL || params == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format == AMDUAT_FORMAT_OUTPUT_TEXT) {
|
||||||
|
fprintf(stream, "op=%.*s\n", (int)op_name.len, (const char *)op_name.data);
|
||||||
|
fprintf(stream, "version=%u\n", version);
|
||||||
|
fprintf(stream, "kind=%s\n",
|
||||||
|
amduat_format_pel_kernel_kind_name(params->kind));
|
||||||
|
switch (params->kind) {
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_CONCAT:
|
||||||
|
fprintf(stream, "params=unit\n");
|
||||||
|
break;
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_SLICE:
|
||||||
|
fprintf(stream, "offset=%" PRIu64 "\n",
|
||||||
|
(uint64_t)params->value.slice.offset);
|
||||||
|
fprintf(stream, "length=%" PRIu64 "\n",
|
||||||
|
(uint64_t)params->value.slice.length);
|
||||||
|
break;
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_CONST: {
|
||||||
|
char *hex = NULL;
|
||||||
|
if (!amduat_hex_encode_alloc(params->value.konst.bytes.data,
|
||||||
|
params->value.konst.bytes.len,
|
||||||
|
&hex)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fprintf(stream, "has_type_tag=%s\n",
|
||||||
|
params->value.konst.has_type_tag ? "true" : "false");
|
||||||
|
if (params->value.konst.has_type_tag) {
|
||||||
|
fprintf(stream, "type_tag=0x%08x\n",
|
||||||
|
(unsigned int)params->value.konst.tag_id);
|
||||||
|
}
|
||||||
|
fprintf(stream, "bytes_hex=%s\n", hex);
|
||||||
|
free(hex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_HASH_ASL1: {
|
||||||
|
const amduat_hash_asl1_desc_t *desc_hash =
|
||||||
|
amduat_hash_asl1_desc_lookup(params->value.hash.hash_id);
|
||||||
|
fprintf(stream, "hash_id=0x%04x\n",
|
||||||
|
(unsigned int)params->value.hash.hash_id);
|
||||||
|
if (desc_hash != NULL && desc_hash->name != NULL) {
|
||||||
|
fprintf(stream, "hash_name=%s\n", desc_hash->name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fputs("{\"op\":", stream);
|
||||||
|
amduat_format_json_escape(stream, op_name);
|
||||||
|
fprintf(stream, ",\"version\":%u", version);
|
||||||
|
fputs(",\"kind\":", stream);
|
||||||
|
amduat_format_json_escape(
|
||||||
|
stream,
|
||||||
|
amduat_octets(amduat_format_pel_kernel_kind_name(params->kind),
|
||||||
|
strlen(amduat_format_pel_kernel_kind_name(params->kind))));
|
||||||
|
switch (params->kind) {
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_CONCAT:
|
||||||
|
fputs(",\"params\":null", stream);
|
||||||
|
break;
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_SLICE:
|
||||||
|
fprintf(stream, ",\"offset\":%" PRIu64,
|
||||||
|
(uint64_t)params->value.slice.offset);
|
||||||
|
fprintf(stream, ",\"length\":%" PRIu64,
|
||||||
|
(uint64_t)params->value.slice.length);
|
||||||
|
break;
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_CONST: {
|
||||||
|
char *hex = NULL;
|
||||||
|
if (!amduat_hex_encode_alloc(params->value.konst.bytes.data,
|
||||||
|
params->value.konst.bytes.len,
|
||||||
|
&hex)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fputs(",\"has_type_tag\":", stream);
|
||||||
|
fputs(params->value.konst.has_type_tag ? "true" : "false", stream);
|
||||||
|
if (params->value.konst.has_type_tag) {
|
||||||
|
fprintf(stream, ",\"type_tag\":%u", params->value.konst.tag_id);
|
||||||
|
} else {
|
||||||
|
fputs(",\"type_tag\":null", stream);
|
||||||
|
}
|
||||||
|
fputs(",\"bytes_hex\":", stream);
|
||||||
|
amduat_format_json_escape(stream, amduat_octets(hex, strlen(hex)));
|
||||||
|
free(hex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case AMDUAT_PEL_KERNEL_OP_HASH_ASL1: {
|
||||||
|
const amduat_hash_asl1_desc_t *desc_hash =
|
||||||
|
amduat_hash_asl1_desc_lookup(params->value.hash.hash_id);
|
||||||
|
fprintf(stream, ",\"hash_id\":%u",
|
||||||
|
(unsigned int)params->value.hash.hash_id);
|
||||||
|
fputs(",\"hash_name\":", stream);
|
||||||
|
if (desc_hash != NULL && desc_hash->name != NULL) {
|
||||||
|
amduat_format_json_escape(
|
||||||
|
stream,
|
||||||
|
amduat_octets(desc_hash->name, strlen(desc_hash->name)));
|
||||||
|
} else {
|
||||||
|
fputs("null", stream);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fputs("}\n", stream);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
51
src/near_core/format/parse.c
Normal file
51
src/near_core/format/parse.c
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include "amduat/format/parse.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool amduat_format_ref_parse(const char *text,
|
||||||
|
amduat_format_ref_format_t *out_fmt) {
|
||||||
|
if (text == NULL || out_fmt == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "hex") == 0) {
|
||||||
|
*out_fmt = AMDUAT_FORMAT_REF_HEX;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "bytes") == 0) {
|
||||||
|
*out_fmt = AMDUAT_FORMAT_REF_BYTES;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_format_output_parse(const char *text,
|
||||||
|
amduat_format_output_t *out_fmt) {
|
||||||
|
if (text == NULL || out_fmt == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "text") == 0) {
|
||||||
|
*out_fmt = AMDUAT_FORMAT_OUTPUT_TEXT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "json") == 0) {
|
||||||
|
*out_fmt = AMDUAT_FORMAT_OUTPUT_JSON;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_asl_io_format_parse(const char *text,
|
||||||
|
amduat_asl_io_format_t *out_fmt) {
|
||||||
|
if (text == NULL || out_fmt == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "raw") == 0) {
|
||||||
|
*out_fmt = AMDUAT_ASL_IO_RAW;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strcmp(text, "artifact") == 0) {
|
||||||
|
*out_fmt = AMDUAT_ASL_IO_ARTIFACT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
67
src/pel_stack/decode.c
Normal file
67
src/pel_stack/decode.c
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#include "amduat/pel/decode.h"
|
||||||
|
|
||||||
|
#include "amduat/enc/pel1_result.h"
|
||||||
|
#include "amduat/enc/pel_program_dag.h"
|
||||||
|
#include "amduat/enc/pel_trace_dag.h"
|
||||||
|
#include "amduat/pel/program_dag_desc.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool amduat_pel_program_decode_artifact(const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_program_t *out_program) {
|
||||||
|
if (artifact == NULL || out_program == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (artifact->has_type_tag &&
|
||||||
|
artifact->type_tag.tag_id != AMDUAT_PEL_TYPE_TAG_PROGRAM_DAG_1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memset(out_program, 0, sizeof(*out_program));
|
||||||
|
return amduat_enc_pel_program_dag_decode_v1(artifact->bytes, out_program);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_pel_trace_decode_artifact(const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_trace_dag_value_t *out_trace) {
|
||||||
|
if (artifact == NULL || out_trace == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (artifact->has_type_tag &&
|
||||||
|
artifact->type_tag.tag_id != AMDUAT_TYPE_TAG_PEL_TRACE_DAG_1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memset(out_trace, 0, sizeof(*out_trace));
|
||||||
|
return amduat_enc_pel_trace_dag_decode_v1(artifact->bytes, out_trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_pel_result_decode_artifact(
|
||||||
|
const amduat_artifact_t *artifact,
|
||||||
|
amduat_pel_surface_execution_result_t *out_result) {
|
||||||
|
if (artifact == NULL || out_result == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (artifact->has_type_tag &&
|
||||||
|
artifact->type_tag.tag_id != AMDUAT_TYPE_TAG_PEL1_RESULT_1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memset(out_result, 0, sizeof(*out_result));
|
||||||
|
return amduat_enc_pel1_result_decode_v1(artifact->bytes, out_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_pel_program_validate_artifact(const amduat_artifact_t *artifact,
|
||||||
|
bool *out_valid) {
|
||||||
|
amduat_pel_program_t program;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (out_valid == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*out_valid = false;
|
||||||
|
if (!amduat_pel_program_decode_artifact(artifact, &program)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = amduat_pel_program_dag_validate(&program);
|
||||||
|
amduat_enc_pel_program_dag_free(&program);
|
||||||
|
*out_valid = ok;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
83
src/pel_stack/run.c
Normal file
83
src/pel_stack/run.c
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include "amduat/pel/run.h"
|
||||||
|
|
||||||
|
#include "amduat/asl/artifact_io.h"
|
||||||
|
#include "amduat/enc/pel1_result.h"
|
||||||
|
#include "amduat/enc/pel_program_dag.h"
|
||||||
|
#include "amduat/pel/program_dag.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool amduat_pel_surf_run_with_result(amduat_asl_store_t *store,
|
||||||
|
amduat_reference_t scheme_ref,
|
||||||
|
amduat_reference_t program_ref,
|
||||||
|
const amduat_reference_t *input_refs,
|
||||||
|
size_t input_refs_len,
|
||||||
|
bool has_params_ref,
|
||||||
|
amduat_reference_t params_ref,
|
||||||
|
amduat_pel_run_result_t *out_run) {
|
||||||
|
amduat_artifact_t result_artifact;
|
||||||
|
|
||||||
|
if (out_run == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memset(out_run, 0, sizeof(*out_run));
|
||||||
|
|
||||||
|
if (!amduat_pel_surf_run(store,
|
||||||
|
scheme_ref,
|
||||||
|
program_ref,
|
||||||
|
input_refs,
|
||||||
|
input_refs_len,
|
||||||
|
has_params_ref,
|
||||||
|
params_ref,
|
||||||
|
&out_run->output_refs,
|
||||||
|
&out_run->output_refs_len,
|
||||||
|
&out_run->result_ref)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&result_artifact, 0, sizeof(result_artifact));
|
||||||
|
if (amduat_asl_store_get(store, out_run->result_ref, &result_artifact) ==
|
||||||
|
AMDUAT_ASL_STORE_OK) {
|
||||||
|
if (amduat_enc_pel1_result_decode_v1(result_artifact.bytes,
|
||||||
|
&out_run->result_value)) {
|
||||||
|
out_run->has_result_value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
amduat_asl_artifact_free(&result_artifact);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool amduat_pel_exec_program_bytes(amduat_octets_t program_bytes,
|
||||||
|
const amduat_artifact_t *inputs,
|
||||||
|
size_t inputs_len,
|
||||||
|
amduat_artifact_t **out_outputs,
|
||||||
|
size_t *out_outputs_len,
|
||||||
|
amduat_pel_execution_result_value_t *out_result) {
|
||||||
|
amduat_pel_program_t program;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
|
if (out_outputs == NULL || out_outputs_len == NULL || out_result == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (inputs_len != 0 && inputs == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_outputs = NULL;
|
||||||
|
*out_outputs_len = 0;
|
||||||
|
memset(out_result, 0, sizeof(*out_result));
|
||||||
|
|
||||||
|
memset(&program, 0, sizeof(program));
|
||||||
|
if (!amduat_enc_pel_program_dag_decode_v1(program_bytes, &program)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = amduat_pel_program_dag_exec(&program,
|
||||||
|
inputs,
|
||||||
|
inputs_len,
|
||||||
|
out_outputs,
|
||||||
|
out_outputs_len,
|
||||||
|
out_result);
|
||||||
|
amduat_enc_pel_program_dag_free(&program);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
|
#include "amduat/asl/artifact_io.h"
|
||||||
#include "amduat/asl/asl_store_fs.h"
|
#include "amduat/asl/asl_store_fs.h"
|
||||||
#include "amduat/asl/asl_store_fs_meta.h"
|
#include "amduat/asl/asl_store_fs_meta.h"
|
||||||
#include "amduat/asl/io.h"
|
#include "amduat/asl/io.h"
|
||||||
#include "amduat/asl/parse.h"
|
#include "amduat/asl/parse.h"
|
||||||
|
#include "amduat/asl/ref_io.h"
|
||||||
#include "amduat/asl/ref_text.h"
|
#include "amduat/asl/ref_text.h"
|
||||||
#include "amduat/asl/store.h"
|
#include "amduat/asl/store.h"
|
||||||
#include "amduat/enc/asl1_core_codec.h"
|
#include "amduat/enc/asl1_core_codec.h"
|
||||||
|
#include "amduat/format/parse.h"
|
||||||
|
#include "amduat/format/ref.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -24,16 +28,6 @@ enum {
|
||||||
|
|
||||||
static const char *const AMDUAT_ASL_CLI_DEFAULT_ROOT = ".amduat-asl";
|
static const char *const AMDUAT_ASL_CLI_DEFAULT_ROOT = ".amduat-asl";
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
AMDUAT_ASL_CLI_REF_HEX = 0,
|
|
||||||
AMDUAT_ASL_CLI_REF_BYTES = 1
|
|
||||||
} amduat_asl_cli_ref_format_t;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
AMDUAT_ASL_CLI_IO_RAW = 0,
|
|
||||||
AMDUAT_ASL_CLI_IO_ARTIFACT = 1
|
|
||||||
} amduat_asl_cli_io_format_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *root;
|
const char *root;
|
||||||
const char *store_id;
|
const char *store_id;
|
||||||
|
|
@ -47,8 +41,8 @@ typedef struct {
|
||||||
const char *root;
|
const char *root;
|
||||||
const char *input_path;
|
const char *input_path;
|
||||||
const char *output_path;
|
const char *output_path;
|
||||||
amduat_asl_cli_io_format_t input_format;
|
amduat_asl_io_format_t input_format;
|
||||||
amduat_asl_cli_ref_format_t ref_format;
|
amduat_format_ref_format_t ref_format;
|
||||||
bool has_type_tag;
|
bool has_type_tag;
|
||||||
amduat_type_tag_t type_tag;
|
amduat_type_tag_t type_tag;
|
||||||
bool quiet;
|
bool quiet;
|
||||||
|
|
@ -58,8 +52,8 @@ typedef struct {
|
||||||
const char *root;
|
const char *root;
|
||||||
const char *ref;
|
const char *ref;
|
||||||
const char *output_path;
|
const char *output_path;
|
||||||
amduat_asl_cli_io_format_t output_format;
|
amduat_asl_io_format_t output_format;
|
||||||
amduat_asl_cli_ref_format_t ref_format;
|
amduat_format_ref_format_t ref_format;
|
||||||
bool has_expect_type_tag;
|
bool has_expect_type_tag;
|
||||||
amduat_type_tag_t expect_type_tag;
|
amduat_type_tag_t expect_type_tag;
|
||||||
bool print_type_tag;
|
bool print_type_tag;
|
||||||
|
|
@ -95,40 +89,6 @@ static void amduat_asl_cli_print_usage(FILE *stream) {
|
||||||
AMDUAT_ASL_CLI_DEFAULT_ROOT);
|
AMDUAT_ASL_CLI_DEFAULT_ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool amduat_asl_cli_parse_ref_format(
|
|
||||||
const char *text,
|
|
||||||
amduat_asl_cli_ref_format_t *out_fmt) {
|
|
||||||
if (text == NULL || out_fmt == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "hex") == 0) {
|
|
||||||
*out_fmt = AMDUAT_ASL_CLI_REF_HEX;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "bytes") == 0) {
|
|
||||||
*out_fmt = AMDUAT_ASL_CLI_REF_BYTES;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool amduat_asl_cli_parse_io_format(
|
|
||||||
const char *text,
|
|
||||||
amduat_asl_cli_io_format_t *out_fmt) {
|
|
||||||
if (text == NULL || out_fmt == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "raw") == 0) {
|
|
||||||
*out_fmt = AMDUAT_ASL_CLI_IO_RAW;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "artifact") == 0) {
|
|
||||||
*out_fmt = AMDUAT_ASL_CLI_IO_ARTIFACT;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void amduat_asl_cli_free_reference(amduat_reference_t *ref) {
|
static void amduat_asl_cli_free_reference(amduat_reference_t *ref) {
|
||||||
if (ref == NULL) {
|
if (ref == NULL) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -138,15 +98,6 @@ static void amduat_asl_cli_free_reference(amduat_reference_t *ref) {
|
||||||
ref->digest.len = 0u;
|
ref->digest.len = 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void amduat_asl_cli_free_artifact(amduat_artifact_t *artifact) {
|
|
||||||
if (artifact == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free((void *)artifact->bytes.data);
|
|
||||||
artifact->bytes.data = NULL;
|
|
||||||
artifact->bytes.len = 0u;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void amduat_asl_cli_print_store_meta(
|
static void amduat_asl_cli_print_store_meta(
|
||||||
const amduat_asl_store_fs_config_t *cfg) {
|
const amduat_asl_store_fs_config_t *cfg) {
|
||||||
if (cfg == NULL) {
|
if (cfg == NULL) {
|
||||||
|
|
@ -298,8 +249,8 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
opts.root = AMDUAT_ASL_CLI_DEFAULT_ROOT;
|
opts.root = AMDUAT_ASL_CLI_DEFAULT_ROOT;
|
||||||
opts.input_path = "-";
|
opts.input_path = "-";
|
||||||
opts.output_path = "-";
|
opts.output_path = "-";
|
||||||
opts.input_format = AMDUAT_ASL_CLI_IO_RAW;
|
opts.input_format = AMDUAT_ASL_IO_RAW;
|
||||||
opts.ref_format = AMDUAT_ASL_CLI_REF_HEX;
|
opts.ref_format = AMDUAT_FORMAT_REF_HEX;
|
||||||
|
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "--root") == 0) {
|
if (strcmp(argv[i], "--root") == 0) {
|
||||||
|
|
@ -329,7 +280,7 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: --input-format requires a value\n");
|
fprintf(stderr, "error: --input-format requires a value\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
if (!amduat_asl_cli_parse_io_format(argv[++i], &opts.input_format)) {
|
if (!amduat_asl_io_format_parse(argv[++i], &opts.input_format)) {
|
||||||
fprintf(stderr, "error: invalid input-format\n");
|
fprintf(stderr, "error: invalid input-format\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
@ -338,7 +289,7 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: --ref-format requires a value\n");
|
fprintf(stderr, "error: --ref-format requires a value\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
if (!amduat_asl_cli_parse_ref_format(argv[++i], &opts.ref_format)) {
|
if (!amduat_format_ref_parse(argv[++i], &opts.ref_format)) {
|
||||||
fprintf(stderr, "error: invalid ref-format\n");
|
fprintf(stderr, "error: invalid ref-format\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +310,7 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.input_format == AMDUAT_ASL_CLI_IO_ARTIFACT && opts.has_type_tag) {
|
if (opts.input_format == AMDUAT_ASL_IO_ARTIFACT && opts.has_type_tag) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"error: --type-tag is not valid with --input-format artifact\n");
|
"error: --type-tag is not valid with --input-format artifact\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
|
|
@ -382,21 +333,17 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
return AMDUAT_ASL_CLI_EXIT_IO;
|
return AMDUAT_ASL_CLI_EXIT_IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.input_format == AMDUAT_ASL_CLI_IO_ARTIFACT) {
|
ok = amduat_asl_artifact_from_bytes(amduat_octets(input_bytes, input_len),
|
||||||
ok = amduat_enc_asl1_core_decode_artifact_v1(
|
opts.input_format,
|
||||||
amduat_octets(input_bytes, input_len),
|
opts.has_type_tag,
|
||||||
&artifact);
|
opts.type_tag,
|
||||||
|
&artifact);
|
||||||
|
if (opts.input_format == AMDUAT_ASL_IO_ARTIFACT) {
|
||||||
free(input_bytes);
|
free(input_bytes);
|
||||||
if (!ok) {
|
}
|
||||||
fprintf(stderr, "error: invalid artifact encoding\n");
|
if (!ok) {
|
||||||
return AMDUAT_ASL_CLI_EXIT_CODEC;
|
fprintf(stderr, "error: invalid artifact encoding\n");
|
||||||
}
|
return AMDUAT_ASL_CLI_EXIT_CODEC;
|
||||||
} else {
|
|
||||||
artifact = opts.has_type_tag
|
|
||||||
? amduat_artifact_with_type(
|
|
||||||
amduat_octets(input_bytes, input_len),
|
|
||||||
opts.type_tag)
|
|
||||||
: amduat_artifact(amduat_octets(input_bytes, input_len));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&ref, 0, sizeof(ref));
|
memset(&ref, 0, sizeof(ref));
|
||||||
|
|
@ -409,7 +356,7 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
amduat_asl_cli_store_error_str(err));
|
amduat_asl_cli_store_error_str(err));
|
||||||
exit_code = amduat_asl_cli_map_store_error(err);
|
exit_code = amduat_asl_cli_map_store_error(err);
|
||||||
} else {
|
} else {
|
||||||
if (opts.ref_format == AMDUAT_ASL_CLI_REF_HEX) {
|
if (opts.ref_format == AMDUAT_FORMAT_REF_HEX) {
|
||||||
char *hex_ref = NULL;
|
char *hex_ref = NULL;
|
||||||
if (!amduat_asl_ref_encode_hex(ref, &hex_ref)) {
|
if (!amduat_asl_ref_encode_hex(ref, &hex_ref)) {
|
||||||
fprintf(stderr, "error: failed to encode reference\n");
|
fprintf(stderr, "error: failed to encode reference\n");
|
||||||
|
|
@ -455,11 +402,7 @@ static int amduat_asl_cli_cmd_put(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.input_format == AMDUAT_ASL_CLI_IO_ARTIFACT) {
|
amduat_asl_artifact_free(&artifact);
|
||||||
amduat_asl_cli_free_artifact(&artifact);
|
|
||||||
} else {
|
|
||||||
free((void *)artifact.bytes.data);
|
|
||||||
}
|
|
||||||
amduat_asl_cli_free_reference(&ref);
|
amduat_asl_cli_free_reference(&ref);
|
||||||
return exit_code;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
@ -481,8 +424,8 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
opts.root = AMDUAT_ASL_CLI_DEFAULT_ROOT;
|
opts.root = AMDUAT_ASL_CLI_DEFAULT_ROOT;
|
||||||
opts.output_path = "-";
|
opts.output_path = "-";
|
||||||
opts.output_format = AMDUAT_ASL_CLI_IO_RAW;
|
opts.output_format = AMDUAT_ASL_IO_RAW;
|
||||||
opts.ref_format = AMDUAT_ASL_CLI_REF_HEX;
|
opts.ref_format = AMDUAT_FORMAT_REF_HEX;
|
||||||
|
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "--ref") == 0) {
|
if (strcmp(argv[i], "--ref") == 0) {
|
||||||
|
|
@ -502,7 +445,7 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: --ref-format requires a value\n");
|
fprintf(stderr, "error: --ref-format requires a value\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
if (!amduat_asl_cli_parse_ref_format(argv[++i], &opts.ref_format)) {
|
if (!amduat_format_ref_parse(argv[++i], &opts.ref_format)) {
|
||||||
fprintf(stderr, "error: invalid ref-format\n");
|
fprintf(stderr, "error: invalid ref-format\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
@ -517,7 +460,7 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: --output-format requires a value\n");
|
fprintf(stderr, "error: --output-format requires a value\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
if (!amduat_asl_cli_parse_io_format(argv[++i], &opts.output_format)) {
|
if (!amduat_asl_io_format_parse(argv[++i], &opts.output_format)) {
|
||||||
fprintf(stderr, "error: invalid output-format\n");
|
fprintf(stderr, "error: invalid output-format\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
return AMDUAT_ASL_CLI_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
@ -561,8 +504,10 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
amduat_asl_store_init(&store, cfg.config, amduat_asl_store_fs_ops(), &fs);
|
amduat_asl_store_init(&store, cfg.config, amduat_asl_store_fs_ops(), &fs);
|
||||||
|
|
||||||
memset(&ref, 0, sizeof(ref));
|
memset(&ref, 0, sizeof(ref));
|
||||||
if (opts.ref_format == AMDUAT_ASL_CLI_REF_HEX) {
|
if (opts.ref_format == AMDUAT_FORMAT_REF_HEX) {
|
||||||
if (!amduat_asl_ref_decode_hex(opts.ref, &ref)) {
|
ok = amduat_asl_ref_decode_format(
|
||||||
|
opts.ref_format, amduat_octets(opts.ref, strlen(opts.ref)), &ref);
|
||||||
|
if (!ok) {
|
||||||
fprintf(stderr, "error: invalid hex reference\n");
|
fprintf(stderr, "error: invalid hex reference\n");
|
||||||
return AMDUAT_ASL_CLI_EXIT_CODEC;
|
return AMDUAT_ASL_CLI_EXIT_CODEC;
|
||||||
}
|
}
|
||||||
|
|
@ -573,7 +518,8 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: failed to read reference: %s\n", opts.ref);
|
fprintf(stderr, "error: failed to read reference: %s\n", opts.ref);
|
||||||
return AMDUAT_ASL_CLI_EXIT_IO;
|
return AMDUAT_ASL_CLI_EXIT_IO;
|
||||||
}
|
}
|
||||||
ok = amduat_asl_ref_decode_bytes(ref_bytes, ref_len, &ref);
|
ok = amduat_asl_ref_decode_format(
|
||||||
|
opts.ref_format, amduat_octets(ref_bytes, ref_len), &ref);
|
||||||
free(ref_bytes);
|
free(ref_bytes);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
fprintf(stderr, "error: invalid reference bytes\n");
|
fprintf(stderr, "error: invalid reference bytes\n");
|
||||||
|
|
@ -591,15 +537,15 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
exit_code = amduat_asl_cli_map_store_error(err);
|
exit_code = amduat_asl_cli_map_store_error(err);
|
||||||
} else {
|
} else {
|
||||||
if (opts.has_expect_type_tag) {
|
if (opts.has_expect_type_tag) {
|
||||||
if (!artifact.has_type_tag ||
|
if (!amduat_asl_artifact_expect_type_tag(&artifact,
|
||||||
artifact.type_tag.tag_id != opts.expect_type_tag.tag_id) {
|
opts.expect_type_tag)) {
|
||||||
fprintf(stderr, "error: type-tag mismatch\n");
|
fprintf(stderr, "error: type-tag mismatch\n");
|
||||||
exit_code = AMDUAT_ASL_CLI_EXIT_UNSUPPORTED;
|
exit_code = AMDUAT_ASL_CLI_EXIT_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exit_code == AMDUAT_ASL_CLI_EXIT_OK) {
|
if (exit_code == AMDUAT_ASL_CLI_EXIT_OK) {
|
||||||
if (opts.output_format == AMDUAT_ASL_CLI_IO_RAW) {
|
if (opts.output_format == AMDUAT_ASL_IO_RAW) {
|
||||||
if (!amduat_asl_write_path(opts.output_path,
|
if (!amduat_asl_write_path(opts.output_path,
|
||||||
artifact.bytes.data,
|
artifact.bytes.data,
|
||||||
artifact.bytes.len)) {
|
artifact.bytes.len)) {
|
||||||
|
|
@ -642,7 +588,7 @@ static int amduat_asl_cli_cmd_get(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
amduat_asl_cli_free_reference(&ref);
|
amduat_asl_cli_free_reference(&ref);
|
||||||
amduat_asl_cli_free_artifact(&artifact);
|
amduat_asl_artifact_free(&artifact);
|
||||||
return exit_code;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -6,6 +6,7 @@
|
||||||
#include "amduat/asl/store.h"
|
#include "amduat/asl/store.h"
|
||||||
#include "amduat/enc/pel1_result.h"
|
#include "amduat/enc/pel1_result.h"
|
||||||
#include "amduat/pel/program_dag_desc.h"
|
#include "amduat/pel/program_dag_desc.h"
|
||||||
|
#include "amduat/pel/run.h"
|
||||||
#include "amduat/pel/surf.h"
|
#include "amduat/pel/surf.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
@ -161,12 +162,7 @@ int main(int argc, char **argv) {
|
||||||
amduat_reference_t program_ref;
|
amduat_reference_t program_ref;
|
||||||
amduat_reference_t params_ref;
|
amduat_reference_t params_ref;
|
||||||
amduat_reference_t *input_refs = NULL;
|
amduat_reference_t *input_refs = NULL;
|
||||||
amduat_reference_t *output_refs = NULL;
|
amduat_pel_run_result_t run_result;
|
||||||
size_t output_refs_len = 0;
|
|
||||||
amduat_reference_t result_ref;
|
|
||||||
amduat_artifact_t result_artifact;
|
|
||||||
amduat_pel_surface_execution_result_t result_value;
|
|
||||||
bool has_result_value = false;
|
|
||||||
bool has_trace_ref = false;
|
bool has_trace_ref = false;
|
||||||
amduat_reference_t trace_ref;
|
amduat_reference_t trace_ref;
|
||||||
amduat_artifact_t output_artifact;
|
amduat_artifact_t output_artifact;
|
||||||
|
|
@ -297,8 +293,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&result_ref, 0, sizeof(result_ref));
|
memset(&run_result, 0, sizeof(run_result));
|
||||||
if (!amduat_pel_surf_run(
|
if (!amduat_pel_surf_run_with_result(
|
||||||
&store,
|
&store,
|
||||||
amduat_pel_program_dag_scheme_ref(),
|
amduat_pel_program_dag_scheme_ref(),
|
||||||
program_ref,
|
program_ref,
|
||||||
|
|
@ -306,36 +302,26 @@ int main(int argc, char **argv) {
|
||||||
opts.input_refs_len,
|
opts.input_refs_len,
|
||||||
opts.has_params_ref,
|
opts.has_params_ref,
|
||||||
params_ref,
|
params_ref,
|
||||||
&output_refs,
|
&run_result)) {
|
||||||
&output_refs_len,
|
|
||||||
&result_ref)) {
|
|
||||||
fprintf(stderr, "error: PEL surface execution failed\n");
|
fprintf(stderr, "error: PEL surface execution failed\n");
|
||||||
exit_code = AMDUAT_PEL_RUN_EXIT_STORE;
|
exit_code = AMDUAT_PEL_RUN_EXIT_STORE;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&trace_ref, 0, sizeof(trace_ref));
|
memset(&trace_ref, 0, sizeof(trace_ref));
|
||||||
memset(&result_artifact, 0, sizeof(result_artifact));
|
|
||||||
memset(&output_artifact, 0, sizeof(output_artifact));
|
memset(&output_artifact, 0, sizeof(output_artifact));
|
||||||
if (amduat_asl_store_get(&store, result_ref, &result_artifact) ==
|
if (run_result.has_result_value && run_result.result_value.has_trace_ref) {
|
||||||
AMDUAT_ASL_STORE_OK) {
|
trace_ref = run_result.result_value.trace_ref;
|
||||||
if (amduat_enc_pel1_result_decode_v1(result_artifact.bytes,
|
has_trace_ref = true;
|
||||||
&result_value)) {
|
|
||||||
has_result_value = true;
|
|
||||||
if (result_value.has_trace_ref) {
|
|
||||||
trace_ref = result_value.trace_ref;
|
|
||||||
has_trace_ref = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.output_raw) {
|
if (opts.output_raw) {
|
||||||
if (opts.output_index >= output_refs_len) {
|
if (opts.output_index >= run_result.output_refs_len) {
|
||||||
fprintf(stderr, "error: output index out of range\n");
|
fprintf(stderr, "error: output index out of range\n");
|
||||||
exit_code = AMDUAT_PEL_RUN_EXIT_USAGE;
|
exit_code = AMDUAT_PEL_RUN_EXIT_USAGE;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (amduat_asl_store_get(&store, output_refs[opts.output_index],
|
if (amduat_asl_store_get(&store, run_result.output_refs[opts.output_index],
|
||||||
&output_artifact) != AMDUAT_ASL_STORE_OK) {
|
&output_artifact) != AMDUAT_ASL_STORE_OK) {
|
||||||
fprintf(stderr, "error: failed to load output artifact\n");
|
fprintf(stderr, "error: failed to load output artifact\n");
|
||||||
exit_code = AMDUAT_PEL_RUN_EXIT_STORE;
|
exit_code = AMDUAT_PEL_RUN_EXIT_STORE;
|
||||||
|
|
@ -352,24 +338,26 @@ int main(int argc, char **argv) {
|
||||||
if (!opts.quiet) {
|
if (!opts.quiet) {
|
||||||
char *hex_ref = NULL;
|
char *hex_ref = NULL;
|
||||||
fprintf(stderr, "status=%s(%u)\n",
|
fprintf(stderr, "status=%s(%u)\n",
|
||||||
has_result_value
|
run_result.has_result_value
|
||||||
? amduat_pel_run_status_name(result_value.core_result.status)
|
? amduat_pel_run_status_name(
|
||||||
|
run_result.result_value.core_result.status)
|
||||||
: "UNKNOWN",
|
: "UNKNOWN",
|
||||||
has_result_value ? (unsigned int)result_value.core_result.status
|
run_result.has_result_value
|
||||||
|
? (unsigned int)run_result.result_value.core_result.status
|
||||||
: 0u);
|
: 0u);
|
||||||
fprintf(stderr, "error_kind=%s(%u)\n",
|
fprintf(stderr, "error_kind=%s(%u)\n",
|
||||||
has_result_value
|
run_result.has_result_value
|
||||||
? amduat_pel_run_error_kind_name(
|
? amduat_pel_run_error_kind_name(
|
||||||
result_value.core_result.summary.kind)
|
run_result.result_value.core_result.summary.kind)
|
||||||
: "UNKNOWN",
|
: "UNKNOWN",
|
||||||
has_result_value
|
run_result.has_result_value
|
||||||
? (unsigned int)result_value.core_result.summary.kind
|
? (unsigned int)run_result.result_value.core_result.summary.kind
|
||||||
: 0u);
|
: 0u);
|
||||||
fprintf(stderr, "status_code=%u\n",
|
fprintf(stderr, "status_code=%u\n",
|
||||||
has_result_value
|
run_result.has_result_value
|
||||||
? (unsigned int)result_value.core_result.summary.status_code
|
? (unsigned int)run_result.result_value.core_result.summary.status_code
|
||||||
: 0u);
|
: 0u);
|
||||||
if (amduat_asl_ref_encode_hex(result_ref, &hex_ref)) {
|
if (amduat_asl_ref_encode_hex(run_result.result_ref, &hex_ref)) {
|
||||||
fprintf(stderr, "result_ref=%s\n", hex_ref);
|
fprintf(stderr, "result_ref=%s\n", hex_ref);
|
||||||
free(hex_ref);
|
free(hex_ref);
|
||||||
}
|
}
|
||||||
|
|
@ -377,7 +365,7 @@ int main(int argc, char **argv) {
|
||||||
fprintf(stderr, "trace_ref=%s\n", hex_ref);
|
fprintf(stderr, "trace_ref=%s\n", hex_ref);
|
||||||
free(hex_ref);
|
free(hex_ref);
|
||||||
}
|
}
|
||||||
if (amduat_asl_ref_encode_hex(output_refs[opts.output_index], &hex_ref)) {
|
if (amduat_asl_ref_encode_hex(run_result.output_refs[opts.output_index], &hex_ref)) {
|
||||||
fprintf(stderr, "output_ref[%zu]=%s\n", opts.output_index, hex_ref);
|
fprintf(stderr, "output_ref[%zu]=%s\n", opts.output_index, hex_ref);
|
||||||
free(hex_ref);
|
free(hex_ref);
|
||||||
}
|
}
|
||||||
|
|
@ -399,7 +387,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
{
|
{
|
||||||
char *hex_ref = NULL;
|
char *hex_ref = NULL;
|
||||||
if (!amduat_asl_ref_encode_hex(result_ref, &hex_ref)) {
|
if (!amduat_asl_ref_encode_hex(run_result.result_ref, &hex_ref)) {
|
||||||
fprintf(stderr, "error: failed to encode result ref\n");
|
fprintf(stderr, "error: failed to encode result ref\n");
|
||||||
exit_code = AMDUAT_PEL_RUN_EXIT_CODEC;
|
exit_code = AMDUAT_PEL_RUN_EXIT_CODEC;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -419,9 +407,9 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < (int)output_refs_len; ++i) {
|
for (i = 0; i < (int)run_result.output_refs_len; ++i) {
|
||||||
char *hex_ref = NULL;
|
char *hex_ref = NULL;
|
||||||
if (!amduat_asl_ref_encode_hex(output_refs[i], &hex_ref)) {
|
if (!amduat_asl_ref_encode_hex(run_result.output_refs[i], &hex_ref)) {
|
||||||
fprintf(stderr, "error: failed to encode output ref\n");
|
fprintf(stderr, "error: failed to encode output ref\n");
|
||||||
exit_code = AMDUAT_PEL_RUN_EXIT_CODEC;
|
exit_code = AMDUAT_PEL_RUN_EXIT_CODEC;
|
||||||
break;
|
break;
|
||||||
|
|
@ -432,17 +420,17 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (has_result_value) {
|
if (run_result.has_result_value) {
|
||||||
amduat_enc_pel1_result_free(&result_value);
|
amduat_enc_pel1_result_free(&run_result.result_value);
|
||||||
}
|
}
|
||||||
if (has_output_artifact) {
|
if (has_output_artifact) {
|
||||||
amduat_pel_run_free_artifact(&output_artifact);
|
amduat_pel_run_free_artifact(&output_artifact);
|
||||||
}
|
}
|
||||||
if (output_refs != NULL) {
|
if (run_result.output_refs != NULL) {
|
||||||
amduat_pel_surf_free_refs(output_refs, output_refs_len);
|
amduat_pel_surf_free_refs(run_result.output_refs,
|
||||||
|
run_result.output_refs_len);
|
||||||
}
|
}
|
||||||
amduat_pel_surf_free_ref(&result_ref);
|
amduat_pel_surf_free_ref(&run_result.result_ref);
|
||||||
amduat_pel_run_free_artifact(&result_artifact);
|
|
||||||
if (input_refs != NULL) {
|
if (input_refs != NULL) {
|
||||||
amduat_pel_run_free_refs(input_refs, opts.input_refs_len);
|
amduat_pel_run_free_refs(input_refs, opts.input_refs_len);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
#include "amduat/asl/store.h"
|
#include "amduat/asl/store.h"
|
||||||
#include "amduat/enc/asl1_core_codec.h"
|
#include "amduat/enc/asl1_core_codec.h"
|
||||||
#include "amduat/enc/pel_program_dag.h"
|
#include "amduat/enc/pel_program_dag.h"
|
||||||
|
#include "amduat/format/parse.h"
|
||||||
|
#include "amduat/format/ref.h"
|
||||||
#include "amduat/pel/opreg_kernel.h"
|
#include "amduat/pel/opreg_kernel.h"
|
||||||
#include "amduat/pel/program_dag_desc.h"
|
#include "amduat/pel/program_dag_desc.h"
|
||||||
|
|
||||||
|
|
@ -27,11 +29,6 @@ enum {
|
||||||
|
|
||||||
static const char *const AMDUAT_PEL_SEED_DEFAULT_ROOT = ".amduat-asl";
|
static const char *const AMDUAT_PEL_SEED_DEFAULT_ROOT = ".amduat-asl";
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
AMDUAT_PEL_SEED_REF_HEX = 0,
|
|
||||||
AMDUAT_PEL_SEED_REF_BYTES = 1
|
|
||||||
} amduat_pel_seed_ref_format_t;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AMDUAT_PEL_SEED_CONST = 0,
|
AMDUAT_PEL_SEED_CONST = 0,
|
||||||
AMDUAT_PEL_SEED_CONCAT = 1,
|
AMDUAT_PEL_SEED_CONCAT = 1,
|
||||||
|
|
@ -55,7 +52,7 @@ typedef struct {
|
||||||
const char *root;
|
const char *root;
|
||||||
const char *output_path;
|
const char *output_path;
|
||||||
amduat_pel_seed_kind_t seed;
|
amduat_pel_seed_kind_t seed;
|
||||||
amduat_pel_seed_ref_format_t ref_format;
|
amduat_format_ref_format_t ref_format;
|
||||||
bool quiet;
|
bool quiet;
|
||||||
bool list_only;
|
bool list_only;
|
||||||
} amduat_pel_seed_opts_t;
|
} amduat_pel_seed_opts_t;
|
||||||
|
|
@ -87,23 +84,6 @@ static void amduat_pel_seed_print_list(FILE *stream) {
|
||||||
" const-hash Const \"hello\" then hash (no inputs)\n");
|
" const-hash Const \"hello\" then hash (no inputs)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool amduat_pel_seed_parse_ref_format(
|
|
||||||
const char *text,
|
|
||||||
amduat_pel_seed_ref_format_t *out_fmt) {
|
|
||||||
if (text == NULL || out_fmt == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "hex") == 0) {
|
|
||||||
*out_fmt = AMDUAT_PEL_SEED_REF_HEX;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (strcmp(text, "bytes") == 0) {
|
|
||||||
*out_fmt = AMDUAT_PEL_SEED_REF_BYTES;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool amduat_pel_seed_parse_kind(const char *text,
|
static bool amduat_pel_seed_parse_kind(const char *text,
|
||||||
amduat_pel_seed_kind_t *out_kind) {
|
amduat_pel_seed_kind_t *out_kind) {
|
||||||
if (text == NULL || out_kind == NULL) {
|
if (text == NULL || out_kind == NULL) {
|
||||||
|
|
@ -537,7 +517,7 @@ int main(int argc, char **argv) {
|
||||||
opts.root = AMDUAT_PEL_SEED_DEFAULT_ROOT;
|
opts.root = AMDUAT_PEL_SEED_DEFAULT_ROOT;
|
||||||
opts.output_path = "-";
|
opts.output_path = "-";
|
||||||
opts.seed = AMDUAT_PEL_SEED_CONST;
|
opts.seed = AMDUAT_PEL_SEED_CONST;
|
||||||
opts.ref_format = AMDUAT_PEL_SEED_REF_HEX;
|
opts.ref_format = AMDUAT_FORMAT_REF_HEX;
|
||||||
|
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "--root") == 0) {
|
if (strcmp(argv[i], "--root") == 0) {
|
||||||
|
|
@ -560,7 +540,7 @@ int main(int argc, char **argv) {
|
||||||
fprintf(stderr, "error: --ref-format requires a value\n");
|
fprintf(stderr, "error: --ref-format requires a value\n");
|
||||||
return AMDUAT_PEL_SEED_EXIT_USAGE;
|
return AMDUAT_PEL_SEED_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
if (!amduat_pel_seed_parse_ref_format(argv[++i], &opts.ref_format)) {
|
if (!amduat_format_ref_parse(argv[++i], &opts.ref_format)) {
|
||||||
fprintf(stderr, "error: invalid ref-format\n");
|
fprintf(stderr, "error: invalid ref-format\n");
|
||||||
return AMDUAT_PEL_SEED_EXIT_USAGE;
|
return AMDUAT_PEL_SEED_EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
@ -626,7 +606,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exit_code == AMDUAT_PEL_SEED_EXIT_OK) {
|
if (exit_code == AMDUAT_PEL_SEED_EXIT_OK) {
|
||||||
if (opts.ref_format == AMDUAT_PEL_SEED_REF_HEX) {
|
if (opts.ref_format == AMDUAT_FORMAT_REF_HEX) {
|
||||||
char *hex_ref = NULL;
|
char *hex_ref = NULL;
|
||||||
if (!amduat_asl_ref_encode_hex(ref, &hex_ref)) {
|
if (!amduat_asl_ref_encode_hex(ref, &hex_ref)) {
|
||||||
fprintf(stderr, "error: failed to encode reference\n");
|
fprintf(stderr, "error: failed to encode reference\n");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue