Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
apache-hb committed Mar 26, 2024
1 parent 607eb6d commit f6d4395
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/common/interop/include/interop/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ typedef struct parse_result_t
/// @param callbacks the flex/bison callbacks
///
/// @return the parse result
CT_INTEROP_API parse_result_t scan_buffer(IN_NOTNULL scan_t *extra,
IN_NOTNULL const scan_callbacks_t *callbacks);
CT_INTEROP_API parse_result_t scan_buffer(
IN_NOTNULL scan_t *extra,
IN_NOTNULL const scan_callbacks_t *callbacks);

/// @}

Expand Down
8 changes: 4 additions & 4 deletions src/common/interop/include/interop/flex.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ CT_BEGIN_API
///
/// @param where a pointer to the current location
/// @param text current source text
CT_INTEROP_API void flex_action(IN_NOTNULL where_t *where, IN_STRING const char *text);
CT_INTEROP_API void flex_action(INOUT_NOTNULL where_t *where, IN_STRING const char *text);

/// @brief retrevies more input for flex
///
Expand All @@ -30,19 +30,19 @@ CT_INTEROP_API void flex_action(IN_NOTNULL where_t *where, IN_STRING const char
/// @param size total number of characters to write
///
/// @return number of characters written
CT_INTEROP_API int flex_input(IN_NOTNULL scan_t *scan, OUT_WRITES(size) char *out, int size);
CT_INTEROP_API int flex_input(INOUT_NOTNULL scan_t *scan, OUT_WRITES(size) char *out, int size);

/// @brief initialize source location tracking
///
/// @param where the source location to initialize
CT_INTEROP_API void flex_init(IN_NOTNULL where_t *where);
CT_INTEROP_API void flex_init(OUT_NOTNULL where_t *where);

/// @brief update the source location
///
/// @param where the source location to update
/// @param offsets the source location offsets
/// @param steps the number of steps to update by
CT_INTEROP_API void flex_update(IN_NOTNULL where_t *where, IN_READS(steps) const where_t *offsets, int steps);
CT_INTEROP_API void flex_update(INOUT_NOTNULL where_t *where, IN_READS(steps) const where_t *offsets, int steps);

/// track source locations inside flex and bison
#ifndef YY_USER_ACTION
Expand Down
6 changes: 3 additions & 3 deletions src/common/notify/include/notify/notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ CT_NOTIFY_API void logger_reset(IN_NOTNULL logger_t *logs);
/// @return the new event builder
CT_PRINTF(4, 5)
CT_NOTIFY_API event_builder_t msg_notify(
IN_NOTNULL logger_t *logs,
const diagnostic_t *diagnostic,
INOUT_NOTNULL logger_t *logs,
IN_NOTNULL const diagnostic_t *diagnostic,
const node_t *node,
CT_FMT_STRING const char *fmt, ...);

Expand All @@ -140,7 +140,7 @@ CT_NOTIFY_API event_builder_t msg_notify(
///
/// @return the new event
CT_NOTIFY_API event_builder_t msg_vnotify(
IN_NOTNULL logger_t *logs,
INOUT_NOTNULL logger_t *logs,
IN_NOTNULL const diagnostic_t *diagnostic,
const node_t *node,
const char *fmt, va_list args);
Expand Down
4 changes: 3 additions & 1 deletion src/common/scan/include/scan/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ CT_SCAN_API node_t *node_new(const scan_t *scan, where_t where);
///
/// @return the builtin node
CT_NODISCARD CT_PUREFN
CT_SCAN_API node_t *node_builtin(IN_STRING const char *name, IN_NOTNULL arena_t *arena);
CT_SCAN_API node_t *node_builtin(
IN_STRING const char *name,
IN_NOTNULL arena_t *arena);

/// @brief check if a node is the builtin node
///
Expand Down
15 changes: 10 additions & 5 deletions src/common/scan/include/scan/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CT_BEGIN_API
typedef struct scan_t
{
/// @brief the backing io object
/// this will be NULL if the scanner is a builtin scanner
/// @note this will be NULL if the scanner is a builtin scanner
io_t *io;

/// @brief the allocator to use
Expand Down Expand Up @@ -95,6 +95,7 @@ CT_SCAN_API void scan_set_context(IN_NOTNULL scan_t *scan, void *value);
/// @param scan the scanner to get the context of
///
/// @return the context of @p scan
CT_NODISCARD CT_PUREFN
CT_SCAN_API void *scan_get_context(IN_NOTNULL const scan_t *scan);

/// @brief get a text span of the scanners contents
Expand All @@ -121,7 +122,10 @@ CT_SCAN_API arena_t *scan_get_arena(IN_NOTNULL const scan_t *scan);
///
/// @return the number of bytes read
CT_NODISCARD RET_RANGE(0, size) CT_NOALIAS
CT_SCAN_API size_t scan_read(IN_NOTNULL scan_t *scan, OUT_WRITES(size) void *dst, size_t size);
CT_SCAN_API size_t scan_read(
IN_NOTNULL scan_t *scan,
OUT_WRITES(size) void *dst,
size_t size);

/// @brief create a scanner from an io source
///
Expand All @@ -131,9 +135,10 @@ CT_SCAN_API size_t scan_read(IN_NOTNULL scan_t *scan, OUT_WRITES(size) void *dst
///
/// @return the created scanner
CT_NODISCARD
CT_SCAN_API scan_t *scan_io(IN_STRING const char *language,
IN_NOTNULL io_t *io,
IN_NOTNULL arena_t *arena);
CT_SCAN_API scan_t *scan_io(
IN_STRING const char *language,
IN_NOTNULL io_t *io,
IN_NOTNULL arena_t *arena);

/// @brief create a builtin scanner
///
Expand Down
2 changes: 1 addition & 1 deletion src/cthulhu/broker/include/cthulhu/broker/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ typedef void (*target_create_t)(target_runtime_t *runtime);
typedef void (*target_destroy_t)(target_runtime_t *runtime);

/// @brief tree output generation
typedef void (*target_tree_t)(target_runtime_t *runtime, tree_t *tree);
typedef void (*target_tree_t)(target_runtime_t *runtime, const tree_t *tree, target_emit_t *emit);

/// @brief ssa output generation
typedef void (*target_ssa_t)(target_runtime_t *runtime, const ssa_result_t *ssa, target_emit_t *emit);
Expand Down
6 changes: 6 additions & 0 deletions src/cthulhu/broker/include/cthulhu/broker/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ CT_BROKER_API arena_t *ctx_get_ast_arena(const scan_t *scan);
// alias for vector_init(init, scan_get_arena(scan))
CT_BROKER_API vector_t *ctx_vector_init(void *init, const scan_t *scan);

// alias for vector_new(size, scan_get_arena(scan))
CT_BROKER_API vector_t *ctx_vector_new(size_t size, const scan_t *scan);

// alias for vector_of(type, scan_get_arena(scan))
CT_BROKER_API vector_t *ctx_vector_of(size_t size, const scan_t *scan);

CT_BROKER_API void *ctx_get_user(const scan_t *scan);

CT_BROKER_API void ctx_error(const where_t *where, const void *state, const scan_t *scan, const char *msg);
Expand Down
13 changes: 11 additions & 2 deletions src/cthulhu/broker/src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ arena_t *ctx_get_ast_arena(const scan_t *scan)

vector_t *ctx_vector_init(void *init, const scan_t *scan)
{
scan_context_t *ctx = scan_get_context(scan);
return vector_init(init, ctx->arena);
return vector_init(init, ctx_get_arena(scan));
}

vector_t *ctx_vector_new(size_t size, const scan_t *scan)
{
return vector_new(size, ctx_get_arena(scan));
}

vector_t *ctx_vector_of(size_t size, const scan_t *scan)
{
return vector_of(size, ctx_get_arena(scan));
}

void *ctx_get_user(const scan_t *scan)
Expand Down
4 changes: 2 additions & 2 deletions src/language/ctu/src/ctu.y
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ importAlias: %empty { $$ = NULL; }

/* decorators */

attribs: %empty { $$ = vector_new(4, BISON_ARENA(x)); }
attribs: %empty { $$ = ctx_vector_new(4, x); }
| attribs attrib { vector_append(&$1, $2); $$ = $1; }
;

Expand Down Expand Up @@ -370,7 +370,7 @@ opt_type_list: %empty { $$ = &kEmptyVector; }

/* statements */

stmt_list: %empty { $$ = vector_of(0, BISON_ARENA(x)); }
stmt_list: %empty { $$ = ctx_vector_of(0, x); }
| stmt_list stmt { vector_push(&$1, $2); $$ = $1; }
;

Expand Down
8 changes: 4 additions & 4 deletions src/language/pl0/src/pl0.y
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ program: block DOT { scan_set(x, $1); }
block: module imports consts vars procedures toplevel { $$ = pl0_module(x, @$, $1, $2, $3, $4, $5, $6); }
;

imports: %empty { $$ = vector_new(0, BISON_ARENA(x)); }
imports: %empty { $$ = ctx_vector_new(0, x); }
| IMPORT paths SEMICOLON { $$ = $2; }
;

Expand All @@ -136,7 +136,7 @@ toplevel: %empty { $$ = NULL; }
| stmtlist { $$ = pl0_stmts(x, @$, $1); }
;

consts: %empty { $$ = vector_new(0, BISON_ARENA(x)); }
consts: %empty { $$ = ctx_vector_new(0, x); }
| CONST inits SEMICOLON { $$ = $2; }
;

Expand All @@ -147,7 +147,7 @@ inits: init { $$ = ctx_vector_init($1, x); }
init: IDENT EQUALS expr { $$ = pl0_value(x, @$, $1, $3); }
;

vars: %empty { $$ = vector_new(0, BISON_ARENA(x)); }
vars: %empty { $$ = ctx_vector_new(0, x); }
| VAR names SEMICOLON { $$ = $2; }
;

Expand All @@ -158,7 +158,7 @@ names: name { $$ = ctx_vector_init($1, x); }
name: IDENT { $$ = pl0_value(x, @$, $1, NULL); }
;

procedures: %empty { $$ = vector_new(0, BISON_ARENA(x)); }
procedures: %empty { $$ = ctx_vector_new(0, x); }
| proclist { $$ = $1; }
;

Expand Down
4 changes: 4 additions & 0 deletions src/target/cfamily/include/cfamily/target.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only

#pragma once

typedef struct target_runtime_t target_runtime_t;
typedef struct tree_t tree_t;
typedef struct ssa_result_t ssa_result_t;
37 changes: 36 additions & 1 deletion src/target/cfamily/src/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@

#include "cfamily/target.h"

#include "core/macros.h"
#include "driver/driver.h"

static void cfamily_create(target_runtime_t *runtime)
{
// empty
CT_UNUSED(runtime);
}

static void cfamily_destroy(target_runtime_t *runtime)
{
// empty
CT_UNUSED(runtime);
}

static void cfamily_tree(target_runtime_t *runtime, const tree_t *tree, target_emit_t *emit)
{
// empty
CT_UNUSED(runtime);
CT_UNUSED(tree);
CT_UNUSED(emit);
}

static void cfamily_ssa(target_runtime_t *runtime, const ssa_result_t *ssa, target_emit_t *emit)
{
// empty
CT_UNUSED(runtime);
CT_UNUSED(ssa);
CT_UNUSED(emit);
}

CT_DRIVER_API const target_t kTargetC = {
.info = {
.id = "target/cfamily",
Expand All @@ -14,7 +43,13 @@ CT_DRIVER_API const target_t kTargetC = {
.desc = "C89 output target",
.version = CT_NEW_VERSION(0, 0, 1)
}
}
},

.fn_create = cfamily_create,
.fn_destroy = cfamily_destroy,

.fn_tree = cfamily_tree,
.fn_ssa = cfamily_ssa
};

CT_TARGET_EXPORT(kTargetC)

0 comments on commit f6d4395

Please sign in to comment.