1 /* 2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef HCS_COMPILER_PARSER_H 10 #define HCS_COMPILER_PARSER_H 11 12 #include <stdio.h> 13 #include "hcs_types.h" 14 15 #define OBJECT_NAME_MAX_LEN 100 16 17 enum ParserObjectType { 18 PARSEROP_UINT8 = 0x01, 19 PARSEROP_UINT16, 20 PARSEROP_UINT32, 21 PARSEROP_UINT64, 22 PARSEROP_STRING, 23 PARSEROP_CONFNODE, 24 PARSEROP_CONFTERM, 25 PARSEROP_ARRAY, 26 PARSEROP_NODEREF, 27 PARSEROP_DELETE, 28 PARSEROP_COUNT, 29 }; 30 31 enum NodeRefType { 32 CONFIG_NODE_NOREF = 0, 33 CONFIG_NODE_COPY, 34 CONFIG_NODE_REF, 35 CONFIG_NODE_DELETE, 36 CONFIG_NODE_TEMPLATE, 37 CONFIG_NODE_INHERIT, 38 CONFIG_NODE_TYPE_COUNT 39 }; 40 enum ParserObjectStatus { 41 PARSER_OBJ_IDLE = 0, 42 PARSER_OBJ_PROCESSING, 43 }; 44 struct ParserObjectBase; 45 typedef struct ParserObjectBase ParserObjectBase; 46 47 #define PARSER_OBJECT_COMMON \ 48 uint32_t type; \ 49 uint32_t status; \ 50 const char *name; \ 51 ParserObjectBase *parent; \ 52 ParserObjectBase *next; \ 53 ParserObjectBase *child; \ 54 uint32_t lineno; \ 55 const char *src; \ 56 uint8_t opCode; \ 57 uint32_t size; \ 58 uint32_t subSize; \ 59 uint32_t hash; \ 60 union { \ 61 uint64_t value; \ 62 uint64_t integerValue; \ 63 char *stringValue; \ 64 } 65 66 struct ParserObjectBase { 67 PARSER_OBJECT_COMMON; 68 }; 69 70 typedef struct TemplateNodeInstance { 71 struct ConfigNode *nodeObject; 72 struct TemplateNodeInstance *next; 73 } TemplateNodeInstance; 74 75 typedef struct ConfigNode { 76 PARSER_OBJECT_COMMON; 77 const char *refNodePath; 78 uint32_t nodeType; 79 struct ConfigNode *inheritNode; 80 uint32_t inheritIndex; 81 uint32_t inheritCount; 82 uint32_t templateSignNum; 83 TemplateNodeInstance *subClasses; 84 } ConfigNode; 85 86 typedef struct { 87 PARSER_OBJECT_COMMON; 88 uint32_t flag; // for array or other assembly type 89 uint32_t signNum; 90 } ConfigTerm; 91 92 typedef union { 93 ParserObjectBase objectBase; 94 ConfigNode configNode; 95 ConfigTerm configTerm; 96 } ParserObject; 97 98 enum AstWalkDirection { 99 AST_WALK_FORWARD = 0x01, 100 AST_WALK_BACKEND, 101 AST_WALK_ROUND, 102 }; 103 104 enum AstCopyOverWriteFlag { 105 AST_COPY_SRC_OVER_DST = 0, // source term overwrite destination terms 106 AST_COPY_DST_OVER_SRC, // destination term overwrite source terms 107 }; 108 109 /* lexer and parser auto-gen api start */ 110 void HcsParserRestart(FILE *inputFile); 111 112 int32_t HcsCompilerparse(void); 113 114 /* lexer and parser auto-gen api end */ 115 bool HcsIsAnonymousObject(const ParserObject *obj); 116 117 int32_t HcsProcessInclude(char *includePath, uint32_t lineNumber); 118 119 bool HcsIsSameTypeObject(const ParserObject *cs, const ParserObject *ct); 120 121 bool HcsIsNumberObject(const ParserObject *obj); 122 123 bool HcsIsStringObject(const ParserObject *obj); 124 125 const char *HcsParserNodeTypeToStr(uint32_t nodeType); 126 127 void HcsAstFreeObject(ParserObject *object); 128 129 int32_t HcsGetCurrentSourceLine(void); 130 131 void HcsSetCurrentSourceLine(int32_t lineNumber); 132 133 uint32_t HcsAlign(uint32_t size); 134 135 #endif // HCS_COMPILER_PARSER_H 136