HyperDbg Debugger
Loading...
Searching...
No Matches
generator.Generator Class Reference

Public Member Functions

 __init__ (self)
 
 Run (self)
 
 WriteCommonHeader (self)
 
 Parse (self, Tokens)
 

Public Attributes

 SourceFile
 
 HeaderFile
 
 CommonHeaderFile
 
 CommonHeaderFileScala
 
 ll1
 
 lalr
 
 gr
 
 lalr_table
 

Constructor & Destructor Documentation

◆ __init__()

generator.Generator.__init__ ( self)
21 def __init__(self):
22 self.SourceFile = open("..\\code\\parse-table.c", "w")
23 self.HeaderFile = open("..\\header\\parse-table.h", "w")
24 self.CommonHeaderFile = open("..\\..\\include\\SDK\\Headers\\ScriptEngineCommonDefinitions.h", "w")
25 self.CommonHeaderFileScala = open("..\\..\\..\\hwdbg\\src\\main\\scala\\hwdbg\\script\\script_definitions.scala", "w")
26 self.ll1 = LL1Parser(self.SourceFile, self.HeaderFile, self.CommonHeaderFile, self.CommonHeaderFileScala)
27 self.lalr = LALR1Parser(self.SourceFile, self.HeaderFile)
28

Member Function Documentation

◆ Parse()

generator.Generator.Parse ( self,
Tokens )
210 def Parse(self, Tokens):
211 Stack = self.ll1.Parse(Tokens)
212 print(Stack)
213
214

◆ Run()

generator.Generator.Run ( self)
29 def Run(self):
30
31
32 self.WriteCommonHeader()
33 self.ll1.Run()
34 self.HeaderFile.write("\n\n")
35 self.lalr.ReadGrammar()
36
37 self.gr = get_grammar(self.lalr)
38 self.lalr_table = lalr_one.ParsingTable(self.gr)
39 self.lalr.ParseTable = self.lalr_table
40 self.ll1.SetLalr(self.lalr, self.lalr_table)
41
42 self.lalr.Run()
43
44 self.CommonHeaderFile.write("#endif\n")
45
46
47 # Closes Output Files
48 self.SourceFile.close()
49 self.HeaderFile.close()
50 self.CommonHeaderFile.close()
51
52

◆ WriteCommonHeader()

generator.Generator.WriteCommonHeader ( self)
53 def WriteCommonHeader(self):
54
55 #
56 # Write scala headers
57 #
58 self.CommonHeaderFileScala.write("""package hwdbg.script
59
60import chisel3._
61import chisel3.util._
62
63/**
64 * @brief
65 * The structure of HWDBG_SHORT_SYMBOL used in script engine of HyperDbg
66 */
67class HwdbgShortSymbol(
68 scriptVariableLength: Int
69) extends Bundle {
70
71 //
72 // Ensure that the script variable length is at least 8 bits or 1 byte
73 //
74 require(
75 scriptVariableLength >= 8,
76 f"err, the minimum script variable length is 8 bits (1 byte)."
77 )
78
79 val Type = UInt(scriptVariableLength.W) // long long unsigned is 64 bits but it can be dynamic
80 val Value = UInt(scriptVariableLength.W) // long long unsigned is 64 bits but it can be dynamic
81}
82
83/**
84 * @brief
85 * Constant values for the script engine
86 */
87object ScriptConstants {
88 val SYMBOL_MEM_VALID_CHECK_MASK = 1 << 31
89 val INVALID = 0x80000000
90 val LALR_ACCEPT = 0x7fffffff
91}
92
93/**
94 * @brief
95 * Constant type values for the script engine
96 */
97object ScriptConstantTypes {
98 object ScriptDataTypes extends ChiselEnum {
99 val symbolUndefined, symbolGlobalIdType, symbolLocalIdType, symbolNumType, symbolRegisterType, symbolPseudoRegType, symbolSemanticRuleType, symbolTempType, symbolStringType, symbolVariableCountType, symbolInvalid, symbolWstringType, symbolUserDefinedFunctionType, symbolFunctionParameterIdType, symbolReturnAddressType, symbolStackTempType, symbolFunctionParameterType = Value
100 }
101}
102
103""")
104 #
105 # Write C/C++ headers
106 #
107 self.CommonHeaderFile.write(
108 """#pragma once
109#ifndef SCRIPT_ENGINE_COMMON_DEFINITIONS_H
110#define SCRIPT_ENGINE_COMMON_DEFINITIONS_H
111
112typedef struct SYMBOL
113{
114 long long unsigned Type;
115 long long unsigned Len;
116 long long unsigned VariableType;
117 long long unsigned Value;
118
119} SYMBOL, *PSYMBOL;
120
121typedef struct HWDBG_SHORT_SYMBOL
122{
123 long long unsigned Type;
124 long long unsigned Value;
125
126} HWDBG_SHORT_SYMBOL, *PHWDBG_SHORT_SYMBOL;
127
128typedef struct SYMBOL_BUFFER {
129 PSYMBOL Head;
130 unsigned int Pointer;
131 unsigned int Size;
132 char* Message;
133} SYMBOL_BUFFER, * PSYMBOL_BUFFER;
134
135typedef struct SYMBOL_MAP
136{
137 char* Name;
138 long long unsigned Type;
139} SYMBOL_MAP, * PSYMBOL_MAP;
140
141typedef struct ACTION_BUFFER {
142 long long unsigned Tag;
143 long long unsigned CurrentAction;
144 char ImmediatelySendTheResults;
145 long long unsigned Context;
146 char CallingStage;
147} ACTION_BUFFER, *PACTION_BUFFER;
148
149typedef struct USER_DEFINED_FUNCTION_NODE
150{
151 char * Name;
152 long long unsigned Address;
153 long long unsigned VariableType;
154 PSYMBOL_BUFFER ParameterBuffer;
155 long long unsigned ParameterNumber;
156 long long unsigned StackTempNumber;
157 struct USER_DEFINED_FUNCTION_NODE * NextNode;
158} USER_DEFINED_FUNCTION_NODE, *PUSER_DEFINED_FUNCTION_NODE;
159
160#define SYMBOL_UNDEFINED 0
161#define SYMBOL_GLOBAL_ID_TYPE 1
162#define SYMBOL_LOCAL_ID_TYPE 2
163#define SYMBOL_NUM_TYPE 3
164#define SYMBOL_REGISTER_TYPE 4
165#define SYMBOL_PSEUDO_REG_TYPE 5
166#define SYMBOL_SEMANTIC_RULE_TYPE 6
167#define SYMBOL_TEMP_TYPE 7
168#define SYMBOL_STRING_TYPE 8
169#define SYMBOL_VARIABLE_COUNT_TYPE 9
170#define SYMBOL_INVALID 10
171#define SYMBOL_WSTRING_TYPE 11
172#define SYMBOL_FUNCTION_PARAMETER_ID_TYPE 12
173#define SYMBOL_RETURN_ADDRESS_TYPE 13
174#define SYMBOL_STACK_TEMP_TYPE 14
175#define SYMBOL_FUNCTION_PARAMETER_TYPE 15
176#define SYMBOL_STACK_INDEX_TYPE 16
177#define SYMBOL_STACK_BASE_INDEX_TYPE 17
178#define SYMBOL_RETURN_VALUE_TYPE 18
179
180static const char *const SymbolTypeNames[] = {
181"SYMBOL_UNDEFINED",
182"SYMBOL_GLOBAL_ID_TYPE",
183"SYMBOL_LOCAL_ID_TYPE",
184"SYMBOL_NUM_TYPE",
185"SYMBOL_REGISTER_TYPE",
186"SYMBOL_PSEUDO_REG_TYPE",
187"SYMBOL_SEMANTIC_RULE_TYPE",
188"SYMBOL_TEMP_TYPE",
189"SYMBOL_STRING_TYPE",
190"SYMBOL_VARIABLE_COUNT_TYPE",
191"SYMBOL_INVALID",
192"SYMBOL_WSTRING_TYPE",
193"SYMBOL_FUNCTION_PARAMETER_ID_TYPE",
194"SYMBOL_RETURN_ADDRESS_TYPE",
195"SYMBOL_STACK_TEMP_TYPE",
196"SYMBOL_FUNCTION_PARAMETER_TYPE",
197"SYMBOL_STACK_INDEX_TYPE",
198"SYMBOL_STACK_BASE_INDEX_TYPE",
199"SYMBOL_RETURN_VALUE_TYPE"
200};
201
202#define SYMBOL_MEM_VALID_CHECK_MASK (1 << 31)
203#define INVALID 0x80000000
204#define LALR_ACCEPT 0x7fffffff
205
206\n\n""")
207
208
209

Member Data Documentation

◆ CommonHeaderFile

generator.Generator.CommonHeaderFile

◆ CommonHeaderFileScala

generator.Generator.CommonHeaderFileScala

◆ gr

generator.Generator.gr

◆ HeaderFile

generator.Generator.HeaderFile

◆ lalr

generator.Generator.lalr

◆ lalr_table

generator.Generator.lalr_table

◆ ll1

generator.Generator.ll1

◆ SourceFile

generator.Generator.SourceFile

The documentation for this class was generated from the following file: